akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FOR(i, a, n) for(int (i) = (int)(a); (i) < (int)(n); ++(i))
#define FORe(i, a, n) for(int (i) = (int)(a); (i) <= (int)(n); ++(i))
#define rFOR(i, a, n) for(int (i) = (int)(n)-1; (i) >= (int)(a); --(i))
#define REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 0, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define rep(i, n) FOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

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; }

int main() {
  int n;
  cin >> n;
  vector<double> a(n);
  REP(i, n) cin >> a[i];
  sort(all(a));
  double ans = a[0];
  REP(i, n-1) {
    ans = (ans+a[i+1])/2;
  }
  printf("%.10lf\n", ans);

  return 0;
}

Measured memory_bytes: 384
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	aa := make([]int, n)

	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
	}

	ans := make([]int, n+1)
	ans[n] = aa[n-1]

	m := 0
	if ans[n] == 1 {
		m++
	}
	for i := n - 2; i >= 0; i-- {
		x := i + 1
		s := 0
		for ii := 2; ii*x < n+1; ii++ {
			s += ans[ii*x]
		}

		ans[x] = aa[i] ^ (s % 2)
		if ans[x] == 1 {
			m++
		}
	}

	if m == 0 {
		fmt.Fprintln(writer, 0)
	} else {
		fmt.Fprintln(writer, m)
		for i := 1; i < n+1; i++ {
			if ans[i] == 1 {
				fmt.Fprint(writer, i)
				m--
				if m >= 0 {
					fmt.Fprint(writer, " ")
					continue
				}
				fmt.Fprintln(writer, "")
			}
		}
	}

	writer.Flush()
}


Measured memory_bytes: 6144
import sys
input = sys.stdin.readline
from collections import deque
mod = 10**9 + 7

n, m = [int(x) for x in input().split()]
g = [[] for _ in range(n)]

for _ in range(m):
    u, v = [int(x) for x in input().split()]
    g[u - 1].append(v - 1)

s, t = [int(x) for x in input().split()]

d = [[-1, -1, -1] for _ in range(n)]

def bfs(u):
    queue = deque([[u, 0]])
    d[u][0] = 0
    while queue:
        v, d_ = queue.popleft()
        for i in g[v]:
            if d[i][(d_ + 1) % 3] < 0:
                d[i][(d_ + 1) % 3] = d_ + 1
                queue.append([i, d_ + 1])
    return d

d = bfs(s - 1)

print(d[t - 1][0] // 3)


Measured memory_bytes: 67504
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner scan=new Scanner(System.in);
    int A=scan.nextInt();
    int B=scan.nextInt();
    int ans=-1;
    if(A<=9&&B<=9){
      ans=A*B;
      }
    System.out.println(ans);
  }
}

Measured memory_bytes: 22612
a, b = map(int, input().split())

if a%2 == 0:
    if b%2 == 0:
        ans = int(((b-a)/2) % 2) ^ b
    else:
        ans = int((b-a+1)/2) % 2
else:
    if b%2 == 0:
        ans = a ^ b ^ int(((b-a-1)/2) % 2)
    else:
        ans = a ^ int(((b-a)/2) % 2)
print(ans)

Measured memory_bytes: 3060
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a[] = new int[3];
		for(int i = 0; i < 3; i ++) {
			a[i] = sc.nextInt();
		}
		int max = 0;
		int sum = 0;
		for(int i = 0; i < 3; i ++) {
			max = Math.max(max, a[i]);
			sum += a[i];
		}
		System.out.println(sum - max);
	}
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            string s_ = s;
            for (int i = s.Length - 1; i >= 1; i--)
            {
                if (s[i - 1] < s[i])
                {
                    s_ = s.Substring(0, i - 1);
                    break;
                }
            }
            if (Next(s, s) != "-1") Console.WriteLine(Next(s, s));
            else Console.WriteLine(Next(s_, s));
        }

        static string Next(string s, string v)
        {
            for (char c = 'a'; c <= 'z'; c++)
            {
                if (string.Compare(v, s + c.ToString()) < 0)
                {
                    if (Judge(s + c.ToString()))
                    {
                        return s + c.ToString();
                    }
                }
            }
            return "-1";
        }

        static bool Judge(string s)
        {
            for (char c = 'a'; c <= 'z'; c++)
            {
                if (s.Count(x => x == c) > 1) return false;
            }
            return true;
        }
    }
}

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

long long int N,ans = 0;

int main()
{
    scanf("%lld",&N);
    ans += (N / 11) * 2 + ((N % 11) + 6 - 1) / 6;
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 256
using System.Text;
using System.Linq;
using System;

public class P
{
    public int id { get; set; }
    public int city { get; set; }
    public int no { get; set; }
    public int y { get; set; }
}

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var m = int.Parse(line[1]);
        var ps = new P[m];
        for (int i = 0; i < m; i++)
        {
            line = Console.ReadLine().Trim().Split(' ');
            var p = int.Parse(line[0]);
            var y = int.Parse(line[1]);
            ps[i] = new P { id = i, city = p, y = y };
        }
        var ps2 = ps.OrderBy(x => x.city).ThenBy(x => x.y).ToArray();
        var pre = ps2[0].city;
        ps2[0].no = 1;
        var pp = 1;
        for (int i = 1; i < m; i++)
        {
            if (pre == ps2[i].city) { ps2[i].no = ++pp; }
            else { ps2[i].no = 1; pp = 1; pre = ps2[i].city; }
        }
        var sb = new StringBuilder();
        foreach (var x in ps2.OrderBy(y => y.id).ToArray())
        {
            sb.Append(string.Format("{0:000000}", x.city));
            sb.Append(string.Format("{0:000000}\n", x.no));
        }
        Console.Write(sb);
    }
}


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

int main() {


    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n  = 0;
    scanf("%d", &n);
    float l = (float) n/3;
    printf("%f", pow(l, 3));


    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <stack>
#include <string>
#include <deque>
#include <map>
#include <algorithm>

using namespace std;

//--------------------
int gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a % b);
}

