akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	set<string> st;
	bool ok = true;
	string t;
	cin >> t;
	st.insert(t);
	REP(i, n - 1) {
		string s;
		cin >> s;
		if (t.back() != s.front())ok = false;
		if (st.count(s))ok = false;
		st.insert(s);
		t = s;
	}
	if (ok)cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
from collections import deque
import sys
sys.setrecursionlimit(10**8)

def dp(dp_l,i,N,xs,cum,now):
    if i == N:
        if now == 0:
            return True
        return False
    if abs(now) > cum[i]:
        return False
    if dp_l[i][abs(now)] != -1:
        return dp_l[i][abs(now)]
    dp_l[i][abs(now)] = dp(dp_l,i+1,N,xs,cum,now+xs[i]) or dp(dp_l,i+1,N,xs,cum,now-xs[i])
    return dp_l[i][abs(now)]

def check():
    S = input()
    x, y = map(int, input().split())
    fs = list(map(len,S.split('T')))
    if len(fs)<3:
        if x != fs[0]:
            return False
        if len(fs)==1:
            if y == 0:
                return True
            else:
                return False
        if y != fs[1] and y != -fs[1]:
            return False
        return True
    xs = fs[2::2]
    ys = fs[1::2]
    xs.sort(reverse = True)
    N = len(xs)
    M = len(ys)
    cum = [0]*(N+1)
    for i in range(N-1,-1,-1):
        cum[i] = cum[i+1]+xs[i]
    dp_l = [[-1]*(cum[0]+1) for _ in range(N)]
    if not dp(dp_l,0,N,xs,cum,fs[0]-x):
        return False
    ys.sort(reverse = True)
    cum = [ys[-1]]*(M+1)
    for i in range(M-1,-1,-1):
        cum[i] = cum[i+1]+ys[i]
    dp_l = [[-1]*(cum[0]+1) for _ in range(M)]
    if not dp(dp_l,0,M,ys,cum,-y):
        return False
    return True
if check():
    print('Yes')
else:
    print('No')

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

using namespace std;
using namespace __gnu_pbds;

typedef long long 		ll;
typedef unsigned long long 		ull;
typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//find_by_order kth largest  order_of_key <
const int tam = 100010;
const int MOD = 1e9+7;
const double EPS = 1e-9;
int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	//freopen("qwe.txt", "r", stdin);
	//freopen("asd.txt", "w", stdout);
	int n;
	ll ta;
	cin>>n>>ta;
	pair<ll,ll> pre[n], suf[n];
	ll masu[n], mapre[n];
	ll res = 0;
	fore(i, 0, n)
	{
		cin>>pre[i].f>>pre[i].s;
		suf[n - i - 1] = pre[i];
		suf[n - i - 1].f = ta - suf[n - 1 - i].f;
	}
	ll acu1 = pre[0].s, acu2 = suf[0].s;
	mapre[0] = max(0ll, pre[0].s - pre[0].f);
	masu[0] = max(0ll, suf[0].s - suf[0].f);
	fore(i, 1, n)
	{
		mapre[i] = max(mapre[i-1], acu1 + pre[i].s - pre[i].f);
		acu1 += pre[i].s;
		masu[i] = max(masu[i-1], acu2 + suf[i].s - suf[i].f);
		acu2 += suf[i].s;
	}	
	res = max(res, max(mapre[n-1], masu[n-1]));
	fore(i, 0, n-1)
	{
		res = max(res, mapre[i] - pre[i].f + masu[n - i - 2]);
		res = max(res, masu[i] - suf[i].f + mapre[n - i - 2]);
	}
	cout<<res<<'\n';
	return 0;
}

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

Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <queue>

using namespace std;

#define lli long long int
#define REP(i,n) for(int i=0;i<n;i++)
#define REP2(i,n) for(int i=1;i<=n;i++)
#define DEBUG 0

int main(){

	lli n,a,b;
	cin>>n>>a>>b;

	vector<lli> x(n);
	REP(i,n)cin>>x[i];

	lli ans=0;
	for(lli i=1;i<n;i++){
		if(a*(x[i]-x[i-1])<b)ans+=(a*(x[i]-x[i-1]));
		else ans+=b;
	}

	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 1024
n=int(input())
s=[list(input()) for i in range(n)]
for i in s:
  i.sort()
s.sort()
cnt=1
ans=0
for i in range(n-1):
  if s[i]==s[i+1]:
    if i!=n-2:
      cnt+=1
    else:
      cnt+=1
      ans+=(cnt*(cnt-1))//2
  else:    
    ans+=(cnt*(cnt-1))//2
    cnt=1
print(ans)

Measured memory_bytes: 24652
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;


namespace AtC
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var S = Console.ReadLine();
            var K = int.Parse(Console.ReadLine());

            Console.WriteLine(Regex.Replace(S, "[^" + S[K - 1] + "]", "*"));
        }
    }

    static class EnumerableExtension
    {
        public delegate void Function<in T>(T val);

        public static void ForEach<T>(this IEnumerable<T> enumerable, Function<T> function)
        {
            foreach (var x in enumerable)
            {
                function(x);
            }
        }
    }
}

Measured memory_bytes: 16068
N, M = map(int, input().split())
A = []
B = []
for i in range(N):
  A.append(list(input()))
for i in range(M):
  B.append(list(input()))

f = False
ff = False

for i in range(N-M+1):
  for j in range(N-M+1):
    f = True
    for k in range(M):
      for l in range(M):
        if A[i+k][j+l] != B[k][l]:
          f = False
    if f:
      ff = True
      break

