akhauriyash/Code-Regression huggingface dataset:
while 1:
    n=input()
    if n==0:break
    N=range(n)
    T=N[:]
    M=range(input())
    S=[map(int,raw_input().split(","))for i in M]
    S=sorted(S,key=lambda x:x[2])        
    a=0
    while S:
        x,y,w=S.pop(0)
        b,c=T[x],T[y]
        if b==c:continue
        for i in N:
            if T[i]==b:T[i]=c
        a+=w/100-1
    print a

Measured memory_bytes: 4996
#include<stdio.h>

int main() {
	long long int n, d, x, y;
	long long int num = 0;
	scanf("%lld", &n);
	scanf("%lld", &d);
	for (int i = 0;i < n;i++) {
		scanf("%lld", &x);
		scanf("%lld", &y);
		if (d * d >= x * x + y * y)
		{
			num++;
		}
	}
	printf("%lld", num);
	return 0;
}

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

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

  // vector<int> b = {50, 40, 30, 20, 10};
  // cout << *(lower_bound(b.rbegin(), b.rend(), 1)) << endl;
  // return 0;

  int N; cin >> N;
  deque<int> a;

  rep(i, N) {
    int A; cin >> A;

    int p = lower_bound(a.begin(), a.end(), A) - a.begin();
    if(p == 0) {
      a.push_front(A);
    } else {
      a[p-1] = A;
    }
  }

  cout << a.size() << endl;
}


// 1,2


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <stdio.h>

using namespace std;

int main()
{
    string x;
    cin >> x;
    if (x == "Sunny")
        cout << "Cloudy";
    else if (x == "Cloudy")
        cout << "Rainy";
    else if (x == "Rainy")
        cout << "Sunny";
}

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

#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define VPII vector<PII>
#define LD long double

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout << fixed << setprecision(11);
    cerr << fixed << setprecision(6);
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << max(max(a*c,a*d),max(b*c,b*d)) << endl;
}


Measured memory_bytes: 3656
#include <iostream>

using namespace std;

int main() {

  int l;
  int m,n;

  int saving;
  int success;


  while(cin >> l) {

    if(l==0) break;

    saving=0;
    success=0;

    for(int i=0;i<12;i++) {

      cin >> m >> n;

      saving+=m-n;

      if(saving>=l) {
	
	if(success==0) success=i+1;

      }

    }

    if(success>0) cout << success << endl;
    else cout << "NA" << endl;
    
  }

  return 0;

}

Measured memory_bytes: 0
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ENDL '\n'
#define print(i) std::cout << (i) << '\n'

#define int long long // at least int64 > 9*10^18
#define all(v) (v).begin(), (v).end()
/* libraries */

#define dump1(v) for(auto i:v) std::cout << i << ' '; std::cout << "\n";
#define dump2(v) for(auto i:v) { for(auto j:i) std::cout << j << ' '; std::cout << "\n"; }


struct Edge
{
	int a,b,c;
	Edge(int a,int b,int c) : a(a),b(b),c(c) {}
	bool operator<(const Edge e)const{ return c<e.c; }
};
using Graph = std::vector<std::vector<Edge> >;
using n_node = std::pair<int, int>; // cost, int
struct Dijkstra
{
	const int INF = 1e16;
	std::vector<int> dist;
	Dijkstra(Graph& g, int s) : dist(g.size(),INF) {
		std::priority_queue<n_node,std::vector<n_node>,std::greater<n_node> > next;
		next.emplace(0,s);
		while(!next.empty()) {
			auto t = next.top(); next.pop();
			int i=t.second;int cost=t.first;
			if(dist[i]!=INF) continue;
			dist[i] = cost;
			for(auto e:g[i]) {
				next.emplace(cost+e.c,e.b);
			}
		}
	}
};

signed main() {
	int n,m,s,t;
	std::cin >> n >> m >> s >> t;
	s--;t--;
	Graph ga(n);
	Graph gb(n);
	rep(i,m) {
		int u,v,a,b;
		std::cin >> u >> v >> a >> b;
		u--;v--;
		ga[u].emplace_back(u,v,a); ga[v].emplace_back(v,u,a);
		gb[u].emplace_back(u,v,b); gb[v].emplace_back(v,u,b);
	}
	Dijkstra da(ga,s),db(gb,t);

	std::vector<int> min_reduce(n);
	int min = da.dist[n-1]+db.dist[n-1];
	min_reduce[n-1] = min;
	for(int i=n-2;i>=0;i--) {
		min = std::min(min,da.dist[i]+db.dist[i]);
		min_reduce[i] = min;
	}

	const int start = 1e15;

	rep(i,n) print(start-min_reduce[i]);

	return 0;
}


Measured memory_bytes: 24868
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int N, M, K;
int D[16];
int v[110][110];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> M >> K;
  for (int i = 0; i < M; i++) {
    cin >> D[i];
    D[i]--;
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < K; j++) {
      cin >> v[i][j];
      v[i][j]--;
    }
  }

  int dist[1 << M];
  memset(dist, -1, sizeof(dist));
  dist[(1 << M) - 1] = 0;
  queue<int> que;
  que.emplace((1 << M) - 1);
  while (!que.empty()) {
    int curr = que.front(); que.pop();
    for (int $ = 0; $ < K; $++) {
      int next = 0;
      for (int i = 0; i < M; i++) {
        if (!(curr >> i & 1)) continue;
        int to = v[D[i]][$], id = -1;
        for (int j = 0; j < M; j++) {
          if (D[j] == to) id = j;
        }
        if (id < 0) continue;
        next |= 1 << id;
      }
      if (dist[next] >= 0) continue;
      dist[next] = dist[curr] + 1;
      que.emplace(next);
    }
  }
  cout << dist[0] << endl;

  return 0;
}


