akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 100;
ll M = 1e18;
ll l, r;
ll n, k, equ;
ll a[N], b[N];

ll cal(ll mid) {
    ll cnt = 0;
    ll i= 0, j = r - 1;

    for(;i<r-1;i++) {
        for(;j>i;j--) {
            if(b[i] * b[j] <= mid) {
                if(b[i] * b[j] == mid)equ ++;
                break;
            }
        }
        if(j <= i)break;
        cnt += (j - i);
    }

    i = l - 1, j = 0;

    for(;i>0;i--) {
        for(;j<i;j++) {
            if(a[i] * a[j] <= mid) {
                if(a[i] * a[j] == mid)equ ++;
                break;
            }
        }
        if(j >= i)break;
        cnt += (i - j);
    }

    return cnt;
}


int main() {
    M = M + 100;

	cin>>n>>k;
	ll x;
	l = 0, r = 0;
	while(n--) {
        cin>>x;
        if(x >= 0)b[r ++] = x;
        else a[l ++] = x;
	}
	// 3 3
	sort(b, b + r);
	// -4 -2
	sort(a, a + l);

	ll left = -M, right = M, mid;
	int y = 0;
	for(y=0;y<100;y++){
	//while(left < right) {
        mid = (left + right + 1) / 2;
        //cout<<mid<<endl;
        ll cnt = 0;
        equ = 0;
        if(mid >= 0) {
            cnt += l * r;
            if(mid == 0 && b[0] == 0) {
                equ += (n - 1);
            }
            cnt += cal(mid);
        }else {
            ll i = 0, j = 0;
            for(;i<l;i++) {
                for(;j<r;j++) {
                    if(a[i] * b[j] <= mid) {
                        if(a[i] * b[j] == mid)equ ++;
                        break;
                    }
                }
                cnt += (r - j);
            }
        }
        //cout<<cnt<<"equ:"<<equ<<endl;
        if(cnt == k) {
            if(equ > 0) {
                cout<<mid<<endl;
                break;
            }else right = mid - 1;
        }else if(cnt < k) {
            left = mid;
        }else {
            right = mid;
        }
	}
    if(y == 100) {
        cout<<mid<<endl;
    }
    return 0;
}


Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;


public class Main {
	 static class FastReader 
	    { 
	        BufferedReader br; 
	        StringTokenizer st; 
	       
	  
	        public FastReader() 
	        { 
	            br = new BufferedReader(new
	                     InputStreamReader(System.in)); 
	        } 
	  
	        String next() 
	        { 
	            while (st == null || !st.hasMoreTokens()) 
	            { 
	                try
	                { 
	                    st = new StringTokenizer(br.readLine()); 
	                } 
	                catch (IOException  e) 
	                { 
	                    e.printStackTrace(); 
	                } 
	            } 
	            return st.nextToken();
	            
	        } 
	  
	        int nextInt() 
	        { 
	            return Integer.parseInt(next()); 
	        } 
	  
	        long nextLong() 
	        { 
	            return Long.parseLong(next()); 
	        } 
	  
	        double nextDouble() 
	        { 
	            return Double.parseDouble(next()); 
	        } 
	  
	        String nextLine() 
	        { 
	            String str = ""; 
	            try
	            { 
	                str = br.readLine(); 
	            } 
	            catch (IOException e) 
	            { 
	                e.printStackTrace(); 
	            } 
	            return str; 
	        }

			public Character charAt(int i) {
				// TODO Auto-generated method stub
				return null;
			} 
	    } 
 
	public static void main(String[] args)throws IOException  {
		FastReader s=new FastReader();		
		String t  = s.next();
		int c=0;
		for(int i=0;i<t.length();i++) {
			if((int)t.charAt(i)==111)c++;
		}
		int p = 15-t.length();
		if(p>=(8-c))System.out.println("YES");
		
		else System.out.println("NO");
	}
}

Measured memory_bytes: 32648
#include <iostream>
using namespace std;
typedef long long int LLI;
int main()
{
	LLI n, t, a;
	cin >> n >> t >> a;
	
	LLI min_t = t, min_a = a, div_a, div_t, max;
	for(LLI i = 0; i < n-1; i++)
	{
		cin >> t >> a;
		if( min_a % a == 0 )
			div_a = min_a / a;
		else
			div_a = min_a / a + 1;
			
		if( min_t % t == 0 )
			div_t = min_t / t;
		else
			div_t = min_t / t + 1;
		
		max = div_t > div_a ? div_t : div_a;
		
		min_a = a * max;
		min_t = t * max;
	}
	cout << min_t + min_a;
}

Measured memory_bytes: 256
x,y=map(int,input().split())
if x>0:
  if y>x:
    print(y-x)
  elif 0<y<x:
    print(x-y+2)
  elif y<=0:
    print(abs(abs(x)-abs(y))+1)
elif x==0:
  if y>0:
    print(y-x)
  else:
    print(x-y+1)
else:
  if y<x:
    print(x-y+2)
  elif x<y<=0:
    print(y-x)
  else:
    print(abs(abs(x)-abs(y))+1)

