akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
const int mod=1e9+7;
typedef long long ll;
char ch[1010];
int a[1010][1010],h,w,up_down,left_right,cnt,usb;//cnt:黑点总数，usb：原图内总接口数 
long long _pow; 
ll ksm(ll x,long long k)
{
    ll ans=1;
    while (k)
    {
        if (k&1)ans=ans*x%mod;
        k>>=1;
        x=x*x%mod;
    }
    return ans;
}
struct Matrix
{
    ll t[4][4];
    friend Matrix operator *(Matrix x,Matrix y)
    {
        Matrix z;
        memset(z.t,0,sizeof(z.t));
        for (int i=0;i<2;i++) 
            for (int j=0;j<2;j++)
                for (int k=0;k<2;k++)
                    z.t[i][j]=(z.t[i][j]+x.t[i][k]*y.t[k][j])%mod;
        return z;
    }
    friend Matrix operator ^(Matrix x,long long k)
    {
        Matrix ans;
        memset(ans.t,0,sizeof(ans.t));
        ans.t[0][0]=ans.t[1][1]=1;
        while (k)
        {
            if (k&1) ans=ans*x;
            k>>=1;
            x=x*x;
        }
        return ans;
    }
}A,B;
int main()
{
    scanf("%d%d%lld",&h,&w,&_pow);
    if (_pow<=1) {printf("1");return 0;}
    for (int i=1;i<=h;i++)
    {
        scanf("%s",ch+1);
        for (int j=1;j<=w;j++) 
        {
            a[i][j]=(ch[j]=='#');
            if (a[i][j]) cnt++;
        }
    }    
    for (int i=1;i<=w;i++) 
        if (a[1][i]&&a[h][i]) up_down++;
    for (int i=1;i<=h;i++)
        if (a[i][1]&&a[i][w]) left_right++;
    if (!up_down&&!left_right)
    {
        printf("%lld",ksm(cnt,_pow-1));return 0;
    }
    if (up_down&&left_right) 
    {
        printf("1");return 0;
    }
    for (int i=1;i<=h;i++)
        for (int j=1;j<=w;j++)
        {
            if (a[i][j]&&a[i][j+1]&&left_right) usb++;
            if (a[i][j]&&a[i+1][j]&&up_down) usb++;
        }
    A.t[0][0]=cnt;A.t[0][1]=usb;A.t[1][1]=max(up_down,left_right);
    A=A^(_pow-2);
    ll ans;ans=A.t[0][0]*usb%mod+A.t[0][1]*max(up_down,left_right)%mod;
    ans%=mod;
    printf("%lld",(ksm(cnt,_pow-1)-ans+mod)%mod);
}

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> nums(N);
    for (int i = 0; i < N; i++)
    {
        cin >> nums.at(i);
    }
    ll answer = 0;
    ll currentNum = 0;
    ll count = 0;
    for (int i = 0; i < N; i++)
    {
        while (i + count < N && (currentNum ^ nums.at(i + count)) == currentNum + nums.at(i + count))
        {
            currentNum = currentNum + nums.at(i + count);
            count++;
        }
        answer += count;
        currentNum -= nums.at(i);
        --count;
    }
    cout << answer << endl;
    return 0;
}


Measured memory_bytes: 1792
using System;

public class MainApp
{
    static public void Main(string[] args)
    {
        var num = int.Parse(Console.ReadLine());
        var i = num % 10;
        switch(i) {
            case 2:
            case 4:
            case 5:
            case 7:
            case 9:
                Console.WriteLine("hon");
                break;
            case 0:
            case 1:
            case 6:
            case 8:
                Console.WriteLine("pon");
                break;
            default:
                Console.WriteLine("bon");
                break;
        }

//#if DEBUG
//        Console.WriteLine("Press Any Key...");
//        Console.ReadKey();
//#endif
    }
}



Measured memory_bytes: 17628
#include<iostream>
using namespace std;
long long key[1000000];
int fro = 0;
int las = 0;
void push(long long a) {
  key[las] = a;
  las ++;
}
long long pop() {
  fro ++;
  return key[fro - 1];
}
int main () {
  int K;
  cin >> K;
  for (int i = 0; i < 9; i ++) push(i + 1);
  long long ans = 0;
  for (int i = 0; i < K; i ++) {
    ans = pop();
    long long ku = ans * 10;
    long long ma = ans % 10;
    if (ma != 0) push(ku + ma - 1);
    push(ku + ma);
    if (ma != 9) push(ku + ma + 1);
  }
  cout << ans << endl;
}


Measured memory_bytes: 4352
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll cmp(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}

//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int x,y;cin>>x>>y;
    cout<<x+y/2<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------


Measured memory_bytes: 256
str1=input()
str2=input()

str1_len=len(str1)+1
str2_len=len(str2)+1

co=[[0 for j in range(str2_len)]for i in range(str1_len)]

for i in range(str1_len):
    co[i][0]=i
for j in range(str2_len):
    co[0][j]=j

for i in range(1,str1_len):
    for j in range(1,str2_len):
        if str1[i-1]==str2[j-1]:
            co[i][j]=co[i-1][j-1]
        else:
            co[i][j]=min(co[i-1][j-1],co[i-1][j],co[i][j-1])+1
print(co[str1_len-1][str2_len-1])


Measured memory_bytes: 42896
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }

int main() {
	int H; int W; int N;
	while(~scanf("%d%d%d", &H, &W, &N)) {
		vpii colored;
		vpii poses;
		rep(i, N) {
			int y; int x;
			scanf("%d%d", &y, &x), -- y, -- x;
			colored.emplace_back(y, x);
			rer(dy, -1, 1) rer(dx, -1, 1) {
				int yy = y + dy, xx = x + dx;
				if(0 < yy && yy < H - 1 && 0 < xx && xx < W - 1)
					poses.emplace_back(yy, xx);
			}
		}
		sort(colored.begin(), colored.end());
		sort(poses.begin(), poses.end());
		poses.erase(unique(poses.begin(), poses.end()), poses.end());
		ll ans[10] = {};
		for(auto p : poses) {
			int j = 0;
			rer(dy, -1, 1) rer(dx, -1, 1) {
				pii q{ p.first + dy, p.second + dx };
				j += binary_search(colored.begin(), colored.end(), q);
			}
			++ ans[j];
		}
		ans[0] += (ll)(H - 2) * (W - 2) - poses.size();
		for(int i = 0; i < 10; ++ i)
			printf("%lld\n", ans[i]);
	}
	return 0;
}


Measured memory_bytes: 9452
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define rrep(i,m,n) for(int i = m; i >= n; i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printa2(x,m,n) for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << x[i][j] << " ";} cout << endl;}
#define printp(x,n) for(int i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
typedef struct{
    ll to;
    ll cost;
} edge;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    ll p[20010];
    cin >> N;
    rep(i,0,N){
        cin >> p[i];
        p[i]--;
    }
    ll a[20010], b[20010];
    rep(i,0,N){
        a[i] = (i+1) * 30000;
        b[N-1-i] = (i+1) * 30000;
    }
    rep(i,0,N){
        a[p[i]] += i;
    }
    rep(i,0,N){
        if(i != N-1){
            cout << a[i] << " ";
        }else{
            cout << a[i] << endl;
        }
    }
    rep(i,0,N){
        if(i != N-1){
            cout << b[i] << " ";
        }else{
            cout << b[i] << endl;
        }
    }

}


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

const int INF=0x3f3f3f3f;

int n,a[110],ans,cost;

int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    ans=INF;
    for(int i=1;i<=100;i++)
    {
        cost=0;
        for(int j=1;j<=n;j++)
            cost+=(a[j]-i)*(a[j]-i);
        if(cost<ans) ans=cost; 
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <set>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll mod = 1000000007;

struct segtree {
  int n;
  vector<int> data;

  segtree(const int s) {
    init(s);
  }

  segtree(const int s, const int u) {
    init(s);
    for (int i = 0; i < s; i++) {
      data[i+n-1] = u;
    }
    for (int i = n-2; i >= 0; i--) {
      data[i] = min(data[i*2+1], data[i*2+2]);
    }
  }

  segtree(const vector<int> &v) {
    int s = v.size();
    init(s);
    for (int i = 0; i < s; i++) {
      data[i+n-1] = v[i];
    }
    for (int i = n-2; i >= 0; i--) {
      data[i] = 0;
    }
  }

  void init(const int s) {
    n = 1;
    while (n < s) n <<= 1;
    data = vector<int>(2*n-1);
  }

  void update(int x, int v) {
    int p = x + n - 1;

    // update bottom
    data[p] = v;

    // update rest
    while (p > 0) {
      p = (p - 1) >> 1;
      data[p] = min(data[p*2+1], data[p*2+2]);
    }
  }

  int query(int l, int r, int p = 0, int a = 0, int b = -1) {
    if (b < 0) b = n; // init
    if (r <= a || b <= l) return 0x7fffffff; // out of range

    if (l <= a && b <= r) return data[p];// fully covered

    int vl = query(l, r, p*2+1, a, (a + b) / 2); // left
    int vr = query(l, r, p*2+2, (a + b) / 2, b); // right
    return min(vl, vr);
  }
};

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

  int h, w;
  cin >> h >> w;
  vector<Pii> ab(h);
  for (auto &x: ab) {
    cin >> x.first >> x.second;
    x.first--;
    x.second--;
  }

  segtree st(w+1, 0);
  set<int> relevant;
  for (int i = 0; i < w; i++) relevant.insert(i);

  vector<int> ans(h);
  for (int i = 0; i < h; i++) {
    auto it = relevant.lower_bound(ab[i].first);
    if (it != relevant.end()) {
      int next_blocked = *it;
      int minimum_move = 1000000007;
      while (next_blocked <= ab[i].second) {
        minimum_move = min(minimum_move, ab[i].second - next_blocked + st.query(next_blocked, next_blocked+1) + 1);
        st.update(next_blocked, 1000000007);
        it = relevant.erase(it);
        if (it != relevant.end()) next_blocked = *it;
        else break;
      }
      st.update(ab[i].second+1, min(st.query(ab[i].second+1, ab[i].second+2), minimum_move));
      if (ab[i].second+1 < w && st.query(ab[i].second+1, ab[i].second+2) < 1000000007) relevant.insert(ab[i].second+1);
    }
    ans[i] = st.query(0, w) + i + 1;
    if (ans[i] >= 1000000007) ans[i] = -1;
  }

  for (auto &x: ans) cout << x << endl;

  return 0;
}


Measured memory_bytes: 16880
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>

using namespace std;

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

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e9 + 7;
const ll MOD = 1e9 + 7;

ll n, a, x[100];
ll dp[100][100][2501];

int main(){
	cin >> n >> a;
	REP(i, n){
		cin >> x[i];
	}
	dp[0][0][0] = 1;
	REP(i, n){
		REP(j, n){
			REP(k, 2501){
				if (k + x[i] <= 2500)dp[i + 1][j + 1][k + x[i]] += dp[i][j][k];
				dp[i + 1][j][k] += dp[i][j][k];
			}
		}
	}
	//REP(k, 30){
	//	cout << k << endl;
	//	REP(i, n){
	//		REP(j, n){
	//			cout << dp[i][j][k] << " ";
	//		}
	//		cout << endl;
	//	}
	//	cout << endl;
	//}
	ll ans = 0;
	REP(i, n){
		ans += dp[n][i + 1][(i + 1)*a];
	}
	cout << ans << endl;
}

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

