akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    int N;
    ll t[1010],a[1010];
    cin>>N;
    REP(i,N) cin>>t[i]>>a[i];
    ll sum=0;
    if(N!=1){
    REP(i,N-1){
        sum=a[i+1]+t[i+1];
        //cout<<a[i+1]<<a[i]<<endl;
        if((t[i+1]<t[i]) || (a[i+1]<a[i])){
            ll s=t[i+1]*max((t[i]+t[i+1]-1)/t[i+1],(a[i]+a[i+1]-1)/a[i+1]);
            a[i+1]=a[i+1]*max((t[i]+t[i+1]-1)/t[i+1],(a[i]+a[i+1]-1)/a[i+1]);
            sum=s+a[i+1];
            t[i+1]=s;
            //cout<<"t"<<t[i+1]<<"a"<<a[i+1]<<endl;
            ////cout<<sum<<endl;
        }
        
        
       
        
    }
    cout<<sum<<endl;
    }
    else{
        cout<<t[0]+a[0]<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

ll mod = 1e9 + 7;

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

    string s;
    cin >> s;
    ll n = s.size();
    if(n == 1){
        cout << 1 << endl;
        return 0;
    }
    ll res = n, len = 1;
    FOR(i, 1, n - 1){
        if(len == 1 && s[i] == s[i - 1]){
            i++;
            len = 2;
            res--;
        }
        else len = 1;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(void) {
	
	int n;
	cin >> n;
	
	vector<ll> a(n + 1), b(n);
	for(int i = 0; i < n + 1; ++i) {
		cin >> a[i];
	}
	
	for(int i = 0; i < n; ++i) {
		cin >> b[i];
	}
	
	ll ans = 0;
	ll tmp = 0;
	for(int i = 0; i < n; ++i) {
		
		tmp = min(a[i], b[i]);
		ans += tmp;
		a[i] -= tmp;
		b[i] -= tmp;
		
		tmp = min(a[i + 1], b[i]);
		ans += tmp;
		a[i + 1] -= tmp;
		b[i] -= tmp;
	}
	
	cout << ans << endl;
	
	return 0; 
}


Measured memory_bytes: 1792
#include<stdio.h>
#include<stdlib.h>

int main(){
    long long int c;
    scanf("%lld",&c);
    long long int syou=c/11;
    int amari=c%11;
    int nokori=0;
    if(amari>=7) nokori=2;
    else if(amari==0) nokori=0;
    else nokori=1;
    printf("%lld\n",syou*2+nokori);

}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 1e5;

int n, arr[MAXN+10][3], dp[MAXN+10][3];

int main()
{
    cin.tie(0); cout.tie(0);
    ios_base::sync_with_stdio(false);
    int i, j;

    scanf("%d", &n);
    for(i=1; i<=n; i++) for(j=0; j<3; j++) scanf("%d", &arr[i][j]);

    for(i=1; i<=n; i++)
    {
        dp[i][0]=max(dp[i-1][1], dp[i-1][2])+arr[i][0];
        dp[i][1]=max(dp[i-1][0], dp[i-1][2])+arr[i][1];
        dp[i][2]=max(dp[i-1][0], dp[i-1][1])+arr[i][2];
    }

    printf("%d", max(dp[n][0], max(dp[n][1], dp[n][2])));
    return 0;
}


Measured memory_bytes: 2560
#include <cstdio>
#include <algorithm>
using namespace std;
int N, B[101], ans = 0;
int main() {
  scanf("%d", &N);
  for(int i = 1; i < N; i++) scanf("%d", &B[i]);
  B[0] = B[N] = 1e5;
  for(int i = 1; i <= N; i++) {
    ans += min(B[i-1], B[i]);
  }
  printf("%d", ans);
}

Measured memory_bytes: 128
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N, K = map(int, input().split())
A = len(input().split())

print((N - 2) // (K - 1) + 1)


Measured memory_bytes: 17256
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define reps(i,n) for (int i=1;i<=(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rreps(i,n) for (int i=(n);i>0;i--)
#define all(v) (v).begin(),(v).end()
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>
template<class T> inline bool chmin(T &a, T b) {if (a>b) {a = b; return 1;} return 0;};
template<class T> inline bool chmax(T &a, T b) {if (a<b) {a = b; return 1;} return 0;};
typedef long long int ll;
const long long INF = 1LL << 60;

int main(){
  int N; cin >> N;
  vector<vector<pair<int,ll>>> G(N);
  rep(i,N-1){
    int a, b; cin >> a >> b;
    ll c; cin >> c;
    --a, --b;
    G[a].push_back({b,c});
    G[b].push_back({a,c});
  }

  int Q, K; cin >> Q >> K;
  --K;

  // Kを始点としたBFS
  queue<int> q;
  q.push(K);
  vector<ll> dist(N, -1);
  dist[K] = 0;
  while (!q.empty()){
    int v = q.front(); q.pop();
    for (auto p : G[v]){
      if (dist[p.first]!=-1) continue;

      dist[p.first] = dist[v] + p.second;
      q.push(p.first);
    }
  }
  rep(i,Q){
    int x, y; cin >> x >> y;
    --x, --y;
    ll ans = dist[x] + dist[y];
    cout << ans << endl;
  }
  
  // cout << fixed << setprecision(10);
  
  return 0;
}


Measured memory_bytes: 11576
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 305;
typedef v(vl) vvl;

// coordinate compression
struct X {
  typedef int T;
  vector<T> d;
  X() {}
  X(vector<T>& a): d(a) {
    d.pb(0);
    init();
    for (T& na : a) na = (*this)(na);
  }
  void add(const T& x) { d.pb(x);}
  void init() {
    sort(rng(d));
    d.erase(unique(rng(d)), d.end());
  }
  int size() const { return sz(d);}
  T operator[](int i) const { return d[i];}
  int operator()(const T& x) const { return upper_bound(rng(d),x)-d.begin()-1;}
} xs;
//

ll f(int a, int b) {
  a = xs[a];
  b = xs[b];
  return max(0,b-a);
}

int main() {
  int n,t;
  scanf("%d%d",&n,&t);
  vi a(n);
  cin>>a;
  xs = X(a);
  int m = sz(xs);
  vvl dp(1,vl(m,LINF));
  dp[0][0] = 0;
  rep(i,n) {
    vvl p(i+2,vl(m,LINF)); swap(dp,p);
    rep(j,i+1)rep(k,m) {
      ll now = p[j][k];
      if (now == LINF) continue;
      mins(dp[j][a[i]], now+f(k,a[i]));
      mins(dp[j+1][k], now);
    }
  }
  ll ans = LINF;
  rep(i,t+1)rep(j,m) mins(ans,dp[i][j]);
  cout<<ans<<endl;
  return 0;
}






















Measured memory_bytes: 1664
import java.util.Scanner;

public class Main {
	public static void main(String []args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int k = sc.nextInt();
		int n = Math.min(a, b);
		int ans = 0;

		sc.close();

		for (int i = n; i >= 1; i--) {
			if (a%i == 0 && b%i == 0) {
				k--;
				ans = i;
				if (k == 0) {
					break;
				}
			}
		}
		System.out.println(ans);


	}
}


Measured memory_bytes: 23764
import math

c1x,c1y,c1r = [int(i) for i in input().split()]
c2x,c2y,c2r = [int(i) for i in input().split()]

d = math.sqrt(pow(c1x-c2x, 2) +  pow(c1y-c2y, 2))

bcr = 0
scr = 0

if c1r > c2r:
    bcr = c1r
    scr = c2r
else:
    bcr = c2r
    scr = c1r


if d > bcr + scr:
    print(4)
elif d == bcr + scr:
    print(3)
elif d + scr > bcr:
    print(2)
elif d + scr == bcr:
    print(1)
else:
    print(0)



Measured memory_bytes: 5668
S = input()

s_odd = S[::2]
s_even = S[1::2]


def is_valid_str(s_list, valid_strs):
    for s in s_list:
        if s not in valid_strs:
            return False

    return True


even_ok = is_valid_str(s_even, ["L", "U", "D"])
odd_ok = is_valid_str(s_odd, ["R", "U", "D"])

if even_ok and odd_ok:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 9104
#/*
    AUTHOR:shivam51
    IIESTS
*/
  #include<bits/stdc++.h>
  using namespace std;
  //
  #define add accumulate
  #define ll long long int
  #define ff first
  #define ss second
  // typedef second ss;
  #define pb push_back
  #define mp make_pair
  #define vll vector<ll>
  #define lb lower_bound
  #define ub upper_bound
  #define pll pair<ll,ll>
  #define vpll vector<pll>
  #define all(v) v.begin(), v.end()
  #define rep(i,k,n) for(int i=k;i<n;i++)
  #define hs ios_base::sync_with_stdio(false);cin.tie(NULL);
  const ll mod=1e9+7;
  const ll MAX=3e6+10;
  //
  //
  ll solve(){
    ll x,a;
    cin>>x>>a;
    if(x<a)
      cout<<"0";
    else
      cout<<"10";
  }
  int main(){ 
        ll t;
        // cin>>t;
        t=1;
        while(t--)
          solve();
    } 

Measured memory_bytes: 256
#include <iostream>

int main(){
  int a, b, k;
  std::cin >> a >> b >> k;

  int cnt=0, ret, div[100];
  for(int i = 1; i <= std::min(a, b); i++){
    if(a % i == 0 && b % i == 0){
      div[cnt] = i;
      cnt++;
    }
  }
  ret = div[cnt - k];
  
  std::cout << ret << std::endl;

  return 0;
}


Measured memory_bytes: 256
import operator


def div3(a, b):
    return operator.floordiv(a, b), operator.mod(a,  b), a / b


if __name__ == '__main__':
    a, b = (int(i) for i in input().split())
    ans1, ans2, ans3 = div3(a, b)
    print(ans1, ans2, '{:.5f}'.format(ans3))



Measured memory_bytes: 5708
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;
  int mi = min({a, b, c, d, e});
  int ma = max({a, b, c, d, e});
  if ((ma - mi) > k) {
    cout << ":(" << endl;
  } else {
    cout << "Yay!" << endl;
  }
  return 0;
}


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

int main(){
    int N; cin>>N;
    int a[N];
    int sum = 0;
    rep(i, N){
        cin>>a[i];
        sum ^= a[i];
    }

    rep(i, N){
        cout << (sum^a[i]);
        if(i != N-1) cout << " ";
    }

    cout << endl;
}


Measured memory_bytes: 4312
import sys
rd = sys.stdin.readline

class BIT:
    def __init__(self,len_A):
        self.N = len_A + 10
        self.bit = [0]*(len_A+10)
        
    # sum(A0 ~ Ai)
    # O(log N)
    def query(self,i):
        res = 0
        idx = i+1
        while idx:
            res += self.bit[idx]
            idx -= idx&(-idx)
        return res

    # Ai += x
    # O(log N)
    def add(self,i,x):
        idx = i+1
        while idx < self.N:
            self.bit[idx] += x
            idx += idx&(-idx)
    
    # min_i satisfying {sum(A0 ~ Ai) >= w} (Ai >= 0)
    # O(log N)
    def lower_left(self,w):
        if (w < 0):
            return -1
        x = 0
        k = 1<<(self.N.bit_length()-1)
        while k > 0:
            if x+k < self.N and self.bit[x+k] < w:
                w -= self.bit[x+k]
                x += k
            k //= 2
        return x

n,q = map(int,rd().split())
c = list(map(int,rd().split()))
lr = []
for i in range(q):
    l,r = map(int,rd().split())
    lr.append([l,r,i])
lr.sort(key = lambda x:x[1])

last = [-1]*(n+1)
bit = BIT(n+1)
ans = [0]*q
current = 1
for i in range(q):
    # rightに達するまで
    while current <= lr[i][1]:
        # 今の色が過去にあった場合、bitの値を0に戻す
        if last[c[current-1]] != -1:
            bit.add(last[c[current-1]], -1)
        last[c[current-1]] = current
        bit.add(current, 1)
        current += 1
    ans[lr[i][2]] = bit.query(lr[i][1]) - bit.query(lr[i][0] - 1)

print(*ans, sep = "\n")

Measured memory_bytes: 233592
#include <bits/stdc++.h>
using namespace std;
template<class T> inline T gcd(T a,T b)
  {if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);} 
template<class T> inline T lcm(T a,T b) 
  {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}

int main(){
  long long a, b;
  cin>>a>>b;
  cout<<lcm(a, b)<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
long long inf=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  int a,b;
  string op;
  cin>>a>>op>>b;
  if(op=="+"){
    cout<<a+b<<endl;
  }else{
    cout<<a-b<<endl;
  }
  return 0;
}


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

int main() {
   std::string n;
   std::cin >> n;
   int in;
   in = stoi(n);
   int sn = 0;
   for (size_t i = 0; i < n.size(); i++) {
      sn += n.at(i) - '0';
      //std::cout << "sn: " << sn << '\n';
   }
   if (in % sn == 0) {
      std::cout << "Yes" << '\n';
   }else{
      std::cout << "No" << '\n';
   }
}


Measured memory_bytes: 256
N, A, B, C, D = map(int, input().split())

X = abs(A - B)

result = "NO"
for i in range(N):
    X_min = i * C - ((N - 1 - i) * D)
    X_max = i * D - ((N - 1 - i) * C)
    if X_min <= X <= X_max:
        result = "YES"
        break

print(result)

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

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


Measured memory_bytes: 3128
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i ++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i ++)
#define MP make_pair

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int MOD = 998244353;

int n, m, q, cw, m0, m1;
int u[50005], v[50005], w[50005];
bool ok[1000005][2];

int rt[300005];
int root(int x)
{
	return x == rt[x] ? x : rt[x] = root(rt[x]);
}
void unite(int u, int v)
{
	u = root(u);
	v = root(v);
	if(u == v) return;
	rt[v] = u;
}

int main()
{
	scanf("%d%d%d%d", &n, &m, &q, &m0);
	rep(i, m) {
		scanf("%d%d%d", &u[i], &v[i], &w[i]);
		u[i] --;
		v[i] --;
	}
	
	rep(i, m - 1) m0 = __gcd(m0, 3 * (w[i] - w[i + 1]));
	if(m0 < 0) m0 *= -1;
	if(m0 % 3 == 0) {
		m1 = 3;
		m0 /= 3;
	} else m1 = 1;
	
	rep(i, m) w[i] %= m0 * m1;
	cw = w[0] % m0;
	rep(i, m) w[i] /= m0;
	
	rep(i, 2 * n * m1) rt[i] = i;

	rep(i, m) rep(j, m1) {
		unite(u[i] * m1 + j, v[i] * m1 + (j * 2 + w[i]) % m1 + n * m1);
		unite(u[i] * m1 + j + n * m1, v[i] * m1 + (j * 2 + w[i]) % m1);
	}
	
	int cur = cw, ck = 0;
	do {
		ok[cur][ck] = true;
		cur = 2 * cur % (m0 * m1);
		ck ^= 1;
	} while(cur != cw || ck != 0);
	
	rep(i, q) {
		int qu, qv, qw;
		scanf("%d%d%d", &qu, &qv, &qw);
		qu --; qv --;
		swap(qu, qv);
		qw = (qw + cw) % (m0 * m1);
		bool ans = false;
		rep(i, m1) rep(j, 2)
		if(ok[(qw + (m1 - i) * m0) % (m0 * m1)][j] && root(qu * m1) == root(qv * m1 + i + j * n * m1)) ans = true;
		printf(ans ? "YES\n" : "NO\n");
	}
	
	return 0;
}


Measured memory_bytes: 4096
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
using namespace std;
typedef long long ll;

const int INF = 1001001001;

int main() {
    int n; cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    ll b = 0;
    for (int i = 0; i < n; i++) {
        b = a[i] - b;
    }

    ll ans = b;
    cout << ans;
    for (int i = 0; i < n-1; i++) {
        ans = (a[i]-ans/2)*2;
        cout << ' ' << ans; 
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
vector<P> to[100001];
bool color[100001];
void dfs(int i,int par){
    for(auto x:to[i]){
        if(x.first!=par){
            if(x.second%2==0){
                color[x.first]=color[i];
            }
            else color[x.first]=!color[i];
            dfs(x.first,i);
        }
    }
}
int main(void){
    int n;
    cin>>n;
    for(int i=0;i<n-1;i++){
        int a,b,c;
        cin>>a>>b>>c;
        to[a].push_back(P(b,c));
        to[b].push_back(P(a,c));
    }
    color[1]=0;
    dfs(1,-1);
    for(int i=1;i<=n;i++){
        cout<<color[i]<<endl;
    }
}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;

int POWINT(int x, int n) {
  int ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

ll POWLL(int x, int n) {
  ll ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

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

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

bool check(int mid, vector<int> &a, int n, int p, int v, int m) { // 問題セットになる可能性がある
  if (n - mid <= p) return true;
  if (a[mid] + m < a[n-p]) return false;
  {
    ll score =  (ll)a[mid] + (ll)m;
    ll mv = (ll)m * (ll)v;
    ll possible_mv = 0ll;
    possible_mv += (ll)(mid+1) * (ll)m;
    possible_mv += (ll)(p-1) * (ll)m;
    rep(i, mid+1, n-p+1) {
      possible_mv += (score - (ll)a[i]);
    }
    if (possible_mv >= mv) {
      return true;
    } else {
      return false;
    }
  }
};

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

  int n, m, v, p;
  cin >> n >> m >> v >> p;

  vector<int> a(n);

  rep(i, 0, n) {
    cin >> a[i];
  }

  sort(All(a));

  int low = -1; // ng
  int high = n-1; // ok

  while (abs(high - low) > 1) {
    int mid = (high + low) / 2;
    if (check(mid, a, n, p, v, m)) {
      high = mid;
    } else {
      low = mid;
    }
  }

  cout << n - high << endl;

  return 0;
};


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

typedef long long ll;
typedef pair<int,int> pp;
const ll INF = 1e9;
const ll MOD = 1000000007;
const double pi = 3.141592653589793238;

ll gcd(ll a, ll b) { return __gcd(a,b); } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } //最大公倍数

void printV(vector<int> &v);
void printVV(vector<vector<int>> &vv);


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

  vector<bool>issafe;

  issafe.assign(N+1,true);
  for(int i=0;i<M;i++){
    int a;cin>>a;
    issafe[a]=false;
  }

  vector<int>dp(N+1,0);

  dp[0]=1;
  if(issafe[1])dp[1]=1;

  for(int n=2;n<=N;n++){
    if(issafe[n-1])dp[n]+=dp[n-1];
    if(issafe[n-2])dp[n]+=dp[n-2];
    dp[n]%=MOD;
  }
  cout<<dp[N]<<endl;
  return 0;
}


// ベクターの中身を全部出力
void printV(vector<int> &v) {
  cout << "  [ ";
  for(int i = 0; i < (int)v.size(); i++) {
    cout << v.at(i) << " ";
  }
  cout << "]" << endl;
}

void printVV(vector<vector<int>> &vv) {
  cout << "{" << endl;
  for(int i = 0; i < (int)vv.size(); i++) {
    cout << "  [ ";
    for(int j = 0; j < (int)vv.at(i).size(); j++) {
      cout << vv.at(i).at(j) << " ";
    }
    cout << "]," << endl;
  }
  cout << "}" << endl;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> X(N);
  for(int i=0; i<N; i++){
    cin >> X.at(i);
  }
  int Ans=10000000;
  int sum=0;
  for(int i=1; i<101; i++){
    sum=0;
    for(int j=0; j<N; j++){
      sum+=pow(X.at(j)-i,2);
    }
    if(sum<Ans){
      Ans=sum;
    }
  }
  cout << Ans << endl;
}

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

int main() {

string S;
  cin >> S;
  
  if(S.at(2) == S.at(3) && S.at(4) == S.at(5)){
   cout << "Yes" << endl; 
  }
  
  else{
   cout << "No" << endl; 
  }
  
  
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

int main() {
	string s, t;
	cin >> s >> t;
	for (int i = 0; i < s.length(); i++) {
		if (s[i] != t[i]) {
			cout << "No\n";
			return 0;
		}
	}
	cout << "Yes\n";
	return 0;
}


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

double dp[330][330][330];

int main() {
  int a = 0;
  int b = 0;
  int c = 0;
  int n;
  cin >> n;
  rep(i,n) {
    int x;
    cin >> x;
    if(x==3) a++;
    if(x==2) b++;
    if(x==1) c++;
  }
  for(int i = 0; i<=n; i++) {
    for(int j = 0; j<=n; j++) {
      for(int k = 0; k<=n; k++) {
        int sum = i + j + k;
        if(sum==0) {
          dp[i][j][k] = 0;
          continue;
        }
        dp[i][j][k] = (double)n / sum;
        if(i>0) dp[i][j][k] += dp[i-1][j+1][k]  * i / sum;
        if(j>0) dp[i][j][k] += dp[i][j-1][k+1]  * j / sum;
        if(k>0) dp[i][j][k] += dp[i][j][k-1]  * k / sum;
      }
    }
  }
  cout << fixed << setprecision(10) << dp[a][b][c] << endl;
  return 0;
}

Measured memory_bytes: 258176
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main() {
    int h, w, n; cin >> h >> w >> n;
    auto g = make_v(h, w, '0');

    int fy, fx;
    REP(i, h)REP(j, w) {
        cin >> g[i][j];
        if (g[i][j] == 'S') {
            fy = i; fx = j;
        }
    }

    constexpr int dy[] = {-1, 0, 1, 0}, dx[] = {0, -1, 0, 1};
    auto in = [&](int i, int j) {
        return 0 <= i && i < h && 0 <= j && j < w;
    };
    
    function<int(int, int, int)> solve = [&](int i, int sy, int sx) {
        if (i == n) return 0;

        using p = pair<int, int>;
        queue<p> q;
        auto v = make_v(h, w, -1);
        
        q.push({sy, sx});
        v[sy][sx] = 0;

        while (!q.empty()) {
            auto now = q.front(); q.pop();
            int y = now.first, x = now.second;
            
            if (g[y][x] == '0' + i + 1) {
                return v[y][x] + solve(i + 1, y, x);
            }

            REP(i, 4) {
                int ny = y + dy[i], nx = x + dx[i];
                if (in(ny, nx) && g[ny][nx] != 'X' && v[ny][nx] == -1) {
                    q.push({ny, nx});
                    v[ny][nx] = v[y][x] + 1;
                }
            }
        }
        
        return -1; // error
    };

    cout << solve(0, fy, fx) << endl;

    return 0;
}



Measured memory_bytes: 39112
package main

import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
)

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  var line, buffer []byte
  var isPrefix bool = true
  var err error
  for isPrefix {
    line, isPrefix, err = reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
  }
  return string(buffer)
}
func NextIntVec() []int {
  L := strings.Split(NextLine(), " ")
  N := make([]int, len(L))
  for i := range N {
    N[i], _ = strconv.Atoi(L[i])
  }
  return N
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func Output() {
  _ = writer.Flush()
}

func Factorial(N int) (F, Finv []int) {
  F = make([]int, N + 1)
  Finv = make([]int, N + 1)
  inv := make([]int, N + 1)
  F[0] = 1
  F[1] = 1
  Finv[0] = 1
  Finv[1] = 1
  inv[0] = 1
  inv[1] = 1
  for i := 2; i < N + 1; i++ {
    F[i] = F[i - 1] * i % p
    inv[i] = p - inv[p % i] * (p / i) % p
    Finv[i] = Finv[i - 1] * inv[i] % p
  }
  return
}
func Comb(F, Finv *[]int, i, j int) int {
  return ((*F)[i + j] * (*Finv)[i] % p) * (*Finv)[j] % p
}
func Inverse(N int) []int {
  Inv := make([]int, N + 1)
  Inv[0] = 1
  Inv[1] = 1
  for i := 2; i < N + 1; i++ {
    Inv[i] = p - Inv[p % i] * (p / i) % p
  }
  return Inv
}

func Sum(A *[]int) int {
  S := 0
  for _, a := range (*A) {
    S += a
    S %= p
  }
  return S
}

const p = 1000000007

func main() {
  NABC := NextIntVec()
  N, A, B:= NABC[0], NABC[1], NABC[2]
  F, Finv := Factorial(2 * N)
  I := Inverse(A + B)
  PA := make([]int, 2 * N + 1)
  PB := make([]int, 2 * N + 1)
  ABI := make([]int, 2 * N + 1)
  PA[0] = 1
  PB[0] = 1
  ABI[0] = 1
  for i := 0; i < 2 * N; i++ {
    PA[i + 1] = PA[i] * A % p
    PB[i + 1] = PB[i] * B % p
    ABI[i + 1] = ABI[i] * I[A + B] % p
  }
  P := make([]int, N)
  S := make([]int, N)
  P[0] = Comb(&F, &Finv, N - 1, 0) * (PA[N] + PB[N]) * ABI[N] % p
  S[0] = P[0]
  for i := 1; i < N; i++ {
    P[i] = (PA[N] * PB[i] + PA[i] * PB[N]) % p
    P[i] = P[i] * Comb(&F, &Finv, N - 1, i) % p
    P[i] = P[i] * ABI[N + i] % p
    S[i] = (S[i - 1] + P[i]) % p
  }
  E := make([]int, N)
  for i := range E {
    E[i] = (N + i) * P[i] % p
  }
  Write((Sum(&E) * 100 % p) * ABI[1] % p)
  Output()
}

Measured memory_bytes: 11776
#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
int main() {
	ios_base :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	const int MAXN = 1e5;
	int n, p = 0;
	long long a[MAXN], lim = 1e18;
	cin >> n;
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
		if(a[i] == 0) p = 1;
	}
	if(p == 1) cout << "0\n";
	else {
		long long res = 1;
		for(int i = 0; i < n; ++i) {
			long long k = lim / res;
			if(k < a[i]) {
				res = -1;
				break;
			}
			res *= a[i];
		}
		cout << res << '\n';
	}
	return 0;
}

Measured memory_bytes: 4420
#include<iostream>
using namespace std;
int main()
{
    int n,sum=0,b=0,b1=0,b2=0,sum1=0,sum2=0;
    float avg=0;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum+=a[i];
    }
    avg=sum*1.0/n;
    b2=sum/n;
    if(avg!=b2){
        b=(int)avg;
        b1=(int)(avg+1);
        for(int i=0;i<n;i++){
            sum1+=(a[i]-b)*(a[i]-b);
        }
        for(int i=0;i<n;i++){
            sum2+=(a[i]-b1)*(a[i]-b1);
        }
        if(sum1>=sum2){
            cout<<sum2<<endl;
        }
        else{
            cout<<sum1<<endl;
        }
    }
    else{
        for(int i=0;i<n;i++){
            sum1+=(a[i]-b2)*(a[i]-b2);
        }
        cout<<sum1<<endl;
    }
    return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
#define fr(i,c,b) for(int i=c;i<b;i++)
#define si(x) int x; scanf("%d", &x)
#define sll(x) ll x; scanf("%lld", &x)
#define pi(x) printf("%d", x)
#define pll(x) printf("%lld", x)
#define nl printf("\n")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define MAX 1000001
typedef long long int ll;

using namespace std;



int main(){
    si(n);
    double a[n];
    fr(i,0,n)
        cin>>a[i];
    double ans=0;
    sort(a,a+n);
    fr(i,1,n)
        a[i]=(a[i-1]+a[i])/2;
    cout<<a[n-1];
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000007
#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
signed main()
{
    int N;
    cin >> N;
    vector<vector<int>> to(N), cost(N);
    rep(i, N - 1)
    {
        int a, b, w;
        cin >> a >> b >> w;
        a--;
        b--;
        to[a].push_back(b);
        cost[a].push_back(w);
        to[b].push_back(a);
        cost[b].push_back(w);
    }
    vector<int> ans(N, -1);
    queue<int> q;
    ans[0] = 0;
    q.push(0);
    while (!q.empty())
    {
        int v = q.front();
        q.pop();
        rep(i, to[v].size())
        {
            int u = to[v][i];
            int w = cost[v][i];
            if (ans[u] != -1)
                continue;
            ans[u] = (ans[v] + w) % 2;
            q.push(u);
        }
    }
    rep(i, N)
    {
        cout << ans[i] << endl;
    }
}


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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)):((m)-(n))),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)
#define loop for(;;)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;
typedef vector<int> vi;
typedef vector<string> vs;
typedef map<string,int> Dictionary;
const Real PI = acos(-1);

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

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