Measured memory_bytes: 9156
#include<stdio.h>
int main(){
    long long k;
    char s[110];
    scanf("%s%lld",s,&k);
    for(int i=0;i<k;i++){
        if(s[i]!='1'){
            putchar(s[i]);
            return 0;
        }
    }
    puts("1");
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <cmath>

using namespace std;

void funcA() {

  int x;
  cin >> x;

  if (x >= 30) cout << "Yes";
  else cout << "No";
}

void funcB() {

  double n;
  double d;
  cin >> n >> d;
  vector<vector<double>> zahyo(n, vector<double>(2));

  for (int i = 0; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    zahyo[i][0] = x;
    zahyo[i][1] = y;
  }

  int count = 0;
  for (int i = 0; i < n; ++i) {
    double length = sqrt(pow(zahyo[i][0], 2) + pow(zahyo[i][1], 2));
    if (length <= d) ++count;
  }

  cout << count;


}

void funcC() {

}

int main() {

  //funcA();
  funcB();

  return 0;
}

Measured memory_bytes: 14468
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
// typedef __int128_t Int;
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  int N;
  cin >> N;
  vector<int> a(N);
  rep(i, 0, N) { cin >> a[i]; }
  vector<int> b(N);
  rep(i, 0, N) { cin >> b[i]; }

  int ans = 0;

  rep(k,0,29){
    vector<int>c(N),d(N);
    rep(i,0,N){
      c[i]=a[i]%(1<<(k+1));
      d[i]=b[i]%(1<<(k+1));
    }
    sort(all(c));
    sort(all(d));
    dump(c,d);

    rep(i,0,N){
      auto t1=lower_bound(all(d),  (1<<k)-c[i]);
      auto t2=lower_bound(all(d),2*(1<<k)-c[i]);
      auto t3=lower_bound(all(d),3*(1<<k)-c[i]);
      auto t4=lower_bound(all(d),4*(1<<k)-c[i]);

      dump(t1-d.begin());
      dump(t2-d.begin());
      dump(t3-d.begin());
      dump(t4-d.begin());

      int d1=t2-t1 + t4-t3;
      
      ans^=((d1&1)<<k);
      dump(ans);
    }
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);i++) 
#define per(i,a,b) for(int i=(a);i>=(b);i--)
const int maxn=1e5+10;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
int n,k;
ll qpow(ll a,int b) {
	ll ans=1;
	while(b) {
		if(b&1) ans=ans*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ans;
}
int main() 
{
	ios::sync_with_stdio(false);cin.tie(0);
	cin>>n>>k;
	k=min(n-1,k);
	ll ans=0,a=1,b=1;
	rep(i,0,k) {
		ans=(ans+a*b)%mod;
		a=a*(n-i)%mod*qpow(i+1,mod-2)%mod;
		b=b*(n-1-i)%mod*qpow(i+1,mod-2)%mod;
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int a = N%2;
		
		if(a==0) {
			System.out.print(N/2);
		}else {
			System.out.println(N/2+1);
		}
		
		sc.close();
	}
}

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

using namespace std;

int main(){
	int N;
	cin >> N;
	double tmp;
	int tmp2;
	while(N > 0){
		tmp = sqrt(N);
		tmp2 = ceil(tmp);
		if(tmp2*tmp2 == N){
			cout << N << endl;
			break;
		}
		N--;
	}
	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

public class Main {
	// AtCoder Beginner Contest 082
	// https://atcoder.jp/contests/abc082/tasks
	final static int MOD = 10007;
	
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int n = sc.nextInt();
		int res = 0;
		Map<Integer, Integer> map = new HashMap<>();
		
		for (int i = 0; i < n; i++) {
			int num = sc.nextInt();
			map.put(num, map.getOrDefault(num, 0) + 1);
		}
		
		for (int key: map.keySet()) {
			int v = map.get(key);
			
			if (v > key) {
				res += (v - key);
			} else if (v < key) {
				res += v;
			}
		}
		
		System.out.println(res);
	}
	
	static class FastReader { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() { 
            br = new BufferedReader(new InputStreamReader(System.in)); 
        } 
  
        String next() { 
            while (st == null || !st.hasMoreElements()) { 
                try { 
                    st = new StringTokenizer(br.readLine()); 
                } catch (IOException  e) { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() { 
            String str = ""; 
            try{ 
                str = br.readLine(); 
            } catch (IOException e) { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
}


Measured memory_bytes: 46680
// I can't tell you what it really is,
// I can only tell you what it feels like.
#include "bits/stdc++.h"
using namespace std;

#define int long long
#define F first
#define S second
#define rep(i,a,n) for (int i = a; i <= n; ++i)
#define fo(i, n)   for (int i = 1; i <= n; ++i)
#define all(v)  v.begin(), v.end()
#define pb push_back
#define P pair < int, int > 
#define fast  ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define E cout << '\n'
const int N = 10 + 5;
vector < int >v[N];
int vis[N], ans;
void dfs(int node, int ht) {
	vis[node] = true;
	ans = max(ans, ht);
	for(auto i : v[node])
		if(!vis[i])
			dfs(i, ht + 1);
}
signed main(){  
   fast;
   int l, r;
   fo(i, 3) {
   	cin >> l >> r;
   	v[l].pb(r);
   	v[r].pb(l);
   } 

   fo(i, 4) {
   	ans = 0;
   	dfs(i, 1);
   	if(ans == 4)
   		return cout << "YES\n",0;
   	memset(vis, 0, sizeof vis);
   }
   cout << "NO";


















	return 0;
}   

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

int main()
{
    long long N, A, B, v, r;
    cin >> N >> A >> B;
    if (A == 0) {cout << 0 << endl; return 0;}

    v = N / (A+B);
    r = N % (A+B);

    if (r >= A) cout << A * v + A << endl;
    else cout << A * v + r << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>

#define INFL (1LL << 60)

using namespace std;

typedef long long ll;

int main() {
    ll n, f, ans = -INFL;
    scanf("%lld", &n);
    vector<ll> df(n);
    vector< vector<ll> > dp(n, vector<ll>(11));
    for (ll i = 0; i < n; ++i) for (ll j = 0; j < 10; ++j) {
        scanf("%lld", &f);
        df.at(i) |= (f << j);
    }
    for (ll i = 0; i < n; ++i) for (ll j = 0; j <= 10; ++j) scanf("%lld", dp.at(i).begin() + j);
    for (ll i = 1; i < (1 << 10); ++i) {
        ll sum = 0;
        for (ll j = 0; j < n; ++j) {
            ll t = i & df.at(j), cnt = 0;
            for (ll k = 0; k < 10; ++k) if (t & (1 << k)) ++cnt;
            sum += dp.at(j).at(cnt);
        }
        ans = max(ans, sum);
    }
    printf("%lld\n", ans);
    return 0;
}


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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;


class Solver {
  public:
    bool solve() {
        int H, W; cin >> H >> W;
        int N; cin >> N;
        vector<int> A(N); cin >> A;

        vector<vector<int>> G(H, vector<int>(W));

        int i = 0;
        rep(y, H) {
            rep(x, W) {
                int xx = (y % 2 ? x : W - x - 1);
                G[y][xx] = i + 1;
                if(--A[i] == 0) i++;
            }
        }
        rep(y, H) rep(x, W) {
            cout << G[y][x] << (x == W - 1 ? "\n" : " ");
        }
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}


Measured memory_bytes: 384
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

// Monge の場合は閉区間で考えたほうがよいかも？
int N, dp[410][410], idx[410][410], sum[410], A[410];

signed main() {
    cin >> N;
    for(int i=0; i<N; i++) {
        cin >> A[i];
        sum[i+1] += sum[i] + A[i];
    }

    fill(dp[0], dp[N+1], INF);
    for(int i=0; i<N; i++) {
        dp[i][i] = 0;
        idx[i][i] = i;
    }

    for(int len=2; len<=N; len++) {
        for(int a=0; a<N-len+1; a++) {
            int b = a + len - 1;
            int cost = sum[b+1] - sum[a];

            int l = idx[a][b-1];
            int r = idx[a+1][b];

            for(int k=r; k>=l; k--) {
                if(dp[a][b] > dp[a][k] + dp[k+1][b] + cost) {
                    dp[a][b] = dp[a][k] + dp[k+1][b] + cost;
                    idx[a][b] = k;
                }
            }
        }
    }

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


Measured memory_bytes: 2816
//尺取法
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;
typedef long long ll;

int main(){
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;

    vector<int> nums;

    int now=1; //今見ている数
    int cnt=0; //nowがいくつ並んでいるのか

    for (int i = 0; i < n; i++)
    {
        if(s[i]==(char)('0'+now)) cnt++;
        //0と1が切り替わる
        else{
            nums.push_back(cnt);
            now = 1-now;
            cnt = 1;
        }
    }
    if(cnt!=0) nums.push_back(cnt);

    //1_0_1_0_1の配列がいい
    //1_0_1_0だったら配列を1増やす
    if(nums.size() % 2 == 0) nums.push_back(0);

    //足す項の数
    int add = 2*k+1;
    
    int left=0;
    int right=0;
    int tmp=0; //[left, right)のsum

    int ans = 0;
    //1_0_1_0....の、1だけをみる
    for (int i = 0; i < nums.size(); i+=2)
    {
        int nextLeft = i;
        int nextRight = min(i+add, (int)nums.size());
        while (nextLeft>left)
        {
            tmp -= nums[left];
            left++;
        }
        while (nextRight>right)
        {
            tmp += nums[right];
            right++;
        }

        ans = max(tmp, ans);
    }
    
    cout << ans << endl;

}

Measured memory_bytes: 1020
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <climits>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <cstring>
#include <numeric>
#include <set>

#define INF 2000000000
#define MOD 1000000007
#define sp ' '
#define endl "\n"
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define FOR(YY, yy) for(long long yy = 0; yy < YY; ++yy)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef pair<int, int> ii;
typedef vector<pair<int, int> > vii;
typedef vector<pair<int, pair<int, int> > > vpip;
typedef vector<bool> vb;
typedef priority_queue<int> pqi;

int main(int argc, char **argv)
{
    ios::sync_with_stdio(); cin.tie(0);
    double N; cin >> N;

    double odd = 0;
    for(int i = 1; i <= N; ++i)
    {
        if(i % 2) odd++;
    }
    
    printf("%.10lf\n", odd/N);


    return 0;
}

//cikisir



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>

using namespace std;

int main() {

	string s;
	cin >> s;
	int mini = 1000000007;
	for (int i = 0; i < s.length() - 2; i++) {

		string t = s.substr(i, 3);//3文字を取り出す
		int tmp = stoi(t);//整数型に変換
		mini = min(mini, abs(753 - tmp));
	}
	cout << mini << endl;

	return 0;
}


Measured memory_bytes: 256
D,G=map(int, input().split())

L=[]
for i in range(D):
    p,c=map(int, input().split())
    L.append((p,c))

from itertools import permutations
from math import ceil
ans=float("INF")
for t in permutations(range(1,D+1)):
    #print(t)
    t=list(t)
    now=G
    sub=0
    for x in t:
        p,c=L[x-1]
        if now/(x*100)<=p:
            sub+=ceil(now/(x*100))
            break
        elif x*p*100+c>=now:
            sub+=p
            break
        else:
            now-=x*p*100+c
            sub+=p

    #print(t, sub)
    ans=min(ans, sub)
    
print(ans)

Measured memory_bytes: 41960
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		new Main().start();
	}
	void start(){
		Scanner in = new Scanner(System.in);
		in.nextInt();
		int n = in.nextInt()*10 + in.nextInt();
		if(n % 4 == 0){
			System.out.println("YES");
		}else{
			System.out.println("NO");
		}
		in.close();
	}

}

Measured memory_bytes: 23892
#include<stdio.h>

int main(){
  int i,j,n,u,k,v,m[200][200];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++) m[i][j]=0;
  }
  for(i=1;i<=n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
      m[i][v]=1;
    }
  }
  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      if(j!=1) printf(" ");
      printf("%d",m[i][j]);
    }
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2108
#include <iostream>
#include <math.h>
#include <strings.h>
using namespace std;

int main()
{
    int N ,A ,i;
    cin >> N;
    int f;
    f=0;
    for(i=0;i<N;i++){
        cin >> A;
        if(A%2==0){
            if(A%3!=0 and A%5!=0){
                f=1;
            }
        }
    }
    if(f==1){
        cout <<"DENIED";
    }else{
        cout <<"APPROVED";
    }
    return 0;
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;
#define MAX_N 100010

ll N;
ll A[MAX_N] = {};

signed main()
{
    cin >> N;
    ll cnt = 0;
    REP(i, N) {
        cin >> A[i];
        if(A[i] % 2 == 1) { cnt++; }
    }
    if(cnt % 2 == 0) { printf("YES\n"); }
    else { printf("NO\n"); }
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<cstdlib>
#include<algorithm>
using namespace std;
#define MAX 10

void solve(string line, int N){
  int C[MAX];
  int B = 0;
  for (int i = 0; i < N; i++ ) C[i] = 0;

  for ( int i = 0; i < line.size(); i++ ){
    int p = i%N;
    if ( line[i] == 'M' ){
      C[p]++;
    } else if ( line[i] == 'S' ){
      C[p]++;
      B += C[p];
      C[p] = 0;
    } else if ( line[i] == 'L' ){
      C[p] += B + 1;
      B = 0;
    }
  }

  sort(C, C+N);

  for ( int i = 0; i < N; i++ ) cout << C[i] << " ";
  cout << B << endl;
}

main(){
  int N;
  string line;
  while(1){
    cin >> N;
    if ( N == 0 ) break;
    cin >> line;
    solve(line, N);
  }
}



Measured memory_bytes: 3172
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define show(x) true
#endif
template<unsigned int mod_>
struct ModInt{
	using uint = unsigned int;
	using ll = long long;
	using ull = unsigned long long;

	constexpr static uint mod = mod_;

	uint v;
	ModInt():v(0){}
	ModInt(ll _v):v(normS(_v%mod+mod)){}
	explicit operator bool() const {return v!=0;}
	static uint normS(const uint &x){return (x<mod)?x:x-mod;}		// [0 , 2*mod-1] -> [0 , mod-1]
	static ModInt make(const uint &x){ModInt m; m.v=x; return m;}
	ModInt operator+(const ModInt& b) const { return make(normS(v+b.v));}
	ModInt operator-(const ModInt& b) const { return make(normS(v+mod-b.v));}
	ModInt operator-() const { return make(normS(mod-v)); }
	ModInt operator*(const ModInt& b) const { return make((ull)v*b.v%mod);}
	ModInt operator/(const ModInt& b) const { return *this*b.inv();}
	ModInt& operator+=(const ModInt& b){ return *this=*this+b;}
	ModInt& operator-=(const ModInt& b){ return *this=*this-b;}
	ModInt& operator*=(const ModInt& b){ return *this=*this*b;}
	ModInt& operator/=(const ModInt& b){ return *this=*this/b;}
	ModInt& operator++(int){ return *this=*this+1;}
	ModInt& operator--(int){ return *this=*this-1;}
	ll extgcd(ll a,ll b,ll &x,ll &y) const{
		ll p[]={a,1,0},q[]={b,0,1};
		while(*q){
			ll t=*p/ *q;
			rep(i,3) swap(p[i]-=t*q[i],q[i]);
		}
		if(p[0]<0) rep(i,3) p[i]=-p[i];
		x=p[1],y=p[2];
		return p[0];
	}
	ModInt inv() const {
		ll x,y;
		extgcd(v,mod,x,y);
		return make(normS(x+mod));
	}
	ModInt pow(ll p) const {
		if(p<0) return inv().pow(-p);
		ModInt a = 1;
		ModInt x = *this;
		while(p){
			if(p&1) a *= x;
			x *= x;
			p >>= 1;
		}
		return a;
	}
	bool operator==(const ModInt& b) const { return v==b.v;}
	bool operator!=(const ModInt& b) const { return v!=b.v;}
	friend istream& operator>>(istream &o,ModInt& x){
		ll tmp;
		o>>tmp;
		x=ModInt(tmp);
		return o;
	}
	friend ostream& operator<<(ostream &o,const ModInt& x){ return o<<x.v;}
};
using mint = ModInt<1000000007>;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	
	int N,M;
	cin >> N >> M;
	V<bool> broken(N+1);
	rep(i,M){
		int x;
		cin >> x;
		broken[x] = true;
	}
	V<mint> dp(N+1);
	dp[0] = 1;
	rep1(i,N) if(!broken[i]) dp[i] = dp[i-1] + (i>=2 ? dp[i-2] : 0);
	cout << dp[N] << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define MOD (int)1e9+7
#define EPS 1e-8
#define INF 1e9+10
#define INFL 1e18
typedef long long ll;
using namespace std;
int main()
{
  int a,b,c;
  cin >> a >> b >> c;
  if(a+b+c>=22){
      cout << "bust" << endl;

  }
  else{
      cout << "win" << endl;
  }

}


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

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

    int x,y;cin>>x>>y;

    int ans=abs(abs(x)-abs(y));

    if(abs(x)>abs(y))ans+=(x>0?1:0)+(y>0?1:0);
    else if(abs(x)<abs(y))ans+=(x<0?1:0)+(y<0?1:0);
    else ans++;

    cout<<ans<<"\n";

    return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cstring>
#include <cmath>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
#define reps(i,s,n) for(int i=s; i<n; i++)
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;

int main() {
    int n;
    cin >> n;
    rep(t, n) {
        string in, num="";
        vector< vector<int> > g(5000);
        int cur = 0;
        cin >> in;
        rep(i, in.length()) {
            if( in[i] == '[' ) {
                num = "";
                cur++;
            } else if( in[i] == ']' ) {
                int sum = 0;
                if( in[i-1] == ']' ) {
                    sort( g[cur].begin(), g[cur].end() );
                    rep(j, (g[cur].size()+1)/2) {
                        sum += g[cur][j];
                    }
                } else {
                    sum = (atoi( num.c_str() )+1)/2;
                }
                cur--;
                g[cur].push_back(sum);
                g[cur+1].clear();
            } else {
                num += in[i];
            }
        }
        cout << g[0][0] << endl;
    }
    return 0;
}

Measured memory_bytes: 1376
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define INF 1000000007
#define ff first
#define ss second
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define int long long
#define all(a) a.begin(), a.end()
#define inf (1LL<<61)
#define ull unsigned long long
#define debug1(x) cerr << #x << ": " << x <<'\n'
#define debug2(x, y) cerr << #x << ": " << x << '\t' << #y << ": " << y <<'\n'
#define debug3(x, y, z) cerr << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": " << z <<'\n'
using namespace std;
int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
int gcd(int x,int y)
{
    if(y==0)
        return x;
    else
        return gcd(y,x%y);
}
int expo(int n,int m,int p)   //modULAR EXPONENTIATION
{
    int r=1;
    n=n%p;
    while(m>0)
    {
        if(m%2)
            r=(r*n)%p;
        n=(n*n)%p;
        m=m/2;
    }
    return r%p;
}
bool isPrime(int n)
{
    // Corner cases
    if (n <= 1)  return false;
    if (n <= 3)  return true;
 
    // This is checked so that we can skip 
    // middle five numbers in below loop
    if (n%2 == 0 || n%3 == 0) return false;
 
    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
 
    return true;
}
int32_t main()
{
   IOS;
   /*#ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin); 
   freopen("output.txt","w",stdout);
   #endif
   /********************* Code starts here ***********************/   
   int n,k;
   cin>>n>>k;
   if(k==1)
   {
   	cout<<0<<endl;
   	return 0;
   }
   cout<<n-k<<endl;
}	

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long int N=0,A=0,B=0;
  cin>>N;
  A=N;
  while(A>0){
    B+=A%10;
    A/=10;
  }
  if(N%B)
    cout<<"No"<<endl;
  else
    cout<<"Yes"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <map>
#include <vector>
#include <string>
#include <vector>
#include <cassert>
#include <cmath>
#include <cctype>
#include <queue>
#include <algorithm>
#include <memory>
#include <memory.h>

using namespace std;

int main(){
	string s;
	int n;
	while(cin >> s){
		int count = 0;
		string s2;
		cin >> n;
		for(int i = 0; i < n;i++){
			cin >> s2;
			s2 += s2;
			int p = s2.find(s);
			if(p != string::npos) count++;
		}
		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;
// ------------------------------

int bin_search(vector<int> S, int n, int i) {
    int left = 0, right = n;
    while (left < right) {
        int mid = (left + right) / 2;
        if (S[mid] == i) return 1;
        if (S[mid] > i) right = mid;
        if (S[mid] < i) left = mid + 1;
    }
    return 0;
}

int main() {
    int n;
    cin >> n;
    vector<int> S(n);
    rep(i, n) cin >> S[i];
    int q;
    cin >> q;
    vector<int> T(q);
    rep(i, q) cin >> T[i];
    int ans = 0;
    for (int i : T) {
        ans += bin_search(S, n, i);
    }
    cout << ans << endl;
    return 0;
}


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

#define Fast cin.tie(0), ios::sync_with_stdio(0)
#define All(x) x.begin(), x.end()
#define louisfghbvc int t; cin >> t; while(t--)
#define sz(x) (int)(x).size()
using namespace std;
typedef long long LL;
typedef pair<LL, LL> ii;
typedef vector<LL> vi;

template<typename T> istream& operator>>(istream &is, vector<T> &v) { for(auto &it : v) is >> it; return is; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep = ""; for(const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void dbg_out() { cerr << "\n"; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

const int mod = 1e9+7;
const int N = 2e5+5;

void solve(){
    int n;
    cin >> n;
    vi arr(n);
    cin >> arr;

    LL sum = 0;
    vi pre(n+1);
    pre[0] = 0;
    for(int i = 1; i <= n; ++i)
        pre[i] = (pre[i]+pre[i-1]+arr[i-1])%mod;
    //dbg_out(pre);
    for(int i = 1; i < n; ++i){
        sum = sum + (arr[i]*pre[i]) % mod;
        sum %= mod;
    }

    cout << sum << "\n";
}

int main()
{
    Fast;
    //louisfghbvc{
        solve();
    //}
    return 0;
}


Measured memory_bytes: 6300
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n,h,cnt=0,x;
    cin>>n>>h;
    vector<ll>vec;
    vector<ll>::iterator it;
     for(int i=0;i<n;i++)
     {
        cin>>x;
        vec.push_back(x);

     }
     sort(vec.begin(),vec.end());
       for(it=vec.begin();it!=vec.end();it++)
          if(*it>=h) {
          cnt++;}
             cout<<cnt<<endl;





return 0;}


Measured memory_bytes: 1400
#include <stdio.h>
  
int main(int argc, char *argv[]) {
    int n, m;
    int cnt[50] = {0};
    int a, b;

    scanf("%d%d", &n, &m);
    for (int i = 0; i < m; i++) {
        scanf("%d%d", &a, &b);
        cnt[a - 1]++;
        cnt[b - 1]++;
    }

    for (int i = 0; i < n; i++) {
        printf("%d\n", cnt[i]);
    }

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;

int main(int argc, char *argv[])
{
	int a, b, c;
	cin >> a >> b >> c;

	if (c - b == b - a)
		cout << "YES";
	else
		cout << "NO";

	cout << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> que;
ll n, m, a, b;
int main(void){
    // Your code here!
    cin >> n >> m;
    for (ll i = 0; i < m; i++) {
        cin >> a >> b;
        que.push(P(b, a));
    }
    ll res = 1;
    P p = que.top(); que.pop();
    a = p.second, b = p.first;
    for (ll i = 1; i < m; i++) {
        p = que.top(); que.pop();
        if (p.second >= b) {
            res++;
            a = p.second;
            b = p.first;
        } else if (p.second <= a) {
            continue;
        } else {
            a = p.second;
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 2420
cost={(i,j):[] for i in range(51) for j in range(51)}
def dfs(nf,c,fr,to):
    if nf==to:
        cost[(fr,to)].append(c)
        return 0

    if to*2+1>nf:
        return 0

    for i in range(1,nf+1):
        dfs(nf%i,c+2**i,fr,to)


for i in range(1,51):
    for j in range(51):
        dfs(i,0,i,j)
        cost[(i,j)].sort()

N=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

for i in range(51):
    cost[(i,i)].append(0)

for i in range(N):
    if not cost[(a[i],b[i])]:
        print(-1)
        exit()

ans=0
k=50
while k>0:
    check=False
    for i in range(N):
        test=cost[(a[i],b[i])][0]
        if test>>k &1==1:
            check=True

    if check:
        ans+=2**k
        for i in range(N):
            for j in range(len(cost[(a[i],b[i])])):
                c=cost[(a[i],b[i])][j]
                if c>>k &1==1:
                    cost[(a[i],b[i])][j]-=2**k
            cost[(a[i],b[i])].sort()
    k-=1

print(ans)

Measured memory_bytes: 4584
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N; cin >> N;
    int v = 2;
    int mod2 = 0, mod3 = 0, mod5 = 0;
    for (int i = 0; i < N-2; i++) {
        while (!(v % 2 == 0 || v % 3 == 0 || v % 5 == 0)) v++;
        mod2 = (mod2 + v) % 2;
        mod3 = (mod3 + v) % 3;
        mod5 = (mod5 + v) % 5;
        cout << v++ << ' ';
    }
    while (!((v % 2 == 0 || v % 3 == 0 || v % 5 == 0) && v % 5 == (5 - mod5) % 5)) v++;
    mod2 = (mod2 + v) % 2;
    mod3 = (mod3 + v) % 3;
    mod5 = (mod5 + v) % 5;
    cout << v++ << ' ';
    while (!(v % 2 == (2 - mod2) % 2 && v % 3 == (3 - mod3) % 3 && v % 5 == 0)) v++;
    cout << v << '\n';
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <cmath>
#include <cstdio>
using namespace std;
 
int main() {
 
  double sum = 0;
 
  double  x[21],y[21];
  double hen[30];
  double shen;
  int count = 0;
  double z;
  while(scanf("%lf,%lf",&x[count],&y[count]) != EOF) {
    if(count > 0) {
      hen[count-1] =  sqrt((x[0]-x[count])*(x[0]-x[count]) + (y[0]-y[count])*(y[0]-y[count]));
    }
    if(count >1) {
      shen = sqrt((x[count]-x[count-1])*(x[count]-x[count-1]) + (y[count]-y[count-1])*(y[count]-y[count-1]));
      z = (hen[count-1] + hen[count -2] + shen ) /2;
      // cout << sqrt(z*(z-shen)*(z-hen[count-1])*(z-hen[count-2])) << endl;
    sum += sqrt(z*(z-shen)*(z-hen[count-1])*(z-hen[count-2]));
    }
    count ++;
     
  }
 
  
     
  printf("%.8lf\n",sum);
 
  return 0;
}
  

Measured memory_bytes: 1240
#0からiまでのSを2019で割ったときのあまりを調べる
#A%mod =a,B$mod=aなら（A-B)%mod=0
from collections import Counter
S = input()
dp = [0]
mod = 2019
for i in reversed(range(len(S))):
    dp.append(dp[-1]%mod+pow(10,len(S)-i-1,mod)*int(S[i]))
    dp[-1]%=mod
count = Counter(dp)
ans = 0
for key,val in count.items():
    if val>=2:
        ans += val*(val-1)//2
print(ans)

Measured memory_bytes: 84648
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int a, b; cin >> a >> b;
	if(a < 10 and b < 10) {
		cout << a * b << endl;
	} else {
		cout << -1 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
    int d;
    cin >> d;
    string ans;
    if(d == 25) ans = "Christmas";
    if(d == 24) ans = "Christmas Eve";
    if(d == 23) ans = "Christmas Eve Eve";
    if(d == 22) ans = "Christmas Eve Eve Eve";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int i,a[10],t=0;
  for(i=0;i<5;i++){
    scanf("%d",&a[i]);
    if(a[i]<=40){
      a[i]=40;
    }
    t=t+a[i];
  }
 printf("%d\n",t/5);
 return 0;
}

Measured memory_bytes: 596
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		Scanner in = new Scanner(System.in);
		int a = in.nextInt();
		int b = in.nextInt();
		int c = in.nextInt();
		if ((a+b+c)<22) System.out.println("win");
		else System.out.println("bust");
	}

}


Measured memory_bytes: 21716
/*
digu_J - Digvijay Janartha
NIT Hamirpur - INDIA
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

template < typename T > using ordered_set = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << std :: endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    int len = comma - names;
    for (int i = 0; i < len; ++i) {
        cout << names[i];
    }
    cout <<  " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < ll, ll > pll;
typedef pair < int, int > pii;
typedef vector < ll > vll;
typedef vector < int > vi;

#define eb emplace_back
#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

const ll LINF = LLONG_MAX, base = 1e9, MOD = 1e9 + 7, N = 1e5 + 10, M = 1e3 + 10;
const int INF = INT_MAX;
const db PI = acos(-1);

void test();

int main() {
    fast_io();
    test();
    return 0;
}

void test() {
    string s;
    cin >> s;
    int a = (s[0] - '0') * 10 + (s[1] - '0');
    bool yy = false, mm = false;
    if (a > 12 or a == 0) {
        yy = true;
    } else {
        yy = mm = true;
    }
    a = (s[2] - '0') * 10 + (s[3] - '0');
    if (a > 12 or a == 0) {
        if (yy and mm) {
            cout << "MMYY\n";
        } else {
            cout << "NA\n";
        }
    } else {
        if (yy and mm) {
            cout << "AMBIGUOUS\n";
        } else {
            cout << "YYMM\n";
        }
    }
}


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

#define FIO ios_base::sync_with_stdio(0); cin.tie(0);
#define T() int tt; cin >> tt; rep1(qq,1,tt)
#define rep(i,start,lim) for(int i=start;i<lim;i++)
#define rep1(i,start,lim) for(int i=start; i<=lim; ++i)
#define repd(i,start,lim) for(int i=start;i>=lim;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define br cout<<"\n"
#define MOD (1000000007LL)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define eps (1e-6)
#define what_is(x) cerr << #x << " is " << x << "\n";
#define int long long int
#define infll 9e18
#define inf 1e12

#define lnode (2 * node + 1)
#define rnode (2 * node + 2)

using namespace std;

typedef pair<int, int> pii;

const int N = 1005;

int n, m, k;
char s[N][N];

int solve(vector<int> &cuts){
  vector<vector<int>> v;
  vector<int> t(m+1,0);
  v.push_back(t);
  for(int cut = 1; cut < cuts.size(); ++cut){
    int pre = cuts[cut - 1], cur = cuts[cut];
    vector<int> temp; temp.push_back(0);
    for(int j = 1; j <= m; ++j){
      int here = 0;
      for(int i = pre + 1; i <= cur; ++i){
        here += (s[i][j] == '1');
      }
      if(here > k) return -1;
      temp.push_back(here);
    }
    v.push_back(temp);
  }
  int res = 0;
  int sz = v.size();
  assert(v[0].size() == m + 1);
  vector<int> sums(sz + 1, 0);
  for(int j = 1; j <= m; ++j){
    int cut_here = 0;
    for(int i = 1; i < sz; ++i){
      sums[i] += v[i][j];
      if(sums[i] > k) cut_here = 1;
    }
    if(cut_here){
      ++res;
      for(int i = 1; i < sz; ++i){
        sums[i] = v[i][j];
      }
    }
  }
  return res;
}

int32_t main(){
  ios_base::sync_with_stdio(0); cin.tie(NULL);
  cin >> n >> m >> k;
  for(int i = 1; i <= n; ++i)
    for(int j = 1; j <= m; ++j)
      cin >> s[i][j];

  int res = inf;
  for(int mask = 0; mask < (1 << (n - 1)); ++mask){
    vector<int> cuts;
    cuts.push_back(0);
    for(int i = 0; i < (n - 1); ++i){
      if(mask & (1 << i)){
        cuts.push_back(i + 1);
      }
    }
    cuts.push_back(n);
    int tempAns = solve(cuts);
    if(tempAns == -1) continue;
    res = min(res, tempAns + (int)cuts.size() - 2LL);
  }
  cout << res << '\n';
  
  
  
  return 0;
}




Measured memory_bytes: 384
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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


int main(int argc, char const *argv[]) {
    int n; cin>>n;
    vector<int> a(n);
    rep(i,n) cin>>a[i];
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i+1; j < n; ++j) {
            ans += a[i]*a[j];
        }
    }

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

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { 
  if (a < b) { 
    a = b; return 1; 
  }
  return 0; 
}
template<class T> inline bool chmin(T& a, T b) { 
  if (a > b) { 
    a = b;
    return 1; 
  } 
  return 0; 
}

const long long INF = 1LL << 60;

int N;
long long h[100010];

long long dp[100010];

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

    for (int i = 0; i < 100010; ++i) dp[i] = INF;

    dp[0] = 0;

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

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=a,_b=b;i<=_b;i++)
#define rep(i,n) REP(i,0,n-1)
#define FORD(i,b,a) for(int i=b,_a=a;i>=_a;i--)
#define ford(i,n) FORD(i,n-1,0)
#define sqr(x) ((x)*(x))
#define ll long long
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pi>
#define vll vector<ll>
#define fi first
#define se second
#define all(a) a.begin(),a.end()
#define add push_back
#define len(arr) arr.size()
#define print(x) cout<<(x)<<endl
using namespace std;


int main(){
	//freopen("in.txt", "r", stdin);
	int W, H, n, x, y, a;
	cin >> W >> H >> n;
	int w1 = 0, h1 = H, h2 = 0, w2 = W;
	rep(i, n){
		cin >> x >> y >> a;
		if(a == 1){
			w1 = max(x, w1);
		}
		else if(a == 2){
			w2 = min(x, w2);
		}
		else if(a == 3){
			h2 = max(h2, y);
		}
		else h1 = min(h1, y);
	}
//	cout << w1 << " - " << w2 << endl;
//	cout << h1 << " - " << h2 << endl; 

	int w = w2 <= w1 ? 0 : w2 - w1;
	int h = h2 >= h1 ? 0 : h1 - h2;
	
	print(w * h);
	
	return 0;
}



Measured memory_bytes: 256
H, W = map(int, input().split())
C = [list(map(int, input().split())) for i in range(10)]
A = [list(map(int, input().split())) for i in range(H)]

for k in range(10):
    for i in range(10):
        for j in range(10):
            C[i][j] = min(C[i][j], C[i][k] + C[k][j])

ans = 0
for row in A:
    for n in row:
        if n == -1:
            continue
        else:
            ans += C[n][1]

print(ans)

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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

typedef long long ll;
typedef pair<int, int> p;

int main(){
  ll a, b, k;
  cin >> a >> b >>k;
  for (int i = 0; i < k; i++)
  {
    if(i % 2 == 0)
    {
      b += a / 2;
      a /= 2;
    }
    else
    {
      a += b / 2;
      b /= 2;
    }
  }

  cout << a << ' ' << b << endl;

}


Measured memory_bytes: 256
const main = stdin => {
  const input = stdin.trim().split('\n')
  const [A, B] = input[0].split(' ').map(x => parseInt(x))
  if (A < 10 && B < 10) {
    console.log(A * B)
  } else {
    console.log(-1)
  }
}

// 標準入力
main(require("fs").readFileSync("/dev/stdin", "utf8"))


Measured memory_bytes: 30464
from operator import itemgetter
 
n,m=map(int, input().split())
A=[]
B=[]
a=0
b=0
for i in range(m):
  a,b=map(int, input().split())
  A.append([a,b])

A.sort(key=itemgetter(1))
bri=0 #取った橋のうち番号最大の島のもの。bri=5なら4,5番目の島の橋

count=0

for i in range(m):
  a=A[i][0]
  b=A[i][1]
  
  if a>=bri:
    bri=b
    count+=1

print(count)


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define FOR(NAME, START, NUM) for (ll NAME = START; NAME < (NUM); NAME++)
#define REP(NAME, NUM) for (ll NAME = 0; NAME < (NUM); NAME++)
#define BREP(NAME, NUM) for (ll NAME = (NUM)-1; NAME >= 0; NAME--)
#define ALL(NAME) (NAME).begin(), (NAME).end()
const ll INF =1000000000000000;

int main(){
  ll n,m,x,y;
  cin>>n>>m;
  vector<ll> s(0);
  vector<ll> b(0);
  REP(i,m){
    cin>>x;
    cin>>y;
    s.push_back(min(x,y));
    b.push_back(max(x,y));
  }
  sort(ALL(s));
  sort(ALL(b));
  ll ans=b[0]-s[m-1]+1;
  if(ans<0)cout<<0<<endl;
  else cout<<ans<<endl;
}

Measured memory_bytes: 2036