akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
#define phb push_back
#define fr first
#define sc second
using namespace std;

const int kSize = 1010;
const int kMaxPw = 18;

int N, Ai[kSize];

map< int, vector< int > > bsm;

void read();
void solve();

int dp(const vector< int > &);

int main() {
  while (cin >> N, N)
    read(), solve();

  return 0;
}

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

void solve() {
  bsm.clear();
  for (int i = 0; i < N; ++i) {
    int t = Ai[i], k = 1;
    while (t % 2 == 0)
      k <<= 1, t /= 2;
    bsm[t].phb(k);
  }

  int res = 0;
  for (auto itr: bsm)
    res = max(res, dp(itr.sc));
  cout << res << "\n";
}

int dp(const vector< int > &v) {
  int sum = accumulate(all(v), 0), n = sz(v);
  vector< int > f(sum + 1, -1);

  f[0] = 0;
  for (int i = 0; i < n; ++i)
    for (int j = sum & ~(v[i] - 1); j > 0; j -= v[i])
      if (f[j - v[i]] != -1)
        f[j] = max(f[j], f[j - v[i]] + 1);

  int ret = 0;
  for (int i = 0; (1 << i) <= sum; ++i)
    ret = max(ret, f[1 << i]);
  return ret;
}

Measured memory_bytes: 1740
N = int(input())
T, A = map(int,input().split(" "))
H = [int(i) for i in input().split(" ")]
ans = 0
for i in range(1,N):
  if abs(A-T+H[i]*0.006) < abs(A-T+H[ans]*0.006):
    ans = i
print(ans+1)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#define INF 1000000000
#define LLINF 2000000000000000
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
// #define int long long

signed main(){
  int a=0,b=0,c=0;
  // int ans=0;
  // string ss=0;
  // string s=0,t=0;
  // int x=0,y=0,z=0;

  cin >> a >> b;
  if(a*500 >= b){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  //cout << ans;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define io() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); srand(time(NULL));
 
using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

signed main(){
    io();
    int n, k; cin >> n >> k;
    int cpy = k;
    int limit = ((n - 1)*(n - 2))/2;
    if(k > limit){
        cout << "-1\n";
    }else{
        bool matrix[n][n]; memset(matrix, 1, sizeof(matrix));
        for(int i = n - 1; ~i; --i){
            for(int j = n - 1; j > i; --j){
                if(k){
                    --k;
                    matrix[i][j] &= 0;
                    //cout << i << ' ' << j << '\n';
                }
            }
        }
        cout << (n*(n - 1))/2 - cpy << '\n';
        for(int i = 0; i < n; ++i){
            for(int j = i + 1; j < n; ++j){
                if(matrix[i][j]) cout << i + 1 <<  ' ' << j + 1 << '\n';
            }
        }
    }
    return 0;  
}

Measured memory_bytes: 3644
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";


typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_7_B&lang=ja

int main() {

    while(true) {
        int n, x; cin >> n >> x;
        if (n==0&&x==0) break;

        int cnt = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = i+1; j <= n; j++) {
                for (int k = j+1; k <= n; k++) {
                    if (i+j+k==x) cnt++;
                }
            }
        }
        cout << cnt << "\n";
    }


    return 0;
}


Measured memory_bytes: 3072
#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 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 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 vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
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 = 200005;

// Segment tree
struct F { // min func
  typedef ll TT;
  TT d;
  F(TT d=0):d(d) {}
  F& operator+=(const F& f) {
    maxs(d, f.d);
    return *this;
  }
  F operator+(const F& f) const { return F(*this) += f;}
};
struct seg {
  vector<F> d; int n;
  seg(){}
  seg(int mx) {
    n = 1; while (n < mx) n <<= 1;
    d = vector<F>(n<<1);
  }
  void upd(int i) { d[i] = d[i<<1]+d[i<<1|1];}
  F& operator[](int i) { return d[n+i];}
  void init() { for(int i=n-1;i;--i) upd(i);}
  void set(int i, F f) {
    i+=n; d[i] = f;
    for (i>>=1;i;i>>=1) upd(i);
  }
  F get(int l, int r) {
    l += n; r += n;
    F lf, rf;
    while (l < r) {
      if (l&1) lf += d[l++];
      if (r&1) rf = d[--r] + rf;
      l >>= 1; r >>= 1;
    }
    return lf += rf;
  }
};
//


int main() {
  int n;
  scanf("%d",&n);
  vi a(n), b(n);
  cin>>a>>b;
  seg t(n+5);
  ll ans = 0;
  rep(i,n) {
    ll now = t.get(0,a[i]).d + b[i];
    maxs(ans,now);
    t.set(a[i],F(now));
  }
  cout<<ans<<endl;
  return 0;
}






















Measured memory_bytes: 6016
// inputに入力データ全体が入る
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	S = input[0];
	//K = input[1];
	var k = parseInt(input[1], 10);
	n = S.length;
	//console.log(S,k,n);
	
	
	 S1=[];
	var cnt =0;var f = 0;
	for(i=0;i<n;i++){if( S.substr(i,1)==S.substr(i+1,1)){f++;
	                                                   //  S1[i] =f;
	                                                     }
	                              else if(f > 0){S1[i-f] =f+1;
	                                             f = f/2;
	                                            f = Math.ceil(f);
	                                            cnt = cnt + f;
                                                var f = 0;
	                                         //   S1[i]=f;
	                                            }
                                                         else{S1[i]=f+1;}
                                              }
//	console.log(i,cnt,k);
//	console.log(S1);
	//console.log(S1.shift(),S1.pop());
 //   console.log(S1.length)
if (n==1){cnt = Math.floor(k/2);}
                  else if (S1.length == 1){//console.log('***');
                                           t=S1[0]*k;
                                           cnt = Math.floor(t/2);
                                    //     console.log(t);
                                             }
                             else if
    
	                         (S.substr(0,1)==S.substr(n-1,1)){ 
	                                      //  console.log(S1);
                                            x = S1[0]%2;
	                                        y = S1.pop()%2;
	                                      //  console.log(x,y);
	                                           if (x ==1 && y==1)
	                                              { cnt=cnt*k+k-1;}
                                                 else {// console.log('*');
                                                      cnt = cnt*k;}}
                               else{cnt = cnt*k;}
                                                    //     }}
	                                                     
	   
	                                         
	console.log(cnt);
	//console.log(cnt*k);
	//if (n==1){cnt = Math.ceil(cnt*k/2);}else{cnt = cnt*k;}  
