akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <cmath>
#include <climits>
#include <bitset>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

int main(int argc, char const* argv[])
{
  int n;
  cin >> n;
  vector<int> q = vector<int>(n+1, 0);
  for(int i = 0; i < n; i++){
    int x;
    cin >> x;
    x--;
    q[x] = i + 1;
  }
  for(int i = 0; i < n; i++){
    cout << 30000 * (i + 1);
    if(i == n - 1)cout << endl;
    else cout << " ";
  }
  for(int i = 0; i < n; i++){
    cout << 30000 * (n - i) + q[i];
    if(i == n - 1)cout << endl;
    else cout << " ";
  }
	return 0;
}


Measured memory_bytes: 768
data class Data(
  val index: Int,
  val name: String,
  val score: Int
)

fun main() {
  val N = readInt()
  val dataList = mutableListOf<Data>()
  for (i in 1..N) {
    val SP = readStrings()
    dataList.add(Data(i, SP[0], SP[1].toInt()))
  }
  dataList.sortedWith(compareBy({ it.name }, { -it.score })).forEach {
    println(it.index)
  }
}

fun gcd(a: Int, b: Int): Int = if (a < b) gcd(b, a) else if (b == 0) a else gcd(b, a % b)
fun gcd(a: Long, b: Long): Long = if (a < b) gcd(b, a) else if (b == 0L) a else gcd(b, a % b)
fun lcm(a: Int, b: Int): Int = (a * b) / gcd(a, b)
fun lcm(a: Long, b: Long): Long = (a * b) / gcd(a, b)

fun readString() = readLine()!!
fun readStrings() = readLine()!!.split(" ")
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readInts() = readLine()!!.split(" ").map { it.toInt() }
fun readLongs() = readLine()!!.split(" ").map { it.toLong() }


Measured memory_bytes: 40600
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
  int n,ans=0;
  cin>>n;
  map<int,int> mp;
  vector<int> a(n);
  rep(i,n){
    cin>>a[i];
    mp[a[i]]++;
  }
  for(auto i:mp){
    if(i.first!=i.second){ans+=(i.first>i.second?i.second:i.second-i.first);}
  }
  cout<<ans;
}

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

int n, m, a, b, c, t;
mat mul(mat&a, mat&b) {
	mat c(a.size(), vec(b[0].size()));
	rep(i, a.size())rep(j, b[0].size())rep(k, b.size())
		(c[i][j] += a[i][k] * b[k][j]) %= m;
	return c;
}
mat ppow(mat&a, int b) {
	mat res(a.size(), vec(a.size()));
	rep(i, a.size())res[i][i] = 1;
	while (b) {
		if (b & 1)res = mul(res, a);
		a = mul(a, a);
		b >>= 1;
	}
	return res;
}
int main() {
	while (scanf("%d%d%d%d%d%d", &n, &m, &a, &b, &c, &t), n) {
		mat A(n, vec(n)), B(n, vec(1));
		rep(i, n)scanf("%d", &B[i][0]);
		rep(i, n)rep(j, n) {
			if (j == i - 1)A[i][j] = a;
			if (j == i)A[i][j] = b;
			if (j == i + 1)A[i][j] = c;
		}
		A = ppow(A, t);
		A = mul(A, B);
		rep(i, n) {
			if (i)printf(" ");
			printf("%d", A[i][0]);
		}
		puts("");
	}
}

Measured memory_bytes: 3232
#include<bits/stdc++.h>
#define U [1<<17]={}
#define G(a)((c=A[a]+A[P[a]]+C[a])%k?c:0)
typedef long long L;using namespace std;map<L,L>T U;L P U,E U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c,p;char s U;L D(L a){L d;Z[a]=1;for(map<L,L>::iterator I=T[a].begin();I!=T[a].end();I++)d=I->first,d-P[a]?P[d]=a,E[d]=E[a]+1,C[d]=I->second,D(d),Z[a]+=Z[d],!H[a]|Z[H[a]]<Z[d]?H[a]=d:0:0;}L M(L i){return i?B[i]+M(i^i&-i):0;}L S(L x,L i){for(x=G(x)+M(i++)-M(i);i<1e5;i+=i&-i)B[i]+=x;}L K(L f){p=X[f];n=X[b];return p-n?M(O[E[p]<E[n]?p=n,a=b,b=f,a:f])-M(O[p])+G(p)+K(P[p]):abs(M(O[f])-M(O[b]));}main(){for(cin>>n>>k;++p<n;T[a][b]=T[b][a]=c)cin>>a>>b>>c;for(D(b=p=0);p<n;p++)if(!p|H[P[a=p]]-p)for(;!b|a;S(a=H[a],O[a]=b++))X[a]=p;for(cin>>a;cin>>s>>a>>b;*s&2?cout<<K(a)<<endl,0:A[a]+=b,S(H[a],O[a]),a&&S(a,O[a]-1));}

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

int main() {
  int n;
  cin>>n;
  vector<vector<int>>a(3,vector<int>(n+1,0));
  vector<vector<int>>b(3,vector<int>(n+1,0));
  for(int i=0;i<2;i++){
    for(int j=0;j<n;j++){
      cin>>a[i][j];
    }
  }
  b[0][0]=a[0][0];
  for(int j=1;j<n+1;j++){
    b[0][j]=a[0][j]+b[0][j-1];
  }
  b[1][0]=a[0][0]+a[1][0];
  for(int j=1;j<n+1;j++){
    b[1][j]=a[1][j]+max(b[1][j-1],b[0][j]);
  }
  cout<<b[1][n-1]<<endl;
  return 0;
}


Measured memory_bytes: 256
h,w,k=map(int,input().split())
dp=[0]*(w)
l=[1,1,2,3,5,8,13,21,34]#n本の縦線に高さ1のvalidな横棒を引く通り、フィボナッチ数列になる
#a_n:=n本の縦線にvalidな横棒を引く通りの総数、とすれば
#n+1本の時は1.1と2本目に横棒を引く（2と3の間に引けないのでa_n-1通り）
#          2.                引かない（a_n通り）
#よって漸化式a_n+1=a_n+a_n-1が成立。
dp[0]=1
mod=10**9+7
r=[0]*w
for i in range(h):
    for i in range(w):
        r[i]=dp[i]*l[i]*l[w-1-i]#左右に横棒を引かない
        if i>=1:
            r[i]+=dp[i-1]*l[i-1]*l[w-1-i]#左にのみ横棒を引く
        if i<=w-2:
            r[i]+=dp[i+1]*l[i]*l[w-2-i]#右にのみ横棒を引く
        r[i]%=mod
    dp,r=r,dp

