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



ll modpower(ll a, ll r, ll mod){ //a^r
    ll x = 1;
    a %= mod;
    while (r > 0) {
        if (r & 1) x = x * a % mod;
        r >>= 1;
        a = a * a % mod;
    }
    return x;
}

ll modinv(ll a, ll mod){
    return modpower(a, mod-2, mod);
}

vector<ll> fact;
vector<ll> invfact;

void set_fact(ll n, ll mod){
    fact.resize(n+1, 1);
    invfact.resize(n+1, 1);
    for (ll i = 2; i <= n; i++) {
        fact[i] = fact[i-1] * i % mod;
    }
    invfact[n] = modinv(fact[n], mod);
    for (ll i = n-1; i >= 2; i--) {
        invfact[i] = invfact[i+1] * (i+1) % mod;
    }
    return;
}

ll comb(ll n, ll k, ll mod) {
    if (k > n || k < 0) return 0;
    if (k == n || k == 0) return 1;
    return fact[n] * invfact[n-k] % mod * invfact[k] % mod;
}


int main() {
    ll N;
    cin >> N;
    ll mod = 998244353;
    ll all = modpower(3, N, mod);
    ll ex = 0;
    set_fact(N+2, mod);
    for (ll i = N/2+1; i <= N; i++) {
        ex += 2LL * comb(N, i, mod) * modpower(2, N-i, mod) % mod;
        ex %= mod;
    }
    cout << (all+mod-ex)%mod << endl;
    return 0;
}

Measured memory_bytes: 156544
let () =
  try
    while true do
      let (a, b, c, d, e, f) = Scanf.scanf "%f %f %f %f %f %f " (fun a b c d e f -> a, b, c, d, e, f) in
      let s = a *. e -. b *. d in
      let x = (e *. c -. b *. f) /. s in
      let y = (a *. f -. d *. c) /. s in
      Printf.printf "%.3f %.3f\n" (x +. 0.) (y +. 0.)
    done
  with _ -> ()

Measured memory_bytes: 2268
#include<iostream>
#include<algorithm>

int main() {

	int q,i,j,k,arg1,arg2;

	std::string str,com,arg3,tmp;
	
	std::cin >> str;

	std::cin >> q;

	for (i=0;i<q;i++) {

		std::cin >> com;

		if (com == "replace") {
			std::cin >> arg1 >> arg2 >> arg3;
			str.replace(arg1, arg2 - arg1+1, arg3);

//			std::cout << "DEBUG:"<<str << std::endl;	// DEBUG
		}
		else if (com == "reverse") {
			std::cin >> arg1 >> arg2;
			tmp	 = str;
			for (j = arg1,k=0; j <= arg2; j++,k++) {
				str[j] = tmp[arg2 - k];
			}
//			std::cout << "DEBUG:" << str << std::endl;	// DEBUG

		}
		else if (com == "print") {
			std::cin >> arg1 >> arg2;
			tmp = str.substr(arg1, arg2 - arg1+1);
			std::cout << tmp << std::endl;
		}
		else {
			std::cout << "error" << std::endl;
		}

	}

	return 0;
}


Measured memory_bytes: 3224
#include<bits/stdc++.h>
using namespace std;
int func( int n ){
    int ans;
    if(n%2==0){
        ans = n/2;
    }else{
        ans = 3*n+1;
    }
    return ans;
}

