akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
constexpr auto ctz(int x) { return __builtin_ctz(x);      } constexpr auto ctz(ll x) { return __builtin_ctzll(x);      }
constexpr auto clz(int x) { return __builtin_clz(x);      } constexpr auto clz(ll x) { return __builtin_clzll(x);      }
constexpr auto pop(int x) { return __builtin_popcount(x); } constexpr auto pop(ll x) { return __builtin_popcountll(x); }
const int N = 16;
int a[N][N];
ll score[1 << N], opt[N + 1][1 << N];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            cin >> a[i][j];
        }
    }
    for(int mask = 0; mask < 1 << n; mask++) {
        for(int ii = mask, i = ctz(ii); ii > 0; ii &= ~(ii & -ii), i = ctz(ii)) {
            for(int jj = mask, j = ctz(jj); jj > 0; jj &= ~(jj & -jj), j = ctz(jj)) {
                if(i < j) {
                    score[mask] += a[i][j];
                }
            }
        }
    }
    ll ans = 0;
    for(int i = 1; i <= n; i++) {
        for(int mask = 0; mask < 1 << n; mask++) {
            if(i == 1) {
                opt[i][mask] = score[mask];
            } else {
                for(int x = mask; x > 0; x = (x - 1) & mask) {
                    opt[i][mask] = max(opt[i][mask], opt[i - 1][mask ^ x] + score[x]);
                }
            }
        }
        ans = max(ans, opt[i][(1 << n) - 1]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8960
#include<cstdio>
#include<algorithm>
#include<cmath>
struct point {
	int x, y;
}w[110];
using namespace std;
int n;
double P[210];
const double PI = acos(-1.0);
int main() {
	int i, j;
	scanf("%d", &n);
	for (i = 1; i <= n; i++) {
		scanf("%d%d", &w[i].x, &w[i].y);
	}
	for (i = 1; i <= n; i++) {
		int cnt = 0;
		for (j = 1; j <= n; j++) {
			if (i == j)continue;
			P[cnt++] = atan2(w[j].y - w[i].y, w[j].x - w[i].x);
		}
		sort(P, P + cnt);
		for (j = 0; j < cnt; j++)P[j + cnt] = P[j] + 2 * PI;
		double res = 0.0;
		for (j = 0; j < cnt; j++) {
			res = max(res, PI - P[j + cnt - 1] + P[j]);
		}
		printf("%.10f\n", res/(2*PI));
	}
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
 
int main(void)
{
    long long n, m, sum = 0, i;
    cin >> n >> m;
    vector<long long> a(m);
    for(i = 0; i < m; i++) {
        cin >> a.at(i);
        sum += a.at(i);
    }

    if(sum > n)
        cout << "-1" << endl;
    else
        cout << n - sum << endl;
}

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

int main(){
int n, m;
cin >> n >> m;
int maxl = 0;
int minr = 1e5 + 5;
for(int i = 0; i< m; i++){
  int l, r;
 cin >> l >> r;
 maxl = max(maxl, l);
 minr = min(minr, r); 
}
int ans;
if(minr >=maxl) ans = minr - maxl +1;
else ans = 0;
cout << ans <<endl;
return 0;
}

Measured memory_bytes: 3604
a, b, x = map(int, input().split())

a_ = 2 * x / a / b

import math

#print(a_, a, b, x)

if a_ < a:
    ang = math.degrees(math.atan(b / a_))
    print(ang)
else:
    b_ = 2 * ((a**2) * b - x) / (a**2)
    ang = math.degrees(math.atan(b_ / a))
    print(ang)

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main()
{
    char b;
    cin >> b;
    switch(b)
    {
        case 'A': cout << "T" << endl;
                  break;
        case 'T': cout << "A" << endl;
                  break;
        case 'C': cout << "G" << endl;
                  break;
        case 'G': cout << "C" << endl;
                  break;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int x[100];
int main()
{
    string s;
    cin>>s;
    for(int i=0;i<4;i++)
        x[s[i]]++;
    for(int i=65;i<=90;i++)
    {
        if(x[i]==1 || x[i]==3 || x[i]==4)
        {
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;


    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
  int a,b,d,i=0,j=0;
  while((scanf("%d,%d,%d",&a,&b,&d)) != EOF){
    if(a*a+b*b==d*d) i++;
    if(a==b) j++;
  }
  printf("%d\n%d\n",i,j);
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()

vector <pair <long long, long long> > prime_factorize(long long N){
    vector <pair <long long, long long> > res;
    for(long long a=2; a*a <= N; a++){//a<=N^0.5まで試す
        if(N % a != 0) continue;//素因数でないなら次のforループ
        long long ex = 0;//指数
        while(N % a == 0){
            ex ++;
            N /= a;
        }
        res.push_back({a,ex});//結果を格納{素因数,指数}
    }
    if(N != 1) res.push_back({N,1});//最後が1でなければ素因数
    return res;
}

int main(){
    long long n;
    cin >> n;
    auto table = prime_factorize(n);
    int ans = 0;
    for(int i=0; i<table.size(); i++){
        int tmp=table[i].second;
        for(int j=0; j<500; j++){
            if((j*(j+1)<=2*tmp) && (2*tmp < (j+1)*(j+2))){
                ans += j;
                break;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3640
import sys
import math
input = sys.stdin.readline


def main():
    sc = Scan()
    A, B, C, D = sc.intarr()
    div_b = B//C + B//D - B//(lcm(C, D))
    div_a = (A-1)//C + (A-1)//D - (A-1)//(lcm(C, D))

    ans = B - (A-1) - div_b + div_a

    print(ans)


def format_str(num):
    if num < 10:
        return "00" + str(num)
    elif num < 100:
        return "0" + str(num)
    else:
        return str(num)


class Scan():

    def intarr(self):
        line = input()
        array = line.split(' ')
        num_array = [int(n) for n in array]
        return num_array

    def intarr_ver(self, n):
        return [int(input()) for _ in range(n)]

    def strarr(self):
        line = input()
        array = line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


def display(array):
    for a in range(len(array)):
        if len(array) - a != 1:
            print(array[a], end=' ')
        else:
            print(array[a])


def gcd(a, b):  # 最大公約数
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):  # 最小公倍数
    return a * b // gcd(a, b)


main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
using tpl = tuple<char, int>;
typedef pair<int,int> pii;
typedef long long ll;

void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}

ll N, M;

int main(){

    cin >> N >> M;
    if(N >= 2 && M >= 2){
        cout << N*M - ((N + M) * 2 - 4) << endl;
    }
    else if(N == 1 && M == 1){
        cout << 1 << endl;
    }
    else{
        cout << max(N, M) - 2 << endl;
    }


    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
map<int,int> m;
vector<int> v;

int main(){
    int n,ans;
    cin>>n;
    for(register int i=1;i<=n;++i){
        int x;
        cin>>x;
        if(m[x]==0) v.push_back(x);
        ++m[x];
    }
    for(register int i=0;i<v.size();++i) if(m[v[i]]>=v[i]) ans+=m[v[i]]-v[i]; else ans+=m[v[i]];
    cout<<ans;
    return 0;
}

Measured memory_bytes: 5112
/**-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
*-*                                                               *-*
*-*                  Bismillahir Rahmanir Rahim                   *-*
*-*                                                               *-*
*-*                  Author: Ahsan Habib (comrade)                *-*
*-*                    Metropolitan University                    *-*
*-*                         Language: C++                         *-*
*-*                                                               *-*
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**/
#include<bits/stdc++.h>
#include<istream>
#include<cstdio>
#define pii          pair<ll,ll >
#include<string>
#define In freopen("ahsan.txt","r",stdin);
#define ll long long
#define ff first
#define ss second
#define NO cout<<"NO"<<endl
#define m1 cout<<"-1"<<endl
#define No cout<<"No"<<endl
#define cinarr0(n) for(int i = 0;i<n;i++)cin>>a[i];
#define cinarr1(n) for(int i = 1;i<=n;i++)cin>>a[i];
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define pb push_back
#define sorta(a) sort(a,a+n)
#define sortv(v)  sort(v.begin,v.end())
#define bug(a) cerr << #a << " : " << a << endl
#define all(v) (v.begin(), v.end())
#define   sz(x)       x.size()
#define fill(x, y) memset(x, y, sizeof(x))
const int mx = 1e6+5;
using namespace std;
ll a[200010],m,ans,i,t,k,ev=0,od=0,tt=0,n,cas = 1;
vector<int>vec[mx];
vector<pii>v;
bool ok = true;
int dp[6000];
int main()
{
    //In;
    ios::sync_with_stdio(false);
    cin.tie(0);



    ll n,x1,x;
    cin>>n>>x1;
    ll sum = 0;
    for(int i =1; i<n; i++)
    {
        cin>>x;
        if(x1>x)
            sum+= x1-x,x = x + x1-x;
        x1 = x;
    }
    cout<<sum<<endl;




}


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

int main(){
	int dt[11];
	int m1,m2,y1,y2;
	while(cin>>m1){
		cin>>m2>>y1;
		for(int i=0;i<11;i++){
			dt[i]=0;
		}
		dt[m1]=1;
		dt[m2]=1;
		dt[y1]=1;
		int num=0;
		for(int i=1;i<11;i++){
			if(dt[i]==0 && (m1+m2+i)<=20)num++;
		}
		if(((double)num/7)>=0.5)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
  
void chmin(int& x, int y)
{
  x = min(x, y);
}
void chmax(int& x, int y)
{
  x = max(x, y);
}
  
int main()
{
  int Q, H, W;
  string S[50];
  int proc = 1;
  int used[50][50] = {{}};
  
  cin >> Q;
  while(Q--) {
    cin >> H >> W;
  
    string chars = "";
    for(int i = 0; i < H; i++) {
      cin >> S[i];
      chars += S[i];
    }
    sort(chars.begin(), chars.end());
    chars += ".";
    chars.erase(unique(chars.begin(), chars.end()), chars.end());
    vector< int > x1(chars.size(), W), x2(chars.size(), 0);
    vector< int > y1(chars.size(), H), y2(chars.size(), 0);
    for(int i = 0; i < H; i++) {
      for(int j = 0; j < W; j++) {
        int pos = chars.find(S[i][j]);
        chmin(x1[pos], j);
        chmax(x2[pos], j);
        chmin(y1[pos], i);
        chmax(y2[pos], i);
      }
    }
    int xx1[128], xx2[128], yy1[128], yy2[128];
    for(int i = 0; i < chars.size(); i++) {
      xx1[chars[i]] = x1[i];
      xx2[chars[i]] = x2[i];
      yy1[chars[i]] = y1[i];
      yy2[chars[i]] = y2[i];
    }
    
    bool Judge = chars.size() == 1;
    do {
      if(chars[chars.size() - 1] != '.') continue;
      Judge = true;
      for(int i = 0; i < chars.size(); i++) {
        for(int j = xx1[chars[i]]; j <= xx2[chars[i]]; j++) {
          for(int k = yy1[chars[i]]; k <= yy2[chars[i]]; k++) {
            if(used[j][k] == proc) continue;
            used[j][k] = proc;
            if(S[k][j] != chars[i]) {
              Judge = false;
              goto myon;
            }
          }
        }
      }
    myon: ;
      ++proc;
    } while(!Judge && next_permutation(chars.begin(), chars.end()));
    if(Judge) cout << "SAFE" << endl;
    else cout << "SUSPICIOUS" << endl;
  }
}

Measured memory_bytes: 1260
# solution

def f(data):
    if data<=0: return 0
    if data%2==1:
        ara = (data+1)//2
        if ara%2==0: return 0
        else: return 1
    else:
        ara = data//2
        if ara%2==0: return data
        else: return data+1
nim,mike = map(int,input().split())
print(f(nim-1)^f(mike))

Measured memory_bytes: 3060
import math
n,p=map(int,input().split())
a=list(map(int,input().split()))
odd=0
even=0
for i in range(n):
  if a[i]%2==0:
    even+=1
  else:
    odd+=1
ans=0
t=1
while t<=odd:
  res=math.factorial(odd)//(math.factorial(t)*math.factorial(odd-t))
  t+=2
  if even!=0:
    w=0
    while w<=even:
      res1=math.factorial(even)//(math.factorial(w)*math.factorial(even-w))
      w+=1
      ans+=res*res1
  else:
    ans+=res
if p==1:
  print(ans)
else:
  print(2**n-ans) 

Measured memory_bytes: 9064
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VVI;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back

struct UnionFind{
  VI par;
  VI siz;
  UnionFind(int N):par(N),siz(N){
    rep(i,N){
      par[i]=i;
      siz[i]=1;
    }
  }
  int root(int x){
    if(par[x]==x) return x;
    return par[x]=root(par[x]);
  }
  void unite(int x, int y){
    int rx=root(x);
    int ry=root(y);
    if(rx==ry) return;
    par[rx]=ry;
    siz[ry]=siz[rx]+siz[ry];
  }
  int size(int x){
    return siz[root(x)];
  }
  bool same(int x, int y){
    int rx=root(x);
    int ry=root(y);
    return rx==ry;
  }
};

int main(){
  ll N,M;
  cin>>N>>M;
  VI A(M),B(M);
  rep(i,M) cin>>A[i]>>B[i];
  UnionFind uf(N);
  vector<ll> ans(M);
  ll sum=N*(N-1)/2;
  rep(i,M){
    int X=M-1-i;
    ans[X]=sum;
    if(uf.same(A[X]-1,B[X]-1)==0){
      ll AA=uf.size(A[X]-1);
      ll BB=uf.size(B[X]-1);
      sum=max(0ll,sum-AA*BB);
      uf.unite(A[X]-1,B[X]-1);
    }
  }
  rep(i,M) cout<<ans[i]<<endl;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
int main() {
  int N;
  cin >> N;
  vector<vector<int> > cnt(10, vector<int>(10));
  REP(i, 1, N+1) {
    int last = i % 10;
    int first = i / (int)pow(10, floor(log10(i)));
    cnt[first][last]++;
  }
  ll ans = 0;
  rep(i, 10) rep(j, 10) ans += cnt[i][j] * cnt[j][i];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//Abdulhamid Han
//Bismillahirrahmanirrahim
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long lo;
typedef pair< int,int > PII;

#define fi first
#define se second
#define mp make_pair
#define int long long int
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 1000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;

int n,m,yer=-1,b[li],a[li],k,flag,t;
int cev;
string s,ss;
vector<int> v[li];

main(void){
	fio();
	cin>>s>>ss;
	for(int i=0;i<(int)s.size();i++){
		v[s[i]-'a'].pb(i);
	}
	for(int i=0;i<(int)ss.size();i++){
		int bas=0;
		int son=v[ss[i]-'a'].size()-1;
		while(bas<=son){
			if(v[ss[i]-'a'][ort]<=yer)bas=ort+1;
			else son=ort-1;
		}
		if(bas==(int)v[ss[i]-'a'].size()){
			yer=-1;
			cev++;
			int bas=0;
			int son=v[ss[i]-'a'].size()-1;
			while(bas<=son){
				if(v[ss[i]-'a'][ort]<=yer)bas=ort+1;
				else son=ort-1;
			}
			if(bas==(int)v[ss[i]-'a'].size()){cout<<"-1\n";return 0;}
			yer=v[ss[i]-'a'][bas];
		}
		else yer=v[ss[i]-'a'][bas];
	}
	//~ cout<<cev<<endl;
	cev=cev*s.size();
	cev+=yer;
	cout<<cev+1<<endl;
	return 0;
}


Measured memory_bytes: 13904
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,K;

int ret[2020][2020];

void check() {
	int cnt[2020]={};
	int i,j,y,x;
	FOR(y,N) FOR(x,K) cnt[ret[y][x]]++;
	FOR(i,N) if(cnt[i+1]!=K) _P("NG\n");
	FOR(y,N) for(x=1;x<y;x++) {
		int match=0;
		FOR(i,K) FOR(j,K) if(ret[y][i]==ret[x][j]) match++;
		if(match!=1) _P("NG2 %d %d\n",x,y);
	}
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	//cin>>K;
	K=38;
	N=K*(K-1)+1;
	
	FOR(x,K) ret[0][x]=x+1;
	for(y=1;y<N;y++) ret[y][0]=1+(y-1)/(K-1);
	int nex=K+1;
	for(y=1;y<K;y++) {
		for(x=1;x<K;x++) {
			ret[y][x]=nex;
			FOR(i,K-1) {
				int y2=K+i*(K-1)+(i*(y-1)+((K-1)*2020)+x-1)%(K-1);
				ret[y2][y]=nex;
			}
			nex++;
		}
	}
	
	check();
	_P("%d %d\n",N,K);
	FOR(y,N) {
		FOR(x,K) _P("%d%c",ret[y][x],(x==(K-1))?'\n':' ');
	}
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 11776
using System;
 
class Program
{
  static void Main(string[] args)
  {
    string[] input = Console.ReadLine().Split(' ');
    int a = int.Parse(input[0]);
    int b = int.Parse(input[1]);
    int c = int.Parse(input[2]);
    
    if(b - a == c - b) Console.WriteLine("YES");
    else Console.WriteLine("NO");
  }
}

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

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)cin >> a[i];
    int mi = 1145141919;
    int ma = 0;
    for (auto x:a) {
        mi = min(mi, x);
        ma = max(ma, x);
    }
    if (ma - mi > 1)cout << "No" << endl;
    else {
        int mincount = 0, maxcount = 0;
        for (auto x:a) {
            if (x == ma)maxcount++;
            else mincount++;
        }
        if (maxcount == 1)cout << "No" << endl;
        else if (mincount == 0 && ma == n - 1)cout << "Yes" << endl;
        else {
            int mincolor = mincount + 1;
            int maxcolor = mincount + maxcount / 2;
            cout << (maxcolor >= ma && ma >= mincolor ? "Yes" : "No") << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int n;
    cin >> n;
    vi r(n), l(n);
    int ret = 0;
    for (int i = 0; i < n; ++i) {
        cin >> r[i] >> l[i];
        ret += l[i] - r[i] + 1;
    }
    cout << ret << "\n";
    return 0;
}

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

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

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;



int main(void){
  string s;
  int k;
  cin >> s >> k;
  REP(i, 0, s.length()) {
    int diff = s[i] - 'a';
    if (diff > 0) {
      diff = 26 - diff;
    }
    if (k < diff) {
      continue;
    }
    s[i] = 'a';
    k -= diff;
  }
  //shift the last letter by k
  int ch = s[s.length() - 1] - 'a';
  ch = (ch + k) % 26;
  s[s.length() - 1] = 'a' + ch;
  cout << s << endl;
}


Measured memory_bytes: 640
import sys

class segTree():
    def __init__(self, N, value):
        d, k = 1, 0
        while d < N:
            d *= 2
            k += 1
        self.tree = [value for _ in range(2 * d - 1)]
        self.size = d
    
    def update(self, i, a):
        now = self.size - 1 + i 
        self.tree[now] = a
        while now > 0:
            now = (now - 1) // 2
            self.tree[now] = max(self.tree[2 * now + 1], self.tree[2 * now + 2])
        #print(self.tree)

    def search(self, lower, higher, lbound, hbound, pos):
        if higher <= lbound or hbound <= lower: return 0
        if lower <= lbound and hbound <= higher: return self.tree[pos]
        else:
            left = self.search(lower, higher, lbound, (lbound + hbound) // 2, 2 * pos + 1)
            right = self.search(lower, higher, (lbound + hbound) // 2, hbound, 2 * pos + 2)
            return max(left, right)
        
def solve():
    input = sys.stdin.readline
    N = int(input())
    H = [int(h) for h in input().split()]
    A = [int(a) for a in input().split()]
    highest = max(H) + 1
    ans = segTree(highest, 0)
    for i, h in enumerate(H): 
        maxSum = ans.search(0, h, 0, ans.size, 0)
        ans.update(h, A[i] + maxSum)
    print(ans.search(0, highest, 0, ans.size, 0))

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 118096
program prob4
    implicit none
    integer :: i, N, ans, tmp
    integer :: a(100005)
    integer, allocatable :: r(:)
    read(*,*) N
    allocate(r(N))
    read(*,*) r
    ans = 0
    do i = 1, N
        tmp = r(i)
        if(tmp >= 100001)then
            ans = ans + 1
        else
            a(tmp) = a(tmp) + 1
        end if
    end do

    do i = 1, 100005
        if(a(i) < i) then
            ans = ans + a(i)
        else
            ans = ans + a(i) - i
        end if
    end do

    write(*,*) ans

    deallocate(r)
    stop
contains
end program prob4

Measured memory_bytes: 3596
// skip until line 65
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <istream>
#include <iterator>
#include <sstream>
#include <list>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
using namespace std;

#define BR "\n"
#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define ALL(cont) begin(cont),end(cont)
#define AS_MOD(a, b) ((((a) % (b) ) + (b)) % (b))
#define MO(a) AS_MOD(a,mod)
#define FEACH(it, cont) for(auto (it) = begin(cont); it!=end(cont);++it)
#define FEACHR(it, cont) for(auto (it) = rbegin(cont); it!=rend(cont);++it)
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define getll() ([](){ll s;scanf("%lld", &s);return s;})()
#define getld() ([](){ld s;scanf("%Lf", &s);return s;})()
#define prl(P) printf("%lld", P)
#define prd(P) printf("%.10Lf", P)
#define pr(P) printf(P)
#define MAX(V, T) V=max(V,T)
#define MIN(V, T) V=min(V,T)

#define DumpArray(cont, from, to) for(int __i=from;__i<to;++__i) {cout<<"(" <<__i<<": " << cont[__i]<<")";} cout<<endl;

/*
 * ***_bound(6)
 * 5 6 6 6 6 6 7 7 7
 *   ^lower    ^upper
 * void reverse(c.begin(), c.end())
 *
 * graph
 * seg tree
 * dp
 * brute force
 */
struct Comparator{
    int operator()(int l, int r) const {
        return r<l;
    }
};
struct Vec;
//set<int, Comparator> S;

// solution below
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
int main() {
    cout.precision(15);
    cout << fixed;
    string S;
    cin >> S;
    cout<<S[0]<<S[1]<<S[2]<<endl;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long
#define mx 200005
#define gcd __gcd
#define pb push_back
#define mk make_pair
#define bs binary_search
using namespace std;

bool isp[mx];

void sv(){

	ll i,j;
	memset(isp, true, sizeof(isp));
	
	isp[1]= false;
	for(i=2;i*i<mx;i++){
		if(isp[i]){
			for(j=i*i;j<mx;j+=i)
			isp[j]= false;
		}
	}
}

ll powr(ll a,ll b)
{
	ll res=1;
	while(b)
	{
		if(b&1)res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
	//sv();
	ll n,a[mx],i,j;
    cin>>n;
    ll tmp=0,ans=0;
    for(i=0;i<n;i++){
        cin>>a[i];
        if(a[i]>=tmp){
            ans++;
            tmp= a[i];
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<cctype>
using namespace std;
int n,m;
signed main()
{
	scanf("%d%d",&n,&m);int t,now(0),ans(1);
	for(register int i(0);i^(n-1);i++){scanf("%d",&t);if(!now){now=((m<t)?(1):((m>t)?(-1):(0)));}else if(((!(now-1))&&(m>t))||((!(now+1))&&(m<t))){now=0,ans++;}m=t;}
	printf("%d",ans);
	return putchar(10),0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		solver();
	}

	@SuppressWarnings("unchecked")
	static void solver() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int w = sc.nextInt();
		int h = sc.nextInt();
		int[] x = new int[n];
		int[] y = new int[n];
		ArrayList<Integer>[] x_ord = new ArrayList[w];
		ArrayList<Integer>[] y_ord = new ArrayList[h];
		for (int i = 0; i < w; i++)
			x_ord[i] = new ArrayList<>();
		for (int i = 0; i < h; i++)
			y_ord[i] = new ArrayList<>();
		int x0 = 0, xw = 0, y0 = 0, yh = 0;
		for (int i = 0; i < n; i++) {
			x[i] = sc.nextInt() - 1;
			y[i] = sc.nextInt() - 1;
			if (x[i] == 0 && x0 == 0)
				x0++;
			else if (x[i] == w - 1 && xw == 0)
				xw++;
			if (y[i] == 0 && y0 == 0)
				y0++;
			else if (y[i] == h - 1 && yh == 0)
				yh++;
			x_ord[x[i]].add(i);
			y_ord[y[i]].add(i);
		}
		int d = Math.max(Math.max(x0, xw), Math.max(y0, yh));

		DJSet ds = new DJSet(n);
		for (int i = 0; i < w; i++) {
			while (!x_ord[i].isEmpty()) {
				for (int j = 0; j < x_ord[i].size(); j++) {
					ds.setUnion(x_ord[i].get(0), x_ord[i].get(j));
				}
				x_ord[i].clear();
			}
		}
		for (int i = 0; i < h; i++) {
			while (!y_ord[i].isEmpty()) {
				for (int j = 0; j < y_ord[i].size(); j++) {
					ds.setUnion(y_ord[i].get(0), y_ord[i].get(j));
				}
				y_ord[i].clear();
			}
		}
		int sum = n - ds.count();
		if (ds.count() == 1) {
			System.out.println(sum);
		} else {
			sum +=2 * ds.count() - 1 - d;
			System.out.println(sum);
		}

	}

	public static class DJSet {
		int n;// the number of vertices
		int[] d;

		DJSet(int n) {
			this.n = n;
			d = new int[n];
			Arrays.fill(d, -1);
		}

		int root(int x) {
			return d[x] < 0 ? x : root(d[x]);
		}

		boolean setUnion(int x, int y) {
			x = root(x);
			y = root(y);
			if (x != y) {
				if (x < y) {
					int d = x;
					x = y;
					y = d;
				}
				// x>y
				d[y] += d[x];
				d[x] = y;
			}
			return x != y;
		}

		boolean equiv(int x, int y) {
			return root(x) == root(y);
		}

		// the number of nodes of which graph contains x
		int size(int x) {
			return d[root(x)] * (-1);
		}

		// the number of connected graphs
		int count() {
			int ct = 0;
			for (int u : d) {
				if (u < 0)
					ct++;
			}
			return ct;
		}
	}
}

Measured memory_bytes: 85868
//----------------------------おまじない
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")
//----------------------------
#define FOR(i,j,n) for (int i=(j);i<(n);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define REPN(i,n) for (int i=(n);i>=0;i--)
#define I(n) scanf("%d", &(n))
#define LL(n) scanf("%lld", &(n))
#define pb(n) push_back((n))
#define mp(i,j) make_pair((i),(j))
#define eb(i,j) emplace_back((i),(j))
#include <bits/stdc++.h>
using namespace std;

//------------------------------typedef集
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
typedef vector<vpi> vvpi;
typedef vector<vvi> vvvi;
typedef long long ll;
const int mod = 1000000009;

char board[301][301],buffer[301];
int n,ret;

int main(){
    cin >> n;
    REP(i,n) REP(j,n) cin >> board[i][j];

    REP(cycle,n){
        REP(i,n){
            FOR(j,i+1,n){
                if (board[i][j] != board[j][i]) goto HOGE;
            }
        }
        ret += n;
        HOGE:
        REP(j,n) buffer[j] = board[0][j];
        REP(i,n-1) REP(j,n) board[i][j] = board[i+1][j];
        REP(j,n) board[n-1][j] = buffer[j];
    }
    cout << ret << endl;
}


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

#define lpsbd(i, s, b, d) for(size_t i = (s); i < (b); i+=(d))
#define lpsb(i, s, b) for(size_t i = (s); i < (b); i++)
#define lpn(i, n) for(size_t i = 0; i < (n); i++)
#define fa(i, x) for(auto &i: x)
#define vcd(t, n, d) vector<t>(n, d)
#define vc(t, n) vector<t>(n)

using namespace std;
using ull = unsigned long long;

const ull MOD = 1000000007;

int main(void)
{
    int N, M, L, R;
    cin >> N >> M;
    int l = 1, r = N;
    lpn(i, M)
    {
        cin >> L >> R;
        l = max(l, L);
        r = min(r, R);
    }
    cout << (l <= r ? r - l + 1 : 0) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <vector>
#include <algorithm>
#include <numeric>
#include <climits>

using namespace std;

int main()
{
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    const int MAXC = max(X,Y)*2;
    int minvalue = INT_MAX;
    for (int c = 0; c <= MAXC; ++c)
    {
        int value = 2 * c * C;
        int x = X - c;
        int y = Y - c;
        value += A * max(x, 0) + B * max(y, 0);

        if(minvalue>value){
            minvalue = value;
        }
    }
    cout << minvalue << endl;
}

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

int main() {
    int R, G, B, N;
    cin >> R >> G >> B >> N;

    int res = 0;
    for (int i = 0; i <= N / R; i++) {
        for (int j = 0; j <= N / G; j++) {
            int t = R * i + G * j;
            if (N >= t && (N - t) % B == 0)
                res++;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int p = sc.nextInt();
      String s = sc.next();
      long res = 0;
      if(p == 2 || p == 5) {
          for(int i = s.length() - 1; i >= 0; i--) {
            if(s.charAt(i) == '0' || (s.charAt(i) - '0') % p == 0)
                res += (i + 1);
          }
          System.out.println(res);
          return;
      }
      Map<Integer, Integer> prefixCnt = new HashMap<>();
      prefixCnt.put(0, 1);
      int fac = 1; 
      int cur = 0;
      
      for(int i = s.length() - 1; i >= 0; i--) {
        cur = (cur + (s.charAt(i) - '0') * fac) % p;
        fac = (fac * 10) % p;
        if(prefixCnt.containsKey(cur)) {
          res += prefixCnt.get(cur);
          prefixCnt.put(cur, prefixCnt.get(cur) + 1);
        } else
          prefixCnt.put(cur, 1);
      }
      System.out.println(res);
  }
}

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

typedef long long ll;
using namespace std;
bool comp(string v1, string v2)
{
	return (strlen(v1.c_str()) < strlen(v2.c_str()));
}
unsigned long long power(unsigned long long a, unsigned long long b)
{
	unsigned long long pow = 1;
	while (b)
	{
		if (b & 1)
		{
			pow = pow * a;
			--b;
		}
		a = a * a;
		b = b / 2;
	}
	return pow;
}

bool is2s(ll a)
{
	return (ceil(log2(a)) == floor(log2(a)));
}


int main()
{
	
	ll a;
	ll f=0, s = 0;
	for (ll i = 0; i < 3; i++)
	{
		cin >> a;
		if (a == 7)
		{
			s++;
		}
		if (a == 5)
		{
			f++;
		}
	}
	
	if (f == 2 && s == 1)
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 256
#include <stdio.h>


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

    int ans=0;
    for(int i=1;i<n;i++)
    {
        for(int j=1;j<n;j++)
        {
            if(i*j>=n) break;
            else
            {
                ans++;
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}

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

using namespace std;
typedef long long ll;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    int m1 = 0, m2 = 0, idx1 = -1;
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
        if (m1 < A[i]) {
            m2 = m1;
            m1 = A[i];
            idx1 = i;
        }else if(m2 < A[i]){
            m2 = A[i];
        }
    }

    for (int i = 0; i < N; ++i) {
        if (i == idx1) {
            cout << m2 << endl;
        } else {
            cout << m1 << endl;
        }
    }
    return 0;
}

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

int main() {
	int a[5][4][11];
	for (int i = 1; i < 5; ++i)
	{
		for (int j = 1; j < 4; ++j)
		{
			for (int k = 1; k < 11; ++k)
			{
				a[i][j][k]=0;/* code */
			}	/* code */
		}/* code */
	}
	int n,b,f,r,v;
	cin>>n;
	for (int i = 0; i < n; ++i)
	{
		cin>>b>>f>>r>>v;
		a[b][f][r]+=v;
		/* code */
	}

	for(int i=1;i<=3;i++)
	{

	
	for(int j=1; j<=3;j++)
	{
		for(int k=1; k<=10; ++k)
		{
			cout<<" "<<a[i][j][k];
		}
		cout<<endl;
	}
	cout<<"####################"<<endl;
	}

	for(int j=1; j<=3;j++)
	{
		for(int k=1; k<=10; ++k)
		{
			cout<<" "<<a[4][j][k];
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#[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, usize1) => {
        read_value!($next, usize) - 1
    };

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }

    input!{
      n: usize,
      m: usize,
      aa: [chars; n],
      bb: [chars; m],
    }

    for i in 0..n {
        if i+m > n {
            continue;
        }

        for j in 0..n {
            if j+m > n {
                continue;
            }

            let mut ok = true;
            for x in 0..m {
                for y in 0..m {
                    let a = i+x;
                    let b = j+y;
                    if aa[a][b] != bb[x][y] {
                        ok = false;
                    }
                }
            }
            if ok {
                return puts!("{}\n", "Yes");
            }
        }
    }
    puts!("{}\n", "No");
}


Measured memory_bytes: 4352
import math
t1,t2=map(int,input().split())
a1,a2=map(int,input().split())
b1,b2=map(int,input().split())
#相対速度
c1,c2=a1-b1,a2-b2
#離れる距離
d1,d2=abs(c1*t1),-abs(c2*t2)

if (c1>0 and c2>0) or (c1<0 and c2<0) or d1+d2>0:
    print(0)
elif d1+d2==0:
    print("infinity")
else:
    x=d1//(-(d1+d2))
    y=d1%(-(d1+d2))
    if y==0:
        print(2*x)
    else:
        print(2*x+1)


Measured memory_bytes: 3064
#include <iostream>


#define MAX_H 100
#define MAX_W 100

using namespace std;

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

char field[MAX_H][MAX_W];
int h, w;

/* check position (y, x) with fruit 'c' */
void dfs(int y, int x, char c) {
    int next_y, next_x;
    for (int i = 0; i < 4; ++i) {
        next_y = y + dy[i];
        next_x = x + dx[i];
        if (0 <= next_y && next_y < h && 0 <= next_x && next_x < w
            && field[next_y][next_x] == c) {
            field[next_y][next_x] = '/';  // update used flag
            dfs(next_y, next_x, c);
        }
    }
}

int main() {
    //freopen("0118.in", "r", stdin);

    while (cin >> h >> w, h|w) {
        for (int i = 0; i < h; ++i) {
            for (int j = 0; j < w; ++j) {
                cin >> field[i][j];
            }
        }

        /* init */
        int count = 0;
        /* check field
         * '@' apple
         * '#' kaki
         * '#' orange
         * '/' already checked (used true flag)
         */
        for (int i = 0; i < h; ++i) {
            for (int j = 0; j < w; ++j) {
                if (field[i][j] != '/') {
                    dfs(i, j, field[i][j]);
                    count++;
                }
            }
        }
        cout << count << endl;
    }
    return 0;
}

Measured memory_bytes: 1632
class Line
	require 'matrix'
	#ax+by = c   (a > 0 or (a == 0 && b > 0))
	def self.through_two_points(x1, y1, x2, y2)
		a = y1 - y2
		b = x2 - x1
		c = a * x1 + b * y1
		new(a, b, c, x1, y1, x2, y2)
	end

	def cross_point(l)
		m = Matrix[
			[@a, @b],
			[l.a, l.b],
		];
		v = Vector[@c, l.c]
		return (m.inv * v).to_a
	end

	def cross?(l)
		(@a * l.x1 + @b * l.y1 - @c) * (@a * l.x2 + @b * l.y2 - @c) < 0 &&
		(l.a * @x1 + l.b * @y1 - l.c) * (l.a * @x2 + l.b * @y2 - l.c) < 0
	end

	private_class_method :new

	def initialize(*args)
		@a, @b, @c, @x1, @y1, @x2, @y2 = args	
	end

	attr_reader :a, :b, :c, :x1, :y1, :x2, :y2
end

t = gets.to_i
t.times do
	nl = Line.through_two_points(*gets.split.map(&:to_i))
	n = gets.to_i
	arr = []
	(1..n).each do
		x1, y1, x2, y2, a, b = gets.split.map(&:to_i)
		l = Line.through_two_points(x1, y1, x2, y2)
		next if !nl.cross?(l)
		arr << [*nl.cross_point(l), a ^ b]
	end
	if arr.size < 2
		p 0
	else
		p arr.sort.map(&:last).each_cons(2).map{|x, y| x ^ y}.inject(:+)
	end
end

Measured memory_bytes: 9320
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] w = new int[n];
        for (int i = 0; i < n; i++) {
            w[i] = sc.nextInt();
        }

        // Arrays.sort(w);
        int temp1 = 0;
        int ans = 100;
        for (int i = 0; i < n - 1; i++) {
            temp1 += w[i];
            int temp2 = 0;
            for (int j = i + 1; j < n; j++) {
                temp2 += w[j];
            }
            int tAns = Math.abs(temp1 - temp2);
            if (tAns < ans) {
                ans = tAns;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(a) a.begin(),a.end()
#define INF 1<<30
typedef long long ll;

struct magic{
    int A;
    int B;

};

bool cmp(const magic &a,const magic &b){
    return a.A < b.A;
}

int main()
{
    int H,N;
    cin >> H >> N;
    vector<magic> M(N);
    int maxa = 0;
    int mina = INF;
    REP(i,N){
        cin >> M[i].A >> M[i].B;
        if(M[i].A > maxa)maxa = M[i].A;
        if(M[i].A < mina)mina = M[i].A;
    }
    vector<int> dp(H+maxa,INF);
    dp[0] = 0;
    REP(i,dp.size()){
        REP(j,N){
            if(i >= M[j].A)dp[i] = min(dp[i-M[j].A]+M[j].B,dp[i]);
        }
    }
    int minb = INF;
    FOR(i,H,dp.size())if(dp[i]<minb)minb = dp[i];
    cout << minb << endl;
    return 0;
}

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

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

ull lcm( ull a, ull b ){
 return a* (b / gcd(a, b));
}

int main(){
  ull n;
  cin >> n;
  ull ans;
  rep(i,n){
    ull num;
    cin >> num;
    if( i == 0 ){
      ans =  num;
    }else{
      ans = lcm(ans,num);
    }
  }
  cout << ans << "\n";
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N,K;
    string S;
    cin>>N>>K>>S;
    vector<int> be, en;
    int l=0, r=0;
    while(l<N){
        while(r<N&&S[r]=='0') r++;
        l=r;
        if(l<N){
            be.pb(l);
            while(r<N&&S[r]=='1') r++;
            en.pb(r);
            l=r;
        }
    }
    if(sz(en)==0){
        cout <<N<<"\n";
        return 0;
    }
    int ans=0;
    rep(i,0,min(K,sz(en))){
        ans=max(ans, en[i]);
    }
    rep(i,min(K,sz(en)), sz(en)){
        ans=max(ans, en[i]-be[i-K]);
    }
    ans=max(ans,N-be[sz(en)-K]);
    cout <<ans<<"\n";
}

Measured memory_bytes: 1024
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);		
		
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();

		int num[] = {a, b, c};
		
		Arrays.sort(num);
		
		System.out.println(num[0] + " " + num[1] + " " + num[2]);

		scan.close();

	}

}

Measured memory_bytes: 17156
a,b,c,d,e,f=map(int,input().split())#ć­Łč§Ł
w=[]
for i in range(f//100+1):
    for j in range(f//100+1):
        x=100*a*i+100*b*j
        if x<=f:
            w.append(x)
s=[]
for i in range(f):
    for j in range(f):
        y=i*c+j*d
        if y<=f:
            s.append(y)
max_con=0
ans,ans_2=0,0
for i in w:
    for j in s:
        if i!=0 or j!=0:
            if j<=e*(i//100):
                if i+j<=f:
                    con=(100*j)/(i+j)
                    if max_con<=con:
                        max_con=con
                        ans,ans_2=i+j,j
print(ans,ans_2)


Measured memory_bytes: 12440
#include<iostream>
#include<sstream>
#include<vector>
#include <algorithm>
#include <complex>
using namespace std;

typedef long long int lli;
const double EPS = 1e-10;
template<class T>
bool eq(const T& a, const T& b) {return abs(a - b) < EPS;}

typedef  complex<double> point;
// sort/unique用、setではうまく動かないので使うべからず
namespace std {
	bool operator==(const point &a, const point &b){
		return eq(a, b);
	}
	bool operator<(const point& a, const point& b) {
		return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
	}
}
double cross(const point& a, const point& b) {
	return imag(conj(a)*b);
}
double dot(const point& a, const point& b) {
	return real(conj(a)*b);
}

int ccw(point a, point b, point c) {
	b -= a; c -= a;
	if (cross(b, c) > 0)   return +1;  // counter clockwise
	if (cross(b, c) < 0)   return -1;  // clockwise
	if (dot(b, c) < 0)     return +2;  // c--a--b on line
	if (norm(b) < norm(c)) return -2;  // a--b--c on line
	return 0;  // a--c--b on line or a----bc
}


typedef vector<point> polygon;

//凸包
//点集合 ps に対してその凸包を求める．
//O(n log n)
polygon convex_hull(polygon ps) {
  int n=ps.size(), k=0;
  sort(ps.begin(), ps.end());
  polygon ch(2*n);
  for (int i=0; i < n; ch[k++]=ps[i++]) // lower-hull
    while (k >= 2 && ccw(ch[k-2], ch[k-1], ps[i]) <= 0) --k;
  for (int i=n-2, t=k+1; i >= 0; ch[k++]=ps[i--]) // upper-hull
    while (k >= t && ccw(ch[k-2], ch[k-1], ps[i]) <= 0) --k;
  ch.resize(k-1);
  return ch;
}

//凸性判定
//与えられた多角形 P が凸かどうかを判定する．一周回ってみて，右向きの辺がないことを確かめればよい．
//O(n)
bool isconvex(const polygon &P) {
  for (int i = 0; i < P.size(); ++i)
    if (ccw(P[(i+P.size()-1) % P.size()], P[(i) % P.size()], P[(i+1) % P.size()]) > 0) return false;
  return true;
}


int main()
{
  double x,y;
  char aa;
  for(;cin>>x>>aa>>y;)
    {
      polygon a;
      a.push_back(point(x,y));
      //      cout<<x<<" "<<y;
      for(int i=0;i<3;i++)
	{
	  char aa;
	  cin>>aa>>x>>aa>>y;
	  a.push_back(point(x,y));
	  //	  cout<<" "<<x<<" "<<y;
	}
      //cout<<endl<<endl;
      cout<<((isconvex(a)||isconvex(polygon(a.rbegin(),a.rend())))?"YES":"NO")<<endl;
    }

}

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

using namespace std;

int main() {
    string str;
    cin >> str;
    
    int ind=-1;
    for(int si=str.size()-1; si>=1; si--) {
        if(str[si]>str[si-1]) {
            ind = si;
            break;
        }
    }
    
    if(str.size()==26) {
        if(ind==-1) {
            cout << ind << endl;
        } else {
            cout << str.substr(0, ind-1);
            char minc=str[ind];
            for(int i=ind; i<str.size(); i++) {
                if(str[i]>str[ind-1] && minc>str[i]) {
                    minc = str[i];
                }
            }
            cout << minc << endl;
        }
    } else {
        cout << str ;
        for(int i=0; i<26; i++) {
            bool flag=true;
            for(int si=0; si<str.size(); si++) {
                if(str[si]==(char)('a'+i)) {
                    flag = false;
                    break;
                }
            }
            if(flag) {
                cout << (char)('a'+i);
                break;
            }
        }
        
        cout << endl;
    }


    return 0;
    
}

Measured memory_bytes: 504
n = int(input())
s1 = input()
s2 = input()

mod = 1000000007

num = 1
i = 0
b = 0
tmp_t = -1
while(b + i < n):
    if s1[i + b] == s2[i + b]: # t 0
        if tmp_t == 0:
            num = (num * 2) % mod
        elif tmp_t == 1:
            num = (num * 1) % mod
        else:
            num = 3
        tmp_t = 0
    else: # t 1
        if tmp_t == 0:
            num = (num * 2) % mod
        elif tmp_t == 1:
            num = (num * 3) % mod
        else:
            num = 6
        tmp_t = 1
        b += 1
    i += 1

print(num)


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

int main() {
  int N, D;
  std::cin >> N >> D;
  int count = 0;
  while (N--) {
    int X, Y;
    std::cin >> X >> Y;
    double distance = sqrt(pow(X,2)+pow(Y,2));   
    if (distance <= D) {
      count++;
    }
  }
  std::cout << count << std::endl;
}

Measured memory_bytes: 3608
n = int(input()) - 1
a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(a[n])

Measured memory_bytes: 3060