akhauriyash/Code-Regression huggingface dataset:
using System;

class Program
{
    static void Main()
    {
        while (true)
        {        
            string[] ss = Console.ReadLine().Split(' ');
            int h = int.Parse(ss[0]);
            int w = int.Parse(ss[1]);

            // "0 0" 終了
            if (h == 0 && w == 0) break;

            char[,] t = new char[h, w];
            int x = 0; // w
            int y = 0; // h
            
            string s = "";

            // タイルの状態を保持
            for (int i = 0; i < h; i++)
            {
                s = Console.ReadLine();

                for (int j = 0; j < w; j++)
                {
                    t[i, j] = s[j];
                }
            }

            char c;
            bool f = false;

            // "." 又は "*"(2回目) まで繰り返し
            while (true)
            {
                c = t[y, x];
                // 2回目目印
                t[y, x] = '*';

                    if (c == '.') break;
                else if (c == '>') x++;
                else if (c == 'v') y++;
                else if (c == '<') x--;
                else if (c == '^') y--;
                else if (c == '*')
                {
                    f = true;
                    break;
                }
            }

            string ret = "";
            if (f) ret = "LOOP";
            else   ret = string.Format("{0} {1}", x, y);

            Console.WriteLine(ret);
        }
    }
}


Measured memory_bytes: 9308
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>
#include <climits>
#include <set>
#include <complex>
#include <cmath>
#include <cstring>
#include <map>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 1LL << 59

double x[1010], y[1010];
int main()
{
    //std::ios::sync_with_stdio(false);
    //std::cin.tie(0);
    cout << fixed << setprecision(3);

    x[1] = 1.0;
    y[1] = 0.0;
    for (int i = 2; i <= 1000; ++i)
    {
        double d = sqrt(x[i - 1] * x[i - 1] + y[i - 1] * y[i - 1]);
        double dx = -y[i - 1] / d;
        double dy = x[i - 1] / d;
        x[i] = x[i - 1] + dx;
        y[i] = y[i - 1] + dy;
    }

    int n;
    while (cin >> n)
    {
        if (n == -1)
            break;

        cout << x[n] << endl;
        cout << y[n] << endl;
    }
    return 0;
}


Measured memory_bytes: 3248
#include<stdio.h>

int partition(int,int);

int A[100000];

int main()
{
  
  int i,j,n,p,r;

  scanf("%d",&n);

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

  p=0;
  r=n-1;

  j=partition(p,r);

  for(i=0; i<n; i++){
    if(i>0) printf(" ");
    if(i == j){
      printf("[%d]",A[i]);
      continue;
    }
    printf("%d",A[i]);
  }
  printf("\n");
 
  return 0;
}

int partition(int p, int r)
{
  int x = A[r];
  int i = p-1;
  int tmp;

  for(int j = p; j<r; j++){
    if(A[j] <= x){
      i = i+1;
      tmp = A[j];
      A[j] = A[i];
      A[i] = tmp;
    }
  }
  tmp = A[r];
  A[r] = A[i+1];
  A[i+1] = tmp;
  return i+1;
}



