akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
const int N=1e6+5;
typedef long long ll;
const ll mod=1e9+7;
const ll hjb=19260817;
char s[N];
ll hjball[N];
ll f[N];
ll Hash(int l,int r){
    return ((f[r]-f[l-1]*hjball[r-l+1]%mod)%mod+mod)%mod;
}
bool pre[N];
bool nxt[N];
int main()
{
    scanf("%s",s+1);
    int n=strlen(s+1);
    hjball[0]=1;
    for(int i=1;i<=n;i++)
        hjball[i]=(hjball[i-1]*hjb)%mod;
    for(int i=1;i<=n;i++)
        f[i]=(f[i-1]*hjb%mod+s[i]-'a')%mod;
    for(int d=1;d<=n;d++)
        for(int i=d*2;i<=n;i+=d)
            if(Hash(1,i-d)==Hash(d+1,i))
                pre[i]=true;
    for(int d=1;d<=n;d++)
        for(int i=n-2*d+1;i>=1;i-=d)
            if(Hash(i,n-d)==Hash(i+d,n))
                nxt[i]=true;
    if(!pre[n]){
        printf("1\n1\n");
        return 0;
    }
    int cnt=0;
    for(int i=1;i<n;i++)
        if(!pre[i]&&!nxt[i+1])
            cnt++;
    if(cnt){
        printf("2\n%d\n",cnt);
        return 0;
    }
    printf("%d\n1\n",n);
}


Measured memory_bytes: 13696
#include <iostream>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <numeric> // accumulate(begin,end,初期値)

#define all(x) (x).begin(),(x).end()
#define FOR(x) for(ll i = 0;i < x;++i)

using namespace std;
typedef long long ll;

int main(){
  
  int N;
  cin>>N;
  int ans = 180 * (N-2);
  cout<<ans;
  
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;

public class CSharp{
    public static void Main(){
        Kyopuro chokudai = new Kyopuro();
	    chokudai.AtCoder();
	}
}

public class Kyopuro{
    int h, w, k;
    int sx, sy;
    bool[][] g;
    int close;
    List<List<int>> list;
    
    public void AtCoder(){
        string[] s;
        s = Console.ReadLine().Split(' ');
        h = int.Parse(s[0]);
        w = int.Parse(s[1]);
        k = int.Parse(s[2]);
        g = new bool[h][];
        int tmpx, tmpy;
        string t;
        for(int i=0; i<h; i++){
            g[i] = new bool[w];
            t = Console.ReadLine();
            for(int j=0; j<w; j++){
                if(t[j] != '#') g[i][j] = true;
                if(t[j] == 'S'){
                    sx = i;
                    sy = j;
                    tmpx = i;
                    tmpy = j;
                    if(h - 1 - i < i) tmpx = h - 1 - i;
                    if(w - 1 - j < j) tmpy = w - 1 - j;
                    close = tmpx;
                    if(tmpy < tmpx) close = tmpy;
                }
            }
        }
        list = new List<List<int>>();
        list.Add(new List<int>());
        list[0].Add(sy + sx * w);
        Bfs(0);
        if(close % k == 0) Console.WriteLine(close / k + 1);
        else Console.WriteLine(close / k + 2);
    }
    
    void Bfs(int z){
        if(z>k) return;
        if(close < 1) return;
        list.Add(new List<int>());
        foreach(int r in list[z]){
            int x = r / w;
            int y = r % w;
            g[x][y] = false;
            if(x == 0 || x == h - 1 || y == 0 || y == w - 1){
                close = 0;
                return;
            }
            int tmpx = x;
            int tmpy = y;
            if(h - 1 - x < x) tmpx = h - 1 - x;
            if(w - 1 - y < y) tmpy = w - 1 - y;
            if(tmpx < close) close = tmpx;
            if(tmpy < close) close = tmpy;
            
            if(g[x-1][y]) list[z+1].Add(y + w * (x-1));
            if(g[x+1][y]) list[z+1].Add(y + w * (x+1));
            if(g[x][y-1]) list[z+1].Add((y-1) + w * x);
            if(g[x][y+1]) list[z+1].Add((y+1) + w * x);
            g[x-1][y] = false;
            g[x+1][y] = false;
            g[x][y-1] = false;
            g[x][y+1] = false;
        }
        if(list[z+1].Count>0) Bfs(z+1);
    }
    
    public static void DebugWL(object x){ System.Diagnostics.Debug.WriteLine(x); }
}

Measured memory_bytes: 16588
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }



const int MOD = 10007;
void add(int &a, int b) { a += b; if (a >= MOD) a -= MOD; }


map<char,int> ma;
int dp[2100][21];   // J:1, O:2, I:4

int n;
string str;

int main() {
    ma['J'] = 0, ma['O'] = 1, ma['I'] = 2;
    while (cin >> n >> str) {
        memset(dp, 0, sizeof(dp));
        dp[0][1] = 1;
        
        for (int i = 0; i <= n; ++i) {
            int pre = -1, to = -1;
            if (i == 0) pre = 0;
            else pre = ma[str[i-1]];
            to = ma[str[i]];
            
            for (int bit = 0; bit < 8; ++bit) {
                //cout << i << ", " << bitset<3>(bit) << " : " << dp[i][bit] << endl;
                for (int bit2 = 0; bit2 < 8; ++bit2) {
                    if ( !(bit2 & (1<<to)) ) continue;
                    if ( (bit & bit2) == 0 ) continue;
                    
                    add(dp[i+1][bit2], dp[i][bit]);
                }
            }
        }
         
        int res = 0;
        for (int bit = 0; bit < 8; ++bit) add(res, dp[n][bit]);
        
        cout << res << endl;
    }
    return 0;
}


