akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  long long N,Y;
  cin >> N >> Y;

  int a,b,c;
  a = Y/10000;
  Y = Y%10000;
  b = Y/5000;
  Y = Y%5000;
  c = Y/1000;

  int dis = N-(a+b+c);
  // cout << dis << endl;
  bool flug = true;
  while(flug==true){
    if(dis>=9 && a>=1) {
    dis -= 9;
    --a;
    c += 10;
    }
    else flug = false;
  }
  flug = true;
  while(flug==true){
    if(dis>=4 && b>=1){
      dis -=4;
      --b;
      c += 5;
    }
    else flug = false;
  }
  flug = true;
  while(flug==true){
    if(dis>=1 && a>=1){
      --dis;
      --a;
      b += 2;
    }
    else flug = false;
  }

  // cout << dis << endl;

  if(dis==0){
    cout << a << " " << b << " " << c << endl;
  }
  else{
    cout << "-1 -1 -1" << endl;
  }


  

}



Measured memory_bytes: 256
d = 1000000000000001
n = int(input())
abc = "abcdefghijklmnopqrstuvwxyz"
l = len(abc)

a = 1
while True:
    if n <= l**a:
        break
    n -= l**a
    a += 1
namelen = a

n -= 1
list = []
while True:
    if n < l:
        list.append(n)
        break
    list.append(n % l)
    n = n // l

namelist = ["a"]*namelen

for i in range(len(list)):
    namelist[-i-1] = abc[list[i]]

name = "".join(namelist)
print(name)

Measured memory_bytes: 9208
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <algorithm>

#define REP(i,n) for(int i=0; i<n; i++)
#define FOR(i,a,b) for(int i=a; i<=b; i++)
#define ll long long int

using namespace std;

int main(void) {
    string str;
    cin >> str;
    REP(i,str.length()){
        str[i]-=3;
        if(str[i]<'A')
            str[i]+=26;
    }
    cout << str << endl;
    
    return 0;
}

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

using namespace std;

#define endl "\n"
#define ll unsigned long long
#define int long long int
#define vi vector <int >
#define vvi vector < vector < int >  >
#define vii vector < pii >
#define vll vector <ll >
#define pii pair <int, int>
#define pdd pair< double, double>
#define piii pair < pii, int > 
#define pll pair<ll, ll >
#define umap unordered_map
#define pb push_back
#define pq priority_queue
#define forn(i, n) for(int i = 0; i < (int)n; i++)
#define fore(i,c) for(int i = 1; i <= (int)c; i++)
#define rep(i,b,c) for(int i = (int)b; i < (int)c; i++)
#define double long double
#define a first
#define b second

string s;
int dp[105][5][3], k;

int f(int pos, int n, int lb){

    if(pos == s.length()){
        return (n == k);
    }
    if(n > k){
        return 0;
    }

    if(dp[pos][n][lb] != -1) return dp[pos][n][lb];

    dp[pos][n][lb] = 0;

    int up = 9;
    if(!lb)
        up = s[pos] - '0';

    for(int i = 0; i <= up; i++){
        dp[pos][n][lb] += f(pos + 1, n + (i != 0), lb|(i < up));
    }    

    return dp[pos][n][lb];
}

int32_t main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

    memset(dp, -1, sizeof dp);
    cin >> s >> k;
    cout << f(0, 0, 0) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define fi first
#define se second
#define pi pair<int, int>
#define rep(i, a, n) for(int i = a; i <= n; i++)
#define per(i, a, n) for(int i = a; i >= n; i--)
#define REP(i, a, n) for(int i = a; i < n; i++)
#define Y "YES"
#define N "NO"
using namespace std;

int n, a, b, c;
bool ans;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	//freopen("in.txt", "r", stdin);

	cin >> n;
	while (n--) {
		cin >> a >> b;
		if (!ans) {
			if (a == b) c++;
			else c = 0;
			if (c == 3) ans = 1;
		}
	}
	cout << (ans ? "Yes" : "No");
}

Measured memory_bytes: 3648
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a;
		String op = "";
		int b;
		int ans = 0;
		A: while(true) {
			a= sc.nextInt();
			op= sc.next();
			b= sc.nextInt();
			switch(op){
				case "+":
					ans = a + b;
					break;
				case "-":
					ans = a - b;
					break;
				case "*":
					ans = a * b;
					break;
				case "/":
					ans = a / b;
					break;
				case "?":
					break A;
			}
			System.out.println(ans);
		}
		sc.close();
	}
}



Measured memory_bytes: 26376
import math
import collections
import itertools
import sys
import bisect
from heapq import heappop,heappush,heapify
sys.setrecursionlimit(10**6)
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

def dist(l1,l2):
    return math.sqrt((l1[0]-l2[0])**2 + (l1[1]-l2[1])**2)

n = INT()
ll = [MAP() for _ in range(n)]

ans=0
for i in itertools.permutations(ll):
    for j in range(n-1):
        ans += dist(i[j],i[j+1])

