akhauriyash/Code-Regression huggingface dataset:
#include <string>
#include <vector>
#include <iostream>
using namespace std;
int N, K, Q, h, g; vector<int> p[32]; string s;
vector<int> merge(vector<int> p1, vector<int> p2) {
	vector<int> ret(N);
	for (int i = 0; i < N; i++) ret[i] = p2[p1[i]];
	return ret;
}
vector<int> unit(int, int);
vector<int> expr(int, int);
vector<int> unit(int l, int r) {
	if (r - l == 1) return p[s[l] - 65];
	vector<int> res; int mul = 0;
	for (int i = l; i < r; i++) {
		if (48 <= s[i] && s[i] <= 57) mul = mul * 10 + (s[i] - 48);
		else if (i != r - 1) {
			res = expr(i + 1, r - 1);
			break;
		}
		else res = p[s[i] - 65];
	}
	vector<int> ret(N);
	for (int i = 0; i < N; i++) ret[i] = i;
	while (mul >= 1) {
		if(mul & 1) ret = merge(ret, res);
		res = merge(res, res);
		mul >>= 1;
	}
	return ret;
}
vector<int> expr(int l, int r) {
	vector<int> ret(N);
	for (int i = 0; i < N; i++) ret[i] = i;
	int pl = l, depth = 0;
	for (int i = l; i <= r; i++) {
		if (i != r && s[i] == '(') depth++;
		if (i != r && s[i] == ')') depth--;
		if (depth == 0 && (i == r || s[i] == '+')) {
			ret = merge(ret, unit(pl, i));
			pl = i + 1;
		}
	}
	return ret;
}
int main() {
	cin >> N >> K;
	for (int i = 0; i < K; i++) {
		cin >> s >> h;
		vector<int> inv(N);
		for (int j = 0; j < N; j++) inv[j] = j;
		for (int j = 0; j < h - 1; j++) {
			for (int k = 0; k < N - 1; k++) {
				cin >> g;
				if (g == 1) swap(inv[k], inv[k + 1]);
			}
		}
		p[s[0] - 65].resize(N);
		for (int j = 0; j < N; j++) p[s[0] - 65][inv[j]] = j;
	}
	cin >> Q;
	while(Q--) {
		cin >> s;
		vector<int> res = expr(0, s.size());
		vector<int> ret(N);
		for (int i = 0; i < N; i++) ret[res[i]] = i;
		for (int i = 0; i < N; i++) {
			if (i) cout << ' ';
			cout << ret[i] + 1;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3120
import java.util.Scanner;
import java.io.*;

public class Main{
	public static void main(String[] args){
		Scanner stdIn = null;
		long[] result = new long[10000];
		int index = 0;
		
		try{
			stdIn = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
			double v = 0;
			while( stdIn.hasNext() ){
				if( stdIn.hasNextDouble() ){
					v = stdIn.nextDouble();
				} else {
					stdIn.next();
				}
				double h = Math.floor((v*v/98)+1)+1;
				result[index] = (long)h;
				index++;
			}
			for(int i = 0; i < index; i++){
				System.out.println(result[i]);
			}
		} finally {
			if( stdIn != null ){
				stdIn.close();
			}
		}
	}
}

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

string shuffle(string &s,int &i)
{
    string s1,s2;
    s1 = s.substr(0, static_cast<unsigned long long int>(i));
    s2 = s.substr(static_cast<unsigned long long int>(i), s.length() - 1);
    return s2 + s1;
}
int main() {
    string s;
    int m,h;
    cin>>s;
    while (s!="-")
    {
        cin>>m;
        for (int i = 0; i < m; ++i) {
            cin>>h;
            s = shuffle(s,h);
        }
        cout<<s<<endl;
        cin>>s;
    }
    return 0;
}


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+5; 
int n,k;
int a[maxn];
set<int>s;
int ans=1;
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=k;i++) s.insert(a[i]);
	for(int i=k+1;i<=n;i++){
		ans+=*s.begin()!=a[i-k]||*--s.end()>a[i];
		s.erase(a[i-k]); s.insert(a[i]);
	}
	bool flag=0;
	int cnt=0;
	a[0]=-1;
	for(int i=1;i<=n;i++){
		if(a[i-1]<a[i]) cnt++;
		else cnt=1;
		if(cnt==k){
			flag=1;
			ans--;
		}
	}
	printf("%d\n",ans+flag);
	return 0;
} 

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

using namespace std;

int main(){
    int n;
    long long int ans=0;
    cin>>n;
    
    for(int i=1;i<=n;i++){
        if(i%3!=0 && i%5!=0)
            ans +=i;
    }
    
    cout<<ans<<endl;
}

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

#define REP(i, s, e) for(int i = (int)s; i < (int) e; i++)
#define rep(i, n) REP(i, 0 ,n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define fi first
#define se second
#define pb push_back
#define mp make_pair


typedef long long ll;

int perseInt(string s){
  bool f = s[0] == '-';
  int ret = 0;
  REP(i, f ? 1 : 0, s.size()) ret *= 10, ret += (s[i]-'0');
  if(f) ret *= -1;
  return ret;
}

int main(){
  int n;
  while(cin>>n && n){
        vector<int> v;
        string s;
        rep(i, n){
          cin>>s;
          v.pb(s=="x"?2e9:perseInt(s));
        }
        int l = -2e9, r = 2e9;
        bool ng = false;
        rep(i, n){
          if(v[i] != 2e9) {
                if(i > 0 && v[i-1] != 2e9){
                  if(i % 2 == 1 && v[i-1] >= v[i]) ng = true;
                  else if(i % 2 == 0 && v[i-1] <= v[i]) ng = true;
                }
                if(i + 1 < n && v[i+1] != 2e9){
                  if(i % 2 == 1 && v[i+1] >= v[i]) ng = true;
                  else if(i % 2 == 0 && v[i+1] <= v[i]) ng = true;
                }
          }
          else {
                if(i > 0){
                  if(v[i-1]==2e9) ng = true;
                  else {
                        if(i % 2 == 0) r = min(r, v[i-1]);
                        else l = max(l, v[i-1]);
                  }
                }
                if(i + 1 < n){
                  if(v[i+1] == 2e9) ng = true;
                  else{
                        if(i%2==0) r = min(r, v[i+1]);
                        else l= max(l, v[i+1]);
                  }
                }
          }
        }
        if(ng || (ll)r - l < 2) printf("%s\n", "none");
        else if((ll)r - l > 2) printf("%s\n", "ambiguous");
        else printf("%d\n", l + 1);
        //cout<<" "<<l<<" "<<r<<endl;
  }
}

Measured memory_bytes: 3292
#include<bits/stdc++.h>
#define $$ long long int
#define pb push_back
#define db pop_back
#define ff first
#define ss second
#define tt third
#define q2(n) (n%2)==0
#define vp vector<pair <$$,$$> >
#define vctr vector<$$>
#define in(a) scanf("%lld",&a)
#define out(a) printf("%lld ",a)
#define loop(i,m,p) for ($$ i = m; i < p; i++)
#define loopn(i,m,p) for ($$ i = p-1; i >=m; --i)

using namespace std;


int main()
{


   $$ n;
   cin>>n;
   string s,ss="";

   cin>>s;
   ss+=s[0];
   loop(i,1,n){
       $$ cn=ss.length();
      if(s[i]!=ss[cn-1]){
        ss+=s[i];
      }
   }

   cout<<ss.length()<<endl;









return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)

int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15);
    if (argc == 2 && atoi(argv[1]) == 123456789) freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);

    ll n;
    cin >> n;
    n--;

    string res;
    ll q = 1;
    while(q*26 <= n){
        q *= 26;
        n -= q;
    }
    while(q) {
        res += 'a' + n / q;
        n %= q;
        q /= 26;
    }
    cout << res << endl;

    if (argc == 2 && atoi(argv[1]) == 123456789) cout << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
    return 0;
}

