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

int N,M;
vector<vector<int>> to; vector<int> color;
int Q;

vector<int> used;

vector<tuple<int,int,int>> Queries;

void DFS(int u, int d, int c){
  
  if( used[u] >= d ){ return ;}
  
  used[u] = d;
  //一度同じペアについて塗ったことがあるなら、上書き不可だからもうしなくていい
  
  if( d == -1 ){ return ;} //終了
  
  if( color[u] == -1 ){ //まだ塗られていなかったら塗る
    color[u] = c;
  }
  
  for(auto p : to[u] ){ 
    
    DFS(p,d-1,c);
    
  }
  
  DFS(u,d-1,c);
  
  return ;
}



signed main(void){ 
  
  cin >> N >> M; to.resize(N); 
  used = vector<int>(N,-1);
  color = vector<int>(N,-1); //-1はまだ色を塗っていない
  
  for(int i = 0; i < M; i++){
    int a,b; cin >> a >> b; a--; b--;
    to[a].push_back(b); to[b].push_back(a);
  }
  
  cin >> Q; 
  Queries.resize(Q);
  
  for(int i = 0; i < Q; i++){
    int u,d,c; cin >> u >> d >> c; u--;
    Queries.emplace_back(u,d,c);
  }
  
  reverse(Queries.begin(),Queries.end());
  
  for(int i = 0; i < Q; i++){ 
    auto q = Queries[i];
    int u = get<0>(q); 
    int d = get<1>(q);
    int c = get<2>(q);
    
    // ここからBFS
    
    DFS(u,d,c);
    
  }
  
  for(int i = 0; i < N; i++){ 
    int res = color[i];
    if( res == -1 ){ res = 0;}
    
    cout << res << endl;
    
                    
  }
  return 0;
}

Measured memory_bytes: 14196
#include <iostream>
#include <iomanip>
#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>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repq(i,a,n) for(int i=a; i<=n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

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

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

ll x, y;
ll t[1010], a[1010];

int main() {
    ll n; cin >> n;
    rep(i,0,n) cin >> t[i] >> a[i];
    x = 1, y = 1;
    ll s;

    rep(i,0,n) {
        if(i != 0) {
            s = max((x-1) / t[i] + 1, (y-1) / a[i] + 1);
            t[i] *= s;
            a[i] *= s;
        }
        x = t[i];
        y = a[i];
    }
    cout << x + y << endl;
    return 0;
}

Measured memory_bytes: 256
N,M,Q=map(int, input().split())
G=[]
for i in range(Q):
    a,b,c,d=map(int, input().split())
    G.append((a,b,c,d))
L=[]

que=[[1]]
while len(que)!=0:
    now=que.pop(0)
    last=now[-1]
    #print(now)
    for next_n in range(last, M+1):
        if len(now)+1==N:
            L.append(now+[next_n])
        else:
            que.append(now+[next_n])

ans=0
for A in L:
    sub=0
    for j in range(Q):
        a,b,c,d=G[j]
        
        if A[b-1]-A[a-1]==c:
            sub+=d
        #print(sub)
    ans=max(ans, sub)

print(ans)

Measured memory_bytes: 16488
N, M = map(int, input().split())
lst = [list(map(int, input().split())) for i in range(M)]
p = list(map(int, input().split()))

count = 0
#bit全探索
for i in range(2**N): #スイッチの状態をbit-全探索
    c = [0] * M
    for j in range(N): #j桁目を確認
        if (i >> j) & 1: #j桁目 = j個目のスイッチがONの時
            for k in range(M): #M個の電球に対して確認
                if j+1 in lst[k][1:]:
                    c[k] += 1
    flag = True
    for l in range(M):
        if c[l]%2 != p[l]:
            flag = False
    if flag:
        count += 1


print (count)




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

int main() {
    int64_t n, m;
    cin >> n >> m;
    
    vector<vector<int64_t>> r(m+1);
    for (int i = 0; i < n; i++) {
        int64_t a, b;
        cin >> a >> b;
        if (a <= m) r[a].push_back(b);
    }

    priority_queue<int64_t> pq;
    int64_t ans = 0;
    for (int i = 1; i <= m; i++) {
        for (auto e : r[i]) pq.push(e);
        if (!pq.empty()) {
            auto a = pq.top(); pq.pop();
            ans += a;
        }
        
    }
    cout << ans << endl;
}

Measured memory_bytes: 5632
def l str
    result = str[0].to_i
    ((str.length - 1) / 2).times{|i|
        result += str[i * 2 + 2].to_i if str[i * 2 + 1] == "+"
        result *= str[i * 2 + 2].to_i if str[i * 2 + 1] == "*"
    }
    result
end

def m str
    str.split("+").map{|x| l x}.inject(:+)
end

expression = gets.chomp
bob = gets.to_i

a = m(expression) == bob
b = l(expression) == bob
answer = "M"
answer = "L" if !a && b
answer = "U" if a && b
answer = "I" if !a && !b
puts answer


Measured memory_bytes: 6884
S = input()
T = input()
Ns = len(S)
Nt = len(T)

ans = 10 ** 18
for i in range(Ns - Nt + 1):
    cnt = 0
    for j in range(Nt):
        if S[i + j] != T[j]:
            cnt += 1
    ans = min(ans, cnt)

print(ans)

Measured memory_bytes: 9124
def twodig(x, N):
  l = list(bin(x))
  n = len(l)- 2
  ans = []
  for i in range(N- n):
    ans.append(0)
  for i in range(2, n+ 2):
    ans.append(int(l[i]))
  return ans

N, M, X = map(int, input().split())
lista = []
for i in range(N):
  lista.append(list(map(int, input().split())))
  
count = 1
ans = []

