akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main()
{
  string s;
  cin >> s;
  string ans = "Yes";
  for (int i=0; i<s.size(); i++) {
    if (i%2 && s[i]=='R') ans = "No";
    if (!(i%2) && s[i]=='L') ans = "No";
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

#define ll long long 
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mkp make_pair
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define ff first
#define ss second
#define endl "\n"
#define MOD 1000000007
#define MOD1 998244353
#define inf LLONG_MAX

ll GCD(ll x,ll y){if(y==0)return x;return GCD(y,x%y);}
ll LCM(ll x,ll y){return (x*y)/(GCD(x,y));}
ll LOGK(ll x,ll k){if(x>=k)return 1+LOGK(x/k,k);return 0;}
ll MPOW( ll a, ll b, ll m) { if(b==0) return 1; ll x=MPOW(a,b/2,m); x=(x*x)%m; if(b%2==1) x=(x*a)%m; return x;}
ll MINV(ll a,ll m) {return MPOW(a,m-2,m);}

class pnc{
  ll FACT_MAX,MODU;
  vector<ll> fact;
public:
  pnc( ll n, ll m) { FACT_MAX = n; fact.resize(FACT_MAX); MODU = m; MFACT_INIT(MODU);}
  void MFACT_INIT( ll m) { fact[0]=1; for(ll i=1;i<FACT_MAX;++i) fact[i]=(i*fact[i-1])%MODU;}
  ll MFACT( ll n) { return fact[n];}
  ll PERM( ll n, ll r) { return (fact[n]*::MINV(fact[n-r],MODU))%MODU;}
  ll COMB( ll n , ll r) { return (PERM(n,r)*::MINV(fact[r],MODU))%MODU;}
};

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);    

    ll test=1;
    //cin>>test;
    while(test--)
    {
        ll n,m,x;
        cin>>n>>m>>x;

        ll ar[15][15];
        ll cost[15];

        for(ll i=0;i<n;i++)
        {
            for(ll j=0;j<m;j++)
            {
                if(j==0)
                {
                    cin>>cost[i]>>ar[i][j];
                }
                else
                {
                    cin>>ar[i][j];
                }
                
            }
        }

        ll ans=inf;
        ll check[15]={0};

        for(ll i=1;i<pow(2,n);i++)
        {
            ll tcost=0;
            for(ll pp=0;pp<12;pp++)
            check[pp]=0;
            
            for(ll k=0;k<12;k++)
            {
                ll val=(i>>k)&1;

                if(val)
                {
                    for(ll j=0;j<m;j++)
                    {
                        check[j]+=ar[k][j];
                    }

                    tcost+=cost[k];
                }
            }
            ll ff=1;

            for(ll ii=0;ii<m;ii++)
            {
                if(check[ii]<x)
                {
                    ff=0;
                    break;
                }
            }

            if(ff==1)
            {
                ans=min(ans,tcost);
            }
        }

        if(ans==inf)
        cout<<-1;
        else
        cout<<ans;

    }
}














Measured memory_bytes: 4124
#include<cstdio>
int main() {
	int n, l, r, m;
	char lc, tmp[7];
	scanf("%d", &n);
	l = 0;
	r = n;
	printf("0\n");
	fflush(stdout);
	scanf("%s", tmp);
	if (tmp[0] == 'V') return 0;
	lc = tmp[0];
	while (true) {
		m = (l + r) / 2;
		printf("%d\n", m);
		fflush(stdout);
		scanf("%s", tmp);
		if (tmp[0] == 'V')break;
		if ((lc == tmp[0]) == ((m - l - 1) % 2 == 0))r = m;
		else {
			l = m;
			lc = tmp[0];
		}
	}
	return 0;
}

Measured memory_bytes: 760
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        int[] l = new int[m];
        int[] r = new int[m];
        for (int i = 0; i < m; i++) {
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        }

        // 主処理
        int left = Arrays.stream(l).max().getAsInt();
        int right = Arrays.stream(r).min().getAsInt();

        int result = Math.max(0, right - left + 1);

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

Measured memory_bytes: 50964
N = int(input())
S = input()

ans = 0
while True:
    left_white_idx = S.find('W')
    right_red_idx  = S.rfind('R')

    if left_white_idx == -1 or right_red_idx == -1 or left_white_idx > right_red_idx:
        break

    # 左のRの連続とW　Rと右のWの連続を切り取った文字列に更新
    S = S[left_white_idx+1:right_red_idx]

    ans = ans + 1

print(ans)


Measured memory_bytes: 9452
N = int(input())
A = sorted(list(map(int,input().split())))[::-1]

for n in range(N-1):
  if A[n]==A[n+1]:
    A[n+1]=0
  else:
    A[n]=0

A = sorted(A)[::-1]
print(A[0]*A[1])

Measured memory_bytes: 20044
#include "iostream"
#include "math.h"
using namespace std;