Measured memory_bytes: 3648
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

#define N_MAX 1000100

struct bit{
  long long dat[N_MAX + 1];

  void init(){
    for(int i = 0; i < N_MAX; i++){
      dat[i] = 0;
    }
  }

  long long sum(int i){
    long long s = 0;
    while(i > 0){
      s += dat[i];
      i -= i & -i;
    }
    return s;
  }

  void add(int i, long long x){
    while(i <= N_MAX){
      dat[i] += x;
      i += i & -i;
    }
  }
}bit1;  

int main() {
    ll n;
    cin>>n;
    vector<ll> v;
    rep(i,0,n){
      ll a;
      cin>>a;
      v.pb(a);
    }
    sort(all(v));
    bit1.init();
    ll ans = 0;
    rep(i,0,v.sz){
      ll a = v[i];
      ans += bit1.sum(1000100)-bit1.sum(a);
      rep(j,0,i){
          bit1.add(a+v[j],1);
      }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8192
#include <algorithm>
#include <array>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>

using namespace std;

typedef long long ll;

#define MOD_NUM 1000000007

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

  ll ninePowerOfN = 1;
  for (int i = 0; i < n; i++) {
    ninePowerOfN *= 9;
    ninePowerOfN %= MOD_NUM;
  }

  ninePowerOfN *= 2;
  ninePowerOfN %= MOD_NUM;

  ll eightPowerOfN = 1;
  for (int i = 0; i < n; i++) {
    eightPowerOfN *= 8;
    eightPowerOfN %= MOD_NUM;
  }

  ninePowerOfN -= eightPowerOfN;
  if (ninePowerOfN < 0) {
    ninePowerOfN += MOD_NUM;
  }

  ll tenPowerOfN = 1;
  for (int i = 0; i < n; i++) {
    tenPowerOfN *= 10;
    tenPowerOfN %= MOD_NUM;
  }

  if (tenPowerOfN < ninePowerOfN) {
    cout << (tenPowerOfN - ninePowerOfN + MOD_NUM) << endl;
  } else {
    cout << (tenPowerOfN - ninePowerOfN) << endl;
  }

  return 0;
}


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

int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> A(N);
    double total = 0;
    rep(i, N)
    {
        int tmp;
        cin >> tmp;
        A[i] = tmp;
        total += tmp;
    }
    //    cout << total << endl;
    total = total / (4.0 * M);
    sort(A.rbegin(), A.rend());
    if (double(A[M - 1]) < total)
    {
        cout << "No" << endl;
    }
    else
    {
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(void){
    long long int n,a,b,ans;
    cin>>n>>a>>b;
    if(a>b)ans=0;
    else if(a==b)ans=1;
    else if(n==1)ans=0;
    else ans=(b*(n-1)+a)-(a*(n-1)+b)+1;
    cout<<ans<<endl;
    return 0;
}

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

int main(){
	int a,b,c,sum=0;
	cin>>a>>b>>c;
	
	sum=a+b+c;
	if(sum<22)
		cout<<"win"<<endl;
	else
		cout<<"bust"<<endl;
		
	return 0;
}

Measured memory_bytes: 256
using System;

namespace TestConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = int.Parse(Console.ReadLine());

            var h = input / 3600;
            input = input % 3600;

            var m = input / 60;
            input = input % 60;

            Console.WriteLine($"{h}:{m}:{input}");
        }
    }
}