//	console.log(cnt);   
	}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <map>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
const long long INF=(1LL<<62);
const double inf=pow(10,10);
double pi=3.141592653589793;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const ll MOD = 1000000007;
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
}

long long gcd(long long a,long long b){
	if(a<b)swap(a,b);
	if(a%b==0)return b;
	else return gcd(a%b,b);
}

long long lcm(long long a,long long b){
	return a/gcd(a,b)*b;
}

int main(){
	init();
	ll N;cin>>N;
	string map[2];
	cin>>map[0]>>map[1];
	vector<ll>type;
	for(int i=0;i<N;i++){
		if(map[0][i]==map[0][i+1]){
			type.push_back(0);
			i++;
		}else type.push_back(1);
	}
	ll ans;
	if(type[0]==0)ans=6;
	if(type[0]==1)ans=3;
	for(int i=1;i<type.size();i++){
		if(type[i-1]==0&&type[i]==0)ans*=3;
		if(type[i-1]==0&&type[i]==1)ans*=1;
		if(type[i-1]==1&&type[i]==0)ans*=2;
		if(type[i-1]==1&&type[i]==1)ans*=2;
		ans%=MOD;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void init_ios() {ios_base::sync_with_stdio(false); cin.tie(nullptr);}

long long pow_mod(long long x, long long n, const long long mod) {
	long long ret = 1;
	while (0 < n) {
		if (n & 1) ret = ret * x % mod;
		x = x * x % mod;
		n >>= 1;
	}
	return ret;
}

const long long MOD = 1000000007;
int H, W, A, B;
long long fact[200001], ifact[200001];

int main() {
	scanf("%d%d%d%d", &H, &W, &A, &B);

	fact[0] = ifact[0] = 1;
	for (int i = 1; i <= H+W; ++i) {
		fact[i] = (fact[i-1] * i) % MOD;
		ifact[i] = pow_mod(fact[i], MOD-2, MOD);
	}

	long long res = 0;
	for (long long i = 0, n,r,c1,c2; i < W-B; ++i) {
		n = H-A + B+1+i - 2, r = H-A-1;
		c1 = fact[n] * ifact[n-r] % MOD * ifact[r] % MOD;
		n = A + W-B-i - 2, r = A-1;
		c2 = fact[n] * ifact[n-r] % MOD * ifact[r] % MOD;
		(res += c1 * c2 % MOD) %= MOD;
	}

	printf("%lld\n", res);

	return 0;
}


Measured memory_bytes: 3328
#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define MOD (1000000007l)
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)

using namespace std;

void solve() {
  ll a, b, c;
  cin >> a >> b >> c;
  ll sum = a + b + c;
  cout << (sum >= 22 ? "bust" : "win") << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  cout << fixed;
  solve();
  return 0;
}


Measured memory_bytes: 256
main :: IO ()
main = do
  n <- readLn
  print $ g n

f :: Int -> [(Int,Int)]
f n = [(x, n-x) | x <- [1..((n+1) `div` 2)]]

sod :: Int -> Int
sod = sum . sod'
sod' n
  | q == 0 = [r] 
  | otherwise = r : sod' q
  where
    (q,r) = quotRem n 10

g = minimum . map (\(x,y) -> (sod x) + (sod y)) . f

Measured memory_bytes: 1020
// Isaunoya
#include<bits/stdc++.h>
using namespace std ;
using LL = long long ;
using uint = unsigned int ;
#define int long long
#define fir first
#define sec second
#define pb push_back
#define mp(x , y) make_pair(x , y)
template < typename T > inline void read(T & x) { x = 0 ; int f = 1 ; register char c = getchar() ;
  for( ; ! isdigit(c) ; c = getchar()) if(c == '-') f = -1 ;
  for( ; isdigit(c) ; c = getchar()) x = (x << 1) + (x << 3) + (c & 15) ;
  x *= f ;
}
template < typename T > inline void print(T x) {
  if(! x) { putchar('0') ; return ; }
  static int st[105] ;
  if(x < 0) putchar('-') , x = -x ;
  int tp = 0 ;
  while(x) st[++ tp] = x % 10 , x /= 10 ;
  while(tp) putchar(st[tp --] + '0') ;
}
template < typename T > inline void print(T x , char c) { print(x) ; putchar(c) ; }
template < typename T , typename ...Args > inline void read(T & x , Args & ...args) { read(x) ; read(args...) ; }
template < typename T > inline void sort( vector < T > & v) { sort(v.begin() , v.end()) ; return ; }
template < typename T > inline void unique( vector < T > & v) { sort(v) ; v.erase(unique(v.begin() , v.end()) , v.end()) ; }
template < typename T > inline void cmax(T & x , T y) { if(x < y) x = y ; return ; }
template < typename T > inline void cmin(T & x , T y) { if(x > y) x = y ; return ; }
const int Mod = LLONG_MAX ;
inline int QP(int x , int y) { int ans = 1 ;
  for( ; y ; y >>= 1 , x = (x * x) % Mod)
    if(y & 1) ans = (ans * x) % Mod ;
  return ans ;
}
template < typename T > inline T gcd(T x , T y) { if(y == 0) return x ; return gcd(y , x % y) ; }
template < typename T > inline T lcm(T x , T y) { return x * y / gcd(x , y) ; }
template < typename T > inline void mul(T & x , T y) { x = 1LL * x * y ; if(x >= Mod) x %= Mod ; }
template < typename T > inline void add(T & x , T y) { if((x += y) >= Mod) x -= Mod ; }
template < typename T > inline void sub(T & x , T y) { if((x -= y) < 0) x += Mod ; }

signed main() { int n ; read(n) ;
  int f = 0 ;
  for(register int i = 1 ; i <= sqrt(n) ; i ++)
    if(! (n % i) && n / i <= 9 && i <= 9) f = 1 ;
  puts(f ? "Yes" : "No") ;
}

Measured memory_bytes: 256
import math

# インプットデータを受け取る
x1, y1, x2, y2 = map(float, input().split())

# 2点間の距離を求める
sub1 = abs(x1 - x2)
sub2 = abs(y1 - y2)
dstncsqr = sub1 ** 2 + sub2 ** 2
print(math.sqrt(dstncsqr))



Measured memory_bytes: 5652
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))

