akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define int long long
using P = pair<int,int>;

signed main(){
  int h,w;
  cin >> h >> w;
  vstring mass(h);
  rep(i,h) cin >> mass[i];
  vvint U(h,vint(w));
  vvint D(h,vint(w));
  vvint L(h,vint(w));
  vvint R(h,vint(w));
  rep(j,w){
    rep(i,h){
      if(i == 0){
        if(mass[i][j] == '.') U[i][j] = 1;
      }
      else{
        if(mass[i][j] == '.') U[i][j] = U[i-1][j] + 1;
      }
    }
  }
  rep(j,w){
    for(int i = h-1;i >= 0;i--){
      if(i == h-1){
        if(mass[i][j] == '.') D[i][j] = 1;
      }
      else{
        if(mass[i][j] == '.') D[i][j] = D[i+1][j] + 1;
      }
    }
  }
  rep(i,h){
    rep(j,w){
      if(j == 0){
        if(mass[i][j] == '.') L[i][j] = 1;
      }
      else{
        if(mass[i][j] == '.') L[i][j] = L[i][j-1] + 1;
      }
    }
  }
  rep(i,h){
    for(int j = w-1;j >= 0;j--){
      if(j == w-1){
        if(mass[i][j] == '.') R[i][j] = 1;
      }
      else{
        if(mass[i][j] == '.') R[i][j] = R[i][j+1] + 1;
      }
    }
  }
  int ans = 0;
  rep(i,h){
    rep(j,w){
      ans = max(ans,U[i][j] + L[i][j] + R[i][j] + D[i][j] -3);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 129664
from collections import Counter

MOD = 10**9 + 7

N = int(input())
As = list(map(int, input().split()))

ptns = Counter([(0, 0, 0)])
#print('ptns:', ptns)
for A in As:
    ptn2s = Counter()
    for ptn, num in ptns.items():
        for i in range(3):
            if ptn[i] == A:
                ptn2 = list(ptn)
                ptn2[i] += 1
                ptn2s[tuple(ptn2)] += num
                ptn2s[tuple(ptn2)] %= MOD
    ptns = ptn2s

#print(ptns)
print(sum(ptns.values()) % MOD)


Measured memory_bytes: 55004
import java.util.*;
import static java.lang.System.*;

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

		System.out.println(Math.min(n * a, b));
	}
}


Measured memory_bytes: 22612
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define F first
#define S second
#define pss pair<string,string>
#define pcc pair<char,char>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define piii pair<int,pii>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define vs vector<string>
#define vl vector<ll>
#define vs vector<string>
#define vll vector<pll>
#define vss vector<pss>
#define vcc vector<pcc>
#define MP make_pair
using namespace std;
const int N=2e5+5;
const int mod=1e9+7;
ll cal(ll a,ll b)
{
	if(a==0)return 1;
	ll res=cal(a/2,b);
	if(a%2==0)res=res*res%mod;
	else res=res*res%mod*b%mod;
	return res;
}
ll che[N],n,m,ny[N];
ll C(ll y,ll x)
{
	return che[y]*ny[x]%mod*ny[y-x]%mod;
}
ll ans=1;
int main()
{
	cin>>n>>m;
	m=min((ll)n-1,m);
	che[0]=1;
	ny[0]=1;
	for(int i=1;i<=n;i++)che[i]=che[i-1]*i%mod,ny[i]=cal(mod-2,che[i])%mod;
	for(int i=1;i<=m;i++)
	{
		ll sum=C(n,i)*C(n-1,i)%mod;
		ans=(ans+sum)%mod;
	}
	cout<<ans<<endl;
	return 0;
}

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

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

  for(int n = 1;n <= 3500;n++) {
    for(int h = 1;h <= 3500;h++) {
      if(4*n*h-(n+h)*N > 0 && (N*n*h) % (4*n*h-(n+h)*N) == 0) {
        cout << n << " " << h << " " << N*n*h / (4*n*h-(n+h)*N) << endl;
        return 0;
      }
    }
  }
  
}

Measured memory_bytes: 256
N=int(input())
dic={}
for i in range(N):
  s=input()
  s=sorted(s)
  s=''.join(s)
  if s in dic:
    dic[s]+=1
  if s not  in dic:
    dic[s]=1
ans=0
for v in dic.values():
  ans+=v*(v-1)/2
print(int(ans))

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

int main(){
 
  while(1){
    int in; cin >> in ;
    if(in==0) break;
     double n = (double)in;
     double s[in]={}, sum=0.0;
    for(int i=0;i<n;i++){
      cin >> s[i];
      sum += s[i];
    }
     double ans=0.0, m = sum / n;
    for(int i=0; i<n; i++){
      ans += (s[i] - m)*(s[i] - m);
      //      cout << ans << " " << n << "\n";
    }
    printf("%.10lf\n",sqrt(ans/n));
  }
}

Measured memory_bytes: 3288
#include <bits/stdc++.h>
#include <stdlib.h>
#include <string>
#include <algorithm>
#include <map>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

vi prime(55555);
bool is_prime[55556];

int sieve(int n){
  int p = 0;
  for (int i = 0; i <= n; i++) is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i <= n; i++){
    if (is_prime[i]){
      prime[p++] = i;
      for (int j = 2*i; j <=n; j+=i) is_prime[j] = false;
    }
  }
  //return p;
}