Measured memory_bytes: 1388
import Control.Applicative

main = do
    ss <- (map read . words) <$> getLine
    let area = (head ss) * (ss !! 1)
    let perimeter = 2 * ((head ss) + (ss !! 1))
    putStr $ show area
    putStr " "
    putStr $ show perimeter
    putStrLn ""


Measured memory_bytes: 3592
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C
# CreatedDate:  2020-09-10 18:27:16 +0900
# LastModified: 2020-09-10 18:35:34 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd
from collections import Counter


def main():
    n = int(input())
    A = []
    for _ in range(n):
        A.append(int(input()))
    A_cnt = Counter(A)
    flag = 0
    A_max = max(A)
    A_next_max = sorted(A, reverse=True)[1]
    if A_cnt[A_max] > 1:
        flag = 1

    for a in A:
        if a == A_max and flag == 1:
            print(A_max)
        elif a == A_max and flag == 0:
            print(A_next_max)
        else:
            print(A_max)


if __name__ == "__main__":
    main()


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

using ll = long long;
using ull = unsigned long long;

#define MOD 1000000007

int main(void) {
    string S;
    bool flag = false;
    cin >> S;
    if(S[0] == 'A') {
        ll c = 0;
        flag = true;
        for(ll i = 1;i < S.size();i++) {
            if(2 <= i && i < S.size() - 1) {
                if(S[i] == 'C') {
                    c++;
                    if(c > 1) {
                        flag = false;
                        break;
                    }
                    continue;
                }
            }
            if(S[i] < 'a' || 'z' < S[i]) {
                flag = false;
                break;
            }
        }
        if(c == 0) flag = false;
    }
    cout << (flag ? "AC" : "WA") << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const int INF=1000000001;
const double PI=3.141592653589;
const ll LMAX=1000000000000001;
ll gcd(ll a,ll b){if(a<b)swap(a,b);while((a%b)!=0){a=b;b=a%b;}return b;}
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};



int main(){
  vector<string> s(3);
  rep(i,3) cin>>s[i];
  rep(i,3){
    char c=s[i][0]-'a'+'A';
    cout<<c;
  }
  cout<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<unordered_map>
#include<bitset>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<ctype.h>
#include<unordered_set>
#include<string>
#include<iomanip>
#include<queue>
#include<limits>
#include<map>
#include<stack>
#include<iterator>
#include<cstring>
 
#include<deque>
#define pi 3.141592653589793238
#include<chrono>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define MOD 1000000007
#define INF 999999999999999999 
#define pb push_back
#define ff first
#define ss second
 
#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
 
 
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    ll T = 1, i, j;
    
    //cin >> T;
    while (T--) {
        ll n;
        cin >> n;
        vector<ll> v(n + 1);
        for(i = 0; i < n + 1;  i++){
            cin >> v[i];
        }
        vector<ll> b(n);
        for(i = 0; i < n; i++){
            cin >> b[i];
        }
        ll ans = 0;
        for(i = 0; i < n; i++){
            if(v[i] >= b[i]){
                v[i] -= b[i];
                ans += b[i];
                continue;
            }

            b[i] -= v[i];
            ans += v[i];
            if(v[i + 1] <= b[i]){
                ans += v[i + 1];
                v[i + 1] = 0;
            }
            else{
                v[i + 1] -= b[i];
                ans += b[i];
            }
        }
        cout << ans;
    }
    return 0;
}

Measured memory_bytes: 4792
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<string>
#include<vector>
#include<map>  
#include<set>
#include<iterator>
#include<list>
#include<utility>
#include<cstdlib>
#include<queue>
#include<stack>
#include<bitset>
//#include<bits/stdc++.h>
#define PI  2*acos(0.0)
#define pb push_back

       
using namespace std;
using ll = long long;
using lli = long long int;
using ld = long double;



int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
/*
ll 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};

ll size=sizeof(a)/sizeof(a[0]);
*/

ll a,b,c,d;
  cin >> a >> b >> c;
  d = c-a-b;
  if(d*d > 4*a*b && d > 0) cout << "Yes" << endl;
  else cout << "No" << endl;








	
	
	return 0;
	
	
	       /***Israil Hosen
	            Computer Science & Engineering
	         University Of Rajshahi.
	         ***/
	
	
	
}


Measured memory_bytes: 3140
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <map>

using namespace std;
using PII = pair<int, int>;

int main() {
	int h, w, d, tmp;
	cin >> h >> w >> d;

	vector<vector<int>> a(h, vector<int>(w, 0));
	map<int, PII> val2point;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> tmp;
			tmp--;
			val2point[tmp] = make_pair(i, j);
			a[i][j] = tmp;
		}
	}

	vector<long long> cumul(h * w + d, -1);
	for (int st = 0; st < d; st++) {
		cumul[st] = 0;

		for (int i = st; i + d < cumul.size(); i += d) {
			auto from = val2point[i];
			auto to = val2point[i + d];

			cumul[i + d] = cumul[i] + abs(to.first - from.first) + abs(to.second - from.second);
		}
	}

	int q, l, r;
	cin >> q;
	vector<long long> ans(q);
	for (int i = 0; i < q; i++) {
		cin >> l >> r;
		l--;
		r--;
		ans[i] = cumul[r] - cumul[l];
	}

	for (auto x: ans) {
		cout << x << endl;
	}


	return 0;
}