def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]
def S(): return sys.stdin.readline().rstrip()
def LS(): return sys.stdin.readline().split()
def LS2(N): return [sys.stdin.readline().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 998244353
INF = float("inf")
sys.setrecursionlimit(10**6+10)
input = sys.stdin.readline

A,B,C,K = MI()
ans = 0
if K<=A:
    print(K)
elif K<=A+B:
    print(A)
else:
    print(2*A+B-K)


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

#define rep(i,b) for(long long i = 0; i < (b); i++)
#define all(a) a.begin(),a.end()
#define allr(a) a.rbegin(),a.rend()
using ll = long long;

ll lcm(ll a,ll b){
	
	return (a*b)/(__gcd(a,b));
}
void solve() 
{
ll n;
cin>>n;
ll d;
cin>>d;
ll ans=0;
rep(i,n){
	ll x,y;
	cin>>x>>y;
	if(x*x+y*y<=d*d){
		ans++;
	}
}
cout<<ans;

}



int  main(){

		solve();
		cout<<endl;

}
	

	

	

	

Measured memory_bytes: 3620
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc073/tasks/abc073_d
"""
from itertools import permutations


def warshallFloyd(V, dp):
    for k in range(V):
        for i in range(V):
            for j in range(V):
                # dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])
                new_dist = dp[i][k] + dp[k][j]
                if dp[i][j] > new_dist:
                    dp[i][j] = new_dist


def main():
    N, M, R = [int(x) for x in input().split()]
    destinations = [int(x) for x in input().split()]
    dp = [[float('inf')]*(N+1) for _ in range(N+1)]
    for i in range(N+1):
        dp[i][i] = 0
    for _ in range(M):
        f, t, d = [int(x) for x in input().split()]
        dp[f][t] = dp[t][f] = d

    warshallFloyd(N+1, dp)

    minimum_cost = float('inf')
    for route in permutations(destinations, len(destinations)):
        cost = 0
        while len(route) > 1:
            f, t = route[0], route[1]
            cost += dp[f][t]
            if cost > minimum_cost:
                break
            route = route[1:]
        if cost < minimum_cost:
            minimum_cost = cost
    print(minimum_cost)


if __name__ == '__main__':
    main()
    


Measured memory_bytes: 4668
#include<bits/stdc++.h>
using namespace std;
int main(){
    string a;
    long long ans=0;
    cin>>a;
    if(a[0]!='C') ans++;
    if(a[1]!='O') ans++;
    if(a[2]!='D') ans++;
    if(a[3]!='E') ans++;
    if(a[4]!='F') ans++;
    if(a[5]!='E') ans++;
    if(a[6]!='S') ans++;
    if(a[7]!='T') ans++;
    if(a[8]!='I') ans++;
    if(a[9]!='V') ans++;
    if(a[10]!='A') ans++;
    if(a[11]!='L') ans++;
    if(a[12]!='2') ans++;
    if(a[13]!='0') ans++;
    if(a[14]!='1') ans++;
    if(a[15]!='6') ans++;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
def main():

    S = input()

    n = len(S)

    candid0 = [i % 2 for i in range(n)]
    candid1 = [1 - (i % 2) for i in range(n)]

    count0 = 0
    count1 = 0
    for i in range(n):
        if int(S[i]) == candid0[i]:
            count0 += 1
        if int(S[i]) == candid1[i]:
            count1 += 1

    print(min(count0, count1))


main()


Measured memory_bytes: 4724
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
import java.util.ArrayList;

public class Main {
	Scanner sc = new Scanner(System.in);
	int n, m;
	int[] p; 
	Pair[] pairs;
	public void run(){
		n = sc.nextInt();
		m = sc.nextInt();
		p = new int[n];
		for(int i = 0; i < n; i++){
			p[i] = sc.nextInt() - 1;
		}
		pairs = new Pair[m];
		for(int i = 0; i < m; i++){
			int x = sc.nextInt() - 1;
			int y = sc.nextInt() - 1;
			
			if(x < y) pairs[i] = new Pair(x, y);
			else pairs[i] = new Pair(y, x);
		}
		
		solve();
	}
	public void solve(){
		UnionFind uf = new UnionFind(n);
		int gnum = 0;
		for(int i = 0; i < m; i++){
			Pair npair = pairs[i];
			uf.unite(npair.first, npair.second);
		}
		
		int ans = 0;
		
		for(int i = 0; i < n; i++){
			if(uf.same(i,  p[i])){
				ans = ans + 1;
			}
		}
		
		System.out.println(ans);
	}
	
	public static void main(String[] args){
		new Main().run();
	}
	
	static class Pair {
        int first,second;
        public Pair(int a,int b) {
            this.first = a;
            this.second = b;
        }
    }	
	
	static class UnionFind{
		int par[];
		int rank[];
		
		public UnionFind(int t){
			par = new int[t];
			rank = new int[t];
			
			for(int i = 0; i < t; i++){
				par[i] = i;
				rank[i] = 0;
			}
		}
		
		int find(int x){
			if(par[x] == x){
				return x;
			}
			else{
				return par[x] = find(par[x]);
			}
		}
		
		void unite(int x, int y){
			x = find(x);
			y = find(y);
			if(x == y) return;
			
			if(rank[x] < rank[y]){
				par[x] = y;
			} else{
				 par[y] = x;
				 if(rank[x] == rank[y]) rank[x]++;
			}
			
		}
		
		boolean same(int x, int y){
			return find(x) == find(y);
		}
	}
}


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

int main() {
  int n, k;
  std::cin >> n >> k;
  std::vector<int> l(n);
  for (int i = 0; i < n; i++) {
    int v;
    std::cin >> v;
    l.push_back(v);
  }
  std::sort(l.begin(), l.end(), std::greater<int>());
  int max = 0;
  for (int i=0; i < k; i++)
    max += l[i];
  std::cout << max << std::endl;
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long

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

  ll N,M,pow=1; cin >> N >> M;
  for (ll i = 1; i <= N; ++i) pow *= 2;
  vector<ll> z(N,0);
  vector<vector<ll>> v(pow,z);
  for (ll i = 0; i < pow; ++i) {
    ll pow_tmp = pow;
    ll ii = i, pos = N;
    while (ii > 0) {
      if (ii - pow_tmp >= 0) {
        (v[i])[pos] += 1;
        ii -= pow_tmp;
      }
      pos -= 1;
      pow_tmp /= 2;
    }
  }
  vector<vector<ll>> svec(M);
  for (ll i = 0; i < M; ++i) {
    ll k; cin >> k;
    vector<ll> s(k);
    for (ll j = 0; j < k; ++j) cin >> s[j];
    svec[i] = s;
  }
  vector<ll> p(M);
  for (ll i = 0; i < M; ++i) cin >> p[i];

  ll ans = 0;
  for (ll i = 0; i < pow; ++i) {
    bool consistent = true;
    for (ll s_itr = 0; s_itr < M; ++s_itr) {
      ll check = 0;
      for (ll k_itr = 0; k_itr < svec[s_itr].size(); ++k_itr)
        check += (v[i])[(svec[s_itr])[k_itr]-1];
      if (check%2 != p[s_itr]) {
        consistent = false;
        break;
      } 
    }
    if (consistent) ans += 1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ri register int
namespace io {
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	// getchar
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	// print the remaining part
	inline void flush () {
		fwrite (obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	// putchar
	inline void putc (char x) {
		*oS ++ = x;
		if (oS == oT) flush ();
	}
	// input a signed integer
	template <class I>
	inline void gi (I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = (x << 1) + (x << 3) + (c & 15); x *= f;
	}
	// input a letter
	template <class I>
	inline void get (I &x) {
		for (c = gc(); c < 'A' || c > 'Z'; c = gc()) ;
		x = c;
	}
	// input a string
	inline void read (char *s){
		for(c = gc(); c < 'A' || c > 'Z'; c = gc()) ;
		for(; c >= 'A' && c <= 'Z'; c = gc()) *++s = c;
		*++s = '\0';
	}
	// print a signed integer
	template <class I>
	inline void print (I x) {
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10;
		while (qr) putc (qu[qr --]);
	}
	//no need to call flush at the end manually!
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io :: gi;
using io :: get;
using io :: read;
using io :: putc;
using io :: print;
const int N=1e5+5,mod=1e9+7;
int ny,a[N],b[N],px[N],py[N],f[N];
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
pii p[N];
inline void add(int &x,ri y){
	x=(x+=y)>=mod?x-mod:x;
}
struct bitree{
	int v[N];
	inline void upd(ri i,ri x){
		for(;i<=ny;i+=i&-i)
			add(v[i],x);
	}
	inline int query(ri i){
		ri s=0;
		for(;i;i-=i&-i)
			add(s,v[i]);
		return s;
	}
}bit;
int main(){
	ri n,m,i,cnt,nx,ans;
	gi(n);gi(m);
	for(i=1;i<=n;++i) gi(a[i]);
	for(i=1;i<=m;++i) gi(b[i]);
	cnt=0;
	for(i=1;i<=n;++i){
		if(a[i]<=b[1]||a[i]>=b[m]) continue;
		p[++cnt]=mp(b[lower_bound(b+1,b+1+m,a[i])-b]-a[i],a[i]-b[upper_bound(b+1,b+1+m,a[i])-b-1]);
	}
//	for(i=1;i<=cnt;++i) printf("%d %d\n",p[i].fi,p[i].se);
	for(i=1;i<=cnt;++i) px[i]=p[i].fi,py[i]=p[i].se;
	sort(px+1,px+1+cnt);
	sort(py+1,py+1+cnt);
	nx=unique(px+1,px+1+cnt)-px-1;
	ny=unique(py+1,py+1+cnt)-py-1;
	for(i=1;i<=cnt;++i)
		p[i].fi=lower_bound(px+1,px+1+nx,p[i].fi)-px,
		p[i].se=lower_bound(py+1,py+1+ny,p[i].se)-py;
	sort(p+1,p+1+cnt,[&](pii a,pii b){
		return a.fi==b.fi?a.se>b.se:a.fi<b.fi; 
	});
	cnt=unique(p+1,p+1+cnt)-p-1; 
//	for(i=1;i<=cnt;++i) printf("%d %d\n",p[i].fi,p[i].se);
	ans=1; // (0,0) -> (inf,inf)
	for(i=1;i<=cnt;++i)
		f[i]=1+bit.query(p[i].se-1),
	//	printf("f %d %d\n",i,f[i]),
		bit.upd(p[i].se,f[i]),
		add(ans,f[i]);
	printf("%d\n",ans);
	return 0;
}

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

long long N,maxW;
long long dp[102][100002];
struct asdfklj{
    long long val,w;
}arr[102];

long long knapsack(long long i, long long current){
    if(current<0)return INT_MAX;
    if(current==0)return 0;
    if(i==N)return INT_MAX;
    long long &ret=dp[i][current];
    if(ret!=-1)return ret;
    return ret = min(arr[i].w+knapsack(i+1,current-arr[i].val), knapsack(i+1,current));
}

int main(){
    cin>>N>>maxW;
    memset(dp,-1,sizeof(dp));
    for(long long i=0; i<N; i++)cin>>arr[i].w>>arr[i].val;
    for(long long i=100000;;i--)
        if(knapsack(0,i)<=maxW)
            printf("%d",i),exit(0);
}


Measured memory_bytes: 80000
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class TaskC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long n = in.nextLong(), y = in.nextLong();
            for (int i = 0; i <= n; i++) {
                for (int j = 0; j <= n - i; j++) {
                    long res = 10000 * i + 5000 * j;
                    long last = (y - res) / 1000;
                    if (res <= y && (y - res) % 1000 == 0 && i + j + last == n) {
                        out.println(i + " " + j + " " + last);
                        return;
                    }
                }

            }

            out.println(-1 + " " + -1 + " " + -1);
        }

    }
}



Measured memory_bytes: 22996
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
    Scanner sc = new Scanner(System.in);
     int i = sc.nextInt();
     int j = sc.nextInt();
int c = 1000;
int count =0;
        for(int k =0;k<i;k++){

     int x = sc.nextInt();
     int  y = sc.nextInt();
     if(j >= y){
     
     
     if(c > x){

        c =x;
      } 
     
count = 1;

      }
}
if(count == 1){
   System.out.println(c);
    }

if(count == 0){
   System.out.println("TLE");
    }
}

}


Measured memory_bytes: 23124
x, y = map(int, input().split())
group1 = [1, 3, 5, 7, 8, 10, 12]
group2 = [4, 6, 9, 11]

flag = False
if x in group1 and y in group1:
    flag = True
elif x in group2 and y in group2:
    flag = True
    
if flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9060
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define fi first
#define se second
#define inf (INT_MAX/2-1)
#define infl (1LL<<60)
#define vi vector<int>
#define pb push_back
#define sz(a) (int)(a).size()
#define all(a) begin(a),end(a)
#define y0 y5656
#define y1 y7878
#define aaa system("pause");
#define dbg(x) cerr<<(#x)<<": "<<(x)<<'\n',aaa
#define dbga(x,n) cerr<<(#x)<<"[]: ";for(int _=0;_<n;_++)cerr<<x[_]<<' ';cerr<<'\n',aaa
#define dbgs(x) cerr<<(#x)<<"[stl]: ";for(int _:x)cerr<<_<<' ';cerr<<'\n',aaa
#define dbgp(x) cerr<<(#x)<<": "<<x.fi<<' '<<x.se<<'\n',aaa

using namespace std;

int main () {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  string s; cin >> s;
  ll ans = 0;
  for (char ch: s) ans += ch-'0';
  if (ans%9 == 0) cout << "Yes";
  else cout << "No";
  return 0;
}


Measured memory_bytes: 3800
#include<stdio.h>

int main(void){
    
    int W, H, x, y, r;
    
    scanf("%d", &W);
    scanf("%d", &H);
    scanf("%d", &x);
    scanf("%d", &y);
    scanf("%d", &r);
    
    if(((x - r) >= 0 ) && ((y - r) >= 0 ) && ((x + r) <= W) && ((y + r) <= H))
        printf("Yes\n");
    else
        printf("No\n");
        
    return 0;
}


Measured memory_bytes: 2104
def main():
    N,T=map(int,input().split())
    A=[0 for i in range(0,N)]
    B=[0 for i in range(0,N)]
    for i in range(0,N):
        A[i],B[i]=map(int,input().split())
    C=[[A[i],B[i]] for i in range(0,N)]
    C.sort()
    B=[C[i][1] for i in range(0,N)]
    A=[C[i][0] for i in range(0,N)]
    dp=[[0 for j in range(0,T+1)] for i in range(0,N+1)]#i番目までの料理でT分までの注文での満足度最大値
    for i in range(0,N):
        for j in range(1,T+1):
            if j-A[N-1-i]<0:
                dp[i+1][j]=max(dp[i][j],B[N-1-i])
            else:
                dp[i+1][j]=max(dp[i][j],dp[i][j-A[N-1-i]]+B[N-1-i])
    print(dp[N][T])

if __name__ == '__main__':
    main()


Measured memory_bytes: 125784
def cmb(n, r, p):
    r = min(r, n - r)

    # n*(n-1)*...*(n-r+1)
    # 組み合わせの分子
    upper = 1
    for i in range(n, n - r, -1):
        upper = (upper * i) % p

    # 1*2*...*r
    # 組み合わせの分母
    lower = 1
    for i in range(1, r + 1):
        lower = (lower * i) % p
    # 剰余の計算において、+-*は良いが、/は普通にやると成り立たない
    # 割るのではなく、「逆元」を掛けるとする
    # フェルマーの小定理より、pが素数なら1/lowerの逆元はlower**(p-2)
    # powの第3引数を使うことで繰り返し二乗法になる
    return (upper * pow(lower, p - 2, p)) % p


mod = pow(10, 9) + 7
n, a, b = map(int, input().split())
# 全ての選び方-何も選ばない時-a本の時-b本の時
ans = (pow(2, n, mod) - 1 - cmb(n, a, mod) - cmb(n, b, mod)) % mod
print(ans)


Measured memory_bytes: 63484
X =int( input())
if 400<= X and X<=599:
  print("8")
elif 600<= X and X<=799:
  print("7")
elif 800<= X and X<=999:
  print("6")
elif 1000<= X and X<=1199:
  print("5")
elif 1200<= X and X<=1399:
  print("4")
elif 1400<= X and X<=1599:
  print("3")
elif 1600<= X and X<=1799:
  print("2")
elif 1800<= X and X<=1999:
  print("1")

Measured memory_bytes: 9204
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#define N 100005
using namespace std;
bool dp[N];
string s;
int main() {
  cin>>s;
  memset(dp, false, sizeof(dp));
  int n = s.size();
  dp[0] = true;
  for (int i = 1; i <= n; ++i) {
    if (i >= 5 && (s.substr(i-5, 5) == "erase" || s.substr(i-5, 5) == "dream")) {
      if (dp[i-5] == true) dp[i] = true;
    } else if (i >= 6 && (s.substr(i-6, 6) == "eraser")) {
      if (dp[i-6]) dp[i] = true;
    } else if (i >= 7 && (s.substr(i-7, 7) == "dreamer")) {
      dp[i] |= dp[i-7];
    }
  }
  if (dp[n]) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
	return 0;
}


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

public class AtCoder_Pana_D
{
    public static void Main()
    {
        string[] a = new string[]
        {
            "a", "b", "c", "d", "e", "f", "g", "h", "i", "j"
        };

        int n = int.Parse(Console.ReadLine());

        List<List<List<int>>> lists = new List<List<List<int>>>();
        var list0 = new List<List<int>>();
        list0.Add(new List<int>{0});
        lists.Add(list0);

        for (int i = 1; i < n; i++)
        {
            lists.Add(new List<List<int>>());
            var prevList = lists[i - 1];
            for (int j = 0; j < prevList.Count; j++)
            {
                var prefixs = prevList[j];
                for (int k = 0; k <= prefixs.Max() + 1; k++)
                {
                    var addList = new List<int>();
                    addList.AddRange(prefixs);
                    addList.Add(k);
                    lists[i].Add(addList);
                }
            }
        }

        var nList = lists[n - 1];
        var sb = new StringBuilder();
        for (int i = 0; i < nList.Count; i++)
        {
            var nums = nList[i];
            for (int j = 0; j < nums.Count; j++)
            {
                sb.Append(a[nums[j]]);
            }
            sb.AppendLine();
        }

        Console.Write(sb.ToString());
    }
}


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



int main(){
    int n;
    cin >> n;
    vector<ll> ryuka(87);
    ryuka[0] = 2;
    ryuka[1] = 1;
    repa(i, 2, 87){
        ryuka[i] = ryuka[i-1] + ryuka[i-2];
    }

    cout << ryuka[n] << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <string.h>

using namespace std;

int main()
{
	long long subS;
	int i, n, m, Mod, count, t;
	string str;
	int p = 2019;
	int DP[2019];

	for (i = 0; i < p;i++)
		DP[i] = 0;
	DP[0]++;
	cin >> str;
	n = str.size();
	t = 1;
    subS = 0;
	for (i = n-1; i >=0; i--) {
		subS += t*(str[i]-'0');
		subS %= p;
		t *= 10; t %= p;
		Mod =  subS % p;
		// fprintf(stderr, "i: %d, SubS: %ld, %d (mod2019)\n",i, subS, Mod);
		DP[Mod]++;
	}
	count = 0;
	for (i = 0; i < p;i++) {
		m = DP[i];
		if (m > 1)
			count += m*(m-1)/2;
	}
	cout << count << endl;
	return EXIT_SUCCESS;
}


Measured memory_bytes: 3696
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;


int main(){
    ll t1, t2, a1, a2, b1, b2;
    cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;

    ll l = t1 * (b1 - a1);
    ll d = t2 * (b2 - a2) + l;

    if(d == 0) {
        cout << "infinity" << endl;
        return 0;
    }
    if ((l > 0 && d > 0) || (l < 0 && d < 0)){
        cout << 0 << endl;
        return 0;
    }

    l = abs(l);
    d = abs(d);

    if (l % d != 0) cout << 2 * (l/d) + 1 << endl;
    else cout << 2*(l/d) << endl;

    return 0;
}


Measured memory_bytes: 3648
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
#include <queue>
typedef long long ll;
using namespace std;
const int maxn = 1E5 + 5;
int n;
ll a[maxn];
vector<ll> sco1, sco2;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	string S;
	cin >> S;
	ll ans = 0;
	int len = S.length();
	ll l = 0;
	for(int i = 0; i < len; i++){
		if(S[i] == 'B'){l = i; break;}
	}
	for(int i = l; i < len; i++){
		if(S[i] == 'W'){
			ans = ans + (i - l);
			l++;
		}
	}
	cout << ans << endl;
	return 0 ;
}

Measured memory_bytes: 720
n,m=map(int,input().split())
INF=10**18
e=[[INF for _ in range(n)]for _ in range(n)]
d=[]
for i in range(m):
  a,b,c=map(int,input().split())
  e[a-1][b-1]=c
  e[b-1][a-1]=c
  d.append((a-1,b-1,c))
for k in range(n):
  for i in range(n):
    for j in range(n):
      e[i][j]=min(e[i][j],e[i][k]+e[k][j])
ans=0
for i,j,k in d:
  if e[i][j]!=k:ans+=1
print(ans)

Measured memory_bytes: 9328
# -*- coding: utf-8 -*-
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys

def s():
    return raw_input().strip()
def n():
    return int(raw_input())
def d():
    return float(raw_input())

def ls():
    return raw_input().strip().split()
def ln():
    return map(int, raw_input().strip().split())
def ld():
    return map(float, raw_input().strip().split())

def fs():
    return [raw_input().strip() for i in xrange(input())]
def fn():
    return [int(raw_input().strip()) for i in xrange(input())]
def fd():
    return [float(raw_input().strip()) for i in xrange(input())]

S = fs()

char = {c: 1000 for c in string.lowercase}


for s in S:
    count = collections.Counter(s)
    for c in string.lowercase:
        if count[c] < char[c]:
            char[c] = count[c]

result = ''
for c in char:
    result += c * char[c]

print result


Measured memory_bytes: 34792
//
//  B - Count ABC.cpp
//  Practice
//
//  Created by Hajime Sakamoto on 2020/01/10.
//  Copyright © 2020 Hajime Sakamoto. All rights reserved.
//

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <iterator>

using namespace std;


int main(){
    
    int N;
    string S;
    int Count=0;
    
    cin >>N;
    cin >>S;
    
    
    for (int i=0; i<N-2; i++){
        if (S[i]=='A'){
            if (S[i+1]=='B'){
                if (S[i+2]=='C'){
                    Count++;
                }
            }
        }
    }

    
    cout <<Count;
    
    return 0;
    
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
long long a[1000010];
int main()
{
    int n,x=1,ans=0;//x表示一个数出现的次数，赋值1
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>a[i];
    sort(a,a+n);//先排序，判断奇偶
    for(int i=1; i<n; i++)
    {
        if(a[i]==a[i-1])//出现相同的数，x+1然后mod2
            x=(x+1)%2;
        else
        {
            ans+=x;///单独的一个数，ans+1，x重新赋值为1，进行循环
            x=1;
        }
    }
    if(x%2)///再次判断 ，若不为0，则ans+1
        ans++;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int a[201];
int n;
void shuffle(int k);

int main(){

	int m;
	int k;
	int i;

	scanf("%d\n",&n);
	for(i=0;i<2*n;i++){
		a[i]=i+1;
	}
	for(i=2*n;i<201;i++){
		a[i]=0;
	}
	scanf("%d\n",&m);
	for(i=0;i<m;i++){
		scanf("%d\n",&k);
		shuffle(k);
	}

	for(i=0;i<2*n;i++)printf("%d\n",a[i]);

	return 0;
}

void shuffle(int k){

	int buf[201];
	int i;

	if(k==0){
		for(i=0;i<2*n;i++){
			if(i<n)buf[2*i]=a[i];
			if(i>=n)buf[2*(i-n)+1]=a[i];
		}
	}
	
	if(k>0){
		for(i=0;i<2*n;i++){
			if(i<k)buf[2*n-k+i]=a[i];
			if(i>=k)buf[i-k]=a[i];
		}
	}
	for(i=0;i<2*n;i++)a[i]=buf[i];
	return;

}

Measured memory_bytes: 600
from functools import reduce
n = int(input())
A = list(map(int,input().split()))
b = sorted(A,reverse=True)
c = 1
if b[-1] == 0:
    c = 0
else:
    for i in range(n):
        if c > 10 ** 18:
            break
        c *= b[i]
    

if c > 10**18:
    print(-1)
else:
    print(c) 

Measured memory_bytes: 22944
#include <stdio.h>
int main(){
 int n;
 scanf("%d",&n);
 int p[n];
 for(int a=0;a<n;a++){
     scanf("%d",&p[a]);
 }
 int count=0;
 for(int b=0;b<n-1;b++){
     for(int c=1;c<n-b;c++){
         if(count==0){
             if(p[b]>p[b+c]){int tmp=b+c;int tmp3=p[b+c];
                 for(int d=1;d<n-b-c;d++){
                     if(tmp3>p[b+c+d]){tmp3=p[b+c+d];tmp=b+c+d;}}
                     int tmp2;
                     tmp2=p[b];
                     p[b]=p[tmp];
                     p[tmp]=tmp2;
                     count++;}
             else{}
         }
         else{if(p[b]<p[b+c]){}
              else{printf("NO\n");return 0;}}
     }
 }
 printf("YES\n");
 return 0;
}

Measured memory_bytes: 128
n,m = map(int,input().split())
procedure = []
for i in range(m):
    x,y = map(int,input().split())
    procedure.append([x-1,y-1])

exist = [False for i in range(n)]
counts = [1 for i in range(n)]
exist[0] = True

for i in range(m):
    counts[procedure[i][0]] += -1
    counts[procedure[i][1]] += 1
    if exist[procedure[i][0]]:
        exist[procedure[i][1]] = True
    if counts[procedure[i][0]] == 0:
        exist[procedure[i][0]] = False

counter = 0
for i in range(n):
    if exist[i]:
        counter += 1

print(counter)


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

using namespace std;

typedef pair< int,int > PII;
typedef long long int lo;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid (bas+son)/2

const lo MAX = -1000000000000000000; 
const lo MIN = 1000000000000000000; 
const lo inf = 1000000000; 
const lo KOK = 100000; 
const lo LOG = 30; 
const lo li = 100005; 
const lo mod = 1000000007; 

lo n,m,cev,b,a[li],dp[3005][3005][5];
string s;
vector<int> v;

lo f(lo bas,lo son,lo sira){
	if(bas>son){
		return 0;
	}
	if(~dp[bas][son][sira]) return dp[bas][son][sira];
	if(sira==0){
		return dp[bas][son][sira]=max(f(bas+1,son,1)+a[bas],f(bas,son-1,1)+a[son]);
	}
	else{
		return dp[bas][son][sira]=min(f(bas+1,son,0)-a[bas],f(bas,son-1,0)-a[son]);
	}
}

int main(){
	memset(dp,-1,sizeof(dp));
	scanf("%lld",&n);
	FOR{
		scanf("%lld",&a[i]);
	}
	printf("%lld\n",f(1,n,0));
	return 0;
}


Measured memory_bytes: 353152
// A New Plan of Aizu Ski Resort
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int w = sc.nextInt(), h = sc.nextInt();
			if ((w | h) == 0)
				break;
			int[][] field = new int[h][w];
			int[][] dp = new int[h][w];
			for (int i = 0; i < h; i++)
				for (int j = 0; j < w; j++)
					field[i][j] = sc.nextInt();
			for (int i = 0; i < w; i++)
				if (field[0][i] == 0)
					dp[0][i] = 1;
			for (int i = 0; i < h - 1; i++) {
				for (int j = 0; j < w; j++) {
					switch (field[i][j]) {
					case 0:
						if (field[i + 1][j] != 1)
							dp[i + 1][j] += dp[i][j];
						if (j >= 1 && field[i + 1][j - 1] == 0)
							dp[i + 1][j - 1] += dp[i][j];
						if (j < w - 1 && field[i + 1][j + 1] == 0)
							dp[i + 1][j + 1] += dp[i][j];
						break;
					case 2:
						if (i < h - 2 && field[i + 2][j] != 1)
							dp[i + 2][j] += dp[i][j];
						break;
					}
				}
			}
			int result = 0;
			for (int i = 0; i < w; i++) {
				result += dp[h - 1][i];
				if (h >= 2 && field[h - 2][i] == 2)
					result += dp[h - 2][i];
			}
			System.out.println(result);
		}
		sc.close();
	}
}

Measured memory_bytes: 23476
#include<cmath>
#include<iostream>
#include<cstdio>
#include<iomanip>
using namespace std;



int main() {
	int n;
	char e;
	int suji;
	int t[4][13] = {};
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> e >> suji;
		switch (e) {
		case 'S':t[0][suji - 1] = 1; break;
		case 'H':t[1][suji - 1] = 1; break;
		case 'C':t[2][suji - 1] = 1; break;
		case 'D':t[3][suji - 1] = 1; break;
		}
	}
	for (int j = 0; j < 4; j++) {

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

			if (!t[j][k]) {
				switch (j) {
				case 0:cout << "S "; break;
				case 1:cout << "H "; break;
				case 2:cout << "C "; break;
				case 3:cout << "D "; break;
				}
				cout << k + 1 << endl;
			}
		}
	}
	//cout << endl;

	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <utility>
#include <numeric>
#include <iomanip>
#include <locale>
#include <map>
#include <set>
#include <queue>
#include <cstdlib>
#include <cmath>

using namespace std;

pair<int, vector<int> > read();
long think(const pair<int, vector<int> > &);
void write(long);

int main(int argc, char* argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);

  auto input = read();
  auto output = think(input);
  write(output);

  return 0;
}

pair<int, vector<int> > read() {
  int n, m, buf;

  scanf("%d %d", &n, &m);
  auto a = vector<int>(m, 0);

  for (int i = 0; i < m; i++) {
    scanf("%d", &buf);
    a.at(i) = buf;
  }
  return make_pair(n, a);
}

long think(const pair<int, vector<int> > &input) {
  long mode = 1000000007;
  long INVALID = -1;
       
  auto n = input.first;
  auto a = input.second;

  auto ways = vector<long>(n + 1, 0);
  for (auto e : a) {
    ways.at(e) = INVALID;
  }
  ways.at(0) = 1;

  for (int i = 1; i < ways.size(); i++) {
    if (ways.at(i) == INVALID) {
      continue;
    }
    ways.at(i) += (ways.at(i - 1) == INVALID ? 0 : ways.at(i - 1));
    if (i >= 2) {
      ways.at(i) += (ways.at(i - 2) == INVALID ? 0 : ways.at(i - 2));
    }
    ways.at(i) %= mode;
  }
  return ways.at(ways.size() - 1);
}

void write(long output) {
  cout << output << endl;
}



Measured memory_bytes: 1784
#include <bits/stdc++.h>
using namespace std;
int main()

{
  string str;
  cin >> str;
  if(str.size() < 4){
    cout << "No" << endl;
    return 0;
  }
  if(str[0] == 'Y'&&str[1]=='A'&&str[2]=='K'&&str[3]=='I'){
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
import itertools

N,M,Q=map(int,input().split())
a_list,b_list,c_list,d_list=[],[],[],[]
for _ in range(Q):
    a,b,c,d=map(int,input().split())
    a_list.append(a);b_list.append(b);c_list.append(c);d_list.append(d)

score_max=0
for A in itertools.combinations_with_replacement(list(range(1,M+1)), N):
    score=0
    for i in range(Q):
        if A[b_list[i]-1]-A[a_list[i]-1]==c_list[i]:
            score+=d_list[i]
    score_max=max(score,score_max)
print(score_max)

Measured memory_bytes: 9192
#include <iostream>
#include <vector>
#include <string>

using namespace std;

struct yx{
  int y, x;
  yx(int _y, int _x) : y(_y), x(_x){}
};

const int LL = 10000000;

int main(void){
  int h, w;
  cin >> h >> w;
  vector<vector<int> > v = vector<vector<int> >();
  v.reserve(h);
  vector<yx> st = vector<yx>();
  for(int i = 0; i < h; ++i){
    string str;
    cin >> str;
    vector<int> vv = vector<int>();
    vv.reserve(w);
    for(int j = 0; j < w; ++j){
      if (str[j] == '#'){
        vv.push_back(0);
      }else{
        vv.push_back(LL);
        st.push_back(yx(i, j));
      }
    }
    v.push_back(vv);
  }
  while(true){
    vector<yx> st2 = vector<yx>();
    for(yx p : st){
      int init = v[p.y][p.x];
      if (p.y != 0 && v[p.y-1][p.x] != LL){
        if (v[p.y-1][p.x]+1 < v[p.y][p.x]){
          v[p.y][p.x] = v[p.y-1][p.x]+1;
        }
      }
      if (p.y != h-1 && v[p.y+1][p.x] != LL){
        if (v[p.y+1][p.x]+1 < v[p.y][p.x]){
          v[p.y][p.x] = v[p.y+1][p.x]+1;
        }
      }
      if (p.x != 0 && v[p.y][p.x-1] != LL){
        if (v[p.y][p.x-1]+1 < v[p.y][p.x]){
          v[p.y][p.x] = v[p.y][p.x-1]+1;
        }
      }
      if (p.x != w-1 && v[p.y][p.x+1] != LL){
        if (v[p.y][p.x+1]+1 < v[p.y][p.x]){
          v[p.y][p.x] = v[p.y][p.x+1]+1;
        }
      }
      if (init != v[p.y][p.x]){
        if (p.y != 0 && v[p.y-1][p.x] > v[p.y][p.x]+1){
          st2.push_back(yx(p.y-1, p.x));
        }
        if (p.y != h-1 && v[p.y+1][p.x] > v[p.y][p.x]+1){
          st2.push_back(yx(p.y+1, p.x));
        }
        if (p.x != 0 && v[p.y][p.x-1] > v[p.y][p.x]+1){
          st2.push_back(yx(p.y, p.x-1));
        }
        if (p.x != w-1 && v[p.y][p.x+1] > v[p.y][p.x]+1){
          st2.push_back(yx(p.y, p.x+1));
        }
      }
    }
    if (st2.empty()){
      break;
    }
    st = vector<yx>();
    for(int i = 0; i < st2.size(); ++i){
      st.push_back(st2[i]);
    }
  }
  int maxvar = 0;
  for(int i = 0; i < h; ++i){
    for(int j = 0; j < w; ++j){
      if (maxvar < v[i][j]){
        maxvar = v[i][j];
      }
    }
  }
  cout << maxvar << endl;
}


Measured memory_bytes: 43800
#include<iostream>
using namespace std;
int main(){
	int N;
  	int summ = 0;
  	cin >>N;
  int N1 = N;
  while(N1){
  	summ += N1%10;
    N1 /= 10;
  }
  (N%summ == 0)? cout << "Yes"<<'\n': cout << "No"<<'\n';
  return 0;
}

Measured memory_bytes: 256