Measured memory_bytes: 17932
def main():
    string = input().strip()
    k = int(input())
    s = set()
    for char in sorted(set(string)):
        for i in range(len(string)):
            if string[i] == char:
                s.add(string[i])
                s.add(string[i:i+1])
                s.add(string[i:i+2])
                s.add(string[i:i+3])
                s.add(string[i:i+4])
                s.add(string[i:i+5])
        if len(s) >= k:
            print(sorted(s)[k - 1])
            return


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#define errOut(s) \
  { std::cerr << __LINE__ << ":" << #s << ":" << (s) << std::endl; }

#include <bits/stdc++.h>
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Weverything"
//#include <boost/multi_array.hpp>
//#include <boost/optional.hpp>
//#include <boost/range/adaptors.hpp>
//#include <boost/range/algorithm.hpp>
//#include <boost/range/irange.hpp>
#pragma clang diagnostic pop

using namespace std;

int64_t solve(int64_t n, const std::string& s) {
  std::bitset<200000> bits;
  for (int i = 0; i < n; i++) {
    bits[i] = s[i] == 'R';
  }
  bool all = true;
  bool none = true;
  bool noneAfterAll = true;
  bool prev = false;
  for (int i = 0; i < n; i++) {
    if (bits[i]) {
      none = false;
    } else {
      all = false;
    }
    if (i > 0 && !prev && bits[i]) {
      noneAfterAll = false;
    }
    prev = bits[i];
  }
  if (all || none || noneAfterAll) {
    return 0;
  }
  int i = 0;
  int j = n - 1;
  int ret = 0;
  for (;;) {
    while (i < n && bits[i]) {
      i++;
    }
    while (j >= 0 && !bits[j]) {
      j--;
    }

    if (i >= j) {
      break;
    }

    bits[i] = true;
    bits[j] = false;

    ret++;
  }

  return ret;
}

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  int64_t n;
  std::cin >> n;
  std::string s;
  std::cin >> s;
  std::cout << solve(n, s) << std::endl;
  return 0;
}


Measured memory_bytes: 3768
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(vec) (vec).begin(), (vec).end()
#define SUM(...) accumulate(ALL(__VA_ARGS__),0LL)
#define DSUM(...) accumulate(ALL(__VA_ARGS__),0.0)
using namespace std;
using ll = long long;
using P = pair<int, int>;

// 便利関数
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

// 出力
void print() { std::cout << '\n'; }
template <class T>void print(const T &x) {std::cout << x <<'\n';}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}

const int INF = 2002002002;

void solve(std::string S){
    REP(i, S.size())
        printf("%c", 'x');
    cout << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
//#include <iomanip>
#include <stdlib.h>
#include <cctype>

using namespace std;

#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define ssort(z) sort(z.begin(),z.end())
#define rsort(z) sort(z.rbegin(),z.rend())
#define eerase(z) z.erase(unique(z.begin(),z.end()),z.end())
#define ccnt(z,w) count(z.begin(),z.end(),w)


void printVec(std::vector<int> & vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec2(std::vector<Int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a / gcd(a, b) *b;
	//a*bは64bit integer overflow
}

bool comp(const string a, const string b) {
	return a.length() < b.length();
}

bool integer(double num) {
	return floor(num) == num;
}

string gen(int num) {
	string str = "";
	for (int i = 0; i < num; i++) str += ".";
	return str;
}
Int fact(int num) {
	if (num == 0) return 1;
	else return num * fact(num - 1);
}



int main() {
	//int a, b, c,d; cin >> a>>b>>c>>d ;
	//string s,t; cin >> s;
	Int a; cin >> a;
	string o; cin >> o;
	Int b; cin >> b;
	if (o == "+")cout << a + b;
	else cout << a - b;

	cout << endl;
	return 0;
}


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

int main(){
    string s;cin>>s;
    ll zero=0;ll one=0;


    rep(i,s.size()){
        if(s[i]=='0')zero++;
        else{one++;}
    }

    cout<<2*min(zero,one)<<endl;
}

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

long long N;


bool isInt(double num) {
	long long numLong = (long long)num;

	if(numLong >= 1 && numLong - 0.0001 < num && numLong + 0.0001 > num) {
		return true;
	}
	numLong++;
	if(numLong >= 1 && numLong - 0.0001 < num && numLong + 0.0001 > num) {
		return true;
	}
	return false;

}

long long solve(long long num) {
	long long ans = 0;
	for(long long x = 1; x * x <= num; x++) {
		for(long long y = 1; x * x  + y * y + x * y <= num; y++) {
			long long b = x + y;
			long long c = x * x + y * y + x * y - num;
			
			for(long long z = 1; x*x + y*y + z*z + x*y + y*z + z*x <= num; z++) {
				if(x*x + y*y + z*z + x*y + y*z + z*x == num) {
					ans++;
				}
			}

			
			//double z1 = (-1 * b + sqrt(b*b - 4*c))/2;
			//double z2 = (-1 * b - sqrt(b*b - 4*c))/2;

			//if(isInt(z1) || isInt(z2)) {
			//	ans++;
			//}


		}
	}
	return ans;
}

int main(){
	cin >> N;

	for(long long i = 1; i <= N; i++) {
		cout << solve(i) << endl;
	}
}

Measured memory_bytes: 3580
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

int main(){
  int N, K;
  string S;
  cin >> N >> S >> K;
  char target = S[K-1];
  for(int i=0; i<N; i++)
    if(S[i] == target)
      cout << S[i];
    else
      cout << '*';
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;

namespace Tasks
{
    public class B
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var (N, Q) = Scanner.Scan<int, int>();
            var A = Scanner.ScanEnumerable<int>().ToArray();
            var ft = new FenwickTree(N);
            for (var i = 0; i < N; i++)
            {
                ft.Add(i, A[i]);
            }

            for (var i = 0; i < Q; i++)
            {
                var (t, p, x) = Scanner.Scan<int, int, int>();
                if (t == 0) ft.Add(p, x);
                else Console.WriteLine(ft.Sum(p, x));
            }
        }

        public class FenwickTree
        {
            private readonly int _n;
            private readonly long[] _data;

            public FenwickTree(int n = 0)
            {
                _n = n;
                _data = new long[n];
            }

            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            public void Add(int p, long x)
            {
                if (p < 0 || _n <= p) throw new ArgumentException(nameof(p));
                p++;
                while (p <= _n)
                {
                    _data[p - 1] += x;
                    p += p & -p;
                }
            }

            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            public long Sum(int l, int r)
            {
                if (0 > l || l > r || r > _n) throw new ArgumentException();
                return Sum(r) - Sum(l);
            }

            private long Sum(int r)
            {
                var s = 0L;
                while (r > 0)
                {
                    s += _data[r - 1];
                    r -= r & -r;
                }

                return s;
            }
        }

        public static class Scanner
        {
            private static Queue<string> queue = new Queue<string>();
            public static T Next<T>()
            {
                if (!queue.Any()) foreach (var item in Console.ReadLine().Trim().Split(" ")) queue.Enqueue(item);
                return (T)Convert.ChangeType(queue.Dequeue(), typeof(T));
            }
            public static T Scan<T>() => Next<T>();
            public static (T1, T2) Scan<T1, T2>() => (Next<T1>(), Next<T2>());
            public static (T1, T2, T3) Scan<T1, T2, T3>() => (Next<T1>(), Next<T2>(), Next<T3>());
            public static (T1, T2, T3, T4) Scan<T1, T2, T3, T4>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>());
            public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>(), Next<T5>());
            public static IEnumerable<T> ScanEnumerable<T>() => Console.ReadLine().Trim().Split(" ").Select(x => (T)Convert.ChangeType(x, typeof(T)));
        }
    }
}


