akhauriyash/Code-Regression huggingface dataset:
import std;

alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
//aryread!string();
void main()
{
    auto st = aryread!string();
    // writeln(st);
    long a, b;
    scan(a, b);
    auto u = sread();
    // writeln(u);
    if (u == st[0])
    {
        writeln(a - 1, ' ', b);
    }
    else if (u == st[1])
    {
        writeln(a, ' ', b - 1);
    }

}

void scan(L...)(ref L A)
{
    auto l = readln.split;
    foreach (i, T; L)
    {
        A[i] = l[i].to!T;
    }
}

void arywrite(T)(T a)
{
    a.map!text.join(' ').writeln;
}


Measured memory_bytes: 3612
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// const ll INF = 1LL <<60;
// const int INF = 10000;

//最大公約数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

const int MAX = 1e6+1;
const int MOD = 1e9+7;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}

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

//sieve(MAX);でベクトルIsPrimeに「MAXまでの数値の素数の真偽」を格納する。
vector<bool> IsPrime;
void sieve(size_t max){
    if(max+1 > IsPrime.size()){     // resizeで要素数が減らないように
        IsPrime.resize(max+1,true); // IsPrimeに必要な要素数を確保
    } 
    IsPrime[0] = false; // 0は素数ではない
    IsPrime[1] = false; // 1は素数ではない

    for(size_t i=2; i*i<=max; ++i) // 0からsqrt(max)まで調べる
        if(IsPrime[i]) // iが素数ならば
            for(size_t j=2; i*j<=max; ++j) // (max以下の)iの倍数は
                IsPrime[i*j] = false;      // 素数ではない
}
// ここから開始
int main(){
  int a,b;
  cin>>a>>b;
  cout<<lcm(a,b)<<endl;
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rp(i,n) for(int i=0; i<n; i++)
using namespace std;
using ll=long long;
using P=pair<int,int>;
using G=vector<vector<int>>;

int main(){
    int n,k;
    cin >> n >> k;
    ll sum=0ll;
    for(int i=n+1; i>=k;i--){
        sum += (ll) i*(n*2-i+1)/2-(ll)i*(i-1)/2+(ll)1;
    }
    sum %= 1000000007;
    cout << sum << endl;
    return 0;
}

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

using namespace std;
#define For(i,l,r) for (int i = l; i <= r; ++i)

string s;
int main() {
	cin >> s;
	For(i,0,11) {
		putchar(s[i]);
		if (i == 3) putchar(' ');
	}
	puts("");
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  string s;
  cin >> s;
  bool sysflag = false;

  if(s[0]=='A')
    sysflag = true;

  ll count = 0;
  bool sysflag2 = true;
  REP(i, s.size()){
    if(3 <= i+1 && i+1 <= s.size()-1 && s[i]=='C')
      count++;
    else if('A' <= s[i] && s[i] <= 'Z' && i != 0)
      sysflag2 = false;
  }

  if(sysflag && sysflag2 && count == 1)
    cout << "AC" << endl;
  else
    cout << "WA" << endl;
  
}


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


int main() {
    int N, M;
    cin >> N >> M;
    vector<int> L(M), R(M);
    rep(i,M) cin >> L.at(i) >> R.at(i);
    sort(L.begin(), L.end(), greater<int>());
    sort(R.begin(), R.end());
    cout << max(0, R.at(0) - L.at(0) + 1) << endl;
}


Measured memory_bytes: 4024
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const long Mod = 1000000007;

    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
        //MyDebugger.Test(process, "../TextFile2.txt");
        //MyDebugger.MakeTestCase("../TextFile2.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var spl = input.ReadLine().Split(' ');
        var n = int.Parse(spl[0]);
        var m = int.Parse(spl[1]);
        var q = int.Parse(spl[2]);

        var AA = new List<int[]>();
        for (int i = 0; i < q; i++) {
            var ary = ToIntArray(input.ReadLine(), 4);
            AA.Add(ary);
        }

        Func<int[], long> count = (A) => {
            long sum = 0;
            foreach(var aa in AA) {
                var ai = aa[0] - 1;
                var bi = aa[1] - 1;
                var ci = aa[2];
                var di = (long)aa[3];
                sum += (A[bi] - A[ai] == ci ? di : 0);
            }
            return sum;
        };

        int[] tmp = new int[10];
        long max = 0;
        
        for(tmp[0]=     1; tmp[0]<=m; tmp[0]++)  
        for(tmp[1]=tmp[0]; tmp[1]<=m; tmp[1]++)  
        for(tmp[2]=tmp[1]; tmp[2]<=m; tmp[2]++)  
        for(tmp[3]=tmp[2]; tmp[3]<=m; tmp[3]++)  
        for(tmp[4]=tmp[3]; tmp[4]<=m; tmp[4]++)  
        for(tmp[5]=tmp[4]; tmp[5]<=m; tmp[5]++)  
        for(tmp[6]=tmp[5]; tmp[6]<=m; tmp[6]++)  
        for(tmp[7]=tmp[6]; tmp[7]<=m; tmp[7]++)  
        for(tmp[8]=tmp[7]; tmp[8]<=m; tmp[8]++)  
        for(tmp[9]=tmp[8]; tmp[9]<=m; tmp[9]++)
        {
            //print(tmp);
            var sum = count(tmp);
            max = Math.Max(max, sum);
        }

        return max;
    }

    static void print(int[] A) {
        var buil = new StringBuilder();
        foreach (var i in A) {
            buil.Append(i);
            buil.Append(',');
        }
        Debug.WriteLine(buil.ToString());
    }

    static int[] ToIntArray(string strs, int n) {
        var ret = new int[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = int.Parse(spl[i]);
        return ret;
    }
}


