akhauriyash/Code-Regression huggingface dataset:
import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B
import Data.Ord
--import Debug.Trace

main :: IO ()
main = readContents 2 >>= main'
    where
        main' [[n, m], as] = readContents m >>= print . solve n m as

solve :: Int -> Int -> [Int] -> [[Int]] -> Int
solve n m as bcs = count (sum fs) es ds
    where
        (es, fs) = span (< (last (head ds))) $ sort as
        ds = sortBy (flip (comparing last)) bcs

        count acc (x : xs) ([b, c] : ys)
            | b == 0 = count acc (x : xs) ys
            | x < c = count (acc + c) xs $ [b - 1, c] : ys
            | otherwise = acc + sum (x : xs)
        count acc xxs@(_ : _) _ = acc + sum xxs
        count acc _ _ = acc 

readLine :: IO [Int]
readLine = unfoldr (fmap (second (maybe B.empty snd . B.uncons)) . B.readInt) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine

Measured memory_bytes: 52604
#include<bits/stdc++.h>
using namespace std;
long long x,y;
int main(){
	cin>>x>>y;
	int cnt=0;
	for(int i=2;i*x<=1e18;i++){
		if(++cnt > 1e5)break;
		if(i*x%y!=0){
			cout<<i*x<<endl;
			return 0;
		}
	}
	cout<<-1<<endl;
	return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
# coding: utf-8
import sys
sys.setrecursionlimit(10000000)

#const
# my functions here!
def pin(type=int):
    return map(type,input().rstrip().split())

def resolve():
    A=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
    K,=pin()
    print(A[K-1])
"""
#printデバッグ消した？
#前の問題の結果見てないのに次の問題に行くの？
"""
"""
お前カッコ閉じるの忘れてるだろ
"""
import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """6"""
        output = """2"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """27"""
        output = """5"""
        self.assertIO(input, output)

if __name__=="__main__":resolve()

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

public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pr=new PrintWriter(System.out);
		String str[]=br.readLine().split(" ");
		Deque<Integer> stack=new ArrayDeque<Integer>();
		int a,b;
		for (int i=0;i<str.length;i++){
			switch(str[i]){
			case "+":
				a=stack.pop();
				b=stack.pop();
				stack.push(b+a);
				break;
			case "-":
				a=stack.pop();
				b=stack.pop();
				stack.push(b-a);
				break;
			case "*":
				a=stack.pop();
				b=stack.pop();
				stack.push(b*a);
				break;
			default:
				stack.push(Integer.parseInt(str[i]));
				break;
			}
		}
		pr.println(stack.pop());
		pr.close();
	}

}

Measured memory_bytes: 24328
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
map<ll,int>st;
int main(){
	ll s=0,ans=0;
	int n;
	scanf("%d",&n);
	st[s]++;
	for(int i=1,x;i<=n;++i){
		scanf("%d",&x);
		s+=x;
		ans+=st[s];
		st[s]++;
	}
	printf("%lld",ans);
}

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

using i64 = long long int;

const int INF = 1e9;

int edit_distance(string s1, string s2) {
    vector<vector<int>> dp(s1.size()+1, vector<int>(s2.size()+1, INF));

    for(int i=0;i<=s1.size();++i)dp[i][0] = i;
    for(int j=0;j<=s2.size();++j)dp[0][j] = j;

    for(int i=1;i<=s1.size();++i){
        for(int j=1;j<=s2.size();++j){
            dp[i][j] = min({
                dp[i-1][j] + 1,
                dp[i][j-1] + 1,
                dp[i-1][j-1] + !!(s1[i-1] != s2[j-1])
            });
        }
    }

    return dp[s1.size()][s2.size()];
}

int main(){
    string s1, s2;
    cin >> s1 >> s2;

    cout << edit_distance(s1, s2) << endl;

    return 0;
}



Measured memory_bytes: 6928
s=list(input())
k=int(input())
A,B,C=0,0,0
test=s*3
for i in range(len(s)*3-1):
    if test[i]==test[i+1]:
        test[i+1]="A"
A=test[:len(s)].count("A")
B=test[len(s):len(s)*2].count("A")
C=test[len(s)*2:len(s)*3].count("A")

if s.count(s[0])==len(s):
    print((len(s)*k)//2)
else:
    if k==1:print(A)
    elif k==2:print(A+B)
    else:print(A+B*(k-2)+C)

Measured memory_bytes: 3064
N,M=map(int,input().split())
s=[list(map(int,input().split()))[1:] for m in range(M)]
p=list(map(int,input().split()))
count=0
for i in range(1<<N):
    flag=True
    for m in range(M):
        on=0
        for n in range(N):
            if (i>>n)&1 and n+1 in s[m]:
                on+=1
        if on%2!=p[m]:
            flag=False
    if flag:
        count+=1
print(count)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll n,m;
unordered_map<ll,vector<ll>>seen;
ll dp[100001];
bool visited[100001];
void dfs(ll i)
{
    visited[i]=true;
    for(ll j=0;j<seen[i].size();j++)
    {
        if(!visited[seen[i][j]])
        {
            dfs(seen[i][j]);
            
        }
        dp[i]=max(dp[i],1+dp[seen[i][j]]);
    }
}

int main(){
    // Your code here!
    
    cin>>n>>m;
    for(ll i=0;i<m;i++)
    {
        ll a,b;
        cin>>a>>b;
        a--;
        b--;
        seen[a].push_back(b);
    }
    for(ll i=0;i<n;i++)
    {
        dp[i]=0;
        visited[i]=false;
    }
    for(ll i=0;i<n;i++)
    {
        if(!visited[i])
        {
            //cout<<"go "<<i<<'\n';
            dfs(i);
        }
    }
    ll maxele=0;
    for(ll i=0;i<n;i++)
    {
     //   cout<<dp[i]<<" ";
        maxele=max(maxele,dp[i]);
    }
    //cout<<'\n';
    cout<<maxele;
}


Measured memory_bytes: 15488
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=100000;
char s[maxn+10];
int ans,l;
int main(){
	scanf("%s",s); ans=l=strlen(s);
	for(int i=1;i<l;++i)
		if(s[i]!=s[i-1]) ans=min(ans,max(i,l-i));
	printf("%d",ans); return 0;
}


Measured memory_bytes: 256
import java.util.*;
class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		int[][] s=new int[m][];
		for(int i=0;i<m;i++){
			int ki=sc.nextInt();
			s[i]=new int[ki];
			for(int j=0;j<ki;j++){
				s[i][j]=sc.nextInt()-1;
			}
		}
		int[] p=new int[m];
		for(int i=0;i<m;i++){
			p[i]=sc.nextInt();
		}
		
		int r=0;
		loop:
		for(int f=0;f<(1<<n);f++){
			for(int i=0;i<m;i++){
				int c=0;
				for(int j=0;j<s[i].length;j++){
					if((f&(1<<s[i][j]))>0)
						c++;
				}
				if(c%2!=p[i])
					continue loop;
			}
			r++;
		}
		System.out.println(r);
			

	}
}

Measured memory_bytes: 21972
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String line = reader.readLine();
		String[] str = line.split(" ");
		int n = Integer.parseInt(str[0]);
		int k = Integer.parseInt(str[1]);
		double ans = 0.0;
		for (int i = 1; i <= n; i++) {
			int zyo = 0;
			int zz = i;
			outer:
			for (int z = 1; z <= k;  z++) {
				if (zz >= k) {
					break outer;
				}
				zz *= 2;
				zyo ++;
			}
//			if (i == k) {
//				zyo = 0;
//			}
//			else if (i > 1) {
//			    zyo = (int) Math.floor(Math.log(k) / Math.log(i));
//			}
//			else {
//				zyo = (int) Math.floor(Math.log(k) / Math.log(2)) + 1;
//			}
//			System.out.println("i=" + i + ", zyo=" + zyo);   ////////////////////
			ans += Math.pow(0.5, zyo);
		}
		ans /= n;
		System.out.println(ans);
	}
}

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

using namespace std;

int main(void) {
    int a, b;
    cin >> a >> b;
    int sum = (a >= b) ? a : b;
    if (sum == a) {
        a--;
        sum += (a >= b) ? a : b;
    }
    else if (sum == b) {
        b--;
        sum += (a >= b) ? a : b;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
N = int(input())
txy = [[0,0,0] for i in range(N+1)]
for i in range(1,N+1):
    txy[i] = list(map(int,input().split()))

ans = 'Yes'
for i in range(1,N+1):
    dist = abs(txy[i][1]-txy[i-1][1])+abs(txy[i][2]-txy[i-1][2])
    dt   = txy[i][0]-txy[i-1][0]
    
    if dist%2 != dt%2 or dist>dt:
        ans = 'No'
        
print(ans)

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

int main() {
    int n, d;
    string x, ans;
    cin >> n >> x >> d;
    ans = x;
    for(int i=0;i<n && d>0;i++){
        if(x[i]=='0'){
            ans[i] = '1';
            d--;
        }
    }
    for(int i=n-1;i>=0 && d>0;i--){
        if(x[i]=='1'){
            ans[i] = '0';
            d--;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3196
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#include <boost/range/adaptors.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;
using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long int;

int main() {
    ll N;
    cin >> N;
    vector<ll> v(N, 0);
    for (auto &&i: irange(0LL, N)){
        cin >> v.at(i);
    }
    sort(v.begin(), v.end());
    cout << v.at(N-1) - v.at(0) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int X;

	scanf("%d", &X);

	if (X >= 400 && X <= 599)
	{
		printf("8");
	}
	else if (X >= 600 && X <= 799)
	{
		printf("7");
	}
	else if (X >= 800 && X <= 999)
	{
		printf("6");
	}
	else if (X >= 1000 && X <= 1199)
	{
		printf("5");
	}
	else if (X >= 1200 && X <= 1399)
	{
		printf("4");
	}
	else if (X >= 1400 && X <= 1599)
	{
		printf("3");
	}
	else if (X >= 1600 && X <= 1799)
	{
		printf("2");
	}
	else if (X >= 1800 && X <= 1999)
	{
		printf("1");
	}
	printf("\n");

	return 0;
}

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

int main(){
    string s; cin >> s;
    deque<int> p, q;
    vector<int> ans(s.size(), 0);
    for (auto i = 0; i < (int) s.size() - 1; i++) {
        if(s[i] == 'R' and s[i + 1] == 'L') { p.push_back(i); q.push_back(i); }
    }
    for (auto i = 0; i < (int) s.size(); i++) {
        if(p.empty()) break;
        if(s[i] == 'R' and p.front() >= i) {
            if((p.front() - i) % 2) ans[p.front() + 1]++;
            else ans[p.front()]++;
        }
        if(p.front() == i) p.pop_front();
    }
    for (auto i = (int) s.size() - 1; i >= 0; i--) {
        if(q.empty()) break;
        if(q.back() == i) q.pop_back();
        if(s[i] == 'L' and q.back() < i) {
            if((i - q.back()) % 2) ans[q.back() + 1]++;
            else ans[q.back()]++;
        }
    }

    for (auto & elm : ans) cout << elm << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 4076
#include <stdio.h>

int main(void){
    int a, b, k, i;
    scanf("%d%d%d", &a, &b, &k);
    for(i = a; i <= b; i++){
        if((i < a + k) || (i > b - k))
            printf("%d\n", i);
    }
    return 0;
}


Measured memory_bytes: 128
while True:
	m,f,r = list(map(int, input().split()))
	if (m == -1 and f == -1 and r == -1):
		break
	elif ((m == -1) or (f == -1)) or (m + f < 30):
		print("F")
	elif (80 <= m + f):
		print("A")
	elif (65 <= m + f) and (m + f < 80):
		print("B")
	elif (50 <= m + f) and (m + f < 65) or (50 <= r):
		print("C")
	elif (30 <= m + f) and (m + f <50) :
		print("D")
		

Measured memory_bytes: 7716
#include<cstdio>
#include<vector>
#include<algorithm>
#include<functional>


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


int main(void)
{
	int n;

	while(scanf("%d", &n)==1)
	{
		vi a(n*3);

		for(auto&ae:a) scanf("%d", &ae);
		sort(a.begin(), a.end(), greater<int>());

		ll ans=0;
		for(int i=0;i<n;i++) ans+=a[i*2+1];
		printf("%lld\n", ans);
	}

	return 0;
}


Measured memory_bytes: 1408
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#S = list(str(input()))
#N = int(input())
N, T = map(int, input().split())
L = []
for _ in range(N) :
  L.append(list(map(int, input().split())))
#print (L)

ans = sys.maxsize
TLEflag = True
for i in range(N) :
  if L[i][1] <= T :
    ans = min(ans, L[i][0])
    TLEflag = False

if TLEflag == True :
  print ("TLE")
else :
  print (ans)
  
  

Measured memory_bytes: 38256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<string>
#include<sstream>
#include<iomanip>
#include<utility>
#include<cmath>
#include<set>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<set>
#include<cstring>
#include<iterator>
#include<bitset>
#include<assert.h>
using namespace std;
 
#define int ll
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
typedef vector<int> VI;
typedef vector<long long int> VL;
static const int MOD = 1000000007;
static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const int INF = 1000010000;
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define NP next_permutation
#define PQ priority_queue
#define UB upper_bound
#define LB lower_bound
#define ALL(x) (x).begin(),(x).end()
#define SZ(a) int((a).size())
#define LEN(a) int((a).length())
#define MAX(a,b,c) max((a),max((b),(c)))
#define MIN(a,b,c) min((a),min((b),(c)))
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REP1(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREP1(i,x) for(int i=((int)(x));i>0;i--)
//struct edge {int to,cost;};
 
signed main(){
    int k;
    cin >> k;
    if(k==0) puts("4\n3 3 3 3");
    else if(k==1) puts("3\n1 0 3");
    else if(k<=50){
        printf("%lld\n",k);
        REP1(i,k) printf("%lld ",i);
        puts("");
    } else {
        int a = (k-50)/50;
        int b = k%50;
        int ans[51]={};
        REP(i,50) ans[i] = i+1;
        REP(i,50) ans[i] += a;
        for(int i=50-b;i<50;i++) ans[i]++;
        puts("50");
        REP(i,50) printf("%lld ",ans[i]);
        puts("");
    }
    return 0;
}



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

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	int n;
	cin >> n;

	ll a[n];
	rep(i, n) cin >> a[i];
	sort(a, a+n);

	ll ans = 0;
	if(n % 2 == 0){
		rep(i, n){
			if(i < n/2-1) ans -= 2 * a[i];
			else if(i == n/2-1) ans -= a[i];
			else if(i == n/2) ans += a[i];
			else ans += 2 * a[i];
		}
	}else{
		ll ans1 = 0;
		rep(i, n){
			if(i < n/2) ans1 -= 2 * a[i];
			else if(i == n/2 || i == n/2+1) ans1 += a[i];
			else ans1 += 2 * a[i];
		}

		ll ans2 = 0;
		rep(i, n){
			if(i < n/2-1) ans2 -= 2 * a[i];
			else if(i == n/2-1 || i == n/2) ans2 -= a[i];
			else ans2 += 2 * a[i];
		}

		ans = max(ans1, ans2);
	}

	cout << ans << endl;
}


Measured memory_bytes: 1024
/*
 * Author       : YangDavid
 * Created Time : 2019年10月05日 星期六 22时07分14秒
 */

#include<bits/stdc++.h>
#define rep(i, n) for(int i = 1; i <= n; ++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

const int maxn = 422222, MOD = 998244353;
int sub(int x, int y) { return x-y<0 ? x-y+MOD : x-y; }
int add(int x, int y) { return x+y>=MOD ? x+y-MOD : x+y; }
int mul(int x, int y) { return 1LL * x * y % MOD; }

int n, g[maxn], h[maxn], mu[maxn], pcnt, pr[maxn], vis[maxn], p2[maxn];
char s[maxn], t[maxn];

int gao(int hper) {
    int res = 0;
    for(int i = 1; i <= hper; ++i)
        if(s[i] == '1')
            res = add(res, p2[hper-i]);
    int tgeq = 0;
    for(int i = 1; i <= n; ++i) {
        if(i <= hper) t[i] = s[i];
        else t[i] = t[i-hper]=='0' ? '1' : '0';
        if(tgeq == 0 && t[i] != s[i]) {
           if(t[i] > s[i])  tgeq = 1;
           else tgeq = -1;
        }
    }
    res += tgeq <= 0;
    return res;
} 
int main() {
    mu[1] = p2[0] = 1;
    for(int i = 1; i <= 400000; ++i) p2[i] = mul(p2[i - 1], 2);
    for(int i = 2; i <= 400000; ++i) {
        if(!vis[i]) pr[++pcnt] = i, mu[i] = MOD-1;
        for(int j = 1; j <= pcnt && i *pr[j] <= 400000; ++j) {
            vis[i * pr[j]] = true;
            if(i % pr[j] == 0) break;
            mu[i * pr[j]] = sub(0, mu[i]);
        }
    }

    scanf("%d%s", &n, s + 1);
    for(int i = 1; i <= n; ++i) if(n%i==0 && n/i%2!=0)
        g[i] = gao(i);
    int ans = 0;
    for(int i = 1; i <= n; ++i)
        for(int j = 1; i*j <= n; ++j)
            h[i*j] = add(h[i*j], mul(g[i], mu[j]));

    for(int i = 1; i <= n; ++i) if(n%i==0 && n/i%2!=0)
        ans = add(ans, mul(i*2, h[i]));
    printf("%d\n", ans);

    return 0;
}


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

int main(){
    int N,a[100002];
    cin >> N;
    a[0]=0;
    a[N+1]=0;
    for(int i=1; i<=N; i++)
    cin >> a[i];

    int all=0;
    for(int i=1; i<=N+1; i++){
        int cost=a[i]-a[i-1];
        if(cost<0)
        cost*=(-1);
        all+=cost;
    }

    for(int i=1; i<=N; i++){
        int ans=all;
        for(int j=0; j<2; j++){
            int cansel=a[i+j]-a[i+j-1];
            if(cansel<0)
            cansel*=-1;
            ans-=cansel;
        }
        int plus=a[i-1]-a[i+1];
        if(plus<0)
        plus*=(-1);
        ans+=plus;
        cout << ans << "\n";
    }

    return 0;
}

Measured memory_bytes: 1664
#include <string>
#include <iostream>
using namespace std;
int main() {
	string s;
	cin >> s;
	int ans = 0;
	for (int i = 0; i < s.size(); ++i) {
		ans += int(s[i] - '0');
	}
	if (ans <= 1) cout << ans + 9 << endl;
	else cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <iostream>
#include <stdlib.h>

using namespace std;


const long long int MAX = 2000000007;
long long int dist[1001][1001]={};
long long int parent[1001][1001]={};
long long int visit[8] = {};
int r;
long long int ans = 2000000006;


void print_shortest_path(int i, int j){
  if(i == j)
    cout << i << ",";
  else if(parent[i][j] == -1)
    cout << "no path" << endl;
  else{
    print_shortest_path(i,parent[i][j]);
    cout << j <<",";
  }
}


void solve(long long int x, int y, long long int tmp){

  if(x == ( 1 << r ) - 1 ){
    if(tmp < ans){
      ans = tmp;
      return;
    }
  }
  else{
    for(int i = 0;i<r;i++){
      if(  !( ( ( x & (1 << i) ) >> i ) % 2 ) ){

        long long int hoge = x + ( 1 << i );
        long long int hige = tmp + min(dist[ visit[y] ][ visit[i] ] ,  dist[ visit[i] ][ visit[y] ] );
        solve( hoge , i , hige);
      }
    }
  }
}


int main()
{
  int i,j,k;
  int n,m;
  cin >> n >> m >> r;

  //行列を初期化
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(i!=j)
        dist[i][j] = MAX;
      else
        dist[i][j] = 0;
      parent[i][j] = -1;
    }
  }

  //点を読み込む
  for(i=0;i<r;i++){
    int tmp;  cin >> tmp;
    visit[i] = --tmp;
  }

  //辺と重み(距離)を読み込む
  for(i=0;i<m;i++){
    int x,y;
    long long int d;
    cin >> x >> y >> d;  x--;  y--;
    dist[x][y] = d;
    dist[y][x] = d;
    parent[x][y] = x;
    parent[y][x] = y;
  }

  //各点に対して、その点を最短経路に含むパスの両端点間の距離を更新
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      for(k=0;k<n;k++){
        if( dist[j][k] > dist[j][i] + dist[i][k] ){
          dist[j][k] = dist[j][i] + dist[i][k];
          parent[j][k] = parent[i][k];
        }
      }
    }
  }



  for(int i=0;i<r;i++){
    solve( 1 << i , i , 0);
  }


  cout << ans << endl;

  return 0;
}


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


 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
 
    ll N; cin >> N;
    ll cur = 100;
    int c = 0;
    while (cur < N) {
        c++;
        cur = cur + cur/100;
    }
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 3628
import sys
sys.setrecursionlimit(100000)
class UnionFind():
    def __init__(self, n):
        self.parents = [-1]*n
        self.count = [1]*n
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        self.parents[y] = x
        self.count[x] +=  self.count[y]
n,m,k = map(int,input().split())
uf = UnionFind(n)
block = [[] for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    uf.union(a-1,b-1) 
    block[a-1].append(b-1)
    block[b-1].append(a-1)
for i in range(k):
    c,d = map(int,input().split())
    if uf.find(c-1) == uf.find(d-1):
        block[c-1].append(d-1)
        block[d-1].append(c-1)
ans = []
for i in range(n):
    ans.append(uf.count[uf.find(i)]-len(block[i])-1)
print(" ".join(map(str,ans)))

Measured memory_bytes: 57008
N , K = map(int, input().split())

mod_0_num = N//K

ans_mod_0 = mod_0_num**3
ans_mod_K = 0
if K%2 == 0:
    mod_K_num = (2*N-K)//(2*K) + 1
    ans_mod_K = mod_K_num**3

ans = ans_mod_0 + ans_mod_K
print(ans)

Measured memory_bytes: 61608
#include<cstdio>
#include<cstring>
using namespace std;
int main(){
    char s[201], t[101], p[101];
    scanf("%s %s", s, p);
    strcpy(t, s);
    strcat(s, t);
    if(strstr(s, p) == NULL) printf("No\n");
    else printf("Yes\n");
    
    return 0;
}


Measured memory_bytes: 2744
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    int h[n],  dp[n];
    for(int i = 0; i < n; i++) {
        cin >> h[i];
    }
    dp[0] = 0;
    dp[1] = abs(h[1]-h[0]);
    for(int i = 2; i < n; i++) {
        dp[i] = min(dp[i-1]+abs(h[i-1]-h[i]), dp[i-2]+abs(h[i-2]-h[i]));
    }
    cout << dp[n-1] << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <cmath>
#include <utility>
#include <queue>
#include <stdio.h>

using namespace std;
typedef pair<double, int> P;

struct edge{
	int to;
	double cost;
	edge(int a, double b){
		to = a, cost = b;
	}
};

int N, S, T;
double xs, ys, xt, yt;
double x[1005], y[1005], r[1005];
vector<edge> G[1005];
double dist[1005];
bool used[1005];

void dijkstra()
{
	for(int i = 1; i <= T; i++) dist[i] = 1e18;
	dist[S] = 0;
	
	priority_queue< P, vector<P>, greater<P> > Q;
	Q.push( make_pair(0, S) );
	int v; double d;
	while(Q.size()){
		v = Q.top().second;
		d = Q.top().first;
		Q.pop();
		used[S] = true;
		if(d > dist[v]) continue;
		for(int i = 0; i < G[v].size(); i++){
			if(used[G[v][i].to]) continue;
			if(dist[G[v][i].to] > dist[v] + G[v][i].cost){
				dist[G[v][i].to] = dist[v] + G[v][i].cost;
				Q.push( make_pair(dist[G[v][i].to], G[v][i].to) );
			}
		}
		
	}
}

int main(void)
{
	cin >> xs >> ys >> xt >> yt;
	cin >> N;
	for(int i = 1; i <= N; i++){
		cin >> x[i] >> y[i] >> r[i];
	}
	S = N+1, T = N+2;
	x[S] = xs, y[S] = ys, x[T] = xt, y[T] = yt;
	r[S] = r[T] = 0.0;
	
	double d;
	for(int i = 1; i <= T; i++){
		for(int j = 1; j <= T; j++){
			if(i >= j) continue;
			d = (x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]);
			if(d != 0.0) d = sqrt(d);
			d -= r[i] + r[j];
			if(d < 0.0) d = 0.0;
			G[i].push_back( edge(j, d) );
			G[j].push_back( edge(i, d) );
		}
	}
	
	dijkstra();
	printf("%.12f\n", dist[T]);
	return 0;
}

Measured memory_bytes: 22164
#include <iostream>

using namespace std;

int main() {
    string str;
    cin >> str;
    int state = 0;
    for (int i = 0; i < str.size(); i ++) {
        if ( ( str[i] == 'C' ) && ( state == 0 ) ) {
            state = 1;
        }
        if ( ( str[i] == 'F' ) && ( state == 1 ) ) {
            state = 2;
        }
    }
    if ( state == 2 ) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
from itertools import permutations, tee

N, M = map(int, input().split())
edges = set()

for _ in range(M):
    edges.add(tuple(map(int, input().split())))


def each_cons(iterable):
    a, b = tee(iterable)
    next(b, None)
    return zip(a, b)


def is_available(edge):
    return edge in edges or edge[::-1] in edges


cases = permutations(range(2, N + 1), N - 1)

count = 0

for numbers in cases:
    if all(map(is_available, each_cons((1,) + numbers))):
        count += 1


print(count)


Measured memory_bytes: 3064
n=int(input())
a=list(map(int,input().split()))
b=sorted(a)
c=0
for i in range(n):
 t=k=0
 x=a.index(b[i])
 while x>i:
  y=a.index(b[x])
  a[x],a[y]=b[x],b[i]
  k+=1
  t+=b[x]+b[i]
  x=y
 if k:c+=min(t,(b[i]+b[0])*2+t-(b[i]-b[0])*k)
print(c)


Measured memory_bytes: 5628
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    int n; cin >> n;
    if (n/100 == n%10) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 1
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

lli convert[26];

signed main(){

	string s,t;
	cin>>s>>t;

	map<char,lli> ss,tt;
	REP(i,0,s.size()){
		ss[s.at(i)]++;
		tt[t.at(i)]++;
	}

	multiset<lli> sC,tC;
	for(auto e:ss){
		sC.insert(e.second);
	}

	for(auto e:tt){
		tC.insert(e.second);
	}

	if(sC.size()!=tC.size()){
		cout<<"No"<<endl;
		return 0;
	}
	auto itr1 = sC.begin();
	auto itr2 = tC.begin();

	while(itr1!=sC.end()){
		if((*itr1)!=(*itr2)){
			cout<<"No"<<endl;
			return 0;
		}
		itr1++;
		itr2++;
	}
	cout<<"Yes"<<endl;

	return 0;
}

Measured memory_bytes: 776
import sys
input = sys.stdin.readline
n,w = map(int,input().split())
wv = [tuple(map(int,input().split())) for i in range(n)]

dp = [0]*(w+1)
for i in range(n):
    for j in range(w,wv[i][0]-1,-1):
        dp[j] = max(dp[j],dp[j-wv[i][0]]+wv[i][1])

print(max(dp))

Measured memory_bytes: 41708
import java.util.Scanner;
public class Main {

    public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
    	// 入力
    	String a = sc.next();
    	String b = sc.next();

    	String ans ="";

    	if(a.charAt(0) ==b.charAt(2) && a.charAt(1) ==b.charAt(1) && a.charAt(2) ==b.charAt(0)){
    		ans = "YES";
    	} else {
    		ans = "NO";
    	}

    	// 出力
    	System.out.println(ans);
    }
}

Measured memory_bytes: 23892
#!Python3.4.3

# SUN,MON,TUE,WED,THU,FRI,SAT 
days = ['SUN','MON','TUE','WED','THU','FRI','SAT']
days = reversed(days)

s = input()

for i, day in enumerate(days):
    if s == day:
        print(i+1)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main()
{
     int t,c1=0,c2=0,c3=0,c4=0;
     cin>>t;
     while(t--)
     {
         string s;
         cin>>s;
         if(s[0]=='A')
            c1++;
         else if(s[0]=='W')
            c2++;
         else if(s[0]=='T')
            c3++;
         else if(s[0]=='R')
            c4++;

     }
     cout<<"AC x "<<c1<<endl;
     cout<<"WA x "<<c2<<endl;
     cout<<"TLE x "<<c3<<endl;
     cout<<"RE x "<<c4<<endl;

return 0;
}


Measured memory_bytes: 3560
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}

int dp[2002][2002];
int n;
vector<pair<int,int>>a(2002);

int solve(int ind, int from_front){
	if(ind > n) return 0;
	int &res = dp[ind][from_front];
	if( res != -1) return res;
	res = 0;
	int from_back =   (ind  - 1  - (from_front)) ;
	res = max({res,
				a[ind].first * abs(a[ind].second - (from_front + 1)) + solve(ind + 1,from_front + 1) , 
				a[ind].first * abs(a[ind].second - ( n  - (from_back))  ) + solve(ind + 1, from_front)
			});
	return res;
}

int32_t main(){
	fastio();
	cin >> n;
	for(int i = 1; i <= n; i++){
		int x;
		cin >> x;
		a[i] = {x, i};
	}
	sort(a.begin() + 1, a.begin() + n + 1);
	reverse(a.begin() + 1, a.begin() + n + 1);
	memset(dp , -1 , sizeof(dp));
	int ans = 0;
	
		ans = max({ans,a[1].first * abs(1  - a[1].second) + solve(2,1) , a[1].first * abs(n - a[1].second) + solve(2,0)});
	
	cout << ans;
}

Measured memory_bytes: 35152
num = gets.chomp.split(" ").map(&:to_i).sort!
count = 0

loop do
    if num[0] == num[1] and num[1] == num[2]
        break
    end

    if num[0] < num[1]
        num[0] += 2
    else
        num[0] += 1
        num[1] += 1
    end

    num.sort!
    count += 1
end

p count


Measured memory_bytes: 1788
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <cctype>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <iomanip>
#include <limits>

#define roop(i, n) for(int i=0;i<n;i++)
#define DIV 1000000007
//static const long double pi = 3.1415926535897932;

using namespace std;
using ll = long long int;
using ull = unsigned long long;

char toSmall(char c) { // 大文字を小文字へ
	return (c + 0x20);
}

char toLarge(char c) { // 小文字を大文字へ
	return (c - 0x20);
}

float myPower(int a, int n) { // aのn乗の計算
	float x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

ll combination(ll n, ll r) { // nCr の計算
	if (n < 0 || r < 0 || r > n) return -1;

	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> num(r);
	vector<ll> den(r);

	for (ll i = 0; i < r; i++) {
		num[i] = n - r + i + 1;
		den[i] = i + 1;
	}

	for (ll p = 2; p <= r; p++) {
		ll pivot = den[p - 1];
		if (pivot > 1) {
			ll offset = (n - r) % p;
			for (ll k = p - 1; k < r; k += p) {
				num[k - offset] /= pivot;
				den[k] /= pivot;
			}
		}
	}
	ll result = 1;
	for (ll k = 0; k < r; k++) {
		if (num[k] > 1) result *= num[k];
	}
	return result;
}

vector<string> split(const string& src, const char* delim = ",") { //カンマ区切り
	vector<string> vec;
	string::size_type len = src.length();

	for (string::size_type i = 0, n; i < len; i = n + 1) {
		n = src.find_first_of(delim, i);
		if (n == string::npos) {
			n = len;
		}
		vec.push_back(src.substr(i, n - i));
	}

	return vec;
}

bool check_int(string str)
{
	if (all_of(str.cbegin(), str.cend(), [](char ch) { return isdigit(ch);}))
	{
		return true;
	}
	return false;
}

struct rest {
	string s;
	int p;
	int num;

	/* -------------------------------------
	sort関数を使用したときのソートの定義をする。
	まずは文字列sでソートする。
	文字列sが同じだった場合、pでソートする。
	この条件を参考演算子で表現(ifでもOK)
	-------------------------------------*/
	bool operator<(const rest& right) const {
		return s == right.s ? p > right.p : s < right.s;
	}
};

int main() {
	int a;
	cin >> a;
	cout << (a + a*a + a*a*a) << endl;
	return 0;
}

Measured memory_bytes: 3612
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const D = Number(input[0][0]);
  const C = input[1].map(Number);

  const T: number[] = [];

  let CS: number[] = Array(26).fill(0);

  for (let i = 2; i < D + 2; i++) {
    const S = input[i].map(Number);

    const maxS = Math.max(...S);
    const maxCS = Math.max(...CS);

    const indexOfMaxS = S.indexOf(maxS);
    const indexOfMaxCS = CS.indexOf(maxCS);

    CS = CS.map((cs, t) => cs + C[t]);

    if (maxS > maxCS) {
      T.push(indexOfMaxS + 1);
    } else {
      T.push(indexOfMaxCS + 1);

      CS[indexOfMaxCS] = 0;
    }
  }

  return T.join("\n");
};

console.log(main(read()));


Measured memory_bytes: 30552
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <string>
#include <numeric>
#include <stack>
#include <cstdlib>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

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

const int inf = 1000000000;

//#define DEBUG

int main() {
    int n;
    int max_cnt = 1;
    map<string, int> mp;
    
    cin >> n;
    rep(i, 0, n) {
        string s;
        cin >> s;
        if(mp[s]) {
            mp[s]++;
            max_cnt = max(max_cnt, mp[s]);
        }
        else mp[s] = 1;
    }
    
    #ifdef DEBUG
        cout << endl;
        cout << max_cnt << endl;
    #endif

    for(auto it: mp) {
        if (it.second == max_cnt) cout << it.first << endl;
    }
}

Measured memory_bytes: 18688
#include <bits/stdc++.h>
using namespace std;
#define ri register int
namespace io {
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	// getchar
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	// print the remaining part
	inline void flush () {
		fwrite (obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	// putchar
	inline void putc (char x) {
		*oS ++ = x;
		if (oS == oT) flush ();
	}
	// input a signed integer
	template <class I>
	inline void gi (I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = (x << 1) + (x << 3) + (c & 15); x *= f;
	}
	// input a letter
	template <class I>
	inline void get (I &x) {
		for (c = gc(); c < 'A' || c > 'Z'; c = gc()) ;
		x = c;
	}
	// input a string
	inline void read (char *s){
		for(c = gc(); c < 'A' || c > 'Z'; c = gc()) ;
		for(; c >= 'A' && c <= 'Z'; c = gc()) *++s = c;
		*++s = '\0';
	}
	// print a signed integer
	template <class I>
	inline void print (I x) {
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10;
		while (qr) putc (qu[qr --]);
	}
	//no need to call flush at the end manually!
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io :: gi;
using io :: get;
using io :: read;
using io :: putc;
using io :: print;
const int N=405,M=1e5+5;
bitset<N> f[N];
int g[N],tot,head[N],nxt[M<<1],adj[M<<1],w[M<<1],vis[N];
inline void addedge(ri x,ri y,ri z){
	nxt[++tot]=head[x];
	adj[head[x]=tot]=y;
	w[tot]=z;
}
inline bool dfs(ri rt,ri x,ri lst){
	if(vis[x]==rt){
		g[rt]=1;
		return true;
	}
	vis[x]=rt;
	f[rt][x]=1;
	for(ri i=head[x];i;i=nxt[i])
		if(w[i]<lst&&dfs(rt,adj[i],w[i]))
			return true;
	return false;
}
int main(){
	ri n,m,i,j,ans,x,y;
	gi(n);gi(m);
	for(i=1;i<=m;++i) gi(x),gi(y),addedge(x,y,i),addedge(y,x,i);
	for(i=1;i<=n;++i) dfs(i,i,2e9);
	ans=0;
	for(i=1;i<=n;++i)
		if(!g[i])
			for(j=i+1;j<=n;++j)
				ans+=!g[j]&&!(f[i]&f[j]).any();
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 6400
package main

import (
	"fmt"
	"os"
)

func main() {
	var N int

	fmt.Scan(&N)
	hashMap := make(map[int]int, N)
	A := make([]int, N, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&A[i])
		hashMap[A[i]]++
	}

	for _, count := range hashMap {
		if count > 1 {
			fmt.Println("NO")
			os.Exit(0)
		}
	}
	fmt.Println("YES")
}


Measured memory_bytes: 13184
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
#define RF(x) freopen(x,"r",stdin)
#define WF(x) freopen(x,"w",stdout)
typedef long long LL;
using namespace std;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
const LL MOD = (LL)1e9+7;
const int SIZE = 2e5+5;
const LL INF = 1LL<<60;
const double eps = 1e-4;
const double PI=3.1415926535897932;

int cur = 1;

int adj[1000009][26];
int cnt[1000009][26];//extra lol
string s[200009];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int  n;
	cin >> n;
	REP(i,n){
		cin>>s[i];
		reverse(ALL(s[i]));
	}
	LL ans = 0;
	for(int iter = 0;iter < 2;iter++){
		MS1(adj);
		REP(i,n){
			int x = 0;
			bool has = 1;
			REP(j,SZ(s[i])-1){
				if(adj[x][s[i][j]-'a']==-1){
					has = 0;break;
				}
				else x = adj[x][s[i][j]-'a'];
			}
			if(has)ans += cnt[x][s[i].back()-'a'];
			int bm[SZ(s[i])+1];
			bm[SZ(s[i])] = 0;
			for(int j=SZ(s[i])-1;j>=0;j--){
				bm[j] = bm[j+1] | 1<<(s[i][j]-'a');
			}
			x=0;
			REP(j,SZ(s[i])){
				for(int k=0;k<26;k++){
					if(bm[j]&(1<<k))cnt[x][k]++;
				}
				if(adj[x][s[i][j]-'a']==-1){
					adj[x][s[i][j]-'a']=cur;
					x=cur++;
				}
				else x = adj[x][s[i][j]-'a'];
			}
			
		}
		//cout << "BIG" << ans << endl;
		if(iter ==1)break;
		cur = 1;
		MS0(cnt);
		reverse(s,s+n);
	}
	cout << ans;
}


Measured memory_bytes: 217480
# coding:utf-8
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = 0

for i in range(n):
    if a[i] >= b[i]:
        ans += b[i]
    else:
        ans += a[i]
        b[i] -= a[i]
        if a[i + 1] >= b[i]:
            a[i + 1] -= b[i]
            ans += b[i]
        else:
            ans += a[i + 1]
            a[i + 1] = 0


print(ans)


Measured memory_bytes: 24164
/*
*/

#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>

#include <memory.h>
#include <assert.h>

#define y0 sdkfaslhagaklsldk

#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define norm asdfasdgasdgsd
#define have adsgagshdshfhds
#define ends asdgahhfdsfshdshfd
#define prev asdgSHJsfgsdfhdsh

#define eps 1e-8
#define M_PI 3.141592653589793
#define bsize 512

#define ldouble long double
using namespace std;

#define bs 1000000007

const int N = 1200031;

int main(){
//	freopen("apache.in","r",stdin);
//	freopen("apache.out","w",stdout);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(0);
//	cin.tie(0);

	int n;
	cin>>n;
	if (n<1000)
		cout<<"ABC"<<endl;
	else
		cout<<"ABD"<<endl;

//	cin.get(); cin.get();
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int S[50][50];
int ans[50][50];
int W, H;
int main() {
	cin >> H >> W;
	string s;
	for(int i = 0; i < H; i++) {
		cin >> s;
		for(int j = 0; j < W; j++) {
			S[i][j] = s[j] == '#' ? 1 : 0;
			ans[i][j] = -1;
		}
	}
	int a = 0, cx, cy;
	for(int y = 0; y < H; y++) {
		for(int x = 0; x < W; x++) {
			if(S[y][x]) continue;
			a = 0;
			for(int dy = -1; dy <= 1; dy++) {
				for(int dx = -1; dx <= 1; dx++) {
					cx = dx + x, cy = dy + y;
					if(cx < 0 || W <= cx || cy < 0 || H <= cy) continue;
					a += S[cy][cx];
				}
			}
			ans[y][x] = a;
		}
	}
	for(int y = 0; y < H; y++) {
		for(int x = 0; x < W; x++) {
			if(ans[y][x] < 0) cout << '#';
			else cout << ans[y][x];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
 
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <random>
#include <chrono>

#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
 
#define itn int
#define fro for
#define lowbit(x) (x & (-x))
#define Fast freopen("in.txt", "r", stdin)

using namespace std;
typedef long long ll;


/*------------------------------------------------------------------------------------*/
template <typename _t>
inline void read(_t &x){
    x = 0; _t fu = 1; char ch = getchar();
    while(ch < '0' || ch > '9'){if(ch == '-') fu = - 1; ch = getchar();}
    while(ch >= '0' && ch <= '9'){
        x = (x << 3) + (x << 1) + (ch & 15);
        ch = getchar();
    }
    x *= fu ;
}
/*------------------------------------------------------------------------------------*/
ll gcd(ll x, ll y){return !x? y: gcd(y % x, x);}
void exgcd(ll a, ll b, ll &x, ll &y){
    if(!b){x = 1; y = 0;return;}
    exgcd(b, a % b, y, x);
    y -= a / b * x;
}
/*------------------------------------------------------------------------------------*/
struct Mart{
    int a, b, c, d;
    Mart operator *(Mart &m){
        Mart temp;
        temp.a = a * m.a + b * m.c;
        temp.b = a * m.b + b * m.d;
        temp.c = c * m.a + d * m.c;
        temp.d = c * m.b + d * m.d;
        return temp;
    }
    Mart(){a = b = c = d = 0;}
    Mart(int x[4]){a = x[0]; b = x[1]; c = x[2]; d = x[3];}
    Mart(int u, int v, int w, int x){a = u; b = v; c = w; d = x;}
    int det(){return a * d - b * c;}
};
/*------------------------------------------------------------------------------------*/

const int maxn = 2e3 + 10;

int n;

struct NODE{
    ll key; int id;
    bool operator < (const NODE &b)const{
        return key > b.key;
    }
};
NODE node[maxn];
ll dp[maxn][maxn];

int main(){
//    Fast;
    read(n); for(int i = 0; i < n; i++){
        read(node[i].key);
        node[i].id = i;
    }
    sort(node, node + n);
    //dp[i][j]表示剩余的元素只能放在区间[i, j]时区间外面所可能得到的最大值
    //在i == j的时候终止循环。
    
    for(int d = n; d > 1; d--){
        //长度为d，对应当前要放的是第n - d个元素
        for(int i = 0; i + d - 1 < n; i++){
            dp[i + 1][i + d - 1] = max(dp[i + 1][i + d - 1], dp[i][i + d - 1] + abs(node[n - d].id - i) * node[n - d].key);
            dp[i][i + d - 2] = max(dp[i][i + d - 2], dp[i][i + d - 1] + abs(node[n - d].id - (i + d - 1)) * node[n - d].key);
        }
    }
    ll ans = 0;
    for(int i = 0; i < n; i++){
        ans = max(ans, dp[i][i] + abs(node[n - 1].id - i) * node[n - 1].key);
    }
    printf("%lld\n", ans);
    
    return 0;
}


Measured memory_bytes: 26440
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 5LL << 60;
const ll mod = 1e9 + 7;

int main() {
	int N, M;
	cin >> N >> M;
	int s[M], c[M];
	for(int i = 0; i < M; i++) cin >> s[i] >> c[i];

	int ans[N];
	for(int i = 0; i < N; i++) ans[i] = -1;
	for(int i = 0; i < M; i++) {
		s[i]--;
		if(ans[s[i]] == -1) {
			ans[s[i]] = c[i];
		} else {
			if(ans[s[i]] != c[i]) {
				cout << -1;
				return 0;
			}
			ans[s[i]] = c[i];
		}
	}
	if(ans[0] == 0 && N != 1)
		cout << -1;
	else if(ans[0] == -1 && N == 1)
		cout << 0;
	else
		for(int i = 0; i < N; i++) {
			if(ans[i] == -1) {
				if(i == 0)
					cout << 1;
				else
					cout << 0;
			} else
				cout << ans[i];
		}
	return 0;
}


Measured memory_bytes: 3616
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int x = sc.nextInt();
		int cnt= 0;
		
		for(int i = 0; i<=a ; i++) {
			for(int j= 0; j<=b ; j++) {
				for(int k = 0; k<=c ; k++) {
					if(500*i+100*j+50*k==x) {
						cnt++;
					}
				}
			}
		}
		

		System.out.println(cnt);
		
		sc.close();

	}

}


Measured memory_bytes: 21844
#include <iostream>
using namespace std;
int main(void){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    while(1){
        c-=b;
        if(c<=0){
            cout << "Yes" << endl;
            break;
        }
        a-=d;
        if(a<=0){
            cout << "No" << endl;
            break;
        }
    }
}

Measured memory_bytes: 3064
#include <iostream>

using namespace std;
using ll = long long;

#define FOR(i,m,n) for(ll (i)=(m); (i)<(n); ++(i))
#define REP(i,n) FOR(i,0,n)

/*---------------------------------------------------*/

typedef struct node{
  ll key;
  node *prev, *next;
}n_t;

n_t *snt;

inline void initNode(){
  snt = (n_t*)malloc(sizeof(n_t));
  snt->next = snt;
  snt->prev = snt;
}

inline void insertNode(const ll key){
  n_t *x = (n_t*)malloc(sizeof(n_t));
  x->key = key;
  x->next = snt->next;
  snt->next->prev = x;
  x->prev = snt;
  snt->next = x;
}

inline n_t* listSearch(const ll key){
  n_t *now = snt->next;
  while(now != snt && now->key != key){
    now = now->next;
  }
  return now;
}

inline void deleteNode(n_t* x){
  if(x == snt) return;
  x->prev->next = x->next;
  x->next->prev = x->prev;
  free(x);
}

inline void deleteFirst(){
  deleteNode(snt->next);
}

inline void deleteLast(){
  deleteNode(snt->prev);
}

inline void printList(){
  n_t *now = snt->next;
  while(now != snt){
    cout << now->key;
    if(now->next != snt) cout << " ";
    now = now->next;
  }
  cout << "\n";
}

/*---------------------------------------------------*/

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  initNode();  
  ll n; cin >> n;
  REP(i,n){
    string s; cin >> s;
    ll num;
    if(s == "insert"){
        cin >> num;
        insertNode(num);
    }
    else if(s == "delete"){
        cin >> num;
        deleteNode(listSearch(num));
    }
    else if(s == "deleteFirst"){
        deleteFirst();
    }
    else if(s == "deleteLast"){
        deleteLast();
    }
  }
  printList();
  
  return 0;
}



Measured memory_bytes: 34336
n,k = map(int,input().split())
sunuke = [i for i in range(n)]
for i in range(k):
  d = int(input())
  a_list = list(map(int,input().split()))
  for a in a_list:
    if a-1 in sunuke:
      sunuke.remove(a-1)
print(len(sunuke))

Measured memory_bytes: 9180
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef vector <ll> vll;
typedef pair <ll, ll> pll;
#define pb push_back
#define mp make_pair
#define MAX 1000000
#define mod 1000000007
#define all(_) _.begin(), _.end()
#define F first
#define S second

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    ll n, i, j, k;
    cin >> n;
    ll dp[n][n];
    vll psum(n + 1, 0);
    for(i = 0; i < n; i++)
    {
        cin >> j;
        psum[i + 1] = psum[i] + j;
    }
    memset(dp, 0, sizeof dp);
    for(i = 1; i < n; i++)
    {
        for(j = 0; i + j < n; j++)
        {
            dp[j][i + j] = LLONG_MAX;
            for(k = j; k < i + j; k++)
                dp[j][i + j] = min(dp[j][i + j], dp[j][k] + dp[k + 1][i + j] + psum[i + j + 1] - psum[j]);
        }
    }
    cout << dp[0][n - 1] << endl;
    return 0;
}

Measured memory_bytes: 1536