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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

ll dp[105][2][5];

string N;
ll K;

ll rec(ll idx, bool tight, ll kosu){
	if(kosu<0) return 0;
	if(dp[idx][tight][kosu]>=0) return dp[idx][tight][kosu];
	if(idx == (int)N.size()){
		return (kosu==0 ? 1 : 0);
	}

	ll res = 0;
	ll ub = (tight ? N[idx]-'0' : 9);
	for(int i=0;i<=ub;i++){
		bool flag = (i==ub ? tight : false);
		ll kn = kosu - (i==0 ? 0 : 1);
		res += rec(idx+1, flag, kn);
	}
	dp[idx][tight][kosu] = res;
	return res;
}

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

    cin >> N >> K;

    REP(i, 105) REP(j, 2) REP(k, 5) dp[i][j][k] = -1;

    cout << rec(0, true, K) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 int main (){
	
	int apple; 
	scanf ("%d",&apple);
	int potongan;
	potongan = apple*3;
	int pieces;
	scanf ("%d", &pieces);
	int pie; 
	pie = (pieces+potongan) / 2;
	printf("%d ", pie);
	
return 0;
}

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

int main(){
    int a, b;
    cin >> a >> b;

    if(a >= 13){
        cout << b << endl;
    }else if(a >= 6){
        cout << b/2 << endl;
    }else{
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
	public static void main(String[] args){
		char[] alfabet = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
		Scanner scn = new Scanner(System.in);
		int N = scn.nextInt();
		int p = 0,Shift;
		String s = scn.next();
		String result = "";
		char tmp[] = new char[10000];
		for(int i=0;i<s.length();i++){
			tmp[i] = s.charAt(i);
			for(int j=0;j<26;j++){
				if(tmp[i]==alfabet[j]){
					p=j;
					break;
				}
			}
			Shift = (p+N)%26;
			tmp[i] = alfabet[Shift];
		}
		for(int i=0;i<s.length();i++){
			result += tmp[i];
		}
		System.out.println(result);
	}
}

Measured memory_bytes: 145620
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
#include <iomanip>

using namespace std;

#define FOR(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)
#define REP(i, n) FOR((i), 0, (n))

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;


int getketa(int x){
    int cnt = 0;
    while(x>0){
        cnt++;
        x /= 10;
    }
    return cnt;
}

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

    ll memo[10][10] = {0};

    ll ans1 = 0, ans2 = 0;
    IFOR(a, 1, n){
        int tail = a % 10;
        int tmp = a;
        while(tmp>=10) tmp /= 10;
        int head = tmp;
        ans1 += memo[tail][head];

        if(head == tail){
            ans2++;
        }
        memo[head][tail]++;
    }
    ll ans = ans1*2+ans2;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
package main

import (
  "fmt"
)

func main() {
  var x,y,z,a,b,c int
  
  fmt.Scanf("%d%d%d", &x,&y,&z)
  a=x
  b=y
  c=z
  
  a=y
  b=x

  a=z
  c=y
  
  fmt.Printf("%d %d %d", a,b,c)
}

Measured memory_bytes: 512
s=input()
a,b,c,d=s[0],s[1],s[2],s[3]
ans='=7'
def bitmath(nums):
    return bin(nums)[2:].zfill(3).replace('0','+').replace('1','-')
for i in range(2**len(s)-1):
    op=bitmath(i)
    if eval(a+op[0]+b+op[1]+c+op[2]+d)==7:
        print(a+op[0]+b+op[1]+c+op[2]+d+ans)
        exit()


Measured memory_bytes: 3064
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <iomanip>       // fixed, setprecision
using namespace std;

int main()
{
  int64_t N, K, c = 0;
  cin >> N >> K;
  vector<int64_t> H(N);
  for (int i = 0; i < N; i++)
  {
    cin >> H.at(i);
  }
  sort(H.rbegin(), H.rend());
  for (int i = 0; i < N; i++)
  {
    if (K > 0)
    {
      K--;
    }
    else
    {
      c += H[i];
    }
  }
  cout << c << endl;
}


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

int main(){
	int a[3],k;
	cin >> a[0] >> a[1] >> a[2] >> k;

	sort(a, a+3);
	for (int i = 0; i < k; i++) {
		a[2] *= 2;
	}
	cout << a[0] + a[1] + a[2] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <tuple>
#include <numeric>

using namespace std;

int main()
{
    int w, h, n;
    cin >> w >> h >> n;
    int x[n], y[n], a[n];
    for(int i=0; i<n; ++i) cin >> x[i] >> y[i] >> a[i];

    int x_min = 0, x_max = w, y_min = 0, y_max = h;
    for(int i=0; i<n; ++i){
        if(a[i] == 1){
            if(x[i] > x_min){
                x_min = x[i];
            } 
        }
        else if(a[i] == 2){
            if(x[i] < x_max){
                x_max = x[i];
            }
        }
        else if(a[i] == 3){
            if(y[i] > y_min){
                y_min = y[i];
            }
        }
        else if(a[i] == 4){
            if(y[i] < y_max){
                y_max = y[i];
            }
        }
    }
    if(x_max-x_min>=0 && y_max-y_min>=0) cout << (x_max-x_min)*(y_max-y_min) << endl;
    else cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int h,w;
	while(cin>>h>>w)
	{
		vector<pair<int,int> > v; 
		char c[h][w];
		for(int i=0;i<h;i++)
		{
			for(int j=0;j<w;j++) 
			{
				cin>>c[i][j];
				if(c[i][j]=='.') v.push_back(pair<int,int>(i,j));
			}
		}
		int ans=-1;
		for(int i=0;i<v.size();i++)
		{
			int n[h][w];
			memset(n,0,sizeof(n));
			n[v[i].first][v[i].second]=1;
			queue<int> x;
			queue<int> y;
			y.push(v[i].second);
			x.push(v[i].first);
			while(!x.empty())
			{
				if(x.front()-1>=0)
				{
					int x2=x.front()-1;
					int y2=y.front();
					if(c[x2][y2]=='.'&&!n[x2][y2]) n[x2][y2]=n[x.front()][y.front()]+1,x.push(x2),y.push(y2);	
				} 
				if(x.front()+1<h)
				{
					int x2=x.front()+1;
					int y2=y.front();
					if(c[x2][y2]=='.'&&!n[x2][y2]) n[x2][y2]=n[x.front()][y.front()]+1,x.push(x2),y.push(y2);	
				} 
				if(y.front()-1>=0)
				{
					int x2=x.front();
					int y2=y.front()-1;
					if(c[x2][y2]=='.'&&!n[x2][y2]) n[x2][y2]=n[x.front()][y.front()]+1,x.push(x2),y.push(y2);	
				} 
				if(y.front()+1<w)
				{
					int x2=x.front();
					int y2=y.front()+1;
					if(c[x2][y2]=='.'&&!n[x2][y2]) n[x2][y2]=n[x.front()][y.front()]+1,x.push(x2),y.push(y2);	
				} 
				x.pop();
				y.pop();
			}
			/*for(int i=0;i<h;i++)
			{
				for(int j=0;j<w;j++) cout<<n[i][j]<<" ";
				cout<<"\n";
			}
			cout<<"\n";*/
			
			for(int i=0;i<h;i++) ans=max(ans,*max_element(n[i],n[i]+w)-1);
		}
		cout<<ans<<"\n";
	}
	return 0;
}

Measured memory_bytes: 256
import math
import sys
from itertools import accumulate
from functools import reduce
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

sys.setrecursionlimit(10000)

mod = 1000000007

"""
# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]

# 標準入力取得
## 文字列
    = sys.stdin.readline().rstrip()
    = list(sys.stdin.readline().rstrip())

## 数値
    = int(sys.stdin.readline())
    = map(int, sys.stdin.readline().split())
    = list(map(int, sys.stdin.readline().split()))
    = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき
"""

if __name__ == "__main__":
    A, B, C, D = map(int, sys.stdin.readline().split())
    L = A + B
    R = C + D
    if L > R:
        print("Left")
    elif R > L:
        print("Right")
    else:
        print("Balanced")



Measured memory_bytes: 5232
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a, five = 0, seven = 0;
		for (int i = 0; i < 3; i++) {
			a = sc.nextInt();
			if (a == 5) {
				five++;
			} else if (a == 7) {
				seven++;
			}
		}
		if (five == 2 && seven == 1) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
		sc.close();
	}
}