Measured memory_bytes: 27628
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
#include<set>
#include<queue>
#include<cmath>

using namespace std;

#define INF 10000000000007
#define XX first.first
#define YY first.second
#define RR second

vector<vector<long double> > dist;

long long n;
vector<long double> d;
vector<bool> done;

void dijk(long long s,long long g)
{
	done=vector<bool>(n+2,false);
	d[s]=0;
	while(true)
	{
		long double mn=INF;
		long long nx=-1;
		for(long long i=0;i<n+2;i++)
		{
			if(done[i]!=true)
			{
				if(mn>d[i])
				{
					mn=d[i];
					nx=i;
				}
			}
		}
		if(nx==-1)break;
		done[nx]=true;
		for(long long i=0;i<n+2;i++)
		{
			long double dnx=d[nx]+dist[i][nx];
			if(d[i]>dnx)
				d[i]=dnx;
		}
	}
}

int main()
{
	long long xs,ys,xt,yt;
	cin >> xs >> ys >> xt >> yt;
	cin >> n;
	vector<pair<pair<long long,long long>,long long> > p(n+2);
	p[0]=make_pair(make_pair(xs,ys),0);
	p[n+1]=make_pair(make_pair(xt,yt),0);
	for(long long i=1;i<=n;i++)
	{
		long long x,y,r;
		cin >> x >> y >> r;
		p[i]=make_pair(make_pair(x,y),r);
	}

	dist=vector<vector<long double> >(n+2,vector<long double>(n+2,INF));

	for(long long i=0;i<n+2;i++)
		for(long long j=0;j<n+2;j++)
		{
			dist[i][j]=sqrt((p[i].XX-p[j].XX)*(p[i].XX-p[j].XX)+(p[i].YY-p[j].YY)*(p[i].YY-p[j].YY))-p[i].RR-p[j].RR;
			if(dist[i][j]<0)
				dist[i][j]=0;
		}

	d=vector<long double>(n+2,INF);
	d[0]=0;


	dijk(0,n+1);

	for(long long i=0;i<n+2;i++)
		cerr << i << " : " << d[i] << endl;
	cout << setprecision(16) <<  d[n+1] << endl;
}

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

int main() {
  int n,m;
  cin>>n>>m;
  if(n%3==0 || m%3==0 || (n+m)%3==0) cout<<"Possible"<<endl;
  else cout<<"Impossible"<<endl;
  return 0;
}


Measured memory_bytes: 256
//default
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define answer cout << ans << endl;
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
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; }
template<class T> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const int MOD=1e9+7;
const long long INF = 1LL << 60;