Measured memory_bytes: 86608
def calc(a, op, b):
    if op == "+":
        r = a + b
    elif op == "-":
        r = a - b
    elif op == "*":
        r = a * b
    else:
        r = a / b
    return r

while True:
    a, op , b = raw_input().split()
    if op == "?":
        break
    print(calc(int(a), op, int(b)))

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int A[101010];
int cnt[101010];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) {
		cin>>x;
		cnt[x]++;
		cnt[x+1]++;
		cnt[x+2]++;
	}
	int ma=0;
	FOR(i,101000) ma=max(ma,cnt[i]);
	cout<<ma<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 640
import itertools
from collections import defaultdict
n=int(input())
a=[0]+list(map(int,input().split()))
L=list(itertools.accumulate(a))

d=defaultdict(int)
for i in L:
  d[i]+=1
res=0
for i in d.keys():
  res+=d[i]*(d[i]-1)//2
print(res)

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

import static java.lang.Integer.parseInt;

/**
 * Palindromic Number
 */
public class Main {

	static boolean[] palindrom = new boolean[10002];

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		//1,11
		for (int i = 0; i <= 9; i++) {
			palindrom[i] = true;
			palindrom[i * 10 + i] = true;
		}

		//101,111
		for (int i = 1; i <= 9; i++) {
			int p = i * 101;
			palindrom[p] = true;
			for (int j = 0; j <= 9; j++) {
				int q = p + j * 10;
				palindrom[q] = true;
			}
		}

		//1001,1111
		for (int i = 1; i <= 9; i++) {
			int p = i * 1001;
			palindrom[p] = true;
			for (int j = 0; j <= 9; j++) {
				int q = p + j * 100 + j * 10;
				palindrom[q] = true;
			}
		}

		palindrom[10001] = true;

		int n = parseInt(br.readLine());
		int ans = 0;

		for (int i = 0; ; i++) {
			if (palindrom[n - i]) {
				ans = n - i;
				break;
			}
			if (palindrom[n + i]) {
				ans = n + i;
				break;
			}
		}

		System.out.println(ans);

	}
}

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

#define INF 1 << 29
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)

using namespace std;

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

void gen_sosuu(int sosuu[]){
  REP(i,100010){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(100000)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<=100000;j++){
      //printf("%d %d %d\n",i*j,i,j);
      sosuu[i*j] =false;
    }
  }
}

string o,e;

int main(){
  cin >> o >> e;
  REP(i,o.size()){
    cout << o[i];
    if(e[i] != '\0'){
      cout << e[i];
    }
  }
  cout << endl;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		List<Long> unko=new ArrayList<Long>();
		int unko2=sc.nextInt();
		fra(unko2,unko);
		int[] Ns=new int[32];
		int cnt=0;
		for(int i=0; i<unko.size(); i++) {
			long tmp=unko.get(i);
			if(tmp>1) {
				Ns[cnt]=(int)tmp;
				cnt++;
			}
		}
		int[] kai=new int[cnt];
		for(int i=0; i<cnt; i++) {
			kai[i]=Ns[i];
		}
		Arrays.sort(kai);
		String buri="";
		buri=buri+unko2+": ";
		for(int i=0; i<cnt-1; i++) {
			buri=buri+kai[i]+" ";
		}
		buri=buri+kai[cnt-1];
		System.out.println(buri);
	}
	public static void fra(int a,List<Integer> p) {//int型用
		for(int i=2; i*i<=a; i++) {
			if(a%i==0) {
				p.add(i);
				fra(a/i,p);
				return;
			}
		}
		p.add(a);
	}

	public static void fra(long a,List<Long> p) {//long型用
		for(long i=2; i*i<=a; i++) {
			if(a%i==0) {
				p.add(i);
				fra(a/i,p);
				return;
			}
		}
		p.add(a);
	}

}


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

#define cn count
#define pb push_back
#define in insert
#define fs first
#define sc second
#define sz size
#define len length
#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define forni(i, n) for (ll i = 1; i < (ll) (n); ++i)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using namespace std;
using ll = long long;
const ll inf = 1e9+7; 
const double PI =  3.141592653589793;