for i in range(2** N):
  flag = 0
  r = twodig(count, N)
  newlista = []
  c = r.count(1)
  for j in range(c):
    index = r.index(1)
    r[index] = 0
    newlista.append(lista[index])
  for k in range(1, M+ 1):
    summ = 0
    for l in range(c):
      summ+= newlista[l][k]
    if(summ < X):
      ans.append(-1)
      flag = 1
      break
  if(flag == 1):
    count+= 1
    continue
  else:
    cuota = 0
    for i in range(c):
      cuota+= newlista[i][0]
    ans.append(cuota)
    count+= 1
    
Ans = list(filter(lambda x: x!= -1, ans))

if(Ans == []):
  print(-1)
else:
  print(min(Ans))

Measured memory_bytes: 9324
import sys
def input():
    return sys.stdin.readline()[:-1]
N=int(input())
s=[[]for i in range(N)]
for i in range(N-1):
    a,b=map(lambda x: int(x)-1,input().split())
    s[a].append(b)
    s[b].append(a)
sys.setrecursionlimit(300000)
l=[None]*N
l[0]=0
def hu(n,c):
    for i in s[n]:
        if l[i]==None:
            l[i]=c
            hu(i,c+1)
hu(0,1)
t=l.index(max(l))
l=[None]*N
l[t]=0
hu(t,1)
if max(l)%3==1:
    print("Second")
else:
    print("First")

Measured memory_bytes: 223892
#include <iostream>
#include <set>
#include <algorithm>
#include <cmath>

int n, t;
int A[100010];

