akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define randome_generate srand(std::chrono::high_resolution_clock::now().time_since_epoch().count())
using namespace std;
int dp[3010][3010];
pair<int,int> pre[3010][3010];
pair<int,int> xxxx;
string s,t;
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>s>>t;
	int ns=s.size();
	int nt=t.size();
	s="#"+s;
	t="#"+t;
	for(int i=1;i<=ns;i++){
		for(int j=1;j<=nt;j++){
			if(s[i]==t[j]){
				dp[i][j]=dp[i-1][j-1]+1;
				pre[i][j]=make_pair(i-1,j-1); 
			}
			if(dp[i][j-1]>=dp[i][j]){
				dp[i][j]=dp[i][j-1];
				pre[i][j]=make_pair(i,j-1);
			}
			if(dp[i-1][j]>=dp[i][j]){
				dp[i][j]=dp[i-1][j];
				pre[i][j]=make_pair(i-1,j);
			}
		}
	}
	int a=ns,b=nt;
	string ans="";
	while(a&&b){
		if(pre[a][b].first==a-1&&pre[a][b].second==b-1){
			ans+=s[a];
		}
		xxxx=pre[a][b];
		a=xxxx.first;
		b=xxxx.second;
	}
	reverse(ans.begin(),ans.end());
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 106368
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>
#include<queue>
#include<stack>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用

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

	string s;
	cin >> s;
	bool ans = true;
	rep(i, s.size())
	{
		if (i % 2 == 0)
		{
			if (s[i] == 'R' || s[i] == 'U' || s[i] == 'D')
				continue;
			else
				ans = false;
		}
		else
		{
			if (s[i] == 'L' || s[i] == 'U' || s[i] == 'D')
				continue;
			else
				ans = false;
		}
		if (!ans)
		{
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>

using namespace std;

int main(){
 
  int n;
  
  cin >> n;
  
  vector<tuple<string, int, int>> data(n);
  
  for(int i = 0; i < n; i++){
    string s;
    int p;
    
    cin >> s >> p;
    
    data[i] = make_tuple(s, -p, i + 1);
  }
  
  sort(data.begin(), data.end());
  
  for(int i = 0; i < n; i++){
    cout << get<2>(data[i]) << endl;
  }
  
  return 0;
}

Measured memory_bytes: 764
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long int


int main(void)
{
  ll X;
  scanf("%lld",&X);
   ll dep=100;
   ll count=1;
  while (1)
  {
     dep+=(dep*1)/100;
	 if (dep<X)count++;
     else break;
  }	
  
  printf("%lld",count);
	
	return 0;
}


Measured memory_bytes: 1736
#include <bits/stdc++.h>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define endl "\n"
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define traceV(v) for(auto x:v)cout<<x<<" ";cout<<endl
#define traceM(mp) for(auto x:mp)cout<<x.first<<" "<<x.second<<endl

//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 2e+9 + 10;
typedef pair<ll, ll> P;

int F(ll A, ll B) {
  int cnt = 0;
  int x = max(A,B);
  while(x) {
    x/=10;
    cnt++;
  }
  return cnt;
}

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

  ll N; cin >> N;
  int res = 11;  // MAX
  reps(A, 1, 1000001) {  // min(A,B)<=100000=sqrt(max(N))
    ll B;
    if(N%A==0)B = N/A;
    else continue;
    res = min(res, F(A,B));
  }

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
import sys

readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))


n,m = readints()

ans = [-1]*n

flag = 1
for i in range(m):
    s,c = readints()
    s-=1
    if s==c==0 and n!=1:
        flag = 0
        break
    elif ans[s] == -1:
        ans[s]=c
    elif ans[s]!=c:
        flag = 0
        break

if flag:
    if ans[0]==-1:
        if n==1:
            ans[0]=0
        else:
            ans[0]=1
    ans = [x if x>=0 else 0 for x in ans]
    print(''.join(map(str,ans)))
else:
    print(-1)

Measured memory_bytes: 38384
import math

if __name__ == "__main__":
    a, b, h, m = map(int, input().split())
    dm = m*6
    dh = h*30 + m/2
    d = math.fabs(dh - dm)
    d = a**2 + b**2 - 2*a*b*math.cos(math.radians(d))
    print("%.10lf"%math.sqrt(d))


Measured memory_bytes: 9544
package main

import "fmt"

func main() {
	var K, A, B int
	fmt.Scan(&K)
	fmt.Scan(&A, &B)

	i := 1
	for ; i <= A; i++ {
		if (i * K) >= A {
			break
		}
	}
	if (i * K) <= B {
		fmt.Println("OK")
	} else {
		fmt.Println("NG")
	}
}

Measured memory_bytes: 1752
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>

using namespace std;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))

int main()
{
	int n, a, count = 0;
	cin >> n;
	map<int, int> mp;
	rep(i, 1, n)
	{
		cin >> a;
		if (mp[a] == 0)
		{
			mp[a] = 1;
		}
		else
		{
			mp[a] = 0;
		}
	}
	for (auto itr = mp.begin(); itr != mp.end(); ++itr)
	{
		if (itr->second)
		{
			++count;
		}
	}
	cout << count << endl;
}

Measured memory_bytes: 4992
/*
ID: taoxiaa1
PROG: concom
LANG: C++
*/
//URAL ID:248353QC
#include<bits/stdc++.h>
using namespace std;
//FILE *fin, *out;
//fin = fopen("money.fin", "r");
//out = fopen("money.out", "w");
//ofstream fout("money.out");
//ifstream fin("money.in");
int main()
{
    int a,b,c,x,y;
    scanf("%d%d%d%d%d",&a,&b,&c,&x,&y);
    long long sum=0;
    if(2*c<=a+b){
        int z=min(x,y);
        sum+=z*c*2;
        x-=z,y-=z;
        if(x!=0){
            sum+=min(x*2*c,x*a);
        }
        if(y!=0){
            sum+=min(y*2*c,y*b);
        }
    }
    else {
        sum+=a*x+b*y;
    }
    printf("%lld\n",sum);
    return 0;
}


