akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
using namespace std;
int main(){
	int n,i,sum=0;
	long long a[3010];
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a[i];
		sum+=a[i]-1;
	}
	cout<<sum<<endl;
}

Measured memory_bytes: 384
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <cmath>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
const ll MOD = 998244353;

ll gcd(ll a, ll b){
    return b?gcd(b, a%b):a;
}

int main() {
    ll n;
    cin >> n;
    vector<ll> A(n);
    for (auto & a : A) {
        cin >> a;
    }
    ll res = A[0];
    for (auto & a : A) {
        res = gcd(res, a);
    }
    cout << res << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s; char k; int h=0;
    cin>>s;
    k=s[0];
    for(int i=1;i<s.length();i++)
    {
        if(s[i]!=k)  h++;
        k=s[i];
    }
    cout<<h;
    return 0;
}

Measured memory_bytes: 512
## coding: UTF-8
N, A, B = map(int,input().split())

ans = 0
for i in range(1, N+1):
    s = str(i)
    w = 0
    for j in range(len(s)):
        w += int(s[j])
    if(A<= w and w <= B):
        ans += int(s)
print(ans)




Measured memory_bytes: 40684
#include <iostream>
#include <string>
using namespace std;
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <map>
#include <queue>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200010
#define LIMIT2 500010
#define INF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef long double ld;
typedef const void cv;
typedef pair<ll,ll> P;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
#define setpre(n) fixed << setprecision(n)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1},dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(cv *a, cv *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(cv *a, cv *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(cv *left, cv *right) {return strcmp((char *)left,(char *)right);}
int downchar(cv *left, cv *right) {return strcmp((char *)right,(char *)left);}
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1){
      res *= a; if(mod>=1) res %= mod;
    }
    a *= a; if(mod>=1) a %= mod;
    n >>= 1;
  }
  return res;
}
void initialize(){
  
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0;
  int a,b;
  queue<ll> que;
  string s;
  vector<ll> edge[200010],parent(200010,-1);
  map<ll,ll> dp;
  
  cin >> n >> m;
  rep(i,m){
    cin >> a >> b;
    a--;b--;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  rep(i,n){
    if(parent[i]!=-1) continue;
    que.push(i);
    parent[i] = i;
    while(!que.empty()){
      auto p=que.front();
      que.pop();
      for(auto q : edge[p]){
        if(parent[q]!=-1) continue;
        parent[q] = i;
        que.push(q);
      }
    }
  }
  rep(i,n) dp[parent[i]]++;
  for(const auto& [key,value] : dp){
    result = max(result,value);
  }
  cout << result << endl;
  return 0;
}

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

#define ndl "\n"
#define f first
#define s second
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ll long long
#define faster ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const ll M = 1e9+7;
const int N = 2*1e5+5;
const ll INF = 1e18;
const double EPS = 1e-6;

char a[1000][1000];
ll h,w,k,b[1000][1000],l[N],cnt = 1;

int main () {
	faster;
	cin>>h>>w>>k;
	for (int i = 1; i<=h; i++) {
		for (int j = 1; j<=w; j++) {
			cin>>a[i][j];
			if (a[i][j] == '#') b[i][j] = cnt++;
		}
	}
	for (int i = 1; i<=h; i++) {
		for (int j = 1; j<=w; j++) {
			if (b[i][j] != 0 && b[i][j+1] == 0) b[i][j+1] = b[i][j];
		}
	}
	for (int i = h; i>=1; i--) {
		for (int j = w; j>=1; j--) {
			if (b[i][j] != 0 && b[i][j-1] == 0) b[i][j-1] = b[i][j];
		}
	}
	for (int i = w; i>=1; i--) {
		for (int j = h; j>=1; j--) {
			if (b[j][i] != 0 && b[j-1][i] == 0) b[j-1][i] = b[j][i];
		}
	}
	for (int i = 1; i<=w; i++) {
		for (int j = 1; j<=h; j++) {
			if (b[j][i] != 0 && b[j+1][i] == 0) b[j+1][i] = b[j][i];
		}
	}
	for (int i = 1; i<=h; i++) {
		for (int j = 1; j<=w; j++) {
			cout<<b[i][j]<<' ';
		}
		cout<<endl;
	}

    return 0;
}


Measured memory_bytes: 5248
#include <iostream>
#include <string>
using namespace std;
int main(void){
    string S,T;
    cin>>S>>T;
    string code;
    code="abcdefghijklmnopqrstuvwxyz";
    bool po[26];
    bool flag =true;
    for(int i=0;i<26;i++){
        po[i]=false;
    }
    for(int i=0;i<S.length();i++){
        if(!po[S[i]-'a']){  //その文字がまだ出てきていないのなら
            po[S[i]-'a']=true;
            code[S[i]-'a']=T[i];
        } else {
            if(T[i]!=code[S[i]-'a']){
                flag =false;
                break;
            }
        }
    }
    
    code="abcdefghijklmnopqrstuvwxyz";
    for(int i=0;i<26;i++){
        po[i]=false;
    }
    if(flag){
    for(int i=0;i<S.length();i++){
        if(!po[T[i]-'a']){  //その文字がまだ出てきていないのなら
            po[T[i]-'a']=true;
            code[T[i]-'a']=S[i];
        } else {
            if(S[i]!=code[T[i]-'a']){
                flag =false;
                break;
            }
        }
    }
    }
    
    
    if(flag){
        cout<<"Yes"<<endl;
    } else {
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 776
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**9

n = int(input())
a = list(map(int, input().split()))
l = len(a)
r = inf
for i in range(-101, 101, 1):
    c = 0
    for ai in a:
        c += (ai - i) ** 2
    if r > c:
        r = c
print(r)


Measured memory_bytes: 8224
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.io.OutputStream;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.math.BigDecimal;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int A = in.nextInt();
            int B = in.nextInt();
            int C = in.nextInt();
            int D = in.nextInt();

            boolean N[] = new boolean[101];
            boolean M[] = new boolean[101];

            for(int i=A; i<=B; i++){
                N[i] = true;
            }
            for(int i=C; i<=D; i++){
                M[i] = true;
            }
            int res=0;
            for(int i=0; i<=100; i++){
                if(N[i]==true && M[i]==true){
                    res++;
                }
            }
            if(res>0) res--;
            out.println(res);

        }
    }


    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}