int main()
{
	long long int n, c;
	cin >> n;
	c = n + 1;
	int a = 0;
	while (c > 10) {
		c = (c - c % 10) / 10;
		a++;
	}
	int b = a * 9 +int( (n + 1) / (pow(10, a))) - 1;
	cout << b << endl;

	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n,cost=0,cur_idx=0,prev_idx=0;
    cin>>n;
    ll arr[n+5],ans[n+5]={0};
    for (int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    ans[0]=0;
    ans[1]=abs(arr[1]-arr[0]);
    for(ll i=2;i<n;i++)
    {
        ans[i]=min((ans[i-1]+abs(arr[i]-arr[i-1])),(ans[i-2]+abs(arr[i]-arr[i-2])));
        //cout<<ans[i]<<' ';
    }
   // cout<<'\n';
    cout<<ans[n-1]<<'\n';
    return 0;
}

Measured memory_bytes: 5132
#include<bits/stdc++.h>
using namespace std;
int w,a,b,swp;
int main(){
	scanf("%d%d%d",&w,&a,&b);
	if(a>b){
		swp=a;
		a=b;
		b=swp;
	}
	if(a+w>=b){
		printf("0");
	}else printf("%d",b-(a+w));
}

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

int main() {
    ll A, B, C, ans = 0;
    cin >> A >> B >> C;
    if (A % 2 != 0 || B % 2 != 0 || C % 2 != 0) {
        cout << 0 << endl;
        return 0;
    }
    if (A == B && B == C) {
        cout << -1 << endl;
        return 0;
    }
    while (A%2==0 && B%2==0 && C%2==0)
    {
        ans++;
        ll a, b, c;
        a = (B + C) / 2;
        b = (C + A) / 2;
        c = (A + B) / 2;
        A = a;
        B = b;
        C = c;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn=3e5+10;
struct point {
    int x,y;
}p[maxn];
map<int,int> xcnt,ycnt;
signed main(void){
    int n,m,k;
    cin>>n>>m>>k;
    int x,y,maxr=0,maxc=0;
    for(int i=0;i<k;i++){
        cin>>x>>y;
        p[i]={x,y};
        xcnt[x]++,ycnt[y]++;
        maxr=max(maxr,xcnt[x]),maxc=max(maxc,ycnt[y]);
    }
    int num1=0,num2=0;
    for(auto tmp:xcnt)
		if(tmp.second==maxr)
			num1++;
    for(auto tmp:ycnt)
		if(tmp.second==maxc)
			num2++;
    int cnt=0;
    for(int i=0;i<k;i++){
        x=p[i].x,y=p[i].y;
        if(xcnt[x]==maxr&&ycnt[y]==maxc)cnt++;
    }
    if(cnt==num1*num2)
		cout<<(maxc+maxr-1)<<endl;
    else
		cout<<(maxc+maxr)<<endl;
    return 0;
}

Measured memory_bytes: 34036
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <vector>
#include <queue>
using namespace std;
const int mod = 1e9 + 7;
typedef long long ll;

int n;
int a[110], b[110];

int ha[110], hb[110];

void Swap (int x) {
	swap (ha[x], hb[x]);
	swap (ha[x + 1], hb[x + 1]);
	swap (ha[x], ha[x + 1]);
	swap (hb[x], hb[x + 1]);
}

int flag[22];
int x[22], y[22];

int find () {
	int ans = 0;
	for (int i = 1; i <= n; i ++) {
		int tg = y[i];
		int find = -1;
		for (int j = i; j <= n; j ++)
			if (x[j] == tg)
				if ((flag[j] == 1 && (j - i) % 2 == 0) || (flag[j] == -1 && (j - i) % 2 == 1)) {
					find = j;
					break;
				}
		// for (int j = 1; j <= n; j ++)
			// cerr << "[" << x[j] << " " << y[j] << " " << flag[j] << "]";
		// cerr << endl;
		if (find == -1) {
			// cerr << "cannot find: " << i << " " << tg << endl;
			return -1;
		}
		// cerr << "find: " << find << endl;
		ans += find - i;
		flag[find] = -100;
		for (int j = find; j > i; j --) {
			swap (x[j], x[j - 1]);
			flag[j] *= -1;
			flag[j - 1] *= -1;
			swap (flag[j], flag[j - 1]);
		}
	}
	return ans;
}

int main() {
	ios::sync_with_stdio(false);
	cin >> n;

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

	int st = (1 << n);
	int fans = 10000;
	for (int msk = 0; msk < st; msk ++) {
		int pans = 0;
		int _m = msk;
		memset(flag, 0, sizeof flag);
		memset(x, 0, sizeof x);
		memset(y, 0, sizeof y);
		for (int i = 1; i <= n; i ++, _m >>= 1)
			if (_m & 1) {
				x[i] = a[i];
				y[i] = a[i];
				flag[i] = 1;
			}
			else {
				x[i] = b[i];
				y[i] = b[i];
				flag[i] = -1;
			}
		sort (y + 1, y + n + 1);

		// for (int i = 1; i <= n; i ++)
			// cout << "(" << a[i] << " " << b[i] << " " << flag[i] << " - " << y[i] << ")";
		// cout << endl;
		pans = find();
		// cout << pans << endl;
		if (pans != -1)
			fans = min (fans, pans);
	}
	cout << (fans == 10000 ? -1 : fans) << endl;
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

N = int(input())
S = input()
c = Counter(S)
ans = 1
for v in c.values():
    ans *= (v + 1)
print((ans - 1) % 1000000007)


Measured memory_bytes: 8008
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;

# define mp make_pair
# define pb push_back
# define PI acos(-1)
# define ff first 
# define ss second 
# define endl '\n'
# define vt vector
# define all(c) (c).begin(), (c).end()
# define rep(i,a,b) for(int i = a ; i < b ; ++i)

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

template<class T> bool umin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool umax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

const int MOD = 1e9+9 ;
const ll inf = 1e18 ;  
const ll mod = 1e9+7 ;  

ll nCr(ll n,ll r){ll t=1;if(r>n)return 0;if(r>n-r)r=n-r;for(ll i=0;i<r;i++){t*=(n-i);t/=(i+1);}return t;}
ll power(ll a, ll n) { ll r=1;while(n){if(n&1)r=(r*a)%MOD;n>>=1;a=(a*a)%MOD;}return r%MOD;}



vt<pii> dir =  {{-1,0} , {1, 0} , {0,-1} , {0,1}} ; 

// ==========Start Here==============

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL) ; 
 	int n , m ; 
 	cin >> n >> m ; 
 	map<int,int> pr ; 
 	vt<bool> vis(n+1) ; 
 	int r ; 
 	string t ;
 	rep(i,0,m) {
 		cin >> r >> t ; 
 
 		if(!vis[r]) {
 			if(t == "WA")
 				pr[r]++;
 			else 
 				vis[r] = 1 ; 
 		}
 	}
 	int ac = 0 , pe = 0 ;
 	rep(i,1,n+1) {
 		if(vis[i] == 1) {
 			ac++;
 			pe += pr[i] ; 
 		}

 	}
 	cout << ac << " " << pe << endl ; 
	return 0 ; 
}

Measured memory_bytes: 8176
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n = sc.nextInt();
		int[][] dp=new int[n][3];
		dp[0][0]=sc.nextInt();
		dp[0][1]=sc.nextInt();
		dp[0][2]=sc.nextInt();
		for(int i = 1; i<n; i++){
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();
			dp[i][0]=a+Math.max(dp[i-1][1],dp[i-1][2]);
			dp[i][1]=b+Math.max(dp[i-1][0],dp[i-1][2]);
			dp[i][2]=c+Math.max(dp[i-1][0],dp[i-1][1]);
		}
		System.out.println(Math.max(Math.max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]));
	}
}


