akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<bitset>

using namespace std;
typedef long long ll;
#define i_7 1000000007
#define i_5 1000000005

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=1000000000000;/*10^12*/
#define rep(i,l,r) for(ll i=l;i<=r;i++)
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(){
    string s,t;cin>>s>>t;
    int ls=s.size(),lt=t.size();
    int dp[ls+1][lt+1];rep(i,0,ls)rep(j,0,lt)dp[i][j]=inf;
    
    rep(i,0,ls)dp[i][0]=i;
    rep(i,0,lt)dp[0][i]=i;
    
    rep(i,1,ls)rep(j,1,lt){
        dp[i][j]=min(dp[i-1][j]+1,dp[i][j-1]+1);
        if(s[i-1]==t[j-1])dp[i][j]=min(dp[i][j],dp[i-1][j-1]);
        else dp[i][j]=min(dp[i][j],dp[i-1][j-1]+1);
    }
 /*   rep(i,0,ls){
        rep(j,0,lt){
        cout<<dp[i][j]<<" ";
        }cout<<endl;
    }*/
    cout<<dp[ls][lt]<<endl;
    
    
    return 0;
}



Measured memory_bytes: 7072
#include "bits/stdc++.h"

using namespace std;

int main() {
	int N;
	long long D;
	cin >> N >> D;
	int ans = 0;
	for (int n = 0; n < N; ++n) {
		long long X, Y;
		cin >> X >> Y;
		if (D*D >= (X*X + Y * Y)) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
  string s;
  cin >> s;
  ll cnt = 0;
  rep(i,s.size()){
    cnt += s[i] - '0';
  }
  if(cnt %9 == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3716
unittest
{
	assert( [ "1234567876" ].parse.expand.solve == 34 );
	assert( [ "35753" ].parse.expand.solve == 0 );
	assert( [ "1111111111" ].parse.expand.solve == 642 );
}



import std.algorithm;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto ss = input.front.strip;
	return tuple( ss );
}

auto solve( string ss )
{
	auto d = long.max;
	for( auto i = 0; i + 3 <= ss.length; i++ )
	{
		d = min( d, ( ss[ i .. i + 3 ].to!( long ) - 753L ).abs );
	}
	return d;
}


Measured memory_bytes: 256
def main():
    N =int(input())
    list_a = list(map(int,input().split()))
    i = 1
    j = 0
    count = 0
    while N > j :
        if list_a[j] == i:
            i += 1
            j += 1
        else :
            count += 1
            j += 1
    if i == 1:
        print(-1)
    else :
        print(count)

main()


Measured memory_bytes: 26268
#include<bits/stdc++.h>
using namespace std;
int main(){
  char s[30];
  cin >> s;
  for(int i=0;i<strlen(s);i++){
    for(int j=0;j<i;j++){
      if(s[i]==s[j]){
        cout << "no";
        return 0;
      }
    }
  }
  cout << "yes";
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
if n%2==0:
    b=sorted(a)
    i=0
    while i<len(b):
        if not (b[i]==b[i+1] or b[i+2]==b[i]+2):
            print(0)
            exit()
        i+=2
    print((2**(len(b)//2))%(10**9+7))
else:
    b=sorted(a)
    if len(b)>1:
        if b[1]==0:
            print(0)
            exit()
    if b[0]!=0:
        print(0)
        exit()
    else:
        i=1
        while i<len(b):
            if not (b[i]==b[i+1] or b[i+2]==b[i]+2):
                print(0)
                exit()
            i+=2
        print(2**(len(b)//2)%(10**9+7))




Measured memory_bytes: 14220
#include "bits/stdc++.h"
using namespace std;
void __dump(int x){cerr << x;}
void __dump(long long x){cerr << x;}
void __dump(long double x){cerr << fixed << setprecision(3) << x;}
void __dump(char x){cerr << '\'' << x << '\'';}
void __dump(const string &x){cerr << '"' << x << '"';}
void __dump(const char *x){cerr << '"' << x << '"';}
void __dump(bool x){cerr << (x ? "true" : "false");}
void _dump(){cerr << "\n";}
template <typename T, typename U> void __dump(const pair<T, U> &x){cerr << '{'; __dump(x.first); cerr << ','; __dump(x.second); cerr << '}';}
template <typename T, typename U, typename V> void __dump(const tuple<T, U, V> &x){cerr << '{'; __dump(get<0>(x)); cerr << ',';  __dump(get<1>(x)); cerr << ',';  __dump(get<2>(x)); cerr << '}';}
template <typename T> void __dump(const T& x){int f=0; cerr << '{'; for(auto&i:x) cerr << (f++ ? "," : ""), __dump(i); cerr << "}";}
template <typename T, typename ... U> void _dump(T t, U ... u){__dump(t); if(sizeof...(u)) cerr << ", "; _dump(u...);}
#define dump(x ...) cerr  <<  "|| "  <<  # x  <<  "  =  ", _dump(x) 
//#define int long long
#define FAST ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define size(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define ln '\n'
#define __ ' '
#define LL long long
#define LD long double
#define pii pair<int,int>
const int INF = 2e9;
const int NN = -1;
const int HH = 500;
const int WW = 500;
int H,W;
int h,w;
int arr[HH+1][WW+1];

int main(){ FAST
	cin >> H >> W >> h >> w;

	if(h == 1 && w == 1){
		cout << "No" << ln;
		return 0;
	}

	for(int i=h; i<=H; i+=h) for(int j=w; j<=W; j+=w) arr[i][j] = -1e9;

	for(int i=1; i<=H; i+=h) for(int j=1; j<=W; j+=w) arr[i][j] = 1e9-1;

	LL sum = 0;
	for(int i=1; i<=H; ++i) for(int j=1; j<=W; ++j) sum+=arr[i][j];

	if(sum <= 0){
		cout << "No" << ln;
		return 0;
	}
	cout << "Yes" << ln;
	for(int i=1; i<=H; ++i){
		for(int j=1; j<=W; ++j){
			cout << arr[i][j] << __;
		}
		cout << ln;
	}
}

Measured memory_bytes: 3968
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    long long int n;
    cin >> n;
    vector<long long int> lucas(n+1, -1);
    lucas[0] = 2;
    lucas[1] = 1;
    FOR(i,2, n + 1){
        lucas[i] = lucas[i - 1] + lucas[i - 2];
    }
    cout << lucas[n] << endl;

    return 0;
}


Measured memory_bytes: 888
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		n = scanner.nextInt();
		m = scanner.nextInt();
		t = new int[n];
		for (int i = 0; i < n; i++)
			t[i] = scanner.nextInt();
		d = new int[3][m];
		for (int i = 0; i < m; i++)
			for (int j = 0; j < 3; j++) {
				int a = scanner.nextInt();
				d[j][i] = a;
			}
		dp = new int[n][m];
		for (int[] dp1 : dp)
			Arrays.fill(dp1, -1);
		int ans = 0;
		for (int i = 0; i < m; i++) {
			if (t[0] < d[0][i] || d[1][i] < t[0])
				continue;
			ans = Math.max(ans, slove(1, i));
		}
		System.out.println(ans);

	}

	private int slove(int day, int x) {
		if (day == n)
			return 0;
		if (dp[day][x] != -1)
			return dp[day][x];
		int ret = 0;
		for (int i = 0; i < m; i++) {
			if (t[day] < d[0][i] || d[1][i] < t[day])
				continue;
			ret = Math
					.max(ret, slove(day + 1, i) + Math.abs(d[2][x] - d[2][i]));
		}

		return dp[day][x]=ret;
	}

	int n, m;
	int[] t;
	int[][] d, dp;
}

Measured memory_bytes: 22020
#include <string>
#include <cstdio>
#include <cstdlib>
using namespace std;

const string table[] ={
	"100101",
	"10011010",
	"0101",
	"0001",
	"110",
	"01001",
	"10011011",
	"010000",
	"0111",
	"10011000",
	"0110",
	"00100",
	"10011001",
	"10011110",
	"00101",
	"111",
	"10011111",
	"1000",
	"00110",
	"00111",
	"10011100",
	"10011101",
	"000010",
	"10010010",
	"10010011",
	"10010000",
};

void out( const string &s ){
	int n = strtol( s.substr( 0, 5 ).c_str(), 0, 2 );
	if( n < 26 )	putchar( n + 'A' );
	else putchar( " .,-'?"[n - 26] );
}

int main(){
	char c;
	string s;
	for(; c = getchar(), c != EOF; ){
		switch(c){
			case '\n':
				if( s.length() > 0 ){
					s += "0000";
					out(s);
				}
				puts("");
				s = "";
				break;
			case ' ':
				s += "101";
				break;
			case '\'':
				s += "000000";
				break;
			case ',':
				s += "000011";
				break;
			case '-':
				s += "10010001";
				break;
			case '.':
				s += "010001";
				break;
			case '?':
				s += "000001";
				break;
			default:
				s += table[c - 'A'];
				break;
		}
		while( s.length() > 4 ){
			out( s );
			s = s.substr(5);
		}
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"
	#define ll long long int
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define inf 1000000000000000001;
	#define all(c) c.begin(),c.end()
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define f first
	#define s second
	

	ll power(ll x, ll y, ll p) {
		ll res = 1;
		x = x%p;

		if(x == 0) {
			return 0;
		}
		
		while(y>0) {
			if(y&1) {
				res = (res*x)%p;
			}
			y = y>>1;
			x = (x*x)%p;
		}
		return res;
	}
	using namespace std;
	int main()
	{
		std::ios::sync_with_stdio(false);

		ll n;
		cin>>n;

		vector<ll> v;

		for(ll i=0; i<n; i++) {
			ll x;
			cin>>x;
			v.push_back(x);
		}

		sort(v.begin(),v.end());
		ll tag = 0;
		if(n%2 == 0) {
			for(ll i=0; i<n; i+=2) {
				if(v[i] != i+1 || v[i+1] != i+1) {
					tag = 1;
					
					break;
				}
			}
		}
		else {
			if(v[0] != 0) {
				
				tag = 1;
			}
			else {
				for(ll i=1; i<n; i+=2) {
					if(v[i] != i+1 || v[i+1] != i+1) {
						tag = 1;
						
						break;
					}
				}
			}
		}

		if(tag == 1) {
			cout<<0<<endl;
		}
		else {
			cout<<power(2,n/2,mod)<<endl;
		}
		return 0;
	}


Measured memory_bytes: 1400
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>

#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)

using namespace std;

int N, M, a[100010], b[100010];

int main() {
  cin>>N>>M;
  REP(i,0,M){
    cin>>a[i]>>b[i];
    a[i]--; b[i]--;
  }

  int d[100010];
  REP(i,0,N) d[i] = 0;
  REP(i,0,M){
    if(a[i]!=0) d[a[i]]++;
    if(b[i]!=0) d[b[i]]++;
  }

  REP(i,1,N){
    if(d[i]%2 == 1){
      cout<<"NO"<<endl;
      return 0;
    }
  }
  cout<<"YES"<<endl;

  return 0;
}


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

int main(){
	cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);
	LL n;
	cin >> n;
	string s;
	string t;
	cin >> s >> t;
	vector<LL> b1, b2;
	for(LL i = 0; i + 1 < n; i++){
		if(s[i] == s[i+1]) b1.push_back(i+1);
		if(t[i] == t[i+1]) b2.push_back(i+1);
	}
	sort(b1.begin(), b1.end());
	sort(b2.begin(), b2.end());
	LL best = 1e15;

	int par = s[0] != t[0];
	for(LL dx = -6000; dx <= 6000; dx++){
		int par2 = dx & 1;
		if(par2 != par) continue;
		LL minv = min(0LL, -dx) - 10;
		LL maxv = max(n, n-dx) + 10;
		LL val = 0;
		for(LL v = minv; v <= maxv; v++){
			LL w = v + dx;
			LL g1, g2;
			if(v < 0){
				g1 = 0;
			} else if(v >= b1.size()){
				g1 = n;
			} else {
				g1 = b1[v];
			}
			if(w < 0){
				g2 = 0;
			} else if(w >= b2.size()){
				g2 = n;
			} else {
				g2 = b2[w];
			}
			val += abs(g2 - g1);
		}
		best = min(best, val);
	}
	cout << best << endl;
}

Measured memory_bytes: 384
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n = sc.nextInt();
			int m = sc.nextInt();
			if(n+m==0)break;
			int[] t = new int[n+1];
			int sumt = 0;
			for(int i=1;i<=n;i++) {
				t[i] = sc.nextInt();
				sumt += t[i];
			}
			
			int[] h = new int[m+1];
			int sumh = 0;
			for(int i=1;i<=m;i++) {
				h[i]  = sc.nextInt();
				sumh += h[i];
			}
			
			int Git=101;int Gih=101;
			for(int i=1;i<=n;i++){
				for(int j=1;j<=m;j++) {
					if(sumt-t[i]+h[j] == sumh-h[j]+t[i] && Git+Gih > t[i]+h[j]) {
						Git=t[i];
						Gih=h[j];
					}
				}
			}
			if(Git + Gih == 202)
				System.out.println("-1");
			else System.out.println(Git + " " + Gih);
			
		}
		
	}
}


Measured memory_bytes: 29652
dbflag=""

def debug(*args):
	if ""!=dbflag: print(*args)

if ""!=dbflag: _INDATA=open(dbflag)

def readline():
	if ""!=dbflag:return _INDATA.readline()
	else: return input()


result = 0

N,A,B = map(int, readline().split())



for i5 in range(0,2):
  for i4 in range(0,10):
    for i3 in range(0,10):
      for i2 in range(0,10):
        for i1 in range(0,10):
          s = i5 + i4 + i3 + i2 + i1
          sss = 10000* i5 + 1000 *i4 + 100 * i3 + 10 * i2 + i1
          if sss > N :
            break
            
          if A<= s and s <= B:
            result += sss

print(result)

Measured memory_bytes: 3064
#include<cstdio>
#include<vector>
int n;
char s[201000];
int m;
struct person {
	int kind; // 0 -> initially in pos-th position, 1 -> came in pos-th op
	int pos;
};
person cameout[200100];
person respos[600100];
person ncameout[200100];
person nrespos[600000];
person camein[3][200100];
int sz;
int tsz;
int ans[600100];
person refpos(int grp, person p) { // in : person 0~sz out : person 0~tsz
	if (p.kind == 0) {
		person res;
		res.kind = 0;
		res.pos = grp * sz + p.pos;
		return res;
	}
	return camein[grp][p.pos];
}
void f(int dep) {
	if (dep == 0) {
		sz = 1;
		respos[0].kind = 0;
		respos[0].pos = 0;
		for (int i = 0; i < m; i++) {
			if (s[i] == 'S')continue;
			else {
				cameout[i] = respos[0];
				respos[0].kind = 1;
				respos[0].pos = i;
			}
		}
		return;
	}
	f(dep - 1);
	tsz = sz * 3;
	int salsan = 0;
	for (int i = 0; i < m; i++) {
		if (s[i] == 'S') {
			salsan++;
		}
		else {
			person tin;
			tin.kind = 1;
			tin.pos = i;
			camein[0][i] = tin;
			if (salsan % 2 == 0) {
				camein[1][i] = refpos(0, cameout[i]);
				camein[2][i] = refpos(1, cameout[i]);
				ncameout[i] = refpos(2, cameout[i]);
			}
			else {
				camein[2][i] = refpos(0, cameout[i]);
				camein[1][i] = refpos(2, cameout[i]);
				ncameout[i] = refpos(1, cameout[i]);
			}
		}
	}
	for (int i = 0; i < sz; i++) {
		nrespos[i] = refpos(0, respos[i]);
		if (salsan % 2 == 0) {
			nrespos[sz + i] = refpos(1, respos[i]);
			nrespos[2 * sz + i] = refpos(2, respos[i]);
		}
		else {
			nrespos[2 * sz + i] = refpos(1, respos[i]);
			nrespos[sz + i] = refpos(2, respos[i]);
		}
	}
	sz = tsz;
	for (int i = 0; i < sz; i++) {
		respos[i] = nrespos[i];
	}
	for (int i = 0; i < m; i++) {
		cameout[i] = ncameout[i];
	}
	return;
}
int main() {
	scanf("%d", &n);
	scanf("%s", s);
	for (m = 0; s[m]; m++);
	f(n);
	for (int i = 0; i < m; i++) {
		camein[0][i] = refpos(0, cameout[i]);
	}
	for (int i = 0; i < sz; i++) {
		respos[i] = refpos(0, respos[i]);
		if (respos[0].kind == 1) {
			printf("ERR!");
		}
		ans[respos[i].pos] = i;
	}
	for (int i = 0; i < sz; i++) {
		printf("%d ", ans[i]);
	}
	return 0;
}


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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pll> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-9;

int main() {
	int a[3];
	REP(i, 3) cin >> a[i];
	sort(a, a + 3);
	
	cout << a[0] + a[1] << endl;
	
	return 0;
}


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

int a[200005];

int main(){

  
  long long s=0;
  int n;
  cin>>n;

  for(int i=0;i<n;i++) cin>>a[i], s+=a[i];

  long long sum=0;

  long long ans=(long long)(1e17);
  
  for(int i=0;i<n-1;i++){
    
    sum+=a[i];
    
    ans=min(ans,abs(sum-(s-sum)));
    
  }

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


Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
const int N=105;
int n,fa[N],dep[N],len,t[N];
long long ans=1ll<<60;
vector<int>E[N];
void dfs(int u,int f){
	fa[u]=f;dep[u]=dep[f]+1;int s=0;
	for(int v:E[u])if(v!=f)++s,dfs(v,u);
	t[dep[u]]=max(t[dep[u]],s);
}
void solve(int x,int y){
	memset(t,0,sizeof(t));
	dep[y]=0;dfs(x,y);
	if(y)dep[x]=0,dfs(y,x);
	long long res=1;
	for(int i=1;i<len;++i)res*=t[i];
	if(y)res<<=1;
	ans=min(ans,res);
}
int main(){
	scanf("%d",&n);
	for(int i=1,x,y;i<n;++i){
		scanf("%d%d",&x,&y);
		E[x].push_back(y);E[y].push_back(x);
	}
	dfs(1,0);int P=1;
	for(int i=2;i<=n;++i)P=dep[i]>dep[P]?i:P;
	dfs(P,0);int Q=1;
	for(int i=2;i<=n;++i)Q=dep[i]>dep[Q]?i:Q;
	printf("%d ",len=dep[Q]+1>>1);int R=Q;
	while(dep[fa[R]]<<1>dep[Q])R=fa[R];
	if(dep[Q]&1){
		solve(R,0);
		for(int S:E[R])solve(R,S);
	}
	else solve(R,fa[R]);
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))

mod = 10 ** 9 + 7

dp = [[0 for i in range(M+1)] for i in range(N+1)]

for i in range(1, N+1):
    for j in range(1, M+1):
        if S[i-1] == T[j-1]:
            dp[i][j] = (1 + dp[i-1][j] + dp[i][j-1]) % mod
        else:
            dp[i][j] = (dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1]) % mod

print((dp[-1][-1] + 1) % mod)


Measured memory_bytes: 75484
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define PI 				acos(-1)
#define mp				make_pair
#define pb				push_back
#define all(a)			(a).begin(), (a).end()
#define sz(a)			a.size()
#define srt(a)			sort(all(a))
#define mem(a, h)		memset(a, (h), sizeof(a))
#define f 				first
#define s 				second
#define MOD1			998244353
#define fore(i, b, e)	for(int i = b; i < e; i++)
#define forg(i, b, e, m)	for(int i = b; i < e; i+=m)
int in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;
using namespace __gnu_pbds;

typedef long long 		ll;
typedef unsigned long long 		ull;
typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//find_by_order kth largest  order_of_key <
const int tam = 100010;
const int MOD = 1e9+7;
const double EPS = 1e-9;

char fir[100][100], sec[100][100];
	int n, m;
bool bla(int i, int j)
{
	if(i >= 0 && i < n && j >= 0 && j < m && fir[i][j] == '#')
		return true;
	return false;
}
int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	//freopen("qwe.txt", "r", stdin);
	//freopen("asd.txt", "w", stdout);
	int su[2][4] = {{0, 1, 0, -1}, {1, 0, -1, 0}};
	cin>>n>>m;
	fore(i, 0, m) fore(j, 0, m) cin>>fir[i][j], sec[i][j] = '.';
	fore(i, 0, n) fore(j, 0, m) 
	{
		if(fir[i][j] == '#')
		{
			fore(k, 0, 4)
			{
				if(bla(i + su[0][k], j + su[1][k]))
					sec[i][j] = '#';
			}
			if(sec[i][j] == '.')
			{
				cout<<"No\n";
				return 0;
			}
		}
	}
	cout<<"Yes\n";
	return 0;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS2

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

int main() {
    string S;
    cin >> S;
    int c=0;
//    cout << S.length();
    for (int i = 0; i < S.length(); i=i+2) {
        if(S.length()%2 == 1){
            break;
        }
        if(S.at(i)=='h' && S.at(i+1)=='i'){
            c=c+2;
        }
    }
    if(c == S.length()){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll N,count=0; cin>>N;
  vector<pair<ll,ll>>A;
  map<pair<ll,ll>,ll>M;
  for(int i=0; i<N; i++){
    ll x,y; cin>>x>>y;
    A.push_back(make_pair(x,y));
  }
  for(int i=0; i<N-1; i++){
    for(int j=i+1; j<N; j++){
      ll a,b;
      a=(A[i].first-A[j].first);
      b=(A[i].second-A[j].second);
      if(a<0) a*=-1, b*=-1;
      if(a==0 && b<0) b*=-1;
      ll value=M[make_pair(a,b)];
      value++;
//      cout<<"value:"<<value<<" a:"<<a<<" b:"<<b<<endl;
      count=max(count,value);
      M[make_pair(a,b)]=value;
    }
  }
  cout<<N-count<<endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#define MAX 5000
using namespace std ;

vector<int> a, b, c;
int n, ma, mb;
int search(int sumA, int sumB, int sumC, int st, int opt){
    if(sumC>=opt){return opt;}   
    if((sumA+a[st])*mb==(sumB+b[st])*ma){
        if(sumC+c[st]<opt){opt=sumC+c[st];}
        if(st==n-1){return opt;}
        return min(opt, search(sumA, sumB, sumC, st+1, opt));
    }
    else{
        if(st==n-1){return opt;}
        opt=min(search(sumA, sumB, sumC, st+1, opt), opt);
        return min(opt, search(sumA+a[st], sumB+b[st], sumC+c[st], st+1, opt));
    }
}
int main(void){
    int opt=MAX;
    cin>>n>>ma>>mb;
    int ai,bi,ci;
    for(int i=0;i<n;i++){
        cin>>ai>>bi>>ci;
        a.push_back(ai);
        b.push_back(bi);
        c.push_back(ci);
    }
    opt=search(0,0,0,0,opt);
    if(opt>=MAX) opt=-1;
    cout<<opt<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int N;
    string S;
    cin >> N >> S;

    int ans = 0;
    rep(i, 10) {
        rep(j, 10) {
            rep(k, 10) {
                int I = -1, J = -1, K = -1;
                rep(l, N) {
                    int n = S[l] - '0';
                    if (n == i && I == -1) I = l;
                    else if (n == j && I != -1 && J == -1) J = l;
                    else if (n == k && I != -1 && J != -1 && K == -1) K = l;
                }
                if (I != -1 && J != -1 && K != -1) ans++;
            }
        }
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 384
#include<utility>
#include<vector>
#include<cstdio>
using namespace std;

int main(){
  vector <pair<char, char> > base;
  base.push_back(pair<char,char>('A','T'));
  base.push_back(pair<char,char>('T','A'));
  base.push_back(pair<char,char>('G','C'));
  base.push_back(pair<char,char>('C','G'));
  char b;
  scanf("%c",&b);
  for(auto tgt : base){
    if(b==tgt.first){
      printf("%c\n",tgt.second);
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
 
int main() {
    char p_1[200], p_2[100], s[100];
    scanf("%s",p_1);
    strcpy(p_2,p_1);
    strcat(p_1,p_2);
    scanf("%s",s);
    if (strstr(p_1,s)){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 2692
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < (n); i++)

using namespace std;

void solve() {
  long x, y;
  cin >> x >> y;

  long ans = 2000000000000l;

  if (y-x >= 0) ans = min(ans, y-x);
  if (y-(-x) >= 0) ans = min(ans, 1+y-(-x));
  if (-y-x >= 0) ans = min(ans, -y-x+1);
  if (-y-(-x) >= 0) ans = min(ans, 1-y-(-x)+1);

  cout << ans << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 256
n=int(input())
c=[]
s=[]
f=[]
t=0
for i in range(n-1):
    a1,a2,a3=(list)(map(int,input().split()))
    c.append(a1)
    s.append(a2)
    f.append(a3)
time=[]
time.append(t)
for j in range(0,n-1):
    t=0
    for i in range(j,n-1):
        if i==j:
            t=s[i]+c[i]
        elif s[i]>=t:
            t=s[i]+c[i]
        elif (t-s[i])%f[i]==0:
            t=c[i]+t
        else:
            t=f[i]-(t-s[i])%f[i]+c[i]+t
    time.append(t)
    

time.sort(reverse=True)
for i in range(n):
    print(time[i])

Measured memory_bytes: 3188
n=int(input())
xy=[list(map(int,input().split())) for _ in range(n)]
ans=0
for i in range(n):
  for j in range(n):
    ans+=((xy[i][0]-xy[j][0])**2+(xy[i][1]-xy[j][1])**2)**0.5
print(ans/n)

Measured memory_bytes: 3188
n = int(input())
a = list(map(int,input().split()))

count = 1
flag = 0

for i in range(len(a)-1):
    if flag == 1:
        if a[i] > a[i+1]:
            flag = 0
            count += 1
    elif flag == -1:
        if a[i] < a[i+1]:
            flag = 0
            count += 1
    else:
        if i == len(a)-1:
            count+1
        elif a[i] < a[i+1]:
            flag = 1
        elif a[i] > a[i+1]:
            flag = -1

print(count)

Measured memory_bytes: 14224
(defun xor (x y)
  (or (and (not x) y)
      (and x (not y))))


(let* ((s (read-line))
       (size 400000)
       (buf (make-array size))
       (q (read))
       (parity nil)
       (head (- size 1))
       (len (length s))
       (tail len))
  (loop for i from 0 below (length s)
        do (setf (aref buf i) (aref s i)))

  (loop repeat q
        for query = (read)
        do (if (= query 1)
               (setf parity (not parity))
               (let ((f (read))
                     (c (read-char)))
                 (incf len)
                 (if (xor (= f 1) parity)
                     (progn
                       (setf (aref buf head) c)
                       (decf head))
                     (progn
                       (setf (aref buf tail) c)
                       (incf tail))))))

  (if parity
      (loop repeat len
            for i downfrom (- tail 1)
            do (format t "~a" (aref buf (mod (+ i size) size))))
      (loop repeat len
            for i from (+ head 1)
            do (format t "~a" (aref buf (mod i size)))))
  (terpri))


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

int main()
{
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;

    bool res = e - a <= k;

    cout << (res ? "Yay!" : ":(") << "\n";
    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 10000000000000009
//#define INF 9223372036854775807
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define ORREP(i,n) for(int i=(n);i>=1;--i)
#define ZREP(i,n) for(int i=1;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl
typedef pair<int,int> Pp;

int IsPrime(int X){
    if(X<=1)return false;
    for(int i=2;i*i<=X;i++){
        if(X%i==0){
            return false;
        }
    }
    return true;
}



signed main(){
    int N,M;
    cin >>  N >> M;
    if(N==1){
        cout << M << endl;
        return 0;
    }
    if(IsPrime(M)==true){
        cout << 1 << endl;
        return 0;
    }
    if(N==M){
        cout << 1 << endl;
        return 0;
    }
    
    for(int i=M/N;i>=1;i--){
        if(M%i==0){//Mはiの倍数
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}   


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

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

fn main() {
    input! {
        n: usize,
        m: usize,
        mut xs: [i64; m],
    }
    xs.sort();
    let mut diffs = xs
        .windows(2)
        .map(|x| ((x[0] - x[1]).abs(), x[1]))
        .collect::<Vec<_>>();
    diffs.sort_by(|l, r| match r.0.cmp(&l.0) {
        std::cmp::Ordering::Equal => l.1.cmp(&r.1),
        ordering => ordering,
    });
    let ans = xs.last().unwrap() - xs[0] - diffs.iter().take(n - 1).fold(0, |sum, i| sum + i.0);
    println!("{}", ans);
}


Measured memory_bytes: 8444
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int r = sc.nextInt();
        int ans = 3 * r * r;
        System.out.println(ans);
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

int main() {
    ll N, A, B;
    cin >> N >> A >> B;
    
    vec<ll> X(N);
    rep(i, N) cin >> X[i];

    ll ans = 0;
    ll now = X[0];
    for(int i=1;i<N;++i){
        ans+=min(A*(X[i]-now),B);
        now=X[i];
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3984
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL -1
using namespace std;
const int64_t MOD = 1e9 + 7;

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

	deque<int> deq;
	for (int i = 0; i < n; i++) {
		int num;
		cin >> num;

		if (n % 2 != i % 2) deq.push_front(num);
		else deq.push_back(num);
	}

	for (int i = 0; i < deq.size(); i++) {
		if (i) cout << ' ';
		cout << deq.at(i);
	}
	cout << endl;
}

Measured memory_bytes: 4472
#include <iostream>
#include <algorithm>

using namespace std;

long dif(long a, long b, long c) {
    return max({a, b, c}) - min({a, b, c});
}

int main() {
    long h, w;
    cin >> h >> w;
    long best = min({
        ((h + 2) / 3 - h / 3) * w,
        ((w + 2) / 3 - w / 3) * h,
        dif(h * (w / 3), (h / 2) * (w - w / 3), (h + 1) / 2 * (w - w / 3)),
        dif(w * (h / 3), (w / 2) * (h - h / 3), (w + 1) / 2 * (h - h / 3)),
        dif(h * ((w+2) / 3), (h / 2) * (w - (w+2) / 3), (h + 1) / 2 * (w - (w+2) / 3)),
        dif(w * ((h+2) / 3), (w / 2) * (h - (h+2) / 3), (w + 1) / 2 * (h - (h+2) / 3))
    });
    cout << best << '\n';
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] log = new int[n];
		for(int i = 0; i < n; i++)
			log[sc.nextInt()]++;
		boolean check = true;
		if(n%2 == 1) {
			check = (log[0] == 1);
			for(int i = 1; i <= n/2; i++)
				check = check && (log[i*2] == 2);
		} else {
			for(int i = 1; i <= n/2; i++)
				check = check && (log[i*2 - 1] == 2);
		}
		if(check) {
			long result = 1;
			for(int i = 0; i < n/2; i++)
				result = (result*2)%1000000007;
			System.out.println(String.valueOf(result));
		} else
			System.out.println("0");
	}
}

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

void print_horizontal_frame(int w) {
  for (int i = 0; i < w + 2; i++) {
    cout << '#';
  }
  cout << endl;
}
int main() {
  int h, w;
  cin >> h >> w;
  string a[h];
  for (int i = 0; i < h; i++) {
    cin >> a[i];
  }
  print_horizontal_frame(w);
  for (string s: a) {
    cout << '#' << s << '#' << endl;
  }
  print_horizontal_frame(w);
  return 0;
}

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

using i64 = int64_t;

int main(){
    vector<int> v(3);
    cin >> v[0] >> v[1] >> v[2];
    sort(v.begin(), v.end());
    int k;
    cin >> k;
    for(int i=0;i<k;++i)v[2]<<=1;
    cout << v[0]+v[1]+v[2] << endl;

    return 0;
}


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

int h, w, n;

int main() {
	cin >> h >> w >> n;
	
	int a = (n + h - 1) / h;
	int b = (n + w - 1) / w;
	if (a > b) cout << b << endl;
	else cout << a << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
//geo
#include <complex>
typedef complex<double> P;
inline bool equal(double x, double y){
  return abs(x - y) < EPS;
}
inline bool operator == (const P& x, const P& y){
  return equal(x.real(), y.real()) && equal(x.imag(), y.imag());
}
double dot(P x, P y){
  return real(conj(x) * y);
}
double cross(P x, P y){
  return imag(conj(x) * y);
}
int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;
}
//---
int main(){
  int n;
  while(cin>>n && n ){
    vector<P> points;
    vector<bool> used(n);
    REP(i,n){
      int x,y;
      cin>>x>>y;
      points.push_back(P(x,y));
    }
    P now(0, 0);
    double ans = 0;
    REP(time, n){
      int next = -1;
      REP(i, n)if(!used[i]){
        bool ok = true;
        REP(j, n)if(!used[j] && i != j){
          int cw = ccw(now, points[i], points[j]);
          if(cw == 0 || cw == 1) {
            ok = false;
            break;
          }
          assert(cw != 2);
        }
        if(ok){
          assert(next == -1);
          next = i;
        }
      }
      assert(next != -1);
      used[next] = true;
      ans += abs(points[next] - now);
      now = points[next];
    }
    printf("%.1lf\n", ans);
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

int dp[200005];

int main(){
  int N, M;
  cin >> N >> M;
  map<int,int> cnt;
  vector<int> v;
  rep(i,N){
    int a;
    cin >> a;
    v.push_back(a);
    cnt[a]++;
  }

  FOR(it,cnt){
    rep(i,it->second){
      if(it->first-1-i>=0){
        dp[it->first-1-i]++;
      }
    }
  }
  int ret = 0;
  rep(i,N){
    if(dp[i] == 0) ret++;
  }
  
  rep(m,M){
    int x, y;
    cin >> x >> y;
    x--;
    int prev = v[x];
    v[x] = y;

    
    if(prev-cnt[prev]>=0){
      if(dp[prev-cnt[prev]] == 1) ret++;
      dp[prev-cnt[prev]]--;
    }
    cnt[prev]--;
    cnt[v[x]]++;
    if(v[x]-cnt[v[x]]>=0){
      if(dp[v[x]-cnt[v[x]]] == 0) ret--;
      dp[v[x]-cnt[v[x]]]++;
    }

    
    cout << ret << endl;
  }
  
  return 0;
}



Measured memory_bytes: 14196
#include <iostream>
#include <queue>
#include <vector>
#include <set>
#include <algorithm>
#include <tuple>
using namespace std;

#define ll long long
#define sum_cake tuple<ll, int, int, int>

bool comp(sum_cake x, sum_cake y){
    ll first_sum = get<0>(x);
    ll sec_sum = get<0>(y);
    return first_sum < sec_sum;
}

ll to_use_idx(int x, int y, int z){
    return 1000000 * x + 1000 * y + z;
}

int main(){
    int x,y,z,k;
    cin >> x >> y >> z >> k;
    ll A[x], B[y], C[z];
    
    for(int i = 0; i < x; i++) {
        cin >> A[i];
    }
    for(int i = 0; i < y; i++) {
        cin >> B[i];
    }
    for(int i = 0; i < z; i++) {
        cin >> C[i];
    }
    sort(A, A+x, greater<ll>()); 
    sort(B, B+x, greater<ll>()); 
    sort(C, C+x, greater<ll>()); 

    priority_queue<sum_cake, vector<sum_cake>, decltype(&comp)> q(comp);
    set<ll> used_idx;

    sum_cake first_set = make_tuple(A[0] + B[0] + C[0], 0, 0, 0);
    vector<ll> sum_list;
    q.push(first_set);
    used_idx.insert(0);

    for (int i = 0; i < k; i++) {
        auto larg = q.top();
        sum_list.push_back(get<0>(larg));
        int a=get<1>(larg), b=get<2>(larg), c=get<3>(larg);
        q.pop();
        if ((a + 1 < x) && (used_idx.count(to_use_idx(a+1,b,c)) == 0)) {q.push(make_tuple(A[a+1] + B[b] + C[c], a+1, b, c)); used_idx.insert(to_use_idx(a+1, b, c));}
        if ((b + 1 < x) && (used_idx.count(to_use_idx(a,b+1,c)) == 0)) {q.push(make_tuple(A[a] + B[b+1] + C[c], a, b+1, c)); used_idx.insert(to_use_idx(a, b+1, c));}
        if ((c + 1 < x) && (used_idx.count(to_use_idx(a,b,c+1)) == 0)) {q.push(make_tuple(A[a] + B[b] + C[c+1], a, b, c+1)); used_idx.insert(to_use_idx(a, b, c+1));}
        
    }

    for (int i = 0; i < k; i++) cout << sum_list[i] << endl;
    return 0;
}


Measured memory_bytes: 768
n = int(input())

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


for i in range(len(a)):
    a[i] = a[i] -(i+1)

a.sort()

x=a[int(int(len(a))/2)]

ans = 0
for i in range(len(a)):
    ans =ans+ abs(a[i]-x)

print(ans)


Measured memory_bytes: 26180
n,k,j;
long dp[2<<17],mod=1e9+7,*p;
main(a)
{
	scanf("%*d%d",&k);
	p=dp+k;
	for(*p=1;~scanf("%d",&a);)
	{
		for(;dp-p--;)*p+=p[1];
		for(;p++-dp<k;*p%=mod)*p-=p[a+1];
	}
	printf("%ld",*dp);
}

Measured memory_bytes: 896
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial

def main():
    num = int(input())
    ans = 0
    for i in range(1, num + 1):
        if len(str(i)) % 2 == 1:
            ans += 1
    print(ans)






if __name__ == '__main__':
    main()

Measured memory_bytes: 39920
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? 1e9:1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    int n,m;
    cin >> n >> m;
    vector<int>v(n);
    erep(e,v) cin >> e;
    vector<int>dp(n);
    rep(i,n){
        if(i)dp[i] += dp[i-1] + v[i];
        else dp[i] = v[i];
    }
    map<int,int>mp;
    int ans = 0;
    rep(i,n)mp[dp[i]%m]++;
    for (auto itr :mp){
        if(itr.first == 0){
            ans += itr.second * (itr.second + 1)/2;
        } else {
            ans += itr.second * (itr.second - 1)/2;
        }
    }
    cout << ans << endl;
}




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

int main() {
	int N = 0;
	cin >> N;

	int l = 0;
	int r = 0;
	int total = 0;
	for (int i = 0; i < N; i++) {
		cin >> l >> r;
		total += r - l + 1;
	}

	cout << total << endl;

	return 0;
}

Measured memory_bytes: 256
def max_points(arr):
	dp = [[0] * (len(arr[0])) for _ in range(len(arr) + 1)]

	for i in range(len(arr)):  # days
		for j in range(len(arr[0])):  # activities
			max_before = 0
			for k in range(len(arr[0])):
				if k == j:
					continue
				max_before = max(max_before, dp[i][k])
			dp[i+1][j] = arr[i][j] + max_before
	return max(dp[-1])

  
arr = [[int(x) for x in input().strip().split()]for _ in range(int(input().strip()))]
print(max_points(arr))

Measured memory_bytes: 44108
from itertools import permutations
N,M = map(int,input().split())
E = [[False for _ in range(N)] for _ in range(N)]
for i in range(M):
    a,b = map(int,input().split())
    E[a-1][b-1] = True
    E[b-1][a-1] = True

P = permutations([i for i in range(1,N)])

ans = 0
for pp in P:
    l = len(pp)
    ni,mi = 0,0
    chk = True
    for p in pp:
        mi = p
        if not E[ni][mi]:
            chk = False
            break
        ni = p
    if chk:
        ans += 1

print(ans)




Measured memory_bytes: 3064
import java.util.Scanner;

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


Measured memory_bytes: 28292
import java.util.*;
import java.text.*;

public class Main{
	public static void main (String[] args){
		Scanner sc = new Scanner(System.in);
		DecimalFormat df = new DecimalFormat("##,###.##");
		int a= sc.nextInt();
		int b= sc.nextInt();
		int c= a-(b*2);
		if (c<=0)
		System.out.println("0");
		else
		System.out.println(c);
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;

int main()
{
  int N, P;
  int a[51];
  ll res=1;
  cin >> N >> P;

  bool hasOdd = false;
  rep(i,N) {
    cin >> a[i];
    if(a[i] % 2) hasOdd = true;
  }

  if(!hasOdd) {
    if(P) res = 0;
    else rep(i, N) res *= 2;
    cout << res << endl;
    return 0;
  }

  rep(i, N-1) res *= 2;
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int N;
int A[100000];
int B[100000];

int main() {
    int a, b, c;
    scanf("%d", &N);
    for (int i = 0; i < N; i++) {
        scanf("%d", &A[i]);
    }
    for (int i = 0; i < (N+1)/2; i++) {
        B[i] = A[i * 2];
    }
    sort(A, A + N);
    sort(B, B + (N+1)/2);

    int res = 0;
    int k = 0;
    for (int i = 0; i < (N+1)/2; i++) {
        while (A[k] != B[i])
            k++;
        if (k & 1)
            res++;
    }
    printf("%d\n", res);
}


Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n-1); i >= 0; i--)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a;cin>>a;
  cout<<a*a<<endl;
  return 0;

}


Measured memory_bytes: 256