Measured memory_bytes: 21460
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int read() {
	int ans = 0, flag = 1;
	char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') flag = - flag; ch = getchar();}
	while(ch >= '0' && ch <= '9') {ans = ans * 10 + ch - '0'; ch = getchar();}
	return ans * flag;
}
const int N = 200010;
const int mod = 1000000007;
int n;
int pre[N];
int col[N];
int f[N];
int main() {
	n = read();
	for(int i = 1; i <= n; ++ i) {
		int c = read();
		pre[i] = col[c];
		col[c] = i;
	}
	f[0] = 1;
	for(int i = 1; i <= n; ++ i) {
		f[i] = f[i - 1];
		if(pre[i] != i - 1 && pre[i] != 0)
			f[i] += f[pre[i]];
		f[i] %= mod;
	}
	printf("%d\n", f[n]);
	return 0;
}

Measured memory_bytes: 2560
#include <stdio.h>
int main() {
    int n;
    int a[100];
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    for (int i = n - 1; i > 0; i--) {
        printf("%d ", a[i]);
    }
    printf("%d\n", a[0]);
    return 0;
}


Measured memory_bytes: 2044
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

h1,m1,h2,m2,k=map(int,input().split())
h=h2-h1
m=m2-m1
leng=h*60+m
print(leng-k)

Measured memory_bytes: 68236
#include <cstdio>
#include <cctype>
#include <algorithm>
#define repu(i,x,y) for (int i=x; i<=y; ++i)
using namespace std;

int n,k,ans,f[100100];
struct edge
{
    int v;
    edge *nxt;
} pool[100100],*tp=pool,*fst[100100];

int getint()
{
    char ch;
    while (!isdigit(ch=getchar()));
    int x=ch-'0';
    for (; isdigit(ch=getchar()); x=x*10+ch-'0');
    return x;
}

void dfs(int x,int fa)
{
    f[x]=1;
    for (edge *i=fst[x]; i; i=i->nxt)
        dfs(i->v,x),f[x]=max(f[x],f[i->v]+1);
    if (f[x]==k && fa>1)
        f[x]=0,++ans;
}