int main(){
	IO;
	ll n;
	cin>>n;
	ll d[n];
	forn(i,n){
		cin>>d[i];
	}
	sort(d,d+n);
	cout<<d[n/2]-d[n/2-1]<<"\n";
	return 0;
}

// _   .-')                .-. .-')                 .-')                                               
//( '.( OO )_              \  ( OO )               ( OO ).                                             
// ,--.   ,--.).-'),-----. ,--. ,--.  .-'),-----. (_)---\_) ,--. ,--.     .-----.  ,-.-')  .-'),-----. 
// |   `.'   |( OO'  .-.  '|  .'   / ( OO'  .-.  '/    _ |  |  | |  |    '  .--./  |  |OO)( OO'  .-.  '
// |         |/   |  | |  ||      /, /   |  | |  |\  :` `.  |  | | .-')  |  |('-.  |  |  \/   |  | |  |
// |  |'.'|  |\_) |  |\|  ||     ' _)\_) |  |\|  | '..`''.) |  |_|( OO )/_) |OO  ) |  |(_/\_) |  |\|  |
// |  |   |  |  \ |  | |  ||  .   \    \ |  | |  |.-._)   \ |  | | `-' /||  |`-'| ,|  |_.'  \ |  | |  |
// |  |   |  |   `'  '-'  '|  |\   \    `'  '-'  '\       /('  '-'(_.-'(_'  '--'\(_|  |      `'  '-'  '
// """    """     """""""" """  """"      """""""  """""""  """"""""      """"""   """         """""""


Measured memory_bytes: 4420
x,y=map(int,input().split())
g1 = {1,3,5,7,8,10,12}
g2 = {4,6,9,11}
g3 = {2}

def group(z):
  if z in g1:return 1
  elif z in g2:return 2
  else: return 3
  
if group(x)==group(y):print('Yes')
else:print('No')

Measured memory_bytes: 9092
#include <bits/stdc++.h>
using namespace std;
int main() {
	int a,b,c,ans;
	cin>>a>>b>>c;
	ans=min(b,c);
	b-=ans; c-=ans;
	ans*=2;
	if (c>0) {
		if (a>=c) ans+=c;
		else ans+=a+1;
	}
	else ans+=b;
	cout<<ans<<endl;
	return 0;
} 

Measured memory_bytes: 256
import java.io.InputStream;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		InputStream is = System.in;
		solve(is);
	}

	private static void solve(InputStream is) {
		try (Scanner cin = new Scanner(is)) {
			int a = cin.nextInt();
			int b = cin.nextInt();
			int c = cin.nextInt();
			int x = cin.nextInt();

			int ans = 0;
			int sum;

			for (int ai = 0; ai <= a; ai++) {
				for (int bi = 0; bi <= b; bi++) {
					for (int ci = 0; ci <= c; ci++) {
						sum = (500 * ai + 100 * bi + 50 * ci);
						if (sum == x) {
							ans++;
							break;
						} else if (sum > x) {
							break;
						}
					}
				}
			}
			System.out.println(ans);
		}
	}
}


Measured memory_bytes: 23252
use std::collections::HashMap;
fn main() {
    let s = read::<String>().chars().collect::<Vec<_>>();
    let mut hs = HashMap::new();
    for c in s {
        let count = hs.entry(c).or_insert(0);
        *count += 1;
    }
    yn(hs.values().all(|&v| v % 2 == 0));
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
def detectCycle(a):
    start, length = 0, 1
    p1, p2 = a[1], a[a[1]]
    while p1 != p2:
        p1, p2 = a[p1], a[a[p2]]
    
    p2 = 1
    while p1 != p2:
        p1, p2 = a[p1], a[p2]
        start += 1
    
    p2 = a[p1]
    while p1 != p2:
        p2 = a[p2]
        length += 1
    
    return start, length

n, k = (int(x) for x in input().split())
a = [-1] + [int(x) for x in input().split()]
start, length = detectCycle(a)

loc = 1
for i in range(min(start,k)):
    loc = a[loc]
k = max(k-start,0)

k %= length
for i in range(k):
    loc = a[loc]
print(loc)

Measured memory_bytes: 32328
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  string S;
  cin >> S;
  vector<int> ans(0);
  int pos = N;
  bool flag = true;
  while(pos != 0){
    if(pos - M <= 0){
      if(pos != 0){
        ans.push_back(pos);
      }
      pos = 0;
    }
    else{
      for(int i=M; i>0; i--){
        if(S.at(pos-i) == '0'){
          ans.push_back(i);
          pos -= i;
          break;
        }
        if(i == 1){
          flag = false;
          break;
        }
      }
    }
    if(!flag){
      break;
    }
  }
  if(flag){
    for(int i=ans.size()-1; i>=0; i--){
      cout << ans.at(i) << " ";
      if(i == 0){
        cout << endl;
      }
    }
  }
  else{
    cout << -1 << endl;
  }
}

Measured memory_bytes: 1144
X=int(input())

X_=int(X**0.5)+1

ans=1
for i in range(2,X+1):
    for j in range(2,X_):
        bi=i
        while True:
            if bi%j!=0:
                break
            bi//=j
            if bi==1:
                ans=i

print(ans)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;

constexpr int Mod = 998244353;
constexpr int mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;

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

/*-------------------------------------------*/

ll n, k, sum;
V<ll> a;

bool need(const int &mid) {
    bitset<5005> b(1);
    rep(i, n) if(i != mid && a[i] < k) b |= b << a[i];
    FOR(i, max(0LL, k - a[mid]), k) if(b[i]) return true;
    return false;
}

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

    cin >> n >> k;
    a.resize(n);
    rep(i, n) {
        cin >> a[i];
        sum += a[i];
    }
    sort(ALL(a));
    ll ok = -1, ng = n;
    while(ok + 1 < ng)
        (need(ng + ok >> 1) ? ng : ok) = ng + ok >> 1;
    cout << ng << endl;

    return 0;
}