Measured memory_bytes: 96436
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());
		int k = Integer.parseInt(sc.next());
		int r = Integer.parseInt(sc.next());
		int s = Integer.parseInt(sc.next());
		int p = Integer.parseInt(sc.next());
		String[] t = sc.next().split("");


		for(int i = 0 ; i < n -k ; i++ ) {
			if(t[i].equals(t[i + k])) {
				
				if(i+k+k < n) {
					
					if(t[i].equals(t[i+k+k])) {
						t[i+k] = "N";
						continue;
					}
				

				}
				
				t[i] = "N";
			}
			
		}
		
		
		int ans = 0;
		String aa= "";
		for(int i = 0 ; i < n ; i++) {
			switch(t[i]) {
			case "r":
				ans += p;

				break;

			case "s":
				ans += r;
				
				break;

			case "p":
				ans += s;
				
				break;
			}
			
		}
		System.out.println(ans);
	}

}

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

using namespace std;

typedef long long ll;

int main() {
    int n; cin >> n;
    int mx = 0;
    int sm = 0;
    for (int i = 0; i < n; i++) {
        int p; cin >> p;
        sm += p;
        mx = max(mx, p);
    }
    cout << sm - mx / 2;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int w,h,n;
    cin >> w >> h >> n;
    int x,y,a;
    VVI v(4);
    v[0].push_back(0);
    v[1].push_back(w);
    v[2].push_back(0);
    v[3].push_back(h);
    REP(i,0,n) {
        //cerr << n << endl;
        cin >> x >> y >> a;
        v[a-1].push_back(a > 2 ? y : x);
    }
    sort(all(v[0]));
    sort(all(v[1]));
    sort(all(v[2]));
    sort(all(v[3]));
    reverse(all(v[0]));
    reverse(all(v[2]));
    int ans = 1;
    ans *= max(0, v[1][0] - v[0][0]);
    ans *= max(0, v[3][0] - v[2][0]);
    cout << ans << endl;
    /*
    VI xl(w+1), xr(w+1), yl(h+1), yr(h+1);
    REP(i,0,n) {
        cin >> x >> y >> a;
        if (a == 1) xl[x] += 1;
        if (a == 2) xr[x] += 1;
        if (a == 3) yl[y] += 1;
        if (a == 4) xr[y] += 1;
    }
    RREP(i,0,w) xl[i] = xl[i+1];
    RREP(i,0,h) yl[i] = yl[i+1];
    REP(i,1,w+1) xl[i] = xl[i-1];
    REP(i,1,h+1) yl[i] = yl[i-1];
    int s = 0,t = 0,u = 0,v = 0;
    REP(i,)
    */
}

int main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 256
n,a,b=map(int,input().split())
number=[]
for i in range(1,n+1):
    number.append(i)
#print(number)
number_2=[]
for i in number:
    number_2.append(str(i))
#print(number_2)
sum=[]
c=0
for i in range(len(number_2)):
    for j in number_2[i]:
        c+=int(j)
    sum.append(c)
    c=0
#print(sum)
ans=0
for i in range(len(sum)):
    if a<=sum[i]<=b:
        ans+=number[i]
print(ans)

Measured memory_bytes: 4084
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

N, M = MAP()
xy = [LIST() for _ in range(M)]

check = [0]*N
check[0] = 1
cnt = [1]*N

for x, y in xy:
	if check[x-1]:
		check[y-1] = 1
	cnt[x-1] -= 1
	cnt[y-1] += 1
	if cnt[x-1] == 0:
		check[x-1] = 0

print(sum(check))


Measured memory_bytes: 30972
#include <cstdio>
#include <vector>
#include <stack>
#include <iostream>
#include <string>
#include <tuple>
#include <random>
#include <map>
#include <queue>
#include <set>
#include <complex>
#include <algorithm>
#include <cassert>
#include <iterator>
#include <numeric>

using namespace std;

typedef long double ld;
typedef long long ll;
typedef pair<ll, ll> P;

const ll INF = 1e10;
const double eps = 1e-6;
const ll MOD = 1000000007;