Measured memory_bytes: 21844
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

A,B,Q = inpl()
s = [int(input()) for i in range(A)]
t = [int(input()) for i in range(B)]
ss = [-INF] + s + [INF]
tt = [-INF] + t + [INF]

for _ in range(Q):
    x = int(input())
    si = bisect.bisect_left(ss,x)
    ti = bisect.bisect_left(tt,x)
    sl,sr = x-ss[si-1] , ss[si]-x
    tl,tr = x-tt[ti-1] , tt[ti]-x
    ans = INF
    ans = min(ans,max(sr,tr))
    ans = min(ans,max(sl,tl))
    ans = min(ans,sl*2 + tr)
    ans = min(ans,tl*2 + sr)
    ans = min(ans,sr*2 + tl)
    ans = min(ans,tr*2 + sl)
    print(ans)


Measured memory_bytes: 15512
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(A,x,n) rep(I,0,n){cout<<(I ? " ":"")<<A[I]x;}cout<<endl;
#define pprint(A,y,m,n) rep(J,0,m){print(A[J],y,n);}
const long mod=1e9+7;
const int size=1e5;
const int inf=1e9;
int main(){
	string s,t; cin>>s>>t;
	vector<char> a,b;
	for(char c:s) a.push_back(c);
	for(char c:t) b.push_back(c);
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	reverse(b.begin(), b.end());
	rep(i,0,s.size()) s[i] = a[i];
	rep(i,0,t.size()) t[i] = b[i];
	cout<<(s < t ? "Yes" : "No")<<endl;
}

Measured memory_bytes: 256
while True:
    H, W = map(int, input().split())
    if H == W == 0:
        break
    for i in range(H):
        for j in range(W):
            if (i+j) % 2 == 0:
                print('#', end='')
            else:
                print('.', end='')
        print()
    print()


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

using namespace std;

bool ispalindrome(int n) {
  string s = to_string(n);
  for (int i = 0; i < 2; i++)
    if (s[i] != s[s.size() - i - 1]) return false;
  return true;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int A, B;
  cin >> A >> B;
  int cnt = 0;
  for (int i = 10000; i < 100000; i++)
    if (ispalindrome(i) && i >= A && i <= B) cnt++;
  cout << cnt << '\n';
  return 0;
}


Measured memory_bytes: 256
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, k  = na()
ans = 1
i =1
while (k*i <= n):
  i *= k
  ans +=1
print(ans)
  

Measured memory_bytes: 9100
import std.stdio, std.conv, std.string;
import std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

int DEBUG_LEVEL = 0;
void print()(){ writeln(""); }
void print(T, A ...)(T t, lazy A a){ write(t), print(a); }
void print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }

void main(string[] args){
	if(args.length > 1 && args[1] == "-debug"){
		if(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;
		else DEBUG_LEVEL = 1;
	}
	
	int n = read.to!int;
	
	int a = n / 100, b = n % 100;
	
	bool x = (a >= 1 && a <= 12), y = (b >= 1 && b <= 12);
	
	
	if(x && y) writeln("AMBIGUOUS");
	if(! x && y) writeln("YYMM");
	if(x && ! y) writeln("MMYY");
	if(! x && ! y) writeln("NA");
	
}


Measured memory_bytes: 256
import math

a = [int(input()) for _ in range(5)]
a_2 = [(i-1)%10 for i in a]

last_item=a[a_2.index(min(a_2))]
print(int(sum([math.ceil(i/10)*10 for i in a])+((last_item-1)%10-9)))


Measured memory_bytes: 62088
import queue
n = int(input())

abc = [[] for i in range(n+1)]

for i in range(n-1):
    a,b,c = map(int,input().split())
    abc[a].append([b,c])
    abc[b].append([a,c])

Q,k = map(int,input().split())
xy = [[int(i) for i in input().split()] for j in range(Q)]

q = queue.Queue()

q.put(k)

path = [-1]*(n+1)
path[k] = 0

while not q.empty():
    tmp = q.get()
    for i in range(len(abc[tmp])):
        #print(abc[tmp])
        #exit()
        num = abc[tmp][i][0]
        if path[num] != -1:
            continue
        else:
            path[num] = path[tmp] + abc[tmp][i][1]
            q.put(num)
            
for i in range(Q):
    print(path[xy[i][0]]+path[xy[i][1]])

Measured memory_bytes: 68648
#include <iostream>
using namespace std;
int i,n,a,b,val,nr1,nr2,nr3,ans;
int main()
{
    cin>>n>>a>>b;
    for(i=1;i<=n;++i)
    {
        cin>>val;
        if(val<=a)++nr1;
        else if(val>a && val<=b)++nr2;
        else if(val>b)nr3++;
    }
    ans=min(nr1,nr2);ans=min(nr3,ans);
    cout<<ans<<'\n';

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a, b;
	int n;
	int i;
	int A, B;
	
	while (1){
		A = B = 0;
		scanf("%d", &n);
		if (n == 0) break;
		
		for (i = 0; i < n; i++){
			scanf("%d %d", &a, &b);
			if (a == b){
				A += a;
				B += b;
			}
			else if (a > b){
				A += a;
				A += b;
			}
			else if (a < b){
				B += a;
				B += b;
			}
		}
		printf("%d %d\n", A, B);
	}
	return (0);
}

Measured memory_bytes: 600
import sys
lines = sys.stdin.readlines()
n = int(lines[0])
arr = list(map(int, lines[1].split(' ')))

maxi = 62
mod = int(1e9) + 7
ones = [0 for _ in range(maxi)]
for num in arr:
    for idx, val in enumerate(range(maxi)):
        ones[idx] += (num >> idx ) & 1

ans = 0
for idx, val in enumerate(ones):
    ans += ((pow(2, idx) % mod) * (((n - val)%mod) * (val%mod))) % mod

    ans %= mod

print(ans)

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

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int i=(first);i<(last);++i){cout<<#a<<"["<<i<<"] = "<<(a)[i]<<endl;}
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#endif

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}

int main(void)
{
    const int N_MAX = 100000;
    int N, M;
    int a[N_MAX];
    vector<int> edges[N_MAX];
    cin >> N >> M;
    if ((N - 1 - M) * 2 > N) {
        cout << "Impossible" << endl;
        return 0;
    }
    REP(i, N) cin >> a[i];
    REP(i, M) {
        int x, y;
        cin >> x >> y;
        edges[x].push_back(y);
        edges[y].push_back(x);
    }
    bool used[N_MAX], used2[N_MAX];
    REP(i, N) {
        used[i] = false;
        used2[i] = false;
    }
    int n_trees = 0;
    int cost[2];
    ll result = 0;
    int n_verteces_need = (N - 1 - M) * 2;
    REP(i, N) {
        if (!used[i]) {
            ++n_trees;
            used[i] = true;
            int min_i = i;
            queue<int> q;
            q.push(i);
            while (!q.empty()) {
                int u = q.front();
                q.pop();
                for (int v: edges[u]) {
                    if (!used[v]) {
                        used[v] = true;
                        if (a[min_i] > a[v]) {
                            min_i = v;
                        }
                        q.push(v);
                    }
                }
            }
            if (n_verteces_need > 0) {
                used2[min_i] = true;
                result += a[min_i];
                --n_verteces_need;
            }
        }
    }
    vector<int> b;
    REP(i, N) {
        if (!used2[i]) {
            b.push_back(a[i]);
        }
    }
    sort(b.begin(), b.end());
    REP(i, n_verteces_need) {
        result += b[i];
    }
    cout << result << endl;
    return 0;
}


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

struct Edge {
    int to, id;
    Edge (int to, int id) : to(to), id(id) { }
    bool operator< (const Edge &r) const {
        return (id < r.id);
    }
};

int n, m;
vector<vector<Edge>> g;
vector<pair<int, int>> edges;
vector<bool> cycle, idx, seen;

bool dfs1 (int v, int t) {
    if (v == t and seen[v]) return cycle[v] = true;
    if (seen[v]) return false;
    seen[v] = true;
    for (const auto &e : g[v]) {
        if (dfs1(e.to, t)) {
            idx[e.id] = true;
            return cycle[v] = true;
        }
    }
    return false;
}