signed _main(){
  string S_,T; cin >> S_ >> T;
  v<string> ans;
  rep(i,S_.size()){
    bool flag=false;
    if(i+T.size()>S_.size()) break;
    for(int j=i;j<i+T.size();j++){
      if(S_[j]=='?' || S_[j]==T[j-i]);
      else{
        flag=true;
        break;
      }
    }
    if(flag) continue;
    string S="";
    rep(j,S_.size()){
      if(j>=i && j<i+T.size()) S=S+T[j-i];
      else if(S_[j]=='?') S=S+'a';
      else S=S+S_[j];
    }
    //cout << S << endl;
    ans.push_back(S);
  }
  sort(ans.begin(),ans.end());
  if(ans.size()==0) cout << "UNRESTORABLE" << endl;
  else cout << ans[0] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>


unsigned long long MAX;


int main()
{
	FILE *fp;
	char file_name[30];

	char in[30];
	char c;
	unsigned long long BALL_BOX[100000];
	unsigned long long K;
	unsigned long long x, y, bk, remainder;
	int N;
	int i;

/*
	printf("読み込むファイル名を入力して下さい。\n");
	fgets(in, sizeof(in), stdin);
	in[strlen(in) - 1] = '\0';
	sprintf(file_name, "%s", in);

	if( (fp = fopen(file_name, "r")) == NULL){
		printf("file open error\n");
		exit(1);
	}
*/
	fgets(in, sizeof(in), stdin);
	sscanf(in, "%d %lld", &N, &K);

	i = MAX = 0;
	while((c = getc(stdin)) && i < N){
		if(isdigit(c)){
			ungetc(c, stdin);
			fscanf(stdin, "%lld", &BALL_BOX[i]);
			if(BALL_BOX[i] > MAX)
				MAX = BALL_BOX[i];
			i++;
		}
	}

//	fclose(fp);

	if(N == 1){
		if(BALL_BOX[0] == K)
			printf("POSSIBLE\n");
		else
			printf("IMPOSSIBLE\n");
		return 0;
	}

	// 最大公約数を求める
	for(i = 0; i < N - 1; i++){
		if(i == 0)
			x = BALL_BOX[i];

		y = BALL_BOX[i + 1];

		if(x < y){
			bk = x;
			x = y;
			y = bk;
		}

		// ユークリッド互除法
		while( (remainder = x % y) != 0){
			x = y;
			y = remainder;
		}

		x = y;
	}

/*
	printf("MAX = %lld\n", MAX);
	for(i = 0; i < N; i++){
		printf("%lld ", BALL_BOX[i]);
	}
	printf("\n");
*/


	if(K % x == 0 && K <= MAX)
		printf("POSSIBLE\n");
	else
		printf("IMPOSSIBLE\n");


	return 0;
}

Measured memory_bytes: 896
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	a := getNextInt(scanner)
	b := getNextInt(scanner)
	c := getNextInt(scanner)

	ans:=c-(a-b)

	if ans<0{
		ans=0
	}
	fmt.Fprintln(writer, ans)

	writer.Flush()
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#define rep0(i,n) for (int i = 0; i <= (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)
using namespace std;
int main() {
	int n;
	int s = -1;
	cin >> n;
	vector<int>a(n);
	rep0(i, n - 1) {
		cin >> a[i];
	}
	rep0(k, n - 1) {
		if (s < a[k])
			s = a[k] - 1;
		else if (s == a[k])
			s = a[k];
		else {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 640
n=int(input())
h=list(map(int,input().split()))

dp=[-1]*n
dp[0]=0
dp[1]=abs(h[1]-h[0])

for i in range(2,n):
    dp[i]=min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]))
print(dp[-1])

Measured memory_bytes: 13928
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
#define ll long long
#define FOR(i, n, m) for(int i=n; i<m; ++i)

int main(){
  int x[4], y[4];
  cin >> x[0] >> y[0] >> x[1] >> y[1];
  int dif_x, dif_y;
  
  dif_x = x[1] - x[0];
  dif_y = y[1] - y[0];
  
  /*if(dif_x*dif_y>=0){
    x[2] = x[1] - dif_y;
    x[2] = y[1] + dif_x;
    x[3] = x[0] - dif_y;
    x[3] = y[0] + dif_x;
  }else{
    x[2] = x[1] - dif_y;
    x[2] = y[1] + dif_x;
    x[3] = x[0] - dif_y;
    x[3] = y[0] + dif_x;    
  }*/
  
  cout << x[1]-dif_y <<" " << y[1]+dif_x <<" " << x[0]-dif_y <<" " << y[0]+dif_x << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
using namespace std;
const int MAXN=505;
int n,m,k,cnt=0;
int mp[MAXN][MAXN],add[MAXN][MAXN];
struct ans{
	int sx,sy,ex,ey;
	ans(int ssx=0,int ssy=0,int eex=0,int eey=0){
		sx=ssx;sy=ssy;ex=eex;ey=eey;
	}
}arr[MAXN];
int read(){
	int x=0,f=1;char c=getchar();
	for(;c<'0'||c>'9';c=getchar()) if(c=='-') f=-1;
	for(;c>='0'&&c<='9';c=getchar()) x=(x<<3)+(x<<1)+c-'0';
	return x*f;
}
int main(){
	n=read();m=read();
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)
			mp[i][j]=read();
	for(int i=1;i<n;++i)
		for(int j=1;j<=m;++j)
			if(mp[i][j]&1){
				mp[i+1][j]+=mp[i][j];
				arr[++cnt]=ans(i,j,i+1,j);
			}
	for(int i=1;i<m;++i)
		if(mp[n][i]&1){
			mp[n][i+1]+=mp[n][i];
			arr[++cnt]=ans(n,i,n,i+1);
		}
	printf("%d\n",cnt);
	for(int i=1;i<=cnt;++i)
		printf("%d %d %d %d\n",arr[i].sx,arr[i].sy,arr[i].ex,arr[i].ey);
	return 0;
}

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

// int/long:		-2,147,483,648 - 2,147,483,648 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<29)
//536,870,912

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

#define	MOD 1000000007

int	main() {
	int N;
	cin >>N;
	N +=N;
	vector<int> L(N, 0);
	for (int i=0; i<N; i++)
		cin >>L.at(i);
	sort(L.begin(), L.end());
	int S=0;
	for (int i=0; i<N; i +=2)
		S +=L.at(i);
	cout <<S <<endl;
	return 0;
}



Measured memory_bytes: 256
import Control.Applicative

main = do
    ss <- words <$>getLine
    let a:b:_ = [read x| x<- ss] ::[Int]
    if a==0 then return ()
    else do
      let o = (take b (repeat '#')) ++ "\n" ++ concat[x++"\n" | x<-(take (a-2) (repeat("#" ++ take (b-2) (repeat '.') ++ "#")))] ++ (take b (repeat '#')) ++ "\n"
      putStrLn $ o
      main

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

int main() {
  int a, b , i;
  cin >> a >> b >> i;
  i = a * b;
  if (i % 2 == 0){
  cout << "Even" << endl;
  }
  else{
  cout << "Odd" << endl;
  }
}

Measured memory_bytes: 3628
#include <iostream>

using namespace std;

unsigned long long lucas(int x) {
	unsigned long long temp[87];
	for (int i = 0; i <= x; i++) {
		if (i == 0) temp[0] = 2;
		else if (i == 1) temp[1] = 1;
		else temp[i] = temp[i - 1] + temp[i - 2];
	}
	return temp[x];
}

int main() {
	int x;
	cin >> x;
	cout << lucas(x) << endl;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}
template<class A,size_t N,class T>void Fill(A(&a)[N],const T&v){fill((T*)a,(T*)(a+N),v);}

const int MOD = 1e9+7; //998244353;

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m=MOD){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m=MOD){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int N = 2e5;
int n, a, b;
ll c(int a){
  ll r=1, d=1;
  FOR(i, 0, a){
    r=r*(n-i)%MOD;
    d=d*(i+1)%MOD;
  }
  return r*modInv(d)%MOD;
}
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> a >> b;
  ll ans = modPow(2, n)-1;
  ans -= c(a)+c(b);
  cout << (ans%MOD+MOD)%MOD << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdio>
using namespace std;
vector <int> ami[100][100];
int hi[1000];
int n,m,a,mh;


int kuji(int x,int h) {
  //cout << "start kuji()"<<endl;
  int t;
  int fl = 0;
  int i;
  // cout << "h = "<< h << endl;
  // cout << "x = " << x << endl;
  mh = -1;
  fl == 0;
  
  if(x > 0)
    for(i =0;i<ami[x][x-1].size();i++){
      if(h>= ami[x][x-1][i] && ami[x][x-1][i] > mh){
	fl = 1;
	mh = ami[x][x-1][i];
	t = i;
      }
    }

  
  if(x < n-1) {
    for(i=0;i<ami[x][x+1].size();i++) {
      if(h >= ami[x][x+1][i] && ami[x][x+1][i] > mh) {
	mh = ami[x][x+1][i];
	fl = 2;
	t = i;
      }
    }
  }

  if(fl == 1) {
    ami[x][x-1][t] = h+1;
    ami[x-1][x][t] = h+1;
  }else if(fl == 2)  {
    ami[x][x+1][t] = h+1;
    ami[x+1][x][t] = h+1;
  }
  if(mh == -1) return x;
  
  // printf("mh = %d\n",mh);
  if(fl == 1) kuji(x-1,mh);
  else if(fl == 2) kuji(x+1,mh);
  
  
}	



int main() {
  

  while(1) {
    cin >> n >> m >> a;
    if(n == 0 && m == 0 && a == 0)break;
  
    mh = -1;  
    for(int i=0;i<m;i++) {
      int h,p,q;
      cin >> h >> p >> q;
      if(h == 0 && p == 0 && q ==0) break;
      ami[p-1][q-1].push_back(h);
      ami[q-1][p-1].push_back(h);
      //    cout << ami[q-1][p-1].back() << endl;
      if(mh < h) mh = h;
    }

   
    int ans = 0;
    ans = kuji(a-1,mh);
  
    cout << ans+1 << endl;

    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++){
	ami[i][j].clear();
	//	cout << ami[i][j].size() <<": i, j " <<i <<" "<< j << endl;
      }
  }
  
  return 0;
  
}