int main()
{
    scanf("%d%d",&n,&k),ans=getint()!=1;
    repu(i,2,n)
    {
        int fa=getint();
        *tp=(edge){i,fst[fa]},fst[fa]=tp++;
    }
    dfs(1,0),printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 7552
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cctype>
#define len length()
#define sz size()
#define rng(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) rng(i, 0, n)
#define srt(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define vi(a, n) vector<int> a(n)
#define vs(a, n) vector<string> a(n)
#define vc(a, n) vector<char> a(n)
#define psb(a) push_back(a)
#define ppb pop_back()
#define erc(S, i) S.erase(S.begin() + i)
#define ers(S, i, j) S.erase(S.begin() + i, S.begin() + j)
#define sp(n) cout << setprecision(n) << fixed
#define fst(s) s.at(0)
#define lst(s) s.at(s.len - 1)
typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(){
    int a, b;
    cin >> a >> b;
    int ans;
    ans = max(int (a * 12.5), b * 10) - 1 ;
    while(ans < a * 12.5 + 12.5 && ans < b * 10 + 10){
        if(ans * 4 - 50 < a * 50 && a * 50 <= ans * 4 && ans - 10 < b * 10 && b * 10 <= ans){
            cout << ans << endl;
            return 0;
        }
        ans += 1;
        
    }
    cout << -1 << endl;
    return 0;
}

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

signed main() {
    string s;
    cin >> s;

    string t = "keyence";

    int head, tail;
    head = tail = 0;

    for (int i = 0; i < t.size(); i++) {
        if (s[i] != t[i]) break;
        head++;
    }

    for (int i = 0; i < t.size(); i++) {
        if (s[s.size() - i - 1] != t[t.size() - i - 1]) break;
        tail++;
    }

    cout << (head + tail >= t.size() ? "YES" : "NO") << endl;

    return 0;
}


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

using namespace std;

#define dbg(x) { cerr << #x << " - " << x << endl; }

int a[3];

int main() {
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	cout << a[0] + a[1] << '\n';
	return 0;
}


Measured memory_bytes: 256
#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int M=200005,Mod=1e9+7;
const int N=20;
int a[N],n,ans;
inline int mo(int x){return x<Mod?x:x-Mod;} 
struct AC{
	int ch[M][11],fail[M],cnt;
	bool end[M];
	inline void init(){cnt=0;}
	inline void insert(int n){
		int now=0;
		for (int i=1;i<=n;i++){
			if (!ch[now][a[i]-1]) ch[now][a[i]-1]=++cnt;
			now=ch[now][a[i]-1];
		}
		end[now]=true;
	}
	inline void build(){
		queue <int > Q;
		for (int i=0;i<10;i++) if (ch[0][i]) Q.push(ch[0][i]);
		while (!Q.empty()){
			int x=Q.front();Q.pop();
			end[x]|=end[fail[x]];
			for (int i=0;i<10;i++)
				if (ch[x][i]) fail[ch[x][i]]=ch[fail[x]][i],Q.push(ch[x][i]);
				else ch[x][i]=ch[fail[x]][i];
		}
	}
	int dp[45][M];//dp[i][j]表示匹配长度为 i ,在AC自动机上第 j 个节点 
	inline void work(){
		dp[0][0]=1;
		for (int i=0;i<n;i++)
			for (int j=0;j<=cnt;j++)
				for (int k=0;k<10;k++)
					if (!end[ch[j][k]])
						dp[i+1][ch[j][k]]=mo(dp[i+1][ch[j][k]]+dp[i][j]);
		for (int i=0;i<=cnt;i++) ans=mo(ans+dp[n][i]);
	}
}T;
int X,Y,Z;
inline void dfs(int i,int sum,int now){
	if ((i==0&&sum>X)||(i==1&&sum>Y)||(i==2&&sum>Z)||(now>n)) return;
	if (i==0&&sum==X) ++i,sum=0;
	if (i==1&&sum==Y) ++i,sum=0;
	if (i==2&&sum==Z) {
		T.insert(now);
		return;
	}
	for (int j=1;j<=10;j++) a[now+1]=j,dfs(i,sum+j,now+1);
}
int main (){
	scanf ("%d%d%d%d",&n,&X,&Y,&Z);
	T.init();
	dfs(0,0,0);
	T.build();
	T.work();
	int t=1;
	for (int i=1;i<=n;i++) t=1ll*t*10%Mod;
	printf ("%d",mo(t-ans+Mod));
	return 0;
}


Measured memory_bytes: 36608
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;

ll v[10][10];

ll dig(ll n) {
  ll res = 0;
  while(n > 0) {
    res++;
    n /= 10;
  }
  return res;
}

int main() {
  ll n;
  cin >> n;
  for(ll i = 1; i <= n; i++) {
    ll j = i;
    ll m = dig(j);
    ll k = j/(pow(10,m-1));
    v[k][j%10]++;
  }
  ll ans = 0;
  for(int i = 1; i<=9; i++)for(int j = 1; j<=9; j++) {
    ans += v[i][j]*v[j][i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
S = [0]*M
C = [0]*M
SC = {}
SC = {1: set([]), 2: set([]), 3: set([])}
for m in range(M):
    S[m], C[m] = map(int, input().split())
    SC[S[m]].add(C[m])

ANS = [0]*N
out = 0
for i in range(1, 4):
    if len(SC[i]) >= 2:
        out = 1
if out == 1:
    print(-1)

else:
    out = 0
    if N == 1:
        if len(SC[1]) == 0:
            ANS[0] = 0
        else:
            ANS[0] = list(SC[1])[0]

    else:
        for i in range(N):
            if i == 0:
                if len(SC[i+1]) == 0:
                    ANS[0] = 1
                elif list(SC[i+1])[0] == 0:
                    out = 1
                else:
                    ANS[0] = list(SC[i+1])[0]
            else:
                if len(SC[i+1]) == 0:
                    ANS[i] = 0
                else:
                    ANS[i] = list(SC[i+1])[0]
    if out == 1:
        print(-1)
    else:
        ans = 0
        for i in range(N):
            ans += ANS[i]*10**(N-i-1)
        print(ans)

Measured memory_bytes: 38384
#include <iostream>
#include <iomanip>
#include <math.h>
#include <fstream>
#include <string>
#include <time.h>
#include <ctime>
#include <stdlib.h>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <cstdlib>
using namespace std;

void trace(int A[],int N){
	for(int i=0;i<N;i++){
		if(i>0)cout << ' ';
		cout << A[i];
	}
	cout << endl;
}

void selectionSort(int A[],int N){
	
	int minj,count=0;
	for(int i=0;i<N;i++){
		minj = i;
		for(int j=i;j<N;j++){
			if(A[j]<A[minj]){
				minj= j;
			}
		}
		swap(A[i],A[minj]);
		if(i!=minj)count++;
	}
	trace(A,N);
	cout << count;
	cout << endl;
}

int main(){

	int N;
	int A[100];

	cin >> N;
	for(int i=0;i<N;i++){
		cin >> A[i];
	}
	selectionSort(A,N);

	return 0;
}

Measured memory_bytes: 1160
W, H, N = map(int, input().split())

x1 = []
x2 = []
y3 = []
y4 = []

for _ in range(N):
  x, y, a = map(int, input().split())
  if a == 1:
    x1.append(x)
  elif a == 2:
    x2.append(x)
  elif a == 3:
    y3.append(y)
  else:
    y4.append(y)

if not x1:
  if not x2:
    W = W
  else:
    W = min(x2)
elif not x2:
  W -= max(x1)
elif max(x1) >= min(x2):
  W = 0
else:
  W = min(x2) - max(x1)

if not y3:
  if not y4:
    H = H
  else:
    H = min(y4)
elif not y4:
  H -= max(y3)
elif max(y3) >= min(y4):
  H = 0
else:
  H = min(y4) - max(y3)
  
print(W*H)

Measured memory_bytes: 3064
/*author  ADITYA BANSAL
         MNNIT ALLAHABAD     */
#include<bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp> 
//using namespace boost::multiprecision; 
using namespace std;
#define ll long long
ll power(ll,ll);
ll mul(ll a,ll b);
#define watch(x) cerr<<(#x)<<"is"<<x<<nl;
#define fast  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi(a,b) for(ll i=a; i<b; i++)
#define fk(a,b) for(ll k=a; k<b; k++)
#define fri(a,b) for(ll i=a; i>b; i--)
#define fj(a,b) for(ll j=a; j<b; j++)
#define ffi(a,b) for(ll i=a;i*i<=b;i++)
#define mp make_pair
#define ff first 
#define  tc ll t; cin>>t; while(t--)
#define all(v) (v).begin(),(v).end()
#define ss second
#define pb push_back
#define mem(v) memset((v),0,sizeof(v));
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define sll set<ll>
#define vll vector<ll>
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define ad(a,b)  (a%mod+b%mod+mod)%mod
#define pob pop_back
#define nl endl
const int mod=1e9+7;
const ll  N=100002LL;

signed main(){ fast
  
  
  
   //tc
  // calc();
 {   ll h[100001],n,k;
	 ll dp[100001];
	 mem(dp)
	 cin>>n>>k;
	 fi(1,n+1) cin>>h[i];
	 ll f=1;
	 if(n<k){ f=0;
	 swap(n,k); 
 }
	   dp[1]=0;
	   dp[2]=abs(h[2]-h[1]);
	 fi(3,k+1) {  dp[i]=INT_MAX;
		    fj(1,i){
				dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]));
			}
	 }
	 if(f==0){
	 cout<<dp[k]<<nl;
	 return 0;}
	 fi(k+1,n+1) {   dp[i]=INT_MAX;
		  fj(i-k,i){
				dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]));
			}
	 }
 
 //fi(1,n+1) cerr<<dp[i]<<" ";
	 cout<<dp[n]<<nl;
  
	  
 }
    return 0;
}


