akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <list>
#include <queue>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <math.h>

#define PREP(i, m, n) for(int i = m; i < n; i++)
#define MREP(i, m, n) for(int i = m - 1; i >= n; i--)
using namespace std;

struct point{
	int x;
	int y;
};

bool checkSame(vector<point> sour, vector<point> dest){
	point half, pi, tot, sSub, dSub;
	int size = sour.size();
	//比較対象はどの頂点を原点とみなしても問題ないので、適当に原点に合わせる
	dSub.x = dest[0].x;
	dSub.y = dest[0].y;
	//折れ線を回転させる頂点を変えていく
	for(int i = 0; i < size; i++){
		int count1 = 0, count2 = 0, count3 = 0, count4 = 0;
		//ある頂点が原点に平行移動するのに、他の頂点も合わせるための差分
		sSub.x = sour[i].x;
		sSub.y = sour[i].y;
		//ある頂点が原点にあると仮定して、その頂点に合わせて回転させた頂点とターゲットの頂点を比較し、全て一致したらtrueを返す
		for(int j = 0; j < size; j++){
			//ある点を平行移動した後90度回転
			half.x = (sour[j].y - sSub.y) * -1;
			half.y = sour[j].x - sSub.x;
			//ある点を平行移動した後180度回転
			pi.x = (sour[j].x - sSub.x) * -1;
			pi.y = (sour[j].y - sSub.y) * -1;
			//ある点を平行移動した後270度回転
			tot.x = half.x * -1;
			tot.y = half.y * -1;
	
			if(sour[j].x - sSub.x == dest[j].x - dSub.x && sour[j].y - sSub.y == dest[j].y - dSub.y){
				count1++;
			}
			if(half.x == dest[j].x - dSub.x && half.y == dest[j].y - dSub.y){
				count2++;
			}
			if(pi.x == dest[j].x - dSub.x && pi.y == dest[j].y - dSub.y){
				count3++;
			}
			if(tot.x == dest[j].x - dSub.x && tot.y == dest[j].y - dSub.y){
				count4++;
			}
		}
		if(count1 == size || count2 == size || count3 == size || count4 == size) return true;
	}
	return false;
}

int main(){
	int n = 0;
	while(cin >> n && n != 0){
		vector<vector<point> > vertex;
		vector<int> same;
		for(int i = 0; i < n + 1; i++){
			int m = 0;
			cin >> m;
			
			//折れ線の頂点を収納
			vector<point> a;
			for(int j = 0; j < m; j++){
				point tmp;
				cin >> tmp.x >> tmp.y;
				a.push_back(tmp);
			}
			
			vertex.push_back(a);
			//折れ線一個目ならiを進める
			if(!i){
				continue;
			}
			
			//逆順経路の場合に、逆順を元の順に戻す
			vector<point> tmp(m);
			reverse_copy(vertex[i].begin(), vertex[i].end(), tmp.begin());

			//元々受け取った頂点順、もしくは逆順で同じ折れ線になるかをチェックする
			if(checkSame(vertex[0], vertex[i]) || checkSame(vertex[0], tmp)){
				same.push_back(i);
			}
		}
		for(int i = 0; i < same.size(); i++){
			cout << same[i] << endl;
		}
		cout << "+++++" << endl;
	}
	return 0;
}

Measured memory_bytes: 1232
#include <stdio.h>

int main(void)
{
  int s,w;
  
  do {
  	scanf("%d %d",&s,&w);
  } while((s<1 || s>100)||(w<1 || w>100));
  
  if(s>w)
    puts("safe");
  else
    puts("unsafe");
  
  return 0;
}

Measured memory_bytes: 1664
import std.stdio;
import std.conv;
import std.algorithm;
import std.range;
import std.string;
import std.typecons;
import std.math;
import std.range;
auto gcd(T)(T x, T y)
{
    if (x < y)
        x.swap(y);
    while (y > 0)
    {
        auto r = x % y;
        x = y;
        y = r;
    }
    return x;
}
void main()
{
    auto a = readln().strip.split(" ").map!(to!int);
    auto x = a[0];
    auto y = a[1];
    writeln(gcd(x, y));
}


Measured memory_bytes: 2500
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long ll;

typedef long double ld;
typedef pair<ll,ll> pp;
typedef tree<pp,null_type,less<pp>,rb_tree_tag,tree_order_statistics_node_update> super_set;

#define x1 dfds
#define y1 dsfdsfe
#define pb push_back
#define forn(i,n) for(ll i = 1;i<=n;++i)
#define fi first
#define sc second
#define endl '\n'
#define po(x) (1ll<<x)
#define log sdfdsfdsf

const ll DIM = 2E5+7;
const ll MOD = 1e9+7;

const ll INF = 1E9;
const ld eps = 0.00000000000001;
const ld PI = 3.14159265358979323846;
int getInt(int a = 0, int b = INT_MAX){
    static mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    return uniform_int_distribution <int> (a, b)(rng);
}
struct node{
    ll fi,sc,pos;
};
const bool operator<(const node &a,const node &b){
    if (a.fi==b.fi)return a.sc<b.sc;
    return a.fi<b.fi;
}
node A[DIM];
ll P[DIM],sz[DIM],ans[DIM];
ll F(ll x){
    if (x==P[x])return x;
    return P[x] = F(P[x]);
}
void unite(ll x,ll y){
    x = F(x);
    y = F(y);
    if (x==y)return;
    if (rand()%2)swap(x,y);
    P[x] = y;
    A[y].sc = min(A[x].sc,A[y].sc);
    sz[y]+=sz[x];
}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll n;
    cin>>n;
    forn(i,n)cin>>A[i].fi>>A[i].sc;

    forn(i,n)A[i].pos=  i;
    forn(i,n){
        P[i] = i;
        sz[i] = 1;
    }
    sort(A+1,A+1+n);
    priority_queue<pp,vector<pp>,greater<pp> > Q;
    forn(i,n){
        ll ct = A[i].sc;
        while(!Q.empty() && Q.top().fi<=ct){
            pp t = Q.top();
            Q.pop();
            unite(i,t.sc);
        }
        Q.push({A[F(i)].sc,F(i)});
    }
    forn(i,n){
        ans[A[i].pos] = sz[F(i)];

    }
    forn(i,n)cout<<ans[i]<<endl;
    return 0;
}