Measured memory_bytes: 2984
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(i=0;i<n;i++)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max(a,b)-min(a,b))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1; rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define fact(n) nPr((int)n,(int)n)
#define nHr(n,r) nCr((int)(n+r+1),(int)r)
#define sankaku(x) ((1+x)*x)/2
int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(const void *a, const void *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(const void *a, const void *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(const void* left, const void* right) {return strcmp((char *)left,(char *)right);}
int downchar(const void* left, const void* right) {return strcmp((char *)right,(char *)left);}
ll stack[LIMIT2],queue[LIMIT2*10];//stack[0]=count;queue[0]=start,queue[1]=length;
int enqueue(ll n){
    if(queue[0]+queue[1]>=LIMIT2) return -1;
    queue[queue[0]+queue[1]] = n;
    queue[1]++;
    return 1;
}
ll dequeue(){
    ll result;
    if(queue[1]<=0) return -1;
    result = queue[queue[0]];
    queue[0]++;
    queue[1]--;
    if(queue[1]==0){
        queue[0] = 2;
    }
    return result;
}
void initialize(){
    stack[0] = 0;
    queue[0] = 2;
    queue[1] = 0;
}
int main(void){
  initialize();
  ll n,k,i,j,result=0,sum=0;
  int a[LIMIT1];
  char s[LIMIT1];

  scanf("%lld",&k);
  rep(i,9) enqueue(i+1);
  result = dequeue();
  for(i=1;i<k;i++){
    if(result % 10 != 0) enqueue(result*10+result%10-1);
    enqueue(result*10+result%10);
    if(result % 10 != 9) enqueue(result*10+result%10+1);
    result = dequeue();
  }
  printf("%lld",result);
  return 0;
}

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

int main() {
	int n;
	
	while (cin >> n, n) {
		int ans = -1, mx = -1;
		
		for_(i,0,n) {
			int p, d1, d2;
			cin >> p >> d1 >> d2;
			
			if (mx < d1 + d2) {
				mx = d1 + d2;
				ans = p;
			}
		}
		
		cout << ans << " " << mx << endl;
	}
}

Measured memory_bytes: 1156
#include<iostream>

using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    bool ans[3];

    for (int i = 0; i < 3; i++) {
        ans[i] = false;
    }

    ans[a - 1] = true;
    ans[b - 1] = true;

    for (int i = 0; i < 3; i++) {
        if (ans[i] == false) {
            cout << i + 1 << endl;
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 256
fn main(){ 
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).expect("Failed");

    let part:Vec<&str>=  input.split(" ").collect();

    let tables: usize = part[0].trim().parse().expect("Not valid");
    let player_a: usize = part[1].trim().parse().expect("Not valid");
    let player_b: usize = part[2].trim().parse().expect("Not valid");

    let res = if (player_b - player_a) % 2 == 0 {
        (player_b - player_a) / 2
    } else if player_a - 1 < tables - player_b {
        player_a + (player_b -  player_a) / 2
    } else {
        tables - player_b + 1 + (tables - (player_a + tables - player_b + 1)) / 2
    };
    println!("{}", res);
}


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

int main(void){
    int n;
    string s;
    cin >> n >> s;

    char p = s[0];
    int slime = 1;
    for(int i=1;i<n;i++){
        if(p==s[i]) continue;
        slime++;
        p = s[i];
    }
    cout << slime << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <math.h>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  a+=b;
  c+=d;
  if(a==c){
    cout<<"Balanced"<<"\n";
  }
  else if(a>c){
    cout<<"Left"<<"\n";
  }
  else{
    cout<<"Right"<<"\n";
  }
  return 0;
  }

Measured memory_bytes: 3592
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();

		double result = 0;
		for(int i = 1; i <= N; i++) {
			double a = 1d / N;
			int total = i;
			while(total < K) {
				total *= 2;
				a = a * 0.5;
			}
			result += a;
		}
		System.out.println(result);
	}
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string N;
  cin >> N;
  int zeros = 0;
  int ones = 0;
  for ( int i = 0 ; i< N.size() ; i++ ) {
    if ( N[i] - '0' == 0 ) {
      zeros++;
    }
    else {
      ones++;
    }
  }
  int ans = 0;
  ans = min (zeros,ones);
  ans *= 2;
  cout << ans << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int n,k,a[510],tmp[510],r[510],l[510],sum,ans=1;
bool check(int num) {
	for(int i=1;i<=n;++i)
		tmp[i]=a[i]%num;
	sort(tmp+1,tmp+n+1);
	for(int i=1;i<=n;++i)
		l[i]=l[i-1]+tmp[i];
	for(int i=n;i>=1;--i)
		r[i]=r[i+1]+(num-tmp[i]);
	for(int i=1;i<n;++i)
		if(l[i]==r[i+1]&&l[i]<=k) return true;
	return false;
}
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;++i) {
		scanf("%d",&a[i]);
		sum+=a[i];
	}
	for(int i=1;i*i<=sum;++i)
		if(sum%i==0) {
			if(check(i)) ans=max(ans,i);
			if(check(sum/i)) ans=max(ans,sum/i);
		}
	printf("%d",ans);
	return 0;
}

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

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

    long long L[N];
    L[0] = 2; L[1] = 1;
    for(int i = 2; i <= N; i++){
        L[i] = L[i - 1] + L[i - 2];
    }

    cout << L[N] << endl;
}

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

int main (){
  ll N;
  cin >> N;
  ll n = (ll)sqrt((ll)N+1)+1;
  ll ans = 1+N;
  for(int i=1; i<=n; ++i){
    if(N%i==0) ans = min(ans, i+N/i);
  }
  cout << ans-2 << endl;
  return 0;
}

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

class Main {
    public static void main(String[] args) {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));// ??\????????????????????????
            String line = br.readLine();
            System.out.println(getCubed(line));

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * @param line
     *            ??´??°x?????\???
     * @return x???3???
     */
     private static long getCubed(String line) {
    	 long x = Long.parseLong(line);
    	 return (long) Math.pow(x, 3);
     }
}

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

int main(){
  string w, t;
  char fg, hg;
  int ans=0;
  cin >> w;
  while(true){
    cin >> t;
    if(t == "END_OF_TEXT")break;
    for(int i = 0;i < t.size();i++){
      fg = t.at(i);
      if(isupper(fg))t.at(i)=tolower(fg);
    }
    if(w == t)ans++;
  }
  cout << ans << endl;
}


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

int main(){
    long int a, b, c, k;
    cin >> a >> b >> c >>k;
    
    int ans=0;
    if(k>=a){
        ans += a;
        if(k-a-b>0) ans -= (k-a-b);
    }
    else ans += k;

    cout << ans << endl; 
}

Measured memory_bytes: 3624
#!/usr/bin python3
# -*- coding: utf-8 -*-

import numpy as np

def main():
    N, W = map(int, input().split())
    dp = [0] * (W+1)
    dp = np.array(dp)
    #dp[i][j]  iまでをみてjの重さでの最大価値
    for i in range(1,N+1):
        w, v = map(int, input().split())
        dp[w:W+1] = np.maximum(dp[w:W+1], dp[:W+1-w] + v)

#    print(dp)
    print(dp[W])

if __name__ == '__main__':
    main()

Measured memory_bytes: 14796
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define INF 100000000000000
#define MOD 1000000007LL
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;

template<typename T>
void invec(vector<T> &A){rep(i, 0, A.size()) cin >> A[i];}

struct edge {int to, cost;};
template <typename T>
bool chmin(T &a, const T& b) {if (a > b) {a = b; return true;} return false;}

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

int N, Q, K; cin >> N;
VI a(N-1), b(N-1), c(N-1);
vector<vector<edge>> G(N+1);
rep(i, 0, N-1){ 
    int a;
    edge e; cin >> a >> e.to >> e.cost;
    G[a].push_back(e);
    swap(a, e.to);
    G[a].push_back(e); 
}

cin >> Q >> K;

// K からの最短経路. dijkstra.
VI d(N+1, INF); // d[i] = 頂点 s から i への最短距離
d[K] = 0;

