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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

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

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

int main(void){
    string S; cin >> S;
    if(S == "Sunny") cout << "Cloudy" << endl;
    else if(S == "Cloudy") cout << "Rainy" << endl;
    else cout << "Sunny" << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const long long mod = 1e9 + 7;

ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

ll powMod(ll n, ll k, ll m) {
	if (k == 0) {
		return 1;
	} else if (k % 2 == 1) {
		return powMod(n, k - 1, m) * n % m;
	} else {
		ll t = powMod(n, k / 2, m);
		return t * t % m;
	}
}


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

	ll ac=0;
	ll wa = 0;
	ll tle = 0;
	ll re = 0;

	rep(i, n) {
		string s;
		cin >> s;
		if (s == "AC") {
			ac++;
		} else if(s=="WA"){
			wa++;
		} else if (s == "TLE") {
			tle++;
		} else {
			re++;
		}
	}

	cout << "AC x " << ac << endl;
	cout << "WA x " << wa << endl;
	cout << "TLE x " << tle << endl;
	cout << "RE x " << re << endl;
}


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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	long long int N,A,B;
	cin>>N>>A>>B;
	long long int temp=max(A,B)-min(A,B)-1;
	if(temp%2) cout<<temp/2+1<<"\n";
	else{
	    long long int ans1,ans2;
	    long long int a,b;
	    a=min(A,B);
	    b=max(A,B);
	    ans1=N-b;
	    a+=N-b;
	    b=N;
	    a++;
	    ans1++;
	    if(a!=b) ans1+=(b-a-1)/2+1;
	    a=min(A,B);
	    b=max(A,B);
	    ans2=a-1;
	    b-=a-1;
	    a=1;
	    b--;
	    ans2++;
	    if(a!=b) ans2+=(b-a-1)/2+1;
	    cout<<min(ans1,ans2)<<"\n";
	}
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] tmpArray = br.readLine().split(" ");
		
		int a = Integer.parseInt(tmpArray[0]);
		int b = Integer.parseInt(tmpArray[1]);
		
		int result = 0;
		for(int i = 1; i <= a; i++){
			for(int j = 1; j <= 31; j++){
				if(i == j){
					result++;
				}
				if(i == a && j == b){
					break;
				}
			}
		}

		System.out.println(result);
	}

}


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

int main(){
	int n;
	int max1 = 0;
	int max2 = 0;
	unordered_map<int, int> m;
	cin >> n;
	for(int i=0; i<n; i++){
		int tmp;
		cin >> tmp;
		m[tmp]++;
		if(m[tmp]==2){
			if(tmp > max1) {
				max2 = max1;
				max1 = tmp;
			} else if(tmp > max2) max2 = tmp;
		}
	}
	if(m[max1] < 4) {
		cout << (long)max1 * max2;
	} else {
		cout << (long)max1 * max1;
	}
}



Measured memory_bytes: 4388
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    n = list(map(int,input().rstrip()))
    digit=len(n)
    ans1=0
    ans2=0

    if digit==1:
        print(n[0])
        exit()
    else:
        ans1=sum(n)
        ans2=n[0]-1+(digit-1)*9
        print(max(ans1,ans2))

if __name__=="__main__":
    main()

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

int main(void){
    int a,b;
    char c;
    char op[]={'+','-','*','/'};

while(1){
    scanf("%d %c %d",&a,&c,&b);

    if (c==op[0]){
        printf("%d\n",a+b);
    }else if(c==op[1]){
        printf("%d\n",a-b);
    }else if (c==op[2]){
        printf("%d\n",a*b);
    }else if (c==op[3]){
        printf("%d\n",a/b);
    }else if (c=='?'){
        break;
    }
}
}


Measured memory_bytes: 2116
// Date: 2020-03-16

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

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
#define FIO ios::sync_with_stdio(false);cin.tie(0)
#define rep(i, a, b) for(int i = int(a); i <= int(b); ++i)
#define per(i, b, a) for(int i = int(b); i >= int(a); --i)
#define mem(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const LL INF = 1e18;
const LL mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 1e4 + 10;
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
LL qpow(LL x, LL y, LL MOD) {LL a=1; while(y){ if(y&1) a=a*x%MOD; x=x*x%MOD; y>>=1; } return a;}

LL dp[N][100];
int a[N], D;
string s;
LL dfs(int pos, bool lim, int sum) {
    if(pos == -1) return sum % D == 0;
    if(dp[pos][sum] != -1 && !lim) return dp[pos][sum];
    int up = lim ? a[pos] : 9;
    LL ans = 0;
    rep(i, 0, up) {
        ans = (ans + dfs(pos-1, lim && i == up, (sum + i) % D)) % mod;
    }
    if(!lim) dp[pos][sum] = ans;
    return ans;
}

