akhauriyash/Code-Regression huggingface dataset:
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
using namespace std;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N, count;
	cin >> N;
	REP(i, N) {
		int x;
		cin >> x;
		bool flag = true;
		for(int j = 2; j*j <= x; j++) {
			if(x%j == 0) {
				flag = false;
				break;
			}
		}
		if(flag) count++;
	}
	cout << count << endl;
}


Measured memory_bytes: 3204
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
typedef vector<ll>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

ll a[1010], b[1010];
ll C[1010][20];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;

    REP(i,M){
        cin >> a[i] >> b[i];
        REP(j,b[i]){
            cin >> C[i][j];
            C[i][j]--;
        }
    }
    vector<ll> dp((1<<N), LINF);
    dp[0] = 0;
    REP(i,(1<<N)){
        REP(j,M){
            int tmp = i;
            REP(k, b[j]){
                tmp |= (1 << C[j][k]);
            }
            chmin(dp[tmp], dp[i] + a[j]);
        }
    }
    ll ans = dp[(1<<N)-1];
    if(ans == LINF) cout << -1 << endl;
    else cout << ans << endl;
}


Measured memory_bytes: 512
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()

struct graph {
  int L, R;
  vector<vector<int>> adj;
  graph(int L, int R) : L(L), R(R), adj(L + R) {}
  void add_edge(int u, int v) {
    adj[u].push_back(v + L);
    adj[v + L].push_back(u);
  }
  int maximum_matching() {
    vector<int> visited(L), mate(L + R, -1);
    function<bool(int)> augment = [&](int u) {  // DFS
      if (visited[u]) return false;
      visited[u] = true;
      for (int w : adj[u]) {
        int v = mate[w];
        if (v < 0 || augment(v)) {
          mate[u] = w;
          mate[w] = u;
          return true;
        }
      }
      return false;
    };
    int match = 0;
    for (int u = 0; u < L; ++u) {
      fill(ALL(visited), 0);
      if (augment(u)) ++match;
    }
    return match;
  }
};

int main() {
  //
  int n;
  cin >> n;
  graph g(n, n);
  vi x(2 * n), y(2 * n);
  rep(i, 2 * n) { cin >> x[i] >> y[i]; }
  rep(l, n) {
    rep(r, n) {
      if (x[l] < x[n + r] && y[l] < y[n + r]) {
        g.add_edge(l, r);
      }
    }
  }
  cout << g.maximum_matching() << endl;

  return 0;
}


Measured memory_bytes: 256
import math

#桁の配置 → あるところまで Kと同じで、あるところで 1  のところを0を配置、後は理想的配置

N,K = list(map(int,input().split(" ")))
As = list(map(int,input().split(" ")))
dp =[ [ -1 for  _ in range(2)] for _ in range (51)]
dp[0][0] = 0 #-1→未定義状態→そこから遷移も何も無い
for d in range(50):
    mask =  1 << (50 - d - 1) # (50 - d - 1)→50桁の数の上からd番目を残すマスク
    cot = 0
    for A in As:
        if (A & mask): #上からd桁目の 1をカウント
            cot += 1
    cost0 = mask * cot #mask桁目を0にしたときの利益 1 1 のところの数= 0にすれば利益を得られるところ
    cost1 = mask * (N -cot) #桁目を1にしたときの利益
    #三通りの遷移(1 → 0 の遷移は無い)
    if dp[d][1] != -1: #1→1の遷移
        dp[d + 1][1] = max( dp[d][1] + cost0,dp[d][1] + cost1    )
    if dp[d][0] !=-1: # 0→ 1の遷移

        if (K &mask): #Kのある桁が1のときに、そこを0にすることで1→0に遷移をする
            dp[d + 1][1] = max(dp[d][0] + cost0 , dp[d + 1][1])
    if dp[d][0] !=-1: # 0→ 0の遷移
        if (K &mask): #同じ数字を配置することでトレースする
            dp[d + 1][0] = max(dp[d][0]  , dp[d][0] + cost1)

        else:
            dp[d + 1][0] = max(dp[d][0]  , dp[d][0] + cost0)
# print(dp)
print(max(dp[50][0],dp[50][1]))

Measured memory_bytes: 68572
#ライブラリインポート
from collections import defaultdict

#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	H, W, K = getlist()
	S = []
	for i in range(H):
		s = list(input())
		S.append(s)
	ans = [[0] * W for i in range(H)]
	c = 1
	for i in range(H):
		v = 0
		for j in range(W):
			if S[i][j] == "#":
				for k in range(v, j + 1):
					ans[i][k] = c
				v = j + 1
				c += 1
	for i in range(H):
		for j in range(W - 1):
			if ans[i][j] != 0 and ans[i][j + 1] == 0:
				ans[i][j + 1] = ans[i][j]
	for i in range(1, H):
		for j in range(W):
			if ans[i][j] == 0:
				ans[i][j] = ans[i - 1][j]
	for i in range(H - 1):
		for j in range(W):
			if ans[H - 2 - i][j] == 0:
				ans[H - 2 - i][j] = ans[H - 1 - i][j]

	for i in range(H):
		print(" ".join(list(map(str, ans[i]))))


if __name__ == '__main__':
	main()