priority_queue<PII, VP, greater<PII>> q; 
q.push(PII(0, K));

while(!q.empty()){
    PII p = q.top(); q.pop();
    int v = p.second;
    if (d[v] < p.first) continue; 
    for (edge e: G[v])
        if (chmin(d[e.to], d[v] + e.cost))
            q.push(PII(d[e.to], e.to));
}

rep(_, 0, Q) {
    int x, y; cin >> x >> y;
    cout << d[x] + d[y] << "\n";
}


}
// 書いて考える．場合分け
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割統治，次にDP
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 12400
#include <bits/stdc++.h>
#define max		  1000000
#define pb		  push_back
#define pairs	  pair<int, int>
#define vi		  vector<int>
#define vb		  vector<bool>
#define vii		  vector<pairs>
#define lb		  lower_bound
#define ub		  upper_bound
#define lli		  long long int
#define endl	  '\n'
#define FastInput ios_base::sync_with_stdio(false), cin.tie(NULL);
#define Cases	  cout << "Case " << ++Case << ": ";
#define __test    \
	int tt;       \
	int Case = 0; \
	cin >> tt;    \
	while (tt--)
#define read(x)	 freopen(x, "r", stdin)
#define write(x) freopen(x, "w", stdout)
#define InputArray(a, n)        \
	for (int i = 0; i < n; i++) \
		cin >> a[i];
#define CopyArray(a, temp, n)   \
	for (int i = 0; i < n; i++) \
		temp[i] = a[i];
#define PrintArray(a, n)        \
	for (int i = 0; i < n; i++) \
		cout << a[i] << " ";    \
	cout << endl;

#define PI 3.14159265358979323846L
using namespace std;

int main() {
#ifdef Niloy
	read("input.txt");
	write("output.txt");
#endif
	int a;
	cin >> a;

	long double result = (long double) 2.0 * M_PI * a;

	printf("%.20Lf\n", result);

	cerr << "time = " << (clock() / CLOCKS_PER_SEC) << " sec" << '\n';
	return 0;
}

Measured memory_bytes: 3724
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
int n, a[350][350]; 
bool road[350][350];
int main() {
  cin >> n;
  rep(i,n) rep(j,n) cin >> a[i][j];
  rep(i,n) rep(j,n) if (i!=j) road[i][j] = true;
  
  rep(i,n) {
    rep(j,n) {
      rep(k,n) {
        if (a[i][j] > a[i][k]+a[k][j]) {
          cout << -1 << endl;
          return 0;
        }
        if (a[i][j] == a[i][k]+a[k][j] && k!=i && k!=j) road[i][j] = false;
      }
    }
  }
  ll len = 0;
  rep(i,n) rep(j,n) {
    if (road[i][j]) len += a[i][j];
  }
  len /= 2;
  cout << len << endl;
  return 0;
}

Measured memory_bytes: 4156
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) string((s).rbegin(), (s).rend())
#define MP make_pair
#define X first
#define Y second

using namespace std;

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

int sq[1010];
int cu[1010];

void init(){
	rep(i, 1010){
		sq[i] = i*i;
		cu[i] = sq[i]*i;
	}
}

int main(){
	init();

	while(1){
		int e;
		cin >> e;
		if(!e)break;

		int xyz = 1000000;

		rep(z, 101){
			rep(y, 1001){
				if(cu[z]+sq[y] > e) continue;
				xyz = min(xyz, z+y+(e-cu[z]-sq[y]));
			}
		}

		cout << xyz << endl;
	}

	return 0;
}

Measured memory_bytes: 1168
s=input()

hit = 0
for j in range(len(s)):
    if j%2 ==0:
        if s[j] == "0":
            hit = hit+1
        else:
            continue
    if j%2 ==1:
        if s[j] == "1":
            hit = hit+1
        else:
            continue
print(min(hit,len(s)-hit))

Measured memory_bytes: 3188
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#define MAX(X, Y) (((X) > (Y))? (X) : (Y))
#define MIN(X, Y) (((X) < (Y))? (X) : (Y))
int compare_int(const void *a, const void *b){
  return *(long int*)b - *(long int*)a; // 大きい順
}
// 公約数
long int gcd(long int a, long int b){
  if(b == 0){
    return a;
  }else{
    return gcd(b, a % b);
  }
}
// 最小公倍数 = a * b / 最大公約数
// 公倍数
long int lcm(long int a, long int b){
  return a * b / gcd(a, b);
}


// min
int main(void){
  int a, p;
  int ans = 0;

  scanf("%d%d", &a, &p);

  ans = (a * 3 + p) / 2;

    printf("%d\n", ans);
  
  return 0;
}


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

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

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