int main() {
    FIO;
    cin >> s >> D;
    int pos = 0;
    for(int i = s.size()-1; i >= 0; --i) a[pos++] = s[i]-'0';
    mem(dp, -1);
    LL ans = (dfs(pos-1, 1, 0) - 1 + mod) % mod;
    cout << ans;

    return 0;
}

Measured memory_bytes: 9088
<?php

function main() {
  $a = fgets(STDIN);
  $aArr = explode(" ", $a);
  $k = $aArr[0];
  $x = $aArr[1];

  if($k*500 >= $x) echo 'Yes',PHP_EOL;
  else echo 'No',PHP_EOL;
}

main();

Measured memory_bytes: 4728
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const double eps = 1E-18;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

//////////////////////////////////////


int main() {
	ll N;
	cin >> N;
	vvll a(N + 1, vll(N + 1, 0));
	rep(i, N)rep(j, N) cin >> a[i][j];

	vmint dp(1 << N, 0);
	dp[0] = 1;

	repn(i, (1 << N)-1) {
		
		ll pop = 0;
		rep(j, N) { if ((i >> j) & 1) { pop++; } }

		rep(j, N) {
			if (((i >> j) & 1)&&a[j][pop-1]==1) {
				dp[i] += dp[i ^ (1 << j)];
			}
		}

		//cout << i << dp[i] << endl;
	}

	cout << dp[(1 << N) - 1] << endl;
}



Measured memory_bytes: 19588
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,a,b,c,t=0;
    cin>>a>>b>>c>>n;
    for(int i=0;i<=a;i++)
        for(int j=0;j<=b;j++)
            for(int k=0;k<=c;k++)
            {
                if(i*500+j*100+k*50==n)
                   t++;
                if(i*500+j*100+k*50>n)break;
            }
    cout<<t;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
using P = pair<int,int>;
static const int64_t INF = 1000000000;


int main(){
	int N;
	cin >> N;
	vector<int> x(N);
	vector<int> y(N);
	rep(i, N) cin >> x[i] >> y[i];
	
	vector<vector<long double>> mp(N, vector<long double>(N, 0.0));
	rep(i, N) rep(j, N){
		if(i == j) continue;
		mp[i][j] = sqrt((x[i] - x[j])*(x[i] - x[j]) + (y[i] - y[j])*(y[i] - y[j]));
	}
	
	vector<int> route(N);
	rep(i, N) route[i] = i+1;
	long double total = 0;
	int num = 0;
	do{
		rep(i, N-1){
			total += mp[route[i]-1][route[i+1]-1];
		}
		num++;
	}while(next_permutation(route.begin(), route.end()));
    total /= (long double)num;
	cout << fixed << setprecision(10) << total << endl;
	
	return 0;
}




Measured memory_bytes: 256
#include<stdio.h>
#include<cmath>
using namespace std;
  
int main()
{
	double r;
	scanf("%lf", &r);
	
	double S = r * r * M_PI;
	double L = 2 * r * M_PI;
	
	printf("%.6lf\n%.6lf\n" , S ,L);
	return 0;
}

Measured memory_bytes: 1080
n = int(input())
if n == 1:
    print(1)
else:
    result = 0
    _max = 0
    for i in range(n//2, n+1):
        count = 0
        current = i
        while current % 2 == 0:
            current = current // 2
            count += 1
        if _max < count:
            _max = count
            result = i
    print(result)

Measured memory_bytes: 38256
#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase
from math import ceil

def main():
    s = int(input())
    length = s / 3; 
  
    s -= length; 
  
    breadth = s / 2; 
    height = s - breadth; 
    print(length*breadth*height)





# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define FILEIN freopen("input.txt", "r", stdin)
#define endl "\n"
#define ll long long

const ll m = 1e9 + 7;

int main(){
    // FILEIN;
    char a; cin>>a;
    a++; 
    cout<<a<<endl;
}

Measured memory_bytes: 256
w = input()

cnt = {chr(i): 0 for i in range(97, 97 + 26)}
for _w in w:
    cnt[_w] += 1

ans = True
for v in cnt.values():
    if v % 2 != 0:
        ans = False
        break

if ans:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 38384
import java.io.*;
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = Integer.parseInt(sc.next());
    
    if (a >= 3200) {
      System.out.println(sc.next());
    } else {
      System.out.println("red");
    }
  }
}

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

int main(){
	int n,t,a;
	cin>>n;
	cin>>t>>a;
	int h[n];

	for(int i=0;i<n;i++)cin>>h[i];

	double temp[n];
	double res=0,res_tmp,res_min=1000000;
	for(int i=0;i<n;i++){
		temp[i] = t - (h[i]*0.006);
		//cout<<temp[i]<<endl;
		res_tmp = abs(a-temp[i]);
		if(res_min>res_tmp){
			//cout<<res_tmp<<endl;
			res_min = res_tmp;
			//cout<<res_min<<endl;
			res = i+1;
		}
	}

	cout<<res<<endl;

}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