int main() {
	ll Q;
	cin >> Q;
	for (int t = 0;t < Q;t++) {
		ll A, B, C, D;
		cin >> A >> B >> C >> D;
		ll l1 = 0;
		ll r1 = INF;
		while (r1 - l1 > 1) {
			ll m = (r1 + l1) / 2;
			if (max(A, B) <= m*min(A, B) + m)
				r1 = m;
			else
				l1 = m;
		}
		ll l = r1;
		if (0 <= max(A, B) - min(A, B) * l && max(A, B) - min(A, B) * l <= l) {
			string ans = "";
			if (A < B) {
				while (C <= D) {
					ans.push_back(C % (l + 1) == (B - A * l + 1) % (l + 1) ? 'A' : 'B');
					C++;
				}
			}
			else {
				while (C <= D) {
					ans.push_back(C % (l + 1) == (A + B - (A - B * l)) % (l + 1) ? 'B' : 'A');
					C++;
				}
			}
			cout << ans << endl;
			continue;
		}
		// 左
		l1 = 0;
		r1 = min(A / l, B) + 1;
		while (r1 - l1 > 1) {
			ll m = (r1 + l1) / 2;
			ll nowA = A - m*l;
			ll nowB = B - m;
			if (nowB <= (nowA + 1) * l - 1)
				l1 = m;
			else
				r1 = m;
		}
		ll left = l1;
		A -= left * l;
		B -= left;
		// 右
		l1 = 0;
		r1 = min(A, B / l) + 1;
		while (r1 - l1 > 1) {
			ll m = (r1 + l1) / 2;
			ll nowA = A - m;
			ll nowB = B - m*l;
			if (nowA <= (nowB + 1) * l - 1)
				l1 = m;
			else
				r1 = m;
		}
		ll right = l1;
		A -= right;
		B -= right * l;
		string ans = "";
		ll cnt = 0;
		
		while (A + B > 0) {
			if (B > (A - 1) * l + l || cnt == l || A == 0) {
				ans.push_back('B');
				B--;
				cnt = 0;
			}
			else {
				ans.push_back('A');
				A--;
				cnt++;
			}
		}
		string answer = "";
		while (C <= (l + 1)*left && C <= D) {
			if (C % (l + 1) == 0)
				answer.push_back('B');
			else
				answer.push_back('A');
			C++;
		}
		ll pos = C - 1 - (l + 1) * left;
		while (C <= D && pos < ans.size()) {
			answer.push_back(ans[pos]);
			pos++;
			C++;
		}
		while (C <= D) {
			ll nowC = C - left*(l + 1) - ans.size();
			if (nowC % (l + 1) == 1)
				answer.push_back('A');
			else
				answer.push_back('B');
			C++;
		}
		cout << answer << endl;
	}
	return 0;
}

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

void bfs(const vector<vector<int>> &G, vector<int> &res, int s) {
    queue<int> que; que.push(s);
    vector<int> parent(G.size(), -1);
    vector<int> depth(G.size());
    while(!que.empty()) {
        int cur = que.front(); que.pop();
        for(auto &to : G[cur]) {
            if(parent[to] != -1) continue;
            que.push(to);
            parent[to] = cur;
            depth[to] = depth[cur] + 1;
            if(to == s) {
                vector<int> tmp;
                int i = to;
                for(int j = 0; j < depth[to]; ++j) {
                    tmp.push_back(i);
                    i = parent[i];
                }
                if(res.size() > tmp.size()) {
                    res = tmp;
                    return;
                }
            }
        }
    }
}

vector<int> mincycle(const vector<vector<int>> &G) {
    vector<int> res(G.size() + 1);
    for(int s = 0; s < G.size(); ++s) bfs(G, res, s);
    if(res.size() == G.size() + 1) return vector<int>();
    return res;
}

void solve() {
    int V, E;
    cin >> V >> E;
    const long long INF = 1e18;
    vector<vector<int>> G(V);
    for(int i = 0; i < E; ++i) {
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
    }
    auto cycle = mincycle(G);
    if(cycle.size()) cout << 1 << '\n';
    else cout << 0 << '\n';
}

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



Measured memory_bytes: 3212
import Data.List

x ? (a,b) = if x then a else b

readInt :: String -> Int
readInt = read

main = do
    getLine
    vs <- map readInt.words<$>getLine
    cs <- map readInt.words<$>getLine
    print $ solve vs cs

solve vs cs = select gain where
  gain = sort $ zipWith (-) vs cs

select [] = 0
select (a:b) = (a>0)?(a,0) + select b 


Measured memory_bytes: 764
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    int N,K;
    cin >> N >> K;
    vector<int> H(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> H[i];
    }

    sort( H.begin(), H.end(), greater<int>() );

    K = min( K , N );
    long long ans = 0;
    for ( int i = K; i < N; i++ ) {
        ans += H[i];
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main(){
  int n;
  cin>>n;
  int h[n];
  rep(i,n){
    cin>>h[i];
  }
  int k[n];
  rep(i,n){
    k[i]=1;
  }
  for(int i=1;i<n;i++){
    for(int j=0;j<i;j++){
      if(h[i]<h[j]){
        k[i]=0;
      }
    }
  }
  int ans=0;
  rep(i,n){
    ans+=k[i];
  }
  cout<<ans<<endl;
        
}

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

using namespace std;
typedef long long ll;
char arr[10][10];
int rows[10] , cols[10] ;
int n , m , k ;
int dp[10][10][40];
string s;
vector<string>strs;
int z;
void rec(string s )
{
    if(s.size()==z)
    {
        strs.push_back(s);
        return;
    }
    rec(s+'1');
    rec(s+'0');
}
int main()
{

    cin >> n >> m >> k ;
    z=n+m;
    rec("");
    int cntr=0;
    for(int i = 1 ; i <=n ;i++)
    {
        for(int j = 1 ; j <=m ;j++)
        {
            cin >> arr[i][j];
            if(arr[i][j]=='#')
            {
                rows[i]++;
                cols[j]++;
                cntr++;
            }
        }
    }
    int need =cntr-k;
    int ns=0;
    for(int i = 0 ; i < strs.size() ;i++)
    {
        int f=0;
        for(int j = 1; j<=n;j++)
        {
            for(int k=1; k<=m;k++)
            {
                if(strs[i][j-1]=='0'&&strs[i][n+k-1]=='0')
                {
                    if(arr[j][k]=='#')
                        f++;
                }
            }
        }
        if(f==k)
            ns++;
    }
    cout << ns;
    return 0;
}


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

using namespace std;

#define FOR(i, a, b) for (int(i) = a; (i) <= (b); ++(i))
#define rep(i, n) FOR(i, 0, n-1 )
#define all(c) (c).begin(), (c).end()
#define mod 1000000007LL
#define INF 123456789012345
#define int long long

int dp[505][505];

signed main() {
  ios::sync_with_stdio(false);
    cin.tie(0);
  int n,m,q;cin>>n>>m>>q;

  rep(i,m)
  {
    int l,r;cin>>l>>r;
    l--,r--;
    dp[l][r]++;
  }

  rep(i,n)FOR(j,i,n)
  {
    if(j==0)continue;
    dp[i][j]+=dp[i][j-1];
  }

  for(int j=n-1;j>=0;j--)for(int i=j;i>=0;i--)
  {
    if(i==n-1) continue;
    dp[i][j] += dp[i+1][j];
  }


  rep(i,q)
  {
    int p,q;cin>>p>>q;
    p--,q--;
    cout << dp[p][q] << endl;
  }
     
}


Measured memory_bytes: 2944
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0; i < n; i++)

