akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>//random,NULL
#include <string.h>
#include <time.h>
#include <unistd.h>//sleep()
#include <math.h>
#include <stdbool.h>

#define rep(i,n) for(int i=0; i<((int)n); i++)
#define REP(i,n) for(int i=0; i<=((int)n); i++)
#define srep(i,a,n) for(int i=a; i<((int)n); i++)
#define SREP(i,a,n) for(int i=a; i<=((int)n); i++)
#define rrep(i,n) for(int i=n-1; i>=0; i--)
#define RREP(i,n) for(int i=n; i>=0; i--)
#define INF 1000000000
const int mod = INF+7;

//木を作る。
struct edge{
  int to;
  struct edge *next;
};

void push(struct edge **edges, struct edge **last, int from, int too){
  struct edge *edge1=(struct edge *)malloc(sizeof(struct edge));
  edge1->to=too;
  edge1->next=NULL;
  if(last[from]==NULL){
    edges[from]=edge1;
  }
  else{
    last[from]->next=edge1;
  }
  last[from]=edge1;
}


//木の構造を調べ、各ノードの親ノードを記録
void tree_parent(int *parent, int par, int current, struct edge **edges){
  struct edge *end=edges[current];
  while(end!=NULL){
    int child=end->to;
    if(child!=par){
      parent[child]=current;
      tree_parent(parent, current, child, edges);
    }
    end=end->next;
  }
}


//遡りながら値をcompleteしていく。
void dfs(int *parent, bool *comp, int a, int *node){
  if(a==0){
    ;
  }
  else if(comp[parent[a]]==true){
    node[a]+=node[parent[a]];
    comp[a]=true;
  }
  else if(comp[parent[a]]==false){
    dfs(parent, comp, parent[a], node);
    node[a]+=node[parent[a]];
    comp[a]=true;
  }
}

int main(){
  char buf[1024];
  int N, Q;

  fgets(buf,sizeof(buf),stdin);
  sscanf(buf, "%d %d", &N, &Q);

  int *a=(int *)malloc(sizeof(int)*(N-1));
  int *b=(int *)malloc(sizeof(int)*(N-1));
  int *p=(int *)malloc(sizeof(int)*Q);
  int *x=(int *)malloc(sizeof(int)*Q);
  rep(i,N-1){
    fgets(buf,sizeof(buf),stdin);
    sscanf(buf, "%d %d", &a[i], &b[i]);
    a[i]--;
    b[i]--;
  }
  rep(i,Q){
    fgets(buf,sizeof(buf),stdin);
    sscanf(buf, "%d %d", &p[i], &x[i]);
    p[i]--;
  }

  //木の辺のlistを作る。
  struct edge **last=(struct edge **)malloc(sizeof(struct edge *)*N);
  rep(i,N){
    last[i]=NULL;
  }
  struct edge **edges=(struct edge **)malloc(sizeof(struct edge *)*N);
  rep(i,N-1){
    push(edges, last, a[i], b[i]);
    push(edges, last, b[i], a[i]);
  }

  // rep(i,N){
  //   struct edge *end=edges[i];
  //   while(end!=NULL){
  //     printf("%d %d\n", i, end->to);
  //     end=end->next;
  //   }
  // }

  //親ノードを記録
  int *parent=(int *)malloc(sizeof(int)*N);
  parent[0]=0;
  tree_parent(parent, -1, 0, edges);

  int *node=(int *)calloc(N, sizeof(int));
  rep(i,Q){
    node[p[i]]+=x[i];
  }

  // rep(i,N){
  //   printf("%d\n", parent[i]);
  // }

  bool *comp=(bool *)malloc(sizeof(bool)*N);
  rep(i,N){
    comp[i]=false;
  }
  comp[0]=true;

  rep(i,N){
    dfs(parent, comp, i, node);
  }

  rep(i,N){
    printf("%d ", node[i]);
  }
  printf("\n");
}


Measured memory_bytes: 32256
from sys import stdin
readline = stdin.readline


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


def unit(a):
    return a / abs(a)


def near_pos_online(p, a, b):
    unit_a_b = unit(b - a)
    dist_from_a = dot(unit_a_b, p - a)
    return a + unit_a_b * dist_from_a


def intersection_of_circle_and_line(center, r, a, b):
    near = near_pos_online(center, a, b)
    d = sqrt(r ** 2 - abs(center - near) ** 2) * unit(b - a)
    return [near + d, near - d]


from math import sqrt
from operator import attrgetter
def main():
    cx, cy, r = map(int, readline().split())
    center = complex(cx, cy)
    q = int(readline())
    for i in range(q):
        x1, y1, x2, y2 = map(int, readline().split())
        a, b = complex(x1, y1), complex(x2, y2)
        intersection = intersection_of_circle_and_line(center, r, a, b)
        intersection.sort(key=attrgetter('real', 'imag'))
        pre, post = intersection

        print(*list(map('{:.6f}'.format, [pre.real, pre.imag, post.real, post.imag])))

main()

Measured memory_bytes: 6876
n = int(input())
p = [int(x) - 1 for x in input().split()]

ans = 0
num = -1
for i in range(n - 1):
    if num == i:
        continue
    if p[i] == i:
        if p[i + 1] == i + 1:
            num = i + 1
        
        ans += 1

if num != n - 1 and p[n - 1] == n - 1:
    ans += 1
    
print(ans)

Measured memory_bytes: 13880
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
int main() {
  int n;
  cin >> n;
  set<ll> a;
  rep(i,n){
    ll x;
    cin >> x;
    a.insert(x);
  }
  if(a.size() == n) cout << "YES" << endl;
  else cout << "NO" << endl;
  }


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