int main(){
  sieve(55555);
  int N;
  cin >> N;
  vi ans;
  rep(i, prime.size()){
    if (prime[i] % 5 == 1){
      ans.push_back(prime[i]);
    }
    if (ans.size() == N){
      break;
    }
  }
  rep(i, N){
    cout << ans[i] << " ";
  }
}


Measured memory_bytes: 512
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0

using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

/*-----------------------------------------ここからコード-----------------------------------------*/


int main() {
	
	string s;
	scans(s);
	printf("%d\n", -4 + (s[0] == '+') * 2 + (s[1] == '+') * 2 + (s[2] == '+') * 2 + (s[3] == '+') * 2);
	
	Please AC;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define pll pair <ll, ll>
#define mp make_pair
#define pyshnapyshnakaa ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define x first
#define y second
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#define plll pair <pair <ll, ll>, ll>
#define pllll pair <pair <ll, ll>, pair <ll, ll> >
#define psl pair <string, ll>
#define all(a) a.begin(), a.end()
#define vvl vector <vector <ll> >
 
typedef long long ll;

typedef long double ld;
 
using namespace std;
 
const ll maxn = 4e3;
const ll mod = 998244353;

ll n, m, k, t;

ll D[maxn][maxn];

int main() {
    pyshnapyshnakaa;
    ll q, w, e, a, b, c, d;
    cin >> a >> b >> c >> d;
    D[a][b] = 1;
    for (q = a; q <= c; q++) {
        for (w = b; w <= d; w++) {
            if (q == a && w == b) {
                continue;
            }
            D[q][w] = D[q - 1][w] * (w) + D[q][w - 1] * q;
            D[q][w] = D[q][w] - D[q - 1][w - 1] * (q - 1) * (w - 1) % mod + mod;
            D[q][w] %= mod;
            // cout << q << " " << w << " " << D[q][w] << endl;
        }
    }
    cout << D[c][d];
    return 0;
}

Measured memory_bytes: 85956
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define rev(i, n) for(int i = n;i >= 0;i--)
#define Rep(i, m, n) for(int i = m;i < n;i++)
#define repeatrev(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define itn int
const int MAX = 510000;


using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef priority_queue<int> Pr;

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a;
    string s;
    cin >> a >> s;
    if(a >= 3200) cout << s << endl;
    else cout << "red" << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef long double lb;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int dx[] = {0, 0, 1, -1};
constexpr int dy[] = {1, -1, 0, 0};

ll div_up(ll a, ll b)
{
    return (a + b - 1) / b;
}

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

    ll n, a[212345], dp1[212345][16], dp2[212345][16];

    cin >> n;
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i];
    }

    for (int i = 0; i <= 15; i++)
    {
        dp1[n - 1][i] = i;
        dp2[0][i] = i;
    }

    for (int i = n - 2; i >= 0; i--)
    {
        ll tmp = a[i];
        for (int j = 0; j <= 15; j++)
        {
            if (tmp <= a[i + 1])
                dp1[i][j] = j + dp1[i + 1][0];
            else
            {
                int x = ceil(log(div_up(tmp, a[i + 1])) / log(4));
                dp1[i][j] = j + dp1[i + 1][min(x, 15)];

                if (x >= 15)
                {
                    dp1[i][j] += (x - 15) * (n - i - 1);
                }
            }

            tmp *= 4;
        }
    }

    for (int i = 1; i < n; i++)
    {
        ll tmp = a[i];
        for (int j = 0; j <= 15; j++)
        {
            if (tmp <= a[i - 1])
                dp2[i][j] = j + dp2[i - 1][0];
            else
            {
                int x = ceil(log(div_up(tmp, a[i - 1])) / log(4));
                dp2[i][j] = j + dp2[i - 1][min(x, 15)];

                if (x >= 15)
                {
                    dp2[i][j] += (x - 15) * i;
                }
            }

            tmp *= 4;
        }
    }

    ll res = min(dp1[0][0] * 2, dp2[n - 1][0] * 2 + n);

    for (int i = 1; i < n; i++)
    {
        res = min(res, dp1[i][0] * 2 + dp2[i - 1][0] * 2 + i);
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 54784
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int c = 1;
		int n;
		try {
			while ((n = Integer.parseInt(br.readLine())) != 0) {
				System.out.println("Case " + c + ": " + n);
				c++;
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 32116
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;//10^12
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
////////////////////////////////////////

int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    
    ll a,b;cin>>a>>b;
    if(a*b%2==1)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
    return 0;
}

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

typedef long long ll;
#define ALL(a) a, a+sizeof(a)/sizeof(a[0])
#define all(a) a.begin(),a.end()
#define MOD 1000000007
using namespace std;
ll gcd(ll n, ll m) {
	if (m == 0) return n;
	return gcd(m, n % m);
}
ll lcm(ll n, ll m) {return m / gcd(n, m) * n;}

int main(void) {
	ll n;
	cin >> n;
	int tmp;
	int Max = -100;
	int Min = 10000;
	for (int i = 0; i < n; i++) {
		cin >> tmp;
		if (tmp > Max) Max = tmp;
		if (tmp < Min) Min = tmp;
	}
	if ((Max - Min) % 2 == 0)	cout << (Max - Min) / 2 << endl;
	else cout << (Max - Min) / 2 + 1 << endl;
	return 0;
}


Measured memory_bytes: 3108
#include<bits/stdc++.h>
    using namespace std;
  #define int long long int
    #define endl "\n"
    #define MOD 1000000007
    #define mod 1000000007
    #define M 1000000007
    
    #define pb push_back
    #define take(a,b,c) for(int b=0;b<c;b++) cin>>a[b]
  //  #define mp make_pair
  #define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);  
  #define mx 400005
  #define fiint(a,b) memset(a,b,sizeof(a))  
  #define bitcount __builtin_popcount
  #define fori(i,a,b) for(int i=a;i<b;i++)
  #define ford(i,a,b) for(int i=a;i>=b;i--)
  #define debug(x) cout<<x<<endl;
  #define cases(t) int t; cin>>t; while(t--)
  #define inf1 INT_MAX
  #define all(a) a.begin(),a.end()
  #define vec vector<int>
  #define pii pair<int,int>
  #define plii pair<int,int>
  #define pint pair<int,int>
  #define ff first
  #define ss second
  #define lb lower_bound
  #define ub upper_bound
  #define bs binary_search
  #define sz(x) (int)x.size()
#define PI                    3.14159265359

bool prime[10000001];

void sieveFunction(int maxLimit){
    memset(prime, true, sizeof(prime));
    prime[0] = prime[1]=false;
    for(int i=2; maxLimit >= i ; i++){
        if(prime[i]){
            for(int j=2*i ; maxLimit >= j ; j+=i)
                prime[j]=false;
        }
    }
}



signed  main() 
{ 
	int h,w;
	cin>>h>>w;
	vector < vector<char> >	v (  h+1  , vector<char>(w+1) ) ; 
	fori(i,1,h+1)
		fori(j,1,w+1)
			cin>>v[i][j];

	vector < vec >	dp (  h+1  , vector<int>(w+1) ) ; 
	dp[1][1] = 1;		
	fori(i,1,h+1)
		fori(j,1,w+1)
			if (i==1 && j==1)
				continue;
			else if(v[i][j]=='.')
			dp[i][j] = (dp[i-1][j]%mod + dp[i][j-1] %mod)%mod;

			cout<<dp[h][w]<<endl; 
		
	
}




 


Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define P pair<int,int>
#define vp vector<P>
#define PP pair<int,P>
#define vpp vector<PP>
#define fi first
#define se second
#define INF 1e9
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define all(x) (x).begin(),(x).end()
signed main(){
    int n;
    cin>>n;
    string m("MARCH");
    vi vec(5);
    REP(i,n){
        string t;
        cin>>t;
        REP(j,5){
            if(t[0]==m[j]){
                vec[j]++;
            }
        }
    }
    int ans=0;
    REP(i,5){
        FOR(j,i+1,5){
            FOR(k,j+1,5){
                ans+=vec[i]*vec[j]*vec[k];
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))

using namespace std;
using ll = long long;
using pii = pair<int, int>;

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'000'000'001;
constexpr ll LLINF = 4'000'000'000'000'000'001;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    string s, t;
    cin >> s >> t;
    vector<vector<int>> dp(s.size() + 1, vector<int>(t.size() + 1));
    for(int i = 1; i <= s.size(); ++i){
        for(int j = 1; j <= t.size(); ++j){
            dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            if(s[i-1] == t[j-1]) dp[i][j] = max(dp[i][j], dp[i-1][j-1]  + 1);
        }
    }
    string ans;
    int ss = s.size(), tt = t.size();
    while(ss * tt){
        if(dp[ss][tt] == dp[ss-1][tt]) --ss;
        else if(dp[ss][tt] == dp[ss][tt-1]) --tt;
        else{
            ans.push_back(s[ss-1]);
            --ss;
            --tt;
        }
    }
    reverse(begin(ans), end(ans));
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 35584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF 2 << 29
#define MOD 1000000007
#define Yes(f) puts((f)? "Yes" : "No")
#define YES(f) puts((f)? "YES" : "NO")
int gcd(int a, int b) {
	if (b != 0)return gcd(b, a % b);
	return a;
}
int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}

using Graph = vector<vector<int>>;

int main(){
	int a, b; cin >> a >> b;
	int ans = 0;
	rep(i, a + 1){
		rep(j, a + 1){
			if(0 <= b - i - j && b - i - j <= a) ans++;
		}
	}
	cout << ans << endl;
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
//typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define UNIQUE(c) sort(ALL(c)), c.erase(unique(ALL(c)), c.end())

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N, Q; cin >> N >> Q;
  vector<int> stops(N);
  vector<tuple<int, int, int>> times;
  REP(i, N) {
    int s, t, x; cin >> s >> t >> x;
    times.emplace_back(s-x, 0, i);
    times.emplace_back(t-x, -1, i);
    stops[i] = x;
  }
  REP(i, Q) {
    int d; cin >> d;
    times.emplace_back(d, 1, i);
  }
  sort(ALL(times));
  set<pair<int, int>> now;

  vector<int> ans(Q, -1);
  for (auto tu : times) {
    int t, k, i; tie(t, k, i) = tu;
    if (k == -1) {
      now.erase(make_pair(stops[i], i));
    } else if (k == 0) {
      now.insert(make_pair(stops[i], i));
    } else {
      if (now.size()) ans[i] = now.begin()->first;
    }
  }

  for (int v : ans) cout << v << endl;

  return 0;
}


Measured memory_bytes: 20968
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e13;
const int mod = 1e9+7;
#define ll long long
map<char, int> m;
signed main() {
    int k;
    cin >> k;
    vector<int> a(1000002);
    a[0]=7%k;
    FOR(i,1,a.size()) {
        a[i]=10*a[i-1]%k;
    }
    int total = 0;
    rep(i,a.size()) {
        total += a[i];
        total %= k;
        if(total==0) {
            cout << i+1 << endl;
            return 0;
        }
    }
cout << -1 << endl;
    


  return 0; 
}



Measured memory_bytes: 11172
n = int(input())
f = [list(map(int,input().split())) for _ in range(n)]
p = [list(map(int,input().split())) for _ in range(n)]

a     = []
count = 0
point = []
PP = []

for _ in range(2**10+1,2**10*2):
    a.append(list(map(int,list(bin(_)[3:]))))

for k in range(2**10-1):
    for i in range(n):
        for j in range(10):
            if f[i][j]&a[k][j] == 1:
                count += 1
        point.append(p[i][count])
        count = 0
    PP.append(sum(point))
    point = []
print (max(PP))
        

Measured memory_bytes: 3316
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int m = s.nextInt();
		int i = 0;
		int j = 0;
		int k = 0;
		int l = 0;
		String answer = "No";
		String[][] ary1 = new String[n][n];

		for (j = 0; j < n; j++) {
			String str = s.next();
			for (i = 0; i < n; i++) {
				ary1[j][i] = str.charAt(i) + "";
			}
		}

		String[][] ary2 = new String[m][m];
		for (l = 0; l < m; l++) {
			String str2 = s.next();
			for (k = 0; k < m; k++) {
				ary2[l][k] = str2.charAt(k) + "";
				//System.out.println(ary2[l][k]);
			}
		}

		b:for (j = 0; j+m <= n; j++) {
			for (i = 0; i+m <= n; i++) {
				a: for (l = 0; l < m; l++) {
					for (k = 0; k < m; k++) {
						if (ary1[j + l][i + k].equals(ary2[l][k])) {
						} else {
							break a;
						}
					}
				}
				if(k==m&&l==m) {
					answer = "Yes";
					break b;
				}
			}
		}
		System.out.println(answer);

	}

}


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

int main() {
  long h,w;
  cin >> h >> w;
  vector<string> a(h);
  vector<bool> x(h),y(w);
  for(long i=0;i<h;i++) cin >> a[i];
  for(long i=0;i<h;i++) {
    for(long j=0;j<w;j++) {
      if(a[i][j]=='#') x[i]=true,y[j]=true;
    }
  }
  for(long i=0;i<h;i++) {
    if(x[i]) {
      for(long j=0;j<w;j++) {
        if(y[j]) cout << a[i][j];
      }
      cout << endl;
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    ll a,b,c,x,y,ans=0,n,m,p,q;
    cin>>a>>b>>c>>x>>y;
    ll d=a+b;
    ll e=min(x,y);
    x-=e;
    y-=e;
    n=d*e;
    m=c*e*2;
    if(n<m)
        ans+=n;
    else
        ans+=m;
    if(x){
        if(a*x<c*2*x)
            ans+=a*x;
        else
            ans+=(c*2*x);
    }
    if(y){
        if(y*b<c*2*y)
            ans+=y*b;
        else
            ans+=(c*2*y);
    }
    cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 3640
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Map;
import java.util.TreeMap;
import java.lang.StringBuilder;

class Pair
{
  public Long x;
  public Long y;
  public Pair(){x = 0L; y = 0L;}
  public Pair(Long x, Long y)
  {
    this.x = x;
    this.y = y;
  }
}

public class Main
{
  private static final long mod = 1000000007;
  // public static long gcd(long a, long b)
  // {
  //   if(b == 0) return a;
  //   return gcd(b, a % b);
  // }
  public static Pair extended_gcd(long a, long b)
  {
    if (b == 0) {
        return new Pair(1L, 0L);
    }
    Pair p = extended_gcd(b, a % b);
    long x = p.y;
    long y = p.x - (a / b) * p.y;
    return new Pair(x, y);
  }
  public static long power(long b, long p)
  {
    if(p == 0) return 1L;
    long ret = power(b, p / 2);
    ret = (ret * ret) % mod;
    if(p % 2 == 1) ret = (ret * b) % mod;
    return ret;
  }
  public static long modInverse(long a, long mod)
  {
    return (extended_gcd(a, mod).x % mod + mod) % mod;
  }
  public static void main(String[] args) throws FileNotFoundException
  {
      Scanner scanner = new Scanner(System.in);//new File("input.txt"));
      int n = scanner.nextInt();
      long[] a = new long[n];
      for(int i = 0 ; i < n ; i++)
        a[i] = scanner.nextInt();
      TreeMap<Integer, Integer> map = new TreeMap<>();
      for(int i = 0 ; i < n ; i++)
      {
        int temp = (int)a[i];
        for(int j = 2 ; j * j <= temp ; j++)
        {
          int cnt = 0;
          while(temp % j == 0)
          {
            temp /= j;
            ++cnt;
          }
          if(map.containsKey(j))
            map.put(j, Math.max(cnt, map.get(j)));
          else
            map.put(j, cnt);
        }
        if(temp != 1)
        {
          if(map.containsKey(temp))
            map.put(temp, Math.max(1, map.get(temp)));
          else
            map.put(temp, 1);
        }
      }
      long lcm = 1;
      for(Map.Entry<Integer, Integer> e : map.entrySet())
      {
        // System.out.println(e.getKey() + " " + e.getValue());
        lcm = (lcm * power(e.getKey(), e.getValue())) % mod;
      }
      long sum = 0;
      for(int i = 0 ; i < n ; i++)
      {
          sum = (sum + (lcm * modInverse(a[i], mod)) % mod) % mod;
      }
      System.out.println(sum);
  }
}


Measured memory_bytes: 148800
n = int(input())
a = list(map(int, input().split()))
q = int(input())
bc = list(map(int, input().split()) for _ in range(q))

s = sum(a)

num = [0]*(10**5 + 1)
for x in a:
    num[x] += 1

for b, c in bc:
    s += (c - b)*num[b]
    num[c] += num[b]
    num[b] = 0

    print(s)

Measured memory_bytes: 57440
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pf push_front
#define mod 1000000007
#define endl '\n'
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

int main()
{
   ll n,i;
   cin>>n;
   ll arr[n+1];
   for(i=1;i<=n;i++)
   {
       cin>>arr[i];
   }
   ll ans=0;
   for(i=1;i<n;i++)
   {
       if(arr[i]==i)
       {
           if(arr[i+1]==i+1)
           {
               swap(arr[i],arr[i+1]);
               ans++;
               i++;
           }

           else
           {

             ans++;

           }
       }
   }
   if(arr[n]==n)
   {
       ans++;
   }
   cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
const int N = 1000000;

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

    int sum = 0;
    for (int i = 0; i < n.length(); ++i) {
        sum += stoi(n.substr(i,1));
    }
    if(stoi(n) % sum == 0)print("Yes");
    else print("No");
}


Measured memory_bytes: 256
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using lint = long long;
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 (b<a) { a=b; return 1; } return 0; }

const long long INF = 1LL << 60;

long long dp[100010];

int N;
long long h[100010];

int main()
{
    cin >> N;
    rep(i,N){
        cin >> h[i];
    }

    rep(i,100010) dp[i] = INF;

    dp[0] = 0;

    reps(i,N){
        chmin(dp[i], dp[i-1] + abs(h[i] - h[i-1]));
        if(i>1) chmin(dp[i], dp[i-2] + abs(h[i] - h[i-2]));
    }

    cout << dp[N-1] << endl;
    return 0;
}

Measured memory_bytes: 1792
N, M, X, Y = map(int, input().split())
xlist = list(map(int, input().split()))
ylist = list(map(int, input().split()))

if X < max(xlist):
    xmax = max(xlist)
else:
    xmax = X

if Y > min(ylist):
    ymin = min(ylist)
else:
    ymin = Y

if xmax + 1 <= ymin:
    print("No War")
else:
    print("War")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

class Segment_Tree{
	private:
	int n;
	vi date;
	public:
	void Init(int n_){
		n=1;
		while(n<n_) n*=2;
		date=vi(2*n-1);
	}
	void Update(int k,int x){
		k+=n-1;
		date[k]+=x;
		while(k>0){
			k=(k-1)/2;
			date[k]=date[k*2+1]+date[k*2+2];
		}
	}
	int Query(int a,int b){
		a+=n-1;b+=n-1;
		int m=0;
		while(a<b){
			if(a%2==0) m+=date[a++];
			if(b%2==0) m+=date[--b];
			a/=2;b/=2;
		}
		return m;
	}
	int Open(int k){return date[k+n-1];}
};

const int M=26;
int n,q;
string s;

int main(){
	cin>>n>>s>>q;
	Segment_Tree st[M];
	for(int i=0;i<M;i++) st[i].Init(n);
	for(int i=0;i<n;i++) st[s[i]-'a'].Update(i,1);
	for(int i=0;i<q;i++){
		int t;
		cin>>t;
		if(t==1){
			int x;
			char c;
			cin>>x>>c;
			x--;
			st[s[x]-'a'].Update(x,-1);
			s[x]=c;
			st[s[x]-'a'].Update(x,1);
		}
		else{
			int l,r;
			cin>>l>>r;
			l--;
			int res=0;
			for(int j=0;j<26;j++) if(st[j].Query(l,r)) res++;
			cout<<res<<endl;
		}
	}
}

Measured memory_bytes: 107524
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
int pos[maxn];
int n,x;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&x);
        pos[x]=i;
    }
    for(int i=1;i<=n;i++)
        printf("%d ",pos[i]);
    return 0;
}


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