Measured memory_bytes: 256
def powmod b, e, m
	z = 1
	while 0 < e
		z = z*b%m if e&1 == 1
		b, e = b*b%m, e>>1
	end
	return z
end
def xgcd a, b
	x, y, u, v = 1, 0, 0, 1
	until b == 0
		q, a, b = a/b, b, a%b
		x, y, u, v = u, v, x-q*u, y-q*v
	end
	return a, x, y
end
def imod a, m
	d, x, = xgcd a, m
	return nil unless d == 1
	return 0<x ? x : x+m
end

(N,A,B),M = gets.split.map(&:to_i), 1000000007

a,b, = [N-A,A,N-B,B].sort
c,d = N-b+1,N-a+1
f = lambda{|x,y| x*y%M }

x = powmod 2,N,M
y = (d..N).inject(imod((2..a).inject(1,&f),M),&f)
z = (c...d).inject(imod((a+1..b).inject(1,&f),M),&f)*y%M
p (x-y+M-z+M-1)%M


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)


void solve(std::string S){
  map<char, bool> tab;
  char result = '#';
  REP(i, S.size()) {
    tab[S[i]] = true;
  }

  REP(i, 26) {
    if(!tab[('a'+i)]) {
      cout << (char)('a'+i) << endl;
      goto solved;
    }
  }
  cout << "None" << endl;

  return;
  solved:
  return;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
  std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 512
#include<stdio.h>

int main(void) {
	int i = 1, n, k, j = 0;

	scanf("%d %d", &n, &k);

	if (2 > k || k > 10 || n < 1 || n > 1000000000) {
		return 0;
	}
	do {
		i *= k;
		j++;
	} while (i <= n);
	printf("%d", j);

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define ALL(x) x.begin(),x.end()
#define MOD (1000000000+7)
using namespace std;
#define PI 3.14159265359
#define tMOD 998244353
#define mkpr(x,y) make_pair(x,y)

int main(){
  ll X;
  cin>>X;


  ll cnum = 105;
  ll check = X%100;
  ll ama = check/5;
  ll bma = check%5;

  ll tmp=0;
  tmp+= 105*ama;
  if(bma!=0)
  tmp+= 100+bma;

  if(tmp<=X){
    cout<<1<<endl;
  }
  else{
    cout<<0<<endl;
  }



}



Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
struct node{int n;struct node *np,*pp;};
struct node *fp=NULL,*ep,*n,*nfp,*nep;
int N,t,a;
char cmd[15];

void del(struct node*dp)
{
	struct node *nnp=dp->np;
	struct node *npp=dp->pp;
	npp->np=nnp;
	nnp->pp=npp;
	free(dp);
}

int main()
{
	scanf("%d\n",&N);
	for(;N--;)
	{
		scanf("%s",cmd);
		if(cmd[0]=='i')
		{
			scanf("%d\n",&t);
			struct node *tp=(struct node*)malloc(sizeof(struct node));
			tp->n=t;
			if(fp==NULL)
			{
				tp->np=tp->pp=tp;
				fp=tp;
				ep=tp;
				tp->np=fp;
			}
			else
			{
				tp->np=fp;
				fp->pp=ep->np=tp;
				tp->pp=ep;
				fp=tp;
			}
		}
		else
		{
			if(cmd[6]=='F')
			{
				nfp=fp;
				fp=fp->np;
				del(nfp);
			}
			else if(cmd[6]=='L')
			{
				nep=ep;
				ep=ep->pp;
				del(nep);
			}
			else
			{
				scanf("%d\n",&t);a=0;
				for(n=fp;n->n!=t&&(!a||n!=fp);)
					n=n->np,a++;
				if(n->n!=t)continue;
				if(n==fp)
					fp=fp->np;
				if(n==ep)
					ep=ep->pp;
				del(n);
			}
		}
	}
	for(n=fp,t=1;t||n!=fp;n=n->np)
		t=!printf("%d%c",n->n,n->np==fp?'\n':' ');
	return 0;
}



Measured memory_bytes: 32956
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define LLMAX (1ll << 60) - 1
#define llMAX (1 << 30) - 1
#define MOD 1000000007 
#define NMAX 1000*100+1
#define MSET(x,y) memset(x,y,sizeof(x))
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define vi vector<ll>
#define prll(x)    for(auto it=x.begin();it!=x.end();it++) cout<<*it<<' '; cout<<endl;
#define in(x,n)   for(ll e=0;e<n;e++){ll y;cin>>y;x.pb(y);}
#define vl vector<long long>
#define ii pair<ll,ll>
#define pll pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define mp make_pair


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    ll a[30];
    cin>>n;
    for(int i=0;i<n;i++){
    	cin>>a[i];
	}
	ll m=-1,ans=0;
	for(int i=0;i<n;i++){
    	if(a[i]>=m)
    	ans++;
    	m=max(m,a[i]);
	}
	cout<<ans;
    return 0;
}
 

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

using namespace std;

int main() {
    long n, k;
    cin >> n >> k;
    long a[n], amari[n], total=0;
    for (auto &ai:a) {
        cin >> ai;
        total += ai;
    }
    vector<long> insu;
    long root = sqrt(total);
    for (long i=1; i<=root; i++) {
        if (total % i) continue;
        insu.push_back(i);
        insu.push_back(total/i);
    }
    sort(insu.begin(), insu.end(), greater<long>());
    for (auto in:insu) {
        long sum = 0;
        for (int i=0; i<n; i++) {
            amari[i] = a[i] % in;
            sum += amari[i];
        }
        if (sum % in) continue;
        sort(amari, amari+n, greater<long>());
        long cnt = 0;
        for (int i=0; i<sum/in; i++)
            cnt += in - amari[i];
        if (cnt <= k) {
            cout << in << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define MOD 1000000007
#define INF 1000000000000000000

#define MI modint<MOD>
template<int mod>struct modint{
	int x;
	modint():x(0){}
	modint(LL n):x(n>=0?n%mod:(mod-(-n)%mod)%mod){}
	modint &operator+=(const modint &n){if((x+=n.x)>=mod)x-=mod;return *this;}
	modint &operator-=(const modint &n){if((x+=mod-n.x)>=mod)x-=mod;return *this;}
	modint &operator++(){*this+=1;return *this;}
  modint &operator--(){*this-=1;return *this;}
	modint &operator*=(const modint &n){x=(int)((LL)x*n.x%mod);return *this;}
	modint &operator/=(const modint &n){*this*=n.inv();return *this;}
	modint operator-()const{return modint(-x);}
	modint operator+(const modint &n)const{return modint(*this)+=n;}
	modint operator-(const modint &n)const{return modint(*this)-=n;}
	modint operator++(int){modint ret(*this);*this+=1;return ret;}
  modint operator--(int){modint ret(*this);*this-=1;return ret;}
	modint operator*(const modint &n)const{return modint(*this)*=n;}
	modint operator/(const modint &n)const{return modint(*this)/=n;}
	bool operator<(const modint &n)const{return x<n.x;}
	bool operator>(const modint &n)const{return x>n.x;}
	bool operator<=(const modint &n)const{return x<=n.x;}
	bool operator>=(const modint &n)const{return x>=n.x;}
	bool operator!=(const modint &n)const{return x!=n.x;}
	bool operator==(const modint &n)const{return x==n.x;}
	friend istream &operator>>(istream &is,modint &n){LL l;is>>l;n=modint<mod>(l);return is;}
	friend ostream &operator<<(ostream &os,const modint &n){return os<<n.x;}
	int getmod(){return mod;}
	modint inv()const{int a=x,b=mod,c=1,d=0,n;while(b){n=a/b;swap(a-=n*b,b);swap(c-=n*d,d);}return modint(c);}
	modint pow(LL n)const{modint ret(1),m(x);while(n){if(n&1)ret*=m;m*=m;n>>=1;}return ret;}
};

int main() {
	LL N;
	MI m;
	cin>>N;
	LL D[N],E[N];
	for(LL i=0;i<N;i++){
		cin>>D[i]>>E[i];
	}
	for(LL i=0; i<N-2; i++){
		if(D[i]==E[i]&&D[i+1]==E[i+1]&&D[i+2]==E[i+2]){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
}


Measured memory_bytes: 3584
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <cstring>

#define INF_LL 9000000000000000000
#define INF 2000000000

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

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<int, PII> PPII;
typedef pair<int, PPII> PPPII;

class Union_find{
private:
	vector<int> par;
	vector<int> rank;
	int n;

public:
	Union_find(int a){
		n = a;
		for(int i = 0;i < n;i++){
			par.push_back(i);
			rank.push_back(0);
		}
	}

	int find(int x){
		if(par[x] == x){
			return x;
		}else{
			return par[x] = find(par[x]);
		}
	}

	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return;

		if(rank[x] < rank[y]){
			par[x] = y;
		}else{
			par[y] = x;
			if(rank[x] == rank[y]) rank[x]++;
		}
	}

	bool same(int x, int y){
		return find(x) == find(y);
	}
};

int main(void){
	ll res = 0;
	int n, m;
	int pass[100010] = {};
	cin >> n >> m;
	int from, to;
	cin >> from;
	from--;
	REP(i, m-1){
		cin >> to;
		to--;
		pass[min(from, to)]++;
		pass[max(from, to)]--;
		from = to;
	}
	REP(i, n-1){
		pass[i+1] += pass[i];
	}
	REP(i, n-1){
		int a, b, c;
		cin >> a >> b >> c;
		res += min((ll)a*pass[i], (ll)b*pass[i]+c);
	}
	cout << res << endl;
}

Measured memory_bytes: 3492
/* Generated by powerful Codeforces Tool
 * You can download the binary file in here https://github.com/xalanq/cf-tool (win, osx, linux)
 * Author: step_by_step
 * Time: 2020-03-19 17:35:03
**/

//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
  
#include <iostream>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <assert.h>
#include <memory.h>
#include <time.h>
#include <bitset>

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = (l); i < (r); i++)
#define repb(i, r, l) for (int i = (r); i > (l); i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)
#define rank qwertyuio
#define next dfghjk
#define prev fhsgfhjf
#define plus fsghsf
#define minus ytryr
  
using namespace std;
  
inline bool setmin(int &x, int y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(int &x, int y) { return (y > x) ? x = y, 1 : 0; }
inline bool setmin(ll &x, ll y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(ll &x, ll y) { return (y > x) ? x = y, 1 : 0; }
  
const int N = 100000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 239;
const int P1 = 31;
const int P2 = 57;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const int MOD2 = 998244353;
const ld eps = 1e-9;
const double pi = atan2(0, -1);
const int ABC = 26;

int main()
{
    //freopen("circus.in", "r", stdin);
    //freopen("circus.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    cout << fixed;
    //ll TL = 10.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    string s;
    cin >> s;
    rep(i, 0, sz(s)) {
        if (s[i] == '?') {
            s[i] = 'D';
        }
    }
    cout << s << "\n";
    return 0;
}



Measured memory_bytes: 3780
import bisect


def answer(n: int, m: int, x: int, a: []) -> int:
    i = bisect.bisect_left(a, x)
    return min(i, len(a) - i)


def main():
    n, m, x = map(int, input().split())
    a = list(map(int, input().split()))
    print(answer(n, m, x, a))


if __name__ == '__main__':
    main()

Measured memory_bytes: 9076
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    int n,k;cin>>n>>k;
    int r,s,p;cin>>r>>s>>p;
    string t;cin>>t;
    ll ans=0;
    map<char,ll> mp;
    mp['r']=p;
    mp['s']=r;
    mp['p']=s;
    rep(i,0,k){
        char ma='u';
        for(int j=i;j<n;j+=k){
            char now=t[j];
            if(ma=='u'){
                ans+=mp[now];
                ma=now;
            }
            else{
                if(ma==now){
                    ma='u';
                    continue;
                }
                else{
                    ans+=mp[now];
                    ma=now;
                }
            }
        }
    }
    cout<<ans<<endl;
}


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

typedef long long ll;
const int INF = 1e9;
const ll INFF = 1e18;
const int MAXN = 510;
const int MOD = 1e9 + 7;

char tab[1010][1010];
int dist[1010][1010];
int n,m;
queue< pair< pair<int,int>,int > > q;

int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};

void bfs()
{
	while (!q.empty())
	{
		pair< pair<int,int>,int > depan = q.front();
		q.pop();
		int x = depan.first.first;
		int y = depan.first.second;
		int step = depan.second;
		// cout << x << " " << y << " " << step << endl;
		for (int i = 0 ; i < 4 ; i++)
		{
			int xx = x + dx[i];
			int yy = y + dy[i];
			// cout << xx << " " << yy << endl;
			if (1 <= xx && xx <= n && 1 <= yy && yy <= m && dist[xx][yy] == -1)
			{
				dist[xx][yy] = step + 1;
				q.push(make_pair(make_pair(xx,yy),dist[xx][yy]));
			}
		}
	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	memset(dist,-1,sizeof(dist));
	cin >> n >> m;
	for (int i = 1 ; i <= n ; i++)
		for (int j = 1 ; j <= m ; j++)
		{
			cin >> tab[i][j];
			if (tab[i][j] == '#')
			{
				q.push(make_pair(make_pair(i,j),0));
				dist[i][j] = 0;
			}
		}
	bfs();
	int ans = 0;
	for (int i = 1 ; i <= n ; i++)
		for (int j = 1 ; j <= m ; j++)
			ans = max(ans,dist[i][j]);
	cout << ans << endl;
}

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

int main(void) {
	int m, f, r;
	char c;
	while (1) {
		cin >> m >> f >> r;
		if (m == -1 && f == -1 && r == -1)break;
		if (m == -1 || f == -1)c = 'F';
		else if ((m + f) >= 80)c = 'A';
		else if ((m + f) >= 65)c = 'B';
		else if ((m + f) >= 50)c = 'C';
		else if ((m + f) >= 30) {
			if (r >= 50)
				c = 'C';
			else
				c = 'D';
		} else
			c = 'F';
		cout << c << endl;
	}
	return 0;
}



Measured memory_bytes: 3112
'''ika tako
bit桁ごとに考える。「XORを取り、その後足し算」という計算過程では
他の桁が影響することはないので、桁毎に独立に考えて問題ない。
N = 5
A = {   1   2   3   4   5 }
               ↓
    { 001 010 011 100 101 }
たとえば2桁目を取り出すと
       0   1   1   0   0
各ペアでXORを取ると、(0,1)は'1'となり、(0,0)(1,1)は'0'となる。 
0はいくら足しても0なので、(0,1)の数だけわかれば良い。
それは、(0の個数)×(1の個数)で計算できる。
    0が3個、1が2個
→  XORを取ったとき、2桁目について'1'が立っているペア
　　　　　　　　　　　=合計に足される回数は 3x2=6
→  2進数の2桁目は2を表すので、合計に足される値は6x2=12
これを各桁について足し合わせる。
'''
n = int(input())
aaa = list(map(int, input().split()))
 
MOD = 10 ** 9 + 7
ans = 0
m = 1
for _ in range(60):
    bit = sum(a & m for a in aaa)
    bit //= m
    #bit >>= m これはダメだった。なぜ、だろう？
    non_bit = n - bit
    ans = (ans + bit * non_bit * m) % MOD
    m <<= 1
print(ans)

Measured memory_bytes: 43692
#include <iostream>
#include <cstdio> 
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <complex>
using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;

#ifndef typeof
#define typeof __typeof__
#endif // typeof
 
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define tr(c, i) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define rtr(c, i) for(typeof((c).rbegin()) i = (c).rbegin(); i != (c).rend(); i++)
#define repby(i, a, b, step) for(typeof(b) i = (a); i < (b); i += (step))
#define repab(i, a, b) repby(i, (a), (b), 1)
#define rep(i, n) repab(i, 0, (n))
#define pb push_back
#define sz(c) int((c).size())

int main(int argc, char **argv)
{
  vi v;
  int x;

  while (cin >> x) {
    v.pb(x);
  }

  sort(rall(v));

  cout << v[0] << endl;
  cout << v[1] << endl;
  cout << v[2] << endl;

  return 0;
}

Measured memory_bytes: 1216
import java.io.IOException;
import java.math.BigInteger;

public class Main {
    private static final StringBuilder builder = new StringBuilder();
    public static void main(String[] args) {
        System.out.print(readInt() * readInt());
    }

    private static void read() {
        builder.setLength(0);
        while (true) {
            try {
                int b = System.in.read();
                if (b == ' ' || b == '\n' || b == -1) {
                    break;
                } else {
                    builder.appendCodePoint(b);
                }
            } catch (IOException e) {
                break;
            }
        }
    }

    private static int readInt() {
        read();
        return Integer.parseInt(builder.toString());
    }

    private static int readInt(int radix) {
        read();
        return Integer.parseInt(builder.toString(), radix);
    }

    private static long readLong() {
        read();
        return Long.parseLong(builder.toString());
    }

    private static long readLong(int radix) {
        read();
        return Long.parseLong(builder.toString(), radix);
    }

    private static BigInteger readBigInteger() {
        read();
        return new BigInteger(builder.toString());
    }

    private static BigInteger readBigInteger(int radix) {
        read();
        return new BigInteger(builder.toString(), radix);
    }

    private static void skipLine() {
        while (true) {
            try {
                int b = System.in.read();
                if (b == '\n' || b == -1) {
                    break;
                }
            } catch (IOException e) {
                break;
            }
        }
    }

    private static void skip() {
        while (true) {
            try {
                int b = System.in.read();
                if (b == ' ' || b == '\n' || b == -1) break;
            } catch (IOException e) {
                break;
            }
        }
    }

}


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

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

    int counter = 0;

    for (int i=0; i<S.size(); i++) {
        int j = S.size()-(i+1);
        if (S.at(i)!=S.at(j)) counter++;
    }

    cout << counter/2 << endl;
}

Measured memory_bytes: 256
#![allow(unused_parens)]
#![allow(unused_imports)]
#![allow(non_upper_case_globals)]
#![allow(non_snake_case)]
#![allow(unused_mut)]
#![allow(unused_variables)]
#![allow(dead_code)]

use itertools::Itertools;
use proconio::input;
use proconio::marker::{Chars, Usize1};

#[allow(unused_macros)]
#[cfg(debug_assertions)]
macro_rules! mydbg {
    //($arg:expr) => (dbg!($arg))
    //($arg:expr) => (println!("{:?}",$arg));
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
      }
}
#[cfg(not(debug_assertions))]
macro_rules! mydbg {
    ($($arg:expr),*) => {};
}

macro_rules! echo {
    ($($a:expr),*) => {
          $(println!("{}",$a))*
      }
}

use std::cmp::*;
use std::collections::*;
use std::ops::{Add, Div, Mul, Sub};

#[allow(dead_code)]
static INF_I64: i64 = 92233720368547758;
#[allow(dead_code)]
static INF_I32: i32 = 21474836;
#[allow(dead_code)]
static INF_USIZE: usize = 18446744073709551;
#[allow(dead_code)]
static M_O_D: usize = 1000000007;
#[allow(dead_code)]
static PAI: f64 = 3.1415926535897932;

trait IteratorExt: Iterator {
    fn toVec(self) -> Vec<Self::Item>;
}

impl<T: Iterator> IteratorExt for T {
    fn toVec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

trait CharExt {
    fn toNum(&self) -> usize;
    fn toAlphabetIndex(&self) -> usize;
    fn toNumIndex(&self) -> usize;
}
impl CharExt for char {
    fn toNum(&self) -> usize {
        return *self as usize;
    }
    fn toAlphabetIndex(&self) -> usize {
        return self.toNum() - 'a' as usize;
    }
    fn toNumIndex(&self) -> usize {
        return self.toNum() - '0' as usize;
    }
}

trait VectorExt {
    fn joinToString(&self, s: &str) -> String;
}
impl<T: ToString> VectorExt for Vec<T> {
    fn joinToString(&self, s: &str) -> String {
        return self
            .iter()
            .map(|x| x.to_string())
            .collect::<Vec<_>>()
            .join(s);
    }
}

trait StringExt {
    fn get_reverse(&self) -> String;
}
impl StringExt for String {
    fn get_reverse(&self) -> String {
        self.chars().rev().collect::<String>()
    }
}

trait UsizeExt {
    fn pow(&self, n: usize) -> usize;
}
impl UsizeExt for usize {
    fn pow(&self, n: usize) -> usize {
        return ((*self as u64).pow(n as u32)) as usize;
    }
}

fn main() {
    input! {
       s:Chars,
    }

    let mut ans: usize = 0;
    let c = s[0];
    if c.to_string() == c.to_lowercase().to_string() {
        echo!("a");
    } else {
        echo!("A");
    }
}


Measured memory_bytes: 2208
n = int(input())
l = list(map(int, input().split()))

def gcd(a, b):
  while b != 0:
    a, b = b, a%b
  return a

def lcm(a, b):
  return (a* b) // gcd(a, b)

t = 1
for i in range(n):
  t = lcm(t, l[i])

ans = 0
for i in range(n):
  ans += t//l[i]
ans %= 10**9+7

print(ans)

Measured memory_bytes: 4084
#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 <queue>
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 vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//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(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
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;

int a,b,c,d;
int main(){
    
    cin>>a>>b>>c>>d;
    cerr<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
     a=max(a,c);
     b=min(b,d);
    cerr<<a<<" "<<b<<endl;

    int ans=max(b-a,0);
    cout<<ans<<endl;




}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int acs(const void *a, const void *b) { 
  return *(int*)a - *(int*)b;
} /* 1,2,3,4.. */
int des(const void *a, const void *b) {
  return *(int*)b - *(int*)a;
} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { 
  return *(char*)a - *(char*)b;
} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) {
  return strcmp(*(const char **)a, *(const char **)b);
} /* aaa,aab.. */
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007
#define INF 1000000009
typedef long long int lli;

int main(void) {
  int N, Q, A;
  int a[MAX] = {0}, B[MAX], C[MAX];
  scanf("%d", &N);
  rep(ni, 0, N) {
    scanf("%d", &A);
    a[A]++;
  }
  scanf("%d", &Q);
  rep(qi, 0, Q) scanf("%d %d", &B[qi], &C[qi]);

  long long int sum = 0;
  rep(ni, 0, MAX) sum += a[ni] * ni;

  rep(qi, 0, Q) {
    int add = C[qi] - B[qi];
    sum += add * a[B[qi]];  // 増加分 × 個数
    a[C[qi]] += a[B[qi]]; a[B[qi]] = 0;
    printf("%lld\n", sum);
  }
  return 0;
}


Measured memory_bytes: 2908
import java.io.*;
public class Main{
    public static void main(String[] args) throws IOException{
        Reader r = new Reader();
        int N = r.i();
        int[][] xyh = new int[N][3];
        for(int i = 0; i < N; i++){
            xyh[i] = r.ii();
        }
        for(int Cx = 0; Cx < 101; Cx++){
            loop: for(int Cy = 0; Cy < 101; Cy++){
                int H = 0;
                int j = 0;
                while(true){
                    int[] xyhi = xyh[j++];
                    if(xyhi[2] > 0){
                        H = Math.abs(Cx-xyhi[0])+Math.abs(Cy-xyhi[1])+xyhi[2];
                        break;
                    }
                }                
                for(int i = 0; i < N; i++){
                    int[] xyhi = xyh[i]; 
                    if(xyhi[2] != Math.max(H - Math.abs(Cx-xyh[i][0]) - Math.abs(Cy-xyh[i][1]), 0))
                        continue loop;
                }
                System.out.println(Cx + " " + Cy + " " + H);
                return;
            }
        }        
    }
    static void print(Object o){
        System.out.println(o.toString());
    }
    static class Reader extends BufferedReader{
        Reader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return s().split(" ");
        }
        int Int(String s){
            return Integer.parseInt(s);
        }
        int i() throws IOException{
            return Int(s());
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Int(ss[j]);
            return ii;
        }
    }
}

Measured memory_bytes: 22612
#include <iostream>
#include <typeinfo>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <queue>
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 10000000000
#define MOD 1000000007LL
#define LEN 100005
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

int main(void) {
    string s;
    ull k;
    cin >> s;
    cin >> k;
    k--;
    ll i;
    for(i=0; i<(ll)s.size(); i++) {
        if(s[i]!='1' && i<=k) {
            cout << s[i] << endl;
            return 0;
        }else if(s[i]=='1' && k<=i) {
            cout << 1 << endl;
            return 0;
        }
    }
    
    
    
    
}


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

int main() {
	int N, M, X, Y;
	cin >> N >> M >> X >> Y;
	vector<int> x(N), y(M);
	for (int i = 0; i < N; i++)
		cin >> x.at(i);
	for (int i = 0; i < M; i++)
		cin >> y.at(i);
	sort(x.begin(), x.end());
	sort(y.begin(), y.end());
	if (x.at(N - 1) < y.at(0) && x.at(N - 1) < Y&&y.at(0) > X)
		cout << "No War" << endl;
	else
		cout << "War" << endl;
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
N = int(input())
a = list(map(int, input().split()))

sunuke_l = []
sunuke = 0
arai_l = []
arai = 0
all_sum = sum(a)
diff_l = []
for i in range(N-1):
    sunuke = sunuke + a[i]
    arai = all_sum - sunuke
    diff_l.append(abs(sunuke - arai))

print(min(diff_l))


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

int main(){
    int t;
    cin>>t;
    int n,k;
    for(int i=0;i<t;++i){
        cin>>n>>k;
        int* A=new int[n];
        for(int j=0;j<n;++j){
            cin>>A[j];
        }
        int* D=new int[n-1];
        for(int j=0;j<n-1;++j){
            D[j]=A[j+1]-A[j];
        }
        sort(D,D+n-1);
        int S=0;
        for(int j=0;j<n-k;++j){
            S+=D[j];
        }
        cout<<S<<"\n";
        delete[] D;
        delete[] A;
    }
}

Measured memory_bytes: 3528
use proconio::{input, fastout};

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
      }
  }

#[fastout]
fn main() {
    input!{
        x: usize,
    }

    if x==7 || x==5 || x==3 {
        println!("YES");
    } else {
        println!("NO");
    }

}


Measured memory_bytes: 2124
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>

# define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<vs> vvs;


typedef vector<pair<int, int>> vpi;
typedef vector<tuple<int, int, int>> vti;


int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    string s;
    cin >> s;
    char p=s[0];
    
    string ans = "Good";
    for (int i=1;i<s.size();i++){
        if (p==s[i]){
            ans = "Bad";
            break;
        }
        p = s[i];
    }
    cout << ans << endl;
}


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

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> A(M);
    int res = N;
    for (int i=0; i<M; i++) cin >> A.at(i);
    for (int i=0; i<M; i++) {
        res -= A.at(i);
    }
    cout << max(-1, res);
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define INF 10000000