int main(){
  int A,B,K; cin >> A >> B >> K;
  for(int i=0; i<K; i++){
    if(i%2==0){
      if(A%1==1){
        A--;
      }
      A/=2;
      B+=A;
    }else{
      if(B%1==1){
        B--;
      }
      B/=2;
      A+=B;
    }
  }
  cout << A << " " << B << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<string>

using namespace std;

int main(void) {

	int num = 0, n;

	string a, b, c;

	cin >> n >> a >> b >> c;

	for (int k = 0; k < n; k++) {
		if (a[k] != b[k] && b[k] != c[k]&&c[k]!=a[k])num += 2;
		else if (a[k] != b[k] || b[k] != c[k]||c[k]!=a[k])num++;
		//printf("k==%d,num==%d\n", k, num);
	}

	cout << num << "\n";

	return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    int N;
    cin >> N;
    int ans = INT_MAX;
    for (int i = 1; i < N; i++) {
        int tmp = 0;
        int j = N - i;
        int A = i;
        while (A) {
            tmp += A % 10;
            A /= 10;
        }
        while (j) {
            tmp += j % 10;
            j /= 10;
        }
        ans = min(ans, tmp);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

typedef vector<int> VI;

void solve() {
  VI balls;
  for (int i = 0; i < 10; i++) {
    int n;
    cin >> n;
    balls.push_back(n);
  }

  int l = 0;
  int r = 0;
  for (int i = 0; i < 10; i++) {
    int n = balls[i];
    if (n > l) {
      l = n;
    } else if (n > r) {
      r = n;
    } else {
      cout << "NO" << endl;
      return;
    }
  }

  cout << "YES" << endl;
}

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    solve();
  }

  return 0;
}

Measured memory_bytes: 3076
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define p pair<int,int>
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
using namespace std;
int POW(int x,int y){return int(pow(double(x),double(y)));}
int ketakazu(int n){ //何桁かを返す
	return int(log10(double(n)))+1;
}

int main(){
	int a,b;
	cin>>a>>b;
	if(int(sqrt(double(POW(10,ketakazu(b))*a+b)))*int(sqrt(double(POW(10,ketakazu(b))*a+b)))==POW(10,ketakazu(b))*a+b){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
}

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

int main() {
  int r, g, b, k, a = 0;
  cin >> r >> g >> b >> k;
  while(g <= r || b <= g) {
    if(g <= r) g *= 2;
    else if (b <= g) b *= 2;
    a++;
    if(a > k) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <sstream>
#include <numeric>
#include <cstdio>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;

#define pb push_back
#define F first
#define S second

const int N = 3 * 2000 + 20;
int n, mod, ans;
int C[N][N], fac[N], inv[N], p2[N], save2[N], save3[N];

inline int pw (int a, int b) {
    int res = 1;

    while (b) {
        if (b & 1) res = 1ll * res * a % mod;
        a = 1ll * a * a % mod;
        b >>= 1;
    }

    return res;
}

void pre () {
    for (int i = 0; i < N; i++)
    {
        C[i][0] = 1;
        for (int j = 1; j <= i; j++)
            C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod;
    }

    fac[0] = 1;
    for (int i = 1; i < N; i++) fac[i] = 1ll * fac[i - 1] * i % mod;

    inv[N - 1] = pw(fac[N - 1], mod - 2);
    for (int i = N - 2; i >= 0; i--) inv[i] = 1ll * (i + 1) * inv[i + 1] % mod;

    p2[0] = 1;
    for (int i = 1; i < N; i++) p2[i] = 2 * p2[i - 1] % mod;

    save2[0] = 1;
    for (int i = 2; i < N; i += 2) save2[i] = 1ll * C[i][2] * save2[i - 2] % mod;

    save3[0] = 1;
    for (int i = 3; i < N; i += 3) save3[i] = 1ll * C[i][3] * save3[i - 3] % mod;
}

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

    cin >> n >> mod;

    pre();

    for (int a = 0; a <= n; a++) {
        for (int b = 0; b <= n; b++) {
            int c = 3 * n - 3 * a - 2 * b;

            if (c < b) continue;

            int res = 1;

            res = 1ll * res * C[3 * n][3 * a] % mod * save3[3 * a] % mod * p2[a] % mod * inv[a] % mod;

            res = 1ll * res * C[3 * n - 3 * a][2 * b] % mod * save2[2 * b] % mod * inv[b] % mod;

            ans = (ans + res) % mod;
        }
    }

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


Measured memory_bytes: 140416
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

int n,num;
char s[1005];

int main(void){
	scanf("%d %d",&n,&num);
	scanf("%s",s+1);
	s[num]+='a'-'A';
	printf("%s",s+1);
} 

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define EPS 1e-6
#define INF 1000000000

// MAXIMIZAR f(x) == MINIMIZAR -f(x)
// It is easy to prove ... 

#define _ ios_base::sync_with_stdio(0), cin.tie(0), cin.tie(0), cout.tie(0), cout.precision(15);
#define FOR(i, a, b) for(int i=int(a); i<int(b); i++)
#define FORC(i, a, b) for(int i=int(a); i>=int(b); i--)
#define pb push_back
#define fi first
#define se second
#define debug(x) cout << (#x) << " = " << x << "\n";
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

clock_t t_;

using namespace std;


template<class T> void print(T s){cout << s << "\n";}
template<class T> void emax(T &a, T b){a = (a<b ? b : a);};
template<class T> void emin(T &a, T b){a = (a>b ? b : a);}
template<class T> void printC(T s){ for(auto &x : s){cout << x << " ";} cout << "\n";}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ii> vii;
typedef vector<vi> vvi;

#define maxn 110
#define mod 1000000007

int n,w;
int we[maxn], val[maxn];
ll dp[maxn][100010];

int main(int argc, const char * argv[]) {
     
    #ifdef input
    freopen("input.txt", "r", stdin);
    #endif
    #ifdef output
    freopen("output.txt", "w", stdout);
    #endif
    t_ = clock();
        
    cin >> n >> w;
    FOR(i,0,n){
    	cin >> we[i] >> val[i];
    }

    FOR(i,1,n+1){
    	FORC(j, w, 1){
    		dp[i][j] = dp[i-1][j];
    		if(j-we[i-1] >= 0){
    			dp[i][j] = max(dp[i-1][j-we[i-1]] + val[i-1], dp[i-1][j]);
    		}
    	}
    }

    print(dp[n][w]);


    t_ = clock()-t_;
    cerr << setprecision(9) << fixed << ((float)t_ / CLOCKS_PER_SEC) << endl;

        
    return 0;
}





Measured memory_bytes: 79360
import java.util.Scanner;

//深さ優先探索を用いる
public class Main{
  public static int[] dx = {1, 1, 1, 0, -1, -1, -1, 0};
  public static int[] dy = {1, 0, -1, -1, -1, 0, 1, 1};


  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    while(true){
      int w = Integer.parseInt(sc.next());
      int h = Integer.parseInt(sc.next());
      if(h == 0 && w == 0){
        break;
      }
      int[][] c = new int[h][w];//島の情報(海か陸か)
      int [][] seen = new int[h][w];//探索済みか？初期値0
      //初期化用
      for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
          c[i][j] = Integer.parseInt(sc.next());
          seen[i][j] = 0;
        }
      }

      //探索用
      int k = 1;//島の数(k-1)
      for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
          //falseが返ってきたとき初手で島が見つからなかったからkは増やさない
          if(dfs(true, k, c, seen, j, i, h, w)) k++;
        }
      }
      System.out.printf("%d\n", k - 1);

      /*for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
          System.out.printf("%d", [i][j]);
        }
        System.out.printf("\n");
      }*/
    }
  }

  //深さ優先探索(引数が多くて気持ち悪い) グローバル変数を用いるしかないのか？
  public static boolean dfs(boolean flag, int num, int[][] c, int[][] seen, int x, int y, int h, int w){
    //初手が探索済みの陸もしくは海ならばfalseを返す
    if(flag && (seen[y][x] != 0 || c[y][x] == 0)){
      return false;
    }
    //初手以外で領域外、海、探索済みだった場合trueを返す
    else if( x >= w || y >= h || x < 0 || y < 0 || c[y][x] == 0 || seen[y][x] != 0){
      return true;
    }
    else{
      //陸ならば同一のナンバーで管理する
      seen[y][x] = num;
      for(int _x: dx){
        for(int _y:dy){
          //上下左右斜めで再起で探索
          dfs(false, num, c, seen, x + _x, y + _y, h, w);
        }
      }
      //true
      return true;
    }
  }
}