namespace Main
{
    class Program
    {
        static void Main(string[] args)
        {
            //ここから
            //int n = int.Parse(Console.ReadLine());
            //string[] str = Console.ReadLine().Split(' ');

            string s = Console.ReadLine();
            string t = Console.ReadLine();

            for(int i = 0; i < s.Length; i++)
            {
                if (s[i] != t[i])
                {
                    Console.WriteLine("No");
                    return;
                }
            }
            Console.WriteLine("Yes");


            //ここまで
        }

        static long Max(long a, long b)
        {
            if (a > b) return a;
            else return b;
        }


    }

}


Measured memory_bytes: 25680
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

// BEGIN CUT HERE
struct Dense2DSegmentTree {
  using T = int;
  static T op(const T& a, const T& b) { return min(a, b); }
  static constexpr T e() { return ~(~0 << 31); }

  struct SegmentTree {
    const int n;
    V<T> t;
    SegmentTree(int n) : n(n), t(2 * n, e()) {}
    T& operator[](int i) { return t[i + n]; }
    void build() { for (int i = n - 1; i; --i) t[i] = op(t[2 * i], t[2 * i + 1]); }
    T acc(int l, int r) const {
      T res = e();
      for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
        if (l & 1) res = op(res, t[l++]);
        if (r & 1) res = op(res, t[--r]);
      }
      return res;
    }
    void set(int i, const T& a) {
      t[i += n] = a;
      while (i >>= 1) t[i] = op(t[2 * i], t[2 * i + 1]);
    }
  };
  const int n, m;
  V<SegmentTree> st;
  Dense2DSegmentTree(int n, int m) : n(n), m(m), st(2 * n, SegmentTree(m)) {}
  SegmentTree& operator[](int x) { return st[x + n]; }
  void build() {
    for (int x = 0; x < n; ++x) st[x + n].build();
    for (int x = n - 1; x; --x) {
      for (int y = 0; y < m; ++y) st[x][y] = op(st[2 * x][y], st[2 * x + 1][y]);
      st[x].build();
    }
  }
  T acc(int x0, int x1, int y0, int y1) const {
    T res = e();
    for (x0 += n, x1 += n; x0 < x1; x0 >>= 1, x1 >>= 1) {
      if (x0 & 1) res = op(res, st[x0++].acc(y0, y1));
      if (x1 & 1) res = op(res, st[--x1].acc(y0, y1));
    }
    return res;
  }
  void set(int x, int y, const T& a) {
    st[x += n].set(y, a);
    while (x >>= 1) st[x].set(y, op(st[2 * x][y], st[2 * x + 1][y]));
  }
};
// END CUT HERE

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  while (true) {
    int r, c, q; cin >> r >> c >> q;
    if (!r) break;
    Dense2DSegmentTree st(r, c);
    for (int i = 0; i < r; ++i) for (int j = 0; j < c; ++j) {
      cin >> st[i][j];
      // int x; cin >> x;
      // st.set(i, j, x);
    }
    st.build();
    while (q--) {
      int r0, c0, r1, c1; cin >> r0 >> c0 >> r1 >> c1, ++r1, ++c1;
      cout << st.acc(r0, r1, c0, c1) << '\n';
    }
  }
}


Measured memory_bytes: 127880
#[allow(unused_macros)]
macro_rules! input {
    ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } };
    ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ( $ next : expr ) => { };
    ( $ next : expr , ) => { };
    ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! read_value {
    ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) };
    ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) };
    ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) };
    ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 };
    ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) };
}

#[allow(unused_macros)]
macro_rules! chmin {
    ( $ x : expr , $ y : expr ) => { if $ x > $ y { $ x = $ y ; true } else { false } };
}

fn main() {
    input! {
        n: usize,
        h: [i64; n]
    }

    let mut dp = vec![1i64 << 60;n];
    dp[0] = 0;
    for i in 0..n-1 {
        chmin!(dp[i+1], dp[i] + (h[i] - h[i+1]).abs());
        if i != n-2 {
            chmin!(dp[i+2], dp[i] + (h[i] - h[i+2]).abs());
        }
    }
    println!("{}", dp[n-1]);
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
template <class T> vector<T> make_vec(size_t a, T val) {
    return vector<T>(a, val);
}
template <class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec(ts...))>(a, make_vec(ts...));
}
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
template <typename T> struct edge {
    int to;
    T cost;
    edge(int t, T c) : to(t), cost(c) {}
};
template <typename T> using WGraph = vector<vector<edge<T>>>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    ll N, X, M;
    cin >> N >> X >> M;
    ll res = 0;
    ll sum = X;
    set<int> se;
    se.insert(X);
    ll len = 1;
    ll f = 0;
    vector<ll> hist;
    vector<ll> tim(M + 1, -1);
    tim[X] = 1;
    hist.pb(X);
    if(N <= M) {
        res = X;
        for(int i = 0; i < N - 1; i++) {
            X = (X * X) % M;
            res += X;
        }
        cout << res << endl;
        return 0;
    }

    while(1) {
        len++;
        X = (X * X) % M;
        sum += X;
        if(X == 0) {
            f = 1;
            break;
        } else if(X == 1) {
            f = 2;
            break;
        }
        if(se.count(X)) {
            sum -= X;
            len = len - tim[X];
            break;
        } else {
            se.insert(X);
            tim[X] = len;
            hist.pb(X);
        }
    }

    if(f == 1) {
        cout << sum << endl;
    } else if(f == 2) {
        cout << sum + (N - len) << endl;
    } else {
        N -= tim[X];
        ll s = 0, rest = 0;
        rep(j, tim[X] - 1) s += hist[j];
        rep(j, N % len + tim[X]) rest += hist[j];
        sum -= s;
        res = sum * (N / len) + rest;
        cout << res << endl;
    }
}

