akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL<<61LL;

vector<ll> visited;
vector<vector<ll> > es;

void dfs(ll now){
	visited[now] = true;
	for(auto &e : es[now]){
		if(!visited[e])
			dfs(e);
	}
}

int main(){
	ll N, M;
	cin >> N >> M;
	visited.assign(N, false);
	es = vector<vector<ll> >(N, vector<ll>(0));
	for(int i=0;i<M;i++){
		ll a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		es[a].push_back(b);
		es[b].push_back(a);
	}
	ll ans = 0;
	for(int i=0;i<N;i++)
		if(!visited[i]){
			ans++;
			dfs(i);
		}
	cout << ans << endl;
}


Measured memory_bytes: 9600
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;

/*--- Macro ---*/
#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 mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

/*---  Type ---*/
typedef long long ll;

/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

// Util
int max(int a, int b, int c) {return max(a, max(b, c));}
int min(int a, int b, int c) {return min(a, min(b, c));}
ll max(ll x, ll y) {return x > y ? x : y;}
ll min(ll x, ll y) {return x < y ? x : y;}
ll max(ll a, ll b, ll c) {return max(a, max(b, c));}
ll min(ll a, ll b, ll c) {return min(a, min(b, c));}

// -------------------------------------------------------------------------------------

bool equals(vector<int> n) {
  return n[0] == n[1] && n[1] == n[2];
}

int main() {
  vector<int> n(3);
  cin >> n[0] >> n[1] >> n[2];

  int ans = 0;
  while(!equals(n)) {
    sort(all(n));
    if(n[0] == n[1]) {
      n[0]++;
      n[1]++;
    } else {
      n[0] += 2;
    }
    ans++;
  }

  cout << ans << endl;

  return 0;
}

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

int main(){
	string str, ring;
	int N;
	int res;
	bool OUT;
	
	res = 0;
	cin >> str;
	cin >> N;
	for(int i = 0; i < N; i++){
		cin >> ring;
		
		OUT = false;
		for(int j = 0; j < ring.size(); j++){
			for(int k = 0; k < str.size(); k++){
				if(ring[(j + k) % ring.size()] != str[k]) break;
				
				if(k + 1 == str.size()){
					res++;
					OUT = true;
				}
			}
			if(OUT) break;
		}
	}
	
	cout << res << endl;
	
	return 0;
}

Measured memory_bytes: 1204
unittest
{
	assert( [ "7", "nikoandsolstice" ].parse.expand.solve == "nikoand..." );
	assert( [ "40", "ferelibenterhominesidquodvoluntcredunt" ].parse.expand.solve == "ferelibenterhominesidquodvoluntcredunt" );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto k = input.front.to!( long );
	input.popFront;
	auto s = input.front.to!( dchar[] );
	return tuple( k, s );
}

auto solve( long k, dchar[] s )
{
	if( s.length <= k ) return s;
	else                return s[ 0 .. k ] ~ "...";
}


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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<int> pv(n+10);
    vector<tuple<int, int, int>> v;
    vector<string> an(m);
    for (int i = 0; i < m; ++i) {
        int p, y;
        cin >> p >> y;
        v.push_back(make_tuple(y, p, i));
    }
    sort(v.begin(), v.end());
    for (auto &tu: v) {
        int y, p, i;
        tie(y, p, i) = tu;
        string pid = to_string(p);
        string id = to_string(++pv[p]);
        while (pid.size() < 6) pid = "0" + pid;
        while (id.size() < 6) id = "0" + id;
        an[i] = pid + id;
    }
    for (int i = 0; i < m; ++i) cout << an[i] << endl;
    return 0;
}


Measured memory_bytes: 8564
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,n) for(int i = 0;i < (int)(n);i++)
#define RREP(i,n) for(int i = (int)n-1;i >= 0;i--)
#define FOR(i,s,n) for(int i = s;i < (int)n;i++)
#define RFOR(i,s,n) for(int i = (int)n-1;i >= s;i--)
#define ALL(a) a.begin(),a.end()
#define IN(a, x, b) (a<=x && x<b)
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a = b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a = b;return true;}return false;}
template<class T>istream&operator >>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<class T>inline void OUT(T t){cout<<t<<"\n";}
template<class T,class... Ts>inline void OUT(T t,Ts... ts){cout<<t<<" ";OUT(ts...);}
template<typename T=int>vector<T>mv(size_t a){return vector<T>(a);}
template<typename T=int,typename... Ts>auto mv(size_t a,Ts... ts){return vector<decltype(mv<T>(ts...))>(a,mv<T>(ts...));}
template<typename T,typename V>typename enable_if<is_class<T>::value==0>::type FILL(T&t,const V&v){t=v;}
template<typename T,typename V>typename enable_if<is_class<T>::value!=0>::type FILL(T&t,const V&v){for(auto &e:t)FILL(e,v);}
constexpr long long INF = 1e18;

int dp[1ll<<20];
signed main(){
	int N,K;
	cin>>N>>K;
	auto a = mv(N);
	cin>>a;
	REP(i,1ll<<N){
		int s = 0;
		REP(j,N){
			if(i&(1ll<<j))s+=a[j];
		}
		if(s==K)dp[i]=1;
	}
	REP(i,1ll<<N){
		if(dp[i]==0)continue;
		REP(j,N){
			if(i&(1ll<<j))continue;
			dp[i^(1ll<<j)]|=dp[i];
		}
	}
	int ans = N;
	REP(i,1ll<<N){
		if(dp[i])continue;
		int cnt = 0;
		REP(j,N){
			if(i&(1ll<<j))cnt++;
		}
		CHMIN(ans,N-cnt);
	}
	OUT(ans);
}