//------------
void func() {
    int N;
    cin >> N ;
    for (int i = 0; i <= N / 4 ; ++i) {
        for (int j = 0; j <= N / 7 ; ++j) {
            if(4 * i + 7 * j == N) {
                cout << "Yes" << endl;
                return;
            }
        }
    }
    cout << "No" << endl;
}

int main() {
    func();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

// AtCoder
// #include <atcoder/all>
// using namespace atcoder;

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...)
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
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; }
#define fls(x) (64 - __builtin_clzll(x))
#define pcnt(x) __builtin_popcountll(x)
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    if (s.back() == 's') cout << s << "es\n";
    else cout << s << "s\n";
    /***************************************************/
    /* Submit this code from the browser if using ACL! */
    /***************************************************/
    return 0;
}

Measured memory_bytes: 3652
#include <stdio.h>

int main(){
	for(int i = 0; i < 2000000; ++i) putchar('(');

	int a, b, c, d;
	while(1){
		scanf("%d%d%d%d", &a, &b, &c, &d);
		if(a == 0){ break; }
		printf("%d+%d+%d+%d\n", a, b, c, d);
	}
}

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

int main(){
	int m,n;
	cin>>m>>n;
	vector<vector<bool>> choco(m,vector<bool>(n));
	for(int c,i=0; i<m; i++){
		for(int j=0; j<n; j++){
			cin>>c;
			choco[i][j] = !!i != !!c;
		}
	}
	int ans=0;
	for(vector<bool> row : choco){
		int max=-1;
		for(int e=0; e<n; e++){
			int cnt=0;
			for(int i=0; i<n; i++){
				if(e==0){
					cnt += i==n-1 == row[i] ? 1 : 0;
				}else if(e==n-1){
					cnt += i==0 == row[i] ? 1 : 0;
				}else{
					cnt += (i==0 || i==n-1 || i==e) == row[i] ? 1 : 0;
				}
			}
			if(max < cnt) max = cnt;
		}
		ans += max;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3160
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <stack>
#include <queue>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
using ld = long double;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    ll N, X, Y, i, j, a, b;
    ll d[2010][2010], count[3000]={0};

    cin >> N >> X >> Y;

    for(i=1; i<=N-1; i++){
        for(j=i+1; j<=N; j++){
            if(i<=X && Y<=j){ // 1
                d[i][j] = X-i + 1 + j-Y;
            }

            else if(X<=i && j<=Y){ // 2
                a = j-i;
                b = i-X+1+Y-j;
                d[i][j] = min(a,b);
            }

            else if(i<=X && X<=j && j<=Y){
                a = j-i;
                b = X-i+1+Y-j;
                d[i][j] = min(a,b);
            }

            else if(X<=i && i<=Y && Y<=j){
                a = j-i;
                b = i-X+1+j-Y;
                d[i][j] = min(a,b);
            }

            else{
                d[i][j] = j-i;
            }
        }
    }

    for(i=1; i<=N-1; i++){
        for(j=i+1; j<=N; j++){
            count[d[i][j]]++;
        }
    }

    for(i=1; i<=N-1; i++){
        cout << count[i] << endl;
    }

    return 0;
}

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

using namespace std;

int main(){
    string sentence;
    
    while(true){
        getline(cin,sentence);
        if(sentence[0]=='0') break;
        int sentence_len = sentence.length();
    
        int sum = 0;
        for(int i = 0;i < sentence_len;i++){
            sum += sentence[i] - '0';
        }
        cout << sum << "\n";
    }
    
    return 0;
}


Measured memory_bytes: 3128
#include<bits/stdc++.h>
using namespace std;
int f[3005][3005];
int path[3005][3005];
main()
{
    string s,t;
    cin>>s>>t;
    for(int i=0;i<s.length();i++)
    {
        for(int j=0;j<t.length();j++)
        {
            if(s[i]==t[j])
            {
                f[i+1][j+1]=f[i][j]+1;
                path[i+1][j+1]=0;
            }
            else if(f[i+1][j]>f[i][j+1])
            {
                f[i+1][j+1]=f[i+1][j];
                path[i+1][j+1]=1;
            }
            else
            {
                f[i+1][j+1]=f[i][j+1];
                path[i+1][j+1]=2;
            }
        }
    }
//    cout<<f[s.length()][t.length()]<<endl;
    int i=s.length();
    int j=t.length();
    string ss="";
    while(i>0&&j>0)
    {
//        cout<<123;
        if(path[i][j]==0)
        {
            ss=t[j-1]+ss;
            i--;
            j--;
        }
        else if(path[i][j]==1)
        j--;
        else i--;
    }
    cout<<ss;
}


Measured memory_bytes: 70784
function main(input) {
  const lines = input.split('\n');
  lines.forEach(line => {
    if (line.length === 0) {
      return;
    }
    const vs = line.split(' ');
    console.log(flow(parseInt(vs[0], 10), parseInt(vs[1], 10)));
  });
}

function flow(length, start) {
  var result = 0;
  var minimum = null;
  for(var i = 1; i <= length; i++) {
    var current = start+i-1;
    if (minimum === null) {
      minimum = current;
    }
    if (Math.abs(minimum) > Math.abs(current)) {
      minimum = current;
    }
    result += start+i-1;
  }
  if (minimum === null) {
    minimum = 0;
  }
  return result - minimum;
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007
int main() {
	ll h,w;
	cin>>h>>w;
	ll dx[4]={1,0,-1,0};
	ll dy[4]={0,1,0,-1};
	ll ch,cw,dh,dw;
	cin>>ch>>cw>>dh>>dw;
	ch--;cw--;dh--;dw--;
	char s[1002][1003];
	ll ans[1002][1002];
	for(ll i=0;i<h;i++){
		for(ll j=0;j<w;j++){
			cin>>s[i][j];
			ans[i][j]=-1;
		}
	}
	queue<pair<ll,ll>>q,r;
	q.push(make_pair(ch,cw));
	ans[ch][cw]=0;
	while(q.size()!=0){
		while(q.size()!=0){
			pair<ll,ll>now=q.front();
			q.pop();
			ll nowh=now.first;
			ll noww=now.second;			r.push(make_pair(nowh,noww));
			for(ll i=0;i<4;i++){
				ll nexh=nowh+dx[i];
				ll nexw=noww+dy[i];
				if(nexh<0||nexw<0||nexh==h||nexw==w){
					continue;
				}
				if(s[nexh][nexw]=='#'){
					continue;
				}
				if(ans[nexh][nexw]!=-1){
					continue;
				}
				ans[nexh][nexw]=ans[nowh][noww];
				q.push(make_pair(nexh,nexw));
				r.push(make_pair(nexh,nexw));
			}
		}
		while(r.size()!=0){
			pair<ll,ll>now=r.front();
			r.pop();
			ll nowh=now.first;
			ll noww=now.second;
			for(ll i=-2;i<3;i++){
				for(ll j=-2;j<3;j++){
					if(i==0&&j==0){
						continue;
					}
					ll nexh=nowh+i;
					ll nexw=noww+j;
					if(nexh<0||nexw<0||nexh>=h||nexw>=w){
					continue;
					}
					if(s[nexh][nexw]=='#'){
					continue;
					}
					if(ans[nexh][nexw]!=-1){
					continue;
					}
					ans[nexh][nexw]=ans[nowh][noww]+1;
					if(nexh==dh&&nexw==dw){
					cout << ans[nexh][nexw];
					return 0;
					}
					q.push(make_pair(nexh,nexw));
				}
			}
		}
	}
	cout << ans[dh][dw]<<endl;
	// your code goes here
	return 0;
}

Measured memory_bytes: 12640
a,b=map(int,input().split())
if a==1 and b!= 1:
    a += 13
    if a>b:
     print('Alice')
    elif b>a:
     print('Bob')
    else:
     print('Draw')
elif b==1 and a!= 1:
    b += 13
    if a>b:
     print('Alice')
    elif b>a:
     print('Bob')
    else:
     print('Draw')
elif a==1 and b== 1:
     print('Draw')
else:
    if a>b:
     print('Alice')
    elif b>a:
     print('Bob')
    else:
     print('Draw')

Measured memory_bytes: 9144
# coding: utf-8
import queue
nodelist={}
n=int(input())
dist={}
used={}
for i in range(n):
    line=list(map(int,input().split()))
    nodelist[line[0]]=[]
    dist[line[0]]=99999999
    used[line[0]]=False
    j=2
    while True:
        try:
            nodelist[line[0]].append((line[j],line[j+1]))
            j+=2
        except:
            break
q=queue.PriorityQueue()
dist[0]=0
for node in nodelist.keys():
    q.put((dist[node],node))

while not q.empty():
    node=q.get()
    if used[node[1]]:
        continue
    else:
        used[node[1]]=True
    for edge in nodelist[node[1]]:
        if dist[edge[0]]>dist[node[1]]+edge[1]:
            dist[edge[0]]=dist[node[1]]+edge[1]
            q.put((dist[edge[0]],edge[0]))

for d in dist.items():
    print(*d)


Measured memory_bytes: 7552
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // min, max, sort, swap
#include <numeric> // iota, accumulate, inner_product
#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)>
using namespace std;
#define rep(i,n) rep1(i,0,n)
#define rep1(i,m,n) for(int i=m;i<(n);i++)
#define All(v) (v).begin(),(v).end()
using ll = long long;
const int inf = 1<<30;
const ll mod = 1000000007;
const ll INF = 100000000000000000LL;
const double PI = acos(-1);
int main(){
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    vector<int> A(a);
    rep(i, a) cin >> A[i];
    cout << (a + b - 1) / b << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,sum=0;
  cin >> a >> b;
  for(int i=a; i<=b; i++){
    string s = to_string(i);
    if(s[0]==s[4] &&s[1]==s[3]){
      sum++;
    }
  }
  cout<<sum;
 
}

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

int main() {
    long n, m;
    const long MOD = 1e9 + 7;
    cin >> n >> m;
    vector<long> stair(n + 1, -1);
    stair.at(n) = stair.at(n - 1) = 1;
    rep(i, m) {
        long t;
        cin >> t;
        stair.at(t) = 0;
    }
    for(int i = n - 2; i >= 0; i--) {
        if(stair.at(i) == -1) stair.at(i) = (stair.at(i + 1) + stair.at(i + 2)) % MOD;
    }
    cout << stair.at(0) << endl;
}

Measured memory_bytes: 1024
var board = [];




var dx = [1,1,1,0,0,-1,-1,-1];
var dy = [1,0,-1,1,-1,1,0,-1];


function check(x,y){
    var rx = x,ry = y;

    for(var i = 0;i < 8;i++){
        x = rx + dx[i];y = ry + dy[i];
        while(x >= 0 && x < 8 && y >= 0 && y < 8){
            if(board[x][y])
                return false;
            x += dx[i];y += dy[i];
        }
    }
    return true;
}

function eightqueens(row){

    if(row >= 8){
        for(var i = 0;i < 8;i++){
            var s = "";
            for(var j = 0;j < 8;j++)
                if(board[i][j])
                    s += "Q";
                else
                    s += ".";
            console.log(s);
        }
        return; 
    }
    var k = 0;
    for(;k < 8;k++){
        if(board[k][row])
            break;
    }
    if(k < 8){
        eightqueens(row + 1);
    }
    else{
        for(var i = 0;i < 8;i++){
            if(check(i,row)){
                board[i][row] = true;
                eightqueens(row + 1);
                board[i][row] = false;
            }
        }
    }
}

function Main(input){
    input = input.split("\n");

    for(var i = 0;i < 8;i++){
        board[i] = new Array(8);
        for(j = 0;j < 8;j++)
            board[i][j] = false;
    }
    
    var k = parseInt(input[0],10);

    for(var i = 1;i <= k;i++){
        input[i] = input[i].split(" ");
        var a = parseInt(input[i][0],10);var b = parseInt(input[i][1],10);
        board[a][b] = true;
    }

    eightqueens(0);
}
Main(require("fs").readFileSync("/dev/stdin","utf8"));

Measured memory_bytes: 15488
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
using namespace std;

#define Getsign(n) ((n > 0) - (n < 0))

typedef vector<int> Ivec;
typedef pair<int, int> Pos;

int main() {
	int n;

	scanf("%d", &n);

	int y, m, d;
	for (int i = 0; n > i; i++) {
		scanf("%d %d %d", &y, &m, &d);
		int sum = (y-1)*195 + (y-1)/3*5+ d-1;
		if (!(y % 3))
			sum += (m - 1) * 20;
		else
			sum += (m - 1) * 20 - (int)((m - 1)/2);
		printf("%d\n", 196470-sum);
	}


	return 0;
}

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


using namespace std;

#define ll long int
#define ull unsigned long long int

#define I_read()  freopen("input.tex","r",stdin);

#define O_write() freopen("output.txt","w",stdout);


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

//	I_read();
//	O_write();

    ll a;
    ull b,temp,rem=0,numt=0;
  
  	cin>>a >>b;
  
  	ll town[a],trv[a],ptow=0;
  	bool pass[a];
  
  	for(ll i=0;i<a;i++)
    {
    	cin>>town[i];
	pass[i]=0;
//	cout<<pass[i]<<" ";
    }
  	cout<<endl;
  	
  	while( pass[ptow] != 1 && numt < b)
    {
      	trv[ptow] =numt;
      	pass[ptow] = 1;
//	cout<<ptow+1<<"->";
      	ptow= town[ptow] -1;
      	numt++;
    }
  	
//	cout<<"numt="<<numt<<"pass[ptow]="<<pass[ptow]<<endl;

  	if( numt != b)
    { 
//	cout<<"not-compleated-";
    	temp = numt - trv[ptow] ;
      
      	rem = (b - numt) % temp ;

//	cout<<"temp="<<temp<<"rem="<<rem<<"->";
    }
  
  	while(  rem > 0)
    {
      	//trv[ptow] =numt;
      	//pass[ptow] = 1;
      	ptow= town[ptow] -1;
      	rem--;
    }
  	cout<<ptow+1<<endl;
 return 0;	
}



Measured memory_bytes: 6936
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>

using namespace std;
int main() {

	int n;

	cin >> n;

	vector<int> a(n);

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

	sort(a.begin(), a.end());
	
	cout << a.back() - a.front();

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
const int mod = 1000000007;

int main(){
    int n;
    cin >> n;
    int a[n][n];
    for(int i = 0; i < n*n; i++)    cin >> a[i/n][i%n];
    vector<int> dp(1<<n, 0);
    dp.back() = 1;
    vector<int> pop(1<<n, n);
    for(int i = 0; i < 1<<n; i++){
        for(int j = 0; j < n; j++)  pop[i] -= (i>>j)&1;
    }
    for(int i = 0; i < n; i++){
        vector<int> ndp(1<<n, 0);
        for(int j = 0; j < 1<<n; j++){
            if(pop[j] != i) continue;
            for(int k = 0; k < n; k++){
                if(a[i][k] && (j>>k)&1) ndp[j^(1<<k)] = (ndp[j^(1<<k)]+dp[j])%mod;
            }
        }
        dp = ndp;
    }
    cout << dp[0] << endl;
    return 0;
}

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

using namespace std;

const int N = 10000 + 4;;

int n  , r;

int main()
{
    cin>>n>>r;
    if(n>=10)
    {
        cout<<r;
    }
    else
    {
        cout<<r + 100*(10-n);
    }
    return 0;
}



Measured memory_bytes: 256
program main
  implicit none
  integer i,D,j,last(26),day, score(26)
  integer,allocatable :: c(:),s(:,:)
  read(*, *)D
  allocate(c(26))
  allocate(s(D,26))
  read(*, *) (c(i), i = 1,26)
  do i = 1,D
    read(*, *) (s(i,j), j = 1,26)
  end do
  last = 0
  do i = 1,D-3
    last = last + 1
    score = 0
    do j = 1,26
      score(j) = 4*s(i,j) - 5*s(i+1,j) - 0.6*s(i+2,j) - 0.3*s(i+3,j) + 10*last(j)*c(j)
    end do
    day = 1
    do j = 1,26
      if (score(j) > score(day)) then
        day = j
      end if
    end do
    write(*, *) day
    last(day) = 0
  end do
  do i = D-2,D
    last = last + 1
    score = 0
    do j = 1,26
      score(j) = s(i,j) + last(j)*c(j)
    end do
    day = 1
    do j = 1,26
      if (score(j) > score(day)) then
        day = j
      end if
    end do
    write(*, *) day
    last(day) = 0
  end do
end program main

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

template <typename T>
void print_vec(const vector<T>& v, bool is_reverse=false, ll num=0){
  if(num == 0) num = (ll)v.size();
  cout << endl; cout << "i=  ";for(ll i=0; i<num; i++) cout << i << "   ";cout << endl;  
  cout << "    ";
  if(is_reverse) for(ll i=num-1; i>=0; i--){ cout<<v[i]; if(i!=0) cout<<"   ";}
  else for(ll i=0; i<num; i++){ cout<<v[i]; if(i!=num-1) cout<<"   ";}
  cout << endl;
}

// template <typename T>
// void print_pairvec(const vector<T> &v, ll num=0){
//   if(num == 0) num = (ll)v.size();
//   cout << endl; for(ll i=0; i<num; i++){ cout << v[i].first << " " << v[i].second << endl;}
// }
template <typename T>
void print_pairvec(const T &_pair, ll num=0){
  cout << endl; for(pair<ll, int> x: _pair){ cout << x.first << " " << x.second << endl;}
}

template <typename T>
void print_vec2(const vector<vector<T>>& v){
  cout << endl; cout << "       ";
  for(ll i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(ll i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(ll j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}

// GCD, LCM
// https://youtu.be/8lm8o8L9Bmw?t=2285
// https://youtu.be/XI8exXVxZ-Q?t=3595
// https://youtu.be/F2p_e6iKxnk?t=843
// ll GCD(ll a, ll b) { return b?GCD(b,a%b):a;}
// ll LCM(ll a, ll b) { return a/GCD(a,b)*b;}

ll GCD(ll a, ll b){
  if(b == 0) return a;
  return GCD(b, a%b);//オーバーフローしないように先にgcd(a, b)で割る
}
ll LCM(ll a, ll b){return a/GCD(a, b)*b;}

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

  x.push_back(X);
  sort(x.begin(), x.end());
  vector<ll> interval(N);
  for(int i=1; i<(int)x.size(); i++) interval[i-1] = x[i] - x[i-1];
  // cout << " x: "; print_vec(x);
  // cout << " interval: "; print_vec(interval);
  ll gcd = 0;
  for(int i=0; i<(int)interval.size(); i++) gcd = GCD(gcd, interval[i]);
  cout << gcd << endl; 

  return 0;
  // cout << fixed;//小数点を確実に10桁で表示するためのもの
  // cout << setprecision(10); 
}


Measured memory_bytes: 4660
#include <stdio.h>
#include <iostream>
using namespace std;

int main(void){
	int n, nn, i, j;
	cin >> n;
	nn = n*(n-1)/2;
	int a[nn], b[nn], c[nn], d[nn], win[n], p[n], swap[1];
	for (i = 0; i < n; ++i){
		win[i] = 0;
	}
	for (i = 0; i < nn; ++i){
		scanf("%d %d %d %d", &a[i], &b[i], &c[i], &d[i]);
		if (c[i] > d[i]){
			win[a[i]-1] += 3;
		}else if (c[i] < d[i]){
			win[b[i]-1] += 3;
		}else{
			win[a[i]-1] += 1;
			win[b[i]-1] += 1;
		}
	}
	for (i = 0; i < n; ++i){
		p[i] = 1;
	}
	for (i = 0; i < n; ++i){
		for (j = 0; j < n; ++j){
			if (win[i] < win[j]){
				p[i]++;
			}
		}
		printf("%d\n", p[i]);
	}
	return 0;
}

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

using namespace std;

int N;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	cin >> N;
	
	long long ans = 0LL;
	for (int i = 1; i <= N; i++)
		ans += (long long)((N + i - 1) / i - 1);
	
	cout << ans << "\n";
	
	return 0;
}


Measured memory_bytes: 3648
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int k = Integer.parseInt(sa[1]);
		Susi[] arr = new Susi[n];
		for (int i = 0; i < n; i++) {
			sa = br.readLine().split(" ");
			Susi o = new Susi();
			o.t = Integer.parseInt(sa[0]);
			o.d = Integer.parseInt(sa[1]);
			arr[i] = o;
		}
		br.close();

		Arrays.sort(arr, (o1, o2) -> o2.d - o1.d);
		long ans = 0;
		long sumd = 0;
		Map<Integer, Integer> map = new HashMap<>();
		for (int i = 0; i < k; i++) {
			addCntMap(map, arr[i].t);
			sumd += arr[i].d;
		}
		ans = sumd + (long) map.size() * map.size();

		long val = ans;
		int idx = k - 1;
		for (int i = k; i < n; i++) {
			if (!map.containsKey(arr[i].t)) {
				while (idx >= 0 && map.get(arr[idx].t) == 1) {
					idx--;
				}
				if (idx < 0) {
					break;
				}
				long d1 = arr[i].d - arr[idx].d;
				long size = map.size();
				long d2 = (size + 1) * (size + 1) - size * size;
				val += d1 + d2;
				ans = Math.max(ans, val);
				map.put(arr[idx].t, map.get(arr[idx].t) - 1);
				map.put(arr[i].t, 1);
				idx--;
			}
		}
		System.out.println(ans);
	}

	static void addCntMap(Map<Integer, Integer> map, Integer key) {
		if (map.containsKey(key)) {
			map.put(key, map.get(key) + 1);
		} else {
			map.put(key, 1);
		}
	}

	static class Susi {
		int t, d;
	}
}


Measured memory_bytes: 50496
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include <cassert>
    #include <cmath>
    #include<cstdint>

    #define INF 1e7
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))

    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<int,int>;

    int main(){
        int a,p;cin>>a>>p;
        cout<<(a*3+p)/2;
    }
    


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