print(dp[k-1])

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

long long h,w,n,u,v,s,t,cs=0,kq[15],dem,p,q;
struct st{
    long long x,y;
};
st a[1000010];

bool cmp(st c, st d){
    if (c.x==d.x) return c.y < d.y;
    else return c.x < d.x;
}

int main()
{
    cin >> h >> w >> n;
    for (long i=1;i<=n;i++){
        cin >> u >> v;
        for (int j=0;j<=2;j++){
        for (int k=0;k<=2;k++){
            s=u-j;
            t=v-k;
            if (s>0 && t>0 && s<=h-2 && t<=w-2){
                cs++;
                a[cs].x=s;
                a[cs].y=t;

            }

        }
        }
    }
    //cout << p << " " << q << endl;
    p=(h-2)*(w-2);
    sort(a+1,a+1+cs,cmp);
    dem=1;
  //  for (long i=1;i<=cs;i++) cout << a[i].x << " " << a[i].y << endl;
    for (long i=2;i<=cs+1;i++){
        if (a[i].x==a[i-1].x && a[i].y==a[i-1].y) dem++;
        else {
            kq[dem]++;
            dem=1;
            q++;
        }
    }
    kq[0]=p-q;
    for (int i=0;i<=9;i++) cout << kq[i] << endl;
    return 0;
}


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

const int INF = 1<<30;

bool contain(string s, char c){
    for(int i = 0; i < s.size(); i++){
        if(s[i] == c) return true;
    }
    return false;
}

bool isOK(string s){
    char c = s[0];
    for(int i = 0; i < s.size(); i++){
        if(s[i] != c) return false;
    }
    return true;
}

int numOfOperations(string s, char c){
    int res = 0;
    if(!contain(s,c)) return INF;
    string temp(s.size(), 'a');

    while(!isOK(s)){
        for(int i = 0; i < s.size() - 1; i++){
            if(s[i] == c || s[i + 1] == c) temp[i] = c;
            else temp[i] = s[i];
        }
        for(int i = 0; i < s.size(); i++){
            s[i] = temp[i];
        }
        s.pop_back();
        res++;
    }
    return res;
}

