akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n,m,X,Y;
  cin >> n >> m >> X >> Y;
  
  int maxx = -1e9;
  int miny = 1e9;
  
  vector<int> x(n);
  for (int i=0; i<n; i++){
    cin >> x.at(i);
    if (maxx < x.at(i)) maxx = x.at(i);
  }
  
  vector<int> y(m);
  for (int i=0; i<m; i++){
    cin >> y.at(i);
    if (miny>y.at(i)) miny = y.at(i);
  }
  
  maxx = max(maxx, X);
  miny = min(miny, Y);
  
  if (miny - maxx > 0) cout << "No War" << endl;
  else cout << "War" << endl;
  
}



Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
import copy
import math
from itertools import accumulate
sys.setrecursionlimit(10**6)

# lis_of_lis = [[] for _ in range(N)]


def floor(a, b): return -(-a // b)


def zz(): return list(map(int, sys.stdin.readline().split()))


def z(): return int(sys.stdin.readline())


def S(): return sys.stdin.readline()[:-1]


def C(line): return [sys.stdin.readline() for _ in range(line)]


a, b, c, d = zz()
# 正負の場合
a1 = a * c
a2 = a * d
a3 = b * c
a4 = b * d
if (a <= 0 <= b):
    a5 = 0
else:
    a5 = a4
if (c <= 0 <= d):
    a6 = 0
else:
    a6 = a4
print(max(a1, a2, a3, a4, a5, a6))


Measured memory_bytes: 67928
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define reg(i,a,b) for(int i=((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int,int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))


int n,m,cn,s,g;

lli dat[25][105][105];

lli ds[105][105];


int ps[55];
lli qs[25][55];
lli rs[25][55];


lli calc(int c,lli d){
	lli res = 0;
	rep(i,ps[c]){
		res += rs[c][i] * (min(d,qs[c][i+1])-qs[c][i]);
		//printf("%lld %lld %lld\n",rs[c][i],qs[c][i],res);
		if(d<qs[c][i+1])break;
	}
	
	//printf("calc %d %lld %lld\n",c,d,res);
	return res;
}

int main(void){
	for(;;){
		scanf("%d%d%d%d%d",&n,&m,&cn,&s,&g); s--; g--;
		if(n==0)break;
		//fill(dat,dat+25*105*105,IINF);
		rep(i,25)rep(j,105)rep(k,105)dat[i][j][k]=IINF;
		
		rep(i,m){
			int x,y,d,c;
			scanf("%d%d%d%d",&x,&y,&d,&c); x--; y--; c--;
			if(dat[c][x][y]>d){
				dat[c][x][y]=d;
				dat[c][y][x]=d;
			}
		}
		
		rep(i,cn)scanf("%d",&ps[i]);
		rep(i,cn){
			qs[i][0]=0;
			reg(j,1,ps[i]-1)scanf("%lld",&qs[i][j]);
			qs[i][ps[i]]=IINF*10LL;
			rep(j,ps[i])scanf("%lld",&rs[i][j]);
		}
		
		
		//fill(ds,ds+105*105,IINF*100LL);
		rep(j,105)rep(k,105)ds[j][k]=IINF*100LL;

		rep(c,cn){
			rep(i,n)dat[c][i][i]=0;
			rep(k,n)rep(i,n)rep(j,n){
				dat[c][i][j]=min(dat[c][i][j],dat[c][i][k]+dat[c][k][j]);
			}
			
			/*
			printf("dat %d\n",c);
			rep(i,n){
				rep(j,n){
					printf("%lld ",dat[c][i][j]);
				}
				printf("\n");
			}
			*/
			rep(i,n){
				rep(j,n){
					if(dat[c][i][j]==IINF)continue;
					ds[i][j]=min(ds[i][j],calc(c,dat[c][i][j]));
				}
			}
		}
		
		rep(i,n)ds[i][i]=0;
		rep(k,n)rep(i,n)rep(j,n){
			ds[i][j]=min(ds[i][j],ds[i][k]+ds[k][j]);
		}
		
		if(ds[s][g]>=IINF)printf("-1\n");
		else printf("%lld\n",ds[s][g]);
	}
	
	return 0;
}

Measured memory_bytes: 3456
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;

ll h,w,d;
ll dist[90010];

int main(void){
    ll a,q;
    cin>>h>>w>>d;
    vector<P>p(h*w+1);
    for(ll i=0;i<h;i++){
        for(ll j=0;j<w;j++){
            cin>>a;
            p[a].first=i;
            p[a].second=j;
        }
    }
    for(ll i=1;i<=d;i++){
        dist[i]=0;
        for(ll j=i+d;j<=h*w;j+=d){
            dist[j]=(ll)dist[j-d]+abs(p[j].first-p[j-d].first)+abs(p[j].second-p[j-d].second);
        }
    }
    cin>>q;
    ll l,r;
    for(ll i=0;i<q;i++){
        cin>>l>>r;
        cout<<dist[r]-dist[l]<<endl;
    }
    return 0;
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using Tup = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define prt(v) cout<<(v)<<"\n";
#define fl cout<<flush;
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
#define endl "\n"
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld pi=3.141592653589793238;

vector<vector<vector<ld>>> dp(301,vector<vector<ld>>(301,vector<ld>(301,-3)));
ld F(ll a, ll b, ll c,ld N){
    if(dp[a][b][c]>=0)return dp[a][b][c];
    if(a==0&&b==0&&c==0)return 0.0;
    ld ret=(N-a-b-c)/N;
    if(a>0)ret+=(((ld)a)/N)*(1.0+F(a-1,b+1,c,N));
    if(b>0)ret+=(((ld)b)/N)*(1.0+F(a,b-1,c+1,N));
    if(c>0)ret+=(((ld)c)/N)*(1.0+F(a,b,c-1,N));
    ret*=N/((ld)(a+b+c));
    return dp[a][b][c]=ret;
}


signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> a(N,0);
    for(ll i=0;i<N;++i)cin>>a[i];
    ll cou1=0,cou2=0,cou3=0;
    for(ll i=0;i<N;++i){
        if(a[i]==1)cou1++;
        if(a[i]==2)cou2++;
        if(a[i]==3)cou3++;
    }
    cout << fixed << setprecision(15);
    prt(F(cou3,cou2,cou1,(ld)N))


    return 0;
}


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 m1,d1,m2,d2;
    cin >> m1 >> d1 >> m2 >> d2;
    if(d2 == 1){
        cout << 1 << endl;
    }else{
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
main(){
while(true){
int x[15000],n,i,j,k,l,m,y[15000],b,c,d,p[15000],minx;
scanf("%d", &n);
if(n==0){break;}
for(i=0;i<n;i++){scanf("%d", &y[i]);p[i] = x[i] = y[i];}
c=0;d=0;m=n;d=m;
minx=99999;
for(i=0;i<n;i++){
for(j=1;j<=3;j++){
if(i>=1 && (y[i-1]!=j && y[i+1]!=j)){goto z;}
p[i] = x[i] = j;
b=1;d=n;
while(true){c=0;
for(k=0;k<m;k++){
if(p[k]==p[k+1]){b++;}
else{
if(b >= 4){
for(l = k + 1; l < m; l++){p[l-b] = p[l];}
d -= b;c++;
for(l=d;l<m;l++){p[l]=0;}
}
b=1;}   
m=d;}
if(c==0){break;}
else{c=0;}
}
minx=std::min(minx,m);x[i]=y[i];
for(int k=0;k<n;k++){p[k]=y[k];}
z:;
}
}
printf("%d\n", minx);}
}

Measured memory_bytes: 2672
#pragma comment(linker, "/STACK:64777216")
#define _CRT_SECURE_NO_WARNINGS
#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <stdio.h>
#include <cctype>
#include <algorithm>
#include <utility>
#include <cassert>
#include <complex>
#include <time.h>
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b) - 1; i >= (a); i--)
#define ITER(it, a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define MP make_pair
#define PB push_back

typedef long long Int;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;

const int MAX = 1000007;
const int CNT = 17;

int n;
VI G[MAX];
int R[MAX];

void dfs(int v, int p)
{
	FOR (i,0,SZ(G[v]))
	{
		int to = G[v][i];
		if (to == p) continue;
		dfs(to, v);
		R[v] ^= R[to];
	}
	++ R[v];
}

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

	cin >> n;
	FOR (i,0,n-1)
	{
		int u, v;
		scanf("%d %d", &u, &v);
		-- u;
		-- v;
		G[u].PB(v);
		G[v].PB(u);
	}

	dfs(0, -1);

	-- R[0];

	cout << (R[0] == 0 ? "Bob" : "Alice") << endl;





	return 0;
}


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