void dfs();
int dp[100000];
int t[16][17];
int N;

int main(){
  while(cin >> N , N){
    for(int i=0;i<N;i++){
      for(int j=0;j<N+1;j++){
	cin >> t[i][j];
      }
    }
    dfs();
  }
}

void dfs(){
  int to = (1<<N);
  for(int i=0;i<to;i++){
    dp[i] = INF;
  }
  dp[0] = 0;
  for(int next=0;next<to;next++){
    //if(dp[next] == INF) continue;
    for(int i=0;i<N;i++){
      int cost = t[i][0];
      if((next & (1 << i)) != 0) continue;
      for(int j=0;j<N;j++){
	if((next & (1 << j)) != 0){
	  cost = min(cost,t[i][j+1]);
	}
      }
      int bit = (next | (1 << i));
      dp[bit] = min(dp[bit],dp[next]+cost);
    }
  }
  cout << dp[to-1] << endl;
}

Measured memory_bytes: 1416
/*
 * atcoder/abc130/a.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>

using namespace std;

#define ll long long

#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

string S;
int N;
int len=3;
int y = 753;

void input() {
  cin >> S;
  N = S.size();
  int min_ = 100000000;
  for (int l=0; l+len<=N; l++) {
    int x = stoi(S.substr(l, len));
    chmin(min_, abs(y-x));
  }
  cout << min_ << endl;
}

int main() {
  // cout.precision(15);
  input();
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl "\n"
#ifdef ONLINE_JUDGE
#define DEBUG(x)
#else
#define DEBUG(x) cout<<#x<<" : {"<<x<<"}"<<endl;
#endif
using namespace std;
typedef long long int lli;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	int q;
	int x;
	vector<lli> v;
	lli s = 0;
	map<lli, int> freq;
	for(int i=0; i<n; ++i){
		cin>>x;
		v.push_back(x);
		freq[x]++;
		s += x;
	}
	cin>>q;
	lli a, b;
	for(int i=0; i<q; ++i){
		cin>>a>>b;
		s -= a * freq[a];
		s += b * freq[a];
		freq[b] += freq[a];
		freq[a] = 0;
		cout<<s<<endl;
	}
	
    return 0;
}


Measured memory_bytes: 9968
#include<stdio.h>

int main(){
	int i,j;
	int n,m,q,d;
	int day[100];
	int max;

	while(scanf("%d%d",&n,&q),n+q){
		for(i = 0;i < 100;i++)day[i] = 0;
		for(i = 0;i < n;i++){
			scanf("%d",&m);
			for(j = 0;j < m;j++){
				scanf("%d",&d);
				day[d]++;
			}
		}
		
		max = 0;
		for(i = 0;i < 100;i++){
			if(day[max] < day[i])max = i;
		}
		if(day[max]<q)max = 0;

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

Measured memory_bytes: 600
// In the name of God

#include <bits/stdc++.h>

#define double long double

#define PI acos(-1)

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int a, b;
	cin >> a >> b;
	int A;
	cin >> A;
	double original_area = A;
	double x = 2*(original_area/(double)(a*a))-b;
	double kk = (2*original_area)/(a*b);
	cout << setprecision(10) << fixed;
	if(x<0.0)cout << 90.0-atan(kk/b)*(180.0/PI);
	else cout << 90.0-atan(a/(b-x))*(180.0/PI);
	return 0;
}


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

using namespace std;
using ll = long long;
constexpr int mo = 1e9+7;
constexpr int  mod = mo;
constexpr int inf = 1<<30;
constexpr int mo2 = 998244353;
constexpr ll infl = 1ll<<60;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    
    int n,t;
    cin>>n>>t;
    vector<pair<int,int>> ab(n);
    for(auto &a : ab)cin>>a.first>>a.second;
    vector<vector<int>> l(n+1,vector<int>(t+1));
    auto r = l;
    for(int i=0;i<n;++i){
        for(int j=0;j<=t;++j){
            l[i+1][j] = max(l[i+1][j],l[i][j]);
            if(j + ab[i].first <= t) l[i+1][j+ab[i].first] = max(l[i+1][j+ab[i].first],l[i][j] + ab[i].second);
        }
    }
    for(int i=n-1;i>=0;i--){
        for(int j=0;j<=t;++j){
            r[i][j] = max(r[i][j],r[i+1][j]);
            if(j + ab[i].first <= t) r[i][j+ab[i].first] = max(r[i][j+ab[i].first],r[i+1][j] + ab[i].second);
        }
    }
    
    for(int i=0;i<=n;++i){
        for(int j=0;j<t;++j){
            l[i][j+1] = max(l[i][j],l[i][j+1]);
            r[i][j+1] = max(r[i][j],r[i][j+1]);
        }
    }
    
    int ma = 0;
    for(int i=0;i<n;++i){
        for(int j=0;j<t;++j){
            ma = max(ma,ab[i].second+l[i][j] + r[i+1][t-j-1]);
        }
    }
    cout << ma << endl;
    return 0;
}



Measured memory_bytes: 70912
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int k = Integer.parseInt(sc.next());
    int s = Integer.parseInt(sc.next());
    int count = 0;
    for(int i = 0; i <= k; i++) {
      for(int j = 0; j <= k; j++) {
        if(s - i - j >= 0 && s - i - j <= k) {
        	count++;
        }
      }
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define pb push_back
#define tam 3100
#define offset 100000
#define se second
#define fi first
#define forr(i,p,n) for(ll i=p;i<n;i++)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
ll mult(ll a,ll b, ll p=MOD){return ((a%p)*(b%p))%p;}
ll add(ll a, ll b, ll p=MOD){return (a%p + b%p)%p;}
typedef pair<ll,ll> ii;

int main()
{
    ll N;
    ll Ao,Bo ;
    Ao=Bo=0;
    ll A,B;
    cin>>N;
    forr(i,0,N)
    {
        cin>>A>>B;
        if (Ao==0)
            Ao=A,Bo=B;
        else
        {
            ll iz,der,mid;
            iz=0;
            der=1;
            while(A*der<Ao|| B*der<Bo)
                der*=2;
            while(iz+1<der)
            {
                mid=(iz+der)/2;
                if (A*mid>=Ao&& B*mid>=Bo)
                    der=mid;
                else
                    iz=mid;
            }
            Ao=A*der;
            Bo=B*der;
            //cout<<endl;
            //cout<<Ao<<" "<<Bo<<endl;

        }
    }
    cout<<Ao+Bo<<endl;
}

Measured memory_bytes: 256
while (n=gets.to_i)!=0
    p1 = 0
    p2 = 0
    for i in 0...n
        a,b = gets.split(" ").map(){|num|num.to_i}
        if a<b
            p2 += a+b
        elsif a>b
            p1 += a+b
        else
            p1 += a
            p2 += b
        end
    end
    puts(sprintf("%d %d",p1,p2))
end

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

#define INF 1e9
#define LLINF 1e18
#define pi 3.14159265358979323
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

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


int main() {
    int n, a;
    cin >> n;
    if (n >= 400 && n < 600) a = 8;
    else if (n >= 600 && n < 800) a = 7;
    else if (n >= 800 && n < 1000) a = 6;
    else if (n >= 1000 && n < 1200) a = 5;
    else if (n >= 1200 && n < 1400) a = 4;
    else if (n >= 1400 && n < 1600) a = 3;
    else if (n >= 1600 && n < 1800) a = 2;
    else a = 1;
    cout << a << endl;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

int main() 
{
    int N; ll W;
    cin >> N >> W;
    ll w0, v0;
    vector<ll> value[4];
    cin >> w0 >> v0;
    value[0].push_back(v0);
    for(int i = 1; i < N; ++i) {
        ll w, v;
        cin >> w >> v;
        value[w - w0].push_back(v);
    }
    for(int i = 0; i < 4; ++i)
        sort(value[i].begin(), value[i].end(), greater<ll>());
    
    for(int i = 0; i < 4; ++i) 
        for(int j = 1; j < value[i].size(); ++j)
            value[i][j] += value[i][j-1]; //累積和
    
    

    ll res = 0;
    ll weight =0;
    for(ll i0 = 0; (weight = i0*w0) <= W && i0 <= value[0].size(); ++i0) {
        for(ll i1 = 0; weight + i1*(w0 + 1) <= W && i1 <= value[1].size(); ++i1) {
            weight += i1*(w0 + 1);
            for(ll i2 = 0; weight + i2*(w0 + 2) <= W && i2 <= value[2].size(); ++i2) {
                weight += i2*(w0 + 2);
                for(ll i3 = 0; weight + i3*(w0 + 3) <= W && i3 <= value[3].size(); ++i3) {
                    ll tmp = 0;
                    tmp += (i0 == 0) ? 0 : value[0][i0-1];
                    tmp += (i1 == 0) ? 0 : value[1][i1-1];
                    tmp += (i2 == 0) ? 0 : value[2][i2-1];
                    tmp += (i3 == 0) ? 0 : value[3][i3-1];
                    res = max(res, tmp);
                }
                weight -= i2*(w0 + 2);
            }
            weight -= i1*(w0 + 1);
        }
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
N = gets.to_i
S = gets.chomp

c = S[1,N].count('E')
m = c

for i in 0..N-2
    if S[i] == 'W' && S[i+1] == 'W'
        c += 1
    end
    if S[i] == 'E' && S[i+1] == 'E'
        c -= 1
    end
    if m > c
        m = c
    end
end

puts m

Measured memory_bytes: 2564
/**
                 MD.Faysal Hasan
                Comilla Univesity               **/