int restore () {
    int res = 0;
    vector<vector<Edge>> h(n);
    for (int i = 0; i < m; i++) {
        int a, b; tie(a, b) = edges[i];
        if (cycle[a] and cycle[b]) {
            if (not idx[i]) res = i;
            h[a].emplace_back(b, i);
        }
    }
    swap(g, h);
    return res;
}

bool ok () {
    vector<int> indeg(n, 0), outdeg(n, 0);
    for (int v = 0; v < n; v++) {
        for (const auto &e : g[v]) {
            indeg[e.to]++; outdeg[v]++;
        }
    }
    for (int i = 0; i < n; i++) {
        if (indeg[i] == 0 and outdeg[i] == 0) continue;
        if (indeg[i] == 1 and outdeg[i] == 1) continue;
        return false;
    }
    return true;
}

bool dfs2 (int v, int t) {
    if (v == t) return cycle[v] = true;
    seen[v] = true;
    for (const auto &e : g[v]) {
        if (seen[e.to]) continue;
        if (dfs2(e.to, t)) {
            idx[e.id] = true;
            return cycle[v] = true;
        }
    }
    return false;
}

int main() {
    cin >> n >> m;
    g.resize(n);
    cycle.resize(n);
    idx.resize(m);
    seen.resize(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].emplace_back(b, i);
        edges.emplace_back(a, b);
    }
    
    auto refresh = [&]() -> void {
        fill(cycle.begin(), cycle.end(), false);
        fill(idx.begin(), idx.end(), false);
        fill(seen.begin(), seen.end(), false);
    };
    
    bool no_cycle = true;
    for (int v = 0; v < n; v++) {
        refresh();
        if (dfs1(v, v)) { no_cycle = false; break; }
    }
    
    if (no_cycle) { cout << -1 << '\n'; return 0; }
    int index = restore();
    
    while (not ok()) {
        refresh();
        int a, b; tie(a, b) = edges[index];
        idx[index] = true;
        dfs2(b, a);
        index = restore();
    }
    
    vector<int> ans;
    for (int i = 0; i < n; i++) {
        if (cycle[i]) ans.emplace_back(i + 1);
    }
    
    cout << ans.size() << '\n';
    for (const int &e : ans) cout << e << '\n';
    
    return 0;
}

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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
  int n;cin>>n;
  vector<int> a(n);
  int i,j,k;
  rep(i,n)cin>>a[i];
  vector<vector<vector<double>>> dp(n+1,vector<vector<double>>(n+1,vector<double>(n+1,0.0)));
  dp[0][0][0]=0.0;
  rep(k,n+1)
  {
    rep(j,n+1)
    {
      rep(i,n+1)
      {
        if(i==0&&j==0&&k==0)continue;
        if(i+j+k>n)break;
        if(i-1>=0)
        {
          dp[i][j][k]+=dp[i-1][j][k]*i/n;
        }
        if(i+1<=n&&j-1>=0)
        {
          dp[i][j][k]+=dp[i+1][j-1][k]*j/n;
        }
        if(j+1<=n&&k-1>=0)
        {
          dp[i][j][k]+=dp[i][j+1][k-1]*k/n;
        }
        dp[i][j][k]+=1.0;
        dp[i][j][k]*=(double)n/(i+j+k);
      }
    }
  }
  vector<int> count(3,0);
  rep(i,n)count[a[i]-1]++;
  cout<<fixed<<setprecision(10)<<dp[count[0]][count[1]][count[2]]<<endl;
}

Measured memory_bytes: 216832
#include<iostream>
#include <string>
#include <memory>

using namespace std;

int main()
{
    int K;
    string S;

    cin >> K >> S;

    if (S.size() <= K)
    {
        cout << S << '\n';
    }
    else
    {
        cout << string(begin(S), begin(S) + K) << "...\n";
    }
    return 0;
}


Measured memory_bytes: 3580
#include<bits/stdc++.h>
#define N 10009
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;

int main()
{
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    if(a <= c && c <= b) puts("Yes");
    else puts("No");
    return 0;
}










Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
const long long INF = 1LL << 60;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int X,Y;
  cin >> X >> Y;
  if(X==1&&Y==1)
  {
    cout << 1000000 << endl;
    return 0;
  }
  int sum = 0;
  if(X==1)
  {
    sum += 300000;
  }
  else if(X==2)
  {
    sum += 200000;
  }
  else if(X==3)
  {
    sum += 100000;
  }
  if(Y==1)
  {
    sum += 300000;
  }
  else if(Y==2)
  {
    sum += 200000;
  }
  else if(Y==3)
  {
    sum += 100000;
  }
  cout << sum << endl;
  return 0;
}


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


using namespace std;


int main()
{


	int r, n;
	while (cin >> r >> n && r){
		
		map<int, int> d,d2;
		for (int x = -21; x < 21; x++)d[x] = 0;
		for (int i = 0; i < n; i++){
			int xl, xr, h;
			cin >> xl >> xr >> h;
			for (int x = xl + 1; x <= xr; x++)d[x] = max(d[x], h);
			for (int x = xl; x < xr; x++)d2[x] = max(d2[x], h);
		}

		double ans = 1e9;
		for (double x = -r; x <= r; x++){


			double ty = double(r) - sin(acos(abs(x / double(r)))) * double(r);

			if (x != -r)ans = min(ans, double(d[x] + ty));
			if (x != r)ans = min(ans, double(d2[x] + ty));
		}

		cout << setprecision(6) << ans << endl;

	}

	return 0;
}