Measured memory_bytes: 38736
import java.util.*;


public class Main {
    public static void main(String[] args) {
        // 自分の得意な言語で
        // Let's チャレンジ！！
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        String s[]=line.split("",0);
        boolean b=true;
        int count=0;
        for(int i=0;i<s.length;i++){
            if(i==0){
                if(!s[i].equals("A")){
                    b=false;
                break;}
                
            }
            
            if(i!=0){
                if(i>=2&&i<=s.length-2&&(s[i].equals("C"))){
                    count++;
                }
                else{
                    char[] c = s[i].toCharArray();
                    if(!((int)c[0]>96&&(int)c[0]<123)){
                        b=false;
                        break;
                    }
                
                }
            }
                
            
        }
        if(count!=1)b=false;
        if(b)System.out.println("AC");
        else System.out.println("WA");
        
    }
}

Measured memory_bytes: 23636
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int d1 = 1868 * 365 + 9 * 12 + 8;
		int d2 = 1912 * 365 + 7 * 12 + 30;
		int d3 = 1926 * 365 + 12 * 12 + 25;
		int d4 = 1989 * 365 + 12 * 1 + 8;
		while(sc.hasNext()) {
			int y = sc.nextInt();
			int m = sc.nextInt();
			int d = sc.nextInt();
			int t = y * 365 + m * 12 + d;
			if(t < d1) {
				System.out.println("pre-meiji");
			}else if(t < d2) {
				System.out.print("meiji ");
				System.out.printf("%d %d %d\n", y - 1867, m, d);
			}else if(t < d3) {
				System.out.print("taisho ");
				System.out.printf("%d %d %d\n", y - 1911, m, d);
			}else if(t < d4){
				System.out.print("showa ");
				System.out.printf("%d %d %d\n", y - 1925, m, d);
			}else {
				System.out.print("heisei ");
				System.out.printf("%d %d %d\n", y - 1988, m, d);
			}
		}
	}
}



Measured memory_bytes: 26136
for _ in range(int(input())):
    ano = []
    balls = list(map(int, input().split()))
    i = 0
    while balls != sorted(balls):
        if balls[i] > balls[i + 1]:
            ano.append(balls[i + 1])
            del balls[i + 1]
        else:
            i += 1
    print('YES' if ano == sorted(ano) else 'NO')

