akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const  int maxn = 1e6 + 5;
typedef long long ll;
ll w[maxn], v[maxn];
ll dp[maxn];
int main() {
//freopen("in.in", "r", stdin);
    int n, V;
    cin >> n >> V;
    for (int i = 1; i <= n; i++) {
        cin >> v[i] >> w[i];
        for (int j = V; j >= v[i]; j--) {
            dp[j] = max(dp[j], dp[j - v[i]] + w[i]);
        }
    }
    cout << dp[V] << endl;
    return 0;
}

Measured memory_bytes: 5120
using System;

namespace _4_B {
    class Program {
        static void Main (string[] args) {
            var pi = 3.141592653589d;
            var r = Convert.ToDouble (Console.ReadLine ());
            var area = pi * r * r;
            var circumference = 2 * pi * r;

            Console.WriteLine ($"{area} {circumference}");
        }
    }
}


Measured memory_bytes: 18072
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var A = int.Parse(Console.ReadLine());

            Console.WriteLine(N % 500 <= A ? "Yes" : "No");
        }
    }
}

Measured memory_bytes: 13140
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
using namespace std;
int main(){
  int N, X;
  int m[1010];
  cin >> N >> X;

  for(int i = 0; i < N; i++) cin >> m[i];

  int c = 0;
  for(int i =0; i < N; i++){
    X -= m[i];
    c++;
  }

  sort(m, m+N);
  int mi = m[0];

  while(true){
    X -= mi;
    if(X >= 0){
      c++;
    }else{
      break;
    }
  }

  cout << c << endl;
}


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

int N;
int D[110][2];

int main()
{
    cin >> N;
    int cnt = 0;
    for (size_t i = 0; i < N; i++)
    {
        cin >> D[i][0] >> D[i][1];
        if (D[i][0] == D[i][1])
        {
            cnt++;
            if (cnt == 3)
            {
                cout << "Yes" << endl;
                return 0;
            }
        }
        else
        {
            cnt = 0;
        }
    }
    cout << "No" << endl;
}

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

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