int main(){
    int N;
    cin >> N;
    map<ll, int> mp;
    rep(i, N){
        ll a;
        cin >> a;
        mp[a]++;
    }
    ll ans = 1;
    ll line_pair[2] = {0};
    rep(i, 2){
        for(auto p : mp){
            if(p.second >= 2) line_pair[i] = max(line_pair[i], p.first);
        }
        mp[line_pair[i]] -= 2;
    }
    cout << line_pair[0] * line_pair[1] << endl;
    return 0;
}

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

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

  int n,m; cin >> n >> m;
  int ans = 0;
  if(n > m) swap(n,m);
  if(n == 1 && m == 1) ans += 1;
  if(n == 1) ans += max(0LL,m-2);
  if(n > 1 && m > 1) ans += max(0LL,(n-2) * (m-2));
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long

using namespace std;

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

	vector <double> x(N);
	vector <double> y(N);
	for (int ii = 0; ii < N; ++ii){
		cin >> x[ii] >> y[ii];
	}

	vector <int> v;
	for (int ii = 0; ii < N; ++ii){
		v.push_back(ii);
	}

	vector <double> dist;
	do {
		double sum = 0.0;
		for (int ii = 0; ii < N-1; ++ii){
			int j = v[ii];
			int k = v[ii+1];
			sum += sqrt( (x[j]-x[k])*(x[j]-x[k]) + (y[j]-y[k])*(y[j]-y[k]) );
		}
		dist.push_back(sum);
	} while(next_permutation(v.begin(), v.end()));

	double ans = 0.0;
	int size = dist.size();
	for (int ii = 0; ii < size; ++ii){
		ans += dist[ii];
	}
	ans /= (double) size;

	cout << fixed << setprecision(10) << ans << "\n";

	return 0;
}


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

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int N, K, d; cin >> N >> K;
	unordered_map <int, int> mp;
	for (int i = 0; i < N; ++i){
		cin >> d;
		++mp[d];
	}
//	assert(m.size() == N);
	set <pair<int,int>> s;
	for (auto it = mp.begin(); it != mp.end(); ++it){
//		cout << *it << " " << m.count(*it) << "\n";
		s.insert(make_pair(it->second, it->first));
	}
//j	cout << s.size() << "\n";
	
	int cnt = 0;
	while (s.size() > K){
//		if (s.size() - *s.begin().first > K){
			cnt += s.begin()->first;	
			s.erase(s.begin());		
	}
	cout << cnt << "\n";	
	return 0;
}