int main() {

  int case_index = 1;
  loop {
    int C, n; cin >> C >> n;
    if (!C) break;
    cout << "Case " << case_index << ':' << endl;
    ++case_index;

    vi cs(n);
    vi xs(n);
    char comma;
    rep (i, n) cin >> xs[i] >> comma >> cs[i];

    int dp[C+1];
    rep (c, C+1) dp[c] = 0;

    rep (i, n) {
      for (int c = C - cs[i]; c >= 0; --c) {
        int c2 = c + cs[i];
        if (dp[c2] < dp[c] + xs[i]) {
          dp[c2] = dp[c] + xs[i];
        }
      }
    }

    int mx = 0,
        mc = -1;
    rep (c, C + 1) {
      if (mx < dp[c]) {
        mx = dp[c];
        mc = c;
      }
    }
    cout << mx << endl;
    cout << mc << endl;
  }

  return 0;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
//using namespace __gnu_pbds;
#define rep(i,a,b) for(i=(a);i<=(b);i++)
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define maxn 100005
#define inf 1e18
#define boost ios::sync_with_stdio(false);cin.tie(0)
#define fr freopen("source.txt","r",stdin),freopen("output.txt","w",stdout)
#define SET(a,b) memset(a,b,sizeof(a))
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x) x.begin(), x.end()
//template<typename T>
//using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
ll powermod(ll x,ll y){
	ll res=1;
	while(y>0){
		if(y&1)
		res=(res*x)%mod;

		y/=2;
		x=(x*x)%mod;
	}
	return res;
}
int main()
{
    boost;
    ll n,i,j,x,t,k,y;
    cin>>n>>k;
    ll a[n];
    for(i=0;i<n;i++) cin>>a[i];
    ll f[n+1];
    f[0]=f[1]=1;
    for(i=2;i<=n;i++) f[i]=(i*f[i-1])%mod;
    sort(a,a+n);
    ll mx=0,mn=0;
    t=powermod(f[k-1],mod-2);
    for(i=0;i<=(n-k);i++){
        y=n-i-1;
        x=(f[y]*t)%mod;
        x=(x*powermod(f[y-k+1],mod-2))%mod;
        //cout<<x<<" ";
        mn=(mn+(x*a[i])%mod)%mod;
    }
    for(i=n-1;i>=k-1;i--){
        y=i;
        x=(f[y]*t)%mod;
        x=(x*powermod(f[y-k+1],mod-2))%mod;
        //cout<<x<<" ";
        mx=(mx+(x*a[i])%mod)%mod;
    }
    ll ans=(mx-mn+10LL*mod)%mod;
    cout<<ans;
}