using namespace std;


#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)


using Pi = pair<int, int>;
using Tapris = tuple<int, int, int>;
using vint = vector<int>;


signed main() {
    long long a, b;

    cin >> a >> b;

    bitset<32> bita(a), bitb(b);

    cout << (bita & bitb) << endl;
    cout << (bita | bitb) << endl;
    cout << (bita ^ bitb) << endl;

    return 0;
}


Measured memory_bytes: 3140
def read():
    S = input().strip()
    return S, 


def solve(S):
    count = [0] * 26
    S = sorted(S)
    if S[0] == S[1] and S[1] != S[2] and S[2] == S[3]:
        return 'Yes'
    else:
        return 'No'


if __name__ == '__main__':
    inputs = read()
    print(solve(*inputs))


Measured memory_bytes: 2940
//#pragma warning disable

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net.Sockets;
using System.Text;

public class Test
{
    public static void Main()
    {
        var line1 = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        var N = line1[0];
        var W = line1[1];
        var w = new long[N];  // weight
        var v = new long[N];  // value

        for (int i = 0; i < N; i++)
        {
            var line2 = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
            w[i] = line2[0];
            v[i] = line2[1];
        }

        var w1 = w[0];  // base weight

        // これナップザック問題ではないな？？
        // 総当りすれば 100^4 オーダーで解けそう

        var valuesByWeight = new List<long>[4] {
            new List<long>(),
            new List<long>(),
            new List<long>(),
            new List<long>(),
        };

        for (int i = 0; i < N; i++)
        {
            valuesByWeight[w[i] - w1].Add(v[i]);
        }

        for (int j = 0; j < 4; j++)
        {
            valuesByWeight[j].Add(long.MinValue / 3);  // ちょっとしたトリック
            valuesByWeight[j] = valuesByWeight[j].OrderByDescending(x => x).ToList();
        }

        long maxValue = long.MinValue / 3;

        long sum0 = 0;
        for (int i0 = 0; i0 < valuesByWeight[0].Count; i0++)
        {

            long sum1 = 0;
            for (int i1 = 0; i1 < valuesByWeight[1].Count; i1++)
            {

                long sum2 = 0;
                for (int i2 = 0; i2 < valuesByWeight[2].Count; i2++)
                {

                    long sum3 = 0;
                    for (int i3 = 0; i3 < valuesByWeight[3].Count; i3++)
                    {
                        long totalWeight = i0 * w1 + i1 * (w1 + 1) + i2 * (w1 + 2) + i3 * (w1 + 3);

                        if (totalWeight <= W)
                        {
                            maxValue = Math.Max(maxValue, sum0 + sum1 + sum2 + sum3);
                        }

                        sum3 += valuesByWeight[3][i3];

                    }

                    sum2 += valuesByWeight[2][i2];
                }

                sum1 += valuesByWeight[1][i1];
            }

            sum0 += valuesByWeight[0][i0];
        }

        Console.WriteLine(maxValue);
    }
}

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

#define ll long long
#define ld long double
#define pb push_back
#define mod 1000000007
#define mk make_pair
#define sz size

const ll MAXN = 13;
const ll MASMASK = (1<<12) + 1;
const ll MAXM = 1e3 + 10;
ll a[MAXM];
ll cost[MAXM];
ll n,m;
const ll INF = 1e15;
ll dp[MAXM][MASMASK];