int main(){
	int n,q,l,r;
	cin>>n>>q;
	string s,tmp;
	cin>>s;
	rep(i,s.size()-1){
		tmp="";
		tmp+=s[i];tmp+=s[i+1];
		if(tmp=="AC")s[i]='a';
	}
	int t[s.size()];
	rep(i,s.size())t[i]=0;
	if(s[0]=='a')t[1]=1;
	rep(i,s.size()-1){
		t[i+1]=t[i];
		if(s[i]=='a')t[i+1]++;
	}
	rep(i,q){
		cin>>l>>r;
		cout<<t[r-1]-t[l-1]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1408
import java.util.LinkedList;
import java.util.Scanner;

//And Then There Was One
public class Main{

	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			int n = sc.nextInt(), k = sc.nextInt(), m = sc.nextInt();
			if((n|k|m)==0)break;
			LinkedList<Integer> l = new LinkedList<Integer>();
			for(int i=0;i<n;i++)l.add(i);
			int p = m-1;
			l.remove(p);
			while(l.size()>1){
				p = (p+k-1)%l.size();
				l.remove(p);
			}
			System.out.println(l.get(0)+1);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 0
#include <cstdio>
#include <cstring>
#define MAXN 200010
#define LL long long

struct edge{
	int to,next;
	edge(int _to=0,int _next=0):to(_to),next(_next){}
}e[MAXN<<1];

LL n,m;
int g[MAXN],nume;
int c[MAXN],nowc,d[MAXN],tag[MAXN];

void addEdge(int u,int v){
	e[nume]=edge(v,g[u]);
	g[u]=nume++;
}

void dfs(int x){
	c[x]=nowc;
	for(int i=g[x];~i;i=e[i].next)
		if(!c[e[i].to]){
			d[e[i].to]=!d[x];
			dfs(e[i].to);
		}
}

int main(){
	memset(g,-1,sizeof g);
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=m;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		addEdge(u,v); addEdge(v,u);
	}
	LL c0=0,c1=0,c2=0;
	for(int i=1;i<=n;i++)
		if(!c[i]){
			if(g[i]==-1){
				c0++;
				continue;
			}
			nowc=i;
			d[i]=0;
			dfs(i);
		}
	for(int x=1;x<=n;x++)
		for(int i=g[x];~i;i=e[i].next)
			if(d[x]==d[e[i].to])
				tag[c[x]]=1;
	for(int i=1;i<=n;i++)
		if(c[i]==i){
			if(tag[i]) c2++;
			else c1++;
		}
	LL ans=0;
	ans+=c0*c0+2*c0*(n-c0);
	ans+=(c1+c2)*(c1+c2)+c1*c1;
	printf("%lld\n",ans);
}


Measured memory_bytes: 7040
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iomanip>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;

#define ld long double
#define ll long long

map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int N;
  cin >> N;
  int A[100010]={0};
  int x;
  int ans=0;
  int b=0;
  for(int i=0;i<N;i++){
    cin >> x;
    A[x]++;
    b=max(x,b);
  }
  int t=0;
  for(int i=0;i<=b;i++){
    if(A[i]>=1){
      ans++;
    }else if(A[i]==0){
      continue;
    }
    if(A[i]%2==0){
      t++;
    }
  }
  cout << ans-(t%2) << endl;
  return 0;
}

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

int main()
{
	long long s;
	long long x1,y1,x2,y2,x3,y3;
	scanf("%lld\n",&s);
	long long p,q;
	x1=0;
	y2=0;
	p=sqrt(s);
	x3=p;
	y1=p;
	x2=0;
	y3=0;
	if (p*p==s)
	{
		y3=y1;
	}
	else
	if (s>p*p)
	{
		p=p+1;
		x3=p;
		y1=p;
		y3=y1-1;
		x2=p*p-s;
	}
	else
	{
		y3=y1-1;
		x2=p*p-s;
	}
	printf("%lld %lld %lld %lld %lld %lld\n",x1,y1,x2,y2,x3,y3);
    return 0;
 } 


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

using namespace std;

#define FAST       			ios_base :: sync_with_stdio(false); cin.tie(NULL);
#define endl "\n"

typedef long long int  ll;
typedef unsigned long long int ull;

int main()
{
	FAST;
	string str;
	int a, b, c, d;
	cin >> str;
	a = str[0] - '0';
	b = str[1] - '0';
	c = str[2] - '0';
	d = str[3] - '0';

	for (int i = 0 ; i < 2 ; i++)
	{
		for (int j = 0 ; j < 2 ; j++)
		{
			for (int k = 0 ; k < 2 ; k++)
			{
				int temp1, temp2, temp3;
				if (i == 0)
					temp1 = 1;
				else
					temp1 = -1;

				if (j == 0)
					temp2 = 1;
				else
					temp2 = -1;

				if (k == 0)
					temp3 = 1;
				else
					temp3 = -1;

				b = b * temp1;
				c = c * temp2;
				d = d * temp3;

				if (a + b + c + d == 7)
				{
					cout << a;
					if (temp1 == 1)
						cout << "+";
				    
				
				    cout << b;
					if (temp2 == 1)
						cout << "+";
					
					cout << c;
					
					if (temp3 == 1)
						cout << "+";
					    
					    
					cout << d;
					cout << "=7";
					return 0;
				}
				
				b = b * temp1;
				c = c * temp2;
                d = d * temp3;
			}
		}
	}


	return 0;
}



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

int mult(int a , int b);
int add(int a , int b);

int main(int argc, const char * argv[]) {
    int a,b;
    cin >> a >> b;
    cout << mult(a,b) <<  " " << add(a,b) << endl;
    return 0;
}

int add(int a, int b){
    return a*2+b*2;
}

int mult(int a , int b){
        return a*b;
}

Measured memory_bytes: 1164
n = gets.to_i
a = gets.split.map(&:to_i)
count = 0

n.times do |i|
    (i+1).upto(n-1) do |j|
        (j+1).upto(n-1) do |k|
            b = [a[i],a[j],a[k]]
            if b[0]!=b[1] and b[1]!=b[2] and b[0]!=b[2] and b.max < b.sum-b.max 
                count+=1
            end
        end
    end
end
p count

Measured memory_bytes: 14276
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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 int mod=1e9+7;
const int INF=1001001001;

int f(int x){
  if(x==0){return 0;}
  int p=__builtin_popcount(x);
  return f(x%p)+1;
}

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

  int pop=0;
  for(int i=0;i<N;i++){
    if(S[i]=='1'){pop++;}
  }

  vector<int>ans(N);
  for(int r=0;r<2;r++){
    int basep=pop;
    if(r==0){basep++;}
    else{basep--;}
    
    if(basep<=0){continue;}

    int base=0;
    int s=1;
    for(int i=N-1;i>=0;i--){
      if(S[i]=='1'){(base+=s)%=basep;}
      (s*=2)%=basep;
    }
    s=1;
    int start=0;
    for(int i=N-1;i>=0;i--){
      if(S[i]-'0'==r){
        if(r==0){(start=base+s)%=basep;}
        else if(r==1){(start=base-s+basep)%=basep;}
        ans[i]=f(start)+1;
      }
      (s*=2)%=basep;
    }
  }
  for(int i=0;i<N;i++){
    cout<<ans[i]<<endl;
  }
  return 0;  
}