Measured memory_bytes: 6572
N, K = map(int, input().split())
A = list(map(int, input().split()))

l = [[0]*N for _ in range(60)]

for i in range(60):
    for j in range(N):
        if i == 0:
            l[i][j] = A[j] - 1
        else:
            tmp = l[i-1][j]
            l[i][j] =l[i-1][tmp]
ans = -1
for i in range(59, -1, -1):
    if K >> i & 1:
        if ans == -1:
            ans = l[i][0]
        else:
            ans = l[i][ans]
print(ans+1)


Measured memory_bytes: 174948
#include <stdio.h>

int main(void)

{
 int n, i, j;
 int a[10000];
 int k = 0;
 int count = 0;
 
 scanf("%d", &n);

 for(i = 0; i < n; i++)
{
  scanf("%d", &a[i]);

 if(a[i] % 2 != 0 || a[i] == 2) 
{

  for(j = 2; j <= sqrt(a[i]); j++)
{
  if(a[i] % j == 0)
{
   k = 1;
   break;
}

}

  if(k == 0)
   count++;

 k = 0;

}

}

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

return 0;

}



Measured memory_bytes: 2124
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
int main(){
  int N,D,count=0;
  cin>>N>>D;
  vector<vector<int>> A(N,vector<int>(D));
  rep(i,0,N){
    rep(j,0,D)
      cin>>A.at(i).at(j);
    }
  rep(i,0,N-1){
    rep(j,i+1,N){
      int X=0;
      double Y;
      rep(k,0,D){
        X+=(A.at(i).at(k)-A.at(j).at(k))*(A.at(i).at(k)-A.at(j).at(k));
        }
      Y=sqrt(X);
      X=Y;
      if(X==Y) count++;
      }
    }
  cout<<count<<endl;
  }

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int length = s.length();
        int count_A = -1;
        int count_Z = 0;

        for(int i = 0; i < length; i++){
            char moji = s.charAt(i);
            if(moji == 'A'){
                if(count_A == -1){
                    count_A = i;
                }
            }else if(moji == 'Z'){
                if(count_Z < i){
                    count_Z = i;
                }
            }
        }
        System.out.println(count_Z - count_A + 1);
    }
}

Measured memory_bytes: 26636
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S,ans="Yes";
  cin>>S;
  for(int i=0; i<S.size(); i++){
    if(i%2==0&&S[i]=='L')ans="No";
    if(i%2==1&&S[i]=='R')ans="No";
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
n = gets.to_i
a = gets.split(' ').map(&:to_i)

a.sort!.reverse!

sum = 0
method = 'p'
a.each do |n|
        if n
                if method == 'p'
                        sum += n
                        method = 'm'
                else
                        sum -= n
                        method = 'p'
                end
        else
                break
        end
end

puts sum

Measured memory_bytes: 1788
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#define rep(i,N) for(long long  i=0;i<N;i++)

long long  INF=1000000000000000000;
long long mod=1000000007;
using namespace std;


int main(){

long long dp[110][100010];
//dp[i][k]:=i番目までのitemで価値kを得る時の
//重さの最小値
long long N,W;
cin>>N>>W;
rep(i,N){
    rep(k,N*1000+1){
        dp[i][k]=INF;
    }
}
long long weight[N],value[N];
rep(i,N){
cin>>weight[i]>>value[i];
}

rep(i,N)dp[i][0]=0;

rep(k,N*1000+1){
    rep(i,N){
        if(value[i]<=k){
        dp[i+1][k]=min(dp[i][k],dp[i][k-value[i]]+weight[i]);
        }
        else{
            dp[i+1][k]=dp[i][k];
        }
    }
}
for(long long k=N*1000;k>=0;k--){
    if(dp[N][k]<=W){
        //cout<<dp[N][k]<<endl;
        cout<<k<<endl;
        return 0;
    }
}

 return 0;
}
/*
3 8
3 30
4 50
5 60

90

1 1000000000
1000000000 10

10

6 15
6 5
5 6
6 4
6 6
3 5
7 2

17

*/

Measured memory_bytes: 81152
#include <stdio.h>

int integral(int d){
  int i;
  int area=0;
  int f=0;
  for(i=0;i*d < 600;i++){
	f = i*i*d*d;
	area = area + f*d;
  } 
  return area;
}

int main(){
  char tmp[32];
  int num;
  while(fgets(tmp,32,stdin)!=NULL){
	sscanf(tmp, "%d", &num);
	printf("%d\n", integral(num));
  }
  return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>pppp(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}
 
int main() {
 int N,M;
 cin>>N>>M;
 vector<int>WA(N);
 vector<bool>AC(N,false);
 int ac=0,wa=0;
 for(int i=0;i<M;i++){
   int p;
   string s;
   cin>>p>>s;
   if(AC[p]){continue;}
   if(s=="AC"){ac++;wa+=WA[p];AC[p]=true;}
   if(s=="WA"){WA[p]++;}
 }
 cout<<ac<<" "<<wa<<endl;
 return 0;
}

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

int point[200][3];
int sp[200];

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

	for (int i = 0;i < 3;i++) {
		for (int j = 0;j < n;j++) {
			int a = point[j][i];
			int flg = 0;
			for (int k = 0;k < n;k++) {
				if (a == point[k][i] && (k != j)) {
					point[k][i] = 0;
					flg = 1;
				}
			}
			if (flg == 1)point[j][i] = 0;
		}
	}

	for (int i = 0;i < n;i++) {
		sp[i] = point[i][0] + point[i][1] + point[i][2];
		cout << sp[i] << endl;
	}
	return 0;
}

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

#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
#define PI 3.14159265358979
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}