ll rec(ll idx,ll mask){
    if(idx == m+1){
        if(mask == ((1<<n)-1)) return 0;
        else return INF;
    }
 
    ll &ans = dp[idx][mask];
 
    if(ans != -1) return ans;
 
    ans = INF;
 
    ans = min(ans,rec(idx+1,mask));
    ans = min(ans,rec(idx+1,(mask|a[idx]))+cost[idx]);
 
    return ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    ll i,j;
    
    memset(dp,-1,sizeof(dp));
    cin>>n>>m;

    for(i=1;i<=m;i++){
        ll aa,b;
        cin>>aa>>b;
        cost[i]=aa;
        for(j=0;j<b;j++){
            ll x;
            cin>>x;
            a[i]|=(1<<(x-1));
        }
    }
    
    ll ans=rec(1,0);
    if(ans>=INF)cout<<"-1\n";
    else
        cout<<ans<<"\n";

    return 0;  
}

Measured memory_bytes: 32640
def pfactor(n):
    result = []
    for i in range(2, int(n**0.5)+1):
        while n%i == 0:
            result.append(i)
            n //= i
    
    if n != 1:
        result.append(n)
    return result

  
N = int(input())
factor = pfactor(N)
ans = 0

for p in set(factor):
    i = factor.count(p)
    while i > 0:
        c = (1 + 8*i) ** 0.5
        if c.is_integer():
            ans += (int(c)-1) // 2
            break
        i -= 1

print(ans)

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

using namespace std;

using ll = long long;

using vec = vector<ll>;
using mat = vector<vec>;

mat mul(mat& A, mat& B, ll mod) {
	mat C(A.size(), vec(B[0].size(), 0));
	for (int i = 0; i < A.size(); i++) {
		for (int k = 0; k < B.size(); k++) {
			for (int j = 0; j < B[0].size(); j++) {
				(C[i][j] += A[i][k] * B[k][j] % mod) %= mod; 
			}
		}
	}
	return C;
}

mat pow(mat A, ll n, ll mod) {
	mat B(A.size(), vec(A.size(), 0));
	for (int i = 0; i < A.size(); i++) {
		B[i][i] = 1;
	}
	while (n > 0) {
		if (n & 1) B = mul(B, A, mod);
		A = mul(A, A, mod);
		n >>= 1;
	}
	return B;
}

const ll MOD = 1000000007;

ll modpow(ll x, ll n, ll mod = MOD) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

map<ll, int> prime_factor(ll n) {
    map<ll, int> res;
    for (ll i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            ++res[i];
            n /= i;
        }
    }
    if (n != 1) res[n] = 1;
    return res;
}

ll euler(ll n) {
    map<ll, int> pv = prime_factor(n);
    ll res = 1;
    for (auto& p : pv) {
        ll hoge = 1;
        for (int i = 0; i < p.second - 1; i++) {
            hoge *= p.first;
        }
        res *= (hoge * p.first - hoge);
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, a, b, m;
    cin >> n >> a >> b >> m;

    ll lim_max = 1000000000000000000LL, lim_min = lim_max / 10;
    ll ans = 0;
    ll foobar = 1;

    for (int i = 18; i >= 1; i--) {
        if (foobar == 0) break;
        ll ok1 = n - 1, ng1 = -1;
        while (ok1 - ng1 > 1) {
            ll mid = (ok1 + ng1) / 2;
            ll val = a + mid * b;
            if (lim_min <= val) ok1 = mid;
            else ng1 = mid;
        }

        ll ok2 = 0, ng2 = n;
        while (ng2 - ok2 > 1) {
            ll mid = (ok2 + ng2) / 2;
            ll val = a + mid * b;
            if (val < lim_max) ok2 = mid;
            else ng2 = mid;
        }

        if (ok2 < ok1) {
            lim_min /= 10;
            lim_max /= 10;
            continue;
        }

        ll v1 = a + ok1 * b;
        ll v2 = a + ok2 * b;
        if (v1 < lim_min || v1 >= lim_max || v2 < lim_min || v2 >= lim_max) {
            lim_max /= 10;
            lim_min /= 10;
            continue;
        }

        // ok1 <= ok2
        ll first_val = v1;
        ll p = ok2 - ok1 + 1;
        mat A = {{1, 0, 0}, {1, 1, 0}, {0, 1, lim_max % m}};
        A = pow(A, p, m);
        mat B = {{b % m}, {first_val % m}, {0}};
        (ans += mul(A, B, m)[2][0] * foobar % m) %= m; 

        (foobar *= modpow(lim_max % m, p, m)) %= m;
        lim_min /= 10;
        lim_max /= 10;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		double num1 = scanner.nextDouble();
		System.out.println(String.format("%.6f %.6f", Math.pow(num1, 2)
				* Math.PI, num1 * 2 * Math.PI));
	}
}

Measured memory_bytes: 18916
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    
    String in = s.next();
    for (char c : in.toCharArray()) {
      switch (c) {
        case 'A':
          System.out.print("T");
          break;
        case 'T':
          System.out.print("A");
          break;
        case 'C':
          System.out.print("G");
          break;
        case 'G':
          System.out.print("C");
          break;
      }
    }
    System.out.println();
  }
}


Measured memory_bytes: 22228
#include <iostream>
#include <cstdio>
#include <cstring>
#include <climits>
#include <functional>

#define N 100000

using namespace std;

// int pq[2*N+1] = {};
// int q_max = 0;

int parent(int i){return((i-1)/2);}
int lchild(int i){return(2*i+1);}
int rchild(int i){return(2*i+2);}

void display_queue(int *pq, int *q_max){
  int j = 0;
  int b = 0;
  for (int i=0;i < *q_max;i++) {
    cout << pq[i] << " ";
    if (j==0 || j==(1<<b)) {
      cout << endl;
      b++;
      j=0;
    }
    j++;
  }
  cout << endl;
}

bool gt(long long x, long long y){
  return(x > y);
}

bool lt(long long x, long long y){
  return(x < y);
}