long long calc(long long n) {
	return n*(n+1)/2;
}

int main(){
	long long n, k;
	cin >> n >> k;
  
  //cout << calc(3) << endl;
	
	long long ans = 0;
	for (int i = k; i < n+2; i++) {
		ans += calc(n)-calc(n-i) - calc(i-1) + 1;
      //cout << calc(n)-calc(n-i) - calc(i-1) + 1<< endl;
	}
	cout << ans % 1000000007 << endl;
}

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


long long int gcd(long long int a, long long int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

int main() {
	ios_base::sync_with_stdio(false);
	long long int a, b;
	cin >> a >> b;

	cout << (a * b) / gcd(a, b) << endl;

	return 0;
}


Measured memory_bytes: 256
def main():
    a, b, c, x, y = map(int, input().split())

    ans = 1000000000

    tmp_x = x
    tmp_y = y

    for ab in range(max(x, y)+1):
        x -= ab
        y -= ab
        if x < 0:
            x = 0
        if y < 0:
            y = 0
        ans = min(ans, a * x + b * y + 2 * ab * c)
        x, y = tmp_x, tmp_y

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 39152
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys  # {{{
import os
import time
import re
from pydoc import help
import string
import math
from operator import itemgetter
from collections import Counter
from collections import deque
from collections import defaultdict as dd
import fractions
from heapq import heappop, heappush, heapify
import array
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy as dcopy
import itertools
# }}}

# pre-defined{{{
sys.setrecursionlimit(10**7)
INF = 10**20
GOSA = 1.0 / 10**10
MOD = 10**9+7
ALPHABETS = [chr(i) for i in range(ord('a'), ord('z')+1)]  # can also use string module
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def DP(N, M, first): return [[first] * M for n in range(N)]
def DP3(N, M, L, first): return [[[first] * L for n in range(M)] for _ in range(N)]
from inspect import currentframe
# }}}

def local_input():# {{{
    from pcm.utils import set_stdin
    import sys
    from pathlib import Path
    parentdir = Path(os.path.dirname(__file__)).parent
    inputfile = parentdir.joinpath('test/sample-1.in')
    if len(sys.argv) == 1:
        set_stdin(inputfile)
# }}}

def solve():
    l,r = map(int,input().split())
    if r-l > 2019:
        print(0)
    else:
        c = 2018
        for i in range(l,r+1):
            for j in range(i+1,r+1):
                c = min(c,(i*j % 2019))
        print(c)
    
    return 0

if __name__ == "__main__":# {{{
    try:
        local_input()
        def dump(*args):
            names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
            print(', '.join(names.get(id(arg),'???')+' => '+repr(arg) for arg in args), file=sys.stderr)
    except:
        def dump(*args):
            pass

    solve()

# vim: set foldmethod=marker:}}}


Measured memory_bytes: 103148
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long x;
  cin>>x;
  while(1){
    bool ok=true;
    for(int i=2;i<x;i++){
      if(x%i==0){
        ok=false;
        break;
      }
    }
    if(ok)break;
    x++;
  }
  cout<<x<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int w = sc.nextInt();
	int h = sc.nextInt();
	int n = sc.nextInt();
	int[] x = new int[n];
	int[] y = new int[n];
	int[] a = new int[n];
	for(int i=0; i<n; i++) {
		x[i] = sc.nextInt();
		y[i] = sc.nextInt();
		a[i] = sc.nextInt();
	}
	int[] xmax = new int[n];
	int[] xmin = new int[n];
	int[] ymax = new int[n];
	int[] ymin = new int[n];
	int j = 0;
	int k = 0;
	int l = 0;
	int m = 0;
	for(int i=0; i<n; i++) {
		switch(a[i]) {
		case 1:
			xmax[j] = x[i];
			j++;
			break;
		case 2:
			xmin[k] = x[i];
			k++;
			break;
		case 3:
			ymax[l] = y[i];
			l++;
			break;
		case 4:
			ymin[m] = y[i];
			m++;
			break;
		}
	}
	int x1 = 0;
	int x2 = w;
	int y1 = 0;
	int y2 = h;
	for(int i=0; i<j; i++) {
		x1 = Math.max(x1, xmax[i]);
	}
	for(int i=0; i<k; i++) {
		x2 = Math.min(x2, xmin[i]);
	}
	for(int i=0; i<l; i++) {
		y1 = Math.max(y1, ymax[i]);
	}
	for(int i=0; i<m; i++) {
		y2 = Math.min(y2, ymin[i]);
	}
	if(x2-x1 > 0 && (x2-x1)*(y2-y1) > 0) {
		System.out.println((x2-x1)*(y2-y1));
	} else {
		System.out.println(0);
	}
}
}


Measured memory_bytes: 21972
f=lambda:map(int,input().split())
h,w,m=f()
l,H,W=[],[0]*-~h,[0]*-~w
for _ in range(m):
  x,y=f()
  l+=[(x,y)]
  H[x]+=1
  W[y]+=1
s,t=max(H),max(W)
print(s+t-(H.count(s)*W.count(t)==sum(H[x]+W[y]==s+t for x,y in l)))

Measured memory_bytes: 54156
#include <cstdio>