Measured memory_bytes: 3576
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#include<iomanip>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const ll INF=1e18;


int main()
{
    ll a,b,k;
    cin>>a>>b>>k;
    if(a>=k)
    {
        a-=k;

    }
    else
    {
        if(b>=(k-a))
        {
            b-=(k-a);
        }
        else
        {
            b=0;
        }
        a=0;
        
    }
    
    cout<<a<<" "<<b;

}

Measured memory_bytes: 256
// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = int64_t;
using ull = uint64_t;
using PLL = pair<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace init__ {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
// #include "../debug/debug.cpp"
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

void input(V<ll> &v) { for(auto &&ele : v) cin >> ele; }

int main() {
    ll N;
    cin >> N;
    V<ll> A(N), B(N), C(N - 1);
    input(A);
    input(B);
    input(C);
    for(auto &&ele : A) ele--;
    ll ans = 0;
    ll pre = -2;
    for(ll i = 0; i < N; i++) {
        ans += B[A[i]];
        if(pre + 1 == A[i]) ans += C[pre];
        pre = A[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;

int main() {
  int n, x, i = 0;
  scanf("%d", &n);
  char com[15];
  list<int> v;

  rep(i, n) {
    scanf("%s", &com);
    if (com[0] == 'i') {
      scanf("%d", &x);
      v.push_front(x);
    }
    else if (com[6] == 'F') {
      v.pop_front();
    }
    else if (com[6] == 'L') {
      v.pop_back();
    }
    else if (com[0] == 'd') {
      scanf("%d", &x);
      for(list<int>::iterator it = v.begin(); it != v.end(); it++) {
        if (*it == x) {
          v.erase(it);
          break;
        }
      }
    }
  }

  for(list<int>::iterator it = v.begin(); it != v.end(); it++) {
    if (i++) printf(" ");
    printf("%d", *it);
  }
  printf("\n");

  
  return 0;
}


Measured memory_bytes: 34388
#include<bits/stdc++.h>
#define int long long
const int inf=1145141919ll;
const int mod=1000000007ll;
const int dd[]={0,-1,0,1,0};
using namespace std;
int n,m,k;
int p[50];
signed main(){
	int i,j;
	cin>>n;
	for(i=0;i<n;i++)
		cin>>p[i];
	int ans=0,u=0;
	for(i=0;;i++){
		if(i==n)
			i=0;
		if(p[i]>=n){
			int x=p[i]/n;
			ans+=x;
			p[i]=p[i]%n;
			for(j=0;j<n;j++)
				if(j!=i)
					p[j]+=x;
			u=0;
		}else
			u++;
		if(u==50)
			break;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
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 (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

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

    int x,y;
    cin >> x >> y;
    rep(i,x+1){
        if(i*2+(x-i)*4==y)Yes
    }
    No


    return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
#ifdef _MSC_VER
inline unsigned int __builtin_popcount(unsigned int x) { return __popcnt(x); }
#endif // _MSC_VER
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N;
string X;
int cnt[201010];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> X;

	rep(i, 1, 201010) {
		int pp = __builtin_popcount(i);
		cnt[i] = cnt[i % pp] + 1;
	}

	reverse(all(X));

	int cn = 0;
	rep(i, 0, N) if (X[i] == '1') cn++;

	int tot1 = 0, p1 = 1;
	int tot2 = 0, p2 = 1;
	rep(i, 0, N) {
		if (X[i] == '1') {
			tot1 = (tot1 + p1) % (cn + 1);
			if (2 <= cn) tot2 = (tot2 + p2) % (cn - 1);
		}

		p1 = (p1 * 2) % (cn + 1);
		if (2 <= cn) p2 = (p2 * 2) % (cn - 1);
	}

	vector<int> ans;
	p1 = 1;
	p2 = 1;
	rep(i, 0, N) {
		if (X[i] == '1') {
			if (cn == 1) {
				ans.push_back(0);
			}
			else {
				int x = (tot2 - p2 + cn - 1) % (cn - 1);
				ans.push_back(cnt[x] + 1);
			}
		}
		else {
			int x = (tot1 + p1 + cn + 1) % (cn + 1);
			ans.push_back(cnt[x] + 1);
		}

		p1 = (p1 * 2) % (cn + 1);
		if (2 <= cn) p2 = (p2 * 2) % (cn - 1);
	}

	reverse(all(ans));
	rep(i, 0, N) printf("%d\n", ans[i]);
}







Measured memory_bytes: 5236
import java.util.*;
import java.util.Map.Entry;
 
class Main {
	 static int mod =  (int) (Math.pow(10,9)+7);
//	 static int mod = 998244353;
   public static void main(String[] args) {
	   
       Scanner sc = new Scanner(System.in);
       int[] b=new int[9];
       for(int i=0;i<9;i++){
    	   b[i]=sc.nextInt();
       }
       int  N = sc.nextInt();
       boolean[] m=new boolean[9];
       for(int i=0;i<N;i++) {
    	   int tmp=sc.nextInt();
    	   for(int j=0;j<9;j++) {
    		   if(tmp==b[j]) {
    			   m[j]=true;
    		   }
    	   }
       }
       String ans="No";
       if(m[0]&&m[1]&&m[2] ||
    	    	m[3]&&m[4]&&m[5] ||
    	    	m[6]&&m[7]&&m[8] ||
    	    	m[0]&&m[3]&&m[6] ||
    	    	m[1]&&m[4]&&m[7] ||
    	    	m[2]&&m[5]&&m[8] ||
    	    	m[0]&&m[4]&&m[8] ||
    	    	m[2]&&m[4]&&m[6] ) {
    	   ans="Yes";
       }
       System.out.println(ans);
   }
}

Measured memory_bytes: 22996
N = int(input())
d = list(map(int, input().split()))
TTL = 0
TTL_odd = 0

for i in range(0, N):
	for j in range(0, N):
		TTL += d[i]*d[j]
		if i == j:
			TTL_odd += d[i]*d[j]
			
print(int((TTL-TTL_odd)/2))

Measured memory_bytes: 3064
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.lang.StringBuilder
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val o = sc.nextLine()
    val e = sc.nextLine()
    val s = StringBuilder()
    for (i in e.indices) {
        s.append(o[i])
        s.append(e[i])
    }
    if (o.length != e.length) {
        s.append(o.last())
    }
    println(s.toString())
}

fun main(args: Array<String>) {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

Measured memory_bytes: 31264
#include <iostream>
#include <string>

using namespace std;

int convert(char n) {
    switch (n) {
    case 'I': return 1;
    case 'V': return 5;
    case 'X': return 10;
    case 'L': return 50;
    case 'C': return 100;
    case 'D': return 500;
    case 'M': return 1000;
    default: return 0;
    }
}

int main(void) {
    string str;
    while (true) {
        int n = 0;
        cin >> str;
        if (cin.eof()) break;
        for (int i = 0, len = str.size(); i < len; i++) {
            int a = convert(str[i]), b = convert(str[i + 1]);
            if (a < b && i != len - 1) {
                n -= a;
            } else {
                n += a;
            }
        }
        cout << n << endl;
    }
    return 0;
}

Measured memory_bytes: 1180
// Example program
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    
    ll n;
    cin >> n;
    ll s1 = pow (n,2);
    ll s2 = pow (n,3);
    cout << n + s1 + s2 << endl;
      
}


Measured memory_bytes: 4104
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

//Alien's Counting
public class Main{

	Set<Integer>[] e, rev, in, out;
	int N, M;
	long MOD = 1000000007;
	
	int[] scc;
	boolean[] u;
	List<Integer> list;
	
	long[][] dp;
	
	void dfs(int k){
		u[k] = true;
		for(int v:e[k])if(!u[v])dfs(v);
		list.add(k);
	}
	void rdfs(int k, int id){
		u[k] = true;
		scc[k] = id;
		for(int v:rev[k])if(!u[v])rdfs(v, id);
	}

	long get(int k){
		if(dp[k][0]!=-1)return (dp[k][0]+dp[k][1])%MOD;
		if(out[k].isEmpty()){
			dp[k][0] = dp[k][1] = 1;
			return 2;
		}
		dp[k][0] = dp[k][1] = 1;
		for(int v:out[k]){
			dp[k][1]*=get(v);
			dp[k][1]%=MOD;
			dp[k][0]*=dp[v][0];
			dp[k][0]%=MOD;
		}
		return (dp[k][0]+dp[k][1])%MOD;
	}
	
	@SuppressWarnings("unchecked")
	void run(){
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		M = sc.nextInt();
		e = new Set[N];
		rev = new Set[N];
		for(int i=0;i<N;i++){
			e[i] = new HashSet<Integer>();
			rev[i] = new HashSet<Integer>();
		}
		while(M--!=0){
			int s = sc.nextInt()-1, t = sc.nextInt()-1;
			e[s].add(t);
			rev[t].add(s);
		}
		list = new ArrayList<Integer>();
		u = new boolean[N];
		for(int i=0;i<N;i++)if(!u[i])dfs(i);
		Arrays.fill(u, false);
		int ID = 0;
		scc = new int[N];
		for(int i=list.size()-1;i>=0;i--){
			int j = list.get(i);
			if(u[j])continue;
			rdfs(j, ID);
			ID++;
		}
		in = new Set[ID];
		out = new Set[ID];
		for(int i=0;i<ID;i++){
			in[i] = new HashSet<Integer>();
			out[i] = new HashSet<Integer>();
		}
		for(int i=0;i<N;i++){
			for(int v:rev[i]){
				if(scc[i]==scc[v])continue;
				out[scc[i]].add(scc[v]);
				in[scc[v]].add(scc[i]);
			}
		}
		dp = new long[ID][2];
		for(long[]d:dp)Arrays.fill(d, -1);
		long res = 1;
		for(int i=0;i<ID;i++)if(in[i].isEmpty()){
			res*=get(i);
			res%=MOD;
		}
		System.out.println(res);
	}

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

Measured memory_bytes: 13000
using System;
using System.Linq;

namespace _0544
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
                if (x[0] == 0 && x[1] == 0)
                {
                    break;
                }
                int[] a = new int[x[0]];
                for (int i = 0; i < x[0]; i++)
                {
                    a[i] = int.Parse(Console.ReadLine());
                }
                int now = 0;
                int ret = 1;
                while (true)
                {
                    now += int.Parse(Console.ReadLine());
                    if (now >= x[0] - 1)
                    {
                        break;
                    }
                    now += a[now];
                    if (now >= x[0] - 1)
                    {
                        break;
                    }
                    ret++;
                }
                for (int i = 0; i < x[1] - ret; i++)
                {
                    Console.ReadLine();
                }
                Console.WriteLine(ret);
            }
        }
    }
}

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

#define ll long long
#define ff first
#define ss second
#define pb push_back

using namespace std;

const int N  = 1e6 + 69;

double n;

double ans[309][309][309];

int cnt[3];

double dfs(int a,int b,int c){

        if(a+b+c == 0) return 0.0;

        if(ans[a][b][c] != -1) return ans[a][b][c];

        double p = n/(double)(a+b+c);
        double res = 0;

        if(a){
                res += (dfs(a-1,b,c)+p)*a/(a+b+c);
        }

        if(b){
                res += (dfs(a+1,b-1,c)+p)*b/(a+b+c);
        }

        if(c){
                res += (dfs(a,b+1,c-1)+p)*c/(a+b+c);
        }

        return ans[a][b][c] = res;
}

int main(){

        cin >> n;
        for(int i = 1; i <= n; i++){
                int x;
                cin >> x;
                cnt[x]++;
        }

        for(int i = 0 ; i <= 305; i++)for(int j = 0 ; j <= 305; j++)for(int t = 0 ; t <= 305; t++) ans[i][j][t] = -1;


        printf("%0.10f",dfs(cnt[1],cnt[2],cnt[3]));

}


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

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

int main()
{
	int a,aa,b,bb,c,cc;
	while(cin>>a>>aa>>b>>bb>>c>>cc,a) 
	{
		int x=1,y=1,z=1;
		long long xx=0,yy=0,zz=0,ans=0;

		do {
			x=a*x%aa;
			xx++;
		} while(x!=1);
		do {
			y=b*y%bb;
			yy++;
		} while(y!=1);
		do {
			z=c*z%cc;
			zz++;
		} while(z!=1);

		ans=xx*yy/gcd(xx,yy);
		ans=ans*zz/gcd(ans,zz);

		cout<<ans<<endl;

	}
  return 0;
}

Measured memory_bytes: 1156
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
const int C=100001;

int n, k, dp[C], a[101];

int main(){
	int i, j;
	scanf ("%d %d", &n, &k);
	dp[0]=0;
	for (i=0;i<n;i++)	scanf ("%d", &a[i]);
	
	for (i=0;i<=k;i++){
		for (j=0;j<n;j++){
			if (i>=a[j]&&dp[i-a[j]]==0)	dp[i]=1;
		}
	}
	
	if (dp[k]==0)	printf ("Second");
	else printf ("First");
	
return 0;}

Measured memory_bytes: 512
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))
 