void push(long long x, long long *pq, long long *q_max, function<bool(long long, long long)> f){
  pq[*q_max] = x;
  int idx = *q_max;
  (*q_max)++;
  while (idx > 0) {
    if (f(pq[idx], pq[parent(idx)])) {
      int tmp = pq[parent(idx)];
      pq[parent(idx)] = pq[idx];
      pq[idx] = tmp;
      idx = parent(idx);
    } else {
      return;
    }
  }
}

long long pop(long long *pq, long long *q_max, function<bool(long long, long long)> f){
  if (*q_max < 0) {
    cerr << "queue is empty." << endl;
    return 0;
  }
  int result = pq[0];
  pq[0] = pq[--(*q_max)];
  int idx = 0;
  while (lchild(idx) < *q_max) {
    if (f(pq[idx], pq[lchild(idx)]) && f(pq[idx], pq[rchild(idx)])) {
      return(result);
    }
    if (f(pq[lchild(idx)], pq[rchild(idx)])) {
      int tmp = pq[lchild(idx)];
      pq[lchild(idx)] = pq[idx];
      pq[idx] = tmp;
      idx = lchild(idx);
    } else {
      int tmp = pq[rchild(idx)];
      pq[rchild(idx)] = pq[idx];
      pq[idx] = tmp;
      idx = rchild(idx);
    } 
  }
  return(result);
}


int main(){
  long long n;
  long long a1_pq[N+1], a2[N+1], a3_pq[N+1];
  long long a1_pq_max = 0;
  long long a3_pq_max = 0;
  long long a1_max[N+1], a3_min[N+1];
  cin >> n;
  a1_max[0] = 0;
  a3_min[n] = 0;
  for (int i=0;i<n;i++) {
    long long a;
    cin >> a;
    push(a, a1_pq, &a1_pq_max, lt);
    a1_max[0] += a;
  }
  for (int i=0;i<n;i++) {
    long long a;
    cin >> a;
    a2[i] = a;
  }
  for (int i=0;i<n;i++) {
    long long a;
    cin >> a;
    push(a, a3_pq, &a3_pq_max, gt);
    a3_min[n] += a;
  }
  for (int i=0;i<n;i++) {
    if (a1_pq[0] < a2[i]) {
      a1_max[i+1] += a2[i] - a1_pq[0] + a1_max[i];
      pop(a1_pq, &a1_pq_max, lt);
      push(a2[i], a1_pq, &a1_pq_max, lt);
    } else {
      a1_max[i+1] = a1_max[i];
    }
  }
  for (int i=n;i>0;i--) {
    if (a3_pq[0] > a2[i-1]) {
      a3_min[i-1] += a2[i-1] - a3_pq[0] + a3_min[i];
      pop(a3_pq, &a3_pq_max, gt);
      push(a2[i-1], a3_pq, &a3_pq_max, gt);
    } else {
      a3_min[i-1] = a3_min[i];
    }
  }
  long long result = LLONG_MIN;
  for (int i=0;i<=n;i++) {
    if (a1_max[i] - a3_min[i] > result) {
      result = a1_max[i] - a3_min[i];
    }
  }
  cout << result << endl;  
}


Measured memory_bytes: 4224
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<cmath>
#include<cstdint>
//#include<>
using namespace std;

typedef int64_t i64;typedef int32_t i32;
typedef int16_t i16;typedef int8_t i8;
typedef uint64_t ui64;typedef uint32_t ui32;
typedef uint16_t ui16;typedef uint8_t ui8;

typedef i32 int__;
#define rep(i,j) for(int__ i=0;i<j;i++)
#define repeat(i,j,k) for(int__ i=(j);i<(k);i++)
#define repeat_eq(i,j,k) for(int__ i=(j);i<=(k);i++)
#define all(v) begin(v),end(v)

const i32 INF=1<<30;//=10E10