int main(){
    int s;
    cin >> s;
    int n;
    n = 1000000;
    int a[n];
    bool flag;
    flag = false;
    int ans;
    ans = 0;
    for(int i=1; i<=n; i++){
        if(i==1){
            a[i-1] = s;
        }else{
            a[i-1] = func(a[i-1-1]);
        }
        //cout << a[i-1] << endl;
        for(int j=i-1; j>=1; j--){
            if(i==1) break;
            //cout << "in " << j << a[j-1] << endl;
            if(a[j-1]==a[i-1]){
                ans = i;
                flag = true;
                //cout << "break" << endl;
                break;
            }
        }
        if(flag) break;
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
import java.util.stream.Collectors;

public class Main {

    public static void main(String[] args) {
        Scanner stdin = new Scanner(System.in);
        int k = stdin.nextInt();
        int x = stdin.nextInt();

        Set<Integer> v = new HashSet<>();
        for (int i = 0; i < k; i++) v.add(x + i);
        for (int i = 0; i < k; i++) v.add(x - i);
        String ans = v.stream().sorted().map(i -> i.toString()).collect(Collectors.joining(" "));
        System.out.println(ans);
    }
}


Measured memory_bytes: 29396
#include <bits/stdc++.h> 
using namespace std; 
string s1 , s2 ;
int n1 , n2 , dp[3005][3004];
int main(){
	cin>>s1>>s2;
	n1 = s1.size();
	n2 = s2.size();
	for(int i = 0; i <= n1 ; i++){
		for(int j = 0; j <= n2 ; j++){
			if(i == 0 || j == 0){
				dp[i][j] = 0;
			}else if(s1[i - 1] == s2[j - 1]){
				dp[i][j] = dp[i-1][j-1] + 1 ;
			}else{
				dp[i][j] = max(dp[i-1][j] , dp[i][j-1]);
			}
		}
	}
	int x = n1 , y = n2;
	string ans = "";
	while(x > 0 ||y > 0){
		if(x == 0 )break;
		else if(y==0)break;
		else if(dp[x-1][y] == dp[x][y])x--;
		else if(dp[x][y-1] == dp[x][y])y--;
		else if(dp[x][y] == dp[x-1][y-1] + 1){
			ans += s1[x - 1];
			x--;
			y--;
		}
	}
	reverse(ans.begin(),ans.end());
	cout<<ans;
	return 0;
}  


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

 #define REP(i, a, n) for(int i=a; i<n; i++)

int main() {
	long long a, b, c, k;
	cin >> a >> b >> c >> k;
  	if(k%2==0){
      cout << a-b << endl;
    }else{
      cout << b-a << endl;
    }
}


Measured memory_bytes: 256
// Example program
#include <iostream>
#include <string>
using namespace std;
int main()
{
  int n,a,b;
  cin>>n>>a>>b;
  if(n*a==b)cout<<b<<endl;
  else if(n*a>b)cout<<b<<endl;
  else if(n*a<b)cout<<n*a<<endl;
  return 0;
}


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

const int MOD = 1000000007;

const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

int main()
{
    int N;
    cin >> N;
    if (N < 1 || N > 81) {
        cout << "No" << endl;
        return 0;
    }
    for (int i = 1; i <= 9; i++) {
        int q = N / i;
        int r = N % i;

        if (q >= 1 && q <= 9 && r == 0) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define gep(i,g,j) for(int i = g.head[j]; i != -1; i = g.e[i].next)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("-1"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,vector<T>,greater<T> >
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;



int main() {
  int n, a, b;
  scanf("%d%d%d",&n,&a,&b);
  string s;
  cin >> s;
  a += b;
  rep(i,n) {
    if (s[i] == 'a') {
      puts(a?"Yes":"No");
      if (a) a--;
    } else if (s[i] == 'b') {
      puts((a&&b)?"Yes":"No");
      if (a&&b) a--, b--;
    } else puts("No");
  }
  return 0;
}































Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

int main(){
  string s; cin >> s;
  if(s=="SUN"){cout << 7 << endl;}
  if(s=="MON"){cout << 6 << endl;}
  if(s=="TUE"){cout << 5 << endl;}
  if(s=="WED"){cout << 4 << endl;}
  if(s=="THU"){cout << 3 << endl;}
  if(s=="FRI"){cout << 2 << endl;}
  if(s=="SAT"){cout << 1 << endl;}
  
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	private static final long MOD = 1_000_000_007L;

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			System.out.println(calcFactorialMod(n));
		}
	}

	/**
	 * @param n
	 * @return nの階乗 mod MOD
	 */
	private static long calcFactorialMod(int n) {
		long result = 1L;
		for (int i = 2; i <= n; i++) {
			result = result * i % MOD;
		}
		return result;
	}
}


Measured memory_bytes: 35676
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let mut k: i64 = read();
    let mut a: Vec<usize> = vec![];
    for _ in 0..n {
        let ai = read();
        a.push(ai);
    }

    let mut done: Vec<bool> = vec![false; n + 1];
    let mut cn = 1;
    while !done[cn] {
        done[cn] = true;
        cn = a[cn - 1];
    }
    // println!("{}", cn);

    // root dist
    let mut nn = 1;
    let mut cnt = 0;
    let mut dist = 0;
    let mut dist_s = 0;
    loop {
        nn = a[nn - 1];
        if cnt == 1 {
            dist += 1;
        }
        if cnt == 0 {
            dist_s += 1;
        }
        if nn == cn {
            cnt += 1;
            if cnt > 1 {
                break;
            }
        }
    }
    // println!("dist{}, dist_s: {} nn:{}, cn:{}", dist, dist_s, nn, cn);
    // find roop

    let mut ans = 1;
    if k <= dist_s {
        while k > 0 {
            k -= 1;
            ans = a[ans - 1];
        }
    } else {
        let mut x = (k - dist_s) % dist;
        ans = cn;
        // println!("{}", x);
        while x > 0 {
            x -= 1;
            ans = a[ans - 1];
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 3924
#pragma GCC optimize(2)
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <set>
#include <ctime>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
#define inf 2147483647
#define IosF ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define N 200004

ll x[N], y[N];
int main() {
    IosF;
    int n;
    cin >> n;
    for ( int i = 0; i < n; ++ i ) 
        cin >> x[i] >> y[i];

    ll res = 0, mi = inf, mx = -inf, k;
    for ( int i = 0; i < n; ++ i ) {
        k = x[i] + y[i];
        mi = min(mi, k);
        mx = max(mx, k);
    }
    res = max(res, mx - mi);

    mi = inf, mx = -inf;
    for ( int i = 0; i < n; ++ i ) {
        k = (x[i] - y[i]);
        mi = min(mi, k);
        mx = max(mx, k);
    }
    res = max(res, mx - mi);
    cout << res << endl;

    // system("pause");
    return 0;
}

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

int main()
{
	long long int n, x, y, z, tk;
	cin>>n;
	x = n/500;
	tk = x*1000;
	y = n%500;
	z = y/5;
	tk = tk+z*5;
	
	cout<<tk<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
    using namespace std;
    int main(){
    	long long a=1;
    	long long n,i;
    	std::cin>>n;
    	for(i=1;i<=n;i++){
    		a=(a*i)%1000000007;
    	}
    	std::cout<<a;
    	return 0;
    }

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int q,w,e;
    while(~scanf("%d %d %d",&q,&w,&e))
    {
        if(e>=q&&e<=w)
        {
            printf("Yes\n");
        }
        else
            printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<utility>
#include<string>
#include<algorithm>
using namespace std;
typedef pair<string, int> P;
typedef pair<P, int> PP;

bool comp(const PP& l, const PP& r) {
    if (l.first.first != r.first.first) return l.first.first > r.first.first;
    else return l.first.second < r.first.second;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<PP> V(N);
    for (int i = 0; i < N; i++) {
        cin >> V[i].first.first >> V[i].first.second;
        V[i].second = i;
    }
    sort(V.begin(), V.end(), comp);
    reverse(V.begin(), V.end());
    for (int i = 0; i < N; i++) {
        cout << V[i].second + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

// 提出時にclass Main に書き換え
public class Main {
	public static void main(String[] args)  {
		// 標準入力を受け取る
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(); // int Nを受け取る

		long sum = 0; // 踏み台の高さの合計
		long mhigh = 0; // A[i]より前での、身長の最高値

		for(int i = 0; i < N; i++) {
			long A = sc.nextLong(); // long Aを受け取る
			if(A > mhigh) {
				mhigh = A; // 身長の最高値更新
			} else if(A < mhigh) sum += mhigh - A; // 踏み台の高さ加算
		}

		System.out.println(sum);
	}

}

Measured memory_bytes: 58892
#include <iostream>
#include <algorithm>

using namespace std;

int main(int argc, char *argv[])
{
	int N;
	int p[55], q[55];

	cin >> N;

	for (int i = 0; i < N; i++) {
		cin >> p[i];
		q[i] = p[i];
	}
	sort(p, p + N);

	int c = 0;
	for (int i = 0; i < N; i++) {
		if (p[i] != q[i]) {
			c++;
		}
	}
	if (c < 3) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int h,i,j;
  char b[8][9],c[8][9],s[9];
  memset(b,0,sizeof(b));
  memset(c,0,sizeof(c));
  for(i=0;i<8;i++){
    cin>>s;
    for(j=0;j<8;j++)
      b[j][i]=s[j];
  }
  for(h=1;h<4;h++){  
    for(i=0;i<8;i++)
      for(j=0;j<8;j++)
	c[j][i]=b[i][7-j];    
    memcpy(b,c,sizeof(c));
    cout<<h*90<<endl;
    for(i=0;i<8;i++){
      for(j=0;j<8;j++)
	cout<<b[j][i];
      cout<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#include<string.h>
#define M 1000003 
#define L 14
char H[M][L];
int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2; 
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
} /* convert a string into an integer value */ 
int getKey(char str[]){ 
  int sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
} 
int h1(int key){ 
  return key%M; 
} 
int h2(int key){ 
  return 1+key%(M-1); 
} 
int find(char str[]){
  int i=0,k,n=0,sum;
  sum=getKey(str);
  while(i<M){
    k=(h1(sum)+i*h2(sum))%M;
    if(H[k][0]=='\0'){
      break;
    }
    if(strcmp(H[k],str)==0){
      n=1;
      break;
    }
    i++;
  }
  return n;
} 
int insert(char str[]){
  int sum,i=0,k; 
  sum=getKey(str);
  while(i<M){
    k=(h1(sum)+i*h2(sum))%M;
    if(H[k][0]=='\0'){
      strcpy(H[k],str);
      break;
    }
    i++;
  }
  
}
int main(){
  int i, n, h,k=0; 
  char str[L], com[9], sc[500000][4];
  for ( i = 0; i < M; i++ ) H[i][0] = '\0';
  scanf("%d", &n);
  for ( i = 0; i < n; i++ ){ 
    scanf("%s %s", com, str);
    if ( com[0] == 'i' ){ 
      insert(str); 
    }
    else {
      if (find(str)){ 
	strcpy(sc[k],"yes");
        k++;
      }
      else {
	strcpy(sc[k],"no");
	k++;
      }
    }
  }
  for(i=0;i<k;i++){
    printf("%s\n",sc[i]);
  }
  return 0;
}

Measured memory_bytes: 15964
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1e9+100;
const ll INF64 = 7e18l;
const int mod = 1000000007;
#define rep(i,a,b) for(int i(a);i<(b);i++)
#define ALL(a) (a).begin(), (a).end()
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


int main(){
    FIN;

    ll N,W,weight,value;
    cin >> N >> W;
    ll M = N*1000 + 1;
    vector<ll> dp(M,INF);  //dp[i] = min weight with value's sum i

    dp[0] = 0;
    rep(i,0,N){
        cin >> weight >> value;
        for(ll from = M-value;from>=0;from--){
            dp[from+value] = min(dp[from+value],dp[from]+weight);
        }
    }

    ll ans = 0;
    for(ll i=0;i<M;i++){
        if(dp[i] <= W) ans = max(ans,i);
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ut i=(a);i<(ut)(b);i++)
#define REP(i,b) FOR(i,0,b)
#define ALL(c) c.begin(),c.end()
#define PB push_back
#define cat //cout << __LINE__ << endl;
using namespace std;
typedef long long LL;
typedef double ld;
typedef int ut;
typedef vector<ut> VI;
typedef pair<int,int> pr;
const int SIZE=5+3*1e5;
const int INF=10+1e9;
const LL p =7+1e9;
LL A[SIZE];
bool solve(){

	LL N;
	cin >> N;
	LL sum=0;
	REP(i,N){
		cin >> A[i];
		sum+=A[i];
	}
	if(sum%(N*(N+1)/2)){
		return false;
	}
	LL times=sum/(N*(N+1)/2);
	REP(i,N){
		LL tar=A[(i+1)%N]-A[i];
		if((times-tar)<0 or (times-tar)%N){
			return false;
		}
	}
	return true;
}
int main(){
	if(solve()) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 1024
import math


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


def resolve():
    N, K = map(int, input().split())
    const = 1e9 + 7
    for i in range(1, K + 1):
        if (N - K + 1 >= i):
            print(
                combinations_count(N - K + 1, i) *
                combinations_count(K - 1, i - 1) % 1000000007)
        else:
            print(0)
            
resolve()

Measured memory_bytes: 3316
#include<cstdio>
#include<algorithm>
#include<vector>
#define N_ 201000
using namespace std;
int A[N_], B[N_], DegA[N_], DegB[N_], Q[N_], head, tail, vis[N_], CA, CB;
int n, Num[N_][2];
vector<int>GA[N_], GB[N_];

#define N_ 300100
#define M_ 2001000
struct MaxFlow {
	vector<int>G[N_];
	struct Edge {
		int b, e, f;
	}E[M_];
	int EC, flow, PV[N_], Q[N_], Level[N_], n, source, sink, INF = 1e9;
	void init(int N, int S, int T) {
		source = S, sink = T, flow = EC = 0;
		n = N;
		for (int i = 0; i <= n; i++)G[i].clear();
	}
	void Add_Edge(int a, int b, int f) {
		G[a].push_back(EC);
		G[b].push_back(EC + 1);
		E[EC++] = { a,b,f };
		E[EC++] = { b,a,0 };
	}
	int BlockFlow(int a, int f) {
		if (a == sink)return f;
		for (int &i = PV[a]; i >= 0; i--) {
			int t = G[a][i];
			if (E[t].f && Level[E[t].e] == Level[a] + 1) {
				int ff = BlockFlow(E[t].e, min(E[t].f, f));
				if (ff) {
					E[t].f -= ff;
					E[t ^ 1].f += ff;
					return ff;
				}
			}
		}
		return 0;
	}
	bool GetLevel() {
		int head = 0, tail = 0, i;
		for (i = 1; i <= n; i++)Level[i] = -1;
		Q[++tail] = source; Level[source] = 0;
		while (head < tail) {
			int x = Q[++head];
			for (auto &t : G[x]) {
				if (E[t].f && Level[E[t].e] == -1) {
					Level[E[t].e] = Level[x] + 1;
					Q[++tail] = E[t].e;
				}
			}
		}
		return Level[sink] != -1;
	}
	void Dinic() {
		int i, t;
		flow = 0;
		while (GetLevel()) {
			for (i = 1; i <= n; i++)PV[i] = G[i].size() - 1;
			while (t = BlockFlow(source, INF)) {
				flow += t;
			}
		}
	}
}G1;

int main() {
	int i;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &A[i]);
		DegA[A[i]]++;
	}
	for (i = 0; i < n; i++) {
		scanf("%d", &B[i]);
		DegB[B[i]]++;
	}

	for (i = 0; i < n; i++) {
		if (!DegA[i])Q[++tail] = i;
	}
	while (head < tail) {
		int x = Q[++head];
		DegA[A[x]]--;
		if (!DegA[A[x]])Q[++tail] = A[x];
	}
	for (i = 0; i < n; i++) {
		if (DegA[i] && !vis[i]) {
			int x = i;
			vector<int>T;
			while (!vis[x]) {
				vis[x] = 1;
				T.push_back(x);
				x = A[x];
			}
			if (T.size() == 1)continue;
			GA[++CA] = T;
			for (auto &t : T)Num[t][0] = CA;
		}
	}
	for (i = 0; i < n; i++)vis[i] = 0;

	head = tail = 0;

	for (i = 0; i < n; i++) {
		if (!DegB[i])Q[++tail] = i;
	}
	while (head < tail) {
		int x = Q[++head];
		DegB[B[x]]--;
		if (!DegB[B[x]])Q[++tail] = B[x];
	}
	for (i = 0; i < n; i++) {
		if (DegB[i] && !vis[i]) {
			int x = i;
			vector<int>T;
			while (!vis[x]) {
				vis[x] = 1;
				T.push_back(x);
				x = B[x];
			}
			if (T.size() == 1)continue;
			GB[++CB] = T;
			for (auto &t : T)Num[t][1] = CB;
		}
	}

	long long res = 0;
	G1.init(CA + CB + 2, CA + CB + 1, CA + CB + 2);
	for(i=1;i<=CA;i++){
		G1.Add_Edge(G1.source, i, (int)GA[i].size());
		res += GA[i].size();
	}
	for (i = 1; i <= CB; i++) {
		G1.Add_Edge(CA + i, G1.sink, (int)GB[i].size());
		res += GB[i].size();
	}
	for (i = 0; i < n; i++) {
		if (Num[i][0] && Num[i][1]) {
			G1.Add_Edge(Num[i][0], CA + Num[i][1], 1);
			if (A[i] == B[i]) {
				G1.Add_Edge(Num[i][0], CA + Num[i][1], 1);
			}
		}
	}
	G1.Dinic();
	printf("%lld\n", res - G1.flow);
}

Measured memory_bytes: 41596
/*     ####   ####  #               ####  #        ##   #    # #    # ###### #####
      #      #    # #              #      #       #  #  ##  ## ##  ## #      #    #
       ####  #    # #               ####  #      #    # # ## # # ## # #####  #    #
           # #  # # #                   # #      ###### #    # #    # #      #####
      #    # #   #  #              #    # #      #    # #    # #    # #      #   #
       ####   ### # ###### #######  ####  ###### #    # #    # #    # ###### #    #
*/
 
#include<bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef vector<long long> VLL;
typedef vector<string> VS;
typedef vector<pair<LL, LL> > VP;
 
 
#define For(in) for (LLi i = 0; i < (n); i++)
#define FOR(in) for(LLi i=1; i <= (n); i++)
#define pb push_back
#define sr(v) sort(v.begin(), v.end())
#define rev(v) reverse(v.begin(), v.end())
#define uniq(v) v.erase(unique(v.begin(), v.end()), v.end());
#define exit(); return 0;
#define no "NO"
#define yes "YES"
#define con continue;
 

 
 
int main()
{
	
	long long a,b,c,d;
	cin>>a>>b;
	if(a==b)cout<<"Draw"<<endl;
	else if(a==1)cout<<"Alice"<<endl;
	else if(b==1)cout<<"Bob"<<endl;
	else if(a>b)cout<<"Alice"<<endl;
	else cout<<"Bob"<<endl;
	
	
	
    exit()
    
    
    
 
 
}


Measured memory_bytes: 3616
def resolve():
    A, V = map(int, input().split())
    B, W = map(int, input().split())
    T = int(input())

    diff_d = abs(A - B)
    dif_move = (V - W) * T

    if diff_d <= dif_move:
        print("YES")
    else:
        print("NO")

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 9076
#include <iostream>
using namespace std;
int main(void){
    int a,b,c;
    cin>>a>>b>>c;
    int a1=a+b;
    int a2=b+c;
    int a3=c+a;
    int ans=min(min(a1,a2), a3);
    cout<<ans<<endl;
}


Measured memory_bytes: 504
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace AtCoder
{
	public class ABC
	{
		static public void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
			Solve(args);
			Console.Out.Flush();
		}

		private const int mod = 1000000007;  // 10^9+7

		static public void Solve(string[] args)
		{
			//string s = Console.ReadLine();
			//int x = int.Parse(Console.ReadLine());
			//long x = long.Parse(Console.ReadLine());
			int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();
			int n = vs[0];
			int m = vs[1];
			int q = vs[2];

			int[][] list = new int[q][];
			for (int i = 0; i < q; i++) {
				list[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();
			}
			int ans = saiki(m, new int[n], 0, list);
			Console.WriteLine(ans);
		}

		static int saiki(int m, int[] A, int i, int[][] Q)
		{
			int ans = 0;
			if (A.Length == i) {
				foreach (var q in Q) {
					int a = q[0] - 1;
					int b = q[1] - 1;
					int c = q[2];
					int d = q[3];
					if (A[b] - A[a] == c) {
						ans += d;
					}
				}
				System.Diagnostics.Debug.WriteLine($"{string.Join(' ', A)} : {ans}");
			} else {
				for (int j = (i == 0 ? 1 : A[i - 1]); j <= m; j++) {
					A[i] = j;
					ans = Math.Max(ans, saiki(m, A, i + 1, Q));
				}
			}
			return ans;
		}

	}
}


Measured memory_bytes: 28260
#include "bits/stdc++.h"
using namespace std;
int main() {
	int N, sum = 0;
	cin >> N;
	vector<int> d(N);
	for (int i = 0; i < N; i++) {
		cin >> d[i];
	}
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N ; j++) {
			sum = sum + d[i] * d[j];
		}
	}
	cout << sum;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N, A, B; cin >> N >> A >> B;
	
	int res = min(N * A, B);

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector<string> s;
vector<vector<bool> > done;
int w,h;
int dy[] = {-1,1,0,0};
int dx[] = {0,0,-1,1};
int ans = 0;

void dfs(int y, int x)
{
		ans++;
        done[y][x] = true;
        for(int i=0;i<4;i++)
        {
                int ny = y + dy[i];
                int nx = x + dx[i];
                if(0<=ny && ny<h && 0<=nx && nx<w && s[ny][nx]=='.' && !done[ny][nx])
                {
                        dfs(ny,nx);
                }
        }
}
 
signed
main()
{
    while(cin >> w >> h and !(w==0 & h==0))
    {
            s = vector<string>(h);
            done = vector<vector<bool> >(h,vector<bool>(w, false));

			int sy,sx;
            for(int y=0;y<h;y++)
			{
					cin >> s[y];
					for(int x=0;x<w;x++)
					{
						if(s[y][x]=='@')
						{
								sy = y;
								sx = x;
						}
					}
			}
 			dfs(sy,sx);
            cout << ans << endl;
			ans = 0;
    }
}


Measured memory_bytes: 3068
n, m = map(int, input().split())
ks = [list(map(int, input().split())) for i in range(m)]
p = list(map(int, input().split()))

ans = 0

for i in range(2**n):
  light_on = 0
  for j in range(m):
    switch_on = 0
    for k in ks[j][1:]:
      if (i >> k-1) & 1:
        switch_on += 1
    if switch_on % 2 == p[j]:
      light_on += 1
  if light_on == m:
    ans += 1

print(ans)

Measured memory_bytes: 40944
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

void integerFactorization(int n, vector<int>& base, vector<int>& expo)
{
    base.clear();
    expo.clear();
    int a = 2;
    while(a * a <= n){
        int b = 0;
        while(n % a == 0){
            ++ b;
            n /= a;
        }
        if(b > 0){
            base.push_back(a);
            expo.push_back(b);
        }
        ++ a;
    }
    if(n > 1 || base.size() == 0){
        base.push_back(n);
        expo.push_back(1);
    }
}

long long toInt(string s, int n)
{
    long long ret = 0;
    for(unsigned i=0; i<s.size(); ++i){
        ret *= n;
        if(isdigit(s[i]))
            ret += s[i] - '0';
        else
            ret += s[i] - 'A' + 10;
    }
    return ret;
}

int main()
{
    for(;;){
        int n;
        string s;
        cin >> n >> s;
        if(n == 0)
            return 0;

        vector<int> base, expo;
        integerFactorization(n, base, expo);

        long long m = toInt(s, n);

        long long ret = LLONG_MAX;
        for(unsigned i=0; i<base.size(); ++i){
            long long m2 = m;
            long long tmp = 0;
            while(m2 > 0){
                tmp += m2 / base[i];
                m2 /= base[i];
            }
            ret = min(ret, tmp / expo[i]);
        }

        cout << ret << endl;
    }
}

Measured memory_bytes: 1228
////*24-AUG-19*///
//Why do we fall?//
// So we can learn to pick ourself up!//
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define endl "\n"
#define F first
#define S second
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define fr(a,b,c) for(int a=b; a<c; a++)
#define frr(a,b,c) for(int a=b;a>=c;a--)
#define pb push_back
#define pii pair<int,int>
#define R(a) ll a; cin >> a;
#define RA(a, n) ll a[(n) + 1] = {}; fr(i, 1, (n)+1) {cin >> a[i];}
#define RM(a, n, m) int a[n + 1][m + 1] = {}; fr(i, 1, n) {fr(j, 1, m) cin >> a[i][j];}
#define reset(X) memset(X, 0, sizeof(X))
const int inf = 1e18;
const int mod=1e9+7;
unsigned int power(int x, unsigned int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
bool isPrime(int n)
{   if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
    return true;
    }

    //z function -  z[i] is the length of the longest common prefix between s and the suffix of s starting at i
vector<int>z_function(string s) {
    int n = (int) s.length();
    vector<int> z(n);
    for (int i = 1, l = 0, r = 0; i < n; ++i) {
        if (i <= r)
            z[i] = min (r - i + 1, z[i - l]);
        while (i + z[i] < n && s[z[i]] == s[i + z[i]])
            ++z[i];
        if (i + z[i] - 1 > r)
            l = i, r = i + z[i] - 1;
    }
    return z;
}
int countPalindrome(string str)
{
	int i,j,k,count=0;
	for(i=0;str[i];i++)
	{
		k=i-1;j=i+1;  //count odd length palindromes
		while(k>=0 && str[j] && str[k]==str[j])
		{
			++count;
			k--;j++;
		}

		k=i;j=i+1; //count even length palindrome
		while(k>=0 && str[j] && str[k]==str[j])
		{
			++count;
			k--;j++;
		}
	}
	return count;
}
signed main()
{
    fastio;
    cout<<setprecision(20);
    string s;
    cin>>s;
    int k;
    cin>>k;
    int cnt=1;
    int ans=0;
    int n=s.size();
    fr(i,1,n)
    {
        if(s[i]==s[i-1])
        {
            cnt+=1;
        }
        else
        {
            ans+=cnt/2;
            cnt=1;
        }
    }
    if(cnt==n)
    {
        cout<<k*s.size()/2<<endl;
    }
    else
    {
        if(s[0]!=s[n-1])
        {
            cout<<k*(ans+cnt/2)<<endl;
        }
        else
        {
            int a=0,b=0;
            fr(i,0,s.size())
            {
                if(s[i]==s[n-1])
                {
                    a+=1;
                }
                else
                    break;
            }
            frr(i,s.size()-1,0)
            {
                if(s[i]==s[n-1])
                {
                    b+=1;
                }
                else
                {
                    break;
                }
            }
            //cout<<a<<" "<<b<<endl;
            cout<<k*(ans+cnt/2)-(k-1)*(a/2+b/2-(a+b)/2)<<endl;
        }
    }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<int, int> pi;
const int MAXN = 105;

struct edg{
	int s, e;
	double x;
	bool operator<(const edg &e)const{
		return x < e.x;
	}
};

struct disj{
	int pa[20];
	void init(int n){
		iota(pa, pa + n, 0);
	}
	int find(int x){
		return pa[x] = (pa[x] == x ? x : find(pa[x]));
	}
	bool uni(int p, int q){
		p = find(p);
		q = find(q);
		if(p == q) return 0;
		pa[q] = p; return 1;
	}
}disj;

double getmst(vector<edg> &v){
	sort(v.begin(), v.end());
	disj.init(16);
	double ans = 0;
	for(auto &i : v) if(disj.uni(i.s, i.e)) ans += i.x;
	return ans;
}

int n, x[15], y[15], z[15];
double ans[50000];

int main(){
	cin >> n;
	for(int i=0; i<n; i++) cin >> x[i] >> y[i] >> z[i];
	for(int i=1; i<(1<<n); i++){
		vector<edg> v;
		double sum = 0;
		int cnt = 0;
		for(int j=0; j<n; j++){
			if((i >> j) & 1) sum += z[j], cnt++;
		}
		for(int j=0; j<n; j++){
			for(int k=0; k<j; k++){
				if((i >> j) % 2 == 1 && (i >> k) % 2 == 1){
					double dx = hypot(x[j] - x[k], y[j] - y[k]);
					v.push_back({j, k, dx});
				}
			}
		}
		ans[i] = (sum - getmst(v)) / cnt;
	}
	for(int i=1; i<(1<<n); i++){
		for(int j=i; j>0; j = (j - 1) & i){
			int x = j, y = i ^ j;
			if(x && y) ans[i] = max(ans[i], min(ans[x], ans[y]));
		}
	}
	printf("%.10f\n", ans[(1<<n) - 1]);
}


Measured memory_bytes: 512
#include<iostream>
#include <algorithm>
#include <string>
#include<vector>
#include<tuple>

//AtCoderC++.cpp

using namespace std;

template<typename T> void Show(const vector<vector<T>>& v, string delimiter = " ") {
	for (int i = 0; i < v.size(); i++) {
		for (int j = 0; j < v[i].size(); j++) {
			cout << v[i][j];
			if (j != v[i].size() - 1) {
				cout << delimiter;
			} else {
				cout << endl;
			}
		}
	}
}
template<typename T> void Show(const vector<T>& v, string delimiter = " ") {
	for (int i = 0; i < v.size(); i++) {
		cout << v[i];
		if (i != v.size() - 1) {
			cout << delimiter;
		} else {
			cout << endl;
		}
	}
}
template<typename T> vector<T> getUniform(T value, int n) {
	vector<vector<T>> ts;
	ts.resize(n);
	for (int i = 0; i < n; i++) {
		ts[i] = value;
	}
	return ts;
}
template<typename T> vector<vector<T>> getUniform(T value, int row, int col) {
	vector<vector<T>> ts;
	ts.resize(row);
	for (int i = 0; i < row; i++) {
		ts[i].resize(col);
		for (int j = 0; j < col; j++) {
			ts[i][j] = value;
		}
	}
	return ts;
}
bool All(vector<vector<bool>> ts) {
	int h = ts.size();
	int w = ts[0].size();
	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++)
			if (!ts[i][j])return false;
	return true;
}

vector<string> split(string& content, char delim) {
	auto ss = vector<string>();
	string s = "";
	for (size_t i = 0; i < content.length(); i++) {
		if (content[i] == delim) {
			ss.push_back(s);
			s = "";
			continue;
		}
		s += content[i];
	}
	if (s != "")ss.push_back(s);
	return ss;
}

int main() {
	string S; cin >> S;
	int length = S.length();
	int dis_a = 0;
	for (size_t i = 0; i < length; i++) {
		if (i % 2 == 0 && S[i] != '0')dis_a++;
		else if (i % 2 != 0 && S[i] != '1')  dis_a++;
	}
	int dis_b = 0;
	for (size_t i = 0; i < length; i++) {
		if (i % 2 == 0 && S[i] != '1')dis_b++;
		else if (i % 2 != 0 && S[i] != '0')  dis_b++;
	}
	cout << min(dis_a, dis_b) << endl;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << x << endl;
#define printv(x) for(int i = 0; i < x.size(); i++){ cout << (x[i]) << " "; } cout << endl; 
#define printa(x) for(int i = 0; i < (sizeof(x)/sizeof(x[0])); i++){ cout << (x[i]) << " ";} cout << endl;

typedef long long ll;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    int ans = N;
    rep(i,0,N+1){
        int six = i;
        int tmp = 0;
        while(six > 0){
            tmp += six % 6;
            six = (six - (six%6)) / 6;
        }
        int nine = N - i;
        while(nine > 0){
            tmp += nine % 9;
            nine = (nine - (nine%9)) / 9;
        }
        ans = min(ans,tmp);
    }

    print(ans);
    return 0; 
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

type pay struct {
	io *IO
}

func (p *pay) yes() {
	p.io.Print("Yes")
}

func (p *pay) no() {
	p.io.Print("No")
}

func main() {
	io := NewStdIO()
	defer io.Flush()
	p := pay{
		io: io,
	}

	N := Stoi(p.io.Next())
	A := Stoi(p.io.Next())

	if N%500 <= A {
		p.yes()
	} else {
		p.no()
	}
}

// Stoi converts string to integer
func Stoi(s string) int {
	i, err := strconv.Atoi(s)
	if err != nil {
		fmt.Println(i)
		fmt.Println(err)
	}
	return i
}

// NewStdIO return standard IO instance.
func NewStdIO() *IO {
	return &IO{
		In:  bufio.NewReader(os.Stdin),
		Out: bufio.NewWriter(os.Stdout),
	}
}

// IO supports IO processing.
type IO struct {
	In  *bufio.Reader
	Out *bufio.Writer
}

// Flush outputs buffed data.
func (io *IO) Flush() {
	if err := io.Out.Flush(); err != nil {
		panic(err)
	}
}

// Printf writes string to buffer.
func (io *IO) Printf(format string, a ...interface{}) {
	if _, err := fmt.Fprintf(io.Out, format, a...); err != nil {
		panic(err)
	}
}

// Println writes string to bulnlner.
func (io *IO) Print(s string) {
	if _, err := fmt.Fprint(io.Out, s); err != nil {
		panic(err)
	}
}

// Next reads line and return string.
func (io *IO) Next() string {
	var b []byte
	for {
		l, pre, err := io.In.ReadLine()
		if err != nil {
			panic(err)
		}
		b = append(b, l...)
		if !pre {
			break
		}
	}
	return string(b)
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define tc int t; cin>>t; while(t--)
#define mod 1000000007
 
using namespace std;
 
void fastio(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    // cout.tie(NULL);
    cout<<fixed;
    cout.precision(10);
    
}
 
int sieve(int n) 
{ 
    bool prime[10*n]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=10*n; p++) 
    { 
        if (prime[p] == true) 
        {  
            for (int i=p*p; i<=n*10; i += p) 
                prime[i] = false; 
        } 
    } 
  
    for (int p=n; ; p++) 
       if (prime[p]) 
          return p; 

} 

int main(){
    fastio();
    int n;
    cin>>n;
    int x = sieve(n);
    cout<<x;
    return 0;
}

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

typedef long long ll;
ll n, m, s[55];
ll f(ll p, ll q) {
	ll md;
	if (p == -1 || q <= 0) return 0;
	md = s[p + 1] - 1;
	if (q < md) return f(p - 1, q - 1);
	else return f(p - 1, q - md) + s[p];
}
int main()
{
	ll i;
	cin >> n >>m;
	s[0] = 1;
	for (i = 1; i <= 51; i++) s[i] = s[i - 1] * 2;
	cout << f(n, m);
    return 0;
}


Measured memory_bytes: 256
import Control.Applicative

countOcc :: Int -> [Int] -> Int
countOcc _ [] = 0
countOcc n (x:xs) | n == x = 1 + (countOcc n xs)
                  | otherwise = countOcc n xs

myShow :: Int -> Int -> IO ()
myShow count5 count7 | count5 == 2 && count7 == 1 = putStrLn "YES"
                     | otherwise = putStrLn "NO"

main :: IO ()
main = do
    lst <- map read . words <$> getLine
    let count5 = countOcc 5 lst
        count7 = countOcc 7 lst
    myShow count5 count7


Measured memory_bytes: 508
def sieve(n):
    is_prime = [True for _ in range(n)]
    is_prime[0] = False

    for i in range(2, n+1):
        if is_prime[i-1]:
            j = 2 * i
            while j <= n:
                is_prime[j-1] = False
                j += i
    return is_prime
x=int(input())
ans=sieve(2*10**5)
for i in range(x,2*10**5):
    if ans[i-1]:
        print(i)
        exit()


Measured memory_bytes: 4632
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		string s = Console.ReadLine();
		int n = s.Length;
		long answer = 0;
		long sumB = 0;

		for(int i = 0; i < n; i++)
		{
			if(s[i] == 'B') sumB++;
			else answer += sumB;
		}

		Console.WriteLine(answer);
	}
}

Measured memory_bytes: 13240
//Misterious Gems
#include <iostream>

using namespace std;

enum Direction{
	N = 1,//y+
	E = 2,//x+
	S = 3,//y-
	W = 4///x-
};

struct Order{
	Direction dir;
	int length;
};

int main(){
	int MaxN;//宝石最大数
	bool GemField[21][21];//宝石の有無保持用フィールド[y][x]
	bool RobotField[21][21];//ロボット通過情報保持用フィールド[y][x]
	int MaxM;//命令数
	Order Ord[30];//命令
	int RobotX, RobotY;//ロボット位置
	bool Gettable;//収集可能性

	int i, j, k, l;//使用する一時変数
	char c;//使用する一時変数

	while (1){
		//フィールド初期化
		for (i = 0; i < 21; ++i){
			for (j = 0; j < 21; ++j){
				GemField[i][j] = false;
				RobotField[i][j] = false;
			}
		}
		RobotField[10][10] = true;
		RobotX = 10; RobotY = 10;
		Gettable = true;
		//代入
		cin >> MaxN;
		if (MaxN == 0)break;
		for (i = 0, j = 0, k = 0; i < MaxN; ++i){
			cin >> j >> k;
			GemField[k][j] = true;
		}
		cin >> MaxM;
		for (i = 0, c = 0; i < MaxM; ++i){
			cin >> c >> Ord[i].length;
			switch(int(c)){
			case 'N':
				Ord[i].dir = N;
				break;
			case 'E':
				Ord[i].dir = E;
				break;
			case 'W':
				Ord[i].dir = W;
				break;
			case 'S':
				Ord[i].dir = S;
				break;
			}
		}

		//命令実行&RobotFieldに反映
		for (i = 0, k = 0, l = 0; i < MaxM; ++i){
			//方向決定
			k = (Ord[i].dir % 2 == 0) ? 1 : 0;//偶数ならX
			l = (Ord[i].dir % 2 == 0) ? 0 : 1;//奇数ならY
			if (Ord[i].dir >= 3){
				k *= -1; l *= -1;
			}
			//移動
			for (int j = 0; j < Ord[i].length; ++j){
				RobotX += k; RobotY += l;
				RobotField[RobotY][RobotX] = true;
			}
		}

		//全収集チェック
		for (i = 0; i < 21 && Gettable ; ++i){
			for (j = 0; j < 21 && Gettable; ++j){
				if (GemField[j][i] && !RobotField[j][i])Gettable = false;
			}
		}

		//出力
		cout << (Gettable ? "Yes" : "No") << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <random>
#include <ctime>
#include <bitset>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstring>
#include <queue>
#include <deque>
#include <list>
#include <stack>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define ld long double
#define ull unsigned long long
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(x) x.begin(), x.end()
#define fast_io cout.tie(0), cin.tie(0), ios_base::sync_with_stdio(0)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
using namespace std;
ld eps = (ld)1 / 1e15;
ll inf = 1e18, mod2 = 998244353, mod1 = 1e9 + 7;
ll sqr(ll a) { return a * a; }
ll qb(ll a) { return a * a * a; }
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main()
{
    //freopen("race.in", "r", stdin), freopen("race.out", "w", stdout);
    fast_io;
    ll n, k, s = 0;
    cin >> n >> k;
    while (n > 0)
    {
        n /= k;
        s++;
    }
    cout << s;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

/**
 * LCS
 */
public class Main {

    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            char[] S = sc.next().toCharArray();
            char[] T = sc.next().toCharArray();

            int[][] dp = new int[S.length + 1][T.length + 1];

            for (int i = 1; i <= S.length; i++) {
                for (int j = 1; j <= T.length; j++) {
                    if (S[i - 1] == T[j - 1]) {
                        dp[i][j] = dp[i - 1][j - 1] + 1;
                    } else {
                        dp[i][j] = Math.max(dp[i][j - 1], dp[i - 1][j]);
                    }
                }
            }

            StringBuilder sb = new StringBuilder();

            for (int len = dp[S.length][T.length] - 1, i = S.length, j = T.length; len >= 0; len--) {
                while (dp[i][j] > len) {
                    i--;
                }

                while (dp[i + 1][j] > len) {
                    j--;
                }

                sb.append(S[i]);
            }

            String lcs = sb.reverse().toString();

            System.out.println(lcs);
        }
    }

}


Measured memory_bytes: 80716
#include<iostream>
#include<vector>
using namespace std;
int main () {
  int N, W;
  cin >> N >> W;
  int sum = 0;
  vector<int>wei(N);
  vector<int>val(N);
  for (int i = 0; i < N; i ++) {
    cin >> wei[i] >> val[i];
    sum += val[i];
  }
  vector<vector<int>>dp(N + 1, vector<int>(sum + 1, 1e9));
  dp[0][0] = 0;
  //dp[i][j] = i番目まで処理、価値jとなる重さの最小値
  vector<bool>exi(sum + 1, false);
  //i番目まで処理、価値jのバッグはある？
  exi[0] = true;
  for (int i = 1; i <= N; i ++) {
    int w, v;
    w = wei[i - 1];
    v = val[i - 1];
    for (int j = 0; j <= sum; j ++) dp[i][j] = dp[i - 1][j];
    for (int j = 0; j <= sum - v; j ++) {
      if (exi[j]) {
        int k = dp[i - 1][j] + w;
        if (k < dp[i][j + v]) dp[i][j + v] = k;
        exi[j + v] = true;
      }
    }
  }
  int ans = 0;
  /*for (int i = 0; i <= N; i ++) {
    for (int j = 0; j <= sum; j ++) {
      cout << dp[i][j] << ' ';
    }
    cout << endl;
  }*/
  for (int i = 0; i <= sum; i ++) {
    if (exi[i] && dp[N][i] <= W) ans = i;
  }
  cout << ans << endl;
}



Measured memory_bytes: 40192
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

vector<int> path[100010];
bool visited[100010];
int d[100010];

int dfs(int v) {
    if (visited[v]) return d[v];

    visited[v] = true;

    d[v] = 0;
    for (int sv : path[v]) {
        d[v] = max(d[v], dfs(sv) + 1);
    }

    return d[v];
}

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

    for (int i = 0; i < M; ++i) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        path[u].push_back(v);
    }

    for (int v = 0; v < N; ++v) {
        if (visited[v]) continue;
        dfs(v);
    }

    cout << *max_element(d, d + N) << endl;
    return 0;
}


Measured memory_bytes: 7552
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	k := readI()
	ans := 0
	for a := 1; a <= k; a++ {
		for b := 1; b <= k; b++ {
			for c := 1; c <= k; c++ {
				ans += gcdTriple(a, b, c)
			}
		}
	}

	fmt.Println(ans)
}

// gcd は最大公約数を返します。
func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func gcdTriple(a, b, c int) int {
	d := gcd(a, b)
	return gcd(c, d)
}

/*-----------Utils-----------*/

var sc = bufio.NewScanner(os.Stdin)

func init() {
	if len(os.Args) >= 2 {
		if os.Args[1] == "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.Fprintln(os.Stderr, "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
}


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

int main() {
  string a;
  cin >> a;
  
  if(a.at(0) == a.at(1) && a.at(1) == a.at(2)) {
    cout << "Yes" << endl;
  }
  else if(a.at(1) == a.at(2) && a.at(2) == a.at(3)){
    cout << "Yes" << endl;
  }
    
  else{
    cout << "No" << endl;
  } 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e15;
// __uint128_t

int main(){
    string S;
    cin >> S;
    ll N = S.size();
    map<char, ll> M;
    ll ans = (N*(N-1))/2;
    for(auto c : S) M[c]++;
    for(auto m : M){
        ll n = m.second;
        ans -= (n*(n-1))/2;
    }
    cout << ans+1 << endl;

}

Measured memory_bytes: 640