/******************************************************************************/

ll mul(ll a,ll b){
    return ((a)*1LL*(b))%13;
}

ll power(ll a,ll n){
  ll res=1;
  while(n){
      if(n&1) res= mul(res,a);
     n>>=1; 
     a= mul(a,a);
  }
    return res;
}


Measured memory_bytes: 1792
import math, heapq
from collections import defaultdict

INF = float("inf")
MOD = int(1e9 + 7)

N = int(input())
S = [input() for _ in range(N)]

ss = defaultdict(int)
for s in S:
    ss["".join(sorted(s))] += 1

count = 0
for c in ss.values():
    count += (c - 1) * c // 2
print(count)


Measured memory_bytes: 25300
#include <iostream>
#include <iomanip>
#include <functional>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;

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

	int N; cin >> N;
	int fact = 1;
	for (int i = 1; i <= N; ++i) fact = fact * i;
	vector<pair<double, double> > field;
	double x, y;
	for (int i = 0; i < N; i++) {
		cin >> x >> y;
		field.push_back(make_pair(x, y));
	}

	vector<int> v(N);
	for (int i = 0; i < N; i++) v[i] = i;

	long double sum = 0;
	long double a, b;
	int cnt = 0;
	for (int i = 0; i < fact; ++i) { 
		for (int j = 0; j < N - 1; ++j) {
			a = pow(field[v[j]].first - field[v[j+1]].first, 2);
			b = pow(field[v[j]].second - field[v[j + 1]].second, 2);
			sum += sqrt(a + b);
		}
		next_permutation(v.begin(), v.end()); 
	}

	cout << setprecision(12) << sum / fact;
	return 0;
}

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

int main(){
  long a, b, x;
  cin >> a >> b >> x;
  if (a==0){
    cout << b/x+1 << endl;
  }else{
    cout << (b/x+1)-((a-1)/x+1) << endl;
  }
}


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