Measured memory_bytes: 7584
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define repeat(i,a,b) for(int i=(a),i##__end=(b);i<i##__end;i++)
#define repeat_back(i,a,b) for(int i=(b)-1,i##__end=(a);i>=i##__end;i--)
#define mst(a,x) memset((a),(x),sizeof(a))
#define pii pair<int,int>
#define N 1000010
#define mod 2147483647
#define int ll

signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n;
	cin>>n;
	cout<<n*n<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main() {
  int A;
  int B;
  int C;
  int D;

  std::cin >> A >> B >> C >> D;

  int AB;
  int CD;

  AB = A + B;
  CD = C + D;

  if (AB == CD) {
    std::cout << "Balanced" << std::endl;
  } else if (AB > CD) {
    std::cout << "Left" << std::endl;
  } else {
    std::cout << "Right" << std::endl;
  }
  return 0;
}

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

int main() {
    int a, b, c, d;
    cin>>a>>b>>c;
    d = c+b-a;
    if (d < 0)
    {
        cout<<0;
    }
    else
    {
        cout<<d;
    }
    
    
    
    
    
    return 0;    
}

Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

bool used[100001] = {false};
vector<int> from[100001];
vector<int> to[100001];
int p[100001];
int cnt_to[100001];

void dfs(int n){
    queue<int> que;
    used[n] = true;
    for(int i = 0; i < from[n].size(); i++){
        cnt_to[from[n][i]]++;
        if(cnt_to[from[n][i]] == to[from[n][i]].size()){
            cout << from[n][i] << endl;
            p[from[n][i]] = n;
            dfs(from[n][i]);
        }
    }
}

void bfs(int n){
    queue<int> que;
    used[n] = true;
    for(int i = 0; i < from[n].size(); i++){
        cnt_to[from[n][i]]++;
        if(cnt_to[from[n][i]] == to[from[n][i]].size()){
            que.push(from[n][i]);
            p[from[n][i]] = n;
            //cout << "pushed:" << from[n][i] << endl;
        }
    }
    while(!que.empty()){
        int top = que.front(); que.pop();
        used[top] = true;
        for(int i = 0; i < from[top].size(); i++){
            cnt_to[from[top][i]]++;
            if(cnt_to[from[top][i]] == to[from[top][i]].size()){
                p[from[top][i]] = top;
                que.push(from[top][i]);
                //cout << "pushed:" << from[top][i] << endl;
            }
        }
    }
}

int main(){
    int N, M;
    cin >> N >> M;
    for(int i = 0; i < N+M-1; i++){
        int A, B;
        cin >> A >> B;
        to[B].push_back(A);
        from[A].push_back(B);
    }
    int par;
    for(int i = 1; i <= N; i++){
        if(to[i].size() == 0) {
            par = i;
            p[i] = 0;
            break;
        }
    }
    bfs(par);
    for(int i = 1; i <= N; i++){
        cout << p[i] << endl;
    }
}

Measured memory_bytes: 12672
n, q = map(int, input().split())
s = list(input())
quiz = [list(map(int, input().split())) for _ in range(q)]

cnt_list = [0]*n
judge = 0

for i in range(n):
    if s[i] == "A":
        judge = 1
        cnt_list[i] = cnt_list[i-1]
    elif judge == 1 and s[i] == "C":
        judge = 0
        cnt_list[i] = cnt_list[i-1] + 1
    else:
        judge = 0
        cnt_list[i] = cnt_list[i-1]

for i in range(q):
    print(cnt_list[quiz[i][1] - 1] - cnt_list[quiz[i][0]-1])

Measured memory_bytes: 31388
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
int main() {
  int N;
  cin >> N;
  bool t = true;
  REP(i, N) {
    int a;
    cin >> a;
    if (a % 2 == 1) t = false;
  }
  if (t) {
    cout << "second" << endl;
  } else {
    cout << "first" << endl;
  }
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define rep(i,j,k) for(int i=j;i<k;i++)
#define all(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
#define mp make_pair
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
const int  COMMAX = 510000;

long long fac[COMMAX], finv[COMMAX], inv[COMMAX];

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcd(int a,int b){return a*b / gcd(a,b);}
// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < COMMAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

struct UnionFind {
  vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
  vector<int> rank;
  int num;
  UnionFind(int N) : par(N) , rank(N) { //最初は全てが根であるとして初期化
    num = N;
    for(int i = 0; i < N; i++){
      par[i] = i;
      rank[i] = 0;
    }
  }

  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x); //xの根をrx
    int ry = root(y); //yの根をry
    if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
    if(rank[rx] < rank[ry]){
      par[rx] = ry;  
    }else{
      par[ry] = rx;
      if(rank[rx] == rank[ry])rank[rx]++;
    }
    num--;
  }

  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
    return root(x) == root(y);
  }
};

const int MS = 2;
const long long mod[] = {999999937LL, 1000000007LL}, base = 9973;
struct rolling_hash {
    int n;
    vector<long long> hs[MS], pw[MS];
    rolling_hash(){}
    rolling_hash(const string &s) {
        n = s.size();
        for (int i = 0; i < MS; i++) {
            hs[i].assign(n+1,0);
            pw[i].assign(n+1,0);
            hs[i][0] = 0;
            pw[i][0] = 1;
            for (int j = 0; j < n; j++) {
                pw[i][j+1] = pw[i][j]*base%mod[i];
                hs[i][j+1] = (hs[i][j]*base+s[j])%mod[i];
            }
        }
    }

    long long hash(int l, int r, int i) { return ((hs[i][r]-hs[i][l]*pw[i][r-l])%mod[i]+mod[i])%mod[i]; }

    bool match(int l1, int r1, int l2, int r2) {
        bool ret = 1;
        for (int i = 0; i < MS; i++) ret &= hash(l1,r1,i)==hash(l2,r2,i);
        return ret;
    }

    bool match(int l, int r, long long h[]) {
        bool ret = 1;
        for (int i = 0; i < MS; i++) ret &= hash(l,r,i)==h[i];
        return ret;
    }
};

int main(){
  string s;
  cin >> s;
  bool aflag=false;
  bool bflag=false;
  rep(i,0,s.length()){
    if(s[i] =='A'){
      aflag = true;
    }else{
      bflag = true;
    }
  }
  string res = (aflag and bflag)?"Yes":"No";
  cout << res << endl;
  return 0;
}


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

using namespace std;
using ll = long long;
using ii = pair<ll, ll>;

const int MAX { 100010 };
const ll MOD { 1000000007 }, oo { 1LL << 62 };

set<int> adj[MAX];
set<int> blocks[MAX];

class UFDS
{
private:
    std::vector<int> size, ps;

public:
    UFDS(int N) : size(N + 1, 1), ps(N + 1)
    {
        // ps = {0, 1, 2, 3, ..., N}
        std::iota(ps.begin(), ps.end(), 0);
    }

    int find_set(int x) const
    {
        return x == ps[x] ? x : find_set(ps[x]);
    }

    bool same_set(int x, int y)
    {
        return find_set(x) == find_set(y);        
    }

    void union_set(int x, int y)
    {
        if (same_set(x, y))
            return;

        int p = find_set(x);
        int q = find_set(y);

        if (size[p] < size[q])
            std::swap(p, q);

        ps[q] = p;
        size[p] += size[q];
    }

    int getSize(int u) const { return size[u]; }
};