Measured memory_bytes: 15976
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double PI = acos(-1);
const ll MOD = 1000000007;

int main() {
  int N; cin >> N;
  vector<ll> a(N),b(N),c(N);
  for (int i = 0; i < N; i++) cin >> a[i];
  
  b[0] = a[0];
  for (int i = 1; i < N; i++) b[i] = b[i-1] + a[i];
  for (int i = 0; i < N; i++) c[i] = b[N-1] - b[i];
  
  ll ans = 1e18;
  for (int i = 0; i < N-1; i++) ans = min(ans,abs(b[i]-c[i]));
  
  
  cout << ans << endl;
}

Measured memory_bytes: 4992
import sys

import bisect

# from collections import Counter, deque, defaultdict
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd

import itertools

# from operator import attrgetter, itemgetter
import math

# import numpy as np

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(input())

    ones = [1]
    sixs = [6, 36, 216, 1296, 7776, 46656]
    nines = [9, 81, 729, 6561, 59049]
    withdraws = ones + sixs + nines

    money = {0}
    cnt = 0

    while True:
        cnt += 1
        next_money = set()
        for i in money:
            for j in withdraws:
                nxt = i + j
                if nxt <= n:
                    next_money.add(nxt)
        if n in next_money:
            print(cnt)
            sys.exit()
        else:
            money = next_money


if __name__ == '__main__':
    main()


Measured memory_bytes: 65724
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

struct node
{
	int c;
	int a[15];
}book[15];

int main()
{
//	freopen("input.txt","r",stdin);
	
	int n,m,x;
	cin>>n>>m>>x;
	for(int i=0;i<n;i++)
	{
		cin>>book[i].c;
		for(int j=0;j<m;j++) cin>>book[i].a[j];
	}
//	for(int i=0;i<n;i++)
//	{
//		cout<<book[i].c<<" ";
//		for(int j=0;j<m;j++) cout<<book[i].a[j];
//		puts("");
//	}
	int ans=-1;
	for(int i=0;i<(1<<n);i++)
	{
		int sum=0;
		int b[m+5];//随机值啊 
		memset(b,0,sizeof b); 
		for(int j=0;j<n;j++)
			if((i>>j)&1)
			{
				sum+=book[j].c;
				for(int k=0;k<m;k++) b[k]+=book[j].a[k];
			}
		bool flag=1;
		for(int j=0;j<m;j++) if(b[j]<x) flag=0;
		if(flag)
		{
			if(ans==-1) ans=sum;
			else ans=min(ans,sum);
		}
	}
	cout<<ans<<endl;
	
	return 0;
 } 
 
//每行第一个数前不输出 
 

 
 
 
 
 

Measured memory_bytes: 3596
#include<stdio.h>                
                                 
signed main()                    
{                                
  int n,a,b;                     
  int x;                         
  scanf("%d %d %d",&n,&a,&b);    
                                 
  if( a * n > b ){               
    x = b;                       
  }                              
  else{                          
    x = a * n;                   
  }                              
                                 
  printf("%d\n",x);              
                                 
  return 0;                      
}                                

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

int main(void){
    ll x;
    cin >> x;

    ll tmp = x / 100;
    while(tmp){
        ll diff = x - tmp * 100;
        ll count = 0;
        count += diff / 5;
        diff = diff - (diff / 5) * 5;
        count += diff / 4;
        diff = diff - (diff / 4) * 4;
        count += diff / 3;
        diff = diff - (diff / 3) * 3;
        count += diff / 2;
        diff = diff - (diff / 2) * 2;
        count += diff / 1;
        if(count <= tmp){
            cout << 1 << endl;
            return 0;
        }
        tmp--;
    }
    cout << 0 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int a;
	int b;
	int h;
	int size;
	int tmp;
	tmp = scanf("%d", &a);
	tmp = scanf("%d", &b);
	tmp = scanf("%d", &h);

	if (h < 1)return 0;

	size = (a + b) * h/2;

	tmp = printf("%d", size);
	return 0;
}

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

typedef long long ll;
typedef pair<int,int> pii;
int n,m,a;
priority_queue<pii> pq;
int main()
{
    ios_base::sync_with_stdio(false);
    cin>>n>>m;
    for(int i=0;i<n;i++)
    {
        cin>>a;
        pq.push({a-a/2,a});
    }
    for(int i=0;i<m;i++)
    {
        a=pq.top().second;
        pq.pop();
        a/=2;
        pq.push({a-a/2,a});
    }
    ll res=0;
    while(!pq.empty())
    {
        res+=pq.top().second;
        pq.pop();
    }
    cout<<res;
    return 0;
}


Measured memory_bytes: 1400
def solve():
  raw = input().split()
  K = int(raw[0])
  N = int(raw[1])
  vals = [None] * N
  ans = 99999999
  raw = input().split()
  for i in range(N):
    vals[i] = int(raw[i])
  for i in range(N):
    cc = -1
    if i == 0:
      cc = vals[N-1] - vals[0]
    else:
      cc = vals[i-1] + K - vals[i]
    ans = min(ans, cc)
  print(ans)
solve()
  