int main(){
  int A, B, C;
  cin >> A >> B >> C;
  int S = C- ( A - B );
  if (S > 0) cout << S << endl;
  else cout << 0 << endl;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int ans = __gcd(a[0],a[1]);
    for(int i = 2;i < n;i++) ans = __gcd(ans,a[i]);
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream> 
#include <sstream> 
#include <fstream> 
#include <string> 
#include <vector> 
#include <deque> 
#include <queue> 
#include <stack> 
#include <set> 
#include <map> 
#include <algorithm> 
#include <functional> 
#include <utility> 
#include <bitset> 
#include <cmath> 
#include <cstdlib> 
#include <ctime> 
#include <cstdio> 
using namespace std;


vector<int> adj[100005],bfs1,bfs2,bfs1r,bfs2r;
bool used[100005];

int main(){
	int n;
	cin>>n;
	for(int i=1;i<n;i++){
		int x,y;
		cin>>x>>y;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	bfs1.push_back(1);
	bfs2.push_back(n);
	bfs1r.push_back(0);
	bfs2r.push_back(0);
	used[1]=true;
	used[n]=true;
	int ind=0,ans1=0,ans2=0,p=0,q=0;
	while(p<bfs1.size()||q<bfs2.size()){
		if(p<bfs1.size()){
		while(bfs1r[p]==ind){
			int v,r;
			v=bfs1[p];
			r=bfs1r[p];
			p++;
			for(int i=0;i<adj[v].size();i++) if(used[adj[v][i]]==false) {bfs1.push_back(adj[v][i]);bfs1r.push_back(r+1);used[adj[v][i]]=true;ans1++;}
		}
		}
		if(q<bfs2.size()){
		while(bfs2r[q]==ind){
			int v,r;
			v=bfs2[q];
			r=bfs2r[q];
			q++;
			for(int i=0;i<adj[v].size();i++) if(used[adj[v][i]]==false) {bfs2.push_back(adj[v][i]);bfs2r.push_back(r+1);used[adj[v][i]]=true;ans2++;}
		}
		}
		ind++;
	}
	if(ans1>ans2) cout<<"Fennec"<<endl;
	else cout<<"Snuke"<<endl;
return 0;
}

Measured memory_bytes: 6916
#include <bits/stdc++.h>
#define REP(i, N) for (int i = 0; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

//++時計回り --反時計回り
// int dx[4] = {1, 0, -1, 0};
// int dy[4] = {0, 1, 0, -1};

int main() {
  int N;
  cin >> N;
  ll A[N+1], B[N];
  REP(i, N+1) cin >> A[i];
  REP(i, N) cin >> B[i];
  ll count = 0;
  REP(i, N) {
    if (A[i] < B[i]) {
      count += A[i];
      B[i] -= A[i];
      if (A[i+1] < B[i]) {
        count += A[i+1];
        A[i+1] = 0;
      } else {
        count += B[i];
        A[i+1] -= B[i];
      }
    } else {
      count += B[i];
    }
  }
  cout << count << '\n';
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
    int x,y,ans = 0;
    cin >> x >> y;
    if(abs(y)<abs(x)){
        ans += max(abs(y),abs(x)) - min(abs(y),abs(x));
        if(0<x){
            ans++;
        }
        if(0<y){
            ans++;
        }
    }else{
        ans += max(abs(y),abs(x)) - min(abs(y),abs(x));
        if(x<0){
        ans++;
        }

        if(y<0){
        ans++;
        }
    }

    cout << ans <<endl;

}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
//constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;


int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/

	ll S; scanf("%lld", &S);
	vector<ll> cnt(S + 1);
	for (int i = 1; i <= S; i++) {
		ll sum = 0;
		for (int j = i; j <= S; j++) {
			sum += j;
			if (sum > S) break;
			cnt[sum]++;
		}
	}
	ll res = 0;
	for (ll i = 1; i <= S; i++) {
		if (S % i != 0) continue;
		//cout << i << " " << cnt[i] << " " << S / i << " " << cnt[S / i] << endl;
		res += cnt[i] * cnt[S / i];
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 3564
from itertools import permutations
import math

n = int(input())
x = []
y = []
for i in range(n):
    xi, yi = map(int, input().split(' '))
    x.append(xi)
    y.append(yi)

list = [i for i in range(n)]

total = 0
for i in permutations(list):
    norm = 0
    for j in range(n-1):
        X = x[i[j+1]] - x[i[j]]
        Y = y[i[j+1]] - y[i[j]]
        norm += math.sqrt(X**2 + Y**2)
    total += norm
print(total/math.factorial(n))


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


int main() {
  string A, B;
  cin >> A >> B;
  
  if(A.size() > B.size()) {
    cout << "GREATER" << endl;
    return 0;
  }
  if(A.size() < B.size()) {
    cout << "LESS" << endl;
    return 0;
  }
  rep(i, A.size()) {
    if(A[i] > B[i]) {
      cout << "GREATER" << endl;
      return 0;
    }
    if(A[i] < B[i]) {
      cout << "LESS" << endl;
      return 0;
    }
  }
  cout << "EQUAL" << endl;
  
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

n,m = map(int,input().split())
edges = [[] for _ in range(n)]
edges2 = [[] for _ in range(n)]

dis = [0] * n

for _ in range(m):
    x,y = map(int,input().split())
    edges[y-1].append(x-1)
    edges2[x-1].append(y-1)
    dis[x-1] = -1

q = []

for i in range(n):
    if dis[i] == 0:
        q.append(i)

while q:
    l = q.pop(0)
    for i in edges[l]:
        dis[i] = max(dis[i], dis[l] + 1)
        edges2[i].remove(l)
        if not edges2[i]:
            q.append(i)

print(max(dis))


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

void print(int A[], int N){
    for(int i = 0; i < N - 1; ++i){
        cout << A[i] << " ";
    }
    cout << A[N - 1] << "\n";
}

void insertionSort(int A[], int N){
    int tmp;
    for(int i = 1; i < N; ++i){
        int tmp = A[i];
        int j = i - 1;
        while(j >= 0 && A[j] > tmp){
            A[j + 1] = A[j];
            --j;
        }
        A[j + 1] = tmp;
        print(A, N);
    }
}

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

    int N;
    int A[100];

    cin >> N;
    for(int i = 0; i < N; ++i){
        cin >> A[i];
    }

    print(A, N);
    insertionSort(A, N);

    return 0;
}


Measured memory_bytes: 3212
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>

//#define NDEBUG

#ifdef NDEBUG
#define DEBUG_PRINT(fmt, ...) ((void)0)
#else
#define DEBUG_PRINT(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__)
#endif
#define ASSERT_RANGE(min,x,max) assert(((x)>=(min)) && ((x)<=(max)))


#define N_MIN 0
#define N_MAX 26

#define S_MIN 1
#define S_MAX 10000

int sort_int(int *a, int N) {// {{{
	int i;
	for (i = 0; i < N-1; i++) {
		int j;
		for (j = i + 1; j < N; j++) {
			if (a[i] > a[j]) {
				int tmp = a[i];
				a[i] = a[j];
				a[j] = tmp;
			}
		}
	}
	return 0;
}// }}}

int main(int argc, char **argv) {
	char S[S_MAX+1];
	char ret[S_MAX+1];
	int N;
	int len;
	fscanf(stdin,"%d",&N);
	ASSERT_RANGE(N_MIN,N,N_MAX);
	fscanf(stdin,"%s",S);
	len = strlen(S);
	ASSERT_RANGE(S_MIN,len,S_MAX);

	{
		int i;
		for (i = 0; i < len; i++) {
			ASSERT_RANGE('A',S[i],'Z');
			ret[i] = S[i] + N;
			if (ret[i] > 'Z') {
				ret[i] -= ('Z' - 'A' + 1);
			}
		}
	}
	ret[len] = '\0';
	fprintf(stdout,"%s\n",ret);
	return 0;
}



Measured memory_bytes: 128
F,*q='First';$<.map{|l|l.split.permutation{|a,b|b&&(q[a.to_i]||=[])<<b.to_i}};h=->i,r{c=q[i].count{|j|j!=r&&h[j,i]};c>1&&$><<F<<exit;c<1};puts h[1,1]?F: :Second

Measured memory_bytes: 28796
program sample
	implicit none
    integer(8) :: i,j,k,l,m,h,w
    integer(8) :: n,b,counta,countb,countc
    character(len=10**5) :: a
    
    read(*,*) a
    
    l=len_trim(a)
    counta=0
    countb=0
    countc=0
    
    do i=1,l
    	if (a(i:i)=='a') then
        	counta = counta +1
        else if (a(i:i)=='b') then
        	countb = countb +1
        else if (a(i:i)=='c') then
        	countc = countc +1
        end if
    end do
    !write(*,*) a(1:l),counta,countb,countc
    
    if (abs(counta-countb)>=2 .or. abs(counta-countc)>=2 .or. abs(countc-countb)>=2) then
    	write(*,*) 'NO'
    else 
    	write(*,*) 'YES'
    end if
    stop
end program sample

Measured memory_bytes: 3120
use proconio::input;

fn main() {
    input! {
        n: usize,
        mut a: [i32;n]
    };
    a.sort();
    a.reverse();

    let alice = a.iter().step_by(2).sum::<i32>();
    let bob = a.iter().sum::<i32>() - alice;
    println!("{}", alice - bob)
}


Measured memory_bytes: 2156
n,a,b=map(int,input().split())
s=input()
aa=0
bb=0
for i in range(n):
	if s[i]=="a":
		if aa+bb<a+b:
			aa+=1
			print("Yes")
		else:
			print("No")
	if s[i]=="b":
		if aa+bb<a+b and bb<b:
			print("Yes")
			bb+=1
		else:
			print("No")
	if s[i]=="c":
		print("No")


Measured memory_bytes: 4016
from sys import stdin

def main():
    N = int(input())
    S = list(input())
    K = int(input())

    sk = S[K-1]
    for i, s in enumerate(S):
        if s != sk:
            S[i] = '*'
    print(''.join(S))

input = lambda: stdin.readline().rstrip()
main()


Measured memory_bytes: 3060
n = int(input())
ans = 0

d = 2
while d * d < n:
    if n % d != 0:
        d += 1
        continue

    e = d
    while n % e == 0:
        n //= e
        e *= d
        ans += 1

    while n % d == 0:
        n //= d
if n != 1:
    ans += 1

print(ans)

Measured memory_bytes: 9192
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

using namespace std;

int main() {
   int a,b,c;
   cin >> a >> b >> c;
   cout << min(b/a,c) << endl;
}

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

int64_t Q=1000000007;

int main(){
  int N,M;
  cin>>N>>M;
  vector<int> p(N);
  vector<int> q(M);
  for(int i=0;i<N;i++){
    cin>>p[i];
  }
  for(int i=0;i<M;i++){
    cin>>q[i];
  }
  vector<vector<int64_t>> dp(N+1,vector<int64_t>(M+1,1));
  for(int i=0;i<N;i++){
    for(int j=0;j<M;j++){
      dp[i+1][j+1]=dp[i][j+1]+dp[i+1][j]+Q;
      if(p[i]!=q[j]){
        dp[i+1][j+1]-=dp[i][j];
      }
      dp[i+1][j+1]%=Q;
    }
  }
  cout<<dp[N][M]<<endl;
}

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

///******************************** C o n t a i n e r ********************************///

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

///*********************************** C o n s t ***********************************///

const int       N=1e6+123;
const double    PI = acos(-1);
const ll        MOD=1000000007;                 ///1e9+7
ll dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};       ///first 4 for adjacent
ll dy[] = {0, +1, 0, -1, +1, -1, +1, -1};
ll dx8[]= {+1, +1, -1, -1, +2, +2, -2, -2};    ///knights move
ll dy8[]= {+2, -2, +2, -2, +1, -1, +1, -1};

///********************************** M a r c o ***********************************///

#define pb push_back
#define MP make_pair
#define F first
#define S second
#define test int tc; cin>>tc; while(tc--)
#define forn(i,n) for(i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(x) x.size()
#define el <<'\n'
#define sp <<' '
#define print(a) {for(auto x:a)cout<<x<<" ";cout<<endl;}
#define mem(a,b) memset(a, b, sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) (a)*(a)

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

///*********************************** F u n c t i o n ***********************************///

ll powmod(ll a,ll b){ a%=MOD;if(!a) return 0;ll pr=1;while(b>0){if(b&1){pr*=a;pr%=MOD;--b;}a*=a;a%=MOD;b/=2;}return pr;}
ll modinverse(ll a){return powmod(a,MOD-2);}
bool isPrime(ll n){ if(n<=1)return false;if(n<=3)return true;if(n%2==0 or n%3==0)return false;for(ll i=5;i*i<=n;i+=6){if(n%i==0 or n%(i+2)==0)return false;}return true;}
void seive(bool a[]){ll mx=sqrt(N),ii,jj;for(ii=3;ii<=mx;ii+=2)if(!a[ii])for(jj=ii*ii;jj<N;jj+=2*ii)a[jj]=true;}
void numofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<N;jj+=ii){if(jj==ii*ii) a[jj]++; else a[jj]+=2;}}}
void sumofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<N;jj+=ii){if(jj==ii*ii) a[jj]+=ii; else a[jj]+=ii+jj/ii;}}}