vector<int> solve(ll N)
{
    UFDS ufds(N);

    for (int u = 1; u <= N; ++u)
    {
        for (auto v : adj[u])
            ufds.union_set(u, v);
    }

    vector<int> ans(N + 1, 0);

#ifdef DEBUG
    cout << "--- adj = " << adj[1].size() << ", blocks = " << blocks[1].size() << endl;
#endif
    for (int u = 1; u <= N; ++u)
    {
        for (auto v : adj[u])
            blocks[u].insert(v);
    }

    for (int u = 1; u <= N; ++u)
    {
        auto p = ufds.find_set(u);
        auto s = ufds.getSize(p);

#ifdef DEBUG
    if (u == 1)
        cout << "p = " << p << ", s = " << s << ", adj = " << adj[u].size() << ", blocks = " << blocks[u].size() << endl;
#endif
        ans[u] = (s - 1) - adj[u].size();
    }

    for (int u = 1; u <= N; ++u)
    {
        for (auto v : blocks[u])
            if (ufds.same_set(u, v) and adj[u].count(v) == 0)
                --ans[u];
    }

    return ans;
}

int main()
{
    ios::sync_with_stdio(false);

    int N, M, K;
    cin >> N >> M >> K;

    while (M--)
    {
        int u, v;
        cin >> u >> v;

        adj[u].insert(v);
        adj[v].insert(u);
    }

    while (K--)
    {
        int u, v;
        cin >> u >> v;

        blocks[u].insert(v);         
        blocks[v].insert(u);         
    }

    auto ans = solve(N);

    for (int u = 1; u <= N; ++u)
        cout << ans[u] << (u == N ? '\n' : ' ');

    return 0;
}


Measured memory_bytes: 38912
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  string s;
  cin>>s;
  int ans=0;
  for(int i=0;i<4;i++){
      int a=s[i]-'0';
      if(a==2) ans++;
  }
  cout<<ans<<endl;
  
}

Measured memory_bytes: 256
// 考察　https://twitter.com/tempura_cpp/status/1226506153896493056
// https://twitter.com/kymn_/status/1226504287489912836
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
 
 
template<typename T,T MOD = 1000000007>
struct Mint{
  static constexpr T mod = MOD;
  T v;
  Mint():v(0){}
  Mint(signed v):v(v){}
  Mint(long long t){v=t%MOD;if(v<0) v+=MOD;}
 
  Mint pow(long long k){
    Mint res(1),tmp(v);
    while(k){
      if(k&1) res*=tmp;
      tmp*=tmp;
      k>>=1;
    }
    return res;
  }
 
  static Mint add_identity(){return Mint(0);}
  static Mint mul_identity(){return Mint(1);}
 
  Mint inv(){return pow(MOD-2);}
 
  Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;}
  Mint& operator/=(Mint a){return (*this)*=a.inv();}
 
  Mint operator+(Mint a) const{return Mint(v)+=a;}
  Mint operator-(Mint a) const{return Mint(v)-=a;}
  Mint operator*(Mint a) const{return Mint(v)*=a;}
  Mint operator/(Mint a) const{return Mint(v)/=a;}
 
  Mint operator-() const{return v?Mint(MOD-v):Mint(v);}
 
  bool operator==(const Mint a)const{return v==a.v;}
  bool operator!=(const Mint a)const{return v!=a.v;}
  bool operator <(const Mint a)const{return v <a.v;}
 
  static Mint comb(long long n,int k){
    Mint num(1),dom(1);
    for(int i=0;i<k;i++){
      num*=Mint(n-i);
      dom*=Mint(i+1);
    }
    return num/dom;
  }
};
template<typename T,T MOD> constexpr T Mint<T, MOD>::mod;
template<typename T,T MOD>
ostream& operator<<(ostream &os,Mint<T, MOD> m){os<<m.v;return os;}

Mint<Int> g(Int a, Int b) {
    Mint<Int> res(0);
    ++a, ++b;
    res = res.comb(a+b, b) - Mint<Int>(1);
    return res;
}