int main(void) {
	while(true) {
		int n;
		scanf("%d", &n);
		if(n == 0)
			break;
		int scorea = 0, scoreb = 0;
		for(int i = 0; i < n; i++) {
			int a, b;
			scanf("%d %d", &a, &b);
			if (a > b)
				scorea += a + b;
			else if (a < b)
				scoreb += a + b;
			else {
				scorea += a;
				scoreb += b;
			}
		}
		printf("%d %d\n", scorea, scoreb);
	}
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
int main(int argc, char const *argv[]){
	int a=0,b,c,d,e;
	scanf("%d",&a);
	b=a%10;
	c=(a%100-b)/10;
	d=(a%1000-b-c*10)/100;
	e=a/1000;
	if((b==c&&c==d)||(c==d&&d==e))
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}

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

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

using namespace std;
using ll = long long;

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

    vector<int> z(N);
    vector<int> w(N);
    for (int i = 0; i < N; i++) {
        int x, y;
        cin >> x >> y;
        z[i] = x + y;
        w[i] = x - y;
    }
    sort(z.begin(), z.end());
    sort(w.begin(), w.end());

    // for (int i = 0; i < N; i++) {
    // cout << z[i] << " " << w[i] << endl;
    // }
    cout << max(abs(z[0] - z[N - 1]), abs(w[0] - w[N - 1])) << endl;

    return 0;
}


Measured memory_bytes: 4832
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//#include <math.h>
#include <algorithm>
//#include <vector> 

int main(int argc, char* argv[])
{
	long n, m, x, y;
    scanf("%ld %ld %ld %ld", &n, &m, &x, &y);

    long i;
    for(i=0; i<n; i++) {
        long xx;
        scanf("%ld", &xx);
        if(x < xx) {
            x = xx;
        }
    }
    for(i=0; i<m; i++) {
        long yy;
        scanf("%ld", &yy);
        if(y > yy) {
            y = yy;
        }
    }
    if(x < y) {
        printf("No War\n");
    }
    else {
        printf("War\n");
    }

    return 0;
}

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

typedef long long ll;
const int N = 100000 + 10;
const int M = 1000000007;
const double PI = acos(-1);
const int oo = 1000000000;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ll> row; 
typedef	vector<row> matrix; 
#define pb push_back
#define all(c) (c).begin(),(c).end() 

matrix mat ;

matrix zero(int n , int m ) {

	return matrix(n , row(m , 0)) ; 
}

matrix identity(int n){ 
	
	matrix ret = zero(n , n) ;

	for (int i=0 ; i<n ; ++i) 
		ret[i][i] = 1;

	return ret ;
}

matrix multiply(const matrix &a , const matrix &b){ // n^3
	
	matrix ret = zero(a.size()  ,b[0].size()) ; 

	for (int i =0 ; i<a.size() ; ++i) {
		for (int k = 0 ; k<a[0].size() ; ++k) {
			if (!a[i][k])continue;

			for (int j = 0 ; j<b[0].size() ; ++j){
				ret[i][j] = (1ll*ret[i][j] +  1ll*a[i][k] * 1ll*b[k][j])%M ; 
			}
		}
	}
	return ret ; 
}

matrix Pow(const matrix &a ,  ll k ){ // n^3 * logn
	if (k == 0)
			return identity(a.size()) ; 
	if (k&1)
		return multiply(a , Pow(a , 1ll*k-1)) ; 

	return Pow(multiply(a , a) , 1ll*k/2) ; 
}

int main() {
	
	int n  ;
	ll k  ;
 	scanf("%d %lld" , &n , &k) ; 
 	mat = zero(n , n) ; 
	for (int i =0 ; i<n ; ++i) {
		for (int j = 0 ; j<n ; ++j) {
			int x ; 
			scanf("%d" , &x) ; 
			mat[i][j] = x ; 
		}
	}
	
	mat = Pow(mat , k) ; 
	ll ans = 0 ; 
	for (int i =0 ; i<n ; ++i){
		for (int j = 0 ; j<n ; ++j)
			ans = (ans%M + mat[i][j]%M ) %M;
	}
	printf("%lld\n" , ans%M) ; 
 	return 0;
}

Measured memory_bytes: 1664
#include <iostream>

using namespace std;

int main(void){
  int s;
  int h,m,sec;

  cin >> s;
  sec=s%60;  s=s/60;
  m=s%60;  s=s/60;
  h=s%60;
  cout << h << ':' << m << ':' << sec << endl;
}

Measured memory_bytes: 1160
s = input()
n = len(s)

L = [0] * (n+1)
cnt = 0
for i in range(n) :
    if s[i:(i+1)] == '<' :
        cnt += 1
        L[i + 1] = max(L[i + 1], cnt)
    else :
        cnt = 0

cnt = 0
for i in range(n-1,-1,-1) :
    if s[i:(i+1)] == '>' :
        cnt += 1
        L[i] = max(L[i], cnt)
    else :
        cnt = 0

res = 0
#print(" ".join(str(l) for l in L))
for l in L :
    res += l
print(res)


Measured memory_bytes: 23376
#include <iostream>

using namespace std;

long long int N, p[100001] = {}, num = 0;
bool flag[100001] = {};

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> p[i];
		if (p[i] == i) {
			num++;
			flag[i] = true;
			if (flag[i - 1]) {
				num--;
				flag[i] = false;
			}
		}
	}
	cout << num << endl;
	return 0;
}

Measured memory_bytes: 1152
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class D
{
	public static void Main() => (new Solver()).Solve();
}

public class Solver
{
	public void Solve()
	{
		long X = GetLong();
		for(long A = -127; A < 128; A++)
		{
			for(long B = -127; B < 128; B++)
			{
				if(A * A * A * A * A - B * B * B * B * B == X)
				{
					WriteLine($"{A} {B}");
					return;
				}
			}
		}
	}
}