Measured memory_bytes: 1332
#include<stdio.h>
#include<string.h>


char str[27];
int istr[26];
bool use[26];
const char cs = 'a';

int main(){
	int i,j;
	int n;
	scanf("%s",str);	
	for(n=0;str[n];n++){
		istr[n] = str[n] - cs;
		use[istr[n]] = true;
	}
	if(n < 26){
		char add;
		for(i=0;i<n && use[i];i++);
		add = i + cs;
		sprintf(str,"%s%c",str,add);
	}
	else if(strcmp(str,"zyxwvutsrqponmlkjihgfedcba") == 0){
		printf("-1");
		return 0;
	}
	else{
		use[istr[n-1]] = false;
		for(i=n-2;i>=0;i--){
			use[istr[i]] = false;
			
			//for(j=0;j<26;j++){
			//	printf("%d",use[j]);
			//}
			//printf("\n");
			for(j=istr[i]+1;j<26;j++){
				if(!use[j])break;
			}
			if(j != 26){
				str[i] = j + cs;
				str[i+1] =0;
				break;
			}
		
		
		}
	/*
		for(i=n-2;i>=0;i--){
			char check = istr[i];
			char min_s = 100;
			bool u[26];
			u[min_s] = true;
			for(j=i+1;j<n;j++){
				u[istr[j]] = true;
				min_s = (min_s < istr[j])?min_s:istr[j];
			}
			//printf("%d %d\n",min_s,check);
			if(min_s > check){
				str[i] = min_s + cs;
				str[i+1] = 0;
				break;
			}
			for(j=0;j<min_s;j++){
				if(!u[j])break;
			}
		}
		if(i == -1){
			str[0]++;
			str[1]=0;
		}
		*/
	}
	printf("%s",str);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(int i=0;i<n;i++)
#define int long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
#define mod 1000000007
#define inf 1e15
#define key 1e9
using namespace std;
typedef pair<int, int>P;
void yes() { cout << "Yay!" << endl; }
void no() { cout << ":(" << endl; }
template<class T> inline void chmax(T& a, T b) {
	a = std::max(a, b);
}
template<class T> inline void chmin(T& a, T b) {
	a = std::min(a, b);
}
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y)* mod_pow(kai(y, y), mod - 2, mod) % mod;
}
void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug_out(T...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
struct edge { int to, cost; };
int par[114514], rrank[114514];//親、木の深さ
void init(int n) {
	rep(i, n) {
		par[i] = i;
		rrank[i] = 0;
	}
}
int find(int x) {
	if (par[x] == x) {
		return x;
	}
	else return par[x] = find(par[x]);
}
void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y)return;
	if (rrank[x] < rrank[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (rrank[x] == rrank[y])rrank[x]++;
	}
}
bool same(int x, int y) {
	return find(x) == find(y);
}
signed main() {
	int a, b;
	cin >> a >> b;
	cout << (3 * a + b) / 2 << endl;
	ggr
}



Measured memory_bytes: 256
import java.util.Scanner;


public class Main{
	public static void main(String[]args){
		Scanner sc=new Scanner(System.in);
		String x=sc.next();
		String y=sc.next();
		int inx=0;
		int [][]L=new int[x.length()+1][y.length()+1];
		for(int i=0;i<=x.length();i++){
			for(int j=0;j<=y.length();j++){
				if(i==0||j==0)
					L[i][j]=0;
				else
					if(x.charAt(i-1)==y.charAt(j-1))
						L[i][j] = L[i-1][j-1] + 1; 
					else
						L[i][j]=Math.max(L[i][j-1],L[i-1][j]);
				inx=L[i][j];
			}
		}char[]c=new char[inx+1];
		c[inx]=' ';
		for(int i=x.length(),j=y.length();i>0&&j>0;){
			if(x.charAt(i-1)==y.charAt(j-1)){
				c[inx-1]=x.charAt(i-1);
				i--;j--;inx--;
			}else if(L[i-1][j]>L[i][j-1])
				i--;
			else
				j--;
		}for(int i=0;i<c.length;i++){
			System.out.print(c[i]);
		}
	}
}

Measured memory_bytes: 83276
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<cmath>
#include<map>
#include<functional>
#include<queue>
#include<set>
#include<stack>
#include<iomanip>
#include<algorithm>
#include<unordered_map>
#include <numeric>
#include<string_view>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(i) i.begin(),i.end()
template<typename T =ll> using v = vector<T>;
template<typename T =ll> using vv = v<v<T>>;
template<typename T =ll,typename U =ll> using p = pair<T,U>;
template<typename T> T chmin(T &a,T b) {return a=min(a,b);}
template<typename T> T chmax(T &a,T b) {return a=max(a,b);}
const ll INF = (ll)1e9;
template <int MOD>
struct ModInt {
    using lint = long long;
    int val;

    // constructor
    ModInt(lint v = 0) : val(v % MOD) {
        if (val < 0) val += MOD;
    };

    // unary operator
    ModInt operator+() const { return ModInt(val); }
    ModInt operator-() const { return ModInt(MOD - val); }
    ModInt inv() const { return this->pow(MOD - 2); }

    // arithmetic
    ModInt operator+(const ModInt& x) const { return ModInt(*this) += x; }
    ModInt operator-(const ModInt& x) const { return ModInt(*this) -= x; }
    ModInt operator*(const ModInt& x) const { return ModInt(*this) *= x; }
    ModInt operator/(const ModInt& x) const { return ModInt(*this) /= x; }
    ModInt pow(lint n) const {
        auto x = ModInt(1);
        auto b = *this;
        while (n > 0) {
            if (n & 1) x *= b;
            n >>= 1;
            b *= b;
        }
        return x;
    }