print(ans/math.factorial(n))

Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <queue>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main() {
	int n, l;
	while(cin >> n >> l) {
		if(n == 0 && l == 0) break;

		vector<int> v(n), cnt(n);
		priority_queue<P, vector<P>, greater<P> > que;
		rep(i, n) {
			cin >> v[i];
			cnt[i] = 0;
			que.push(P(v[i], i));
		}

		while(que.size()) {
			P p = que.top();
			que.pop();

			int d = l - p.first;
			int id = p.second;

			if(id == 0) cnt[id] += cnt[id+1] + d;
			else if(id == n-1) cnt[id] += cnt[id-1] + d;
			else cnt[id] += max(cnt[id-1], cnt[id+1]) + d;
		}

		int ans = 0;
		rep(i, n) {
			ans = max(ans, cnt[i]);
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 2832
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
ll mod=1e9+7;

int main(){
    int n;
    cin>>n;
    vector<int> h(n);
    rep(i,n) cin>>h[i];
    int ans=0;
    int active=0;

    for(int i=0;i<n;i++){
        if(active>=h[i]){
            active=h[i];
        }else{
            ans+=h[i]-active;
            active=h[i];
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
L = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

K = int(input()) - 1

print(L[K])

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

int main(){
   int a;
   while(cin>>a,a){
       vector<unordered_set<string>>V(50);
       for(int b=0;b<a;b++){
	   string c;cin>>c;
	   string d="a";d[0]=c[0];
	   for(int e=1;e<c.length();e++){
	       if(c[e-1]=='a'||c[e-1]=='i'||c[e-1]=='u'||c[e-1]=='e'||c[e-1]=='o'){
		     d+=c[e];
		   }
	       }
	    for(int e=1;e<=50;e++){
		V[e-1].insert(d.substr(0,e));
		}
	   }
	   for(int f=1;f<=50;f++){
	       if(V[f-1].size()==a){
		   cout<<f<<endl;
		   goto l;
		   }
	       }
	       puts("-1");
	       l:;
       }
    }

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

#define int ll
#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;++i)
using ll  = long long;
using vi  = vector<int>;
constexpr int mod = 1e9+7;

// map<int,int> pf(int n){
//   map<int,int> res;
//   int i = 2;
//   while(n != 1){
//     if(n % i == 0){
//       res[i]++;
//       n /= i;
//     }else
//       i++;
//   }
//   return res;
// }

map<int,int> pf(int n){
  map<int,int> res;
  FOR(i,2,sqrt(n)+1){
    //if(n == 1) break;
    while(n%i == 0){
      res[i]++;
      n /= i;
    }
  }
  if(n != 1) res[n]++;
  return res;
}

class ModuloCombination{
public:
  vector<ll> fact, fact_inv;

  static ll mod_pow(ll a, ll n){
    if(n == 0) return 1;
    if(n % 2 == 0) return mod_pow((a * a) % mod, n/2);
    return (a * mod_pow(a, n-1) % mod);
  }

  ModuloCombination(ll N):fact(N+1), fact_inv(N+1){ // N log Nで初期化
    fact[0] = 1;
    FOR(i, 1, N+1) fact[i] = (i * fact[i-1]) % mod;
    FOR(i, 0, N+1) fact_inv[i] = mod_pow(fact[i], mod-2);
  }

  ll op(ll n, ll r){ // nCr
    if(r < 0 or n < r) return 0;
    return fact[n] * fact_inv[r] % mod * fact_inv[n-r] % mod;
  }
};

main(){
  int n,m; cin >> n >> m;
  auto fact = pf(m);

  ModuloCombination C(n+30);
  int res = 1;
  for(auto x : fact){
    int tmp = C.op(n+x.second-1,x.second);
    tmp %= mod;
    res *= tmp;
    res %= mod;
  }
  cout << res << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
//typedef tuple<ll, ll, ll> T;

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

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    vector<string> substr;
    int k;
    cin>>s>>k;
    int length=min(k,int(s.size()));
    REP(i,(int)s.size()){
        string tmp="";
        for(int j=0;j<length;j++){
            if(i+j>=s.size())break;
            tmp+=s[i+j];
            //cout<<tmp<<endl;
            substr.push_back(tmp);
        }
    }
    set<string> tmp(substr.begin(),substr.end());
    vector<string> ans(tmp.begin(),tmp.end());
    sort(ans.begin(),ans.end());
    //for(auto s : ans) cout<<s<<endl;
    cout<<ans[k-1]<<endl;

}


Measured memory_bytes: 2428
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int D;
int C[26];
int S[365][26];

int last[400][30];

ll score(vector<int>& t)
{
  ll s = 0LL;
  REP(i,D){
    s += S[i][t[i]];
    REP(j,26) last[i+1][j] = last[i][j];
    last[i+1][t[i]] = i+1;
    REP(j,26){
      s -= C[j] * (i+1-last[i+1][j]);
    } 
  }
  return s;
}

ll score_2(vector<int>& t, ll before, int d, int old, int q)
{
  ll s = before;
  s += S[d][q] - S[d][old];
  FOR(i,d,D){
    if(t[i]==old) break;
    s += C[old] * ((i+1) - last[i+1][old]);
    s -= C[old] * ((i+1) - last[d][old]);
  }
  FOR(i,d,D){
    if(i!=d && t[i]==q) break;
    s += C[q] * ((i+1) - last[i+1][q]);
    s -= C[q] * ((i+1) - (d+1));
  }

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

  cin >> D;
  REP(i,26) cin >> C[i];
  REP(i,D) REP(j,26) cin >> S[i][j];
  vector<int> T(D);
  REP(i,D){ 
    cin >> T[i];
    T[i]--;
  }
  ll sc = score(T);
  int m; cin >> m;
  REP(i,m){
    int d,q; cin >> d >> q;
    d--, q--;
    int old = T[d];
    T[d] = q;
    ll tmp = score_2(T, sc, d, old, q);
    cout << tmp << '\n';
    sc = tmp;
    FOR(i,d,D){
      if(T[i]==old) break;
      last[i+1][old] = last[d][old];
    }
    FOR(i,d,D){
      if(i!=d && T[i]==q) break;
      last[i+1][q] = (d+1);
    }
  }
  return 0;
}


Measured memory_bytes: 3640
-- Try AtCoder
-- author: Leonardone @ NEETSDKASU

import Data.List

main = putStrLn . unwords . map show . solve . map read . tail . words =<< getContents

solve s = [mincolors, maxcolors] where
    (lowers, highers) = partition (< 8) $ map (`div` 400) s
    lowercolors = length $ nub lowers
    mincolors = max lowercolors 1
    maxcolors = lowercolors + length highers


Measured memory_bytes: 892
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;


int main() {
    int N;
    string S;
    cin >> N;
    cin >> S;
    ll b = 0, w = 0;
    ll B[200003], W[200003];
    for (int i = 0; i < 200003; i++)
        B[i]  = W[i] = 0;
    S = '.' + S + '#';
    for(int i = 0; i < N+2; i++) {
        B[i] = b;
        if (S[i] == '#') b++;
    }
    for(int i = N+1; i >= 0; i--) {
        W[i] = w;
        if (S[i] == '.') w++;
    }

    int ans = 400000;
    for (int i = 0; i <= N+1; i++) {
        int g = B[i] + W[i];
        ans = min(ans, g);
    }
    cout << ans << '\n';
}



Measured memory_bytes: 3844
// -*- mode:c++; coding:utf-8; c-basic-offset:2; -*-
// ALDS1_5-D: The Number of Inversions

#include <cstdio>
#include <cstring>

static void print_long(const unsigned long n)
{
  std::printf("%lu\n", n);
}

static unsigned long inversion_count = 0ul;

static void merge(int* const ss, const unsigned int n)
{
  auto n1 = n/2, n2 = n-n1;
  int tmp[n1];
  std::memcpy(tmp, ss, sizeof(tmp));
  auto ss1 = tmp, ss2 = ss+n1;
  auto i = 0u, i1 = 0u, i2 = 0u;
  while (i1 < n1 && i2 < n2) {
    if (ss1[i1] < ss2[i2]) {
      ss[i++] = ss1[i1++];
    } else {
      inversion_count += n1 - i1;
      ss[i++] = ss2[i2++];
    }
  }
  while (i1 < n1) {
    ss[i++] = ss1[i1++];
  }
  while (i2 < n2) {
    ss[i++] = ss2[i2++];
  }
}

static void merge_sort(int* const ss, const unsigned int n)
{
  if (n > 1) {
    auto n1 = n/2, n2 = n-n1;
    auto ss1 = ss, ss2 = ss+n1;
    merge_sort(ss1, n1); // ss[0..n/2-1] is sorted
    merge_sort(ss2, n2); // ss[n/2..n-1] is sorted
    merge(ss, n);
  }
}

int main()
{
  unsigned int n;
  std::scanf("%d", &n);
  int ss[n];
  for (auto i = 0u; i < n; ++i) {
    std::scanf("%d", &ss[i]);
  }

  merge_sort(ss, n);
  print_long(inversion_count);
}

// eof

Measured memory_bytes: 3928
import java.io.*;
import java.util.*;  
public class Main {	
	static int N,W;
	static int[] val,weight;
	static long[][] memo;
	public static long dp(int indx,int remWeight)
	{
		if(indx==N)return 0;
		if(memo[indx][remWeight]!=-1)return memo[indx][remWeight];
		return memo[indx][remWeight]=Math.max(remWeight-weight[indx]<0?Integer.MIN_VALUE:val[indx]+dp(indx +1,remWeight-weight[indx]), dp(indx+1, remWeight));
	}
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(System.out);
		StringTokenizer st = new StringTokenizer(br.readLine());
		N=Integer.parseInt(st.nextToken()); W=Integer.parseInt(st.nextToken());
		val= new int[N]; weight= new int[N]; memo= new long[N][W+1];
		for (int i = 0; i < N; i++) {
			st = new StringTokenizer(br.readLine());
			weight[i]=Integer.parseInt(st.nextToken());val[i]=Integer.parseInt(st.nextToken());
		}
		for (int i = 0; i < memo.length; i++) {
			for (int j = 0; j < memo[i].length; j++) {
				memo[i][j]=-1;
			}
		}
		pw.print(dp(0,W));
		pw.close();
	}
}

Measured memory_bytes: 131132
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a;i<(int)b;++i)
int main(){
    int n,m;cin>>n>>m;
    vector<int> v(n,0);
    rep(i,m){
        int a,b;cin>>a>>b;
        v[a-1]++;
        v[b-1]++;
    }
    rep(i,n){
        cout<<v[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# lcm & gcd not math
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(x, y):
    return (x * y) // gcd(x, y)

A, B = map(int, input().split())

print(lcm(A, B))

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn=2e5+10;
main(){
    string s;
    cin>>s;
    int ans=0;
    int len=s.length();
    int a=0,b=0;
    if(len&1)a=1;
    if(s[0]==s[len-1])b=1;
    if(a+b==1)puts("First");
    else puts("Second");
}


Measured memory_bytes: 512
# -*- coding: utf-8 -*-
"""
C - To Infinity
https://atcoder.jp/contests/abc106/tasks/abc106_c

"""
import sys

def solve(S, K):
    leading_1 = 0
    infinity_ch = '@'
    for s in S:
        if s == '1':
            leading_1 += 1
        else:
            infinity_ch = s
            break
    if K <= leading_1:
        return '1'
    else:
        return infinity_ch


def main(args):
    S = input()
    K = int(input())
    ans = solve(S, K)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 3064
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, 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
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
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

N = INT()
v = LIST()

v.sort()
for i in range(1, N):
  v[i] = (v[i] + v[i-1])/2
  
print(v[N-1])

Measured memory_bytes: 5196
#include <stdio.h>
int main(void){
  int i;
  int len,b;
  char aa[100],bb[100],cc[100];
  int ia,ib,ic;
//  scanf("%s %s",&aa,&bb);
//    printf("aa:%s bb:%s\n",aa,bb);
  scanf("%d %d",&ia,&ib);
//    printf("aa:%d bb:%d\n",ia,ib);
	len=0;
  	b = ia;
  for(i=0;i<1000;i++){
	ia = ia/ib;
//	printf("%d %d\n",i,b);
    if (ia != 0 ){
      len++;
    }
    else    {
		break;
    }
  }
	printf("%d\n",len+1);

  return 0;

}

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

int main(){
  int n;
  string s,t;
  cin>>n>>s>>t;
  s=s.substr(0,n);
  t=t.substr(t.size()-n,n);
  int ans=n*2;
  for(int i=0;i<n;i++){
    int f=0;
    for(int j=0;j<n-i;j++)
      if(t[j]!=s[j+i])f=1;
    if(!f)ans=min(ans,n*2-(n-i));
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <math.h>
#include <map>
#include <stack>
using namespace std;
static const int INF = 1e9+7;
// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, a, b) for (int i =a; i < b; i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define PI 3.14159265359

int main(){
    int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
    cout << x2-(y2-y1) << " " << y2+(x2-x1) << " " << x1-(y2-y1) << " " << y1+(x2-x1) << endl;
    return 0;
}


Measured memory_bytes: 3564
#include<iostream>
#include<algorithm>
#define fi first
#define se second
const int in=1;
const int out=0;

using namespace std;

int main()
{
	int n,t;cin>>n>>t;
	vector<pair<int,int>> a;
	int it,ot;
	for(int i=0;i<n;i++)
	{
		cin>>it>>ot;
		a.push_back(make_pair(it,in));
		a.push_back(make_pair(ot,out));
	}
	sort(a.begin(),a.end(),[](const pair<int,int> s1,const pair<int,int> s2)
	{return s1.fi==s2.fi?s1.se<s2.se:s1.fi<s2.fi;});
	
	int maxm=0,now=0;
	
	for(int i=0;i<a.size();i++)
	{
		pair<int,int> s;
		s=a[i];
		if(s.se==out)
		{
			now--;
		}
		else
		{
			now++;
			maxm=max(maxm,now);
		}
	}
	
	cout<<maxm<<endl;
	return 0;
}

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

#define PII pair<int, int>
#define MP make_pair

#define N 100100

using namespace std;

typedef long long ll;

int fa[N], vis[N], dep[N];

void dfs(int u, vector<vector<int>>& links) {
	// cout << u << endl;
	int v;
	vis[u] = 1;
	dep[u] = 0;
	for (int i = 0; i < links[u].size(); i++) {
		v = links[u][i];
		if (!vis[v]) dfs(v, links);
		if (dep[v] + 1 > dep[u]) {
			fa[u] = v;
			dep[u] = dep[v] + 1;
		}
	}
}

int main() {
	int n, m, x, y;
	scanf("%d %d", &n, &m);
	vector<vector<int>> links(n + 1);
	vector<int> ind(n + 1, 0);
	for (int i = 0; i < n - 1 + m; i++) {
		scanf("%d %d", &x, &y);
		links[y].push_back(x);
		ind[x]++;
	}
	int root = 0;
	for (int i = 1; i <= n; i++) {
		if (ind[i] == 0) {
			dfs(i, links);
		}
	}
	for (int i = 1; i <= n; i++) {
		printf("%d\n", fa[i]);
	}
	return 0;
}

Measured memory_bytes: 14080
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<sstream>
#include<bits/stdc++.h>
using namespace std;
int n;
int main()
{
	cin>>n;
  cout<<((n/1000+1)*1000-n)%1000;
	
}

Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    string s,t;
    cin >> s >> t;
    vector<int> svec(26), tvec(26);
    for(int i = 0; i < s.size(); i++)
    {
        svec[s[i]-'a']++;
        tvec[t[i]-'a']++;
    }
    sort(svec.begin(),svec.end());
    sort(tvec.begin(),tvec.end());
    bool flag = true;
    for(int i = 0; i < svec.size(); i++)
    {
        if (svec[i] != tvec[i]) {
            flag = false;
            break;
        }        
    }
    if (flag) {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
}

Measured memory_bytes: 776
#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, k;
    cin >> n >> k;
    int count = 0;
    while (n > 0)
    {
        n /= k;
        count++;
    }
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
/*******************************
 * written by Koki Riho
 * Rih0z https://github.com/Rih0z
 *******************************/

#include<iostream>
#include<map>
#include<vector>
#include<string>
#include <numeric>
#include<algorithm>

#define DEBUG false
#define FOR(i , a, b) for(size_t i = a ; i < b ; i++ )
#define REP(i,b) FOR(i , 0 , b)
#define RFOR(i,a,b) for(size_t i = a-1 ; i >= b ; i--)
#define RREP(i,a) RFOR(i,a,0)



typedef long long ll;
using namespace std;

int scanInt(void);
string scanString(void);

void scanLlArr(ll *a , int n);
void scanCharArr(char *string);

void printInt(int p);
void printLlArr(ll *a);
void printCharArr(char *string);


void perSum(ll *a , ll *sum ,int n);
int gcd(int a,int b);
/*************Global variable  **************/
int n ,x ;


/*******************************/

int main(){
  if (DEBUG){
    std::printf("******debug mode********\n");
  }
  cin >> n >> x ;
  int a[n];
  cin >> a[0];
  a[0] = abs(a[0] - x);
  int ans = a[0];
  REP(i,n-1){
    cin >> a[i+1];
    a[i+1] = abs(a[i + 1 ] - x );
    ans = gcd(ans,a[i+1]) ;
  }

  if (DEBUG){
    std::printf("******debug********\n");
    cout << gcd(33,105)  << endl;
    std::printf("******debug********\n");
  }
  cout << ans << endl;

  return 0 ;
}


int gcd(int a,int b)
{
  if (a%b==0)
  {
    return(b);
  }
  else
  {
    return(gcd(b,a%b));
  }
}
//各地点までの部分和を計算する
void perSum(ll *a , ll *sum ,int n){
  int i ;
  sum[0] = a[0];
  for(i = 1 ; i < n ; i++){
    sum[i] = a[i] + sum[i-1];
  }

}


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

const ll MAX = 9999999;
const ll MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){

  ll x,y; cin>>x>>y;
  if(x<y) swap(x,y); //x>=y
  ll s = x-y;
  ll t = x-2*s;
  if(t%3==0){
    //ans!=0
    // 前処理
    COMinit();

    // 計算例
    cout << COM(2.0/3.0*t+s,t/3.0+s) << endl;
  }else{
    cout<<0<<endl;
  }
}


Measured memory_bytes: 234752
#include <iostream>
using namespace std;
#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)

template<int MOD> struct MInt {
  long long val;
  MInt(long long val = 0) : val(val % MOD) { if (val < 0) val += MOD; }
  MInt operator-() const { return MInt(-val); }
  MInt operator+(const MInt& n) const { return MInt(val) += n; } MInt& operator+=(const MInt& n) { val = (val + n.val) % MOD; return *this; }
  MInt operator-(const MInt& n) const { return MInt(val) -= n; } MInt& operator-=(const MInt& n) { val = (MOD + val - n.val) % MOD; return *this; }
  friend ostream& operator<<(ostream& os, const MInt& n) { os<<n.val; return os; }
  friend istream& operator>>(istream& os, MInt& n) { os>>n.val; return os; }
};
using mint = MInt<1000000007>;

int N, D;
string S;
mint dp[10001][2][100];
bool visited[10001][2][100];
mint dfs(int i, bool lower, int r) {
  r %= D;
  if (visited[i][lower][r]) return dp[i][lower][r];
  if (i == N) return r == 0;

  int d = S[i]-'0';
  mint ans = 0;
  rep(j, (lower ? 9 : d)+1)
    ans += dfs(i+1, lower || (j < d), r+j);

  visited[i][lower][r] = true;
  return dp[i][lower][r] = ans;
}

int main() {
  cin >> S >> D;
  N = S.size();

  cout << dfs(0, false, 0) - 1 << endl;

  return 0;
}


Measured memory_bytes: 18816
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007

#A
def A():
    return

#B
def B():
    x1, y1, x2, y2 = LI()
    a = x2 - x1
    b = y2 - y1
    print(x2 - b, y2 + a, x1 - b, y1 + a)
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    B()


Measured memory_bytes: 38512
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>

typedef std::pair<int, int> T;

const int vecx[4] = { 1,0,-1,0 };
const int vecy[4] = { 0,-1,0,1 };
int h, w, n;
T goal[10];
char filed[1000][1000];
int si, sj;
int ans;
int dis[1000][1000];

void bfs(T _goal, T _start) {
	std::queue<T> q;
	q.push(_start);
	while (q.size()) {
		T tmp = q.front();
		q.pop();
		if (tmp == _goal) {
			ans += dis[_goal.first][_goal.second];
			break;
		}
		int x = tmp.first;
		int y = tmp.second;
		for (int i = 0; i < 4; i++) {
			if (x + vecx[i] < 0 || x + vecx[i] >= h || y + vecy[i] < 0 || y + vecy[i] >= w)continue;
			if (filed[x + vecx[i]][y + vecy[i]] != 'X' && !dis[x + vecx[i]][y + vecy[i]]) {
				dis[x + vecx[i]][y + vecy[i]] = dis[x][y] + 1;
				q.push(std::make_pair(x + vecx[i], y + vecy[i]));
			}
		}
	}
}

int main() {
	std::cin >> h >> w >> n;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			std::cin >> filed[i][j];
			if (filed[i][j] == 'S') {
				goal[0].first = i;
				goal[0].second = j;
			}
			if (filed[i][j] > '0' && filed[i][j] <= '9') {
				goal[filed[i][j] - '0'].first = i;
				goal[filed[i][j] - '0'].second = j;
			}
		}
	}

	for (int i = 0; i < n; i++) {
		bfs(goal[i + 1], goal[i]);
		for (int j = 0; j < h; j++)for (int k = 0; k < w; k++)dis[j][k] = 0;
	}
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 7920
use std::io::*;
use std::str::FromStr;
use std::iter::*;

struct Scanner<R: Read> {
    reader: R,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }

    fn safe_read<T: FromStr>(&mut self) -> Option<T> {
        let token = self.reader.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            token.parse::<T>().ok()
        }
    }

    fn read<T: FromStr>(&mut self) -> T {
        if let Some(s) = self.safe_read() {
            s
        } else {
            writeln!(stderr(), "Terminated with EOF").unwrap();
            std::process::exit(0);
        }
    }
}

macro_rules! rotate {
    ($a: expr, $b: expr, $c: expr, $d: expr) => {{
        let t = $a;
        $a = $b;
        $b = $c;
        $c = $d;
        $d = t;
    }}
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let mut u: u32 = sc.read();
    let mut s: u32 = sc.read();
    let mut e: u32 = sc.read();
    let mut w: u32 = sc.read();
    let mut n: u32 = sc.read();
    let mut d: u32 = sc.read();

    let com: String = sc.read();
    for c in com.chars() {
        match c {
            'E' => rotate!(u, w, d, e),
            'W' => rotate!(u, e, d, w),
            'N' => rotate!(u, s, d, n),
            'S' => rotate!(u, n, d, s),
            _ => panic!(),
        };
    }

    println!("{}", u);
}



Measured memory_bytes: 5036
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<utility>
#include<cmath>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 2e9;
ll N,H,W,a,b,c,d,e;

ll A[20][5] = {};
bool f,ff;

queue<ll> qll[6];

int main() {

	while (true) {
		cin >> H;
		if (H == 0) {
			break;
		}
		e = 0;

		for (int i = 0; i < 20; i++) {
			for (int j = 0; j < 5; j++) {
				A[i][j] = -1;
			}
		}

		for (int i = 0; i < H; i++) {
			for (int j = 0; j < 5; j++) {
				cin >> A[H-1-i][4-j];
			}
		}

		d = H * 5;

		while (d > 0) {
			ff = true;
			for (int i = 0; i < H; i++) {

				a = 1;
				b = A[i][0];

				for (int j = 1; j < 5; j++) {
					if (A[i][j] == b && b > 0) {
						a++;
					}
					else {
						a = 1;
						b = A[i][j];
					}

					if (a >= 3) {
						if (j == 4) {
							e += a * b;
							d -= a;
							ff = false;
							for (int k = 0; k < a; k++) {
								A[i][j - k] = -1;
							}
							break;
						}
						else if (A[i][j + 1] != b) {
							e += a * b;
							d -= a;
							ff = false;
							for (int k = 0; k < a; k++) {
								A[i][j - k] = -1;
							}
							break;
						}
					}


				}
			}

			f = true;

			for (int i = 0; i < H; i++) {
				for (int j = 0; j < 5; j++) {
					if (A[i][j] != -1) {
						f = false;
					}
				}
			}

			if (f || ff)break;


			for (int j = 0; j < 5; j++) {
				for (int i = 0; i < H; i++) {
					if (A[i][j] != -1) {
						qll[j].push(A[i][j]);
					}
				}
			}

			for (int i = 0; i < 20; i++) {
				for (int j = 0; j < 5; j++) {
					A[i][j] = -1;
				}
			}

			for (int j = 0; j < 5; j++) {
				W = 0;
				while (!qll[j].empty())
				{
					A[W][j] = qll[j].front();
					W++;
					qll[j].pop();
				}
			}

		}

		cout << e << endl;

	}

	

}


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

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)

/* memo
int no[tate][yoko]
*/

int main() {
    int N;
    cin >> N;
    int P = N % 10;
    if (P == 3) {
        cout << "bon" << endl;
    } else if (P == 0 || P == 1 || P == 6 || P == 8) {
        cout << "pon" << endl;
    } else {
        cout << "hon" << endl;
    }
}


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

int gcd(int a, int b){
    while(b!=0){
        int t=a;
        a=b;
        b=t%b;
    }
    return a;
}

int main(void){
    int n,x; cin >> n >> x;
    vector<int> A;
    for(int i=0; i<n; i++){
        int a; cin >> a;
        A.push_back(abs(a-x));
    }
    int ans=A[0];
    for(int i=0; i<n; i++){
        ans=gcd(A[i],ans);
    }

    cout << ans << endl;
    
}

Measured memory_bytes: 1020
#include <stdio.h>

#define KIRAI 9

int money(int k, int D[], int payment);

int main(void){
	int k,D[KIRAI]={},n,i,payment;
	scanf("%d %d", &n, &k);
	for(i=0;i<k;i++){scanf("%d", &D[i]);}
	for(payment=n ;; payment++){
		if(money(k,D,payment)==1){
			break;
		}
	}
	printf("%d\n",payment);
	return 0;
}

int money(int k, int D[], int payment){
	int keta,i;
	while(payment>0){
		keta=payment%10;
		for(i=0;i<k;i++){
			if(D[i]==keta){return 0;}
		}
		payment/=10;
	}
	return 1;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b)for(int i=(a);i<=(b);i++)
#define repR(i,n) for(int i=n;i>=0;i--)
#define P pair<int, int>
#define sz(x) x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<int>
#define COUT(x) cout<<(x)<<endl
#define MA map<int,int>
#define SE set<int>
#define PQ priority_queue<int>
#define PQR priority_queue<int,VE,greater<int>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

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;
}

using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}
const long long MOD = 1000000007;
const long long INF = 1LL << 50;
// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int x, y; cin >> x >> y;
	int tmp = y / x;
	int ans = 1;
	while (true) {
		if (tmp == 1)break;
		tmp /= 2;
		ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <iostream>
#include <queue>

using namespace std;

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64; // 9e18
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

const double PI = 3.141592653589793238463;
const int MAXN = 1000500;
const int MAXVALUE = 1000000500;
const long double EPS = 1e-7;
const i64 INF = 1e18;
i64 mod = 1e9 + 7;


i64 T, n, m, k;
vector <i64> a;
vector <i64> dp;



int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(16);
    cin >> n;
    a.resize(n);

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

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


    i64 res;
    if (a[0] == 0) {
        res = 0;
    }
    else {
        res = 1;
        for (i64 i = 0; i < n; ++i) {
            i64 res0 = res;
            res *= a[i];
            if (res < res0 || res > (i64)1e18) {
                res = -1;
                break;
            }
        }
    }  

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3676
# include <iostream>

int main() {

	while (true) {
		int n, x;
		std::cin >> n >> x;
		if (n == 0 && x == 0)
			break;
		int cnt = 0;
		for (int i = 1; i <= n; i++)
			for (int j = 1; j < i; j++)
				for (int k = 1; k < j; k++)
					if (i + j + k == x) 
						cnt++;

		std::cout << cnt << std::endl;
	}

	return 0;
}

Measured memory_bytes: 3076
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <map>

#define mod 1000000007
#define ten5 100005
#define PI 3.1415926
using namespace std;

int num[15];

int main()
{
    //int m,n,o=0,i,j,k;
    long long int sum=0,sum2=0,n1=0,n2=0,n3;
    double ans=0.0,half;
    long long int m,n,o,i,j,k=1,now=1;
    long long int a,a1,a2,a3,a4;
    //float f,g,h;
    char c;
    string s,s1;
    //priority_queue<int> pq;
    //map<string,int> mp;
    //map<string,int>::iterator iter;
    cin>>n;
    a1=10;a2=1;m=n;a=0;
    while(m>0)
    {
        m/=10;
        a++;
    }
    for(i=1;i<=a;i++)
    {
        if(i%2==0)
        {
            sum+=a1-a2;
            a1*=100;
            a2*=100;
        }
        else if(i==a)
        {
            sum+=n-a2+1;
        }
    }
    cout<<sum;
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
vector<ll> pas[300005];
int main(){
  int n;
  cin>>n;
  for(int i=1;i<=n;i++){
    int s;
    cin>>s;
    for(int j=0;j<s;j++){
      ll a;
      cin>>a;
      pas[i].push_back(a);
    }
  }
  priority_queue<ll> pque;
  ll ans=0;
  for(int i=n;i>0;i--){
    for(int j=0;j<pas[i].size();j++){
      pque.push(pas[i][j]);
    }
    ans+=pque.top();
    pque.pop();
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 19528
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn push_if_needed(){

}

// 19:54
fn main(){
    let line: Vec<usize> = read_as_vec();
    let (h, w) = (line[0], line[1]);
    let mut s: Vec<Vec<char>> = vec![];

    for _ in 0..h{
        let row = read_as_string().chars().collect::<Vec<char>>();
        s.push(row);
    }
    let mut found = false;
    for i in 0..h{
        for j in 0..w{
            if s[i][j] == '#'{
                /*
                if s[cmp::min(h, i+1)][j] == '#' || s[i][cmp::min(w, j+1)] == '#'||
                    s[cmp::max(i, 1)-1][j] == '#' || s[i][cmp::max(w, 1)-1] == '#'{
                    }
                 */

                if i < h-1{
                    if s[i+1][j] == '#'{
                        found = true;
                        continue;
                    }
                }

                if i > 0{
                    if s[i-1][j] == '#'{
                        found = true;
                        continue;
                    }
                }

                if j < w -1{
                    if s[i][j+1] == '#'{
                        found = true;
                        continue;
                    }
                }

                if j > 0{
                    if s[i][j-1] == '#'{
                        found = true;
                        continue;
                    }
                }
                println!("No");
                return;
            }
        }
    }

    println!("Yes");
}


Measured memory_bytes: 4352
import java.util.Scanner;
import java.util.Arrays;
public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        
        long N=sc.nextLong();
        long M=sc.nextLong();
        String S=sc.next();
        String T=sc.next();
        long L=0;
        int G=0;
        for(int i=1;i<=N;i++){
            if(N%i==0 && M%i==0){
                L=N*M/i;
                G=i;
            }
        }
        int some=0;
//        System.out.println(L+" "+G);
        boolean able =true;
        for(int i=0;i<N;i++){
            if(M*i%N==0){
                some=(int) (M*i/N);
                if(S.charAt(i)!=T.charAt(some)){
                    able=false;
                }
            }
//            System.out.println(able);
        }
        if(able){
            System.out.println(L);
        }else{
            System.out.println(-1);
        }
    }
}

Measured memory_bytes: 26036
#include<iostream>
#include<map>
#include<algorithm>
using namespace std;
typedef long long ll;
int main(){
  ll n,cnt=0;
  map<ll,ll> m;
  cin >> n;
  ll a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  for(int i=n-1;i>=0;i--){
    auto it = m.upper_bound(a[i]);
    if(it==m.end()){
      cnt++;
    }else{
      if((*it).second==1) m.erase(it);
      else (*it).second--;
    }
    m[a[i]]++;
  }
  cout << cnt<<endl;
}


Measured memory_bytes: 7168
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#define SF scanf
#define PF printf
#define MAXN 100010
#define INF 0x7FFFFFFF
using namespace std;
int n,m;
int minl[MAXN],maxl[MAXN],p[MAXN];
bool flag=1;
vector<int> a[MAXN];
bool check(int x,int y,int val){
	if(y==INF)
		return 1;
	if(x>val||y<val)
		return 0;
	if((val-x)%2)
		return 0;
	return 1;
}
void dfs(int x,int f){
	for(int i=0;i<a[x].size();i++){
		int u=a[x][i];
		if(u==f)
			continue;
		dfs(u,x);
		if(minl[u]==-INF)
			continue;
		if(minl[x]==-INF){
			minl[x]=minl[u]-1;
			maxl[x]=maxl[u]+1;
		}
		else{
			if(maxl[x]%2==maxl[u]%2)
				flag=0;
			maxl[x]=min(maxl[x],maxl[u]+1);
			minl[x]=max(minl[x],minl[u]-1);	
		}
	}
	if(p[x]!=-1){
		if(check(minl[x],maxl[x],p[x])==0)
			flag=0;
		minl[x]=maxl[x]=p[x];
	}
}
void dfs1(int x,int f,int minv,int maxv){
	if(maxv!=INF){
		if(maxl[x]==INF){
			maxl[x]=maxv+1;
			minl[x]=minv-1;
		}
		else{
			if(maxv%2==maxl[x]%2)
				flag=0;
			if(p[x]!=-1){
				if(check(minl[x],maxl[x],p[x])==0)
					flag=0;
			}
			else{
				minl[x]=max(minl[x],minv-1);
				maxl[x]=min(maxl[x],maxv+1);
			}
		}
	}
	for(int i=0;i<a[x].size();i++){
		int u=a[x][i];
		if(u==f)
			continue;
		dfs1(u,x,minl[x],maxl[x]);
	}
	if(minl[x]>maxl[x])
		flag=0;
}

int main(){
	memset(p,-1,sizeof p);
	SF("%d",&n);
	for(int i=1;i<=n;i++){
		minl[i]=-INF;
		maxl[i]=INF;	
	}
	int u,v;
	for(int i=1;i<n;i++){
		SF("%d%d",&u,&v);
		a[u].push_back(v);
		a[v].push_back(u);
	}
	SF("%d",&m);
	for(int i=1;i<=m;i++){
		SF("%d%d",&u,&v);	
		p[u]=v;
	}
	dfs(1,0);
	dfs1(1,0,-INF,INF);
	if(flag){
		PF("Yes\n");
		for(int i=1;i<=n;i++)
			PF("%d\n",minl[i]);
	}
	else{
		PF("No");
	}
}

Measured memory_bytes: 15360
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  string s;
  cin >> s;
  if (s == "AAA" or s == "BBB") {
    cout << "No" <<endl;
  } else {
    cout << "Yes" <<endl;
  }
}


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

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

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#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)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

struct City{
  int idx;
  int year;
  int name_first;
  int name_second;
};

int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int N, M;
  cin >> N >> M;
  vector<City> X(M);
  rep(i, M) {
    X[i].idx = i;
    cin >> X[i].name_first;
    cin >> X[i].year;
  }
  std::sort(X.begin(), X.end(), [](auto& l, auto& r){return ((l.name_first != r.name_first)?(l.name_first<r.name_first):(l.year<r.year));});

  int num {1};
  int tmp_name_first;
  rep(i, M) {
    if (tmp_name_first != X[i].name_first) {
      tmp_name_first = X[i].name_first;
      num = 1;
    }
    X[i].name_second = num;
    ++num;
  }
  std::sort(X.begin(), X.end(), [](auto& l, auto& r){return (l.idx<r.idx);});
  rep(i, M) {
    cout <<std::setfill('0')<<std::setw(6)<< X[i].name_first <<std::setw(6)<< X[i].name_second << '\n';
  }
}


Measured memory_bytes: 3072
#include <iostream>
using namespace std;
constexpr int MOD = 1e9 + 7;

long dp1[2][64], dp2[2][64];

int main() {
    long n; cin >> n;
    int msb = 0;
    for(int i=0; i < 64; ++i) if(n & (1L<<i)) msb = i;

    dp1[0][0] = dp2[0][0] = 1;
    for(int i = 0; i <= msb; ++i) {
        // (a, b)
        (dp1[0][i + 1] += dp1[0][i]) %= MOD; // (0, 0)
        (dp1[0][i + 1] += dp1[0][i]) %= MOD; // (1, 0)
        (dp1[1][i + 1] += dp1[0][i]) %= MOD; // (1, 1)
        
        (dp1[0][i + 1] += dp1[1][i]) %= MOD; // (0, 0)
        (dp1[1][i + 1] += dp1[1][i]) %= MOD; // (1, 0)
        (dp1[1][i + 1] += dp1[1][i]) %= MOD; // (1, 1)

        // update main dp
        if(n & (1L<<i)) {
            (dp2[0][i + 1] += dp1[0][i]) %= MOD; // (0, 0)
            (dp2[1][i + 1] += dp1[0][i]) %= MOD; // (1, 1)
            (dp2[1][i + 1] += dp1[1][i]) %= MOD; // (1, 0)

            (dp2[0][i + 1] += dp2[0][i]) %= MOD; // (1, 0)
            (dp2[0][i + 1] += dp2[1][i]) %= MOD; // (0, 0)
            (dp2[1][i + 1] += dp2[1][i]) %= MOD; // (1, 1)
        } else {
            (dp2[0][i + 1] += dp2[0][i]) %= MOD; // (0, 0)
            (dp2[1][i + 1] += dp2[0][i]) %= MOD; // (1, 1)
            (dp2[1][i + 1] += dp2[1][i]) %= MOD; // (1, 0)
        }
    }

    cout << dp2[0][msb+1] << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 100000
#define M 200000
using namespace std;

struct Info{
    int x,y,w;
} q[M+1];
int ind[N+1],a[M+1],n,m;
int st[N+1],ch[M+1],we[M+1],nx[M+1];
int u[N+1],xs[N+1],xn;
bool ck[N+1];
queue<int> Q;

int getRoot(int x){
    return u[x]==x ? x : u[x]=getRoot(u[x]);
}

void input(void){
    int i;
    scanf("%d %d",&n,&m);
    for(i=1;i<=n;i++) u[i]=i;
    for(i=1;i<=m;i++){
        scanf("%d %d %d",&q[i].x,&q[i].y,&q[i].w);
        if(q[i].w==0){
            u[getRoot(q[i].x)]=getRoot(q[i].y);
        }
    }
    for(i=1;i<=m;i++){
        if(q[i].w){
            int x=getRoot(q[i].x),y=getRoot(q[i].y);
            ch[i]=y, we[i]=q[i].w, nx[i]=st[x], st[x]=i;
            ind[y]++;
        }
    }
}

void process(void){
    int i;
    for(i=1;i<=n;i++){
        if(!ck[getRoot(i)]){
            ck[getRoot(i)]=true;
            xs[++xn]=getRoot(i);
            a[xs[xn]]=-1;
            if(!ind[xs[xn]]) Q.push(xs[xn]), a[xs[xn]]=0;
        }
    }
    if(xn>1 && Q.empty()){
        printf("No\n");
    }else{
        while(!Q.empty()){
            int x=Q.front(); Q.pop();
            for(i=st[x];i;i=nx[i]){
                if(a[ch[i]]==-1 || a[ch[i]]==a[x]+we[i]){
                    a[ch[i]]=a[x]+we[i];
                    ind[ch[i]]--;
                    if(!ind[ch[i]]) Q.push(ch[i]);
                }else{
                    printf("No\n");
                    return;
                }
            }
        }
        for(i=1;i<=xn;i++) if(ind[xs[i]]){
            printf("No\n");
            return;
        }
        printf("Yes\n");
    }
}

int main(){
    input();
    process();

    return 0;
}

Measured memory_bytes: 7552