Measured memory_bytes: 1512
#include<bits/stdc++.h>
using namespace std;
#define ll        long long
#define  sci(x)   scanf("%d", &x)
#define  scl(x)   scanf("%lld", &x)
#define  scd(x)   scanf("%lf", &x)
#define l0(i,n)   for(ll i=0; i<n; i++)

int main ()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	//CODE TONOY
	int a;
	cin >> a;
	cout <<(ll) 3*a*a << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;

int main() {
  map<char, int> m;
  m['q'] = 0; m['w'] = 0; m['e'] = 0; m['r'] = 0; m['t'] = 0;
  m['a'] = 0; m['s'] = 0; m['d'] = 0; m['f'] = 0; m['g'] = 0;
  m['z'] = 0; m['x'] = 0; m['c'] = 0; m['v'] = 0; m['b'] = 0;
  m['y'] = 1; m['u'] = 1; m['i'] = 1; m['o'] = 1; m['p'] = 1;
  m['h'] = 1; m['j'] = 1; m['k'] = 1; m['l'] = 1;
  m['n'] = 1; m['m'] = 1;
  string s;
  while(cin >>s && s != "#"){
    int t = m[s[0]], ans = 0;
    FOR(i, 1, s.length()){
      if(t != m[s[i]]) ++ans;
      t = m[s[i]];
    }
    cout <<ans <<endl;
  }
  return 0;
}

Measured memory_bytes: 1188
import math

H, W = map(int, input().split())

if H%3 == 0 or W%3 == 0:
    print(0)