public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => Enumerable.Range(0, (int)N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(long N) => Enumerable.Range(0, (int)N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDouble()).ToArray();
	public static decimal[] GetDecimals(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDecimal()).ToArray();
	public static string[] GetStrings(long N) => Enumerable.Range(0, (int)N).Select(_ => GetString()).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) < 0)
			x = y;
	}

	public static void chmin<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) > 0)
			x = y;
	}

	public static void swap<T>(ref T x, ref T y)
	{
		T tmp = x;
		x = y;
		y = tmp;
	}
}

Measured memory_bytes: 27484
n, m = map(int, input().split())
g = [set() for _ in range(n)]

for i in range(m):
  a, b = map(int, input().split())
  g[a-1].add(b)
  g[b-1].add(a)

from collections import deque

s = [0 for _ in range(n)]
seen = [False for _ in range(n)]
seen[0] = True
queue = deque([1])
while queue:
    now = queue.popleft()
    for i in g[now-1]:
      if(not seen[i-1]):
        seen[i-1] = True
        s[i-1] = now
        queue.append(i)
s = s[1:]
if(0 in s):
  print("No")
else:
  print("Yes")
  for s_i in s:
    print(s_i)

Measured memory_bytes: 64148
#include<stdio.h>

int main(void){
    int n,i,j,num;
    char a,S[4]={'S','H','C','D'};
    int cards[4][13];

    for(i=0;i<4;i++){
        for(j=0;j<13;j++){
            cards[i][j]=0;
        }
    }

    scanf("%d",&n);

    for(i=0;i<n;i++){
        scanf("%*c%c %d",&a,&num);
        switch (a){
            case 'S':
                cards[0][num-1]=1;
                break;
            case 'H':
                cards[1][num-1]=1;
                break;
            case 'C':
                cards[2][num-1]=1;
                break;
            case 'D':
                cards[3][num-1]=1;
                break;
        }
    }

    for(i=0;i<4;i++){
        for(j=0;j<13;j++){
            if(cards[i][j]==0) printf("%c %d\n",S[i],j+1);
        }
    }
    return 0;
}


Measured memory_bytes: 2104
/* imports all std modules {{{*/
import
  std.algorithm,
  std.array,
  std.ascii,
  std.base64,
  std.bigint,
  std.bitmanip,
  std.compiler,
  std.complex,
  std.concurrency,
  std.container,
  std.conv,
  std.csv,
  std.datetime,
  std.demangle,
  std.encoding,
  std.exception,
  std.file,
  std.format,
  std.functional,
  std.getopt,
  std.json,
  std.math,
  std.mathspecial,
  std.meta,
  std.mmfile,
  std.net.curl,
  std.net.isemail,
  std.numeric,
  std.parallelism,
  std.path,
  std.process,
  std.random,
  std.range,
  std.regex,
  std.signals,
  std.socket,
  std.stdint,
  std.stdio,
  std.string,
  std.system,
  std.traits,
  std.typecons,
  std.uni,
  std.uri,
  std.utf,
  std.uuid,
  std.variant,
  std.zip,
  std.zlib;
/*}}}*/

/+---test
3 2
5 1 4
2 3
1 5
---+/
/+---test
10 3
1 8 5 7 100 4 52 33 13 5
3 10
4 30
1 4
---+/
/+---test
3 2
100 100 100
3 99
3 99
---+/
/+---test
11 3
1 1 1 1 1 1 1 1 1 1 1
3 1000000000
4 1000000000
3 1000000000
---+/

void main(string[] args) {
  long N, M;
  readf(" %d %d ", &N, &M);

  auto A = readln.split.map!(to!long).array.sort!"a < b".array;

  auto op = new long[][](M, 2);
  foreach (ref o; op) {
    readf(" %d %d ", &o[0], &o[1]);
  }
  op = op.sort!"a[1] > b[1]".array;

  auto resa = appender!(long[]);
  resa.reserve(N);
A:foreach (o; op) foreach (i; 0..o[0]) {
    resa ~= o[1];
    if (resa.data.length >= N) break A;
  }

  long ans;
  foreach (a; zip(resa.data.chain([0].cycle), A)) {
    ans += max(a[0], a[1]);
  }
  ans.writeln;
}


Measured memory_bytes: 15272
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long int ll;
typedef vector<ll> Vl;
typedef vector<int> Vi;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pl;

#define MOD   (1000000000 + 7)
#define MAX_N (1000000000000000000)

ll N;
map<Pl, ll> MAP;

ll func(ll S, ll X) {
//  printf("%lld, %lld\n", S, X);
  if (S < 0) return 0;
  if (S < 1) return 1;
  Pl p = Pl(S, X);
  if (MAP[p] > 0) return MAP[p];
  ll val = func(S / 2, X / 2) % MOD;
  val = (val + func((S - 1) / 2, X / 2)) % MOD;
  if (S > 1) val = (val + func((S - 2) / 2, X / 2)) % MOD;
  return MAP[p] = val;
}

void solve() {
  printf("%lld\n", func(N, N));
}