using namespace std;
 
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
 
const ll mod=1e9+7;

bool dp[100100];

int main(){
    ll n,k;
    cin >> n>>k;
    vector<ll> a(n);
    rep(i,n){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    for(ll i=0;i<=k;i++){
        bool ok=false;
        rep(j,n){
            if(i-a[j]<0){
                continue;
            }
            if(!dp[i-a[j]]){
                ok=true;
                break;
            }
        }
        if(ok) dp[i]=true;
    }
    if(dp[k]) cout << "First" << endl;
    else cout << "Second" << endl;
    return 0;
} 

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

char c[4] = {'i', 'x', 'c', 'm'};
int Calc(string s);
void Convert(int num);

int main(void){
	int n;
	cin >> n;
	for(int i=0; i<n; i++){
		string s1, s2;
		cin >> s1 >> s2;

		int num1 = Calc(s1);
		int num2 = Calc(s2);

		Convert(num1 + num2);
	}


	return 0;
}

int Calc(string s){
	int num = 0;
	int set = 1;
	for(int i=0; i<s.size(); i++){
		if(s[i] >= '2' && s[i] <= '9'){
			set = s[i] - '0';
		}else{
			if(s[i] == 'm'){
				num += 1000*set;
			}else if(s[i] == 'c'){
				num += 100*set;
			}else if(s[i] == 'x'){
				num += 10*set;
			}else if(s[i] == 'i'){
				num += set;
			}
			set = 1;
		}
	}
	return num;
}

void Convert(int num){
	int out[4];
	for(int i=0; i<4; i++){
		out[i] = 0;
	}
	for(int i=0; i<4; i++){
		int t = num % 10;
		if(t != 0){
			out[i] = t;
		}
		num/=10;
	}

	for(int i=3; i>=0; i--){
		if(out[i] != 0){
			if(out[i] > 1)cout << out[i];
			cout << c[i];
		}
	}
	cout << endl;
}

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


public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] str = br.readLine().split(" ");
		double a = Double.parseDouble(str[0]);
		double b = Double.parseDouble(str[1]);
		double C = Double.parseDouble(str[2]);

		double S = 0.5 * a * b * Math.sin(Math.toRadians(C));
		double L = a + b + Math.sqrt(a*a + b*b - 2*a*b*Math.cos(Math.toRadians(C)));
		double h = b * Math.sin(Math.toRadians(C));

		System.out.println(S + "\n" + L + "\n" + h);
	}
}

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