int main() {
  ll N,K;
  cin>>N>>K;
  vector<ll> v(N);
  for(ll i = 0LL; i < N; i++) cin>>v[i];
  vector<ll> S(N);
  for(ll i = 0LL; i < N; i++){
    if(i==0LL) S[i]=v[i];
    else S[i]=S[i-1]+v[i];
  }
  unordered_map<ll,ll> m;
  for(ll i = 0LL; i < N-1; i++){
    for(ll j = i+1; j < N; j++){
      m[S[j]-S[i]]++;
    }
  }
  for(ll i = 0LL; i < N ;i++) m[S[i]]++;
  ll cnt = 0LL;
  ll M = S[N-1];
  while(M>0LL) {
    M=(M>>1);
    cnt++;
  }
  ll ans = 0LL;
  for(ll i = cnt; i >=0LL; i--){
    ll x = ans + (1LL<<i);
    ll num = 0;
    for(auto y:m){
      if((y.first&x)==x) num+= y.second;
    }
    if(num>=K) ans=x;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 22004
/*
    if you can't see the repay
    Why not just work step by step
    rubbish is relaxed
    to ljq
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;

#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define lc (rt<<1)
#define rc (rt<<11)
#define mid ((l+r)>>1)

typedef pair<int,int> pll;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll _INF = 0xc0c0c0c0c0c0c0c0;
const ll mod =  (int)1e9+7;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}
void exgcd(ll a,ll b,ll &x,ll &y,ll &d){if(!b) {d = a;x = 1;y=0;}else{exgcd(b,a%b,y,x,d);y-=x*(a/b);}}//printf("%lld*a + %lld*b = %lld\n", x, y, d);
int arr[4],n;
double dp[305][305][305];
double dfs(int a,int b,int c)
{
    if(a==0&&b==0&&c==0) return 0;
    if(dp[a][b][c]>0) return dp[a][b][c];
    double ans = 1.0*n/(a+b+c);
    if(a) ans+=(1.0*a/(a+b+c))*dfs(a-1,b,c);
    if(b) ans+=(1.0*b/(a+b+c))*dfs(a+1,b-1,c);
    if(c) ans+=(1.0*c/(a+b+c))*dfs(a,b+1,c-1);
    return dp[a][b][c] = ans;
}
int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);
    int d;
    scanf("%d",&n);
    for(int i = 1;i<=n;++i)
    {
        scanf("%d",&d);
        arr[d]++;
    }
    printf("%.10f\n",dfs(arr[1],arr[2],arr[3]));
    //fclose(stdin);
    //fclose(stdout);
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


Measured memory_bytes: 219392
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,x;
    int ans=0;
    cin >> a>>b>>c>>x;
    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==x){
                    ans++;
                }
            }
        }
    }

    cout << ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <typeinfo>

using namespace std;

int main(){
  int N;
  cin >> N;
  vector<int> Anum(100000);
  for(int i=0;i<N;i++){
    int a;
    cin >> a;
    Anum.at(a)++;
  }

  int ans=0;
  for(int i=0;i<100000;i++){
    int count=0;
    if(i>0) count+=Anum.at(i-1);
    count+=Anum.at(i);
    if(i<100000-1)  count+=Anum.at(i+1);
    ans=max(ans,count);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N =sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		if (N*A<B) {
			System.out.println(N*A);
		} else {
			System.out.println(B);
		}
	}
}

Measured memory_bytes: 22228
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  n <- unsafeTextToInt <$> T.getLine :: IO Int
  print $ (1000 - (n `mod` 1000)) `mod` 1000

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}


Measured memory_bytes: 3784
#include<stdio.h>
int main(){
    int H,N,i,A,sum;
    sum=0;
    scanf("%d%d",&H,&N);
    for(i=1;i<=N;i++){
        scanf("%d",&A);
        sum=sum+A;
    }
    if(sum>=H)
    printf("Yes");
    else
    printf("No");
  
    return 0;
}

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

long long GetGreatestCommonDivisor(long long a, long long b) {
	long long m = a;
	long long n = b;
	long long temp;

	while (m % n != 0) {
		temp = n;
		n = m % n;
		m = temp;
	}
	return n;
}

int main() {

	int n; cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	// 3つ以上の整数の場合
	long long tmp = a[0];
	for (int i = 1; i < n; i++) {
		tmp = GetGreatestCommonDivisor(tmp, a[i]);
	}

	cout << tmp << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B;
  cin>>A>>B;
  int hachi[1264];
  int juu[1012];
  for(int i=1;i<1264;i++){
    hachi[i]=i*0.08;
    //cout<<i<<"円 "<<hachi[i]<<endl;
  }
  for(int i=1;i<1012;i++){
    juu[i]=i*0.1;
    //cout<<i<<"円 "<<juu[i]<<endl;
  }
  bool hantei1=false;
  int atai_hachi=0;
  int count1=0;
  bool hantei2=false;
  int atai_juu=0;
  int count2=0;
  for(int i=1;i<1264;i++){
    if(hachi[i]==A){
      hantei1=true;
      atai_hachi=i;
      count1++;
    }
  }
  for(int i=1;i<1012;i++){
    if(juu[i]==B){
      hantei2=true;
      atai_juu=i;
      count2++;
    }
  }
  //cout<<count1<<" "<<count2<<endl;
  //cout<<hantei1<<" "<<hantei2<<endl;
  if(hantei1==true&&hantei2==true){
    //cout<<atai_hachi<<" "<<atai_juu<<endl;
    for(int i=atai_hachi-count1+1;i<atai_hachi+1;i++){
      for(int j=atai_juu-count2+1;j<atai_juu+1;j++){
        if(i==j){
          cout<<i<<endl;
          return 0;
        }
      }
    }
    cout<<-1<<endl;
  }else{
    cout<<-1<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
/******************************************
* AUTHOR : Ashish Joshi* 
* INSTITUTION : NIT Hamirpur *
******************************************/
#include <bits/stdc++.h>
using namespace std;

#define N 100005
#define MOD 1000000007
#define PI 3.141592653589793

#define dd double
#define loop(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define set(b,i) (b|(1<<i))
#define unset(b,i) (b&!(1<<i))
#define cbit(b,i) bool(b&(1<<i))

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<long long,long long> > vpll;
typedef vector<vector<ll> > vvll;

int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//ios_base& scientific (ios_base& str);
ll n;
cin>>n;
ll a[n];
map<ll,ll> m1;
for(int i=0;i<n;i++){
	cin>>a[i];
	m1[a[i]]++;
}
ll c=0;
for(auto x:m1){
	c+=(x.se*(x.se-1))/2;
}

for(int i=0;i<n;i++){
ll ans=c-(m1[a[i]]*(m1[a[i]]-1))/2 + max(0LL,((m1[a[i]]-1)*(m1[a[i]]-2))/2);
	// if(m1[a[i]]==2)cout<<c-1<<endl;
cout<<ans<<endl;
	// else if()
	// cout<<m1[a[i]]<<endl;
}
// cout<<c<<endl;
return 0;
}

Measured memory_bytes: 11136
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define ll long long
using namespace std;

int main(){

    int a,b;
    cin >> a >> b;

    int x,y,z;

     x = a + b;
     y = a - b;
     z = a * b;

     cout << max({x,y,z}) << endl;
}




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

const int MAX = 100003;
const int MAX_a = 1000000003;

class unionfind {
private:
	int par[MAX]; int rank[MAX];
public:
	unionfind(int n) {
		for (int i = 0; i < n; i++) {
			par[i] = i;
			rank[i] = 0;
		}
	}
	int find(int x) {
		if (par[x] == x) {
			return x;
		}
		else {
			return par[x] = find(par[x]);
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	void unite(int x, int y) {
		if (!same(x, y)) {
			x = par[x]; y = par[y];
			if (rank[x] < rank[y]) {
				par[x] = y;
			}
			else {
				par[y] = x;
				if (rank[x] == rank[y]) {
					rank[x]++;
				}
			}
		}
	}
};

int a[MAX], b[MAX], c[MAX];

int main() {
	int n, m;
	cin >> n>> m;
	if (n - 1 == m) {
		cout << 0 << endl;
		return 0;
	}
	else if (2 * (n - m - 1) > n) {
		cout << "Impossible" << endl;
		return 0;
	}
	unionfind u(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		u.unite(x, y);
	}
	for (int i = 0; i < n; i++) {
		b[i] = MAX_a; c[i] = -1;
	}
	for (int i = 0; i < n; i++) {
		int boss = u.find(i);
		if (a[i] < b[boss]) {
			b[boss] = a[i];
			c[boss] = i;
		}
	}
	long long ans = 0;
	for (int i = 0; i < n; i++) {
		if (b[i] != MAX_a) {
			ans += b[i];
			a[c[i]] = MAX_a;
		}
	}
	sort(a, a + n);
	for (int i = 0; i < 2 * (n - m - 1) - (n - m);i++) {
		ans += a[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 2304
from functools import reduce
from math import gcd

N=int(input())
A=list(map(int, input().split()))

c=max(A)+1
D=[0]*c
div=[0]*c
P=[]

for i in range(2,c):
    if D[i]==0:
        P.append(i)
        D[i]=i
    for j in P:
        if i*j>=c  or j>D[i] :
           break
        D[i*j]=j
f=0
for i in A:
    if i==1:
        continue
    temp=i
    while temp!=1:
        if div[D[temp]]==1:
            f=1
            break
        div[D[temp]]+=1
        temp2=D[temp]
        while temp%temp2==0 and temp>=temp2:
            temp=temp//temp2
    if f==1:
        break
        
if f==0:
    print('pairwise coprime')

elif reduce(gcd, A) == 1:
    print('setwise coprime')

else:
    print('not coprime')

Measured memory_bytes: 127640
#include<iostream>
using namespace std;
int main(void) {
	//入力
	int n;
	cin >> n;
	int a[100001];
	a[0] = 0;
	for (int i(1); i <=n; i++) {
		cin >> a[i];
	}
	a[n + 1] = 0;
	//処理
	bool change_sign[100001];
	for (int i(1); i <=n; i++) {
		if ((a[i] - a[i - 1])*(a[i + 1] - a[i]) < 0)change_sign[i] = true;
		else change_sign[i] = false;
	}
	int first_money(0);
	for (int i(1); i <= n+1; i++) {
		first_money += abs(a[i]-a[i-1]);
	}
	//cout << first_money << endl;
	for (int i(1); i <= n; i++) {
		if (change_sign[i]) {
			if (abs(a[i]-a[i-1])>abs(a[i+1]-a[i])) {
				cout << first_money - abs(a[i+1] - a[i]) * 2 << endl;
			}
			else {
				cout << first_money - abs(a[i] - a[i - 1]) * 2 << endl;
			}
		}
		else cout << first_money << endl;
	}
	return 0;
}

Measured memory_bytes: 1664
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int p = sc.nextInt();

		System.out.println((a * 3 + p)/2);
	}

}


Measured memory_bytes: 21972
#include "bits/stdc++.h"
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define INF 1e9
using ll = std::int64_t;

template <class T>
bool chmax(T &a, const T &b);
template <class T>
bool chmin(T &a, const T &b);
//最大公約数
std::int64_t gcd(std::int64_t a, std::int64_t b);
std::int64_t gcd_s(std::int64_t aa, std::int64_t bb);
//ラングレス圧縮
std::vector<std::pair<char, std::int64_t>> rle(std::string str);
//素数判定
bool is_prime(std::int64_t n);
// 約数の列挙
std::vector<std::int64_t> divisor(std::int64_t n);
// 素因数分解
std::map<std::int64_t, std::int64_t> prime_factor(std::int64_t n);

//10^9 + 7
#define yojo 1000000007
#define MAX_NUM 200001

void Main()
{
  string a, b;
  cin >> a >> b;
  string c = a + b;
  int num = stoi(c);

  for (int i = 1; i * i <= 1000 * 1000; i++)
  {
    if (num == i * i)
    {
      std::cout << "Yes" << std::endl;
      return;
    }
  }
  
  std::cout << "No" << std::endl;

  return;
}

int main()
{
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}

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

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

//最大公約数
std::int64_t gcd(std::int64_t a, std::int64_t b)
{
  // a >= b && b != 0
  std::int64_t c;
  do
  {
    c = a % b;
    a = b;
    b = c;
  } while (c);

  return a;
}

//最大公約数安全版
std::int64_t gcd_s(std::int64_t aa, std::int64_t bb)
{
  std::int64_t a = max(aa, bb);
  std::int64_t b = min(aa, bb);
  std::int64_t c;
  if (b == 0)
  {
    return -1;
  }
  do
  {
    c = a % b;
    a = b;
    b = c;
  } while (c);

  return a;
}

//ラングレス圧縮
std::vector<std::pair<char, std::int64_t>> rle(std::string str)
{
  std::vector<std::pair<char, std::int64_t>> data;
  char now = str[0];
  std::int64_t count = 0;
  for (std::int64_t i = 0; i < str.size() + 1; i++)
  {
    if (i == str.size())
    {
      data.push_back(make_pair(str[i - 1], count));
      break;
    }
    else if (now != str[i])
    {
      data.push_back(make_pair(now, count));
      now = str[i];
      count = 0;
    }
    count++;
  }

  return data;
}

//素数判定
bool is_prime(std::int64_t n)
{
  for (std::int64_t i = 0; i * i <= n; i++)
  {
    if (n % i == 0)
    {
      return false;
    }
  }

  return n != 1;
}

//約数の列挙
std::vector<std::int64_t> divisor(std::int64_t n)
{
  std::vector<std::int64_t> res;
  for (int i = 0; i < n; i++)
  {
    if (n % i == 0)
    {
      res.push_back(i);
      if (i != n / i)
        res.push_back(n / i);
    }
  }
  return res;
}

// 素因数分解
std::map<std::int64_t, std::int64_t> prime_factor(std::int64_t n)
{
  std::map<std::int64_t, std::int64_t> res;
  for (int i = 2; i * i <= n; i++)
  {
    while (n % i == 0)
    {
      ++res[i];
      n /= i;
    }
  }

  if (n != 1)
  {
    res[n] = 1;
  }

  return res;
}

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

int N;
int A[210];         // 最大 200 個なので余裕を持って 210 に --- 200 以上ならなんでもよいです

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

    int res = 0;

    // 操作が行える限り操作を繰り返す
    while (true) {
        bool exist_odd = false;  // A[i] がすべて偶数かどうかを判定するフラグ
        for (int i = 0; i < N; ++i) {
            if (A[i] % 2 != 0) exist_odd = true;  // 奇数があったらフラグを立てる
        }

        if (exist_odd) break;  // 奇数があったら break

        // 操作を行えるなら操作を実際に行う
        for (int i = 0; i < N; ++i) {
            A[i] /= 2;//復号代入演算子
        }
        ++res;  // 操作回数をインクリメント
    }

    cout << res << endl;
}

Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
#define pow107 int(pow(10,9) + 7)
#define F(i,x,n) for(int i = x; i < n ; ++i)

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

long int jou(long int x, long int y){
    long int f = 1;
    for(int i = 0; i < y; ++i){
        f = f * x % pow107;
    }
    return f;
}

inline bool pn(long int x){
    if(x <= 1)return false;
    if(x != 2 && x % 2 == 0)
        return false;
    for(int i = 3; i <= (3 + int(sqrt(x)))/2; ++i){
        if((x != i && x % i == 0) || (x != (3 + int(sqrt(x)) - i) && x % (3 + int(sqrt(x)) - i) == 0))
            return false;
    }
    return true;
}

long int factorial(long int n){
    long int f = 1;
    for(long int i = 1; i <= n; ++i){
        f = f * i % pow107;
    }
    return f;
}

long int Func2(long int n,long int m){
    long int s2 = 1,
        r = 1;
    for(long int i = 1; i <= m; ++i){
        s2 = (s2*(n - (i - 1))/i) % (pow107);
    }
    return s2;
}

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

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

long int LCM(long int a,long int b){
    return a/GCD(a,b)*b;
}

void warfl(vector<vector<int> > &dist, int n){
  for(int k=0; k<n; k++){
    for(int i=0; i<n; i++){
      for(int j=0; j<n; j++){
        dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
      }
    }
  }
  return;
}
//#define long long long

const int MAX = 1000000;
const int MOD = 1e9+7;

long mpow(long x, long n){
    long ans = 1;
    while(n != 0){
        if(n%2==1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n/2;
    }
    return ans;
}

long mfact(long n){
  long ans = 1;
  for(long i=2; i<=n; i++){
    ans = ans*i % MOD;
  }
  return ans;
}

long mcomb(long n, long m){ //aCbをmod計算
    if(n == 0 && m == 0) return 1;
    if(n < m || n < 0) return 0;
    long ans = mfact(n)*mpow(mfact(m), MOD-2) %MOD;
    ans = ans*mpow(mfact(n-m), MOD-2) %MOD;
    return ans;
}

long int jjjjj(long int n){
    long int x = 1;
    for(int i = 1; i <= n; ++i){
        x *=i;
    }
    return x;
}

int main(){
    int n;
    cin >> n;
    int c[101] = {0};
    for(int i = 0; i < n; ++i){
        int a;
        cin >> a;
        c[a]++;
    }

    int ans = 0;
    for(int i = 0; i < 101; ++i){
        if(c[i] > 0)ans++;
    }

    cout << ans << endl;

}

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

int main() {

  int N;
  cin >> N;

  vector<int> A(N), B(N);
  rep(i, N) cin >> A[i];

  rep(i, N) B[A[i]-1] = i+1;
  rep(i, N) cout << B[i] << endl;

  return 0;
}

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

const int N = 200005;

int n, q;
int a[N], b[N];

int main() {
  cin >> n >> q;
  ll blk = (ll)(n - 2) * (n - 2);
  int h = n, w = h;
  rep(qi, q) {
    int t, x;
    cin >> t >> x;
    if (t == 1) {
      if (x > h) {
        blk -= a[x - 1];
      } else {
        for (int i = x; i < h; i++) a[i] = w - 2;
        blk -= w - 2;
        h = x;
      }
    } else {
      if (x > w) {
        blk -= b[x - 1];
      } else {
        for (int i = x; i < w; i++) b[i] = h - 2;
        blk -= h - 2;
        w = x;
      }
    }
  }
  cout << blk << endl;
  return 0;
}

Measured memory_bytes: 5152
#include <iostream>
using namespace std;
int main()
{
    int a,b,c,d,e,f;
    cin>>a>>b>>c>>d;
    if (a>b) e=b;
    else e=a;
    if (c>d) f=d;
    else f=c;
    cout<<e+f<<endl;
    system ("pause");
    return 0;
}

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

int n, m, q;
vector<int> a, b, c, d;
int ans;

void dfs(vector<int> g) {
    if (g.size() == n + 1) {
        int sum = 0;
        REP(i, q)
            if (g[b[i]] - g[a[i]] == c[i])
                sum += d[i];
        ans = max(ans, sum);
        return ;
    }
    g.push_back(g.back());
    while (g.back() <= m) {
        dfs(g);
        g.back()++;
    }
}

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

    cin >> n >> m >> q;

    a = b = c = d = vector<int>(q);
    REP(i, q) cin >> a[i] >> b[i] >> c[i] >> d[i];

    dfs(vector<int>(1, 1));
    cout << ans << '\n';
    return 0;
}


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

#define ll long long
#define ull unsigned long long
#define N 100005
#define mod 998244353
#define boost ios_base::sync_with_stdio(false);cin.tie(0)
#define prec(n) fixed<<setprecision(n)

#define mii unordered_map<int,int>
#define mll unordered_map<ll,ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi  first

#define se second
#define pb push_back
#define mp make_pair
#define pp pop_back
#define vii vector<int>
#define vll vector<ll>
#define vpp vector<pii>
#define all(c) c.begin(),c.end()
#define tr(it,c) for(it = c.begin() ; it!=c.end() ; it++)
int inf = INT_MAX ;
ll modulo(ll num,ll MOD=mod){ return ((num%MOD)+MOD)%MOD;} // for negative integer
ll power(ll b,ll e,ll MOD=mod){ll ans=1; while(e){if(e%2) ans=(ans*b)%MOD; b=(b*b)%MOD; e/=2;} return ans;}
ll inv(ll num,ll MOD=mod){ return power(modulo(num),MOD-2,MOD); }
ll gcd(ll a,ll b){ return ((b==0) ? a:gcd(b,a%b));}

int main(){
	boost;
	// #ifndef ONLINE_JUDGE
	// 	freopen("D:/Disk D/Work/c++ workspace/input.txt","r",stdin);
	// 	freopen("D:/Disk D/Work/c++ workspace/output.txt","w",stdout);
	// #endif
	ll n,a,b;
    cin>>n>>a>>b;

    ll k = n/(a+b);
    n = n - k*(a+b);
    ll ans = k*a;
    if(a>=n){
        ans = ans + n;
    }else{
        ans = ans + a;
    }
    cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<utility>
#include<map>
#include<algorithm>
using namespace std;
typedef pair<int,int> p;
map<p,p>F;
int N,X,Y,D,m[5]={0,1,0,-1,0};
int dfs(p pos,p f,int c)
{
	F[pos].first=c;
	for(int i=0;i<4;i++)
	{
		p tmp(pos.first+m[i],pos.second+m[i+1]);
		if(F.count(tmp))
		{
			if(F[tmp].second==f.second)//same_futon
			{
				if(F[tmp].first==-1&&dfs(tmp,F[tmp],!c)==0)
					return 0;
				else if(F[tmp].first==c)
					return 0;
				continue;
			}
			else//diff_futon
			{
				if(F[tmp].first==-1&&dfs(tmp,F[tmp],c)==0)
					return 0;
				else if(F[tmp].first!=c)
					return 0;
				continue;
			}
		}
	}
	return 1;
}
int main()
{
	for(;scanf("%d",&N),N;)
	{
		F.clear();
		for(int i=0;i<N;i++)
		{
			scanf("%d%d %c\n",&X,&Y,&D);
			if(D-'x')
			{
				F[p(X,Y)]=p(-1,i);
				F[p(X,Y+1)]=p(-1,i);
			}
			else
			{
				F[p(X,Y)]=p(-1,i);
				F[p(X+1,Y)]=p(-1,i);
			}
		}
		map<p,p>::iterator i=F.begin();
		for(;i!=F.end();i++)
		{
			if(i->second.first==-1&&dfs(i->first,i->second,0)==0)
				break;
		}
		puts(i==F.end()?"Yes":"No");
	}
	return 0;
}

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

int N;

string S[202];
int color[202], visit[202];

int dfs(int x, int col)
{
    if(color[x])
        return (color[x] == col);

    color[x] = col;

    int ans = 1;

    for(int i=0; i<N; i++)
        if(S[x][i] == '1')
            ans &= dfs(i, col == 1 ? 2 : 1);
    
    return ans;
}

int solve(int s)
{
    queue<int> Q;

    for(int i=0; i<N; i++)
        visit[i] = 0;
    
    Q.push(s);
    visit[s] = 1;

    while(!Q.empty())
    {
        int q = Q.front();
        Q.pop();

        for(int i=0; i<N; i++)
            if(S[q][i] == '1' && visit[i] == 0)
            {
                visit[i] = visit[q] + 1;
                Q.push(i);
            }
    }

    int ans = 0;

    for(int i=0; i<N; i++)
        ans = max(ans, visit[i]);

    return ans;
}

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

    cin >> N;

    for(int i=0; i<N; i++)
        cin >> S[i];
    
    if(!dfs(1, 1))
    {
        cout << -1 << "\n";
        return 0;
    }

    int ans = 0;

    for(int i=0; i<N; i++)
        ans = max(ans, solve(i));

    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 384
import sys
from collections import deque
input = sys.stdin.readline

n,q = map(int,input().split())
score = [0]*(n+1)
tree = [[] for i in range(n+1)]
check = [0]*(n+1)
check[1] = 1

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

que = deque([1])
qappend = que.append
qpop = que.pop

for i in range(q):
  q,x = map(int,input().split())
  score[q] += x

while que:
  n = qpop()
  for i in tree[n]:
    if check[i]:continue
    check[i] = 1
    score[i] += score[n]
    qappend(i)

print(" ".join(map(str, score[1:])))

Measured memory_bytes: 67176
#pragma optimize("", off)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/STACK:36777216")
#include <bits/stdc++.h>
 
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long 
#define all(v) v.begin(),v.end()
#define pb push_back
#define sz(i) int(i.size())
#define setto(n) cout << fixed << setprecision(n)
#define fi first
#define se second
#define inf LONG_MAX //change to 2e18 according to requirement and also check that operation on it doesn't overflows.
#define random() ((ll)rand() << 32 | rand())
const int mod = 1000000007;
 
using namespace std;
 
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}
template<class T> void smax(T& a, T val) {if (a < val) a = val;}
template<typename T>inline std::ostream &operator << (std::ostream & os,const std::vector<T>& v){bool first = true;os << "[";for(auto i: v){if(!first)os << ", ";os << i;first = false;}return os << "]";}
//Check N size twiceeeeeeeeeeeeeeeeee, and verify it
const int N = 2*1e4 + 10;
 
#define int ll

main(){
 	int n, x;
 	cin>>n>>x;
 	cout<<n-x+1<<endl; 	
	return 0;	
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int k,a,b;
	cin>>k>>a>>b;
	for (int i=a;i<=b;i++){
		if (i%k==0){
			cout<<"OK"<<endl;
			return 0;
		}
	}
	cout<<"NG"<<endl;
	return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  
using namespace std;
 
const ll inf = 1e17;
const ll N = 2010;
const ll bits = 30;
const ll mod = 998244353;



int main(){
    FASTIO;
    string s,t;
    cin>>s>>t;
    int n1 = s.size(), n2 = t.size();

    vector< vector<int> >dp(n1+1,vector<int>(n2+1,0));

    for(int i=1;i<=n1;i++){
        for(int j=1;j<=n2;j++){
            if(s[i-1]==t[j-1]){
                dp[i][j] = dp[i-1][j-1]+1;
            }else{
                dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }

    // cout<<dp[n1][n2]<<"\n";

      // Following code is used to print LCS 
   int index = dp[n1][n2]; 
  
   // Create a character array to store the lcs string 
   char lcs[index+1]; 
   lcs[index] = '\0'; // Set the terminating character 
  
   int i = n1, j = n2; 
   while (i > 0 && j > 0) 
   { 
      if (s[i-1] == t[j-1]) 
      { 
          lcs[index-1] = s[i-1];
          i--; j--; index--;
      } 
  
      else if (dp[i-1][j] > dp[i][j-1]) 
         i--; 
      else
         j--; 
   } 
  
   cout << lcs; 
    





    
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int n;
  cin >> n;
  bool first = false;
  rep(i, n) {
    int a;
    cin >> a;
    if (a % 2 == 1) first = true;
  }
  if (first) {
    cout << "first" << endl;
  } else {
    cout << "second" << endl;
  }
}


Measured memory_bytes: 256
//g++ -std=c++14 test.cpp -o test.out
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const int INF_INT = 2147483647;
const LL mod = 1000000007ll;

string s,t;

LL ans;
 
void solve(){
	vector<set<int>> s_type(26);
	for(int i=0;i<s.size();i++){
		s_type[s[i]-'a'].insert(i);
		s_type[s[i]-'a'].insert(i+s.size());
	}

	int p = 0;//今参照しているsのインデックス 最初は文字列先頭を表す0
	for(int i=0;i<t.size();i++){
		int character = t[i]-'a';
		if(s_type[character].size()==0){
			ans = -1;
			return;
		}
		p = *(s_type[character].lower_bound(p))+1;//lower_boundで帰ってくるのはイテレータ
		if(p>=s.size()){
			p -= s.size();
			ans += s.size();
		}
	}
	ans += p;
}
 
int main(){
	cin >> s >> t;
 
	solve();
 
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 9856
import std.stdio;
import std.string;
import std.conv;

void main() {
	string[] inputs = split(readln());
	int A = to!int(inputs[0]);
	int B = to!int(inputs[1]);
	int C = to!int(inputs[2]);
	int D = to!int(inputs[3]);
	
	if(A + B > C + D) writeln("Left");
	else if(A + B == C + D) writeln("Balanced");
	else writeln("Right");
}


Measured memory_bytes: 256