int main() {
    std::cin >> n >> t;
    
    int maxDiff = 0;
    int min = 1e9+10;
    int mincnt = 0;
    int ans = 0;
    for(int i = 0; i < n; ++i) {
        std::cin >> A[i];
//        std::cout << maxDiff << " " << min << " " << mincnt << " " << ans << std::endl;
//        std::cout << A[i] - min << std::endl;
        
        if(A[i] - min == maxDiff) {
            ans += mincnt;
        }else if(A[i] - min > maxDiff) {
            maxDiff = A[i] - min;
            ans = mincnt;
        }
        
        if(min > A[i]) {
            min = A[i];
            mincnt = 1;
        }else if(min == A[i]) {
            ++mincnt;
        }
    }
    
    std::cout << ans << std::endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) for (ll i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (ll i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
//#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 1e9 + 7LL;

template <typename T>
istream &operator>>(istream &is, vector<T> &v)
{
    for (int i = 0; i < v.size(); ++i)
    {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    for (int i = 0; i < v.size() - 1; ++i)
    {
        os << v[i] << " ";
    }
    if (v.size() > 0)
    {
        os << v[v.size() - 1] << endl;
    }
    return os;
}

int gcd(int a, int b){
    if (b == 0) return a;
    return gcd(b, a % b);
}

int main()
{
    int n;
    string s;
    cin >> n >> s;
    vector<int> R(n,0), G(n,0), B(n,0);
    vector<vector<int>> RGB(n, vector<int>(3, 0));
    map<char, int> ma {{'R', 0}, {'G', 1}, {'B', 2}};
    ++RGB[0][ma[s[0]]];
    for (int i = 1; i < n; ++i){
        for (int j = 0; j < 3; ++j){
            RGB[i][j] = RGB[i - 1][j];
        }
        ++RGB[i][ma[s[i]]];
    }
    long long ans = 0;
    for (int j = 1; j < n; ++j)
    {
        for (int k = j + 1 ; k < n; ++k){
            if (s[j] == s[k]){
                continue;
            }
            set<int> se{ma[s[j]], ma[s[k]]};
            int num = -1;
            for (int l = 0 ; l < 3; ++l){
                if (se.find(l) == se.end()){
                    num = l;
                    break;
                }
            }
            ans += RGB[j - 1][num];
            if (2*j - k >= 0 && 2*j - k < n){
                if (ma[s[2*j - k ]] == num ){
                    --ans;
                }
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3892
#include <queue>
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <iomanip>
#include <cstdio>
#define rep(i, n) for(long long i = 0;(i) < (n);(i)++)
using namespace std;
using ll = long long;
const ll mod = 1000000007;

int main()
{
	ll a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	if (a[0] == 5 && a[1] == 5 && a[2] == 7)
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}
	return 0;
}

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

void fnInput(llong& rnNum)
{
  cin >> rnNum;
}

void fnNumToName(llong nNum)
{
  const int cnnDivisor = 26;
  vector<int> vnRemain;
  llong nDividend = nNum;

  while ( nDividend )
  {
    llong nQuotient = nDividend / cnnDivisor;
    int nRemain = nDividend % cnnDivisor;
    if (!nRemain)
    {
      vnRemain.push_back( cnnDivisor );
      nQuotient--;
    }
    else
      vnRemain.push_back( nRemain );

    nDividend = nQuotient;
  }
  reverse(begin(vnRemain), end(vnRemain));

  for (int nRemain : vnRemain)
    cout << (char)('a' + nRemain - 1);

  cout << endl;
}
  
int main()
{
  llong nNum;
  fnInput(nNum);
  fnNumToName(nNum);

  return 0;
}

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

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  // 入力
  int n;
  string s;
  cin >> n >> s;

  int ans = 0;
  for (int i = 1; i < n - 1; i++) {
    bool x[26], y[26];
    fill(x, x + 26, false);
    fill(y, y + 26, false);

    for (int j = 0; j < i; j++) {
      x[s[j]-'a'] = true;
    }
    for (int j = i; j < n; j++) {
      y[s[j]-'a'] = true;
    }

    int cnt = 0;
    for (int j = 0; j < 26; j++) {
      if (x[j] && y[j]) cnt++;
    }

    ans = max(ans, cnt);
  }

  // 解答
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String... args) {
    Scanner scan = new Scanner(System.in);
    int A = scan.nextInt();
    int B = scan.nextInt();
    System.out.println(1<=A && A<=9 && 1<=B && B<=9 ? A*B : -1);
    scan.close();
  }
}

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

using ll = long long;

#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 ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;
using vvs = vector<vs>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "{";
    rep(i, (int)v.size()) {
        if (i)
            os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
    for (auto val : array)
        std::cout << val << ", ";
    std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::setprecision(10);

    int n, K; std::cin >> n >> K;
    vi a(n); rep(i, n) std::cin >> a[i];
    auto f = [&]() {
        vi aa(n);
        rep(i, n) {
            if (a[i] == 0) continue;
            aa[max(0, i-a[i])]++;
            if (i+a[i]+1 < n) aa[i+a[i]+1]--;
        }
        srep(i, 1, n) aa[i] += aa[i-1];
        rep(i, n) a[i] = aa[i] + (a[i] == 0 ? 1 : 0);
    };
    rep(i, K) {
        bool ok = true;
        rep(j, n) if (a[j] != n) ok = false;
        if (ok) break;
        f();
    }
    rep(i, n) std::cout << a[i] << (i+1 < n ? " " : "\n");
}


Measured memory_bytes: 4976
#include <iostream>
#include <algorithm>
using namespace std;
string d[6] = {"*01***",
	       "***1**",
	       "*0****",
	       "****01",
	       "**1**0",
	       "*10***"};
int main(){
  string str;
  while(cin >> str){
    if(str[0] == '#')break;
    int now = 0;
    bool f;
    for(int i = 0 ; i < str.size() ; i++ ){
      f = false;
      for(int j = 0 ; j < 6 ; j++ ){
	if(str[i] == d[now][j]){
	  now = j;
	  //  cout << " now " << now << endl;
	  f = true;
	  break;
	} 
      }
      if(!f)break;
    }
    if(now==5 && f)cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 1188
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        Main m = new Main();
        m.resolve(scan);
        scan.close();
    }

    final private void resolve(Scanner scan) {
        int k = scan.nextInt(), a = scan.nextInt(), b = scan.nextInt();
        int tmp = k;
        while (tmp < a) {
            tmp += k;
        }
        if (tmp > b) {
            System.out.println("NG");
        } else {
            System.out.println("OK");
        }
    }
}

Measured memory_bytes: 35772
def solve(A, nNow, n, m, q, a, b, c, d):
    if nNow == n:
        ret = 0
        for i in range(q):
            if A[b[i] - 1] - A[a[i] - 1] == c[i]:
                ret += d[i]
        return ret
    elif nNow == 0:
        ret = 0
        for i in range(1, m + 1):
            ret = max(ret, solve(A + [i], nNow + 1, n, m, q, a, b, c, d))
        return ret
    else:
        ret = 0
        for i in range(A[nNow - 1], m + 1):
            ret = max(ret, solve(A + [i], nNow + 1, n, m, q, a, b, c, d))
        return ret


def main():
    n, m, q = map(int, input().split())
    a, b, c, d = [[], [], [], []]
    for _ in range(q):
        ai, bi, ci, di = map(int, input().split())
        a.append(ai)
        b.append(bi)
        c.append(ci)
        d.append(di)
    print(solve([], 0, n, m, q, a, b, c, d))

    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 9264
using System;

class CF2017QAC
{
	static public void Main(string[] args)
	{
		int H, W;
		string[] vals = Console.ReadLine().Split(' ');
		H = int.Parse(vals[0]);
		W = int.Parse(vals[1]);
		int[] count = new int[26];
		string line;
		for(int i=0; i<H; i++)
		{
			line = Console.ReadLine();
			for(int j=0; j<W; j++)
			{
				count[line[j]-'a']++;
			}
		}
		
		int c4, c2, c1;
		if(H % 2 == 0 && W % 2 == 0)
		{
			c4 = H * W;
			c2 = c1 = 0;
		}
		else if(H % 2 == 1 && W % 2 == 0)
		{
			c2 = W;
			c4 = H * W - W;
			c1 = 0;
		}
		else if(H % 2 == 0 && W % 2 == 1)
		{
			c2 = H;
			c4 = H * W - H;
			c1 = 0;
		}
		else
		{
			c2 = H + W - 2;
			c4 = H * W - (H + W - 1);
			c1 = 1;
		}

		for(int i=0; i<26; i++)
		{
			while(count[i] >= 4 && c4 >= 4)
			{
				count[i] -= 4;
				c4 -= 4;
			}
		}
		if(c4 != 0)
		{
			Console.WriteLine("No");
			return;
		}

		for(int i=0; i<26; i++)
		{
			while(count[i] >= 2 && c2 >= 2)
			{
				count[i] -= 2;
				c2 -= 2;
			}
		}
		if(c2 != 0)
		{
			Console.WriteLine("No");
			return;
		}

		if(c1 == 1)
		{
			for(int i=0; i<26; i++)
			{
				if(count[i] == 1)
				{
					count[i]--;
					c1--;
					break;
				}
			}
		}
		if(c1 != 0)
		{
			Console.WriteLine("No");
			return;
		}


		Console.WriteLine("Yes");
	}
}


Measured memory_bytes: 13140
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 *

S = input()

S_correct ="CODEFESTIVAL2016"

ans = 0
for i in range(len(S)):
	if S[i] != S_correct[i]:
		ans += 1

print(ans)

Measured memory_bytes: 5200
#ifdef ONLINE_JUDGE
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2,bmi,bmi2,lzcnt")
#endif
#include <x86intrin.h>
#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

mt19937 mt_engine(chrono::steady_clock::now().time_since_epoch().count());
template <class T> enable_if_t<is_integral_v<T>, T> rng(T l, T r) {
  return uniform_int_distribution<T>(l, r - 1)(mt_engine);
}
template <class T> enable_if_t<is_floating_point_v<T>, T> rng(T l, T r) {
  return uniform_real_distribution<T>(l, r)(mt_engine);
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  using ll = long long;
  vector<ll> x(n), y(n), p(n), vx;
  for (int i = 0; i < n; ++i) {
    x[i] = rng(0, 100000);
    y[i] = rng(0, 100000);
    p[i] = rng(0, 100000);
    cin >> x[i] >> y[i] >> p[i];
    if (x[i]) {
      vx.push_back(x[i]);
    }
  }
  sort(begin(vx), end(vx));
  vx.erase(unique(begin(vx), end(vx)), end(vx));
  int nx = size(vx);
  vector<ll> res(n + 1, 1e18);
  for (int btx = 0; btx < 1 << nx; ++btx) {
    vector<ll> xx{0};
    for (int ix = 0; ix < nx; ++ix) {
      if (btx >> ix & 1) {
        xx.push_back(vx[ix]);
      }
    }
    sort(begin(xx), end(xx));
    int pcx = __builtin_popcount(btx);
    vector<ll> mn(n, 1e18);
    for (int i = 0; i < n; ++i) {
      auto it = lower_bound(begin(xx), end(xx), x[i]);
      if (it != end(xx)) {
        mn[i] = min(mn[i], *it - x[i]);
      }
      if (it != begin(xx)) {
        mn[i] = min(mn[i], x[i] - *prev(it));
      }
    }
    vector<ll> vy;
    for (int i = 0; i < n; ++i) {
      if (binary_search(begin(xx), end(xx), x[i])) continue;
      vy.push_back(y[i]);
    }
    sort(begin(vy), end(vy));
    vy.erase(unique(begin(vy), end(vy)), end(vy));
    int ny = size(vy);
    vector<vector<ll>> yys{{0}};
    yys.reserve(1 << ny);
    for (int iy = 0; iy < ny; ++iy) {
      for (int bty = 0; bty < 1 << iy; ++bty) {
        yys.emplace_back(yys[bty]);
        yys.back().insert(lower_bound(begin(yys.back()), end(yys.back()), vy[iy]), vy[iy]);
      }
    }
    for (int bty = 0; bty < 1 << ny; ++bty) {
      // vector<ll> yy;
      // for (int iy = 0; iy < ny; ++iy) {
      //   if (bty >> iy & 1) {
      //     yy.push_back(vy[iy]);
      //   }
      // }
      // yy.insert(lower_bound(begin(yy), end(yy), 0), 0);
      auto&& yy = yys[bty];
      int pcy = __builtin_popcount(bty);
      ll cur = 0;
      for (int i = 0; i < n; ++i) {
        ll t = mn[i];
        if (t == 0) continue;
        auto it = lower_bound(begin(yy), end(yy), y[i]);
        if (it != end(yy)) {
          t = min(t, *it - y[i]);
        }
        if (it != begin(yy)) {
          t = min(t, y[i] - *prev(it));
        }
        cur += t * p[i];
      }
      res[pcx + pcy] = min(res[pcx + pcy], cur);
    }
  }
  for (int k = 1; k <= n; ++k) {
    res[k] = min(res[k], res[k - 1]);
  }
  for (auto e : res) {
    cout << e << '\n';
  }
}


Measured memory_bytes: 8520
#include <bits/stdc++.h>
const int N=100005,MOD=1000*1000*1000+7;
typedef long long ll;
using namespace std;
vector<int>g[N];
ll n,cnt[N][2];
ll dfs(int cur,int col,int prev=0){
    if(cnt[cur][col]!=-1)return cnt[cur][col];
    int vis=0;
    ll ans=1;
    for(auto el:g[cur]){
        if(el==prev)continue;
        vis=1;
        if(col==0){
            ans*=(dfs(el,1,cur)+dfs(el,0,cur));
            ans%=MOD;
        }
        else{
            ans*=dfs(el,0,cur);
            ans%=MOD;
        }
    }
    if(!vis)cnt[cur][col]=1;
    else cnt[cur][col]=ans;
    return cnt[cur][col];
}
int main()
{ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
    cin>>n;
    memset(cnt,-1,sizeof cnt);
    for(int i=1;i<n;i++){
        int a,b;cin>>a>>b;g[a].push_back(b);g[b].push_back(a);
    }
    dfs(1,0);
    dfs(1,1);
    ll ans=cnt[1][0]+cnt[1][1];
    ans%=MOD;
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 15616
#include <iostream>
#define N 15
using namespace std;
int data[N][N];
void func(int,int);
int Cnt(int,int);
int X,Y,cnt;
int main(){
  while(1){
    cin >> X >> Y;
    if(X==0&&Y==0) break;
    for(int i=0;i<Y;i++)
      for(int j=0;j<X;j++)
	cin >> data[i][j];
    cnt=0;
    for(int i=0;i<X;i++){
      if(data[0][i]==0) func(0,i);
    }
    cout << cnt << endl;
  }
  return 0;
}
void func(int y,int x){
  if(y>=Y-1){
    cnt++;
    return;
  }
  if(y+1<Y&&x+1<X&&data[y+1][x+1]==0) func(y+1,x+1);
  if(y+1<Y&&x-1>=0&&data[y+1][x-1]==0) func(y+1,x-1);
  if(y+1<Y&&data[y+1][x]==2){
    int r=Cnt(y,x);
    if(r!=-1) func(r,x);
    else return ;
  }
  if(y+1<Y&&data[y+1][x]==0) func(y+1,x);
}
int Cnt(int y,int x){
  y+=3;
  while(1){
    if(y>=Y-1){
      if(y>Y-1) cnt++;
      else if(y==Y-1&&data[y][x]!=1) cnt++;
      break;
    }
    if(data[y][x]==1) break;
    if(data[y][x]==2) y+=2;
    if(data[y][x]==0) return y;
  }
  return -1;
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
using namespace std;
int main() {
	string character_string;
	cin >> character_string;
	if (character_string.size() < 2) cout << character_string << endl;
	else {
		for (int i = 0; i < character_string.size(); i += 2) { cout << character_string[i]; }
	}
	return 0;
}

Measured memory_bytes: 512
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

typedef long long ll;

const double EPS = 1e-9;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};

typedef vector<int> vi;
typedef pair<int, int> pi;

#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define ALL(v) (v).begin(), (v).end()

int main(){
  int n;
  int a[100000] = {};
  int f[100000] = {};
  scanf("%d", &n);
  rep(i,n){
    scanf("%d", &a[i]);
  }
  int c = 0;
  int it = 0;
  while(c != 1){
    it++;
    if(f[c]==1){
      it=-1;
      break;
    }
    f[c] = 1;
    c = a[c]-1;
  }
  printf("%d\n", it);

  return 0;
}


Measured memory_bytes: 1024
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]

    N,_ = LI()
    N0 = 2 ** N.bit_length()
    st = [0] * (N0*2)

    def add(p,x):
        p += N0-1
        st[p] = x
        while p > 0:
            p = (p-1) // 2
            st[p] = max(st[p*2+1],st[p*2+2])

    def get(a,b,x,l,r):
        if a <= l and r <= b: return st[x]
        if a >= r or b <= l: return 0
        vl = get(a,b,x*2+1,l,(l+r)//2)
        vr = get(a,b,x*2+2,(l+r)//2,r)
        return max(vl,vr)

    A = []
    for e,a in enumerate(sys.stdin.readline().split()):
        a = int(a)
        A.append(a)
        add(e+1,a)
    max_a = -1
    max_cnt = 0
    for i in range(1,N):
        a = get(i+1,N+1,0,0,N0) - A[i-1]
        if a > max_a:
            max_a = a; max_cnt = 1
        elif a == max_a:
            max_cnt += 1

    print(max_cnt)


if __name__ == '__main__':
    main()

Measured memory_bytes: 112744
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  string S,T;
  cin>>S>>T;
  int N=S.size(),M=T.size();
  vector<vector<int>> A(N+1,vector<int>(M+1));
  for(int i=1;i<=N;i++){
    for(int j=1;j<=M;j++){
      if(S[i-1]==T[j-1])
        A[i][j]=max({A[i-1][j-1]+1,A[i-1][j],A[i][j-1]});
      else
        A[i][j]=max(A[i-1][j],A[i][j-1]);
    }
  }
  string U="";
  int j=N,k=M;
  for(int i=A[N][M];i>0;i--){
    for(;A[j][k]==i;j--);j++;
    for(;A[j][k]==i;k--);j--;
    U+=S[j];
  }
  reverse(U.begin(),U.end());
  cout<<U<<endl;
}

Measured memory_bytes: 73644
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces
 
n = ni()
if n==1:
    print('Hello World')
else:
    a = ni()
    b = ni()
    print(a+b)


Measured memory_bytes: 2692
# include <iostream>
# include <set>
# include <vector>


template <typename integer>
integer _gcd(integer a, integer b) {
    if (b != 0) return _gcd(b, a%b);
    else return a;
}

template <typename integer>
integer gcd (integer a, integer b) {
    if (a > b) return _gcd(a, b);
    return _gcd(b, a);
}


using namespace std;


int main() {
    int n; cin >> n;
    vector<int> fa(n);
    for (int i=0; i<n; i++) cin >> fa[i];

    vector<int> fgcd(n+1, 0), bgcd(n+1, 0);

    for (int i=1;   i<=n; i++) fgcd[i] = gcd(fgcd[i-1], fa[i-1]);
    for (int i=n-1; i>=0; i--) bgcd[i] = gcd(bgcd[i+1], fa[i]);

    int ans = 0;
    for (int i=1; i<=n; i++) {
        ans = max(ans, gcd(fgcd[i-1], bgcd[i]));
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 1408
#include<stdio.h>
int main()
{
    int a,b,div,mod;
    double div1;
    scanf("%d %d",&a,&b);
    div=(int)a/b;
    mod=(int)a%b;
    div1=(double)a/b;
    printf("%d %d %f",div,mod,div1);




    return 0;
}



Measured memory_bytes: 2064
#include<bits/stdc++.h>
using namespace std;
#define N 100010
#define ll long long
int main()
{
    int n;
    int ans1 = 0;
    int ans2 = 0;
    cin>>n;
    int a[n];
    for(int i = 0; i < n; i++){
        cin>>a[i];
    }
    int pre = -100;
    for(int i = 0; i < n; i++){
        if(pre <= a[i]-1){
            pre = a[i]-1;
        }
        else if(pre <= a[i]){
            pre = a[i];
        }
        else{
            puts("No");
            return 0;
        }
    }
    puts("Yes");
    return 0;
}


Measured memory_bytes: 4012
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(){
    int n; cin >> n;
    int a[n]; int a_max=0;
    int ans=0;
    for(int i=0; i<n; i++){
        cin >> a[i];
        ans += a[i]-1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG
#endif
#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 <limits>//setprecision
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set,multiset
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
#include <numeric> //accumulate,,,
#define endl "\n";
using namespace std;

const long long INF = 4000000000000000001;
const int inf = 1001001001;
int MOD = 2019;
typedef pair<long long,long long> P;

void chmax(long long &a,long long b){if(a < b) a = b;}
void chmin(long long &a,long long b){if(a > b) a = b;}

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //When end-of-a bit is 1, times simple N.
    if (M & 1) res = (res * N) % MOD;
    return res %= MOD;
}
long long gcd(long long a, long long b) {
    if (b == 0) return a; else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}
//dp[i][j]:i個目まで考えた時、j分かかったときのおいしさの最大値
int dp[3005][3005];

int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int N,T;cin >> N >> T;
   
    
    /*for(int i = 0;i<3005;i++) for(int j = 0;j<3005;j++) dp[i][j] = -inf;
    dp[0][0] = 0;*/
    vector<pair<int,int>> food;
    for(int i = 0;i<N;i++){
        int time,delicious;cin >> time >> delicious;
        food.push_back(make_pair(time,delicious));
    }
    sort(food.begin(),food.end());
    int ans = 0;
    //最後の一品（一番時間かかるやつ）はT-1分に注文する
    for(int i = 0;i<N;i++){
        int time = food.at(i).first,delicious = food.at(i).second;
        for(int j = 0;j<T;j++){
            //if(dp[i][j] == -inf) continue;
            if(j+time < T){
                dp[i+1][j+time] = max(dp[i+1][j+time],dp[i][j]+delicious);
                dp[i+1][j] = max(dp[i+1][j],dp[i][j]);
            }
            else{
                dp[i+1][j] = max(dp[i+1][j],dp[i][j]);
            }
        }
        //i個目までを考える時、i個目を確実に取るとする（i個目が影響するのはdpテーブルのi+1からなので問題ない）
        int now = 0;
        for(int j = 0;j<T;j++){
            now = max(now,dp[i][j]);
        }
        ans = max(ans,now+food.at(i).second);
    }
    cout << ans << endl;
}


Measured memory_bytes: 38868
//#include    <bits/stdc++.h>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#define N  500005
#define mem(a,b) memset(a,b,sizeof(a))
#define IOS ios::sync_with_stdio(false)
#define INF 0x3f3f3f3f
#define MOD 998244353
#define Mod 1e9 + 7
template<typename T> inline T max(T a,T b,T c){
    return max(a,max(b,c));
}
template<typename T> inline T min(T a,T b,T c){
    return min(a,min(b,c));
}
template<typename T> inline T max(T a,T b,T c,T d){
    return max(a,max(b,c,d));
}
template<typename T> inline T min(T a,T b,T c,T d){
    return min(a,min(b,c,d));
}
const int  dx[]={0,1,0,-1,0,1,-1,1,-1};
const int  dy[]={0,0,1,0,-1,1,-1,-1,1};
typedef long long ll;
using namespace std;
ll a[N],b[N];
int main(){
    ll n,i,ans=0,mini=INF,f=0;
    scanf("%lld",&n);
    for (i=1;i<=n;i++){
        scanf("%lld%lld",&a[i],&b[i]);
        ans+=a[i];
        if (a[i]>b[i])
            f=1,mini=min(mini,b[i]);
    }
    if (f)
       printf("%lld\n",ans-mini);
    else printf("0\n");
    return 0;
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)

int main(){
    int n ,t;
    cin >> n >> t;
    int ans = 1002;
    for(int i = 0; i < n; i++){
        int c, x;
        cin >> c >> x;
        if(x <= t){
            ans = min(ans, c);
        }
    }
    if(ans == 1002){
        cout << "TLE" << endl;
    }else{
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
//#pragma comment(linker, "/STACK:102400000,102400000") 
#pragma warning(disable:4996)
#include <fstream>
#include <iostream>
#include <functional>
#include <algorithm>
#include <cstring>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
#define eps 1e-10
#define LL_INF 0x33ffffffffffffff
#define INF 0x3f3f3f3f
#define mem(a, b) memset(a, b, sizeof(a))
#define pper(i,n,m) for(int i = n;i >= m; i--)
#define repp(i, n, m) for (int i = n; i <= m; i++)
#define rep(i, n, m) for (int i = n; i < m; i++)
#define sa(n) scanf("%d", &(n))
#define mp make_pair
#define ff first
#define ss second
#define pb push_back

const int maxn = 500005;
const ll mod = 998244353;
const double PI = acos(-1.0);

int n, k;
vector<int>edge[maxn];
int u[maxn], v[maxn];

int dfs(int x, int fa, int dis)
{
	int res = (dis<0);
	int sz = edge[x].size();

	int k = 0;
	rep(i, 0, sz)
	{
		k = edge[x][i];
		if (k == fa)continue;

		res += dfs(k, x, dis - 1);
	}
	return res;
}

void solve()
{
	sa(n), sa(k);
	int i, j;

	repp(i, 1, n - 1)
	{
		sa(u[i]), sa(v[i]);
		edge[u[i]].push_back(v[i]);
		edge[v[i]].push_back(u[i]);
	}

	int res = n;

	if ((k & 1) == 0)
	{
		repp(i, 1, n)
		{
			res = min(res, dfs(i, -1, k / 2));
		}
	}
	else
	{
		repp(i, 1, n - 1)
		{
			res = min(res, dfs(u[i], v[i], (k - 1) / 2) + dfs(v[i], u[i], (k - 1) / 2));
		}
	}
	printf("%d\n", res);
}

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


Measured memory_bytes: 12160
#include <bits/stdc++.h>
 
using namespace std;
 
#define endl '\n'
#define f first
#define s second
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define debug(...) cout << " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " << endl

using ld = long double;
using ll = long long;
using pii = pair <int,int>;
using pll = pair <ll,ll>;
using vi = vector <int>;
using vll = vector <ll>;
using vpii = vector <pii>;
using vpll = vector<pll>;
using vs = vector <string>;


int main(){
  fastio;

  string a;
  cin >> a;

  int sum = 0;

  for(char c:a){
    sum += c-'0';
  }

  if(sum % 9 == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}

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

int main(){
    int n,d;
    cin>>n;
    set<int> st;
    for(int i=0;i<n;i++){
        cin>>d;
        st.insert(d);
    }
    cout<<st.size()<<endl;
    return 0;
}

Measured memory_bytes: 256
module.exports=function(r){var e={};function t(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return r[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=r,t.c=e,t.d=function(r,e,n){t.o(r,e)||Object.defineProperty(r,e,{enumerable:!0,get:n})},t.r=function(r){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(r,"__esModule",{value:!0})},t.t=function(r,e){if(1&e&&(r=t(r)),8&e)return r;if(4&e&&"object"==typeof r&&r&&r.__esModule)return r;var n=Object.create(null);if(t.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:r}),2&e&&"string"!=typeof r)for(var o in r)t.d(n,o,function(e){return r[e]}.bind(null,o));return n},t.n=function(r){var e=r&&r.__esModule?function(){return r.default}:function(){return r};return t.d(e,"a",e),e},t.o=function(r,e){return Object.prototype.hasOwnProperty.call(r,e)},t.p="",t(t.s=0)}([function(r,e,t){t(1)(t(2).readFileSync("/dev/stdin","UTF-8"))},function(r,e){function t(r,e){return function(r){if(Array.isArray(r))return r}(r)||function(r,e){var t=[],n=!0,o=!1,u=void 0;try{for(var i,f=r[Symbol.iterator]();!(n=(i=f.next()).done)&&(t.push(i.value),!e||t.length!==e);n=!0);}catch(r){o=!0,u=r}finally{try{n||null==f.return||f.return()}finally{if(o)throw u}}return t}(r,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}r.exports=function(r){for(var e=r.split("\n"),n=t(e[0].split(" ").map(function(r){return Number(r)}),2),o=n[0],u=n[1],i=[],f=0;f<o;f++){var l=e[f+1].split("");i.push(l)}for(var a=[[0,-1],[1,-1],[1,0],[1,1],[0,1],[-1,1],[-1,0],[-1,-1]],c=0;c<o;c++){for(var p=0;p<u;p++)if("."==i[c][p]){for(var s=0,d=0,y=a;d<y.length;d++){var v=y[d],b=p+v[0],m=c+v[1];b>=0&&b<u&&m>=0&&m<o&&"#"==i[m][b]&&(s+=1)}i[c][p]=s}console.log(i[c].join(""))}}},function(r,e){r.exports=require("fs")}]);

Measured memory_bytes: 7372
#include<cstdio>
#include<string>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<map>
#define For(i,j,k) for(ll i=j;i<=k;++i)
#define Dow(i,j,k) for(ll i=k;i>=j;--i)
#define ll long long
#define inf 1e17
using namespace std;
inline ll read()
{
	ll t=0,f=1;char c=getchar();
	while(c<'0'||c>'9')	{if(c=='-')	f=-1;c=getchar();}
	while(c<='9'&&c>='0')	t=t*10LL+c-48LL,c=getchar();
	return t*f;
}
int a[200001],b[200001],c[200001];
ll s[200001],ans;
int n;
int main()
{
	n=read();
	For(i,1,n)	a[i]=read();
	For(i,1,n)	b[i]=read();
	For(i,1,n)	c[i]=read();
	sort(a+1,a+n+1);sort(b+1,b+n+1);
	sort(c+1,c+n+1);
	For(i,1,n)
		s[i]=lower_bound(a+1,a+n+1,b[i])-a-1;
	For(i,1,n)	s[i]+=s[i-1];
	For(i,1,n)
		ans+=s[lower_bound(b+1,b+n+1,c[i])-b-1];
	cout<<ans<<endl;
}

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

int mat[3][100005];
int func(int n)
{
    int dp[3][n];
    for(int j=0;j<3;j++)
    dp[j][0] = mat[j][0];

    for(int i=1;i<n;i++)
    {
        for(int j=0;j<3;j++)
        {
            int val=0;
            for(int k=0;k<3;k++)
            {
                if(k != j)
                val=max(val , dp[k][i-1]);
            }

            dp[j][i] = val + mat[j][i];
        }
    }
    int ans=0;
    
    for(int j=0;j<3;j++)
    ans=max(ans , dp[j][n-1]);

    return ans;
}

int main() {
    int n; cin>>n;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<3;j++) cin>>mat[j][i];
    }
    cout<<func(n);
}


Measured memory_bytes: 5504
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    static class BKagamiMochi
    {        
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var ds = new List<int>();
            for (int i = 0; i < n; i++)
            {
                ds.Add(int.Parse(Console.ReadLine()));
            }

            Console.WriteLine(ds.Distinct().Count());
            Console.ReadLine();
        }
  }
}

Measured memory_bytes: 13152
#include <stdio.h>
#define NIL -1

long long fibs[50];

int fibs_(int n){
    if(fibs[n] != NIL)
        return fibs[n];

    if (n >= 2)
        fibs[n] = fibs_(n - 1) + fibs_(n - 2);

    return fibs[n];
}

void init(){
    for(int i = 0; i < 45; i++){
        fibs[i] = NIL;
    }
    fibs[0] = 1;
    fibs[1] = 1;
}


int main(void){
    init();

    int n;
    scanf("%d", &n);

    for(int i = 2; i < n; i++){
        int _;
        _ = fibs_(i);
    }

    printf("%d\n", fibs_(n));

    return 0;
}



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

int main() {
    int n;
    cin >> n;
    string s = "";
    while (n != 0) {
        if (n % -2 != 0) {
            n--;
            s = "1" + s;
        }
        else
            s = "0" + s;
        n /= -2;
    }
    if (s.empty()) {
        cout << 0 << endl;
        return 0;
    }
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
w = list(range(1,int(raw_input())+1))
for i in range(int(raw_input())):
	a,b = map(int,raw_input().split(','))
	t = w[a-1]
	w[a-1] = w[b-1]
	w[b-1] = t
print('\n'.join(map(str,w)))

Measured memory_bytes: 4208
#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define vd vector<ld>
#define vvd vector<vector<ld>>
#define ALL(a) begin(a), end(a)
#define RALL(a) rbegin(a), rend(a)
#define SORT(a) stable_sort(ALL(a))
#define RSORT(a) stable_sort(RALL(a))
#define REV(a) reverse(ALL(a))
#define lambda(i) [](auto& i)
#define compare(i, j) [](auto& i, auto& j)
#define min_of(a) *min_element(ALL(a))
#define max_of(a) *max_element(ALL(a))
#define sum(a) accumulate(ALL(a), 0)
#define pb push_back
#define mp make_pair
#define SZ(a) ll((a).size())
#define REP(i, n) for (decltype(n) i = 0; i < (n); i++)
#define RREP(i, n) for (auto i = n - 1; i != static_cast<decltype(i)>(-1); i--)
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define RFOR(i, a, b) for (auto i = b - 1; i != a; i--)
#define EACH(i, a) for (auto&& i: (a))
using namespace std;

const ll INF = 1e18;
const ll mod = 1e9 + 7;

vi cum(vi V) {
  vi U(SZ(V));
  partial_sum(ALL(V), begin(U));
  return U;
}

void solve() {
  ll n;
  bool ans = true;

  cin >> n;
  vi v(n);
  REP(i, n) {
    cin >> v[i];
    if (v[i] % 2 == 0 && v[i] % 3 != 0 && v[i] % 5 != 0) ans = false;
  }

  cout << (ans ? "APPROVED" : "DENIED") << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout << fixed << setprecision(15);
  solve();
}


Measured memory_bytes: 256
#coding:utf-8
import bisect
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = True

def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]


    m = II()
    dc = XLMIIS(m)

    s = 0
    k = 0
    for i in range(m):
        s += dc[i][0] * dc[i][1]
        k += dc[i][1]

    if s % 9 == 0:
        ans = k + s//9 - 2
    else:
        ans = k + s//9 - 1

    print(ans)






if __name__ == '__main__':
    main()


Measured memory_bytes: 46768
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ll x, k, d;
  cin >> x >> k >> d;
  x = abs(x);
  if(x / d > k) cout << x - k * d << endl;
  else {
    ll n = x / d;
    x = x - n * d;
    if((k - n) % 2 == 0) cout << x << endl;
    else cout << d - x << endl;
  }
}

Measured memory_bytes: 3632
import java.util.*;
 
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.next(), T = sc.next();
    int a = 0;
    for(int i=0; i<3; i++) {
    if(S.substring(i,i+1).equals(T.substring(i,i+1))) {
    a++;
    }
    }
    System.out.println(a);
  }
}

Measured memory_bytes: 35716
list_num = int(input())
word_list= []
for i in range(list_num):
    word_list.append(input())
    
ac = word_list.count('AC')
wa = word_list.count('WA')
tle = word_list.count('TLE')
re = word_list.count('RE')

print('AC x ',ac)
print('WA x ',wa)
print('TLE x ',tle)
print('RE x ',re)

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

int D1[10] = {};
int D2[100] = {};
int D3[1000] = {};

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

    int P[N], Q[N];
    rep(i, N) cin >> P[i];
    rep(i, N) cin >> Q[i];

    vector<int> v;
    rep(i, N) v.push_back(i+1);

    int a=0, b=0;
    bool find_p = false, find_q = false;
    do {
        bool same_p = true, same_q = true;
        for (int i=0; i<v.size(); i++) {
            if (v[i] != P[i]) same_p = false;
            if (v[i] != Q[i]) same_q = false;
        }
        if (same_p) find_p = true;
        if (same_q) find_q = true;

        if (!find_p) a++;
        if (!find_q) b++;

    } while(next_permutation(v.begin(), v.end()));

    cout << abs(b - a) << endl;

    return 0;
}



Measured memory_bytes: 256
n,q = map(int,input().split())
S = input()
b = [0]*(n+10)
for i in range(1,n):
	if S[i-1] == 'A' and S[i] == 'C':
		b[i] = 1
for i in range(1,n):
	b[i] += b[i-1]
for i in range(q):
	l,r = map(int,input().split())
	print(b[r-1]-b[l-1]) 


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

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

#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;
const ll INF=1000000000000000;

vector<ll> pw2(51,1); vector<ll> pw10(19,1);
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll mid(ll x,ll y,ll z){return x>y?y>=z?y:min(z,x):x>=z?x:min(y,z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll myceil(ll x,ll y){if(x<=y) return 1;else if(x%y==0) return x/y;else return x/y+1;}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> divisor(ll x){vector<ll> div;
	for(ll i=1;i*i<=x;i++){if(x%i==0){div.pb(i);if(i*i!=x)div.pb(x/i);}}
	sort(div.bg,div.ed);return div;}


int main(){
	string s; cin>>s;
	ll K; cin>>K;
	ll i=0;
	while(s[i]=='1'){
		i++;
	}
	if(K<=i) cout<<1;
	else cout<<s[i]-'0';
}

Measured memory_bytes: 256