akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " = " << x << endl

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const ll Mod = 1e9 + 7;
const int Maxn = 4e3 + 10;
const ll Inf = 1e8;

pll cut(ll h, ll w){
	if(h % 2 == 0 || w % 2 == 0) return {h * w / 2LL, h * w / 2LL};
	pll a = {Inf, Inf};
	pll b = {Inf, Inf};
	if(w > 1){
		a = {h* (w/2LL), h * (w - (w/2LL))};
	}
	if(h > 1){
		b = {w* (h/2LL), w * (h - (h/2LL))};
	}
	if(max(a.F, a.S) > max(b.F, b.S)) return b;
	return a;
}

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll h, w;
	cin >> h >> w;
	ll ans = h * w;
	ll a, b, c;
	
	for(int i = 1; i < w; i++){
		a = i * h;
		pll res = cut(h, w - i);
		b = res.F;
		c = res.S;
		ans = min( ans, max({a,b,c}) - min({a,b,c}) );
	}
	swap(h, w);
	
	for(int i = 1; i < w; i++){
		a = i * h;
		pll res = cut(h, w - i);
		b = res.F;
		c = res.S;
		ans = min( ans, max({a,b,c}) - min({a,b,c}) );
	}
	cout << ans;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P std::pair<int,int>
#define PiP std::pair<int,std::pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp std::make_pair
#define prique(T) std::priority_queue<T,vector<T>,greater<T>>
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = std::max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = std::min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x != 1;
}
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;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int get_rand(int MIN, int MAX) {
	std::random_device rnd;
	std::mt19937 mt32(rnd());
	std::uniform_int_distribution<int>engine(MIN, MAX);
	return engine(mt32);
}
/*--------Library Zone!--------*/


int n;
int a[15];
int x[15][15], y[15][15];
signed main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
		rep(j, a[i]) {
			cin >> x[i][j] >> y[i][j]; x[i][j]--;
			y[i][j] ^= 1;
		}
	}
	int ans = 0;
	rep(i, 1 << n) {
		int hon[15];
		int cnt = 0;
		rep(j, n) {
			if (i >> j & 1) {
				hon[j] = 0; cnt++;
			}
			else hon[j] = 1;
		}
		rep(j, n) {
			if (hon[j])continue;
			rep(k, a[j]) {
				if (hon[x[j][k]] != (y[j][k] ^ hon[j])) {
					goto ng;
				}
			}
		}
		chmax(ans, cnt);
	ng:;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		System.out.println(a/b + " " + a%b + " " + String.format("%f", (double)a / (double)b)); 
	}
}



Measured memory_bytes: 26516
#include <bits/stdc++.h>
typedef long long LL;
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define RALL(X) (X).rbegin(), (X).rend()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VL vector<long long>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second

using namespace std;

int main(){
    DRIII(na,nb,m);
    VI a(na);
    int mina=10000000;
    VI b(nb);
    int minb=10000000;
    REP(i,na) {RI(a[i]); mina=min(mina,a[i]);}
    REP(i,nb) {RI(b[i]); minb=min(minb,b[i]);}
    int res=mina+minb;
    REP(i,m){
        DRIII(x,y,c);
        x--;
        y--;
        res=min(res,a[x]+b[y]-c);
    }
    printf("%d\n",res);
}


Measured memory_bytes: 1024
import itertools

N = int(input())
P = [int(i) for i in input().split()]
Q = [int(i) for i in input().split()]
P = tuple(P)
Q = tuple(Q)
pm = list(itertools.permutations(list(range(1, N+1))))

a = 0
b = 0

for i in range(len(pm)):
    if pm[i] == P:
        a = i+1
    if pm[i] == Q:
        b = i+1

print(abs(a-b))

Measured memory_bytes: 8052
#include <cstdio>
#include <vector>