int main()
{
    Int r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    Mint<Int> res(0);
    res = g(r2,c2) - g(r2, c1 - 1) - g(r1 - 1, c2) + g(r1-1, c1-1);
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define for1(i,n) for (ll i=0;i<(n);i++)
#define for2(i,m,n) for (ll i=(m);i<(n);i++)
#define for3(i,m,n,d) for (ll i=(m);i<(n);i+=(d))
#define DEBUG 0

string solve()
{
    ll N;
    cin >> N;
    ll a4 = 0;
    ll a2 = 0;
    ll a1 = 0;
    for1(i,N) {
        ll a;
        cin >> a;
        if (a % 4 == 0) {
            a4 += 1;
        }
        else if (a % 2 == 0) {
            a2 += 1;
        }
        else if (a % 1 == 0) {
            a1 += 1;
        }
    }
    if (a4 >= a1) {
        return "Yes";
    }
    if (a2 == 0 && a4 >= a1 - 1) {
        return "Yes";
    }
    return "No";
}

int main()
{
    do {
        cout << solve() << endl;
    } while (DEBUG);
}


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

int main()
{
    int n, level[6];
    double d;

    for( int i = 0; i < 6; i++ )
        level[i] = 0;

    cin >> n;

    for( int i = 0; i < n; i++ )
    {
        cin >> d;
        if( d < 165 )
            level[0]++;
        else if( d < 170 )
            level[1]++;
        else if( d < 175 )
            level[2]++;
        else if( d < 180 )
            level[3]++;
        else if( d < 185 )
            level[4]++;
        else
            level[5]++;
    }

    for( int i = 0; i < 6; i++ )
    {
        cout << i + 1 << ":";
        for( int j = 0; j < level[i]; j++ )
            cout << '*';
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3144
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define br break
#define con continue
#define lcm(n, m) (n * m / gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define repill(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define repll(i, n) repill(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m);i>(int)(n);i--)
#define rev(i, m) revi(i, m, 0)
#define revill(i, m, n) for(ll i=(ll)(m);i>(ll)(n);i--)
#define revll(i, n) revill(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) (n.begin(), n.end())
#define allr(n) (n.rbegin(), n.rend())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数
// __builtin_popcount bitの個数

int main() {
  char c;
  ci(c);
  c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' ? co("vowel") : co("consonant");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
signed main(){
  int N,M; cin>>N>>M;
  vii A(N);
  rep(i,0,M){
    int X,Y; cin>>X>>Y;
    A[X-1].pb(Y-1);
  }
  vector<set<int>> F(N);
  int S,T; cin>>S>>T;
  T--;
  S--;
  F[S].insert(0);
  queue<pii> Q;
  Q.push(mp(S,0));
  int count=0;
  Q.push(mp(-1,-1));
  int ans=-1;
  while(Q.size()>1){
    int X=Q.front().first,Y=Q.front().second;
    if(X==T&&Y==0){
      ans=count/3;
      break;
    }
    Q.pop();
    if(X==-1){
      count++;
      Q.push(mp(-1,-1));
    }
    else{
      rep(i,0,A[X].size()){
        if(!F[A[X][i]].count((Y+1)%3)){
          Q.push(mp(A[X][i],(Y+1)%3));
          F[A[X][i]].insert((Y+1)%3);
        }
      }
    }
  }
  cout<<ans<<endl;
  }




Measured memory_bytes: 24448
#include <bits/stdc++.h>
#define pi pair<int,int>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,a,b) for(int i = a ; i < b;i++)
using namespace std;
void debug(int x){
    cerr<<x<<endl;
}
void debug(vector<int> v){
    for(int i = 0 ; i<v.size(); i++) cout<<v[i]<<" ";
    cout<<"\n";
}
void debug(int *A, int N){
    for(int i = 0 ; i < N;i++) cout<<A[i]<<" ";
    cout<<endl;
}
void scan(vector<int> &h,int N){
    for(int i = 0 ; i < N;i++){
        scanf("%d",&h[i]);
    }
}
int dp[100005];
int main(){
       int N;
       cin>>N;
       vector<int> h(N);
       scan(h,N);
       //dp[i] is the minimum cost incurred to reach i
       dp[0] = 0;
      // debug(h);
       rep(i,1,N){
           //for each i ..you can reach here from i-1 or i-2
           dp[i]=INT_MAX;
        
           if(i-1>=0) dp[i] = min(dp[i-1]+abs(h[i] - h[i-1]),dp[i]);
           if(i-2>=0) dp[i] = min(dp[i],dp[i-2]+abs(h[i]-  h[i-2]));
       }
      // debug(dp,N); 
       cout<<dp[N-1]<<"\n";
}

Measured memory_bytes: 1024
import java.util.*;
public class Main {
   public static void main(String args[]){
      //declaration and initialization
      Scanner sc = new Scanner(System.in);
      String input[];
      
      //variables for each problem
      String answer;
      int a;
      int b;
      int c;
      
      //reading the intput
      input = sc.nextLine().split(" ",0);
      
      //assginment
      a = Integer.parseInt(input[0]);
      b = Integer.parseInt(input[1]);
      c = Integer.parseInt(input[2]);
      
      //evaluation
      if(a >= b){
         answer = "No";
      }else if(b >= c){
         answer = "No";
      }else{
         answer = "Yes";
      }
      
     //output
     System.out.println(answer);
      
      
      
   }//main
      
}//class

Measured memory_bytes: 26096
n=int(input())
a=list(map(int,input().split()))
q=int(input())
A=[0]*(10**5+1)
for i in a:
    A[i]+=1
a_sum=sum(a)
for j in range(q):
    b,c=map(int,input().split())
    x=(c-b)*A[b]
    a_sum+=x
    A[c]=A[c]+A[b]
    A[b]=0
    print(a_sum)

Measured memory_bytes: 20956
h,w=map(int,input().split())
#a=[[j for j in input()] for i in range(h)]

lis=[]
for i in range(h):
#     a=list(map(str,input().split()))
    a = list(input())
    if '#' in a:
        lis.append(a)
lis2=list(zip(*lis))
lis_ans=[]
for i in range(w):
    if '#' in lis2[i]:
        lis_ans.append(lis2[i])
lis_ans = list(zip(*lis_ans))
# print(list(zip(*lis_ans)))
# print(lis_ans)
for i in range(len(lis_ans)):
    print(''.join(lis_ans[i]))

Measured memory_bytes: 38384
p = 10**9 + 7
n,m = list(map(int, input().split()))
a = set()
for _ in  range(m):
    a.add(int(input()))

dp = [0 for i in range(n+1)]
dp[0] = 1

for i in range(1, n+1):
    if i not in a:
        dp[i] = dp[i-1] + dp[i-2]
        dp[i] %= p
    else:
        dp[i] = 0

print(dp[-1])

Measured memory_bytes: 56408
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define EPS 1e-9
#define first fst
#define second scd

#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long


signed main(){
  int s;
  cin>>s;
  int i,j,k;
  int a,b,c,d;
  a=s/1000;b=(s%1000)/100;c=(s%100)/10;d=s%10;
  char x,y,z;
  x=y=z='+';
  int sum=a+b+c+d;
  rep(i,2){
    if(i==1){sum-=b*2;x='-';}
    rep(j,2){
      if(j==1){sum-=c*2;y='-';}
      rep(k,2){
	if(k==1){sum-=d*2;z='-';}
	//	cout<<sum<<endl;
	if(sum==7) break;
	if(k==1){sum+=d*2; z='+';}
      }
      if(sum==7) break;
      if(j==1){sum+=c*2; y='+';}
    }
    if(sum==7) break;
  }
  cout<<a<<x<<b<<y<<c<<z<<d<<"=7"<<endl;
  

  return 0;
}








Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
int N, M;
bool red[100010];
int ball[100010];
int ans;
int main() {
	red[1] = true;
	std::cin >> N >> M;
	for (int i = 1; i <= N; i++) {
		ball[i]++;
	}
	for (int i = 0; i < M; i++) {
		int x, y;
		std::cin >> x >> y;
		ball[x]--;
		ball[y]++;
		if (red[x]) {
			red[y] = true;
			if (ball[x] == 0) {
				red[x] = false;
			}
		}
	}
	for (int i = 1; i <= N; i++) {
		if (red[i])ans++;
	}
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)   for(signed i=0; i<n; i++)
#define FOR(i, k, n)    for(signed i=k; i<n; i++)
#define yn(b)   cout << ((b)?"Yes":"No") << endl
#define YN(b)   cout << ((b)?"YES":"No") << endl
#define pr(r)   cout << r << endl
#define min(x,y)    (x<y)?x:y
#define max(x,y)    (x>y)?x:y
#define ll  long long
int main(void){
    int N;
    cin >> N;
    int A[N];
    int i;
    rep(i, N) cin >> A[i];
    int B[N];
    rep(i, N) B[A[i]-1] = i + 1;
    rep(i, N) cout << B[i] << " ";
}

Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>

#define rrep(i,n) for(int i=n;i>0;i--)
#define RREP(i,a,n) for(int i=n;i>a;i--)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,a,n) for(int i=a;i<n;i++)
#define all(a) (a).begin(),(a).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))

#define fs first
#define sc second

#define MOD 1000000007
#define INF 1LL<<55

#define show(...) cerr<<#__VA_ARGS__<<" = ";_DEBUG(__VA_ARGS__)

using namespace std;

using ll = long long;

template<typename T1,typename T2> using P = pair< T1, T2 >;
using Pii = P<int,int>;
using Pll = P<ll,ll>;
using Pdd = P<double,double>;

template<typename T> using V = vector< T >;
using Vi = V<int>;
using Vll = V<ll>;
using Vs = V<string>;

template<typename T1,typename T2> using M = map< T1, T2>;
using Mii = M<int, int>;
using Mll = M<ll, ll>;
using Msi = M<string, int>;

template<class T> istream& operator >>(istream &is, vector<T> &v){for(T &e:v)is>>e;return is;}
template<class T> ostream& operator <<(ostream &os, vector<T> v){os<<"{";for(T &e:v)os<<e<<(v.size()-(int)(&e-&v[0])>1?", ":"");os<<"}";return os;}

void _DEBUG(){}
template<typename H,typename... T> void _DEBUG(H a,T...b){cerr<<a<<(sizeof...(b)?",":"\n");_DEBUG(b...);}

inline void in(){}
template<typename H,typename... T>void in(H &a, T&... b){cin>>a;in(b...);}
inline void out(){}
template<typename H,typename... T> void out(H a, T... b){cout<<a<<(sizeof...(b)?" ":"\n");out(b...);}

template<class T> void resz(int n,T& v){v.resize(n);}
template<class H,class... T> void resz(int n,H& a,T&... b){a.resize(n);resz(n,b...);}

// please declaration dx[8], dy[8]
#define DX {-1,0,1,0,-1,-1,1,1}
#define DY {0,-1,0,1,-1,1,1,-1}
#define DX2 {-1,0,1,0}
#define DY2 {0,-1,0,1}

signed main() {
  string s;

  in(s);
  if (s.length() == 2) {
    out(s);
  } else {
    reverse(all(s));
    out(s);
  }


  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

vector<int> graph[250000];
bool besucht[250000];
ll query[250000];
ll res[250000];

void dfs( int p, ll sum ){
	// if( besucht[p] ) return;
	besucht[p] = true;
	res[p] = sum;
	for( auto next : graph[p] ){
		dfs( next, sum+query[next] );
	}
}

int main(){
	int n, q; cin >> n >> q;
	for( int i = 0; i < n-1; ++i ){
		int a, b; cin >> a >> b; --a; --b;
		graph[a].push_back(b);
	}
	for( int i = 0; i < q; ++i ){
		int p; ll x; cin >> p >> x;
		query[p-1] += x;
	}
	dfs(0, query[0]);
	for( int i = 0; i < n; ++i ){
		cout << res[i] << ' ';
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 24448
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;

string f(const char *p){
  char prev = *p;
  int cnt = 0;
  string ret;

  do{
    if(*p == prev){
      cnt++;
    }else{
      char buff[10];
      sprintf(buff,"%d%c",cnt,prev);
      ret += buff;
      prev = *p;
      cnt = 1;
    }
  }while(*p++ != '\0');

  return ret;
}

int main(){
  int n;
  string str;
  while(cin >> n, n){
    cin >> str;
    REP(i,n) str = f(str.c_str());
    cout << str << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>


int main(){
	
	int n,a[101],d,x,i,sum=0,j;
	
	scanf("%d\n%d %d",&n,&d,&x);
	
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
		for(j=0;j<d;j=j+a[i]){
			sum=sum+1;
		}
	}
	
	printf("%d\n",sum+x);
	
	return 0;
}


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

int main(){
  int N, M; cin >> N >> M;
  int A[1010]={};
  int sum=0;
  for(int i=0; i<N; i++){
    cin >> A[i];
    sum+=A[i];
  }
  int c=0;
  for(int i=0; i<N; i++){
    if(4*M*A[i]>=sum) c++;
  }
  if(c>=M) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

template <typename T> struct SegmentTree {
  struct Node {
    T v;
    Node(T v) : v(v) {}

    Node operator*(const Node &r) const {
      return Node(min(v, r.v));
    }
  };

  Node e = Node((1ll << 31) - 1);
  size_t sz;
  vector<Node> seg;

  SegmentTree(int n) : sz(1 << (32 - __builtin_clz(n - 1))), seg(2 * sz - 1, e) {}

  void update(int k, const Node &x) {
    k += sz - 1;
    seg[k] = x;
    while (k) {
      k = (k - 1) / 2;
      seg[k] = seg[2 * k + 1] * seg[2 * k + 2];
    }
  }

  Node query(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) return e;
    if (a <= l && r <= b) return seg[k];
    return query(a, b, 2 * k + 1, l, (l + r) / 2) * query(a, b, 2 * k + 2, (l + r) / 2, r);
  }

  void update(int k, T x) {
    update(k, Node(x));
  }

  T query(int a, int b) {
    return query(a, b, 0, 0, sz).v;
  }
};

int main() {
  int n, q;
  cin >> n >> q;

  SegmentTree<int> seg(n);
  while (q--) {
    int c, x, y;
    cin >> c >> x >> y;

    if (c) {
      cout << seg.query(x, y + 1) << endl;
    } else {
      seg.update(x, y);
    }
  }
}

Measured memory_bytes: 3920
n = gets.chomp.to_i
t,a = gets.strip.split.map(&:to_i)
hs = gets.strip.split.map(&:to_i)
ans = 0
most_near_abs = 10000
hs.each.with_index(1) do |h,i|
  th = (t - h*0.006)
  abs = (a - th).abs
  if abs < most_near_abs
    ans = i
    most_near_abs = abs
  end
end
puts ans


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

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


Measured memory_bytes: 3540
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    bool sw = 0;
    for(int i = 0; i < s.size(); i++)
        if(s[i] == '7')
            sw = 1;
    if(sw)
        cout << "Yes\n";
    else
        cout << "No\n";
	return 0;
}


Measured memory_bytes: 3624
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAX 2000000
#define INFTY (1<<30)
int H,A[MAX+1];
void maxHeapify(int i){
  int l,r,largest;
  l=2*i;
  r=2*i+1;
  if(l<=H && A[l]>A[i])largest=l;
  else largest=i;
  if(r<=H && A[r]>A[largest])largest=r;
  if(largest!=i){
    swap(A[i],A[largest]);
    maxHeapify(largest);
  }
}
int ext(){
  int maxv;
  if(H<1){
    return -INFTY;
  }
  maxv=A[1];
  A[1]=A[H--];
  maxHeapify(1);
  return maxv;
}
void incKey(int i,int key){
  if(key<A[i])return;
  A[i]=key;
  while(i>1&&A[i/2]<A[i]){
    swap(A[i],A[i/2]);
    i=i/2;
  }
}
 
void ins(int key){
  H++;
  A[H]=-INFTY;
  incKey(H,key);
}
 
int main(){
  int key;
  char com[10];
  while(1){
    scanf("%s",com);
    if(com[0]=='e' && com[1]=='n')break;
    if(com[0]=='i'){
      scanf("%d",&key);
      ins(key);
    }
    else{printf("%d\n",ext());
  }
  }
  return 0;
}


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

int main()
{
  int n;
  cin >> n;
  while (n--) {
    string s;
    cin >> s;

    vector<int> v;
    for (unsigned int i = 0; i < s.size(); ++i)
      v.push_back(s[i]-'0');

    int turn = 0;
    while (v.size() >= 2) {
      int a = v.back();
      v.pop_back();
      int b = v.back();
      v.pop_back();

      int sum = a + b;
      if (sum >= 10)
	v.push_back(sum/10);
      v.push_back(sum%10);
      ++turn;
    }

    if (turn & 1)
      cout << "Fabre wins." << endl;
    else
      cout << "Audrey wins." << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <algorithm>

using namespace std;

int main( void ) {
	long long A[3];
	scanf("%lld %lld %lld", &A[0], &A[1], &A[2]);
	
	sort(A, A+3);
	
	printf("%lld\n", A[0] * A[1] * ((A[2]+1)/2 - A[2]/2));
	
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int n,m,a,sum;
int main()
{
    cin>>a;
    for(int i=1;i<=a;i++)
    {
    	cin>>n>>m;
    	sum=sum+(m-n+1);
	}
	cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
const config = {
    input: '/dev/stdin',
    newline: '\n'
};

const line = require('fs').readFileSync(config.input, 'utf-8').split(config.newline);
const data = line[1].split(' ').map(x => [parseInt(x[1]), x]);

const bswap = arr => {
    if (arr.length === 1) return arr;
    const f = arr[0];
    const s = arr[1];
    const tl = arr.slice(2);
    if (f[0] > s[0]) {
        return [s, ...bswap([f, ...tl])];
    } else {
        return [f, ...bswap([s, ...tl])];
    }
};

const bsort = arr => {
    if (arr.length === 0) return [];
    const swapped = bswap(arr);
    const hd = swapped.slice(0, swapped.length-1);
    const tl = swapped[swapped.length-1];
    return [...bsort(hd), tl];
};

const ssort = arr => {
    if (arr.length === 0) return [];
    const min = arr.reduce((acc, x) => acc[0] > x[0] ? x : acc);
    const hd = arr[0];
    const filter = arr.slice(1).map(x => x[1] === min[1] ? hd : x);
    return [min, ...ssort(filter)];
};

const isStable = (bsort, arr) => arr.every((x, i) => bsort[i][1] === x[1]);

const bsorted = bsort(data);
const ssorted = ssort(data);

console.log(bsorted.map(x => x[1]).join(' '));
console.log('Stable');
console.log(ssorted.map(x => x[1]).join(' '));
console.log(isStable(bsorted, ssorted) ? 'Stable' : 'Not stable');


Measured memory_bytes: 18152
l = list(input())
for i in range(8):
  s = int(l[0])
  b = bin(i)[2:].zfill(3)
  op = ["", "", ""]
  for j in range(len(b)):
    if b[j] == "0":
      s += int(l[j+1])
      op[j] = "+"
    else:
      s -= int(l[j+1])
      op[j] = "-"
  if s == 7:
    print(l[0]+op[0]+l[1]+op[1]+l[2]+op[2]+l[3]+"=7")
    break
  
  
  


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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}

//最小公倍数
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}

//階乗
ll ka(ll i){
    ll res=1;
    while(i>0){
        res=res*i;
        i--;
    }
    return res;
}
 
//ncr
ll ncr(ll x,ll y){
    ll a = x;
    ll b = 1;
    if(y>(x/2)){
        y=x-y;
    }
    for(ll i=1;i<y;i++){
        a*=x-i;
        b*=i+1;
    }
    return a/b;
}

//フィボナッチ数列
ll f(ll x){
    ll dp[x+1];
    dp[1]=1;
    dp[2]=1;
    for(ll i=3;i<=x;i++){
        dp[i]=dp[i-1]+dp[i-2];
    }
    return dp[x];
}

//char->int
int ctoi(char c){
    return c-'0';
}



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

    char x = s[k-1];

    for(int i=0;i<n;i++){
        if(s[i]!=x){
            cout << '*' ;
        }else{
            cout << s[i] ;
        }
    }
    cout << endl;
}


Measured memory_bytes: 256