akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
using namespace std;

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

    int A[N + 10];
    int town = 1;

    set<int> visited;
    decltype(visited)::iterator it;
    visited.insert(town);

    int loop_size = 0;
    bool skipped_flag = false;
    map<int, int> mp;
    mp[1] = 0;

    for (int i=1 ; i < N + 1; ++i) {
        cin >> A[i];
    }
    for (long long i=1; i < K + 1; ++i) {
        // cout << i << endl;
        town = A[town];

        if (!skipped_flag) {
            it = visited.find(town);
            if (it != visited.end()) {
                // already viisted
                loop_size = visited.size() - mp[town];
                i = ((K - mp[town]) / loop_size) * loop_size + mp[town];
                // town = 1;
                skipped_flag = true;
            }
            else {
                visited.insert(town);
                mp[town] = i;
            }
        }
    }
    cout << town << endl;
}

Measured memory_bytes: 19368
N = int(input())
aa = []
for _ in range(N): aa.append(int(input()))

"""
    条件
        - はじめ、ボタン1が光っている
        - ボタン2が光っている状態で終了したい
        - そのようなことは可能か？可能ならボタンを押す最低回数を、不可能なら-1を出力せよ。
"""

ans = -1
cnt = 0
pos = 0
for _ in range(N): # N回ボタンを押す
    cnt += 1
    pos = aa[pos] - 1
    if pos == 1:
        ans = cnt
        break

print(ans)


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

#define debug(x) cout << (#x) << " is " << x << endl;
#define Q int t; scanf("%d", &t); for(int q=1; q<=t; q++)
typedef long long int lli;
typedef pair<int, int> pi;


int main()
{
    string s, t;
    cin>> s >> t;
    int a=s.size();
    int b=t.size();
    int mn = a;
    for(int i=0; i<=a-b; i++){
		int k=0, c=0;
		for(int j=i;k<b; j++, k++){
			if(s[j]!=t[k]){
				c++;
			}
		}
		mn = min(mn, c);
	}
	cout << mn << endl;
 
    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include<vector>
using namespace std;
int main(void){
    int n;
    cin >> n;
    vector<int> ans(10001);
    
    for(int x = 1;x <= 100;x++){
          for(int y = 1; y <= 100;y++){
                for(int z = 1;z <= 100;z++){
                      int s = x * x + y * y + z * z;
                      s += x * y + y * z + z * x;
                      if(s > 10000)continue;
                      else ans[s]++;
                }
          }
    }
    for(int i = 1;i <= n;i++){
          cout << ans[i] << endl;
    }
}


Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <numeric>
#include <string>
using namespace std;

vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0;
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
        res.push_back({a, ex});
    }
    if (N != 1) res.push_back({N, 1});
    return res;
}


long long is_divide(long long n){
    const auto &pf = prime_factorize(n);
    long long res = 1;
    for (auto p : pf) res *= p.second + 1;
    
    return res;
}