    // compound assignment
    ModInt& operator+=(const ModInt& x) {
        if ((val += x.val) >= MOD) val -= MOD;
        return *this;
    }
    ModInt& operator-=(const ModInt& x) {
        if ((val -= x.val) < 0) val += MOD;
        return *this;
    }
    ModInt& operator*=(const ModInt& x) {
        val = lint(val) * x.val % MOD;
        return *this;
    }
    ModInt& operator/=(const ModInt& x) { return *this *= x.inv(); }

    // compare
    bool operator==(const ModInt& b) const { return val == b.val; }
    bool operator!=(const ModInt& b) const { return val != b.val; }

    // I/O
    friend std::istream& operator>>(std::istream& is, ModInt& x) noexcept { return is >> x.val; }
    friend std::ostream& operator<<(std::ostream& os, const ModInt& x) noexcept { return os << x.val; }
};

constexpr int MOD = 1e9 + 7;
using mint = ModInt<MOD>;
void c(){
    string s; cin >> s;
    ll K; cin >> K;
    ll znump = (ll)'z'+1-'a';
    v<> snum;
    ll N =s.size();
    rep(i,N){
        snum.push_back((ll)(s[i]-'a'));
    }
    for(ll i=0;i<N&&K>0;i++){
        if(snum[i]==0) continue;
        ll cntzp = znump-snum[i];
        if(K>=cntzp) {
            K-=cntzp;
            snum[i]=0;
        }
    }

    snum[N-1]=(snum[N-1]+K)%znump;
    
    rep(i,N){
        cout << static_cast<char>(snum[i]+'a');
    }
}
int main(void){
    c();
    return 0;
 }

Measured memory_bytes: 4452
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {
 
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		long mod = (long)(1e9+7);
		long N = input.nextLong();
		long K = input.nextLong();
		long maxCap = N*(N+1)/2; //NO OVERFLOW!
		long cnt = 0;
		//long minCap = (K-1)*K/2;
		for (long i = K; i <= N; i++) {
			cnt+=maxCap;
			cnt-=(N-i)*(N-i+1)/2;
			cnt-=i*(i-1)/2;
			cnt%=mod;
			cnt++;
		}
		cnt++; //(only one sum when picking all numbers)
		System.out.println(cnt);
	}
}

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

const ll mod = 1e9 + 7;

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

/*-------------------------------------------*/

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

    int k, q;
    cin >> k >> q;
    ll d[k];
    rep(i, k) { cin >> d[i]; }

    while(q--) {
        ll n, x, m;
        cin >> n >> x >> m;
        ll cnt = 0;
        x %= m;
        rep(i, k) {
            if(d[i] % m != 0) {
                ll y = (n - 2 - i + k) / k;
                cnt += y;
                x += y * (d[i] % m);
            }
        }
        cout << cnt - x / m << endl;
    }
}

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

int n = 0, m = 0;
int main()
{
	
	scanf("%d", &n);
	int temp = n;
	while (temp != 0)
	{
		m += temp % 10;
		temp = temp / 10;
	}
	if (n%m == 0) printf("Yes\n");
	else printf("No\n");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <ios>
#include <iomanip>
#include <algorithm>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define ENDL cout << endl;
using namespace std;
using LL = long long;
using LD = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using PLL = pair<LL, LL>;
using VPLL = vector<PLL>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
using VD = vector<double>;
const LL INF = 1e18;
const LL MOD = 1e9 + 7;

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

void END(){cout << 1 << endl; exit(0);}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  LL a, b, k;
  cin >> a >> b >> k;
  LL aa = a, kk = k;
  a -= min(aa, kk);
  k -= min(aa, kk);
  if (k > 0) b -= min(b, k);
  cout << a << " " << b << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int cmpint(const void *x, const void *y) { return *(int *)x - *(int *)y; }
int main() {
	int n, d[100], ans;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &d[i]);
	}
	qsort(d, n, sizeof(int), cmpint);
	ans = n;
	for (int i = 1; i < n; i++) {
		if (d[i - 1] == d[i]) {
			ans--;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define mod 998244353
using namespace std;
int fac[1000005],inv[1000005],n,m;
inline int qpow(int a,int b)
{int tp=a,res=1;
while (b)
{if (b&1) res=1ll*res*tp%mod;
tp=1ll*tp*tp%mod;b>>=1;
}
return res;
}
inline int cal(int a,int b)
{return 1ll*(1ll*fac[a+b]*inv[a]%mod)*inv[b]%mod;}
int main (){
	int i,ans;
	scanf ("%d%d",&n,&m);
	if (n>m) swap(n,m);
	for (fac[0]=1,i=1;i<=n+m;i++)fac[i]=1ll*fac[i-1]*i%mod;
	for (inv[n+m]=qpow(fac[n+m],mod-2),i=n+m-1;i>=0;i--)inv[i]=1ll*inv[i+1]*(i+1)%mod;
	int tot=cal(n,m),now=0;
	for (i=1;i<=n;i++)
	{now+=1ll*cal(i,i)*cal(n-i,m-i)%mod;
	if (now>=mod) now-=mod;
	}
	now=1ll*now*qpow(tot,mod-2)%mod;
	now=1ll*now*qpow(2,mod-2)%mod;
	now=(now+m>=mod?now+m-mod:now+m);
	printf ("%d\n",now);
	return 0;
}

Measured memory_bytes: 8064
function main(arg) {
    var tmp = arg.split("\n").map(n=>parseInt(n));
    var N = tmp[0];
    var H = tmp[1];
    var W = tmp[2];
    
    console.log( (1 + (N - W)) * (1 + (N - H)));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21064
"""
#kari1 = 'needed' #2 5
#kari1 = 'atcoder' #-1 -1
in1 = kari1
"""
in1 = input()

RC = '-1 -1'

str1 = in1[0]
str2 = in1[1]

if str1 != str2:
    idx1 = 0
    for idx1 in range(2, len(in1) - 2):
        if   in1[idx1] == str1:
            RC = str(idx1 - 1) + ' ' + str(idx1 + 1)
            break
        elif in1[idx1] == str2:
            RC = str(idx1) + ' ' + str(idx1 + 1)
            break
        else:
            str1 = str2
            str2 = in1[idx1]
elif str1 == str2:
    RC = '1 2'

print(RC)


Measured memory_bytes: 3188
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;


int main() {
	int N; cin >> N;
	if (N == 0||N==2)cout << 1 << endl;
	else if (N == 1)cout << 2 << endl;
	else cout << 0 << endl;
	return 0;
}

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

using namespace std;

#define llong long long int
#define ldouble long double
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) x.begin(), x.end()
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)

const static int MOD = 1000000000 + 7;
const static llong INF = 1LL << 60;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};