else:
    res = 10 ** 11
    for i in range(1, H):
        a = W*i
        b = math.ceil(W/2) * (H-i)
        m = W//2 * (H-i)
        res = min(res, max(a,b,m)-min(a,b,m))

    for i in range(1, W):
        a = H*i
        b = math.ceil(H/2) * (W-i)
        m = H//2 * (W-i)
        res = min(res, max(a,b,m)-min(a,b,m))

    for i in range(1, H-1):
        a = W*i
        b = W * math.ceil((H-i)/2)
        m = W * ((H-i)//2)
        res = min(res, max(a,b,m)-min(a,b,m))

    for i in range(1, W-1):
        a = H*i
        b = H * math.ceil((W-i)/2)
        m = H * ((W-i)//2)
        res = min(res, max(a,b,m)-min(a,b,m))

               
    print(res)

Measured memory_bytes: 3188
#include<stdio.h>
#include<iostream>
using namespace std;


int main(){

  long n,m,i,left;
  long total=0;
  cin>>n>>m;

  long a[m];
  for(i=0; i<m; i++){
    scanf("%ld",&a[i]);
    total=total+a[i];
  }

  left=n-total;

  if(total>n){
    printf("-1\n");
  }else{
    printf("%ld\n",left);
  }

  return 0;
}

Measured memory_bytes: 3900
N = int(input())
a = list(map(int, input().split()))
odd = 0
even = 0
four = 0
for i in a:
    if i % 4 == 0:
        four += 1
    elif i % 2 == 0:
        even += 1
    else:
        odd += 1
if even == 0:
    if four >= odd - 1:
        print('Yes')
    else:
        print('No')
else:
    if four >= odd:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 14224
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    string x;
    while(cin >> x && x != "0")
    {
        int ans = 0;
        for(int i = 0;i < x.size();i++)
        {
            ans += x[i] - '0';
        }
        cout << ans << "\n";
    }

    return 0;
}


Measured memory_bytes: 3216
#include <bits/stdc++.h>
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrepi(i,a,b) for(int i=((int)(b)-1);i>=(a);--i)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) rrepi(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define ZERO(x) memset(x,0,sizeof(x))
#define MINUS(x) memset(x,-1,sizeof(x))
#define UNIQUE(x) (x).erase(unique(ALL(x)), (x).end())
#define TOUPPER(x) transform(ALL(x), (x).begin(), ::toupper)
#define TOLOWER(x) transform(ALL(x), (x).begin(), ::tolower)
#define debug(var)  do{std::cout << #var << " : "; view(var);}while(0)
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){for(const auto& v : vv){ view(v); } }
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void viewarr(T arr[], int n) { for(int i = 0; i < n; ++i) std::cout << arr[i] << " "; std::cout << std::endl; }
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; }
ll qp(ll a,ll b){ll ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
ll qp(ll a,ll b,ll mo){ll ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const int INF = 1e9;
const ll INFL = 1e18;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5;

int main() {
    ll N, K; cin >> N >> K;
    N %= K;
    ll d = abs(N - K);
    if(d < N) N = d;
    cout << N << endl;
    return 0;
}


Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007

#A
def A():
    a, b = LI()
    if a <= b:
        print(a)
    else:
        print(a-1)
    return

#B
def B():
    a, b, c = LI()
    k = II()
    print(a + b + c + max(a, b, c) * ((2 ** k) - 1))
    return

#C
def C():
    return

#D
def D():
    n = II()
    ans = []
    sosu = [2]
    i = 2
    while len(ans) != n:
        for k in sosu:
            if i % k == 0:
                i += 1
                break
        else:
            sosu.append(i)
            if i % 5 == 1:
                ans.append(i)
            i += 1
    for i in ans:
        print(i, end=" ")
    print()
    return


#Solve
if __name__ == '__main__':
    B()


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

using namespace std;

const int Nmax = 5005;
typedef long long ll;

int n, A, B, i, j, p;
int smaller[Nmax], a[Nmax];

int main()
{
//    freopen("input", "r", stdin);
    cin.sync_with_stdio(false);

    cin >> n >> B >> A;
    for(i=1; i<=n; ++i) cin >> a[i];

    vector<ll> dp(n+2), new_dp(n+2);

    for(i=1; i<=n; ++i)
    {
        for(p=1; p<=n; ++p)
            if(a[p] == i) break;

        for(j=p; j<=n; ++j)
            smaller[j]++;

        for(j=1; j<p; ++j) new_dp[j] = dp[j];

        for(j=p; j<=n; ++j)
            new_dp[j] = min(dp[p-1] + (ll) A * (smaller[j] - smaller[p]), dp[j] + B);

        swap(dp, new_dp);
    }

    cout << dp[n] << '\n';
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{   
    ll d;
    cin>>d;
    ll n;
    cin>>n;
    n = (2*n+1);
    ll ans  = d/n;
    if(d%n == 0)
    {
        cout<<ans<<endl;
    }
    else
    {
        cout<<ans+1<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = [(int(x), i+1) for i, x in enumerate(input().split())]

a = sorted(a, reverse=True)

dp = [[0]*(n+1) for __ in range(n+1)]

for k in range(1, n+1):
    child = a[k-1][0]
    ind = a[k-1][1]
    for i in range(k+1):
        if i != 0:
            dp[i][k-i] = dp[i-1][k-i] + child*(ind-i)
        if k-i != 0:
            dp[i][k-i] = max(dp[i][k-i], dp[i][k-i-1] + child*((n+1-(k-i))-ind))

ans = 0

for i in range(n+1):
    ans = max(ans, dp[i][n-i])

print(ans)

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

struct UnionFind {
	vector<int> parent;
	
	UnionFind(int n){
		parent.resize(n);
		for (int i = 0; i < n; i++){
			parent[i] = i;
		}
	}
	
	int find(int x){
		if (parent[x] == x) return x;
		return parent[x] = find(parent[x]);
	}
	
	bool same(int x, int y){
		return find(x) == find(y);
	}
	
	bool unite(int x, int y){
		x = find(x);
		y = find(y);
		if (x == y) return false;
		parent[x] = y;
		return true;
	}
};

int n;
UnionFind uf(0);
vector<int> in, out;
vector<bool> f;

string solve()
{
	int p = -1;
	for (int i = 0; p == -1; i++){
		if (f[i]) p = uf.find(i);
	}
	
	for (int i = 0; i < 26; i++){
		if (f[i] && p != uf.find(i)) return "NG";
	}
		
	for (int i = 0; i < 26; i++){
		if (in[i] != out[i]) return "NG";
	}
	
	return "OK";
}

int main()
{
	while (scanf("%d", &n), n){
		uf = UnionFind(26);
		in = vector<int>(26, 0);
		out = vector<int>(26, 0);
		f = vector<bool>(26, false);
		
		for (int i = 0; i < n; i++){
			string str;
			cin >> str;
			int a = str.front() - 'a';
			int b = str.back() - 'a';
			uf.unite(a, b);
			out[a]++;
			in[b]++;
			f[a] = f[b] = true;
		}
		
		cout << solve() << endl;
	}
}

Measured memory_bytes: 1236
main=do
 n<-readLn;s<-getLine
 putStrLn(g s (f "" s 0 n))
  where f ini _ _ 0 = ini
        f ini las _ 1 = ini++las
        f _ ('(':')':las) 0 lan = f "" las 0 (lan-2)
        f ini ('(':')':las) inn lan = f (init ini) ((last ini):las) (inn-1) (lan-1)
        f ini las inn lan = f (ini++[head las]) (tail las) (inn+1) (lan-1)
        g s l = ['('|x<-l,x==')']++s++[')'|x<-l,x=='(']

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define n 10005
ll mod=1e9+7;
ll dp[n][105];
ll ans=0;
ll D;
void f(string s,ll p)
{
	if (s.length()==0)
		return;
	ll v=s[0]-'0';
	ll N=s.length();
	if (N==1)
		v++;
	for(ll i=0;i<v;i++)
	{
		ll V=(i%D+p)%D;
		if (N==1)
			V=p%D;
		if (V!=0)
			V=D-V;
		//cout<<i<<" "<<V<<" "<<dp[N-1][V]<<endl;
		if (N>1)
		ans+=(dp[N-1][V]);
		else
		ans+=(i%D==V);
		//cout<<ans<<endl;
		if (ans>=mod)
			ans%=mod;
	}
	s=s.substr(1,N);
	v=(v%D+p)%D;
	f(s,v);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	string K;
	cin>>K;
	
	cin>>D;
	ll N=K.length();
	memset(dp,0,sizeof(dp));
	for(ll i=0;i<=9;i++)
		dp[1][i%D]++;
	for(ll i=2;i<=N;i++)
	{
		for(ll j=0;j<D;j++)
		{
			for(ll k=0;k<=9;k++)
			{
				ll v=(k%D+j)%D;
				dp[i][v]+=dp[i-1][j];
				if (dp[i][v]>=mod)
					dp[i][v]%=mod;
			}
		}

	}

	/*
	for(ll i=1;i<=N;i++)
	{	
		for(ll j=0;j<D;j++)
		{
			cout<<dp[i][j]<<" ";
		}
		cout<<endl;
	}*/
	f(K,0);
	ans=(ans-1+mod)%mod;
	
	cout<<ans;
}

Measured memory_bytes: 72320
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		for (; solver.hasNext();) {
			solver.readBody(in.readLine());
		}
		solver.solve();
	}
}

class Solver {
	int N;
	int M;
	int cnt;
	HashMap<Integer, Boolean> ChkMap;

	public void init() {
		N = 0;
		M = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split(" ");
		N = Integer.parseInt(strArr[0]);
		M = Integer.parseInt(strArr[1]);
		ChkMap = new HashMap<Integer, Boolean>();
	}

	public boolean hasNext() {
		return cnt < M;
	}

	public void readBody(String str) {
		// System.out.println(str);
		String[] strArr = str.split(" ");
		for (int i = 0; i < strArr.length; i++) {
			int v = Integer.parseInt(strArr[i]);
			if (ChkMap.containsKey(v)) {
				ChkMap.put(v, !ChkMap.get(v));
			} else {
				ChkMap.put(v, true);
			}
		}
		cnt++;
	}

	public void solve() {
		for (int i : ChkMap.keySet()) {
			if (ChkMap.get(i)) {
				System.out.println("NO");
				return;
			}
		}
		System.out.println("YES");
	}
}


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

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MIN(a,b) ((a)>(b)? (b): (a))
#define MAX(a,b) ((a)<(b)? (b): (a))

const long long INF = 1LL << 60;
typedef unsigned long long ll;
const long long MOD = 1000000000 + 7;

int main(){
    char s;
    cin >> s;
    char base = 'a';
    if (s - base >= 0)
        cout << 'a' << endl;
    else
        cout << 'A' << endl;
    return 0;
}

Measured memory_bytes: 3616
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const double PI = acos(-1);
const ll MOD = 1000000007;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////

vector<vector<bool>> dpx(8010, vector<bool>(16010));
vector<vector<bool>> dpy(8010, vector<bool>(16010));

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    string S; cin >> S;
    int x,y; cin >> x >> y;
    int N = S.size();
    
    int count = 0;
    vector<int> A;
    rep(i,N) {
        if (S[i] == 'F') count++;
        else {
            A.emplace_back(count);
            count = 0;
        }
    }
    A.emplace_back(count);
    int M = A.size();
    dpx[0][8000] = dpy[0][8000] = true;
    rep(i,M) {
        if (i % 2 == 0) {
            rep(j,16001) {
                if (dpx[i][j]) {
                    dpx[i+1][j+A[i]] = true;
                    if (i != 0) dpx[i+1][j-A[i]] = true;
                }
                if (dpy[i][j]) dpy[i+1][j] = true;
            }
        } else {
            rep(j,16001) {
                if (dpy[i][j]) {
                    dpy[i+1][j+A[i]] = true;
                    dpy[i+1][j-A[i]] = true;
                }
                if (dpx[i][j]) dpx[i+1][j] = true;  
            }
        }
    }

    cout << ((dpx[M][8000+x] && dpy[M][8000+y]) ? "Yes" : "No") << endl;
}


Measured memory_bytes: 32512
import java.util.Scanner;

 public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(a==b){
            System.out.println("a == b");
        } else if(a>b){
            System.out.println("a > b");
        } else{
            System.out.println("a < b");
        }
        sc.close();

    }
}
    



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

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)