Measured memory_bytes: 11292
import os
import heapq
import sys,threading
import math
import bisect
import operator
from collections import defaultdict
sys.setrecursionlimit(10**5)
from io import BytesIO, IOBase
def gcd(a,b):
    if b==0:

        return a
    else:
        return gcd(b,a%b)
def power(x, p,m):
    res = 1
    while p:
        if p & 1:
            res = (res * x) % m
        x = (x * x) % m
        p >>= 1
    return res
def inar():
    return [int(k) for k in input().split()]

def lcm(num1,num2):
    return (num1*num2)//gcd(num1,num2)

def main():
    #t=int(input())
    t=1
    for _ in range(t):
        n,d=inar()
        ans=0
        d=float(d)
        for i in range(n):
            u,v=inar()
            take=(u**2+v**2)**0.5
            #print(take)
            if take<=d:
                ans+=1
        print(ans)


BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

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

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

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

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


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


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

if __name__ == "__main__":
    main()
    #threadin.Thread(target=main).start()


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

#define name ""
#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)
#define foe(it,c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); it++)
#define long long long 
#define db double 
#define pii pair <int, int>
#define pll pair <long, long>
#define all(c) c.begin(), c.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

const int INF = 1e9+7;
const int MOD = 1e9+7;
const int dx[4] = {0,0,-1,1};
const int dy[4] = {-1,1,0,0};
const char c[3] = {'R', 'G', 'B'};

const int N = 4e3+1;
int n, cnt[3][N], type[256];
string s; 

int main()
{
  fastio;
  type['R'] = 0; type['G'] = 1; type['B'] = 2;
  cin >> n >> s; s = '#' + s;
  for (int i = 1; i <= n; i++){
    for (int j = 0; j < 3; j++){
      cnt[j][i] = cnt[j][i - 1] + (type[s[i]] == j);
    }
  }
  long res = 0;
  for (int i = 1; i < n; i++){
    for (int j = i + 1; j <= n; j++){
      if (s[i] != s[j]){
        char need = 'G';
        for (int k = 0; k < 3; k++){
          if (c[k] != s[i] && c[k] != s[j]) need = c[k];
        }
        res += cnt[type[need]][n] - cnt[type[need]][j];
        if (2 * j - i <= n) res -= (s[2 * j - i] == need);
      }
    }
  }
  cout << res;
  return 0;
}

Measured memory_bytes: 3644
def main():
    n,k = map(int,input().split())
    h = list(map(int,input().split()))
    dp = [0]*n
    dp[1] = abs(h[1] - h[0])
    for i in range(2,n):
        dp[i] = min(abs(h[i] - h[j]) + dp[j] for j in range(max(0,i-k),i))
    print(dp[-1])

main()



Measured memory_bytes: 13980
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"
#define fcout cout << fixed << setprecision(18)

#define MOD 1000000007 // 1e9+7
#define PI 3.1415926535
/*
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
*/
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1
#define LINF 1000000000000000001 // 1e18+1

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
//---------------------------
int a[3333];
ll gcd(ll a, ll b)
{
  for (;;)
  {
    if (a == 0) return b;
    b %= a;
    if (b == 0) return a;
    a %= b;
  }
}
ll lcm(ll a, ll b)
{
    ll temp = gcd(a, b);

    return temp ? (a / temp * b) : 0;
}
int main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int n;cin>>n;
  // ll lcm_sum=1;
  REP(i,n){
    cin>>a[i];
    // lcm_sum=lcm(a[i], lcm_sum);
  }
  // ll f=0;
  // P(lcm_sum);
  // REP(i,n){
  //   f+=(lcm_sum-1) % a[i];
  //   P(f);
  // }
  // P(f);
  ll ff=0;
  REP(i,n){
    ff+=a[i]-1;
  }
  P(ff);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m; i < n; i++) 