Measured memory_bytes: 48364
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);

		int n = sc.nextInt();
		int min = 114514, max = -114514;
		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();
			min = Math.min(min, a);
			max = Math.max(max, a);
		}

		out.println(max - min);
		out.flush();
	}

}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private byte readByte() {
		if (hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}

	private boolean isPrintableChar(int c) {
		return '!' <= c && c <= '~';
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public int nextInt() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		int n = 0;
		boolean minus = false;
		byte b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
}

Measured memory_bytes: 21204
import collections
N, M, K = map(int, input().split())
friend = [[] for i in range(N)]
block = [[] for i in range(N)]
graph = [-1] * N
for i in range(M):
  a, b = map(int, input().split())
  friend[a-1].append(b-1)
  friend[b-1].append(a-1)
  
for i in range(K):
  c, d = map(int, input().split())
  block[c-1].append(d-1)
  block[d-1].append(c-1)
  
#print(friend, block)

used = [True] * N
for i in range(N):
  if used[i]:
    q = [i]
    used[i] = False
    graph[i] = i
    while q:
      now = q.pop()
      for j in friend[now]:
        if used[j]:
          graph[j] = graph[now]
          q.append(j)
          used[j] = False
          
          
#print(graph)          
gg = dict(collections.Counter(graph))  
#print(gg)

for i in range(N):
  nn = graph[i]
  size = gg[nn]
  ans = size - 1
  for j in friend[i]:
    if nn == graph[j]:
      ans -= 1
  for j in block[i]:
    if nn == graph[j]:
      ans -= 1
  print(ans, end = " ")




Measured memory_bytes: 55772
# -*- coding: utf-8 -*-


def main():
    n = int(input().strip())
    if n >= 100000:
        r = (99999 - 10000 + 1) + (999 - 100 + 1) + (9 - 1 + 1)
    elif n >= 10000:
        r = (n - 10000 + 1) + (999 - 100 + 1) + (9 - 1 + 1)
    elif n >= 1000:
        r = (999 - 100 + 1) + (9 - 1 + 1)
    elif n >= 100:
        r = (n - 100 + 1) + (9 - 1 + 1)
    elif n >= 10:
        r = (9 - 1 + 1)
    else:
        r = n - 1 + 1
    print('%d' % r)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> b(n-1);
    vector<int> a(n);
    for (int i = 0;i < n-1;i++) cin >> b[i];
    a[0] = b[0];
    for (int i = 1;i <= n-2;i++){
        a[i] = min(b[i-1],b[i]);
    }
    a[n-1] = b[n-2];
    int ans = 0;
    for (int i = 0;i < n;i++) ans += a[i];
    cout << ans << endl;    
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    readLine()?.let {
        var num = 0.toLong()
        for (i in 1..it.toLong()) {
            if (!(i % 3.toLong() == 0.toLong() || i % 5.toLong() == 0.toLong())) {
                num += i.toLong()
            }
        }
        println(num)
    }
}

Measured memory_bytes: 34356
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define rrep(i,a) for(int i=(int)a-1;i>=0;--i)
#define REP(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RREP(i,a,b) for(int i=(int)a-1;i>=b;--i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n) / gcd(n, m)*abs(m);//gl=xy
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;

void solve(){
  int n;
  cin>>n;
  vector<ll>s(n);
  rep(i,n)cin>>s[i];
  int q;
  cin>>q;
  vector<ll>t(q);
  rep(i,q)cin>>t[i];
  ll cnt=0;
  rep(i,q){
    ll x=*lower_bound(all(s),t[i]);
    if(x==t[i])++cnt;
  }
  cout<<cnt<<endl;
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}



Measured memory_bytes: 4120
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var n = input.trim() - 0;
var ans = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
var i = 0;
while (true) {
   i++;
   var cnt = 0;
   for (var j = i; j >= 1; j--) {
      if (i % j == 0) cnt++;
   }
   if (ans[cnt - 1] == 0) {
      ans[cnt - 1] = i;
      if (!ans.includes(0)) break;
   }
}
console.log(ans[n-1]);


Measured memory_bytes: 17372
#include <iostream>
using namespace std;

int main()
{
	int r = 0, c = 0, a[100][100] = {0}, ttl = 0;

	cin >> r >> c;

	for (int i = 0; i < r; i++){
		for (int j = 0; j < c; j++)
			cin >> a[i][j];
	}

	for (int i = 0; i < r; i++) {
		int k = 0;
		for (int j = 0; j < c; j++) {
			cout << a[i][j] << " ";
			k += a[i][j];
		}
		cout << k << endl;
	}

	for (int j = 0; j < c; j++) {
		int k = 0;
		for (int i = 0; i < r; i++) {
			k += a[i][j];
		}
		cout << k << " ";
		ttl += k;
	}

	cout << ttl << endl;

    return 0;
}

Measured memory_bytes: 3136
MOD = 10**9+7

# フェルマーの小定理
def nCr(n, r, mod=MOD):
    r = min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n+1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom, mod-2, mod) % mod

def g(r, c):
    return nCr(r+c+2, r+1) - 1

r1, c1, r2, c2 = map(int, input().split())
r1 -= 1; c1 -= 1
ans = g(r2, c2)
ans -= g(r1, c2)
ans -= g(r2, c1)
ans += g(r1, c1)
ans += MOD * 2
ans %= MOD
print(ans)