int main() {
  int N, a = 0, b = 0 ,c = 0, d = 0, e;
  cin >> N;
  
  for (int i = 0; i < N; i++){
    string A;
    cin >> A;
    if (A == "P"){
    	a = 1;
    }
    
    if (A == "W"){
    	b = 1;
    }
     
    if (A == "G"){
    	c = 1;
    }
    
     if (A == "Y"){
    	d = 1;
    }
  }
  
  e = a + b + c + d;
  
  if (e == 3){
  	 cout << "Three" << endl;
  }
  
  else{
  	 cout << "Four" << endl;
  }
}


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

#define NIL 20000

enum Directions { North, East, South, West, Direction_Max };
enum Instructions { FORWARD, BACKWARD, RIGHT, LEFT, Instractions_Max };
const char Inst[][16] = {"FORWARD","BACKWARD","RIGHT","LEFT"};
using namespace std;

int main(){
	while( true ){
		int direction = North;
		int max_x = 0;
		int max_y = 0;
		int nowpos_x = 1;
		int nowpos_y = 1;

		cin >> max_x >> max_y;

		if( max_x == 0 && max_y == 0 )
			break;

		while( true ){
			int k = NIL;
			std::string instruction;

			cin >> instruction;
			if( instruction.compare("STOP") == 0 )
				break;
			
			for(int ei = FORWARD; ei < Instractions_Max; ++ei ){
				if( instruction.compare( Inst[ei] ) == 0 ){
					switch( ei ){
						case FORWARD: cin >> k; break;
						case BACKWARD: cin >> k; k = -k; break;
						case RIGHT: direction = ( direction + 1 ) % Direction_Max; break;
						case LEFT: direction = (direction - 1 + Direction_Max ) % Direction_Max; break;
					}
					break;
				}
			}
			if( k != NIL ){
				switch( direction ){
					case North: nowpos_y += k; break;
					case East: nowpos_x += k; break;
					case West: nowpos_x -= k; break;
					case South: nowpos_y -= k; break;
				}
			}
			if( nowpos_x < 1 ) nowpos_x = 1;
			if( nowpos_x > max_x ) nowpos_x = max_x;
			if( nowpos_y < 1 ) nowpos_y = 1;
			if( nowpos_y > max_y ) nowpos_y = max_y;
			
		}
		cout << nowpos_x << ' ' << nowpos_y << '\n';
	}
	return 0;
}

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