#include<bits/stdc++.h>
#include<algorithm>
#include<cmath>
#include<string>
#include <stdlib.h>
using namespace std;

#define         rep(i,n)       for ( i=0 ; i<n ; ++i )
#define         rep1(i,n)      for ( i=1 ; i<=n ; ++i )
#define         sajo(str)      sort(str.begin(),str.end())
#define         rev(str)       reverse(str.begin(),str.end())
#define         usajo(str)     sort(str.rbegin(),str.rend())
#define         pi             2*acos(0.0)
#define         nel            printf("\n")
#define         longmx         92233720368547758
#define         gcd(a,b)       __gcd(a,b)
#define         lcm(a,b)       (a/gcd(a,b))*b
#define         yes            cout<<"Yes"<<"\n"
#define         no             cout<<"No"<<"\n"
#define         vcl            vector<ll>
#define         pb             push_back
#define         prl            pair< ll , ll >
#define         mkp(x,y)       make_pair(x,y)
#define         ff             first
#define         sc             second
#define         spc            ' '
#define         nn             '\n'
#define         Faysal         ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef         long long int  lli;
typedef         long long      ll;

int main(){Faysal

    lli ans,sum,tot,cnt,mx,mn,idx,chk,rem,ret,tmp,mid,lft,rgt,pos;

    lli tc,n,m,a,b,c,d,g,h,l,r,x,y,i,j,k;

    string s;
    cin>>s;
    n=3;
    bool f=false,ff=false;
    rep(i,n)
    {
        if(s[i]==65)
            f=true;
        else
            ff=true;
    }
    if(f && ff)
        yes;
    else
        no;
    return 0;
}


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