vector<pair<int,ll>> vec[100000];
ll cost[100000];
void dfs(int now,ll COST){
    cost[now]=COST;
    int next;
    REP(i,vec[now].size()){
        next=vec[now][i].first;
        if(cost[next]<0){
            dfs(next,COST+vec[now][i].second);
        }
    }
}
int counter(int x){
    if(!x)return 0;
    return counter(x>>1)+(x&1);
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N=in();
    vector<int> ls(N);
    for(auto& l:ls){
        cin>>l;
    }
    int max_l=*max_element(all(ls));
    debug(max_l);
    vector<int>count(2*max_l+1,0);
    for(auto l:ls){
        ++count[l];
    }
    vector<int>count_sum(2*max_l+1,0);
    count_sum[0]=count[0];
    for(int i=1;i<(int)count.size();++i){
        count_sum[i]=count_sum[i-1]+count[i];
    }
    ll num_1=0;
    REP(i,N){
        REP(j,N){
            if(make_pair(ls[i],i)<make_pair(ls[j],j)){
                num_1+=count_sum[ls[i]+ls[j]-1]-count_sum[ls[j]];
            }
        }
    }
    ll num_2=0;
    REP(i,2*max_l+1){
        if(count[i]>=3){
            num_2+=((ll)count[i])*(count[i]-1)*(count[i]-2)/6;
        }
    }
    ll num_3=0;
    REP(i,2*max_l+1){
        if(count[i]>=2){
            num_3+=(ll)(count[i]-1)*count[i]*(count_sum[i-1])/2;
        }
    }
    cout<<num_1+num_2+num_3<<endl;
    return 0;
}


Measured memory_bytes: 3584
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

public class Main {

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.call(in , out);
        out.close();
    }

    static class TaskA {
        public void call(InputReader in ,PrintWriter out ) {
            int n ;
            n=in.nextInt();
            int[][] arr = new int[n][3];
            for(int i=0;i<n;i++){
                for(int j =0;j<3;j++){
                    arr[i][j] = in.nextInt();
                }
            }
            int[][] dp = new int[n][3];
            for(int j =0;j<3;j++){
                dp[n-1][j]=arr[n-1][j];
            }
            for(int i=n-2;i>=0;i--){
                for(int j =0;j<3;j++){
                    if(j==0)
                        dp[i][j] =arr[i][j] + Math.max(dp[i+1][j+1] , dp[i+1][j+2]);
                    else if(j==1)
                        dp[i][j] =arr[i][j] + Math.max(dp[i+1][j-1] , dp[i+1][j+1]);
                    else
                        dp[i][j] =arr[i][j] + Math.max(dp[i+1][j-1] , dp[i+1][j-2]);
                }
            }
            out.println(Math.max(dp[0][0] ,Math.max(dp[0][1] ,dp[0][2])));


        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }


    }
}


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

int main(){
  int n,d,x;
  cin >> n >> d >> x;
  vector<int> p(n);
  rep(i,n)cin >> p[i];

  rep(azu,d-1){
    vector<int> q(n);
    rep(i,n)cin >> q[i];
    vector<int> dp(x+1,0);
    
    rep(i,n){
      rep(j,x-p[i]+1){
	dp[j+p[i]] = max(dp[j+p[i]], dp[j]+q[i]);
      }
    }

    int maxv = x;
    rep(i,x+1)maxv = max(maxv, dp[i]+x-i);
    x = maxv;
    p = q;
  }
  cout << x << endl;
}

