akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
    using namespace std;
    #define lc "\n"
    #define fast_io ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(0)
    #define mp make_pair
    #define pb push_back
    #define fi first
    #define se second
    #define int long long
    #define c(a,n) for(size_t i = 0; i < n; i++) cin >> a[i];
    #define ffor(n) for(size_t i = 0; i < n; i++)
    #define asort(a) sort(a.begin(), a.end())
    #define rsort(a) sort(a.begin(), a.end(), greater<int>())
    
    typedef vector<int> vi;
    typedef vector<float> vf;
    typedef vector<vi> vii;
    typedef vector<string> vs;
    typedef vector<long long> vll;
    typedef map<string,int> msi;
    typedef map<int,int> mii;
    typedef unordered_map<string,int> umsi;
    

    int32_t main()
    {
        fast_io;
        int n, w;
        cin >> n >> w;
        vii a(n+1, vi(2));
        int x, y;
        for(int i = 1; i <= n; i++)
        {   
            cin >> x >> y;
            a[i][0] = x;
            a[i][1] = y;
        }
        sort(a.begin(), a.end());
        vii dp(n+1, vi(w+1));
        for(int i = 1; i <= n; i++)
        {
            for(int j = 1; j <= w; j++)
            {
                if(j < a[i][0])
                    dp[i][j] = dp[i-1][j];
                else if(j == a[i][0])
                {
                    dp[i][j] = a[i][1];
                }
                else
                {
                    dp[i][j] = max(dp[i-1][j], dp[i-1][j-a[i][0]] + a[i][1]);    
                }
            }
        }
        cout << dp[n][w];
        return 0;
    }

Measured memory_bytes: 83072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pll = pair<ll, ll>;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, m, n) for(ll i = m; i > n; i--)
#define Rep(i, m, n) for(ll i = m; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define lmax(x, y) max<ll>(x, y)
#define lmin(x, y) min<ll>(x, y)
#define tmax(x, y, z) lmax((x), lmax((y), (z)))
#define tmin(x, y, z) lmin((x), lmin((y), (z)))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define ZERO(a) memset(a, 0, sizeof(a))
const ll INF = 1LL << 60;
const ll MM = 1000000000; const ll MOD = MM + 7; const ll MMM=9223372036854775807;//2^63 -1
#define ADD(a,b) a = (a + ll(b)) % MOD
#define MUL(a,b) a = (a * ll(b)) % MOD
ll GCD(ll x, ll y){ if(y == 0) return x; else return GCD(y, x % y);}
ll LCM(ll x, ll y){ return x / GCD(x, y) * y;}
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;}
template<typename A, size_t N, typename T> void FILL(A (&array)[N], const T &val){ fill( (T*)array, (T*)(array+N), val );}
// struct edge{ ll from, to, cost; };
// struct edge{ ll to, cost; };
// using Graph = vector<vector<ll>>;  // 重み無し
// using Graph = vector<edge>;  // 辺
// using Graph = vector<vector<edge>>;  // 重み付き
ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
ll ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//cout << fixed << setprecision(10);
// priority_queue<ll, vector<ll>, greater<ll>> pq;


int main(){
    ll n, cnt = 0, ans = 0; cin >> n;
    rep(i, n){
        ll p; cin >> p; p--;
        if(p == i) cnt++;
        else ans += (cnt+1)/2, cnt = 0;
    }
    ans += (cnt+1)/2;
    cout << ans << endl;
}


Measured memory_bytes: 3648
import java.util.*;
import java.io.*; 

public class Main {
	
	public static void main(String... string) {
		Scanner sc = new Scanner(System.in); 
		long n = sc.nextLong();
		long blue = sc.nextLong();
		long red = sc.nextLong();
		long ans = n/(red+blue) * blue; 
		long y = n%(red+blue); 
	    System.out.println(ans + Math.min(blue, y)); 
	}
}

Measured memory_bytes: 23508
import heapq


h, w = map(int, input().split())
meiro = []
for i in range(h):
    line = input()
    meiro.append(line)


def dfs(y, x):
    dist = [[-1]*w for _ in range(h)]
    if meiro[y][x] == '#':
        return 0
    dist[y][x] = 0

    pattern = [[-1, 0], [1, 0], [0, -1], [0, 1]]
    todo = []
    for dy, dx in pattern:
        ny, nx = y + dy, x + dx
        if 0 <= ny <= h-1 and 0 <= nx <= w-1:
            if meiro[ny][nx] == '.':
                heapq.heappush(todo, [1, ny, nx])

    while todo:
        d, y, x = heapq.heappop(todo)
        if meiro[y][x] == '#':
            continue
        if dist[y][x] != -1:
                continue

        dist[y][x] = d
        for dy, dx in pattern:
            ny, nx = y + dy, x + dx
            if 0 <= ny <= h - 1 and 0 <= nx <= w - 1:
                if dist[ny][nx] == -1 and meiro[ny][nx] == '.':
                    heapq.heappush(todo, [d+1, ny, nx])

    res = 0
    for line in dist:
        res = max(max(line), res)

    return res


ans = []
for y in range(h):
    for x in range(w):
        ans.append(dfs(y, x))

print(max(ans))


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

#define F first
#define S second
#define pii pair<int, int>
#define pb push_back

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 18;

pii dp[(1 << N)];

inline pii merge(pii A, pii B)
{
	if(A.F >= B.F) {
		if(A.S >= B.F) return A;
		else return make_pair(A.F, B.F);
	}else
	{
		if(B.S >= A.F) return B;
		else return make_pair(B.F, A.F);
	}
	return {B.F, A.F};
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin >> n;
	
	for (int i=0; i<(1 << n); i++)
	{
		int x; cin >> x;
		dp[i] = {x, -1};
	}

	for (int i=0; i<n; i++){
		for (int mask=(((1 << n))-1); mask>=0; mask--)
			if(mask & (1 << i))
				dp[mask] = merge(dp[mask], dp[mask - (1 << i)]);

	}

	int ans = 0;
	for (int mask=1; mask<(1 << n); mask++)
	{
		int m = 0;
		for (int i=0; i<n; i++)
		{
			if(mask & (1 << i))
			{
				m += (1 << i) - 1;
				ans = max(ans, dp[m].F + dp[m].S);
				m ++;
			}
		}
		ans = max(ans, dp[mask].F + dp[mask].S);
		cout << ans << '\n';
	}

}

