akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define rt return 0
#define endln "\n"
#define all(v) v.begin(), v.end()
#define for1(i, a, b) for (long long int i = a; i < b; i++)
#define for2(i, a, b) for (long long int i = a; i > b; i--)
//  cout << fixed << setprecision(0) << pi <<" "<<npi<<endl;typedef long long int i;
typedef long long int lli;
typedef pair<lli, lli> pll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli d, t, s;
    cin >> d >> t >> s;
    vector<lli> v;
    if (t * s >= d)
    {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3644
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <numeric>

using namespace std;
#define ALL(x)			(x).begin(),(x).end()
#define REP(i, n)		for (int (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n)	for (int (i) = m ; (i) < (ll)(n) ; ++(i))
#define INF				(int)2e9
#define MOD				(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)		(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)		(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)	((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)		(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)		(!IsOdd((x)))						
#define M_PI			3.14159265358979323846
typedef long long		ll;
typedef pair<ll, ll>	P;
typedef vector<ll>		VLL;
typedef vector<VLL>		VVLL;
typedef vector<VVLL>	VVVLL;

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

	int ketaNum = N.size();
	VVLL dp0(ketaNum + 1, VLL(K + 1, 0));
	VVLL dp1(ketaNum + 1, VLL(K + 1, 0));
	
	dp0[0][0] = 1;
	REP(i, ketaNum) {
		int digitMax = N[i] - '0';
		REP(j, K + 1) {
			REP(digitVal, 10) {
				if (digitVal == 0) {
					if (digitVal < digitMax) {
						dp1[i + 1][j] += (dp0[i][j] + dp1[i][j]);
					} else if (digitVal == digitMax) {
						dp0[i + 1][j] += dp0[i][j];
						dp1[i + 1][j] += dp1[i][j];
					} else {
						dp1[i + 1][j] += dp1[i][j];
					}
				} else {
					if (j < K) {
						if (digitVal < digitMax) {
							dp1[i + 1][j + 1] += (dp0[i][j] + dp1[i][j]);
						} else if (digitVal == digitMax) {
							dp0[i + 1][j + 1] += dp0[i][j];
							dp1[i + 1][j + 1] += dp1[i][j];
						} else {
							dp1[i + 1][j + 1] += dp1[i][j];
						}
					}
				}
			}
		}
	}

    cout << dp0[ketaNum][K] + dp1[ketaNum][K] << endl;
    return 0;
}


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


public class Main{
	public static void main(String[] args) throws Exception{
		//入力
		String[][] in_data=input();
		

		String A[]=new String[2];
		for(int k=0;k<=in_data.length-1;k++){
		//出力	
			A[0]=in_data[k][0];
			A[1]=in_data[k][1];	
			outPut(A);
		}
	}
	//入力inut関数を用意a
	public static String[][] input() throws Exception{
		
		int s=0;
		String str="";
		String text="";
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while((str=br.readLine())!=null){
		        text=text+str+"\n";
			s=s+1;
			}
		
		String[] tempArray=text.split("\n");

		String twoArray[][]=new String[s][1];
		for(int k=0;k<=s-1;k++){
			twoArray[k]=tempArray[k].split(" ");	
		}
		return twoArray;
	}
	
	//出力処理関数
	public static void outPut(String[] data) throws Exception{
	
	//描写クラスからインスタンス化
		Draw rec=new Draw();
		rec.draw(data,"chessboard");
	}


}

class Draw{
	public void draw(String[] drawArray, String type) throws Exception{
		String mark="";
		String mark2="";
		String mark3="";
		String mark4="";
		int W;
		int H;
		int i=1;
		int j=1;
		int k=1;
		
		H=Integer.parseInt(drawArray[0]);
		W=Integer.parseInt(drawArray[1]);

		if(W==0 && H==0){
			
		}else{
			if(type=="rec"){
		
				while(j<=W){
					mark=mark+"#";
					j=j+1;}
				while(i<=H){
					System.out.println(mark);
					i=i+1;}
			System.out.println("");

			}else if(type=="frame"){
				while(j<=W){
					mark=mark+"#";
					j=j+1;	
				}
				while(k<=W-2){
					mark2=mark2+".";
					k=k+1;	
				}
				while(i<=H){
					if (i==1 || i==H){
					System.out.println(mark);
					i=i+1;
					}else{
					System.out.println("#"+mark2+"#");
					i=i+1;
					}
				}
			System.out.println("");
			}else if(type=="chessboard"){
				for(int p=1;p<=(W/2);p++){
					mark=mark+"#.";
					mark4=mark4+".#";	
				}
				for(int p=1;p<=(W-1)/2;p++){
					mark2=mark2+".#";
					mark3=mark3+"#.";
				}


				while(i<=H){
					if (i%2==1){
						if(W%2==0){
							System.out.println(mark);
						}else{
							System.out.println("#"+mark2);
						}
					i=i+1;	
					}else{
						if(W%2==0){
							System.out.println(mark4);
						}else{
							System.out.println("."+mark3);
						}
					i=i+1;
					}

				}

			System.out.println("");
			}
		}
	}


}


Measured memory_bytes: 26428
var
	ans,m,k,i:Longint;
	c:Char;
	s:String;
begin
	readln(s);
	ans:=114514;
	for c:='a'to'z'do begin
		m:=0;
		k:=0;
		for i:=1 to length(s)do begin
			if s[i]=c then begin
				if m<k then m:=k;
				k:=0;
			end else inc(k);
		end;
		if m<k then m:=k;
		if ans>m then ans:=m;
	end;
	writeln(ans);
