akhauriyash/Code-Regression huggingface dataset:
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 1
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"

def UnionFind(n):
    a = n
    while a != groups[a]:
        a = groups[a]
    groups[n] = a
    return a

n,m = I()
groups = [x for x in range(n)]
count = [0]*n

for _ in range(m):
    x,y = I()
    x,y = UnionFind(x-1), UnionFind(y-1)
    if x != y:
        groups[y] = x

for i in range(n):
    count[UnionFind(i)] += 1

print(max(count))

Measured memory_bytes: 19912
#include <cstdio>
bool  d[101];
int main(int argc, const char * argv[]) {
   
    int n,ans = 0;
    
    scanf("%d",&n);
    for(int i=0,t;i<n;i++){
        scanf("%d",&t);
        if(!d[t]){
            d[t]=true;
            ans++;
        }
    }
    
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;
using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;
const int INF=1<<30,MOD=1000000007;const ll LINF=1ll<<60;
#define _ol3(_1,_2,_3,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,v) REP(i,v.size())
#define all(v) (v).begin(),(v).end()
#define bit(n) (1ll<<(n))
#define clamp(n,mi,ma) max(min(n,ma),mi)
#define uniq(v) sort(all(v));v.erase(unique(all(v)),v.end())
#define pb push_back
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b) cout<<((n)?a:b)<<endl
#define YES(n) cho(n,"YES","NO")
#define Yes(n) cho(n,"Yes","No")
#define Poss(n) cho(n,"Possible","Impossible")
template<class T>bool chmax(T&a,const T&b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T&a,const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>ostream&operator<<(ostream&o,const vector<T>&v){for(const T&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>ostream&operator<<(ostream&o,const set<T>&v){for(const T&i:v)o<<i<<' ';return o;}
template<class T>ostream&operator<(ostream&o,const T&t){return o<<t;}
template<class T>istream&operator>(istream&i,T&t){return i>>t;}
#ifndef LOCAL
struct ostdmy{
template<class T>ostdmy&operator<<(const T&t){return*this;}
template<class T>ostdmy&operator<(const T&t){return*this;}};ostdmy cer_;
#define cerr cer_
#endif
int mnh(const P&a,const P&b){return abs(a.F-b.F)+abs(a.S-b.S);}
int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    int n;
    cin>n;
    vector<pair<P,int>> s;
    set<P> z;
    REP(i,n){
        int x,y,h;
        cin>x>y>h;
        if(h)
            s.push_back({{x,y},h});
        else
            z.insert({x,y});
    }
    REP(x,101){
        REP(y,101){
            int h=s[0].S+mnh(s[0].F, {x,y});
            bool flag=true;
            REPA(i,s){
                if(s[i].S+mnh(s[i].F, {x,y})!=h){
                    flag=false;
                    break;
                }
            }
            if(!flag)continue;
            for(P a:z){
                if(mnh(a, {x,y})<h){
                    flag=false;
                    break;
                }
            }
            if(flag){
                cout<<x<<' '<<y<<' '<<h<<endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
s = int(input())
arr = []
set_num = {s}

for i in range(2,1000000):        
    if s % 2 == 0:
        s = s / 2
    else:
        s = 3 * s + 1
    if s in set_num:
        print(i)
        break
    else:
        set_num.add(s)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    int ej=0;
    cin>>n;
    vector<int> value1,value2;
    for(int i=0;i<n;i++)
    {
        int m;
        cin>>m;
        value1.push_back(m);
    }
    value2=value1;
    sort(value1.begin(),value1.end());
    for(int i=0;i<n;i++)
    {
        if(value1[i]!=value2[i])
        {
            ej++;
        }
    }

    if(ej<=2)
    {
        cout<<"YES"<<endl;
    }
    else
    {
        cout<<"NO"<<endl;
    }


}

Measured memory_bytes: 256
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    while(true) {
      int n = sc.nextInt();
      if (n == 0) {
        break;
      }
      int sum = 0;
      while(true) {
        if (n == 0) {
          break;
        }
        n /= 5;
        sum += n;
      }
      System.out.println(sum);
    }
  }
}

Measured memory_bytes: 12000
#include <iostream>
#include <string>
#include <algorithm>
#include <cassert>
#include <limits>
#include <numeric>
#include <type_traits>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <complex>
#include <climits>
#include <queue>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<ll, ll> P;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)

const double PI = 3.1415926535897932;
/******define variable start******/
string s, t;
/*******define variable end*******/
ll solve(){
    cin >> s >> t;
    cout << t << s << endl;
    return 0;
}
int main(){

    //clock_t start = clock();
    cout << std::fixed << std::setprecision(10);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll end_solve = solve();
    /*
    clock_t end = clock();
    const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
    printf("time %lf[ms]\n", time);
    */
    return (int)end_solve;
}


Measured memory_bytes: 256
N = int(input())
s = list(map(int,input().split()))

ans = 0
for c in range(1,N-1):
    ltor = [0]
    for p in s[::c]:
        ltor.append(ltor[-1] + p)
    rtol = [0]
    for p in s[N-1::-c]:
        rtol.append(rtol[-1] + p)
    A = N-1-c
    while c < A:
        if A % c == 0 and A + c * (A//c-1) < N-1:
            break
        ind = (N-1-A)//c+1
        temp = ltor[ind] + rtol[ind]
        ans = max(temp,ans)
        A -= c

print(ans)



Measured memory_bytes: 69392
#include <iostream> 
using namespace std;
int main(){
  string S ;
  cin>>S;
string arr[]={"MON","TUE","WED","THU","FRI","SAT","SUN"};
int index,place;
for (int i=0; i<7;i++){
     if ("SUN"== arr[i]){
         index = i;
         break;
     }
}   
    for(int i=0;i<7;i++){
      if(S==arr[i]){
        place=i;
        break;
      }
    }
      if(place==index){
        cout<<7;
      }
      else{
        cout<<index-place;
      } 

return 0; 
}



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

int main()
{
  int a,b;
  cin >> a >> b;
  int w1 = min(a,b);
  int w2 = max(a,b);

  int ans;
  if((w1 == 1) && (w2 == 2)){
    ans = 3;
  }else if((w1 == 1) && (w2 == 3)){
    ans = 2;
  }else{
    ans = 1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,c,i,j,ct=0,jd;
  cin >>n>>m>>c;
  vector<int> bdata(m);
  vector<vector<int> > adata(n, vector<int>(m));
  for(i=0;i<m;i++){
    cin>>bdata.at(i);
  }
  for(i=0;i<n;i++){
    for(j=0;j<m;j++){
      cin>>adata.at(i).at(j);
    }
  }

  jd=c;
  for(i=0;i<n;i++){
    for(j=0;j<m;j++){
      jd+=adata.at(i).at(j)*bdata.at(j);
    }
    if(jd>0){
      ct++;
    }
    jd=c;
  }

  cout<<ct<<endl;

  return 0;
}


Measured memory_bytes: 256
w,h,n=map(int,input().split())
w0,h0=0,0
for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        if w0<x:
            w0=x
    elif a==2:
        if w>x:
            w=x
    elif a==3:
        if h0<y:
            h0=y
    elif a==4:
        if h>y:
            h=y
    if w-w0 <0 or h-h0<0:
        print(0)
        exit()
print((w-w0)*(h-h0) if (w-w0)*(h-h0)>0 else 0 )

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef long long ll;
const int inf=1e9;
const double PI=acos(-1);
const double eps=1e-6;
const int mod=1e9+7;
const int maxn=1e5+10;
ll a[66],n;
int c[66];
int main(){
	//ios::sync_with_stdio(false);
	//freopen("in","r",stdin);
	cin>>n;
	for(int i=1;i<=5;i++){
		cin>>a[i];
	}
	ll ans=0;
	for(int i=1;i<=5;i++){
		ans=max(ans,(n+a[i]-1)/a[i]);
	}
	cout<<ans+4<<endl;
	return 0;
}

Measured memory_bytes: 256
// Problem : D - Xor Sum 4
// Contest : AtCoder Beginner Contest 147
// URL : https://atcoder.jp/contests/abc147/tasks/abc147_d
// Memory Limit : 1024.000000 MB 
// Time Limit : 2000.000000 milisec 
// Powered by CP Editor (https://github.com/coder3101/cp-editor)

// writer: w33z8kqrqk8zzzx33
#include <bits/stdc++.h>
using namespace std;
 
#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define log(a) cerr<<"\033[32m[DEBUG] "<<#a<<'='<<(a)<<" @ line "<<__LINE__<<"\033[0m"<<endl
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
using ll=long long;
using pii=pair<int, int>;
//#define int ll
const int MOD = 1000000007;

ll cnt[70][2];

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int N; cin >> N;
    rep(i, N) {
        uint64_t v; cin >> v;
        rep(bi, 61) cnt[bi][(bool)(v & (1ull<<bi))]++;
    }
    ll cur = 1, ans = 0;
    rep(bi, 61) {
        ans = (ans + (cnt[bi][0]*cnt[bi][1]%MOD)*cur) % MOD;
        cur = cur*2%MOD;
    }
    cout << ans << endl;
}



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

using namespace std;

#define int long long
#define endl '\n'
#define maxn 100010
const int MOD = 1000000007;

void solve() {
    int n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;

    string s;
    cin >> s;

    s = " " + s;
    if (c < d) {
        while (b < d) {
            if (b + 1 <= d and s[b + 1] != '#')
                b++;
            else if (b + 2 <= d and s[b + 2] != '#')
                b += 2;
            else
                break;
        }
        if (b != d) {
            cout << "No";
            return;
        }
        while (a < c) {
            if (a + 1 <= c and s[a + 1] != '#')
                a++;
            else if (a + 2 <= c and s[a + 2] != '#')
                a += 2;
            else break;
        }
        if (a != c) {
            cout << "No";
            return;
        }
        cout << "Yes";
        return;
    } else {
        for (int i = b; i <= d; i++) {
            if (s[i] != '#' and i + 1 <= n and s[i + 1] == '.' and i - 1 > 0 and s[i - 1] == '.' and i - 1 != a) {
                cout << "Yes" << endl;
                return;
            }
        }
    }
    cout << "No";
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 720
a = list(map(int, input().split()))
A = list(map(int, input().split()))

N, M = a[0], a[1]

sum = sum(A)

c = 0

for i in range(N):
  if A[i] >= sum/4/M:
    c = c+1

if c >= M:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
  int h,w,n;
  cin >>h >>w >> n;
  if(h>=w){
    if(n%h==0)cout << n/h <<endl;
    else cout << n/h+1 <<endl;
  }
  else{
    if(n%w==0)cout << n/w <<endl;
    else cout << n/w+1 <<endl;
  }
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val aa = readLine()!!.split(" ").map { it.toInt() - 1 }
    val bb = readLine()!!.split(" ").map { it.toInt() }
    val cc = readLine()!!.split(" ").map { it.toInt() }
    var result = bb[aa[0]]
    var prevA = aa[0]

    for ( i in 1 until n) {
        result += bb[aa[i]] + if (aa[i] - prevA == 1) cc[prevA] else 0
        prevA = aa[i]
    }

    println(result)
}

Measured memory_bytes: 35960
#define _USE_MATH_DEFINES

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <utility>
#include <climits>
#include <vector>
#include <map>
#include <queue>
#include <set>
using namespace std;

#define ll long long
const int MOD = 1000000007;//10^9+7
const string SPACE = " ";

ll powsur(ll a, ll b, ll p) {

	if (b == 0) {

		return 1;

	}
	else if (b % 2 == 0) {

		ll d = powsur(a, b / 2, p);
		return ((d%p)*(d%p)) % p;

	}
	else {

		return ((a%p)*powsur(a, b - 1, p) % p) % p;

	}

}
//pは素数,aのb乗をpで割った余り

ll CMOD(ll n, ll r, ll p) {

	ll a = 1, b = 1, c = 1, re;
	for (int i = 1; i <= n; i++) {

		a *= i;
		a = a%p;

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

		b *= i;
		b = b%p;

	}
	for (int i = 1; i <= n - r; i++) {

		c *= i;
		c = c%p;

	}
	b = powsur(b, p - 2, p);
	c = powsur(c, p - 2, p);
	re = ((a%p)*(b%p)) % p;
	re = ((re%p)*c%p) % p;

	return re;

}
//pは素数,(nCr)%p

ll gcd(ll a, ll b) {

	if (a > b) {

		ll tmp = a;
		a = b;
		b = tmp;

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

}
//最大公約数

ll lcm(ll a, ll b) {

	return (a / gcd(a, b))*b;

}
//最小公倍数

ll MAX(ll a, ll b) {

	if (a > b)return a;
	else return b;

}
//MAX

ll MIN(ll a, ll b) {

	if (a < b)return a;
	else return b;

}
//MIN

bool p_judge(ll p) {

	if (p == 1)return false;
	else if (p == 2)return true;
	else {

		bool flag = true;
		for (int i = 2; i <= sqrt(p); i++) {

			if (p%i == 0) {

				flag = false;
				break;

			}

		}
		return flag;

	}

}
//素数判定,素数=true,合成数=false

ll func(int n) {

	ll a = 1;
	for (int i = 0; i < n; i++) {

		a *= 2;
		a %= MOD;

	}
	return a;

}

int main() {

	int N, A[100005], m[100005];

	for (int i = 0; i < 100005; i++)m[i] = 0;

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

		cin >> A[i];
		m[A[i]]++;

	}

	int cnt2 = 0, cnt134 = 0;
	for (int i = 1; i < 100005; i++) {

		if (m[i] == 2)cnt2++;
		else if (m[i] != 0)cnt134++;

	}

	//cout << cnt2 << endl << cnt134 << endl;

	if (cnt134 > 0)cout << 0 << endl;
	else {

		cout << func(cnt2) << endl;

	}

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
#define fastIO ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define endl '\n'
#define ll long long
ll mod = 1e9+7;
 
int main() {
    fastIO
    ll n,k;
    cin>>n>>k;
    ll a[n];
    for (ll int i = 0; i < n; ++i)
        cin>>a[i];
    ll dp[n+1][k+1],sum[n+1][k+1];
    for (ll int children = 0; children <= n; ++children)
    {
        for (ll int candies = 0; candies <= k; ++candies)
        {
            if(candies==0){
                dp[children][candies] = 1;
                sum[children][candies] = 1;
            }
            else if(children==0){
                dp[children][candies] = 0;
                sum[children][candies] = 1;
            }
            else{
                ll candiesRangeStart = candies - min(candies,a[children-1]);
                dp[children][candies] = sum[children-1][candies] - sum[children-1][candiesRangeStart]+mod;
                dp[children][candies] = (dp[children][candies] + dp[children-1][candiesRangeStart]) % mod;
                sum[children][candies] = (dp[children][candies] + sum[children][candies-1]) % mod;
            }
        }
    }
    cout << dp[n][k] << endl;
}

Measured memory_bytes: 158080
from collections import Counter


class UnionFind:
    def __init__(self, size):
        self.data = [-1] * size

    def find(self, x):
        if self.data[x] < 0:
            return x
        else:
            self.data[x] = self.find(self.data[x])
            return self.data[x]

    def union(self, x, y):
        x, y = self.find(x), self.find(y)
        if x != y:
            if self.data[y] < self.data[x]:
                x, y = y, x
            self.data[x] += self.data[y]
            self.data[y] = x
        return (x != y)

    def same(self, x, y):
        return (self.find(x) == self.find(y))

    def size(self, x):
        return -self.data[self.find(x)]


def main():
    MAX = 10 ** 5 + 1
    uf = UnionFind(2 * MAX)

    N, *XY = map(int, open(0).read().split())

    for x, y in zip(*[iter(XY)] * 2):
        uf.union(x, y + MAX)

    X = Counter(uf.find(i) for i in range(MAX))
    Y = Counter(uf.find(i) for i in range(MAX, MAX * 2))
    res = sum(X[i] * Y[i] for i in range(MAX * 2))

    print(res - N)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38580
N, K = list(map(int, input().split()))
P = list(map(lambda x: int(x) - 1, input().split()))
C = list(map(int, input().split()))
ans = -10**9-1
for i in range(N):
    cumsum = [0]*(N+1)
    seen = [-1]*N
    K_ = K
    now = i
    j = 0
    while K_ > 0 and seen[now] == -1:
        seen[now] = 1
        now = P[now]
        cumsum[j+1] = cumsum[j] + C[now]
        K_ -= 1
        j += 1
    if K_ == 0:
        ans = max(ans, max(cumsum[1:j+1]))
    else:
        if cumsum[j] > 0:
            loop_size = j
            loop_n = K//loop_size - 1
            tmp = loop_n*cumsum[loop_size]
            tmp += max(max(cumsum[1:loop_size+1]), cumsum[loop_size] + max(cumsum[0:K_%loop_size+1]))
            ans = max(ans, tmp)
        else:
            ans = max(ans, max(cumsum[1:j+1]))
print(ans)

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

int main() {
    int x; cin >> x;
    if (x == 7 || x == 5 || x == 3)
    {
        cout << "YES\n";
        return 0;
    }
    cout << "NO\n";
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int solve(int, int);
#define N 2000
int A[N],S[N],n;

int main(){

  int q,i,j,m;

  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);
  scanf("%d",&q);
  for(i=0;i<q;i++) scanf("%d",&S[i]);

  for(i=0,j=0;i<q;i++){
    if(solve(j,S[i])==0) printf("no\n");
    else printf("yes\n");
     }
  return 0;
}

int solve(int i , int m){

  int res;

  if(m==0) return 1;
  if(i>=n) return 0;

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

Measured memory_bytes: 584
// Try AtCoder
// author: Leonardone @ NEETSDKASU

fn main() {
	let mut stdin = String::new();
    std::io::Read::read_to_string(
    	&mut std::io::stdin(),
        &mut stdin).unwrap();
	let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
    	($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
	}
    let _f = 5_000_000_000_000_000;
    let s = get().as_bytes();
    let k = get!(usize);
    let mut ans = b'1';
    for i in 0..s.len() {
    	if s[i] != b'1' {
        	ans = s[i];
            break;
        }
        if i + 1 == k {
        	ans = s[i];
            break;
        }
    }
    
    println!("{}", ans as char);
}

Measured memory_bytes: 4352
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<list>
#include <cstring>
#include <functional>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF ((Int)1<<60)
#define EPS (1e-10)
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define RREP(i,n) for(int i=1; i<=(int)(n); ++i)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
typedef long long Int;
typedef pair<Int, Int> PI;
typedef pair<int, int> P;
typedef vector<double> vec;
typedef vector<vec> mat;
const int N = 100005;
//////////////////////////////

int n, m;
int q;
vector<int> edge[108000];
int query[11][108000];
int a, b, v, d;
int c[108000];

void solve()
{
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> a >> b;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}
	cin >> q;
	for (int i = 1; i <= q; i++) {
		cin >> v >> d >> c[i];
		query[d][v] = i;
	}
	for (int d = 10; d >= 1; d--) {
		for (int i = 1; i <= n; i++) {
			query[d - 1][i] = max(query[d - 1][i], query[d][i]);
			for (auto to : edge[i]) {
				query[d - 1][to] = max(query[d - 1][to], query[d][i]);
			}
		}
	}
	for (int i = 1; i <= n; i++) {
		cout << c[query[0][i]] << endl;
	}	
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(13);
	solve();
	return 0;
}


Measured memory_bytes: 13992
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    StringBuilder sb = new StringBuilder();
    String[] str = sc.nextLine().split("");
    String p = sc.nextLine();
    for(int i = 0; i < str.length; i++) {
      sb.setLength(0);
      for(int j = i; j < i + str.length; j++) {
        int a = j;
        if(a >= str.length) {
          a -= str.length;
        }
        sb.append(str[a]);
      }
      String s = sb.toString();
      if(s.contains(p)) {
        System.out.println("Yes");
        break;
      } else if(i == str.length - 1) {
        System.out.println("No");
      }
    }
  }
}



Measured memory_bytes: 26920
//⣿⣿⣿⣿⣿⣿⠟⠋⠁⣀⣤⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⢿⣿⣿
//⣿⣿⣿⣿⠋⠁⠀⠀⠺⠿⢿⣿⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⠻⣿
//⣿⣿⡟⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣤⣤⣤⣤⠀⠀⠀⠀⠀⣤⣦⣄⠀⠀
//⣿⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣤⣶⣿⠏⣿⣿⣿⣿⣿⣁⠀⠀⠀⠛⠙⠛⠋⠀⠀
//⡿⠀⠀⠀⠀⠀⠀⠀⠀⡀⠀⣰⣿⣿⣿⣿⡄⠘⣿⣿⣿⣿⣷⠄⠀⠀⠀⠀⠀⠀⠀⠀
//⡇⠀⠀⠀⠀⠀⠀⠀⠸⠇⣼⣿⣿⣿⣿⣿⣷⣄⠘⢿⣿⣿⣿⣅⠀⠀⠀⠀⠀⠀⠀⠀
//⠁⠀⠀⠀⣴⣿⠀⣐⣣⣸⣿⣿⣿⣿⣿⠟⠛⠛⠀⠌⠻⣿⣿⣿⡄⠀⠀⠀⠀⠀⠀⠀
//⠀⠀⠀⣶⣮⣽⣰⣿⡿⢿⣿⣿⣿⣿⣿⡀⢿⣤⠄⢠⣄⢹⣿⣿⣿⡆⠀⠀⠀⠀⠀⠀
//⠀⠀⠀⣿⣿⣿⣿⣿⡘⣿⣿⣿⣿⣿⣿⠿⣶⣶⣾⣿⣿⡆⢻⣿⣿⠃⢠⠖⠛⣛⣷⠀
//⠀⠀⢸⣿⣿⣿⣿⣿⣿⣾⣿⣿⣿⣿⣿⣿⣮⣝⡻⠿⠿⢃⣄⣭⡟⢀⡎⣰⡶⣪⣿⠀
//⠀⠀⠘⣿⣿⣿⠟⣛⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣿⣿⣿⡿⢁⣾⣿⢿⣿⣿⠏⠀
//⠀⠀⠀⣻⣿⡟⠘⠿⠿⠎⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣵⣿⣿⠧⣷⠟⠁⠀⠀
//⡇⠀⠀⢹⣿⡧⠀⡀⠀⣀⠀⠹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠋⢰⣿⠀⠀⠀⠀
//⡇⠀⠀⠀⢻⢰⣿⣶⣿⡿⠿⢂⣿⣿⣿⣿⣿⣿⣿⢿⣻⣿⣿⣿⡏⠀⠀⠁⠀⠀⠀⠀
//⣷⠀⠀⠀⠀⠈⠿⠟⣁⣴⣾⣿⣿⠿⠿⣛⣋⣥⣶⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⣿⡀ 
//
//⣿⠛⣷⠀⠀⢸⣟⡛⠀⠀⣿⠛⣷⠀⠀⢸⣟⡛⠀⠀⣴⢟⣛⡀⠀⠀⣸⢿⣇⠀ 
//⣿⠉⠉⠀⠀⢸⣯⣥⠀⠀⣿⠉⠉⠀⠀⢸⣯⣥⠀⠀⢿⣮⣽⡇⠀⢠⡿⠶⣿⡄ 
#include <bits/stdc++.h>
#define DEBUG false
#define debugf if (DEBUG) printf
#define MAXN 150001
#define MAXM 900009
#define MAXLOGN 20
#define ALFA 256
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3f
#define EPS 1e-9
#define PI 3.141592653589793238462643383279502884
#define FOR(x,n) for(int x=0; (x)<int(n); (x)++)
#define FOR1(x,n) for(int x=1; (x)<=int(n); (x)++)
#define REP(x,n) for(int x=int(n)-1; (x)>=0; (x)--)
#define REP1(x,n) for(int x=(n); (x)>0; (x)--)
#define pb push_back
#define pf push_front
#define pr printf
#define sc(x) scanf("%d", &x)
#define sc2(x, y) sc(x);sc(y)
#define sc3(x, y, z) sc2(x, y);sc(z)
#define scll(x) scanf("%lld", &x)
#define sc2ll(x, y) scll(x);scll(y)
#define sc3ll(x, y, z) sc2ll(x, y);scll(z)
#define ff first
#define ss second
#define mp make_pair
#define sz(x) int(x.size())
#define all(x) x.begin(), x.end()
#define mset(x,y) memset(&x, (y), sizeof(x))
#define LOWBIT(A) (A & -A)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef unsigned int uint;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair <ll, ll> pll;
typedef pair < pll, ll > plll;
int n;
double fat;
double resp;
vector < pair < double , int > > ladj[10];

void dfs(int node, int mask, double custo){
    int entrei = 0;
    for(pair < double, int > vizi : ladj[node]){
        if((1 << vizi.ss) & mask)continue;
        dfs(vizi.ss, mask | (1 << vizi.ss), custo + vizi.ff);
        entrei++;
    }
    if(entrei == 0)
        resp += custo / fat;
}

int main(){
    resp = 0;
    fat = 1;
    sc(n);
    FOR1(i, n)fat *= i;
    pair <double, double> bla[n + 1];
    FOR(i, n){
        double a, b;
        cin >> a >> b;
        bla[i] = {a, b};
    }
    FOR(i, n){
        FOR(j, n){
            if(i >= j)continue;
            double dist = pow(bla[i].ff - bla[j].ff, 2) + pow(bla[i].ss - bla[j].ss, 2);
            dist = sqrt(dist);
            ladj[i].push_back({dist, j});
            ladj[j].push_back({dist, i});
        }
    }
    FOR(i, n)dfs(i, (1 << i), 0);
    pr("%.16f\n", resp);
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        String s = sc.next();
        sc.close();

        // 主処理
        int result = solve(n, s);

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

    private static int solve(int n, String s) {
        if (!s.contains(".") || !s.contains("#")) {
            return 0;
        }
        int black = s.replaceAll("[^#]", "").length();
        int white = s.replaceAll("[^.]", "").length();
        int countReplace = Math.min(black, white);

        int[] countBlack = new int[n];
        int[] countWhite = new int[n];
        char[] c = s.toCharArray();
        int cb = 0;
        int cw = 0;
        for (int i = 0; i < n; i++) {
            if (c[i] == '#') {
                cb++;
            }
            countBlack[i] = cb;
            if (c[n - 1 - i] == '.') {
                cw++;
            }
            countWhite[n - 1 - i] = cw;
        }
        int count = n;
        for (int i = 0; i < n - 1; i++) {
            count = Math.min(count, countBlack[i] + countWhite[i + 1]);
        }

        return Math.min(countReplace, count);
    }
}


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

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());

			for (int i = 9; i > 0; i--)
			{
				if (n % i == 0)
				{
					if (n / i < 10)
					{
						Console.WriteLine("Yes");
						return;
					}

					else Console.WriteLine("No");
					return;
				}
			}

			Console.WriteLine("No");


		}
	}

}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    string S;
    cin >> S;
    string T;
    cin >> T;
    int len = S.size();
    bool ans = true;
    rep(i,len){
        if (S[i] != T[i]) ans = false;
    }
    if (ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3568
import java.util.Scanner;

/**
 *
 * @author cs18097
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String txt = sc.next();
        String arytxt[] = txt.split("");
        int count = 1; 
        for(int i = 0;i<arytxt.length-1;i++){
            if(!arytxt[i].equals(arytxt[i+1]))count++;
        }
        System.out.print(count);
    }
    
}


Measured memory_bytes: 34616
unittest
{
	assert( [ "7", "3 1 4 1 5 9 2" ].parse.expand.solve == 4 );
	assert( [ "10", "0 1 2 3 4 5 6 7 8 9" ].parse.expand.solve == 3 );
	assert( [ "1", "99999" ].parse.expand.solve == 1 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.strip.to!( long );
	input.popFront;
	auto as = input.front.split.to!( long[] );
	return tuple( as );
}

auto solve( long[] as )
{
	as.sort();
	as = -100 ~ as ~ -100;
	
	auto r = 0L;
	auto gs = as.group.array;
	foreach( i; 1 .. gs.length - 1 )
	{
		auto sa = gs[ i ][ 1 ];
		auto sb = ( gs[ i - 1 ][ 0 ] == gs[ i ][ 0 ] - 1 ) ? gs[ i - 1 ][ 1 ] : 0L;
		auto sc = ( gs[ i + 1 ][ 0 ] == gs[ i ][ 0 ] + 1 ) ? gs[ i + 1 ][ 1 ] : 0L;
		auto s = sa + sb + sc;
		if( r < s ) r = s;
	}
	
	return r;
}


Measured memory_bytes: 7356
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        var p = new Program();
        var input = p.ConvertIntArray(p.ReadInput());
        var K = input[0];
        var X = input[1];
        var min = X - (K - 1);
        var max = X + (K - 1);
        StringBuilder sb = new StringBuilder();
        for (var i = min; i <= max; i++)
        {
            sb.Append(i).Append(" ");
        }
        Console.WriteLine(sb.ToString());
    }


    public string[] ReadInput()
    {
        return Console.ReadLine().Split(' ');
    }

    public int[] ConvertIntArray(string[] x)
    {
        var convertedArray = new int[x.Length];
        for (var i = 0; i < x.Length; i++)
        {
            convertedArray[i] = int.Parse(x[i]);
        }

        return convertedArray;
    }
}



Measured memory_bytes: 13140
#include <iostream>

using namespace std;

int main(){
  int n;
  string s;
  std::cin >> n >> s;
  int ans = 0;
  for(int i=0; i<n-2; i++){
    if( 'A' == s[i] ){
      if( 'B' == s[i+1] ){
        if( 'C' == s[i+2] ){
          ans += 1;
        }
      }
    }
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<set>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define INF 1e8
using namespace std;
int n,m,k,a,b,c,alt,p,q,r;
long long cost[101][101],tm[101][101],d[101];
bool used[101];

void dfunc(int s,int r){
	rep(i,101){
		used[i]=true;
		d[i]=INF;
	}
	d[s]=0;
	while(1){
		int mem=INF,now=-1;
		rep(i,101){
			if(used[i] && mem>d[i]){
				now=i;
				mem=d[i];
			}
		}
		if(now==-1)break;
		used[now]=false;
		rep(i,101){
			if(r==0){
				if(cost[now][i]!=INF)d[i]=min(d[i],d[now]+cost[now][i]);
			}else{
				if(tm[now][i]!=INF)d[i]=min(d[i],d[now]+tm[now][i]);
			}
		}
	}
}

int main(){
	while(cin>>n>>m,n||m){
		rep(i,101)rep(j,101){
			cost[i][j]=INF;
			tm[i][j]=INF;
		}
		rep(i,n){
			cin>>a>>b>>c>>alt;
			a--;
			b--;
			cost[b][a]=cost[a][b]=c;
			tm[b][a]=tm[a][b]=alt;
		}
		cin>>k;
		rep(i,k){
			cin>>p>>q>>r;
			dfunc(p-1,r);
			cout<<d[q-1]<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1316
//In the Name of God
//Ya Ali

#include <bits/stdc++.h>

#define int long long

#define err(A) cout << #A << " = " << (A) << endl

using namespace std;

const int maxn = 404;

int n;

int a[maxn];

int p[maxn];

int dp[maxn][maxn];

int32_t main()
{
  memset(dp, 30, sizeof dp);
  
  ios::sync_with_stdio(0); cin.tie(0);

  cin >> n;

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

  for (int i = 0; i < n; i ++)
    p[i + 1] = p[i] + a[i];

  for (int i = 0; i < n; i ++)
    dp[i][i + 1] = 0;

  for (int j = 1; j <= n; j ++)
    for (int i = j - 2; i >= 0; i --)
      for (int k = i; k < j; k ++)
	dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j] + p[j] - p[i]);
  
  cout << dp[0][n] << endl;
  
  return 0;
}


Measured memory_bytes: 1536
n = input()
n_list = n.split(" ")
a = int(n_list[0])
b = int(n_list[1])
k = int(n_list[2])

if k < a:
    a = a-k
    b = b
    print(str(a) + " " + str(b))
elif k >= a and k-a < b:
    b = b - (k-a)
    print(str(0) + " " + str(b))
elif k >= a and k-a >= b:
    a = 0
    b = 0
    print(str(0) + " " + str(0))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int a,b,alpha;
double S,c,P,h;
int main()
{
    scanf("%d%d%d",&a,&b,&alpha);
    c=sqrt((double)a*a+(double)b*b-(double)2*a*b*cos((double)alpha/180*M_PI));
    P=a+b+c;
    S=(double)1/2*a*b*sin((double)alpha/180*M_PI);
    h=(double)S*2/a;
    printf("%f\n%f\n%f\n",S,P,h);
}



Measured memory_bytes: 3420
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L
#define PI 3.141592653589793238462643383279502884L

#define long long long int

using std::vector;
using std::map;
using std::set;
using std::string;
using std::pair;
using std::cin;
using std::cout;
using std::cerr;

// @author: pashka

void solve_test() {
    long a, b, c, d;
    cin >> a >> b >> c >> d;
    long aa = a < b ? a : b;
    long bb = a < b ? b : a;
    long L = (bb + aa) / (aa + 1);
//    cout << L << "\n";
    long l = 0;
    long r = (a + b + 1);
    while (r > l + 1) {
        long m = (l + r) / 2;
        bb = b - (m / (L + 1));
        aa = a - (m - (b - bb));
//        cout << m << " " << aa << " " << bb << "\n";
        long bbb = (aa + 1) * L;
        if (m % (L + 1) == 0) bbb--;
        if (bb <= bbb) {
            l = m;
        } else {
            r = m;
        }
    }
//    cout << l << "\n";
    string res = "";
    for (int i = c - 1; i < d; i++) {
        if (i < l) {
            res += (i % (L + 1) == L) ? 'B' : 'A';
        } else {
            res += ((a + b - i) % (L + 1) == 0) ? 'A' : 'B';
        }
    }
    cout << res << "\n";
}

int main() {
    std::ios::sync_with_stdio(false);

    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        solve_test();
    }

    return 0;
}

Measured memory_bytes: 384
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
# ----------------------------------------------------------- #

# 1, 2, 3, 4, 5, 6, 7, 8, 9, 19, 29, 39, 49, 59, 69, 79, 89, 99, 199, 299, 399, ... , 1999, 2999, ...

def f(n):
    return n/sum((int(x) for x in str(n)))

ANS = []
tmp = INF
for i in reversed(range(16)):
    for j in reversed(range(100, 1000)):
        x = int(str(j)+'9'*i)
        if f(x) <= tmp:
            ANS.append(x)
            tmp = f(x)

for x in reversed([1, 2, 3, 4, 5, 6, 7, 8, 9, 19, 29, 39, 49, 59, 69, 79, 89, 99]):
    ANS.append(x)

ANS.reverse()
# print(ANS)

k = I()
for i in range(k):
    print(ANS[i])


Measured memory_bytes: 71384
#include <iostream>
#include <cstdio>
#include <map>
#define F first
#define S second

using namespace std;

typedef long long ll;

ll h, w, n;
ll a[15];
map<pair<ll, ll>, ll> ma;

int main()
{
    scanf("%lld%lld%lld", &h, &w, &n);
    a[0] = (h - 2) * (w - 2);
    for(ll i = 0; i < n; i++)
    {
        ll x, y;
        scanf("%lld%lld", &x, &y);
        for(ll j = -2; j <= 0; j++)
        {
            for(ll k = -2; k <= 0; k++)
            {
                if(x + j < 1 || y + k < 1) continue;
                if(x + j + 2 > h || y + k + 2 > w) continue;
                ll t = ma[make_pair(x + j, y + k)]++;
                a[t]--;
                t++;
                a[t]++;
            }
        }
    }
    for(ll i = 0; i <= 9; i++)
    {
        printf("%lld\n", a[i]);
    }
    return 0;
}


Measured memory_bytes: 56448
from heapq import heappush, heappop
class MinCostFlow_by_Dijkstra:
    #Dijkstraによる最小費用流問題
    #(参考元:https://tjkendev.github.io/procon-library/python/min_cost_flow/primal-dual.html)
    INF = float("inf")

    def __init__(self, N):
        self.N = N
        self.G = [[] for i in range(N)]
        self.E=set()

    def add_edge(self, fr, to, cap, cost):
        forward = [to, cap, cost, None]
        backward = forward[3] = [fr, 0, -cost, forward]
        self.G[fr].append(forward)
        self.G[to].append(backward)
        self.E.add((fr,to))

    def flow(self, s, t, f,Mode=False):
        N = self.N; G = self.G
        INF = MinCostFlow_by_Dijkstra.INF

        res = 0
        H = [0]*N
        prv_v = [0]*N
        prv_e = [None]*N

        d0 = [INF]*N
        dist = [INF]*N

        while f:
            dist[:] = d0
            dist[s] = 0
            que = [(0, s)]

            while que:
                c, v = heappop(que)
                if dist[v] < c:
                    continue
                r0 = dist[v] + H[v]
                for e in G[v]:
                    w, cap, cost, _ = e
                    if cap > 0 and r0 + cost - H[w] < dist[w]:
                        dist[w] = r = r0 + cost - H[w]
                        prv_v[w] = v; prv_e[w] = e
                        heappush(que, (r, w))
            if dist[t] == INF:
                return None

            for i in range(N):
                H[i] += dist[i]

            d = f; v = t
            while v != s:
                d = min(d, prv_e[v][1])
                v = prv_v[v]
            f -= d
            res += d * H[t]
            v = t
            while v != s:
                e = prv_e[v]
                e[1] -= d
                e[3][1] += d
                v = prv_v[v]

        if Mode:
            R={}
            for v in range(self.N):
                R[v]={}
                for S in self.G[v]:
                    w=S[0]
                    if (v,w) in self.E:
                        R[v][w]=S[-1][1]

            return res,R
        else:
            return res
#================================================
N,K=map(int,input().split())
A=[[0]*N for _ in range(N)]

for i in range(N):
    A[i]=list(map(int,input().split()))

inf=float("inf")
huge=10**18

D=MinCostFlow_by_Dijkstra(2*N+2)
s=2*N
t=2*N+1

for i in range(N):
    D.add_edge(s,i,K,0)
    D.add_edge(N+i,t,K,0)
D.add_edge(s,t,N*K,huge)

for i in range(N):
    for j in range(N):
        D.add_edge(i,N+j,1,huge-A[i][j])

p,R=D.flow(s,t,N*K,True)
p=huge*N*K-p

S=[["."]*N for _ in range(N)]
for i in range(N):
    for j in range(N):
        if R[i][N+j]==1:
            S[i][j]="X"

T=["".join(a) for a in S]

print(p)
print("\n".join(T))

Measured memory_bytes: 74260
// lcmとかはg++ -std=c++17 default.cppみたいなかんじで
//vector<vector<ll>> piyo(tate,vector<ll> (yoko));

#include <bits/stdc++.h>
#define mod 1000000007
#define INF 1000000000
#define ll long long
#define ln cout<<endl;
#define Yes cout<<"Yes"<<endl;
#define No cout<<"No"<<endl;
#define double long double
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
using namespace std;

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

    ll maxi=0,f=0,mini=INF,sum=0;
    string str1,str2;
    ll h,w;
    ll n;
    ll a,b,c,d;
    cin>>str1;
    set<char> s;
    rep(i,str1.length()) s.insert(str1[i]);
    if(s.size()!=str1.length()) cout<<"no";
    else cout<<"yes";
    return 0;
}


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

#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

typedef long long LL;
typedef unsigned long long ULL;
template<typename T> using V = std::vector<T>;
template<typename T> using VV = std::vector<std::vector<T>>;
template<typename T> using VVV = std::vector<std::vector<std::vector<T>>>;
template<class T> inline T ceil(T a, T b) { return (a + b - 1) / b; }
template<class T> inline void print(T x) { std::cout << x << std::endl; }
template<class T> inline bool inside(T y, T x, T H, T W) {return 0 <= y and y < H and 0 <= x and x < W; }
inline double distance(double y1, double x1, double y2, double x2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }

const int INF = 1L << 30;
const double EPS = 1e-9;
const std::string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
const std::vector<int> dy = { 0, 1, 0, -1 }, dx = { 1, 0, -1, 0 };    // 4近傍（右, 下, 左, 上）

using namespace std;


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

    int N, M;
    cin >> N >> M;
    string S;
    cin >> S;


    vector<unsigned long long> powb(N + 10), shash(N + 10);
    unsigned long long b = 1000000007;

    powb[0] = 1;
    FOR(i, 0, N) {
        powb[i + 1] = powb[i] * b;
        shash[i + 1] = shash[i] * b + S[i];
    }

    set<unsigned long long> hash;
    int left = 0, right = 1;
    FOR(i, 0, M){
        string q;
        cin >> q;
        if      (q == "L++") { left++; }
        else if (q == "L--") { left--; }
        else if (q == "R++") { right++; }
        else if (q == "R--") { right--; }
        hash.insert(shash[right] - shash[left] * powb[right - left]);
    }

    print(hash.size());

    return 0;
}


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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int n, m, g, d;
string s[30];

bool reach() {
  int now = m;
  for (int i = 0; i < d; i++) {
    if (now - 1 >= 0 && s[i][now - 1] == '1') now--;
    else if (now + 1 < n && s[i][now] == '1') now++;
  }
  return now == g;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  while (cin >> n, n) {
    cin >> m >> g >> d;
    m--, g--;
    for (int i = 0; i < d; i++) {
      cin >> s[i];
    }
    if (reach()) {
      cout << "0" << endl;
      continue;
    }
    bool ok = false;
    for (int i = 0; i < d; i++) {
      for (int j = 0; !ok && j < n - 1; j++) {
        if (s[i][j] == '1') continue;
        if (j - 1 >= 0 && s[i][j - 1] == '1') continue;
        if (j + 1 < n - 1 && s[i][j + 1] == '1') continue;
        s[i][j] = '1';
        if (reach()) {
          cout << i + 1 << " " << j + 1 << endl;
          ok = true;
          break;
        }
        s[i][j] = '0';
      }
    }
    if (!ok) cout << "1" << endl;
  }

  return 0;
}


Measured memory_bytes: 3220
abcd = list(map(int, list(input())))

s = ''
for i in range(8):
    s = str(abcd[0])
    tmp = abcd[0]
    for j in range(3):
        if (1 << j) & i == 0:
            s += '+'
            tmp += abcd[j + 1]
        else:
            s += '-'
            tmp -= abcd[j + 1]
        s += str(abcd[j + 1])
    s += '=7'
    if tmp == 7:
        break
print(s)

Measured memory_bytes: 38384
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <functional>
#include <set>
#include <numeric>
#include <queue>
#include<map>
#define ll long long int
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
#define PI 3.14159265358979323846264338327950


int main() {
	ll d, l, sl, min=1000, ans=0;
	string s, t;

	cin >> s >> t ;
	l = t.length();
	sl = s.length();

	for (int i = 0; i <= sl-l; i++){
		d = 0;
		rep(x, l){
			if (s[x + i] == t[x])continue;
			d++;
		}
		if (d < min)min = d;
	}

	cout << min << endl;
	return 0;
}

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

int main(){
  string s, ans;
  int K, to_a;
  cin >> s >> K;

  //i番目の文字が残り回数xより少ない回数でaに変えられるなら、変更
  //そうでない場合、次の番号へ
  //i == s.size()のとき、x回変更

  for(int i = 0; i < s.size(); i++){
    to_a = 26 - (s[i] - 'a');
    //cout << to_a << endl;
    if(s[i] == 'a') continue;

    if(to_a <= K){
      s[i] = 'a';
      K -= to_a;
    }
  }
  s[s.size()-1] = s[s.size()-1] + (K % 26);

  for(int i = 0; i < s.size(); i++){
    cout << s[i];
    if(i == s.size()-1) cout << endl;
  }
  return 0;
}

Measured memory_bytes: 512
def readInt():
    return list(map(int, input().split()))

n = int(input())
a = readInt()

# print(n)
# print(a)
b = 0
ans = 0
for i in a:
    i %= 10**9+7 
# print(a)

for i in range(n-1):
    b += a[i]
    ans += a[i+1] * b

ans %= (10**9+7)

print(ans)


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

#define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++)
#define ALL(x) x.begin(),x.end()
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

int N;
list<int> edges [100001];

ll dfs(int curr,int prev,bool& ans,vector<ll>& A)
{
	ll res = 0,children = 0,mx = 0;
	for(const auto& it : edges [curr]) if(it != prev){
		ll t = dfs(it,curr,ans,A);
		res += t;
		chmax(mx,t);
		children++;
	}
	if(children == 0){
		return A [curr];
	}
	if(children == 1){
		ans &= res == A [curr];
		return res;
	}
	if(max(res - res / 2,mx) <= A [curr] && A [curr] <= res && A [curr] * 2 - res >= 0){
		return A [curr] * 2 - res;
	}
	ans = false;
	return 0;
}

int main()
{
	scanf("%d",&N);
	vector<ll> A(N + 1);
	FOR(i,1,N + 1){
		scanf("%lld",&A [i]);
	}
	FOR(i,0,N - 1){
		int u,v;
		scanf("%d%d",&u,&v);
		edges [u].push_back(v);
		edges [v].push_back(u);
	}

	bool ans = true;
	FOR(i,1,N + 1){
		if(edges [i].size() == 1){
			dfs(i,-1,ans,A);
			break;
		}
	}
	printf("%s\n",ans ? "YES" : "NO");

	return 0;
}


Measured memory_bytes: 18176
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctype.h>
#include <math.h>
using namespace std;

int main(){
    int a,b;
    cin>>a>>b;
    //1個でa-1増える
    int count=0;
    for(int i=1;;i++){
        if(a+(i-1)*(a-1)>=b){
            count=i;
            break;
        }
    }
    if(b==1){
        cout<<"0"<<endl;
    }
    else{
        cout<<count<<endl;
    }

}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <array>
#include <tuple>
#include <random>

using namespace std;
typedef long long int ll;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

#define const INF 10000000000

ll a, b, c, n, x, y, z, w, h, ans = 0, cnt = 0, max = 0;
string s;

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

    string t;
    cin >> s >> t;
    rep(i, s.size()){
        if(s == t){
            cout << "Yes" << endl;
            return 0;
        }
        s = s.back() + s.substr(0, s.size() - 1);
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.string;

void main()
{
    int n = readln.chomp.to!int;
    if (n == 1){
        "Hello World".writeln;
        return;

    }
    int a = readln.chomp.to!int;
    int b = readln.chomp.to!int;
    (a + b).writeln;
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

void ABC097C()
{
	string s;
	cin >> s;
	int K;
	cin >> K;
	set<char> alp;
	for (auto x : s)
	{
		alp.insert(x);
	}
	set<string> dict;
	int n = s.size();
	auto p = alp.begin();
	while (dict.size() < K)
	{
		for (int i = 0; i < n; ++i)
		{
			if (s[i] == *p)
			{
				for (int j = 1; j <= 5; ++j)
				{
					if (i + j - 1 >= n)
						break;
					dict.insert(s.substr(i, j));
				}
			}
		}
		++p;
	}
	auto q = dict.begin();
	for (int i = 0; i < K - 1; ++i)
		++q;
	cout << *q << endl;
}
int main()
{
	ABC097C();
	return 0;
}


Measured memory_bytes: 256