int main(){
    string s;
    cin >> s;
    int ans = INF;
    for(char c = 'a'; c <= 'z'; c++){
        int n = numOfOperations(s, c);
        if(n < ans) ans = n;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define MIN -1000000
using namespace std;
typedef long long ll;
typedef pair <int,int> pii;
bool visited[100005];
const int max_N=1e5+10;
int H,W,h,w;
int board[105][105];
int mxindex,mxchain=0;
int main(void)
{
  string b;
  cin >> b;
  string ans="";
  for(int i=0;i<int(b.size());i++)
    {
      if(b[i]=='A')
	{
	  ans.push_back('T');
	}
       if(b[i]=='T')
	{
	  ans.push_back('A');
	}
        if(b[i]=='C')
	{
	  ans.push_back('G');
	}
	 if(b[i]=='G')
	{
	  ans.push_back('C');
	}
    }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
from itertools import accumulate

n, m = map(int, input().split())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))
mod = 10 ** 9 + 7
# X.sort()
# Y.sort()
AX = list(accumulate([0] + X))
AY = list(accumulate([0] + Y))
xsum = 0
for i in range(1, n):
    xsum += (AX[n] - AX[i]) - (n - i) * X[i - 1]
    xsum %= mod
ysum = 0
for i in range(1, m):
    ysum += (AY[m] - AY[i]) - (m - i) * Y[i - 1]
    ysum %= mod
ans = xsum * ysum
print(ans % mod)


Measured memory_bytes: 93540
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;
public class Main{
	static BufferedReader br;
	static int cin() throws Exception
	{
		return Integer.valueOf(br.readLine());
	}
	static int[] split() throws Exception
	{
		String[] cmd=br.readLine().split(" ");
		int[] ans=new int[cmd.length];
		for(int i=0;i<cmd.length;i++)
		{
			ans[i]=Integer.valueOf(cmd[i]);
		}                                              
		return ans;
	} 
	static long mod=1000000007;
	static long power(long x,long y) 
    { 
        long res = 1; 
        x = x % mod; 
        while (y > 0) { 
            if (y % 2 == 1) 
                res = (res * x) % mod; 
            y = y >> 1;
            x = (x * x) % mod; 
        } 
        return res%mod; 
    } 
    static long modInverse(long n) 
    { 
        return power(n, mod-2); 
    } 
    static int digits(int n)
    {
    	int ans=0;
    	while(n!=0)
    	{
    		ans++;
    		n=n/10;
    	}
    	return ans;
    }
    public static void main(String[] args) throws Exception {
        br = new BufferedReader(new InputStreamReader(System.in));
        String s=br.readLine();
        String t=br.readLine();
        int n=s.length();
        int m=t.length();
        int[][]dp=new int[n+1][m+1];
        for(int i=0;i<=n;i++)
        {
        	for(int j=0;j<=m;j++)
        	{
        		if(i==0 || j==0)
        			continue;
        		if(s.charAt(i-1)==t.charAt(j-1))
        			dp[i][j]=1+dp[i-1][j-1];
        		else
        			dp[i][j]=Math.max(dp[i-1][j],dp[i][j-1]);
        	}
        }
        String ans="";
        int i=n;
        int j=m;
        while(i>0 && j>0)
        {
        	if(s.charAt(i-1)==t.charAt(j-1))
        	{
        		ans=s.charAt(i-1)+ans;
        		i--;
        		j--;
        	}
        	else
        	{
        		if(dp[i-1][j]>dp[i][j-1])
        			i--;
        		else
        			j--;
        	}
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 86844
#include<bits/stdc++.h>
#define forn(i, n) for(int i=0;i<(int)(n);i++)
#define for1(i, n) for(int i=1;i<=(int)(n);i++)
#define fore(i, l, r) for(int i=(int)(l);i<=(int)(r);i++)
#define ford(i, n) for(int i=(int)(n)-1;i>=0;i--)
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define endl "\n"
#define MAX 1000000007
using namespace std;
typedef int64_t ll;
typedef vector<int> vi;
typedef vector<int64_t> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
int dp[100009][4];
int a[100009],b[100009],c[100009];
int n;
int solve(int idx,int p){
if(idx==n)return 0;
if(dp[idx][p]!=-1) return dp[idx][p];
int ans=0;
if(p==0){
	ans=max(ans,b[idx]+solve(idx+1,1));
	ans=max(ans,c[idx]+solve(idx+1,2));
}
else if(p==1){
	ans=max(ans,c[idx]+solve(idx+1,2));
	ans=max(ans,a[idx]+solve(idx+1,0));
}
else if(p==2){
	ans=max(ans,a[idx]+solve(idx+1,0));
	ans=max(ans,b[idx]+solve(idx+1,1));
}
else{
	ans=max(ans,a[idx]+solve(idx+1,0));
	ans=max(ans,b[idx]+solve(idx+1,1));
	ans=max(ans,c[idx]+solve(idx+1,2));
}
return dp[idx][p]=ans;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.precision(10);
	cout << fixed;
	memset(dp,-1,sizeof(dp));
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i]>>b[i]>>c[i];
	int ans=solve(0,3);
	cout<<ans;
	return 0;
}



Measured memory_bytes: 14164
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
using namespace std;
int main(){
int A,B,C;
cin >> A >> B >> C;
bool cou = false;
if(A + B >= C)cou = true;
if(cou)cout << "Yes" << endl;
else cout << "No" << endl;
        return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
inline int abs(int x){return (x<0)?-x:x;}
int main(void){
    char mask[110];
    int x,n;
    cin >> x >> n;
    for(int i=0;i<110;i++){
        mask[i]=1;
    }
    for(int i=0;i<n;i++){
        int t;
        cin >> t;
        mask[t]=0;
    }
    int min=0, minv=x;
    for(int i=1;i<=101;i++){
        if(!mask[i]) continue;
        int d = abs(x-i);
        if(d<minv){
            minv=d;
            min=i;
        }
    }
    cout << min << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
     
     
typedef long long ll;
typedef vector <int> vi;
typedef pair <int,int> pi;
typedef tuple <int,int,int> ti;

#define forn(i,a,n) for(int i = a; i < n ; i++)
#define mem(str,a) memset(str, a, sizeof(str));
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(nullptr)
const int MOD = 1e9+7, N = 1e7 + 10, E = 1e-9;
/*
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
//vector <int> show;
//for (auto x : show)
//   cout << x << " ";
getline(cin,s);


*/

int main() {
    string s1,s2,s3;
    cin >> s1 >> s2 >> s3;
    cout << (char)(s1[0]-32) << (char)(s2[0]-32) << (char)(s3[0]-32) << endl;
    return 0;
}

Measured memory_bytes: 3588
//Bokan ga bokka--nn!!
//Daily Lunch Special Tanoshii !!
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
#define s(x) scanf("%d",&x)
#define rep(i,x) for(int i=0;i<x;i++)
int main()
{
	string s;
	cin >> s;
	int id=0;
	int ret=0;
	while(id<s.size())
	{
		if(s[id]!='J')
		{
			id++;
			continue;
		}
		int j=0,o=0,i=0;
		while(id<s.size() && s[id]=='J') { j++; id++;}
		while(id<s.size() && s[id]=='O') { o++; id++;}
		while(id<s.size() && s[id]=='I') { i++; id++;}
		if(j<o || o>i) continue;
		ret=max(ret,o);
	}
	printf("%d\n",ret);
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    vll x(n), y(n);
    vll h(n);
    rep(i,n){
        cin>>x[i]>>y[i]>>h[i];
    }
    rep(i,101)rep(j,101){
        bool ng = false;
        ll tall=1e10;
        rep(k,n){
            tall = min(tall, h[k]+abs(x[k]-j)+abs(y[k]-i));
        }
        rep(k,n){
            ll tmp = h[k]+abs(x[k]-j)+abs(y[k]-i);
            if (tall!=tmp && !(h[k]==0 && tall<=tmp)){
                ng = true;
                break;
            }
        }
        if (ng) continue;
        cout<<j<<" "<<i<<" "<<tall<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
    string a;
    cin>>a;
    int len=a.size();
    int i;
    int x=0,y=0,ans=0;
    for (i=0;i<len;i++){
        if (x==y){
            x++;if (a[i]=='p') ans--;
        }
        else{
            y++;if (a[i]=='g') ans++;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 512
#!/usr/bin/env python3
import sys
import numpy as np

def main():
    N = int(input())
    for i in range(N):
        t, x, y = map(int,input().split())
        if x + y > t or (x + y - t) % 2:
            print("No")
            exit()

    print("Yes")
    

        


if __name__ == '__main__':
    main()


Measured memory_bytes: 12508
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
cb_list = []
for i in range(m):
  b, c = map(int, input().split())
  cb_list.append((c, b))

cb_list.sort(key=lambda x: x[0], reverse=True)

elim_count = 0
for i in range(m):
  c,b = cb_list[i]
  a.extend([c] * b)
  if len(a) >= 2*n:
    break

a.sort(reverse=True)
print(sum(a[:n]))

Measured memory_bytes: 24124
#include <stdio.h>


int main(void)
{
    char str;
    scanf("%c",&str);
    
    if (str >= 'A' && str <= 'Z')
    {
        printf("A\n");
        return 0;
    }
    else
    {
        printf("a\n");
    }



    return 0;
}

Measured memory_bytes: 1584
#include<bits/stdc++.h>
using namespace std;
struct sq{
  vector<int> v;
  bool operator<(const sq& p)const{
    int s=min(v.size(),p.v.size());
    for(int i=0;i<s;i++){
      if(v[i]==p.v[i]) continue;
      return v[i]>p.v[i];
    }
  }
  bool operator==(const sq& p)const{
    if(v.size()!=p.v.size()) return false;
    for(int i=0;i<v.size();i++) if(v[i]!=p.v[i]) return false;
    return true;
  }
  void print(){
    for(int i=0;i<v.size();i++) cout << v[i] << (i+1==v.size()?'\n':' ');
  }
};
vector<sq> v;
void rec(int n,int d,sq x){
  if(n==0){
    v.push_back(x);
    return;
  }
  if(n<0) return;
  for(int i=1;i<=d;i++){
    x.v.push_back(i);
    rec(n-i,i,x);
    x.v.pop_back();
  }
}


int main(){
  int n;
  while(cin >> n,n){
    v.clear();
    sq x;
    rec(n,n,x);
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
    for(int i=0;i<v.size();i++) v[i].print();
  }    
  return 0;
}

Measured memory_bytes: 1796
#include <stdio.h>
int main(void){
    int h, w;
    int i, j;
    while(1){
        scanf("%d %d", &h, &w);
        if(h + w == 0)
            break;
        for(i = 0; i < h; i++){
            for(j = 0; j < w; j++)
                putchar('#');
            putchar('\n');
        }
        puts("");
    }
    return 0;
}

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

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

    int l = 1, r = N;
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        if (a > r || l > b) {
            cout << 0 << endl;
            return 0;
        }
        else if (a >= l && b <= r) {
            l = a;
            r = b;
        }
        else if (a <= l && r <= b) {
            continue;
        }
        else if (a <= l) {
            r = b;
        }
        else {
            l = a;
        }
    }

    cout << min(r - l + 1, N) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x, y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
/* (๑╹◡╹) */
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll MOD = 1000000007;
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;
}
/* (๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹) */
///////////////////////////////////////////////
const int MAX = 510000;
 
long long fac[MAX], finv[MAX], inv[MAX];
 



int main() {
	int ans = 0;
	string S; cin >> S;
	int N = S.length();
	int A[N+2] = {};
	int B[N+2] = {};

	char a = 'R';
	int ind = 0;
	for (int i = 0; i < N; i++) //連続する文字の数を格納する
	{
		if(a == S.at(i)){A[ind]++;}
		else{a = S.at(i); ind++;A[ind]++;}
	}
	ind = -1;
	for (int i = 0; 0 < A[i]; i+=2)
	{
		ind += A[i];
		B[ind] = A[i]/2 + A[i+1]/2 + A[i]%2;
		B[ind+1] = A[i]/2 + A[i+1]/2 + A[i+1]%2;
		ind += A[i+1];
	}
	

	for (int i = 0; i < N; i++)
	{
		cout << B[i] << ' ';
	}
	cout << endl;
}


Measured memory_bytes: 1408
#include <cstdio>
using namespace std;

int n;
int y, m, d;

int main() {
  scanf("%d", &n);
  for (int i=0; i<n; i++) {
    scanf("%d%d%d", &y, &m, &d);
    
    int cnt = 0;
    while (!(y == 1000 && m == 1 && d == 1)) {
      int days = 19;
      if (y%3 == 0 || m%2 == 1) days = 20;
      cnt += days-d+1;
      d = 1;
      m++;
      if (m == 11) {
        m = 1;
        y++;
      }
    }

    printf("%d\n", cnt);
  }
}

Measured memory_bytes: 2688
//@author KhaledAlam.net
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef stringstream ss;
typedef pair<int, int> pii;
//#########################
#define fi           first
#define se           second
#define pb           push_back
#define mp           make_pair
#define out(x)       return cout<<x,0
#define all(x)       x.begin(),x.end()
#define sz(x)        ((int)(x.size()))
#define clr(x)       memset(x,0,sizeof x)
#define rep(i,n)     for(int i=0;i<n;i++)
#define debug(x)     cerr<<"[l#: "<<__LINE__<<"] "<<#x<<" = "<<x<<endl
// v0.0.2 | Github.com/khaledalam/templates/tree/master/cpp
//##########################################################################

#define maxn 101010

string s;
vector<string> v;
bool vis[4] = {0};
int a, b, c, d;

void run(int h, string k)
{
	if (h == 3)
	{
		v.pb(k);
		return;
	}
	for (int i = h; i < 3; ++i)
	{
		if (!vis[i])
		{
			vis[i] = true;
			k[i] = '+';
			run(h + 1, k);
			k[i] = '-';
			run(h + 1, k);
			vis[i] = false;
		}
	}
}

void test()
{
	for (auto it : v)
	{
		int sum = a;
		sum += (it[0] == '+' ? b : -b);
		sum += (it[1] == '+' ? c : -c);
		sum += (it[2] == '+' ? d : -d);
		if (sum == 7)
		{
			cout << a << it[0] << b << it[1] << c << it[2] << d << '=' << 7
					<< endl;
			exit(0);
		}
	}
}
int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
//	freopen("input.txt", "r", stdin); //freopen("output.txt","w",stdout);

	cin >> s;
	a = s[0] - '0';
	b = s[1] - '0';
	c = s[2] - '0';
	d = s[3] - '0';

	run(0, "+++");
	test();

}



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

int main() {
  
  int x=0, t=0;
  
  cin >> x >> t;
  
  if(t<=x) {
    
    cout << x-t << endl;
    
  } else if(x<t) {
    
    cout << "0" << endl;
    
  }
  
  return 0;
  
}

Measured memory_bytes: 256
import java.util.*;
    public class Main {
     
    	public static void main(String[] args) {
    			
    		Scanner scan =new Scanner(System.in);
    		
    		int a=Integer.parseInt(scan.next());
    		int b=Integer.parseInt(scan.next());
    		
    		int[] ans= {a+b,a-b,a*b};
    		Arrays.parallelSort(ans);
    		System.out.print(ans[2]);
    		
    	


    		
     
    }
    }
// end 

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

using namespace std;

long long h(long long a) {
    return (a % 4 == 1) ? 1 : 0;
}

long long g(long long a) {
    if (a % 2 == 1) {
        return h(a);
    } else {
        return h(a + 1) ^ (a + 1);
    }
}

long long f(long long a, long long b) {
    return g(a - 1) ^ g(b);
}

int main() {
    long long A, B;
    cin >> A >> B;

    cout << f(A, B) << endl;
    return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val paperAmount = readLine().orEmpty()
    val paperList = readLine()?.split(" ").orEmpty()
    var paperContent = mutableListOf<Int>()
    var bool = true

    paperList.forEach {
        paperContent.add(it.toInt())
    }

    run loop@{
        paperContent.forEach {
            if (it % 2 == 0) {
                if (it % 3 != 0 && it % 5 != 0) {
                    bool = false
                    return@loop
                }
            }
        }
    }

    if(bool){
        println("APPROVED")
    } else{
        println("DENIED")
    }

}


Measured memory_bytes: 37900
N,M = map(int,input().split())

from1 = [False]*max(N,M)
toN = [False]*max(N,M)
for i in range(M):
  a,b = map(int,input().split())
  if a ==1 or b ==1:
    from1[a-1 if a!= 1 else b-1]=True
  if a == N or b == N:
    toN[a-1 if a!= N else b-1]=True
cnt =0 
for i in range(M):
  cnt+=from1[i]&toN[i]
print("POSSIBLE" if cnt else "IMPOSSIBLE")

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

#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define lrp(i,n) for(long long i=0;i<n;i++)
#define lrep(i,m,n) for(long long i=m;i<=n;i++)
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define elif else if
#define unique(a) a.erase(unique(a.begin(),a.end()),a.end())
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef string S;
typedef queue<int> qi;

int gcd(int a,int b){
    if(b!=0){
        return gcd(b,a%b);
    }else{
        return a;
    }
}
int main(){
    int n,k;
    cin >> n >> k;
    vi a(n);
    rp(i,n){
        cin >> a.at(i);
    }
    sort(a);
    if(a.at(n-1)<k){
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }
    int GCD=a.at(0);
    rep(i,1,n-1){
        GCD=gcd(GCD,a.at(i));
    }
    if(k%GCD){
        cout << "IMPOSSIBLE" << endl;
    }else{
        cout << "POSSIBLE" << endl;
    }
    return 0;
}


Measured memory_bytes: 640
n = int(input())
p = list(map(int,input().split()))
c = 0
for i in range(n-2):
    if p[i] < p[i+1] and p[i+1] < p[i+2]:
        c += 1
    elif p[i] > p[i+1] and p[i+1] > p[i+2]:
        c += 1
print(c)

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

int main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  int res = 0;
  for (int a = 0; a <= A; ++a) {
    for (int b = 0; b <= B; ++b) {
      for (int c = 0; c <= C; ++c) {
        int total = 500*a + 100*b + 50*c; // 合計金額
        if (total == X) ++res; // 合計金額が X に一致したら答えをインクリメント
      }
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 256
x, y, z, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
AB = [x + y for x in A for y in B]
AB.sort(reverse=True)
ABC = [x + y for x in AB[:min(len(AB), k)] for y in C[:min(len(C), k)]]
ABC.sort(reverse=True)
for i in range(k):
    print(ABC[i])

Measured memory_bytes: 208204
#include <bits/stdc++.h>
using namespace std;
using lint = long long;

using pi = pair<int, int>;
using frac = pair<lint, lint>;
const int MAXN = 100005;

int n;
pi a[MAXN];
lint sum[MAXN];

bool cmp(frac a, frac b){
	return (__int128)a.first * b.second < (__int128)b.first * a.second;
}

lint gcd(lint x, lint y){ return y ? gcd(y, x%y) : x; }

int main(){
	scanf("%d",&n);
	for(int i=0; i<n; i++) scanf("%d %d",&a[i].first,&a[i].second);
	sort(a, a + n, [&](const pi &p, const pi &q){
		return max(p.first, p.second) > max(q.first, q.second);
	});
	frac dap(n, 1);
	auto upd_val = [&](lint n, lint a, lint b){
	//	assert(a <= b);
		a += n * b;
		dap = min(dap, frac(a, b), cmp);
	};
	lint sumA = 0;
	for(int i=1; i<=n; i++){
		sumA += a[i-1].first;
		sum[i] = sum[i-1] + max(a[i-1].first, a[i-1].second);
	}
	for(int i=0; i<n; i++){
		if(sum[i] >= sumA - a[i].second){
			auto lb = lower_bound(sum, sum + i + 1, sumA - a[i].second) - sum;
			lint tmp = sumA - sum[lb];
			if(tmp <= 0){
				upd_val(lb, 0, 1);
			}
			else{
				upd_val(lb, tmp, a[i].second);
			}
		}
		else{
			lint newval = sumA + max(a[i].first, a[i].second);
			auto lb = lower_bound(sum + i + 1, sum + n + 1, newval - a[i].second) - sum;
			lint tmp = newval - sum[lb];
			if(tmp <= 0) upd_val(lb - 1, 0, 1);
			else{
				if(tmp <= a[i].second) upd_val(lb - 1, tmp, a[i].second);
			}
		}
	}
	dap.first = (n * dap.second - dap.first);
	dap.second *= n;
	
	{
		lint g = gcd(dap.first, dap.second);
		dap.first /= g; dap.second /= g;
	}
	printf("%lld %lld\n", dap.first, dap.second);
}


Measured memory_bytes: 1792
from random import randrange


def is_valid(ans_types: list, ans_val: int) -> bool:
    """ans_types(1-indexed)を選んだときに、
    答えがans_valになるかどうかを確かめる。"""
    res = 0

    tmp_last_days = {}
    for c_type in range(1, C_TYPES + 1):
        tmp_last_days[c_type] = 0
   
    for day in range(1, DAYS + 1):
        c_type = ans_types[day - 1]
        res += s[day][c_type]

        tmp_last_days[c_type] = day
        for c_type in range(1, C_TYPES + 1):
            res -= c[c_type] * (day - tmp_last_days[c_type])

    return res == ans_val


def search_max_point(day: int, last_days: dict):
    """day-1日目までに選んだコンテストが確定している状態で
    day日目にどのコンテストを選べば満足度を最適化できるか貪欲に探索する。
    dayは1-indexedに注意。
    返値として、選ぶコンテスト(1-indexed)、そのときに得られる満足度を返す。
    """
    max_val = -INF
    max_type = -1
    for c_type in range(1, C_TYPES + 1):
        tmp = s[day][c_type]
        for c_type2 in range(1, C_TYPES + 1):
            if c_type2 == c_type:
                continue
            tmp -= c[c_type2] * (day - last_days[c_type2])
        if max_val < tmp:
            max_val = tmp
            max_type = c_type
    return max_type, max_val


def change(ans_types: list, day: int, from_type: int, to_type:int):
    """day日目のコンテストをfrom_typeからto_typeに変更する。
    dayは1-indexed、選ぶコンテストは1-indexedに注意。
    返値として、そのときに得られる満足度の変化量を返す。
    """
    res_diff = 0
    res_diff = -s[day][from_type] + s[day][to_type]

    from_t = ans_types
    to_t = ans_types[0:]
    to_t[day - 1] = to_type

    l_day = {from_type: 0, to_type: 0}
    for day, type_c in enumerate(from_t):
        day += 1
        if type_c in l_day:
            l_day[type_c] = day
        for type_c2 in l_day:
            res_diff += c[type_c2] * (day - l_day[type_c2])

    l_day = {from_type: 0, to_type: 0}
    for day, type_c in enumerate(to_t):
        day += 1
        if type_c in l_day:
            l_day[type_c] = day
        for type_c2 in l_day:
            res_diff -= c[type_c2] * (day - l_day[type_c2])
    return res_diff

# 1-indexedに統一(重要！！！！)
d = int(input())  # 365
c = [0] + list(map(int, input().split()))
s = [[0 for i in range(27)]] + [[0] + list(map(int, input().split())) for i in range(d)]

# 重要な定数
DAYS = d
C_TYPES = 26
INF = 10 ** 18

# last_days: 最後にコンテストを行った日を記録する
last_days = {}
for c_type in range(1, C_TYPES + 1):
    last_days[c_type] = 0

# Step1.
# 貪欲で初期解を構築する
ans_val = 0
ans_types = []
for day in range(1, DAYS + 1):
    c_type, val = search_max_point(day, last_days)
    ans_types.append(c_type)
    ans_val += val
    last_days[c_type] = day

# 解が不当な場合(アルゴリズムが正しく構築できてない場合)、REにさせる。
if not is_valid(ans_types, ans_val):
    print(re)
    exit()


# Step2.
# 初期解をランダムに変形させて、解をより良くする。
cnt = 0
while cnt < 1000:
    day = randrange(1, DAYS + 1)
    from_type = ans_types[day - 1]
    while True:
        to_type = randrange(1, C_TYPES + 1)
        if to_type != from_type:
            break
    diff = change(ans_types, day, from_type, to_type)
    if diff > 0:
        ans_types[day - 1] = to_type
        ans_val += diff
    cnt += 1
for i in ans_types:
    print(i)

Measured memory_bytes: 79252
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;


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


signed main(){
    int x;
    cin >> x;

    int p=x;
    while(!is_prime(p)) p++;
    cout << p<<endl;
    return 0;
  
}

Measured memory_bytes: 256
n = int(input())
a_list = list(map(int,input().split()))
b_list = list(map(int,input().split()))
if sum(a_list)<sum(b_list):
    print(-1)
else:
    diff_list = [a_list[i]-b_list[i] for i in range(n)]
    posi_list=[]
    cnt,diff_sum = 0,0
    for diff in diff_list:
        if diff<0:
            cnt+=1
            diff_sum+=diff
        elif diff>0:
            posi_list.append(diff)
    diff_sum*=(-1)
    posi_list.sort(reverse=True)
    i,S=0,0
    while S<diff_sum:
        S+=posi_list[i]
        i+=1
    print(i+cnt)

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

const bool DEBUG = false;

int main(int argc, char const *argv[]) {
  int A, B;
  cin >> A >> B;
  if (A > 9) {
    cout << "-1" << endl;
    return 0;
  }
  if (B > 9) {
    cout << "-1" << endl;
    return 0;
  }
  cout << A * B << endl;

  return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>
//#include<bits/stdc++.h>

using namespace std;
long long MOD = 1000000007LL;
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define endl "\n"

template<class T>
map<T, int> prime_factorization(T n) {
	map<T, int> ret;

	for (long long i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}

	if (n != 1)ret[n] = 1;
	return ret;
}



int main() {
	map<int, int> aret;
	map<int, int> bret;
	int a, b;

	cin >> a >> b;
	aret = prime_factorization(a);
	bret = prime_factorization(b);
	
	map<int, int> ret;
	for (auto i = aret.begin(); i != aret.end(); ++i) {
		ret[i->first] = i->second;
	}
	for (auto i = begin(bret); i != end(bret); ++i) {
		ret[i->first] = max(ret[i->first], i->second);
	}

	long long ans = 1;
	for (auto i = begin(ret); i != end(ret); ++i) {
		ans *= pow(i->first, i->second);
	}

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



Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBAG = false;

int main(){

    string s;
    cin >> s;
    
    string s_inv;
    for(int i = 0; i < s.size(); i++){
        s_inv.push_back(s[s.size() - 1 - i]);
    }

    int id = 0;
    int id_inv = 0;
    ll cnt = 0;
    while( id != s.size() ){
        if(s[id] == s_inv[id_inv]){
            id ++;
            id_inv ++;
        }
        else if(s[id] == 'x'){
            id  ++;
            cnt ++;
        }
        else if(s_inv[id_inv] == 'x'){
            id_inv ++;
            //cnt ++;
        }
        else{
            cout << -1 << endl;
            return 0;
        }
    }

    cout << cnt << endl;


}

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

int main(){
    int sx,sy,tx,ty;
    cin >> sx >> sy >> tx >> ty;
    for(int i = 0;i < tx-sx;i ++){
        cout << "R";
    }
    for(int i = 0;i < ty-sy;i ++){
        cout << "U";
    }
    for(int i = 0;i < tx-sx;i ++){
        cout << "L";
    }
    for(int i = 0;i < ty-sy+1;i ++){
        cout << "D";
    }
    for(int i = 0;i < tx-sx+1;i ++){
        cout << "R";
    }
    for(int i = 0;i < ty-sy+1;i ++){
        cout << "U";
    }
    cout << "LU";
    for(int i = 0;i < tx-sx+1;i ++){
        cout << "L";
    }
    for(int i = 0;i < ty-sy+1;i ++){
        cout << "D";
    }
    cout << "R" << endl;
    return 0;
}

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

using namespace std;
using ll = long long;
using vi = vector<int>;
using vii = vector<vi>;

const long long int llinf = 1LL << 62;
const int inf = 99999999;
const int dx[4] = { 1,0,-1,0 };
const int dy[4] = { 0,1,0,-1 };

#define Endl endl
#define pr(x) cout << x << endl
#define FOR(i,a,b) for(int i = a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb(a) push_back(a);
#define mp(a,b) make_pair(a,b)
#define atcoder int(1e9) +7;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
#define all(x) x.begin,x.end();

int main() {
	
	int n, p;
	cin >> n >> p;
	ll eo[2] = { 0 };

	rep(i, n) {
		int a;
		cin >> a;
		eo[a % 2]++;
	}

	ll odd = 1, even = 1;
	rep(i, eo[0]) even *= 2;
	FOR(i, 1, eo[1])odd *= 2;

	if (p == 1 && eo[1] == 0)odd = 0;
	pr(even * odd);

	return 0;
}

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

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

int main() {
    ll n; cin >> n;
    vector<ll> a(n); 
    rep (i, n) {
        cin >> a[i];
        a[i]--;
    }
    ll sum = accumulate(a.begin(), a.end(), 0);
    cout << sum << endl;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

ll cnt[20][20];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  int n;
  cin>>n;
  FOR(i, 1, n+1){
    int m=i;
    int x=m%10, y=m%10;
    while(m>0){
      y=m%10;
      m/=10;
    }
    ++cnt[y][x];
  }
  // FOR(i, 1, 10){
  //   FOR(j, 1, 10){
  //     cout<<cnt[i][j]<<" \n"[j==9];
  //   }
  // }
  ll ans=0;
  FOR(i, 1, 10){
    FOR(j, i, 10){
      if(i==j){
        ans+=cnt[i][i]*cnt[i][i];
        // if(cnt[i][i]*cnt[i][i]>0){
        //   DEBUG(i);DEBUG(j);
        // }
      }
      else{
        ans+=cnt[i][j]*cnt[j][i]*2;
        // if(cnt[j][i]*cnt[i][j]>0){
        //   DEBUG(i);DEBUG(j);
        // }
      }
    }
  }
  cout<<ans<<'\n';
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int r;
    if (k <= a) {
        r = k;
    } else if (k <= a + b) {
        r = a;
    } else {
        r = a - (k - a - b);
    }

    cout << r << endl;

    return 0;
}

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

using namespace std;
using ll =long long;
using db = double;

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; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define leftunique(a) {SORT(a);(a).erase(unique((a).begin(),(a).end()),(a).end());}
//leftuniqueは配列から同じ要素のものを取り除く 例 4 6 2 1 3 4 1 2 なら 1 2 3 4 6 になる
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}
const int mod = 1e9 + 7;
const ll INF = 1LL << 60;

//ここから書き始める

int main()
{
	cout << setprecision(10);


	ll n , k; cin >> n >> k;
	vector<ll> x(n);
	rep(i,n) cin >> x[i];
	ll ans  = INF ;
	for(int i = 0 ; i + k -1 < n ; i ++){
		//left x[i] , right x[i+k];
		ll left = x[i];
		ll right = x[i+k-1];

		ll tmpleft = abs (right - left) + abs(left);
		ll tmpright = abs( right - left) + abs(right);
		
		ll tmp = min(tmpleft,tmpright);
		chmin(ans,tmp);
	}
	cout << ans << endl;
}


Measured memory_bytes: 1024
while True:
    h,w = map(int,input().split())
    if h == 0 and w == 0:
        break
    for x in range(h):
        if x == range(h)[0] or x == range(h)[-1]:
                print(w*"#",end="")
        else:
            for y in range(w):
                if y == range(w)[0] or y == range(w)[-1]:
                    print("#",end="")
                else:
                    print(".",end="")
        print()
    print()


Measured memory_bytes: 7004
def d_we_like_agc(N):
    from itertools import product
    MOD = 10 ** 9 + 7

    # dp[i][j][k][l]: Sの先頭i文字目を見ているとき、i-3, i-2, i-1番目の文字が
    # j, k, lだとして、そのような文字列が何通り存在するか
    # ACGTはそれぞれ0123と対応付けされる
    dp = [[[[0 for k in range(4)] for k in range(4)] for j in range(4)] for i in range(N + 1)]
    # 文字の制約はAGCに関するものであり、Tは関係ない。
    # よって、調べる文字列が 'TTT' + S だとしていい。
    dp[0][3][3][3] = 1

    def digit2acgt(a, b, c, d):
        # 4つの数字abcdを対応するACGTに変換する
        a, b, c, d = map(lambda x: 'ACGT'[x], (a, b, c, d))
        return ('*' + b + c + d, a + '*' + c + d, a + b + '*' + d)

    for k in range(N):
        for c0, c1, c2, c3 in product(range(4), repeat=4):
            for s in digit2acgt(c0, c1, c2, c3):
                # これらの文字列は許されない
                if s in ('*AGC', '*GAC', '*ACG', 'A*GC', 'AG*C'):
                    break
            else:
                # 文字列 TTT...c0c1c2(TTTを除く長さk) の末尾にc3を加えることが許される
                # 次回は新しい文字列 TTT...c1c2c3(長さk+1)に対して同じことを行う
                dp[k + 1][c1][c2][c3] += dp[k][c0][c1][c2]
                dp[k + 1][c1][c2][c3] %= MOD

    ans = 0
    for c0, c1, c2 in product(range(4), repeat=3):
        ans += dp[N][c0][c1][c2]
        ans %= MOD
    return ans

N = int(input())
print(d_we_like_agc(N))

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

int main() {
  long long a,b,c,d;
  long long ans;
  
  cin >> a >> b >> c >> d;
  
  if(a>=0){
    ans = max(b*d,a*d);
  } else{
    if(b>=0){
      ans = max(b*d,a*c);
    } else{
      ans = max(b*c,a*c);
    }
  }
       
  cout << ans << endl;
}


Measured memory_bytes: 3568
#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <list>
#include <map>
#include <deque>
#include <algorithm>
#include <utility>
#include <stdio.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
#define for1(i,n) for (ll i=0;i<(n);i++)
#define for2(i,m,n) for (ll i=(m);i<(n);i++)
#define for3(i,m,n,d) for (ll i=(m);i<(n);i+=(d))
#define DEBUG 0
template <class T>
void dumplist(T list)
{
    for (auto item : list) {
        cout << item << " ";
    }
    cout << endl;
}


ll dp[2001][2001][2];
#define mod 1000000007

void solve()
{
    ll N,M;
    cin >> N >> M;
    vll S(N);
    vll T(M);
    for1(i,N) {
        cin >> S[i];
    }
    for1(i,M) {
        cin >> T[i];
    }
    dp[0][0][0] = 1;
    for1(i,N+1) {
        for1(j,M+1) {
            if (i >= 1 && j >= 1) {
                if (S[i-1]==T[j-1]) {
                    dp[i][j][0] += dp[i-1][j-1][0];
                    dp[i][j][0] += dp[i-1][j-1][1];
                    dp[i][j][0] %= mod;
                }
            }
            if (i >= 1) {
                dp[i][j][0] += dp[i-1][j][0];
                dp[i][j][0] %= mod;
            }
            if (j >= 1) {
                dp[i][j][1] += dp[i][j-1][0];
                dp[i][j][1] += dp[i][j-1][1];
                dp[i][j][1] %= mod;
            }
        }
    }
    cout << (dp[N][M][0]+dp[N][M][1]) % mod << endl;
}

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


Measured memory_bytes: 62848
import java.util.*;
import java.io.*;
 
public class Main{
    
	public static void main(String[] $){
		Scanner s = new Scanner(System.in);
		int X = s.nextInt();
		int Y = s.nextInt();
		boolean isTrue = false;
		for(int i = 0; i <= X; i++){
			if(Y == 2*(i)+4*(X-i)) isTrue = true;
		}
		if(isTrue){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
			
	}
} 

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

int main(){
    int a, b;
    char op;
    while(cin >> a >> op >> b,op!='?'){
        switch (op)
        {
        case '+':
            cout << a+b << endl;
            break;
        case '-':
            cout << a-b << endl;
            break;
        case '*':
            cout << a*b << endl;
            break;
        case '/':
            cout << a/b << endl;
            break;
        default:
            break;
        }
    }
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

ll pow(ll b, ll e) {
  if(e==0) return 1;
  if(e%2==0) {
    ll t = pow(b,e/2);
    return t*t;
  }
  return b*pow(b,e-1);
}


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  cout<<fixed;
  ll K,c=0;
  cin>>K;
  if(K<10) {
    cout << K << endl;
    return 0;
  }
  unordered_map<ll,unordered_map<ll,vector<ll>>> mp;
  vector<ll> cand;
  rep(i,10) {
    mp[0][i].push_back(i);
    cand.push_back(i);
  }

  repeat(i,1,12) {
    repeat(j,1,10) {
      if(j==1) {
	rep(ii,i-1) {
	  for(auto x : mp[ii][0]) {
	    ll y = pow(10,i)+x;
	    mp[i][j].push_back(y);
	    cand.push_back(y);
	  }
	  for(auto x : mp[ii][1]) {
	    ll y = pow(10,i)+x;
	    mp[i][j].push_back(y);
	    cand.push_back(y);
	  }
	}
      }
      rep(k,10) {

	if(abs(j-k)<=1) {
	  for(auto x : mp[i-1][k]) {
	    ll y = pow(10,i)*j+x;
	    //	    	    cout << "c=" << c << " y=" << y << endl;
	    mp[i][j].push_back(y);
	    cand.push_back(y);
	  }
	}
      }
    }
  }
  sort(cand.begin(),cand.end());
  cout << cand[K] << endl;
  return 0;
}


Measured memory_bytes: 32740
N = gets.to_i
S = gets
 
slimes = S.chars
 
i = 0
cnt = 0
 
slimes.length.times do
  break if i == slimes.length - 1
  
  if slimes[i] == slimes[i+1]
    #
  else
    cnt += 1
  end
  
  i += 1
end
 
p cnt

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;

int x;

#define POOL_SIZE 10000 // (10^9)^0.2 = 63.1
ll pool_p[POOL_SIZE];
//ll pool_n[POOL_SIZE];

ll mod5(ll n)
{
	return ((((((((n*n) % MOD) * n) % MOD)* n) % MOD)* n) % MOD);
}

bool calc(ll diff)
{
	//cout << "diff : " << diff << endl;
	if (diff > POOL_SIZE)
	{
		return false;
	}
	// a-b = diff
	for(int a = 0; a < POOL_SIZE; ++a)
	{
		int b = a - diff;
		// cout << a << " " << b << " | " << mod5(a) << " " << mod5(b) << " " << mod5(a) - mod5(b) << endl;
		if(((mod5(a) - mod5(b)) + MOD) % MOD == x % MOD)
		{
			cout << a << " " << b << endl;
			return true;
		}
	}
	return false;
}

void solve()
{
	cin >> x;

	pool_p[0] = 0;//pool_n[0] = 0;
	for(int i = 1; i < POOL_SIZE; ++i)
	{
		pool_p[i] = pow(i, 5);
		//pool_n[i] = -pool_p[i];
		//cout << pool_p[i] << " " << pool_n[i] << endl;
	}

	//cout << "in " << x << endl;

	// a - b は x の約数
	for (int i = 1; i * i <= x; i++)
	{
		if(x % i == 0)
		{
			if (calc(i)) return;
			if (calc(x / i)) return;
		}
	}

}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 4288
// Package main provides
//
// File:  d.go
// Author: ymiyamoto
//
// Created on Mon Jan  7 17:54:40 2019
//
package main

import (
	"errors"
	"fmt"
)

type graph [][]int

func warshalFloyd(g graph) (int, error) {
	g2 := make(graph, len(g))
	for i := range g2 {
		g2[i] = make([]int, len(g[i]))
		copy(g2[i], g[i])
	}

	for k := range g {
		for i := range g {
			for j := range g {
				if g[i][k]+g[k][j] < g[i][j] {
					return 0, errors.New("error")
				} else if i != k && k != j && g[i][k]+g[k][j] == g[i][j] {
					g2[i][j] = 0
				}
			}
		}
	}

	sum := 0
	for i := range g2 {
		for j := range g2[i] {
			sum += g2[i][j]
		}
	}

	return sum / 2, nil
}

func main() {
	var N int
	fmt.Scan(&N)

	routes := make(graph, N)
	for i := range routes {
		routes[i] = make([]int, N)
		for j := range routes[i] {
			fmt.Scan(&routes[i][j])
		}
	}

	if n, err := warshalFloyd(routes); err != nil {
		fmt.Println(-1)
	} else {
		fmt.Println(n)
	}
}


Measured memory_bytes: 4736