Measured memory_bytes: 4412
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>

using namespace std;
using int64 = long long;

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> p(n, vector<int>());

    for (int i=0; i<m; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        p[a].push_back(b);
        p[b].push_back(a);
    }

    cout << "Yes" << endl;

    queue<int> que;
    que.push(0);
    vector<int> ans(n, -1);
    while(!que.empty()) {
        int par = que.front();
        que.pop();
        for (auto i : p[par]) {
            if (ans[i] != -1) continue;
            ans[i] = par;
            que.push(i);
        }
    }

    for (int i=1; i<n; i++)
        cout << ans[i]+1 << endl;
}


Measured memory_bytes: 9688
import sys
import math
import collections
from collections import deque
import heapq
#n = int(input())
n, m = map(int, sys.stdin.readline().split())
#s = input()
a = list(map(int, sys.stdin.readline().split()))

x = sum(a)
y = x/(4*m)

a.sort(reverse = True)

for i in range(m):
    if a[i] < y:
        print("No")
        sys.exit()

print("Yes")


    


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


long long dp[1000007][2];
void solve(string a){
    int n = a.size();
    for(int i=1;i<=n;++i)dp[i][0]=dp[i][1] = INT_MAX;
    a = "_" + a;
    dp[n][0] = a[n];
    dp[n][1] = 10-a[n];
    for(int i=n-1;i>=1;--i)
    {
        dp[i][0] = min(dp[i+1][0] + a[i], dp[i+1][1] + a[i]+1);
        dp[i][1] = min(dp[i+1][0] + 10-a[i],dp[i+1][1] + (10-a[i]-1));
    }
    cout<<min(dp[1][0],dp[1][1]+1)<<endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    string N;
    cin>>N;
    for(int i=0;i<N.size();++i)N[i]-='0';
    solve(N);
    return 0;
}