int main(){
    string s;cin >> s;
    bool flag = 1;
    for(int i=1;i<4;++i){
        if(s.at(i) == s.at(i-1))flag = 0;
    }
    if(flag)cout << "Good" << endl;
    else cout << "Bad" << endl;
}


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

int A, B, C;

int main() {
	cin >> A >> B >> C;
	if (A > B) swap(A, B);
	if (A > C) swap(A, C);
	if (B > C) swap(B, C);

	int ans = 0;
	while (B != C) {
		A++;
		B++;
		ans++;
	}
	if ((C - A) % 2 != 0) {
		B++;
		C++;
		ans++;
	}
	while (A != C) {
		A += 2;
		ans++;
	}

	cout << ans << endl;
}

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

const ll INF = 1e17;


int main() {
    // input
    int N;
    cin >> N;
    if (N%2 == 1)
    {
        cout << "No" << endl;
        return 0;
    }

    string s;
    cin >> s;

    string first = s.substr(0, N/2);
    string second = s.substr(N/2 , N);

    if(first == second) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
from collections import Counter

N = int(input())
s = [input() for _ in range(N)]

c = Counter(s)
c = c.most_common()
c.sort(key=lambda x: x[0])
c.sort(key=lambda x: x[1], reverse=True)

most_cnt = c[0][1]
for key, cnt in c:
    if cnt == most_cnt:
        print(key)
    else:
        break


Measured memory_bytes: 45032
def main():

    n, m = map(int, input().split())
    ab = [list(map(int, input().split())) for _ in [0]*m]
    g = [[] for _ in [0]*n]
    [g[a-1].append(b-1) for a, b in ab]
    [g[b-1].append(a-1) for a, b in ab]

    import heapq
    h = [(0, 0)]
    heapq.heapify(h)
    d = [10**10]*n
    while h:
        dis, i = heapq.heappop(h)
        if d[i] == 10**10:
            d[i] = dis
            for j in g[i]:
                if d[j] == 10**10:
                    heapq.heappush(h, (dis+1, j))

    print("Yes")
    for i in range(1, n):
        minimum = 10**9
        dire = None
        for j in g[i]:
            if d[j] < minimum:
                minimum = d[j]
                dire = j
        print(dire+1)


main()


Measured memory_bytes: 140364
// D

#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};

int main(){
  int N;
  ll x;
  cin>>N>>x;
  ll L[51] = {0};
  L[0] = 1;
  ll p[51] = {0};
  p[0] = 1;
  for (int i(1);i<N;i++){
    L[i] = 2 * L[i-1] + 3;
    p[i] = 2 * p[i-1] + 1;
  }
  for (int i(0);i<N;i++){
    //cout << L[i] << " " << p[i] << endl;
  }
  ll now(0);
  ll ans(0);
  int v(1);
  for (int i(N-1);i>=0;i--){
      now += v*(L[i] + 2);
      ans += v*(p[i] + 1); 
    if (now == x){
      cout << ans << endl;
      return 0;
    }else if (now < x){
      v = 1;
    }else{
      v = -1;
    }
  //  cout << now << " "<<ans << endl;
  }
  if (now - x <= 2 && now - x > 0){
    cout << ans - (now - x) << endl;
  }else if(now - x == 3){
    cout << ans - 2 << endl;
  }else if (now - x < 0){
    cout << ans + 1 << endl;
  }
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {	
	
	void main() {
		try(Scanner sc = new Scanner(System.in)){
			for(;;) {
				int x = sc.nextInt();
				int y = sc.nextInt();
					if(x == 0 && y == 0)break;
					if ( x < y ){
						System.out.println(x + " " + y);
					} else {
						System.out.println(y + " " + x);
					}
			}
		}
	}

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



Measured memory_bytes: 35872
solve c = trans codePoint
  where
    codePoint = fromEnum c
    trans codePoint
      | 97 <= codePoint && codePoint <= 122 = toEnum (codePoint - 32) :: Char
      | 65 <= codePoint && codePoint <= 90 = toEnum (codePoint + 32) :: Char
      | otherwise = c

main = do
  string <- getLine
  putStrLn $ map solve string


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

using namespace std;
using ll = long long;

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

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

    double L; cin >> L;

    double threeL = L / 3;

    double long volume = threeL * threeL * threeL;

    cout << fixed << setprecision(7) << volume << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }     //最小公倍数
using Graph = vector<vector<int>>;
 
const double PI = 3.14159265358979323846;
/*Graph t;
void dfs(int v, int pv=-1){
    for(int vn: t[v]){
        if (vn == pv) continue;
        dfs(vn, v);
    }
}*/
int main() {
  int n,q;
  cin >> n >> q;
  vector<vector<int>> k(n,vector<int>(1,-1));
  rep(i,n-1){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    k[a].push_back(b);
    k[b].push_back(a);
  }
  vector<int> z(n,0);
  vector<int> ans(n,-1);
  rep(i,q){
    int c,d;
    cin >> c >> d;
    z[c-1]+=d;
  }
  ans[0]=z[0];
  queue<int> x;
  x.push(0);
  while(x.size()!=0){
    int y=x.front();
    x.pop();
    for(int kk: k[y]){
      if(kk==-1)continue;
      if(ans[kk]!=-1)continue;
      ans[kk]=ans[y]+z[kk];
      x.push(kk);
    }
  }
  rep(i,n-1){
    cout << ans[i] << " ";
  }
  cout << ans[n-1] << endl;
}


Measured memory_bytes: 16376
#include<bits/stdc++.h>
using lint=long long;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint n;std::cin>>n;
    std::vector<lint>a(n),b(n);
    for(lint i=0;i<n;i++){
        lint x;std::cin>>x;x--;
        a.at(i)=x;
        b.at(x)++;
    }
    lint ans=std::accumulate(b.begin(),b.end(),0ll,
        [](lint x,lint y){return x+y*(y-1)/2;});
    for(lint x:a){
        lint y=b.at(x);
        std::cout<<ans-(b.at(x)-1)<<'\n';
    }
}



Measured memory_bytes: 5760
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
using int64 = long long;

int main() {
  int64 X;
  cin >> X;
  double minimum = (-1 + sqrt(1 + 8 * X)) / 2;
  int64 ans = ceil(minimum);
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> A(n);
    copy_n(istream_iterator<int>(cin), n, A.begin());

    if (n == 1){
        puts("1");
        return 0;
    }

    for (int i = 0; i < k; i++){
        vector<int> imos(n + 1);
        for (int j = 0; j < n; j++){
            imos[max(0, j - A[j])]++;
            imos[min(n, j + A[j] + 1)]--;
        }
        for (int j = 0; j < n; j++)
            imos[j + 1] += imos[j];
        A = imos;
        A.resize(n);
        if (all_of(A.begin(), A.end(), [&](const auto &a){return a == n;}))
            break;
    }

    for (const auto &a: A)
        cout << a << " ";
    cout << endl;

}

Measured memory_bytes: 5644
#include "bits/stdc++.h"

using namespace std;
using ll = long long int;

template<typename T>
T Gcd(T a, T b)
{
	while (b != 0)
	{
		T next = a % b;
		a = b;
		b = next;
	}

	return a;
}

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

	if (n >= k)
	{
		n = n % k;
	}

	ll ans = min(n, abs(n - k));
	cout << ans << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }

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

    int h,a;cin>>h>>a;
    cout<<(h+a-1)/a<<endl;
    return 0;
}