template<typename T> T my_gcd(T a, T b) {
    return (a ? my_gcd(b % a, a) : b);
}

template<typename T> T my_lcm(T a, T b){
	return a * b / my_gcd(a, b);	
}

struct UF {
    vector<int> par, sz;

    UF(int n) {
        par.resize(n);
        sz.resize(n);
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            sz[i] = 1;
        }
    }

    int find_root(int x) {
        return par[x] == x ? x : par[x] = find_root(par[x]);
    }

    bool same(int x, int y) {
        return find_root(x) == find_root(y);
    }

    void unite(int x, int y) {
        x = find_root(x);
        y = find_root(y);
        if (x == y) return;
        
        if (sz[x] < sz[y]) swap(x, y);
        sz[x] += sz[y];
        par[y] = x;
    }
};

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

    int a, b, k;
    cin >> a >> b >> k;
    int cnt = 0;
    vector<int> tmp;
    for (int i = 1; i <= min(a, b); ++i) {
        if ((a % i) == 0 && (b % i) ==0) tmp.push_back(i);
        if (cnt == k) {
            break;
        }
    }
    reverse(all(tmp));
    cout << tmp[k - 1] << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public  class Main  {

	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
	 int N = sc.nextInt();
	 String s = sc.next();
	 char[] s_i= s.toCharArray();
	int redcounter = 0;
	for(int i = 0; i<s_i.length; i++) {
		if(s_i[i]=='R')redcounter++;
		else redcounter--;
	}
	System.out.println(redcounter>0 ? "Yes":"No");
}

		
	}



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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

const ll MOD = 1000000007;
const int MN = 610;

int N, K;
ll dp[MN][MN];
int mt[MN];
ll sub[MN];
int in[MN][MN];

int main() {
	sub[0] = 1;
	for (int i = 2; i < MN; i += 2) {
		sub[i] = sub[i-2] * (i-1) % MOD;
	}

	cin >> N >> K;

	memset(mt, -1, sizeof(mt));

	rep(i, K) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		mt[a] = b; mt[b] = a;
	}

	N *= 2;

	for (int l = 0; l < N; ++l) {
		for (int r = l; r < N; ++r) {
			bool ok = 1;
			int num = 0;

			for (int m = l; m <= r; ++m) {
				if (mt[m] != -1) {
					if (mt[m] < l || mt[m] > r) {
						ok = 0;
					} else {
						num++;
					}
				}
			}

			if (ok) {
				in[l][r] = num;
			} else {
				in[l][r] = -1;
			}			
		}
	}

	for (int len = 2; len <= N; len += 2) {
		for (int l = 0; l <= N - len; ++l) {
			int r = l + len - 1;

			if (in[l][r] == -1) continue;
			ll t = sub[len - in[l][r]];

			for (int m = l+1; m < r; m += 2) if (in[m+1][r] != -1) {
				t = (t - dp[l][m] * sub[r - m - in[m+1][r]]) % MOD;
				if (t < 0) t += MOD;
			}
			dp[l][r] = t;
		}
	}

	ll ret = 0;
	for (int i = 0; i < N; ++i) {
		for (int j = i; j < N; ++j) {
			if (dp[i][j] == 0) continue;
			int dec = N - K * 2 - (j - i + 1 - in[i][j]);
			ret = (ret + dp[i][j] * sub[dec]) % MOD;
		}
	}

	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 4480
#include <bits/stdc++.h>
#include <cstdio>
 
using namespace std;
 
#define deb(x) cout << #x << " " << x << endl;
 
typedef long long ll;
const ll mod = 1000000007;
 
#define For(i,n) for(int i=0;i<n;i++)
 
 
int main(){
   // freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ll h,g,ans,count;
    count=0;
    cin>>h;
    g=h;
    if(h==1)
        cout<<1;
    else{
        while(g!=0){
            g=g>>1;
            count++;
        }
        ans=((ll)1<<count)-1;
        cout<<ans;
    }
    return 0;
}

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

const int maxn=10+1e5,mod=7+1e9;
int c[maxn],r;

/*long long pow(int a,int p)
{
	if(p==0) return 1;
	r=pow(a,p/2);
	r=(r*r)%mod;
	if(p%2==1) return (r*a)%mod;
	return r;
}*/