Measured memory_bytes: 18948
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  vector<double> v(n);
  for (int i = 0; i < n; i++)
    cin >> v[i];
  
  sort(v.begin(), v.end());
  for (int i = 1; i < n; i++)
    v[i] = (v[i] + v[i-1]) / 2;
  cout << v[n-1] << endl;  
}

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

using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,n,m) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define VEC2(x,a,b) vector<vector<ll>> x = vector<vector<ll>>(a,vector<ll>(b,0))
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "; cout<<endl
#define cout(n) cout<<fixed<<setprecision(n)

vector<string> judge(vector<string> v,ll h, ll w, ll n){
  vector<string> s;
  s=v;
  FOR(i,0,h){
    ll num=1;
    FOR(j,1,w){
      if(v[i][j]==v[i][j-1]){
        num++;
      }
      else num=1;

      if(num>=n){
        FOR(k,j+1-num,j+1){
          s[i][k]='.';
        }
      }
    }
  }

  FOR(j,0,w){
    ll num=1;
    FOR(i,1,h){
      //cout<<"i="<<i<<"j="<<j<<endl;
      if(v[i][j]==v[i-1][j]){
        num++;
      }
      else num=1;

      //cout<<num<<endl;
      if(num>=n){
        FOR(k,i+1-num,i+1){
          //cout<<k<<endl;
          s[k][j]='.';
        }
      }
      //cout<<3<<endl;
    }
  }
  return s;

}