Measured memory_bytes: 1324
import java.util.*;

public class Main{
  
  public static void main(String[] args){
    
  Scanner scanner = new Scanner (System.in);
  
  	int totalButton = scanner.nextInt();
    
    Integer[] buttonList = new Integer[totalButton+1];
    
    for (int buttonNum=0; buttonNum<totalButton; buttonNum++){
      int temp = scanner.nextInt();
      buttonList[buttonNum+1]=temp;
    }
    int nowButton=1;
    boolean flag = false;
    int num;
    for(num=0; num<totalButton; num++){
      int temp = buttonList[nowButton];
      nowButton=temp;
      
      if (nowButton==2){
        flag=true;
        num++;
        break;
      }
    }
    if (flag==true){
      System.out.println(num);
    } else {
      System.out.println("-1");
    }
  }
}

Measured memory_bytes: 63916
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
const ld pi = 3.14159265358979323846;

//最小公倍数(LCM)
ll lcm(ll a, ll b) {
    return a / __gcd(a, b) * b; // Be careful not to overflow
}

int main() {
    ll n;
    cin>>n;
    vector<ll> t(n);
    rep(i,n) cin>>t[i];
    ll LCM=t[0];
    rep2(i,1,n) LCM=lcm(LCM,t[i]);
    cout<<LCM<<endl;
}

Measured memory_bytes: 3652
s = input()
n = len(s)

d = dict()
d['a'] = 1
d['b'] = 2
d['c'] = 3
d['d'] = 4
d['e'] = 5
d['f'] = 6
d['g'] = 7
d['h'] = 8
d['i'] = 9
d['j'] = 10
d['k'] = 11
d['l'] = 12
d['m'] = 13
d['n'] = 14
d['o'] = 15
d['p'] = 16
d['q'] = 17
d['r'] = 18
d['s'] = 19
d['t'] = 20
d['u'] = 21
d['v'] = 22
d['w'] = 23
d['x'] = 24
d['y'] = 25
d['z'] = 26

e = dict()
e[1] = 'a'
e[2] = 'b'
e[3] = 'c'
e[4] = 'd'
e[5] = 'e'
e[6] = 'f'
e[7] = 'g'
e[8] = 'h'
e[9] = 'i'
e[10] = 'j'
e[11] = 'k'
e[12] = 'l'
e[13] = 'm'
e[14] = 'n'
e[15] = 'o'
e[16] = 'p'
e[17] = 'q'
e[18] = 'r'
e[19] = 's'
e[20] = 't'
e[21] = 'u'
e[22] = 'v'
e[23] = 'w'
e[24] = 'x'
e[25] = 'y'
e[26] = 'z'

appear = [0 for i in range(27)]
string = [0]
for i in range(n):
	string.append(d[s[i]])
	appear[d[s[i]]] += 1

exist = 0
for i in range(1,27):
	if appear[i] == 0:
		exist = i
		break

if exist != 0: #ない文字があった時
	string.append(exist)
	for k in range(1,n+2):
		if k != n+1:
			print(e[string[k]],end='')
		else:
			print(e[string[k]])
else:
	if s == 'zyxwvutsrqponmlkjihgfedcba':
		print('-1')
	else:
		bunki = 26
		i = 26
		while i > 1:
			if string[i-1] > string[i]:
				bunki = i-1
				i += -1
			else:
				break
		memo = []
		for k in range(bunki,27):
			memo.append(string[k])
		memo.sort()
		t = [string[bunki-1]]
		for k in range(len(memo)):
			if t[0] < memo[k]:
				okikae = memo[k]
				break
		string[bunki-1] = okikae
		for h in range(1,bunki):
			if h!= bunki-1:
				print(e[string[h]],end='')
			else:
				print(e[string[h]])

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

#n = int(input())
#l = list(map(int, input().split()))

'''
a=[]
b=[]
for i in range():
    A, B = map(int, input().split())
    a.append(A)
    b.append(B)'''

x,y = map(int, input().split())

for i in range(x+1):
    if 2*(x-i)+4*i==y:
        print("Yes")
        sys.exit()
print("No")

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

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

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u; return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}