int main() {
	int n,m,k;
	bool ans = false;
	cin >> n >> m >> k;
	for (int i = 0;i <= n;++i) for (int j = 0;j <= m;++j) if (i*m+j*n-2*i*j == k) ans = true;
	cout << ((ans) ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <functional>
#include <iomanip>
#include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX
#include <assert.h>

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define ll long long
//#define int ll
#define INF INT_MAX/10
#define MOD 1000000007

using namespace std;
using Pi = pair<int, int>;
using Graph = vector<vector<int> >;
using WeightGraph = vector<vector<Pi> >;

int Input[100100];

int main() {
  int a, b, c; cin >> a >> b >> c;
  if (a * c <= b ) {
    cout << c << endl;
  } else {
    cout << b / a << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=2001000;
int Max(int x,int y){
	return x>y?x:y;
}
int a[maxn],b[maxn];
int n,m,k;
char str[maxn];
set<int> sak;
int main(){
//	freopen("F.in","r",stdin);
//	freopen("F.out","w",stdout);
	scanf("%d%d%d",&n,&m,&k);
	scanf("%s",str+1);
	reverse(str+1,str+n+1);
	for(int i=1;i<=n;i++)
		a[i]=str[i]-'0';
	scanf("%s",str+1);
	reverse(str+1,str+m+1);
	for(int i=1;i<=m;i++)
		b[i]=str[i]-'0';
	for(int i=Max(n,m);i>=1;i--)
		if(b[i]!=a[i])
			sak.insert(i);
	int cnt,op,ps,p;
	set<int>::iterator it;
	for(int i=Max(n,m);i>=1;i--){
		if(a[i]==0||b[i]==0) continue;
		cnt=k;
		ps=i;
		while(cnt){
			a[ps]=0,b[ps]=0;
			it=sak.lower_bound(ps);
			if(it==sak.end()||(*it)-ps>cnt){
				a[ps+cnt]=1;
				b[ps+cnt]=1;
				break;
			}
			cnt-=(*it)-ps;
			if(a[*it]) op=0;
			else op=1;
			a[*it]^=1,b[*it]^=1;
			p=*it+1;
			if(op==0){
				while(a[p]){
					a[p]^=1;
					if(b[p]) fprintf(stderr,"fuck\n");
					sak.erase(p);
					p++;
				}
				a[p]^=1;
				if(b[p]){
					sak.erase(p);
					ps=p;
				}
				else{
					sak.insert(p);
					break;
				}
			}
			else{
				while(b[p]){
					b[p]^=1;
					if(a[p]) fprintf(stderr,"fuck\n");
					sak.erase(p);
					p++;
				}
				b[p]^=1;
				if(a[p]){
					sak.erase(p);
					ps=p;
				}
				else
				{
					sak.insert(p);
					break;
				}
			}
		}
	}
	int pos=n+k,fir=0;
	for(int i=pos;i>=1;i--){
		if(a[i]==0){
			if(fir)
				printf("0");
		}
		else{
			fir=1;
			printf("1");
		}
	}
	printf("\n");
	pos=m+k,fir=0;
	for(int i=pos;i>=1;i--){
		if(b[i]==0){
			if(fir)
				printf("0");
		}
		else{
			fir=1;
			printf("1");
		}
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 55168
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
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;

int N;
long long h[100010];

// DP テーブル
long long dp[100010];

int main() {
  cin >> N;
  for(int i=0;i<N;++i) {
    cin >> h[i];
    dp[i]=INF;
  }
  dp[0]=0;
  for (int i = 1; i < N; ++i) {
        chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
        if (i > 1) chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
    }

    cout << dp[N-1] << endl;
}

Measured memory_bytes: 1792
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <cstdio>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

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

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

int main() {
	int Q;
	scanf("%d", &Q);
	LL bs = 0;
	LL asl = 0, asr = 0;
	priority_queue<LL> ql;
	priority_queue<LL, vector<LL>, greater<LL>> qr;
	REP(q, Q) {
		int sp;
		scanf("%d", &sp);
		if (sp == 1) {
			int a, b;
			scanf("%d%d", &a, &b);
			bs += b;
			if (ql.empty()) {
				ql.push(a);
				asl += a;
			}
			else if (ql.top() > a) {
				ql.push(a);
				asl += a;
			}
			else {
				qr.push(a);
				asr += a;
			}
			while (ql.size() > qr.size()) {
				qr.push(ql.top());
				asr += ql.top();
				asl -= ql.top();
				ql.pop();
			}
			while (qr.size() > ql.size()) {
				ql.push(qr.top());
				asl += qr.top();
				asr -= qr.top();
				qr.pop();
			}
		}
		else {
			LL x = ql.top();
			LL ret = x * ql.size() - asl + asr - x*qr.size() + bs;
			printf("%lld %lld\n", x, ret);
		}
	}
	return 0;
}

Measured memory_bytes: 3828
import java.util.*
import java.math.*
import java.lang.Math.*

val readString: ()->String = {readLine()!!}
val readInt: ()->Int = {readLine()!!.toInt()}
val readLong: ()->Long = {readLine()!!.toLong()}
val readIntArray: ()->IntArray = {readLine()!!.split(' ').map{it.toInt()}.toIntArray()}
val readLongArray: ()->LongArray = {readLine()!!.split(' ').map{it.toLong()}.toLongArray()}
val errPrintln: (String)->Unit = {msg -> System.err.println(msg)}
val MOD = 1e9.toLong()+7
val INF = Int.MAX_VALUE/2
val LINF = Long.MAX_VALUE/2
data class IntPair(val first: Int, val second: Int)
data class To(val idx: Int, val cost: Long)


class Bellman(val eg: Array<ArrayList<To>>, val start: Int) {
    private var dist = LongArray(0)

    var hasCycle = false
    private set

    init {
        val N = eg.size

        dist = LongArray(N){-LINF}
        dist[start] = 0L

        for (i in 0 until N) {
            var updating = false
            for (x in 0 until N)  {
                for (t in eg[x]) {
                    val y = t.idx

                    if (dist[x] + t.cost > dist[y]) {
                        dist[y] = dist[x] + t.cost
                        updating = true
                    }
                }
            }
            if (!updating) break
        }

        hasCycle = calcCycle()
    }


    private fun calcCycle(): Boolean {
        val N = eg.size
        val ndst = dist.clone()
        for (i in 0 until N) {
            //var updating = false
            for (x in 0 until N)  {
                for (t in eg[x]) {
                    val y = t.idx
                    if (ndst[x] + t.cost > ndst[y]) {
                        ndst[y] = ndst[x] + t.cost
                        //updating = true
                    }
                }
            }
            //if (!updating) break
        }

        /*for (i in 0 until N) {
            if (ndst[i] != dist[i]) {
                return true
            }
        }
        return false*/
        return ndst[N-1] != dist[N-1]
    }


    fun distance(i: Int): Long {
        return if(hasCycle) LINF else dist[i]
    }
}


fun solve(eg: Array<ArrayList<To>>): Long {
    val N = eg.size

    val bm = Bellman(eg, 0)

    return bm.distance(N-1)
}


fun main(args: Array<String>) {
    val (N, M) = readIntArray()
    val eg = Array(N){ArrayList<To>()}
    for (i in 0 until M) {
        var (a, b, c) = readLongArray()
        a--;b--;
        eg[a.toInt()].add(To(b.toInt(), c))  // 有向グラフ
    }

    val ans = solve(eg)

    if (ans == LINF) println("inf")
    else println(ans)
}


Measured memory_bytes: 52676
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
#define rep(i,n) for(int i=0; i<n; i++)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてから使う
#define INF 2147483647
#define LLINF 9223372036854775807LL

int main() {
  ll a,b,c,d; cin>>a>>b>>c>>d;
  ll ans1 = a*c;
  ll ans2 = a*d;
  ll ans3 = b*c;
  ll ans4 = b*d;
  ll ans = max(ans1, max(ans2, max(ans3, ans4)));
  cout << ans << endl;
}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1000000007;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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

int main(){
    ll n,q;
    set<ll> s;
    cin >> n;
    rep(i,n){
        ll a;
        cin >> a;
        s.insert(a);
    }
    cin >> q;
    ll ans=0;
    rep(i,q){
        ll b;
        cin >> b;
        if (s.count(b)){
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 7748
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int n = sc.nextInt();
			if (n == 0)
				break;
			int[] x = new int[n];
			int[] y = new int[n];
			x[0] = 0;
			y[0] = 0;
			for (int i = 1; i < n; i++) {
				int p = sc.nextInt();
				int d = sc.nextInt();
				switch (d) {
				case 0:
					x[i] = x[p] - 1;
					y[i] = y[p];
					break;
				case 1:
					x[i] = x[p];
					y[i] = y[p] - 1;
					break;
				case 2:
					x[i] = x[p] + 1;
					y[i] = y[p];
					break;
				case 3:
					x[i] = x[p];
					y[i] = y[p] + 1;
					break;
				}
			}
			int xmax = 0, xmin = 0, ymax = 0, ymin = 0;
			for (int i = 1; i < n; i++) {
				xmax = Math.max(xmax, x[i]);
				xmin = Math.min(xmin, x[i]);
				ymax = Math.max(ymax, y[i]);
				ymin = Math.min(ymin, y[i]);
			}
			int w = xmax - xmin + 1;
			int h = ymax - ymin + 1;
			System.out.println(w + " " + h);
		}
		sc.close();
	}
}

Measured memory_bytes: 34980
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
	char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
	int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
	if(nega==-1) return -ans;
	return ans;
}
signed main()
{
	int a,b;
	cin>>a>>b;
	if((b-a)%2!=0)
	{
		cout<<"IMPOSSIBLE\n";
	}
	else
	{
		cout<<b-(b-a)/2<<endl;
	}
#ifndef ONLINE_JUDGE
//	printf("Time Used : %d\n",clock());
#endif
	return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1611&lang=jp
// references : http://ferin-tech.hatenablog.com/entry/2017/05/17/123005
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
	int n;
	while (cin >> n, n) {
		vector<int> w(n);
		for (int i = 0; i < n;i++)cin >> w[i];
		vector<vector<int>> dp(n + 1, vector<int>(n + 1, 0));

		for (int W = 2; W <= n; W++) {
			for (int l = 0; l < n;l++) {
				int r = l + W - 1;
				if (r >= n) continue;

				/* 
				   l+1         r-1
				   [] [] [] [] [] = W - 2 ( = (r - l - 1) - 2)
				l                  r
				{} [] [] [] [] [] {}      w[r] - w[l] <= 1  ==>   dp[l][r] = W
				*/
				if (dp[l + 1][r - 1] == W - 2 && abs(w[l] - w[r]) <= 1) dp[l][r] = W;


				for (int k = l; k < r;k++) {
					dp[l][r] = max(dp[l][r], dp[l][k] + dp[k + 1][r]);
				}
			}
		}
		cout << dp[0][n - 1] << endl;
	}
	return 0;
}

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

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


Measured memory_bytes: 256
MAX = 2000
MOD = 10 ** 9 + 7

fac = [1, 1]
finv = [1, 1]
inv = [0, 1]
for i in range(2, MAX + 1):
    fac.append(fac[-1] * i % MOD)
    inv.append(-inv[MOD % i] * (MOD // i) % MOD)
    finv.append(finv[-1] * inv[-1] % MOD)
    
def COM(n, k):
    if n < k: return 0
    elif n < 0 or k < 0: return 0
    else:
        return fac[n] * finv[k] * finv[n-k] % MOD

n, k = map(int, input().split())
for i in range(1, k+1):
    print(COM(n-k+1, i) * COM(k-1, i-1) % MOD)


Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue>
#include <list>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <iomanip> // std::std::setprecision(X)
#include <limits>  //std::numeric_limits<int>::max(), min()

int main (void) {

  long long N, M;
  std::cin >> N >> M;

  std::vector<long long> A(N), S(N+1);
  for(long long i=0; i<N; i++ ) std::cin >> A[i];
  S[0] = 0;
  for(long long i=1; i<=N; i++) S[i] = S[i-1] + A[i-1];

  std::unordered_map<long long,long long> B;
  for(long long i=0; i<=N; i++) {
    if ( B.count(S[i]%M) == 0 ) B[S[i]%M] = 1;
    else B[S[i]%M]++;
  }

  long long ans = 0;
  for(auto itr = B.begin(); itr != B.end(); ++itr) {
    ans += ( itr->second * ( itr->second - 1 ) / 2 );
  }
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 5260
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    int n;
    scan(n);
    auto a = readln.split.to!(long[]);
    auto adj = new int[][](n, 0);
    foreach (i ; 0 .. n - 1) {
        int u, v;
        scan(u, v);
        u--, v--;
        adj[u] ~= v;
        adj[v] ~= u;
    }

    auto dp = new long[][][](2, n, 0);
    auto size = new int[](n);

    void dfs(int v, int p) {
        size[v] = 1;
        dp[0][v] = new long[](2);
        dp[0][v][] = inf6;
        dp[0][v][1] = a[v];
        dp[1][v] = new long[](2);
        dp[1][v][] = inf6;
        if (a[v] > 0) dp[1][v][1] = a[v];

        foreach (u ; adj[v]) {
            if (u == p) continue;
            dfs(u, v);

            auto next0 = new long[](size[v] + size[u] + 1);
            next0[] = inf6;
            //next0[0 .. dp[0][v].length] = dp[0][v][];

            auto next1 = new long[](size[v] + size[u] + 1);
            next1[] = inf6;
            //next1[0 .. dp[1][v].length] = dp[1][v][];

            foreach (i ; 1 .. size[v] + 1) {
                foreach (j ; 1 .. size[u] + 1) {
                    next0[i + j - 1] = min(next0[i + j - 1], dp[0][v][i] + dp[0][u][j]);
                    if (dp[0][u][j] < 0 || dp[1][u][j] < inf6) next0[i + j] = min(next0[i + j], dp[0][v][i]);

                    next1[i + j - 1] = min(next1[i + j - 1], dp[1][v][i] + dp[1][u][j]);
                    if (dp[0][u][j] < 0 || dp[1][u][j] < inf6) next1[i + j] = min(next1[i + j], dp[1][v][i]);
                }
            }

            dp[0][v] = next0;
            //dp[0][v][0] = 0;
            dp[1][v] = next1;
            //dp[1][v][0] = 0;
            size[v] += size[u];
        }

    }

    dfs(0, -1);

    debug {
        foreach (i ; 0 .. n) {
            writefln("%d:", i);
            writeln(dp[0][i]);
            writeln(dp[1][i]);
        }
    }

    int ans = -1;

    foreach (i ; 1 .. n + 1) {
        if (dp[0][0][i] < 0 || dp[1][0][i] < inf6) {
            ans = i - 1;
            break;
        }
    }

    writeln(ans);
}






void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 186108
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF (long long)1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main(void) {
	ll N, A, B;
	cin>>N>>A>>B;
	if(A > B) cout<<0<<endl;
	else if(N == 1 && A != B) cout<<0<<endl;
	else cout<<(B * (N - 1) + A) - (A * (N - 1) + B) + 1<<endl;
}


Measured memory_bytes: 256
#ifdef __APPLE__
#include "bits:stdc++.h"
#else
#include <bits/stdc++.h>
#endif

using namespace std;
typedef long long LL;
typedef pair<LL, LL> PLL;
string s;

LL D[1000000],T[1000000];
int main() {
  LL n; scanf("%lld",&n);
  for (LL i = 0; i < n; ++i) scanf("%lld",D + i);
  LL m; scanf("%lld",&m);
  for (LL i = 0; i < m ;++i) scanf("%lld",T + i);
  sort(D,D+n);
  sort(T,T+m);
  LL j = 0;
  for(LL i = 0; i < n; ++i){
    if(D[i] == T[j]) ++j;
  }
  puts(j==m?"YES":"NO");
}



Measured memory_bytes: 5888