Measured memory_bytes: 256
//情報オリンピック2011 予選問題5「イルミネーション」C++ver
#include<iostream>
#include<queue>
using namespace std;

//yが奇数
int dx[6] = {1, 1, 0,-1, 0, 1};
int dy[6] = {0,-1,-1, 0, 1, 1};
//ｙが偶数
int dx2[6] = {1, 0,-1,-1,-1, 0};
int dy2[6] = {0,-1,-1, 0, 1, 1};

int bfs(int, int, int **);
typedef pair<int, int> P;

int main()
{
	int **map, f1, f2, h, w;

	cin >> w >> h;
	w += 2; h += 2;

	map = new int *[h];
	for(f1 = 0; f1 < h; f1++)
		map[f1] = new int [w];

	for(f1 = 0; f1 < h; f1++){
		for(f2 = 0; f2 < w; f2++){
			if(f1 == 0 || f1 == h - 1 || f2 == 0 || f2 == w - 1)
				map[f1][f2] = 0;
			else
				cin >> map[f1][f2];
		}
	}

	cout << bfs(w, h, map) << endl;

	return 0;
}

int bfs(int w, int h, int **map)
{
	int f1, nx, ny, cnt = 0;

	queue<P> Q;
	Q.push( P(0, 0) );

	while( !Q.empty() ){
		P p = Q.front(); Q.pop();
		for(f1 = 0; f1 < 6; f1++){

			ny = (p.first % 2 != 0) ? p.first + dy[f1] : p.first + dy2[f1];
			nx = (p.first % 2 != 0) ? p.second + dx[f1] : p.second + dx2[f1];

			if(nx >= 0 && nx < w && ny >= 0 && ny < h){
				if(map[ny][nx] == 0){
					map[ny][nx] = -1;
					Q.push( P(ny, nx) );
				}
				else if(map[ny][nx] == 1)
					cnt++;
			}
		}
	}
	return cnt;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n;
    cin>>n;
    ll money=1000;
    while(1)
    {
        if(money>=n)
        {
            cout<<(money-n)<<endl;
            break;
        }
        else
        {
            money+=1000;
        }
    }
    return 0;
}


Measured memory_bytes: 3632
import java.lang.Math.*

private fun readLn() = readLine()!! // string line
private fun readStrings() = readLn().split(" ") // list of strings
private fun readLong() = readLn().toLong()
private fun readLongs() = readStrings().map { it.toLong() } // list of ints
private fun readInt() = readLn().toInt() // single int
private fun readInts() = readStrings().map { it.toInt() } // list of ints


//var n = 0
//var ar = listOf<Int>()

fun main() {
    val d = readInt()
    val C = readInts()
    var S = mutableListOf<List<Int>>()
    S.add(mutableListOf())

    for (i in 0 until d) {
        S.add(readInts())
    }

    val last = Array(26) {0}
    val chosen = mutableListOf<Int>()
    var ans = 0

    for (day in 1 until d + 1) {
        var max = Integer.MIN_VALUE
        var maxContest = -1

        for (contest in 0 until 26) {
            var cur = S[day][contest]
            val daysSince = day - last[contest]
            val cost = (C[contest] * daysSince * (daysSince + 1) / 2)
            cur += cost

            if (cur > max) {
                max = cur
                maxContest = contest
            }
//            println("cur cost max: $cur $cost $max")
        }
        last[maxContest] = day
        chosen.add(maxContest + 1)

        ans += S[day][maxContest]
        for (i in 0 until 26) {
            val daysSince = day - last[i]

//            print("$daysSince ")
            ans -= (C[i] * daysSince)
        }
//        println()
//
//        println("$max $ans")
    }

    print(chosen.joinToString("\n"))
//    println("total: $ans")
}


Measured memory_bytes: 39704
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Clue = Tuple!(long, "x", long, "y", long, "h");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

long cnt;

void main()
{
    auto x = lread();
    long th = x / 500;
    long five = (x - 500 * th) / 5;
    writeln(1000 * th + 5 * five);
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main ()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	char x;
	cin>>x;
	ll xval;
	if(x!='z')
	{
	xval=(ll)x;
	xval=xval+1;
	char ans;
	ans=(char)xval;	
	cout<<ans<<"\n";
	}
	else
	{
		cout<<" "<<"\n";
	}
	return 0;
	
}


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

int main()
{
  int a, b;
  cin >> a >> b;
  rep(i, 3)
  {
    int ans = i + 1;

    if (ans != a && ans != b)
    {
      cout << ans << endl;
      break;
    }
  }
}

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

using namespace std;

int main()
{
  string str1, str2;
  getline(cin, str1);
  
  int n = str1.size();
  
  for(int i = 0; i < n; i++)
  {
      if(isupper(str1[i]))
      {
          str2[i] = tolower(str1[i]);
      }
      else if(islower(str1[i]))
      {
          str2[i] = toupper(str1[i]);
      }
      else
      {
          str2[i] = str1[i];
      }
  }
   
    for(int i = 0; i < n; i++)
  {
        cout << str2[i];   
  }      
  
  cout << endl;
  
   return 0;
}


Measured memory_bytes: 3236
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

using namespace std;


inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}


void solve() {
    int N; cin >> N;
    vector<long long> A(N+1), B(N);
    for (int i = 0; i < N+1; i++) cin >> A[i];
    for (int i = 0; i < N; i++) cin >> B[i];

    long long ans = 0;
    long long help = 0;
    for (int i = 0; i < N; i++) {
        if (A[i] > help + B[i]) {
            ans += help + B[i];
            help = 0;
        }
        else{
            ans += A[i];
            if (A[i] <= help) help = B[i];
            else help = help + B[i] - A[i];
        }
    }
    ans += min(help, A[N]);

    cout << ans << endl;
}


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