vector<string> lack(vector<string> v, ll h, ll w, ll n){
  FOR(j,0,w){
    FORr(i,h-2,0){
      //cout<<"i="<<i<<"j="<<j<<endl;
      if(v[i][j]!='.'){
        ll x=i;
        while(v[x+1][j]=='.'){
          x++;
          if(x==h-1)break;
        }
        char c = v[i][j];
        v[i][j]='.';
        v[x][j]=c;
      }
    }
  }
  return v;
}

bool ans(vector<string> v){
  FOR(i,0,v.size()){
    FOR(j,0,v[0].size()){
      if(v[i][j]!='.') return false;
    }
  }
  return true;
}


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

  ll h,w,n;
  cin>>h>>w>>n;
  vector<string> v(h);
  string res = "NO";

  cinv(v,0,h);
  FOR(i,0,h){
    FOR(j,1,w){
      vector<string> v1 = v;

      char c;
      c=v1[i][j-1];
      v1[i][j-1]=v1[i][j];
      v1[i][j]=c;
      v1=lack(v1,h,w,n);
      while(v1!=judge(v1,h,w,n)){
        v1=judge(v1,h,w,n);
        v1=lack(v1,h,w,n);
      }

      /*cout<<"i="<<i<<" j="<<j<<endl;
      FOR(i,0,h){
        FOR(j,0,w){
          cout<<
        }
      }*/

      if(ans(v1))res="YES";
    }
  }
  cout<<res<<endl;


}



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

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; }