end.

Measured memory_bytes: 128
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input! {
        n: u64,
        s: chars,
    }
let mut alphabets=vec![0;26];
for i in s {
alphabets[(i as u32 - 48 - 49) as usize]+=1;
}
let mut ans:u64=1;
for j in alphabets {
ans*=(j+1);
ans%=1000000007;
}
ans-=1;
println!("{}", ans);
}


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

int main(void)
{
	int H, W, A, B;
	cin >> H >> W >> A >> B;
	for (int i = 0; i < 2 * B; i++)
	{
		for (int j = 0; j < A; j++) cout << !(i % 2);
		for (int j = A; j < W; j++) cout << (i % 2);
		cout << endl;
	}
	for (int i = 2 * B; i < H; i++)
	{
		for (int j = 0; j < A; j++) cout << 1;
		for (int j = A; j < W; j++) cout << 0;
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define N 100001
using namespace std;
vector <int> a[N];
int deg[N],n,m,i,u,v,p[N];
int main()
{
   // freopen("ntu.inp","r",stdin);
  //  freopen("ntu.out","w",stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin>>n>>m;
    for(i=1;i<=n-1+m;i++)
    {
        cin>>u>>v;
        a[u].push_back(v); deg[v]++;
    }
    queue <int> q;
    for(u=1;u<=n;u++)
        if(deg[u]==0) q.push(u);
    while(q.size()>0)
    {
        u=q.front(); q.pop();
        for(i=0;i<a[u].size();i++)
        {
            v=a[u][i];
            deg[v]--;
            if(deg[v]==0)
            {
                p[v]=u;
                q.push(v);
            }
        }
    }
    for(u=1;u<=n;u++) cout<<p[u]<<'\n';
}


Measured memory_bytes: 7040
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const int INF = 1e9 + 6;
const ll MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
/* -- template -- */

const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

bool dp[81][81][162 * 81];

int main() {
    int H, W; cin >> H >> W;
    P grid[H][W];
    rep(i, H)
        rep(j, W)
            cin >> grid[i][j].first;

    rep(i, H)
        rep(j, W)
            cin >> grid[i][j].second;
    dp[0][1][0] = true;
    dp[1][0][0] = true;
    rep(h, H) {
        rep(w, W) {
            int d = abs(grid[h][w].first - grid[h][w].second);
            rep(k, 80 * 160 + 1) {
                dp[h + 1][w + 1][k] |= dp[h][w + 1][abs(k - d)];
                dp[h + 1][w + 1][k] |= dp[h][w + 1][k + d];

                dp[h + 1][w + 1][k] |= dp[h + 1][w][abs(k - d)];
                dp[h + 1][w + 1][k] |= dp[h + 1][w][k + d];
            }
        }
    }
    rep(k, 12800) {
        if(dp[H][W][k]) {
            cout << k << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 85248
#include<bits/stdc++.h>
using namespace std;
string s,t;
int main()
{
	cin>>s>>t;
	bool ok=false;
	for(int i=s.size()-1;i>=t.size()-1;i--)
	{
		int ii=i-t.size()+1;
		ok=true;
		for(int j=ii;j<=i;j++)
		{
			if(t[j-ii]!=s[j]&&s[j]!='?')
			{
				ok=false;
				break;
			}
		}
		if(ok)
		{
			for(int j=ii;j<=i;j++)s[j]=t[j-ii];
			break;
		}
	}
	if(!ok)
	{
		cout<<"UNRESTORABLE\n";
		return 0;
	}
	for(int i=0;i<s.size();i++)
		if(s[i]=='?')
			s[i]='a';
	cout<<s<<endl;
	return 0;
}
/*
?tc????
coder
*/


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>

using namespace std;
int main(){
    int  n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n;i++){
        cin >> a[i];
    }
    
    for(int i=n-1; i > 0; i--){
        cout << a[i] << " ";
        
    }
    cout << a[0] << endl;
}


Measured memory_bytes: 3080
N= int(input())
n=[]
j=9
c=0
while N!=0:
    n.append(N%10)
    N//=10
n.reverse()

for i in range(len(n)):
    if n[i-1]==j:
        c+=1

if c > 0:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
#include <iostream>
using namespace std;
 
int main() {
  long long x;
  long long i = 2;
  cin >> x;
  
  while (true) {
    while (x % i != 0) {
      i++;
    }
    if (x == i) {
      break;
    }
    else {
      i = 2;
      x = x + 1;
    }
  }
  cout << x << endl;
  return 0;
}

Measured memory_bytes: 256
r,c=map(int,input().split())
l=[list(map(int,input().split())) for i in range(r)]

l2=[]
for i in range(c):
    l1=[]
    for j in range(r):
        l1.append(l[j][i])
    l2.append(l1)
l3=[sum(l2[i]) for i in range(c)]

l.append(l3)
for i in range(r+1):
    l[i].append(sum(l[i]))
    print(" ".join(map(str,l[i])))


Measured memory_bytes: 5796
#include <bits/stdc++.h>
using namespace std;
#define ll long long
string s,t;
ll solve()
{
    bool f[26] ={};
    for(int i=0;i<t.size();++i)
        f[t[i]-'a'] = 1;
    for(int i=0;i<s.size();++i)
        f[s[i]-'a'] = 0;
    for(int i=0;i<26;++i)
        if( f[i] )
        {
            return -1;
        }
    vector<vector<int> >v(26);
    for(int i=0;i<s.size();++i)
    {
        v[s[i]-'a'].push_back(i);
    }
    ll ans = 0;
    int index = -1;
    for(int i=0;i<t.size();++i)
    {
        auto it = upper_bound(v[t[i]-'a'].begin(),v[t[i]-'a'].end(),index);
        if( it == v[t[i]-'a'].end() )
        {
            ans+=s.size()-1-index;
            index = -1;
            --i;
            continue;
        }
        ans+=*it-index;
        index = *it;
    }
    return ans;
 
}
int main()
{
    cin >> s >> t;
    cout << solve();
}

Measured memory_bytes: 1216
from scipy.misc import comb

N,K = map(int,input().split())
m=1000000007

for i in range(1,K+1):
    B = comb(K-1, i-1, exact=True)
    R = comb(N-K+1, i, exact=True)
    print((B%m *R%m)%m)

Measured memory_bytes: 15240
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
const static int tx[] = {0,1,1,1,0,-1,-1,-1};
const static int ty[] = {-1,-1,0,1,1,1,0,-1};
 
static const double EPS = 1e-8;


int num_of_notes;
int num_of_beauty;
ll force_of_repulsion;
ll sum[200001];
ll dp[2001][2001];
int notes[2001];
ll beauty[100001];

ll compute(int i,int j){
  ll lhs = sum[notes[i]];
  ll rhs = (notes[j] - 1 < 0 ? 0 : sum[notes[j] - 1]);

  return (lhs - rhs) / force_of_repulsion;
}

int main(){
  while(~scanf("%d %d %lld",
               &num_of_notes,
               &num_of_beauty,
               &force_of_repulsion)){

    for(int note_idx = 0; note_idx < num_of_notes; note_idx++){
      scanf("%d",notes + note_idx);
      notes[note_idx]--;
    }

    memset(sum,0,sizeof(sum));

    for(int beauty_idx = 0; beauty_idx < num_of_beauty; beauty_idx++){
      scanf("%d",beauty + beauty_idx);
      sum[beauty_idx] = (beauty_idx - 1 >= 0 ? sum[beauty_idx - 1] : 0) + beauty[beauty_idx];
    }

    sort(notes,notes + num_of_notes);
    reverse(notes,notes + num_of_notes);

    memset(dp,0x3f,sizeof(dp));

    dp[0][0] = 0;
    for(int i=0;i<num_of_notes;i++){
      int next = i + 1;
      if(next >= num_of_notes) break;
      for(int j=0;j<=i;j++){
        dp[next][j]
          = min(dp[next][j],dp[i][j] + compute(i,next));

        dp[next][i]
          = min(dp[next][i],dp[i][j] + compute(j,next));
      }
    }

    ll res = LINF;
    for(int i=0;i<num_of_notes;i++){
      res = min(dp[num_of_notes - 1][i] + compute(i,num_of_notes - 1),res);
    }
    
    printf("%lld\n",res);
  }
}

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

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

struct hoge {
  int s, n;
  string name;
  hoge(int s,int n, string name) : s(s),n(n),name(name) { }
};
bool operator < (const hoge &a, const hoge &b) {
  return a.s!=b.s ? a.s>b.s : a.n < b.n;
}

int main() {
  int n;
  int f = 0;
  while(cin>>n,n) {
    vector<hoge> v;
    REP(i,n) {
      string name;
      int a,b,c;
      cin >> name;
      cin >> a >> b >> c;
      v.push_back(hoge(a*3+c,i,name));
    }
    sort(ALL(v));
    if (f)
      cout << endl;
    else
      f++;
    FOR(it,v) {
      hoge h=*it;
      cout << h.name << "," << h.s << endl;
    }
  }
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef  unsigned int uint;
typedef  long double ld;


int main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	ld a, b;
	cin >> a >> b;
	ld ans = a * b;
	cout << (ll) ans;

	return 0;
}

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

int main(){
  int i,j,n;
  scanf("%d", &n);

  if(n>20){printf("Yes");
    return 0;
  }

  int ANS=0;
  for(i=0;i<6;i++){
    for(j=0;j<3;j++){
      if(4*i+7*j==n){
        ANS++;
      }
    }
  }

  if(ANS==0){printf("No");
  }else{printf("Yes");}
  return 0;
}



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

using namespace std;

int main(){

    int N,M;
    cin>>N;
    vector<long> vec(N);
    long long sums=0;
    for(auto &x:vec){
        cin>>x;
        sums+=x;
    }
    cin>>M;
    vector<long> sum(M);
    for(int i=0;i<M;i++){
        int P,X;
        cin>>P>>X;
        sum[i]=sums-vec[P-1]+X;

    cout<<sum[i]<<endl;

    }



}

Measured memory_bytes: 256
import java.util.Scanner;



public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String N = sc.next();
		String regex = ".9{" + (N.length()-1) + "}";
		Main main = new Main();

		if (N.length() == 1) {
			System.out.println(N);
		}else if(N.matches(regex)){
			System.out.println(main.digitSum(Long.valueOf(N.toString())));
		}else {
			char[] l = N.toCharArray();
			StringBuilder fix = new StringBuilder();

			if (l[0] == '1') {
				for (int i = 1; i < l.length; i++) {
					fix.append("9");
				}
			}else {
				fix.append((char)(l[0] - 1));
				for (int i = 1; i < l.length; i++) {
					fix.append("9");
				}
			}
			System.out.println(main.digitSum(Long.valueOf(fix.toString())));
		}

	}

	public long digitSum(long N) {
		long sum = 0;
		while (N > 0) {
			sum += N % 10;
			N = N / 10;
		}
		return sum;
	}
}


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

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

    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    cout << v.size() << endl;

    return 0;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define lnt long long int
int main()
{
  lnt n;
  cin>>n;
  map<lnt,lnt> arr;
  vector<lnt> v;
  for(int i=0;i<n;i++)
  {
    lnt a;
    cin>>a;
    if(arr[a]==0)
    {
      v.push_back(a);
    }
    arr[a]=arr[a]+1;
    //cout<<arr[a]; 
  }
  //cout<<arr.size();
  if(arr.size()==1)
  {
    if(arr[0]!=0)
    {
      cout<<"Yes";
      return 0;
    }
    else
    {
      cout<<"No";
      return 0;
    }
      
  }
  else if(arr.size()==3)
  {
    auto it = arr.begin();
    lnt prev1 = it->first;
    it++;
    lnt prev2 = it->first;
    it++;
    lnt prev3  = it->first;
    //cout<<prev1<<" "<<(prev2^prev3)<<" "<<prev3<<endl;
    if((prev2^prev3)!=prev1)
    {
      cout<<"No";
      return 0;
    }
    it = arr.begin();
    prev1 = it->second;
    it++;
    prev2 = it->second;
    it++;
    prev3 = it->second;
    if(prev2!=prev1||prev3!=prev1)
    {
      cout<<"No";
      return 0;
    }
    cout<<"Yes";
  }
  else if(arr.size()==2)
  {
    if(arr[0] ==0)
    {
      cout<<"No";
      return 0;
    }
    else
    {
      lnt p1,p2;
      auto it = arr.begin();
      p1 = it->second;
      it++;
      p2 = it->second;
      if(p2==2*p1)
      {
        cout<<"Yes";
        return 0;
      }
      else
      {
          cout<<"No";
          return 0;
      }
      
    }
  }
    
  else
  {
    cout<<"No";
  }
  
}

Measured memory_bytes: 5748
#include<iostream>
using namespace std;
const int MAX = 200001;
int main(){
	int N,A[MAX];
	long long int sum[MAX][3],ans=0;
	bool visit[MAX][3]={0};
	cin>>N;
	for(int i=0;i<N;i++)cin>>A[i];
	for(int i=0;i<N-N%2;i+=2)ans+=A[i];
	
	if(N%2){
		sum[0][2]=A[0];visit[0][2]=true;
		sum[1][1]=A[1];visit[1][1]=true;
		sum[2][0]=A[2];visit[2][0]=true;
		if(N==3)ans=max(A[0],max(A[1],A[2]));
	}else{
		sum[0][1]=A[0];visit[0][1]=true;
		sum[1][0]=A[1];visit[1][0]=true;
		if(N==2)ans=max(A[0],A[1]);
	}
	
	for(int i=0;i+2<N;i++)for(int j=0;j<3;j++){
		if(!visit[i][j])continue;
		for(int k=0;k<=min(j,N-i-3);k++){
			if(visit[i+2+k][j-k])sum[i+2+k][j-k]=max(sum[i+2+k][j-k],sum[i][j]+A[i+2+k]);
			else sum[i+2+k][j-k]=sum[i][j]+A[i+2+k];
			visit[i+2+k][j-k]=true;
			if(i+2+k>=N-(j-k+1))ans=max(ans,sum[i+2+k][j-k]);
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 9732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ss second
#define ff first
ll dp[100100];
int n,k;
ll s[100100];
int go(int idx)
{
    if(idx==n-1)
        return 0;
    ll &ret=dp[idx];
    if(ret!=-1)
        return ret;
    ret=1e12;
    for(int i=1;i<=k;i++)
    {
        if(i+idx<n)
        {
            ret=min(ret,abs(s[idx]-s[idx+i])+go(idx+i));
        }
    }
return ret;
}
int main(){
    memset(dp,-1,sizeof dp);
    cin>>n>>k;
    for(int i=0;i<n;i++)
        scanf("%lld",&s[i]);
    go(0);
    cout<<dp[0];
}


Measured memory_bytes: 6528
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bitset>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef long long LL;

typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<string, int> P;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define REP(i,n)  for(int i=0; i<(n); i++)

//constant
//--------------------------------------------
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const LL MOD = 1e9+7; 
//vector <vector<int>> x(20, vector<int> (20)), y(20,vector<int> (20));
/*int counter_1 (int x) {
    if(x == 0) return 0;
    return counter_1(x >> 1) + (x & 1);
}*/

//int Counter(int x)
/*int factorial(int n) {
    if (n > 0) {
        return n * factorial(n - 1);
    } else {
        return 1;
    }
}*/
int factorial(int n) {
    if (n > 0) {
        return n * factorial(n - 1);
    } else {
        return 1;
    }
}
int main(){
    int n;
    LL r=0,b=0,g=0,k;
    cin >> n;
    string s;
    cin >> s;
    REP(i,n){
        if(s[i]=='R') r++;
        else if(s[i]=='G') g++;
        else b++;
    }
   LL ans=r*g*b;
   //cout << r << g << b << endl;
    REP(i, n){
        //cout << i << endl;
        for(int j = 1+i; j<n; j++){
            //cout << j  << 'j'<< endl;
            int  a=0, o=0, m=0;
            int k=(j-i)+j;
            //cout<< k << 'k' << endl;
            if(k>=n) continue;
            if(s[i]!=s[j]&&s[j]!=s[k]&&s[i]!=s[k]) ans--;

        }
        
    }
    //cout << s[n] << endl;
    cout << ans << endl;
}
    




Measured memory_bytes: 3648
from itertools import permutations

N, M = map(int, input().split())
AB = set([tuple(sorted(map(int, input().split()))) for _ in range(M)])

answer = 0
for pattern in permutations(range(2, N+1), N-1):
    pattern = [1] + list(pattern)
    for i in zip(pattern[:-1], pattern[1:]):
        if tuple(sorted(i)) not in AB:
            break
    else:
        answer += 1
print(answer)

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

typedef long long ll;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) {
    return arg1.first > arg2.first;
}

map<int, int> numsex;
string ss;

void query(int n) {
    cout << n << endl; cout.flush();
    cin >> ss;
    if(ss=="Male") {
        numsex.insert(make_pair(n, 1));
    }
    else if(ss=="Female") {
        numsex.insert(make_pair(n, -1));
    }
    else exit(0);
}

int main(void) {
    int n;
    cin >> n;

    query(0);
    query(n-1);

    int l=0, m, r=n-1;
    for(int i=2;i<20;i++) {
        m = (l+r)/2;
        query(m);

        if((m-l)%2==1&&numsex[l]==numsex[m]) {
            r = m;
        }
        else if((m-l)%2==0&&numsex[l]!=numsex[m]) {
            r = m;
        }
        else if((r-m)%2==1&&numsex[m]==numsex[r]) {
            l = m;
        }
        else {
            l = m;
        }
    }

    return 0;
}


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

using namespace std;
typedef long long ll;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define each(i,mp) for(auto& i:mp)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;
const ll m=1LL<<32;

int main(){

  ll x;cin>>x;
  ll y=0;
  ll num=100;
  while(1){
    if(num>=x){
      out(y);
      return 0;
    }
    num*=1.01;
    y++;
  }

  return 0;
}


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

int main() {
	int N; cin >> N;
	vector<pair<int, int>> R(N);
	for (auto& i : R) { cin >> i.first >> i.second; i.second += i.first; }
	sort(R.begin(), R.end());
	vector<int> dp(N+1,1), f(N);
	for (int i = N-1; i >= 0; i--) {
		int &d = f[i]; d=i+1;
		while (d < N && R[d].first < R[i].second) {
			d=f[d];
		}
		dp[i]=(dp[i+1]+dp[d])%998244353;
	}
	cout << dp[0] << '\n';
	return 0;
}


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

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

  bool ans = true;
  if (S.at(2)!=S.at(3)) ans=false;
  if (S.at(4)!=S.at(5)) ans=false;

  if (ans) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }  
}

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

using namespace std;
int n;
string s;
bool ok(int x){
    map < string, bool > m;
    string cop, e;
    for(int i = 0; i < x; i++){
        cop += s[i];
    }
    for(int i = x; i < x + x; i++){
        e += s[i];
    }
    m[cop] = 1;
    for(int i = 1; i < s.size(); i++){
        if(i + x - 1 < s.size()){
            cop += s[i + x - 1];
        }
        cop.erase(cop.begin());
        if(m[e]){
            return 1;
        }
        m[cop] = 1;
        e.erase(e.begin());
        if(i + x + x - 1 < s.size()){
            e += s[i + x + x - 1];
        }
        else{
            break;
        }
    }
    return 0;
}
int main(){
    cin >> n >> s;
    int l = 1, r = n / 2;
    int res = 0;
    while(l <= r){
        int mid = (l + r) / 2;
        if(ok(mid)){
            l = mid + 1;
            res = mid;
        }
        else{
            r = mid - 1;
        }
    }
    cout << res;
}


Measured memory_bytes: 5828
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define reg register
#pragma GCC optimize(3)
#pragma GCC optimize("02")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#define _inline __inline__ __attribute__((always_inline))
using namespace std;
class complex{
public:
    inline char gc(){
        static const signed IN_LEN=1<<18|1;
        static char buf[IN_LEN],*s,*t;
        return (s==t)&&(t=(s=buf)+fread(buf,1,IN_LEN,stdin)),s==t?-1:*s++;
    }
    template <typename _Tp> _inline complex & operator >> (_Tp &x){
        static char ch,sgn; ch=gc(),sgn=0;
        for(;!isdigit(ch);ch=gc()){if(ch==-1)return *this;sgn|=ch=='-';}
        for(x=0;isdigit(ch);ch=gc())x=x*10+(ch^'0');
        sgn&&(x=-x); return *this;
    }
}inc;
int n;
int a[105];
signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	int maxn=-1<<30;
	for(int i=1;i<=n;i++) cin>>a[i],maxn=max(maxn,a[i]);
	int ans=2147483647;
	for(int i=1;i<=maxn;i++){
		int temp=0;
		for(int j=1;j<=n;j++) temp+=(a[j]-i)*(a[j]-i);
		ans=min(ans,temp);
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

#define LL long long

const int maxN = 2e3 + 2;
const int MOD = 1e9 + 7;

int N, K;
int F[maxN][maxN], fac[maxN * maxN];

LL qpow(LL a, LL b) {
    LL ans = 1;
    while (b) {
        if (b & 1) {
            ans = ans * a % MOD;
        }
        a = a * a % MOD;
        b >>= 1;
    }
    return ans;
}

void init() {
    fac[0] = 1;
    for (int i = 1; i <= N * K; ++i) 
        fac[i] = 1ll * fac[i - 1] * i % MOD; 
}

int Combine(int n, int m) { 
    if (n < m) return 0;
    return 1ll * fac[n] * qpow(fac[m], MOD - 2) % MOD * qpow(fac[n - m], MOD - 2) % MOD;
}

signed main() {
   
    cin >> N >> K;
    if (K == 1) return puts("1"), 0;
    init();
    F[0][0] = 1;
    for (int i = 1; i <= N; ++i) {
        for (int j = 0; j <= i; ++j) {
            F[i][j] = (1ll * F[i - 1][j] + 1ll * (i > 0) * F[i][j - 1] *
                        Combine(N * K - (j - 1) * (K - 1) - i - 1, K - 2) % MOD) % MOD;
        }
    }
    cout << 1ll * F[N][N] * fac[N] % MOD << endl;
}


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

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
const int N = 300006;

int main() { 
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    ll ans = 0;
    map<ll,ll> h;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        h[i - a[i]]++;
    }
    for (int i = 1; i <= n; i++) {
        h[i - a[i]]--;
        ans += h[i + a[i]];
    }
    cout << ans << '\n';
    return 0; 
}
 

Measured memory_bytes: 26588
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
//#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define mp make_pair
#define all(x) x.begin(),x.end()
using namespace std;
int n, q, a[120000], x;
signed main() {
	cin >> n >> q; for1(i, n) cin >> a[i];
	for1(sqlupp, q) {
		cin >> x; int ans = 0;
		int s = 1, e = 1, sum = a[1];
		while (s <= n) {
			int p = e - s + 1;
			while (e < n && sum + a[e+1] <= x) { p++; e++; sum += a[e]; }
			ans += p * !(s == e && a[s] > x);
			sum -= a[s]; s++;
			if (e < s) { e = s; sum = a[e]; }
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 3880
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n = int(input())
    ans = 0
    for a in range(1,n):
        if a ** 2 >= n:
            break
        for b in range(a,n):
            if a * b >= n:
                break
            if a == b:
                ans += 1
            else:
                ans += 2
    print(ans)
        

if __name__=='__main__':
    main()

Measured memory_bytes: 64816
import java.util.*;

public class Main{

    int w,h;
    int[][] grid;
    int[] dx = {-1,0,1,0};
    int[] dy = {-1,-1,-1,-2};

    void solve(){
        Scanner sc = new Scanner(System.in);

        while(true){
            w = sc.nextInt();
            h = sc.nextInt();
            if(w==0 && h==0) break;

            grid = new int[h][w];
            for(int i=0; i<h; i++){
                for(int j=0; j<w; j++){
                    grid[i][j] = sc.nextInt();
                }
            }

            int[][] dp = new int[h][w];
            for(int i=0; i<w; i++){
                if(grid[0][i]==0) dp[0][i] = 1;
            }

            for(int i=0; i<h; i++){
                for(int j=0; j<w; j++){
                    if(grid[i][j]==0){
                        for(int k=0; k<4; k++){
                            int nx = j+dx[k], ny = i+dy[k];
                            if(nx<0 || nx>=w || ny<0 || ny>=h) continue;
                            if((k<=2 && grid[ny][nx]==0) || (k==3 && grid[ny][nx]==2)){
                                dp[i][j] += dp[ny][nx];
                            }
                        }
                    }else if(grid[i][j]==2){
                        if(i-1>=0 && grid[i-1][j]==0) dp[i][j] += dp[i-1][j];
                        if(i-2>=0 && grid[i-2][j]==2) dp[i][j] += dp[i-2][j];
                    }
                }
                //System.out.println(Arrays.toString(dp[i]));
            }

            int ans = 0;
            for(int i=0; i<w; i++){
                ans += dp[h-1][i];
                if(h>=3 && grid[h-2][i]==2) ans += dp[h-2][i];
            }

            System.out.println(ans);
        }
    }

    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 12000
import java.util.Scanner;
public class Main {

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

		if(n == 0) {
			System.out.println("0");
		}
		else {
			String s = "";
			int c = 0;
			while(true){
				long pow = 2L << c;
				if(n % pow != 0) {
					n -= Math.pow(-2, c);
					s = "1" + s;
				}
				else {
					s = "0" + s;
				}
				if(n == 0)
					break;
				c++;
			}
			
			System.out.println(s);
		}
	}
		

}


Measured memory_bytes: 22100
#include<iostream>
#include<math.h>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<stdlib.h>
using namespace std;
#define PI 3.14159265358979
typedef  long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#include<set>


//---------------------------------------------
 


int main (void)
{
    int n;
    cin>>n;

    vector<int> a(n);
    rep(i,n) cin>>a[i];
    sort(a.begin(),a.end());

   int ans = INT_MAX;
    for(int i = a[0];i<=a[n-1];i++)
    { 
        int cost = 0;
        rep(j,n) cost += pow((i-a[j]),2);
        ans =min(ans,cost);

    }

    cout<<ans<<endl;

}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PI;
typedef pair<LL, LL> PLL;
const LL MOD = 1000000007LL;
const int inf = 1e9;
const LL INF = 1e18;
struct edge {
	int to, cap, rev;
	edge(int to, int cap, int rev) :to(to), cap(cap), rev(rev) {}
};
const int MAX_V = 210;
vector<edge> G[MAX_V];
int level[MAX_V];
int iter[MAX_V];
void add_edge(int from, int to, int cap) {
	G[from].emplace_back(to, cap, G[to].size());
	G[to].emplace_back(from, 0, G[from].size() - 1);
}
void bfs(int s) {
	memset(level, -1, sizeof(level));
	queue<int> que;
	level[s] = 0;
	que.push(s);
	while (!que.empty()) {
		int v = que.front(); que.pop();
		for (edge e : G[v]) {
			if (e.cap > 0 && level[e.to] < 0) {
				level[e.to] = level[v] + 1;
				que.push(e.to);
			}
		}
	}
}
int dfs(int v, int t, int f) {
	if (v == t) return f;
	for (int &i = iter[v]; i < G[v].size(); i++) {
		edge &e = G[v][i];
		if (e.cap > 0 && level[v] < level[e.to]) {
			int d = dfs(e.to, t, min(f, e.cap));
			if (d > 0) {
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}
int max_flow(int s, int t) {
	int flow = 0;
	for (;;) {
		bfs(s);
		if (level[t] < 0) return flow;
		memset(iter, 0, sizeof(iter));
		int f;
		while ((f = dfs(s, t, inf)) > 0) flow += f;
	}
}
int main() {
	int N;
	cin >> N;
	int a[100], b[100];
	int c[100], d[100];
	for (int i = 0; i < N; i++) cin >> a[i] >> b[i];
	for (int i = 0; i < N; i++) cin >> c[i] >> d[i];
	for (int i = 1; i <= N; i++) add_edge(0, i, 1), add_edge(i + N, 2 * N + 1, 1);
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) {
			if (a[i - 1] < c[j - 1] && b[i - 1] < d[j - 1]) {
				add_edge(i, j + N, 1);
			}
		}
	}
	cout << max_flow(0, 2 * N + 1) << endl;
}

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

int main(){
  string s;
  int sum,k;
  cin>>s;
  k = atoi(s.c_str());
  sum=0;
  
  for(int i=0;i<s.length();i++){
    sum += s[i] - '0';
  }
  if(k%sum==0)
    cout<<"Yes"<<endl;
  else 
    cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
def euc(x, y):
	if y == 0: return x
	return euc(y, x%y)
N = int(input())
clocks = []
for i in range(0, N):
	clocks.append(int(input()))
ans = clocks[0]
for i in range(1, N):
	ans = ans * clocks[i] // euc(ans, clocks[i])
print(ans)

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

int main(){
  int n,T; cin >> n >> T;
  vector<pii> a(n);
  rep(i,n){
    int x,y; cin >> x >> y;
    a[i] = mp(x, y);
  }
  sort(all(a));

  vvi dp1(n+1,vi(T+1,0));
  rep(i,n) rep(t,T+1) {
    dp1[i+1][t] = dp1[i][t];
    if(t >= a[i].first) chmax(dp1[i+1][t], dp1[i][t-a[i].first] + a[i].second);
  }

  int ans = 0;
  rep(i,n) chmax(ans, dp1[i][T-1] + a[i].second);

  cout << ans << endl;
}

Measured memory_bytes: 35584
#include<bits/stdc++.h>
using namespace std;
# define ld long double
#define lli long long int
int main()
{

lli n,k;
cin>>n>>k;

lli x=ceil((ld)n/(ld)k);
lli y=x-1;

lli ans=min(abs(n-x*k),abs(n-y*k));

cout<<ans;




	return 0;
}

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

int n;
vector<int> et[100000];

int grundy(int v, int p) {
	int g = 0;
	for (int i = 0; i < et[v].size(); i++) {
		if (et[v][i] == p) continue;
		g ^= grundy(et[v][i], v) + 1;
	}
	return g;
}

int main() {
	int i;
	
	cin >> n;
	for (i = 0; i < n - 1; i++) {
		int x, y;
		cin >> x >> y; x--; y--;
		et[x].push_back(y);
		et[y].push_back(x);
	}
	
	if (grundy(0, -1)) cout << "Alice" << endl;
	else cout << "Bob" << endl;
	return 0;
}

Measured memory_bytes: 11904
#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;
  vector<int> W(N);
  rep(i,N)
  {
    cin >> W[i];
  }
  int sum = 0;
  rep(i,N)
  {
    sum += W[i];
  }
  int m = 10000;
  int sum2 = 0;
  rep(i,N)
  {
    sum2 += W[i];
    m = min(m,abs(sum2*2-sum));
  }
  cout << m << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <iomanip>
#include <map>
#include <stack>
#include <queue>
#include <sstream>
#include <bitset>

using namespace std;

typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n,p[110];
    cin>>n;
    string s[110];
    vector<pair<int,string>> d;
    for(int i=0;i<n;i++) {
        cin>>s[i]>>p[i];
        d.push_back(make_pair(p[i], s[i]));
    }
    sort(s,s+n);
    vector<string> ss;
    ss.push_back(s[0]);
    for(int i=1;i<n;i++){
        if(s[i]!=s[i-1]) ss.push_back(s[i]);
    }
    for(int i=0;i<ss.size();i++){
        vector<pair<int,int>> f;
        for(int j=0;j<n;j++){
            if(d.at(j).second==ss.at(i)) {
                f.push_back(make_pair(d.at(j).first, j));
            }
        }
        sort(f.begin(),f.end(),greater<>());
        for(int j=0;j<f.size();j++) cout<<f.at(j).second+1<<endl;
    }
}

Measured memory_bytes: 256
import math


def cnt(l):
    n = 1
    while not l == []:
        x = l.pop(0)
        n += math.factorial(len(l)) * len([y for y in l if y < x])
    return n


def resolve():
    n = int(input())
    p = list(map(int, input().split()))
    q = list(map(int, input().split()))
    print(abs(cnt(p) - cnt(q)))


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 3060
NAB = list(map(int,input().split()))
a = NAB[0] % (NAB[1] + NAB[2])
b = int(NAB[0] / (NAB[1] + NAB[2]))
if a <= NAB[1]:
	print(a + NAB[1] * b)
else:
  print(NAB[1] + NAB[1] * b)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

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

using namespace std;

namespace mp = boost::multiprecision;

using ll = long long;
using Bint = mp::cpp_int;
ll mod = pow(10, 9) + 7;

int main() {
    // source
    ll n;
    cin >> n;
    ll t[n], x[n], y[n];
    rep(i, n) { cin >> t[i] >> x[i] >> y[i]; }

    ll ans = true;
    ll x_now = 0, y_now = 0, t_now = 0;
    rep(i, n) {
        ll dist = abs(x_now - x[i]) + abs(y_now - y[i]);

        if (dist <= t[i] - t_now && (t[i] - t_now - dist) % 2 == 0) {
        } else {
            ans = false;
        }
        x_now = x[i];
        y_now = y[i];
        t_now = t[i];
    }

    if (ans) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}



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

#define INF INT_MAX
#define UINF UINT_MAX
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef std::pair<int,int> pii;

using namespace std;

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

    ll n,m;
    cin >> n >> m;

    vector<ll> wa(n+10,0),ac(n+10,0);
    REP(i,m){
        int p;
        string s;
        cin >> p >> s;
        if(ac[p] == 0 && s == "WA"){
            wa[p]++;
        }else if(ac[p] == 0 && s == "AC"){
            ac[p]++;
        }
    }

    ll ans_ac = 0,ans_wa = 0;
    for(int i = 1;i < n+10;i++){
        ans_ac += ac[i];
        if(ac[i] > 0)ans_wa += wa[i];
    }

    cout << ans_ac << " " << ans_wa << endl;
    return 0;
}

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

int main(){
  int building[4][3][10];
  for(int i=0;i<4;i++){
    for(int j=0;j<3;j++){
      for(int k=0;k<10;k++){
        building[i][j][k] = 0;
      }
    }
  }

  int n;
  cin >> n;

  int b,f,r,v;
  for(int i=0;i<n;i++){
    cin >> b >> f >> r >> v;
    building[b-1][f-1][r-1] += v;
  }

  for(int i=0;i<4;i++){
    for(int j=0;j<3;j++){
      for(int k=0;k<10;k++){
        cout << " " << building[i][j][k];
      }
      cout << endl;
    }
    if(i<3) cout << "####################" << endl;
  }

  return 0;
}

Measured memory_bytes: 1168
def cost(a):
    total = 0
    for i in range(1, len(a)):
        total += abs(a[i] - a[i-1])
    return total

def cancel(a, i, total):
    prev = a[i-1]
    spot = a[i]
    nxt = a[i+1]
    if (nxt >= prev and spot < prev) or (nxt <= prev and spot > prev):
        return total - 2 * abs(prev - spot)
    if (nxt >= prev and spot > nxt) or (nxt <= prev and spot < nxt):
        return total - 2 * abs(nxt - spot)
    return total
        
    
if __name__ == '__main__':
    _ = int(input())
    a = [0] + list(map(int, input().split()))
    a.append(0)
    total = cost(a)
    for i in range(1, len(a)-1):
        print(cancel(a, i, total))

Measured memory_bytes: 14172
while True:
      n, m = map(int, raw_input().split())
      if n == 0 and m == 0:
            break
      p = [ i+1 for i in range(n) ]
      np = n; a = 0
      while np > 1:
            a = (a+m-1)%len(p)
            p.pop(a)
            np -= 1
      print p[0]

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

using namespace std;

const int inf = 1e9;

int main () {

  ios_base::sync_with_stdio(false);
  cin.tie(nullptr); cout.tie(nullptr);
  
  string s; cin >> s;
  if (s == "RRR") {
    cout << 3 << '\n';
  }else if (s == "SSS") {
    cout << 0 << '\n';
  }else {
    for (int i = 0; i < 2; ++i) {
      if (s.substr(i, 2) == "RR") {
        cout << 2 << '\n'; return 0;
      }
    }cout << 1 << '\n';
  }

  return 0;
}




Measured memory_bytes: 3652
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define MAXN (100000 + 5)
#define INF (0x7ffffff)
using namespace std;
int n, a[MAXN];
inline int mabs(int x)
{ return (x > 0 ? x : (-x)); }
int main()
{
//    cout << "Hello world!" << endl;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	sort(a + 1, a + n + 1);
	printf("%d ", a[n]);
	int *fi = upper_bound(a + 1, a + n, a[n] >> 1);
	int ans, tmp;
	if (fi != a + n)
		ans = *fi;
	else
		ans = -INF;
	fi = upper_bound(a + 1, a + n, a[n] >> 1) - 1;
	if (fi != a)
		tmp = *fi;
	else
		tmp = -INF;
	if (mabs((a[n] >> 1) - ans) >= mabs(((a[n] + 1) >> 1) - tmp))
		ans = tmp;
	printf("%d", ans);

    return 0;
}

/*
3
6 3 4


n!/m!(n - m)!

1
2	1
3	3	1
4	6	4	1
5	10	10	5	1
6	15	20	15	6	1
7	21	35	35	21	7	1
8	28	56	70	56	28	8	1
9	36	84	126	126	84	36	9	1
*/


Measured memory_bytes: 640