Measured memory_bytes: 256
package main

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

const (
	defaultBufferSize = 1024
	maxBufferSize     = 1e6
	Mod               = 1e9 + 7
)

var sc = bufio.NewScanner(os.Stdin)

// sc.Buffer(make([]byte, defaultBufferSize), maxBufferSize)

func readInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

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

func readInt64() int64 {
	sc.Scan()
	i, err := strconv.ParseInt(sc.Text(), 10, 64)
	if err != nil {
		panic(err)
	}
	return int64(i)
}

func readfloat64() float64 {
	sc.Scan()
	f, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return f
}

func abs(a int) int {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func gcd(x, y int) int {
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

func ModComb(n, k int) int {
	if k == 0 {
		return 1
	}
	x, y := n, k
	for i := 1; i < k; i++ {
		x = x * (n - i) % Mod
		y = y * (k - i) % Mod
	}
	inv := ModInv(y)
	return x * inv % Mod
}

func ModFact(x int) int {
	fact := 1
	for i := 1; i <= x; i++ {
		fact = fact * i % Mod
	}
	return fact
}

func ModInv(x int) int {
	return ModPow(x, Mod-2)
}

func ModPow(a, n int) int {
	res := 1
	for n > 0 {
		if n%2 != 0 {
			res = res * a % Mod
		}
		a = a * a % Mod
		n /= 2
	}
	return res
}

func pow(a, n int) int {
	if n == 0 {
		return 1
	}

	ans := 0
	if n%2 == 0 {
		ans = pow(a*a, n/2)
	} else {
		ans = a * pow(a*a, (n-1)/2)
	}
	return ans
}

func intSliceReverse(slice []int) []int {
	for i, j := 0, len(slice)-1; i < j; i, j = i+1, j-1 {
		slice[i], slice[j] = slice[j], slice[i]
	}
	return slice
}

func stringReverse(str string) string {
	runes := []rune(str)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func primeFactorization(x int) map[int]int {
	result := make(map[int]int, 0)
	for i := 2; i*i <= x; i++ {
		for x%i == 0 {
			result[i]++
			x /= i
		}
	}
	if x != 1 {
		result[x]++
	}
	return result
}

func isPrime(x int) bool {
	if x == 1 {
		return false
	}
	for i := 2; i*i <= x; i++ {
		if i == x {
			continue
		}
		if x%i == 0 {
			return false
		}
	}
	return true
}

func main() {
	sc.Split(bufio.ScanWords)
	l, r, d := readInt(), readInt(), readInt()

	ans := 0
	for i := l; i <= r; i++ {
		if i%d == 0 {
			ans++
		}
	}
	fmt.Println(ans)

}


Measured memory_bytes: 1772
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <chrono> //1e+9で割る auto end= chrono::system_clock::now()-st;  cout<<end.count()%1e+9<<endl;
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef long double db;

#define fr first
#define sc second
#define pb push_back
#define rep(i,x) for(ll i=0;i<x;i++)
#define rep1(i,x) for(ll i=1;i<=x;i++)
#define rrep(i,x) for(ll i=x-1;i>=0;i--)
#define rrep1(i,x) for(ll i=x;i>0;i--)

ll N,M;
bool used[100001];
P p[100000];
vector<ll> G[100001];
vector<ll> st;
vector<ll> en;

void rec1(ll x){
	st.pb(x);
	for(ll i=0;i<G[x].size();i++){
		if(!used[G[x][i]]){
			used[G[x][i]]=1;
			rec1(G[x][i]);
			return;
		}
	}
	return;
}

void rec2(ll x){
	en.pb(x);
	for(ll i=0;i<G[x].size();i++){
		if(!used[G[x][i]]){
			used[G[x][i]]=1;
			rec2(G[x][i]);
			return;
		}
	}
	return;
}


int main()
{
	cin>>N>>M;
	rep(i,M){
		cin>>p[i].fr>>p[i].sc;
		G[p[i].fr].pb(p[i].sc);
		G[p[i].sc].pb(p[i].fr);
	}
	ll x=1;
	ll y=G[1][0];
	used[1]=used[G[1][0]]=1;
	rec1(x);
	rec2(y);
	cout<<st.size()+en.size()<<endl;
	rrep(i,st.size()){
		cout<<st[i]<<" ";
	}
	rep(i,en.size()){
		cout<<en[i];
		if(i==en.size()-1) cout<<endl;
		else cout<<" ";
	}
}

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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7;
const ll LINF = 1e18;

//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

long long int n=1,cnt=0,a,b,c,cmp=0,ans=INF,data[10000000],m,h,x,y,xcmp=0,ycmp=0,sum=0;

string s,w;

vector<string> z;

int main(void){
       cin.tie(0);
    ios::sync_with_stdio(false);
  
       cin >> n;
       rep(i,n){
           cin >> data[i];
           sum+=data[i];
           }
           rep(i,n-1){
               cmp+=data[i];
               sum-=data[i];
               //cout << cmp << " " << sum << endl;
               if(i==0){
                   ans = Abs(cmp,sum);
               }
               else{
                   ans = min(Abs(cmp,sum),ans);
               }
           }
           Cout(ans);
return 0;

}


Measured memory_bytes: 1792
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 100 , P = 1e9 + 7;
int n;
string s , t;

int main(){
    cin >> n;
    cin >> s >> t;
    int bf=0;
    int ans=1;
    for(int i=0;i<n;){
        if(i!=n-1&&s[i]==s[i+1]){
            if(bf==2) ans=ll(ans)*3%P;
            else if(bf==1) ans=ll(ans)*2%P;
            else ans=ll(ans)*6%P;
            bf=2;
            i+=2;
        } else {
            if(bf==2) ;
            else if(bf==1) ans=(ll)ans*2%P;
            else ans=(ll)ans*3%P;
            bf=1;
            i++;
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define db double

using namespace std;
const int N=55;
int rd()
{
    int x=0,w=1;char ch=0;
    while(ch<'0'||ch>'9'){if(ch=='-') w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+(ch^48);ch=getchar();}
    return x*w;
}
struct graph
{
	int to[N<<2],nt[N<<2],ban[N<<2],hd[N],dg[N],tot;
	graph(){tot=1;}
	void adde(int x,int y){++tot,to[tot]=y,nt[tot]=hd[x],hd[x]=tot,++dg[y];}
	void wd()
	{
		int x=to[tot],y=to[tot-1];
		hd[x]=nt[hd[x]],hd[y]=nt[hd[y]],--dg[x],--dg[y];
		tot-=2;
	}
}t0,t1,g0;
bool z2[N][N],mk[N],ban[N];
int n,ans,na,fa[N],f2[N];
queue<int> q;
void dfs1(int x)
{
	for(int i=t0.hd[x];i;i=t0.nt[i])
	{
		int y=t0.to[i];
		if(t0.ban[i>>1]||y==fa[x]) continue;
		fa[y]=x,mk[y]=mk[x]&z2[x][y],dfs1(y);
	}
}
void dfs2(int x)
{
	for(int i=t1.hd[x];i;i=t1.nt[i])
	{
		int y=t1.to[i];
		if(t1.ban[i>>1]||y==f2[x]) continue;
		f2[y]=x,dfs2(y);
	}
}
void wk(int i,int o)
{
	memset(mk,0,sizeof(bool)*(n+1));
	fa[i]=f2[i]=0,mk[0]=mk[i]=1;
	dfs1(i),dfs2(i),mk[i]=o;
	memset(g0.hd,0,sizeof(int)*(n+1)),memset(g0.dg,0,sizeof(int)*(n+1)),g0.tot=1;
	na=n;
	for(int j=1;j<=n;++j)
	{
		na-=mk[j];
		if(fa[j]!=i&&!mk[j]&&!mk[fa[j]]) g0.adde(fa[j],j);
		if(f2[j]!=i&&!mk[j]&&!mk[f2[j]]) g0.adde(j,f2[j]);
	}
	for(int j=1;j<=n;++j)
		if(!g0.dg[j]) q.push(j);
	int rs=n;
	while(!q.empty())
	{
		int x=q.front();
		q.pop();
		--rs;
		for(int k=g0.hd[x];k;k=g0.nt[k])
		{
			int y=g0.to[k];
			--g0.dg[y];
			if(!g0.dg[y]) q.push(y);
		}
	}
	if(!rs) ans=min(ans,na);
}

int main()
{
//// /bb
	int T=rd();
	while(T--)
	{
		n=rd();
		memset(t0.hd,0,sizeof(int)*(n+1)),memset(t0.dg,0,sizeof(int)*(n+1)),t0.tot=1;
		for(int i=1;i<n;++i)
		{
			int x=rd(),y=rd();
			t0.adde(x,y),t0.adde(y,x);
		}
		memset(t1.hd,0,sizeof(int)*(n+1)),t1.tot=1;
		memset(z2,0,sizeof(z2));
		for(int i=1;i<n;++i)
		{
			int x=rd(),y=rd();
			t1.adde(x,y),t1.adde(y,x),z2[x][y]=z2[y][x]=1;
		}
		ans=n+1;
		for(int i=1;i<=n;++i) wk(i,1);
		for(int x=1;x<=n;++x)
		{
			if(t0.dg[x]>1) continue;
			int j=t0.hd[x];
			t0.ban[j>>1]=1;
			for(int y=1;y<=n;++y)
				if(x!=y) t0.adde(x,y),t0.adde(y,x),wk(x,0),t0.wd();
			t0.ban[j>>1]=0;
		}
		printf("%d\n",ans<=n?ans:-1);
	}
	return 0;
}


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

using namespace std;

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


Measured memory_bytes: 256
a, b, k = map(int, input().split())
down = a + k - 1
up = b - k + 1

if down < up:
    for i in range(a, down+1):
        print(i)
    for i in range(up, b+1):
        print(i)
    exit()

if down >= up:
    for i in range(a, b+1):
        print(i)
    exit()

Measured memory_bytes: 3060
#include <iostream>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
using namespace std;
int main(void){
    int h, w;
    cin >> h >> w;
    vector<vector<int>>color(h);
    for(auto & x : color){
        x.resize(w);
        for(auto & in : x){
            char c;
            cin >> c;
            if(c == '.'){
                in = 0;
            } else{
                in = 1;
            }
        }
    }
    set<int> dh;
    for(auto i = 0; i < h; ++i){
        if(accumulate(color[i].begin(),color[i].end(),0) == 0){
            dh.insert(i);
        }
    }
    set<int> dw;
    for(auto j = 0; j < w; ++j){
        auto csum = 0;
        for(auto i = 0; i < h; ++i){
            csum += color[i][j];
        }
        if(csum == 0){
            dw.insert(j);
        }
    }
    for(auto i = 0; i < h; ++i){
        if(dh.count(i) == 0){
            for(auto j = 0; j < w; ++j){
                if(dw.count(j) == 0){
                    if(color[i][j] == 0){
                        cout << '.';
                    } else{
                        cout << '#';
                    }
                }
            }
            cout << endl;
        }
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<functional>
#include<queue>
#include<stack>
using namespace std;

int main(){
    int a,b,c,x;
    cin>>a>>b>>c>>x;
    int ans=0;
    for(int i=0;i<=a;i++){
        for(int j=0;j<=b;j++){
            for(int k=0;k<=c;k++){
                if(500*i+100*j+50*k==x){
                    ans++;
                }
            }
        }
    }
    cout<<ans<<endl;
}   





Measured memory_bytes: 256
object Main extends App {
  val in = scala.io.Source.stdin.getLines.toSeq
  val ls = in.map(_.split(' ').map(_.toLong))
  val X = ls(0)(0).toInt
  val Y = ls(0)(1).toInt
  var p = ls(1).toSeq.sorted.reverse.take(X)
  var q = ls(2).toSeq.sorted.reverse.take(Y)
  var r = ls(3).toSeq.sorted.reverse
  
  val all = (p ++ q ++ r).sorted.reverse.take(X+Y)
  val ret = all.sum
  println(ret)
}


Measured memory_bytes: 97808
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
using namespace std;
signed main() {
	int n; string s; cin >> n >> s;
	for1(i, s.size() - 1)if (s[i - 1] == s[i])n--;
	cout << n << endl;
}

Measured memory_bytes: 512
/*Shivam Bhalla */
  /* f2016941@pilani.bits-pilani.ac.in */



  #include <iostream>
  #include <cstdio>
  #include <cstring>
  #include <cstdlib>
  #include <cctype>
  #include <algorithm>
  #include <map>
  #include <vector>
  #include <list>
  #include <set>
  #include <queue>
  #include <deque>
  #include <stack>
  #include <iostream>
  #include <string>
  #include <cmath>
  #include <cassert>
  #include <bits/stdc++.h>
  #define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
  using namespace std;
  long long maxv = 1e9;


  int main()
  {
    fast_cin();
    long long num=0;
    int N;
    int A;
    cin>>N;
    for(int i=0;i<N;i++){
      cin>>A;
      num=num^A;
    }
    if(num==0)
      cout<<"Yes";
    else
      cout<<"No";
    return 0;
  }


Measured memory_bytes: 256