Measured memory_bytes: 14208
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#define int long long

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template <class T>
bool chmax(T &a, const T &b) {if (a < b){ a = b; return 1;} return 0;}
template <class T>
bool chmin(T &a, const T &b) {if (a > b){ a = b; return 1;}return 0;}
template <class T>
void printv(vector<T> v) {for (T t : v) {cout << t << " ";}cout << '\n';}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

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

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

    int N;
    cin >> N;

    vi A(N);
    REP(i,N) cin >> A[i];

    vector<ll> e(N,0), o(N, 0);

    e[N-1] = A[N-1];
    o[N-1] = -A[N-1];
    for (int i = N-1; i>=1; i--) {
        if (i%2 == 0) {
            e[i-1] += e[i] - A[i-1];
            o[i-1] += o[i] + A[i-1];
        } else {
            e[i-1] += e[i] + A[i-1];
            o[i-1] += o[i] - A[i-1];
        }
    }

    // printv(A);
    // printv(e);
    // printv(o);
    int a = e[0]/2;
    REP(i,N) {
        if (i == 0) {
            cout << a * 2;
        } else {
            if (i%2 == 0) {
                cout << (e[i] - a)*2;
            } else {
                cout << (o[i] + a)*2;
            }
        }  

        if (i != N-1) cout << " ";
        else cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3328
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int monster = sc.nextInt();
		int teck = sc.nextInt();

		Integer[] HP = new Integer[monster];
		int[] anser = new int[monster];
		long count = 0;
		for(int i = 0; i <monster; i++) {
			HP[i] = sc.nextInt();
		}
		//降順に並び替え
		Arrays.sort(HP, Collections.reverseOrder());
//		一番多いHPの持つモンスターに必殺技を与える。
//		それ以外はHP-1を行う
		for(int i = 0 ; i<HP.length; i++) {
			if(teck > 0) {
				HP[i] = 0;
				teck -= 1;
			}else {
				count += HP[i];
				HP[i] = 0;
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 94172
s = gets.chomp.to_i
m1 = false
m2 = false
if s/100 <= 12 && (s/100 > 0)
  m1 = true
end
if s%100 <= 12 && (s%100 > 0)
  m2 = true
end

if m1 && m2
  puts "AMBIGUOUS"
elsif m1
  puts "MMYY"
elsif m2
  puts "YYMM"
else
  puts "NA"
end

Measured memory_bytes: 3836
a=[int(i) for i in input().split()]
if a[0]+a[1]<=a[2]:
    print(0,0)
else:
    if a[0]<=a[2]:
        print(0,a[1]-(a[2]-a[0]))
    elif a[0]>a[2]:
        print(a[0]-a[2],a[1])

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

using namespace std;

const int INF = 1000000000;

int abs(int x){return x > 0 ? x : -x; }

int main(){
	int n;
	static int DP[3][40];
	int p[40], t[40];
	while(cin >> n, n){
		for(int i=0;i<3;i++)
			for(int j=0;j<n;j++) DP[i][j] = INF;
		cin >> p[0] >> t[0];
		if(t[0] >= p[0]) DP[0][0] = p[0];
		for(int i=1;i<n;i++){
			cin >> p[i] >> t[i];
			for(int j=0;j<3;j++){
				if(DP[j][i-1] == INF) continue;
				if(t[i]-t[i-1] >= p[i]+(j+2)*p[i-1])
					DP[0][i] = min(DP[0][i], DP[j][i-1]+p[i]+p[i-1]);
				if(j!=2 && t[i]-t[i-1] >= (j+2)*abs(p[i]-p[i-1]))
					DP[j+1][i] = min(DP[j+1][i], DP[j][i-1]+abs(p[i]-p[i-1]));
			}
		}
		int res = INF;
		for(int i=0;i<3;i++)
			res = min(res, DP[i][n-1]+p[n-1]);
		if(res < INF) { cout << "OK " << res << endl; }
		else {
			res = 1;
			for(int i=0;i<n;i++)
				for(int j=0;j<3;j++)
					if(DP[j][i] < INF) res = i+2;
			cout << "NG " << res << endl;
		}
	}
}

Measured memory_bytes: 0
fn run() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let mut x: usize = s.trim().parse().unwrap();
    let mut ans = 0;
    ans += x / 500 * 1000;
    x %= 500;
    ans += x / 5 * 5;
    println!("{}", ans);
}

fn main() {
    run();
}

Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <tuple>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repd(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define repdm(i, a, b) for (ll i = (ll)(a); i > (ll)(b); i--)

int height(int H, int X, int Y, int Cx, int Cy)
{
  return H + abs(X - Cx) + abs(Y - Cy);
}

int main()
{

  int N;
  cin >> N;

  int x[N], y[N], h[N];

  rep(i, N) cin >> x[i] >> y[i] >> h[i];

  int MAX = 101;
  int l[MAX][MAX][N];

  repd(i, 0, MAX)
  {
    repd(j, 0, MAX)
    {
      int cnt = 1;
      int ansH = 0;
      int outH = 0;

      rep(k, N)
      {
        int x0 = x[k];
        int y0 = y[k];
        int h0 = h[k];
        if (h0 == 0)
        {
          cnt++;
          continue;
        }

        l[i][j][k] = height(h0, x0, y0, i, j);

        if (ansH == 0)
        {
          ansH = l[i][j][k];
          continue;
        }
        if (ansH != l[i][j][k])
          break;
        if (ansH < outH)
          break;
        cnt++;
      }

      if (cnt < N)
        continue;

      rep(k, N)
      {
        int x0 = x[k];
        int y0 = y[k];
        int h0 = h[k];
        if (h0 == 0)
        {
          outH = height(h0, x0, y0, i, j);
          if (ansH > outH)
          {
            cnt = 0;
          }
        }
      }

      if (cnt < N)
        continue;

      cout << i << " " << j << " " << ansH << endl;
      return 0;
    }
  }
}

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

using namespace std;

#define int long long
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int H, W;
	vector<string> a, ans1, ans2;
	
	cin>>H>>W;
	
	a.resize(H);
	
	for(int i = 0; i < H; i++){
		cin>>a[i];
		if(count(a[i].begin(), a[i].end(), '.') != W) ans1.push_back(a[i]);
	}
	
	ans2.resize(ans1.size());
	
	for(int i = 0; i < W; i++){
		int con = 0;
		for(int j = 0; j < ans1.size(); j++){
			con += ans1[j][i] == '.';
		}
		
		if(con != ans1.size()){
			for(int j = 0; j < ans1.size(); j++){
				ans2[j].push_back(ans1[j][i]);
			}
		}
	}
	
	for(string s : ans2){
		cout<<s<<endl;
	}
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 1000000007
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

void  base_num(ll data,ll base){
    if(data==0) return;
    ll next=abs(data)%abs(base);
    if(data<0) next=(abs(base)-next)%abs(base);
    base_num((data-next)/base,base);
    cout << next;
}



int main(){
    ll n,m=0;
    cin >> n;
    ll a[n],b[n];
    for (ll i=0;i<n;i++)cin >> a[i];
    for (ll i=0;i<n;i++)cin >> b[i];
    ll x[n],y[n];
    x[0]=a[0];
    y[n-1]=b[n-1];
    for (ll i=1;i<n;i++){
        x[i]=x[i-1]+a[i];
    }
    for (ll i=n-2;i>=0;i--){
        y[i]=y[i+1]+b[i];
    }
    for (ll i=0;i<n;i++){
        m=max(m,x[i]+y[i]);
    }
    cout << m << endl;
    return 0;
}



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


int main(){
 long long n,m,c=0,k,x,y,l,r,d=0,sum=0;
 cin >>n>>m>>k;
 long long a[n],b[m];
 for(long long i=0;i<n;i++){cin >>a[i];sum+=a[i];}
 for(long long i=0;i<m;i++)cin >>b[i];
 x=0;
 long long sum2=0;
 for(long long i=n;i>=0;i--){
    if(i<n)sum-=a[i];
    if(sum<=k){
        while(sum+sum2+b[x]<=k && x<m){
            sum2=sum2+b[x++];

        }
     c=max(c,i+x);
    }

 }
 cout << c << endl;
}


Measured memory_bytes: 6716
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

N, M, K = map(int, input().split())
ok = False
for i in range(N + 1):
    # now = M * i
    for j in range(M + 1):
        now = i * (M - j) + (N - i) * j
        if now == K:
            ok = True
        # now -= j * i
        # now += j * (N - i)
        # if now == K:
        #     ok = True
if ok:
    print("Yes")
else:
    print("No")

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

typedef long long lli;
typedef vector<int> Vi;
typedef vector<lli> Vl;
typedef pair<int, int> Pii;
typedef pair<lli, lli> Pll;


//===


int main()
{
	lli N;
	cin >> N;

	lli ans = 0;

	for (lli i = 1; i * (i + 2) <= N; ++i) {
		if (N % i == 0) {
			ans += N / i - 1;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        a: i64,
        mut b: i64,
        mut c: i64,
        k: i64,
    };

    let mut is_b = a >= b;
    for _ in 0..k {
        if is_b {
            b *= 2;
            is_b = a >= b;
        } else {
            c *= 2;
        }
    }
    let ans = a < b && b < c;
    println!("{}", if ans { "Yes" } else { "No" });
}


Measured memory_bytes: 2172
#include<stdio.h>

#define N 100
#define INFTY 1000000


int main(){
  int n,p[N+10000],m[N+1][N+1];
  int i,j,k,l,sum;

  scanf("%d",&n);

  for( i=1 ;i <= n ; i++){
    scanf("%d %d",&p[i-1],&p[i]);

  }

  for(i = 0;i <= n; i++)m[i][i] = 0;


  for(l = 2;l <= n; l++){
  for(i = 1;i <= n; i++){
    j = i + l -1;
    m[i][j] = INFTY;
    for( k = i; k <= j - 1; k++ ){
      sum = m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j];
      if(m[i][j] > sum){
	m[i][j] = sum;
      }
    }
  }
  }
    printf("%d\n",m[1][n]);
    return 0;
 
}

Measured memory_bytes: 644
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b;
    cin>>a>>b;
    if(a>0)cout<<"Positive"<<endl;
    else if(b>=0)cout<<"Zero"<<endl;
    else if((a&1)^(b&1))cout<<"Positive"<<endl;
    else cout<<"Negative"<<endl;
	return 0;
}


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

using ll = long long;

int bit[26][500001], n;

int sum(int j, int i) {
    int s = 0;
    while (i > 0) {
        s += bit[j][i];
        i -= i & -i;
    }
    return s;
}

void add(int j, int i, int x) {
    while (i <= n) {
        bit[j][i] += x;
        i += i & -i;
        //cout << i << " ";
    }
}

int main() {
    int Q, q, i, l, r;
    char c;
    string S;
    cin >> n >> S >> Q;
    //cout << "n=" << n << " S=" << S << " Q=" << Q << "\n";
    rep(j, n) {
        add(S[j] - 'a', j + 1, 1);
    }
    rep(j, Q) {
        cin >> q;
        if (q == 1) {
            cin >> i >> c;
            add(S[i - 1] - 'a', i, -1);
            S[i - 1] = c;
            add(c - 'a', i, 1);
            //cout << "c=" << c << " i=" << i << " S=" << S << "\n";
        } else {
            cin >> l >> r;
            //cout << "l=" << l << " r=" << r << "\n";
            int ans = 0;
            rep(k, 26) {
                if (sum(k, r) > sum(k, l - 1)) ans++;
            }
            cout << ans << "\n";
        }
    }
}

Measured memory_bytes: 51716
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

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






int main(){
    ll n;
    cin >> n;
    ll mx = 0, ans = 0;
    REP(i, n){
        ll h;
        cin >> h;
        if(mx <= h){
            mx = h;
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc154/tasks/abc154_c

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
  int N;
  vector<int> A;

  cin >> N;
  A.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  sort(A.begin(), A.end());

  for (int i = 0; i < N; i++) {
    if (A[i] == A[i + 1]) {
      cout << "NO" << endl;
      return 0;
    }
  }

  cout << "YES" << endl;

  return 0;
}


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

int  main(){
  int n;cin>>n;
  int sum=0;
  int p,pm=0;
  rep(i,n){
    cin>>p;
    pm=max(pm,p);
    sum+=p;
  }
  cout<<sum-pm/2;
}

Measured memory_bytes: 256
<?php

[$N] = fscanf(STDIN, "%d");

$mod = 7 % $N;
for($i=1;$i<9000000;$i++){
    if($mod === 0){
        echo $i;
        exit;
    }
    $mod *=10;
    $mod +=7;
    $mod %= $N;

}

echo -1;

Measured memory_bytes: 16164
s=input()
if len(s)<26:
    al=[chr(ord('a') + i) for i in range(26)]
    for i in al:
        if not(i in s):
            print(s+i)
            exit()
if s=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    exit()
a=[]
for i in range(25,-1,-1):
    for j in range(24-(25-i),-1,-1):
        if s[j]<s[i]:
            a.append(s[:j]+s[i])
print(min(a))

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<set>
#include<algorithm>
static const int P = 998244353;
using namespace std;
vector<int> to[200001];//隣接リスト

long long dfs(int i){
    long long res = 1;
    for (auto j = to[i].begin(); j != to[i].end(); j++)
    {
        res *= dfs(*j) % P;
        res %= P;
    }
    return (res + 1) % P;
}

int main()
{
    int n;
    cin >> n;
    vector<pair<int, int>> p(n);
    for (int i = 0; i < n; i++)
    {
        cin >> p[i].first >> p[i].second;
    }
    sort(p.begin(), p.end());
    set<pair<int, int>> s;//(座標,添字)親リスト
    for (int i = n - 1; i >= 0; --i)
    {
        int x = p[i].first;
        int d = p[i].second;
        while (!s.empty() && s.begin()->first < x + d)//s.beginがp[i]によって起動される時
        {
            to[i].push_back(s.begin()->second);//s.beginの親はp[i]
            s.erase(s.begin());
        }
        s.emplace(x, i);
    }
    long long ans = 1;
    for (auto itr = s.begin(); itr != s.end(); itr++)
    {
        int i = itr->second;
        ans *= dfs(i);
        ans %= P;
    }
    cout << ans << endl;
}

Measured memory_bytes: 22144
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<ll> vll;
#define ff first
#define ss second
#define pb(x) push_back(x)
#define mp make_pair
const int mod=(ll)1e9+7;
#define all(x) x.begin(),x.end()
#define s(x) ((ll)x.size())
#define tc ll t; cin>>t; while(t--)
#define FOR(i,j,n) for(ll i=j;i<n;i++)
#define ig cin.ignore()
#define fast_cin ios_base::sync_with_stdio(false)
ll power(ll a, ll b) {ll ret=1;while(b) {if(b&1) ret*=a;a*=a;if(ret>=mod) ret%=mod;if(a>=mod) a%=mod;b>>=1;}return ret;}
ll inv(ll x) {return power(x,mod-2);}
/*---------------------------------------------------------//
const int MAXM = 1e7+3010;   ll fact[MAXM];
void factorial(){ fact[0]=1;FOR(i,1,MAXM) fact[i]=(fact[i-1]*i)%mod;}
ll nCr(ll n,ll r){return ((fact[n])*(((inv(fact[r]))*(inv(fact[n-r])))%mod))%mod;}

// freopen("Task.in","r",stdin);freopen("Task.out","w",stdout);
//-------------------------------------------------------------------/*/

int main(){
    ll n,k,x,y;    cin >> n >> k;
    map<ll,ll>m;

    FOR(i,0,k){
        cin >> x >> y;
        m[x]++;   m[y]++;
    }

    for(auto it=m.begin(); it!=m.end(); it++){
        if(m[it->ff]%2){
            cout << "NO\n";
            return 0;
        }
    }

    cout << "YES\n";






}


Measured memory_bytes: 5632
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] yobi = {"Sunday","Monday","Tuesday","Wednesday",
							"Thursday","Friday","Saturday"};
		int step1 = 2004 + (2004/4);
		int step2 = step1 - (2004/100);
		int step3 = step2 + (2004/400);
		while(sc.hasNext()){
			int month = sc.nextInt();
			int day = sc.nextInt();
			if(month == 0 & day == 0) break;
			int step4 = ((month*13) + 8) / 5;
			int step5 = step3 + step4;
			int step6 = step5 + day;
			int step7 = step6 % 7;
			System.out.println(yobi[step7]);
		}
	}
}

Measured memory_bytes: 25984
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <numeric>
#include <cmath>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,x); REP(i,sizeof(a)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"
#define PI 3.141592653589793

//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}

int main(){
    while(1){
      int N; cin>>N;
      if(N==0){break;}
      double s[N];
      double avr = 0;
      REP(i,N){
        cin >> s[i];
        avr += s[i];
      }
      avr /= N;
      double ans = 0;
      REP(i,N){
        ans += pow(s[i]-avr,2);
      }
      ans /= N;
      ans = sqrt(ans);
      printf("%.5f\n",ans);
    }
}


Measured memory_bytes: 3208
# B問題
N, M = map(int, input().split())
ab = []
for i in range(N):
    ab.append(list(map(int, input().split())))
cd = []
for i in range(M):
    cd.append(list(map(int, input().split())))
ans = []
for i in range(N):
    tmp_lst = []
    for k in range(M):
        tmp = 0
        tmp = abs(ab[i][0] - cd[k][0]) + abs(ab[i][1] - cd[k][1])
        tmp_lst.append(tmp)
    ans.append(tmp_lst.index(min(tmp_lst)))
for i in range(N):
    print(ans[i] + 1)

Measured memory_bytes: 3064
def cin(): # To take limited number of inputs
	return map(int,input().split())

def cino(test=False): # To take individual int input (test = False)
    if not test:
        return int(input())
    else: # To take string input (test = True)
        return input()

def cina(): # array input
  return list(map(int,input().split()))

def ssplit(): # multiple string input
    return list(input().split())

def printlist(l): # to print space seperated array
    for i in l:
        print(i,end=" ")

def main():
    a = cino()
    b = cino(True)
    l = len(b)
    # print(len(b))
    if l<=a:
        print(b)
    else:
        print(b[:a]+"...")

if __name__=="__main__":
    main()

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


int main(){
    ll N; cin >> N;
    vector<ll> A(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i]; A[i]--;
    }
    ll ans = 0;
    for(int i = 0; i < N; i++){
        if(i == A[A[i]]) ans++;
    }
    cout << ans /2 << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    int x;
    cin >> x;
    
    int ans = 0;
    ans += x/500 * 1000;

    x %= 500;

    ans += x / 5 * 5;


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

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define loop(n, i) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;

using namespace std;
typedef long long ll;

char s[] = { 'o', 'x' };
string B[10];
int dx[] = {  0, -1, -1, -1, 0, 1, 1, 1  };
int dy[] = { -1, -1,  0,  1, 1, 1, 0, -1 };

int count(int t, int ii, int jj)
{
    if (B[ii][jj] != '.') return 0;
    int ans = 0;
    loop (8, p) {
        int i = ii + dx[p], j = jj + dy[p];
        int cnt = 0;
        while (B[i][j] == s[!t]) i += dx[p], j += dy[p], cnt++;
        if (B[i][j] == s[t]) ans += cnt;
    }
    return ans;
}

int move(int t, int ii, int jj)
{
    B[ii][jj] = s[t];
    loop (8, p) {
        int i = ii, j = jj;
        i += dx[p], j += dy[p];
        while (B[i][j] == s[!t]) i += dx[p], j += dy[p];
        if (B[i][j] != s[t]) continue;
        i = ii + dx[p], j = jj + dy[p];
        while (B[i][j] == s[!t]) B[i][j] = s[t], i += dx[p], j += dy[p];
    }
}

int main()
{
    B[0] = "----------";
    B[9] = "----------";
    loop (8, i) {
        string s; cin >> s;
        B[i+1] = "-" + s + "-";
    }

    int t = 0;
    int end = 0;
    while (1) {
        int m_cnt = 0, x = -1, y = -1;
        loop (8, ii) loop (8, jj) {
            int i = ii + 1, j = jj + 1;
            if (t) i = 8 - ii, j = 8 - jj;

            int cnt = count(t, i, j);
            if (cnt > m_cnt) m_cnt = cnt, x = i, y = j;
        }
        if (m_cnt) end = 0, move(t, x, y);
        else end++;
        t ^= 1;
        if (end > 1) break;
    }
    loop (8, i) {
        cout << B[i+1].substr(1, 8) << endl;
    }
    return 0;
}

Measured memory_bytes: 3196
/* Simplicity and Goodness */

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

// using namespace __gnu_pbds;
using namespace std;
// typedef tree<int, null_type, less<int>, rb_tree_tag,
//             tree_order_statistics_node_update> indexed_set;

void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B)
{ cout << ' ' << A; my_dbg(B...); }
#define dbg(...)  cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)