int main(void){
    long long N;
    cin >> N;
    
    long long ans=0;
    
    for(int i=1; i<N; i++){
        ans += is_divide(i);
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3196
use std::io::{self, BufRead, BufWriter, Write};

fn solve<R, W>(reader: R, mut writer: W)
where
    R: BufRead,
    W: Write,
{
    let mut lines = reader.lines();
    let _ = lines.next().unwrap().unwrap();
    let a_line = lines.next().unwrap().unwrap();
    let splited = a_line.trim().split_whitespace();
    let a = splited.map(|c| c.parse().unwrap());
    let denom: f64 = a.map(|x: f64| 1.0 / x).sum();
    let ans = 1.0 / denom;

    writeln!(&mut writer, "{}", ans).unwrap();
}

fn main() {
    let stdio = io::stdin();
    let input = stdio.lock();

    let stdout = io::stdout();
    let output = BufWriter::new(stdout.lock());

    solve(input, output);
}

#[cfg(test)]
mod tests {
    use super::*;

    const TESTS: &'static [(&'static [u8], &'static [u8])] = &[
        (
            br"2
10 30", br"7.5
",
        ),
        (
            br"3
200 200 200", br"66.66666666666667
",
        ),
        (
            br"1
1000", br"1000
",
        ),
    ];

    #[test]
    fn test_b() {
        for &(input, expected) in TESTS {
            let mut output = Vec::new();
            solve(input, &mut output);
            let expected_str = String::from_utf8(expected.to_vec()).unwrap();
            let output_str = String::from_utf8(output).unwrap();
            assert_eq!(expected_str, output_str);
        }
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define N 100010
#define ll long long
int n,m,a[N],s[N];
map<int,int> mp;
ll ans=0;
int main(){
    scanf("%d%d",&n,&m);
    for (int i=1;i<=n;i++) {scanf("%d",&a[i]); a[i]%=m; }
    for (int i=1;i<=n;i++) s[i]=(s[i-1]+a[i])%m;
    for (int i=0;i<=n;i++) 
        if (!mp.count(s[i])) mp[s[i]]=1;
        else mp[s[i]]++;
    map<int,int>::iterator it;
    for (it=mp.begin();it!=mp.end();it++){
        ll n=it->second;
        ans+=n*(n-1)/2;
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 3968
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<int, pii> ppi;
#define FOR(i, n) for(int i = 1; i<=n; i++)
#define F0R(i, n) for(int i = 0; i<n; i++)
#define mp make_pair
#define pb push_back
#define f first
#define s second


//var 
int n, m, stx, sty, enx, eny, dx[4] = {-1,1,0,0}, dy[4] = {0,0,-1,1};
int rd[1005][1005];
bool v[1005][1005];
int dis[1005][1005];
char tt;
priority_queue<ppi, vector<ppi>, greater<ppi>> dij;

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

	cin >> n >> m >> stx >> sty >> enx >> eny;
	FOR(i, n)
		FOR(j, m){
			cin >> tt;
			if(tt == '.') rd[i][j] = 1;
		}

	dij.push(mp(0, mp(stx, sty)));
	while(!dij.empty()){
		ppi tt = dij.top();
		dij.pop();
		if(v[tt.s.f][tt.s.s]) continue;
		v[tt.s.f][tt.s.s] = 1; dis[tt.s.f][tt.s.s] = tt.f;
		//cout << tt.s.f << " " << tt.s.s << " " << tt.f << endl;
		F0R(i, 4){
			int nx = tt.s.f + dx[i], ny = tt.s.s + dy[i];
			if(nx <= 0 || nx > n) continue;
			if(ny <= 0 || ny > m) continue;
			if(!rd[nx][ny]) continue;
			if(v[nx][ny]) continue;
			dij.push(mp(tt.f, mp(nx,ny)));
		}

		for(int i = -2; i<=2; i++){
			for(int j = -2; j<=2; j++){
				if(i == 0 && j == 0) continue;
				int nx = tt.s.f + i, ny = tt.s.s + j;
				if(nx <= 0 || nx > n) continue;
				if(ny <= 0 || ny > m) continue;
				if(!rd[nx][ny]) continue;
				if(v[nx][ny]) continue;
				dij.push(mp(tt.f+1 , mp(nx, ny)));
			}
		}
	}

	if(!v[enx][eny]){
		cout << -1 << endl;
		return 0;
	}

	cout << dis[enx][eny] << endl;

	cout.flush();
	return 0;
}

Measured memory_bytes: 13724
n = int(input())
s = list(input())
alfabets = [chr(i) for i in range(97,97+26)]
numbers = []
for i in range(0,n-1) :
    cnt = 0
    a = s[0:i+1]
    b = s[i+1:n]
    for j in alfabets :
        if j in a and j in b :
            cnt += 1
    numbers.append(cnt)

print(max(numbers))

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

using namespace std;

int main(){
	string str;
	cin>>str;
	for(int i=0;i<str.size();i++){
		if (str[i]=='A'&&str[i+1]=='C'){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}

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

"""
input:
4
1 2 3 5

output:
30
"""

import sys
import fractions
from functools import reduce


def gcd(x, y):
    if x < y:
        x, y = y, x

    while y > 0:
        r = x % y
        x = y
        y = r

    return x


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


def solve(_n_list):
    return reduce(lcm, _n_list)


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    cnt = int(_input[0])
    n_list = tuple(map(int, _input[1].split()))
    print(solve(n_list))

Measured memory_bytes: 10224
import sys
input = sys.stdin.readline

def sol():
    s=input().rstrip()
    q=int(input())
    x=0
    a,b="",""
    for i in range(q):
        l=tuple([i for i in input().split()])
        if l[0]=="1":
            x=(x+1)%2
        elif l[1]=="1":
            if x==0: a=l[2]+a
            else: b=b+l[2]
        elif l[1]=="2":
            if x==0: b=b+l[2]
            else: a=l[2]+a
    s=a+s+b
    print(s if x==0 else s[::-1])

if __name__=="__main__":
    sol()


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

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

using namespace std;

int main()
{
  ll n,a,b,c,d,e;
  cin >> n >> a >> b >> c >> d >> e;
  ll m = min(min(a,b), c);
  m = min(m,d);
  m = min(m,e);
  cout << 4 + (n+m-1)/m << endl;
}


Measured memory_bytes: 256
import kotlin.system.exitProcess

fun main(args: Array<String>) {
    val input = readLine()!!
    var numbers = mutableListOf<Int>()
    for (i in 0..input.length - 1){
        numbers.add(Integer.parseInt(input[i].toString()))
    }
    solve(1, numbers, numbers[0], "${numbers[0]}")
}

fun solve(index: Int, numbers: List<Int>, answer: Int, expr: String) {
    when {
        (answer == 7) and (index == numbers.size)-> {
            println("$expr=7")
            exitProcess(0)
        }
        index == numbers.size -> return
        else -> {
            solve(index + 1, numbers, answer + numbers[index], "$expr+${numbers[index]}")
            solve(index + 1, numbers, answer - numbers[index], "$expr-${numbers[index]}")
        }
    }
}

Measured memory_bytes: 34040
import java.io.*; 
import java.math.*;
import java.util.*;
 
public class Main {
	//static final long MOD = 998244353;
	static final long MOD = 1000000007;
	static final int INF = 1000000007;
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		double a = sc.nd();
		double b = sc.nd();
		double x = sc.nd();
		double criticalAngle = Math.atan(b/a);
		//if angle is small, the answer is the following
		double lowAngle = Math.atan(2*(a*a*b-x)/(a*a*a));
		double highAngle = Math.atan((a*b*b)/(2*x));
		double CONV = 180/Math.PI;
		if (lowAngle <= criticalAngle) {
			System.out.println(lowAngle*CONV);
		} else {
			System.out.println(highAngle*CONV);
		}
	}
    
    public static long power(long x, long y, long p) { 
        // Initialize result
        long res = 1;
         
        // Update x if it is more   
        // than or equal to p 
        x = x % p;  
      
        while (y > 0) 
        { 
            // If y is odd, multiply x 
            // with result 
            if((y & 1)==1) 
                res = (res * x) % p; 
      
            // y must be even now 
            // y = y / 2 
            y = y >> 1;  
            x = (x * x) % p;  
        } 
        return res; 
    }
    
    public static long dist(int[] point, int[] point2) {
    	return (long)(Math.pow((point2[1]-point[1]),2)+Math.pow((point2[0]-point[0]),2));
    }
    
    public static long gcd(long a, long b) {
    	if (b == 0)
    		return a;
    	else
    		return gcd(b,a%b);
    }
    
    public static int[][] sort(int[][] array) {
    	//Sort an array (immune to quicksort TLE)
		Random rgen = new Random();
		for (int i = 0; i < array.length; i++) {
		    int randomPosition = rgen.nextInt(array.length);
		    int[] temp = array[i];
		    array[i] = array[randomPosition];
		    array[randomPosition] = temp;
		}
		Arrays.sort(array, new Comparator<int[]>() {
			  @Override
        	  public int compare(int[] arr1, int[] arr2) {
				  return arr2[1]-arr1[1];
	          }
		});
		return array;
	}
    
    static class FastScanner { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastScanner() { 
            br = new BufferedReader(new InputStreamReader(System.in)); 
        } 
  
        String next() { 
            while (st == null || !st.hasMoreElements()) { 
                try { 
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int ni() { 
            return Integer.parseInt(next()); 
        } 
  
        long nl() { 
            return Long.parseLong(next()); 
        } 
  
        double nd() { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() { 
            String str = ""; 
            try { 
                str = br.readLine(); 
            } catch (IOException e) {
                e.printStackTrace(); 
            } 
            return str; 
        }
    }
}

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

#define ll long long
#define ld long double
#define COIN const int
#define ite iterator
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>

#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define REPD(i,n) for((i)=(n)-1;(i)>=0;(i)--)

#define ALL(c) (c).begin(), (c).end()
#define LEN(s) (s).size()
#define CLEAR(x) memset(x,0,sizeof x);

#define MP make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define X first
#define Y second

#define VI vector<int>
#define VS vector<string>
#define VII vector<PII>
#define VVI vector<VI>

#define PIII 3.1415926
#define PI 3.14
/*****************************************************************************/

using namespace std;

int n,m,a[10000],sum,i; 

int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin >>n >>m;
	for (i=0;i<m;i++) {
		cin >>a[i];
		sum+=a[i];
	}
	if (sum>n) {
		cout <<"-1";
		return 0; 
	}
	cout <<n-sum;
	return 0;
}
/******************************************************************************
******************************************************************************/


Measured memory_bytes: 3672
def isprime(x):
  if x < 2: return False
  for d in range(2, int(x**0.5)+1):
    if x % d == 0: return False
  return True

isp = list(map(isprime, range(100001)))
w = [0]*100001
for i in range(100001):
  if i > 2 and isp[i] and isp[(i + 1)//2]:
    w[i] = 1

for i in range(1,100001):
  w[i] += w[i-1]

Q = int(input())
for i in range(Q):
  L,R = map(int, input().split())
  print(w[R] - w[L-1])


Measured memory_bytes: 7460
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll mod=1000000007;
ll MOD=998244353;
int inf=1000001000;
ll INF=100000000000000000;


int main() {
    int v,E;
    cin >> v >> E;
    vector<vector<pp>> e(v+1,vector<pp>(0));
    rep(i,E){
        int f,g,h;
        cin >> f >> g >> h;
        e[f].push_back(mk(g,h));
        e[g].push_back(mk(f,h));
    } 
    rep(i,v) {
        int f;
        cin >> f;
    }
    int t;
    cin >> t;
    rep(i,500){
        cout << -1 << endl;
        t--;
        if (t==0) return 0;
    }
    queue<int> q;
    q.push(1);
    while(true){
        int f=q.front();
        int u=rand()%e[f].size();
        q.pop();
        q.push(e[f][u].first);
        rep(i,e[f][u].second){
            cout << e[f][u].first << endl;
            t--;
            if (t==0) return 0;
        }
    }
}


Measured memory_bytes: 1236
/*	
	:)
*/
#include <bits/stdc++.h> 
using namespace std;
#define fl(i,a,b) for(int i=a;i<b;i++)
#define endl '\n'
#define pb push_back
#define ff first
#define ff first
#define ss second
#define inf 2e18
#define mod 998244353
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define mx 200005
#define ll long long
#define pi 3.1415926535897932384626433
vector<int> v[mx];
void solve()
{
	int n,m;
	cin >> n >> m;
	fl(i, 1 , m + 1)
	{
		int x,y;
		cin >> x >> y;
		v[x].pb(y);
		v[y].pb(x);
	}
	int par[n + 1];
	int dis[n + 1];
	int vis[n + 1];
	fl(i,1,n+1)
	{
		dis[i] = 1e9;
		par[i] = 0;
		vis[i] = 0;
	}
	queue<pair<int,int> > q;
	q.push({1,0});
	vis[1] = 1;
	while(!q.empty())
	{
		pair<int,int> p = q.front();
		q.pop();
		int x = p.ff;
		int d = p.ss;
		dis[x] = d;
		for(auto i : v[x])
		{
			if(!vis[i])
			{
				vis[i] = 1;
				par[i] = x;
				q.push({i,d+1});
			}
		}
	}
	fl(i,1,n+1)
	{
		if(dis[i] == 1e9)
		{
			cout << "No";
			return ;
		}
	}
	cout << "Yes" << endl;
	fl(i,2,n+1)
	{
		cout << par[i] << endl;
	}
}
main()
{
	fast;
	int t =  1;
	while(t--)
	{
		solve();
	}
}

Measured memory_bytes: 13732
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = LONG_LONG_MAX / 2;
const ll mod = 1000000000 + 7;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main() {
  unsigned int N, K;
  cin >> N >> K;
  vector<int> mv, pv;
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    if (x >= 0)
      pv.push_back(x);
    else
      mv.push_back(-1 * x);
  }
  reverse(mv.begin(), mv.end());
  vector<int> pred;
  if (pv.size() > K - 1) pred.push_back(pv[K - 1]);
  if (mv.size() > K - 1) pred.push_back(mv[K - 1]);
  for (unsigned int i = 0; i < K - 1; i++) {
    if (pv.size() > i && mv.size() > K - i - 2) {
      pred.push_back(pv[i] * 2 + mv[K - i - 2]);
    }
    if (mv.size() > i && pv.size() > K - i - 2) {
      pred.push_back(mv[i] * 2 + pv[K - i - 2]);
    }
  }
  sort(pred.begin(), pred.end());
  cout << pred[0] << endl;
}


Measured memory_bytes: 4308
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = min(a) + min(b)
for i in range(M):
    x, y, c = map(int, input().split())
    if a[x-1] + b[y-1] - c < ans:
        ans = a[x-1] + b[y-1] - c

print(ans)

Measured memory_bytes: 18612
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int a;
      int b;
      int c;
      cin >> a;
      b = a/100;
      a = a%100;
      c = a/10;
      a = a%10;
      cout << a+b+c << endl;
    }

Measured memory_bytes: 3580
/*
    हॉंजी । की हाल चाल?
    बड़ीया सब?
*/

#include<bits/stdc++.h>
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             unordered_map<int,int>
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define MOD             998244353
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
#define EPS             1e-9

void gogeta()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

struct dsu {
    vector<int> parent, sz;
    int total_comp;

    void init(int n) {
        parent.resize(n);
        sz.resize(n);
        for (int i = 0; i < n; i++)
            parent[i] = i;
        for (int i = 0; i < n; i++)
            sz[i] = 1;
        total_comp = n;
    }

    int get_super_parent(int x) {
        if (parent[x] == x)
            return x;
        return parent[x] = get_super_parent(parent[x]);
    }

    void unite(int x, int y) {
        int super_parent_x = get_super_parent(x);
        int super_parent_y = get_super_parent(y);
        if (super_parent_x != super_parent_y) {
            parent[super_parent_x] = super_parent_y;
            sz[super_parent_y] += sz[super_parent_x];
            sz[super_parent_x] = 0;
            total_comp--;
        }
    }
} d;

int32_t main()
{
    gogeta();
    int n, m; cin >> n >> m;
    d.init(n);
    for (int i = 0; i < m; i++) {
        int x, y; cin >> x >> y;
        d.unite(x - 1, y - 1);
    }
    cout << d.total_comp - 1 << endl;
    // for (int i = 0; i < n; i++)  cout << d.par[i] << " ";
}


Measured memory_bytes: 4772
#include <iostream>
#include <queue>
#include <utility>
using namespace std;

int main(){
  int n,q,a,v;
  int c[1000001]={0};
  typedef pair<int,int> P;
  P t;
  priority_queue<P> s;
  cin>>n>>q;
  while(q--){
    cin>>a>>v;
    c[a]+=v;
    s.push(P(c[a],-a));
    while(1){
      t=s.top();
      if(t.first==c[-t.second]){
	cout<<-t.second<<' '<<t.first<<endl;break;
      }
      s.pop();
    }
  }
  return 0;
}

Measured memory_bytes: 6016
def prob(N, K):
    prob = .0

    for n in range(1, N + 1):
        tmp_prob = 1. / N
        while (n < K):
            tmp_prob *= .5
            n *= 2

        prob += tmp_prob

    return prob


if __name__ == '__main__':
    N, K = map(int, input().split())
    prob = prob(N, K)
    print(prob)


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

using namespace std;

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

    if(X==1 && Y==1){
        cout<<1000000<<endl;
    }else{
        long ans = 0;
        if(X==1){
            ans+=300000;
        }else if(X==2){
            ans+=200000;
        }else if(X==3){
            ans+=100000;
        }
        if(Y==1){
            ans+=300000;
        }else if(Y==2){
            ans+=200000;
        }else if(Y==3){
            ans+=100000;
        }
        cout<<ans<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <bitset>
#include <utility>
using namespace std;
const int inf = 1e9;
const int MAXN = 1000;

int upper_right(int x, int y, int w, int h){
	return 2*w +y -x;
}
int upper_left(int x, int y, int w, int h){
	return 2*w +2*h -x -y;
}
int lower_right(int x, int y, int w, int h){
	return x+y;
}
int lower_left(int x, int y, int w, int h){
	return x>y? x-y: 2*h +2*w +x-y;
}

int main(){
	int n,w,h;
	cin >> n >> w >> h;
	vector<int> s(n), e(n);
	for(int i=0; i<n; i++){
		int x,y;
		char f;
		cin >> x >> y >> f;
		if(f == 'N'){
			s[i] = upper_right(x, y, w, h);
			e[i] = upper_left(x, y, w, h);
		}
		if(f == 'W'){
			s[i] = upper_left(x, y, w, h);
			e[i] = lower_left(x, y, w, h);
		}
		if(f == 'S'){
			s[i] = lower_left(x, y, w, h);
			e[i] = lower_right(x, y, w, h);
		}
		if(f == 'E'){
			s[i] = lower_right(x, y, w, h);
			e[i] = upper_right(x, y, w, h);
		}
	}
	vector<pair<int ,int> > es(n);
	for(int i=0; i<n; i++) es[i] = make_pair(e[i], s[i]);
	sort(es.begin(), es.end());
	for(int i=0; i<n; i++){ s[i] = es[i].second; e[i] = es[i].first; }
	
	vector<bitset<MAXN> > cover(n);
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			if((i == j) ||
				(s[j] < e[j] && s[j]<=e[i] && e[i]<=e[j]) ||
				(s[j] > e[j] && (e[i]<=e[j] || s[j]<=e[i]))){
				cover[i][j] = 1;
			}
		}
	}
	
	int ans = inf;
	for(int i=0; i<n; i++){
		int sub = 0;
		bitset<MAXN> cov;
		for(int j=0; j<n; j++){
			if(cov[(i+j)%n] == 0){
				cov |= cover[(i+j)%n];
				sub++;
			}
		}
		ans = min(ans, sub);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3212
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] arr = new long[n];
        int count = 0;
        for(int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }
        Arrays.sort(arr);
        int temp = 0;
        for(int i = 0; i < arr.length-1; i++) {
            temp++;
            if(arr[i] == arr[i+1]) {
                if(i == arr.length-2) {
                    temp++;
                    if(temp % 2 == 1) {
                      count++;
                    }
                    temp = 0;
                }
            }
            else {
                if(temp % 2 == 1) {
                    count++;
                }
                temp = 0;
                if(i == arr.length-2) {
                    count++;
                }
            }
        }
        System.out.println(count);
    }
}

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

const int MAX_N = 2006;
const int MOD = 1e9+7;
int N,K;

ll C[MAX_N][MAX_N];

void solve()
{
	//how many ways to distribute K balls into N slots
	for(int i=0; i<=2000; ++i){
		C[i][i]=C[i][0]=1;
	}
	for(int i=2; i<=2000; ++i){
		for(int j=1;j<i;++j){
			C[i][j]=(C[i-1][j] + C[i-1][j-1])%MOD;
		}
	}
	for(int i=1;i<=K;++i){ //number of ways to distribute K balls into i groups
		cout << (C[N-K+1][i]*C[K-1][i-1])%MOD << "\n";
	}
}

int main()
{
	cin >> N >> K;
	solve();
	return 0;
}

Measured memory_bytes: 30208
#include "bits/stdc++.h"
#include <cmath>

#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
using ull = unsigned long long;
using ll = long long;

struct __INIT {
    __INIT() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __init;

int main() {
    ll A, B, C;
    cin >> A >> B >> C;
    if(A == B and B == C and !(A % 2)) puts("-1");
    else{
        ll sum = 0;
        while(A % 2 == 0 and B % 2 == 0 and C % 2 == 0){
            ll instead_A = A;
            ll instead_B = B;
            A = (B + C) / 2;
            B = (instead_A + C) / 2;
            C = (instead_A + instead_B) / 2;
            sum++;
        }
        cout << sum << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<ll> a(N);
    ll sum = 0;
    REP(i,N){
        cin >> a[i];
        sum += a[i];
    }
    ll cur = 0;
    ll mi = LINF;
    REP(i,N-1){
        cur += a[i];
        chmin(mi, abs(cur - (sum - cur)));
    }
    cout << mi << endl;
}


Measured memory_bytes: 1792
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#define limX(a)(min(max(1,a),X))
#define limY(a)(min(max(1,a),Y))
using namespace std;
typedef struct d{int tx,ty,kx,ky,time;}D;
int G[55][55],X,Y,R,tx,ty,kx,ky,mx[4]={0,-1,0,1},my[4]={-1,0,1,0},F[51][51][51][51];
struct Order{bool operator ()(D const& a, D const& b) const{return a.time>b.time;}};

int main()
{
	D tmp,tmp2;
	for(;scanf("%d%d",&X,&Y),X;)
	{
		memset(F,0,sizeof(F));
		priority_queue<D,vector<D>,Order>Q;
		R=-1;
		tmp.time=0;
		scanf("%d%d%d%d",&tmp.tx,&tmp.ty,&tmp.kx,&tmp.ky);
		for(int i=1;i<=Y;i++)for(int j=1;j<=X;j++)scanf("%d",&G[i][j]);
		Q.push(tmp);
		for(;!Q.empty();)
		{
			tmp=tmp2=Q.top();Q.pop();
			if(tmp.time>=100)break;
			if(tmp.kx==tmp.tx&&tmp.ky==tmp.ty){R=tmp.time;break;}
			for(int i=0;i<4;tmp=tmp2,i++)
			{
				tmp.kx=limX(tmp.kx+mx[i]);
				tmp.ky=limY(tmp.ky+my[i]);
				if(G[tmp.ky][tmp.kx])tmp.kx=tmp2.kx,tmp.ky=tmp2.ky;
				tmp.tx=limX(tmp.tx-mx[i]);
				tmp.ty=limY(tmp.ty-my[i]);
				if(G[tmp.ty][tmp.tx])tmp.tx=tmp2.tx,tmp.ty=tmp2.ty;
				tmp.time++;
				if(!F[tmp.kx][tmp.ky][tmp.tx][tmp.ty])
				{
					F[tmp.kx][tmp.ky][tmp.tx][tmp.ty]=1;
					Q.push(tmp);
				}
			}
		}
		if(R==-1)
			puts("NA");
		else
			printf("%d\n",R);
	}
}

Measured memory_bytes: 28416
import numpy as np

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

H_th = 360*((H+M/60)/12)
M_th = 360*M/60
th = np.abs(H_th-M_th)
if 180 <= th <= 360:
  th = 360-th
th = th*np.pi/180

C = np.sqrt(A**2 + B**2 -2*A*B*np.cos(th))
print(C)

Measured memory_bytes: 27216
#include<iostream>

using namespace std;

int main() {
	
	int a,b; cin >> a >> b;
	
	if(a == 1)a = 14;
	if(b == 1)b = 14;
	
	if(a == b)cout << "Draw\n";
	else if(a > b)cout << "Alice\n";
	else cout << "Bob\n";
	
	return 0;
}

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

int main()
{
  int n;
  while (scanf("%d", &n) != EOF) {
    if (n == 0)
      break;

    vector<int> seq(n);
    for (int i = 0; i < n; ++i)
      scanf("%d", &seq[i]);

    for (int i = 1; i < seq.size(); ++i) {
      if (seq[i-1] > 0)
	seq[i] += seq[i-1];
    }

    cout << *max_element(seq.begin(), seq.end()) << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <cctype>
#include <algorithm>
#include <cstdio>
using namespace std;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 1e5+5;
struct Edge
{
    int next, to;
    Edge(int next = 0, int to = 0):next(next), to(to) {};
}edge[N<<1];
int tot, head[N];
void _add(int x, int y) { edge[++tot] = Edge(head[x], y), head[x] = tot; }
void add(int x, int y) { _add(x, y), _add(y, x); }
int n, m, q, col[N], u[N], d[N], w[N], f[N];
void dfs(int x, int d, int c)
{
    if(f[x]>>d&1) return;
    f[x] |= ((1<<(d+1))-1), col[x] = col[x]?col[x]:c;
    for(int i = head[x]; i&&d; i = edge[i].next)
    {
        int y = edge[i].to;
        dfs(y, d-1, c);
    }
}
int main()
{
    n = read(), m = read();
    for(int i = 1, x, y; i <= m; ++i) x = read(), y = read(), add(x, y);
    q = read();
    for(int i = 1; i <= q; ++i) u[i] = read(), d[i] = read(), w[i] = read();
    for(int i = q; i; --i) dfs(u[i], d[i], w[i]);
    for(int i = 1; i <= n; ++i) printf("%d\n", col[i]);
    return 0;
}

Measured memory_bytes: 4608
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

template<class T> struct Weighted_UnionFind{
  vector<ll> par;
  vector<ll> rank;
  vector<T> diff_weight;

  Weighted_UnionFind(ll n){
    init(n);
  }

  void init(ll n){
    par.resize(n);
    rank.resize(n);
    diff_weight.resize(n);
    REP(i,n){
      par[i] = i;
      rank[i] = 0;
      diff_weight[i] = 0;
    }
  }

  ll find(ll x){
    if(par[x]==x){
      return x;
    }else{
      ll r = find(par[x]);
      diff_weight[x]+=diff_weight[par[x]];
      return par[x] = r;
    }
  }

  T weight(ll x){
    find(x);
    return diff_weight[x];
  }

  bool same(ll x, ll y){
    return find(x)==find(y);
  }

  void unite(ll x, ll y, T w){
    w += weight(x);
    w -= weight(y);
    x = find(x);
    y = find(y);
    if(x==y) return;
    if(rank[x]<rank[y]) swap(x,y), w = -w;
    if(rank[x]==rank[y]) rank[x]++;
    par[y] = x;
    diff_weight[y] = w;
  }

  T diff(ll x, ll y){
    return weight(y)-weight(x);
  }
};

int main(){
  ll n,m;
  cin >> n >> m;
  Weighted_UnionFind<ll> uf(n);
  REP(i,m){
    ll l,r,d;
    cin >> l >> r >> d;
    l--, r--;
    if(uf.same(l,r)){
      ll diff = uf.diff(l,r);
      if(diff!=d){
        cout << "No" << endl;
        return 0;
      }
    }else{
      uf.unite(l,r,d);
    }
  }
  cout << "Yes" << endl;
  return 0;
}


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

using namespace std;

typedef long long int ll;

const ll mod = 1e9 + 7;
const ll MAXN = 2e5 + 5;

int z_function(string s){
  int n = s.length();
  vector < int > z(n, 0);
  int l = 0, r = 0, ans = 0;
  for(int i = 1; i < n; i++){
    if(r >= i) z[i] = min(z[i - l], r - i + 1);
    while(i + z[i] < n && s[i + z[i]] == s[z[i]]) z[i]++;
    if(i + z[i] - 1 > r){
      l = i;
      r = i + z[i] - 1;
    }
    ans = max(ans, min(z[i], i));
  }
  return ans;
}

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

  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 0;
  for(int i = 0; i < n; i++){
    ans = max(ans, z_function(s.substr(i, n - i)));
  }

  cout << ans << '\n';
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using llong = long long;
#define rep(i,N) for (int i = 0; i < N; i++)

const llong MOD = 1e9+7;
const llong inf = 1<<30;

llong N;
vector<llong> h;

int main() {
    cin >> N; h.resize(N);
    for (int i = 0; i < N; i++) scanf("%Ld", &h[i]);
    reverse(h.begin(), h.end());
    for (int i = 0; i < N-1; i++) { //次を一減らす感じで広義単調減少を目指す
        if (h[i] < h[i+1] - 1) {
            cout << "No" << endl;
            return 0;
        }else if (h[i] == h[i+1] - 1) {
            h[i+1]--;
        }
    } 
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(void) {
    int i,n,input,t;
    while(scanf("%d",&n)!=0){
        if(n==0)break;
        int data[10]={0};
        for(i=0;i<n;i++){
            scanf("%d",&input);
            data[input]++;
        }
        for(i=0;i<10;i++){
            if(data[i]==0){
                puts("-");
            }else{
                for(t=0;t<data[i];t++){
                    printf("*");
                }
                puts("");
            }
        }
 
    }
    return 0;
}

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

int main()
{
    int a,b;
    int W,H;
    cin >> H >> W;
    
    while(H)
    {
    for(int i=0; i<H; i++)
        {
            for(int j=0; j<W; j++)
            {
                cout << '#';
            }
            cout << endl;
        }
    cout << endl;
    cin >> H >> W;
    }
    
    return 0;
}


Measured memory_bytes: 3092
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<double,int,double> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf=sizeof(Def)==sizeof(long long)?2e18:1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	string s;
	cin>>s;
	rep(i,s.size())if(i%2==0)cout<<s[i];cout<<endl;
}








Measured memory_bytes: 512
package main

/*
A B
*/
import (
	"bufio"
	"fmt"
	//"log"
	"os"
	"strconv"
	"strings"
)

func main() {
	stdin := bufio.NewScanner(os.Stdin)
	stdin.Scan()
	line := strings.Split(stdin.Text(), " ")
	a, _ := strconv.Atoi(line[0])
	b, _ := strconv.Atoi(line[1])
	// _,_=a,b
	if b%a == 0 {
		fmt.Println(a + b)
	} else {
		fmt.Println(b - a)
	}

}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<int > v;
    for(int i=0;i<n;i++)
    {
        int t;
        cin>>t;
        v.push_back(t);
    }
    auto inew=unique(v.begin(),v.end());
    v.erase(inew,v.end());
    cout<<v[0];
    for(int i=1;i<v.size();i++)
    {
        cout<<" "<<v[i];
    }
    cout<<endl;
}


Measured memory_bytes: 3524
#include <iostream>
#include <bits/stdc++.h>
#define ll long long 
using namespace std;
#define fastio std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pii pair<int, int>
#define mpi make_pair
#define F first
#define S second
#define pb push_back
#define INF 1e15

ll dp[100005][2];
ll mod = 1e9+7;
vector<vector<int>>ng;

void dfs(int u , int p)
{

    ll w=1;ll b =1;

    for(auto x:ng[u])
    {
        if(x == p)continue;

        dfs(x , u);

        w = ((ll)w*dp[x][1])%mod;
        b = ((ll)b*dp[x][0])%mod;
    }
    
    dp[u][0]=w;
    dp[u][1]=b;
    dp[u][0] =(dp[u][1]+dp[u][0])%mod;
}

int main()
{   
    fastio

    int n;
    cin>>n;
    ng.resize(n);
    for(int i = 0 ;i<n-1;i++)
    {
        int u,v;
        cin>>u>>v;

        ng[u-1].push_back(v-1);
        ng[v-1].push_back(u-1);
    }

    dfs(0 ,-1);

    cout<<dp[0][0]<<endl;
    return 0;
} 


Measured memory_bytes: 14208
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <string>
#include <utility>
#include <cstdio>
#include <cmath>
#include <deque>

#define REP(i,n) for(int i = 0; i < (n); ++i)
#define REP1(i,n) for(int i = 1; i <= (n); ++i)
#define RREP(i, n) for(int i = (n) - 1; i >= 0; --i)
#define ALL(a) begin(a), end(a)
#define X first
#define Y second

using ll = long long;
using namespace std;
using vi = vector<int>;
using pii = pair<int, int>;

constexpr int INF = 1e9 + 1;
constexpr ll LLINF = 4 * 1e18 + 1;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vi a(n + 1);
	REP1(i, n) cin >> a[i];
	deque<int> b;
	int amr = n  % 2;
	REP1(i, n) {
		if (i % 2 == amr) b.push_front(a[i]);
		else b.push_back(a[i]);
	}
	cout << b.front(); b.pop_front();
	while (!b.empty()) {
		cout << " " << b.front();
		b.pop_front();
	}
	cout << "\n";
	return 0;
}


Measured memory_bytes: 3840
import java.io.*;

class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		int i=1;
		while(true){
        	String x=br.readLine();
        	if(x.equals("0")) break;
        	sb.append("Case "+i+": "+x+"\n");
        	if(i%1000==0){
        		System.out.print(sb.toString());
        		sb.setLength(0);
        	}
    		i++;
        }
		System.out.print(sb.toString());
	}
}

Measured memory_bytes: 24740
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

const double PI = 3.14159265358969;

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

    cout << fixed << setprecision(12);

    long double R;
    cin >> R;
    cout << 2*PI*R << endl;
}

Measured memory_bytes: 3808
import std.stdio;
import std.array;
import std.conv;
import std.algorithm;
import std.string;
import std.numeric;
bool c_str(int[13] hs){
	for(int i=0;i<10;i++){
		if(hs[i]==1&&hs[i+1]==1&&hs[i+2]==1&&hs[i+3]==1&&hs[(i+4)%13]==1) return true;
	}
	return false;
}
void main() {
	string s;
	while( (s=readln().strip()).length != 0 ){
		auto as = s.split(',').map!(to!int)().array();
		int[13] hs;
		for(int i=0;i<5;i++){
			hs[as[i]-1]++;
		}
		if(!find(hs[],4).empty){
			writeln("four card");
		}else if(!find(hs[],3).empty && !find(hs[],2).empty){
			writeln("full house");
		}else if(c_str(hs)){
			writeln("straight");
		}else if(!find(hs[],3).empty){
			writeln("three card");
		}else if(!find(hs[],2).empty&&!find(find(hs[],2)[1..$],2).empty){
			writeln("two pair");
		}else if(!find(hs[],2).empty){
			writeln("one pair");
		}else{
			writeln("null");
		}
	}
}

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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
	string S, T; cin >> S >> T;
	int len_S = S.size(), len_T = T.size();
	int ans = inf;
	for(int i = 0; i <= len_S - len_T; i++) {
		int cnt = 0;
		for(int j = 0; j < len_T; j++) {
			if(S[i + j] != T[j]) cnt++;
		}
		ans = min(ans, cnt);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3624
import java.util.Random;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);
		String S = scanner.nextLine();
		int length = S.length();
		Random random = new Random();
		int a;
		int b;
		int c;
		int d;
		if (length <= 3) {
			a = 0;
			b = 1;
			c = 2;
			d = 3;

		} else {
		a = random.nextInt(length-4);
		b = a+1;
		c = a+2;
		d = a+3;
		}

//		System.out.println(a);
//		System.out.println(b);
//		System.out.println(c);
//		System.out.println(d);

//		ArrayList<String> list = new ArrayList<>();
//		for (int i = 0; i < length ;) {
//			list.add(S.substring(i, ++i));
//		}

//		System.out.println(list);

		String nickname = S.substring(a,b).concat(S.substring(b,c)).concat(S.substring(c,d));

//		String nickname = list.get(a)+(list.get(b))+(list.get(c));

		System.out.println(nickname);
	}
}


Measured memory_bytes: 35712
from math import factorial

def combinations_count(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))

n, k = map(int, input().split())

for i in range(1,k+1):
    if i <= n-k+1:
        print((combinations_count(n-k+1,i)%(10**9+7)) * combinations_count(k-1,i-1) %(10**9+7))
    else:
        print(0)


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

#define pp push_back
#define pf push_front
#define mp make_pair
#define fs first
#define sc second
#define sf scanf

using namespace std;

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

const int N = (int) 1e5;
const int INF = (int) 1e9 + 7;

int main(int argc, char *argv[])
{
	// ios_base::sync_with_stdio(false);
	// cin.tie(NULL);

	int k;
	sf("%d", &k);
	char s[123];
	sf("%s", s);
	int len = strlen(s);
	if (len <= k) {
		printf("%s", s);
	}
	else {
		for (int i = 0; i < k; ++i) {
			printf("%c", s[i]);
		}
		printf("...");
	}

	return 0;
}


Measured memory_bytes: 3720
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <stdbool.h>

#define M_PI 3.14159265358979323846

int main() {
	int r;
	scanf(" %d", &r);
	double u = 2 * M_PI * r;
	printf("%.3f\n", u);

	return 0;
}


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

void swap(int *dice, int a, int s, int d, int f)
{
	int tmp;
	tmp = dice[a];
	dice[a] = dice[s];
	dice[s] = dice[d];
	dice[d] = dice[f];
	dice[f] = tmp;
}

int main(void)
{
	char com[6][6] = {"North", "East", "West", "South", "Right", "Left"};
	int i;
	int j;
	int n;
	char c[6];
	int sum;
	int dice[6];
	
	while (1) {
		scanf("%d", &n);
		if (n == 0){
			break;
		}
		sum = 1;
		for (i = 0; i < 6; i++){
			dice[i] = i + 1;
		}
		for (i = 0; i < n; i++){
			scanf("%s", c);
			for (j = 0; j < 6; j++){
				if (strcmp(c, com[j]) == 0){
					break;
				}
			}
			switch (j){
			  case 0:
			  	swap(dice, 4, 0, 1, 5);
			  break;
			  case 1:
			    swap(dice, 2, 0, 3, 5);
			  break;
			  case 2:
			  	swap(dice, 3, 0, 2, 5);
			  break;
			  case 3:
			  	swap(dice, 1, 0, 4, 5);
			  break;
			  case 4:
			  	swap(dice, 3, 1, 2, 4);
			  break;
			  case 5:
			  	swap(dice, 1, 3, 4, 2);
			  break;
			}
			sum += dice[0];
		}
		printf("%d\n", sum);
	}
	
	return (0);
}

Measured memory_bytes: 616
N = int(input())
t,x,y = 0,0,0
for n in range(N):
  T,X,Y = map(int,input().split())
  D = abs(X-x) + abs(Y - y) 
  if D <= T - t and (T - t - D) % 2 == 0:
    x = X
    y = Y
    t = T
  else:
    print('No')
    break
else:
  print('Yes')


Measured memory_bytes: 74420
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
3
0 0 1 0 0 1 1 1
0 0 1 0 2 1 1 2
-1 0 1 0 0 1 0 -1

output:
1.0000000000
1.4142135624
0.0000000000
"""

import sys
from collections import namedtuple

EPS = 1e-9


def cross(a, b):
    return a.real * b.imag - a.imag * b.real


def dot(a, b):
    return a.real * b.real + a.imag * b.imag


def get_distance_lp(l, p):
    return abs(cross(l.target - l.source, p - l.source) / abs(l.target - l.source))


def get_distance_sp(s, p):
    if dot(s.target - s.source, p - s.source) < 0:
        return abs(p - s.source)
    elif dot(s.source - s.target, p - s.target) < 0:
        return abs(p - s.target)
    else:
        return get_distance_lp(s, p)


def check_ccw(p0, p1, p2):
    a, b = p1 - p0, p2 - p0
    if cross(a, b) > EPS:
        flag = 1
    elif cross(a, b) < -1 * EPS:
        flag = -1
    elif dot(a, b) < -1 * EPS:
        flag = 2
    elif abs(a) < abs(b):
        flag = -2
    else:
        flag = 0
    return flag


def check_intersection(p0, p1, p2, p3):
    intersected = (check_ccw(p0, p1, p2) * check_ccw(p0, p1, p3) <= 0) and \
                  (check_ccw(p2, p3, p0) * check_ccw(p2, p3, p1) <= 0)

    return intersected


def solve(_segments):
    for segment in _segments:
        axis = tuple(map(int, segment))
        p0, p1, p2, p3 = (x + y * 1j for x, y in zip(axis[::2], axis[1::2]))
        s1, s2 = Segment(p0, p1), Segment(p2, p3)

        intersected = check_intersection(s1.source, s1.target, s2.source, s2.target)
        if intersected:
            distance = 0
        else:
            distance = min(min(get_distance_sp(s1, s2.source), get_distance_sp(s1, s2.target)),
                           min(get_distance_sp(s2, s1.source), get_distance_sp(s2, s1.target)))

        print('{ans:.10f}'.format(ans=distance))

    return None


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    questions = int(_input[0])
    segments = map(lambda x: x.split(), _input[1:])
    Segment = namedtuple('Segment', ('source', 'target'))
    solve(segments)

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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound


signed main() {
    int N, P;
    cin >> N >> P;
    if (N == 1) {
        cout << P << endl;
        return 0;
    }
    int ans = 1;
    for (int i = 2; i <= 1000000; ++i) {
        int cnt = 0;
        while (P != 1 && P % i == 0) {
            cnt++;
            P /= i;
        }
        rep(j, cnt / N) {
            ans *= i;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main(void){
    
    int a, b;
    int cost_b, cost_a;
    
    cin >> a >> b >> cost_b >> cost_a;
    
    if(a >= b) cout << (cost_b * b + cost_a * (a - b)) << endl;
    if(a < b) cout << (a * cost_b) << endl;
    
    return 0;

}


Measured memory_bytes: 256