int main ()
{
    long long n, m, l;
    cin >> n >> m >> l;
    long long A[n][m], B[m][l], C[n][l];
    
    for (int i = 0;i < n;i++)
    {
        for (int j = 0;j < m;j++)
        {
            cin >> A[i][j];
        }
    }
    
    for (int i = 0;i < m;i++)
    {
        for (int j = 0;j < l;j++)
        {
            cin >> B[i][j];
        }
    }
    
    for (int i = 0;i < n;i++)
    {
        for (int j = 0;j < l;j++)
        {
            C[i][j] = 0;
            for (int k = 0;k < m;k++)
            {
                C[i][j] += A[i][k] * B[k][j];
            }
            cout << C[i][j];
            if (j < l-1) cout << " ";
        }
        cout << endl;
    }
    
    return 0;
}


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

int main()
{
  int n, k;
  int i, j, l, a, ans;
  cin >> n;
  cin >> k;
  vector<int> d(k), h(n);
  for(i=0; i<n; i++)
  {
    h[i] = i+1;
  }
  for(i=0; i<k; i++)
  {
    cin >> d[i];
    for(j=0; j<d[i]; j++)
    {
      cin >> a;
      for(l=0; l<n; l++)
      {
        if(h[l] == a)h[l] = 0;
      }
    }
  }
  ans = 0;
  for(i=0; i<n; i++)
  {
    if(h[i] != 0)ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
#include<iostream>
using namespace std;
int main(){
  int n,m;
  int i,j,k;
  int mat[100][100]={{}};
  int ve[100]={};
  cin >> n >> m;
  for(i=0;i<n;i++){
    for(j=0;j<m;j++){
      cin >> mat[i][j];
    }
  }
  for(j=0;j<m;j++) cin >> ve[j];
  for(i=0;i<n;i++){
    int x=0;
    for(j=0;j<m;j++) x+=mat[i][j]*ve[j];
    cout << x << endl;		       
  }
  
  return 0;
}

Measured memory_bytes: 1208