using namespace std;
typedef long long unsigned int ll;

int main() {
  int A, B;
  cin >> A >> B;
  cout << A * B - (A + B - 1) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<iterator>
#include<complex>
#include<stack>
#include "stdio.h"
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const long long mod_const = 1e9+7;
using MIte = multimap<long, long, greater<long> >::iterator;

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

	long long N, C;
	cin >> N >> C;

	vector<long long> vx(N, 0);
	vector<long long> vv(N, 0);
	rep(i, N) cin >> vx[i] >> vv[i];

	long long ans1 = 0;
	vector<long long> vecans1(N, 0);
	ans1 = vv[0] - vx[0];
	{
		long long all = ans1;
		vecans1[0] = ans1;
		for (int i = 1; i != N; ++i) {
			all = all + vv[i] - (vx[i] - vx[i - 1]);
			ans1 = max(ans1, all);
			vecans1[i] = ans1;
		}
	}

	long long ans2 = 0;
	vector<long long> vecans2(N, 0);
	ans2 = vv[N - 1] - (C - vx[N - 1]);
	
	{
		long long all = ans2;
		vecans2[N - 1] = ans2;
		for (int i = N - 2; i != -1; --i) {
			all = all + vv[i] - (vx[i + 1] - vx[i]);
			ans2 = max(ans2, all);
			vecans2[i] = ans2;
		}
	}

	long long ans3 = 0;
	for (int i = 0; i != N - 1; ++i) {
		ans3 = max(ans3, vecans1[i] - vx[i] + vecans2[i + 1]);
	}

	long long ans4 = 0;
	for (int i = N - 1; i != 0; --i) {
		ans4 = max(ans4, vecans2[i] - (C - vx[i]) + vecans1[i - 1]);
	}

	long long ans = max({ ans1, ans2, ans3, ans4 });

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3456
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        sc.nextInt();
        String S = sc.next();

        System.out.println(solve(S));

        sc.close();
    }

    static int solve(String S) {
        int N = S.length();

        int leftWCount = 0;
        int[] leftWCounts = new int[N];
        for (int i = 0; i < leftWCounts.length; ++i) {
            leftWCounts[i] = leftWCount;

            if (S.charAt(i) == 'W') {
                ++leftWCount;
            }
        }

        int rightECount = 0;
        int[] rightECounts = new int[N];
        for (int i = rightECounts.length - 1; i >= 0; --i) {
            rightECounts[i] = rightECount;

            if (S.charAt(i) == 'E') {
                ++rightECount;
            }
        }

        return IntStream.range(0, N).map(i -> leftWCounts[i] + rightECounts[i]).min().getAsInt();
    }
}

