akhauriyash/Code-Regression huggingface dataset:
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
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; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int n, m;
  cin >> n >> m;
  vi c(m);
  rep(i, m) cin >> c[i];
  vi dp(n + 1, INF);
  dp[0] = 0;
  rep(i, dp.size()) rep(j, m) if (i - c[j] >= 0) cmin(dp[i], dp[i - c[j]] + 1);
  cout << dp[n] << endl;
}

Measured memory_bytes: 3068
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 5005
#define eps 1e-12
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
	res = 0;T f = 1;char c = getchar();
	while(c < '0' || c > '9') {
		if(c == '-') f = -1;
		c = getchar();
	}
	while(c >= '0' && c <= '9') {
		res = res * 10 + c - '0';
		c = getchar();
	}
	res *= f;
}
template<class T>
void out(T x) {
	if(x < 0) {x = -x;putchar('-');}
	if(x >= 10) {
		out(x / 10);
	}
	putchar('0' + x % 10);
}
int N,P[MAXN],X[MAXN];
int dp[MAXN],sum[MAXN];
bool f[MAXN][MAXN];
void Solve() {
	read(N);
	for(int i = 2 ; i <= N ; ++i) read(P[i]);
	for(int i = 1 ; i <= N ; ++i) read(X[i]);
	for(int i = 1 ; i <= N ; ++i) f[i][0] = 1;
	for(int i = N ; i >= 1 ; --i) {
		bool flag = 0;
		for(int j = X[i] ; j >= 0 ; --j) {
			if(f[i][j]) {
				dp[i] = sum[i] - j;
				flag = 1;
				break;
			}
		}
		if(!flag) {
			puts("IMPOSSIBLE");return;
		}
		if(P[i]) {
			for(int j = X[P[i]] ; j >= 0 ; --j) {
				bool t = 0;
				if(j >= X[i]) t |= f[P[i]][j - X[i]];
				if(j >= dp[i]) t |= f[P[i]][j - dp[i]];
				f[P[i]][j] = t;
			}
			sum[P[i]] += X[i] + dp[i];
		}
	}
	puts("POSSIBLE");
}
int main() {
#ifdef ivorysi
	freopen("f1.in","r",stdin);
#endif
	Solve();
}


Measured memory_bytes: 6272
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main()
{
	int N; cin >> N;
	if (N % 2 == 0) {
		cout << N / 2 - 1 << endl;
	}
	else {
		cout << N / 2 << endl;
	}
}

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

int main(){
    int K, N;
    cin >> K >> N;
    int A[N];

    for (int i = 0; i < N; i++){
        cin >> A[i];
    }

    int ans = K - (A[N-1] - A[0]);

    for (int i = 1; i < N; i++){
        int tmp = A[i] - A[i -1];
        ans = max(ans, tmp);
    }

    cout << K - ans << endl;
}


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