int main()
{
  stack<int> stk;
  char str[10];
  while(scanf("%s",str)!=EOF){
    if(isdigit(str[0]))stk.push(atoi(str));
    else{
      int a,b;
      b=stk.top();stk.pop();
      a=stk.top();stk.pop();
      switch(str[0]){
      case '+':
      stk.push(a+b);
      break;
      case '-':
      stk.push(a-b);
      break;
      case '*':
	stk.push(a*b);
	break;
      default:
	puts("swtch");
      }
    }
  }
  cout<<stk.top()<<endl;
  return 0;
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
int i, j, k;
#define rep(i, s, e) for(i=s;i<e;i++)

using namespace std;


int main(){
        int n, d;
        double diff;
        cin >> n >> d;

        int arr[n][d];
        rep(i, 0, n){
                rep(j, 0, d) cin >> arr[i][j];
        }

        int ans = 0;
        rep(i, 0, n-1){
                rep(j, i+1, n){
                        diff = 0;
                        rep(k, 0, d) diff += (arr[i][k]-arr[j][k])*(arr[i][k]-arr[j][k]);
                        if (ceil(sqrt(diff)) == floor(sqrt(diff))) ans++;
                }
        }
        cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define ve vector
#define pq priority_queue
#define vi vector<int>
#define vl vector<long long>
#define vii vector<vector<int>>
using namespace std;
using ll = long long;
using ld = long double;
const ll mod = 1000000007;



int main()
{
    int N;
    cin >> N;
    vl A(N);
    rep(i,N) cin >> A[i];
    
    ll ans = 0;
    ll B = 0;
    ll t = 0;
    ll oldt = -1;
    for (ll s = 0; s < (ll)N; s++) {
        while (B+A[t] == (A[t]^B) && t < (ll)N) {
            B += A[t];
            t++;
        }
        ll n = t-s;
        ans += n;
        if(t==s){
            t++;
        }else{
            B-=A[s];
        }
    }
    

    out(ans);


    return 0;
}


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

int main()
{
    long long s, x, y;
    cin>>s;
    x=sqrt(s);
    if(x*x==s) y=x;
    else if(x*(x+1)>=s) y=x+1;
    else y=++x;
    printf("0 0 %lld 1 %lld %lld", x, (x*y)-s, y);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll mod=1000000007;
const int MAX_N = 1000;         // n の最大値
 
// nCk を取得
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
 
int main() {
ll n;
cin>>n;
ll a[n]={};
ll counter=0;
ll bb[100005]={};
for(ll i=0; i<n; i++){
cin>>a[i];
bb[a[i]]++;
counter+=a[i];}
ll q;
cin>>q;
ll b,c;
for(ll i=0; i<q; i++){
cin>>b>>c;
counter=counter+(c-b)*bb[b];
cout<<counter<<endl;
bb[c]+=bb[b];
bb[b]=0;}}

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

int main(){
	ll x, y;
	cin >> x >> y;
	ll ans = 2e9+5;
	ll a = x, b = y;
	if (a<=b) ans = min(ans, b-a);
	a = -x, b = y;
	if (a <= b) ans = min(ans , b-a+1);
	a = x, b = -y;
	if (a <= b) ans = min(ans, b-a+1);
	a = -x, b = -y;
	if (a <= b) ans = min(ans, b-a+2);
	cout << ans << endl;
	return 0;
}

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

/**
 * Created by Harry on 4/7/20.
 */
//矩阵快速幂
//https://atcoder.jp/contests/dp/tasks/dp_r
public class Main {
    private static int mod = 1000000007;
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        long K = scanner.nextLong();
        long[][] m = new long[N][N];
        long[] freq = new long[N];
        long[] nextFreq = new long[N];
        Arrays.fill(freq,1);
        for(int i=0; i<N; i++){
            for(int j=0; j<N; j++){
                m[i][j] = scanner.nextLong();
            }
        }
        transpose(m);

        //entity matrix
        long[][] ansM = new long[N][N];
        for(int i=0; i<N; i++){
            ansM[i][i] = 1;
        }

        while(K>0){
            if((K&1)==1){
                ansM = multi(ansM, m);
            }
            m = multi(m, m);
            K >>= 1;
        }

        for(int r=0; r<N; r++){
            nextFreq[r] = 0;
            for(int c=0; c<N; c++){
                nextFreq[r] = (nextFreq[r] + ansM[r][c]*freq[c])%mod;
            }
        }

        long res = 0;
        for(long f : nextFreq){
            res = (res + f)%mod;
        }
        System.out.print(res);
    }

    public static long[][] multi(long[][] m, long[][] mm){
        int n = m.length;
        int nn = mm[0].length;
        long[][] res = new long[n][nn];
        for(int r=0; r<n; r++){
            for(int c=0; c<nn; c++){
                for(int i=0; i<nn; i++){
                    res[r][c] = (res[r][c]+(m[r][i]*mm[i][c])%mod)%mod;
                }
            }
        }
        return res;
    }

    public static void transpose(long[][] m){
        for(int i=0; i<m.length; i++){
            for(int j=i+1; j<m.length; j++){
                swap(m, i, j, j, i);
            }
        }
    }

    public static void swap(long[][] m, int r1, int c1, int r2, int c2){
        long temp = m[r1][c1];
        m[r1][c1] = m[r2][c2];
        m[r2][c2] = temp;
    }
}


Measured memory_bytes: 29744
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <queue>
#include<iomanip>
#include <cmath>
#include <set>

#define ABS(x) ((x)>0?(x):-(x))
#define MIN(x,y) ((x)>(y)?(y):(x))
#define MAX(x,y) ((x)<(y)?(y):(x))

#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

#define INF 1000000000

using namespace std;
typedef long long ll;

ll newton(long long int a, long long int  b)
{
	if(a==b)
		return a;
	while(a != 0 && b != 0)
	{
		if(a > b)
		{
			b += a;
			a = b-a;
			b -= a;
		}
		b %= a;
	}
	return a;
}

struct UnionFind {
	vector<int> p;
	UnionFind(int N):p(N)
	{
		for(int i=0; i< N; i++)
		{
			p[i] = i;
		}
	}
	int root(int x)
	{
		if(p[x] == x)
			return x;
		return p[x] = root(p[x]);
	}
	void unite(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		if(rx == ry) return;
		p[rx] = ry;
	}
	bool issame(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

//大きな数に対する割り算をするとき、MODを指定することで掛け算の値に変換できる

ll div2mul_calc(ll a, ll b, ll m)
{
	if (b == 0) {
        return 1;
    } else if (b % 2 == 0) {
        ll d = div2mul_calc(a, b / 2, m);
        return (d * d) % m;
    } else {
        return (a * div2mul_calc(a, b - 1, m)) % m;
    }
}
ll div2mul(ll n, ll mod)
{
	return div2mul_calc(n, mod-2, mod);
}

ll twoRow(ll a, ll b, ll mod)
{
	ll ret = 1;
	for(ll i = 1 ;i <= a+b;++i)
	{
		ret *= i;
		ret %= mod;
	}
	for(ll i = 1 ;i <= a;++i)
	{
		ret *= div2mul(i,mod);
		ret %= mod;
	}
	for(ll i = 1 ;i <= b;++i)
	{
		ret *= div2mul(i,mod);
		ret %= mod;
	}
	return ret;
}

struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};

vector< ll > divisor(ll n) {
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(ret.begin(), ret.end());
  return (ret);
}

int main()
{
	string s;
	int t[200010][8] = {0};
	cin >> s;
	int s_len = s.size();
	t[0][1] = 1;
	t[1][2] = 1;
	for(int i=1;i<s_len;++i)
	{
		if(i > 1)
			t[i][1] = t[i-1][2] + 1;
		if(s[i-1]!=s[i])
		{
			t[i][1]=MAX(t[i][1],t[i-1][1]+1);
		}

		if(i > 1)
		{
			t[i][2] = t[i-2][1] + 1;
			if(i > 2)
			{
				if(s[i]!=s[i-2] || s[i-1]!=s[i-3])
				{
					t[i][2]=MAX(t[i][2],t[i-2][2]+1);
				}
			}
		}
		//cout << t[i][1] << " " << t[i][2] << endl;
	}
	cout << MAX(t[s_len-1][1],t[s_len-1][2]) << endl;


	return 0;
}




















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

vector<P>E[100000];
int d[100000],b[100000],cnt[200001],u[200000],v[200000],r[200000];
int main(){
	int n,m,q;scanf("%d%d%d",&n,&m,&q);
	rep(i,m)scanf("%d%d",&u[i],&v[i]),u[i]--,v[i]--,r[i]=q;
	rep(i,q){
		int a;scanf("%d",&a);a--;r[a]=i;
	}
	rep(i,m){
		E[u[i]].push_back(P(v[i],r[i]));E[v[i]].push_back(P(u[i],r[i]));
	}
	memset(d,-1,sizeof(d));d[0]=0;b[0]=q;
	queue<int>que;que.push(0);
	while(!que.empty()){
		int p=que.front();que.pop();
		for(P v:E[p]){
			if(d[v.first]==-1){
				d[v.first]=d[p]+1;b[v.first]=min(b[p],v.second);
				que.push(v.first);
			}
			else if(d[v.first]==d[p]+1&&b[v.first]<min(b[p],v.second)){
				b[v.first]=min(b[p],v.second);
			}
		}
	}
	rep(i,n)cnt[b[i]]++;
	int ans=0;
	rep(i,q){
		ans+=cnt[i];
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 15528
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

using Weight = int;
struct Edge {
	int s, d; Weight w;
	Edge(int s, int d, Weight w = 1) : s(s), d(d), w(w) {};
	bool operator<(const Edge &e)const { return w < e.w; }
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;
using Array = vector<Weight>;
using Matrix = vector<Array>;

//LCA: Lowest Common Ancestor (??????????????° + dfs????????°)
struct LowestCommonAncestor {
	const int n, log2_n;
	vector<vector<int>> parent;
	vector<int> depth;
	LowestCommonAncestor(const Graph &g, int root)
		:n(g.size()), log2_n(log2(n) + 1), parent(log2_n, vector<int>(n)), depth(n) {
		dfs(g, root, -1, 0);
		for (int k = 0; k + 1 < log2_n; k++) {
			for (int v = 0; v < n; v++) {
				if (parent[k][v] < 0)
					parent[k + 1][v] = -1;
				else
					parent[k + 1][v] = parent[k][parent[k][v]];
			}
		}
	}

	void dfs(const Graph &g, int s, int p, int d) {
		parent[0][s] = p;
		depth[s] = d;
		for (auto &e : g[s]) {
			if (e.d == p)continue;
			dfs(g, e.d, s, d + 1);
		}
	}

	int get(int u, int v) {
		if (depth[u] > depth[v]) swap(u, v);
		for (int k = 0; k < log2_n; k++) {
			if ((depth[v] - depth[u]) >> k & 1) {
				v = parent[k][v];
			}
		}
		if (u == v) return u;
		for (int k = log2_n - 1; k >= 0; k--) {
			if (parent[k][u] != parent[k][v]) {
				u = parent[k][u];
				v = parent[k][v];
			}
		}
		return parent[0][u];
	}
};

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	Graph g(n);
	rep(i, 0, n) {
		int k; cin >> k;
		rep(j, 0, k) {
			int c; cin >> c;
			g[i].emplace_back(i, c);
		}
	}
	int q; cin >> q;
	LowestCommonAncestor lca(g, 0);
	rep(i, 0, q) {
		int u, v; cin >> u >> v;
		cout << lca.get(u, v) << endl;
	}
	return 0;
}

Measured memory_bytes: 18296
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define rep(i, a, n) for (int i=(a); i<(n); i++)
#define per(i, a, n) for (int i=(a); i>(n); i--)
typedef long long ll;
const int maxn = 2e5+5;
const int mod = 1e9+7;
using namespace std;

void solve() {
	ll x; cin >> x;
	if (x == 0) cout << 1;
	else cout << 0;
}

int main(int argc, char * argv[]) 
{
	ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef DEBUG
	freopen("C:/Users/Fish_Brother/Desktop/in", "r", stdin);
	//freopen("C:/Users/Fish_Brother/Desktop/out", "w", stdout);
#endif

	//int t; cin >> t; while(t--)
	solve();

    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i=(a); i<(b); i++)

int main() {
  int64_t N;
  cin >> N;
  int64_t a[3*N];
  FOR(i,0,3*N)  cin >> a[i];
  sort(a,a+3*N,greater<int>());
  int64_t sum = 0;
  FOR(i,0,N) sum += a[2*i+1];
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 5984
#include <stdio.h>
 
int main(void){
    int a, b, c, n, i, m, p, cur;
    scanf("%d", &n);
    scanf("%d", &m);
    scanf("%d", &p);
    a=p-m;
    if(m>p){
        m=p;
    }   
    for (i = 2; i < n; i++){
        scanf("%d", &cur);
        b = cur-p;
        c = cur-m;
        if(b>c){
            if(a<b)a=b;
        }else if(a<c){
            a=c;
        }
        if(m>cur){
            m=cur;
        }
        p=cur;
    }
    printf("%d\n", a);
    return 0;
}

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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

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

const int INF = 1e9;

int main(void){

	int N; cin >> N;
	vector<int> a(N);

	REP(i,N) cin >> a[i];

	map<int, int> mp;
	REP(i,N){
		mp[a[i]]++;
		mp[a[i]-1]++;
		mp[a[i]+1]++;
	}

	int ans = -1;
	for(auto a:mp){
		ans = max(ans, a.second);
	}

	cout << ans << endl;
	return 0;

}


Measured memory_bytes: 5120
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <queue>
#include <deque>

using namespace std;
using ll = long long int;

ll gcd(ll a, ll b){
    ll r = a % b;
    while(r!=0){
      a = b;
      b = r;
      r = a % b;
    }
    return b;
}

// 1以上 N 以下で C で割れる
ll candevide(ll N, ll C){
    return N / C;
}

int main(){
    ll A, B, C, D;
    cin >> A >> B >> C >> D;

    ll gcdcd = gcd(D, C);

    ll bc = candevide(B, C);
    ll bd = candevide(B, D);
    ll bcd = candevide(B, C * D / gcdcd);
    ll ans = B - bc - bd + bcd;

    ll ac = candevide(A-1, C);
    ll ad = candevide(A-1, D);
    ll acd = candevide(A-1, C * D / gcdcd);
    ll ansa = A-1 - ac - ad + acd;

    cout << ans - ansa << endl;

    return 0;
}


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

int main() {
	int H, W;
	while(true){

	cin >> H >> W;
	
	if(H==0 && W==0){break;}
	
	for(int i=0; i<H; i++){
		for(int j=0; j<W; j++){
			cout << "#";
		}
		cout<<endl;
	}
	
	cout<<endl;
	
	}
	return 0;
}

Measured memory_bytes: 1152
def solve(a, b, angle)
  ang = 1.0 * angle / 180 * Math::PI
  c = Math.sqrt(a ** 2 + b ** 2 - 2 * a * b * Math.cos(ang))
  area = 0.5 * a * b * Math.sin(ang)
  h = b * Math.sin(ang)
  [area, a + b + c, h]
end

def main
  a, b, ang = gets.split(/\s/).map(&:to_i)
  puts solve(a, b, ang)
end

main

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

#define FOR(i, a, b) for(long long int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;



int main(void) {

	while (1) {
		string s;
		string t;
		int m;
		int h[101];

		cin >> s;
		if (s == "-") {
			break;
		}
		cin >> m;
		FOR(i, 1, m) {
			cin >> h[i];
			t = s.substr(0, h[i]);
			s.erase(0, h[i]);
			s += t;
		}

		cout << s << endl;
	}
	
	
	return 0;
}



Measured memory_bytes: 3144
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::Read;
#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok().unwrap();
    ret
}
fn get_word() -> String {
    let mut stdin = std::io::stdin();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

fn solve() {
    let d = get();
    let n = get();
    let mut a: i64 = if n == 100 { 101 } else { n };
    for _ in 0 .. d {
        a *= 100;
    }
    println!("{}", a);
    
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572
import java.io.*;

public class Main {

    public static void main(String args[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        String[] st = br.readLine().split(" ");
        int[] n = new int[3];
        for (int i = 0; i < 3; i++) {
            n[i] = Integer.parseInt(st[i]);
            for (int j = i; j >= 1; j--) {
                if (n[j - 1] > n[j]) {
                    int tmp = n[j];
                    n[j] = n[j - 1];
                    n[j - 1] = tmp;
                }
            }
        }
        bw.append(n[0] + " " + n[1] + " " + n[2] + "\n");
        bw.flush();
    }


}


Measured memory_bytes: 24408
#include<bits/stdc++.h>
using namespace std;
int main() {
    int a,b,n;
    string str;
    while(cin >> str >> n){
        int len = str.size();
        for(int i = 0,j = 1;i < len;i++,j++){
             if(!(i % n)) cout << str[i];
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define max(x,y) (x>y?x:y)
int dx[]={1,0,-1,0};
int dy[]={0,-1,0,1};
typedef struct{
    int x;
    int y;
}data_t;
typedef struct{
    int head;
    int tail;
    data_t data[200000];
}queue_t;
queue_t queue;
void initqueue(){queue.head=queue.tail=0;}
void enqueue(data_t data){queue.data[queue.tail++]=data;}
data_t dequeue(){return queue.data[queue.head++];}

int h,w;
char map[1000][1000];

int bfs(data_t start,data_t goal){
    int dist[1000][1000];
    data_t now,move;

    initqueue();
    enqueue(start);
    
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            dist[i][j]=-1;
        }
    }
    dist[start.y][start.x]=0;

    int ret=-1;

    while(queue.head!=queue.tail){   
        now=dequeue();
        for(int i=0;i<4;i++){
            move.x=now.x+dx[i];
            move.y=now.y+dy[i];
            if(move.x<0||w<=move.x||move.y<0||h<=move.y)continue;
            if(dist[move.y][move.x]!=-1||map[move.y][move.x]=='#')continue;
            enqueue(move);
            dist[move.y][move.x]=dist[now.y][now.x]+1;
            ret=max(ret,dist[move.y][move.x]);
        }
    }
    return ret;
}
int main(){
    scanf("%d %d",&h,&w);
    for(int i=0;i<h;i++)scanf("%s",map[i]);
    int ans=-1;
    data_t start,end;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(map[i][j]=='#')continue;
            start.x=j;
            start.y=i;
            ans=max(ans,bfs(start,end));
        }
    }
    printf("%d\n",ans);

    return 0;
}

Measured memory_bytes: 2304
// Ashish Agarwal @ashuag007
// references: geeksforgeeks

#include<bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
typedef long long ll;

int main(void)
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    ll test;
    cin>>test;
    ll n=test,t;
    ll cnt=0;
    while(n>0)
    {
        t=n%10;
        if(t==2) cnt++;
        n=n/10;
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int n,m,i,j,u,cnt=0,ans=0;
  scanf("%d %d",&n,&m);
  int a[n][30];
  int k[n];
  for(i=0;i<n;i++){
    scanf("%d",&k[i]);
    for(j=0;j<k[i];j++){
      scanf("%d",&a[i][j]);
    }
  }
  for(i=0;i<k[0];i++){
    cnt=0;
    for(j=0;j<n;j++){
      for(u=0;u<k[j];u++){
        if(a[0][i]==a[j][u]) cnt++;
      }
    }
    if(cnt==n) ans++;
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 128
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))
sys.setrecursionlimit(10 ** 7)

def gcd(n, m):
  while m:
    n, m = m, n%m
  return n

def lcm(n, m):
  return (n * m) // gcd(n, m)

def f(n, m, l):
  a = n // l
  if a * l < n:
    a += 1
  b = m // l
  return b - a + 1

def main():
    a, b, c, d = na()
    x = b - a + 1
    print(x - (f(a, b, c) + f(a, b, d) - f(a, b, lcm(c, d))))

if __name__ == '__main__':
    main()


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

int main(){
	int a, b, c, d;
  	cin >> a >> b >> c >> d;
  	if(a + b > c + d){ cout << "Left" << endl;}
  	else if(a + b == c + d){ cout << "Balanced" << endl;}
  	else { cout << "Right" << endl;}
}

Measured memory_bytes: 256
N = int(input())
R = [list(map(int, input().split())) for _ in range(N)]
T = R[0][0]
A = R[0][1]
for r in R[1:]:
    i = T // r[0]
    if T % r[0] != 0:
        i += 1
    j = A // r[1]
    if A % r[1] != 0:
        j += 1
    T = r[0] * max(i, j)
    A = r[1] * max(i, j)
print(T+A)

Measured memory_bytes: 3188
/**
 *   author: bholuakku
**/

#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define MOD 1000000007
#define Endl cout<<"\n"
#define Test cout<<"Hello\n"

using namespace std;

typedef long long ll;

int power(ll x, ll y, ll p) { ll res = 1; x = x % p; while (y>0){ if (y & 1) res = (res*x) % p; y = y>>1; x = (x*x)%p;} return res;}
int modInverse(ll n) {ll p = MOD;return power(n, p-2, p);}
int min(int a, int b, int c) { return min(a, min(b, c)); }
int max(int a, int b, int c) { return max(a, max(b, c)); }
inline void swap(int &a, int &b) { int t = a; a = b; b = t;}
bool cmp(int a, int b){return a>b;}

vector<bool> sieve;
vector<int> ans(3000000);

void fill(){
    sieve.assign(3000010, true);
    for(int i = 2; i*i<=3000000; i++){
        if(sieve[i]){
        for(int j = i*i; j<=3000000; j+=i){
            sieve[j] = false;
        }
        }
    }
    ans[1] = 0;
    for(int i = 2; i<2100000; i++){
        ans[i] = ans[i-1];
        if(sieve[i]) ans[i]++;
    }
}

int main(){
    int a, b; cin>>a>>b;
    cout<<max(2*a-1, 2*b-1, a+b);
    return 0;
}


Measured memory_bytes: 11904
#include<bits/stdc++.h>
#define ll  long long int
#define db long double 
#define ull unsigned long long int
// #define mp make_pair
#define F first
#define S second
#define pb push_back
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define all(a) a.begin(),a.end()
#define Nmax 1000005
// #define INF 10000000000000
#define MOD 1000000007
#define MAXN 200005
 
using namespace std;

ll mod=1e9+7;
 
ll expo(ll base,ll exponent,ll mod){
    ll ans=1;
    while(exponent!=0){
        if(exponent&1) ans=(1LL*ans*base)%mod;
        base=(1LL*base*base)%mod;
        exponent>>=1;
    }
    return ans%mod;
}

const ll M=3000006;
ll f[M],inv[M];

void compute(){
    f[0]=1;
    rep(i,1,M-1){
        f[i]=(1LL*i*f[i-1])%mod;
    }
    inv[M-1]=expo(f[M-1],mod-2,mod);
    for(ll i=M-2;i>=0;i--){
        inv[i]=(1LL*(i+1)*inv[i+1])%mod;
    }
}
ll C(ll n,ll r){
    return (1LL*((1LL*f[n]*inv[r])%mod)*inv[n-r])%mod;
}

ll dp[2001];

ll recur(ll i)
{
	if(i<3) return 0;
	if(i<6) return 1;
	if(dp[i]!=-1) return dp[i];
	ll res=1;
	for(ll j=3;j<i;j++)
	{
		res+=recur(i-j);
		res%=mod;
	}
	return dp[i]=res;
}

int main()
{
        ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    // compute();
    int tests=1;
    // cin>>tests;    
    while(tests--)
    {
    	ll i,j,s;
    	cin>>s;
    	memset(dp,-1,sizeof(dp));
    	cout<<recur(s);

    }

    return 0;
}
    

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

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A.at(i);
    set<int> B;
    bool flg = true;
    for(int i=0; i<N; i++){
        if(B.find(A.at(i)) == B.end()) B.insert(A.at(i));
        else{
            flg = false;
            break;
        }
    }
    if(flg) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 13464
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define rep1(n) for(ll i=0;i<n;++i)
#define rep2(i,n) for(ll i=0;i<n;++i)
#define rep3(i,a,b) for(ll i=a;i<b;++i)
#define rep4(i,a,b,c) for(ll i=a;i<b;i+=c)
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;in(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;in(__VA_ARGS__)
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//bitSearch, bitList, nod, gcdlcm, isPrime, primeFactorize, Npow, divisor, modinv, dfs, bfs, eratos//
//dijkstra, WarshallFloyd, BellmanFord, UnionFind, COM, digitDP ,RMQ//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q;
ll MOD = 1000000007; ll INF = 1LL << 62; ll ans = -1; ll z = 0, o = 1;
vl flag, color, D; vll path; ll pre = 0;
void bfs(ll now) {
	queue<ll> Q;
	Q.push(now);
	color[now] = 1;
	pre = 1;
	ll u;
	while (!Q.empty()) {
		u = Q.front();
		Q.pop();
		pre = max(pre,color[u]);
		for (ll v = 0; v < path[u].size(); v++) {
			ll next = path[u][v];
			if (color[next] == 0) {
				color[next] = color[u] + 1;
				Q.push(next);
			}
			else if (abs(color[u] - color[next]) != 1) {
				pre=-1;
				return;
			}
		}
	}
}
int main() {
	cin >> N;
	path.resize(N);
	color.resize(N);
	for (i = 0; i < N; i++) {
		string S;
		cin >> S;
		for (j = 0; j < N; j++) {
			if (S[j]=='1') path[i].push_back(j);
		}
		//debug(i,path[i]);
	}
	for (i = 0; i < N; i++) {
		for (j = 0; j < N; j++) {
			color[j] = 0;
		}
		pre = 0;
		bfs(i);
		//debug(i, color,pre);
		ans = max(pre, ans);
	}
	cout << ans;
}

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

int main(){
  int H,W;
  cin >> H >> W;
  string str;
  for(int i = 0; i < H; i++){
    cin >> str;
    for(int j = 0; j < 2; j++){
      for(int k = 0; k < W; k++){
        cout << str.at(k);
      }
      cout << endl;
    }
  }
}
  

Measured memory_bytes: 256