//using Matrix = vector< vector<int> >;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1 << 30;
int dx[5] = {0, 0, 1, -1, 0}, dy[5] = {1, -1, 0, 0, 0};

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

	int r_cnt = 0, b_cnt = 0;
	for(int i=0;i<s.size();i++) {
		if(s[i] == 'R') r_cnt++;
		else b_cnt++;
	}

	if(b_cnt < r_cnt) cout<< "Yes" <<endl;
	else cout<< "No" <<endl;
	
	return 0;
}

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

using namespace std;

#ifdef LOCAL_DEBUG
#include <local_debug.h>
#define DEBUG(...) DBG2::print(#__VA_ARGS__, __LINE__, __VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define SZ(a) int((a).size())
#define REP(i,n) for(int i=0,_n=(n);i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)

typedef long long llong;
typedef vector<int> VI;
typedef vector<VI> VVI;

struct Camel {
   int K, L, R;
   friend ostream& operator<<(ostream& os, const Camel& c) {
      return os << "Camel " << c.K << ' ' << c.L << ' ' << c.R;
   }
};


namespace Greedy3 {

bool trace;

llong process(vector<Camel> camels) {
   sort(camels.begin(), camels.end(),
        [&] (Camel a, Camel b) {
           if (a.K != b.K)
              return a.K < b.K;
           return a.L-a.R > b.L-b.R;
        });

   llong res = 0;
   priority_queue< int, VI, greater<int> > pq;
   for (Camel c : camels) {
      if (trace) cerr << c << endl;
      if (c.K > SZ(pq)) {
         pq.push(c.L-c.R);
      }
      else {
         pq.push(c.L-c.R);
         pq.pop();
      }
   }

   while (!pq.empty()) {
      if (trace) cerr << "+ " << pq.top() << endl;
      res += pq.top();
      pq.pop();
   }
   return res;
}

llong solve(int N, vector<Camel> camels) {
   llong base = 0;

   vector<Camel> camels_left, camels_right;
   for (Camel c : camels) {
      if (c.L > c.R) {
         camels_left.push_back(c);
      }
      else if (c.L < c.R)
         camels_right.push_back({N-c.K, c.R, c.L});
      base += min(c.L, c.R);
   }

   if (trace) {
      DEBUG(base);
      DEBUG(camels_left);
      DEBUG(camels_right);
   }

   return base + process(camels_left) + process(camels_right);
}
}