int main() {
    int n, k;
    string s;
    cin >> n >> k >> s;

    vector<int> v;
    int cnt=0;
    for(int i=0; i<n-1; i++) {
        if(s[i]!=s[i+1]) {
            v.push_back(cnt);
            cnt=0;
        } else {
            cnt++;
        }
    }
    v.push_back(cnt);

    for(int i=0; i<k; i++) {
        if(v.size()==1) break;
        else if(v.size()==2) {
            int a, b, c;
            a = v.back(); v.pop_back();
            b = v.back(); v.pop_back();
            c = a + b + 1;
            v.push_back(c);
        } else if(v.size()>=3) {
            int a, b, c, d;
            a = v.back(); v.pop_back();
            b = v.back(); v.pop_back();
            c = v.back(); v.pop_back();
            d = a + b + c + 2;
            v.push_back(d);
        }
    }

    int ans=0;
    for(auto x:v) ans += x;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1020
#include <iostream>
#include <cctype>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
	int a[3], k;
	for (int i = 0; i < 3; i++)
		cin >> a[i];
	cin >> k;
	sort(a,a+3);

	for (int i = 0; i < k; i++)
		a[2] *= 2;

	cout << a[0] + a[1] + a[2] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>


typedef long double ld;
typedef long long ll;

using namespace std;

#define MAXN (1 << 20)

int mem[MAXN][2];
int a[MAXN];

int f(int pos, int k) {
	if (pos < 0) {
		return k;
	}
	int & ret = mem[pos][k];
	if (ret != -1) {
		return ret;
	}
	int cur = a[pos] + k;
	int sol1 = f(pos - 1, 0) + cur;
	int sol2 = f(pos - 1, 1) + (10 - cur);
	ret = min(sol1, sol2);

	return ret;
}

int main() {
	int n;
	memset(mem, -1, sizeof(mem));
	string s;
	cin >> s;
	n = s.length();
	for (int i = 0; i < n; i++) {
		a[i] = s[i] - '0';
	}
	cout << f(n - 1, 0) << endl;
	return 0;
}


Measured memory_bytes: 62908
S = input()

sample = 'keyence'
flag = True

for i in range(7):
    if S[i] != sample[i]:
        if S[-(7-i):] == sample[-(7-i):]:
            print('YES')

        else:
            print('NO')
        
        flag = False
        break

if flag:
    print('YES')


Measured memory_bytes: 2940
import 'dart:io';

main(List<String> args) {
  var N = int.parse(stdin.readLineSync());
  var S1 = (1 + N) * N ~/ 2;
  var S2 = 0;
  var S3 = 0;
  var S4 = 0;

  if (N >= 3) {
    S2 = (3 + (N ~/ 3) * 3) * (N ~/ 3) ~/ 2;
    if (N >= 5) {
      S3 = (5 + (N ~/ 5) * 5) * (N ~/ 5) ~/ 2;
    }
    if (N >= 5) {
      S4 = (15 + (N ~/ 15) * 15) * (N ~/ 15) ~/ 2;
    }
  }
  print(S1 + S4 - S2 - S3);
}


Measured memory_bytes: 13164
struct Read<R: std::io::BufRead> {
    stdin: R,
    v: Vec<String>,
    i: usize,
}
impl<R:std::io::BufRead> Read<R> {
    pub fn new(stdin: R) -> Self {
        Read{
            stdin: stdin,
            v: Vec::new(),
            i: 0,
        }
    }
    pub fn read_line(&mut self) {
        self.i = 0; self.v.clear();
        let mut buf = String::new();
        self.stdin.read_line(&mut buf).unwrap();
        let buf = buf.trim().to_owned();
        let mut ws = buf.split_whitespace();
        loop {
            let x = ws.next();
            if x.is_none() {break;}
            let x = x.unwrap().to_owned();
            self.v.push(x);
        }
    }
    #[allow(dead_code)]
    pub fn read_t<T: std::str::FromStr>(&mut self) -> T {
        if self.i == self.v.len() {self.read_line();}
        let elem = &self.v[self.i];
        self.i += 1;
        elem.parse().unwrap_or_else(|_| panic!())
    }
    
    #[allow(dead_code)]
    pub fn read_i32(&mut self) -> i32 {
        if self.i == self.v.len() {self.read_line();}
        let elem = self.v[self.i].parse().unwrap();
        self.i += 1;
        elem
    }
    #[allow(dead_code)]
    pub fn read_usize(&mut self) -> usize {
        if self.i == self.v.len() {self.read_line();}
        let elem = self.v[self.i].parse().unwrap();
        self.i += 1;
        elem
    }
    #[allow(dead_code)]
    pub fn read_u64(&mut self) -> u64 {
        if self.i == self.v.len() {self.read_line();}
        let elem = self.v[self.i].parse().unwrap();
        self.i += 1;
        elem
    }
    #[allow(dead_code)]
    pub fn read_string(&mut self) -> String {
        if self.i == self.v.len() {self.read_line();}
        let elem = &self.v[self.i];
        self.i += 1;
        elem.to_owned()
    }
}

fn main() {
    use std::io;
    let stdin = io::stdin();
    let stdin = io::BufReader::new(stdin.lock());
    let read = Read::new(stdin);
    solve(read);
}


fn solve<R: std::io::BufRead>(mut r: Read<R>) {
    let n = r.read_i32();
    let m = r.read_i32();
    let q = r.read_i32();
    let mut a:Vec<i32> = Vec::new();
    let mut b:Vec<i32> = Vec::new();
    let mut c:Vec<i32> = Vec::new();
    let mut d:Vec<i32> = Vec::new();
    for _i in 0..q {
        a.push(r.read_i32());
        b.push(r.read_i32());
        c.push(r.read_i32());
        d.push(r.read_i32());
    }
    let mut x:Vec<i32> = Vec::new();
    for _i in 0..n {
        x.push(1);
    }
    let mut ans:i32 = 0;
    loop {
        let mut sum:i32 = 0;
        for i in 0..q as usize {
            if x[b[i] as usize - 1] - x[a[i] as usize - 1] == c[i] {
                sum += d[i];
            }
        }
        ans = if sum > ans {
            sum
        }else{
            ans
        };
        if make_indexes(&mut x, &m) {
            break;
        }
    }

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

fn make_indexes(a: &mut Vec<i32>, m: &i32) -> bool{
    for i in (0..a.len()).rev() {
        if a[i] < *m {
            a[i] += 1;
            for j in (i+1)..a.len() {
                a[j] = a[i];
            }
            return false;
        }
    }

    true
}

Measured memory_bytes: 2116
#include<iostream>
using namespace std;
int main(){
  int x,y,mem;
  while(cin>>x>>y){
    if(x==0&&y==0) break;
    int count=0;
    if(y>x){
      mem = x;
      x = y;
      y = mem;
    }
    while(y!=0){
      x %= y;
      mem = x;
      x = y;
      y = mem;
      count++;
      //cout << y << endl;
    }
    cout << x << ' ' << count << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
  #include "dbgtoki.hpp"
  #define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i) 
DbgTimer D_t;
  #define TSTART() D_t.start()
  #define TSTOP() D_t.stop()
#else
  #define DUMP(i) 
  #define TSTART()
  #define TSTOP()  
#endif
 
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()) , v.end());
using namespace std;
typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

const int EPS = 1e-9;



int main (){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int x;
  while(cin >> x ){
    TSTART();
    
    string ans;
    if(x < 1200)ans = "ABC";
    else ans = "ARC";
    
    cout << ans << endl;
    TSTOP();
  }
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n, a[100005], l, pla;
int main() {
    scanf("%d %d", &n, &l);
    for (int i = 1; i <= n; i ++) {
        scanf("%d", &a[i]);
        if (i != 1)
            if (a[i] + a[i - 1] >= l) pla = i - 1;
    }
    if (pla == 0) return printf("Impossible"), 0;
    printf("Possible\n");
    for (int i = n - 1; i > pla; i --) printf("%d\n", i);
    for (int i = 1; i <= pla; i ++) printf("%d\n", i);
    return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reprl(i, n) for(ll i = n; i >= 0; i--)
#define fori(i, m, n) for(int i = m; i < (int)n; i++)
#define forl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define all(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
const string btos(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  int n;cin>>n;
  bool ans;
  int base=n;
  int sum=0;
  while(n>0){
    sum+=n%10;
    n/=10;
  }
  cout << btos(base%sum==0)<<endl;
  return 0;
}


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

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

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<ll,ll> pii;
const int MD = (int)1e9+7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

ll gcd(ll x, ll y){ return y==0? x: gcd(y, x%y); }

ll f(const vector<ll>& ts, int s){
	ll ans = s? ts[0]: ts[1];
	rep(i,sz(ts)) if(i!=s) ans = gcd(ans, ts[i]);
	return ans;
}


int main(){
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	vector<ll> a(n);
	rep(i, n) cin>>a[i];
	if(n==2){cout << max(a[0], a[1]) <<"\n"; return 0;}
	
	vector<ll> lck(n), rck(n);
	ll lmn=MD, rmn=MD;
	int lpt=-1, rpt=-1;
	rep(i, n){
		if(i==0) lck[i] = a[0];
		else lck[i] = gcd(lck[i-1], a[i]);
	}
	repr(i, n-1,0){
		if(i==n-1) rck[i] = a[n-1];
		else rck[i] = gcd(rck[i+1], a[i]);
	}
	
	ll ans = max(rck[1], lck[n-2]);
	rep(i,n-2){
		ans = max(ans, gcd(lck[i], rck[i+2]));
		
	}
	
	cout << ans <<"\n";
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define ll long long int
#define pb(x) push_back(x)
#define TEST int inox,t;cin>>t; for(inox=1;inox<=t;inox++)
#define rep(i,n) for(i=0;i<n;i++)
#define repr(i,n) for(i=n-1;i>=0;i--)
#define mp(x,y)  make_pair(x,y)
#define FAST    ios::sync_with_stdio(false); cin.tie(0);
#define modd 1000000007
using namespace std;
 
int main(){
int n; cin>>n;
if(n>=30)cout<<"Yes";
else cout<<"No";
}

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

int main(){
	int n,a,b,c,d;
  cin >> n;
  a = n/1000 ;
  b = (n-a*1000)/100 ;
  c = (n-a*1000-b*100)/10 ;
  d = n-a*1000-b*100-c*10 ;
	if ((a == b && b== c) || (b == c && c == d)){
    cout << "Yes" << endl;
    }
	else
      cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    new Main().solve();
  }

  public void solve() {

    Scanner sc = new Scanner(System.in);

    int N = sc.nextInt();
    int T = sc.nextInt();

    int[] c = new int[N];
    int[] t = new int[N];
    for (int i = 0; i < N; i++) {
      c[i] = sc.nextInt();
      t[i] = sc.nextInt();
    }

    int cmin = 1001;
    for (int i = 0; i < N; i++) {
      if (t[i] <= T) {
        cmin = Math.min(cmin, c[i]);
      }
    }

    if (cmin == 1001) {
      System.out.println("TLE");
    } else {
      System.out.println(cmin);
    }
  }
}


Measured memory_bytes: 23764
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <utility>
#include <cstdio>
#include <cstring>
#include <numeric>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)

int main()
{
    ll n, tmp;
    set<ll> S;
    cin >> n;

    rep(i, n){
        scanf("%ld", &tmp);
        if(S.find(tmp)==S.end()){
            S.insert(tmp);
        }else{
            S.erase(tmp);
        }
    }

    cout << S.size() << endl;
    

}



Measured memory_bytes: 4864
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    string S;
    cin >> S;
    for(int i=0;i<N;i++){
        for(int w=0; w < S.size(); w++){
        if(S[w]==90)
        S[w] = S[w]-25;
        else
        S[w]= S[w]+1;}
    }
    cout << S << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;

const int N = 5005;
const ll INF = 1e18;
int p[N], c[N];
bool seen[N];

int main() {
#ifdef LOCAL_EXEC
//	freopen("sample.in", "r", stdin);
//	freopen("sample.out", "w", stdout);
#else
  ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif

  int n, k; cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> p[i], p[i]--;
  for (int i = 0; i < n; i++) cin >> c[i];

  ll ans = -INF;
  for (int i = 0; i < n; i++) {
    if (seen[i]) continue;
    VI cur;
    ll tot = 0;
    for (int j = i; !seen[j]; j = p[j]) {
      seen[j] = true;
      cur.push_back(c[j]);
      tot += c[j];
    }
    int sz = cur.size();
    tot = max(0ll, tot);

    for (int st = 0; st < sz; st++) {
      ll sum = 0;
      for (int j = 0; j < k && j < sz; j++) {
        sum += cur[(st + j) % sz];
        int cyc = (k - j - 1) / sz;
        ans = max(ans, sum + tot * cyc);
      }
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3720
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        BigDecimal x = new BigDecimal(in.next());
        BigDecimal y = new BigDecimal(in.next());
        System.out.println(x.multiply(y).setScale(0, RoundingMode.DOWN));
    }
}


Measured memory_bytes: 35940
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main() {
    long long N,x,sumv=0;
	cin >> N >> x;
	vector<int> vec(N);
	for (auto& v : vec){cin >> v;sumv += v;}

    if (sumv < x) {cout << N-1 << endl;} 
    else if (sumv == x) {cout << N << endl;}
    else {
        sort(vec.begin(),vec.end());
        for (int i=0;i<N;i++) {
            if (x >= vec[i]) { x -= vec[i]; }
            else { cout << i << endl; break; }
        }
    }
    return 0;
}

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

using namespace std;

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

int getsum(int n)
{
    int res = 0;
    while (n)
    {
        res += n % 10;
        n /= 10;
    }
    return res;
}

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

    int n;
    cin >> n;
    if (n % getsum(n))
        cout << "No" << endl;
    else
        cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
def input():return sys.stdin.readline()[:-1]
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())

D=N()
c=[0]+L()
s=[[0]*27]+[[0]+L() for i in range(D)]

dp=[]
T=[0]
ld=[0]*(27)
for i in range(1,D+1):
    ma=0
    t=0
    for j in range(1,27):
        tmp=s[i][j]+(i-ld[j])*(D-i+1)*c[j]
        if tmp>ma:
            ma=tmp
            t=j
    T.append(t)
    ld[t]=i
        
sc=sum(c)
def point():
    ld=[0]*(27)
    score=-sc*((D+1)*D//2)
    for i in range(1,D+1):
        t=T[i]
        score+=s[i][t]+(i-ld[t])*(D-i+1)*c[t]
        ld[t]=i
    return score

now=point()
import random
for i in range(250000):
    d1,q1=random.randrange(1,D+1),random.randrange(1,27)
    d2,q2=random.randrange(1,D+1),random.randrange(1,27)
    old1=T[d1]
    old2=T[d2]
    T[d1]=q1
    T[d2]=q2
    new=point()
    if new>now:
        now=new
    else:
        T[d1]=old1
        T[d2]=old2
for i in range(300000):
    d1,q1=random.randrange(1,D+1),random.randrange(1,27)

    old1=T[d1]

    T[d1]=q1

    new=point()
    if new>now:
        now=new
    else:
        T[d1]=old1

for i in T[1:]:
    print(i)

Measured memory_bytes: 84960
#include<iostream>
#include<cstdio>
#include<cstring>

const int N=105;
char s[N];
int n,ans;

int calc(int c)
{
	int ret=0,tmp=0;
	for(int i=1;i<=n;i++)
	{
		if(s[i]!=c)tmp++;
		else tmp=0;
		ret=std::max(ret,tmp);
	}
	return ret;
}

int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);

	ans=2333;
	for(int i='a';i<='z';i++)
		ans=std::min(ans,calc(i));
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n;
vector<int>edge[200005];
P dfs(int v,int u,int d){
	P ret = mp(d,v);
	for(int i=0;i<edge[v].size();i++){
		if(edge[v][i]==u) continue;
		ret = max(ret,dfs(edge[v][i],v,d+1));
	}
	return ret;
}
int main(){
	scanf("%d",&n);
	rep(i,n-1){
		int a,b; scanf("%d%d",&a,&b);
		edge[a].pb(b);
		edge[b].pb(a);
	}
	P p = dfs(1,-1,0);
	P q = dfs(p.sc,-1,0);
	//cout << q.fi << " " q.sc << endl;
	if(q.fi%3 == 1) puts("Second");
	else puts("First");
}

Measured memory_bytes: 29952
#include <iostream>

using namespace std;
int main(int argc, char *argv[]) {
	string w,ans="Yes";
	int same;
	cin >> w;
	for(int i = 0; i < w.length(); i++){
		same = 0;
		if (w[i] != '0'){
			for(int j = i+1; j < w.length(); j++){
				if(w[i] == w[j]){
					same++;
					w[j] = '0';
				}
			}
			same++;
			w[i] = '0';
		}
		if(same % 2 == 1) ans = "No";
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
    int N, K, R, S, P; cin >> N >> K >> R >> S >> P;
    int ans = 0;
    string T; cin >> T;
    vector<char> A(K, 'a');
    vector<int> B(K);
    rep(i, N){
        int ama = i%K;
        if(T[i] == 'r'){
            if (A[ama] == 'a' || A[ama] != 'r'){
                ans += P;
                B[ama] = 0;
            } else if(B[ama] == 0){
                B[ama] = 1;
            } else {
                ans += P;
                B[ama] = 0;
            }
            A[ama] = 'r';
        } else if (T[i] == 's'){
            if (A[ama] == 'a' || A[ama] != 's'){
                ans += R;
                B[ama] = 0;
            } else if(B[ama] == 0){
                B[ama] = 1;
            } else {
                ans += R;
                B[ama] = 0;
            }
            A[ama] = 's';
        } else {
            if (A[ama] == 'a' || A[ama] != 'p'){
                ans += S;
                B[ama] = 0;
            } else if(B[ama] == 0){
                B[ama] = 1;
            } else {
                ans += S;
                B[ama] = 0;
            }
            A[ama] = 'p';
        }
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 768
#include <stdio.h>
#define rep(i, n) for(int i = 0; i < n; ++i)

int main(void) {
  int ans = 0, n, min = 101;
  rep(i, 4) {
    scanf("%d", &n);
    ans += n;
    if(n < min) min = n;
  }
  ans -= min;
  min = 101;
  rep(i, 2) {
    scanf("%d", &n);
    ans += n;
    if(n < min) min = n;
  }
  ans -= min;
  printf("%d\n", ans);
  return 0;
}


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

using namespace std;

struct edge
{
    int from,to,cost;
    edge(int _from=0,int _to=0,int _cost=0)
    {
        from=_from;to=_to;cost=_cost;
    }
}edg[10010];

int n,m;

int d[110];
const int INF=1e9+7;
bool bellman(int s)
{
    fill(d,d+n,INF);
    d[s]=0;

    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            edge e=edg[j];
            if(d[e.to]>d[e.from]+e.cost)
            {
                d[e.to]=d[e.from]+e.cost;
                if(i==n-1) return false;
            }
        }
    }
    return true;
}

int main()
{

    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    while(cin>>n)
    {
        m=0;
        int a,b,c,dd;
        for(int i=0;i<n;i++)
        {
            cin>>a>>b;
            for(int j=0;j<b;j++)
            {
                cin>>c>>dd;
                edg[m++]=edge(a,c,dd);
            }
        }
        bellman(0);

        for(int i=0;i<n;i++)
        {
            cout<<i<<" "<<d[i]<<endl;
        }
    }



    return 0;
}



Measured memory_bytes: 3264
N = int(input())
A = [int(i) for i in input().split()]
A.insert(0, 0)

ans = []
for i in reversed(range(1, N + 1)):
    if sum(A[i::i]) % 2 != A[i]:
        A[i] = (A[i] + 1) % 2
    if A[i] == 1:
        ans.append(i)

print(len(ans))
if len(ans) > 0:
    print(*ans)


Measured memory_bytes: 12708
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int H,W;
char table[20][21];

int dp[20][20][20][20];

int grundy(int row1,int col1,int row2,int col2){

	if(row1 > row2 || col1 > col2)return 0;

    if(dp[row1][col1][row2][col2] != -1)return dp[row1][col1][row2][col2];

    set<int> S;

    for(int row = row1; row <= row2; row++){
    	for(int col = col1; col <= col2; col++){
    		 if(table[row][col]=='X')continue;

    		 int x = 0;
    		 x ^= grundy(row1,col1,row-1,col-1);
    		 x ^= grundy(row1,col+1,row-1,col2);
    		 x ^= grundy(row+1,col1,row2,col-1);
    		 x ^= grundy(row+1,col+1,row2,col2);
    		 S.insert(x);
    	}
    }

    int g = 0;
    while(S.count(g) != 0)g++;

    return dp[row1][col1][row2][col2] = g;
}


int main(){

	scanf("%d %d",&H,&W);

	for(int row = 0; row < H; row++){
		scanf("%s",table[row]);
	}

    for(int a = 0; a < H; a++){
    	for(int b = 0; b < W; b++){
    		for(int c = 0; c < H; c++){
    			for(int d = 0; d < W; d++){
    				dp[a][b][c][d] = -1;
    			}
    		}
    	}
    }

	if(grundy(0,0,H-1,W-1) != 0){
		printf("First\n");
	}else{
    	printf("Second\n");
    }
}

Measured memory_bytes: 3788
# 入力
N = int(input())
A = list(map(int,input().split()))

ans = 0
P = 10**9+7
bit = [0 for i in range(70)]

# 各bit独立に1が何個あるか数える
for i in range(N):
    S = bin(A[i])
    for j in range(1,len(S)-1):
        if S[-1*j] == '1':
            bit[j-1] += 1

# 各bitの1の個数と0の個数の積が、XOR和が1になる数字の個数と一致
for i in range(70):
    ans += (2**i)*bit[i]*(N-bit[i])
    ans %= P

print(ans)


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

int main(){
	string s; cin >> s;
	long long count = 0; long long len = 0;
	for (int i = 0; i < (int) s.size(); ++i) {
		if (s[i] == 'W') {
			count += len;
		} else {
			len++;
		}
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 644
import sys

class Node():
    def __init__(self,key):
        self.key = key
        self.left = None
        self.right = None

def insert(t, z):
    y = None
    x = t
    while x is not None:
        y = x
        if z.key < x.key:
            x = x.left
        else:
            x = x.right

    if y is None:
        return z
    else:
        if z.key < y.key:
            y.left = z
        else:
            y.right = z
        return t

def in_order(t):
    s = ""
    l = []
    curr = t
    while True:
        while curr is not None:
            l.append(curr)
            curr = curr.left
        if curr is None and len(l) == 0:
            break
        else:
            curr = l.pop()
            s += " " + str(curr.key)
            curr = curr.right
    return s

def pre_order(t):
    s = ""
    l = []
    curr = t
    while True:
        while curr is not None:
            s += " " + str(curr.key)
            l.append(curr)
            curr = curr.left
        if curr is None and len(l) == 0:
            break
        else:
            curr = l.pop()
            curr = curr.right
    return s

t = None
n = sys.stdin.readline()
lines = sys.stdin.readlines()
for line in lines:
    com = line.split()
    if line[0] == "i":
        t = insert(t, Node(int(com[1])))
    else:
        print(in_order(t))
        print(pre_order(t))

Measured memory_bytes: 151948
n = int(input())

if n == 0:
    print(0)
    exit()

ans = ''
while True:
    ans += str(n % 2)
    if(n < 0):
        n = (abs(n) + 1) // 2
    else:
        n = -1 * (n // 2)

    if(n == 1):
        ans += '1'
        break

print(ans[::-1])

Measured memory_bytes: 3060
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> make_v(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto make_v(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initValue, args...))>(sz, make_v<T>(initValue, args...));
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) out << e << delim[&e == &vec.back()];
    return out;
}
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    i64 N, K;
    read(N, K);

    vector<i64> a(N), b(N);
    rep(i, N) {
        read(a[i], b[i]);
    }

    const auto solve = [&](i64 J) {
        i64 sum = 0;
        rep(i, N) if ((J | a[i]) <= J) sum += b[i];
        return sum;
    };

    i64 ans = solve(K);

    rep(i, 32) {
        if ((K >> i) & 1) {
            i64 J = K;
            J &= ~(1LL << i);
            J |= (1LL << i) - 1;
            chmax(ans, solve(J));
        }
    }

    print(ans);

    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
using namespace std;
int main() {
  char data[8][8];
  for(int i = 0; i < 8; i++) {
    for(int j = 0; j < 8; j++) {
      cin >> data[i][j];
    }
  }

  cout << 90 << endl;
  for(int i = 0; i < 8; i++) {
    for(int j = 0; j < 8; j++) {
      cout << data[7-j][i];
    }
    cout << endl;
  }
  cout << 180 << endl;
  for(int i = 0; i < 8; i++) {
    for(int j = 0; j < 8; j++) {
      cout << data[7-i][7-j];
    }
    cout << endl;
  }
  cout << 270 << endl;
  for(int i = 0; i < 8; i++) {
    for(int j = 0; j < 8; j++) {
      cout << data[j][7-i];
    }
    cout << endl;
  }


  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600
#define BACK 6

int dp[(1<<(BACK*2))+10][60][60][4];

int main(){
  int h,w,k;
  cin>>h>>w>>k;

  vector<string> vec(h+BACK);
  rep(i,BACK){
    vec[i].resize(w);
    vec[i][0] = '.';
    repl(j,1,w) vec[i][j] = '#';
  }
  rep(i,h) cin>> vec[i+BACK];

  h += BACK;

  fill(dp[0][0][0], dp[1<<(BACK*2)][0][0], -INF);
  dp[0][BACK][0][0] = 0;

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

  rep(kk,k+1) rep(x,h) rep(y,w) rep(prevs, 1<<(BACK*2)) if(dp[prevs][x][y][kk]>=0){ //dbg(mp(mp(x,y), mp(kk,dp[prevs][x][y][kk])));
    bool visited[4] = {0,0,0,0};
    int px=0, py=0;
    rep(i,BACK){
      int m = (prevs>>(2*i))%4;
      px -= dx[m], py -= dy[m];
      rep(j,4) if(px==dx[j] && py==dy[j]){
        visited[j] = true;
        break;
      }
    }

    rep(i,4){
      int nx = x + dx[i], ny = y + dy[i], nk = kk + (i>=2);
      if(nk>k || nx<0 || ny<0 || nx>=h || ny>=w || vec[nx][ny]=='#') continue;
      int ncost = dp[prevs][x][y][kk];
      if(vec[nx][ny]!='.' && !visited[i]) ncost += vec[nx][ny] - '0';
      int nmask = prevs%(1<<(2*(BACK-1)));
      nmask = nmask*4 + i;
      dp[nmask][nx][ny][nk] = max(dp[nmask][nx][ny][nk], ncost);
    }
  }

  int res = 0;
  rep(i,1<<(BACK*2)) res = max(res, dp[i][h-1][w-1][k]);

  cout << res << endl;

  return 0;
}

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

#define INF 987654321
#define ll long long

int X, Y, A, B, C;
vector<pair<int, int> > v;

int main()
{
	scanf("%d %d %d %d %d", &X, &Y, &A, &B, &C);
	for(int i=0; i<A; i++)
	{
		int t;
		scanf("%d", &t);
		v.push_back({t, 0});
	}
	for(int i=0; i<B; i++)
	{
		int t;
		scanf("%d", &t);
		v.push_back({t, 1});
	}
	for(int i=0; i<C; i++)
	{
		int t;
		scanf("%d", &t);
		v.push_back({t, 2});
	}
	sort(v.rbegin(), v.rend());
	ll res = 0;
	int a = 0, b = 0, c = 0;
	for(int i=0; i<v.size(); i++)
	{
		int val = v[i].first, col = v[i].second;
		if (col == 0)
		{
			if (a < X) res += val, a++;
		}
		else if (col == 1)
		{
			if (b < Y) res += val, b++;
		}
		else if (col == 2)
		{
			res += val, c++;
		}
		if (a+b+c==X+Y) break;
	}
	printf("%lld", res);
	return 0;
}

Measured memory_bytes: 6128
//by Top1
#include <bits/stdc++.h>
          
#define f first
#define s second
#define int long long
#define ld long double
#define ull unsigned long long
#define pii pair <int, int>
#define pll pair <long, long>
#define mp make_pair
#define pb push_back
#define pf push_front
#define pp pop_back
#define cerr cout
#define rev reverse
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define forn(i, a, b) for (int i = a; i <= b; i++)
#define boost ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0);
#define nxtp next_permutation
#define pvtp prev_permutation
#define KZ return 
#define x1 x21212121
#define y1 y21212121
#define sqr(x) x * x 
      
const int inf = (1e18) + 1;
const int mod = 479001599;
const int maxn = 5e5 + 111;
        
using namespace std;          

int n;
string s, t;

void solve(){
	cin >> n >> s >> t;

	for (int i = 0, j = 0; i + j <= 2 * n - 1;){
		if (i == j){
			cout << s[i];
			i++;
		}
		else{
			cout << t[j];
			j++;
		}
	}
}                              
      
main(){
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);

    boost;
    
    int q = 1;
 
    //cin >> q;
    
    while (q--){
        solve();
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
long long mod = 998244353;
 
// 32 mil = ~1 sec 
long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}
 
/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  
const int biggg = 1000000000;
const long eps = .0000000001;


int main ()
{
  prep();
  double r;
  cin >> r;
  cout << 2*r*pi;
  return 0;
}


Measured memory_bytes: 3800
H,W=map(int,input().split())
while (W>0 and H>0):
    for i in range(H):
        for j in range(W):
            if (i%2==0):
                if (j%2==0):
                    print("#",end="")
                elif ((j+1)%2==0):
                    print(".",end="")
            elif ((i+1)%2==0):
                if ((j+1)%2==0):
                    print("#",end="")
                elif (j%2==0):
                    print(".",end="")
        print()
    print()
    H,W=map(int,input().split())


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

int main(){
    int n,k;
    cin >> n >> k;
    int ans=0;
    while(n>0){
        n /= k;
        ans++;
    }
    cout << ans << endl;

    return 0;    
}

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

using namespace std;

char s[105];

int main() {
	int n;
	scanf("%d%s", &n, s);
	
	if (n & 1) return 0 * printf("No\n");
	
	for (int i = 0; i < n / 2; i++) {
		if (s[i] != s[i + n / 2]) return 0 * printf("No\n");
	}
	
	printf("Yes\n");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
    
signed main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
    cout << fixed << setprecision(20);
 
    int n;
    cin>>n;
    ll a[n-1];
    for(int i=0;i<n-1;i++){
        cin>>a[i];
    }
    ll ans = 0;
    ans += a[0];
    for(int i=0;i<n-2;i++){
        ans += min(a[i],a[i+1]);
    }
    ans += a[n-2]; 
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
static const ll mod=998244353;
ll modpow(ll x,ll y){
if(y==0)
  return 1;
  else if(y%2==0){
  ll z=modpow(x,y/2);
    return (z*z)%mod;
  }else{
  ll z=modpow(x,y/2);
    return (x*((z*z)%mod))%mod;
  }
}
ll K,N;
ll comb[4005];
int main(){
  cin>>K>>N;
  comb[K-1]=1;
  for(ll i=K;i<4005;i++){
  ll x=(comb[i-1]*i)%mod;
    x=(x*modpow(i-K+1,mod-2))%mod;
    comb[i]=x;
  }
  for(ll i=2;i<=2*K;i++){
  ll a=min(i,2*K+2-i);
    a/=2;ll ans=0;ll c=1;
    for(ll j=0;j<=a;j++){
      if(N-2*j<0)break;
      ll b=comb[N+K-1-2*j];
      if(j%2==0)
        ans=(ans+(b*c)%mod)%mod;
      else
        ans=(ans+mod-(b*c)%mod)%mod;
      c=(c*(a-j))%mod;
      c=(c*modpow(j+1,mod-2))%mod;
    }
     cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3636
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
 


public class Main {
	static int a1[]= {0,-1,0,1};
	static int b1[]= {-1,0,1,0};
	private static         Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	static int K,N;
	static long mod =1000000007;

	public static void main(String[] args) {
			int a=sc.nextInt();
			int b=sc.nextInt();
			int c=sc.nextInt();
			
			
			int t=Math.max(a, Math.max(b, c));
			if((t*3-a-b-c)%2==0) {
				p((t*3-a-b-c)/2);
			}else {
				p((t*3-a-b-c)/2+2);
			}
			
	}
	
	static int v(int a,int b,int c) {
		if(a==b&&b==c)return 1;
		int f=Math.min(v(a+1,b+1,c)+1, v(a+1,b,c+1)+1);
		int ff=Math.min(v(a,b+1,c+1)+1, v(a+2,b,c)+1);
		int fff=Math.min(v(a,b+2,c)+1, v(a,b,c+2)+1);
		return Math.min(f, Math.min(ff, fff));
	
	}
	//N==S
	//E==W
//83 S 
	//69E
	//78N
	//87W
	
	//static ArrayList<Integer> cc = new ArrayList<>(10001);
	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	public static int gcd(int a, int b) {
        return b == 0 ? a: gcd(b, a % b);
	}
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
}
	


Measured memory_bytes: 21844
import sys
from collections import deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, k, *a = map(int, read().split())

l = [0] * (n + 1)

q = deque([])
i = 1
while True:
    q.append(i)
    l[i] += 1
    if l[i] == 2:
        left = q.index(i)
        right = len(q)-2
        break
    i = a[i - 1]

length = right - left + 1

if k > left:
    b = k - left
    k = b % length
    print(q[left+k])
else:
    print(q[k])


Measured memory_bytes: 29636
using static System.Math;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //var line = ReadLine().Split(' ').Select(value => int.Parse(value)).ToArray();
            var q = int.Parse(ReadLine());
            var answers = new List<int>();
            var isPrime = new bool[100000];
            for(var i = 3; i < isPrime.Length; i += 2)
            {
                isPrime[i] = true;
            }
            isPrime[2] = true;
            for(var i = 3; i <= isPrime.Length; i += 2)
            {
                if(!isPrime[i])
                {
                    continue;
                }
                for(var j = i + 2; j <= isPrime.Length; j += 2)
                {
                    if(j % i == 0)
                    {
                        isPrime[j] = false;
                    }
                }
            }

            var sumLike2017 = new int[100000];
            for(var i = 3; i < sumLike2017.Length; i += 2)
            {
                if(isPrime[i] && isPrime[(i + 1) / 2])
                {
                    sumLike2017[i] = 1;
                }
            }
            for(var i = 3; i < sumLike2017.Length; i++)
            {
                sumLike2017[i] += sumLike2017[i - 1];
            }

            for(var i = 0; i < q; i++)
            {
                var line = ReadLine().Split(' ').Select(value => int.Parse(value)).ToArray();
                var l = line[0];
                var r = line[1];

                answers.Add(sumLike2017[r] - sumLike2017[l - 1]);
            }

            answers.ForEach(value => WriteLine(value));
        }
    }
}


Measured memory_bytes: 17696
while 1:
    m, n1, n2 = map(int, raw_input().split())
    if m==0:
        break
    P = [int(raw_input()) for i in xrange(m)]
    P.sort()
    m = 0
    idx = -1
    for i in xrange(n2, n1-1, -1):
        v = P[-i] - P[-i-1]
        if m < v:
            m = v
            idx = i
    print idx

Measured memory_bytes: 6344
#include<stdio.h>

int main(void){
    int p, q, r, ans;
    scanf("%d %d %d", &p, &q, &r);

    if(p < q){
        if(q < r) ans = p + q;
        else ans = p + r;
    }else{
        if(p < r) ans = p + q;
        else ans = q + r;
    }

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

    return 0;
}

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

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

int main() {
    int a, b;

    cin >> a >> b;

    cout << (a > b? gcd(a, b): gcd(b, a)) << endl;
    
    return 0;
}

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

int main(){
  int n;
  int d[100];
  cin >> n;
  for (int i = 0; i<n; i++) cin >> d[i];
  
  set<int> values;
  for (int i = 0; i < n; i++){
    values.insert(d[i]);
  }
  
  cout << values.size() << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"flag"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

/*-----------Main-----------*/

func main() {
	u := "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
	s := readS()
	if strings.Contains(u, s) {
		fmt.Println("A")
	} else {
		fmt.Println("a")
	}
}

/*-----------Utilities-----------*/

var sc = bufio.NewScanner(os.Stdin)

func init() {
	if flag.Parse(); flag.Arg(0) == "debug" {
		debug()
	}
	const maxBuf = 200100
	var buf []byte = make([]byte, maxBuf)
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBuf)
}

func debug() {
	testFile, err := os.Open("./test/sample-2.in")
	if err != nil {
		fmt.Println("Error : There is no testfile.")
		os.Exit(1)
	}
	sc = bufio.NewScanner(testFile)
}

func readS() string {
	sc.Scan()
	return sc.Text()
}

func readSs(a int) []string {
	b := make([]string, a)
	for i := 0; i < a; i++ {
		b[i] = readS()
	}
	return b
}

func readI() int {
	sc.Scan()
	r, _ := strconv.Atoi(sc.Text())
	return r
}

func readIs(a int) []int {
	b := make([]int, a)
	for i := 0; i < a; i++ {
		b[i] = readI()
	}
	return b
}

func readF() float64 {
	sc.Scan()
	r, _ := strconv.ParseFloat(sc.Text(), 64)
	return r
}

func readFs(a int) []float64 {
	b := make([]float64, a)
	for i := 0; i < a; i++ {
		b[i] = readF()
	}
	return b
}

func max(a []int) int {
	l := len(a)
	m := a[0]
	for i := 1; i < l; i++ {
		if a[i] > m {
			m = a[i]
		}
	}
	return m
}

func min(a []int) int {
	l := len(a)
	m := a[0]
	for i := 1; i < l; i++ {
		if a[i] < m {
			m = a[i]
		}
	}
	return m
}

func sortI(a []int) []int {
	sort.Ints(a)
	return a
}

func reverse(a []int) []int {
	l := len(a)
	r := make([]int, l)
	for i := 0; i < l; i++ {
		r[i] = a[l-i-1]
	}
	return r
}

func countI(a []int, b int) int {
	l := len(a)
	var c int
	for i := 0; i < l; i++ {
		if a[i] == b {
			c++
		}
	}
	return c
}


Measured memory_bytes: 1848
#include  <bits/stdc++.h>
using namespace std;
map<long long ,int > d;
int main()
{
    int n,m;
    cin>>n;
    int x;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        d[x]=1;
    }
    cin>>n;
    int sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        if(d[x]) sum++;
    }
    cout<<sum<<endl;

}

Measured memory_bytes: 3088