Measured memory_bytes: 1792
K, A, B = map(int,input().split())

first_bis = min(K,A)-1
second_exchange = int((K-first_bis)/2)
final_bis = K-first_bis-second_exchange*2

if A<B-1:
    bis = 1+first_bis+second_exchange*(B-A)+final_bis
else:
    bis = K+1
    
print(bis)

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

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

        map<long long, long long> mp;
        for (long long i=0; i<n; ++i) {
                long long a;
                cin >> a;
                if (mp.find(a)!=mp.end()) {
                        mp[a]++;
                } else {
                        mp[a] = 1;
                }
        }

        long long count = 0;
        map<long long, long long>::iterator it;
        for (it=mp.begin(); it!=mp.end(); ++it) {
                if (it->second==1) continue;
                if (it->second==2) continue;
                if (it->second%2==0) {
                        count += it->second/2-1;
                        it->second = 2;
                } else {
                        count += it->second/2;
                }
        }
        long long two_count=0;
        for (it=mp.begin(); it!=mp.end(); ++it) {
                if (it->second==2) two_count++;
        }
        count += (two_count+1)/2;

        cout << n-count*2 << endl;
        return 0;
}


Measured memory_bytes: 6528
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
// #include<deque>
// #include<multiset>
// #include<bitset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

int n, k;

void solve() {
  string res;
  int ans = 0;
  for(int i = 0; i < 9; i++) {
    cout << i + 1 << endl;
    cin >> res;
    if(res == "Yes") return;
    if(res == "Near") ans ^= 1 << i; // あほくさ
  }
  cout << ans + 1 << endl;
  cin >> res;
  assert(res == "Yes");
}

int main() {
  // ios::sync_with_stdio(false), cin.tie(0);
  cin >> n >> k;

  // int cnt = 0;
  vector<pair<int, int>> v;
  for(int i = 9; i < n; i++) {
    for(int j = 0; j < 9; j++) {
      if(i & (1 << j)) {
        v.emplace_back(j, i);
      }
    }
  }

  cout << v.size() << "\n";
  for(auto p : v){
    cout << p.first + 1 << " " << p.second + 1 << "\n"; //// 
  }
  cout << flush;

  for(int i = 0; i < k; i++) {
    solve();
  }
  return 0;
}



Measured memory_bytes: 3308
#if 0

#endif

#include <bits/stdc++.h>
#define REP(i, n) for(int i=0;i<int(n);++i)
using namespace std;
template<class A>void p(A a){cout << (a) << endl;}
template<class A,class B>void p(A a,B b){cout << a << " "  ;p(b);}
template<class A,class B,class C>void p(A a,B b,C c){cout << a << " " ;p(b,c);}
template<class A,class B,class C,class D>void p(A a,B b,C c,D d){cout << a << " " ;p(b,c,d);}
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
int INF=numeric_limits<int>::max();
// for copy
// for(int i=0;i<N;++i) {

int main(void) {
  int N,M;cin>>N>>M;
  int l = 1;
  int r = 100000;
  REP(i,M) {
    int L,R;cin>>L>>R;
    if(l<L) l=L;
    if(r>R) r=R;
  }
  if(r-l+1>=0) {
    p(r-l+1);
  } else {
    p(0);
  }
  return 0;
}



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

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

    int64_t n, k;
    cin >> n >> k;
    int a[200001], x[200001];
    for(int i=1;i<=n;++i){
        cin >> a[i];
        x[i] = -1;
    }
    int pos = 1, cnt = 0;
    while(x[pos] == -1){
        x[pos] = cnt++;
        pos = a[pos];
    }
    if(k > x[pos]){
        k %= cnt - x[pos];
        while(k < x[pos]) k += cnt - x[pos];
    }
    pos = 1;
    while(k--){
        pos = a[pos];
    }
    cout << pos << endl;
    return 0;
}

Measured memory_bytes: 5220
#include <stdio.h>
int a, n;
int main()
{
    scanf("%d %d", &a, &n);
    while (a != 0 || n != 0)
    {
        if (a >= n)
        {
            printf("%d %d\n", n, a);
        }
        else if (n >= a)
        {
            printf("%d %d\n", a, n);
        }
        scanf("%d %d", &a, &n);
    }
}



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

int main(){
    
    int n,m,memo = 0,memo_c = 0;
    
    while(1){
        cin >> n >> m;
        if(n == 0 && m == 0){
            break;
        }
        else{
            memo = n+m;
            memo_c = 0;
            
            rep(i,1,5){
                cin >> n >> m;
                if(memo < n+m){
                    memo = n+m;
                    memo_c = i;
                }
            }
            
            cout << (char)(memo_c+65) << " " << memo << endl;
            
        }
    }
    return 0;
}


Measured memory_bytes: 3112
#include<iostream>
#define ll long long int
#define ld long double
#define pi acos(-1)
#define pb push_back
using namespace std;
int main()
{
    ll i,j,a,k,b,c,n,t,m,p,q,d,e,f,x,y,g,z,h;
    ld aa,bb,cc,dd,ee,ff,kk,gg;
//    vector<ll > v,s,vv;
//    vector<pair<ll,ll> > sv;
//    map<ll,ll> sa,ta,ma,pa;
//    map<pair<ll,ll>, ll> mm;
//    map<pair< deque<ll>,deque<ll> >,ll  > me;
//    priority_queue<char,vector<ll>,greater<ll> > aq,tq,pq;
//    string st,et,ft,pt,ct;
//    deque<ll> de,pe,ne;
//    ios_base::sync_with_stdio(false);
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
        cin>>a;
        c = 0;
        for(i=1;i<=a;i++){
                cin>>b;
            if(i%2==1 && b%2==1)c++;
        }
        cout<<c<<endl;
}


Measured memory_bytes: 3580
import java.util.Scanner;

public class Main {