Measured memory_bytes: 26444
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> P(N);
    for (auto& p : P) {
        cin >> p;
    }
    int ans = 0;
    rep(i, 0, N - 1) {
        if (P[i] == i + 1) {
            swap(P[i], P[i + 1]);
            ++ans;
        }
    }
    if (P.back() == N) {
        ++ans;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>

constexpr int MAX_N = 100;

int n, m;

struct edge {
	int from_, to_, cost_;
	edge() = default;
	edge(int from, int to, int cost) : from_(from), to_(to), cost_(cost) {}
	bool operator<(const edge& rhs) {
		return (cost_ == rhs.cost_) ? from_ < rhs.from_ : cost_ < rhs.cost_;
	}
};

std::vector<edge> edges;

class Union_find {
	int par[MAX_N], rank[MAX_N];
public:
	Union_find() {
		for (int i = 0; i < n; ++i) {
			par[i] = i;
			rank[i] = 0;
		}
	}
	int find(int x) {
		if (x == par[x])
			return x;
		return par[x] = find(par[x]);
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (rank[x] < rank[y])
			std::swap(x, y);
		par[y] = x;
		rank[x] += rank[y];
	}
};

int main() {
	while (1) {
		std::cin >> n >> m;
		if (n + m == 0)
			break;
		edges.clear();
		Union_find uni;
		int a, b, c;
		for (int i = 0; i < m; ++i) {
			std::cin >> a >> b >> c;
			edges.emplace_back(a, b, c);
		}
		std::sort(edges.begin(), edges.end());
		int ans = 0;
		for (int i = 0; i < edges.size(); ++i) {
			if (!uni.same(edges[i].from_, edges[i].to_)) {
				uni.unite(edges[i].from_, edges[i].to_);
				ans += edges[i].cost_;
			}
		}
		std::cout << ans << std::endl;
	}
	return 0;
}

Measured memory_bytes: 3048
k, t = map(int, input().split())
a = list(map(int, input().split()))

pre = -1
ans = 0
for i in range(k):
    m = 0
    mi = 0
    for j in range(t):
        if m < a[j] and j != pre:
            m = a[j]
            mi = j
    if m == 0:
        a[pre] -= 1
        ans += 1
    else:
        a[mi] -= 1
        pre = mi
print(ans)

Measured memory_bytes: 3064
def f(x,y):
	list=[0]
	for z in y:
		for i in range(len(list)-1,-1,-1):
			tmp=x.find(z,list[i])+1
			if tmp:
				if i+1 < len(list):
					list[i+1]=min(list[i+1],tmp)
				else:
					list.append(tmp)
	return len(list)-1
 
n=int(input())
for i in range(n):
	x=input()
	y=input()
	print(f(x,y))


Measured memory_bytes: 5616
s = input()

op_count = len(s) - 1
op_list = []
for i in range(2**op_count):
    op = [''] * op_count
    for j in range(op_count):
        if (i >> j) & 1:
            op[op_count - 1 - j] = '+'
    op_list.append(op)

ans = 0
for i in range(2**op_count):
    cur = 1
    t = s
    for j in range(op_count):
        if op_list[i][j] == '+':
            t = t[:j + cur] + "+" + t[j + cur:]
            cur += 1
    ans += eval(t)
print(ans)

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


int N;
vector<string> S;
vector<int> T;
string X;


void input() {
    cin >> N;
    S = vector<string>(N);
    T = vector<int>(N);
    rep(i, N) cin >> S[i] >> T[i];
    cin >> X;
}


int main() {
    input();
    vector<int> sum(N+1);
    sum[0] = 0;
    rep(i, N) sum[i+1] = sum[i] + T[i];
    int x = 0;
    while (S[x] != X) x++;
    int ans = sum.back() - sum[x+1];
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define mod 838627288460106
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;

int main()
{
    fast_io
    ll x,y,i,j,cur,cnt=0;
    cin>>x>>y;
    cur=x;
    while(cur<=y)
    {
        cur=cur*2;
        cnt++;
    }
    cout<<cnt<<endl;

    return 0;
}





Measured memory_bytes: 3632
#include <stdio.h>
#include <string.h>

int	main(void)
{
	char	s[1001], t[1001];
	int	lenS, lenT, diff, ans = 1001;

	scanf("%s%s", s, t);
	lenS = strlen(s);
	lenT = strlen(t);
	for (int i = 0; i <= lenS - lenT; i++)
	{
		diff = 0;
		for (int j = 0; j < lenT; j++)
			if (s[i + j] != t[j])
				diff++;
		if (ans > diff)
			ans = diff;
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 2156
import Control.Applicative
import Data.List

main = do
  n <- read <$> getLine :: IO Int
  xs <- (map read).words <$> getLine :: IO [Int]
  let m = length $ filter not $ zipWith (==) xs [1..n]
  if m == 0 || m == 2 then putStrLn "YES" else putStrLn "NO"


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

typedef long long ll;

// chmax, chmin
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 N;
    string S;
    cin >> N;
    cin >> S;
    
    int ans = 0;
    for ( int i = 1; i < N; ++i){
        int ans_sub = 0;
        vector<int> used(26,0);
        for ( int j = 0; j < i; ++j){
            int x = S[j] - 'a';
            used[x] = 1;
        }
        for ( int k = i; k < N; ++k){
            int y = S[k] - 'a';
            if ( used[y] == 1 ){
                used[y] = 2;
            }
        }
        for ( int l = 0; l < 26; ++l){
            if ( used[l] == 2 ) ++ ans_sub;
        }
        chmax(ans,ans_sub);
        
        /*cout << "i " <<  i << endl;
        for ( auto x : used ){
            cout << x << " " ;
        }
        cout << endl;*/
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <sstream>
using namespace std;

typedef long long LL;
#define lowbit(x) ((x)&(-x))
#define INF 0x3f3f3f3f
#define memset(a,b) memset(a,b,sizeof(a))
#define	GE() printf(">----------\n")
#define	IN() freopen("in.txt","r",stdin)
#define	OUT() freopen("out.txt","w",stdout)
const int mod=1e9+7;
const LL inf=0x3f3f3f3f3f3f3f3f;
const double pi=acos(-1.0);
const double eps=1e-8;
const int maxn=100005;

int n, p;
vector<int> E[maxn];
int vis[maxn];

int dfs(int u, int step){
    vis[u]=1;
    int y=0;
    if(u==n){
        int mid=step/2+1+step%2;
        if(step==mid)p=u;
        return mid;
    }
    for(int i=0;i<E[u].size();i++){
        int v=E[u][i];
        if(!vis[v]){
            int mid=dfs(v, step+1);
            y|=mid;
            if(mid&&step==mid&&!p)p=u;
        }
    }
    return y;
}

int dfs2(int u){
    vis[u]=1;
    if(u==p)return 0;
    int add=0;
    for(int i=0;i<E[u].size();i++){
        int v=E[u][i];
        if(!vis[v]){
            add+=dfs2(v);
        }
    }
    return add+1;
}

int main() {
    while(~scanf("%d", &n)){
        p=0;
        int u, v;
        for(int i=1;i<=n;i++)E[i].clear();
        for(int i=0;i<n-1;i++){
            scanf("%d%d", &u, &v);
            E[u].push_back(v);
            E[v].push_back(u);
        }
        memset(vis, 0);
        dfs(1, 1);
        memset(vis, 0);
        int sum=dfs2(1);
        printf("%s\n", sum>n-sum?"Fennec":"Snuke");
    }
    return 0;
}


Measured memory_bytes: 13952
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

N,K = II()
A = [0] + III()

S = []
temp = 0
for i,a in enumerate(A):
    temp += a
    S.append((temp-i)%K)

d = defaultdict(int)
ans = 0
for i in range(N+1):
    ans += d[S[i]]
    d[S[i]] += 1
    if i-K+1>=0:
        d[S[i-K+1]] -= 1

print(ans)

Measured memory_bytes: 111072
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <cstdarg>
#include <sys/time.h>
#include <fstream>
//#include "cout.h"

using namespace std;

#define SZ(x) ((int)x.size())
#define MSET(x,a) memset(x, a, (int)sizeof(x))
#define PB push_back
#define VI vector < int >
#define PII pair < int, int >
#define LL long long
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define FIT(it,v) for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define OUT(A) cout << #A << " = "<< (A) << endl
#define OUT2(A, B) cout << "(" << #A << ", " << #B << ") = (" << (A) << ", "<< (B) << ")" << endl
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }

#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(ALL(c), (e)) != (c).end())

int x[20][20];

void solve() {
  int n, d;
  cin >> n >> d;
  REP(i, n) REP(j, d) cin >> x[i][j];
  int res = 0;
  REP(i, n) FOR(j, i+1, n) {
    bool end = false;
    FOR(a, 1, 1000) {
      if (!end) {
        LL c = 0;
        REP(k, d) c += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
        if (a*a == c) {
          end = true;
          res++;
        }
      }
    }
  }
  cout << res << endl;
}

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


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

const int MOD=1000000007;
ll ppow(ll a,ll b){
	a%=MOD;
	ll res=1;
	while(b){
		if(b&1)res=(res*a)%MOD;
		a=(a*a)%MOD;
		b>>=1;
	}
	return res;
}
class Fact{
	vector<ll>fact;
	vector<ll>inv;
public:
	Fact(){}
	Fact(int n){
		n=n*2+10;
		fact=inv=vector<ll>(n);
		fact[0]=inv[0]=1;
		for(int i=1;i<n;i++){
			fact[i]=(fact[i-1]*i)%MOD;
		}
		inv[n-1]=ppow(fact[n-1],MOD-2);
		for(int i=n-2;i>=0;i--){
			inv[i]=(inv[i+1]*(i+1))%MOD;
		}
	}
	ll get(int n){
		return fact[n];
	}
	ll get_inv(int n){
		return inv[n];
	}
	ll nPr(int n,int r){
		return fact[n]*inv[n-r]%MOD;
	}
	ll nCr(int n,int r){
		return nPr(n,r)*inv[r]%MOD;
	}
	ll nrP(int n,int r){
		return nPr(n+r,n);
	}
	ll nrC(int n,int r){
		return nCr(n+r,n);
	}
};
int main(){
	int x,y;cin>>x>>y;
	int b=x-(x+y)/3;
	int a=x-2*b;
	if(a<0||b<0||a+2*b!=x||b+2*a!=y){
		puts("0");return 0;
	}
	Fact fac(2000000);
	cout<<fac.nCr(a+b,a)<<endl;
}

Measured memory_bytes: 62720
#include <iostream>
#include <sstream>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <cstdint>
#include <cmath>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

#define N_TIMES(i, n)     for ( uint64_t i = 0;     i <  n; ++i )
#define N_TIMES_REV(i, n) for (  int64_t i = n - 1; i >= 0; --i )

using namespace std;

int main()
{
  uint64_t N, P;
  cin >> N >> P;

  string s;
  cin >> s;

  vector<uint64_t> S(N);
  N_TIMES(n, N) { S[n] = s[n] - '0'; }

  uint64_t ans = 0;
  if (10 % P == 0) { // P == 2, 5
    N_TIMES(n, N) {
      if (S[n] % P == 0) {
        ans += n + 1;
      }
    }
  } else { // P != 2, 5
    reverse(S.begin(), S.end());

    uint64_t base = 1;
    vector<uint64_t> T(N + 1, 0);
    N_TIMES(n, N) {
      T[n + 1] = ((S[n] * base) + T[n]) % P;
      base = (base * 10) % P;
    }

    vector<uint64_t> C(P, 0);
    N_TIMES(n, N + 1) { ++C[ T[n] ]; }

    N_TIMES(p, P) {
      if (C[p] > 1) {
        ans += (C[p] * (C[p] - 1)) / 2;
      }
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3716
#include<iostream>
#include<set>
using namespace std;
int n;
multiset<int>s;
int main(){
	ios::sync_with_stdio(false);
	cin >> n;
	for(int i=1; i<=n ;i++){
		int x;cin >> x;
		s.insert(x);
	}
	int ans=0;
	while(!s.empty()){
		multiset<int>::iterator it=s.end();
		--it;
		int cur=*it;
		s.erase(it);
		for(int i=30; i>=0 ;i--){
			auto it2=s.lower_bound((1<<i)-cur);
			if(it2!=s.end() && *it2==(1<<i)-cur){
				ans++;
				s.erase(it2);
				break;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 9600
/*+lmake
 * STD = c++14
 * DEFINE += MDEBUG
 */
#include <bits/stdc++.h>
using namespace std;
using LL=long long;
#ifdef DEBUG
     #define debug(args...)            {dbg,args; cerr<<endl;}
#else
    #define debug(args...)              // Just strip off all debug tokens
#endif

struct debugger
{
    template<typename T> debugger& operator , (const T& v)
    {    
        cerr<<v<<" ";    
        return *this;    
    }
} dbg;
#define MAXN 2000
LL t[MAXN+10],t2[MAXN+10];
void solve(long long N, long long K, long long Q, vector<long long> A){
    LL ans=INT_MAX;
    A.push_back(-1);
    for(int i=0; i<N; ++i) {
        int Min=A[i];
        int l=0;
        int c=0;
        for(int j=0; j<=N; ++j) {
            if (A[j]<Min) {
                int r=j-1;
                if (r-l+1>=K) {
                    for(int p=l; p<=r; ++p) {
                        t[p]=A[p];
                    }
                    int num=r-l+1-K+1;
                    std::nth_element(t+l,t+(l+num-1),t+r+1);
                    for(int p=l; p<=l+num-1; ++p) {
                        t2[++c]=t[p];
                    }
                } 
                l=j+1;
            }
        }
        if (c<Q) continue;
        std::nth_element(t2+1,t2+Q,t2+1+c);
        ans=min(ans,t2[Q]-Min);
    }
    cout<<ans<<endl;
}

int main(){ 
#ifdef MDEBUG
    //freopen("in.txt","r",stdin);
#endif
    long long K;
    long long Q;
    long long N;
    scanf("%lld",&N);
    vector<long long> A(N-1+1);
    scanf("%lld",&K);
    scanf("%lld",&Q);
    for(int i = 0 ; i <= N-1 ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, K, Q, A);
    return 0;
}

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

// dump macro{{{
// http://www.creativ.xyz/dump-cpp-652
#define DUMPOUT cerr // 変数ダンプ先。coutかcerr

#ifdef PCM
// 引数はいくつでもどんな型でも可（ストリーム出力演算子があればOK）
#define dump(...) DUMPOUT<<"  "; \
  DUMPOUT<<#__VA_ARGS__; \
  DUMPOUT<<":=> "; \
  dump_func(__VA_ARGS__); DUMPOUT<<"in ["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl;
#define dump_1d(x,n) DUMPOUT <<"  " \
  <<#x<<"["<<#n<<"]"<<":=> {"; \
  rep(i,n){ DUMPOUT << x[i] << (((i)==(n-1))?"}":", "); } DUMPOUT <<" in [" << __LINE__ << "]" << endl;

#define dump_2d(x,n,m) DUMPOUT <<"  " \
    <<#x<<"["<<#n<<"]"<<"["<<#m<<"]"<<":=> \n"; \
    rep(i,n)rep(j,m){ DUMPOUT << ((j==0)?"     |":" ") << x[i][j] << (((j)==(m-1))?"|\n":" "); } \
    DUMPOUT <<"  in [" << __LINE__ << "]" << endl;
#else
#define dump(...) 42
#define dump_1d(...) 42
#define dump_2d(...) 42
#endif

// デバッグ用変数ダンプ関数
void dump_func() {
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&&... tail)
{
    DUMPOUT << head;
    if (sizeof...(Tail) == 0) {
        DUMPOUT << " ";
    }
    else {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}

// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec) {
    os << "{";
    for (int i = 0; i<vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}/*}}}*/

#define rep(i, x) for(int i = 0; i < (int)(x); i++)/*{{{*/
#define reps(i,x) for(int i = 1; i <= (int)(x); i++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define RFOR(i, m, n) for(int i = m;i >= n;i--)
#define foreach(x,a) for(auto& (x) : (a) )
#define all(x) (x).begin(),(x).end()
#define sum(v) accumulate(all(v), 0)
#define sz(x) ((int)(x).size())
#define fill(x,y) memset(x,y,sizeof(x))
#define pb(a) push_back(a)
#define INF 2147483647
#define INFLL 1000000000000000000LL
#define MOD 1000000007/*}}}*/

struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;/*{{{*/
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<vii> vvii;
typedef tuple<int,int,int> iii;
typedef set<int> si;
typedef complex<double> pnt;
typedef vector<pnt> vpnt;
typedef priority_queue<pii,vii,greater<pii> > spq;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

/*}}}*/

// global variables

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

  int cnt =1;
  char now = s[0];
  FOR(i, 1, s.size()){
    if (s[i]!=now){
      cnt++;
      now = s[i];
    }
  }

  std::cout << cnt-1 << std::endl;

  return 0;
}


Measured memory_bytes: 512
s=input()
m=int(s[:2])
n=int(s[2:])
flag1=1<=m and m<=12
flag2=1<=n and n<=12
if flag1 and flag2 : print("AMBIGUOUS")
elif flag1 : print("MMYY")
elif flag2 : print("YYMM")
else : print("NA")

Measured memory_bytes: 3060
N=int(input())
T=[int(input()) for _ in range(N)]
T=list(set(T))
N=len(T)
#print(T)

def gcd(a,b):
  if b==0:
    return a
  else:
    return gcd(b,a%b)

ans=T[0]
for i in range(N):
  #print(ans)
  ans=ans*T[i]//gcd(ans,T[i])
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)
#define INF 1<<29;


int main()
{
    int n,m;
    cin >> n >> m;
    vector<int> a(m);
    vector<int> b(m);
    rep(i,m) cin >> a[i] >> b[i];

    vector<pair<int,int>> c;
    rep(i,m) c.push_back({b[i],a[i]});
    sort(c.begin(),c.end());

    int rb = -1;
    int cnt = 0;
    rep(i,m)
    {
        int ai = c[i].second;
        int bi = c[i].first;
        if(ai < rb) continue;
        rb = bi;
        cnt++;
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 2168
#include <stdio.h>
#include <stdlib.h>
//#include <string.h>
//#include <limits.h>
//#include <math.h>

//昇順
int acs(const void *a, const void *b) {
  return *(int *)a - *(int *)b;
}

int main() {
  int n;
  scanf("%d", &n);
  int tmp, a[n], b; long ans = 0;
  for (int i=0; i<n; i++) {
    scanf("%d", &tmp);
    a[i] = tmp-i-1;
  }
  qsort(a, n, sizeof(int), acs);
  b = a[n/2];
  for (int i=0; i<n; i++) ans += abs(a[i]-b);
  printf("%ld\n", ans);
  return 0;
}


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

using namespace std;
typedef pair<int,int> pii;
const double PI = acos(-1);
const int MAXN = 200010;
int nowarn;

int sx, sy, tx, ty, n, x[MAXN], y[MAXN];
vector<pii> pt;
vector<int> a;

bool cmpl( int a, int b ) {
	return a < b;
}
bool cmpg( int a, int b ) {
	return a > b;
}

int f[MAXN], fn = 0;
int lis( bool cmp(int,int) ) {
	for( int i = 0; i < (int)a.size(); ++i ) {
		int x = a[i];
		int low = 0, high = fn;
		while( low < high ) {
			int mid = (low + high)/2;
			if( cmp( f[mid], x ) ) low = mid + 1;
			else high = mid;
		}
		f[low] = x;
		if( low == fn ) ++fn;
	}
	return fn;
}

void solve() {
	if( sx > tx )
		swap(sx, tx), swap(sy, ty);
	int up = min(sx, tx);
	int down = max(sx, tx);
	int left = min(sy, ty);
	int right = max(sy, ty);
	for( int i = 0; i < n; ++i )
		if( x[i] >= up && x[i] <= down && y[i] >= left && y[i] <= right )
			pt.push_back( pii( x[i], y[i] ) );
	sort( pt.begin(), pt.end() );
	for( int i = 0; i < (int)pt.size(); ++i )
		a.push_back( pt[i].second );
	int cnt = lis( sy < ty ? cmpl : cmpg );
	double ans = down - up + right - left;
	ans *= 100;
	ans -= cnt * (20 - 5*PI);
	if( cnt == min(right-left+1, down-up+1) )
		ans += 5*PI;
	printf( "%.16lf\n", ans );
}

int main() {
	nowarn = scanf( "%d%d%d%d%d", &sx, &sy, &tx, &ty, &n );
	for( int i = 0; i < n; ++i )
		nowarn = scanf( "%d%d", x+i, y+i );
	solve();
	return 0;
}


Measured memory_bytes: 6000
#include <bits/stdc++.h>
using namespace std;
int main(void){
  long long int n,m,ans;
  cin>>n>>m;
  ans=-1;
  for(long long int i=1;i<1001;i++){
  	if(int(i*0.08)==n&&int(i*0.1)==m){
  		ans=i;
  		cout<<ans<<endl;
  		return 0;
  	}
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.math.*;
public class Main{
        public static void main(String[] arg) throws IOException {
                BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
                String is; 
                String[] ia; 

                final BigInteger N = new BigInteger("1001");
                ArrayList<Integer> al; 
                while((is = in.readLine()) != null){
                        ia = is.split(" ");
                        int V = Integer.parseInt(ia[0]);
                        int d = Integer.parseInt(ia[1]);
                        if(V == 0){ 
                                System.out.println(0);
                                continue;
                        }   
                        BigInteger a = BigInteger.ONE, b = BigInteger.ONE, c;
                        al = new ArrayList<Integer>();
                        for(int i = 0;i < V; ++i){
                                c = a.add(b);
                                a = b;
                                b = c;
                                al.add(c.mod(N).intValue());
                        }   
                        Collections.sort(al);
                        int x = 1;
                        int s = al.get(0), t;
                        for(int i = 1;i < al.size(); ++i){
                                t = al.get(i);
                                if((t-s)>=d){
                                        ++x;
                                }   
                                s = t;
                        }   
                        System.out.println(x);
                }   
        }   
}

Measured memory_bytes: 10000
fn read_line() -> String {
    let mut return_ = format!("");
    std::io::stdin().read_line(&mut return_).ok();
    return_.pop();
    return_
}

fn main() {
    let inp = std::char::from_u32(read_line().parse::<u32>().unwrap()).unwrap();
    if inp.is_lowercase() {
        println!("2");
    } else if inp.is_uppercase() {
        println!("1");
    } else {
        println!("0");
    }
}


Measured memory_bytes: 5032
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))
const int MOD = 1e9 + 7;

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

ll fact[100005];

ll mypow(ll a, ll p){
	if(p == 0) return 1;
	if(p == 1) return (a % MOD);
	if(p & 1) return ((a % MOD) * (mypow(a, p - 1) % MOD)) % MOD;
	ll x = mypow(a, p / 2) % MOD;
	return (x * x) % MOD;
}

ll inv(ll base){
	return mypow(base, MOD - 2);
}

ll choose(ll a, ll b){
	ll ret = fact[a] * inv((fact[b] * fact[a - b]) % MOD);
	return (ret % MOD);
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	ll n, k;
	cin >> n >> k;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	fact[0] = 1LL;
	for(ll i = 1; i < 100005; i++) fact[i] = ((fact[i - 1] * i) + MOD) % MOD;
	sort(all(a));
	ll ans = 0;
	for(ll i = 0; i < n; i++){
		if(i >= (k - 1)){
			ans = (ans + (((a[i] * choose(i, k - 1)) + MOD) % MOD) + MOD) % MOD;
		}
	}
	for(ll i = 0; i < n; i++){
		if(i <= (n - k)){
			ans = (ans - (((a[i] * choose(n - i - 1, k - 1) + MOD) % MOD)) + MOD) % MOD;
		}
	}
	cout << (ans + MOD) % MOD << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 1792
#include<stdio.h>

int main(){
    int i = 0,x,stack[10000];
    char c[100000];
    
    while(scanf("%s",c) != EOF){
        if(c[0] == '+'){
            stack[i-2] = stack[i-2] + stack[i-1];
            i--;
        }
        else if(c[0] == '-'){
            stack[i-2] = stack[i-2] - stack[i-1];
            i--;
        }
        else if(c[0] == '*'){
            stack[i-2] = stack[i-2] * stack[i-1];
            i--;
        }
        else{
            x = atoi(c);
            stack[i] = x;
            i++;
        }
    }

    printf("%d\n",stack[0]);

    return 0;
}


Measured memory_bytes: 2088
#include <string>
#include <iostream>
#include <set>
#include <algorithm>
 
using namespace std;
 
// 文字列一つ受け取る場合
// string s;
// 整数(max 2^31-1 or 10^9)一つ受け取る場合
// int x;
// int k;
// int n;
// set<int> a;
int n;
// int m;
// int total;

int main(){
    cin >> n;
    long long int sum = 0;
    for(int i = 1; i<=n; i++){
        if(i%3 !=0 && i%5 !=0){
            sum = sum+i;
        }
    }
    cout << sum;
}

Measured memory_bytes: 3188
#include <iostream>

const long long D = 1000000007;

int main()
{
	int N;
	long long q = 0;
	std::cin >> N;
	long long* A = new long long[N];
	for (int i=0; i<N; i++) std::cin >> A[i];
	long long res = 0;
	for (int i=0; i<N; i++) res += A[i];
	q += res / D; res %= D;
	res *= res;
	q += res / D; res %= D;
	//q = q*D;
	long long diagonal = 0;
	long long qd = 0;
	for (int i=0; i<N; i++) {
		diagonal += (A[i] * A[i]);
		qd += diagonal / D;
		diagonal %= D;
	}
	res -= diagonal;
	if (res < 0) { res += D; q++; } 
	// std::cout << q << std::endl;
	if ((q-qd)%2==0) std::cout << res/2 << std::endl;
	else std::cout << (D+res)/2 << std::endl;
	delete[] A;
	return 0;
}


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

using namespace std;
using ll = long long;

const int table[10] = { 0, 2, 5, 5, 4, 5, 6, 3, 7, 6 };

vector<int> chmax(vector<int>& a, vector<int>& b) {
	if (a.size() > b.size()) { return a; }
	if (b.size() > a.size()) { return b; }
	sort(a.rbegin(), a.rend());
	sort(b.rbegin(), b.rend());
	for (int i = 0; i < a.size(); ++i) {
		if (a[i] > b[i]) { return a; }
		if (b[i] > a[i]) { return b; }
	}
	return a;
}

int main() {
	int N, M;
	cin >> N >> M;
	vector<int> A(M);
	for (int i = 0; i < M; ++i) { cin >> A[i]; }

	vector<vector<int>> dp(N + 1);
	for (int i = 0; i < M; ++i) {
		int cost = table[A[i]];
		if (cost <= N) {
			vector<int> tmp(1, A[i]);
			dp[cost] = chmax(dp[cost], tmp);
		}
		for (int j = 1; j <= N; ++j) {
			if (dp[j].size() == 0) { continue; }
			if (j + cost > N) { continue; }

			vector<int> tmp = dp[j];
			tmp.push_back(A[i]);
			dp[j + cost] = chmax(dp[j + cost], tmp);
		}
	}

	sort(dp[N].rbegin(), dp[N].rend());
	for (int i = 0; i < dp[N].size(); ++i) {
		cout << dp[N][i];
	}
	cout << endl;

	return 0;
}


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

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

	long double ans=v[0];
	for(int i=1;i<N;i++){
		ans=(ans+v[i])/2;
	}
	
	cout<<ans;
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define ALL(x) (x).begin(),(x).end()
const long long MOD = 1000000007;
const long long INF = 1LL << 60;

int main(){
	int W, H, N;
	cin >> W >> H >> N;
	vector<vector<char>> P(H, vector<char>(W));
	rep(i, H){
		rep(j, W){
			P[i][j] = '.';
		}
	}
	
	for(int k = 0; k < N; k++){
		int x, y, a;
		cin >> x >> y >> a;
		if(a == 1){
			for(int i = 0; i < H; i++){
				for(int j = 0; j < x; j++){
					P[i][j] = '#';
				}
			}
		}else if(a == 2){
			for(int i = 0; i < H; i++){
				for(int j = x; j < W; j++){
					P[i][j] = '#';
				}
			}
		}else if(a == 4){
			for(int i = y; i < H; i++){
				for(int j = 0; j < W; j++){
					P[i][j] = '#';
				}
			}
		}else if(a == 3){
			for(int i = 0; i < y; i++){
				for(int j = 0; j < W; j++){
					P[i][j] = '#';
				}
			}
		}
	}
	
	int ans = 0;
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			if(P[i][j] == '.')ans++;
		}
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <numeric>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef deque<ll> dll;
typedef pair<string, int> P;
#define mod 1e9 + 7;
ll gcd(ll x, ll y)
{
	ll r;
	while ((r = x % y) != 0)
	{
		x = y;
		y = r;
	}
	return y;
}
ll lcm(ll x, ll y)
{
	x /= gcd(x, y);
	y /= gcd(x, y);
	return (x * y);
}


int main()
{
	ios_base::sync_with_stdio(false);
	string s;
	ll a, b, c, d, n;
	cin >> n >> a;
	if (a&1) {
		ll ret = n / a;
		cout << ret * ret * ret << endl;
	}
	else {
		ll ret = (n + a / 2) / a;
		ll ret1 = n / a;
		cout << ret * ret * ret + ret1 * ret1 * ret1 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
     long long  a,b,c;
     long long  m,n;
     long long max=-999999999;
     cin>>m>>n;
     a=m-n; b=m+n; c=m*n;
     if (max<b) max=b;
     if (max<c) max=c;
     if (max<a) max=a;
     cout<<max<<endl;
}


Measured memory_bytes: 256
import Data.List (group)


primes =
    let
        f (p : ps) = p : (filter $ (/= 0) . (`mod` p)) ps
    in
        f [ 2 .. ]

primeFactors n = [ x | x <- takeWhile (\y -> y * y <= n) primes, n `mod` x == 0 ]

factorize 1 = []
factorize n =
    let
        x = case primeFactors n of
            []     -> n
            p : ps -> p
    in
        x : factorize (n `div` x)

toInt :: String -> Int
toInt = read

factors :: Int -> Int
factors = product . map ((+1) . length) . group . factorize

main = do
    n <- toInt <$> getLine

    print . sum . map factors $ [ 1 .. (n - 1) ]


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

int main(){
  int n,m;
  cin>>n>>m;
  vector<int>q(m);
  for(int i=0;i<m;i++)cin>>q[i];
  
  vector<int>used(n+1,0),ans;
  for(int i=q.size()-1;i>=0;i--)
    if(!used[q[i]]++)ans.push_back(q[i]);
  for(int i=1;i<=n;i++)if(!used[i])ans.push_back(i);
  for(int i=0;i<n;i++)cout<<ans[i]<<endl;

  return 0;
}

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

using namespace std;
using ll = long long;

int main(int argc, const char *argv[]) {
  int d;
  ll g;
  cin >> d >> g;

  vector<pair<ll, ll>> v_pc(d);
  for (auto &p : v_pc) {
    cin >> p.first >> p.second;
  }

  ll ans = -1;
  for (int i = 0; i < (1 << d); ++i) {
    ll sum = 0, cnt = 0;

    // フラグが立っている配点の問題は全て解く
    for (int j = 0; j < d; ++j) {
      if (i & (1 << j)) {
        ll pt = (j + 1) * 100;
        sum += v_pc[j].second + v_pc[j].first * pt;
        cnt += v_pc[j].first;
      }
    }

    // その他の問題
    for (int j = d - 1; j >= 0 && sum < g; --j) {
      if (i & (1 << j)) {
        continue;
      }

      ll remain = g - sum;
      ll pt = (j + 1) * 100;
      ll cnt2 = min(v_pc[j].first, remain / pt + (remain % pt != 0));
      cnt += cnt2;
      sum += pt * cnt2;
    }

    if (ans < 0 || ans > cnt) {
      ans = cnt;
    }
  }

  cout << ans << '\n';
}

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

using namespace std;

void subsets(vector<int> S, int n) 
{
     int nSub = 1<<n;
     
     for(int i = 0; i < nSub; i++)
     {
         if(i == 0)
         {
            cout << i << ":\n"; 
         }
     	 else
     	 {
     	     cout << i << ":";
     	     
     	     for(int k = 0; k < n; k++)
             {
                 if((1 << k) & i)
                 {
                     cout << " " << S[k];
                 } 
             }
             cout << "\n";
     	 }
     }
}

int main() 
{
    int n;
    scanf("%d", &n);
    
    vector<int> v;
    
    for(int i = 0; i < n; i++)
        v.emplace_back(i);
        
    subsets(v, n);
    
    return 0;
}


Measured memory_bytes: 3252
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
int a[110000];
int main()
{
	int s = 0, n, k;
	scanf("%d %d", &n, &k);
	int i;
	for (i = 0; i<n; i++)
		scanf("%d", &a[i]);
	int l; l = n;
	while (l>1)
	{
		l = l - k + 1;
		s++;
	}
	printf("%d\n", s);
	return 0;
}


Measured memory_bytes: 640
n,k=map(int,input().split())
count=0
while n>0:
    for i in range(1,n-1):
        for j in range(i+1,n):
            for l in range(j+1,n+1):
                if i+j+l==k:
                    count+=1
    print(count)
    count=0
    n,k=map(int,input().split())


Measured memory_bytes: 5596
#include <iostream>

int main() {
    int a,b;
    char op;
    do {
        std::cin >> a >> op >> b;
        switch(op) {
        case '+': std::cout << (a+b) << std::endl; break;
        case '-': std::cout << (a-b) << std::endl; break;
        case '*': std::cout << (a*b) << std::endl; break;
        case '/': std::cout << (a/b) << std::endl; break;
        default:
            break;
        }
    } while(op != '?');
}



Measured memory_bytes: 3092
#include <stdio.h>
#include <math.h>

int main(void)
{
    int i, n, S[1000];
    double sumi, sumn, avg;
    while (scanf("%d", &n) && n > 0) {
        sumi = 0;
        sumn = 0;
        for (i = 0; i < n; i++) {
            scanf("%d", S + i);
            sumi += S[i];
        }
        avg = sumi / n;
        for (i = 0; i < n; i++) {
            sumn += (S[i] - avg) * (S[i] - avg);
        }
        printf("%.4f\n", sqrt(sumn / n));
    }

    return 0;
}


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

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

struct edge {
    ll from, to, cost;
};

const ll INF = 1ll << 60;
ll N,M;
vector<edge> edges;
vector<ll> d;

// http://sesenosannko.hatenablog.com/entry/2017/09/01/214852
// src->dstの間に閉路があればfalse
bool bellman_ford(ll src, ll dst){
    d[src] = 0;
    rep(i,0,2*N){
        for (auto e: edges) {
            if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
                d[e.to] = d[e.from] + e.cost;
                if (i>=N-1 && e.to == dst)
                    return false;
            }
        }
    }
    return true;
}

signed main() {
    cin>>N>>M;
    rep(i,0,M){
        ll a,b,c;
        cin>>a>>b>>c;
        edges.push_back(edge{a-1,b-1,-c});
    }
    d.resize(N, INF);
    auto t = bellman_ford(0, N-1);
    if (t){
        cout<<-d[N-1]<<endl;
    }else{
        cout<<"inf"<<endl;
    }

    return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

void DFS(
    int s, int M, int rem,
    const vector<int> &pattern, vector<vector<int>> &patterns)
{
    if (rem == 0)
    {
        patterns.push_back(pattern);
        return;
    }
    for (int i = s; i <= M; ++i)
    {
        vector<int> newPattern = pattern;
        newPattern.push_back(i);
        DFS(i, M, rem - 1, newPattern, patterns);
    }
}

int main()
{
    int N, M, Q; cin >> N >> M >> Q;
    vector<vector<int>> patterns;
    DFS(1, M, N, {}, patterns);
    int ans = -1;
    vector<int> as(Q), bs(Q), cs(Q), ds(Q);
    for (int i = 0; i < Q; ++i)
    {
        cin >> as[i] >> bs[i] >> cs[i] >> ds[i];
    }
    for (const auto &pattern : patterns)
    {
        int score = 0;
        for (int i = 0; i < Q; ++i)
        {
            if (pattern[bs[i] - 1] - pattern[as[i] - 1] == cs[i])
            {
                score += ds[i];
            }
        }
        ans = max(ans, score);
    }
    cout << ans << endl;
}

Measured memory_bytes: 9700
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define per(i,a,b) for(ll i=b-1;i>=a;i--)
const ll maxn=1e2+5, maxk=1e5+5, mod=1e9+7;
ll n,k,a[maxn],dp[maxn][maxk];
int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    cin>>n>>k;
    rep(i,1,n+1) cin>>a[i];
    dp[0][0]=1;
    rep(i,1,n+1) {
        ll s=0;
        rep(j,0,k+1) {
            s+=dp[i-1][j];
            if(a[i]<j) s-=dp[i-1][j-a[i]-1];
            s%=mod; if(s<0) s+=mod;
            dp[i][j]=s;
        }
    }
    cout<<dp[n][k]<<"\n";
}


Measured memory_bytes: 79360
import sys
import math
from collections import defaultdict, deque, Counter
from copy import deepcopy
from bisect import bisect, bisect_right, bisect_left
from heapq import heapify, heappop, heappush
    
input = sys.stdin.readline
def RD(): return input().rstrip()
def F(): return float(input().rstrip())
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]
    
    
def main():
    N = I()
    #dpの初期化
    dp = [0]*(N+1)
    dp[0] = 1
    
    mod=10 ** 9 + 7
    
    for i in range(3, N+1):
        dp[i] = (dp[i-1]+dp[i-3]) % mod
        
    print(dp[N])

if __name__ == "__main__":
    main()

Measured memory_bytes: 70068