#define mod 1000000007
typedef long long ll;
int main(){
    int N;
    cin>>N;
    string S;
    map<string,int>ma;
    ll sum=0;
    rep(i,N){
        cin>>S;
        sort(S.begin(),S.end());
        ma[S]++;
        if(ma[S]>=2){
            sum+=ma[S]-1;
        }
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 11136
//35
#include<iostream>

using namespace std;

int main(){
  for(int n;cin>>n,n;){
    bool na=true;
    int i[1000],p[1000],q[1000],r[1000];
    for(int j=0;j<n;j++){
      cin>>i[j]>>p[j]>>q[j]>>r[j];
    }
    int pp,qq,rr,cc;
    cin>>pp>>qq>>rr>>cc;
    for(int j=0;j<n;j++){
      if(p[j]<=pp&&q[j]<=qq&&r[j]<=rr&&p[j]*4+q[j]*9+r[j]*4<=cc){
	na=false;
	cout<<i[j]<<endl;
      }
    }
    if(na){
      cout<<"NA"<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1176
//by (111110101)2
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
vector<char>v[101010];
long long n,k,ans,dp[101010][3],r,s,p;
string ss;
int main()
{
	cin>>n>>k>>s>>p>>r>>ss;
	for(int i=0;i<n;i++)
	{
		v[i%k].push_back(ss[i]);
	}/*
	for(int i=0;i<n;i++)
	{
		if(!v[i].size())
		{
			continue;
		}
		for(int j=0;j<v[i].size();j++)
		{
			cout<<v[i][j];
		}
		cout<<endl;
	}*/
	for(int i=0;i<n;i++)
	{
		if(!v[i].size())
		{
			continue;
		}
		for(int j=0;j<v[i].size();j++)
		{
			dp[j][0]=dp[j][1]=0;
		}
		if(v[i][0]=='s')
		{
			dp[0][1]=s;
		}
		else if(v[i][0]=='r')
		{
			dp[0][1]=r;
		}
		else
		{
			dp[0][1]=p;
		}
		for(int j=1;j<v[i].size();j++)
		{
			dp[j][0]=max(dp[j-1][0],dp[j-1][1]);
			if(v[i][j]!=v[i][j-1])
			{
				dp[j][1]=dp[j-1][1];
			}
			else
			{
				dp[j][1]=dp[j-1][0];
			}
			if(v[i][j]=='s')
			{
				dp[j][1]+=s;
			}
			else if(v[i][j]=='r')
			{
				dp[j][1]+=r;
			}
			else
			{
				dp[j][1]+=p;
			}
		}
		ans+=max(dp[v[i].size()-1][0],dp[v[i].size()-1][1]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 5760
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	static String input;
	static int pos;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			input = sc.next();
			if (input.equals("#"))
				break;
			pos = 0;
			int n = 0;
			List<String> dirList = new ArrayList<String>();
			List<Rational> list = new ArrayList<Rational>();
			while (pos < input.length()) {
				if (input.charAt(pos) == 'n') {
					dirList.add("north");
					pos += 5;
				} else {
					dirList.add("west");
					pos += 4;
				}
				n++;
			}
			Collections.reverse(dirList);
			for (int i = 0; i < n; i++) {
				String dir = dirList.get(i);
				if (dir.equals("north"))
					list.add(new Rational(-90, (long) Math.pow(2, i)));
				else
					list.add(new Rational(90, (long) Math.pow(2, i)));
			}
			Rational result = new Rational(0, 1);
			for (Rational rat : list) {
				result.add(rat);
			}
			System.out.println(result);
		}
		sc.close();
	}

	static class Rational {
		long child, base;

		Rational(long c, long b) {
			child = c;
			base = b;
		}

		public String toString() {
			if (base == 1)
				return Long.toString(child);
			return child + "/" + base;
		}

		public void add(Rational anotherRational) {
			long r = anotherRational.base / base;
			child *= r;
			base *= r;
			child += anotherRational.child;
			child = Math.max(child, 0);
			child = Math.min(child, base * 90);
			while (child % 2 == 0 && base % 2 == 0) {
				child /= 2;
				base /= 2;
			}
		}
	}
}

Measured memory_bytes: 17196
import java.util.*;
import java.io.*;
class Main{
  public static void main(String args[])throws Exception{
    // Scanner sc = new Scanner(System.in);
    // int n = sc.nextInt();
    StringBuilder bl = new StringBuilder();
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(br.readLine());
    int A[] = new int[n];
    int B[] = new int[n];
    String C[] = new String[n];
    String D[] = new String[n];
    String S[];

    for(int i = 0; i<n; i++){
      // A[i] = sc.nextInt();
      S = br.readLine().split("\\s+");
      C[i] = S[0];
      A[i] = Integer.parseInt(S[1]);
      B[i] = A[i];
      D[i] = C[i];
    }

    quicksort(A,C,0,A.length-1);
    mergesort(B,D, n, 0, B.length);

    //安定性の判定
    int j = 0;
    int flag = 0;
    while(j<n){
      if(D[j]!=C[j]){
        System.out.println("Not stable");
        break;
      }
      j++;
    }
    if(j==n)System.out.println("Stable");

    //出力
    for(int i = 0; i < n; i++){
      bl.append(C[i]).append(' ').append(A[i]).append("\n");
    }
    System.out.print(bl);
  }
  static int partition(int A[],String C[], int p, int r){
    int x = A[r];
    int i = p-1;
    int tmp;
    String s;
    for(int j =p; j<r; j++){
      if(A[j]<=x){
        i = i+1;
        tmp = A[i];
        A[i] = A[j];
        A[j] = tmp;
        s = C[i];
        C[i] = C[j];
        C[j] = s;
      }
    }
    tmp = A[i+1];
    A[i+1] = A[r];
    A[r] = tmp;
    s = C[i+1];
    C[i+1] = C[r];
    C[r] = s;
    return i+1;
  }

  static void quicksort(int A[], String C[], int p, int  r){
    if(p<r){
      int q = partition(A, C, p, r);
      quicksort(A, C, p, q-1);
      quicksort(A, C, q+1,r);
    }
  }


  //mergesortと比較
  static void merge(int A[],String S[], int left, int mid, int right){
    int n1 = mid - left;
    int n2 = right - mid;
    int L[] = new int[n1+1];
    int R[] = new int[n2+1];
    String Ls[] = new String[n1+1];
    String Rs[] = new String[n2+1];
    for(int i = 0; i<n1;i++){
      L[i] = A[left+i];
            Ls[i] = S[left+i];
    }
    for(int i =0; i<n2; i++){
      R[i] = A[i+mid];
      Rs[i] = S[i+mid];
    }
    L[n1] = (int)Double.POSITIVE_INFINITY;
    R[n2] = (int)Double.POSITIVE_INFINITY;
    int i = 0;
    int j = 0;
    for(int k = left; k<right; k++){
      if(L[i]<=R[j]){
        A[k] = L[i];
        S[k] = Ls[i++];
      }else{
        A[k] = R[j];
        S[k] = Rs[j++];
      }
    }
  }

  static void mergesort(int A[],String S[], int n, int left, int right){
    if(left+1<right){
      int mid = (left+right)/2;
      mergesort(A,S, n, left, mid);
      mergesort(A,S, n, mid, right);
      merge(A,S, left, mid, right);
    }
  }
}


Measured memory_bytes: 97456
#include <bits/stdc++.h>
using namespace std;
int main() {
	int x, c = -404, cnt = 0, tmp;
	long int a = -404, b = -404;
	vector<int> y = {1};
	cin >> x;
	for (int i = 2; i < pow(x,0.5); i++) {
		if (x % i == 0) {
			y.push_back(i);
			cnt++;
			if (cnt > 4) {
				break;
			}
		}
	}
	tmp = y.size();
	for (int i = 0; i < tmp; i++) {
		y.push_back(x / y.at(i));
	}
	for (int j = 0; j < int(y.size()); j++) {
		for (int i = 0; i < 10000; i++) {
			c = pow(i + y.at(j), 5) - pow(i, 5);
			if (c == x) {
				a = i + y.at(j);
				b = i;
				break;
			}
			c = pow(i, 5) - pow(i - y.at(j), 5);
			if (c == x) {
				a = i;
				b = i - y.at(j);
				break;
			}
		}
	}
	cout << a << ' ' << b << endl;
}

Measured memory_bytes: 4256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		var Q = new Queue<int>[26];
		for(int i=0;i<26;i++) Q[i] = new Queue<int>();
		
		String S = "S" + A + "abcdefghijklmnopqrstuvwxyzG";
		int N = A.Length;
		int NN = S.Length;
		for(int i=1;i<NN-1;i++){
			Q[S[i] - 'a'].Enqueue(i);
		}
		List<int>[] E = new List<int>[NN];
		for(int i=0;i<NN;i++) E[i] = new List<int>();
		
		for(int i=0;i<26;i++){
			int n = Q[i].Peek();
			E[0].Add(n);
			E[n].Add(0);
		}
		
		for(int i=1;i<1+N;i++){
			Q[S[i] - 'a'].Dequeue();
			for(int j=0;j<26;j++){
				var n = Q[j].Peek();
				E[i].Add(n);
				E[n].Add(i);
			}
		}
		
		for(int i=1+N;i<1+N+26;i++){
			E[i].Add(NN-1);
			E[NN-1].Add(i);
		}
		
		int Inf = (int)1e9;
		int[] min = new int[NN];
		for(int i=0;i<NN;i++) min[i] = Inf;
		
		min[NN-1] = 0;
		var Q0 = new Queue<int>();
		Q0.Enqueue(NN-1);
		while(Q0.Count > 0){
			var now = Q0.Dequeue();
			foreach(var nxt in E[now]){
				if(min[nxt] == Inf){
					min[nxt] = min[now] + 1;
					Q0.Enqueue(nxt);
				}
			}
		}
		
		List<char> L = new List<char>();
		int nowp = 0;
		
		while(nowp != NN-1){
			int nxt = -1;
			char minc = (char)('z' + 1);
			foreach(var e in E[nowp]){
				if(min[e] == min[nowp] - 1){
					if(S[e] == 'G'){
						nxt = e;
						break;
					} else {
						if(S[e] < minc){
							nxt = e;
							minc = S[e];
						}
					}
				}
			}
			
			if(S[nxt] != 'G') L.Add(S[nxt]);
			nowp = nxt;
		}
		
		Console.WriteLine(new String(L.ToArray()));
		
		
		
	}
	String A;
	public Sol(){
		A = rs();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


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

int main() {
  int n;
  cin>>n;
  int a[n];
  for (int i=0; i<n; i++) cin>>a[i];
  sort(a, a + n);
  reverse(a, a + n);
  int alice = 0, bob = 0;
  for (int i=0; i<n; i++) {
    if (i % 2 == 0) {
      alice += a[i];
    } else {
      bob += a[i];
    }
  }
  cout<<alice - bob<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;


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

int main(int argc, char *argv[]) {

	int K; cin >> K;	


	int sum = 0;
	for (int i = 1; i <= K; i++) {
		for (int j = 1; j <= K; j++) {
			for (int k = 1; k <= K; k++) {
				sum += gcd(i,gcd(j,k));		
			}
		}
	}
	cout << sum << endl;

	return 0;
}


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

typedef long long int int64;

int64 calc(const char *s,const int n,const int k){
  int64 res=0;
  int cntD=0;
  int cntM=0;
  int64 cntDM=0;
  int64 cntLDM=0;
  int i;
  for(i=0;i<n;i++){
    if(i>=k){
      if(s[i-k]=='D'){
	cntLDM+=cntM;
	cntD--;
      } else if(s[i-k]=='M'){
	cntM--;
      }
    }
    if(s[i]=='D'){
      cntD++;
    } else if(s[i]=='M'){
      cntM++;
      cntDM+=cntD;
    } else if(s[i]=='C'){
      res+=cntDM-cntLDM;
    }
  }
  return res;
}

void run(void){
  int n;
  scanf("%d",&n);
  char *s=(char *)calloc(n+1,sizeof(char));
  scanf("%s",s);
  int q;
  scanf("%d",&q);
  while(q--){
    int k;
    scanf("%d",&k);
    int64 ans=calc(s,n,k);
    printf("%lld\n",ans);
  }
}

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


Measured memory_bytes: 1152
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;

using ll = long long;
ll mod = pow(10, 9) + 7;

template <typename T> void output(T, ll);
ll gcd(ll, ll);
ll lcm(ll, ll);
Bint comb(Bint, Bint);
void prime_map(map<ll, ll> &, ll);

int main() {
    // source
    int n;
    cin >> n;
    int a[n];
    int num1 = 0, num2 = 0, num4 = 0;
    rep(i, n) { cin >> a[i]; }
    rep(i, n) {
        if (a[i] % 4 == 0) {
            num4++;
        } else if (a[i] % 2 == 0) {
            num2++;
        } else {
            num1++;
        }
    }
    if (num2 == 0) {
        if (num1 <= num4 + 1) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    } else {
        if (num1 <= num4) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
    return 0;
}

Bint comb(Bint a, Bint b) {
    Bint ans = 1;

    if (a < b) {
        return 0;
    }

    rep(i, b) {
        ans *= a - i;
        ans /= i + 1;
    }

    return ans;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

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

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

void prime_map(map<ll, ll> &m, ll num) {

    if (num == 1) {
        return;
    }
    ll cache = num;
    repd(i, 2, sqrt(num) + 2) {
        if (num % i == 0) {
            if (m[i] == 0) {
                m[i] = 1;
            } else {
                m[i]++;
            }

            num /= i;
            break;
        }
    }
    if (cache == num) {
        if (m[num] == 0) {
            m[num] = 1;
        } else {
            m[num]++;
        }

        return;
    }
    prime_map(m, num);
    return;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
#define all(X) (X).begin(), (X).end()
#define reset(X) memset(X, 0, sizeof(X))
#define mp(a, b) make_pair(a, b)
#define pb push_back
#define endl '\n'
#define fi first
#define se second



using namespace __gnu_pbds;
using namespace std;
// const int mod=1e9+7;
 const int mod=998244353;
const int INF=4e18+10;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define readv(x, n) vector<int> x(n); for(auto &i:x) cin>>i; 


int pow(int a, int b)
{
    int prod=1;
    int mult=a%mod;
    while(b!=0)
    {
        if(b%2)
        {
            prod*=mult;
            prod%=mod;
        }
        mult*=mult;
        mult%=mod;
        b/=2;
    }
    return prod;
}
int mod_inv(int q, int mod)
{
    return pow(q, mod-2);
}
const int MAXN=6e3;
vector<int>  adj[MAXN];
bool cycle=false;
int visited[MAXN];
int color[MAXN];
// void dfs(int node)
// {
//     visited[node]=1;
//     for(auto i:adj[node])
//     {
//         if(visited[i.fi]==0)
//         {
//             visited[i.fi]=1;
//             color[i.se]=1;
//             dfs(i.fi);
//             visited[i.fi]=2;
//         }
//         else if(visited[i.fi]==1)
//         {
//             cycle=true;
//             color[i.se]=2;
//         }
//         else
//             color[i.se]=1;
//     }
//     visited[node]=2;
// }


signed main()

{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);  
       cout.tie(NULL);
     #ifndef ONLINE_JUDGE
        if(fopen("INPUT.txt","r"))
        {
        freopen ("INPUT.txt" , "r" , stdin);
        freopen ("OUTPUT.txt" , "w" , stdout);
        }
     #endif
    auto clk=clock(); 
    // -------------------------------------Code starts here---------------------------------------------------------------------     
 
    int n;
    cin>>n;
    int sum=0;
    for(int i=1;i<=n;i++)
    {
        if(i%3!=0 && i%5!=0)
        {
            sum+=i;
        }
    }
    cout<<sum<<endl;
    // -------------------------------------Code ends here------------------------------------------------------------------


    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
    return 0;
 }


Measured memory_bytes: 3968
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int n, x, maxx, minx = 0x7fffffff;
int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i){
		scanf("%d", &x);
		maxx = max(maxx, x);
		minx = min(minx, x);
	}
	printf("%d\n", maxx - minx);
	return 0;
} 

Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Scanner;

public class Main {
	
	
	
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		if(n%1000==0) {
			System.out.println(0);
		}
		else {
			System.out.println(1000-n%1000);
		}
	}

}


Measured memory_bytes: 35704
#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 INF 1000000000
#define mod 1000000007
typedef long long ll;
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; }

int main(){
    /*
    一回読んだだけの感覚より難しい
    とりあえずこの前やったようにa~zごとに
    vectorでindexを管理すると何かができそうな気がする
    まて、部分列の過半数をある文字が占めるとき
    必ずその文字の距離で1以下のものが存在しないと過半数しめれなくないか？
     */
    string s;
    cin>>s;
    int n=s.size();
    vector<vector<int>> v(26);
    rep(i,n){
        v[s[i]-'a'].push_back(i);
    }
    rep(i,26){
        if(v[i].size()<=1) continue;
        for(int j=1;j<v[i].size();j++){
            if(v[i][j]-v[i][j-1]<=2){
                cout<<v[i][j-1]+1<<' '<<v[i][j]+1<<endl;return 0;
            }
        }
    }
    cout<<"-1 -1"<<endl;
    return 0;
}


Measured memory_bytes: 1144
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 10e9+9
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

string s, table = "KUPC";
int co[10];

int main(){
	cin >> s;
	REP(i, s.size()){
		REP(j, table.size()){
			if (s[i] == table[j]){
				co[j]++;
			}
		}
	}
	int ans = 100000;
	REP(i, 4){
		ans = min(ans, co[i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 1196
a =  list(map(int, input().split()))
while a != [-1, -1, -1]:
    if a[0]==-1 or a[1]==-1:
        print('F')
    elif a[0]+a[1]>=80:
        print('A')
    elif 65 <= a[0]+a[1] < 80:
        print('B')
    elif 50 <= a[0]+a[1] <65:
        print('C')
    elif 30 <= a[0]+a[1] <50:
        if a[2] >= 50:
            print('C')
        else:
            print('D')
    else:
        print('F')
    a =  list(map(int, input().split()))
        


Measured memory_bytes: 5600
#include<bits/stdc++.h>
using namespace std;
int n,ans;
char s[234234];

int main()
{
	int i,pd;
  scanf("%s",s+1),n=strlen(s+1);
  ans=1,pd=1; 
  for(i=2;i<=n;i++)
    {
	  if(s[i]==s[i-1] && pd) 
	    {
		  if(i<n) ans++;
		  i++;
		  pd=0;
		}
		else ans++,pd=1;
	}
  cout<<ans<<endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long int
#define fr(i, a, b) for (ll i = a; i < b; i++)
#define pb(v, a) v.push_back(a)
#define Sort(v) sort(v.begin(), v.end())
#define For(m) for (auto it = m.begin(); it != m.end(); it++)
#define mod 1000000007
#define PI 3.14159265358979323846
using namespace std;

int main()
{
  ll n;
  cin >> n;
  string a,b,c;
  cin >> a >> b >> c;
  ll ans = 0;
  fr(i,0,n)
  {
     string x;
     pb(x,a[i]);
     pb(x,b[i]);
     pb(x,c[i]);
     sort(x.begin(),x.end());
     if(x[0]!=x[1])ans++;
     if(x[1]!=x[2])ans++;
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 256
#pragma once
#include <stdio.h>
#include <sstream>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <limits>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define bit(x,v) ((ll)x << v)

const ll INF = 1000000007;
const ll MAX = 210000;
const ll MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
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;
}

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}

// res[i][c] := i 文字目以降で最初に文字 c が登場する index (存在しないときは n)
vector<vector<int> > calcNext(const string & S) {
	int n = (int)S.size();
	vector<vector<int> > res(n + 1, vector<int>(26, n));
	for (int i = n - 1; i >= 0; --i) {
		for (int j = 0; j < 26; ++j) res[i][j] = res[i + 1][j];
		res[i][S[i] - 'a'] = i;
	}
	return res;
}
// mod 1000000007 の世界で a += b する関数
void add(long long& a, long long b) {
	a += b;
	if (a >= MOD) a -= MOD;
}
const ll ainf = 998244353;
ll pc = 0;
ll make(int x) {
	if (x == 0) { 
		pc += 1;
		return 1; 
	}

	ll dp = make(x - 1);
	pc *= 2LL;
	pc += 1LL;
	return 1LL + dp + 1LL + dp + 1LL;
}

ll rec(ll len,ll x,ll bc) {

	if (len == 1) {
		if (x == 1) return 1;
		return 0;
	}

	ll hbc = bc / 2;
	if ((len / 2 + 1) == x) return hbc + 1;
	if (len == x) return bc;
	if ((len / 2 + 1) < x) {
		
		return (hbc + 1) + rec(len / 2 - 1, x - (len / 2 + 1), hbc);
	}return rec(len / 2 - 1, x - 1, hbc) ;
}
void solv() {

	ll n,x;
	cin >> n >> x;

	ll bi = make(n);

	cout << rec(bi, x,pc) << endl;
}

int main() {
	//COMinit();
	solv();

	return 0;
}


Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        s: chars,
    };

//    for c in s {
//        if '1' == c {
//            print!("9");
//        } else {
//            print!("1");
//        }
//    }
    
    let o: String = s
        .iter()
        .map(|x: &char| match *x {
            '1' => { '9' }
            _ => { '1' }
//            _ => panic!("error")
        }).collect();

    println!("{}", o);
}



Measured memory_bytes: 4352
s=input()
k=int(input())

n=len(s)
ss=s+s
nn=len(ss)
sss=ss+s
nnn=len(sss)

tmps=1
cnts=0
tmpss=1
cntss=0
tmpsss=1
cntsss=0

for i in range(n-1):
    if s[i]==s[i+1]:
        tmps+=1
    else:
        cnts+=(tmps//2)
        tmps=1
cnts+=(tmps//2)

for i in range(nn-1):
    if ss[i]==ss[i+1]:
        tmpss+=1
    else:
        cntss+=(tmpss//2)
        tmpss=1
cntss+=(tmpss//2)

for i in range(nnn-1):
    if sss[i]==sss[i+1]:
        tmpsss+=1
    else:
        cntsss+=(tmpsss//2)
        tmpsss=1
cntsss+=(tmpsss//2)

if n==1:
    if k%2==0:
        print(k//2)
    else:
        print((k-1)//2)

elif (cntsss-cntss)!=(cntss-cnts):
    print((cntsss-cntss)*((k+1)//2)+(cntss-cnts)*(k//2))

else:
    print((cntsss-cntss)*(k-1)+cnts)


Measured memory_bytes: 3064
a,b,k=map(int,input().split())
takahashi=0
if a>= k:
    #a=a-k
    takahashi=a-k
else:
    dif=k-a
    takahashi=0    
    #print(dif)
    b=b-dif
    if b<0:
        b=0
print("{0} {1}".format(takahashi,b))

Measured memory_bytes: 2940
use v5.18; # strict say state
use warnings;
use List::Util qw(reduce first max min sum0);

chomp (my ($k, $n) = split / /, <STDIN>);
chomp (my @a = split / /, <STDIN>);
my %h;
for my $i (0..$n-1) {
  $h{$i} = $a[$i+1] - $a[$i];
}
$h{$n-1} = $k + $a[0] - $a[$n-1];
my ($max, $m) = (0, 0);
for my $key (keys %h) {
  if ($max < $h{$key}) {
    $max = $h{$key};
    $m = $key;
  }
}
my $ans = 0;
for my $key (keys %h) {
  $ans += $h{$key} if $key != $m;
}
say $ans;

Measured memory_bytes: 61348
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<utility>
#include<algorithm>
#include<bitset>
using namespace std;
string s;
int a,ans,an;
int main(){
  cin>>s;
  for(int i=0;i<s.size();i++)an+=(s[i]-'0');
  ans=9*(s.size()-1);
  if(s[0]!='9'){
    ans+=((s[0]-'0')-1);
  }else{
    for(int i=1;i<s.size();i++){
      if(s[i]!='9'){
	ans+=8;
	a=1;
	break;
      }
    }
    if(a==0)ans+=9;
  }
  cout<<max(ans,an)<<endl;
  return 0;
}


Measured memory_bytes: 256
from collections import deque
s = input()
q = int(input())
ans = deque(s)
rev = 0
for i in range(q):
    qi = input()
    if qi[0] == '1':
        rev += 1
    else:
        parity = rev % 2
        if (int(qi[2]) + parity) % 2:
            ans.appendleft(qi[4])
        else:
            ans.append(qi[4])

parity = rev % 2
if parity:
    ans.reverse()
for i in ans:
    print(i, end='')

Measured memory_bytes: 7664
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int N,ans=0;
    cin >> N;
    vector<int> a(N);
    for(int i=0;i<N;i++)    cin >> a[i];
    sort(a.begin(),a.end());
    for(int i=N-1;i>=1;i-=2)    ans += (a[i] - a[i-1]);
    if(N%2==1)  ans+=a[0];
    cout << ans << endl;   
    return 0;
}

Measured memory_bytes: 256
/*
	submission # - User: herp_sy
	https://atcoder.jp/contests/

	coding: utf-8
	lang: C++ (GCC 5.4.1)
*/

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

// utility of stdin,stdout
#define _CRT_SECURE_NO_WARNINGS
#define OUT cout << 
#define BR << endl
#define RET return 0
#define TLong long long
#define TBMod 1000000007

int main(int argc, char const *argv[])
{
	int n;
	cin >> n;
	printf("%.8f\n", (double)(n - n / 2) / (double)n);
	return 0;
}


Measured memory_bytes: 256
Scanf.scanf "%d %d" (fun n k ->
    let count = Array.make 40 0 in
    let a = Array.init n (fun i ->
        Scanf.scanf " %d" (fun a ->
            let rec loop j r =
                if r = 0 then a else (
                    count.(j) <- count.(j) + (r land 1);
                    loop (j + 1) (r lsr 1)
                )
            in
            loop 0 a
           )
    )
    in
    let rec loop shift acc mode =
        if shift < 0 then acc else (
            let mask = 1 lsl shift in
            if mode then (
                if k land mask = 0 then loop (shift - 1) acc mode else (
                    let p = count.(shift) in (* set *)
                    if n - p >= p then loop (shift - 1) (acc lor mask) mode
                                  else loop (shift - 1) acc false
                )
            ) else (
                let p = count.(shift) in (* set *)
                if n - p >= p then loop (shift - 1) (acc lor mask) mode
                              else loop (shift - 1) acc false
            )
        )
    in
    let x = loop 39 0 true in
    Array.fold_left (fun acc v -> acc + (x lxor v)) 0 a |> Printf.printf "%d\n"
)

Measured memory_bytes: 5376
using System; 
using System.Text; 
using System.Collections.Generic;
using System.Linq; 
using E = System.Linq.Enumerable; 

class Program {
     static long waru = 1000000007;
     static void Main(string[] args) {
     //入力を受け取る
     var S = Console.ReadLine();
     var count = 0;
     var ans   = -1;
     while(count < S.Length){
         var comp = S[count];
         count++;
         while(count < S.Length && comp == S[count]){
             count++;
         }
         ans++;
     }
     
     
     
     Console.WriteLine(ans);
     }
     
     static long kaijo(long num){
         long res =1;
        // Console.WriteLine(res);
         while(num != 1){
             res *= (num%waru);
             num--;
             res = res%waru;
         }
         
         return res%waru;
    　}
}
     
     
     
     
     


Measured memory_bytes: 11232
#include <algorithm>
#include <cstdio>
using std::min;

const int MAXN = 150010;

int n, ce, d[MAXN * 2], ans[MAXN];
struct EDGE { int v; bool x; EDGE *n, *b; } edge[MAXN * 6], *head[MAXN * 2], *cur[MAXN * 2];

void AddEdge(const int u, const int v) {
	edge[ce + 1] = { v, false, head[u], edge + ce + 2 };
	edge[ce + 2] = { u, false, head[v], edge + ce + 1 };
	head[u] = edge + ce + 1;
	head[v] = edge + ce + 2;
	ce += 2;
}

inline void SetEdge(EDGE *e, const bool x) {
	e->b->x = e->x = x;
}

inline void UpdateAns(const int u, const int v) {
	if (static_cast<int>(u <= n) + (v <= n) == 1) {
		int p = min(u, v);
		ans[p] = u == p ? 1 : -1;
	}
}

void FindEulerPath(const int u) {
	// if (d[u] == 1)
	// 	return;
	d[u] --;

	for (EDGE *&e = cur[u]; e; e = e->n) {
		if (e->x || d[e->v] <= 0)
			continue;
		SetEdge(e, true);
		UpdateAns(u, e->v);
		d[u] --;
		FindEulerPath(e->v);
		if (!e)
			break;
	}
}

int main() {
	scanf("%d", &n);

	for (int i = 1, p; i <= n; i++) {
		scanf("%d", &p);
		if (p != -1) {
			AddEdge(p, i);
			d[p] ++;
		}
		else {
			AddEdge(0, i);
			d[0] ++;
		}
		d[i] ++;
	}

	for (int i = 1, p; i <= n; i++) {
		scanf("%d", &p);
		if (p != -1) {
			AddEdge(p + n, i + n);
			d[p + n] ++;
		}
		else {
			AddEdge(0, i + n);
			d[0] ++;
		}
		d[i + n] ++;
	}

	for (int i = 1; i <= n; i++)
		if ((d[i] ^ d[i + n]) & 1) {
			puts("IMPOSSIBLE");
			return 0;
		}

	for (int i = 1; i <= n; i++)
		if (d[i] & 1) {
			d[i] ++;
			d[i + n] ++;
			AddEdge(i, i + n);
		}

	for (int i = 0; i <= n * 2; i++)
		cur[i] = head[i];

	FindEulerPath(0);

	puts("POSSIBLE");
	for (int i = 1; i <= n; i++)
		printf("%d ", ans[i]);
	puts("");

	return 0;
}


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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;

const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-9;

int main() {
	ll N;
	while (cin >> N, N) {
		ll b[14] = {};
		
		b[0] = 1;
		FOR(i, 1, 14) b[i] = b[i - 1] * -10;
		
		queue<pll> que[14];
		que[13].push(pll(N, 0));
		
		for (int i = 13; i > 0; i--) {
			while (!que[i].empty()) {
				pll now = que[i].front(); que[i].pop();
				
				ll dif = now.fi;
				
				REP(j, 10) {
					ll ndif = dif - b[i] * j;
					int nk = log10(abs(ndif)) + 1;
					
					if (i >= nk) que[i - 1].push(pll(ndif, now.se + abs(b[i]) * j));
 
				}
			}
		}
		
		ll ans = -1;
		while (!que[0].empty()) {
			pii now = que[0].front(); que[0].pop();
			if (now.fi >= 0) ans = now.se + now.fi;
		}
		
		
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3332
#include <algorithm>
#include <iostream>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;

#define loop(i, times) for(int i = 0; i < times; i++)
#define seloop(i, start_index, end_index) for(int i = start_index; i < end_index; i++)
#define eqseloop(i, start_index, end_index) for(int i = start_index; i <= end_index; i++)

class NyaGadgetVector
{
public:
	/**
	@brief 加算関数
	@note
	 collectionの全要素にadd_valueだけ値を加算する
	**/
	template<typename T> static void Add(vector<T>& collection, T add_value)
	{
		for (auto& e : collection)
			e += add_value;
	}
	/**
	@brief 標準入力関数
	@note
	 標準入力から入力されたsize個の値をcollectionに格納する
	**/
	template<typename T> static void InputStream(vector<T>& collection, int size)
	{
		for (int i = 0; i < size; i++)
			cin >> collection[i];
	}
	/**
	@brief 最大値取得関数
	@note
	 collectionの要素の中で最大値を取得する
	**/
	template<typename T> static T Max(const vector<T>& collection)
	{
		T max = collection[0];
		for (const auto& e : collection)
		{
			if (max < e)
				max = e;
		}
		return max;
	}
	/**
	@brief 最小値取得関数
	@note
	 collectionの要素の中で最大値を取得する
	**/
	template<typename T> static T Min(const vector<T>& collection)
	{
		T min = collection[0];
		for (const auto& e : collection)
		{
			if (min < e)
				min = e;
		}
		return min;
	}
	/**
	@brief 合計関数
	@note
	 collectionの要素を合計して返す(範囲はstart_index以上end_index未満)
	**/
	template<typename T> static T Sum(const vector<T>& collection, int start_index, int end_index)
	{
		int sum = 0;
		for (int i = start_index; i < end_index; i++)
			sum += collection[i];
		return sum;
	}
};

class NyaGadgetCpp17
{
public:
	template <typename T> static T gcd(T a, T b)
	{ 
		return b ? gcd(b, a % b) : a;
	}
};


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

	long temp;
	vector<long> monster_collection(n, 0);
	NyaGadgetVector::InputStream(monster_collection, n);

	long ans = monster_collection[0];
	loop(i, n-1)
		ans = NyaGadgetCpp17::gcd(ans, monster_collection[i+1]);
	
	cout << ans;
	return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
typedef long long LL;
typedef unsigned long long ULL;
const int MAXN = 100005;
const int P = 1000000007;
const double eps = 1e-6;
using namespace std;
inline int getint() {
    int r = 0; bool b = true; char c = getchar();
    while (c < '0' || c > '9') { if (c == '-') b = false; c = getchar(); }
    while (c >= '0' && c <= '9') { r = (r<<1)+(r<<3) + c - '0'; c = getchar(); }
    return b ? r : -r;
}
int n;
int x[MAXN], y[MAXN];
int cnt, mx[MAXN];
char dst[MAXN];
int main() {
    n = getint();
	for (int i = 0; i < n; ++i) {
		x[i] = getint();
		y[i] = getint();
	}
	int b = (abs(x[0] + y[0]) & 1);
	for (int i = 1; i < n; ++i)
		if ((abs(x[i] + y[i]) & 1) != b) {
			puts("-1");
			return 0;
		}
	printf("%d\n", 32 - b);
	dst[0] = 1;
	if (b == 0) printf("1 ");
	mx[0] = 0;
	for (int i = 1; i < 31; ++i)
		mx[i] = mx[i-1] * 2 + 1;
	for (int i = 0; i < 31; ++i)
		printf("%d ", (1<<i));
	putchar('\n');
	for (int i = 0; i < n; ++i) {
		int X = x[i], Y = y[i];
		if (b == 0) {
			putchar('R');
			--X;
		}
		cnt = 0;
		for (int j = 30; j >= 0; --j) {
			if ((LL) abs(X + (1<<j)) + abs(Y) <= (LL) mx[j]) {
				dst[++cnt] = 'L';
				X += (1<<j);
				continue;
			}
			if ((LL) abs(X - (1<<j)) + abs(Y) <= (LL) mx[j]) {
				dst[++cnt] = 'R';
				X -= (1<<j);
				continue;
			}
			if ((LL) abs(X) + abs(Y + (1<<j)) <= (LL) mx[j]) {
				dst[++cnt] = 'D';
				Y += (1<<j);
				continue;
			}
			if ((LL) abs(X) + abs(Y - (1<<j)) <= (LL) mx[j]) {
				dst[++cnt] = 'U';
				Y -= (1<<j);
				continue;
			}
		}
		for (int j = cnt; j >= 1; --j) putchar(dst[j]);
		putchar('\n');
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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


int main() {

  vector<int> x1(2), x2(2), x3(2), x4(2);
  cin >> x1[0] >> x1[1] >> x2[0] >> x2[1];

  x3[0] = x2[0] - (x2[1] - x1[1]);
  x3[1] = x2[1] + (x2[0] - x1[0]);
  x4[0] = x3[0] - (x2[0] - x1[0]);
  x4[1] = x3[1] - (x2[1] - x1[1]);

  cout << x3[0] << " " << x3[1] << " " << x4[0] << " " << x4[1] << endl;

  return 0;
}


Measured memory_bytes: 256