Measured memory_bytes: 1792
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<functional>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<utility>
#include<vector>

#define INF 1000000007
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define CLR(a) memset((a), 0, sizeof(a))

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

inline int toInt(string s){
    int v;
    istringstream sin(s);
    sin >> v;
    return v;
}

template<class T> inline string toString(T x){
    ostringstream sout;
    sout << x;
    return sout.str();
}

int main(void){

    int n;
    cin >> n;
    double ans = 0;
    FOR(i,0,n){
        double x;
        string s;
        cin >> x >> s;
        if(s=="JPY")ans += x;
        else ans += x*380000;
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
//AUTHOR: RAVAN_2070
//PUNE INSTITUTE OF COMPUTER TECHNOLOGY
/*
    I LOVE CLARICE STARLING

     ♥LOVE♥        ♥LOVE♥
  ♥LOVE♥♥LOVE♥  ♥LOVE♥♥LOVE♥
♥LOVE♥♥LOVE♥♥LOVE♥♥LOVE♥♥LOVE♥
   ♥LOVE♥♥LOVE♥♥LOVE♥♥LOVE♥
      ♥LOVE♥♥LOVE♥♥LOVE♥
         ♥LOVE♥♥LOVE♥
            ♥LOVE♥
               ♥


    EXPLAINATION BELOW->
     * Dfs+dp
   
*/
//
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<pair<ll,ll>> vii;
typedef pair<ll,ll> pii;
typedef map<ll,ll> mii;
#define MOD7 1000000007
#define MOD9 1000000009
#define pi 3.1415926535
#define Test_cases ll TC;cin>>TC;while(TC--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define sp(x) fixed<<setprecision(x)
#define sz(x) (ll)(x.size())
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
vector<vector<int>>adj;
vector<int>dp,visited;
int mx;
int dfs(int v)
{
    for(auto it:adj[v])
    {
        if(dp[it]==-1)
        dp[v]=max(dp[v],1+dfs(it));
        else
        dp[v]=max(dp[v],1+dp[it]);
    }
    if(dp[v]==-1)return 0;
    return dp[v];
}
void solve()
{
    int n,m,u,v,i;cin>>n>>m;
    adj=vector<vector<int>>(n);
    dp=vector<int>(n,-1);
    visited=vector<int>(n,0);
    fo(i,0,m)
    {
        cin>>u>>v;u--;v--;
        adj[u].pb(v);
    }
    fo(i,0,n)
    {
        if(dp[i]==-1)dp[i]=dfs(i);
    }
    fo(i,0,n)mx=max(mx,dp[i]);
    cout<<mx<<"\n";
}
int main()
{
   fastio
   solve();
  return 0;
}
//map<ll,ll,greater<int>> to sort in descending order ,in iterator declaration no greater<int>
//if you want to apply lowerbound on set use s.lower_bound(key),not the one used for vector
/* TIPS FOR DEBUGGING
 * Check if values are not overflowing (use long long where required)
 * Check if ranges are inclusive or not.
 * Check properly if greedy will work or not before using it.
 * Check EDGE CASES!! Seriously, even in 2B, saving 8 points by being
 * 2 minutes faster will bite you in the ass if you don't make sure
 * it works on edge cases.
 * Keep adding to this list.
*/


Measured memory_bytes: 8576
#include<bits/stdc++.h>
#define int long long
#define ll int64_t
using namespace std;
 
bool cmp(pair<int,int> a , pair<int,int> b) {
	return (a.second < b.second);
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
	int n , k , s;
	cin >> n >> k >> s;
	vector<int> v(n+1);
	for(int i = 1; i <= k; i++) v[i] = s;
	if(s == 1e9) for(int i = k+1; i <= n; i++) v[i] = 1;
	else for(int i = k+1; i <= n; i++) v[i] = 1e9;
	for(int i = 1; i <= n; i++) cout << v[i] << " ";
	cout << "\n";
		
    return 0;
}


Measured memory_bytes: 2176
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

typedef long long ll;
//typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define revrep(i, n) for(ll i = n-1; i >= 0; i--)
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll Mypow(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}

ll gcd(ll a, ll b){//計算量はO(log(max(a,b))
    if(b == 0) return a;
    return gcd(b, a % b);
}

ll INFL = 1LL << 60;//10^18 = 2^60
int INF = 1 << 30;//10^9
ll MOD  = 1000000007;
//vector<int> dy = {0,0,1,-1};
//vector<int> dx = {1,-1,0,0};

ll kai(ll x){
  if(x == 1) return 1;
  return x * kai(x-1) % MOD;
}



int main(){
  string S; cin >> S;
  int N = S.size();
  for(int i = N-1;;){
    if(i == -1){
      cout << "YES" << endl;
      return 0;
    }
    bool update = 0;
    if(i-4>=0&&S[i-4]=='d'&&S[i-3]=='r'&&S[i-2]=='e'&&S[i-1]=='a'&&S[i]=='m'){
      update = 1;
      i -= 5;
    }else if(i-6>=0&&S[i-6]=='d'&&S[i-5]=='r'&&S[i-4]=='e'&&S[i-3]=='a'&&S[i-2]=='m'&&S[i-1]=='e'&&S[i]=='r'){
      update = 1;
      i -= 7;
    }else if(i-4>=0&&S[i-4]=='e'&&S[i-3]=='r'&&S[i-2]=='a'&&S[i-1]=='s'&&S[i]=='e'){
      update = 1;
      i -= 5;
    }else if(i-5>=0&&S[i-5]=='e'&&S[i-4]=='r'&&S[i-3]=='a'&&S[i-2]=='s'&&S[i-1]=='e'&&S[i]=='r'){
      update = 1;
      i -= 6;
    }
    if(update == 0){
      cout << "NO" << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 512
//marico el que lo lea
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <stdlib.h>
#include <assert.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;

void fastIO() {
	std::ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
}

#define FOR(i,f,t) for(int i=f; i<(int)t; i++)
#define FORR(i,f,t) for(int i=f; i>(int)t; i--)
#define FORE(i,c) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define all(obj) obj.begin(), obj.end()
#define ms(obj, val) memset(obj, val, sizeof(obj))
#define ms2(obj, val, sz) memset(obj, val, sizeof(obj[0])*sz)

#define fst first
#define snd second

template<typename T, typename U> inline void mnze(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void mxze(T &x, U y) { if(x < y) x = y; }

void _scan( int &x ) { scanf("%d",&x); }
void _scan( long long &x ) { scanf("%lld",&x); }
void _scan( double &x ) { scanf("%lf",&x); }
void _scan( char &x ) { scanf(" %c",&x); }
void _scan( char *x ) { scanf("%s",x); }
void scan() {}
template<typename T, typename... U>
void scan( T& head, U&... tail ) { _scan(head); scan(tail...);}

template<typename T> void _dbg(const char* sdbg, T h) { cerr<<sdbg<<"="<<h<<"\n"; }
template<typename T, typename... U> void _dbg(const char* sdbg, T h, U... t) {
	while(*sdbg != ',')cerr<<*sdbg++; cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; FORE(_i, (x)) cerr <<*_i <<", "; cerr <<"\n"; }}
#define debuga(x, sz) {{cerr <<#x <<" = "; FOR(_i, 0, sz) cerr << x[_i] <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define debuga(x, sz)
#define cerr if(0)cout
#endif

///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////

const int MAXK = 1e5+5, MAXQ = 1e5+5;

ll X, K, r[MAXK], Q, t[MAXQ], a[MAXQ];

ll ans[MAXQ];

int main(){
	scan(X,K);
	FOR(i,0,K) scan(r[i]);
	scan(Q);
	FOR(i,0,Q) scan(t[i], a[i]);
	ll lo = 0, hi = X, d=0, T=0;
	int ri = 0, qi = 0, s=-1;
	while(ri < K){
		while(qi < Q && r[ri] > t[qi]){
			if(a[qi] > hi) a[qi]=hi;
			if(a[qi] < lo) a[qi]=lo;
			ans[qi] = s*(t[qi]-T) + a[qi]+d;
			mxze(ans[qi],0);
			mnze(ans[qi],X);
			qi++;
		}
		d += s*(r[ri]-T);
		T = r[ri];
		mxze(d, -X);
		mnze(d, X);
		if(s<1){
			mxze(lo, -d);
			mxze(hi, lo);
		}else{
			mnze(hi, X-d);
			mnze(lo, hi);
		}
		s*=-1;
		debug(lo, hi);
		ri++;
	}
	while(qi < Q){
		if(a[qi] < lo) a[qi]=lo;
		if(a[qi] > hi) a[qi]=hi;
		ans[qi] = s*(t[qi]-T) + a[qi]+d;
		mxze(ans[qi],0);
		mnze(ans[qi],X);
		qi++;
	}
	FOR(i,0,Q) printf("%lld\n",ans[i]);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reps(i,a,b) for(int i= a; i < b; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  ll n,m;
  cin >> n >> m;
  vector<ll> dist(n+1, -1);
  vector<vector<ll>> g(n+1, vector<ll>());

  rep(i, m) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  queue<int> que;
  que.push(1);
  dist[1] = 0;
  vector<ll> sig(n+1, -1);
  while(!que.empty()) {
    ll v = que.front();
    que.pop();
    rep(i, (int)g.at(v).size()) {
      ll nv = g.at(v).at(i);
      if (dist[nv] == -1) {
        dist[nv] = dist[v] + 1;
        sig.at(nv) = v;
        que.push(nv);
      } else if(dist[nv] > dist[v] + 1) {
        sig.at(nv) = v;
        dist[nv] = dist[v] + 1;
        que.push(nv);
      }
    }
  }
  bool ok = true;
  reps(i, 2, n+1) {
    if (dist[i] == -1) ok = false;
  }
  if (ok) {
    cout << "Yes" << endl;
    reps(i, 2, n+1) cout << sig[i] << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 13420
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>

#include <cmath>
#include <iomanip>

using namespace std;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int w;
  cin >> w;
  int weights[n];
  long long int values[n];
  long long int cur;
  for (int i = 0; i < n; i++) {
    cin >> cur;
    weights[i] = cur;
    cin >> cur;
    values[i] = cur;
  }
  long long int dp[n+1][(1000*n)+1];
  //dp[n][v] represents the minimum weight needed to get value v and only using items with number up to n.
  for (int i = 0; i < n+1; i++) {
    dp[i][0] = 0;
    for (int j = 1; j < (1000*n)+1; j++) {
      dp[i][j] = w+1;
    }
  }
  for (int minInd = 0; minInd < n; minInd++) {
    for (int wanted = 0; wanted < (1000*n); wanted++) {
      dp[minInd+1][wanted] = min(dp[minInd+1][wanted], dp[minInd][wanted]);
      if (dp[minInd][wanted]+weights[minInd] <= w) {
	dp[minInd+1][wanted+values[minInd]] = min(dp[minInd+1][wanted+values[minInd]], dp[minInd][wanted]+weights[minInd]);
      }
    }
  }
  for (int i = (1000*n); i > 0; i--) {
    if (dp[n][i] <= w) {
      cout << i << "\n";
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 79232