#define scn(n) scanf("%d", &n)
#define lscn(n) scanf("%lld", &n)
#define pri(n) printf("%d ", (int)(n))
#define prin(n) printf("%d\n", (int)(n))
#define lpri(n) printf("%lld ", n)
#define lprin(n) printf("%lld\n", n)
#define rep(i,a,b) for(int i=(int)(a); i<(int)(b); i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;

const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 1e9+7;
const int N = 2e5+2;

void rec(string& cur, char act, int len)
{
    if(len == 0)
        cout << cur << '\n';
    else {
        for(char c = 'a'; c <= act + 1; c ++) {
            cur.pb(c);
            rec(cur, max(act, c), len - 1);
            cur.pop_back();
        }
    }
}

void solve()
{
    int n;
    scn(n);

    string cur = "";
    rec(cur, 'a' - 1, n);
}

int main()
{
    int t = 1;
    // scn(t);
    
    while(t --) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using V = vector<int>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVbo = vector<Vbo>;
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define rep(i, n) rep2(i, 0, n)
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }


VV G;
V cl;
V cnt(2);

bool dfs(int u, int x=0) {
  if (cl[u] == x) return true;
  if (cl[u] == (x^1)) return false;
  cl[u] = x;
  ++cnt[x];
  for (auto v : G[u]) {
    if (!dfs(v, x^1)) return false;
  }
  return true;
}


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

  VVbo A(n, Vbo(n, true));
  rep(i, m) {
    int u, v; cin >> u >> v;
    --u; --v;
    A[u][v] = false;
    A[v][u] = false;
  }
  rep(i, n) A[i][i] = false;

  G.assign(n, V());
  cl.assign(n, -1);
  rep(i, n) rep(j, n) if (A[i][j]) G[i].push_back(j);

  bitset<701> dp;
  dp[0] = 1;
  rep(i, n) {
    if (cl[i] != -1) continue;
    cnt.assign(2, 0);
    if (!dfs(i)) {
      cout << -1 << "\n";
      return 0;
    }
    dp = (dp<<cnt[0]) | (dp<<cnt[1]);
  }

  int ans = n*n;
  rep(i, n) if (dp[i]) chmin(ans, i*(i-1)/2 + (n-i)*(n-i-1)/2);
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int,int> pi;
typedef pair<lld,lld> pl;
typedef vector<int> vit;
typedef vector<vit> vitt;
typedef vector<lld> vlt;
typedef vector<vlt> vltt;
typedef vector<pi> vpit;
typedef vector<vpit> vpitt;
typedef long double ld;
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mk(a,b) make_pair(a,b)
bool isrange(int y,int x,int n,int m){
	 if(0<=y&&y<n&&0<=x&&x<m) return true;
	 return false;
}
int dy[4] = {1,0,-1,0},dx[4]={0,1,0,-1},ddy[8] = {1,0,-1,0,1,1,-1,-1},ddx[8] = {0,1,0,-1,1,-1,1,-1};
const int MAX = 2020;
int dp[MAX][MAX],arr[MAX*3],dp2[MAX];
void upd(int f1,int f2,int x){
	dp[f1][f2] = max(dp[f1][f2],x);
	dp[f2][f1] = max(dp[f2][f1],x);
}
int main(void){
	for(int e=0;e<MAX;e++){
		for(int p=0;p<MAX;p++) dp[e][p] = -1e9;
		dp2[e] = -1e9;
	}
	int n;
	scanf("%d",&n);
	for(int e=0;e<3*n;e++) scanf("%d",&arr[e]);
	if(n==1){
		printf("1");
		return 0;
	}
	int tt = 0,mm = 0;
	for(int e=0;e<5;e++){
		for(int p=e+1;p<5;p++){
			int ll = -1,err = 0;
			for(int q=0;q<5;q++){
				if(e==q||p==q) continue;
				if(ll==-1) ll = arr[q];
				else{
					if(ll!=arr[q]) err = 1;
				}
			}
			if(err==0){
				upd(arr[e],arr[p],1);
				dp2[arr[e]] = 1;
				dp2[arr[p]] = 1;
				mm = 1;
			}else{
				upd(arr[e],arr[p],0);
				dp2[arr[e]] = max(dp2[arr[e]],0);
				dp2[arr[p]] = max(dp2[arr[p]],0);
			}
		}
	}
	for(int e=1;e<=n-2;e++){
		int lx = 5 + (e-1) * 3, rx = 5 + e * 3;
		
		// use 3 card 
		
		int ll = -1,err = 0;
		for(int q=lx;q<rx;q++){
			if(ll==-1) ll = arr[q];
			else{
				if(ll!=arr[q]) err = 1;
			}
		}
		int res = 0;
		if(err==0){
			tt++;
			res = 1;
		}
		vector<pair<pi,int> > v;
		
		// use 1 card
		
		for(int q=lx;q<rx;q++){
			if(dp[arr[q]][arr[q]]!=-1e9){
				// find 3 card
				
				int s1 = -1,s2 = -1;
				for(int r=lx;r<rx;r++){
					if(q==r) continue;
					if(s1==-1) s1 = arr[r];
					else s2 = arr[r];
				}
				v.push_back(mk(mk(s1,s2),dp[arr[q]][arr[q]] + 1 - res));
			}
			// no gain
				
			for(int r=1;r<=n;r++){
				if(dp2[r]!=-1e9){
					v.push_back(mk(mk(r,arr[q]),dp2[r] - res));
				}
			}
		}
		
		// use 2 card
		for(int q=lx;q<rx;q++){
			for(int r=q+1;r<rx;r++){
				if(arr[r]==arr[q]){
					int s1 = -1;
					for(int p=lx;p<rx;p++){
						if(p==q||r==p) continue;
						s1 = arr[p];
					}
					for(int p=1;p<=n;p++){
						if(dp[p][arr[q]]!=-1e9){
							v.push_back(mk(mk(p,s1),dp[p][arr[q]] + 1 - res));
						}
					}
				}
				v.push_back(mk(mk(arr[q],arr[r]),mm - res));
			}
		}
		for(int e=0;e<sz(v);e++){
			int f1 = v[e].x.x;
			int f2 = v[e].x.y;
			int wei = v[e].y;
			mm = max(mm,wei);
			dp2[f1] = max(dp2[f1],wei);
			dp2[f2] = max(dp2[f2],wei);
			upd(f1,f2,wei);
		}
	}
	int lastn = arr[3*n - 1];
	if(dp[lastn][lastn]!=-1e9) dp[lastn][lastn]++;
	int ans = 0;
	for(int e=1;e<=n;e++) for(int p=1;p<=n;p++) if(dp[e][p]!=-1e9){
		ans = max(ans,dp[e][p] + tt);
	}
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 19860
#include <bits/stdc++.h>
 
using namespace std;
const int MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
const double PI = 4*atan(1);
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
// ll gcd(ll a, ll b) { 
//     if (a == 0) return b; 
//     return gcd(b % a, a); 
// }
ll mod(ll x) {
	x%=MOD;
	if(x<0)x+=MOD;
	return x;
}
// ll power(int base, int power) {
// 	ll prod = 1;
// 	ll b = base;
// 	while(power) {
// 		if (power & 1) {
// 			prod = mod(prod*b);
// 		}
// 		b = mod(b*b);
// 		power/=2;
// 	}
// 	return prod;
// }
// struct line {
//     int m, c;
//     ll eval(int x) { return 1LL * m * x + c; }
//     double intersectX(line l) { return (double) (c - l.c) / (l.m - m); }
//0 is white, 1 is black
int a,b,c,k;
void solve() {
	cin >> a >> b >> c >> k;
	if (a>=k) {
		cout << k << endl;
	} else if (a+b>=k) {
		cout << a << endl;
	} else {
		cout << a-(k-(a+b)) << endl;
	}
}
int main() {

	int t=1;
	// cin >> t;
	for (int i = 1; i <= t; i++) { 
		// cout << "Case #" << i << ": ";
		solve();
	}
}

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


#define _fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pi acos(-1)
#define MAXS 1e(18)
#define MOD 1000000007
#define all(v) v.begin(),v.end()

typedef long long ll;

int main()
{

    _fastIO;

    int row, col, kk, arr[305][305];

    while(cin>>row>>col>>kk){
        string grid[305];
        memset(arr,0,sizeof(arr));
        for(int i=0; i<row; i++){
            cin>>grid[i];
        }
        //for(int i=0; i<row; i++)cout<<grid[i]<<endl;
        int id=0;
        for(int i=0; i<row; i++){
            for(int j=0; j<col; j++){
                if(grid[i][j]=='#'){
                    ++id;
                    for(int k=j; k>=0 && arr[i][k]==0; k--){
                        arr[i][k]=id;
                    }
                }
            }
        }
//        cout<<"First"<<endl;
//        for(int i=0; i<row; i++){
//            for(int j=0; j<col; j++){
//                cout<<arr[i][j]<<' ';
//            }
//            cout<<endl;
//        }
        for(int i=0; i<row; i++){
            for(int j=0; j<col; j++){
                if(arr[i][j]>0){
                    for(int k=j+1; k<col; k++){
                        if(arr[i][k]==0){
                            arr[i][k]=arr[i][k-1];
                        }
                        else break;
                    }
                }
            }
        }
//        cout<<"before UPP"<<endl;
//        for(int i=0; i<row; i++){
//            for(int j=0; j<col; j++){
//                cout<<arr[i][j]<<' ';
//            }
//            cout<<endl;
//        }
//        cout<<"Be"<<endl;
        for(int i=0; i<row; i++){
            for(int j=0; j<col; j++){
                if(arr[i][j]>0){
                    for(int ro=i-1; ro>=0; ro--){
                        if(arr[ro][j]==0){
                            arr[ro][j]=arr[ro+1][j];
                        }
                        else break;
                    }
                }
            }
        }
        for(int i=0; i<row; i++){
            for(int j=0; j<col; j++){
                if(arr[i][j]>0){
                    for(int ro=i+1; ro<row; ro++){
                        if(arr[ro][j]==0){
                            arr[ro][j]=arr[ro-1][j];
                        }
                        else break;
                    }
                }
            }
        }
        for(int i=0; i<row; i++){
            for(int j=0; j<col; j++){
                cout<<arr[i][j];
                if(j!=(col-1)){
                    cout<<' ';
                }
            }
            cout<<endl;
        }
    }

    return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#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 INF 2e9
#define PI 3.141592653589793
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main(){
    ll N, M;
    cin >> N >> M;
    vector<int> p(M);
    vector<string> S(M);
    for(int i = 0; i < M; i++){
        cin >> p[i];
        cin >> S[i];
    }

    vector<pair<ll,ll> > problem(N+1);//w数, ACかどうか01
    for(int i = 0; i < M; i++){
        if(S[i] == "AC"){
            problem[p[i]].second = 1;
        }else{
            if( problem[p[i]].second == 0){//Acじゃない問題
                problem[p[i]].first++;
            }
        }
    }

    ll WAcnt=0;
    ll ACcnt=0;
    for(int i = 1; i < N+1; i++){
        if(problem[i].second == 1){//AC
            ACcnt++;
            WAcnt += problem[i].first;
        }
    }

    cout << ACcnt <<  " " << WAcnt << endl;;


}

Measured memory_bytes: 7680
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;
    ll ans = N / 2 + N % 2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256