akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
//#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#define pb push_back
#define IOS                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);cout<<fixed<<setprecision(16);
#define ll long long int
#define ld long double
#define el '\n'
#define El '\n'
#define PI (ld)3.141592653589793238462643383279502884197169399375105820974944
#define inf (ll)1000000000
#define mod (ll)1000000007
#define mod1 (ll)998244353
#define fo(i, n) for (long long i = 0; i < n; i++)
#define pll pair<ll, ll>
#define ml map<ll,ll>
#define vpl vector<pll>
#define vvl vector<vector<ll> >
#define vvpl vector< vector<pll> >
#define ff first
#define ss second
#define pqueue priority_queue< ll >
#define pdqueue priority_queue< ll,vl ,greater< ll > >
#define mem(a,b) memset(a,b,sizeof(a));
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define sz(a) (ll)a.size()
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fd(i,a,b) for(ll i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define vl vector<ll>
//#define x ff
//#define y ss
#define pt(a) for(auto it:a)cout<<it<<" ";cout<<endl;
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
using namespace std;

// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << t<<" "; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << v.first << " " << v.second ; }

double gcd(double a, double b) { return a < 0.01 ? b : gcd(fmod(b, a), a); }

long long bpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)

      res = res * a % m;
      a = a * a % m;
      b >>= 1;
  }
  return res;
}


ll kv;
ll t,n,x,y,h,k,z,p,q,w,m;
string s,s1,s2;
//vvl v;
//vl vis,d;
ll dp[100005][13];
ll f[100005];
int main() {
    IOS;
    cin>>s;
    f[0]=1;fo(i,100000)f[i+1]=f[i]*10%13;
    reverse(all(s));
    fo(i,sz(s)){
        if(s[i]!='?'){
            p=(s[i]-'0')*f[i]%13;
            if(i==0)dp[0][p]++;
            else fo(j,13)dp[i][(p+j)%13]=dp[i-1][j];
        }
        else{
            fo(k,10){
                p=k*f[i]%13;
                if(i==0)dp[0][p]++;
                else fo(j,13)dp[i][(p+j)%13]+=dp[i-1][j],dp[i][(p+j)%13]%=mod;
            }
        }
    }
    cout<<dp[sz(s)-1][5];
    return 0;
}


Measured memory_bytes: 11472
#include <memory.h>

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

#define mod 1000000007

int getABcnt(string s) {
	int ans = 0;
	for (int i = 0; i < s.length() - 1; i++) {
		if (s[i] == 'A' && s[i + 1] == 'B') ans++;
	}
	return ans;
}

int main() {
	int n;
	cin >> n;
	string s[10000];
	for (int i = 0; i < n; i++) {
		cin >> s[i];
	}
	int ans = 0;
	int startBEndA = 0;
	int startB = 0;
	int endA = 0;
	for (int i = 0; i < n; i++) {
		ans += getABcnt(s[i]);
		int l = s[i].length();
		if (s[i][0] == 'B' && s[i][l - 1] == 'A') startBEndA++;
		if (s[i][0] == 'B' && s[i][l - 1] != 'A') startB++;
		if (s[i][0] != 'B' && s[i][l - 1] == 'A') endA++;
	}
	if (startBEndA > 0) {
		ans += startBEndA - 1;
		if (startB > 0 || endA > 0) {
			startB++;
			endA++;
		}
	}
	ans += min(startB, endA);
	cout << ans << endl;
}

Measured memory_bytes: 768
#include<cstdio>
#include<iostream>
using namespace std;
int GetScore(int k) {
  if(k == 1) { return 300000; }
  if(k == 2) { return 200000; }
  if(k == 3) { return 100000; }
  return 0;
}

int main() {
  int x = 0, y = 0;
  cin >> x >> y;
  int answer = 0;
  answer += GetScore(x);
  answer += GetScore(y);
  if(x == 1 && y == 1) {
    answer += 400000;
  }
  cout << answer << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    string S,T;
    cin >> S >> T;

    int count = 0;
    for(int i = 0; i < 3; i++){
        if(S.at(i) == T.at(i)){
            count++;
        }
    }
    cout << count << endl;
    return 0;
} 

Measured memory_bytes: 256
input()

living_monsters = list(map(int, input().split()))

while len(living_monsters) > 1:
    living_monsters.sort()
    weakest_monster = living_monsters.pop(0)
    attacked_monsters = []
    for monster in living_monsters:
        attacked_monster = monster % weakest_monster
        if attacked_monster != 0:
            attacked_monsters.append(attacked_monster)
    living_monsters = [weakest_monster] + attacked_monsters

print(living_monsters[0])

Measured memory_bytes: 14252
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vec=vector<ll>;
using mat=vector<vec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define mod 1000000007
using datas=pair<ll,ll>;

long mmid(long a,long b,long c){return a<b?(b<c?b:max(a,c)):(b>c?b:min(a,c));}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

ll modncr(ll n,ll r){
  ll i,plus=1;
  rep(i,r){
    plus=(plus*(n-i))%mod;
    plus=moddevide(plus,i+1);
  }
  return plus;
}

ll euclidean_gcd(ll a, ll b) {
  if(a<b) return euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)){a=b;b=r;}
  return b;
}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

void printmap(vector<ll>& a,ll H,ll W){
  ll i,j;
  For(i,0,H+2){
    For(j,0,W+2){cout<<a[i*(W+2)+j];}
    cout<<endl;
  }
}
void inputmap(vector<ll>& a,ll H,ll W){
  ll i,j;
  string ss;
  For(i,1,H+1){
    cin>>ss;
    For(j,1,W+1){
      if(ss[j-1]=='#'){
        a[i*(W+2)+j]=1;
      }else{
        a[i*(W+2)+j]=0;
      }
    }
  }
}