int main()
{
	bool dobro;
	int a,n;
	cin>>n;
	dobro=true;
	for(int i=0;i<n;i++)
	{
		cin>>a;
		c[a]++;
	}
	for(int i=1-n%2;i<=n-1;i+=2)
		if((i>0 and c[i]!=2) or (i==0 and c[i]!=1)) dobro=false;
	if(dobro)
	{
		long long sol=1;
		for(int i=0;i<n/2;i++) sol=(sol*2)%mod;
		cout<<sol;
	}
	else cout<<0;
}

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

int main() {
  long h,w,k,ans=99999999;
  cin >> h >> w >> k;
  vector<string> a(h);
  vector<vector<bool>> b(h,vector<bool>(w,false));
  queue<long> y;
  queue<long> x;
  for(long i=0;i<h;i++) cin >> a[i];
  for(long i=0;i<h;i++) {
    for(long j=0;j<w;j++) {
      if(a[i][j]=='S') {
        x.push(j);
        y.push(i);
        b[i][j]=true;
      }
      if(a[i][j]=='#') b[i][j]=true;
    }
  }
  for(long i=0;i<k;i++) {
    long l=y.size();
    for(long j=0;j<l;j++) {
      if(x.front()!=0&&!(b[y.front()][x.front()-1])) {
        y.push(y.front());
        x.push(x.front()-1);
        b[y.front()][x.front()-1]=true;
      }
      if(x.front()!=w-1&&!(b[y.front()][x.front()+1])) {
        y.push(y.front());
        x.push(x.front()+1);
        b[y.front()][x.front()+1]=true;
      }
      if(y.front()!=0&&!(b[y.front()-1][x.front()])) {
        y.push(y.front()-1);
        x.push(x.front());
        b[y.front()-1][x.front()]=true;
      }
      if(y.front()!=h-1&&!(b[y.front()+1][x.front()])) {
        y.push(y.front()+1);
        x.push(x.front());
        b[y.front()+1][x.front()]=true;
      }
      y.pop();
      x.pop();
    }
  }
  for(long i=0;i<h;i++) {
    for(long j=0;j<w;j++) {
      if(b[i][j]&&a[i][j]!='#') {
        ans=min(ans,(j+k-1)/k+1);
        ans=min(ans,(w-j-1+k-1)/k+1);
        ans=min(ans,(i+k-1)/k+1);
        ans=min(ans,(h-i-1+k-1)/k+1);
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 4516
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  int a[n];
  rep(i,n) cin>>a[i];
  sort(a,a+n);
  int x=a[n-1];
  int ans=0;
  // cout<<x<<endl;
  rep(i,n-1){
    // cout<<double(ans-x)<<" "<<double(x-a[i])<<" "<<ans<<endl;
    if(abs(ans*2 - x) > abs(a[i]*2 - x)){
      ans=a[i];
    }
  }
  cout<<a[n-1]<<" "<<ans<<endl;
  

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k, q;
  cin >> n >> k >> q;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int ans = (int) 2e9;
  for (int bound : a) {
    vector<int> c;
    multiset<int> s;
    for (int i = 0; i <= n; i++) {
      if (i == n || a[i] < bound) {
        sort(c.begin(), c.end());
        for (int j = 0; j <= (int) c.size() - k; j++) {
          s.insert(c[j]);
        }
        c.clear();
      } else {
        c.push_back(a[i]);
      }
    }
    if ((int) s.size() < q) {
      continue;
    }
    auto it = s.begin();
    for (int i = 0; i < q - 1; i++) {
      it++;
    }
    ans = min(ans, *it - bound);
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3732
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e9;
const ll INF = 1e18;
const ld EPS = 1e-10;

int main(){
    ll H, W;
    cin >> H >> W;
    ll ans = INF;
    rep(i, H+1){
        ll h = H-i, w = W;
        vector<ll> vs;
        vs.pb(i*W);
        if((h*w)%2 == 0) vs.pb((h*w)/2);
        else{
            if((h/2)*w > (w/2)*h){
                vs.pb((h/2)*w), vs.pb((h-h/2)*w);
            }
            else{
                vs.pb((w/2)*h), vs.pb((w-w/2)*h);
            }
        }
        ll M = 0, m = INF;
        for(auto &e: vs) M = max(M, e), m = min(m, e);
        ans = min(ans, M-m);
    }
    rep(i, W+1){
        ll h = H, w = W-i;
        vector<ll> vs;
        vs.pb(i*H);
        if((h*w)%2 == 0) vs.pb((h*w)/2);
        else{
            if((h/2)*w > (w/2)*h){
                vs.pb((h/2)*w), vs.pb((h-h/2)*w);
            }
            else{
                vs.pb((w/2)*h), vs.pb((w-w/2)*h);
            }
        }
        ll M = 0, m = INF;
        for(auto &e: vs) M = max(M, e), m = min(m, e);
        ans = min(ans, M-m);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
#include <cstdio>
#include <tuple>
#include <string>
#include <vector> 
#include <set>
#include <string.h>
#include <map>
#include <cmath>
#include <deque>
using ll = long long;
using Graph = vector<vector<int>>;
#include <queue>
#include <stack>

//最大公約数
ll gcd(ll a,ll b){
    if(b == 0LL) return a;
    return gcd(b , a % b);
}

//最小公倍数
ll lcm(ll a,ll b){
    return a / gcd(a,b) * b;

}

int main(){
    
    
    int a[] = {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};

    int k;
    cin >> k;


    cout << a[k-1] << endl;
}

Measured memory_bytes: 256