Measured memory_bytes: 20724
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i,s,n) for(int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(){
    int n;
    cin>>n;
    int a[2][n];
    rep(i, 2) rep(j, n) cin >> a[i][j];

    int ans = 0;
    rep(i, n) {
        int candies = 0;
        rep(j, i + 1) candies += a[0][j];
        rep2(j, i, n) candies += a[1][j];
        ans = max(ans, candies);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<list>
#include<vector>
using namespace std;

int main() {
	int a, b;
	while (cin >> a >> b, a | b) {
		list<int>L;
		for (int c = 0; c < a; c++)L.push_back(a-c);
		for (int d = 0; d < b; d++) {
			int e, f, i = 1;
			scanf("%d%d", &e, &f);
			vector<int>V;
			for (auto g = L.begin(); g != L.end(); g++,i++) {
				if (i >= e&&e + f > i) {
					V.push_back(*g);
					L.erase(g);
					g--;
				}
			}
			for (int r = 0; r < V.size(); r++)L.push_front(V[V.size() - r - 1]);
		}
		cout << L.front() << endl;
	}
}

Measured memory_bytes: 3080
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
ll m1, d1, m2, d2 ;
 
int main() {
  cin >> m1 >> d1;
  cin >> m2 >> d2;
  ll ans = (m1 != m2) ? 1 : 0;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <climits>
#include <algorithm>
#include <cassert>
#include <vector>
#include <array>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <numeric>
#define ALL(c) (c).begin(), (c).end()

using namespace std;
using ll = long long;
using pli = pair<ll, int>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdi = pair<double, int>;
using pdd = pair<double, double>;

int N, Q;
string s;
string t, d;

bool is_left(int i) {
	int ti = i;
	for (int q = 0; q < Q; q++)
	{
		if (t[q] == s[ti]) {
			if (d[q] == 'L') {
				ti--;
			}
			else {
				ti++;
			}
		}
		if (ti == 0) {
			return true;
		}
		else if (ti == N + 1) {
			return false;
		}
	}
	return false;
}

bool is_right(int i) {
	int ti = i;
	for (int q = 0; q < Q; q++)
	{
		if (t[q] == s[ti]) {
			if (d[q] == 'L') {
				ti--;
			}
			else {
				ti++;
			}
		}
		if (ti == N + 1) {
			return true;
		}
		else if (ti == 0) {
			return false;
		}
	}
	return false;
}

int main() {
	cin >> N >> Q;
	s = string(N + 1, ' ');
	for (int i = 1; i <= N; i++)
	{
		cin >> s[i];
	}
	t = string(Q, ' ');
	d = string(Q, ' ');
	for (int i = 0; i < Q; i++)
	{
		cin >> t[i] >> d[i];
	}

	int lb1 = 0, ub1 = N + 1;
	int mid1;
	while (ub1 - lb1 > 1) {
		mid1 = (ub1 + lb1) / 2;
		if (is_left(mid1)) {
			lb1 = mid1;
		}
		else {
			ub1 = mid1;
		}
	}

	int lb2 = 0, ub2 = N + 1;
	int mid2;
	while (ub2 - lb2 > 1) {
		mid2 = (ub2 + lb2) / 2;
		if (is_right(mid2)) {
			ub2 = mid2;
		}
		else {
			lb2 = mid2;
		}
	}
	int ans = ub2 - lb1 - 1;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> N;
    cin >> S;
    R = 0;
    REP(i, N) {
        if (S[i] == 'R') {
            R++;
        }
    }
    ans = R;
    REP(i, R) {
        if (S[i] == 'R') {
            ans--;
        }
    }
    cout << ans << endl;
}

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

using ll=long long;
const ll MOD=1000000007;

int main() {
  ll n,k;
  cin >> n >> k;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  ll c=0;
  for(int i=0;i<n-1;i++){
    for(int j=i+1;j<n;j++){
      if(a[i]>a[j])
        c++;
    }
  }
  //cout << c << endl;
  ll b=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(a[i]>a[j]){
        b++;
      }
    }
  }
  //cout << b << endl;
  ll ans=0;
  ans +=(c*k)%MOD;
  ans +=(((k*(k-1)/2)%MOD)*b)%MOD;
  cout << ans%MOD << endl;
}

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

using namespace std;
#define ll long long
#define ld long double
#define mp make_pair

void print(vector<auto> &a)
{
    for (int i = 0; i<a.size(); i++) cout<<a[i]<<' ';
    cout<<endl;
}

const ll p = 1e9 + 7;

int mul(int a, int b) {
    return (1LL * a * b) % p;
}

int add(int a, int b) {
    int s = (a+b);
    s = s%p;
    if (s<0) s+=p; 
    return s;
}

const ll INF = 100000000000000000;

int n, m;
struct st
{
    int s;
    int f;
    ll cost;
};


vector<vector<int>> G;
vector<int> incoming;
vector<bool> visited;

vector<int> pr;

void dfs(int s)
{
    visited[s] = true;
    for (auto t: G[s]) incoming[t]--;
    for (auto t: G[s]) if (visited[t]==false&&incoming[t]==0)
    {
        pr[t] = s;
        dfs(t);
    }
}

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

    int n, m;
    cin>>n>>m;
    G.resize(n+1);
    incoming.resize(n+1);
    visited.resize(n+1);
    pr.resize(n+1);
    
    int a, b;
    for (int i = 0; i<n-1+m; i++)
    {
        cin>>a>>b;
        G[a].push_back(b);
        incoming[b]++;
        
    }
    
    //print(incoming);
    
    int s = 1;
    while (incoming[s]) s++;
    pr[s] = 0;
    dfs(s);
    for (int i = 1; i<=n; i++) cout<<pr[i]<<endl;
}

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

long long int modPow(long long int a, long long int n){//繰り返し自乗法(a^n mod p)。計算量 O(logN)
    long long int p = pow(10, 9) + 7;//任意のp(素数) modのやつで使える 
    if(n == 0){
        return 1;
    }
    if(n == 1){
        return a % p;
    }
    if (n % 2 == 1){ 
        return (a * modPow(a, n - 1)) % p;
    }      
    long long t = modPow(a, n / 2);
    return (t * t) % p;
}

int main(){
    long long int x, k , d, ans;
    cin >> x >> k >> d;
    ans = 0;

    bool flag; // true:+. false:-
    long long int count = 0; 
    /*
    if(x > 0){
        //flag = true;
        while(x >= 0 && k > 0){
            x -= d;
            k--;
        }
    }else{
        //flag = false;
        while(x <= 0 && k > 0){
            x += d;
            k--;
        }
    }*/
    
    if(x == 0){

    }else if(x > 0){  
        if(x % d == 0){
            count  = x / d;
        }else{
            count = x / d + 1;
        }

        if(k <= count){
            x = x - k*d;
            k = 0;
        }else{
            x = x - d*count;
            k = k - count;
        }
    }else{
        if(x % d == 0){
            count  = abs(x) / d;
        }else{
            count = abs(x) / d + 1;
        }

        if(k <= count){
            x = x + k*d;
            k = 0;
        }else{
            x = x + d*count;
            k = k - count;
        }
    }


    if(k == 0){
        cout << abs(x) << endl;
    }else if(k % 2 == 0){
        cout << abs(x) << endl;
    }else{
        ans = min(abs(x + d), abs(x - d));
        cout << ans << endl;
    }
}

Measured memory_bytes: 3620
#include<algorithm>
#include<vector>
#include<list>
#include<iostream>
#include<utility>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<iterator>
#include<map>
#include<limits>
#include<iomanip>
#include<ctime>
#include<cmath>
 
const int INF=2147483647;
const long long MOD=1e9+7;
 
using namespace std;




int main(){
    
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n, m;
    
    cin>>n>>m;
    
    vector<vector<pair<long long,long long>>> graph(n+1);
    
    
    
    for(int i=1; i<=m; i++){
        long long x,y,w;
        cin>>x>>y>>w;
        graph[x].push_back(make_pair(y,-w));
    }
    
    vector<long long> dist(n+1,2e18);
    dist[1]=0;
    for(int i=1; i<=n; i++){
        for(int i=1; i<=n; i++){
            for(auto p:graph[i]){
                if(dist[p.first]>=dist[i]+p.second) dist[p.first]=dist[i]+p.second;
            }
        }
    }
    /*
    for(int i=1; i<=n; i++){
        for(auto p:graph[i]){
            if(dist[i]+p.second<dist[p.first]){
                cout<<"inf";
                return 0;
            }
        }
    }*/
    
    long long d1=dist[n];
    
    for(int i=1; i<=n; i++){
        for(int i=1; i<=n; i++){
            for(auto p:graph[i]){
                if(dist[p.first]>=dist[i]+p.second) dist[p.first]=dist[i]+p.second;
            }
        }
    }
    
    if(d1==dist[n]) cout<<-dist[n];
    else cout<<"inf";

    
   
    
    
    
    return 0;
    
    
}

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

using namespace std;

typedef long long int ll;

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

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

  while (k--) {
    vector < int > cnt (n + 2, 0);
    for (int i = 1; i <= n; i++) {
      int l = max (i - a[i], 0);
      int r = min (i + a[i] + 1, n + 1);
      cnt[l]++;
      cnt[r]--;
    }
    for (int i = 1; i < n + 2; i++) cnt[i] += cnt[i - 1];

    bool ok = true;
    for (int i = 1; i <= n; i++) {
      a[i] = cnt[i];
      if (a[i] != n) ok = false;
    }

    if(ok) break;
  }

  for (int i = 1; i <= n; i++) cout << a[i] << " ";
  cout << '\n';
}


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;