int main(){
  ll i,N,M,x,y,ans=0;
  cin>>N>>M;
  vector<ll> redball(N,0),ball(N,1),ch(N,0);
  redball[0]=1;
  ch[0]=1;
  rep(i,M){
    cin>>x>>y;
    x--;y--;
    ball[x]--;ball[y]++;
    if(redball[x]){
      redball[x]--;
      redball[y]=ball[y];
    }else if(redball[y]){
      redball[y]++;
    }
  }
  rep(i,N){
    if(redball[i])ans++;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;

int n;
void koch(int d, double p1x, double p1y, double p2x, double p2y){
    //if ( d == 0 ) return;
    
    //double p1.x = 0.00000
    //double p1.y = 0.00000
    //double p2.x = 100.00000
    //double p2.y = 0.00000
    
    double sx, sy, tx, ty, ux,uy;
    
    //double pi = 3.14159265;
    //double rad = 60*(pi / 180); //ラジアン
    double sin60 = sqrt(3.0) /2.0;
    double cos60 = 1.0 / 2.0;

    sx = (2.0*p1x + 1.0*p2x) / 3.0;
    sy = (2.0*p1y + 1.0*p2y) / 3.0;
    tx = (1.0*p1x + 2.0*p2x) / 3.0;
    ty = (1.0*p1y + 2.0*p2y) / 3.0;
    ux = (tx - sx)*cos60 - (ty - sy)*sin60 + sx;
    uy = (tx - sx)*sin60 + (ty - sy)*cos60 + sy;
    
    if(d >= n) return;
    
    koch(d+1, p1x, p1y, sx, sy);
    cout << sx << " " << sy << endl;
    koch(d+1, sx, sy, ux, uy);
    cout << ux << " " << uy << endl;
    koch(d+1, ux, uy, tx, ty);
    cout << tx << " " << ty << endl;
    koch(d+1, tx, ty, p2x, p2y);
}

int main(){
    cin >> n;
    
    double p1x = 0;
    double p1y = 0;
    double p2x = 100;
    double p2y = 0;
    
    cout << p1x << " " << p1y << endl;
    
    koch(0, 0.0, 0.0, 100.0, 0.0);
    
    cout <<p2x << " " << p2y << endl;
    
    return 0;
    
}


Measured memory_bytes: 3216
l = [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]

n = int(input())
print(l[n-1])

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

main(){
	double x1,y1,x2,y2;
	double x,y,d;
	
	scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
	x = x2 - x1;
	y = y2 - y1;
	d = sqrt(x * x + y * y);
	printf("%.5f\n",d);
	return 0;
}

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

using namespace std;

int n[1600]={};
char c[1600][150] = {};



int main(){
    int s = 0;
    while(1){
        scanf("%d",&n[s]);
        if(n[s] == 0){
            break;
        }
        for(int i=0;i<n[s];i++){
            cin >> c[s][i] ;
        }
        s++;
    }

    int times = s;
    int alpha[26]={};
    for(int i=0;i<times;i++){
        int first = 0,second = 0;
        int first_alpha = 0;
        for(int j=0;j<26;j++){
            alpha[j] = 0;
        }
        for(int j=0;j<n[i];j++){
            int al = c[i][j] - 'A';
            alpha[al]++;
            if(alpha[al] > first) {
                first = alpha[al];
                first_alpha = 'A' + al;
            }
            else{
                if(alpha[al] > second){
                    second = alpha[al];
                }
            }
            
           if(first - second > n[i] - (j+1) ){
                printf("%c %d\n",first_alpha,j+1);
                break;
            }else if(first == second && j == n[i]-1){
                cout << "TIE" << endl;
                break;
            }

        }
    }


    return 0;
}


Measured memory_bytes: 3424
def solve():
    H,W,K = map(int, input().split())
    fi = [list(input()) for i in range(H)]

    res = 1 << 29
    for bit in range(1 << (H-1)):
        gok = True
        N = 0
        ord_lst = [0] * H
        for i in range(H-1):
            if not(bit & 1<<i):
                ord_lst[i+1] = ord_lst[i]
            else:
                ord_lst[i+1] = ord_lst[i] + 1
                N += 1
        
        add = 0
        nums = [0] * (N+1)
        for w in range(W):
            one = [0] * (N+1)
            ok = True
            for h in range(H):
                one[ord_lst[h]] += int(fi[h][w])
                nums[ord_lst[h]] += int(fi[h][w])
                if one[ord_lst[h]] > K:
                    gok = False
                if nums[ord_lst[h]] > K:
                    ok = False
            
            if not ok:
                add += 1
                nums = one[:]
        if gok:
            res = min(res, N + add)
    print(res)

if __name__ == '__main__':
    solve()

Measured memory_bytes: 43612
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main() {
    string s;
    std::cin >> s;
    ll count_a = 0;
    ll len = s.length();
    ll result = 0;
    for (int i = 0; i < len; i++) {
        if(s[i]== 'A'){
            count_a++;
            continue;
        }
        if(s[i]== 'C'){
            count_a = 0;
            continue;
        }
        
        if(s[i]== 'B'){
            if(i==len-1){
                continue;
            }
            if(s[i+1] == 'C'){
                result+=count_a;
                i++;
                continue;
            }
            if(s[i+1] == 'A'){
                count_a = 1;
                i++;
                continue;
            }
            if(s[i+1] == 'B'){
                count_a = 0;
                i++;
                continue;
            }
        }
        
        
    }
    std::cout << result << std::endl;
}


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

int main(){
  int n,ip,nb;
  map<int,int> m;
  cin >> n;
  nb=n-1;
  for(int i=1;i<=n;i++)m[i]=0;
  while(nb--){
    cin >> ip;
    m[ip]++;
  }
  for(auto x:m)cout  << x.second << endl;
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define fin(x) cout << x << endl;

using namespace std;
using ll = long long;

int main(void) {
  string s;
  cin >> s;
  int a, b;
  a = (s.size() - 1) / 2;
  b = (s.size() + 3) / 2;
  bool f = true;
  for (int i = 0; i < a; i++) {
    if (s[i] != s[a - i - 1]) {
      f = false;
    }
  }
  for (int i = b - 1; i < s.size(); i++) {
    if (s[i] != s[s.size() - i - 1]) {
      f = false;
    }
  }
  if (f) {
    fin("Yes");
  } else {
    fin("No");
  }
  return 0;
}

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

using namespace std;

long long dp[105][100005];
long long MOD = 1000000007;

int main(){
    int N, K;
    cin >> N >> K;
    if(!K){
        cout << 1 << endl;
        return 0;
    }
    for(int i = 0; i<=K; i++){
        dp[0][i] = 1;
    }
    for(int i= 1; i<=N; i++){
        int n;
        cin >> n;
        dp[i][0] = 1;
        for(int j =1; j<=K; j++){
            if(n >= j){
                dp[i][j] = dp[i-1][j];
            }
            else{
                dp[i][j] = (dp[i-1][j] - dp[i-1][j-n-1] + MOD)%MOD;
            }
            dp[i][j] = (dp[i][j] + dp[i][j-1])%MOD;
        }
    }
    cout << (dp[N][K]-dp[N][K-1] + MOD)%MOD;
}


Measured memory_bytes: 80128
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#include<bits/stdc++.h>
using namespace std;

#if defined(DAIJOBU)
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}
	

int main(){
	FIO
	
	int n;
	cin >> n;
	int x[n], y[n];
	for(int i = 0; i < n; i++)cin >> x[i];
	for(int i = 0; i < n; i++)cin >> y[i];
	long double A = 0, B = 0, C = 0, D = -651346853;
	for(int i = 0; i < n; i++){
		A += abs(x[i] - y[i]);
		B += (x[i] - y[i]) * (x[i] - y[i]);
		C += abs((x[i] - y[i]) * (x[i] - y[i]) * (x[i] - y[i]));
		D = max((long double)abs(x[i] - y[i]), D);
	}
	B = sqrt(B);
	C = cbrt(C);
	cout << fixed << setprecision(12);
	cout << A << '\n' << B << '\n' << C << '\n' << D;
	return 0;
}



Measured memory_bytes: 3436
let n = Scanf.scanf " %d" (+) 0
let a_s = Array.init n @@ fun _ -> Scanf.scanf " %d" (+) 0
let x = ref 0
let _ =
  for i = 0 to n - 1 do x := !x + a_s.(i) * if i mod 2 = 0 then 1 else -1 done;
  print_int !x;
  for i = 1 to n - 1 do x := 2 * (a_s.(i - 1) - !x / 2); Printf.printf " %d" !x done;
  print_newline ()

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

int main() {
	char X, Y;
	cin >> X >> Y;
	if (X == 'A')X = 10;
	if (X == 'B')X = 11;
	if (X == 'C')X = 12;
	if (X == 'D')X = 13;
	if (X == 'E')X = 14;
	if (X == 'F')X = 15;
	if (Y == 'A')Y = 10;
	if (Y == 'B')Y = 11;
	if (Y == 'C')Y = 12;
	if (Y == 'D')Y = 13;
	if (Y == 'E')Y = 14;
	if (Y == 'F')Y = 15;

	if (X > Y) {
		cout << '>' << endl;
	}
	else if (X < Y) {
		cout << '<' << endl;
	}
	else {
		cout << '=' << endl;
	}

}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
	int A,B,C;
	cin>>A>>B>>C;
	int K;
	cin>>K;
	int Sum=A+B+C;
	int Max=max(A,max(B,C));
	Sum-=Max;
	int i=0;
	for (i=0;i<K;i++){
		Max*=2;
	}
	cout<<Sum+Max<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*

fun main(args : Array<String>) {
    val (h, w) = readLine()!!.split(" ").map { it.toInt() }
    val queue = ArrayDeque<Point>()
    val initial = Array(h){""}

    repeat(h) {
        val line = readLine()!!
        initial[it] = line
        line.forEachIndexed { idx, c ->
            if (c == '#') {
                queue.push(Point(it, idx, 0))
            }
        }
    }

    var cnt = 0
    val seen = Array(h){BooleanArray(w){false} }

    while(queue.isNotEmpty()) {
        val point = queue.pop()
        cnt = point.cnt
        seen[point.h][point.w] = true

        if (point.h > 0 && !seen[point.h-1][point.w] && initial[point.h-1][point.w] == '.') {
            seen[point.h-1][point.w] = true
            queue.add(Point(point.h-1, point.w, point.cnt+1))
        }
        if (point.h < h-1 && !seen[point.h+1][point.w] && initial[point.h+1][point.w] == '.') {
            seen[point.h+1][point.w] = true
            queue.add(Point(point.h+1, point.w, point.cnt+1))
        }
        if (point.w > 0 && !seen[point.h][point.w-1] && initial[point.h][point.w-1] == '.') {
            seen[point.h][point.w-1] = true
            queue.add(Point(point.h, point.w-1, point.cnt+1))
        }
        if (point.w < w-1 && !seen[point.h][point.w+1] && initial[point.h][point.w+1] == '.') {
            seen[point.h][point.w+1] = true
            queue.add(Point(point.h, point.w+1, point.cnt+1))
        }
    }

    println(cnt)
}

data class Point(val h: Int, val w: Int, val cnt: Int)

Measured memory_bytes: 83396
n=int(input())
h=[int(i) for i in input().split()]
li=[float('inf')]*(n)

li[0]=0
li[1]=abs(h[1]-h[0])
for i in range(n-2):
    li[i+2] = min(li[i+2],li[i+1]+abs(h[i+2]-h[i+1]),li[i]+abs(h[i+2]-h[i]))

print(li[-1])
    
    

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

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int p = sc.nextInt();

        System.out.println((a * 3 + p) / 2);

    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

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


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

int main() {
  int N; cin >> N;
  vector<int> P(N); rep(i, N) cin >> P[i];

  const int INF = 1e9 + 10;
  int mini = INF;
  int ans = 0;
  rep(i, N) {
    if (P[i] <= mini) ans++;
    mini = min(mini, P[i]);
  }

  cout << ans << endl;
}

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

// begin fast read template by CYJian (source: https://www.luogu.com.cn/paste/i11c3ppx)

namespace io {
	const int __SIZE = (1 << 21) + 1;
	char ibuf[__SIZE], *iS, *iT, obuf[__SIZE], *oS = obuf, *oT = oS + __SIZE - 1, __c, qu[55]; int __f, qr, _eof;
	#define Gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	inline void flush () { fwrite (obuf, 1, oS - obuf, stdout), oS = obuf; }
	inline void gc (char &x) { x = Gc(); }
	inline void pc (char x) { *oS ++ = x; if (oS == oT) flush (); }
	inline void pstr (const char *s) { int __len = strlen(s); for (__f = 0; __f < __len; ++__f) pc (s[__f]); }
	inline void gstr (char *s) { for(__c = Gc(); __c < 32 || __c > 126 || __c == ' ';)  __c = Gc();
		for(; __c > 31 && __c < 127 && __c != ' '; ++s, __c = Gc()) *s = __c; *s = 0; }
	template <class I> inline bool gi (I &x) { _eof = 0;
		for (__f = 1, __c = Gc(); (__c < '0' || __c > '9') && !_eof; __c = Gc()) { if (__c == '-') __f = -1; _eof |= __c == EOF; }
		for (x = 0; __c <= '9' && __c >= '0' && !_eof; __c = Gc()) x = x * 10 + (__c & 15), _eof |= __c == EOF; x *= __f; return !_eof; }
	template <class I> inline void print (I x) { if (!x) pc ('0'); if (x < 0) pc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10; while (qr) pc (qu[qr --]); }
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
} using io::pc; using io::gc; using io::pstr; using io::gstr; using io::gi; using io::print;

// end fast read template by CYJian

#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define log(a) cerr<<"\033[32m[DEBUG] "<<#a<<'='<<(a)<<" @ line "<<__LINE__<<"\033[0m"<<endl
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
using ll=long long;
using pii=pair<int, int>;
//#define int ll
const int MOD = 1000000007;

int A[15], n, m;
struct t{int a, c, d;};
vector<t> inv[15];
int cb = -1;
int cur = 0;
void dfs(int l, int at) {
	if(at == n+1) {
		cb = max(cb, cur);
		return;
	}
	for(int i=l; i<=m; i++) {
		int pc = cur;
		for(auto& k:inv[at]) {
			if(i - A[k.a] == k.c) cur += k.d;
		}
		A[at] = i;
		dfs(i, at+1);
		cur = pc;
	}
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int Q; gi(n), gi(m), gi(Q);
	while(Q--) {
		int a, b, c, d; gi(a), gi(b), gi(c), gi(d);
		inv[b].pb({a, c, d});
	}
	dfs(1, 1);
	print(cb);
}


Measured memory_bytes: 3684
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<ll,ll>
#define pd pair<double,double>
#define ld long double
#define pld pair<ld,ld>
#define lg length()
#define sz size()
#define pb push_back
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005
#define x1 xdddddddddddddddddd
#define y1 ydddddddddddddddddd

int n,m,p[100005],y[100005];

vector <pi> a[100005];

void Print(int x){
    int s[7];
    for(int i=6;i>=1;i--){
        s[i]=x%10;
        x/=10;
    }
    for(int i=1;i<=6;i++) cout << s[i];
}

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> n >> m;
    for(int i=1;i<=m;i++){
        cin >> p[i] >> y[i];
        a[p[i]].pb({y[i],i});
    }
    for(int i=1;i<=n;i++){
        sort(a[i].begin(),a[i].end());
        for(int j=0;j<a[i].sz;j++){
            y[a[i][j].y]=j+1;
        }
    }
    for(int i=1;i<=m;i++){
        Print(p[i]); Print(y[i]);
        cout << '\n';
    }
}


Measured memory_bytes: 7808
while True:
    N = int(input())
    if N == 0: break
    mem = []
    for i in range(N):
        l,p,a,b,c,d,e,f,s,m = map(lambda x:int(x) if x[0].isdigit() else x, input().split())
        time = a+b+c+(d+e)*m
        income = f*m*s - p
        mem.append((-income/time, l))
    for e,name in sorted(mem):
        print(name)
    print('#')

Measured memory_bytes: 5616
//g++ -std=c++14 test.cpp -o test.out
//問題URL
//https://atcoder.jp/contests/jsc2019-qual/tasks/jsc2019_qual_c
//左端、右端を選んで操作、という操作は
//まず左端のみに注目し、次に右端のみに注目していく
//また最左端にまとめるなんて考え方も
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const int INF_INT = 2147483647-1e6;
const LL mod = 1000000007ll;

int N;
string S;

LL ans = 1;

void solve(){
	int cur = 0;
	for(int i=0;i<2*N;i++){
		if(S[i]=='B'){
			if(cur%2==1){
				ans = ans*cur%mod;
				cur--;
			}else{
				cur++;
			}
		}
		if(S[i]=='W'){
			if(cur%2==1){
				cur++;
			}else{
				ans = ans*cur%mod;
				cur--;
			}
		}
	}
	if(cur>0) ans = 0;
	for(int i=0;i<N;i++) ans = ans*(i+1)%mod;
}
 
int main(){
	cin >> N;
	cin >> S;
 
	solve();

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
import java.util.*;
import java.util.regex.*;
import static java.lang.Math.*;
import static java.lang.System.out;

// AOJ
public class Main {
	final Scanner sc=new Scanner(System.in);
	final int[] vx={0,1,0,-1}, vy={-1,0,1,0};
	final int INF=1<<24;
	static class Point{
		int x, y;
		Point(int x, int y){	this.x=x;	this.y=y;}
		Point(){	this.x=0; this.y=0;}
		@Override public String toString(){	return "("+this.x+","+this.y+")";}
		static boolean ok(int x,int y,int X,int Y,int min){	return (min<=x&&x<X)&&(min<=y&&y<Y);}
		static boolean ok(int x,int y,int X,int Y){	return ok(x,y,X,Y,0);}
	}
	public static void main(String[] args) {
		new Main().AOJ0212();
	}
	
	int c;
	void AOJ0212(){
		while(sc.hasNext()){
			c=sc.nextInt();
			int n=sc.nextInt(),m=sc.nextInt(),s=sc.nextInt()-1,d=sc.nextInt()-1,ans=INF;
			if(c==0)	break;
			int[][] g=new int[n][n];
			for(int i=0; i<n; i++){
				for(int j=0; j<n; j++)	g[i][j]=INF;
			}
			for(int i=0; i<m; i++){
				int a=sc.nextInt()-1,b=sc.nextInt()-1,f=sc.nextInt();
				g[a][b]=f;	g[b][a]=f;
			}
			PriorityQueue<C0212> open=new PriorityQueue<C0212>();
			int[] close=new int[n];
			Arrays.fill(close, INF);
			int[] temp=new int[c];
			open.add(new C0212(s,0,temp,0));
			while(!open.isEmpty()){
				C0212 now=open.poll();
				//out.println("N"+now.now+" S"+now.sum);
				for(int i=0; i<n; i++){
					if(now.now==i)	continue;
					if(g[now.now][i]>=INF)	continue;
					C0212 tmp=new C0212(i,g[now.now][i],Arrays.copyOf(now.max, now.max.length),now.sum);
					if(close[i]<=tmp.sum)	continue;
					//out.println(now.now+" -> "+tmp.now+" S "+tmp.sum);
					if(i==d){
						//out.println("ANS2 "+tmp.sum);
						ans=min(ans,tmp.sum);
						continue;
					}
					open.add(new C0212(tmp));
					close[i]=tmp.sum;
				}
			}
			out.println(ans);
		}
	}
	class C0212 implements Comparable<C0212>{
		int now,sum;
		int[] max=new int[c];
		C0212(C0212 o){this.now=o.now; this.sum=o.sum; this.max=o.max;}
		C0212(int now,int nowc,int[] a,int sum){
			if(a[0]<nowc){
				sum+=a[0]/2;
				sum+=nowc/2;
				a[0]=nowc;
				Arrays.sort(a);
			}else	sum+=nowc;
			this.now=now;	this.max=a;	this.sum=sum;
		}
		@Override public int compareTo(C0212 o) {
			if(this.sum<o.sum)	return -1;
			if(this.sum>o.sum)	return 1;
			return 0;
		}
		@Override public String toString(){
			return "("+this.now+" , "+this.sum+")";
		}
		
	}
}

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

typedef long long LL;
const int N = 1000005, mod = 1000000007;

void reduce(int &x) { x += x >> 31 & mod; }
int pow(int x, int y, int ans = 1) {
	for (; y; y >>= 1, x = (LL) x * x % mod)
		if (y & 1) ans = (LL) ans * x % mod;
	return ans;
}
int factor[N], ifactor[N];
void init(int n) {
	factor[0] = 1;
	for (int i = 1; i <= n; ++i)
		factor[i] = (LL) factor[i - 1] * i % mod;
	ifactor[n] = pow(factor[n], mod - 2);
	for (int i = n; i; --i)
		ifactor[i - 1] = (LL) ifactor[i] * i % mod;
}
int c(int x, int y) { return y < 0 || x < y ? 0 : (LL) factor[x] * ifactor[y] % mod * ifactor[x - y] % mod; }

int n, m, k, pow3[N], g[N], ans;
int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::cin >> n >> m >> k, --n, init(n + m + k);
	if (m > k) std::swap(m, k);
	pow3[0] = g[0] = 1;
	for (int i = 1; i <= m + k; ++i) {
		pow3[i] = pow3[i - 1] * 3u % mod;
		g[i] = (g[i - 1] * 2u + mod * 2 - c(i - 1, i - k - 1) - c(i - 1, m)) % mod;
	}
	for (int t = 0; t <= m + k; ++t)
		ans = (ans + (LL) pow3[m + k - t] * c(n + t, n) % mod * g[t]) % mod;
	std::cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 15488
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;

int main()
{
    int n;
    cin >> n;
    cout << n*(n+1)/2 << endl;
}

Measured memory_bytes: 3616
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
//もう二度とつかわん//
//    ↓ ↓　↓　　 //
#define ll long long
//    ↑　↑　↑    //
//フェルマー方程式の恨み//
#define rep(i,n) for(int i=0;i<n;i++)
#define ggr getchar(); getchar();return 0;
using namespace std;
ll cnt[224514];
signed main() {
	ll n;
	string s;
	cin >> n >> s;
	ll cnta = 0, cntb = 0;
	rep(i, n) {
		if (s[i] == '.')cnta++;
		else cntb++;
	}
	for (int i = 0; i < n; i++) {
		if (s[i] == '.') {
			if (i == 0)cnt[i] = 1;
			else cnt[i] = cnt[i - 1] + 1;
		}
		else {
			if (i == 0)cnt[i] = 0;
			else cnt[i] = cnt[i - 1];
		}
	}
	ll ans = 1e9 + 7;
	rep(i, n)ans = min(ans, i + 1 - cnt[i] + cnta - cnt[i]);
	cout << min({ cnta,cntb,ans }) << endl;
	ggr
}



Measured memory_bytes: 2180
Scanf.scanf "%d %d %d" @@ fun n c k ->
  let a = Array.init n (fun _ -> Scanf.scanf " %d" (fun x -> x)) in
  Array.sort (-) a;
  Array.fold_left (fun ((j, y), s) (i, x) ->
    if i-j < c && x-y <= k then ((j, y), s)
    else ((i, x), s+1)) ((0, a.(0)), 1) (Array.mapi (fun i e -> i, e) a)
  |> snd |> Printf.printf "%d\n"

Measured memory_bytes: 7296
#include <iostream>
 
int main() {
  long long int a, b, k;
  
  std::cin >> a >> b >> k;
  
  if (k < a) {
    std::cout << a - k << " " << b;
  } else if (k < a + b) {
    std::cout << 0 << " " << b - (k - a);
  } else {
    std::cout << 0 << " " << 0;
  }
  
  return 0;
}

Measured memory_bytes: 256
H,W = map(int,input().split())
S = [input() for _ in range(H)]

A = [[0 for _ in range(W)] for _ in range(H)]
for i in range(H):
  for j in range(W):
    if S[i][j] == '#':
      A[i][j] = '#'
    else:
      c =0
      for k in [-1,0,1]:
        for l in [-1,0,1]:
          if i+k < 0 or i+k >= H or j+l < 0 or j+l >= W or (k == 0 and l == 0):
            continue
          if S[i+k][j+l] == '#':
            c += 1
      A[i][j] = c
for a in A:
  print(*a,sep='')


Measured memory_bytes: 44144
_ = input()
S = input()
a = 0
c = 0
for i in S:
    if i == 'A':
        c = 1
    elif i == 'B' and c == 1:
        c = 2
    elif i == 'C' and c == 2:
        c = 0
        a += 1
    else:
        c = 0
print(a)

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main(){
    // cout << fixed << setprecision(10) << flush;

    int n, k, l, r;
    cin >> n >> k >> l >> r;
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }

    // 2^{n/2} について詰める
    vector<vector<int>> cs(n/2+1, vector<int>());
    for(int i=0; i<(1<<(n/2)); i++){
        int s = 0;
        for(int j=0; j<n/2; j++){
            if(i & (1<<j)){
                s += a[j];
            }
        }
        cs[__builtin_popcount(i)].push_back(s);
    }
    for(int i=0; i<n/2+1; i++){
        sort(cs[i].begin(), cs[i].end());
    }

    // 2^(n-n/2) について探す
    int cnt = 0;
    for(int i=0; i<(1<<(n-n/2)); i++){
        int s = 0;
        for(int j=n/2; j<n; j++){
            if(i & (1<<(j-n/2))){
                s += a[j];
            }
        }
        int pc = k - __builtin_popcount(i);
        if(pc >= 0 && pc <= n/2){
            auto itru = upper_bound(cs[pc].begin(), cs[pc].end(), r-s);
            auto itrl = lower_bound(cs[pc].begin(), cs[pc].end(), l-s);
            cnt += itru - itrl;
        }
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 12300
import java.util.Scanner;

class Main{

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

		int x = 0;
		for(int i = 1; true ;i++){
			x = sc.nextInt();
			if(x == 0)break;
			System.out.println("Case " + i + ":" + " "+ x);
		}
	}
}


Measured memory_bytes: 42812
#include <stdio.h>
int main()
{
	int a, b, c;
	
	while(scanf("%d %d %d", &a, &b, &c) != EOF)
	{
		if(a == -1 && b == -1 && c == -1)
		{
			break;
		}
		if((a == -1 || b == -1) && c == -1)
		{
			printf("F\n");
		}
		else 
		{
			int sum = 0, k = 0;
			if(a >= 0)
			{
				sum += a;
			}
			if(b >= 0)
			{
				sum += b;
			}
			if(sum >= 80)
			{
				printf("A\n");
			}
			else if(sum >= 65 && sum < 80)
			{
				printf("B\n");
			}
			else if((sum >= 50 && sum < 65) || c >= 50)
			{
				printf("C\n");
			}
			else if(sum >= 30 && sum < 50)
			{
				printf("D\n");
			}
			else 
			{
				printf("F\n");
			}
		}
	}
	return 0;
}


Measured memory_bytes: 2684
#include <bits/stdc++.h>
using namespace std;
int main(){
  long int N; cin >> N;
  long int ans, f, b, fb;
  ans = N * (N + 1) / 2;
  f = (long int)(N / 3) * ((long int)(N / 3) + 1) * 3 / 2;
  b = (long int)(N / 5) * ((long int)(N / 5) + 1) * 5 / 2;
  fb = (long int)(N / 15) * ((long int)(N / 15) + 1) * 15 / 2;
  ans -= f + b - fb;
  cout << ans;
  return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int a,b,n,m,x,y,z,i=0,ans=0,c=0,r;
    string s,t,u;
    cin >> s >> t >> a >> b >> u;
    if(s==u)
    {
        cout << a-1 << " " << b << endl;
        return 0;
    }
    else
    {
        cout << a << " " << b-1 << endl;
    }
    return 0;
}


Measured memory_bytes: 3580
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  int K;
  cin >> K;
  int t = 0;
  while (t < K) {
    if (B <= A) {
      B *= 2;
      ++t;
    }
    else break;
  }
  while (t < K) {
    if (C <= B) {
      C *= 2;
      ++t;
    }
    else break;
  }
  if (A < B && B < C) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

int main()
{
	#ifdef ARTHUR_LOCAL
		ifstream cin("input.txt");
	#endif

	int n;
	cin>>n;

	vector<int> A={-1};

	for(int i=0; i<n; i++)
	{
		int a;
		cin>>a;
		A.push_back(a);
	}

	vector<int> ans(n+1);
	int ones=0;

	for(int i=n; i>=1; i--)
	{
		int cur_ind=i+i;
		int cur_res=0;

		while(cur_ind <= n)
		{
			cur_res+=ans[cur_ind];
			cur_ind+=i;
		}

		if(cur_res%2 != A[i])
		{
			ans[i]=1;
			ones++;
		}
	}

	cout << ones << "\n";

	for(int i=1; i<=n; i++)
	{
		if(ans[i]==1) cout << i << " ";
	}

	if(ones>0) cout << "\n";
}

Measured memory_bytes: 2548
#pragma region Template
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define rng(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define rbf(i, v) for (auto& (i) : (v))
#define All(x) (x).begin(),(x).end()
#define COL(x) cout << x << endl
#define CO(x) cout << x
//#define int long long

using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;

const double PI = 3.141592653589793;
const int MOD = 1000000007;
const LL INF64 = INT64_MAX >> 1;
const int INF = INT_MAX >> 1;

inline int sqr(int x) { return (x * x); }
inline void printd(double x) { printf("%.10lf\n", x); }
inline void upsort(VI& x) { sort((x).begin(), (x).end()); }
inline void downsort(VI& x) { sort((x).begin(), (x).end(), greater<int>()); }
inline int absdiff(int a, int b) { return (a - b) * (static_cast<int>(a > b)*2 - 1); }
int gcd(int a, int b) { // 最大公約数
	if (a < b) return gcd(b, a);
	int r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
inline int lcm(int a, int b) { return a * b / gcd(a, b); } // 最小公倍数
#pragma endregion

signed main()
{	
	string S, T;
	cin >> S >> T;

	bool ans = true;
	rep(i, S.size()) {
		if (S[i] != T[i]) {
			ans = false;
			break;
		}
	}

	if (ans) COL("Yes");
	else COL("No");

	return 0;
}

Measured memory_bytes: 3628
ans = [1, 9, 30, 76, 141, 267, 400, 624, 885, 1249, 1590, 2208, 2689, 3411, 4248, 5248, 6081, 7485, 8530, 10248, 11889, 13687, 15228, 17988, 20053, 22569, 25242, 28588, 31053, 35463, 38284, 42540, 46581, 50893, 55362, 61824, 65857, 71247, 76884, 84388, 89349, 97881, 103342, 111528, 120141, 128047, 134580, 146316, 154177, 164817, 174438, 185836, 194157, 207927, 218812, 233268, 245277, 257857, 268182, 288216, 299257, 313635, 330204, 347836, 362973, 383709, 397042, 416448, 434025, 456967, 471948, 499740, 515581, 536073, 559758, 583960, 604833, 633651, 652216, 683712, 709065, 734233, 754734, 793188, 818917, 846603, 874512, 909496, 933081, 977145, 1006126, 1041504, 1073385, 1106467, 1138536, 
1187112, 1215145, 1255101, 1295142, 1342852, 1373253, 1422195, 1453816, 1502376, 1553361, 1595437, 1629570, 1691292, 1726717, 1782111, 1827492, 1887772, 1925853, 1986837, 2033674, 2089776, 2145333, 2197483, 2246640, 2332104, 2379085, 2434833, 2490534, 2554600, 2609625, 2693919, 2742052, 2813988, 2875245, 2952085, 3003306, 3096024, 3157249, 3224511, 3306240, 3388576, 3444609, 3533637, 3591322, 3693924, 3767085, 3842623, 3912324, 4027884, 4102093, 4181949, 4270422, 4361548, 4427853, 4548003, 4616104, 4718640, 4812789, 4918561, 5003286, 5131848, 5205481, 5299011, 5392008, 5521384, 5610705, 5739009, 5818390, 5930196, 6052893, 6156139, 6239472, 6402720, 6493681, 6623853, 6741078, 6864016, 6953457, 7094451, 7215016, 7359936, 7475145, 7593865, 7689630, 7886244, 7984165, 8130747, 8253888, 8403448, 8523897, 8684853, 8802826, 8949612, 9105537, 9267595, 9376656, 9574704, 9686065, 9827097, 9997134, 10174780, 10290813, 
10493367, 10611772, 10813692]
k = int(input())
print(ans[k-1])


Measured memory_bytes: 9372
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,m = inpl()
a = inpl()
hq = []
heapq.heapify(hq)
ans = 0
for i in range(n):
    tt = a[i]
    heapq.heappush(hq,-tt)
for i in range(m):
    tmp = heapq.heappop(hq)
    tmp /= 2
    heapq.heappush(hq,tmp)
    # print(hq)
for i in range(n):
    tttt = heapq.heappop(hq)
    ans -= math.ceil(tttt)
print(ans)

Measured memory_bytes: 96148
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <math.h>
#include <unordered_map>
#include <unordered_set>
//#define local
#ifdef local
#include "dbg-macro/dbg.h"
#endif
//#define hacks
#ifdef hacks
#include <boost/multiprecision/cpp_int.hpp>
#endif

#define p std::pair
#define ll long long
#define ull unsigned long long
#define pi (acos(-1))
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (unsigned long long i = 0; i < (unsigned long long)(n); ++i)
#define vec std::vector
#define oreq |=
using namespace std;
std::vector<unsigned ll> genprimevec(const unsigned ll N);
void stat();
constexpr ll mod = 1000000000 + 7;

int main()
{
string s;cin>>s;
cout<<s.substr(0,4)<<' ' <<s.substr(4,s.size()-4)<<endl;


    return 0;
}
ll extgcd(ll a, ll b, ll &x, ll &y)
{
    if (b == 0)
    {
        x = 1, y = 0;
        return a;
    }
    ll d = extgcd(b, a % b, y, x);
    y -= a / b * x;
    return d;
}


std::vector<unsigned ll> genprimevec(const unsigned ll N)
{
    std::vector<bool> is_prime(N + 1);
    for (unsigned ll i = 0; i <= N; i++) { is_prime[i] = true; }
    std::vector<unsigned ll> P;
    for (unsigned ll i = 2; i <= N; i++)
    {
        if (is_prime[i])
        {
            for (unsigned ll j = 2 * i; j <= N; j += i) { is_prime[j] = false; }
            P.emplace_back(i);
        }
    }
    return P;
}

void stat()
{
#ifdef local
    rep(i, 2) { std::cout << "local enable" << std::endl; }
#endif
#ifdef hacks
    rep(i, 2) { std::cout << "boost enable" << std::endl; }
#endif
}


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

// マクロ
// forループ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(ll)(b);i--)
// xにはvectorなどのコンテナ
#define ALL(x) (x)begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
// 出力
#define PRINT(x) cout<<(x)<<endl
#define PRINTA(x,n) REP(i,n)PRINT(x[i])
// 定数
#define INF 1000000000000 // 10^12
#define MOD 1000000007 // 10^9+7
// 略記
#define PB push_back
#define MP make_pair



int main() {
    int A, B, C, K;
    cin >> A >> B >> C >> K;
    int ans = 0;
    if (K <= A) {
        ans = K;
    } else if (K <= A + B) {
        ans = A;
    } else {
        ans = A - (K - A - B);
    }
    PRINT(ans);
    return 0;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main () {
	int n, m;
	cin >> n >> m;
	vector<int> x(m), d(m-1);
	rep(i, m) cin >> x[i];
	sort(all(x));
	REP(i, 1, m) d[i-1] = x[i] - x[i-1];
	sort(all(d));
	ll ans = 0;
	rep(i, d.size()-n+1) ans += d[i];
	cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;

int main()
{
    ll n;
    cin >> n;
    string s[200000];
    for (ll i = 0; i < n; i++)
    {
        cin >> s[i];
    }
    sort(s, s + n);
    ll ans = 1;
    for (ll i = 1; i < n; i++)
    {
        if (s[i - 1] != s[i])
            ans++;
    }
    cout << ans;
}

Measured memory_bytes: 9880
#include<iostream>
#include<cstdio>
#include<queue>
using namespace std;
#define Latte 10007

struct data{
    int x,y;
};

int main(){
    const int dy[2][6]={{-1,0,1,1,0,-1},{-1,0,1,1,0,-1}};
    const int dx[2][6]={{0,1,0,-1,-1,-1},{1,1,1,0,-1,0}};
    int H,W,stage[200][200],ny,nx,ans=0;
    bool memo[200][200]={};
    queue<data> q;
    data q_c,q_d;

    cin>>W>>H;
    for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++){
            cin>>stage[i][j];
        }
    }

    q_d.x=0;q_d.y=0;
    q.push(q_d);
    while(!q.empty()){
        q_c=q.front();
        q.pop();

        if(memo[q_c.y][q_c.x]) continue;
        memo[q_c.y][q_c.x]=true;
        //printf("%d,%d: ",q_c.x,q_c.y);

        for(int i=0;i<6;i++){
            ny=q_c.y+dy[q_c.y&1][i];
            nx=q_c.x+dx[q_c.y&1][i];
            //printf("%d,%d ",nx,ny);
            if(ny<0 || H+1<ny || nx<0 || W+1<nx) continue;
            if(stage[ny][nx]==1){
                ans++;
                continue;
            }
            q_d.y=ny;
            q_d.x=nx;
            q.push(q_d);
        }//puts("");
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 1332
fun main(args : Array<String>) {
    val (a, b, k) = readLine()!!.split(" ").map { it.toInt() }
    val min = Math.min(a, b)

    val ans = mutableListOf<Int>()

    for (i in 1..min) {
        if (a % i == 0 && b % i == 0) ans.add(i)
    }

    println(ans.sortedDescending()[k-1])
}


Measured memory_bytes: 37844
#include<iostream>
using namespace std;
int main(){

	int x,y;
	
	while(1){
	cin >> x;
	cin >> y;
	if(x == 0 && y == 0)break;

	if(x < y){
		cout << x << " "<< y << endl;
	}else{
		cout << y << " " << x << endl;
	}
	}
	return 0;
	}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define inf (1<<30)-1
#define INF (1LL<<62)-1
#define MOD 1000000007LL
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define PI acos(-1)
#define MEM(x,y) memset(x,y,sizeof (x))
#define debug cout<<"A"<<'\n'
#define REP(i,a,b) for (int i=(a); i<=(b); i++)
#define PER(i,a,b) for (int i=(a); i>=(b); i--)
#define REPL(i,a,b) for (LL i=(a); i<=(b); i++)
#define PERL(i,a,b) for (LL i=(a); i>=(b); i--)
#define print(x) cout<<x<<'\n'
#define itrALL(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define UNIQUE(X) X.erase( unique( X.begin(), X.end() ), X.end() )


typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int>PII;
typedef pair<LL,LL>PLL;
typedef vector<int> VI;
typedef vector<LL> VL;


// Order Statistic Tree

/* Special functions:

        find_by_order(k) --> returns iterator to the kth largest element counting from 0
        order_of_key(val) --> returns the number of items in a set that are strictly smaller than our item
*/

typedef tree<
PII,
null_type,
less<PII>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

template <class T> inline T bigmod(T p,T e,T M)
{
    T ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    } return (T)ret;
}

template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}
template <class T, class X> inline bool getbit(T a, X i) { T t=1; return ((a&(t<<i))>0);}
template <class T, class X> inline T setbit(T a, X i) { T t=1;return (a|(t<<i)); }
template <class T, class X> inline T resetbit(T a, X i) { T t=1;return (a&(~(t<<i)));}

/*end of header*/

LL n,p, a[52],ncr[52][52];

int main()
{
    //freopen("input_file_name.in","r",stdin);
    //freopen("output_file_name.out","w",stdout);
    cin>>n>>p;
    REP(i,1,n)cin>>a[i];
    REP(i,0,n)
    {
        ncr[i][0]=ncr[i][i]=1;
        REP(j,1,i-1)ncr[i][j]=ncr[i-1][j]+ncr[i-1][j-1];
    }
    LL cnt1=0, cnt0=0;
    REP(i,1,n)
    {
        if(a[i]%2==1)cnt1++;
        else cnt0++;
    }
    LL ans=0;
    if(p==0)
    {
        for(int i=0;i<=cnt1;i+=2)ans+=ncr[cnt1][i];
    }
    else
    {
        for(int i=1;i<=cnt1;i+=2)ans+=ncr[cnt1][i];
    }
    REP(i,1,cnt0)ans*=2LL;
    print(ans);
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
using namespace std;
const int inf=2147483647,dx[]={-1,0,1,0},dy[]={0,-1,0,1};// 上 左 下 右
const int N=100005,M=1000005,mod=1000000007;
const long long llinf=9223372036854775807ll;
int a,b,p,k,i;
vector<int> v;
int main(){
	cin>>a>>b>>k;
	while(i<min(a,b))
	{
		i++;
		if(a%i==0&&b%i==0)
			v.push_back(i);
	}
	reverse(v.begin(),v.end());
	cout<<v[k-1];
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;
const ll inf = 1001001001;
const ll mod = 1000000007;
 
int main() {
    ll a;
    string b;
    cin >> a >> b;
    int c = b[0]-'0';
    int d = b[2]-'0';
    int e = b[3]-'0';

    cout << (a*c*100 + a*d*10 + a*e)/100<< endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
const int mod=1000000007;
int add(int a, int b)
{
	int c=a+b;
	if(c>=mod)c-=mod;
	return c;
}
int dif(int a, int b)
{
	int c=a-b;
	if(c<0)c+=mod;
	return c;
}
int mlt(int a, int b)
{
	long long c=a*1LL*b;
	return c%mod;
}
int bp(int a, int b)
{
	if(b==0)return 1;
	if(b%2==0)
	{
		int val=bp(a, b/2);
		return mlt(val, val);
	}
	if(b%2==1)
	{
		int val=bp(a, b-1);
		return mlt(val, a);
	}
}
int inv(int a)
{
	return bp(a, mod-2);
}
int ibit(int mask, int i)
{
	return (mask>>i)%2;
}
void outp(vector<vector<int>>&v)
{
	for(int i=0; i<v.size(); i++)
	{
		for(int j=0; j<v[i].size(); j++)cout<<v[i][j]<<' ';
		cout<<endl;
	}
	cout<<endl;
}
int main()
{
	int n;
	vector<vector<long long>> c(60, vector<long long>(60));
	c[0][0]=1;
	for(int i=1; i<60; i++)
	{
		c[0][i]=1;
		c[i][i]=1;
		for(int j=1; j<i; j++)c[j][i]=c[j][i-1]+c[j-1][i-1];
	}
	int k, s, t;
  long long ans=0;
	cin>>n>>k>>t>>s;
	vector<long long> val(60);
	for(int i=1; i<60; i++)
	{
		long long bans=0;
		for(int j=1; j<=k; j++)
		{
			bans+=c[j][i];
		}
		val[i]=bans;
	}
	vector<int>v;
	vector<int>gb;
	for(int i=0; i<18; i++)
	{
		if(ibit(s, i)==0)
			if(ibit(t,i)==1)ans=-1;
		if(ibit(s, i)==1)
			if(ibit(t,i)==0)gb.push_back(i);
	}
	for(int i=0; i<n; i++)
	{
		int x;
		cin>>x;
		int vl=0;
		for(int j=0; j<18; j++)
		{
			if(ibit(s, j)==0)
				if(ibit(x,j)==1)vl++;
			if(ibit(t, j)==1)
				if(ibit(x,j)==0)vl++;
		}
		if(vl==0)
		{
			v.push_back(x);
	//		cout<<x<<' ';
		}
	}
	vector<int>used(1<<18);
	if(ans==-1)cout<<0<<endl;
	else{
		for(int mask=0; mask<(1<<gb.size()); mask++)
		{
			int sn=0;
			for(int i=0; i<gb.size(); i++)
				if(ibit(mask, i))
					sn++;
			sn=sn%2;
			int vl=0;
			for(int i=0; i<gb.size(); i++)
				if(ibit(mask, i))
					vl+=(1<<gb[i]);
			vector<int>cur;
			for(int i=0; i<v.size(); i++)
			{
				int cr=v[i]&vl;
				used[cr]++;
				cur.push_back(cr);
			}
			for(int i=0; i<cur.size(); i++)
			{
				int vd=cur[i];
				long long ad=val[used[vd]];
				used[vd]=0;
				if(sn==0)ans+=ad;
				else ans-=ad;
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 4320