if ff:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
def submit():
    n, k = map(int, input().split())

    if k % 2:
        count = sum([1 for c in range(1, n + 1) if c % k == 0])
        print(count ** 3)
    else:
        count_1 = sum([1 for c in range(1, n + 1) if c % k == 0])
        count_2 = sum([1 for c in range(1, n + 1) if c % k == k // 2])
        print(count_1 ** 3 + count_2 ** 3)


if __name__ == "__main__":
    submit()

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

typedef long long ll;
using namespace std;
const int INF = 1e9;
long long mod = 1000000000+7;
vector<vector<int> >g;
   //         int n,m;

    vector<vector<int> > grid(501,vector<int>(501,INF));
    vector<vector<int> > x(501,vector<int>(501,-1));
  long long  pow(long long  a, long long  b, long long m)
 {
        stack<int>k;
        int j = 128;
        int l = 1;
       int an = 1;
        while(b){
            if(b>=j){
                k.push(j);
                b-=j;
            }
            j/=2;
        }
        while(!k.empty()){
            if(k.top()==l){
                an = (an*a)%mod;
                k.pop();
            }
            a = (a*a)%mod;
            l*=2;
        }

        return an;
 }


 int main(){
   ios_base::sync_with_stdio(0);cin.tie(NULL);
   // freopen("zeros.in","r",stdin);
    //freopen("pizza.out","w",stdout);
			long long n,x;
   cin>>n>>x;
   			cout<< 3*(n-__gcd(n,x))<<endl;
                return 0;
}


Measured memory_bytes: 2304
N,W = map(int,input().split(" "))
w = [0]*N
v = [0]*N
for i in range(N):
    w[i],v[i] = map(int,input().split(" "))

V = sum(v)
dp = [[2**60]*(V+1) for i in range(N+1)]
dp[0][0] = 0
for i in range(N):
    for j in range(V+1):
        if j - v[i] >= 0:
            dp[i+1][j] = min(dp[i][j],dp[i][j-v[i]]+w[i])
        else:
            dp[i+1][j] = min(dp[i+1][j],dp[i][j])
ans = 0
for i in range(N+1):
    for j in range(V+1):
        if dp[i][j] <= W:
            ans = max(ans,j)
print(ans)

Measured memory_bytes: 120044
def input_from_console():
    n = int(input())
    a_list, b_list = [], []
    for i in range(n - 1):
        data = input()
        a, b = map(int, data.split())
        if b > a:
            a, b = b, a  # swap smaller one.
        a_list.append(a)
        b_list.append(b)
    c_list = list(map(int, input().split()))
    return n, a_list, b_list, c_list


def solve(n, a_list, b_list, c_list):
    edge = [[] for i in range(n)]  # 0 based list of list.
    for i in range(len(a_list)):
        a, b = a_list[i] - 1, b_list[i] - 1  # convert to 0 based index.
        edge[a].append(b)
        edge[b].append(a)
    c_list.sort(reverse=True)

    vertices = [None] * n
    vertices[0] = c_list.pop(0)

    graph_value = sum(c_list)  # edge should have the value except the maximum. 

    search_path = []
    search_path.extend(edge[0])

    while search_path:
        node = search_path.pop(0)
        if vertices[node] is None:
            vertices[node] = c_list.pop(0)
            search_path.extend(edge[node])
    return "{:d}\n{}".format(graph_value, ' '.join(map(str, vertices)))


def main():
    n, a_list, b_list, c_list = input_from_console()
    print(solve(n, a_list, b_list, c_list))


if __name__ == "__main__":
    import sys

    if sys.gettrace():  # Check if the python interpreter is in debug mode or not.
        check_cases()
    else:
        main()

Measured memory_bytes: 6648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acosl(-1);

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

    int N;
    cin >> N;
    vector<vector<char>> S(N, vector<char>(N));
    for (int i = 0; i < N; ++i)
        for (int j = 0; j < N; ++j)
            cin >> S[i][j];

    ll ans = 0;
    for (int i = 0; i < N; ++i) {
        {
            bool flag = true;
            for (int j = 0; j < N && flag; ++j) {
                for (int k = j + 1; k < N && flag; ++k) {
                    int ktmp = k - i, jtmp = j - i;
                    if (ktmp < 0)
                        ktmp += N;
                    if (jtmp < 0)
                        jtmp += N;
                    if (S[j][ktmp] != S[k][jtmp])
                        flag = false;
                }
            }
            if (flag)
                ans += N - i;
        }

        if (i != 0) {
            bool flag = true;
            for (int j = 0; j < N && flag; ++j) {
                for (int k = j + 1; k < N && flag; ++k) {
                    int ktmp = k - i, jtmp = j - i;
                    if (ktmp < 0)
                        ktmp += N;
                    if (jtmp < 0)
                        jtmp += N;
                    if (S[jtmp][k] != S[ktmp][j])
                        flag = false;
                }
            }
            if (flag)
                ans += N - i;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
using System;
using CompLib.Util;

public class Program
{
    private int N, X, Y;

    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        X = sc.NextInt() - 1;
        Y = sc.NextInt() - 1;
        var ans = new int[N - 1];
        int d = Y - X;

        for (int i = 0; i < N; i++)
        {
            for (int j = i + 1; j < N; j++)
            {
                int t = j - i;
                t = Math.Min(t, 1 + Math.Abs(i - X) + Math.Abs(j - Y));
                t = Math.Min(t, 1 + Math.Abs(i - Y) + Math.Abs(j - Y));
                ans[t - 1]++;
            }
        }

        Console.WriteLine(string.Join("\n", ans));
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 13268
'use strict'

function main(input) {

    input = input.split(/\n|\s/).map(v => ~~v)
    const sum = input[0] + input[1] - (input[2] + input[3])

    let ans = 'Balanced'

    if (sum > 0) {
        ans = 'Left'
    } else if (sum < 0) {
        ans = 'Right'
    }
    console.log(ans)

}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define long long long
#define up(i,a,b) for (int i=a; i<=b; i++)
#define down(i,a,b) for (int i=a; i>=b; i--)
#define endl '\n'
#define X first
#define Y second
#define II pair<int, int>
#define III pair<int, pair<int, int> >
#define debug(X) cerr<< #X << " = " <<X << endl
#define debug2(X,Y) cerr<< #X << " = " <<X << ","<<#Y<<" = "<<Y<<endl
#define show(X,a,b) {cerr << #X << " = "; up(__,a,b) cerr << X[__] << ' '; cerr << endl;}
#define gc getchar
#define pc putchar
using namespace std;

inline void read(int &x)
{
    register int c = gc();
    x = 0;
    int neg = 0;
    for (;((c<48 || c>57) && c != '-') ;c = gc());
    if(c=='-') {neg=1;c=gc();}
    for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}
inline void writeln(int x){

         char buffor[21];
         register int i=0;
         int neg=0; if (x<0) {neg=1; x= -x;}
         do{
               buffor[i++]=(x%10)+'0';
               x/=10;
            } while(x);
           i--;
           if (neg) pc('-');
           while(i>=0) pc(buffor[i--]);
           pc('\n');
       }
const int N= 2e5+10;
string s;
int n;
vector<int> List[26];
int cur[26], bit[N], ok[N];
void input()
{
    cin>>s; n= (int)s.size(); s= " "+ s;
}
void update(int x, int val)
{
    for (int i= x; i<= n; i+= i& (-i)) bit[i]+= val;
}
int query(int x)
{
    int res= 0;
    for (int i= x; i>= 1; i-= i& (-i)) res+= bit[i];
    return res;
}
void solve()
{
    down(i,n,1)
    {
        int c= (int)(s[i]- 'a'); List[c].push_back(i);
    }

    int odd= 0;
    up(i,0,25)
     if ( (int)List[i].size()% 2== 1 )
	 {
        odd++;
        if (odd> 1)
		{
            cout<<-1; return;
		}
	 }
    up(i,0,25) cur[i]= 0;

    up(i,1,n) update(i,1);
    long res= 0; int cen= 0;
    up(i,1,n)
     if (!ok[i])
     {
        ok[i]= 1;
        int c= (int)(s[i]- 'a');
        int j= List[c][cur[c]]; cur[c]++;
        if (ok[j]== 1)
		{
			cen= 1; continue;
		}
        ok[j]= 1;
		res+= query(n)- query(j)+ cen;
		update(j, -1);
     }
    cout<<res;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);// don't use when interactive

    #ifdef I_Love_Pork
    #define TASK "tmp"
    freopen(TASK".inp","r",stdin);
    freopen(TASK".out","w",stdout);
	  #endif

    input();
    solve();

    return 0;
}


Measured memory_bytes: 3408
#include<bits/stdc++.h>
using namespace std;
inline int_fast64_t read(){int_fast64_t x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return x*f;}
inline string read_s(){string s="";char c=getchar();while(c<'!'||c>'~'){c=getchar();}while(c>='!'&&c<='~'){s+=c;c=getchar();}return s;}
void Main(){
    int R, G, B, N, r, rg, ans = 0;
    R = read(); G = read(); B = read(); N = read();
    r = -R;
    for (int i = 0; i<=N; i++) {
        r += R;
        if (r > N) break;
        rg = r-G;
        for (int j = 0; j<=N; j++) {
            rg += G;
            if (rg > N) break;
            if ((N-rg)%B == 0) ans++;
        }
    }
    printf("%d\n", ans);
}
int main(){cin.tie(nullptr);ios::sync_with_stdio(false);Main();return 0;}

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

int main(){
  int i,co;
  string s;
  cin >> s;
  co=0;
  for(i=0;i<s.size();++i){
    if(i==1){
      if(s[i-1]==s[i]){
        if(s[i-1]=='0'){
          s[i]='1';
        }else{
          s[i]='0';
        }
        co=co+1;
      }
    }
    if(s[i]!=s[i%2]){
        s[i]=s[i%2];
        co=co+1;
      }
  }
  cout << co << endl;
  return 0;

}


Measured memory_bytes: 512
#include <stdio.h>
int main(void){
  int i,j,sum[100];
  int n,t[100],m,p[100],x[100];
  for(i=0;i<100;i++) sum[i]=0;
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&t[i]);
  scanf("%d",&m);
  for(i=0;i<m;i++) scanf("%d %d",&p[i],&x[i]);
  for(i=0;i<m;i++){
    for(j=0;j<n;j++){
      if(p[i]==j+1) sum[i]+=x[i];
      else sum[i]+=t[j];
    }
  }
  for(i=0;i<m;i++){
    printf("%d\n",sum[i]);
  }
  return(0);
}
    


Measured memory_bytes: 128
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int> > Matrix;


int main(){
  int n, m, x;
  cin >> n >> m >> x;
  vector<bool> a(n+1);
  rep(i, m) {
    int b;
    cin >> b;
    a[b] = true;
  }
  int l = 0, r = 0;
  for (int i = 0; i < x; i++){
    if (a[i]) l++;
  }

  for (int i = x; i < n; i++){
    if (a[i]) r++;
  }

  cout << min(l, r) << endl;
  
}

Measured memory_bytes: 256
# coding: utf-8

while True:
	a, b, c = map(int, raw_input().split())
	kosuu = a + b + c
	if kosuu == 0:
		break
	else:
		ans = [5]
		for i in range(1, kosuu+1):
			ans.append(2)

		N = int(raw_input())
		kekka_list = []
		for kensa in range(N):
			kekka = map(int, raw_input().split())
			kekka_list.append(kekka)
		for kekka in kekka_list:
			if kekka[3] == 1:
				ans[kekka[0]] = 1
				ans[kekka[1]] = 1
				ans[kekka[2]] = 1
		for kekka in kekka_list:
			if kekka[3] == 0:
				if ans[kekka[0]] * ans[kekka[1]] * ans[kekka[2]] == 2:
					for l in [kekka[0], kekka[1], kekka[2]]:
						if ans[l] == 2:
							ans[l] = 0
	for i in range(1, len(ans)):
		print(ans[i])

Measured memory_bytes: 4760
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    int n,m;
    cin >> n >> m;
    ll a[n];
    REP(i,n){
        cin >> a[i];
    }
    ll sum[n + 1] = {};
    REP(i,n){
        sum[i + 1] = sum[i] + a[i];
    }
    ll ans = 0;
    map<ll, int> mp;
    REP(i,n + 1){
        ans += mp[sum[i] % m];
        mp[sum[i] % m]++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5760
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
typedef long long Int;

int val(char c, int x){
	if(c == 'X')return x;
	return c - '0';
}

string add(string a, string b, int x){
	string res = "";
	int up = 0;
	if(a.size() > b.size())swap(a,b);
	for(int i = 0;i < b.size();i++){
		int num = val(b[b.size() - 1 - i], x);
		if((int)a.size() - 1 - i >= 0){
			num += val(a[a.size() - 1 - i], x);
		}
		num += up;
		res = (char)((num%10) + '0') + res;
		up =  num / 10;
	}
	if(up)res = '1' + res;
	return res;
}

string replace(string s, int x){
	string res = "";
	for(int i = 0;i < s.size();i++){
		if(s[i] == 'X')res += char('0' + x);
		else res += s[i];
	}
	return res;
}

void solve(string a, string b, string c){
	for(int i = 0;i <= 9;i++){
		if(a.size() != 1 && a[0] == 'X' || b.size() != 1 && b[0] == 'X' || c.size() != 1 && c[0] == 'X')if(i == 0)continue;
		if(replace(c, i) == add(a, b, i)){
			cout << i << endl;
			return;
		}
	}
	cout << "NA" << endl;
}

int main(){
	string str, a[3];
	char s[129];
	while(~scanf(" %s\n", s)){
		str = s;
		a[0] = a[1] = a[2] = "";
		int x = 0;
		if(str == "")return 0;
		for(int i = 0;i < str.size();i++){
			if(str[i] == '+' || str[i] == '=')x++;
			else a[x] += str[i];
		}
		
		solve(a[0], a[1], a[2]);
	}
	return 0;
}

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

int main(){
  unsigned long long N;
  cin >> N;
  vector<unsigned long long> A(N);
  unsigned long long result = 0;
  cin >> A.at(0);
  for(int i = 1; i < N; i++){
    cin >> A.at(i);
    if(A.at(i) < A.at(i-1)){
      int tmp = A.at(i-1) - A.at(i);
      result += tmp;
      A.at(i) += tmp;
    }
  }
  cout << result << endl;
}

Measured memory_bytes: 4784
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac
import fractions
from functools import reduce
from operator import mul
import bisect
import sys
import logging
import heapq
import itertools

logging.basicConfig(level=logging.ERROR)

input = sys.stdin.readline

setrecursionlimit(1000000)


def main():
	n = int(input())
	i = 10
	ans = 0
	while i <= n:
		ans += n//i
		i*=5
	print(ans if n%2==0 else 0)

def factorization(n):
	if n<2:
		return []
	arr = []
	temp = n
	for i in range(2, int(-(-n**0.5//1))+1):
		if temp%i==0:
			cnt=0
			while temp%i==0:
				cnt+=1
				temp //= i
			arr.append([i, cnt])

	if temp!=1:
		arr.append([temp, 1])

	if arr==[]:
		arr.append([n, 1])

	return arr

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(numbers):
	return reduce(fractions.gcd, numbers)

def lcm(numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

class PriorityQueue():
	def __init__(self):
		self.queue = []
	def push(self,i):
		heapq.heappush(self.queue,-i)
	def pop(self):
		return -1 * heapq.heappop(self.queue)
	def sum(self):
		return -sum(self.queue)

main()



Measured memory_bytes: 69356
using System;
using System.Collections.Generic;

namespace abc151_c
{
    class Program
    {
        static void Main()
        {
            var tmp = Console.ReadLine().Split();
            var n = int.Parse(tmp[0]);
            var m = int.Parse(tmp[1]);
            var correctSet = new HashSet<int>();
            var waMap = new Dictionary<int,int>();
            var resultCorrect = 0;
            var resultWrongAnswer = 0;
            for (var i = 0; i < m; i++)
            {
                tmp = Console.ReadLine().Split();
                var p = int.Parse(tmp[0]);
                var s = tmp[1];
                if (correctSet.Contains(p))
                {
                    continue;
                }

                if (s == "WA")
                {
                    if (waMap.ContainsKey(p))
                    {
                        waMap[p] += 1;
                    }
                    else
                    {
                        waMap[p] = 1;
                    }
                    continue;
                }

                //ACの場合

                if (waMap.ContainsKey(p))
                {
                    resultWrongAnswer += waMap[p];
                }

                resultCorrect += 1;
                correctSet.Add(p);
            }

            Console.Write(resultCorrect);
            Console.Write(" ");
            Console.WriteLine(resultWrongAnswer);
        }
    }
}


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

#define rep(i, s, n) for(int i = s; i < n; ++i)
#define rrep(i, n) for(int i = n - 1; i > -1; --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
const long long INF = 1000000000;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    ll n;
    cin >> n;
    map<string, ll> m;
    string s;
    rep(i, 0, n){
        cin >> s;
        sort(all(s));
        m[s] += 1;
    }
    ll ans = 0;
    for(auto mm : m){
        ans += mm.second * (mm.second - 1) / 2;
    }
    cout << ans << endl;


}

Measured memory_bytes: 11136
N, L, T = map(int, input().split())
Xs, Ws = [], []
for _ in range(N):
    X, W = map(int, input().split())
    Xs.append(X)
    Ws.append(W)

nums = []
X0, W0 = Xs[0], Ws[0]
for X, W in zip(Xs[1:], Ws[1:]):
    if W0 == W:
        nums.append(0)
    else:
        num = T//L * 2
        dist = (X-X0)%L if W0 == 1 else (X0-X)%L
        if T%L >= dist/2 + L/2:
            num += 2
        elif T%L >= dist/2:
            num += 1
        nums.append(num)
sumNum = sum(nums)

ZekkenAnt0 = sumNum%N if W0 == 1 else (-sumNum)%N
YZekkenAnt0 = (X0+T)%L if W0 == 1 else (X0-T)%L

Ys = [(X+T)%L if W == 1 else (X-T)%L for X, W in zip(Xs, Ws)]
Ys.sort()

iZekkenAnt0 = N-1-Ys[::-1].index(YZekkenAnt0) if W0 == 1 else Ys.index(YZekkenAnt0)
iZekken0 = (iZekkenAnt0-ZekkenAnt0)%N

anss = Ys[iZekken0:] + Ys[:iZekken0]
print('\n'.join(map(str, anss)))


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

using namespace std;

typedef pair<int, int> ii;

#define X first
#define Y second

map <int,int> ma[2];
ii ch[2];

int main() {
    int n;
    cin >> n;
    for(int i = 0; i < n; i++) {
        int x;
        cin >> x;
        ma[i&1][x]++;
    }
    int ans = n;
    for(auto j : ma[0]){
        if (j.Y > ch[1].Y) ch[1] = j;
        if (ch[1].Y > ch[0].Y) swap(ch[0], ch[1]);
    }
    for(int i = 0; i <= 1; i++){
        int cans = 0;
        for(auto j: ma[1]) if (j.X != ch[i].X) 
            cans = max(cans, j.Y);
        ans = min(ans, n - ch[i].Y - cans);
    }
    cout << ans;
}


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

string devide[4] = {"dream","dreamer","erase","eraser"};

int main(){
    string S;
    cin >> S;

    reverse(S.begin(),S.end());
    for(int i = 0;i < 4; ++i) reverse(devide[i].begin(),devide[i].end());
    bool can = true;
    for(int i = 0;i < S.size();){
        bool can2 = false;
        for(int j = 0;j < 4; ++j){
            string d = devide[j];
            if(S.substr(i,d.size()) == d){
                can2 = true;
                i += d.size();
            }
        }
        if(!can2){
            can = false;
            break;
        }
    }
    if(can) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define FOR0(i,n) for(i=0;i<n;i++)
#define FOR(i,j,n) for(i=j;i<n;i++)
#define FORD(i,j,k) for(i=j;i>=k;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 1000000000
#define ninf -1000000000
#define endl '\n' 
#define she_told_me_dont_worry ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// Use cout.flush() for interactive problems.
// Use this for increased stack size: g++ -o a.exe -Wl,--stack=256000000 -O2 source.cpp
inline long long  MAX2(long long  a, long long int b){return (a)>(b)?(a):(b);}
inline long long  MAX3(long long  a, long long  b,long long  c){return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  MIN2(long long  a, long long  b){return (a)<(b)?(a):(b);}
inline long long  MIN3(long long  a, long long b,long long c){return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;
ll h, n;
ll dp[1005][10005];
ll a[1005], b[1005];
ll compute(int i, int h)
{
    if( h <= 0 ) return 0;
    if( i == n) return inf;
    if(dp[i][h] != -1) return dp[i][h];
    // take
    ll ans = inf;
    ans = MIN2(ans, b[i] + compute(i, h-a[i]));
    // leave
    ans = MIN2(ans, compute(i+1, h));
    return dp[i][h] = ans;
}
int main()
{
    she_told_me_dont_worry
    cin>>h>>n;
    int i, j;
    FOR0(i, n+5)FOR0(j, h+5) dp[i][j] = -1;
    FOR0(i, n)
    {
        cin>>a[i]>>b[i];
    }
    cout<<compute(0, h)<<endl;
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
}

Measured memory_bytes: 78848
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

N = inp()

tmp = 0
i = 1
while tmp < N:
	tmp += i
	i += 1

x = tmp-N
for i in range(1,i):
	if i == x:
		continue
	print(i)


Measured memory_bytes: 4588
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int K = Integer.parseInt(sc.next());
        int [] hi = new int[N];

        for (int i = 0; i < N; i++) {

            hi[i] = Integer.parseInt(sc.next());
        }
        sc.close();

        int[] dp = new int[100000+1];

        dp[0] = 0;
        dp[1] = Math.abs(hi[1] - hi[0]);

        for (int i = 2; i < N; i ++) {

            int min = Integer.MAX_VALUE;

            for (int j = 1; j <= K; j++) {

                if (i >= j) {

                    min = Math.min(min, (dp[i-j] + Math.abs(hi[i] - hi[i-j])));
                }
            }
            dp[i] = min;
        }

        System.out.println(dp[N-1]);

    }

}


Measured memory_bytes: 48924
import math
a , b = map(int,input().split())
res = list(map(int,input().split()))
res2 = []
if len(res) == 1:
    print(0)
else:
    for i in range(len(res)-1):
        aa = res[i+1] - res[i]
        res2.append(aa)
    if res[0] == 0:
        res2.append(a-res[-1])
    else:
        res2.append(res[0] + (a - res[-1]))
print(sum(res2) - max(res2))

Measured memory_bytes: 86140
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define X first
#define Y second
#define pb push_back
#define mp make_pair

const int maxn = 1e5 + 100 , maxc = 115, mod = 1e9 + 7, inf = 1e9+10;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, a, t = 0;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a;
		t += a & 1;
	}
	cout << (t & 1 ? "NO" : "YES") << endl;



	return 0;
}

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

int main() {
  int N,K;
  cin >> N>>K;
  vector<int> p(N);
  for(int i=0;i<N;i++){
    int j;
    cin >> j;
    p[j-1] ++;
    }
    //for(int i=0;i<N;i++){
    //  cout << p[i] << endl;
    //  }

    sort(p.begin(),p.end());
    int cur=0;
    for(int i=0;i<N;i++){
      if(p[i]>0) cur++;
      }
      //cout << cur << endl;
  if(cur<=K){
    cout << 0 << endl;
    return 0;
  }
  int erase= cur-K;
  int c=0;
  for(int i;i<N;i++){
    if(p[i]>0){
      c += p[i];
      erase --;
    }
    if(erase<=0) break;
  }
  cout << c << endl;

}


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

int main()
{
  int n, i, j, temp;
  long int Sum=0;

  cin >> n;
  int a[n];
  
  for(i=0; i<n; i++)
    {
      cin >> a[i];
    }
  
  for(i=0; i<n; i++)
    {
      Sum += a[i];
    }

  for(i=0; i<n; i++)
    {
      for(j=i+1; j<n; j++)
	{
	  if(a[i] < a[j])
	    {
	      temp = a[i];
	      a[i] = a[j];
	      a[j] = temp;
	    }
	}
    }

  cout << a[n-1] << " " << a[0] << " " << Sum <<endl;

  return 0;
}

Measured memory_bytes: 1204
#最大公約数
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

#最小公倍数
def lcm(a,b):
    return a*b//gcd(a,b)

a,b,c,d = map(int,input().split())

bandc = b // c 
bandd = b // d
bandcd = b // lcm(c,d)

aandc = a // c 
aandd = a // d
aandcd = a // lcm(c,d)

totalb = b - bandc - bandd + bandcd
totala = a - aandc - aandd + aandcd
#print(totalb)
#print(totala)
if (a % c != 0) and (a % d != 0):
    ans = totalb - totala + 1
else:
    ans = totalb - totala

print(ans)

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

using namespace std;

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

const int MM = 1e9 + 7;
const double eps = 1e-8;
const int MAXN = 2e6 + 10;

int n, m;

void prework(){

}

void read(){
	
}

vector<int> E[MAXN];

int f(int x){
	vector<int> g;
	for(int i = 0; i < E[x].size(); i++){
		g.push_back(f(E[x][i]));
	}
	if (g.size() == 0)
		return 1;
	sort(g.begin(), g.end());
	int ans = 0;
	int p = g.size();
	for(int i = 0; i < g.size(); i++){
		ans = max(ans, g[i] + p - i);
	}
	return ans;
}

void solve(int casi){
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
		E[i].clear();
	for(int i = 2; i <= n; i++){
		int x;
		scanf("%d", &x);
		E[x].push_back(i);
	}
	printf("%d\n", f(1) - 1);
}

void printans(){

}


int main(){
	prework();
	int T = 1;
//	cin>>T;
	for(int i = 1; i <= T; i++){
		read();
		solve(i);
		printans();
	}
	return 0;
}




Measured memory_bytes: 59648
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
const int N=505;
int dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
int n,f[N][N],ans=0;
int vis[N][N];
void dfs(int x,int y) {
  int ret=f[x][y]+vis[x][y];
  for (int i=0;i<4;++i) {
    int nx=x+dx[i],ny=y+dy[i];
    if(ret<f[nx][ny]) {
      f[nx][ny]=ret;
      dfs(nx,ny);
    }
  }
  return ;
}
int main() {
  scanf("%d",&n);
  for (int i=1;i<=n;++i) {
    for (int j=1;j<=n;++j) {
      vis[i][j]=1;
      f[i][j]=min(min(i,n+1-i),min(j,n+1-j))-1;
    }
  }
  for (int i=1;i<=n*n;++i) {
    int s,x,y;
    scanf("%d",&s);
    x=(s+n-1)/n;
    y=s%n;
    if(y==0) y=n;
    ans+=f[x][y];
    vis[x][y]=0;
    dfs(x,y);
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 20888
import sys
from itertools import accumulate
n, k = [int(i) for i in sys.stdin.readline().split()]
p_ls = [int(i) for i in sys.stdin.readline().split()]
ls = []
for i, p in enumerate(p_ls, 1):
    ls.append((1 + p) / 2)
ans = 0
cur = 0
for i, l in enumerate(ls):
    if i >= k:
        cur -= ls[i-k]
    cur += l
    ans = max(ans, cur)
print(ans)

Measured memory_bytes: 25168
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	int N = getint();

	int A[100000], B[100000];
	rep(i, N) {
		A[i] = getint();
		B[i] = getint();
	}

	ll kotae = 0;
	for(int i = N - 1; i >= 0; i--) {
		kotae = (A[i] + kotae + B[i] - 1) / B[i] * B[i] - A[i];
	}

	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 1152
#include "bits/stdc++.h"
using namespace std;

#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define RREP(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<"\n";
#define all(a)  (a).begin(),(a).end();
#define SORT(a) sort((a).begin(),(a).end())
#define TDARRAY(int,a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()

typedef long long ll;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<b){a=b;return 1;}return 0;}

int h,w;

int main(){
    cin >> h >> w;
    vector<vector<int>> a(h,vector<int> (w));
    vector<int> cnt(26,0);
    REP(i,h){
        REP(j,w){
            char c;
            cin >> c;
            a[i][j] = c-'a';
            cnt[a[i][j]]++;
        }
    }
    int o = 0;
    o+=h%2;
    o+=w%2;
    int c=0;
    int m;
    int n = (h/2)*(w/2);
    if(o==2){
        c=1;
        m=(h+w-2)/2;
    }else if(o==1){
        if(h%2==0)m=h/2;
        else m=w/2;
    }else{
        m=0;
    }
    
    int cn=0,cm=0,cc=0;
    REP(i,26){
        if(cnt[i]%2==1){
            cc++;
        }
        if(cnt[i]%4==2||cnt[i]%4==3){
            cm++;
        }
        cn+=cnt[i]/4;
    }
    
    bool flag = false;
    if(cn>n){
        cm+=(cn-n)*2;
        cn=n;
    }
    if(cn==n&&cm==m&&cc==c){
        flag = true;
    }
    if(flag){
        put("Yes");
    }else{
        put("No");
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define cans cout << ans << endl
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
typedef long long ll;


int main(){
    int n,m;
    cin >> n >> m;
    if(n>=m){
        cout << 0 << endl;
        return 0;
    }
    vector<int> x(m);
    rep(i,m) cin >> x[i];
    sort(x.begin(),x.end());
    vector<int> l(m-1);
    for(int i=1; i<m; i++){
        l[i-1] = x[i]-x[i-1];
    }
    sort(l.begin(),l.end());
    ll ans = 0;
    rep(i,m-n){
        ans += l[i];
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 4048
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int main() {
	int n, m;
	int num[10][10];
	int k;
	int p[10];
	
	// input & setup
	scanf("%d %d", &n, &m);
	for (int i = 0; i < 10; ++i){
		for (int j = 0; j < 10; ++j){
			num[i][j] = 0;
		}
	}
	for (int i = 0; i < m; ++i){
		scanf("%d", &k);
		for (int j = 0; j < k; ++j){
			int c;
			scanf("%d", &c);
			num[i][c - 1] = 1;
		}
	}
	for (int i = 0; i < m; ++i) scanf("%d", &p[i]);
	
	// countup
	int ans = 0;
	for (int i = 0; i < (1 << n); ++i) {
		int chkflag = 1;
		for (int j = 0; j < m; ++j) {
			int bitcnt = 0;
			for (int l = 0; l < n; ++l) {
				if(num[j][l] & i >> l) ++bitcnt;
			}
			if(bitcnt % 2 != p[j]) chkflag = 0;
		}
		if(chkflag) ans += 1;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 128
// 解説AC
// う　し　た　ぷ　に　き　あ　く　ん　笑
#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long

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

    string s;
    cin >> s;

    vector<int> a(s.size() + 1);
    a.at(0) = 0;

    vector<int> leftless(s.size() + 1), rightgreater(s.size() + 1);

    leftless[0] = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '<')
            leftless[i + 1] = leftless[i] + 1;
        else
            leftless[i + 1] = 0;
    }

    rightgreater[s.size()] = 0;
    for (int i = s.size() - 1; i >= 0; i--) {
        if (s[i] == '>')
            rightgreater[i] = rightgreater[i + 1] + 1;
        else
            rightgreater[i] = 0;
    }

    for (int i = 0; i < s.size() + 1; i++) {
        a[i] = max(leftless[i], rightgreater[i]);
    }

    int sum_a = 0;
    for (int i = 0; i < s.size() + 1; i++) {
        sum_a += a[i];
    }

    cout << sum_a << endl;
}


Measured memory_bytes: 15540
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &V) {
  for (int i = 0; i < (int)V.size(); ++i) {
    if (i != 0) os << ' ';
    os << V[i];
  }
  return os;
}
template<typename T>
istream &operator>>(istream &is, vector<T> &V) {
  for (int i = 0; i < (int)V.size(); ++i) {
    is >> V[i];
  }
  return is;
}

int main()  {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  string s;
  cin >> s;
  vector<int> ans(s.length());
  int kek = 0;
  int last = 0;
  while(kek < s.length()) {
    if (s[kek] == 'L') {
      ans[last - (kek - last) % 2]++;
      ++kek;
      continue;
    }
    int ind = kek;
    for (; ind < s.length(); ++ind) if(s[ind] == 'L') break;
    last = ind;
    ans[ind]++;
    for (int y = ind - 1; y >= kek; --y) {
      ans[ind - (ind - y) % 2]++;
    }
    kek = ind + 1;
  }
  cout << ans;
  return 0;
} 



Measured memory_bytes: 1104
import itertools 
n,k = map(int,input().split())
A = list(map(int,input().split()))
B = [ (i+1)/2 for i in A]
C = [0] + list(itertools.accumulate(B))
ans = 0
for i in range(n + 1 - k):
    ans = max(ans,C[i+k]-C[i])
print(ans)

Measured memory_bytes: 26244
N = int(input())
A=sorted(list(map(int,input().split())))
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
ans = []
gcdlist = [A[0]]
for i in range(1,N):
    gcdlist.append(gcd(gcdlist[i-1],A[i]))
gcdlistr = [A[-1]]
for i in range(N-2,-1,-1):
    gcdlistr.append(gcd(gcdlistr[N-i-2],A[i]))
gcdlistr.reverse()
gcdlist.insert(0,0)
gcdlist.append(0)
gcdlistr.insert(0,0)
gcdlistr.append(0)
for i in range(N):
    ans.append(gcd(gcdlist[i],gcdlistr[i+2]))
print(max(ans))
    

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

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

  int n,rank;
  char mark;
  cin >> n;

  for (int x = 1; x<=n; x++){
    cin >> mark >> rank;

    if( mark == 'S'){
      cards[0][rank] = 0;
    }
    if( mark == 'H'){
      cards[1][rank] = 0;
    }
    if( mark == 'C'){
      cards[2][rank] = 0;
    }
    if( mark == 'D'){
      cards[3][rank] = 0;
    }
  }

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

      if (i == 0) mark = 'S';
      if (i == 1) mark = 'H';
      if (i == 2) mark = 'C';
      if (i == 3) mark = 'D';

      cout << mark << " " << j << endl;
    }
  }

  return 0;
}

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

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

    int[] num = new int[3];
    for (int i = 0; i < 3; i++) {
      num[i] = scanner.nextInt();
    }
    Arrays.sort(num);

    System.out.println(num[2] * 10 + num[1] + num[0]);
  }
}


Measured memory_bytes: 22868
using System;


    public static class Program
    {
    static void Main()
    {

        var data1 = Console.ReadLine().Split(' ');
        var num = 0;
        int[] data3 = new int[3];
        for (var i = 0; i < 3; i++)
        {
            data3[i] = int.Parse(data1[i]);
        }
        for (var j = data3[0]; j <= data3[1]; j++)
        {
            if(data3[2] % j == 0)
            {
                num++;
            }
        }
        Console.WriteLine(num);
        
       
    }
    }




Measured memory_bytes: 17888
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000


int main(){
	
	long long S;
	cin>>S;
	
	long long x1,x2,y1,y2;
	x1 = 1000000000;
	x2 = 1;
	y2 = (S + x1 - 1)/x1;
	y1 = (y2 * x1)-S;
	
	cout<<"0 0 "<<x1<<' '<<y1<<' '<<x2<<' '<<y2<<endl;
	
	return 0;
}

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

using namespace std;

template <class M, class N>
common_type_t<M, N> gcd(M a, N b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}

int main(int argc, const char *argv[]) {
  int n, x;
  cin >> n >> x;

  vector<int> vx(n);
  for (int i = 0; i < n; ++i) {
    cin >> vx[i];
  }

  int ans = abs(x - vx.front());
  for (int i = 1; i < n; ++i) {
    ans = gcd(ans, abs(x - vx[i]));
  }

  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
string s,t;
int main() {
	cin>>s>>t;
	int ans=1000000000;
	for(int i=0;i<s.length()-t.length()+1;i++) {
		int y=0;
		for(int j=0;j<t.length();j++) {
			if(s[i+j]!=t[j]) {
				y++;
			}
		}
		ans=min(ans,y);
	}
	cout<<ans; 
}


Measured memory_bytes: 3556
#include <iostream>
#include <string>
#include <queue>
#include <string.h>

using namespace std;

const int INF = 9999999;

int w, h;
string b[20];
int d[20][20];

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

void dist(int sx, int sy){
	for(int i=0;i<20;i++)
		for(int j=0;j<20;j++)
			d[i][j] = INF;
	queue< pair<int,int> > qu;
	qu.push(make_pair(sx,sy));
	d[sy][sx] = 0;
	while(!qu.empty()){
		pair<int, int> p = qu.front(); qu.pop();
		int x = p.first, y = p.second;
		for(int i=0;i<4;i++){
			int nx = x + dx[i], ny = y + dy[i];
			if(nx<0||nx>=w||ny<0||ny>=h||b[ny][nx]=='x') continue;
			if(d[ny][nx] != INF) continue;
			d[ny][nx] = d[y][x] + 1;
			qu.push(make_pair(nx,ny));
		}
	}
}

int main(){
	int c[11][11];
	int x[11], y[11];
	int ans[1<<11][11];
	while(cin >> w >> h){
		if(!(w||h)) break;
		int num = 1;
		for(int i=0;i<h;i++){
			cin >> b[i];
			for(int j=0;j<w;j++){
				if(b[i][j]=='o') x[0] = j, y[0] = i;
				if(b[i][j]=='*') x[num] = j, y[num++] = i;
			}
		}
		bool flag = false;
		memset(c,0,sizeof(c));
		dist(x[0],y[0]);
		for(int i=1;i<num;i++){
			c[0][i] = d[y[i]][x[i]];
			if(c[0][i] == INF) flag = true;
		}
		if(flag) { cout << -1 << endl; continue; }
		for(int i=1;i<num;i++){
			dist(x[i],y[i]);
			for(int j=0;j<num;j++){
				if(i==j) continue;
				c[i][j] = d[y[j]][x[j]];
			}
		}
		for(int i=0;i<(1<<num);i++) for(int j=0;j<num;j++) ans[i][j] = INF;
		ans[1][0] = 0;
		for(int i=0;i<(1<<num);i++){
			for(int j=0;j<num;j++)
				if((i>>j)&1)
					for(int k=0;k<num;k++)
						ans[i|(1<<k)][k] = min(ans[i|(1<<k)][k],ans[i][j]+c[j][k]);
		}
		int cost = INF;
		for(int i=1;i<num;i++) cost = min(cost, ans[(1<<num)-1][i]);
		cout << cost << endl;
	}
}

Measured memory_bytes: 984