const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }



int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	int ans =0;
	rep2(i,1,n+1){
		if(i%2==0) continue;
		int sm =0;
		for(int j=1; j*j <=i ; j++){
			if(i%j==0){
				if(i/j * i/j != n) sm +=2;
				else sm++;
			}
		}
		//dbg(i, sm);
		if(sm==8) ans++;
	}
	
	cout << ans <<"\n";
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main()
{
	int a,b,c;
	scanf("%d %d",&a,&b);
	c=a*b;
	if(c%2==0)
	{
		printf("Even\n");
	}
	else
	{
		printf("Odd\n");
	}
	return 0;
}

Measured memory_bytes: 256
#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 200005
#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,y,a,b;
    cin>>n>>a>>b;
    ll ans=powermod(2,n);
    ans=(ans-1)%mod;
    ll f[maxn];
    f[0]=f[1]=1;
    for(i=2;i<maxn;i++) f[i]=(f[i-1]*i)%mod;
    x=1;
    for(i=n;i>(n-a);i--) x=(x*i)%mod;
    y=powermod(f[a],mod-2)%mod;
    x=(x*y)%mod;
    ans=(ans-x+mod)%mod;
    x=1;
    for(i=n;i>(n-b);i--) x=(x*i)%mod;
    y=powermod(f[b],mod-2)%mod;
    x=(x*y)%mod;
    ans=(ans-x+mod)%mod;
    cout<<ans;
}

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

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
double PI = 3.1415926535897932;
lint MOD;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

void dfs1(int cur, int par, vector<vector<int>> &g, vector<lint> &dp) {
    lint ret = 1;
    for (auto nxt : g[cur]) {
        if (nxt == par) continue;
        dfs1(nxt, cur, g, dp);
        ret *= (dp[nxt] + 1);
        ret %= MOD;
    }
    dp[cur] = ret;
}

void dfs2(int cur, int par, vector<vector<int>> &g, vector<lint> &dp, vector<lint> &ans, lint Dpar) {
    lint ret = (Dpar + 1)%MOD;
    if (Dpar == -1) ret = 1;
    vector<int> chs;
    for (auto nxt : g[cur]) {
        if (nxt == par) continue;
        ret *= (dp[nxt] + 1);
        ret %= MOD;
        chs.push_back(nxt);
    }
    ans[cur] = ret;

    // 左右から累積
    size_t sz = chs.size();
    vector<lint> accLeft(sz + 2, 1);
    vector<lint> accRight(sz + 2, 1);
    for (int i = 1; i <= sz; i++) {
        accLeft[i] = (dp[chs[i - 1]] + 1);
        accRight[i] = (dp[chs[i - 1]] + 1);
    }

    for (int i = 1; i <= sz; i++) {
        accLeft[i] *= accLeft[i - 1];
        accLeft[i] %= MOD;
    }

    for (int i = sz; i >= 1; i--) {
        accRight[i] *= accRight[i + 1];
        accRight[i] %= MOD;
    }

    for (int i = 1; i <= sz; i++) {
        lint nxtDpar = accLeft[i - 1] % MOD * accRight[i + 1] % MOD;
        int nxt = chs[i - 1];
        if (Dpar != -1) {
        nxtDpar *= (Dpar + 1);
        nxtDpar %= MOD;
        }
        if (nxt == par) continue;
        dfs2(nxt, cur, g, dp, ans, nxtDpar);
    }
}