	static int N,R;
	static int[] a;
	static int[] fact=new int[100001];
	static long mod=1000000007;
	static{
		fact[0]=fact[1]=1;
		for(int i=2;i<fact.length;i++){
			fact[i]=factMod(i,1000000007);
		}
	}
	public static void main(String[] args) {
		Scanner cin=new Scanner(System.in);

		for(;;){
			N=cin.nextInt();
			if(N==0)break;
			SegmentTree tree=new SegmentTree(N+1);
			for(int i=0;i<N;i++){
				tree.update(i, 1);
			}
			R=cin.nextInt();
			long ans=0;
			a=new int[N+1];
			for(int i=0;i<N+1;i++){
				a[i]=i-1;
			}
			for(int i=0;i<R;i++){
				int x=cin.nextInt();
				int y=cin.nextInt();
				int tmp=a[x];
				a[x]=a[y];
				a[y]=tmp;
			}
			for(int i=1;i<N+1;i++){
//				System.out.println(i+" "+a[i]+" ");
//				ans=ans+(long)a[i]*(long)(fact[N-i]-bit.sum(a[i]));
				ans+=(long)fact[N-i]*tree.query(0,a[i],0,0,tree.n);
//				System.out.println(i+" "+a[i]+" ");
//				bit.add(a[i],1);
				tree.update(a[i], 0);
				ans%=mod;
				
//				System.out.println(ans);
			}
			System.out.println(ans);
		}
	}
	static int factMod(long n,long mod){
		
		return (int)((n%mod * fact[(int)n-1]%mod)%mod);
	}
	// 0-indexed
	static class SegmentTree {
		int a[];
		int n;
		public SegmentTree(int size) {
			for(n=1;n<size;) n <<= 1;
			a = new int[2*n];
		}
		void update(int k, int v) {
			k += n - 1;
			a[k] = v;
			for(;k>0;) {
				k = (k-1)/2;
				a[k] = a[k*2+1] + a[k*2+2];  // 記憶するデータ
			}
		}
		// [x, y)の最小値 : call as (x, y, 0, 0, n);
		int query(int x, int y, int k, int l, int r) {
			if(r <= x || y <= l) return 0;
			if(x <= l && r <= y) return a[k];
			int vl = query(x, y, k*2 + 1, l, (l+r)/2);
			int vr = query(x, y, k*2 + 2, (l+r)/2, r);
			return vl+ vr;
		}
	}

}

Measured memory_bytes: 59888
from typing import List


class UnionFind:
    """Union Find (Disjoint Set): O(α(N))
    References:
        https://github.com/atcoder/ac-library/blob/master/atcoder/dsu.hpp
        https://tumoiyorozu.github.io/single-file-ac-library/document_en/dsu.html
    """

    __slots__ = ["_data_size", "_roots"]

    def __init__(self, data_size: int) -> None:
        self._data_size = data_size
        self._roots = [-1] * data_size

    def __getitem__(self, x: int) -> int:
        """Find the group (root) of vertex x in O(α(n)) amortized."""
        while self._roots[x] >= 0:
            x = self._roots[x]
        return x

    def is_connected(self, x: int, y: int) -> bool:
        """Return whether two vertices x and y are connected in O(α(n)) amortized."""
        return self[x] == self[y]

    def unite(self, x: int, y: int) -> None:
        """Unite two groups of vertices x and y in O(α(n)) amortized."""
        x, y = self[x], self[y]
        if x == y:
            return
        if self._roots[x] > self._roots[y]:
            x, y = y, x
        self._roots[x] += self._roots[y]
        self._roots[y] = x


def unionfind():
    # https://judge.yosupo.jp/problem/unionfind
    # https://atcoder.jp/contests/practice2/tasks/practice2_a
    import sys

    read = sys.stdin.buffer.read

    N, Q, *TUV = map(int, read().split())
    tree = UnionFind(N)
    res = []
    for t, u, v in zip(*[iter(TUV)] * 3):
        if t:
            res.append(int(tree.is_connected(u, v)))
        else:
            tree.unite(u, v)
    print("\n".join(map(str, res)))


if __name__ == "__main__":
    unionfind()


Measured memory_bytes: 146408
#include<bits/stdc++.h>
#define N 100100
using namespace std;
int f[N];
int in[N],out[N];
int a[N],b[N];
bool vis[N];
int c[N];
vector<int> g[N],r[N];
void DFS(int u, bool &sl, int sz[], int col){
	vis[u]=true;
	sz[col]++;
	c[u]=col;
	for(int i=0;i<g[u].size();i++){
		int v=g[u][i];
		if(!vis[v]) DFS(v,sl,sz,(col+1)%3);
		else if((col+1)%3!=c[v]) sl=true;
	}
	for(int i=0;i<r[u].size();i++){
		int v=r[u][i];
		if(!vis[v]) DFS(v,sl,sz,(col+2)%3);
		else if((col+2)%3!=c[v]) sl=true;
	}
}
int main(){
	int n,m;
	long long ans=0;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) f[i]=i;
	for(int i=0;i<m;i++){
		scanf("%d%d",&a[i],&b[i]);
		out[a[i]]++;
		in[b[i]]++;
		g[a[i]].push_back(b[i]);
		r[b[i]].push_back(a[i]);
	}
	for(int i=1;i<=n;i++){
		if(in[i]&&out[i]&&!vis[i]){
			bool sl=false;
			int sz[3]={};
			DFS(i,sl,sz,0);
			if(sl){
				int tsz=sz[0]+sz[1]+sz[2];
				ans+=1LL*tsz*tsz;
			}
			else{
				ans+=1LL*sz[0]*sz[1]+1LL*sz[1]*sz[2]+1LL*sz[2]*sz[0];
			}
		}
	}
	for(int i=0;i<m;i++){
		if(!vis[a[i]]) ans++;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 21376