akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

class DisjointSet{
public:
  vector<int> rank, p, sz;

  DisjointSet(){}
  DisjointSet(int size){
    rank.resize(size, 0);
    p.resize(size, 0);
    sz.resize(size, 0);
    rep(i, size) makeSet(i);
  }

  void makeSet(int x){
    p[x] = x;
    rank[x] = 0;
    sz[x] = 1;
  }

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

  void unite(int x, int y){
    link(findSet(x), findSet(y));
  }

  void link(int x, int y){
    if(rank[x] > rank[y]){
      p[y] = x;
      sz[x] += sz[y];
    }
    else{
      p[x] = y;
      sz[y] += sz[x];
      if(rank[x] == rank[y]){
        rank[y]++;
      }
    }
  }

  int findSet(int x){
    if(x != p[x]){
      p[x] = findSet(p[x]);
    }
    return p[x];
  }

  int getSize(int x){
    return sz[findSet(x)];
  }
};


int main(){
  int n, m; cin >> n >> m;
  vector<int> p(n), id(n);
  rep(i, n){
    cin >> p[i];
    p[i]--;
    id[p[i]] = i;
  }
  vector<int> a(m), b(m);
  DisjointSet ds = DisjointSet(n);
  rep(i, m){
    int s, t; cin >> s >> t;
    a[i] = s - 1;
    b[i] = t - 1;
    ds.unite(a[i], b[i]);
  }


  int ans = 0;
  rep(i, n){
    if(ds.same(p[i], id[p[i]])){
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}


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

typedef struct ListKey {
    int num;
} ListKey;
bool listkey__equal(ListKey *a, ListKey *b) {
    return a->num == b->num;
}
typedef struct ListDat {
    ListKey key;
    struct ListDat *prev;
    struct ListDat *next;
} ListDat;
typedef struct List {
    size_t len;
    ListDat *hdr;
} List;
#define list_init(l) ((l) ? ((l)->len = 0, (l)->hdr = NULL) : 0)
#define list_len(l) ((l) ? (l)->len : 0)
void list_insert(List *l, ListKey x) {
    ListDat *new_dat = malloc(sizeof(ListDat));
    if(l->len) {
        new_dat->next = l->hdr->next;
        l->hdr->next->prev = new_dat;
        l->hdr->next = new_dat;
    } else {
        l->hdr = malloc(sizeof(ListDat));
        l->hdr->prev = l->hdr->next = new_dat;
        new_dat->next = l->hdr;
    }
    new_dat->key = x;
    new_dat->prev = l->hdr;
    l->len++;
}
void list__delete(List *l, ListDat *a) {
    a->prev->next = a->next;
    a->next->prev = a->prev;
    free(a);
    l->len--;
}
void list_delete(List *l, ListKey x) {
    for(ListDat *it = l->hdr->next; it != l->hdr; it = it->next) {
        if(listkey__equal(&x, &it->key)) {
            list__delete(l, it);
            break;
        }
    }
}
void list_delete_first(List *l) {
    assert(l->len);
    list__delete(l, l->hdr->next);
}
void list_delete_last(List *l) {
    assert(l->len);
    list__delete(l, l->hdr->prev);
}
void list_print(List *l) {
    for(ListDat *it = l->hdr->next; it != l->hdr; it = it->next) {
        printf(it->next == l->hdr ? "%d\n" : "%d ", it->key);
    }
}
int main(int argc, char **argv) {
    int n;
    scanf("%d", &n);
    List l;
    list_init(&l);
    for(int i = 0; i < n; ++i) {
        char str[16];
        scanf("%s", str);
        if(strlen(str) == 6 && strncmp(str, "insert", 6) == 0) {
            ListKey key;
            scanf("%d", &key.num);
            list_insert(&l, key);
        } else if(strlen(str) == 6 && strncmp(str, "delete", 6) == 0) {
            ListKey key;
            scanf("%d", &key.num);
            list_delete(&l, key);
        } else if(strlen(str) == 11 && strncmp(str, "deleteFirst", 11) == 0) {
            list_delete_first(&l);
        } else if(strlen(str) == 10 && strncmp(str, "deleteLast", 10) == 0) {
            list_delete_last(&l);
        }
    }
    list_print(&l);
    return 0;
}



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

using namespace std;

#define ll long long

signed main() {
	int m; cin >> m;
	ll hoge = 0LL;
	while (m--) {
		int d; ll c;
		cin >> d >> c;
		hoge += d * c;
		hoge += c * 9;
	}
	cout << ((hoge - 10) / 9) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>
typedef long long ll;
using namespace std;

const ll MOD = 1e9 + 7;
const ll INF = 1e13;

int main() {
    ll i, j, k, n, m, h;
    cin >> n >> m;
    ll x, y;
    x = 0;
    ll cnt = 0, now;
    for(x = 0; x <= m; x += 2019) {
        if(x >= n) {
            cnt++;
            now = x;
        }
    }
    if(cnt >= 1)
        cout << 0 << endl;
    else {
        ll ret = INF;
        for(i = n; i <= m; i++) {
            for(j = i + 1; j <= m;j++){
                ret = min(ret, (i % 2019) * (j % 2019) % 2019);
            }
        }
        cout << ret << endl;
    }
    return 0;
}

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

int main()
{
    double a, b, c, d;
    cin >> a >> b >> c >> d;
    string ans = "No";
    if(ceil(c/b) <= ceil(a/d)) ans = "Yes";
    cout << ans << endl;
    return 0;
}

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

int main(){
	int n;
  cin >>n;
  long long int a[n],b[n];
  long long int aans=0,bans=0;
  for(int i=0;i<n;i++){
    cin >>a[i];
    b[i]=a[i];
  }
  long long int asum=0,bsum=0;
  for(int i=0;i<n;i++){
    asum+=a[i];
    if(i%2==0 && asum<=0){
        aans+=1-asum;
        asum=1;
      }
    if(i%2!=0 && asum>=0){
        aans+=asum+1;
        asum=-1;
    }
    cerr<< aans<<endl;
    
  }
  for(int i=0;i<n;i++){
    bsum+=b[i];
    if(i%2!=0)if(bsum<=0){
        bans+=1-bsum;
        bsum=1;
    }
    if(i%2==0)if(bsum>=0){
        bans+=bsum+1;
        bsum=-1;
    }
  }
  cout <<min(aans,bans)<<endl;
  cerr << aans <<bans <<endl;
}

Measured memory_bytes: 1792
import java.util.*;
import java.util.function.*;
import java.util.stream.*;

public class Main{
	Scanner s=new Scanner(System.in);

	void solve(){
		System.out.println((gInt()+1)/2);
	}

	public static void main(String[] A){
		new Main().solve();
	}

	int gInt(){
		return Integer.parseInt(s.next());
	}
	long gLong(){
		return Long.parseLong(s.next());
	}
	double gDouble(){
		return Double.parseDouble(s.next());
	}

	SupplyingIterator<Integer> ints(int n){
		return new SupplyingIterator<>(n,this::gInt);
	}
	SupplyingIterator<Long> longs(int n){
		return new SupplyingIterator<>(n,this::gLong);
	}
	SupplyingIterator<Double> doubles(int n){
		return new SupplyingIterator<>(n,this::gDouble);
	}
	SupplyingIterator<String> strs(int n){
		return new SupplyingIterator<>(n,s::next);
	}

	Range rep(int i){
		return Range.rep(i);
	}
	Range rep(int f,int t,int d){
		return Range.rep(f,t,d);
	}
	Range rep(int f,int t){
		return rep(f,t,1);
	}
	Range rrep(int f,int t){
		return rep(t,f,-1);
	}

	IntStream REP(int v){
		return IntStream.range(0,v);
	}
	IntStream REP(int l,int r){
		return IntStream.rangeClosed(l,r);
	}

	IntStream INTS(int n){
		return IntStream.generate(this::gInt).limit(n);
	}
	LongStream LONGS(int n){
		return LongStream.generate(this::gLong).limit(n);
	}
	Stream<String> STRS(int n){
		return Stream.generate(s::next).limit(n);
	}

}

class SupplyingIterator<T> implements Iterable<T>,Iterator<T>{
	int t;
	Supplier<T> supplier;

	SupplyingIterator(int t,Supplier<T> supplier){
		this.t=t;
		this.supplier=supplier;
	}

	@Override
	public Iterator<T> iterator(){
		return this;
	}

	@Override
	public boolean hasNext(){
		return t>0;
	}

	@Override
	public T next(){
		--t;
		return supplier.get();
	}

}

class Range implements Iterable<Integer>,PrimitiveIterator.OfInt{
	int to,cur,d;

	Range(int from,int to,int d){
		this.cur=from-d;
		this.to=to;
		this.d=d;
	}

	Range(int n){
		this(0,n-1,1);
	}

	@Override
	public Iterator<Integer> iterator(){
		return this;
	}

	@Override
	public boolean hasNext(){
		return cur+d==to||(cur!=to&&(cur<to==cur+d<to));
	}

	@Override
	public int nextInt(){
		return cur+=d;
	}
	static Range rep(int i){
		return new Range(i);
	}
	static Range rep(int f,int t,int d){
		return new Range(f,t,d);
	}
	static Range rep(int f,int t){
		return rep(f,t,1);
	}
	static Range rrep(int f,int t){
		return rep(f,t,-1);
	}
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define N 1001
using namespace std;
int n,p1,p2;
typedef pair<int,int> P;
vector<P> G[N],rG[N];
vector<P> A;
 
int used[N],god,devil;
vector<int> Idx[N];
int Sta[N];
 
void dfs(int pos, int sta){
  Idx[A.size()].push_back(pos);
  Sta[pos] = sta;
 
  for(P nx:G[pos]){
    int npos = nx.first;
    int nsta = sta ^ (!nx.second);
    if(used[npos]) assert(Sta[npos] == nsta);
    if(used[npos]++) continue;
    god += nsta;
    devil += !nsta;
    dfs(npos,nsta);
  }
   
  for(P nx:rG[pos]){
    int npos = nx.first;
    int nsta = sta ^ (!nx.second);
    if(used[npos]) assert(Sta[npos] == nsta);
    if(used[npos]++) continue;
    god += nsta;
    devil += !nsta;
    dfs(npos,nsta);
  }
}
 
 
void Push(vector<int> &res,int sta,int i){
  for(int p:Idx[i])if(sta == Sta[p]) res.push_back(p+1);
}
 
int dp[N][N];
vector<int> DP(){
  memset(dp,0,sizeof(dp));  
  dp[0][0] = 1;
  int n = A.size();
  for(int i=0;i<n;i++){
    int a = A[i].first;
    int b = A[i].second;
    for(int j=0;j<=p1;j++){
      dp[i+1][j+a] += dp[i][j];
      dp[i+1][j+b] += dp[i][j];
      dp[i+1][j+a] = min(2,dp[i+1][j+a]);
      dp[i+1][j+b] = min(2,dp[i+1][j+b]);
 
    }
  }
 
  if(dp[n][p1] != 1) return vector<int>(); 
  vector<int> res;
  int god = p1;
    for(int i=n-1;i>=0;i--){
      int a = A[i].first;
      int b = A[i].second;
      if(god-a>=0 && dp[i][god-a] == 1) Push(res,1,i),god -= a;
      else if(god-b>=0 && dp[i][god-b] == 1)Push(res,0,i),god -= b;
      else exit(1);
    }
    assert(god == 0);
    sort(res.begin(),res.end());
    return res;
}
 
int main(){
  while(1){
  cin>>n>>p1>>p2;
  if(!n&&!p1&&!p2)return 0;
 
  A.clear();
  memset(used,0,sizeof(used));
  memset(Sta,-1,sizeof(Sta));
  for(int i=0;i<N;i++) Idx[i].clear(),G[i].clear(),rG[i].clear();
   
  for(int i=0,x,y;i<n;i++){
    string str;
    cin>>x>>y>>str;
    x--,y--;
    G[x].push_back(P(y,str=="yes"));
    rG[y].push_back(P(x,str=="yes"));
  }
 
  for(int i=0;i<p1+p2;i++){
    if(used[i]++)continue;
    god = 1,devil = 0;
    dfs(i,1);
    A.push_back(P(god,devil));
  } 
 
  vector<int> ans = DP();
  if(p1&&ans.empty()) cout<<"no"<<endl;
  else {
    for(int p:ans)cout<<p<<endl;
    cout<<"end"<<endl;
  }
  }
  return 0;
}

Measured memory_bytes: 7232
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ProconTemplate
{
    class Doing
    {
        public static long bisToMoney = 0;
        public static long moneyToBis = 0;

        public static void Main(string[] args)
        {
            var inputInt = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
            
            if(inputInt[0] <= inputInt[1])
            {
                Console.WriteLine(inputInt[0] + 1);
                return;
            }

            if(inputInt[1]+2 >= inputInt[2])
            {
                Console.WriteLine(inputInt[0] + 1);
                return;
            }

            // Calc
            var remaining = inputInt[0] - (inputInt[1] + 1);
            var bis = inputInt[2] + ((remaining / 2) * (inputInt[2] - inputInt[1]));
            if((remaining % 2) == 1) { bis = bis + 1; }
            Console.WriteLine(bis);
        }
    }
}


Measured memory_bytes: 13268
K = int(input())


def check(k):
    if k & 1 == 0:
        return -1
    if k % 7 == 0:
        k //= 7

    a = 1

    for i in range(k + 1):
        if a % k == 0:
            return i + 1
        else:
            a = (10 * a + 1) % k

    return -1


print(check(K))


Measured memory_bytes: 9176
import math
import bisect


prime = [2,3,5,7,11,13,17,19,23]

tab = [False]*100001
tab[2] = True

for i in range(prime[-1]+2,100000+1,2):

    x = int( math.sqrt(i) )
    x += 1 if x%2 == 0 else 0

    found = False
    for p in prime:
        if x < p:
            break;

        if i % p == 0:
            found = True
            break
                
    if not found:
        prime.append(i)


#print(prime[10:100])
for p in prime:
    tab[p] = True

#print(tab[100:150])
q = int(input())

ac = [0] * len(tab)

for i in range(3,len(ac),2):
    ac[i-1] = ac[i-2]
    ac[i] = ac[i-1] + (1 if tab[i] and tab[(i+1)//2] else 0)

#print(ac)
for _ in range(q):

    l, r = map(int,input().split())
   
    
    ans = ac[r] - ac[l-1]

    print(ans)

Measured memory_bytes: 6420
#include <stdio.h>
int main(){
    int n,t,a;
    scanf("%d",&n);
    scanf("%d %d",&t,&a);
    int h[n];
    for(int i = 0; i < n;i++){
        scanf("%d",h+i);
    }
    int c;
    double x,max;
    c = 0;
    max = 100000;
    for(int i = 0; i < n;i++){
        x = a - (t - h[i]*0.006);
        if(x < 0) x = -x;
        if(max >= x){
            max = x;
            c = i+1;
        }
    }
    printf("%d\n",c);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define maxn 10005
using namespace std;
int main()
{
	char a[maxn],b[maxn];
	cin>>a>>b;
	int la=strlen(a);
	int lb=strlen(b);
	int m=max(la,lb);
	int mi=min(la,lb);
	int i;
	for(i=0;i<mi;i++)
	{
		cout<<a[i]<<b[i];
	}
	if(la>lb)
	{
		for(int j=i;j<m;j++)
		{
			cout<<a[j];
		}
	}
	else if(la<lb)
	{
		for(int j=i;j<m;j++)
		{
			cout<<b[j];
		}
	}
	return 0;
}

Measured memory_bytes: 256
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=-1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

a,b,c,d=get_i
if (a-c).abs<=d
    puts "Yes"
elsif (a-b).abs<=d and (b-c).abs<=d
    puts "Yes"
else
    puts "No"
end

Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
 
typedef long double LD;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define REP(i,n) for (ll i = 0; i < n; i++)
#define FOR(i,a,b) for (ll i = a; i < b; i++)
#define REPD(i,n) for (ll i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (ll i = a; i >= b; i--)
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define all(v) v.begin(),v.end()
#define rsort(v) sort(v.begin(), v.end(), greater <>());
typedef map<ll,ll> mll;
typedef vector<ll> vll;
typedef vector<vll> vvl;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
#define F first
#define S second
#define PQ(type) priority_queue<type>
#define PQD(type) priority_queue<type,vector<type>,greater<type> >
#define ITR :: iterator it
#define WL(t) while(t--)
#define SZ(x) ((int)(x).size())
#define TR(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define inrange(i,a,b) ((i>=min(a,b)) && (i<=max(a,b)))
#define i1(x) cin>>x
#define i2(x,n) cin>>x>>n
#define o1(x) cout<<x
#define o2(x,n) cout<<x<<n
int main(){
    ll n,m;
    i2(n,m);
    vll a(n);
    ll s=0;
    REP(i,n){
        i1(a[i]);
        s+=a[i];
    }
    s=ceil(s/((double)(4*m)));
    ll ans=0;
    REP(i,n)
        if(a[i]>=s)
            ans++;
    if(ans>=m)
        o1("Yes");
    else 
        o1("No");
}

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

using namespace std;

int main()
{
    string S, A;
    cin >> S;
    int Difference, B;
    vector<int> v;

    for (int i = 0; i + 2 < S.length(); i++)
    {
        A = S.substr(i, 3);
        B = stoi(A);
        Difference = B - 753;
        Difference = abs(Difference);
        v.push_back(Difference);
    }

    sort(v.begin(), v.end());

    cout << v[0];
}

Measured memory_bytes: 256
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)
# from numba import njit,i8
 
 
# @njit(i8(i8,i8,i8,i8[:,:],i8[:],i8,i8))
def give_dp(N,K,mod,LR,dp,l,r):
    for i in range(N):
        if i > 0:
            dp[i] += dp[i-1]
            dp[i] %= mod
        for k in range(K):
            l = LR[k][0]
            r = LR[k][1]
            if i + l < N:
                dp[i+l] += dp[i]
                dp[i+1] %= mod
            if i + r + 1 < N:
                dp[i+r+1] -= dp[i]
                dp[i+1] %= mod
    return dp[-1]
 
 
def main():
    N,K = map(int,input().split())
    LR = [list(map(int,input().split())) for i in range(K)]
    # LR = np.array(LR)
 
    mod = 998244353
 
    dp = [0 for i in range(N)]
    dp[0] = 1
    dp[1] = -1
    # dp = np.array(dp)
 
    res = give_dp(N,K,mod,LR,dp,0,0)
    res %= mod
 
    print(res)
 
 
 
main()

Measured memory_bytes: 17044
#include<bits/stdc++.h>
#define se second
#define fi first
using namespace std;
const int MAXN = 10+1e5;
typedef pair<int,int> I;
typedef long long LL;
const LL oo = 1e9;
int n,m;
int l1[MAXN],r1[MAXN];
LL a[MAXN];

void Inout()
{
    #define TASK "ABC"
    freopen(TASK ".inp", "r", stdin);
    freopen(TASK ".out", "w", stdout);
}

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

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

    l1[0] = 0;
    a[n+1] = oo;
    r1[n] = n+1;

    for (int i=1; i<=n; ++i)
        if ( a[i] < a[i-1] ) l1[i] = i-1;
        else {
            int x = l1[i-1];
            while( a[x] <= a[i] && x)
                x = l1[x];
            l1[i] = x;
        }

    for (int i=n-1; i; --i)
        if ( a[i] < a[i+1] ) r1[i] = i+1;
        else {
            int x = r1[i+1];
            while( a[x] <= a[i] && x <= n)
                x = r1[x];
            r1[i] = x;
        }
    //for (int i=1; i<=n; ++i)
     //   cerr <<l1[i] <<' ' <<r1[i] <<'\n';
    LL ans = 0;
    for (int i=1; i<=n; ++i) {
        int d = 0,
            l = l1[i],
            r = r1[i];
        if ( l>0 ) {
            --l;
            while( a[l] < a[i] && l ) l = l1[l];
            d += (r1[i] - i )* (l1[i] - l);
        }
        if ( r<n+1 ) {
            ++r;
            while( a[r] < a[i] && r<=n) r = r1[r];
            d += (r - r1[i] )* (i - l1[i]) ;
        }
        ans += d*a[i];
        //cout <<l <<' ' <<r <<' ' <<d <<'\n';
    }
    cout <<ans;
return 0;
}


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

using namespace std;

struct sta{
  int c, s, f;
};

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  sta s[n-1];
  for(int i=0; i<n-1; i++){
    cin >> s[i].c >> s[i].s >> s[i].f;
  }
  for(int i=0; i<n-1; i++){
    int time = s[i].s + s[i].c;
    for(int j=i+1; j<n-1; j++){
      if(time < s[j].s){
        time = s[j].s;
      }
      if(time % s[j].f){
        time += s[j].f - time % s[j].f;
      }
      time += s[j].c;
    }
    cout << time << endl;
  }
  cout << "0" << endl;
  return 0;
}


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



int main() {
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  int ans = 0;
  rep(i, n) cin >> v[i];
  for (int a = 0; a <= min(n, k); a++){
    for (int b = 0; a + b <= min(n, k); b++){
      vector<int> tmp;
      int cur = 0;
      for (int i = 0; i < a; i++) tmp.push_back(v[i]), cur+= v[i];
      for (int i = 0; i < b; i++) tmp.push_back(v[n - i -1]), cur += v[n - 1 -i];
      sort(tmp.begin(), tmp.end());
      for (int i = 0; i < min((int)tmp.size(), k - a - b); i++){
        if(tmp[i] < 0) cur -= tmp[i];
      }
      ans = max(ans, cur);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<limits.h>
#include<utility>
#include<vector>
#include<tuple>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(A) A.begin(),A.end()
vector<vector<bool>> seat;

int main() {
	string s, t;
	cin >> s >> t;
	ll max = 0;
	rep(i, s.size() - t.size()+1) {
		ll tmp = 0;
		rep(j, t.size()) {
			if (s[i + j] == t[j]) {
				tmp++;
			}
		}
		if (max < tmp)max = tmp;
	}
	cout << t.size() - max << endl;
}


Measured memory_bytes: 3168
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
    int a[26] = {0}, b[26] = {0};
    string s, t;
    cin >> s >> t;
    for(unsigned int i = 0; i < s.size(); i++){
        a[int(s[i]) - int('a')] += 1;
        b[int(t[i]) - int('a')] += 1;
    }
    sort(a, a+26);
    sort(b, b+26);
    for(int i = 0; i < 26; i++){
        if(a[i] != b[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 776
//Tue Dec 22 22:01:34 JST 2009
#include<set>
#include<iostream>
#include<queue>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
#define mp make_pair
int dx[]={0,1,1,0,-1,-1};
int dy[]={-1,-1,0,1,1,0};
#define CONNECT true
#define UNCONNECT false
#define CANMOVE true
#define CANNOTMOVE false

class state{
public:
  int len;
  int x[8],y[8];
  int cnt;
  int path[8];
  bool is_connected(int me,int you){
    if ( x[me]==x[you]){
      if ( y[me]-1 == y[you] || y[me]+1 == y[you] || y[me]==y[you])return CONNECT;
    }else if ( x[me]+1 == x[you]){
      if (y[me] ==y[you] || y[me]-1==y[you])return CONNECT;
    }else if ( x[me]-1==x[you]){
      if (y[me] ==y[you] || y[me]+1 == y[you])return CONNECT;
    }

    return UNCONNECT;
  }

  bool can_good_pos(int cur){
    rep(i,cur-1){
      if ( is_connected(cur,i)==CONNECT)return false;//
    }
    if (cur==0 ||  is_connected(cur,cur-1)==CONNECT)return true;//
    return false;
  }
  
  void make_next(int now,queue<state>&Q,set<state>&S,bool flag,set<pair<int,int> > & NG){
    if ( now == len){
      if ( S.find((*this))==S.end()){
	cnt++;
	S.insert(*this);
	Q.push(*this);
	cnt--;
      }
      return;
    }

    //don't move
    
    if (can_good_pos(now) ){
      path[now]=-1;
      make_next(now+1,Q,S,CANMOVE,NG);
    }

    if ( flag == CANNOTMOVE)return;//

    rep(i,6){
      x[now]+=dx[i];
      y[now]+=dy[i];

      path[now]=i;

      if (NG.find(mp(x[now],y[now])) == NG.end() && can_good_pos(now)){
	make_next(now+1,Q,S,CANNOTMOVE,NG);//
      }
      x[now]-=dx[i];
      y[now]-=dy[i];
    }
        
  }
  
  bool operator<(const state & a)const{
    rep(i,len){
      if ( x[i]!=a.x[i])return x[i]<a.x[i];
      if ( y[i]!=a.y[i])return y[i]<a.y[i];
    }
    return false;
  }
  
};



int bfs(state ini,int dx,int dy,set<pair<int,int> > &NG){
  queue<state> Q;
  set<state> S;
  Q.push(ini);
  S.insert(ini);
  while(!Q.empty()){
    state now = Q.front();
    Q.pop();
if (20<now.cnt+(max(now.x[0],dx)-min(now.x[0],dy)+
max(now.y[0],dy)-min(now.y[0],dy))/2)continue;
    if ( now.x[0]==dx && now.y[0]==dy){
      return now.cnt;
    }
    now.make_next(0,Q,S,CANMOVE,NG);
  }
  return -1;
}


main(){
  int n,m,dx,dy;
  while(cin>>n && n){
    state ini;
    set<pair<int,int> > NG;
    
    ini.len=n;
    ini.cnt=0;
    rep(i,n)cin>>ini.x[i]>>ini.y[i];
    cin>>m;
    rep(i,m){
      int f,s;
      cin>>f>>s;
      NG.insert(mp(f,s));
    }
    cin>>dx>>dy;
    cout << bfs(ini,dx,dy,NG)<<endl;
  }
  return false;
}

Measured memory_bytes: 17000
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    ll n;

    cin >> n;

    vector<ll> a(n);
    map<ll, ll> d;

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

    for (int i = 0; i < n; i++)
    {
        d[i + 1 - a[i]]++;
    }

    ll ans = 0;

    for (int i = 0; i < n; i++)
    {
        ans += d[i + 1 + a[i]];
    }

    cout << ans << endl;
}


Measured memory_bytes: 27392
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
ll MOD = 1000000007;
//ll INF = 21474836470000000;
ll INF = 1001001001001001001;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

template <class T>
class SegmentTree{
  ll N;
  vector<T> data;
  vector<T> lazy;
  T def;
  function<T(T,T)> operation;
  function<T(T,T)> update;
  public:
  SegmentTree(size_t _N,T _def,function<T(T,T)> _operaition,function<T(T,T)> _update):def(_def),operation(_operaition),update(_update){
          N = 1;
          while(N < _N){
              N *= 2;
          }
          data = vector<T>(2*N-1,def);
          lazy = vector<T>(2*N-1,0);
  }

  void change(ll i,ll x){
      i += N-1;
      data[i] = update(data[i],x);
      while(i > 0){
          i = (i-1)/2;
          data[i] = operation(data[i*2+1],data[i*2+2]);
      }
  }

  void eval(ll k,ll l,ll r){
      if(lazy[k] != 0){
          data[k] += lazy[k];
          if(r - l > 1){
              lazy[k*2+1] += (lazy[k] / 2);
              lazy[k*2+2] += (lazy[k] / 2);
          }
          lazy[k] = 0;
      }
  }

  void add(ll a,ll b,ll x,ll k = 0,ll l = 0,ll r = -1){
      if(r < 0) r = N;
      eval(k,l,r);
      if(b <= l || r <= a) return;
      if(a <= l && r <= b){
          lazy[k] += (r-l) * x;
          eval(k,l,r);
      }else{
          add(a,b,x,k*2+1,l,(l+r)/2);
          add(a,b,x,k*2+2,(l+r)/2,r);
          data[k] = data[k*2+1] + data[k*2+2];
      }
  }
  
  T query(ll a,ll b,ll k = 0,ll l = 0,ll r = -1){
      if(r < 0) r = N;
      eval(k,l,r);
      if(b <= l || r <= a) return def;
      if(a <= l && r <= b){
          return data[k];
      }else{
          T c1 = query(a,b,k*2+1,l,(l+r)/2);
          T c2 = query(a,b,k*2+2,(l+r)/2,r);
          return operation(c1,c2);
      }
  }

  T operator[](ll i){
      return lazy[i+N-1];
  }

  T oper(ll i){
      return data[i+N-1];
  }

};


int main(){
    ll N,Q;
    cin >> N >> Q;
    auto f = [](ll a,ll b){return a+b;};
    auto g = [](ll a,ll b){return b;};
    SegmentTree<ll> ST(100010,0,f,g);
    rep(i,100010) ST.change(i,0);
    rep(i,Q){
        ll q;cin >> q;
        if(q == 0){
            ll s,t,x;
            cin >> s >> t >> x;
            ST.add(s,t+1,x);
        }else{
            ll s,t;
            cin >> s >> t;
            cout << ST.query(s,t+1) << endl;
        }
    }
}



Measured memory_bytes: 7080
#include <iostream>
#include <fstream>
#include <string>


using namespace std;

int main(){
#ifdef CIN
	ifstream cin("input.txt");
	ofstream cout("output.txt");

#endif

	int h,w;

	while (true)
	{

		cin >> h >> w;

		if (h == 0 && w == 0) break;

		for (int i = 1; i <= h; i++)
		{
			for (int j = 1; j <= w; j++)
			{
				cout << "#";

			}
			cout << endl;
		}
		cout << endl;
	}


}

Measured memory_bytes: 1152
# Your code here!

#データの読み込み

fline=readlines
input=fline[0].split(" ")

#実際の処理

a=input[0].to_i
b=input[1].to_i
k=input[2].to_i

temp=0
i=100
while i>0 do
    if a%i==0&&b%i==0 then
        temp=temp+1
#        printf("i=%d, temp=%d\n",i,temp)
    end
    
    if temp==k then
        ans=i
        temp=temp+1
    end
    i=i-1
end
#出力

printf('%d', ans)





Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;
int main(){
	int N;
	cin >> N;
	ll C;
	cin >> C;
	vector<ll> x(N);
	vector<ll> v(N);
	for(int i = 0;i < N;i++)cin >> x[i] >> v[i];

	//移動の仕方は,右のみ,左のみ,左と右の3種類.
	vector<ll> cost_l_1(N);
	vector<ll> cost_l_2(N);
	vector<ll> cost_r_1(N);
	vector<ll> cost_r_2(N);

	ll ans = 0;
	ll sum_v = 0;

	//右のみ.
	for(int i = 0;i < N;i++){
		sum_v += v[i];
		cost_r_1[i] = sum_v - x[i];
		cost_r_2[i] = sum_v - x[i] * 2;
		ans = max(ans,sum_v - x[i]);
	}

	//左のみ.
	sum_v = 0;
	for(int i = N-1;i >= 0;i--){
		sum_v += v[i];
		cost_l_1[N-1-i] = sum_v - (C - x[i]);
		cost_l_2[N-1-i] = sum_v - (C - x[i]) * 2;
		ans = max(ans,sum_v - (C - x[i]));
	}

	for(int i = 0;i < N-1;i++){
		cost_r_1[i+1] = max(cost_r_1[i], cost_r_1[i+1]);
		cost_r_2[i+1] = max(cost_r_2[i], cost_r_2[i+1]);
		cost_l_1[i+1] = max(cost_l_1[i], cost_l_1[i+1]);
		cost_l_2[i+1] = max(cost_l_2[i], cost_l_2[i+1]);
	}

	/*for(int i = 0;i < N;i++){
		cout << cost_r_1[i] << endl;
	}
	cout << endl;

	for(int i = 0;i < N;i++){
		cout << cost_l_1[i] << endl;
	}
	cout << endl;*/

	//l[N-1] = r[0]
	//左2回,右1回と左1回,右2回の2通り.
	for(int i = 0;i < N - 1;i++){
		ans = max({ans, cost_l_1[i] + cost_r_2[N-2-i], cost_l_2[i] + cost_r_1[N-2-i]});
	}

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


Measured memory_bytes: 8004
class InputLine
  def self.to_s
    gets.chomp
  end

  def self.to_i
    InputLine.to_s.to_i
  end
  
  def self.to_f
    InputLine.to_s.to_f
  end

  def self.to_sa
    InputLine.to_s.split(' ')
  end

  def self.to_ia
    InputLine.to_sa.map(&:to_i)
  end
  
  def self.to_fa
    InputLine.to_sa.map(&:to_f)
  end
end

def main(argv)
  n = InputLine.to_i

  m = n / 2
  if n % 2 > 0 then
    m += 1
  end

  puts m.to_s
end

if self.to_s == 'main' then
  main(ARGV)
end

Measured memory_bytes: 1788
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define SIZE 130


int N,num_query;
int*** table;
int num_span[SIZE],length[SIZE],ok_LOC[SIZE];
char buf[100005];


int main(){

	scanf("%d %d",&N,&num_query);

	int index = 0;

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

		if(N%i == 0){

			num_span[index] = i; //区間の数
			length[index++] = N/i; //各区間の長さ
		}
	}

	num_span[index] = N;
	length[index++] = 1;


	table = new int**[index];

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

		table[i] = new int*[length[i]];

		for(int k = 0; k < length[i]; k++){

			table[i][k] = new int[26];
			for(int a = 0; a < 26; a++){
				table[i][k][a] = 0;
			}
		}
	}

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

		ok_LOC[i] = 0;
	}

	scanf("%s",buf);

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

		for(int k = 0; k < index; k++){

			table[k][i%length[k]][buf[i]-'a']++;
			if(table[k][i%length[k]][buf[i]-'a'] == num_span[k]){

				ok_LOC[k]++;
			}
		}
	}

	int loc;
	char ch[2],pre;

	for(int loop = 0; loop < num_query; loop++){

		scanf("%d %c",&loc,ch);
		loc--;

		pre = buf[loc];
		buf[loc] = ch[0];

		int minimum = N;

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

			if(table[i][loc%(length[i])][pre-'a'] == num_span[i]){

				ok_LOC[i]--;
			}
			table[i][loc%(length[i])][pre-'a']--;
			table[i][loc%(length[i])][ch[0]-'a']++;

			if(table[i][loc%(length[i])][ch[0]-'a'] == num_span[i]){

				ok_LOC[i]++;
			}

			if(ok_LOC[i] == length[i]){

				minimum = min(minimum,length[i]);
			}
		}

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

	return 0;
}



Measured memory_bytes: 34056
#include <cstdio>

int main()
{
        int w, n;
        int lot[30][30];
        int goal[30];

        scanf("%d", &w);
        scanf("%d", &n);
        for (int i = 0; i < n; i++) {
                for (int j = 0; j < w; j++) {
                        lot[i][j] = -1;
                }
        }
        int a, b;
        for (int i = 0; i < n; i++) {
                scanf("%d,%d", &a, &b);
                lot[i][a - 1] = b - 1;
                lot[i][b - 1] = a - 1;
        }
        for (int i = 0; i < w; i++) {
                int cur = i;
                for (int j = 0; j < n; j++) {
                        if (lot[j][cur] >= 0) {
                                cur = lot[j][cur];
                        }
                }
                goal[cur] = i + 1;
        }
        for (int i = 0; i < w; i++) {
                printf("%d\n", goal[i]);
        }

        return 0;
}

Measured memory_bytes: 2604
import sys
input = lambda: sys.stdin.readline()[:-1]

from collections import defaultdict

sys.setrecursionlimit(10 ** 7)


def dfs(v, parent, d):
    depth[v] = d
    for to, cost in tree[v]:
        if to == parent:
            continue
        dfs(to, v, d + cost)


depth = defaultdict(int)
tree = defaultdict(list)
n = int(input())
for i in range(n - 1):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    tree[a].append((b, c))
    tree[b].append((a, c))

q, k = map(int, input().split())
k -= 1

dfs(k, -1, 0)
for i in range(q):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    print(depth[x] + depth[y])


Measured memory_bytes: 142776
#include <iostream>
#include <cstdio>
#include <stdlib.h>
using namespace std;
void priNo()
{
    cout << "NO" << endl;
    exit(0);
}
int main()
{
    int n,x,a = 0,b = 0;
    cin >> n;
    for (int i = 0;i < n;i++)
    {
        scanf("%d",&x);
        if (x&1) a++; else b++;
    }
    if (a&1) priNo();
    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 256
import scala.math._

object Main {
  val sc = new java.util.Scanner(System.in)
  def main(args: Array[String]) {
    while(true) {
      val n = sc.nextInt()
      if(n == 0) {
        return
      }

      val c = new Array[Int](10)
      for(_ <- 1 to n) {
        c(sc.nextInt()) += 1
      }
      c.map{
        case 0 => "-"
        case x => "*" * x
      }.foreach(println)
    }
  }
}

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

int main() {
  int N, M;
  cin >> N >> M;
  int answer = 0;
  vector<int> A(M);

  for (int i = 0; i < M; i++) {
    cin >> A.at(i);
    answer+= A.at(i);
  }
  if (N >= answer){
  cout << N - answer << endl;
  }
  else {
  cout << "-1" << endl;
  }
  
}


Measured memory_bytes: 3664
# coding: utf-8

a, b, k = list(map(int, input().split(" ")))

if a <= k:
    a_after = 0
    k_after = k - a
    b_after = b - k_after if b >= k_after else 0
else:
    a_after = a - k
    b_after = b

print("{} {}".format(a_after, b_after))


Measured memory_bytes: 9152
k=int(input())
a=list(map(int,input().split()))
m=2
M=2
for i in range(k-1,-1,-1):
    x=a[i]
    r=M//x
    l=(m-1)//x
    if r-l<1:
        print(-1)
        exit()
    m=(m+x-1)//x*x
    M=M//x*x+x-1
print(m,M)


Measured memory_bytes: 63856
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORD(i,a,b) for (int i = (a); i >= (b); i--)
#define REP(i,a) FOR(i,0,(int)(a)-1)
#define reset(a,b) memset(a,b,sizeof(a))
#define BUG(x) cout << #x << " = " << x << endl
#define mod 1000000009
#define pi acos(-1)
#define eps 0.00000001
#define pb push_back
#define sqr(x) (x) * (x)
#define _1 first
#define _2 second

int n, lis[111], s, m , p , x;

int main() {
  // ios::sync_with_stdio(false);
  cin >> n;
  FOR (i, 1, n) {
    cin >> lis[i];
    s += lis[i];
  }
  cin >> m;
  while (m--) {
    cin >> p >> x;
    cout << s - lis[p] + x << endl;
  }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define LEN 100005
  
typedef struct pp{
  char name[100];
  int t;
}P;
  
P Q[LEN+1];
int head, tail, n;
  
void enqueue(P x){
     Q[tail] = x;
     if(tail == LEN - 1){
       tail = 0;
     } else {
       tail++;
     }
}     
  
P dequeue(){
     P tmp = Q[head];
     if(head == LEN - 1){
       head = 0;
     } else {
       head++;
     }
return tmp;
}
  
  
int main(){
  int elaps = 0;
  int i, q;

  scanf("%d %d", &n, &q);
  
  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
   
  tail = n+1;
  head = 1;
  
  while(tail != head){    
    if(Q[head].t > q){
      elaps += q;
      Q[head].t -= q; 
      enqueue(dequeue());
  
    } else {
      elaps += Q[head].t;
      dequeue();
      printf("%s %d\n", Q[head-1].name, elaps);
    }
  }
    
  return 0;
}

Measured memory_bytes: 10756
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    String N=sc.next();
    String n[] =N.split("",0);
    int m=N.length();
    int M=m/2;
    for(int i=0;i<M;i++){
      if(!(n[i].equals(n[m-1-i]))){System.out.println("No");System.exit(0);}
      if(!(n[i].equals(n[M+1+i]))){System.out.println("No");System.exit(0);}}
    int X=M/2;
    for(int j=0;j<X;j++){
      if(!(n[j].equals(n[M-1-j]))){System.out.println("No");System.exit(0);}}
    System.out.println("Yes");
  }
}

Measured memory_bytes: 25044
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
	ios_base::sync_with_stdio(NULL);
	cin.tie(NULL);
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	ll count = ((b/c)-(a-1)/c) + ((b/d)-(a-1)/d);
	ll lcm = d*(c/(__gcd(c,d)));
	count -= ((b/lcm)-(a-1)/lcm);
	cout<<(b-a+1-count);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int inf = 1e9;
double pi = 3.14159265359;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, b, a) for (int i = a - 1; i >= b; i--)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

int main() {
    int h, w, n;
    cin >> h >> w >> n;
    int grid[h][w], a[n];
    rep (i, 0, n) cin >> a[i];
    int nowh = 0, noww = 0;
    rep (i, 0, n) {
        while (a[i]--) {
            if (nowh % 2 == 0) {
                grid[nowh][noww++] = i + 1;
                if (noww == w) {
                    nowh++;
                    noww--;
                }
            } else {
                grid[nowh][noww--] = i + 1;
                if (noww == -1) {
                    nowh++;
                    noww++;
                }
            }
        }
    }
    rep (i, 0, h) {
        rep (j, 0, w) cout << grid[i][j] << " ";
        cout << "\n";
    }
}


Measured memory_bytes: 384
require 'set'

loop do
  n = gets.chomp.to_i
  row_count = gets.chomp.to_i

  break if n == 0 && row_count == 0
  
  graph = Hash.new { |h, k| h[k] = [] }

  row_count.times do
    pair = gets.chomp.split(' ')
    graph[pair[0]] << pair[1]
    graph[pair[1]] << pair[0]
  end

  friends = graph['1']
  foaf = Set.new

  friends.each do |f|
    graph[f].each do |of|
      foaf.add(of) if of != '1'
    end
  end

  puts (friends | foaf.to_a).size
end

Measured memory_bytes: 9920
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

void print() {
    cout << endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail) != 0) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
void print(vector<T> &vec) {
    for (auto& a : vec) {
        cout << a;
        if (&a != &vec.back()) cout << ' ';
    }
    cout << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
    for (auto& vec : df) {
        print(vec);
    }
}



void dfs(int x,vector<vector<ll>> &graph, vector<ll> &vec, int count = 0){
    vec[x] = count;
    for(auto next : graph[x]){
        if(vec[next] == INT_MAX) dfs(next, graph, vec, count+1);
    }
}

int main(){
    int n; cin >> n;
    vector<vector<ll>> gr(n, vector<ll>());
    vector<ll> rank_f(n, INT_MAX);
    vector<ll> rank_s(n, INT_MAX);
    rep(i,n-1){
        ll a,b; cin >> a >> b;
        a--;b--;
        gr[a].push_back(b);
        gr[b].push_back(a);
    }
    dfs(0, gr, rank_f);
    dfs(n-1, gr, rank_s);

    ll scnt = 0;
    ll fcnt = 0;
    rep(i,n){
        // if(rank_f[i] == rank_s[i])continue;
        if(rank_f[i] > rank_s[i])scnt++;
        else fcnt++;
    }

    // print(rank_f);
    // print(rank_s);

    cout << (fcnt > scnt ? "Fennec" : "Snuke") << endl;
    return 0;

}

Measured memory_bytes: 12032
n = int(input())
d,x = [int(t) for t in input().split()]
a = []
for i in range(n):
  a.append(int(input()))
res = 0
for i in range(n):
  c = a[i]
  res += 1
  while c < d:
    res += 1
    c += a[i]
res += x
print(res)

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

int main(){
    int n; cin >> n;
    int a[n]; rep(i,n) cin >> a[i];
    int s[n]; rep(i,n) s[i] = 0;
    rep(i,n){
        s[a[i]-1] = i + 1; 
    }
    rep(i,n){ 
        if (i) cout << " " << s[i];
        else cout << s[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
#define inf 1000000007
using namespace std;
int main(){
long long int a,b,c,d,n;
cin >> n;
  if(n==1){cout << 0;return 0;}
long long int i=0,ans1  =1,ans2=1,ans3=1;
for(i=0;i<n;i++){
	ans1 = ans1*10;
  	ans1 = ans1%inf;
    ans2 = ans2*8;
  	ans2 = ans2%inf;
  	ans3 = ans3*9;
  	ans3 = ans3%inf;
}
cout << (((ans1 + ans2)%inf - 2*ans3)%inf +inf )%inf;
}

Measured memory_bytes: 3620
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    static int n;
    static int[] num;

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        n = Integer.parseInt(br.readLine());
        String[] strs = br.readLine().split("\\s+");
        num = new int[n];
        for (int i=0; i<n; i++){
            num[i] = Integer.parseInt(strs[i]);
        }

        int q = Integer.parseInt(br.readLine());
        strs = br.readLine().split("\\s+");
        for (int i=0; i<q; i++){
            if (solve(0, Integer.parseInt(strs[i]))){
                System.out.println("yes");
            }
            else {
                System.out.println("no");
            }
        }
    }

    private static boolean solve(int i, int m) {
        if (m == 0){
            return true;
        }
        if (i >= n){
            return false;
        }

        boolean res = solve(i+1, m) || solve(i+1, m-num[i]);
        return res;
    }
}

Measured memory_bytes: 25056
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include<limits.h>

bool contain(char *s, int start, int end, char c){
	for(int i=start; i<=end; i++){
		if(s[i] == c) return true;
	}
	return false;
}

int both(char *s, int dev, int n){
	int ans = 0;
	for(int i=0; i<26; i++){
		if(contain(s, 0, dev, 'a' + i) && contain(s, dev+1, n-1, 'a' + i)) ans++;
	}
	return ans;
}

int main(){
	int n;
	char s[101];
	int ans = 0;
	int tmp;
	scanf("%d\n", &n);
	scanf("%s\n", s);
	for(int i= 0; i< n; i++){
		tmp = both(s, i, n);
		if(tmp > ans) ans = tmp;
	}
	printf("%d\n", ans);
	return 0;
}




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

#define LL long long

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    
    LL n, a, b, c, d, diff; cin >> n >> a >> b >> c >> d;
    diff = b - a;

    n--;
    for(LL i = 0; i <= n; i++) {
        if(diff <= (n-i) * d - i * c && diff >= (n-i) * c - i * d) {
            return cout << "YES", 0;
        }
    }    
    cout << "NO";
}

Measured memory_bytes: 3632
import sys
from collections import deque

input = sys.stdin.readline

n, q = map(int, input().split())
path = [[] for _ in range(n + 1)]
for i in range(n - 1):
    a, b = map(int, input().split())
    path[a].append(b)
    path[b].append(a)

ans = [0] * (n + 1)

for i in range(q):
    p, x = map(int, input().split())
    ans[p] += x

alr = [0] * (n + 1)
alr[1] = 1

que = deque([[1, 0]])
while len(que) > 0:
    now = que.popleft()
    ans[now[0]] += now[1]
    for j in path[now[0]]:
        if alr[j] == 0:
            que.append([j, ans[now[0]]])
            alr[j] = 1

for i in range(1, n + 1):
    print(ans[i], end=' ')
print()


Measured memory_bytes: 106444
N,M = map(int,input().split())
from collections import deque
g = [[] for _ in range(N)]
for _ in range(M):
    a,b = map(int,input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)

dist = [float('inf')]*(N)
ans = [0]*N
dist[0] = 0
q = deque([])
q.append((0,0))
while q:
    idx,d = q.popleft()
    for nxt in g[idx]:
        if d + 1 < dist[nxt]:
            ans[nxt] = idx+1
            dist[nxt] = d+1
            q.append((nxt,d+1))
for i in range(N):
    if dist[i]==float('inf'):
        print('No');exit()
print('Yes')
for i in range(1,N):
    print(ans[i])


Measured memory_bytes: 99072
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {


        Scanner sc = new Scanner(System.in);
        int p = Integer.parseInt(sc.next());
        int q = Integer.parseInt(sc.next());
        int r = Integer.parseInt(sc.next());
        int min = 1000;

        if (p + q < 1000) {
            min = p + q;
        }
        if (p + r < min) {
            min = p + r;
        }
        if (q + r < min) {
            min = q + r;
        }
        System.out.println(min);
    }
}

Measured memory_bytes: 25300
#include <bits/stdc++.h>
#define inf (1<<29)
#define sq(n) ((n)*(n))
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define MEMSET(a) memset(a,0,sizeof(a))
using namespace std;

using ll=long long;
const int limit=100010;
using edge=struct{int to;ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v,int p,ll d){
	depth[v]=d;
	for(auto &e:tree[v]){
		if(e.to==p)continue;
		dfs(e.to,v,d+e.cost);
	}
}

int main(){
	int n;
	cin>>n;
	rep(i,n-1){
		int a,b,c;
		cin>>a>>b>>c;
		a--;b--;
		tree[a].push_back({b,c});
		tree[b].push_back({a,c});
	}
	int q,k;
	cin>>q>>k;
	k--;
	dfs(k,-1,0);
	rep(i,q){
		int x,y;
		cin>>x>>y;
		x--;y--;
		cout<<depth[x]+depth[y]<<endl;
	}
	return 0;
}

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

using namespace std;

#define int long long

int sum(int x) {
    int ans = 0;
    while (x > 0) {
        ans += x % 10;
        x /= 10;
    }
    return ans;
}

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

    int n;
    cin >> n;
    int deg = 1, len = 1;
    while (deg * 10 <= n) {
        deg *= 10;
        ++len;
    }
    int ans = 9 * (len - 1) + n / deg - 1;
    ans = max(ans, sum(n));
    cout << ans << '\n';

}


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

typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,a,b) for(int i=a;i<(b);i++)
#define vi vector<int>
#define vii vector< vector<int> >

int main() {
    int max = 160;
    vi frag(max);
    rep(i, max) frag[i] = i*i;

    int n, d;
    cin >> n >> d;
    vii x(n, vi(d));
    rep(i, n){
        rep(j, d){
            cin >> x[i][j];
        }
    }
    int result = 0;
    rep(i, n-1){
        REP(j, i+1, n){
            int distance = 0;
            rep(k, d){
                distance = distance + (x[i][k]-x[j][k]) * (x[i][k]-x[j][k]);
            }
            rep(k, max){
                if(distance == frag[k]) result++;
            }
        }
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256