int main() {
  int N, M;
  scanf("%d %d", &N, &M);

  std::vector<int> g(N);
  for (int i=0; i<M; ++i) {
    int a, b;
    scanf("%d %d", &a, &b);
    --a, --b;
    ++g[a];
    ++g[b];
  }

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


Measured memory_bytes: 256
#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;
int INF = 1 << 30;

int main(void){

    ll N,M,X; cin>>N>>M>>X;

    vector<ll> C(N,0);
    vector<vector<ll>> A(N,vector<ll>(M,0));

    for (int i = 0; i < N; ++i) {
        cin>>C[i];
        for (int j = 0; j < M; ++j) {
            cin>>A[i][j];
        }
    }

    ll minMoney=INF;

    bool clear=false;
    for (int i = 0; i < (1<<N); ++i) {

        bool ok = true;
        vector<ll> rikai(M,0);
        ll money = 0;
        for (int j = 0; j < N; ++j) {
            if(i & (1<<j)){
                money += C[j];
                for (int k = 0; k < M; ++k) {
                    rikai[k] += A[j][k];
                }
            }
        }

        // check
        for (int l = 0; l < M; ++l) {
            if(rikai[l]<X) {
                ok = false;
                break;
            }
        }

        if(ok==true){
            clear = true;
            minMoney = min(minMoney,money);
        }

    }


    if(clear==true){
        cout<<minMoney<<endl;
    }else{
        cout<<-1<<endl;
    }
    

}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
 
#define speed ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ub(a,x) upper_bound(a.begin(),a.end(),x)-a.begin()
#define lb(a,x) lower_bound(a.begin(),a.end(),x)-a.begin()
#define ll long long int
#define endl "\n"
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define pb push_back
#define PI 3.1415926535897932384626
#define keep_unique(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end());

 
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
// using namespace __gnu_pbds;
// typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;


void solveFunction()
{
    int n;
    cin>>n;
    ll ans = 0;
    for(int i=1;i<=n;i++)
    {
    	for(int j=1;j<=n;j++)
    	{
    		for(int k=1;k<=n;k++)
    		{
    			ans += __gcd(i,__gcd(j,k));
    		}
    	}
    }
    cout<<ans;
}

main()  
{
    speed;
    int t = 1;
    //cin>>t;
    while(t--)
    {
        solveFunction();
    }
}



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

#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) begin(x), end(x)
#define uniq(x) (x).erase(unique(all(x)), end(x))
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr long double PI = 3.1415926535897932384626433832795028L;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int rest_pre(string s) {
    int cur = 0, ret = 0;
    rep(i, s.length()) {
        if (s[i] == ')') { if (cur == 0) { ret++; } else { cur--; }}
        else { cur++; }
    }
    return ret;
}
string rev(string s) {
    reverse(all(s));
    rep(i, s.length()) { s[i] = '(' + ')' - s[i]; }
    return s;
}
int comple(map<int, int> a) {
    int ret = 0;
    for (auto p:a) {
        if (ret < p.first) { return -1; }
        ret += p.second;
    }
    return ret;
}
int N;
string S[1100000];
signed main() {
    cin >> N;
    map<int, int> l, r;
    rep(i, N) {
        cin >> S[i];
        int rest_l = rest_pre(S[i]);
        int rest_r = rest_pre(rev(S[i]));
        if (rest_l < rest_r) { l[rest_l] += rest_r - rest_l; }
        else { r[rest_r] += rest_l - rest_r; }
    }
    int cl = comple(l), cr = comple(r);
    if (cl == -1 || cr == -1 || cl != cr) { cout << "No" << endl; }
    else { cout << "Yes" << endl; }
}


Measured memory_bytes: 39532
#define _USE_MATH_DEFINES
#include <cmath>
#include <iostream>
# include <bits/stdc++.h>
using namespace std;
long long powerexp(long long base, long long exp, int mod) {
   long long res = 1;
   while (exp > 0) {
      if (exp % 2 == 1)
         res= (res * base) % mod;
      exp = exp >> 1;
      base = (base * base) % mod;
   }
   return res;
}
int gcd(int a, int b)
{
    int c = a % b;
    while(c != 0)
    {
        a = b;
        b = c;
        c = a % b;
    }
    return b;
}
void PrintVector(vector<long long int> v,long long int n)
{
 
    for(int i=v.size()-1;i>=0;i--)
    {
        cout<<v[i]<<" ";
    }
    cout<<endl;
}
void Takevector(vector<long long int> &v,long long int n)
{
  for(long long int i=0;i <n;i++)
  { long long int number;
    cin>>number;
    v.push_back(number);
  }
}
typedef long long int ll;
typedef vector<long long int> vi;
#define sci(x)         int x;       scanf("%d", &x);
#define scii(x, y)     int x, y;    scanf("%d %d", &x, &y);
#define sciii(x, y, z) int x, y, z; scanf("%d %d %d", &x, &y, &z);
#define scl(x)         ll x;       scanf("%lld", &x);
#define scll(x, y)     ll x, y;    scanf("%lld %lld", &x, &y);
#define sclll(x, y, z) ll x, y, z; scanf("%lld %lld %lld", &x, &y, &z);
#define TC(x)          sci(x); while(x --)
#define rep(i, x, y)   for (__typeof(x) i = x; i <= y; i ++)
#define repi(i, x, y)  for (__typeof(x) i = x; i >= y; i --)
#define fore(itr, x)   for (__typeof(x.begin()) itr = x.begin(); itr != x.end(); itr ++)
#define forei(itr, x)  for (__typeof(x.end()) itr = x.end() - 1; itr != x.begin() - 1; itr --)
#define nl cout<<"\n";
int min(int x, int y)  
{  
    return (x < y)? x: y;  
      
}  
int main()
{
	sciii(h1,m1,h2);
	scii(m2,k);
	int c=h2*60+m2;
	int x=h1*60+m1;
	c-=k;
	c-=x;
	cout<<c;

}

Measured memory_bytes: 3720
//atcoder problemsに反映されていないので再提出
#include <bits/stdc++.h>
#define FOR(i,bg,ed) for(ll i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
#define int long long
using namespace std;
typedef long long ll;
typedef vector<vector<ll>> mat;
const int INF = 1e9;
 
pair<double, int> vml[4];  //1Lあたりの価値とミリリットル
 
signed main()
{
    int Q, H, S, D;
    int N;
 
    cin >> Q >> H >> S >> D;
    vml[0].first = Q / 0.25;
    vml[0].second = 250;
    vml[1].first = H / 0.5;
    vml[1].second = 500;
    vml[2].first = S;
    vml[2].second = 1000;
    vml[3].first = D / 2.0;
    vml[3].second = 2000;
 
    sort(vml, vml + 4);
    //reverse(vml, vml + 4);
 
    /*
    REP(i,4) {
        cout << vml[i].first << " : " << vml[i].second << endl;
    }
    */
 
    cin >> N;
    N *= 1000;
 
    int ans = 0;
    REP(i,4) {
        if (vml[i].second == 250) {
            ans += N / 250 * Q;
            N %= 250;
        } else if (vml[i].second == 500) {
            ans += N / 500 * H;
            N %= 500;
        } else if (vml[i].second == 1000) {
            ans += N / 1000 * S;
            N %= 1000;
        } else if (vml[i].second == 2000) {
            ans += N / 2000 * D;
            N %= 2000;
        }
    }
 
    cout << ans << endl;
}

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

int main(){
  int n,m;
  cin >> n >> m;
  
  vector<pair<int,int>> a;
  for(int i = 0; i < n; ++i){
    int p,q;
    cin >> p >> q;
    a.push_back({p,q});
  }
  sort(a.begin(),a.end());
  
  long long int res = 0;
  int c = 0;
  
  for(int i = 0; i < n; ++i){
    for(int j = 0; j < a[i].second; ++j){
      ++c;
      res += a[i].first;
      if (c == m){
        break;
      }
    }
    if(c == m){
      break;
    }
  }
  
  cout << res << endl;
    
}

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

int keta(long num){
  for(int i = 1;i<10+1;i++){
    if(num/10 != 0){
      num = num/10;
    }
    else{
      return i;
    }
  }
}

int main(){
  long N;
  cin >> N;
  priority_queue<long, vector<long>,greater<long>> pq;
  for(int i=1;i<=sqrt(N);i++){
    if(N%i==0){
      long A = i;
      long B = N / A;      
      // cout<< max(keta(A),keta(B)) << endl;
      pq.push(max(keta(A),keta(B)));
    }
  }
  cout<< pq.top() << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#include <random>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define gep(i,g,j) for(int i = g.head[j]; i != -1; i = g.e[i].next)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("-1"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,vector<T>,greater<T> >
#define bn(x) ((1<<x)-1)
#define newline puts("")
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;

int n;
vi x; vvi to;

bool dfs(int v, int p=-1) {
  rep(i,sz(to[v])) {
    int u = to[v][i];
    if (u == p) continue;
    if (x[v] <= x[u]) continue;
    if (!dfs(u,v)) return true;
  }
  return false;
}

int main() {
  scanf("%d",&n);
  to = vvi(n);
  x = vi(n);
  rep(i,n) scanf("%d",&x[i]);
  rep(i,n-1) {
    int a,b;
    scanf("%d%d",&a,&b);
    --a; --b;
    to[a].pb(b);
    to[b].pb(a);
  }
  vi ans;
  rep(i,n) {
    if (dfs(i)) ans.pb(i+1);
  }
  cout<<ans<<endl;
  return 0;
}






















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

using namespace std;

#define ff first
#define ss second

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;

const int MOD = 1e9 + 7;
const ll INF = 1e18;
const double EPS = 1e-6;
const int MAX_N = 405;

int N;
ll a[MAX_N];
ll memo[MAX_N][MAX_N];

ll dp(int l, int r) {
	if (l == r) return 0;
	if (memo[l][r] != -1) return memo[l][r];
	ll total = 0;
	for (int i = l; i <= r; ++i) total += a[i];
	ll ret = INF, sum = 0;
	for (int i = l; i < r; ++i) {
		sum += a[i];
		ret = min(ret, dp(l, i) + dp(i + 1, r) + sum + (total - sum));
	}
	return memo[l][r] = ret;
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
	}
	memset(memo, -1, sizeof memo);

	cout << dp(0, N - 1) << '\n';

	return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
typedef long long ll;
#define REP(i,n) for(int i = 0;i < (n);i++)
using namespace std;
const ll INF = 1e10;
string s;
int main(){
  cin>>s;
  int ans=700;
  for(int i=0;i<3;i++){
    if(s[i]=='o')ans+=100;
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <limits>
#include <map>
using namespace std;
void make_insuu(long n,vector<long> & in){
    for(long i=2;i<n+1;i++){
        if(n%i==0){
            in.push_back(i);
            make_insuu(n/i,in);
            break;
        }
    }
}
int main(){
    long n;
    cin >> n;
    long nsqrt = sqrt(n);
    vector<long> insuu;
    //make_insuu(n,insuu);
    //for(auto & e:insuu){
    //    cout << e << endl;
    //}
    long ans=n;
    for(int i = 1; i <= nsqrt; i++){
        if(n%i==0){
            ans=min(ans,i+n/i-2);
        }
    }
    cout << ans << endl;


    return 0;
}

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

using namespace std;

template<typename T> class BIT {
private:
	int n,m; vector<vector<T> > bit;
public:
	void add(int i, int j, T val){
		for(int i_ = i+1; i_ < n; i_ += i_ & -i_){
			for(int j_ = j+1; j_ < m; j_ += j_ & -j_){
				bit[i_][j_] += val;
            }
    	}
    }
    T sum(int i, int j){
		T s = 0;
        	for(int i_ = i+1; i_ > 0; i_ -= i_ & -i_){
            	for(int j_ = j+1; j_ > 0; j_ -= j_ & -j_){
					s += bit[i_][j_];
                }
            }
        	return s;
    }
	T sum(int lx, int uy, int rx, int dy){
		return sum(rx, dy) - sum(lx-1, dy) - sum(rx, uy-1) + sum(lx-1, uy-1);	
	}
    	BIT(int sz1, int sz2){
        	n = sz1 + 1, m = sz2 + 1;
        	bit.resize(n, vector<T>(m, 0));
    	}
    	BIT(vector<vector<T> >& v){
        	n = (int)v.size()+1, m = (int)v[0].size()+1;
        	bit.resize(n, vector<T>(m, 0));
        	for(int i = 0; i < n; i++)
				for(int j = 0; j < m; j++)
					add(i, j, v[i][j]);
    	}
    	void print_sum(){
		for(int i = 0; i < n; i++)
			for(int j = 0; j < m; j++)
 				cout<< sum(i-1, j-1) << " ";
		cout << "\n";
	}
};

int main()
{
	int m, n, K;
	cin >> m >> n >> K;
	vector<BIT<int> > bt(3, BIT<int>(m, n));
	vector<string> s(m);
	for(int i = 0; i < m; i++){
		cin >> s[i];
		for(int j = 0; j < n; j++){
			if(s[i][j] == 'J'){
				bt[0].add(i, j, 1);
			}else if(s[i][j] == 'O'){
				bt[1].add(i, j, 1);
			}else{
				bt[2].add(i, j, 1);
			}
		}
	}
	for(int i = 0; i < K; i++){
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		--a, --b, --c, --d;
		cout << bt[0].sum(a, b, c, d) << " " << bt[1].sum(a, b, c, d) << " " << bt[2].sum(a, b, c, d) << "\n";
	}
	return 0;
}


Measured memory_bytes: 18360
#include<stdio.h>
int main(void)
{
	int x,y,temp;
	int cnt;
	
	scanf("%d %d",&x,&y);
	while(x!=0 && y!=0){
		cnt=0;
		if(x<y){
			temp=x;
			x=y;
			y=temp;
		}
		while(y!=0){
			x=x%y;
			temp=x;
			x=y;
			y=temp;
			cnt++;
		}
		printf("%d %d\n",x,cnt);
		scanf("%d %d",&x,&y);
	}
	return 0;
}

Measured memory_bytes: 600
#include "bits/stdc++.h"

using namespace std;

//using Matrix = vector< vector<int> >;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9 + 10;
//const ll INF = 1e18 + 10LL;
int dx[5] = {0, 0, 1, -1, 0}, dy[5] = {1, -1, 0, 0, 0};
const double EPS = 1e-10;
bool cmp(P a, P b) { return a.second < b.second; } //End sort (Interval scheduling problem)
ll MOD = 1e9 + 7;

ll H, W;

ll ans;
ll s[3];

int main(void){
	cin>>H>>W;

	ans = H * W;
	for (int i = 0; i < 2; i++) {
		for (ll h = 1; h < H; h++) {
			s[0] = h * W;
			s[1] = (H - h) * (W / 2);
			s[2] = H * W - (s[0] + s[1]);
			sort(s, s + 3);
			ans = min(ans, s[2] - s[0]);

			s[0] = h * W;
			s[1] = ((H - h) / 2) * W;
			s[2] = H * W - (s[0] + s[1]);
			sort(s, s + 3);
			ans = min(ans, s[2] - s[0]);
		}

		swap(H, W);
	}

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

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <sstream>
#include <cmath>

using namespace std;

int main(int argc, const char * argv[]) {
    int N; cin >> N;
    vector<int> d(N);
    for (int i = 0; i < N; i++) {
        cin >> d[i];
    }
    sort(d.begin(), d.end());
    
    int c1 = d[(N / 2) - 1];
    int c2 = d[N / 2];
    cout << c2 - c1 << endl;
    
    return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
#define int long long
#define ld long double
#define MAX 100001
#define MOD 1000000007
using namespace std;

bool play(int n,int k, int a[])
{
    bool dp[n][k+1];
    memset(dp,0,sizeof(dp));

    for(int i=1;i<=k;++i)
    {
        bool flag = 0;
        for(int j=0 ;j<n;++j)
        {
            if(a[j] > i)
                continue;

            dp[j][i] = dp[j][i-a[j]]^1;
            flag += dp[j][i];

            if(flag)
                break;
        }
        if(flag)
            for(int j=0;j<n;++j)
                dp[j][i] = 1;
    }

    return dp[0][k];
}

 
int32_t main()
{
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;++i)
        cin>>a[i];

    int player = play(n,k,a);

    if(player)
        cout<<"First"<<endl;
    else
        cout<<"Second"<<endl;

    return 0;
}

Measured memory_bytes: 9984
#include<stdio.h>
int main(){
  int a,b,c,d=0;
  scanf("%d %d %d",&a,&b,&c);
  for(int i=100; 1<=i; i--){
    if(a%i==0&&b%i==0){
      d++;
    }
    if(d==c){
      printf("%d",i);
      break;
    }
  }
  return 0;}

Measured memory_bytes: 128
#include <bits/stdc++.h>
 #define len length
// smile :)
using namespace std;
typedef long long ll;

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


string s;
cin>>s;
if(s=="ABC") cout<<"ARC";
else cout<<"ABC";
 return 0;
}


Measured memory_bytes: 3652
// -_-
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define fi first
#define se second
#define rz resize
#define fori(i, a, b) for(int i = a; i <= b; i++)
#define ford(i, a, b) for(int i = a; i >= b; i--)
#define mod 1000000007
#define  sort1(v) sort(v.begin(), v.end()) 
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair <int, int>> vpi;

 
signed main() 
{

	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	string s;
	cin >> s;
	int l = s.length();
	int final[l], cnt[l] = {}, in[l], temp = 0;

	fori(i, 0, l-1)
	{
		if(s[i] == 'L')
		{
			fori(j, temp, i-1)
			in[j] = i;

			while(s[i] == 'L' && i < l)
				i++;
			temp = i;
			i--;
		}
	}
	temp = l-1;
	ford(i, l-1, 0)
	{
		if(s[i] == 'R')
		{
			ford(j, temp, i+1)
			in[j] = i;

			while(s[i] == 'R' && i >= 0)
				i--;
			temp = i;
			i++;
		}
	}

	fori(i, 0, l-1)
	{
		if(s[i] == 'R')
		{
			if((in[i]-i)%2 == 1) final[i] = in[i]-1;
			else final[i] = in[i];
		}

		if(s[i] == 'L')
		{
			if((i-in[i])%2 == 1) final[i] = in[i]+1;
			else final[i] = in[i];
		}
	}

	fori(i, 0, l-1)
	cnt[final[i]]++;

	fori(i, 0, l-1) cout << cnt[i] << " ";

	return 0;
}

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

int main(){
  int N,Q;cin >> N >> Q;
  string S;cin >> S;
  vector<int> A(N,0);
  for(int i=1;i<N;i++){
    A[i] = A[i-1];
    if(S[i-1]=='A'&&S[i]=='C'){
      A[i] += 1;
    }
  }
  for(int i=0;i<Q;i++){
    int L,R;cin >> L >> R;
    cout << A[R-1]-A[L-1] << endl;
  }
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); (i)--)
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
template<class T> struct LazySegTree{
    int n = 1;
    int initv;
    vector<T> node, lazy;
    vector<bool> flag;

    LazySegTree(int n_, T initv_){
        while(n < n_) n *= 2;
        initv = initv_;
        node.resize(2*n-1, initv);
        lazy.resize(2*n-1, 0);
        flag.resize(2*n-1, false);
    }

    void eval(int i, int l, int r){
        if(!flag[i]) return;
        node[i] = lazy[i];
        if(r - l > 1){
            lazy[i*2+1] = lazy[i];
            flag[i*2+1] = true;
            lazy[i*2+2] = lazy[i];
            flag[i*2+2] = true;
        }
        flag[i] = false;
        lazy[i] = 0;
    }

    void update(int a, int b, int i, T x, int l, int r){
        eval(i, l, r);
        if(r<=a || b<=l) return;
        if(a<=l && r<=b){
            lazy[i] = x;
            flag[i] = true;
            eval(i, l, r);
            return;
        }
        update(a, b, i*2+1, x, l, (l+r)/2);
        update(a, b, i*2+2, x, (l+r)/2, r);
        node[i] = min(node[i*2+1], node[i*2+2]);
    }

    T getmin(int a, int b, int i, int l, int r){
        eval(i, l, r);
        if(r<=a || b<=l) return initv;
        if(a<=l && r<=b) return node[i];
        T vl = getmin(a, b, i*2+1, l, (l+r)/2);
        T vr = getmin(a, b, i*2+2, (l+r)/2, r);
        return min(vl, vr);
    }
};

int main(){
    int n, q; cin >> n >> q;
    LazySegTree<int> lst(n, INT_MAX);
    rep(i, q){
        int c; cin >> c;
        if(c){
            int s, t; cin >> s >> t;
            cout << lst.getmin(s, t+1, 0, 0, lst.n) << endl;
        }
        else{
            int s, t, x; cin >> s >> t >> x;
            lst.update(s, t+1, 0, x, 0, lst.n);
        }
    }
}


Measured memory_bytes: 4940
#include<iostream>
#include<string>
#include<stdio.h>
#include<cctype>
#include<algorithm>
#include<climits>
#include<cmath>
#define INF INT_MAX
using namespace std;

int ans;
int n;
int v[100010];
int m1[100010];
int m2[100010];
pair<int, int>p11, p12;
pair<int, int>p21, p22;

int main(){

	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> v[i];
	}
	  
	for (int i = 0; i < n; i += 2)m1[v[i]]++;

	for (int i = 1; i < n; i += 2)m2[v[i]]++;

	for (int i = 0; i < 100010; i++){
		if (m1[i] > p11.first){
			p12 = p11;
			p11 = { m1[i], i };
		}
		else if (m1[i] > p12.first){
			p12 = { m1[i], i };
		}

		if (m2[i] > p21.first){
			p22 = p21;
			p21 = { m2[i], i };
		}
		else if (m2[i] > p22.first){
			p22 = { m2[i], i };
		}
	}

	if (p11.second != p21.second){
		ans += n / 2 - p11.first;
		ans += n / 2 - p21.first;
		cout << ans << endl;
	}
	else{
		ans += n / 2 - p11.first;
		ans += n / 2 - p22.first;
		ans = min(ans, n - p12.first - p21.first);
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 1408
#include <stdio.h>

int main(void) {
	int i,ii,n,k,s[200],b[200],a,yn;
	while (scanf("%d%d",&n,&k) , n != 0){
		for (i = 0;i <= 199;i++){
			b[i] = 0;
		}
		for(i = 1;i <= k;i++){
			scanf("%d",&a);
			s[i] = a;
		}
		for(i = 1;i <= n;i++){
			for(ii = 1;ii <= k;ii++){
				scanf("%d",&a);
				b[ii] = b[ii] + a;
			}
		}
		yn = 1;
		for(i = 1;i <= k;i++){
			if (s[i] < b[i]){
				yn = 0;
			}
		}
		if (yn == 1){
			printf("Yes\n");
		}
		else{
			printf("No\n");
		}
	}
	return 0;
}
//aoj 1019

Measured memory_bytes: 584
def san(a,b,c):
    if (a**2)==(b**2)+(c**2):
        print('YES')
    elif (b**2)==(a**2)+(c**2):
        print('YES')
    elif (c**2)==(b**2)+(a**2):
        print('YES')
    else:
        print('NO')
N = int(input())
for i in range(N):
    x, y, z = map(int,input().split())
    san(x,y,z)
    


Measured memory_bytes: 5596
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def simulate(mh, mw, H, W, K, grid):
    flags = [[1 for _ in range(W)] for _ in range(H)]
    for h in range(H):
        if not (mh>>h)&1:
            continue
        for w in range(W):
            flags[h][w] = 0
    for w in range(W):
        if not (mw>>w)&1:
            continue
        for h in range(H):
            flags[h][w] = 0
    cnt = 0
    for h in range(H):
        for w in range(W):
            if flags[h][w] and grid[h][w] == '#':
                cnt += 1
    if cnt == K:
        # print(flags)
        # print(mh, mw)
        return 1
    return 0

def main():
    H, W, K = rli()
    grid = []
    for i in range(H):
        grid.append(input())
    ans = 0
    for mh in range(0, 2**H):
        for mw in range(0, 2**W):
            ans += simulate(mh, mw, H, W, K, grid)
    print(ans)



if __name__ == '__main__':
    main()


Measured memory_bytes: 9268
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main() {
    int A, B, C, K;
    ll result = 0;
    cin >> A >> B >> C >> K;
    if (A <= K) {
        result += A;
        K -= A;
    } else {
        result += K;
        K = 0;
    }
    if (B <= K) {
        K -= B;
    } else {
        K = 0;
    }
    if (C <= K) {
        result -= C;
        K -= A;
    } else {
        result -= K;
        K = 0;
    }
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 3652
#include <algorithm>
#include <iostream>
#include <numeric>
#include <set>
#include <vector>
using namespace std;
int main() {
  int H, W, M, ans{};
  cin >> H >> W >> M;
  vector<int> ch(H), cw(W), I(H), J(W);
  iota(begin(I), end(I), 0);
  iota(begin(J), end(J), 0);
  set<pair<int, int>> s;
  while (cin >> H >> W) ++ch[--H], ++cw[--W], s.insert({H, W});
  sort(begin(I), end(I), [&](int i, int j){return ch[i] > ch[j]; });
  sort(begin(J), end(J), [&](int i, int j){return cw[i] > cw[j]; });
  for (auto i : I) for (auto j : J)
      if (ch[i] + cw[j] <= ans) break;
      else ans = max(ans, ch[i] + cw[j] - (int)s.count({i, j}));
  cout << ans << endl;
}


Measured memory_bytes: 22008
from bisect import bisect_left
S = [60,80,100,120,140,160]
W = [2,5,10,15,20,25]
F = [600,800,1000,1200,1400,1600,0]
def func(x,y,h,w):
    return F[max(bisect_left(S,x+y+h),bisect_left(W,w))]
while True:
    n = input()
    if n == 0:
        break
    print sum(func(*map(int,raw_input().split())) for _ in xrange(n))

Measured memory_bytes: 4316
N = int(input())
L = list(map(int, input().split()))

ans = 0
if len(L) < 3:
    print(ans)
    exit()

for i in range(0, N-2):
    Li = L[i]
    for j in range(i+1,N-1):
        Lj = L[j]
        if Li == Lj:
            continue
        for k in range(j+1,N):
            Lk = L[k]
            if Li == Lk or Lj == Lk:
                continue
            Llist = [Li, Lj , Lk]
            Llist.sort()
            if Llist[0] + Llist[1] <= Llist[2]:
                continue
            ans += 1

print(ans)

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

// https://atcoder.jp/contests/abc149/tasks/abc149_b

int main() {
  long a,b,k;
  cin >> a >> b >> k;

  if (a >= k) {
    cout << a - k << ' ' << b << endl;
  } else if (a + b >= k) {
    cout << 0 << ' ' << b - (k - a) << endl;
  } else {
    cout << 0 << ' ' << 0 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using P = pair<int,int>;

int main(){
  int n,m;
  cin>>n>>m;
  vector<P> p(m);
  rep(i,m) cin>>p[i].first>>p[i].second;
  rep(x,1000){
    int keta=1;
    int nx=x/10;
    vector<int>d(1,x%10);
    while(nx){
      keta++;
      d.push_back(nx%10);
      nx /=10;
    }
    if (keta !=n)continue;
    bool ok=true;
    reverse(d.begin(), d.end());
    rep(i,m){
      if(d[p[i].first-1] !=p[i].second) ok=false;
    }
    if(ok){
      cout<<x<<endl;
      return 0;
    }
  }
  cout<<-1<<endl;
  return 0;
}
    
    
    
    
    


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

constexpr long long MOD = 1000000007;

int main() {
  int H, W;
  std::cin >> H >> W;
  std::vector<std::string> S(H);
  for (auto& str: S)
    std::cin >> str;
  std::vector<std::vector<int>> v1(H), v2(W);
  std::vector<std::vector<int>> u1(H), u2(W);
  for (int i = 0; i < H; ++i)
  {
    for (int j = 0; j < W; ++j)
    {
      if (S[i][j] == '#')
      {
        v1[i].push_back(j);
        u1[i].push_back(-j);
      }
    }
  }
  for (int i = 0; i < H; ++i)
    std::sort(u1[i].begin(), u1[i].end());
  for (int i = 0; i < W; ++i)
  {
    for (int j = 0; j < H; ++j)
    {
      if (S[j][i] == '#')
      {
        v2[i].push_back(j);
        u2[i].push_back(-j);
      }
    }
  }
  for (int i = 0; i < W; ++i)
    std::sort(u2[i].begin(), u2[i].end());
  int ans = 0;
  for (int i = 0; i < H; ++i)
  {
    for (int j = 0; j < W; ++j)
    {
      if (S[i][j] == '.')
      {
        int h, w;
        {
          auto it1 = std::upper_bound(v1[i].begin(), v1[i].end(), j);
          auto it2 = std::upper_bound(u1[i].begin(), u1[i].end(), -j);
          int w1 = it1 != v1[i].end() ? *it1 : W;
          int w2 = it2 != u1[i].end() ? -(*it2) + 1 : 0;
          w = w1 - w2;
        }
        {
          auto it1 = std::upper_bound(v2[j].begin(), v2[j].end(), i);
          auto it2 = std::upper_bound(u2[j].begin(), u2[j].end(), -i);
          int h1 = it1 != v2[j].end() ? *it1 : H;
          int h2 = it2 != u2[j].end() ? -(*it2) + 1 : 0;
          h = h1 - h2;
        }
        ans = std::max(ans, h + w - 1);
      }
    }
  }
  std::cout << ans << std::endl;
  return 0;
}



Measured memory_bytes: 68736
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 2000010

/* Rolling Hash */
// n = 9973, 10007, 1073741789, 1036870427, 999999733

struct RollingHash{
  int N, base;
  vector<ll> hash, pow;

  template <typename Type>
  RollingHash(int base, int n, Type *arr):
    N(n), base(base), hash(n+1), pow(n+1)
  {
    hash[0] = 0;
    pow[0] = 1;
    for(int i=0; i<N; i++){
      hash[i+1] = (hash[i] + arr[i]) * base % mod;
      pow[i+1] = pow[i] * base % mod;
    }
  }

  // get [l,r)
  ll getHash(int l, int r) {
    return (mod + hash[r] - hash[l] * pow[r-l] % mod) % mod;
  }
};

char S[SIZE], T[SIZE];
int to[SIZE];
int dp[SIZE];

int main() {
  int N, M;

  scanf("%s%s", S, T);

  N = strlen(S);
  M = strlen(T);

  int loop = (M+N-1)/N;

  for (int i=1; i<loop*2; i++) {
    for (int j=0; j<N; j++) {
      S[i*N+j] = S[j];
    }
  }

  N = loop * N;


  RollingHash Shash1(1073741789, N*2, S), Shash2(1036870427, N*2, S);
  RollingHash Thash1(1073741789, M, T), Thash2(1036870427, M, T);

  for (int i=0; i<N; i++) {
    to[i] = -1;
    dp[i] = -1;
  }

  for (int i=0; i<N; i++) {
    if (Shash1.getHash(i, i+M) == Thash1.getHash(0, M) &&
        Shash2.getHash(i, i+M) == Thash2.getHash(0, M)) {

      to[i] = (i + M) % N;

      if (to[i] == i) {
        cout << -1 << endl;
        return 0;
      }
    }
  }

  for (int i=0; i<N; i++) {
    int now = i;
    int counter = 0;
    while(to[now] != -1 && to[now] != i) {
      if (dp[now] != -1) {
        counter = counter + dp[now];
        break;
      }
      now = to[now];
      counter++;
    }

    if (to[now] == i) counter = INF;

    now = i;
    while(to[now] != -1 && to[now] != i && dp[now] == -1) {
      dp[now] = min(INF, counter);
      now = to[now];
      counter--;
    }
  }

  int ans = 0;

  for (int i=0; i<N; i++) {
    ans = max(ans, dp[i]);
  }

  if (ans == INF) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }



  return 0;
}


Measured memory_bytes: 93824
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <cstring>
#include <string>
#include <cctype>
#include <cassert>
#include <queue>
#include <unordered_set>
#include <unordered_map>

using namespace std;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,b,e) for(int i = (b); i <= (e); i++)
#define INF (1001001001)
#define EPS (1e-15)

#define pr(x) do{cerr << (#x) << " = " << (x) << endl;}while(0)
#define pri(x,i) do{cerr << (#x) << "[" << i << "] = " << (x[i]) << endl;}while(0)
#define pra(x) do{rep(__i,(x).size()) pri(x,__i);}while(0)
#define pran(x,n) do{rep(__i,n) pri(x,__i);}while(0)
#define pral(x) do{cerr << (#x) << " =";rep(__i,(x).size()) cerr<<" "<<(x[__i]);cerr<<endl;}while(0)
#define prar(x,b,e) do{repr(__i,b,e) pri(x,__i);}while(0)

typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;

template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class T,size_t n> ostream& operator<<(ostream &os, const array<T,n> &t) {os<<"{"; rep(i,n) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool CHMAX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool CHMIN(T &l,const T &r){return l>r?l=r,1:0;}

ll MOD = 1000000007;

function<void(int,int)> tensi_no_3p=[&](int v,int d){
};

int in() {
	int a;
	scanf("%d ", &a);
	return a;
}

int main() {
	int N = in();
	int M = in();
	typedef vector<ll> vll;
	const ll INFll = ll(INF) * INF;
	vll pos(N, INFll);
	vector<vector<pint> > G(N);
	rep(i, M) {
		int l = in() - 1;
		int r = in() - 1;
		int d = in();
		G[l].pb(mp(r, d));
		G[r].pb(mp(l, -d));
	}
	function<bool(int)> visit=[&](int v) {
		for (auto &&p : G[v]) {
			int u = p.first;
			int d = p.second;
			if (pos[u] == INFll) {
				pos[u] = pos[v] + d;
				if (! visit(u)) return false;
			}
			else {
				if (pos[u] != pos[v] + d) return false;
			}
		}
		return true;
	};
	rep(i, N) {
		if (pos[i] == INFll) pos[i] = 0;
		if (! visit(i)) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 13312
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	// write your code here
        Scanner scanner = new Scanner(System.in);
        Integer a = scanner.nextInt();
        Integer b = scanner.nextInt();
        Integer c = scanner.nextInt();

        Integer temp = a;
        a = b;
        b = temp;

        temp = a;
        a = c;
        c = temp;

        System.out.format("%d %d %d", a, b, c);
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define int long long
#define P pair<long,long>
#define all(a) a.begin(),a.end()
using namespace std;
signed main(){
    vector<int> l(3);
    bool two=false;
    rep(i,3){
        cin>>l.at(i);
        if(l.at(i)%2==0) two=true;
    }
    sort(all(l));
    int ans=l.at(0)*l.at(1);
    cout<<(two?0:ans)<<endl;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
#define gap ' '
#define L(i) ((i) - (&i))

const int MAXN = 1e9+1;
const int MAX = 1e6 + 1;
const int MOD = 1e9+7;
const int INF = 1e9 + 5; 

int main(){	
	ll x,y; cin >> x >> y;
	ll ans = 0, n = x;
	while(n <= y){
		++ans;
		n*=2;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3584
a=[int(i) for i in input().split()]
#print(a)
#for i in range(a[0]):
#  for j in range(a[1]):

b=[['.']*(a[1]+2)]
b=b+[['.']+[i for i in input()]+['.'] for i in range(a[0])]
b=b+[['.']*(a[1]+2)]

#print(b)
flag=0
for k in range(1,a[0]+1):
  for i in range(1,a[1]+1):
    if b[k][i]=='#':
      if b[k-1][i]=='.' and b[k][i-1]=='.' and b[k][i+1]=='.'and b[k+1][i]=='.':
        flag=1
    
print('Yes' if flag==0 else 'No')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);  
	cin.tie(NULL);
	int arr[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int k;cin>>k;
	cout<<arr[k-1]<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 2000
#define M 1000000
#define White 0
#define Gray 1
#define Black 2

int n, A[N][N];
int prim();

int main(){
  int  i, j, e;

  scanf("%d",&n);

  for(i=0; i<n; i++){
    for(j=0; j<n; j++){
      scanf("%d",&e);
      if(e == -1) A[i][j] = M;
      else A[i][j] = e;
    }
  }

  printf("%d\n",prim());

  return 0;
}

int prim(){
  int i, u, v, minc;
  int data[N], parent[N], color[N];
  int sum = 0;

  for(i=0; i<n; i++){
    data[i]= M;
    parent[i] = -1;
    color[i] = White;
  }
  data[0] = 0;

  while(1){
    minc = M;
    for(i=0; i<n; i++){
      if(minc>data[i] && color[i] != Black){
	u = i;
	minc = data[i];
      }
    }

    if(minc == M) break;
    color[u] = Black;

    for(v=0; v<n; v++){
      if(color[v] != Black && A[u][v] != M){
	if(data[v]>A[u][v]){
	  data[v] = A[u][v];
	  parent[v] = u;
	  color[v] = Gray;
	}
      }
    }
  }

  for(i=0; i<n; i++){
    if(parent[i] != -1){
      sum += A[i][parent[i]];
      /* printf("%d",sum); */
    }
  }
  return sum;
}

Measured memory_bytes: 1040
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
constexpr auto INF = INT_MAX >> 1;
constexpr auto LINF = 5000000000000000;
constexpr auto MOD = 1000000007;

ll dp[55][5200];

int main() {

	int n, a;
	cin >> n >> a;
	vi x(n);
	rep(i, n) {
		int xx;
		cin >> xx;
		x[i] = xx - a;
	}

	dp[0][2500] = 1;

	rep(i, n)rep(j, 5000) {
		dp[i + 1][j] += dp[i][j];
		if (j + x[i] > 5000 || j + x[i] < 0)continue;
		dp[i + 1][j + x[i]] += dp[i][j];
	}

	cout << dp[n][2500] - 1 << endl;

}

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

int main(){
    int N;
    scanf("%d",&N);
    long int sum=0;
    for(int i=1;i<N+1;i++){
        if(!(i%3==0||i%5==0)){
            sum+=i;
        }
    }
    printf("%ld",sum);
    return 0;
}

Measured memory_bytes: 1736
from sys import stdin
import sys
import math

# S は回文である。
# N を S の長さとするとき、 S の 1 文字目から ( N − 1) / 2 文字目まで(両端含む)からなる文字列は回文である。
# S の ( N + 3) / 2 文字目から N 文字目まで(両端含む)からなる文字列は回文である。

S = input()

def is_kaibun(s):
    for i in range(len(s) // 2 + 1):
        if s[i] != s[-(i + 1)]:
            return False
    return True

def is_half_kaibun(s):
    s = s[0:len(s)//2]
    return is_kaibun(s)

if is_kaibun(S) and is_half_kaibun(S):
    print('Yes')
else:
    print('No')


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

#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

map<int, ll> mp;
ll mod = 1e9 + 7;

ll dp(int s) {
    if (s == 0) {
        return 1;
    }
    if (s < 3) {
        return 0;
    }
    if (mp.count(s)) {
        return mp[s];
    }
    ll count = 0;
    for (int i = 3; i <= s; ++i) {
        count = (count + dp(s - i)) % mod;
    }
    mp[s] = count;
    return count;
}

void one_case() {
    int s;
    cin >> s;

    cout << dp(s);


}


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

    int t = 1;
//    cin >> t;
    while (t--) one_case();
    return 0;
}


Measured memory_bytes: 3728
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn ceil(x: usize, y:usize) -> usize {
    (x + y - 1) / y
}


fn main() {
    input! {
        n: usize,
        k: usize,
    }
    if k == 2 {
        println!("{}", n - 1);
        return;
    }
    if k == n {
        println!("{}", 1);
        return;
    }
    println!("{}", ceil(n - 1, k - 1));
}

Measured memory_bytes: 4352