Measured memory_bytes: 5120
n = int(input())
k = int(input())

a = 1
#n回分のループを回す
for i in range(n):
  #整数に2倍した数と整数にkを足した数を比較して2倍した方が小さい場合、操作Aを行う
  if 2*a < a + k:
    a = a * 2
  #整数を2倍するよりも整数にkを足した数が小さい場合、操作Bを行う
  else:
    a = a + k
#最小値になる
print(a)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+10;
int main(){
    ios::sync_with_stdio(false);
    int n,x,t;
    cin>>n>>x>>t;
    cout<<(n/x*t+((n%x==0)?0:t))<<endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define int long long
#define double long double
const int INF = (int)1e18 + 18;
const int maxn = (int) 1e6 + 6; 
using namespace std;

int n, l;
 
signed main() {

	cin >> n >> l;

	int ans = 0, eat = INF;
  
  for(int i = 1; i <= n; i++){
  	ans += (i - 1 + l);
    //cout << ans << endl;
    if(abs(eat) > abs(i - 1 + l)){
      eat = i - 1 + l;
    }
  }
	cout << ans - eat << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<set>
#include<map>
#include<iterator>
#include<algorithm>
#include<functional>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
int main()
{
	int n;
	int arr[50];
	cin >> n;
	int sum = 0;
	for (int i = 0; i < n; i++)
	{
		cin>>arr[i];
		sum += arr[i];
	}
	sort(arr, arr + n);
	sum -= (arr[n - 1] / 2);
	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma GCC optimize("Ofast")
//*********************************************DO IT NOW****************************************************************
#include<bits/stdc++.h> 
#include<random>
#define int long long   
#define pp pair<int,int> 
#define ss second 
#define ff first 
#define pb push_back
#define mod 1000000007
#define pi 3.14159265359
#define mk(arr,n,type)  type *arr=new type[n];
#define sl s1.length();
#define yes cout<< "YES"<<endl
#define no  cout<< "NO"<<endl
#define all(v) (v).begin(),(v).end()
#define s(v)   sort(v,v+n)
#define  mt mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define read(a,n) for(int i=0;i<n;i++)cin>>a[i]
#define print(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" "
#define for1(i,a,n)  for(int i=0;i<n;i++)
#define rep(i, c) for(int i = 0; i < (int)c; i++)
#define set(x) cout<<fixed<<setprecision(x);
using namespace std;
//**********************************************DO IT NO****************************************************************
void fastio()
{  
  #ifndef ONLINE_JUDGE
  freopen("INPUT.txt","r",stdin);
  freopen("OUTPUT.txt","w",stdout); 
  #endif
  ios_base :: sync_with_stdio(false); 
  cin.tie(NULL) ; 
  cout.tie(NULL);
}
int dp[101][1001],ans1=1e9,dp1[1000001];
int num[10];
int a[1000000];
signed main()
{   
    fastio();
    int t=1;
    //cin>>t;
    while(t--)
    {  
       
       int n;
       cin>>n;
       if(n<=12)
       {
           cout<<n;
           continue;
       }
      for(int i=n/2;i<n;i++)
      {
           int x=i*1.08;
           if(x==n)
           {
               cout<<i;
               return 0;
               break;
           }
          // cout<<x<<"\n";
       }
       cout<<":(";
       
    }
}
// 🍪 🍪 🍪


Measured memory_bytes: 3620
#include <stdio.h>
static int c = 0;
void s(int *a,int *b){
  int i=*a;*a=*b;*b=i;c++;
}
void sS(int *A, int a){
  int i,j;
  for(i=0;i<a;i++){
    int m=i;
    for(j=i;j<a;j++)
      if(A[j]<A[m])
        m=j;
    if(A[i]!=A[m])
      s(&A[i],&A[m]);
  }
}
int main(void){
  int N,n,A[101];
  scanf("%d\n",&N);
  for(n=0;n<N;n++){
    int i;
    scanf("%d", &i); A[n] = i;
  }
  sS(A,N);
  for(n=0;n<N-1;n++)
    printf("%d ",A[n]);
  printf("%d\n",A[N-1]);
  printf("%d\n",c);
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	vector<pair<int, int>> p;
	for (int i = 0; i < n; ++ i) {
		int x;
		scanf("%d", &x);
		p.push_back(make_pair(x, 0));
	}
	for (int i = 0; i < m; ++ i) {
		int x;
		scanf("%d", &x);
		p.push_back(make_pair(x, 1));
	}
	sort(p.begin(), p.end());
	long long cnt = 0, ans = 0;
	int cnt1 = 0, cnt2 = 0;
	for (int i = 0; i < n + m; ++ i) {
		if (p[i].second == 0) {
			int cho = m + 1 - cnt2;
			if (cho) {
				ans += 1LL * cho * p[i].first;
				//printf("%d * %d\n", cho, p[i].first);
				cnt1 ++;
			}
		}
		else {
			int cho = n + 1 - cnt1;
			if (cho) {
				ans += 1LL * cho * p[i].first;
				//printf("%d * %d\n", cho, p[i].first);
				cnt2 ++;
			}
		}
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 2420
MOD = 10**9 + 7
N, K = map(int, input().split())

def combination(n, k, MOD):
  #nCk % MOD を出力する関数(0<=k<=nは暗に仮定)
  frac = [1]*(n+1)
  for i in range(1, n+1):
    frac[i] = (frac[i-1]*i)%MOD
  return (frac[n]*pow(frac[k], MOD-2, MOD)*pow(frac[n-k], MOD-2, MOD))%MOD

for i in range(1, K+1):
  if(N-K-i+1<0):
    print(0)
  else:
    print((combination(K-1, i-1, MOD)*combination(N-K+1, i, MOD))%MOD)

Measured memory_bytes: 74556
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int kai(int x) {
	if (x == 1)return 1;
	return kai(x - 1)*x%mod;
}

int mod_pow(int x, int y, int moder) {
	int res = 1;
	while (y > 0) {
		if (y & 1)res = res * x%moder;
		x = x * x%moder;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	if (x == y)return 1;
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}

int n;
int a[114514];
vector<P> ans;
int ans2;
bool bl;

signed main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
		if (a[i] < 0) {
			bl = true;
		}
	}
	if (!bl) {
		sort(a, a + n);
		int ta = a[0];
		for (int i = 1; i < n - 1; i++) {
			ans.push_back({ ta,a[i] });
			ans2 += a[i];
			ta -= a[i];
		}
		ans.push_back({ a[n - 1],ta });
		ans2 += a[n - 1];
		ans2 -= a[0];
	}
	else {
		sort(a, a + n);
		int x = a[0], y = a[n - 1];
		for (int i = 1; i < n - 1; i++) {
			if (a[i] < 0) {
				ans.push_back({ y,a[i] });
				y += abs(a[i]);
			}
			else {
				ans.push_back({ x,a[i] });
				x -= a[i];
			}
		}
		ans2 = y - x;
		ans.push_back({ y,x });
	}
	cout << ans2 << endl;
	rep(i, ans.size()) {
		cout << ans[i].first << " " << ans[i].second << endl;
	}
}

Measured memory_bytes: 4336
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn=200010;
const int mod=1000000007;
vector<int> g[maxn];
int p[maxn],inv2,son[maxn],f[maxn][3],ff[maxn][3],lv[maxn],dep[maxn];
deque<int> dp[maxn][2];
inline int qpow(int x,int y){
	int ret=1;
	while(y){
		if(y&1) ret=(ll)ret*x%mod;
		x=(ll)x*x%mod;
		y>>=1;
	}
	return ret;
}
inline int get_inv(int x){
	return qpow(x,mod-2);
}
void dfs(int u){
	son[u]=-1;
	lv[dep[u]]++;
	for(int i=0;i<(int)g[u].size();i++){
		int v=g[u][i];
		dep[v]=dep[u]+1;
		dfs(v);
		if(son[u]==-1 || dp[v][0].size()>dp[son[u]][0].size())
			son[u]=v;
	}
	if(son[u]!=-1) dp[u][0].swap(dp[son[u]][0]),dp[u][1].swap(dp[son[u]][1]);
	dp[u][1].push_front(1);
	dp[u][0].push_front(1);
	int maxd=-1;
	for(int i=0;i<(int)g[u].size();i++){
		int v=g[u][i];
		if(v==son[u]) continue;
		maxd=max(maxd,(int)dp[v][0].size());
	}
	if(maxd==-1) return;
	for(int d=1;d<=maxd;d++){
		f[d][0]=dp[u][0][d];
		f[d][1]=dp[u][1][d];
		f[d][2]=0;
	}
	for(int i=0;i<(int)g[u].size();i++){
		int v=g[u][i];
		if(v==son[u]) continue;
		for(int d=1;d<=min(maxd,(int)dp[v][0].size());d++){
			ff[d][0]=ff[d][1]=ff[d][2]=0;
			for(int s=0;s<3;s++){
				for(int ss=0;ss<2;ss++)
					ff[d][min(s+ss,2)]=(ff[d][min(s+ss,2)]+(ll)f[d][s]*dp[v][ss][d-1])%mod;
			}
			f[d][0]=ff[d][0],f[d][1]=ff[d][1],f[d][2]=ff[d][2];
		}
	}
	for(int d=1;d<=maxd;d++)
		dp[u][0][d]=(f[d][0]+f[d][2])%mod,dp[u][1][d]=f[d][1];
}
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",p+i);
		g[p[i]].push_back(i);
	}
	inv2=get_inv(2);
	dfs(0);
	int ans=0;
	for(int i=0;i<(int)dp[0][1].size();i++){
		ans=(ans+(ll)dp[0][1][i]*qpow(2,n+1-lv[i]))%mod;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 488568
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,b,a) for(int i=b;i>=a;i--)
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Forenska(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-x))
#define GREATER(x) x,vector<x>,greater<x>
#define randIn(L,R) (((LL)rand()*rand())%(R-L)+L)
#define __lcm(a,b) ((a)/__gcd(a,b)*(b))
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pLL;
typedef vector<int> vec;
typedef vector<LL> vecL;
typedef vector<pii> vecP;
typedef vector<pLL> vecPL;
typedef vector<string> vecS;
typedef vector<vec> mat;
typedef complex<double> point;
const long double PI=3.14159265358979323846264338327950288419716939937510582097;
const LL INFLL=0x3f3f3f3f3f3f3f3f;
const int INF=0x3f3f3f3f;
const long double EPS=1e-10;
int read()
{
    int x=0;
    char ch=' ';
    bool flag=false;
    while(ch<'0' || ch>'9')
    {
        if(ch=='-')flag=true;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
    {
        x=(x<<3)+(x<<1)+ch-'0';
        ch=getchar();
    }
    return flag?-x:x;
}
const int MAX_N=200005;
int x[MAX_N];
int n,m;
vecP g[MAX_N];
int dp[MAX_N];
int in[MAX_N];
int main()
{
	cin>>n>>m;
	rep(i,0,m)
	{
		int L,R,D;
		cin>>L>>R>>D;
		g[L].pb(mp(D,R));
		in[R]++;
	}
	memset(dp,-1,sizeof(dp));
	queue <int> q;
	vec topo;
	For(i,1,n)
	{
		if(!in[i])
		{
			topo.pb(i);
			q.push(i);
			dp[i]=0;
		}
	}
	while(!q.empty())
	{
		int v=q.front();
		q.pop();
		rep(i,0,g[v].size())
		{
			int u=g[v][i].se;
			int w=g[v][i].fi;
			in[u]--;
			if(!in[u])
			{
				q.push(u);
				topo.pb(u);
			}
			if(dp[u]!=-1 && dp[u]!=dp[v]+w)
			{
				puts("No");
				return 0;
			}
			else dp[u]=dp[v]+w;
		}
	}
	if(topo.size()==n)puts("Yes");
	else puts("No");
	return 0;
}



Measured memory_bytes: 10140
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <stack>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#include <functional>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi   vector<int> 
#define   co(x)  cout << x << '\n' 
#define   dbg(x)  cerr << #x << " = " << x << '\n' 
#define   bitcount(x)  (int)__builtin_popcount(x) 
#define   sz(x)  (int)x.size()
#define   all(a) a.begin(),a.end() 
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    int  n, k ; 
    cin >> n >> k ; 
    vi  a(n), v ; 
    for (int &i: a) cin >> i ; 
    for (int i=0;i<n;i++){
        int sum = 0 ; 
        for (int j=i;j<n;j++){
            sum += a[j] ; 
            v.emplace_back(sum) ; 
        }
    }

    int ans = 0 ; 
    for (int i=40;i>=0;i--){ 
        int c = 0 ; 
        vi cur ; 
        for (auto &it: v){ 
            int x = it;
            if (x&(1LL<<i)) {
                c++ ; 
                cur.pb(x) ; 
            }
        }
        if (c>=k){ 
            ans += (1LL<<i) ; 
            v = cur ; 
        }
    }
    co(ans) ; 
}

signed main()
{
    ios_base::sync_with_stdio(false) ; 
    cin.tie(0),cout.tie(0) ; 
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n;
int a[125252];
int k;

int main(){
  scanf("%d%d",&n,&k);
  REP(i,n)scanf("%d",a+i);
  int g = 0;
  REP(i,n)g=__gcd(g,a[i]);
  REP(i,n){
    if(a[i]<k)continue;
    int s = a[i]-k;
    if(s%g==0){
      puts("POSSIBLE");
      return 0;
    }
  }
  puts("IMPOSSIBLE");
  return 0;
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define lli long long int
#define rep(i,n) for(int i=0; i<n; i++)
#define loop(i, j, n) for(int i=j; i<n; i++)
using namespace std;
// }}} End Header

int main()
{
	int n, m;
	int a;
	cin >> n >> m;
	int sum=0;
	rep(i,m){
		cin >> a;
		sum+=a;
	}
	if(n < sum) cout << -1 << endl;
	else cout << n-sum << endl;
	return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <sstream>
#include <stdio.h>
#include<math.h>
using namespace std;

int main(){

    double N,K;

    cin >> N >> K;

    double kaisuu = -1;
    double goukei = 0;


    for(int i=1;i<=N;i++){
        int now = i;
        kaisuu = 0;
        while(1){
            if(now>=K){
                break;
            }
            now = now * 2;
            kaisuu++;
        }
        double temp;
        temp = 1 / N * pow(0.5,kaisuu);
        goukei += temp;
    }

    printf("%.10f\n",goukei);

    return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var N, K int
	fmt.Scan(&N, &K)
	var ans float64
	for i := 1; i <= N; i++ {
		v := i
		r := 1.0
		for v < K {
			v *= 2
			r *= 0.5
		}
		ans += (1.0 / float64(N)) * r
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
int main(){
  ll n;cin>>n;
  ll a[n],b[n];
  vector<pll> c(n);
  for(ll i=0;i<n;i++){
    cin>>a[i]>>b[i];
    c[i]=make_pair(a[i]+b[i],i);
  }
  sort(c.begin(),c.end(),greater<pll>());
  ll ans=0;
  for(ll i=0;i<n;i++){
    ll num=c[i].second;
    if(i%2==0)ans+=a[num];
    else ans-=b[num];
  }
  cout<<ans<<endl;
}
  


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

int main() {
  string N;
  cin >> N;
  
  
  if ( N.at(0) == '7' ){
    cout << "Yes" << endl;
  }
  
  else if ( N.at(1) == '7' ){
    cout << "Yes" << endl;
  }
  
  else if ( N.at(2) == '7' ){
    cout << "Yes" << endl;
  }
  
  else {
    cout << "No" << endl;
  }
  
  
}

Measured memory_bytes: 3564
import sys
sys.setrecursionlimit(100000000)


def main():
    solve()


def solve():
    for data in get_dataset():
        print search(data)


def search(data):
    count = 0
    H = len(data)
    W = len(data[0])
    for i in xrange(H):
        for j in xrange(W):
            if data[i][j] == '.':
                continue
            _search(i, j, H, W, data[i][j], data)
            count += 1
    return count


def _search(i, j, H, W, cell, data):
    data[i][j] = '.'
    for a in xrange(i-1, i+2):
        if not -1 < a < H:
            continue
        for b in xrange(j-1, j+2):
            if not -1 < b < W:
                continue

            if a != i and b != j:
                continue

            if data[a][b] == '.':
                continue

            if cell == data[a][b]:
                _search(a, b, H, W, cell, data)
    return


def get_dataset():
    dataset = []
    while True:
        line = raw_input().rstrip().split()
        H = int(line[0])
        if H == 0:
            break

        data = []
        for i in xrange(H):
            data.append(list(raw_input().rstrip()))
        dataset.append(data)
    return dataset


if __name__ == '__main__':
    main()

Measured memory_bytes: 15740
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';

int main() {
    ll n,x,ans=0;
    cin>>n>>x;
    vl a(n+1);
    rep(i,n)cin >> a[i];
    rep(i,n-1){
        if(a[i]+a[i+1]>x){
            ll ooi=a[i]+a[i+1]-x;
            ans+=ooi;
            if(ooi<=a[i+1])a[i+1]-=ooi;
            else{
                a[i]-=ooi-a[i+1];
                a[i+1]=0;
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1152
#include<stdio.h>

int main(){
	int i;
  int count=0;
  int n;
  char str[256];
  
  if(scanf("%d%s",&n,str)!=2) return -1;
  for(i=0;i<n;i++){
  	if(str[i]=='A'){
    	if(str[i+1]=='B'){
        	if(str[i+2]=='C'){
            	count++;
              i+=1;
            }
          i+=1;
        }
    }
  }
  printf("%d\n",count);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int main(){
  int N, K, r = 0;
  cin >> N >> K;
  vector<int>c(N, 0);
  for(int i = 0; i < N; i++){
    int a;
    cin >> a;
    c[a - 1]++;
  }
  priority_queue<int, vector<int>, greater<int> >Q;
  for(int i = 0; i < N; i++){
    if(c[i] != 0)Q.push(c[i]);
  }
  int qs = Q.size();
  for(int i = 0; i < qs - K; i++){
    r = r + Q.top();
    Q.pop();
  }
  cout << r;
  return 0;
}

Measured memory_bytes: 2168
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
import sys
import math
def LI(): return [int(x) for x in sys.stdin.readline().split()]

dd = [(1,0),(-1,0),(0,1),(0,-1)]

def solve():
    h,w,k = LI()
    y,x,s,t = LI()
    y -= 1
    x -= 1
    s -= 1
    t -= 1
    c = [input() for i in range(h)]
    q = deque([(y,x)])
    d = [[float("inf")]*w for i in range(h)]
    d[y][x] = 0
    while q:
      y,x = q.popleft()
      if (y,x) == (s,t):
          print(d[s][t])
          return
      nd = d[y][x] + 1
      for dy,dx in dd:
          ny,nx = y,x
          for _ in range(k):
              ny += dy
              nx += dx
              if 0 <= ny < h and 0 <= nx < w and c[ny][nx] != "@" and nd <= d[ny][nx]:
                  if nd < d[ny][nx]:
                      d[ny][nx] = nd
                      q.append((ny,nx))
                  continue
              break
    print(-1)
    return

#Solve
if __name__ == "__main__":
    solve()


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

int main()
{
    int a,b,c,d;

    while(scanf("%d %d %d %d",&a,&b,&c,&d)!=EOF)
    {
        int ans=min(a,b)+min(c,d);

        printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
	ios::sync_with_stdio(false); cin.tie(0);
	int h, w;
	cin >> h >> w;
	vector<string> g(h);
	for (int i = 0; i < h; i++) {
		cin >> g[i];
	}
	vector<vector<int>> vis(h, vector<int>(w));
	queue<pair<int, int>> que;
	que.push(make_pair(0, 0));
	vis[0][0] = 1;
	int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
	while (que.size()) {
		pair<int, int> cur = que.front();
		que.pop();
		bool flag = false;
		for (int i = 0; i < 4; i++) {
			int x = cur.first + dx[i];
			int y = cur.second + dy[i];
			if (x < 0 || x >= h || y < 0 || y >= w || g[x][y] == '.' || vis[x][y]) continue;
			if (cur.first - x == 1 || cur.second - y == 1) {
				cout << "Impossible" << endl;
				return 0;
			} else {
				if (flag) {
					cout << "Impossible" << endl;
					return 0;
				} else {
					vis[x][y] = true;
					que.push(make_pair(x, y));
					flag = true;
				}
			}
		}
	}
	cout << "Possible" << endl;
	return 0;	
}


Measured memory_bytes: 256
h,w,d = map(int, input().split())

al = [list(map(int, input().split())) for _ in range(h)]
v_to_xy = [(-1,-1)]*(h*w+1)
v_to_xy[0] = v_to_xy[d]
for i in range(h):
    for j in range(w):
        v_to_xy[al[i][j]] = (i,j)

dd = []
for i in range(d):
    csum = 0
    cumsum = []
    prev = v_to_xy[i]
    for j in range(i,h*w+1,d):
        if j == 0:
            cumsum.append(0)
            continue
        x,y = v_to_xy[j]
        diff = abs(prev[0]-x) + abs(prev[1]-y)
        csum += diff
        cumsum.append(csum)
        prev = (x,y)
    dd.append(cumsum)
    
# print(dd)

ansl = []
for _ in range(int(input())):
    l,r = map(int, input().split())
    drem = r%d
    ri = (r-drem)//d
    li = (l-drem)//d
    # print(drem,li,ri)
    ans = dd[drem][ri] - dd[drem][li]
    ansl.append(ans)

for ans in ansl: print(ans)

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

#define rep(i, n) for (int i=0; i<(n); ++i)
using ll = long long;
using P = pair<int, int>;

int main() {
  int n, q;
  cin >> n;
  vector<int> s(n);
  rep(i,n) cin >> s[i];
  cin >> q;
  vector<int> t(q);
  rep(i,q) cin >> t[i];

  int ans = 0;
  rep(i,q) {
    rep(j,n) {
      if (t[i] == s[j]) {
	ans++;
	break;
      }
    }
  }

  cout << ans << endl;
  return 0;
}



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

int main(){
    int N;
    cin >> N;

    int h[N];
    int dp[N];
    for (int i=0; i<N;i++) {
        cin >> h[i];
        dp[i]=INT_MAX;
    }

    dp[0]=0;
    for (int i=1;i<N;i++) {
        if (dp[i] > dp[i-1] + abs(h[i]-h[i-1]) ) {
           dp[i] = dp[i-1]+abs(h[i]-h[i-1]) ;
        }
        if (i > 1) {
            if (dp[i] > dp[i-2] + abs(h[i]-h[i-2])) {
                dp[i] = dp[i-2] + abs(h[i]-h[i-2]);
            }
        }
    }

    cout << dp[N-1] << endl;
} 

Measured memory_bytes: 1024
S = input()
L = int(S[:2])
R = int(S[2:])

if 1 <= L <= 12 and 1 <= R <= 12:
	print("AMBIGUOUS")
elif 1 <= L <= 12:
	print("MMYY")
elif 1 <= R <= 12:
	print("YYMM")
else:
	print("NA")


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

int main(void) {
	int i, flag = 0;
	char ch[100];

	scanf("%s", ch);
	for (i = 0; i<100; i++) {
		if(ch[i]=='C'){
			flag=1;
		}else if(ch[i]=='F'){
			if(flag == 1){
				flag=2;
			}
		}
	}
	if(flag == 2){
		printf("Yes");
	}else{
		printf("No");
	}
	return 0;
}


Measured memory_bytes: 128
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<fstream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

const int N_MAX = 100010;
ll dp[N_MAX];

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

    // input
    ll N;
    cin >> N;

    vector<ll> A(N);
    FOR(i, 0, N){
        cin >> A.at(i);
    }

    dp[0] = 0;
    dp[1] = abs(A[1]-A[0]);
    FOR(i, 2, N){
        ll a = dp[i-1] + abs(A[i]-A[i-1]);
        ll b = dp[i-2] + abs(A[i]-A[i-2]);
        dp[i] = min(a, b);
    }

    p(dp[N-1]);
    
    return 0;
}

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

int main(){
	int loop;
	const int UP = 0;
	const int DOWN = 1;
	const int LEFT = 2;
	const int RIGHT = 3;
	int shot[4][2] = {{0,-1},{0,1},{-1,0},{1,0}};
	cin >> loop;
	for(int n=0;n<loop;n++){
		char stage[22][22];

		for(int i=0;i<22;i++){
			for(int j=0;j<22;j++){
				stage[i][j]='#';
			}
		}

		int h,w;
		int commandlength;
		string command;
		int playerX,playerY,playerDir;
		
		cin >> h >> w;
		for(int i=1;i<=h;i++){
			string buf;
			cin >> buf;
			for(int j=1;j<=w;j++){
				stage[i][j] = buf[j-1];
				if(buf[j-1] == '^' || buf[j-1] == 'v' || buf[j-1] == '<' || buf[j-1] == '>'){
					playerX = j;
					playerY = i;
					switch(buf[j-1]){
					case '^':
						playerDir = UP;
						break;
					case 'v':
						playerDir = DOWN;
						break;
					case '<':
						playerDir = LEFT;
						break;
					case '>':
						playerDir = RIGHT;
						break;
					}
				}
			}
		}
		cin >> commandlength;
		cin >> command;

		for(int i=0;i<commandlength;i++){
			switch(command[i]){
			case 'U':
				if(stage[playerY-1][playerX] == '.'){
					stage[playerY][playerX] = '.';
					playerY--;
				}
				stage[playerY][playerX] = '^';
				playerDir = UP;
				break;
			case 'D':
				if(stage[playerY+1][playerX] == '.'){
					stage[playerY][playerX] = '.';
					playerY++;
				}
				stage[playerY][playerX] = 'v';
				playerDir = DOWN;
				break;
			case 'L':
				if(stage[playerY][playerX-1] == '.'){
					stage[playerY][playerX] = '.';
					playerX--;
				}
				stage[playerY][playerX] = '<';
				playerDir = LEFT;
				break;
			case 'R':
				if(stage[playerY][playerX+1] == '.'){
					stage[playerY][playerX] = '.';
					playerX++;
				}
				stage[playerY][playerX] = '>';
				playerDir = RIGHT;
				break;
			case 'S':
				for(int j=0;j<20;j++){
					if(stage[playerY+shot[playerDir][1]*j][playerX+shot[playerDir][0]*j] == '*'){
						stage[playerY+shot[playerDir][1]*j][playerX+shot[playerDir][0]*j] = '.';
						break;
					}
					if(stage[playerY+shot[playerDir][1]*j][playerX+shot[playerDir][0]*j] == '#'){
						break;
					}
				}
				break;
			}
		}

		for(int y=1;y<=h;y++){
			for(int x=1;x<=w;x++){
				cout<<stage[y][x];
			}
			cout<<endl;
		}
		if(n+1 != loop){
			cout << endl;
		}
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdlib>

# define REP(i,n) for(int i=0; i<n;i++)

using namespace std;

int main(){
	int n;
	long long int a[200005];
	cin >> n;
	REP(i,n){
		cin >> a[i];
	}

	long long int x, y, difference, min;
	x = a[0];
	y = 0;
	for(int i=1; i<n; i++){
		y += a[i];
	}
	min = abs(x-y);
	for(int i=1; i<n-1; i++){
		x +=a[i];
		y -=a[i];
		difference = abs(x-y);
		if(difference<min){
			min = difference;
//			cout << x << " " << y << endl;
		}
	}
	cout << min << endl;

}


Measured memory_bytes: 1792
def divisor(n):
    ass = []
    for i in range(1,int(n**0.5)+1):
        if n%i == 0:
            ass.append(i)
            if i**2 == n:
                continue
            ass.append(n//i)
    return ass


N = int(input())

count = 0
for i in range(1, N+1):
  if i % 2 != 0 and len(divisor(i)) == 8:
    count += 1

print(count)



Measured memory_bytes: 9408
#include <iostream>
#include <vector>
#include <cstring>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <stack>
using namespace std;
#define ll long long
#define pb push_back
#define pp pair<long long,long long>
#define ppp pair<long long, pair<long long,long long> >
#define f first	
#define s second
#define pd pair<double,long long>
ll arr[2][100100];
multiset<pp> st[2];
void solveTestCase() {
	ll n,i,j,k,l,x,m;
	cin>>n;
	for (i=1;i<=n;i++) {
		cin>>j; 
		arr[i%2][j]++;
	}
	ll ans=0;
	for (i=0;i<2;i++) {
		for (j=1;j<=100000;j++) {
			if (arr[i][j])
				st[i].insert(pp(-arr[i][j],j));
		}
	}
	pp op1 = *(st[0].begin()),op2=pp(0,-1),op3=*(st[1].begin()),op4=pp(0,-1);
	st[0].erase(st[0].begin());
	st[1].erase(st[1].begin());
	if (!st[0].empty())
		op2=*(st[0].begin());
	if (!st[1].empty())
		op4=*(st[1].begin());
	op1.f*=-1,op2.f*=-1,op3.f*=-1,op4.f*=-1;
	if (op1.s==op3.s)
		ans=min((n/2-op1.f)+(n/2-op4.f),(n/2-op2.f)+(n/2-op3.f));
	else
		ans=(n/2-op1.f)+(n/2-op3.f);
	cout<<ans<<'\n';
}
int main() {
	ll t,n,i,j,k,l,m;
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll p;
	t=1;
	//cin>>t;
	for (ll T=1;T<=t;T++) {
		solveTestCase();
	}
	return 0;
}

Measured memory_bytes: 11336
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
int main() {
   int ans=1,mini,n;
   int arr[200009];
   cin >>n;
   for(int i=0;i<n;i++)cin >>arr[i];
   mini = arr[0];
   for(int i=1;i<n;i++){
       if(mini >= arr[i]){
           ans++;
           mini = arr[i];
       }
   }
   cout <<ans<<"\n";
   return 0;
}


Measured memory_bytes: 1024
N, x = map(int, input().split())
A = list(map(int, input().split()))
ans = float("inf")
Mi = [float("inf")] * N
for i in range(N):
    for j in range(N):
        Mi[j] = min(Mi[j], A[j-i])
    ans = min(ans, x*i + sum(Mi))
print(ans)


Measured memory_bytes: 3188
#include<iostream>

#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;

int main() {
	int n, m, l;
	cin >> n >> m >> l;
	int i, j, k;
	long a[n][m], b[m][l], c;
	
	// input
	rep(i,n) {
		rep(j,m) {
			cin >> a[i][j];
		}
	}
	rep(i,m) {
		rep(j,l) {
			cin >> b[i][j];
		}
	}

	// process
	rep(i,n) {
		rep(j,l) {
			c = 0;
			rep(k,m) {
				c += a[i][k] * b[k][j];
			}
			cout << c;
			if (j < l-1) cout << " "; 
			else if (i < n-1) cout << "\n";
		}
	}	
	cout << endl;
	return 0;
}

Measured memory_bytes: 1316
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds; 
using namespace std;
using   ll=long long;
using   ld=long double;

#define fast        	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ordered_set 	tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>

#define endl        	"\n"
#define pb          	push_back
#define mp          	make_pair
#define F           	first
#define S           	second
#define int             long long int

#define ALL(v)      	v.begin(),v.end()
#define ALLR(v)     	v.rbegin(),v.rend()
#define pii         	3.14159265358979323
#define inf     		LLONG_MAX
#define ones(x)     	__builtin_popcount(x)
#define fill(a,b)   	memset(a,b,sizeof(a))
#define mod 			1000000007

ll mod_pow(ll a,ll b) 
{
    ll res = 1;
    while(b)	
    {
        if(b&1) 	
        {
        	res=(res*a)%mod;
        }
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}

ll mod_inverse(ll a) 
{
	return mod_pow(a , mod-2);
}

void solve()
{
	int n , p;
	
	cin >> n >> p;
	
	string s;
	
	cin >> s;
	
	if(p == 2 or p == 5) {
		int ans = 0;
		
		for(int i = n-1; i >= 0; --i) {
			if((s[i]-'0') % p == 0) {
				ans += i+1;
			}
		}
		
		cout << ans;
		return;
	}
	
	map< int , int > f;
	
	f[0] = 1;
	
	int ten = 1;
	int rem = 0;
	int ans = 0;
	
	for(int i = n-1; i >= 0; --i) {
		rem = (rem + (s[i]-'0')*ten) % p;
		ans += f[rem];
		ten *= 10;
		ten %= p;
		f[rem]++;
	}
	
	cout << ans;
}

signed main() {
    fast;
    
    int t = 1;
    
    //cin >> t;
    
    while(t--) {
        solve();
    }
 
    return 0;
}


Measured memory_bytes: 4128
import java.util.Scanner;
public class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    if (a + b == c || b + c == a || a + c  == b)
      System.out.println("Yes");
    else
      System.out.println("No");
  }
}

Measured memory_bytes: 23764
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)

	N := getInt()
	A := getInt()
	x := make([]int, N)
	for i := 0; i < N; i++ {
		x[i] = getInt() - A
	}

	var dp [51][5300]int
	offset := 2500

	dp[0][offset] = 1
	for i := 0; i < N; i++ {
		for j := 0; j < 5000; j++ {
			//			out(j, j+x[i])
			dp[i+1][j] += dp[i][j]
			if j+x[i] > 0 {
				dp[i+1][j+x[i]] += dp[i][j]
			}
		}
	}

	out(dp[N][offset] - 1)
}


Measured memory_bytes: 3200
a,b,m=map(int,input().split())
reizoko=list(map(int,input().split()))
renji=list(map(int,input().split()))
ans=min(reizoko)+min(renji)
for i in range(m):
    x,y,c=map(int,input().split())
    cost=reizoko[x-1]+renji[y-1]-c
    ans=min(ans,cost)
print(ans)

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


#define debug(x) cout << #x << " = " << x << endl;
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c))

const int INF = 0x3F3F3F3F; 
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const double EPS = 1e-10;
const ll mod = 961748941;

inline int cmp(double x, double y = 0) 
{  
  if(fabs(x - y) < EPS)
    return 0;
  return x > y ? 1 : -1;
}

ll exp(ll a, ll b)
{
  ll ans = 1;
  while(b)
  {
    if(b & 1)
      ans = (ans * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}

const int maxn = 2505 + 5;
ll fat[maxn], inv[maxn];

ll C(int n, int k)
{
  if(n < k) 
    return 0;
  if(n < 0 || k < 0) 
    return 0;
  return (((fat[n] * inv[k]) % mod) * inv[n - k]) % mod;
}

void initFactorials()
{
  fat[0] = 1;
  inv[0] = 1;
  for(int i = 1; i < maxn; i++)
  {
    fat[i] = (i * fat[i-1]) % mod;
    inv[i] = exp(fat[i], mod - 2);
  }
}
int n,k;
int a[maxn];

bool test(int x)
{
  vector<int>v;
  for(int i = 0; i < n; i++)
  {
    v.push_back(a[i] % x);
  }

  sort(v.begin(), v.end());
  int l = 0;
  int r = v.size() - 1;
  int sum = 0;
  int rq = 0;
  while( l <= r )
  {
    if(sum <= 0)
    {
      rq += v[l];
      sum += v[l];
      l++;
    }
    else
    {
      rq += (x - v[r]);
      sum -= (x - v[r]);
      r--;
    }
  }
  if( sum != 0 || rq > 2 * k)
    return false;
  return true;
}

int main()
{
  cin >> n >> k;
  int sum = 0;
  for(int i = 0 ; i < n ; i++)
  {
    cin >> a[i];
    sum += a[i];
  }
  ll ans = 0;
  for(ll i = 1; i * i <= sum ; i++)
  {
    if(sum % i == 0)
    {
      if(test(i))
        ans = max(ans, i);
      if(test(sum / i))
        ans = max(ans, sum / i);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3596
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int nest = 0;
		boolean flag = true;
		for(int i=0;i<n;i++) {
			int dx = 0;
			String s = sc.next();
			if (s.equals("(")) {
				dx = 1;
			}else{
				dx = -1;
			}
			nest += dx * sc.nextInt();
			if (nest < 0) {
				flag = false;
				break;
			}
		}
		if (nest!=0) {
			flag = false;
		}
		System.out.println(flag ? "YES" : "NO");
	}

}

Measured memory_bytes: 24812
#include <stdio.h>

int main(){
  char line[100];
  int h, w;
  int i, j;
  while(1){
	fgets(line, sizeof(line), stdin);
	sscanf(line, "%d %d", &h, &w);
	if((h==0)&&(w==0))
	  break;
	for(i=0; i<h; ++i){
	  for(j=0; j<w; ++j){
		printf("#");
	  }
	  printf("\n");
	}
	printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2044
N = gets.to_i
B = gets.split.map(&:to_i)

A = []
A[0] = B[0]
(1..N - 2).each do |i|
  min_i_B = [B[i - 1], B[i]]
  A[i] = min_i_B.min
end
A[N - 1] = B[N - 2]

p A.inject(:+)

Measured memory_bytes: 1916
#include <stdio.h>

int main(void)
{
	float a;
	float b;
	int i;
	
	while (scanf("%f %f", &a, &b) != EOF){
		
		if (a < 35.50 && b < 71.00){
			printf("AAA");
		}
		else if (a < 37.50 && b < 77.00){
			printf("AA");
		}
		else if (a < 40.00 && b < 83.00){
			printf("A");
		}
		else if (a < 43.00 && b < 89.00){
			printf("B");
		}
		else if (a < 50.00 && b < 105.00){
			printf("C");
		}
		else if (a < 55.00 && b < 116.00){
			printf("D");
		}
		else if (a < 70.00 && b < 148.00){
			printf("E");
		}
		else {
			printf("NA");
		}
		
		printf("\n");
	}
	
	return (0);
}

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

using namespace std;

#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1){std::cerr << name << " = " << arg1 << endl;}
template <typename Arg1, typename... Args>void ZZ(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}

#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define endl '\n'
#define sz(a) int((a).size())

string s, t;
int p;

signed main()
{
	IOS;
	cin >> s >> t;
	for (int i = 0; i < sz(s); i++) {
		if (s.substr(i, sz(s) - i) + s.substr(0, i) == t) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = 0; i < (n); i++)
 
int main(){
    int N;
    cin >> N;
    for(int i=1;i<10;i++){
        for(int j=1;j<10;j++){
            if(N == i*j){
                cout << "Yes";
                return 0;
            }
        }
    }
    cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MN 18
#define pa pair<int,int>
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-'0';ch=getchar();}
    return x*f;
}
int n;pa f[1<<MN];
pa operator + (const pa&a,const pa&b)
{
    if(a.first>b.first) return make_pair(a.first,max(a.second,b.first));
    else return make_pair(b.first,max(a.first,b.second));
}
int main()
{
    n=read();
    for(int i=0;i<1<<n;++i) f[i]=make_pair(read(),-1e9);
    for(int i=0;i<n;++i) for(int j=0;j<1<<n;++j) if(j&(1<<i)) f[j]=f[j]+f[j^(1<<i)];
    for(int i=1,res=0;i<1<<n;++i) printf("%d\n",res=max(res,f[i].first+f[i].second));
    return 0;
}

Measured memory_bytes: 5120
package main

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

func main() {
	var N int
	fmt.Scan(&N)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	a := make([]int, N)
	for i := 0; i < N; i++ {
		sc.Scan()
		a[i], _ = strconv.Atoi(sc.Text())
	}
	a[0] -= 1
	for i := 1; i < N; i++ {
		if a[i] > a[i-1] {
			a[i] -= 1
			continue
		}
		if a[i] < a[i-1] {
			fmt.Println("No")
			return
		}
	}
	fmt.Println("Yes")

}


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

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const int  MOD=1000000007;
const int  INF= int(1e9);

const int  MAX= int(1e6);

int main() {
    ios_base::sync_with_stdio(false);
    int n, s;
    cin >> n >> s;
    vector<ll> w(n+1),v(n+1);   
    for(int i = 1 ; i <= n ; i++) {
        cin >> w[i] >> v[i];
    }

    vector< vector<ll> > dp(n+1, vector<ll>(s+1,0)); 
    for(int i = 1 ; i <= n ; i++) {
        for (int j = s ; j >=1 ; j--) {
            dp[i][j] = dp[i-1][j];
            if( w[i] <= j && dp[i-1][j-w[i]] + v[i] > dp[i][j]) {
                dp[i][j] = dp[i-1][j-w[i]] + v[i];
             }
        }
    }

    cout<<dp[n][s];

    return 0;
}



Measured memory_bytes: 80256
#include <iostream>
#include <cmath>

using namespace std;
typedef long long ll;

const ll mod = 1000000007;

int memo[300000]={0};

void init(){
	memo[0]=1;
	ll a = 1;
	for(int i=1;i<300000;i++){
		a*=i;
		a%=mod;
		memo[i]=a;
	}
}

ll mypow(ll a,ll b){
	if(b==1)return a;
	if(b==0)return 1;
	ll r = mypow(a,b/2);
	r = (r*r)%mod;
	if(b%2==1)r*=a;
	r%=mod;
	return r;
}

ll moddiv(ll a,ll b){
	return (a*mypow(b,mod-2))%mod;
}

ll c(int n,int r){
	if(r<0)return 0;
	if(n<r)return 0;
	if(r==0)return 1;
	
	int a = memo[n];
	int b = memo[r];
	int c = memo[n-r];
	ll t = moddiv(a,b);
	t = moddiv(t,c);
	return t;
}

/*
int i=0;
ll route(int n,int m){
	i++;
	return c(n+m,min(n,m));
}

ll f(int n,int m,int k){
	if(k==0)return route(n,m);
	ll a=0;
	if(n>0)a += f(n-1,m,k);
	if(m>0)a += f(n,m-1,k);
	a += f(n+1,m,k-1);
	a += f(n,m+1,k-1);
	a%=mod;
	return a;
}*/

int main(){
	init();
	int n,m,k;
	cin >> n >> m >> k;
	ll ans=0;
	for(int i=0;i<=k;i++){
		int L = i;
		int D = k-i;
		ll x = c(n+L*2,L)-c(n+L*2,L-1);
		ll y = c(m+D*2,D)-c(m+D*2,D-1);
		ll comb = c(n+m+2*k,n+2*L);
		ll t = (x*y)%mod;
		t = (t*comb)%mod;
		ans = (ans+t)%mod;
	}
	while(ans<0)ans+=mod;
	cout << ans << endl;
}

Measured memory_bytes: 2004