///**************************************************** C o d e ****************************************************///
///-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=///

void _case()
{
    ll n,i,j,k,ans=0;
    string a;
    cin>>a;
    if(a.back()!='s') cout<<a<<"s" el;
    else cout<<a<<"es" el;
}

main()
{
    fastio();
    _case();

}


///Thank you.


///Brainless_Loco Terminates Here!


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+5;
const int maxn = 2e5+5;

int main() {
	int x,y;
	scanf("%d%d",&x,&y);
	for(int i = 0;i <= 1005;++i){
		int tx = (double)i*0.08;
		int ty = (double)i*0.1;
		if(tx == x && ty == y){
			printf("%d\n",i);
			return 0;
		}
	}
	printf("-1\n");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll n,m,i,j,a[10001]; 
int main()
{
	cin>>n;
	if(n&1==0)
	{
		cout<<n<<" "<<n<<" "<<n/2<<"\n";
		return 0;
	}
	if(n%3==0)
	{
		cout<<n<<" "<<n/3*2<<" "<<n/3*2<<"\n";
		return 0; 
	}
	if(n%4==3)
	{
		cout<<(n+1)/4<<" "<<(n+1)*(n+1)/4<<" "<<(n+1)*(n+1)*n/4<<"\n";
		return 0;
	}
	for(i=1;i<=3500;i++)
	{
		for(j=1;j<=3500;j++)
		{
			ll x,y;
			x=n*i*j;
			y=4*i*j-n*i-n*j;
			if(y>0&&x%y==0)
			{
				cout<<i<<" "<<j<<" "<<x/y<<"\n";
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
///بِسْمِ الّٰلهِ الرَّحْمٰنِ الرَحِيْمِ
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi acos(-1.0)
int main()
{
     ios_base::sync_with_stdio(false);cin.tie(NULL);
     ll int i,n,t,j=0,p,x,a=0,b,l=0,r=0,y,k,c,sum=0,m,d;
     cin>>k>>n;
     int ara[101]={0};
     for(i=0;i<n;i++){
        cin>>a;
        ara[a]=1;
     }
     l=0;r=0;
     for(i=k;i<=100;i++){
        if(ara[i]==0){
            break;
        }
        l++;
     }
     for(i=k;i>=0;i--){
        if(ara[i]==0){
            break;
        }
        r++;
     }
     if(l<r){
        cout<<k+l<<endl;
     }
     else{
        cout<<k-r<<endl;
     }

     return EXIT_SUCCESS;
}


Measured memory_bytes: 3596
N = int(input())
claim = []
MAX = 0

for i in range(N):
    A = int(input())
    claim.append([input().split() for i in range(A)])

for i in range(2 ** N):
    people = [0 for i in range(N)]
    FLAG = True
    for j in range(N):  
        if ((i >> j) & 1):  
            people[j] = 1
    
    for k in range(len(claim)):
        if people[k] == 0:
            continue
        for l in range(len(claim[k])):
            if people[int(claim[k][l][0]) - 1] != int(claim[k][l][1]):
                FLAG = False
                break
    
    if FLAG:
        MAX = max(MAX, sum(people))

print(MAX)

Measured memory_bytes: 3064
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
	"strings"

)


func main() {
	solve(os.Stdin, os.Stdout)
}

type ReaderEx struct {
	baseScanner *bufio.Scanner
	words       []string
	nextWordIdx func() int
	initWordIdx func(int)
}

func NewScannerEx(stdin io.Reader) *ReaderEx {
	var this ReaderEx
	var idx int
	var wordsCnt int
	this.baseScanner = bufio.NewScanner(stdin)
	this.baseScanner.Buffer(make([]byte, 0), 1E+11)
	this.nextWordIdx = func() int {
		cur := idx
		idx = (idx + 1) % wordsCnt
		return cur
	}
	this.initWordIdx = func(wc int) {
		idx = 0
		wordsCnt = wc
	}
	return &this
}

func (me *ReaderEx) Scan(doSplit bool) (isScanned bool) {
	isScanned = me.baseScanner.Scan()
	if doSplit {
		me.words = strings.Fields(me.baseScanner.Text())
	} else {
		me.words = []string{me.baseScanner.Text()}
	}
	me.initWordIdx(len(me.words))
	return
}

func (me *ReaderEx) nextBytes() []byte {
	return []byte(me.words[me.nextWordIdx()])
}
func (me *ReaderEx) nextString() string {
	return me.words[me.nextWordIdx()]
}

type StringArray []string

func (me *ReaderEx) nextStringArray() StringArray {
	return me.words[me.nextWordIdx():]
}

func (me StringArray) toStrings() []string {
	return me
}

func (me StringArray) toInts() []int {
	strValues := me.toStrings()
	values := make([]int, len(strValues))
	for i, v := range strValues {
		n, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		values[i] = n
	}
	return values
}
func (me *ReaderEx) nextInt() int {
	n, err := strconv.Atoi(me.words[me.nextWordIdx()])

	defer func() {
		if err != nil {
			panic(fmt.Sprintf("getInt(%d)", n))
		}
	}()
	return n
}

func pow(x, y, mod int) (ans int) {

	ans = 1
	for bit := 1 << uint(math.Floor(math.Log2(float64(y)))); ; bit >>= 1 {
		if y&bit != 0 {
			ans *= x
			if mod > 0 {
				ans %= mod
			}
		}
		if bit <= 1 {
			return
		}
		ans *= ans
		if mod > 0 {
			ans %= mod
		}
	}
}

type factType struct {
	prime int
	count int
}

func fact(n int) (facts []*factType) {

	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			fa := factType{prime: i}
			for n%fa.prime == 0 {
				n /= fa.prime
				fa.count++
			}
			facts = append(facts, &fa)
		}
	}
	if n > 1 {
		facts = append(facts, &factType{prime: n, count: 1})
	}
	return facts
}
func dec2bin(n int) (ret []bool) {
	for bit := 1 << uint(math.Floor(math.Log2(float64(n)))); ; bit >>= 1 {
		ret = append(ret, n&bit != 0)

		if bit <= 1 {
			return
		}
	}

}

func abs(v int) int {
	if v < 0 {
		v = -v
	}
	return v
}

func b2i(b bool) (i int) {
	if b {
		i = 1
	} else {
		i = 0
	}
	return
}

func solve(stdin io.Reader, stdout io.Writer) {

	r := NewScannerEx(stdin)
	r.Scan(true)
	a := r.nextInt()
	r.Scan(true)
	b := r.nextInt()

	fmt.Fprintln(stdout, (1^2^3)^(a^b))
}


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

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

    int ans = 0;
    for (int i=1; i<=M; ++i) {
        for (int j=1; j<=D; ++j) {
            string tmp = to_string(j);
            if (tmp.size() < 2) continue;
            int a = tmp[0]-'0';
            int b = tmp[1]-'0';
            if (a < 2 or b < 2) continue;
            if (a*b == i) ans++;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int MAXN = 100001;
int N, M, ans = 0;
vector<int> Tree(MAXN, 0);

void init()
{
  for (int i = 1; i <= N; i++)
    Tree.at(i) = i;
}

int root(int x)
{
  if (Tree.at(x) == x)
    return x;
  else
    return Tree.at(x) = root(Tree.at(x));
}

bool same(int x, int y)
{
  return root(x) == root(y);
}

void unite(int x, int y)
{
  x = root(x);
  y = root(y);
  if (x == y)
    return;
  Tree.at(x) = y;
}

int main()
{
  cin >> N >> M;
  vector<int64_t> P(N + 1);
  for (int i = 1; i <= N; i++)
    cin >> P.at(i);
  init();
  int x, y;
  for (int i = 0; i < M; i++)
  {
    cin >> x >> y;
    unite(x, y);
  }
  for (int i = 1; i <= N; i++)
  {
    int p = P.at(i);
    if (same(i, p))
      ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1408
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;
#define rep(i,n) for(int i =0;i<(int)n;i++)

int main()
{
    string S;
    cin>>S;
    for(int i = 'A';i <'Z';i++)
    {
        for(int j = i+1;j <'Z'+1;j++)
        {
            if(count(S.begin(),S.end(),i)==2 && count(S.begin(),S.end(),j)==2)
            {
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }

    cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, M, A = 0;

  cin >> N;
  vector<string> blue(N);
  for (int i = 0; i < N; i++) {
    cin >> blue.at(i);
  }

  cin >> M;
  vector<string> red(M);
  for (int i = 0; i < M; i++) {
    cin >> red.at(i);
  }
  
  for (int i = 0; i < N; i++) {
    int count = 0;
    string X = blue.at(i);
    for (int j = 0; j < N; j++) {
      if (blue.at(j) == X) {
        count++;
      }
    }
    for (int j = 0; j < M; j++) {
      if (red.at(j) == X) {
        count--;
      }
    }
    if (count > A) {
      A = count;
    }
  }

  
  cout << A;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a=1;cin>>n;
  vector<int>d(n);
  for(int i=0;i<n;i++)cin>>d.at(i);
  if(n==1)cout<<1<<endl;
  else{ 
    sort(d.begin(),d.end());
    for(int j=1;j<n;j++){
      if(d.at(j)!=d.at(j-1))a++;
    }
    cout<<a<<endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
//AOJ2197

int main(void){
	int N=1,i=0,j=0,count=0;
	while(-1){
		scanf("%d",&N);
		if(N==0){break;}
		for(i=2;i<46;i++){
			if((N-i*(i+1)/2)%i==0&&(N-i*(i+1)/2)>=0){
				count++;
			}
		}
		printf("%d\n",count);
		count=0;
	}
	return 0;
}
	

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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

int N, K;
int mx;

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

	rep(i, N) {
		int x;
		cin >> x;
		mx = max(mx, x);
		if (i) {
			d = __gcd(d, x);
		} else {
			d = x;
		}
	}

	puts(K <= mx && K % d == 0 ? "POSSIBLE" : "IMPOSSIBLE");

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,r;
    cin >> a >> b >> r;
    int u[b],v[b],d[b];
    for(int i=0;i<b;i++)
    {
        cin >> u[i] >> v[i] >> d[i];
    }
    int dis[a];
    for(int i=0;i<a;i++)
    {
        dis[i]=INT_MAX;
    }
    dis[r]=0;
    for(int j=1;j<a;j++)
    {
        for(int i=0;i<b;i++)
        {
            if(dis[u[i]]!=INT_MAX)
            {
                if(dis[v[i]]>dis[u[i]]+d[i])
                    dis[v[i]]=dis[u[i]]+d[i];
            }
        }
    }
    int g=0;
    for(int i=0;i<b;i++)
    {
        if(dis[u[i]]!=INT_MAX)
        {
            if(dis[v[i]]>dis[u[i]]+d[i])
            {
                g++;
            }
        }
    }
    if(g>0)
        cout << "NEGATIVE CYCLE" << endl;
    else
    {
        for(int i=0;i<a;i++)
        {
            if(dis[i]==INT_MAX)
                cout << "INF" << endl;
            else
                cout << dis[i] << endl;
        }
    }
}



Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N, M;
    cin >> N >> M;
    int L[M], R[M];
    int l = 1, r = N;
    for (int i = 0; i < M; i++)
    {
        cin >> L[i] >> R[i];
        l = max(l, L[i]);
        r = min(r, R[i]);
    }
    if (l <= r)
    {
        cout << r - l + 1 << endl;
    }
    else
    {
        cout << "0" << endl;
    }
}

Measured memory_bytes: 1024
import sys
input = sys.stdin.readline
from collections import *

def dfs(now, d, L):
    if d==L:
        return 1
    
    res = 0
    
    for nex in range(max(0, now-1), min(9, now+1)+1):
        res += dfs(nex, d+1, L)
    
    return res

K = int(input())

for i in range(1, 100):
    r = 0
    
    for j in range(1, 10):
        r += dfs(j, 1, i)
    
    if K-r>0:
        K -= r
    else:
        k = i
        break

def dfs2(l, d, k):
    global K
    
    if d==k:
        K -= 1

        if K==0:
            l = list(map(str, l))
            print(''.join(l))
            exit()
        
        return
    
    now = l[-1]
    
    for nex in range(max(0, now-1), min(9, now+1)+1):
        l.append(nex)
        dfs2(l, d+1, k)
        l.pop()

for i in range(1, 10):
    dfs2(deque([i]), 1, k)



Measured memory_bytes: 3316
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,l,r) for(ll i=(l);i<(r);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define abs(p) ((p)>=(0)?(p):(-(p)))
int cmp(const void *a, const void *b);
int main(void){
    ll N, H1, H2, ans=0, w=0;
    scanf("%lld", &N);
    rep(i, 0, N){
        scanf("%lld", &H2);
        if(i!=0){
            if(H1>=H2){
                w++;
                ans = max(ans, w);
            }
            else w=0;
        }
        H1 = H2;
    }
    printf("%lld\n", ans);
    return 0;
}
int cmp(const void *a, const void *b){
    ll A=*(ll *)a, B=*(ll *)b;
    if(A==B)return 0;
    else return A>B ? 1:-1;//昇順ソート
}


Measured memory_bytes: 128
using System;
using System.Linq;

namespace AtCoder.Abcdef
{
    public class QuestionB
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            int[] inputArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            int N = inputArray[0], K = inputArray[1];
            var p = Console.ReadLine().Split(' ').Select(i => int.Parse(i));

            var result = p.OrderBy(item => item).Take(K).Aggregate(0, (a, b) => a + b);
            Console.WriteLine(result);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 28744