Measured memory_bytes: 3064
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n = int(input())
a = list( map(int, input().split()))
a.sort()

from collections import Counter
cnt = Counter(a)

if a[0]==1:
    if cnt[1]==1:
        print(1)
    else:
        print(0)
    exit()

limit = a[-1]
is_prime = [0] * (limit + 1)

for aa in a:
    is_prime[aa]=1

for i in range(2, limit + 1):

    if is_prime[i]==0:
        continue
    for j in range(i * 2, limit + 1, i):
        is_prime[j] = 0

ans=0

for i in range(1,limit+1):
    if is_prime[i] and cnt[i] < 2:
        ans+=1

print(ans)




Measured memory_bytes: 121404
#include <bits/stdc++.h>
using namespace std;

inline int read() {
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - 48; ch = getchar(); }
	return x * f;
}

int main() {
    int n = read(), m = read();
    int l = 1, r = n;
    while (m--) {
        int u = read(), v = read();
        l = max(l, u); r = min(r, v);
    }
    int ans;
    if (l > r) ans = 0;
    else ans = r - l + 1;
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define INF 1000000000000000000LL
#define mod 1000000007LL
#define IN freopen("C.in","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define REP(i,a,b) for(i=(a) ; i<=(b) ; i++)
#define DBG pf("Hi\n")
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 45
#define off 2
#define whatis(x) cout<<x<<endl ;

using namespace __gnu_pbds;
using namespace std ;

typedef pair<int,int> pi ;
typedef tree< pi, null_type, less<pi>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define maxn 1000005

i64 a[55] ;

int main()
{
    i64 i , j , k , l , n , m ;

    scanf("%lld",&n) ;

    for(i=1 ; i<=n ; i++) scanf("%lld",&a[i]) ;

    sort( a+1 , a+n+1 ) ;

    i64 sum = 0LL ;

    for(i=1 ; i<=n ; i++) sum += a[i] ;

    i64 x = sum - n*n ;

    x = max( x  , 0LL ) ;

    REP(i,1,n) a[i] += x ;

    i64 lo = n , hi = a[n] ;

    while( lo<hi )
    {
        i64 m = ( lo+hi )/2 ;

        i64 ret = 0LL ;

        REP( i , 1 , n )
        {
            ret += (max(a[i]-m,0LL)+n)/(n+1) ;
        }
     //   printf("lo:%lld hi:%lld m:%lld ret:%lld x:%lld\n",lo,hi,m,ret,x) ;
        if( ret <= x ) hi = m ;
        else lo = m+1 ;

    }
    i64 cnt = 0LL ;
    REP(  i, 1 , n )
    {
        i64 c = (max(( a[i]-lo),0LL)+n)/(n+1) ;
        a[i] -= (n+1)*c ;
        cnt += c ;
    }

/*    for(i=1 ; i<=n ; i++) printf("%lld ",a[i]) ;
    printf("\n") ;
    printf("%lld %lld\n",cnt,x) ;
*/
    priority_queue<i64> pq ;

    REP(i,1,n) pq.push(a[i]) ;

    while( cnt<x )
    {
 //       printf("Entered\n") ;
        cnt++ ;
        i64 tp = pq.top() ;
        pq.pop() ;
        tp -= (n+1) ;
        pq.push( tp ) ;
    }

    for(i=1 ; i<=n ; i++)
    {
        a[i] = pq.top() ;
        pq.pop() ;
    }

 /*   for(i=1 ; i<=n ; i++) printf("%lld ",a[i]) ;
    printf("\n") ;
*/

    i64 ans = x ;

    while( 1 )
    {
        i64 mx = 0  ,id ;
        REP(i,1,n)
        {
            mx = max( mx , a[i] ) ;
            if( mx==a[i] ) id = i ;
        }
        if( mx > n-1 ) ans++ ;
        else break ;
        REP(i,1,n) a[i] += 1 ;
        a[id] -= (n+1) ;
    }

    printf("%lld\n",ans) ;

    return 0 ;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	m := getNextInt(scanner)

	ans := m
	inf := math.MaxInt32

	var g [100][100]int
	var unused [100][100]int

	for i := 0; i < n; i++ {
		for ii := 0; ii < n; ii++ {
			if i == ii {
				continue
			}
			g[i][ii] = inf
		}
	}

	for i := 0; i < m; i++ {
		a := getNextInt(scanner) - 1
		b := getNextInt(scanner) - 1
		c := getNextInt(scanner)
		g[a][b] = c
		g[b][a] = c
		unused[a][b] = 1
		unused[b][a] = 1
	}

	for m := 0; m < n; m++ {
		for l := 0; l < n; l++ {
			for r := 0; r < n; r++ {
				if l == r {
					continue
				}
				if g[l][r] > g[l][m]+g[m][r] {
					g[l][r] = g[l][m] + g[m][r]
					unused[l][r] = 0
				}
			}
		}
	}

	for i := 0; i < n; i++ {
		for ii := 0; ii < i; ii++ {
			ans -= unused[i][ii]
		}
	}
	fmt.Fprintln(writer, ans)
	writer.Flush()
}


Measured memory_bytes: 896
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
#include <random>
#include <unordered_set>
#include <complex>
using namespace std;
 
#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };
// typedef complex<double> C;
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
int INF = INT_MAX / 2;
double EPS = 1e-10;

int main() {
	int N, A, B;
	cin >> N >> A >> B;
	vector<vector<int> > dp(401, vector<int>(401, INF));
	dp[0][0] = 0;
	while (N--) {
		int a, b, c;
		cin >> a >> b >> c;
		for (int x = 400; x >= a; x--)
			for (int y = 400; y >= b; y--)
				dp[x][y] = min(dp[x][y], dp[x - a][y - b] + c);
	}
	int ans = INF;
	for (int x = 1; x <= 400; x++)
		for (int y = 1; y <= 400; y++)
			if (x * B == y * A)
				ans = min(ans, dp[x][y]);
	if (ans == INF) ans = -1;
	cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int NMAX = 2e5 + 10;
const int MOD = 1e9 + 7;
ll loc[NMAX] ;
ll pre_sum[NMAX];
int main(int argc, char const *argv[])
{
	ll n , ans = 0;
	ll x , m ,pos = 1;
	scanf("%lld%lld%lld",&n,&x,&m);
	loc[x] = 1;
	pre_sum[1] = x % m;
	for(register ll i = 2;i <= n && !loc[x*x%m];i++)
	{
		x = x*x%m;
		loc[x] = i;
		pre_sum[i] = pre_sum[i - 1] + x;
		pos = i;
	}
	if(pos == n)
		return 0*printf("%lld\n",pre_sum[n]);
	ans += pre_sum[loc[x*x%m] - 1];
	ll T = pos - loc[x*x%m] + 1;
	ans += (pre_sum[pos] - pre_sum[loc[x*x%m] - 1]) * ((n - loc[x*x%m] + 1)/T);
	ans += pre_sum[loc[x*x%m] - 1 + (n - loc[x*x%m] + 1)%T] - pre_sum[loc[x*x%m] - 1];
	printf("%lld\n",ans );
	return 0;
}


Measured memory_bytes: 4932
//codeforces
//
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define F first
#define S second
//#define inf 1e9+7
#define int64 long long
#define VI vector < int >
#define all(v) v.begin(),v.end()
#define inpv(v) for(auto &x:v) cin>>x
#define pii pair < int , int >
#define CASES int tt;cin>>tt; while(tt--)
#define for0(i,n) for(int i=0; i<n; i++)
const int64 inf = 1e9+7;
const char nwl = '\n';

int main()
{
	//ur code
  	int n,a,b;
  cin>>n>>a>>b;
  int  t;
  if(a%n)
    t= ((a/n)+1)*n;
  else
    t=a;
  if(n==1 || (a<=t && t<=b) )
    cout<<"OK";
  else
    cout<<"NG";
	
	return 0;
}


Measured memory_bytes: 3624
import math

n = int(input())
s_list = list(map(int, input().split()))
q = int(input())
t_list = list(map(int, input().split()))

count = 0
for t in t_list:
    left = 0
    right = len(s_list) - 1
    while left <= right:
        mid = math.floor((left + right) / 2)
        if s_list[mid] == t:
            count = count + 1
            break
        elif s_list[mid] > t:
            right = mid - 1
            continue
        elif s_list[mid] < t:
            left = mid + 1
            continue

print(count)



Measured memory_bytes: 16768
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#define REP(i,n) for (int i=0;i<(n);i++)
using namespace std;

int main(){
    int n;
    string w[100];
    cin >> n;
    REP(i, n) cin >> w[i];
    bool isSolve = true;
    REP(i, n-1){
        if(w[i].back() != w[i+1].front()){
            isSolve = false;
            break;
        }
        for(int j = i+1; j < n; j++){
            if(w[i] == w[j]){
                isSolve = false;
                break;
            }
        }
    }
    if(isSolve){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;

#define int long long
#define pii pair<int,int>
#define pqi priority_queue<int>
#define pb push_back()
#define INF 1000000000000000000

#define float long double
#define pi acos(-1)

const int modu= (1e9)+7;

void testCase(int ti){
    cout<<"Case "<<ti<<": ";
}

int bigmod(int n,int p){
    if(p==0) return 1;
    int x=bigmod(n,p/2)%modu;
    x=(x*x)%modu;
    if(p%2) return (x*n)%modu;
    return x;
}

int modInverse(int a){
    return bigmod(a,modu-2)%modu;
}

void debug(string pr,vector<int> var,bool out=true){
    #ifdef OFFLINE
        ofstream fl;
        fl.open("debug.txt");
        fl<<pr;
        for(int i=0;i<var.size();i++) fl<<" "<<var[i];
        fl<<endl;
        fl.close();
    if(out){
        cout<<pr;
        for(int i=0;i<var.size();i++) cout<<" "<<var[i];
        cout<<endl;
    }
    #endif
}

void faster(){
    ios_base::sync_with_stdio(false);
    cin.tie();
    cout.tie();
}

void defInit(){
    faster();
    #ifdef OFFLINE
      freopen("in.txt", "r", stdin);
      freopen("out.txt", "w", stdout);
    #endif
}

int add(int x,int y){
    int z =(x%modu + y%modu)%modu;
    while(z<0) z=(z+modu)%modu;
    return z;
}

int mul(int x,int y){
    int z = (x%modu * y%modu)%modu;
    while(z<0) z=(z+modu)%modu;
    return z;
}

//starts here



int32_t main(){
    defInit();
    //Now I will start writing codes and start preparation to get errors
    int n,W;
    cin>>n>>W;
    vector<int> weight(n),value(n);
    for(int i=0;i<n;i++){
        cin>>weight[i]>>value[i];
    }
    int sum=accumulate(value.begin(), value.end(),0);
    vector<int> dp(sum+1,INF);
    dp[0]=0;
    for(int i=0;i<n;i++){
        for(int vi=sum-value[i];vi>=0;vi--){
            dp[vi+value[i]]=min(dp[vi+value[i]],dp[vi]+weight[i]);
        }
    }
    int ans=0;
    for(int i=0;i<=sum;i++){
        if(dp[i]<=W) ans=i;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>

// #define ANS  //for answer
#define CMP  //for compe

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define nv(x) #x,(x)
#define ncv(x) #x,":",(x)
#define ncvc(x) #x,":",(x),","
using ll = long long;
void pPRINT(std::ostream& ost) {}
template <class T, class... U>void pPRINT(std::ostream& ost,const T t,const U... u) {ost<<t<<" ";pPRINT(ost, u...);}
template <class... T>void PRINT(const T... t) {pPRINT(std::cout, t...);}
template <class... T>void PRINTl(const T... t){pPRINT(std::cout,t...);std::cout<<"\n";}
template <class T>void PRINTa(const T* const t,const ll size){REP(i,size)PRINT(t[i]);PRINTl();}
template <class T>void PRINTal(const T* const t,const ll size){REP(i,size)PRINTl(i,":",t[i]);}
#ifdef CMP
using namespace std;
#else
#endif
#ifndef DBG
#define DEBUG(...)
void init(){}
#else
#define DEBUG(...) PRINT("##DEBUG##","file :",__FILE__,", line :",__LINE__,"[");PRINT(__VA_ARGS__);PRINTl("]");
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}
#endif
#ifdef ANS
#else
#endif

void solve();

int main(int argc, char *argv[]) {

  init();
  DEBUG();
  solve();

  return 0;
}

void solve(){

  DEBUG("SOLVE START");

  double t,x;cin>>t>>x;PRINTl(t/x);

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <iomanip>
#include <cmath>
#include <algorithm>

using namespace std;

const double EPS = 1e-8;

int dcmp(double d) {
    if (fabs(d) < EPS) {
        return 0;
    }
    else {
        return d < 0? -1 : 1;
    }
}

struct Vector {
    double x, y;
    Vector(double x = 0, double  y = 0):x(x), y(y) {
    }
};

typedef Vector Point;

Vector operator-(const Vector& a, const Vector& b) {
    return Vector(a.x - b.x, a.y - b.y);
}

double cross(const Vector& a, const Vector& b) {
    return a.x * b.y - a.y * b.x;
}

double dot(const Vector& a, const Vector& b) {
    return a.x * b.x + a.y * b.y;
}

double ccw(const Point& a, const Point& b, const Point& c) {
    return cross(b - a, c - a);
}

int main() {
    int n; 
    cin >> n;
    vector<Point> g(n);
    for (int i = 0; i < n; i++) {
        cin >> g[i].x >> g[i].y;
    }
    
    int q;
    cin >> q;
    
    for (int i = 0; i < q; i++) {
        Vector p;
        cin >> p.x >> p.y;
        
        int count = 0; //0: on segment
        bool onseg = false;
        for (int i = 0; i < n; i++) {
            Vector u = g[i] - p;
            Vector v = g[(i + 1) % n] - p;
            //on segment
            if (dcmp(cross(u, v)) == 0 && dcmp(dot(u, v)) <= 0) {
                onseg = true;
                break;
            }
            if (u.y > v.y) {
                swap(u, v);
            }
            if (dcmp(v.y) >= 0 && dcmp(u.y) < 0 && dcmp(cross(u, v)) > 0) {
                count++;
            }
        }
        if (onseg) {
            cout << 1 << endl;
        }
        else if (count % 2 == 0) {
            cout << 0 << endl;
        }
        else {
            cout << 2 << endl;
        }
    }
   
    return 0;
}

Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
template<typename T>
void print(T x) {
    cout << x << endl;
}
int main(void) {
    int n, k; cin >> n >> k;
    int ans;
    if(n%k == 0) ans = 0;
    else ans = 1;
    cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    string S;
    cin >> S;

    if (S[2] == S[3] && S[4] == S[5]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3568
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e16;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 1005;
constexpr ll nx[4] = {1,0,-1,0};
constexpr ll ny[4] = {0,1,0,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x,y,z;
    cin >> x >> y >> z;
    x -= z;
    PRINT(x/(y+z));
}


Measured memory_bytes: 256
n = gets.to_i

m = 26
ans = ""
e = 0
while(true) do
  if n >= m**e
    n -= m**e
    e += 1
    next
  end
  i = e-1
  while(i>=0) do
    s = n / m**i
    n -= s*(m**i)
    i -= 1
    s = s+97
    ans += s.chr
  end
  break
end

puts("#{ans}")


Measured memory_bytes: 14344
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; i++)

const int MAX_SCORE = 10000;
int n;
int s[100];
int dp[MAX_SCORE+1] = {0};

int main () {
  cin >> n;
  rep(i,n) cin >> s[i];

  dp[0] = 1;
  rep(i,n) for(int j = MAX_SCORE; j >= 0; j--) {
    if(dp[j]) dp[j + s[i]] = 1;
  }

  for(int i = MAX_SCORE; i >= 0; i--) {
    if(dp[i] && i % 10 != 0) {
      cout << i << endl;
      return 0;
    }
  }
  cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 256
/*
  "I knew I shouldn't have
   gotten out of bed today."
   - Squidward Tentacles
*/
#include<iostream>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstring>
#include<climits>
#include<numeric>

#include<deque>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>

#include<fstream>
#include<chrono>
using namespace std;
// using namespace __gnu_pbds;

#define int          long long
#define ld           long double
#define pii          pair<int,int>
#define vi           vector<int>
#define maxheap      priority_queue<int>
#define minheap      priority_queue<int,vi,greater<int>>
#define pb           push_back
#define mp           make_pair
#define ff           first
#define ss           second
#define endl         '\n'
#define rep(i,s,e)   for(int i=s;i<=e;i++)
#define brep(i,s,e)  for(int i=s;i>=e;i--)
#define all(x)       (x).begin(),(x).end()
#define ball(x)      (x).rbegin(),(x).rend()
#define sz(x)        (int)x.size()
#define mem(x,y)     memset(x,y,sizeof(x))
#define pbds         tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define VR46         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int MOD = 1e9+7;
ld EPS = 1e-12;

signed main()
{
    VR46 ofstream out("output.txt");
    // auto start = chrono::high_resolution_clock::now();

    // GANDU TEST CASE BNAKE TEST KRLE
    // OUT OF BOUNDS BHI DEKHLIO CHUTIYE
    int t = 1;
    // cin>>t;
    rep(test,1,t)
    {
        int n;
        cin>>n;
        vi a(n);
        for(auto &i:a) cin>>i;
        int f = 1, cnt = 0;
        rep(i,0,n-1)
        {
            if( a[i]==f ) f++;
            else cnt++;
        }
        if( cnt==n ) cnt = -1;
        cout<<cnt<<endl;

    }

    // auto stop = chrono::high_resolution_clock::now();
    // auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start); 
    // cout<<"Time taken by function: "<<duration.count()<<" milliseconds"<<endl;

    // *( hsh.find_by_order(k) ) kth smallest, from 0
    // hsh.order_of_key(k) num of ele str less than k
    // change less to less_equal for multiset pbds
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <iomanip>
#include <stack>
#include <bitset>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
const ll INF = 1LL << 50;

int solve();

void replace(string& target, const string& from, const string&to) {
	int pos(target.find(from));
	while (pos != string::npos) {
		target.replace(pos, from.length(), to);
		pos = target.find(from);
	}
}

int main(void) {
	while (solve()) {}
	return 0;
}

int solve() {

	string in;
	cin >> in;

	stack< string > q;
	q.push(in);

	vector<string> v = { "A","B","C" };
	set<string> st;

	bool isOK = false;

	if (in.length() < 3) {
		cout << "No" << endl;
		return 0;
	}

	while (q.empty() == false) {

		auto s = q.top();
		st.insert(s);
		q.pop();

		if ( s.length() == 1 ){
			isOK = true;
			break;
		}

		for (string str : v) {

			string s1 = s, s2 = s;

			replace(s1, "ABC", "*");
			replace(s1, "*", str);


			string r;

			for(int i = 0; i < s1.length(); i++)
				if (s1.substr(i, 1) == str) {
					r += "ABC";
				}
				else {
					r += s1[i];
				}


			if ( st.find(s1) == st.end() && r == s) {
				q.push(s1);
				
			}


		}



	}

	if (isOK)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 9280
N, T = list(map(int, input().split()))

t = list(map(int, input().split()))

if N == 1:
    print(T)
    exit()

# t.pop(0)
ans = 0
buff = 0
for i in range(N):
    if i != 0:
        if t[i] - t[i-1] < T:
            ans += t[i] - t[i-1]
        else:
            ans += T

ans += T
print(ans)

Measured memory_bytes: 25196
#include <bits/stdc++.h>

using namespace std;
int w[100100], a[100100];
long long nr,n,m,wa,ac;
char ans[3];
int main()
{
    cin>>n>>m;
    for(int i=1; i<=m; ++i)
    {
        cin>>nr;
        cin.get();
        cin>>ans;
        if(ans[0]=='W')
            w[nr]++;
        else wa+=(w[nr]*(w[nr] && a[nr]==0)), ac+=(a[nr]==0),a[nr]=1;
    }
    cout<<ac<<' '<<wa<<'\n';
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>

int gcd(int x,int y)
{
    int r;
    if(y>x){
        r=x;
        x=y;
        y=r;
    }
    while(y>0){
        r=x%y;
        x=y;
        y=r;
    }
    return x;
}

int main(void)
{
    int n,x,a[100000],i;
    scanf("%d%d",&n,&x);
    for(i=0;i<n;++i){
        scanf("%d",&a[i]);
        a[i]=abs(x-a[i]);
    }
    for(i=1;i<n;++i)a[i]=gcd(a[i-1],a[i]);
    printf("%d",a[i-1]);
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int n;
#define Maxn 1000010
char ch[Maxn];
int a[Maxn],b[Maxn][2];
int main(){
	scanf("%s",ch+1);
	n=strlen(ch+1);
	n++;
	reverse(ch+1,ch+n);
	for(int i=n;i>=1;--i)a[i]=ch[i]-'0';
	b[n][0]=0;b[n][1]=1;
	for(int i=n-1;i>=1;--i){
		b[i][0]=b[i][1]=10000000;
		for(int j=0;j<10;++j){
			int x=j+a[i];
			int fg=0;
			if(x>=10)x-=10,fg=1;
			b[i][0]=min(b[i][0],j+x+b[i+1][fg]);
		}
		for(int j=0;j<10;++j){
			int x=j+1+a[i];
			int fg=0;
			if(x>=10)x-=10,fg=1;
			b[i][1]=min(b[i][1],j+x+b[i+1][fg]);
		}
	} 
	cout<<b[1][0]<<endl;
	return 0;
}

Measured memory_bytes: 12928
#include <bits/stdc++.h>
#define range(i, l, r) for(int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    string s;
    cin >> s;
    replace(s.begin(), s.end(), ',', ' ');
    cout << s << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
/*
*/

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b, a % b);
}

ll lcm(ll a, ll b){
  return a/gcd(a,b) * b;
}
ll func2(ll n){
  ll res = 0;
  while(n%2 == 0){
    n /= 2;
    res++;
  }
  return res;
}

ll zyou(ll a,ll b){//a＾b
  ll res = 1;
  for(int i = 1;i<=b;i++){
    res *= a;
  }
  return res;
}
struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t),weight(w){ }
};

typedef pair<int,int> P;
using Graph = vector<vector<int>>;

ll calc(ll a, ll b, ll p){//aのb乗をpで割った余り
  if(b == 0) return 1;

  else if(b%2 == 0){
    ll d = calc(a,b/2,p);
    return (d*d)%p;
  }
  else if(b%2 == 1){
    return (a * calc(a,b-1,p))%p;
  }
}


bool is_prime(int n){//nが素数であるかどうか判定 iで割り切れると素数でない
    if(n == 1) return false;//1は例外
    for(int i = 2;i*i <= n;i++){
        if(n%i == 0) return false;
    }
    
    return true;
}

bool palin(string S){//回文判定
  int n = S.size();
  bool flag = true;
  if(n%2 == 0){
    for(int i = 0;i<=n/2-1;i++){
      if(S[i] != S[n-i-1]){
        flag = false;
        break;
      }
    }
  }
  else if(n%2 == 1){
    for(int i = 0;i<=n/2-1;i++){
      if(S[i] != S[n-i-1]){
        flag = false;
        break;
      }
    }
  }
  return flag;
}
/*vector<int> d(N+1,-1);

//頂点xとの各点との最短距離を求める
void bfs(int x,Graph &G){
  d[x] = 0;
  queue<<int> que;
  que.push(x);

  // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        int v = que.front(); // キューから先頭頂点を取り出す
        que.pop();

        // v から辿れる頂点をすべて調べる
        for (int nv : G[v]) {
            if (dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない

            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
            dist[nv] = dist[v] + 1;
            que.push(nv);
        }
    }
}*/

int main(){
  int N;
  cin >> N;
  cout << N*N*N << endl;
  
 }

Measured memory_bytes: 256
N,W=map(int,input().split())
dp=[[0 for i in range(W+1)] for j in range(N+1)]
for i in range(1,N+1):
  w,v=map(int,input().split())
  for j in range(1,W+1):
    if w<=j:
      dp[i][j]=max(dp[i-1][j],dp[i-1][j-w]+v)
    else:
      dp[i][j]=dp[i-1][j]
print(dp[N][W])

Measured memory_bytes: 172296
#include <bits/stdc++.h>

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 205;
int N;
vector<int> Edge[MAX_N];

bool used[MAX_N];
int color[MAX_N];
bool loop(int pos, int pre = -1, int depth = 0)
{
  if(color[pos] != -1 && color[pos] != depth%2) {
    return true;
  }
  if(color[pos] != -1 && color[pos] == depth%2) {
    return false;
  }

  color[pos] = depth%2;

  for(int next : Edge[pos]) {
    if(pre == next) continue;
    if(loop(next, pos, depth+1)) return true;
  }

  return false;
}

int dist[MAX_N][MAX_N];

signed main()
{
  cin >> N;
  REP(i,N) {
    string S; cin >> S;
    REP(j,N) {
      if(S[j] == '1') {
        Edge[i].push_back(j);
        dist[i][j] = 1;
      } else {
        dist[i][j] = INF_LL;
      }
    }
    dist[i][i] = 0;
  }

  memset(color, -1, sizeof(color));
  if(loop(0)) {
    cout << -1 << endl;
    return 0;
  }

  REP(k,N) {
    REP(i,N) {
      REP(j,N) {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }

  int ans = 0;
  REP(i,N) {
    REP(j,N) {
      ans = max(ans, dist[i][j] + 1);
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> M(N);
  for(int i = 0;i < N;i++){
    cin >> M.at(i);
  }
  int sum=0;
  for(int i = 0;i < N;i++){
    sum += M.at(i);
  }

  vector<int> out(N-1);
  for(int i = 1;i < N;i++){
      int Sa=0, Sb=0;
    for(int j = 0;j < i;j++){
      Sa += M.at(j);
    }
    Sb = sum-Sa;
    if(Sa >= Sb){
      out.at(i-1) = Sa-Sb;
    }else{
      out.at(i-1) = Sb-Sa;
    }
  }
  int out2 = out.at(0);
  for(int i = 0;i < N-2;i++){
    if(out2 > out.at(i+1)){
      out2 = out.at(i+1);
    }
  }
  cout << out2;
    
}

Measured memory_bytes: 256
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
  let mut s = String::new();
  std::io::stdin().read_line(&mut s).ok();
  s.trim().split_whitespace()
    .map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
  let ab: Vec<u32> = read_vec();

  let ans = if ab[1] % ab[0] == 0 { ab[0] + ab[1] } else { ab[1] - ab[0] };

  println!("{}", ans);
}


Measured memory_bytes: 4352
//#define _GLIBCXX_DEBUG
//#include <atcoder/all>
#include <bits/stdc++.h>


using namespace std;
//using namespace atcoder;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
//const ll MOD=998244353;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);
int dx[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};
int dy[9] = {0, 1, 0, -1, 1, -1, -1, 1, 0};

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

/*複数の整数に対する素因数分解、素数判定*/

//エラトステネスの篩
//前処理でmake_eratos() デフォルトで150msくらい
const int MAX_for_eratos=10000100;
int eratos[MAX_for_eratos];
int prime_number_list[MAX_for_eratos/2];

void make_eratos(){
  rep(i,MAX_for_eratos) eratos[i]=-1;
  //2の倍数だけ先にやっちゃう
  prime_number_list[0]=2;
  for(int j=2;j<MAX_for_eratos;j+=2) eratos[j]=2; 
  int k=1;
  for(int i=3;i<MAX_for_eratos;i+=2){
    if(eratos[i]>-1) continue;
    prime_number_list[k]=i; k++;
    eratos[i]=i;
    if(i>MAX_for_eratos/i+1) continue;
    for(int j=i*i;j<MAX_for_eratos;j+=i) if(eratos[j]==-1) eratos[j]=i;
  }
  
  return;
}
//osa_k法による素因数分解
//普通の因数分解と同様N==1の時に注意
//前処理make_eratos必要
vector<pair<ll,ll>> prime_factorize(ll N){
  vector<pair<ll,ll>> ret={};
  if(N==1) return {};
  for(int i=0;N>MAX_for_eratos-100&&prime_number_list[i]*(ll)prime_number_list[i]<=N;i++){
    if(N%prime_number_list[i]!=0) continue;
    ll a=prime_number_list[i];
    ll ex=0;
    while(N%a==0){
      ex++;
      N/=a;
    }
    ret.push_back({a,ex});
  }
  if(N>MAX_for_eratos-100) {ret.push_back({N,1}); return ret;}
  while(N>1){
    ll ex=0;
    ll a=eratos[N];
    while(N%a==0){
      ex++;
      N/=a;
    }
    ret.push_back({a,ex});
  }
  
  return ret;
}

//素数判定
//前処理make_eratos必要
bool is_prime(ll N) {
  if(N==1) return false;
  if(N<=MAX_for_eratos-100) return N==eratos[N];
  else{
    for(int i=0;prime_number_list[i]*(ll)prime_number_list[i]<=N;i++){
      if(N%prime_number_list[i]==0) return false;
    }
    return true;
  }
}

/*終わり*/

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  // cout << fixed << setprecision(15);

  make_eratos();
  ll N; cin>>N;
  
  ll ans=0;
  for(int i=1;i<=N;i++){
    ll f=1;
    for(auto p:prime_factorize(i)) f*=p.second+1;
    ans+=i*f;
  }
  
  cout<<ans<<'\n';
  
  return 0;
}


Measured memory_bytes: 45288
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n, a, b, c, d = LI()
a, b, c, d = a - 1, b - 1, c - 1, d - 1
s = S()

# 連続した岩がないか
for i in range(a + 1, max(c, d)):
    if s[i] == '#' and s[i + 1] == '#':
        print('No')
        sys.exit()

if c < d:
    print('Yes')
    sys.exit()

else:
    # どこかで a が b を追い越す必要がある
    # b がどこに居ても追い越せるための 3マス連続の空きマスがあるか
    for i in range(b, d + 1):
        if s[i - 1:i + 2] == '...':
            print('Yes')
            sys.exit()
    print('No')


Measured memory_bytes: 9528
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc;

	static final int INF=1<<28;
	static final double EPS=1e-9;

	void run(){
		sc=new Scanner(System.in);
		for(;;){
			if(!sc.hasNext())
				break;
			double a=sc.nextDouble();
			double b=sc.nextDouble();
			double c=sc.nextDouble();
			double d=sc.nextDouble();
			double e=sc.nextDouble();
			double f=sc.nextDouble();
			double det=a*e-b*d;
			double x=(e*c-b*f)/det+0.00005;
			double y=(-d*c+a*f)/det+0.00005;
			println(String.format("%1.3f %1.3f", x, y));
		}
		sc.close();
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		new Main().run();
	}
}

Measured memory_bytes: 12000