bool solve() {
	int W, H, T, P; cin >> W >> H >> T >> P;
	if (!W && !H && !T && !P) return (false);

	int ofx = 0, ofy = 0;
	vvint paper(1000, vint(1000, 0));
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			paper[i][j] = 1;
		}
	}

	while (T--) {
		int d, c; cin >> d >> c;
		if (d == 1) {
			chmax(W, ofx+2*c);
			for (int i = ofy; i < H; i++) {
				for (int j = 0; j < c; j++) {
					paper[i][ofx+2*c-j-1] += paper[i][ofx+j];
				}
			}
			ofx += c;
		}
		if (d == 2) {
			chmax(H, ofy+2*c);
			for (int i = 0; i < c; i++) {
				for (int j = ofx; j < W; j++) {
					paper[ofy+2*c-i-1][j] += paper[ofy+i][j];
				}
			}
			ofy += c;
		}
		/*
		for (int i = ofy; i < H; i++) {
			for (int j = ofx; j < W; j++) {
				cout << paper[i][j] << " ";
			}
			cout << endl;
		}
		cout << endl;
		*/
	}

	while (P--) {
		int x, y;
		cin >> x >> y;
		//cout << ofy << " " << endl;
		cout << paper[y+ofy][x+ofx] << endl;
	}

	return (true);
}

void Main() {
	while (solve());
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}



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