Measured memory_bytes: 35172
#include <iostream>

using namespace std;

void solve()
{
	int hand[5];
	while(cin >> hand[0], hand[0])
	{
		for(int i = 1; i < 5; ++i)
		{
			cin >> hand[i];
		}
		int rockCount = 0;
		int paperCount = 0;
		int scissorsCount = 0;
		for(int i = 0; i < 5; ++i)
		{
			if(hand[i] == 1)
			{
				++rockCount;
			}
			else if(hand[i] == 2)
			{
				++scissorsCount;
			}
			else
			{
				++paperCount;
			}
		}
		if((rockCount && scissorsCount && paperCount)
			|| (rockCount == 0 && scissorsCount == 0) 
			|| (scissorsCount == 0 && paperCount == 0) 
			|| (paperCount == 0 && rockCount == 0))
		{
			for(int i = 0; i < 5; ++i)
			{
				cout << "3" << endl;
			}
		}
		else if(rockCount == 0)
		{
			for(int i = 0; i < 5; ++i)
			{
				if(hand[i] == 2)
				{
					cout << "1" << endl;
				}
				else
				{
					cout << "2" << endl;
				}
			}
		}
		else if(scissorsCount == 0)
		{
			for(int i = 0; i < 5; ++i)
			{
				if(hand[i] == 3)
				{
					cout << "1" << endl;
				}
				else
				{
					cout << "2" << endl;
				}
			}
		}
		else if(paperCount == 0)
		{
			for(int i = 0; i < 5; ++i)
			{
				if(hand[i] == 1)
				{
					cout << "1" << endl;
				}
				else
				{
					cout << "2" << endl;
				}
			}
		}
	}
}

int main()
{
	solve();
	return(0);
}

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

using namespace std;

using ll = long long;
using ld = long double;

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    // cout << setprecision(8) << setiosflags(ios::fixed);

    int n;
    cin >> n;

    vector<int> a(n);
    for (auto &a_i : a) cin >> a_i;

    vector<ll> even(n); // (1, -1, 1, -1, ...) と a の内積の累積和
    vector<ll> odd(n);  // (-1, 1, -1, 1, ...) と a の内積の累積和
    for (int i = 0; i < n; ++i) {
        even[i] = ((i & 1) ? -1 : 1) * a[i];
        odd[i] = ((i & 1) ? 1 : -1) * a[i];
        if (i != 0) {
            even[i] += even[i - 1];
            odd[i] += odd[i - 1];
        }
    }

    for (int i = 0; i < n; ++i) {
        ll sum = 0;
        if (i & 1) {
            sum = odd[n - 1];
            if (0 < i) {
                sum -= odd[i - 1];
                sum += even[i - 1];
            }
        }
        else {
            sum = even[n - 1];
            if (0 < i) {
                sum -= even[i - 1];
                sum += odd[i - 1];
            }
        }

        cout << sum << " \n"[i == n - 1];
    }

    return 0;
}