int main(int argc, char* argv[]) {
   ios_base::sync_with_stdio(false); 
   cin.tie(nullptr);

   int TC;
   cin >> TC;
   FOR(tc, 1, TC) {
      int N;
      cin >> N;
      vector<Camel> camels;
      REP(i, N) {
         int K, L, R;
         cin >> K >> L >> R;
         camels.push_back({K, L, R});
      }
      llong res = Greedy3::solve(N, camels);
      cout << res << '\n';
   }

   return 0;
}


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

#define ll long long int
#define pb push_back
#define BOLT               \
  ios::sync_with_stdio(0); \
  cin.tie(0);              \
  cout.tie(0);
#define endl "\n"

int main()
{
  BOLT;
// #ifndef ONLINE_JUDGE

//   // For getting input from input.txt file
//   freopen("input.txt", "r", stdin);

//   // Printing the Output to output.txt file
//   freopen("output.txt", "w", stdout);

// #endif
    ll n,x,t;
    cin >> n>>x>>t;
    if(n%x==0)
      cout<<t*n/x;
    else
      cout<<t*((n/x)+1);  
}


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

#define N 10000
#define NIL -1

typedef struct Node{
  int parent;
  int right;
  int left;
}node;

node A[N];
int n;

void pre_order(int);
void in_order(int);
void post_order(int);

int main(){
  int left, right, num, root, i;

  scanf("%d", &n);

  for(i = 0; i < n; i++){
    A[i].parent = NIL;
    A[i].left = NIL;
    A[i].right = NIL;
  }

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

    if(left != NIL)
      A[left].parent = num;
    if(right != NIL)
      A[right].parent = num;
  }
  for(i = 0; i < n; i++)
    if(A[i].parent == NIL)
      root = i;

  printf("Preorder\n");
  pre_order(root);
  printf("\n");
  
  printf("Inorder\n");
  in_order(root);
  printf("\n");

  printf("Postorder\n");
  post_order(root);
  printf("\n");

  return 0;
}

void pre_order(int node){
  if(node == NIL)
    return;

  printf(" %d", node);

  pre_order(A[node].left);
  pre_order(A[node].right);
}

void in_order(int node){
  if(node == NIL)
    return;

  in_order(A[node].left);

  printf(" %d", node);

  in_order(A[node].right);
}

void post_order(int node){
  if(node == NIL)
    return;

  post_order(A[node].left);
  post_order(A[node].right);

  printf(" %d", node);
}


Measured memory_bytes: 2112
n = int(input())
work = [list(map(int,input().split())) for _ in range(n)]
work = sorted(work,key = lambda x:x[1])
a = [0] * n
a[0] = work[0][0]
for i in range(1,n):
    a[i] = a[i-1] + work[i][0]
ans = 'Yes'
for j in range(n):
    if a[j] > work[j][1]:
        ans = 'No'
        break
print(ans)

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

#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORTASC(c) sort((c).begin(), (c).end())
#define SORTDESC(c, t) sort((c).begin(), (c).end(), std::greater<t>());
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

const double PI = acos(-1.0);

using ll = long long;
using namespace std;

int main()
{
    vector<ll> h;

    ll tmp;
    REP(i, 10){
        cin >> tmp;
        h.PB(tmp);
    }

    SORTDESC(h, ll);

    cout << h[0] << endl << h[1] << endl << h[2] << endl;

    return 0;
}


Measured memory_bytes: 3096
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, int> LP;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> b(n), ans;
	rep(i,n) cin >> b[i];
	rep(i,n){
		for(int j = b.size()-1; j >= 0; --j){
			if(j+1 == b[j]){
				ans.push_back(b[j]);
				b.erase(b.begin() + j);
				break;
			}
		}
	}
	if(!b.empty()){
		cout << -1 << endl;
		return 0;
	}
	for(int i = n-1; i >= 0; --i) cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 3600
/* 
    HARSHAD VAGHASIYA
 
        @DAIICT
    
          H_M_Vaghasiya
    
            */
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define MAX_INT 100000
#define ld long double
#define pb push_back
#define mp make_pair
#define p_ push
int main()
{
    ll i,j,k,n,x,y;
    ll m,d;
    cin>>m>>d;
    ll ans=0;
    for(i=1;i<=m;i++){
        for(j=10;j<=d;j++){
            ll t1=j%10;
            ll t2=j/10;
            if(t1>=2 &&  t2>=2 && t1*t2==i){
                ans++;
            }
        }
    }
  cout<<ans<<endl;
    return 0;
} 

Measured memory_bytes: 256