int main() {
	ll n;
	cin >> n;
	if (n == 0 || n == 1) {
		cout << n << endl;
		return 0;
	}
	vector<int>ans;
	ll x = 1;
	while (n != 0) {
		ll n0 = n;
		ll n1 = n + x;
		if (n0 % (-2 * x) == 0)ans.push_back(0);
		else {
			ans.push_back(1);
			n -= x;
		}
		x *= (-2);
	}
	reverse(ans.begin(), ans.end());
	for (int i = 0; i < ans.size(); i++)cout << ans.at(i);
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<stack>/*** LIFO *** stack<type> var;
push(), top():to get data, pop():to remove, size(), empty() ***/
using namespace std;

#define Fp(I, STAT, END) for(int I = STAT; I < END; I++)
#define Fm(I, STAT, END) for(int I = STAT; I > END; I--)

int main(){
    int N;
    cin >> N;
    int H[N];
    Fp(i, 0, N) cin >> H[i];
    Fp(i, 1, N){
        if(H[i - 1] > H[i]){
            cout << "No" << endl;
            return 0;
        }else if(H[i - 1] < H[i]) H[i]--;
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 640
module List = ListLabels

let ( *@) a b = (a * b ) mod 1000000007

let () =
  Scanf.scanf "%d %d" @@ fun n k ->
  let g =
    let g = Array.init (n+1) (fun _ -> []) in
    for i = 1 to n-1 do
      Scanf.scanf " %d %d" @@ fun a b ->
        g.(a) <- b :: g.(a);
        g.(b) <- a :: g.(b);
    done; g
  in

  let rec dfs x p c d2 =
    List.fold_left g.(x) ~init:(c, 0) ~f:(fun (a, j) y ->
      if y = p then (a, j) else
      let m = dfs y x (c-1-j+d2) (j + min 1 p) in
      (a *@ m, j+1))
    |> fst
  in
  dfs 1 0 k 0 |> Printf.printf "%d\n"


Measured memory_bytes: 21888
def input_from_console():
    s = list(input().strip())
    return s


def solve(s):
    result = 'No'
    if len(set(s)) == 2 and s.count(set(s).pop()) == 2:
        result = 'Yes'
    return result


def main():
    s = input_from_console()
    print(solve(s))


if __name__ == "__main__":
    import sys

    if sys.gettrace():  # Check if the python interpreter is in debug mode or not.
        check_cases()
    else:
        main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define MOD 1000000007
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef long long ll;
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///

int N;
int par[10001]; int hukasa[10001];

int find(int x)
{
	if (par[x] == x) return x;
	else return par[x] = find(par[x]);
}

void unite(int x, int y)
{
	x = find(x); y = find(y);
	if (x == y) return;
	if (hukasa[x] < hukasa[y]) par[x] = y;
	else
	{
		par[y] = x;
		if (hukasa[x] == hukasa[y]) hukasa[x]++;
	}
}

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

void init_UFT(int n) //要素数nのUFTを初期化
{
	REP(i, n)
	{
		par[i] = i;
		hukasa[i] = 0;
	}
}

int main()
{
	int q;
	cin >> N >> q;
	init_UFT(N);
	REP(i, q)
	{
		int c, x, y;
		cin >> c >> x >> y;
		if (c)
		{
			if (same(x, y)) puts("1");
			else puts("0");
		}
		else
		{
			unite(x, y);
		}
	}
	return 0;
}

Measured memory_bytes: 1184
#include <iostream>
#include <cstring>
using namespace std;
int main(void){
    // Your code here!
    string s,p,t;
    getline (cin,s);
    getline (cin,p);
    t=s+s;//strが連続した
    /*for(int i=0;i<s.size();i++)
    {
        int M[100]={};
        for(int u=0;u<p.size();u++)
        {
            
        }
    }*/
    if(t.find(p)==-1)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    return 0;
    
}



Measured memory_bytes: 3200
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a,b) ((a)>(0)?(a):-(a))

void run(void){
  int a,b,c;
  scanf("%d%d%d",&a,&b,&c);
  int max=MAX(a,MAX(b,c));
  int min=MIN(a,MIN(b,c));
  int mid=a+b+c-max-min;
  int k=0;
  while(mid<max){
    mid++;
    min++;
    k++;
  }
  while(min<max){
    min+=2;
    k++;
  }
  if(min>max) k++;
  printf("%d\n",k);
  return;
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}


int main(){
  string s;
  cin>>s;
  ll a[4]={};
  rep(i,4){
    if(s[i]=='N') a[0]++;
    if(s[i]=='W') a[1]++;
    if(s[i]=='S') a[2]++;
    if(s[i]=='E') a[3]++;
  }

  if(a[0]*a[2]>0&&a[1]==0&&a[3]==0||a[1]*a[3]>0&&a[0]==0&&a[2]==0||a[0]*a[1]*a[2]*a[3]>0)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}


Measured memory_bytes: 256
N = gets.to_i
A = gets.split(' ').map(&:to_i)

@nums = []
A.each_with_index do |num, i|
  @nums << (num - i - 1)
end

@nums.sort!

def score(b)
  score = @nums.map{|n| (n - b).abs }.reduce(:+)
  score
end

current = min = score(@nums[0])
@nums.each_with_index do |b, i|
  next if i == 0 || i == N
  diff = @nums[i] - @nums[i - 1]
  s = current + i * diff - (N - i) * diff
  min = [min, s].compact.min
  current = s
end
puts min


Measured memory_bytes: 23728
using System;

class Program
{
    static string S;
    static int n;

    static void Main()
    {
        S = Console.ReadLine();
        n = S.Length;

        bool f = false;
        for (int i = 0; i < n - 1; i++)
            f = f || (S[i] == 'A' && S[i + 1] == 'C');

        Console.WriteLine(f ? "Yes" : "No");
    }
}

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

int main (){
	int n;
	cin >> n;
	int a[n+1], b[n+1], c[n];
	for(int i=1; i<=n; i++){
		cin >> a[i];
	}
	for(int i=1; i<=n; i++){
		cin >> b[i];
	}
	for(int i=1; i<n; i++){
		cin >> c[i];
	}
	int res=b[a[1]];
	for(int i=2; i<=n; i++){
		res+=b[a[i]];
		if(a[i]==a[i-1]+1) res+=c[a[i-1]];
	}
	cout << res;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n,m=map(int,input().split())
    KV=[None]*m
    for i in range(m):
        K=0
        a,b=map(int,input().split())
        for c in map(int,input().split()):
            c-=1
            K|=1<<c
        KV[i]=(K,a)

    N=1<<n
    dp=[INF]*N
    dp[0]=0
    for K,v in KV:
        ndp=dp[:]
        for i in range(N):
            ndp[i|K]=min(ndp[i|K],dp[i]+v)
        dp=ndp

    ans=dp[-1]
    if(ans==INF): ans=-1
    print(ans)
resolve()

Measured memory_bytes: 44124
x, k, d = map(int, input().split())

cur = abs(x)  # 座標を正にしてしまいます
rem = k  # 残りの移動回数です

cnt = min(cur // d, k)  # 0に向かって移動する回数です
cur -= d * cnt
rem -= cnt

# 0 % 2 = 0なので、残り回数の場合分けをする必要はないのですが、一応
if rem > 0:
    if rem % 2 == 1:
        cur = cur - d

ans = abs(cur)  # 絶対値を出力することに気をつけてください
print(ans)

Measured memory_bytes: 61824
#include<bits/stdc++.h>
#include<iomanip>
#include<numeric>

using namespace std;
using ll = long long;
constexpr int mo = 1e9+7;
constexpr int  mod = mo;
constexpr ll inf = 1e15;
ll combi(ll N_, ll C_) {
	const int NUM_=400001;
	static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];
	if (fact[0]==0) {
		inv[1]=fact[0]=factr[0]=1;
		for (int i=2;i<=NUM_;++i) inv[i] = inv[mo % i] * (mo - mo / i) % mo;
		for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%mo, factr[i]=factr[i-1]*inv[i]%mo;
	}
	if(C_<0 || C_>N_) return 0;
	return factr[C_]*fact[N_]%mo*factr[N_-C_]%mo;
}

int main(){
    int n,k;
    cin>>n>>k;
    int red = n - k;
    for(int i=1;i<=k;++i){
        ll ret = 1;
        (ret *= combi(red+1,i))%=mod;
        (ret *= combi(k-1,i-1))%= mod;
        cout << ret%mod << endl;
    }
    return 0;
}



Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef pair<int, int> P;

map<ll, ll> res;

void prime_factor(ll N)
{
    for (ll i = 2; i * i <= N; i++) {
        while(N % i == 0) {
            ++res[i];
            N /= i;
        }
    }
    if (N != 1) res[N]++;
}

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

    ll ans = 1;
    repd(i, 1, N + 1) prime_factor(i);

    for (auto itr = res.begin(); itr != res.end(); itr++) {
        ans *= (itr->second + 1);
        ans %= MOD;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256