int main() {
  scanf("%lld", &N);

  solve();

  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
const int N=605;
int vis[N][N],a[N][N],d1,d2,n,c1,c2;
int fx[4][2],v,cnt[4],q1;
void make(int c1){
	memset(fx,0,sizeof fx);
	if (c1&1){
		fx[0][0]=1<<(c1/2);
		fx[0][1]=1<<(c1/2);
	}
	else fx[0][0]=1<<(c1/2);
	for (int i=1;i<=3;i++){
		fx[i][0]=-fx[i-1][1];
		fx[i][1]=fx[i-1][0];
	}
}
int inmap(int x,int y){
	return (0<=x&&x<2*n)&&(0<=y&&y<2*n);
}
void dfs(int x,int y,int z){
	a[x][y]+=z*v;
	vis[x][y]=1;
	for (int i=0;i<4;i++){
		int xx=x+fx[i][0],yy=y+fx[i][1];
		if (inmap(xx,yy)){
			if (!vis[xx][yy])
				dfs(xx,yy,z^1);
		}
	}
}
int main(){
	cin>>n>>d1>>d2;
	while (d1%2==0)c1++,d1/=2;
	while (d2%2==0)c2++,d2/=2;
	make(c1);v=1;
	for (int i=0;i<2*n;i++)
	for (int j=0;j<2*n;j++)
		if (!vis[i][j])dfs(i,j,0);
	make(c2);v=2;
	memset(vis,0,sizeof vis);
	for (int i=0;i<2*n;i++)
	for (int j=0;j<2*n;j++)
		if (!vis[i][j])dfs(i,j,0);	
	for (int i=0;i<2*n;i++)
	for (int j=0;j<2*n;j++)
		cnt[a[i][j]]++;
	for (int i=0;i<4;i++)
		if (cnt[i]>=n*n)q1=i;
	int ccnt=0;
	for (int i=0;i<2*n;i++)
	for (int j=0;j<2*n;j++){
		if (a[i][j]==q1){
			ccnt++;
			printf("%d %d\n",i,j);
			if (ccnt==n*n)return 0;
		}
	}
}

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

int main() {
  int K,X;
  cin >> K >> X;
  for( int i = 1; i <= K; i++ ){
    cout << X - ( K - i ) << " ";
  }
  for( int i = 1; i < K; i++ ){
    cout << X + i << " ";
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>

#define rep(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)

#define INF 100000000

typedef  long long ll;

using namespace std;

double euclid_distance(double a,double b){
    return sqrt(a*a+b*b);
}

int gcd(long long int a,long long int b){
    long long int r;
    if(a < b){
        int tmp;
        tmp = a;
        a = b;
        b = tmp;
    }
    while(r != 0){
        r = a % b;
        a = b;
        b = r;
    }
    return r;
}

void Integer_factorization(long long int b,long long int n){
    long long int a = 2;
    long long int count = 0;
    long long int ans = 1;
    long long int ndash = n;
    if(b == 1) cout << n << endl;
    else{
    while(ndash >= a*a){
        if(n % a  == 0){
            count++;
            n/=a;

        if(count % b == 0){
            ans *= a;
        }
        }else{a++;count = 0;}
    }

    cout<<  ans << endl;
    }
}

void ys(){
    cout << "Yes" << endl;
}

void yb(){
    cout << "YES" << endl;
}

void ns(){
    cout << "No" << endl;
}

void nb(){
    cout << "NO" << endl;
}


void solve(void){
    int a,b,c;
    cin >> a >> b >> c;
    if(a == b && b == c)ys();
    else ns();
}

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


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


long solve(long n, long acc) {
  if (n < 0) {
    return -1;
  }

  if (acc > 0) {
    return solve(n - 1, acc - n);
  } else if (acc < 0) {
    return solve(n - 1, acc + n);
  } else {
    return 0;
  }
}
int main() {
  long X;
  cin >> X;

  long acc = 0;
  int i;
  for (i = 1; acc < X; i++) {
    acc += i;
  }

  i--;
  while(1) {
    if (solve(i, X) == 0) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  if(a < b)swap(a,b);
  long long int r=a%b;
  while(r!=0){
    a=b;
    b=r;
    r=a%b;
  }
  return b;
}
long long int lcm(long long int a, long long int b){
  return a/gcd(a,b)*b;
}
int main(){
	int n;
  cin >>n;
  long long int l[n],ans=1;
  for(int i=0;i<n;i++)cin >> l[i];
  ans=l[0];
  for(int i=1;i<n;i++)ans=lcm(ans,l[i]);
  cout << ans <<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	
    public void solve(){
		Scanner sc=new Scanner(System.in);
		int niti,nyuryo,puluryo,nyumai,pulumai,nyukei,pulukei,goukei;
		niti=sc.nextInt();
		for(int i=0; i<niti; i++){
		
		nyuryo=sc.nextInt();
		puluryo=sc.nextInt();
		nyumai=sc.nextInt();
		pulumai=sc.nextInt();
		nyukei=nyuryo*nyumai;
		pulukei=puluryo*pulumai;
		goukei=nyukei+pulukei;
		if(nyumai<=5){
			nyumai=5;
		}
		if(pulumai<=2){
			pulumai=2;
		}
		nyukei=nyuryo*nyumai;
		pulukei=puluryo*pulumai;
		int goukei2=nyukei+pulukei;
		goukei2=goukei2*4/5;
		if(goukei>goukei2 ){
			System.out.println(goukei2);
			}else{
				System.out.println(goukei);
			}
		}
    }

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

Measured memory_bytes: 23420
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N, M = map(int, input().split())
uf = UnionFind(N)
for _ in range(M):
    X, Y, Z = map(lambda x: int(x)-1, input().split())
    uf.union(X, Y)
ans = [uf.find(x) for x in uf.roots()]
print(len(set(ans)))

Measured memory_bytes: 20480
#include"bits/stdc++.h"
using namespace std;
#define rep(i, N) for(int i=0; i<N; ++i)
using ul = unsigned long;
using ll = long long;

struct Node {
    int key;
    Node *prev, *next;
};

Node* nil;

void init() {
    nil = new Node();
    nil->next = nil;
    nil->prev = nil;
}

void printList() {
    Node *cur = nil->next;
    bool isFirst = true;
    while (cur != nil) {
        if (!isFirst) {
            cout << " ";
        } else isFirst = false;
        cout << cur->key;
        cur = cur->next;
    }
    cout << "\n";
}

void insert(int key) {
    Node* node = new Node();
    node->key = key;
    node->next = nil->next;
    nil->next->prev = node;
    nil->next = node;
    node->prev = nil;
}

Node* listSearch(int key) {
    Node* cur = nil->next;
    while ( cur != nil && cur->key != key ) {
        cur = cur->next;
    }
    return cur;
}

void deleteNode(Node *t) {
    if (t == nil) return;
    t->prev->next = t->next;
    t->next->prev = t->prev;
    delete t;
}

void deleteFirst() {
    deleteNode(nil->next);
}

void deleteLast() {
    deleteNode(nil->prev);
}

void deleteKey(int key) {
    deleteNode(listSearch(key));
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    string s;
    int x;
    init();
    rep(i, n) {
        cin >> s;
        if (s == "insert") {
            cin >> x;
            insert(x);
        }
        else if (s == "delete") {
            cin >> x;
            deleteKey(x);
        }
        else if (s == "deleteFirst") deleteFirst();
        else if (s == "deleteLast") deleteLast();
    }
    printList();
}



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

#define int long long

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

int a, b;

signed main() {
    cin >> a >> b;
    if (a * b % 2 == 1) {
        cout << "Odd" << endl;
    } else {
        cout << "Even" << endl;
    }
    return 0;
}


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

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

	vector<int> V;
	vector<int> C;
	for (int i = 0; i < N; i++) {
		int v;
		cin >> v;
		V.push_back(v);
	}

	for (int i = 0; i < N; i++) {
		int c;
		cin >> c;
		C.push_back(c);
	}


	int total = 0;
	for (int i = 0; i < N; i++) {
		if (V[i] > C[i]) {
			total += (V[i] - C[i]);
		}
	}

	cout << total << endl;

}




Measured memory_bytes: 256
/*
                `-/oo+/-   ``
              .oyhhhhhhyo.`od
             +hhhhyyoooos. h/
            +hhyso++oosy- /s
           .yoooossyyo:``-y`
            ..----.` ``.-/+:.`
                   `````..-::/.
                  `..```.-::///`
                 `-.....--::::/:
                `.......--::////:
               `...`....---:::://:
             `......``..--:::::///:`
            `---.......--:::::////+/`
            ----------::::::/::///++:
            ----:---:::::///////////:`
            .----::::::////////////:-`
            `----::::::::::/::::::::-
             `.-----:::::::::::::::-
               ...----:::::::::/:-`
                 `.---::/+osss+:`
                   ``.:://///-.
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair <int, int>;
using pll = pair <ll, ll>;

template <class T> using Tree = tree <T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

template <typename T>
T Max(T a, T b) {
    if(a < b) return b;
    return a;
}

template <typename T>
T Min(T a, T b) {
    if(a < b) return a;
    return b;
}

template <typename T>
T Abs(T a) {
    if(a < 0) return -a;
    return a;
}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void SetIO() {
#ifdef BLAT
    freopen("input.in", "r", stdin);
    freopen("output.out", "w", stdout);
#endif // BLAT
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

const int MOD = 1e9 + 7;
const int INF = 1e9;
const int N = 2e5;

int v[5 + N];
pair <int, int> vp[5];

int main() {
    SetIO();

    int n;
    cin >> n;

    for(int i = 1; i <= n; i++) cin >> v[i];
    sort(v + 1, v + n + 1);

    if(n % 3) {
        if(v[n] != 0) cout << "No\n";
        else cout << "Yes\n";
    } else {
        int scount(0);
        bool ok;
        for(int i = 1; i <= n; i++) {
            ok = false;
            for(int j = 1; j <= scount; j++) {
                if(vp[j].first == v[i]) {
                    vp[j].second++;
                    ok = true;
                }
            }

            if(ok == false) {
                vp[++scount] = make_pair(v[i], 1);
            }

            if(scount > 3) {
                cout << "No\n";
                i = n + 1;
            }
        }

        if(scount == 3) {
            if(vp[1].second != n / 3 || vp[2].second != n / 3)
                cout << "No\n";
            else if((vp[1].first ^ vp[2].first ^ vp[3].first) == 0) cout << "Yes\n";
            else cout << "No\n";
        } else if(scount == 2) {
            if(vp[1].first == 0 && vp[1].second == n / 3) cout << "Yes\n";
            else cout << "No\n";
        } else if(scount == 1 && vp[1].first == 0) cout << "Yes\n";
        else if(scount == 1) cout << "No\n";
    }
    return 0;
}


Measured memory_bytes: 4040
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
#define int long long
#define str string
#define rep(i,j) for(int i=0;i<(int)(j);i++)
typedef long long ll;
typedef long double ld;
const ll inf = 999999999999999999;
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct S {//辺の情報を入れる変数
	int from, to, cost;
};
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
//---------------------------------------------------
//+++++++++++++++++++++++++++++++++++++++++++++++++++
int x, y, ans=inf;
signed main() {
	cin >> x >> y;
	for (int i = -1; i < 2; i += 2) {
		for (int j = -1; j < 2; j += 2) {
			int a = x*i, b = y*j;
			if (b >= a) 
				ans = min(ans, b - a + (i == -1 ? 1 : 0) + (j == -1 ? 1 : 0));
		}
	}
	cout << ans << endl;
	getchar(); getchar();
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

const ll MOD = 1e9+7;

string S, T;
int n;
int nxt[2005][26], nxt_reverse[2005][26]; // i文字目以降で最初に文字cが登場するidx
ll dp[2005][2005]; //

int main() {
    cin >> S;
    n = S.size();
    T = S;
    reverse(T.begin(), T.end());

    fill(nxt[0], nxt[n+1], n);
    for (int i = n-1; i >= 0; i--) {
        for (int j = 0; j < 26; j++) {
            nxt[i][j] = nxt[i+1][j];
        }
        nxt[i][S[i] - 'a'] = i;
    }

    fill(nxt_reverse[0], nxt_reverse[n+1], n);
    for (int i = n-1; i >= 0; i--) {
        for (int j = 0; j < 26; j++) {
            nxt_reverse[i][j] = nxt_reverse[i+1][j];
        }
        nxt_reverse[i][T[i] - 'a'] = i;
    }

    dp[0][0] = 1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            for (int k = 0; k < 26; k++) {
                int s_idx = nxt[i][k];
                int t_idx = nxt_reverse[j][k];
                if (s_idx + t_idx + 2 > n) continue;
                (dp[s_idx + 1][t_idx + 1] += dp[i][j]) %= MOD;
            }
        }
    }

    ll ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            int cnt = 1;
            for (int k = 0; k < 26; k++) {
                if (nxt[i][k] + 1 + j <= n) {
                    cnt++;
                }
            }
            (ans += dp[i][j] * cnt) %= MOD;
        }
    }

    cout << ans - 1<< "\n";
    return 0;
}


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

int main () {
  int N;
  cin >> N;
  vector <int> num(N);
  for (int i = 0; i < N; i++) cin >> num.at(i);
  int ans = 0; 
  int i2 = 0;
  for (int i = 0; i < N; i++) {
    if (ans < num.at(i)){
      ans = num.at(i);
      i2 = i;
    }
  }
  sort(num.begin(),num.end());
  for (int i = 0; i < N; i++){
    if (i == i2) cout << num.at(N-2) << endl;
    else cout << ans << endl;
  }
}

Measured memory_bytes: 2432
import sys
import os
# import math
import bisect
import collections
import itertools
from fractions import gcd

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

# lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, X = il()
    T = il()
    T = sorted(T + [X])
    ret = abs(T[0] - T[1])
    for i in range(len(T)-1):
        ret = gcd(ret, abs(T[i]-T[i+1]))
    print(ret)


if __name__ == '__main__':
    main()


Measured memory_bytes: 14516
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
#define pb push_back
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
const double PI=acos(-1);

ll cnt = 0;
vector<char> lis = {'3', '5', '7'};

bool cnum(string s){
    bool a=false, b=false, c=false;
    REP(i, s.size()){
        if(s[i] == '3') a = true;
        if(s[i] == '5') b = true;
        if(s[i] == '7') c = true;
    }
    if(a == true && b == true && c == true) return true;
    else return false;
}

void dfs(string s, ll n){
    ll num = stoll(s);
    if(num <= n && cnum(s) == true){
        cnt++;
    }
    if(num > n){
        return;
    }

    for(auto x : lis){
        dfs(s+x, n);
    }
}

void solve(){
    ll n; cin >> n;
    dfs("3", n);
    dfs("5", n);
    dfs("7", n);
    cout << cnt << endl;
}

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

Measured memory_bytes: 256
const input=require('fs').readFileSync('/dev/stdin', 'utf8').split(/[\s]/);const nin=()=>{const r = input[0];input.shift();return Number(r)};const nrin=(n)=>{const a:number[]=[];rep(n,()=>a.push(nin()));return a};const sin=()=>{const r = input[0];input.shift();return String(r)};const out=(...a)=>{console.log(...a)};const floor=(a)=>{return Math.floor(a)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const rep=(n, callback)=>{for(let i = 0;i < n; i++){callback()}};const strrep=(s, i, v)=>{return s.slice(0, i)+v+s.slice(i+1);};const permutation=({result=[],pre=[],post,n=post.length})=>{if(n>0){post.forEach((_,i)=>{const rest=[...post];const elem=rest.splice(i, 1);permutation({result, pre: [...pre,...elem],post:rest,n:n-1})})}else{result.push(pre)}return result};const sw=(s,a:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<a.length;i+=2){if(op==='=='){if(s==a[i])return a[i+1]}else if(op==='>='){if(s>=a[i])return a[i+1]}else if(op==='<='){if(s<=a[i])return a[i+1]}else if(op==='>'){if(s>a[i])return a[i+1]}else if(op==='<'){if(s<a[i])return a[i+1]}}return a[a.length-1];};const or=(a,...b)=>{for(let i=0;i<b.length;i++)if(a==b[i])return true;return false};const maxindex=(...a)=>{return a.indexOf(Math.max.apply(null,a))};const asc=(ar:number[])=>{return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{return ar.sort((a,b)=>{return b-a})};const ceil=a=>{return Math.ceil(a)};const srin=s=>{const a:string[]=[];rep(s,()=>a.push(sin()));return a};let ssinteger=-1;const ssin=()=>{ssinteger++;return input[0][ssinteger]};
const main = ()=>{
  let [a,b]=nrin(2)
  out(max(a+b,a-b,a*b)+0)
}
main()

Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
long long n,m,a,num;
int main(){
	cin>>n>>m;
	for (int i=0;i<m;i++){
		cin>>a;
		num+=a;
	}
	if (num>n)
		cout<<-1<<endl;
	else
		cout<<n-num<<endl;
	return 0;
}

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

 using namespace std;
 typedef long long ll;

 int main() {
   int M, D, ans = 0;

   cin >> M >> D;

   for (int d = 10; d <= D; d++) {
     for (int m = 1; m <= M; m++) {
        if (d % 10 > 1 && d / 10 > 1 && (d % 10) * (d / 10) == m) ans++;
     }
   }
   cout << ans << endl;
 }


Measured memory_bytes: 256