Measured memory_bytes: 3328
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0]);
    
    let answer = 0;
    
    for(let i=1; i<=N; i++) {
        if(String(i).length % 2 !== 0) {
            answer++;
        }
    }
    
    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

using namespace std;

int main(){
    int N;
    cin >> N;
    int C[N], S[N], F[N];
    for(int i=0; i<N-1; i++){
        cin >> C[i] >> S[i] >> F[i];
    }    
    for(int i=0; i<N-1; i++){
        int t = 0;
        for(int j=i; j<N-1; j++){
            t = max(S[j], ((t-1)/F[j] + 1) * F[j]);
            t += C[j];
        }
        cout << t << endl;
    }
    cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 3632
A,B =[int(x) for x in input().split()]

def bunkai(n):
    sosu= {1}
    tmp = n
    stop_flag = n
    
    if tmp%2 == 0:
        while tmp%2==0:
            tmp //=2
        sosu.add(2)
    
    for i in range(3,n+1,2):
        if tmp%i == 0:
            while tmp%i==0:
                tmp //=i
            sosu.add(i)
            stop_flag = tmp 
            
        if i > stop_flag:
            break
        else:
            stop_flag = int(n/i)+1
            
    if tmp!=1:
        sosu.add(tmp)
                
    if sosu==[1]:
        sosu.add(n)
    
    return sosu

def check_sosu(n,x):
    ans=0
    tmp = n
    for i in x:
        if (tmp % i) == 0:
            ans+=1
    return ans

ans = check_sosu(B,bunkai(A))

print(ans)


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

int main(){
	int n,t,a;
	cin>>n>>t>>a;

	int h[100010];
	for(int i=0;i<n;++i) cin>>h[i];

	double c[100010];
	for(int i=0;i<n;++i){
		c[i] = t-h[i]*0.006;
	}

	double dif[100010];
	for(int i=0;i<n;++i){
		dif[i] = fabs(a-c[i]);
	}

	double Min = 10000;
	for(int i=0;i<n;++i){
		Min = min(Min,dif[i]);
	}

	int j;
	for(int i=0;i<n;++i){
		if(dif[i] == Min){
			j = i+1;
		}
	}

	cout<<j<<endl;
}

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

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

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


int inversion(int a[],int n){
	int cnt=0;
	for(int i=n-1;i>0;i--){
		for(int j=0;j<i;j++){
			if(a[j]>a[j+1]){
				swap(a[j],a[j+1]);
				cnt++;
			}
		}
	}
	return cnt;
}

int main(){
	int a[100],n;
	while(cin>>n&&n){
		for(int i=0;i<n;i++){
			cin>>a[i];
		}
		cout<<inversion(a,n)<<endl;
	}
	return 0;
}

Measured memory_bytes: 1164
s = input()

a_index = []
for id, chr in enumerate(s):
    if chr == 'A':
        a_index.append(id)

z_index = []
for id, chr in enumerate(s):
    if chr == 'Z':
        z_index.append(id)

print(z_index[-1] - a_index[0] + 1)

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

int main(int argc, char *argv[])
{
    int w, h, diag, i, j;
    while (cin >> w >> h, w | h) {
        diag = w * w + h * h;
        i = 0;
        while (1) {
            i++;
            j = sqrt(diag - i * i);
            if (i >= j) {
                diag++;
                i = 0;
                continue;
            } else {
                if ((diag == w * w + h * h && i <= w) || j * j != diag - i * i)
                    continue;
                cout << i << ' ' << j << endl;
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1160
#include<iostream>
using namespace std;
int main(int argc, char const *argv[])
{
   int A, B;
   cin >> A >> B;
   int ans = A - 2*B;
   if(ans > 0)
   {
      cout << ans << endl;
   }
   else
   {
      cout << 0 << endl;
   }
   
   return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String [] ABC = new String [3];
        for(int i=0; i<3; i++){
            ABC[i] = sc.next();
        }
        Arrays.sort(ABC);
        String S = "";
        for(int i=0; i<3; i++){
            S=S+ABC[i];
        }
        if("557".equals(S)){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    }
}

Measured memory_bytes: 9680
#include<stdio.h>
int main(){
int a,b,i,c=0,d=0;
while(1){
scanf("%d %d\n",&a,&b);
if(a==0 && b==0){
break;
}
if(d!=0){
printf("\n");
}
for(;a<=b;a++){
if(a%400==0){
c++;
printf("%d\n",a);
}
else if(a%100==0){
}
else if(a%4==0){
c++;
printf("%d\n",a);
}
}
if(c==0){
printf("NA\n");
}
c=0,d++;
}
return 0;
}



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

signed main(){

  int n,q;
  string s;
  cin>>n>>q>>s;
  vector<int> sum(n+1);
  for(int i=1;i<n;++i){
    if(s[i]=='C'&&s[i-1]=='A')sum[i]++;
    sum[i+1] += sum[i];
  }
  vector<int> ans;
  while(q--){
    int l,r;cin>>l>>r;
    l--;r--;
    ans.emplace_back(sum[r]-sum[l]);
  }
  //for(auto s:sum)cout<<s<<" ";cout<<endl;
  for(auto x:ans){
    cout<<x<<endl;
  }

}

Measured memory_bytes: 1912
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int i = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int i = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define MP make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    cout << (N * (N + 1)) / 2 << endl;
    return 0;
}

Measured memory_bytes: 256