int N, M, K[31], A[31][31];

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

    vector<int> nums(M, 0);
    for(int i=0;i<N;i++){
        for(int j=0;j<K[i];j++){
            nums[A[i][j]-1]++;
        }
    }

    int ans = 0;
    for(int i=0;i<M;i++){
        if(nums[i] == N)    ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import copy
from collections import deque

n, st, sa = map(int,input().split())
st -= 1
sa -= 1

e = [[] for i in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    e[a].append(b)
    e[b].append(a)

visited = [False] * n
visited[st] = True
d = deque()
d.append([st, 0])
tx = {}
if len(e[st]) == 1:
    tx[st] = 0
cnt = 0
while d:
    f, cnt = d.popleft()
    flg = True
    for t in e[f]:
        if not visited[t]:
            flg = False
            d.append([t, cnt+1])
            visited[t] = True
    if flg:
        tx[f] = cnt

visited = [False] * n
visited[sa] = True
d = deque()
d.append([sa, 0])
ax = {}
if len(e[sa]) == 1:
    ax[sa] = 0
cnt = 0
while d:
    f, cnt = d.popleft()
    flg = True
    for t in e[f]:
        if not visited[t]:
            flg = False
            d.append([t, cnt+1])
            visited[t] = True
    if flg:
        ax[f] = cnt

ax = sorted(ax.items(), key=lambda x:x[1], reverse=True)
for i in range(len(ax)):
    x, d = ax[i][0], ax[i][1]
    if d > tx[x]:
        ans = d - 1
        break

print(ans)

Measured memory_bytes: 37744
d[4][1<<16];*s=d,*t=d+1;w;c;f;p=2e4;i;main(a){s[p]=d[2][p]=1;do{if(a=getchar()-70){for(i=1e4;i<3e4;i++)t[i-c]|=(t[i+c]|=s[i])&&f;w=2-w;s=d[w+f%2];memset(t=d[w?++f%2+w:-~f%2+w],0,2e5);c=-1;}c++;}while(a>=0);scanf("%d%d",&a,&c);puts(d[f%2][p+a]&&d[2+(f+!!w&1)][p+c]?"Yes":"No");}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<endl;
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;
const ll inf=1e15;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,C;
  cin>>n>>C;
  vector<vector<int>> d(C,vector<int>(C)),c(n,vector<int>(n)),sum(3,vector<int>(C,0));
  rep(i,C)rep(j,C) cin>>d[i][j];
  rep(i,n)rep(j,n){
    cin>>c[i][j];
    c[i][j]--;
  }
  rep(i,C)rep(j,n)rep(k,n){
    sum[(j+k)%3][i]+=d[c[j][k]][i];
  }
  int ans=1e9;
  rep(i,C)rep(j,C)rep(k,C){
    if(i==j || j==k || k==i) continue;
    ans=min(ans,sum[0][i]+sum[1][j]+sum[2][k]);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
int main (){
    char b;
    cin >> b;
    if(b == 'A'){
        cout << 'T' << endl;

    }
     if(b == 'T'){
        cout << 'A' << endl;
        
    }
     if(b == 'G'){
        cout << 'C' << endl;
        
    }
     if(b == 'C'){
        cout << 'G' << endl;
        
    }
}

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


typedef pair<int,int> PII;

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

	vector<vector<int>> output;
	for(int i=1; i<20; i++) {
		output.push_back({i, i+1, 0});
	}
	int v = 20;
	int last = 0;
	for(int base=1; base*2 <= L; base*=2, v--) {
		last = base * 2;
		if(v > 0)
			output.push_back({v-1, v, base});
	}
	v = 20;
	for(int base=1; base <=L; base *=2, v--) {
		int k = L;
		for(int i=0; i<20 -v; i++) {
			k/=2;
		}
		if(k%2==0) continue;
		if(last + base <= L) {
			output.push_back({1, v , L - base});
			L -= base;
		}

	}
	cout << 20 <<" " << output.size() <<  endl;
	for(auto data: output) {
		cout << data[0] << " " << data[1] << " " << data[2] << endl;

	}


}


/*
int main() {
	map<int, int> data;
	int iter = 2;
	int L;
	cin >> L;
	for(int i=1; i<=L; i++) {
		int k = i;
		while(k %2 == 0) k/=2;
		int adder = i / k;
		if(adder + i > L) {
			data[i] = iter;
			iter++;
			cout << i << endl;
		}

	} 

	vector<vector<int>> output;
	for(auto val : data) {
		if(val.first == 1) continue;
		int k = val.first;
		while(k%2==0) k/=2;
		int adder = val / k;
		if(adder == val) {
			vector<int> ans;
			ans = {val.second, data[adder/2], 0};
			output.push_back(ans);
			ans = {val.second, data[adder/2], adder}
			output.push_back(ans);
		}
		else {
			vector<int> ans;
			ans = {val.second, data[adder/2 + val.second], adder}
			output.push_back(ans);
			ans = {val.second, data[adder/2], 0}
			output.push_back(ans);
		}
	}
	int maxim = 1;
	for(;maxim < L;) {
		maxim *= 2;
	}
	if(maxim %2 == 0) maxim /= 2;
	output.push_back({1, data[maxim], 0});
	cout << iter + 1 << " " << output.size() + 2 << endl;
	
  return 0;
} 










*/
















Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <set>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>
using namespace std;

int digitsum(int n) {
    int sum = 0;
    while (n > 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}

int main(int argc, const char * argv[]) {
    
    int N, x;
    cin >> N >> x;
    vector<int> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a.at(i);
    }
    
    sort(a.begin(), a.end());
    int cnt = 0;
    for (int i = 0; i < N - 1; i++) {
        if (x >= a.at(i)) {
            x -= a.at(i);
            cnt++;
        } else break;
    }
    if (x == a.at(N - 1)) cnt++;
    
    cout << cnt << endl;
    
    return 0;
}


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


int main() {
	int n; cin >> n;
	int f = -1, s = -1;
	int e = -1;

	for (int i = 0; i < n; i++) {
		int a; cin >> a;
		if (a > f) {
			e = i; s = f; f = a;
		}
		else if (a > s) s = a;
	}

	for (int i = 0; i < n; i++) {
		if (i == e) cout << s << endl;
		else cout << f << endl;
	}

	return 0;
}


Measured memory_bytes: 1664
import sys
import math
from collections import deque
input = sys.stdin.readline
#S,L,R = map(int, input().split())

def solve(N,A,B,C,D):
    
    dp = {}
    
    def dfs(n):
        if n in dp:
            return dp[n]
        if n<=0:
            return 0
        if n==1:
            return D
        
        R = n*D
        
        #2 floor
        R = min(R,A+D*(n%2)+dfs(n//2))
        
        #2 ceil
        if n%2 != 0:
            R = min(R,A+D*(2-n%2)+dfs((n+2-1)//2))
        
        
        #3 floor
        R = min(R,B+D*(n%3)+dfs(n//3))
        
        #3 ceil
        if n%3 != 0:
            R = min(R,B+D*(3-n%3)+dfs((n+3-1)//3))
        
        
        #5 floor
        R = min(R,C+D*(n%5)+dfs(n//5))
        
        #5 ceil
        if n%5 != 0:
            R = min(R,C+D*(5-n%5)+dfs((n+5-1)//5))
        
        
        dp[n]=R
        return R
    
    return dfs(N)
    

T = int(input());
for i in range(T):
    N,A,B,C,D = map(int, input().split())
    print(solve(N,A,B,C,D))


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

int main() {
  int n, l;
  cin >> n >> l;
  vector<string> s(n);
  
  for (int i = 0; i < n; i++) {
    cin >> s.at(i);
  }
  sort(s.begin(), s.end());
  
  for (int i = 0; i < n; i++) {
    cout << s.at(i);
  }
  cout << endl;
}



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

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  if(N/100==N%10)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
l, r = map(int, input().split())

if l%2019 + r - l >= 2019:
  print(0)
else:
  minmod=2019
  r = min(r, l+2019)
  for i in range(l, r+1):
    for j in range(i+1, r+1):
      minmod = min(minmod, (i*j)%2019)
  print(minmod)
  

Measured memory_bytes: 3060
N=int(input())
#S=  [ [-1] * N for i in range(N)]
S=[ [] * N for i in range(N)]
#print(S)
for i in range(N):
  a=int(input())
  for j in range(a):
    x,y=map(int,input().split())
    #S[i][x-1]=y
    S[i].append([x-1,y])
#print(S)
ans=0
P=[0]*N
#print(P)
for i in range(2**N):
  tmp=0
  for j in range(N):
    if P[j]==0:
      P[j]=1
      break
    else:
      P[j]=0
  #print(P,sum(P))
  if sum(P)<=ans:
    continue
  flag=0
  for p in range(len(P)):
    if P[p]==1:
      for s in S[p]:
        if s[1]!=P[s[0]]:
          flag=1
  if flag==1:
    continue
  else:
    ans=sum(P)
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>

using namespace std;

int main(void)
{
    int n, m;
    cin >> n >> m;
    vector<int> coins(m);
    vector<int> nums(n+1);

    for (int i = 0; i < n + 1; i++)
        nums[i] = 0;
    
    for (int i = 0; i < m; i++) {
        int c;
        cin >> c;
        if (c <= n) {
            coins[i] = c;
            nums[c] = 1;
            for (int j = 1; j + c <= n; j++) {
                if (nums[j] && (!nums[c + j] || nums[c] + nums[j] < nums[c + j]))
                    nums[c + j] = nums[c] + nums[j];
            }
        }
    }

    cout << nums[n] << endl;

    return 0;
}

Measured memory_bytes: 1288
fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim_end().to_owned()
}

fn main() {
    let s = read_line();
    let mut ws = s.split_whitespace();
    let a: i32 = ws.next().unwrap().parse().unwrap();
    let b: i32 = ws.next().unwrap().parse().unwrap();

    if a * b % 2 == 0 {
        println!("Even")
    } else {
        println!("Odd")
    }
}

Measured memory_bytes: 2112
/*
 * Created by Dipta Das on 29-06-2019
 * Title: 
 * Problem Link: 
 * Editorial: 
 * Source Code: 
 * Comments: 
*/

#include <bits/stdc++.h>
#include <stdio.h>
#define fin freopen("input", "r", stdin)
#define whatis(x) cerr << #x << ": " << x << endl;

using namespace std;
using ll = long long;
const int size = 1e5 + 100;
vector<int> adj[size];
int dp[size];
int n, m, mn;

int dfs (int node) {
    int &dis = dp[node];
    if (dis != -1) return dis;
    dis = 0;
    for (int i = 0; i < (int) adj[node].size(); ++i) {
        dis = max (dis, dfs(adj[node][i]) + 1);
    }
    return dis;
}

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

    memset(dp, -1, sizeof(dp));

    cin >> n >> m;
    for (int i = 0, x, y; i < m; ++i) {
        cin >> x >> y;
        adj[x].push_back(y);
    }

    mn = 0;
    for (int i = 1; i <= n; ++i) {
        mn = max (mn, dfs (i));
    }

    cout << mn << endl;
    


    return 0;
}



Measured memory_bytes: 8192
n=int(input())
a=list(map(int,input().split()))
check=0

for i in range(n):
  if a[i]<0:
    check=check+1
a=list(map(lambda x:abs(x),a))

if check%2==0:
  print(sum(a))
else:
  k=min(a)
  print(sum(a)-2*k)

  

Measured memory_bytes: 20072
////////////////////////////////////////////
///                                      ///
///         Template ver. 1 rapel        ///
/// Fear is Temporary, Regret is Forever ///
///          Must Try and Get AC         ///
///                                      ///
////////////////////////////////////////////
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>

#include <math.h>
#include <complex>

#include <assert.h>
#include <time.h>
//#include <chrono>
//#include <random>

#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <bitset>

#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define endl '\n'
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

void desperate_optimization(int precision){
  	ios_base::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);
  	cout.setf(ios::fixed);
  	cout.setf(ios::showpoint);
  	cout.precision(precision);
}

const int N = 1e5;
const int BLOCKS = 330;
vector<int> lst[N + 5];
int grundy[N + 5];

void dfs(int idx,int pre) {
	for(auto x: lst[idx]) {
		if(x == pre) continue;
		dfs(x, idx);
	}
	for(auto x: lst[idx]) {
		if(x == pre) continue;
		grundy[idx] ^= (grundy[x] + 1);
	}
}

void hora(int tc) {
	int n;
	cin>>n;
	for(int i = 1;i < n;i++) {
		int u, v;
		cin>>u>>v;
		lst[u].PB(v);
		lst[v].PB(u);
	}
	dfs(1, 1);
	if(grundy[1] == 0) cout<<"Bob"<<endl;
	else cout<<"Alice"<<endl;
}

int main(){
	desperate_optimization(10);
	int ntc = 1;
	//cin>>ntc;
	for(int tc = 1;tc <= ntc;tc++) hora(tc);
	return 0;
}




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

int main()
{
  int n, k;
  cin >> n >> k;
  double ans(0);

  for (int i = 1; i <= n; i++) {
    int p(1);
    for (int j = i; j < k; j *= 2) {
      p *= 2;
    }
    ans += 1 / double(n * p);
  }
  cout << setprecision(12) << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int n;
int a[110000][4];
int m[110000][4];
int dp(int numTaken, int prevTaken){
	if(numTaken == n+1){
		return 0;
	}
	
	if(m[numTaken][prevTaken]!=-1) return m[numTaken][prevTaken];
	
	int ans = 0;
	// 3 pilihan
	for(int i = 1;i<=3;i++){
		if(i != prevTaken){
			ans = max(ans, dp(numTaken+1, i) + a[numTaken][i-1]);
		}
	}
	return m[numTaken][prevTaken] = ans;
}
int main(){
	cin>>n;
	for(int i = 0;i<n;i++){
		for(int j = 0;j<3;j++){
			cin>>a[i][j];
		}
	}
	
	for(int i = 0;i<=n;i++){
		for(int j = 0;j<=3;j++){
			m[i][j] = -1;
		}
	}
	cout<<dp(0,0)<<"\n";
//	for(int i = 0;i<n;i++){
//		for(int j = 0;j<3;j++){
//			cout<<m[i][j]<<" ";
//		}cout<<"\n";
//	}
	return 0;
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}
const int mod = 1'000'000'007;
const int N = 3e5, M = N;
//=======================

void solve() {
  int i, j, n, x;
  cin >> x;
  i = (x*360)/__gcd(x,360);
  cout << i/x;
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

    int t = 1;
    //cin >> t;
    while(t--) {
      solve();
    }

    return 0;
}


Measured memory_bytes: 3536
#include<stdio.h>

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

	scanf("%d %d %d", &a, &b, &c);

	if(a<=b){
	    d = a;
	    if(b<=c){
		e = b;
	    }else{
		e = c;
	    }
	}else{
	    d = b;
	    if(a<=c){
		e = a;
	    }else{
		e = c;
	    }
	}

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

Measured memory_bytes: 128
n = int(input())
A = list(map(int,input().split()))
ok = [0]*(n)
flag = 0
if n == 1 and A == [0]:
	print(1)
	exit()
for a in A:
	ok[a] += 1
if n%2 == 1:
	if ok[0] == 1 and set(ok[1::2]) == {0} and set(ok[2::2]) == {2}:
		flag = 1
else:
	if set(ok[::2]) == {0} and set(ok[1::2]) == {2}:
		flag = 1
if flag:
	print((2**(n//2))%(10**9+7))
else:
	print(0)

Measured memory_bytes: 14008
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i,m,n) for(int i = m - 1; i >= n; i--)
#define ALL(v) v.begin(), v.end()
#define CMAX(m, x)  m = max(m,x)
#define CMIN(m, x)  m = min(m,x)
#define itn int
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
#define YES() cout << "YES" << endl
#define NO() cout << "NO" << endl
typedef long long lint;
typedef long double ldouble;
const int INF = 1e9;
const lint LINF = 1e18;
int main(){
    int n;
    lint k;
    int point = 0;
    cin >> n >> k;
    vector<int> a(n);
    int cnt = 1;
    vector<int> his;
    vector<vector<int>> data(n);
    int start = 0;
    int end = 0;
    his.push_back(1);
    data[0].push_back(cnt);
    REP(i,n)
        cin >> a[i];
    while(1){
        cnt++;
        point = a[point] - 1;
        his.push_back(point + 1);
        data[point].push_back(cnt);

        if(data[point].size() == 2){
            start = data[point][0];
            end = data[point][1];
            break;
        }
        if(cnt - 1 == k){
            cout << point + 1 << endl;
            return 0;
        }
    }
    k -= (start - 1);
    k -= (k / (end - start)) * (end - start);
    cout << his[start + k - 1] << endl;
    return 0;
}

Measured memory_bytes: 14088
#include <iostream>
#include <map>

using namespace std;

int main() {
    long long n;
    map <long long, long long> m;
    long long res = 0;
    cin >> n;
    long long a[n];
    for (long long i = 0; i < n; i++) {
        cin >> a[i];
    }
    long long s[n+1];
    s[0] = 0;
    for (long long i = 1; i < n + 1; i++) {
        s[i] = s[i-1] + a[i-1];
    }
    for (long long i = 0; i < n + 1; i++) {
        if (m.find(s[i]) != m.end()) {
            m[s[i]] += 1;
        } else {
            m[s[i]] = 1;
        }
    }
    for (auto itr = m.begin(); itr != m.end(); itr++) {
        long long c = itr->second;
        res += c * (c - 1) / 2;
    }
    cout << res << endl;
}

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

int main(){
  int N,K;
  cin>>N;
  cin>>K;
  
  int i;
  int s;
  
  for(i=1;i<=N;i++){
    int x;
    cin>>x;
    if(2*x>K){
      s=s+2*(K-x);
    }
    else{
      s=s+2*x;
    }
  }
  cout<<s<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,m,c,i,j,sum,count=0;
  	cin>>n>>m>>c;
  	vector<int> b(21);
    for(i=0;i<m;i++){
		cin>>b.at(i);
    }
  	int a[21][21];
  	for(i=0;i<n;i++){
      for(j=0;j<m;j++){
		cin>>a[i][j];
      }
    }
  
	for(i=0;i<n;i++){
      sum=0;
      for(j=0;j<m;j++){
		sum+=a[i][j]*b.at(j);
      }
      if(sum+c>0){
		count++;
      }
    }
  
  		cout<<count<<endl;
}


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

int f(int x){
    return x*x;
}

int integral(int d, int d0){
    if(d >= 600){
        return 0;
    }
    
    return(f(d)*d0 + integral(d+d0, d0));
}

int main(){
    int d;
    while(cin >> d){
        cout << integral(d, d) << endl;
    }
    return 0;
}
    

Measured memory_bytes: 0
#include <stdio.h>

int main()
{
	int i, N, A, flag[1000001] = {};
	scanf("%d", &N);
	for (i = 1; i <= N; i++) {
		scanf("%d", &A);
		flag[A]++;
	}
	
	int j, ans = 0;
	for (i = 1; i <= 1000000; i++) {
		if (flag[i] == 0) continue;
		else if (flag[i] == 1) ans++;
		for (j = i; j <= 1000000; j += i) flag[j] = 0;
	}
	printf("%d\n", ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 5608
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

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

    set<int> red;
    vector<int> count(N, 1);

    red.insert(0);
    REP(i, 0, M) {
        int x, y; cin >> x >> y;
        x--; y--;

        count[x]--;
        count[y]++;

        if (red.find(x) != red.end()) {
            if (count[x] == 0) red.erase(x);
            red.insert(y);
        }
    }

    cout << red.size() << endl;

    return 0;
}

Measured memory_bytes: 5376
#include <iostream>

using namespace std;

int main(){
  
  int a=0,b=0;
  cin>>a>>b;
  int item[a+1][2]={0};
  for(int i=1;i<=a;i++){
    cin>>item[i][0]>>item[i][1];
  }
  long long int arr[b+1]={0};
  
  for(int i=1;i<=a;i++)
    for(int j=b;j>=item[i][0];j--)
      arr[j]=max(arr[j-item[i][0]]+item[i][1],arr[j]);
    
  cout<<arr[b]<<endl;
  return 0;
}

Measured memory_bytes: 1024
from collections import deque

H, W = map(int, input().split())
w = "#"*(W+2)
white = 0
S = [w]
for _ in range(H):
    wwww = input()
    white += wwww.count(".")
    S.append("#"+wwww+"#")
S.append(w)

m = [[10**10]*(W+2) for _ in range(H+2)]

q = deque([[1, 1]])
d = ((-1, 0), (0, -1), (0, 1), (1, 0))

m[1][1] = 0

while q:
    y, x = q.popleft()
    p = m[y][x]
    for dx, dy in d:
        xx = x + dx
        yy = y + dy
        if S[yy][xx] == "#":
            continue
        if m[yy][xx] > p+1:
            m[yy][xx] = p+1
            q.append([yy, xx])

if m[H][W] == 10**10:
    print(-1)
else:
    print(white-m[H][W]-1)

Measured memory_bytes: 9324
#include <bits/stdc++.h>
using namespace std;
int ans = 0;
vector<int> t(1<<26);
vector<bool> v(1<<26);
int main() {
	ios_base::sync_with_stdio(0);
	string s;
	cin>>s;
	int q = 0;
	int ans = 0;
	int n = s.size();
	v[0] = 1;
	for(int i = 0; i < n; ++i) {
		q ^= 1<<(s[i]-'a');
		int mi = 1e9;
		if(v[q]) {
			mi = min(mi, t[q]);
		}
		for(int j = 0; j < 26; ++j) {
			q ^= 1<<j;
			if(v[q]) {
				mi = min(mi, t[q]+1);
			}
			q ^= 1<<j;
		}
		if(v[q]) {
			t[q] = min(t[q], mi);
		}
		else {
			t[q] = mi;
			v[q] = 1;
		}
		ans = mi;
	}
	if(q == 0) {
		ans = 1;
	}
	cout<<ans<<'\n';
}


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

int main()
{
    long long n,ans=LLONG_MAX;
    cin>>n;
    for(int i=1; i<=sqrt(n); i++)
    {
        if(n%i==0)
        {
            long long c=i-1 + n/i - 1;
            ans=min(ans,c);
        }
    }
    cout<<ans<<endl;
    return 0;
}



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

int main() {
    
    int k,s,res ;
    cin >> k >> s;
    res = 0;
    for (int x= 0; x<=k; x++){
        for(int y=0; y<=k; y++){
            int z;
            z = s - x - y;
                if (z >= 0 && z <= k) res++;
            
        }
    }
 
    cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < n; ++i)
#define FOR(i, b, n) for (ll i = b; i < n; ++i)

using namespace std;
using ll = long long;
using P = pair<int, int>;

void solve(string S) {
  if (S.substr(S.length() - 1) == "s")
    cout << S + "es" << endl;
  else
    cout << S + "s" << endl;
}

int main(){
  // int 3E4  long 2E9  ll 9E18
  cin.tie(0);
  ios::sync_with_stdio(false);

  string S;
  cin >> S;

  solve(S);

  return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#define nmax_def 110
#define Cmax_def 2200
#define mod 1000000007
using namespace std;
typedef long long ll;

int main() {
	int i, j;
	int N, x[nmax_def], y[nmax_def], h[nmax_def], CX, CY, H;
  	cin>>N;
  for(i=0;i<N;i++)
  {
    cin>>x[i]>>y[i]>>h[i];
  }
	for(i=0;i<=100;i++)
    {
      for(j=0;j<=100;j++)
      {
        bool ans=true;
        CX=i;
        CY=j;
        for(int k=0;k<N;k++)
        {
          	if(h[k]!=0)
            {
              H=h[k]+abs(x[k]-CX)+abs(y[k]-CY);
              k=N;
            }
        }
        //if(H<=0)
          //ans=false;
        //else
        //{
        for(int k=0;k<N;k++)
        {
          int Htmp = h[k]+abs(x[k]-CX)+abs(y[k]-CY);
          if(h[k] == 0)
          	{
            	if(H>Htmp)
          			{
          		  	ans=false;
           		  	k=N;
         	    	}
          	}
          else
          	{
          		if(H!=Htmp)
          			{
            			ans=false;
            			k=N;
          			}
          	}
        }
        //}
        if(ans)
        {
          cout<<CX<<" "<<CY<<" "<<H<<endl;
          i=1000;
          j=1000;
        }
      }
    }
	return 0;
}

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

using namespace std;

typedef long long ll;

int main() {
    int N;
    ll sum = 0;

    scanf("%d", &N);
    for (int i = 1; i <= N; i++) {
        if (i % 3 && i % 5)
            sum += i;
    }
    printf("%lld\n", sum);

    return 0;
}

Measured memory_bytes: 3828
#include <stdio.h>
 
int main(void){
int n,i,j,m,a[100],t,c;
c = 0;
scanf("%d", &n);
for(i=0;i<n;++i){
scanf("%d", &a[i]);
}
for(i=0;i<n;++i){
m=i;
for (j=i;j<n;++j){
if(a[j]<a[m]) 
m=j;
}
if(m!=i){
t=a[i];
a[i]=a[m];
a[m]=t;
c=c+1;
}
}
for(i=0;i<n;++i){
printf("%d",a[i]);
if(i!=n-1)putchar(' ');
}
putchar('\n');
printf("%d\n",c);
return 0;
}

Measured memory_bytes: 2744
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
const int INF = 1e9;

int main() {
  int n, m, q;
  ll score = 0;
  cin >> n >> m >> q;
  vector<vector<int>> vec(q, vector<int>(4));
  vector<int> a(n, 1);
  rep(i, q) cin >> vec[i][0] >> vec[i][1] >> vec[i][2] >> vec[i][3];
  while(true) {
    ll d = 0;
    rep(i, q) {
      if (a[vec[i][1] - 1] - a[vec[i][0] - 1] == vec[i][2]) d += vec[i][3];
    }
    if (score < d) score = d;
    bool fin = true;
    rep(i, n) if (a[i] < m) fin = false;
    if (fin) break;
    //next a
    rep(i, n) {
      int k = n - i - 1;
      if (a[k] < m) {
        a[k]++;
        int kk = k;
        while(kk < n - 1) {
          a[kk] = a[k];
          kk++;
        }
        break;
      }
    }
  }
  cout << score << endl;
}


Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long maxv = 0;
		//約数を探して最大の物だけ保持するよ
		for(long i = 1; i <= (int)Math.sqrt(n); i++) {
			if(n % i == 0) {
				maxv = i;
			}

		}

		if(maxv == 0) {//約数がないなら
			System.out.println(n - 1);
		}else {
			long sum = 0;
			sum += maxv - 1;
			sum += (n / maxv) - 1;
			System.out.println(sum);
		}
	}

}


Measured memory_bytes: 23892
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }


    Scanner cin;



    void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        Dictionary<int, int> dic = new Dictionary<int, int>();
        for (int i = 0; i < N; i++)
        {
            int a = cin.nextInt();
            if (!dic.ContainsKey(a)) dic[a] = 0;
            dic[a]++;
        }
        int ans = 0;
        int tmp = 0;
        foreach (var a in dic.Values)
        {
            int A = a;
            int add = (A - 1) / 2;
            A -= add * 2;
            ans += add;
            if (A == 2) tmp++;
        }
        ans += (tmp + 1) / 2;
        Console.WriteLine(N - ans * 2);
    }

}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 21728
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<iomanip>
#include <math.h>
using namespace std;
int main(){
    long long int n,f=0;
    cin>>n;
    for(long long int i=1;i<=3500;i++){
        for(long long int j=1;j<=3500;j++){
            if((4*i*j-n*(i+j))!=0){
                if(((n*i*j)%(4*i*j-n*(i+j)))==0&&((n*i*j)/(4*i*j-n*(i+j)))>0){
                    cout<<i<<' '<<j<<' '<<(n*i*j)/(4*i*j-n*(i+j))<<endl;
                    f=1;
                    break;
                }
            }
        }
        if(f==1){
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 3596
#include<cstdio>
#include<deque>
//#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	int N = getint(), M = getint();

	int E[200010], ne[200010], H[100010] = {};
	int k = 1;
	rep(i, M) {
		int a = getint(), b = getint();
		E[k] = b;
		ne[k] = H[a];
		H[a] = k++;
		E[k] = a;
		ne[k] = H[b];
		H[b] = k++;
	}

	bool S[100010] = {};
	S[1] = 1; 
	S[E[H[1]]] = 1;
	deque<int> kotae;
	kotae.pb(E[H[1]]);
	kotae.pb(1);

	int ima = 1;
	while (true) {
		int nakatta = 1;
		for (int i = H[ima]; i; i = ne[i]) {
			int to = E[i];
			if (!S[to]) {
				kotae.pb(to);
				ima = to;
				S[to] = 1;
				nakatta = 0;
				break;
			}
		}
		if (nakatta) break;
	}
	ima = E[H[1]];
	while (true) {
		int nakatta = 1;
		for (int i = H[ima]; i; i = ne[i]) {
			int to = E[i];
			if (!S[to]) {
				kotae.push_front(to);
				ima = to;
				S[to] = 1;
				nakatta = 0;
				break;
			}
		}
		if (nakatta) break;
	}

	printf("%d\n", kotae.size());
	rep(i, kotae.size()) {
		printf("%d ", kotae[i]);
	}

	Would you please return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#include <boost/integer/common_factor_rt.hpp>
using namespace std;
using ll=long long;
const int MOD=1000000007;

int main() {
  ll n,a,b,c,d,e;
  cin >> n;
  cin >> a;
  cin >> b;
  cin >> c;
  cin >> d;
  cin >> e;
  vector<ll> v={a,b,c,d,e};
  sort(v.begin(),v.end());
  ll ans=(n-1)/v.at(0)+5;
  cout << ans << endl;
}

Measured memory_bytes: 3632
#include <stdio.h>
int main (void)
{
   int W,H,x,y,r;
   scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
   if(0<=x-r && 0<=y-r && x+r<=W && y+r<=H){
      printf("Yes\n");
   }
   else{
      printf("No\n");
   }
   return 0;
}

Measured memory_bytes: 584
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)

Measured memory_bytes: 134368
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

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

#include <map>
#include <set>
using namespace std;

int main(){
  map<int, int> m;
  const int n = getInt();
  REP(i,n){
    const int k = getInt();
    int cur = m[k];
    m[k] = 1 - cur;
  }
  int ans = 0;
  for(auto a : m){
    ans += a.second;
  }

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


Measured memory_bytes: 4864
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
narr = lambda d, f: narr(d[:-1], lambda: [f() for _ in range(d[-1])]) if d else f() # narr((2,3), int)
mod = 1000000007
sys.setrecursionlimit(1000000)

H, W = rl()
C = rl()
D = rl()
M = []
for i in range(H):
	s = rs()
	M.append(s)

start = tuple([C[0]-1, C[1]-1])
end = tuple([D[0]-1, D[1]-1])

queue = deque()
queue.append((start, 0))
visited = narr((H, W), lambda: float('inf'))
visited[start[0]][start[1]] = 0

ds = [(1,0),(-1,0),(0,1),(0,-1)]
while queue:
	n, d = queue.popleft()
	if n == end:
		print(d)
		exit()
	i, j = n
	if visited[i][j] != d:
		continue
	nd = d
	for di, dj in ds:
		ni, nj = i+di, j+dj
		if not (0 <= ni < H and 0 <= nj < W): continue
		if M[ni][nj] == '#': continue
		if nd < visited[ni][nj]:
			queue.appendleft(((ni,nj), nd))
			visited[ni][nj] = nd
	nd = d+1
	for di in range(-2, 3):
		for dj in range(-2, 3):
			if (di, dj) == (0,0): continue
			ni, nj = i+di, j+dj
			if not (0 <= ni < H and 0 <= nj < W): continue
			if M[ni][nj] == '#': continue
			if nd < visited[ni][nj]:
				queue.append(((ni,nj), nd))
				visited[ni][nj] = nd
print(-1)


Measured memory_bytes: 100472
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#include <queue>
#include <set>
#include <list>
#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;
const ll INF=1e9+7;

int main(void) {
	int n, m;
	cin >> n >> m;
	vector<int> num_wa(n+1,0);
	vector<bool> can_ac(n + 1, false);
	int ac = 0, pena = 0;
	rep(i, 0, m) {
		int p; string s;
		cin >> p >> s;
		if (can_ac[p])continue;
		if (s == "AC") {
			can_ac[p] = true;
			ac++;
			pena += num_wa[p];
		}
		else {
			num_wa[p]++;
		}
	}
	cout << ac << " " << pena << endl;
	return 0;
}


Measured memory_bytes: 640
import math
while True:
 s = input().rstrip().split(' ')
 a = int(s[0])
 mark = str(s[1])
 b = int(s[2])
 if mark == "+":
  print(a + b)
 elif mark == "-":
  print(a - b)
 elif mark == "*":
  print(a * b)
 elif mark == "/":
  print(math.floor(a / b))
 elif mark == "?":
  break;


Measured memory_bytes: 5664
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,n) cin>>a[i];
    sort(all(a));
    long w=0,h=0;
    for(int i=n-1;i>=0;i--){
        if(a[i]==a[i-1]){
            if(w==0) w=a[i];
            else h=a[i];
            i--;
        }
        if(w!=0&&h!=0) break;
    }
    cout<<w*h;
}

Measured memory_bytes: 3776
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll N = 1e6;
const double PI = acos(-1.0);
#define Test ll tesnum;tesnum = read();while(tesnum--)
ll read();

int main()
{
    int ans = 0;
    string s,t;
    cin>>s>>t;
    for(int i = 0; i < s.size(); i++){
        if(s[i]!=t[i])ans++;
    }
    cout<<ans<<endl;
    return "BT7274", NULL;
}

inline ll read() {
    ll hcy = 0, dia = 1;char boluo = getchar();
    while (!isdigit(boluo)) {if (boluo == '-')dia = -1;boluo = getchar();}
    while (isdigit(boluo)) {hcy = hcy * 10 + boluo - '0';boluo = getchar();}
    return hcy * dia;
}

Measured memory_bytes: 3848
import scala.io.StdIn


object Main extends App {
  val Array(k, s)  = StdIn.readLine.split(" ").map(_.toInt)

  def solve(k: Int, s: Int) : Int  = {
    var cnt = 0
    for(x <- 0 to k; y <- 0 to k) {
        val z = s - x - y
        if (z >= 0 && z <= k) cnt += 1
    }
    cnt
  }
  println(solve(k, s))

}
  



Measured memory_bytes: 25676
fn main() {
    let r = read::<f64>();
    println!("{}", 2.0 * r * std::f64::consts::PI);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse().ok().unwrap()
}


Measured memory_bytes: 2168
#include <iostream>
#include <string>

int main() {
    std::string a[] = {"SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN"};
    std::string b;
    std::cin >> b;
    for(int i = 0; i < 7; ++i) {
        if(a[i] == b){
            std::cout << i + 1 << std::endl;
            break;
        }
    }
}


Measured memory_bytes: 256
#include <cstdio>

const int maxn = 4020;
const int mod = 1e9 + 7;

int n, m, k, ans;
int dp[maxn][maxn], sum[maxn];

int S(int l, int r) {
	return l <= 0 ? sum[r] : (sum[r] - sum[l - 1] + mod) % mod;
}

int main() {
	scanf("%d%d%d", &n, &m, &k);
	dp[0][0] = 1;
	--k;
	for (int i = 0; i < n + m;) {
		for (int j = 0; j <= i; ++j) {
			sum[j] = dp[i - j][j];
		}
		for (int j = 1; j <= i; ++j) {
			(sum[j] += sum[j - 1]) %= mod;
		}
		if(i + k >= n + m) {
			break;
		}
		for (int j = i + 1; j <= i + k; ++j) {
			sum[j] = sum[j - 1];
		}
		i += k;
		for (int j = 0; j <= i; ++j) {
			dp[i - j][j] = S(j - k, j);
		}
	}
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			if(dp[i][j]) {
				int x = (n - i) % k, y = (m - j) % k;
				if(!x) {
					x += k;
				}
				if(!y) {
					y += k;
				}
				while(x + y < k + 1) {
					if(x + i + k <= n) {
						x += k;
					}
					else {
						y += k;
					}
				}
				if(x + y == k + 1 && x + i <= n && y + j <= m) {
					(ans += dp[i][j]) %= mod;
				}
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 61952
import sys
import math

sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

N, M = MAP()

if abs(N-M) > 1:
	print(0)
	sys.exit()

dog = permutations_count(N, N) % (10**9 + 7)
monkey = permutations_count(M, M) % (10**9 + 7)

ans = dog*monkey % (10**9 + 7) if N!=M else dog*monkey*2 % (10**9 + 7)

print(ans)

Measured memory_bytes: 47088
import copy

H,W,K = map(int,input().split())
C = [list(input()) for i in range(H)]
ans = 0

for h in range(2**H):
    for w in range(2**W):
        tmp = copy.deepcopy(C)
        w_bin = bin(w)[2:].zfill(W)
        h_bin = bin(h)[2:].zfill(H)
        for index_w,flag_w in enumerate(w_bin):
            for index_h,flag_h in enumerate(h_bin):
                if flag_h == '1':
                    tmp[index_h] = ['.' for _ in range(W)]
                if flag_w == '1':
                    tmptmp = [list(x) for x in zip(*tmp)]
                    tmptmp[W-index_w-1] = ['.' for _ in range(H)]
                    tmp = [list(x) for x in zip(*tmptmp)]
        a = 0
        for i in tmp:
            a += i.count('#')
        if K == a:
            ans += 1
print(ans)

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

using namespace std;



int main(void)
{
    int n;
    cin >> n;
    vector<int> x(n),s(n);
    for (int i = 0; i < n;i++){
        cin >> x.at(i);
        s.at(i) = x.at(i);
    }
    sort(s.begin(), s.end());
    int h = s.at(n / 2);
    int l = s.at(n / 2 - 1);
    for (int i = 0; i < n; i++){
        if(h>x.at(i))
            cout << h << endl;
        else
            cout << l << endl;
    }

    return 0;
}

Measured memory_bytes: 3712
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int n = sc.nextInt();

		int saisyo = 0;
		int hozon = 0;
		int saidai = 0;
		int saigo = 0;

		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();

			if (saidai < a - hozon) {
				saidai = a - hozon;
			}

			if (i == 0) {
				saisyo = a;
			}
			if (i == n - 1) {
				saigo = a;
			}

			hozon = a;
		}

		int kotae2 = k - saidai;
		int kotae3 = saigo - saisyo;

		if (kotae2 < kotae3) {
			System.out.println(kotae2);
		} else {
			System.out.println(kotae3);
		}

		sc.close();
	}

}

Measured memory_bytes: 66380
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
const ll mod = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

typedef pair<int, int> P;

int main()
{
	int n, t;
	cin >> n >> t;

	vector<P> ds;
	rep(i, n)
	{
		P d;
		cin >> d.first >> d.second;
		ds.push_back(d);
	}

	sort(ds.begin(), ds.end(), [](const P& a, const P& b) {return a.first < b.first; });

	const int N_MAX = 3001;
	const int T_MAX = 3000;
	
	//dp1[i+1][j] := 0からi番目の料理でj分以内に完食できる美味しさの合計の最大値
	vector<vector<int>> dp1(N_MAX, vector<int>(T_MAX, 0));
	
	rep(i, n)
	{
		P d = ds[i];

		rep(j, t)
		{
			if (j < d.first)
			{
				dp1[i + 1][j] = dp1[i][j];
			}
			else
			{
				if (dp1[i][j] < dp1[i][j - d.first] + d.second)
				{
					dp1[i + 1][j] = dp1[i][j - d.first] + d.second;
				}
				else
				{
					dp1[i + 1][j] = dp1[i][j];
				}
			}
		}
	}


	int answer = 0;

	rep(i, n)
	{
		int tmp1 = 0;
		rep(j, t)
		{
			int tmp2;

			//i番目の料理以外でdp
			if (i > 0)
			{
				//t-1分以内に料理を食べきる。
				//最初にj分使って、あとからt - 1 - j分使う。
				tmp2 = dp1[i][j];
			}

			tmp1 = max(tmp2, tmp1);
		}

		tmp1 += ds[i].second;

		answer = max(tmp1, answer);
	}

	cout << answer << endl;



	return 0;
}

Measured memory_bytes: 35584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100001,INF=1<<30;

int main(){
    int N;cin>>N;
    vector<int> T(13,0);
    for(int i=0;i<N;i++){
        int a;cin>>a;
        T[a]++;
    }
    bool ok=true;
    if(T[0]) ok=false;
    for(int i=0;i<13;i++){
        if(T[i]>2) ok=false;
    }

    if(!ok) cout<<0<<endl;
    else{
        int ans=0;
        for(int bit=0;bit<(1<<12);bit++){
            vector<int> S(24,0);
            S[0]=1;
            for(int i=0;i<13;i++){
                if(T[i]==0) continue;
                if(T[i]==2){
                    S[i]++;
                    S[24-i]++;
                }else{
                    if(bit&(1<<(i-1))){
                        S[i]++;
                    }else S[24-i]++;
                }
            }
            int m=INF,pre=0;
            for(int i=1;i<24;i++){
                if(S[i]){
                    m=min(m,i-pre);
                    pre=i;
                }
            }
            m=min(m,24-pre);
            ans=max(ans,m);

        }

        cout<<ans<<endl;
    }
}

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

int main(){
  int N;
  long long K;
  cin >> N >> K;
  vector<pair<int,long long>> vec(N);
  for(int i=0; i<N; i++) cin >> vec.at(i).first >> vec.at(i).second;
  sort(vec.begin(),vec.end());
  long long cnt=0;
  int ans;
  for(int i=0; i<N; i++){
    cnt+=vec.at(i).second;
    if(cnt>=K){
      ans=vec.at(i).first;
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<vector>
#include <algorithm>

//マクロ
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define REPS(i,n) for(int i=1; i<=(int)(n); ++i)
#define RREP(i,n) for(int i=(int)(n)-1; i>=0; --i)
#define RREPS(i,n) for(int i=(int)(n); i>0; --i)
#define FOR(i,s,e) for(int i=(int)(s); i<(int)(e); ++i)
#define RFOR(i,s,e) for(int i=(int)(e)-1; i>=(int)(s); --i)

#define All(a) (a).begin(),(a).end()

//定数
#define INF 1e9
#define MOD (int)(1e9+7)

typedef long long ll;
typedef unsigned long long ull;

//とりあえず書いておく変数
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

//今回の変数

//使用する関数

using namespace std;
int main()
{
	int n;
	cin >> n;

	int cnt = 0;
	REPS(i, n) {
		int tmp = i;
		REPS(j, 6) {
			tmp /= 10;
			if (tmp == 0) {
				if(j%2 == 1)cnt++;
				break;
			}
		}
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int X = keyboard.nextInt();
		all: for(int a=-1000; a<1001; a++) {
		 for(int b=-1000; b<1001; b++) {
			 if(X == Math.round(Math.pow(a, 5)-Math.pow(b, 5))) {
				 System.out.print(a+" "+b);
				 break all;
			 }
		 }
		}
		keyboard.close();
	}
}


Measured memory_bytes: 38800
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val N = sc.nextInt()
    val r = Array.fill(N)(sc.nextInt())
      .groupBy(identity)
      .foldLeft(0L)((b, n) => {
        if (n._2.length >= n._1) b + (n._2.length - n._1)
        else b + n._2.length
      })

    println(r)
  }

}


Measured memory_bytes: 102088