int main() {

    int n; cin >> n;
    cin >> MOD;
    vector<vector<int>> g(n);
    for (int i = 0; i < n - 1; i++) {
        int a, b; cin >> a >> b;
        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    vector<lint> dp(n);
    vector<lint> ans(n);
    dfs1(0, -1, g, dp);
    dfs2(0, -1, g, dp, ans, -1);
    for (int i = 0; i < n; i++) {
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 26496
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset

#include <math.h>
#include <stdlib.h>


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

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

//INT_MAX	2,147,483,647 = 2*1.0e9

int main(){
  string S;
  cin >> S;

  for(int i = 0;  i < 3; i++){
    if(S[i] == '1') S[i] = '9';
    else S[i] = '1';
  }

  cout << S << endl;


  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int h,n;
    cin >> h >> n;
    
    vector<int> dp(h+1,1e8);
    dp[0]=0;
    
    for (int i=0; i<n;++i) {
        int a,b;
        cin >> a >> b;
        
        for (int idx=0; idx<h+1; idx++) {
            if (dp[idx]!=1e8) {
                dp[min(idx+a,h)]=min(dp[idx]+b,dp[min(idx+a,h)]);
            }
        }
    }
    
    cout << dp[h] << endl;
    
}


Measured memory_bytes: 3664
import itertools

def main():
  n, m, r = map(int, input().split())
  list_r = [one_r-1 for one_r in map(int, input().split())]

  dist = [[float("inf")] * n for _ in range(n)]
  for i in range(n):
    dist[i][i] = 0
  for i in range(m):
    a, b, c = map(int, input().split())
    dist[a-1][b-1] = c
    dist[b-1][a-1] = c
  for k in range(n):
    for i in range(n):
      for j in range(n):
        if dist[i][j] > dist[i][k] + dist[k][j]:
          dist[i][j] = dist[i][k] + dist[k][j]

  result = float("inf")
  for one_cand in itertools.permutations(list_r):
    temp = 0
    for i in range(r-1):
      temp += dist[one_cand[i]][one_cand[i+1]]
    if temp < result:
      result = temp
  print(result)
  

if __name__ == "__main__":
  main()

Measured memory_bytes: 4656
using System;

public class Program{
    public static void Main(){
        string[] input=Console.ReadLine().Split(' ');
        int piece=int.Parse(input[0]);
        int price=int.Parse(input[1]);
        
        int noguchi=0;
        int higuchi=0;
        int fukuzawa=0;
        int flag=0;
        
        for(int j=0;j<=piece;j++) {
            for(int i=0;i<j+1;i++) {
                int bin=piece*1000+i*5000+4000*j;
                if(bin==price) {
                    noguchi=piece-j;
                    higuchi=j-i;
                    fukuzawa=i;
                    flag++;
                }
                
            }
        }
        
        if(flag==0) {
            noguchi=-1;
            higuchi=-1;
            fukuzawa=-1;
        }
        
        Console.WriteLine(fukuzawa+" "+higuchi+" "+noguchi);
        
        
    }
    
}


Measured memory_bytes: 11092
#include <cstdio>
#include <cstring>
#include <unordered_map>
#include <algorithm>
using namespace std;
typedef long long LL;
const int maxn=1e5+100;
int n,m;
unordered_map<int,LL> mp;

int main()
{
    //freopen("1.txt","r",stdin);
    while (scanf("%d%d",&n,&m)!=EOF)
    {
        mp.clear();
        mp[0]=1;
        LL ans=0,sum=0,a=0;
        for (int i=0;i<n;i++)
        {
            scanf("%lld",&a);
            sum=(sum+a)%m;
            ans+=mp[sum]++;
        }
        printf("%lld\n",ans);
    }
    return 0;
}


Measured memory_bytes: 3596
/**************************
*                         *
*  Nothing Is Impossible  *
*                         *
**************************/
//#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <ctype.h>
#include <string>
#include <vector>
#include <math.h>
#include <stack>
#include <cmath>
#include <map>
#define GetRand(Min, Max) ((rand()%(int)(((Max) + 1)-(Min))) + (Min))
#define Rep(i, min, max) for (int i = min; i < max; ++i)
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef long double ld;
using namespace std;

int main()
{
    ios::sync_with_stdio(NULL);
    cin.tie(NULL); cout.tie(NULL);
    int A, B;
    cin >> A >> B;
    Rep(i,1,4){
        if(i != A && i != B)
        {
            cout << i << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
#include<string>
#include<map>
#include<list>
#include<cctype>
#include<utility>
#include<algorithm>
#include<cctype>
using namespace std;

void print(string s,int a,int b){
	cout << s.substr(a,b-a+1) << endl;
}
void reverse(string& s,int a,int b){
	string tmp = s;
	for(int i=a;i<b+1;i++){
		s[i] = tmp[b-(i-a)];
	}
}
void replace(string& s,int a,int b,string x){
	for(int i=a;i<b+1;i++){
		s[i] = x[i-a];
	}
}

int main()
{
	string str,s,x;
	cin >> str;
	int n,a,b;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> s >> a >> b;
		if(s=="print"){
			print(str,a,b);
		}else if(s=="replace"){
			cin >> x;
			replace(str,a,b,x);
		}else if(s=="reverse"){
			reverse(str,a,b);
		}
	}

    return 0;
}

Measured memory_bytes: 1224
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll a, b, k;
    cin >> a >> b >> k;

    ll Ta = a, Ao = b;
    rep(i, k) {
        if(i%2 == 0) {
            if(Ta%2 == 1) {
                Ta--;
            }
            Ao += Ta/2;
            Ta /= 2;
        }
        else {
            if(Ao%2 == 1) {
                Ao--;
            }
            Ta += Ao/2;
            Ao /= 2;
        }
    }
    
    cout << Ta << " " << Ao << endl;
    re0;
}

Measured memory_bytes: 256