akhauriyash/Code-Regression huggingface dataset:
// {{{ by shik
#include <bits/stdc++.h>
#include <unistd.h>
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x),end(x)
#define REP(i,n) for ( int i=0; i<int(n); i++ )
#define REP1(i,a,b) for ( int i=(a); i<=int(b); i++ )
#define FOR(it,c) for ( auto it=(c).begin(); it!=(c).end(); it++ )
#define MP make_pair
#define PB push_back
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
typedef vector<int> VI;

#ifdef SHIK
template<typename T>
void _dump( const char* s, T&& head ) { cerr<<s<<"="<<head<<endl; }

template<typename T, typename... Args>
void _dump( const char* s, T&& head, Args&&... tail ) {
    int c=0;
    while ( *s!=',' || c!=0 ) {
        if ( *s=='(' || *s=='[' || *s=='{' ) c++;
        if ( *s==')' || *s==']' || *s=='}' ) c--;
        cerr<<*s++;
    }
    cerr<<"="<<head<<", ";
    _dump(s+1,tail...);
}

#define dump(...) do { \
    fprintf(stderr, "%s:%d - ", __PRETTY_FUNCTION__, __LINE__); \
    _dump(#__VA_ARGS__, __VA_ARGS__); \
} while (0)

template<typename Iter>
ostream& _out( ostream &s, Iter b, Iter e ) {
    s<<"[";
    for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
    s<<"]";
    return s;
}

template<typename A, typename B>
ostream& operator <<( ostream &s, const pair<A,B> &p ) { return s<<"("<<p.first<<","<<p.second<<")"; }
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) { return _out(s,ALL(c)); }
template<typename T, size_t N>
ostream& operator <<( ostream &s, const array<T,N> &c ) { return _out(s,ALL(c)); }
template<typename T>
ostream& operator <<( ostream &s, const set<T> &c ) { return _out(s,ALL(c)); }
template<typename A, typename B>
ostream& operator <<( ostream &s, const map<A,B> &c ) { return _out(s,ALL(c)); }
#else
#define dump(...)
#endif

template<typename T>
void _R( T &x ) { cin>>x; }
void _R( int &x ) { scanf("%d",&x); }
void _R( long long &x ) { scanf("%" PRId64,&x); }
void _R( double &x ) { scanf("%lf",&x); }
void _R( char &x ) { scanf(" %c",&x); }
void _R( char *x ) { scanf("%s",x); }

void R() {}
template<typename T, typename... U>
void R( T& head, U&... tail ) {
    _R(head);
    R(tail...);
}

template<typename T>
void _W( const T &x ) { cout<<x; }
void _W( const int &x ) { printf("%d",x); }
template<typename T>
void _W( const vector<T> &x ) {
    for ( auto i=x.cbegin(); i!=x.cend(); i++ ) {
        if ( i!=x.cbegin() ) putchar(' ');
        _W(*i);
    }
}

void W() {}
template<typename T, typename... U>
void W( const T& head, const U&... tail ) {
    _W(head);
    putchar(sizeof...(tail)?' ':'\n');
    W(tail...);
}

#ifdef SHIK
#define FILEIO(...)
#else
#define FILEIO(name) do {\
    freopen(name ".in","r",stdin); \
    freopen(name ".out","w",stdout); \
} while (0)
#endif

// }}}

int main() {
    int a,b;
    R(a,b);
    if ( a<=0 && b>=0 ) W("Zero");
    else if ( a>0 ) W("Positive");
    else W((b-a+1)%2==0 ? "Positive" : "Negative");
    return 0;
}


Measured memory_bytes: 764
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		int array[] = null;
		int count = 0;

		Scanner scanner = new Scanner(System.in);

		//入力値を扱いやすいように配列化
		for(int i = 0; scanner.hasNext(); i++) {
			if(i == 0) array = new int[Integer.parseInt(scanner.next())];

			array[i] = Integer.parseInt(scanner.next());
		}

		for(int i = 0; i < (array.length -2); i++) {
			int temp[] = new int[] {array[i], array[i+1], array[i+2]};
			Arrays.sort(temp);
			if(array[i+1] == temp[1]) count++;
		}

		System.out.print(count);

		scanner.close();
	}
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
string zfill(int a){
  int k = 6;int b = a;
  while(a){
    k--;a /= 10;
  }
  string c = string(k,'0');
  c += to_string(b);
  return c;
}
int main(){
  int n,m,i,j,p,y;ios::sync_with_stdio(false);cin >> n >> m;
  vector<vector<pair<int,int>>> k(n+1);vector<string> ans(m);
  for(i=0;i<m;i++){
    cin >> p >> y;k[p].push_back(make_pair(y,i));
  }
  for(i=1;i<=n;i++) sort(k[i].begin(),k[i].end());
  for(i=1;i<=n;i++){
    for(j=0;j<k[i].size();j++){
      ans[k[i][j].second] += zfill(i);ans[k[i][j].second] += zfill(j+1);
    }
  }
  for(i=0;i<m;i++) cout << ans[i] << "\n";
}

Measured memory_bytes: 13440
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int main()
{
  ll N;
  scanf("%lld",&N);
  ll K;
  scanf("%lld",&K);
  vector<ll> A(N-1-0+1);
  for(int i=0; i<N-1-0+1; i++){
    scanf("%lld",&A[i]);
  }

  vector<ll> d(N, 0);
  vector<ll> e(N, 0);
  for (int i=0; i<N; i++) {
    for (int j=0; j<N; j++) {
      if (A[i]>A[j]) {
        d[i]++;
        if (i<j) {
          e[i]++;
        }
      }
    }
  }
  ll ans = 0;
  ll mul = K*(K-1)/2%mod;
  for (int i=0; i<N; i++) {
    ans = (ans + d[i]*mul) % mod;
    ans = (ans + e[i]*K) % mod;
  }
  cout << ans << endl;

  return 0;
}


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

using namespace std;

int main(){
int i, N, M;
int a[110];
cin >> N >> M;
  
for(i=0; i<N; i++){
cin >> a[i];
}

sort(a, a + N, greater<int>());

double sum = 0;
for(i=0; i<N; i++){
sum += a[i];
}
  
double dt = sum / (M*4);
if(a[M-1] >= dt)cout << "Yes";
else cout << "No";
return 0;  

}


Measured memory_bytes: 256
// g++ -std=gnu++1y -O2 main.cpp

#include <cassert>
#include <cstdio>
#include <vector>
#include <set>

#include <map>
#include <unordered_map>
#include <string>
#include <utility>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <climits>

using namespace std;

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

long long factorial(long long n)
{
	assert(n >= 0);

	if (n == 0)
		return 1;

	long long f = 1;
	while (n != 0) {
		f *= n;
		n--;
	}
	return f;
}

long long choose2(long long n)
{
	if (n <= 0)
		return 0;

	return (n * (n - 1)) / 2;
}

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

	vector<long long> A(N);
	unordered_map<long long, long long> table;
	for (long long i = 0; i < N; i++)
	{
		long long Ai;
		cin >> Ai;

		A[i] = Ai;

		if (!table[Ai]) {
			table[Ai] = 0;
		}
		table[Ai]++;
	}

	long long sum = 0;
	for (unordered_map<long long, long long>::iterator itr = table.begin(); itr != table.end(); ++itr)
	{
		long long Ai = itr->first;
		long long cnt = itr->second;

		sum += choose2(cnt);
	}


	for (long long i = 0; i < N; i++) {
		long long ans = sum;
		ans -= choose2(table[A[i]]);
		ans += choose2(table[A[i]] - 1);
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 9160
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
 
int main(){
  
  int lenS,lenT;
  char S[1001],T[1001];
  int i,j,k;
  int min,number=0;
  
  scanf("%s",S);
  scanf("%s",T);
  
  lenS = strlen(S);
  lenT = strlen(T);
  min = lenT;
  
  for(i=0;i<(lenS-lenT+1);i++){
   
      number = 0;
    for(j=0,k=i;j<lenT;j++,k++){
      if(S[k] != T[j]) number++;
    }
    if(min>number) min = number;
   
  }
  
  printf("%d\n",min);
  
  return 0;
}

Measured memory_bytes: 1736
import std.stdio; // ??\????????????????????????
import std.string; // chomp????????????????????????(?????????????????????)
import std.conv; // to????????????????????????
import std.array; // split?????????????????????
import std.algorithm; // map?????????????????????

void main() {
    auto input = readln.split.map!(to!int);
    auto a = input[0];
    auto b = input[1];

    if (a > b) {
        writeln("a > b");
    } else if (a < b){
        writeln("a < b");
    } else {
        writeln("a == b");
    }
}

Measured memory_bytes: 2396
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

const ll INF = 1e16;

int main()
{
	ll n, x; cin >> n >> x;
	vi a(n); cin >> a;
	ll ans = INF;
	vi tmp = a;
	REP(i, n)
	{
		ll sum = 0;
		REP(j, n) sum += tmp[j];
		chmin(ans, sum + i * x);
		REP(j, n)
		{
			chmin(tmp[j], a[(j + n - i - 1) % n]);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
a,b,c,d = map(int,input().split())
def gcd(x, y):
	while y:
		x, y = y, x % y
	return x

def lcm(x, y):
  return x * y // gcd (x, y)  

def cal(n):
  if a%n ==0 and b%n ==0:
    return b//n - a//n + 1
  else:
    return b//n - a//n
    
cd = lcm(c, d)
ans = (b-a+1) - (b//c - (a-1)//c) - (b//d - (a-1)//d) + (b//cd - (a-1)//cd)
print(ans)
    

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
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; }



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

    for(int b = 1; b <= n; b++) {
        int x = n / b;
        int y = n % b;
        ans += x * max(b-k, 0);
        ans += max(y-k+1, 0);
    }
    if(k == 0) ans -= n;
    
    cout << ans << endl;
}

Measured memory_bytes: 3572
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
const int Mod=1000000007;
int n,m;
#define Maxn 100010
#define V 4000010
int f[Maxn];
int x[Maxn],y[Maxn];
struct P{
	int x,y;
	bool operator <(const P &z)const{return x!=z.x?x<z.x:y>z.y;;}
	bool operator ==(const P &z)const{return x==z.x&&y==z.y;}
}p[Maxn];int len=0;
struct Node{
	int sumv;
	int ls,rs;
}tree[V];
int root,cnt=0;
void insert(int &k,int l,int r,int pos,int x){
	if(!k)k=++cnt;
	tree[k].sumv+=x;
	if(tree[k].sumv>=Mod)tree[k].sumv-=Mod;
	if(l==r)return;
	int mid=(l+r)>>1;
	if(pos<=mid)insert(tree[k].ls,l,mid,pos,x);
	else insert(tree[k].rs,mid+1,r,pos,x);
}
int Query(int k,int l,int r,int L,int R){
	if(l==L&&r==R)return tree[k].sumv;
	int mid=(l+r)>>1;
	if(R<=mid)return Query(tree[k].ls,l,mid,L,R);
	else if(mid<L)return Query(tree[k].rs,mid+1,r,L,R);
	else{
		int ans=Query(tree[k].ls,l,mid,L,mid)+Query(tree[k].rs,mid+1,r,mid+1,R);
		if(ans>=Mod)ans-=Mod;
		return ans;
	}
}

int main(){
	scanf("%d%d",&n,&m);
	for(register int i=1;i<=n;++i)scanf("%d",&x[i]);
	for(register int i=1;i<=m;++i)scanf("%d",&y[i]);
	for(register int i=1;i<=n;++i)
	if(x[i]>y[1]&&x[i]<y[m]){
		int at=lower_bound(y+1,y+m+1,x[i])-y;
		if(y[at]==x[i])continue;
		len++;
		p[len]=(P){x[i]-y[at-1],y[at]-x[i]};
	}
	sort(p+1,p+len+1);
	len=unique(p+1,p+len+1)-p-1;
	int Ans=0;
	for(int i=1,nex;i<=len;i=nex+1){
		nex=i;
		while(nex<len&&p[nex+1].x==p[i].x)nex++;
		for(int j=i;j<=nex;++j){
			f[j]=Query(root,0,1e9,0,p[j].y-1)+1;
			if(f[j]>=Mod)f[j]-=Mod;
			Ans=Ans+f[j];
			if(Ans>=Mod)Ans-=Mod;
			insert(root,0,1e9,p[j].y,f[j]);
		}
	}
    printf("%d\n",(Ans+1)%Mod);
    return 0;
}

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

bool is_square(int n)
{
    for (int i = 0; i <= n; i++)
    {
        if (i * i == n)
        {
            return true;
        }
    }
    return false;
}

int main()
{
    string s;
    cin >> s;
    int ans = 0;
    string a = "";
    string b = "";
    for (size_t i = 0; i < s.length(); i++)
    {
        b += s.substr(i, 1);
        if (a != b)
        {
            ans++;
            a = b;
            b = "";
        }
        else
        {
        }
        /* code */
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 10000
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    vector<bool>Isprime(MAX+1,true);
    vector<int>Prime(MAX+1,0); //Primearray
    int Primecounter =0;                  //Primearray counter;
    for(int i = 2; i<MAX+1;i++){
        if(Isprime[i]){
            for(int j = 2;i*j<MAX;j++)
                Isprime[i*j] = false;//テァツエツ?ヲツ閉ーテ」ツ?ェテ」ツつ臼rimearrayテ」ツ?ォテヲツ?シテァツエツ催」ツ?療」ツ?ヲテ」ツ?敕」ツ?ョテ・ツ?催ヲツ閉ーテ」ツつ津・ツ?ィテ」ツ?ヲfalseテ」ツ?ォ
            Prime[Primecounter] = i;
            Primecounter++;
        }
    }
    int m,a,b;
    while (cin>>m>>a>>b){
        if(!(m+a+b))break;
        double dif=(double)a/(double)b;
        pii ans; int maxi=-INF;
        rep(i,Prime.size()){
            if(Prime[i]*Prime[i]>m)break;
            for(int j=i;j<Prime.size();j++){
                int big=(Prime[j]);
                int mini=Prime[i];
                if(b*mini-big*a<0)continue;
                if(big*mini>m)continue;
                if(maxi<big*mini){
                    maxi=big*mini;
                    ans=pii(mini,big);
                }
            }
        }
        cout<<ans.first<<" "<<ans.second<<endl;
    }
}

Measured memory_bytes: 3052
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long int ll;
typedef unsigned long long int ull;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a,b,c;
  string s,t;
  cin >>a>>s;
  if(a<3200)s="red";
  cout <<s;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  int h,w;
  cin >> h >> w;
  vector<string> a;
  rep(i,h){
    string s;
    cin >> s;
    bool x = true;
    rep(j,w){
      if(s.at(j)=='#')x=false;
    }
    if(!x){
      a.push_back(s);
    }
  }
  for(int j=w-1; j>=0; j--){
    bool x = true;
    rep(i,a.size()){
      if(a.at(i).at(j)=='#')x=false;
    }
    if(x){
      rep(i,a.size()){
        a.at(i).erase(a.at(i).begin()+j);
      }
    }
  }

  rep(i,a.size()){
    cout << a.at(i) << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define Rep(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) Rep(i,0,n)
#define stop char nyaa;cin>>nyaa;
using ll = long long;
const int inf = 1e9 + 7;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;

using P = pair<int, int>;

int h, w;
int a[80][80], b[80][80];
bool used[80][80][13001];

void dfs(int x, int y, int t) {
	if (used[x][y][t])return;
	used[x][y][t] = true;
	if (x + 1 < h) {
		int dif = abs(a[x + 1][y] - b[x + 1][y]);
		dfs(x + 1, y, abs(t - dif));
		dfs(x + 1, y, t + dif);
	}
	if (y + 1 < w) {
		int dif = abs(a[x][y + 1] - b[x][y + 1]);
		dfs(x, y + 1, abs(t - dif));
		dfs(x, y + 1, t + dif);
	}
}
void solve() {
	cin >> h >> w;
	rep(i, h)rep(j, w) {
		cin >> a[i][j];
	}
	rep(i, h)rep(j, w) {
		cin >> b[i][j];
	}
	dfs(0, 0, abs(a[0][0] - b[0][0]));
	rep(i, 13001) {
		if (used[h - 1][w - 1][i]) {
			cout << i << endl; return;
		}
	}
}


signed main() {
	solve();
	stop
	return 0;
}


Measured memory_bytes: 80640
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int g=0;
  string s;
  cin>>s;
  for(int i=0;i<s.length();i++)
  {
    if(i&1){
      if(s[i]=='L'||s[i]=='U'||s[i]=='D')
        g++;
      else
        break;}
    if(i%2==0){
      if(s[i]=='R'||s[i]=='U'||s[i]=='D')
        g++;
    else
      break;}
  }
  if(g==s.length())
    cout<<"Yes";
  else
    cout<<"No";
  return 0;
}


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

using namespace std;

typedef pair<int,string> P;

// family tree
struct Node{
  vector<Node*> child;
  Node* parent;
  string name;
  Node():name(""){}
  Node(vector<Node*> c, Node* p, string s):child(c),parent(p),name(s){}

  void init(){
    for(int i = 0; i < (int)child.size(); i++)
      child[i]->init();
    child.clear();
  }

  bool isSibling(const string& A, const string& B){
    return find(A)->parent==find(B)->parent;
  }

  bool isChild(const string& A){
    for(int i = 0; i < (int)child.size(); i++)
      if(child[i]->name == A) return true;
    return false;
  }

  bool isDecendant(const string& A){
    for(int i = 0; i < (int)child.size(); i++)
      if(child[i]->name == A) return true;
    
    bool res = false;
    for(int i = 0; i < (int)child.size(); i++)
      res = res||child[i]->isDecendant(A);
    return res;
  }

  Node* find(const string& name){
    for(int i = 0; i < (int)child.size(); i++)
      if(child[i]->name == name) return child[i];

    for(int i = 0; i < (int)child.size(); i++){
      Node* tmp = child[i]->find(name);
      if(tmp != NULL) return tmp;
    }
    return NULL;
  }
};

int N,M;
Node* top = new Node(vector<Node*>(), top, "");

P devide(const string& s){
  int blank = 0;
  for(int i = 0; i < (int)s.length(); i++) if(s[i] == ' ') blank++;
  return P(blank,s.substr(blank));
}

void input(){
  cin.ignore();
  
  Node* now = top;
  int depth = -1;

  for(int i = 0; i < N; i++){
    string s;
    getline(cin,s);
    P p = devide(s);
    
    if(p.first == depth){
      Node* nex = new Node(vector<Node*>(), now->parent, p.second);
      ((now->parent)->child).push_back(nex);
      now = nex;
    }

    if(p.first < depth){
      // go up
      int diff = depth-p.first+1;
      for(int i = 0; i < diff; i++) now = now->parent;
      Node* nex = new Node(vector<Node*>(), now, p.second);
      now->child.push_back(nex);
      now = nex;
      depth = p.first;
    }
    
    if(p.first > depth){
      // go down
      Node* nex = new Node(vector<Node*>(), now, p.second);
      now->child.push_back(nex);
      now = nex;
      depth = p.first;
    }
  }
}

void solve(){

  for(int i = 0; i < M; i++){
    string X,Y,Q,trash;
    cin >> X >> trash >> trash >> Q >> trash >> Y;
    bool ans = false;
    Y = Y.substr(0,Y.length()-1);

    if(Q[0]=='c') ans = (top->find(Y))->isChild(X);
    if(Q[0]=='p') ans = (top->find(X))->isChild(Y);
    if(Q[0]=='s') ans = top->isSibling(X,Y);
    if(Q[0]=='d') ans = (top->find(Y))->isDecendant(X);
    if(Q[0]=='a') ans = (top->find(X))->isDecendant(Y);
    
    cout << (ans?"True":"False") << endl;
  }
  cout << endl;
}

int main(){
  
  while(cin >> N >> M && N+M){
    top->init();
    input();
    solve();
  }
  return 0;
}

Measured memory_bytes: 1360
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

#define num sizeof(a)/sizeof(int)

long long ncr(long long,long long);//combi

int main(){
    long long i,j,k,n,instead,sum=0;scanf("%lld",&n);
    long long a[n+1],b[n+1];
    for(i=1;i<=n;i++){scanf("%lld",&a[i]);}
    for(i=0;i<=n;i++){b[i]=0;}

    for(i=1;i<=n;i++){
        b[a[i]]++;
    }
    
    for(j=1;j<=n;j++){
            if(b[j]>=2){
                sum+=ncr(b[j],2);
        }
    }//除かない場合の同数の組み合わせの数


    for(i=1;i<=n;i++){//除く
        if(b[a[i]]>=2){
            sum-=(b[a[i]]-1);
        }
        printf("%lld\n",sum);
        if(b[a[i]]>=2){
            sum+=(b[a[i]]-1);
        }
    }
    return 0;
}
long long ncr(long long a,long long b){
    long long i,ans=1;
    for(i=1;i<=b;i++){
        ans=ans*(a-i+1)/i;
    }
    return ans;
}

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

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

using namespace std;
using ll = long long;
int mod = 1000000007;

int main(void){
    int N;
    ll A, B, C, D;
    cin >> N >> A >> B >> C >> D;
    if(A > B) swap(A, B);
    for(int K = 0; K <= N-1; K++){
        ll ulim = D*K - C*((N-1) - K);
        ll dlim = C*K - D*((N-1) - K);
        if(dlim <= B-A && B-A <= ulim){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}

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

//#define DEBUG

using namespace std;

template <class T>
void print_vect(std::vector<T> v){
    for(int i = 0 ; i < v .size(); i++) cout << v[i] << " ";
    cout << endl;
}


void solve(){
    int ans;
    for(int i = 0 ; i < 5 ; i++){
        int x;
        cin >> x;
        if( x == 0){
            ans = i + 1;
        }
    }
    cout << ans << endl;
}

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/

    #ifdef DEBUG
    int TEST_CASES = 2;
    while(TEST_CASES--){
    #endif // DEBBUG

    solve();

    #ifdef DEBUG
    }
    #endif // DEBUG
    
    return 0;
}


Measured memory_bytes: 3592
import sys
def input():
    return sys.stdin.readline()[:-1]
a,b=map(int,input().split())
s=""
t=""
if a<b:
    for i in range(b):
        t+=str(a)
    print(t)
else:
    for i in range(a):
        s+=str(b)
    print(s)

Measured memory_bytes: 38384
import scala.io.StdIn.readInt

object Main extends App {
  var n = 0
  while( {n=readInt;n} != 0 ) {
    val a = new Array[Int](7)
    for(i<-0 until n) {
      val m = readInt
      if(m<10) a(0) += 1
      else if(m>=10 && m<20) a(1) += 1
      else if(m>=20 && m<30) a(2) += 1
      else if(m>=30 && m<40) a(3) += 1
      else if(m>=40 && m<50) a(4) += 1
      else if(m>=50 && m<60) a(5) += 1
      else if(m>=60) a(6) += 1
    }
    a.foreach(println)
  }
}

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

int main(){
    int n;
    cin>>n;
    int arr[n][3];
    int x=n;
    while(x--)
        cin>>arr[n-x-1][0]>>arr[n-x-1][1]>>arr[n-x-1][2];
    int dp[n][3];
    dp[0][0]= arr[0][0];
    dp[0][1]= arr[0][1];
    dp[0][2]= arr[0][2];
    for(int i=1; i<n; i++){
        int a, b, c;
        a= arr[i][0]+ max(dp[i-1][1], dp[i-1][2]);
        b= arr[i][1]+ max(dp[i-1][0], dp[i-1][2]);
        c= arr[i][2]+ max(dp[i-1][0], dp[i-1][1]);
        dp[i][0]= a;
        dp[i][1]= b;
        dp[i][2]= c;
    }
    cout<<max(dp[n-1][2], max(dp[n-1][0], dp[n-1][1]));
}

Measured memory_bytes: 5904
// V solo
#include <bits/stdc++.h>

#define forn(i, a, b) for (int i = a; i <= b; ++i)
#define forr(i, a, b) for (int i = a; i >= b; --i)

using namespace std;

const int N = (int)1e5 + 1;
const long long INF = 1e13 + 7;

typedef long long ll;
typedef long double ld;

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

int a, b, c, x, y;
int main (){
  scanf ("%d %d %d %d %d", &a, &b, &c, &x, &y);
  ll mn = INF;
  forn (i, 0, max(2 * x, 2 * y) + 1){
    ll cur = i * c + max(ll(2 * x - i + 1) / 2 * a, (ll)0) + max(ll(y * 2 - i + 1) / 2 * b, (ll)0);
    mn = min(mn, cur);
  }
  printf ("%lld\n", mn);
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char** argv){
  
  int a, b, c, num, mod;
  scanf("%d %d %d", &a, &b, &c);
  num = 100 * a + 10 * b + c;
  mod = num % 4;
  if(mod) printf("NO");
  else printf("YES");
  return 0;
}  

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
//#define TEST
class P
{
    static void Main()
    {
        long l = long.Parse(Console.ReadLine());
        List<long> ls = new List<long>();
        while (l > 0)
        {
            ls.Add(M(l));
            l -= (long)Math.Pow(2, M(l));
        }
#if TEST
        foreach (var i in ls)
            Console.WriteLine(i);
#endif
        int n = (int)ls[0] + 1;
        List<string> answer = new List<string>();
        long m = 0;
        for (int i = 1; i < n; i++)
        {
            answer.Add(String.Format("{0} {1} {2}", i, i + 1, 0));
            answer.Add(String.Format("{0} {1} {2}", i, i + 1, (long)Math.Pow(2, i - 1)));
            m += 2;
        }
        for (int i = 1; ; i++)
        {
            try
            {
                long d = 0;
                for (int k = 0; k < i; k++)
                    d += (long)Math.Pow(2, ls[k]);
                string ans = String.Format("{0} {1} {2}", ls[i] + 1, n, d);
                answer.Add(ans);
                m++;
            }
            catch
            {
                break;
            }
        }
        Console.WriteLine("{0} {1}", n, m);
        foreach (var s in answer)
            Console.WriteLine(s);
        return;
    }
    static long M(long l)
    {
        long c = 0;
        while ((long)Math.Pow(2, c) <= l)
        {
            c++;
        }
        return c - 1;
    }
}

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

struct UnionFind {
  vector<int> p;

  UnionFind(int N) : p(N) {
    for(int i=0; i<N; i++)
      p[i] = i;
  }

  int root(int x) {
    if (p[x] == x)
      return x;
    return p[x] = root(p[x]);
  }

  void unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if (rx == ry)
      return;
    p[rx] = ry;
  }
};

int main() {
  int N,M,i,x,y,c=0;
  cin >> N >> M;
  vector<int> p(N);
  UnionFind uf(N+1);

  for(i=0; i<N; i++)
    cin >> p.at(i);
  for(i=0; i<M; i++) {
    cin >> x >> y;
    uf.unite(x,y);
  }

  for(i=0; i<N; i++)
    if(uf.root(i+1) == uf.root(p.at(i)))
      c++;
  cout << c << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
int main(void){
  int n,h,w,a,b,ans=0,i;
  scanf("%d%d%d",&n,&h,&w);
  for (i=0;i<n;i++){
    scanf("%d%d",&a,&b);
    if (h<=a&&w<=b) ans++;
  }
printf("%d",ans);

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000

int main(){
	
	int H,W;
	cin>>H>>W;
	
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			string s;
			cin>>s;
			
			if(s=="snuke"){
				cout<<(char)('A'+j)<<i+1<<endl;
				return 0;
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

ll fact(int n) {
  ll res = 1;
  FOR(i, 1, n + 1) res = (res * i) % mod;
  return res;
}

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

  if (abs(n - m) > 1) cout << 0 << endl;
  else if (n == m) cout << 2 * fact(n) * fact(m) % mod << endl;
  else cout << fact(n) * fact(m) % mod << endl;



  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, k;
    cin >> n >> k;
    long long a[n];
    for (int i = 0; i < n; i++)
        cin >> a[i];
    sort(a, a + n);
    long long ans = 1ll << 60;
    for (int i = 0; i < n - k + 1; i++)
    {
        //cout << a[i + k - 1] << "," << a[i] << endl;
        ans = min(ans, a[i + k - 1] - a[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
// "include" {{{
#include <deque>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
// }}}
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;

int gcd(int a,int b){return b ? gcd(b,a%b) : a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}

vector<int> h(100050);
signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	int maxv = -100;
	rep(i,n){
		cin >> h[i];
	}
	int cnt = 0;
	for(int i = 1;i<n;++i){
		if(h[i-1] >= h[i]) ++cnt;
		else{
			if(maxv < cnt){
				maxv = cnt;
			}
			cnt = 0;
		}
	}
	cout << max(maxv,cnt) << '\n';
	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

#define MAX 10000
#define NIL -1

struct Node {int p, l, r;};
struct Node T[MAX];
int n;

/* 先行順巡回 */
void preParse(int u) {
  if(u == NIL) return;
  printf(" %d",u);
  preParse(T[u].l);
  preParse(T[u].r);
}

/* 中間順巡回 */
void inParse(int u) {
  if(u == NIL) return;
  inParse(T[u].l);
  printf(" %d",u);
  inParse(T[u].r);
}

/* 後方順巡回 */
void postParse(int u) {
  if(u == NIL) return;
  postParse(T[u].l);
  postParse(T[u].r);
  printf(" %d",u);
}

int main(void) {
  int i, v, l, r, root;
  scanf("%d",&n);
  for(i=0; i<n; i++) {
    T[i].p = NIL;
  }
  
  for(i=0; i<n; i++) {
    scanf("%d %d %d",&v,&l,&r);
    T[v].l = l;
    T[v].r = r;
    if(l != NIL) T[l].p = v;
    if(r != NIL) T[r].p = v;
  }
  
  for(i=0;i<n;i++) if(T[i].p == NIL) root = i;
  
  printf("Preorder\n");
  preParse(root);
  printf("\n");

  printf("Inorder\n");
  inParse(root);
  printf("\n");

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

  return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()
#define let auto const

template<typename F>
static inline constexpr decltype(auto) fix(F&& f) noexcept {
  return [f = std::forward<F>(f)](auto&&... args) {
    return f(f, std::forward<decltype(args)>(args)...);
  };
}
template<typename T>
static inline T fin() { T t; cin >> t; return std::move(t); }

int main() {
  i64 n;
  cin >> n;
  i64 a = 0;
  for(int i = 1;i <= n;i++) {
    a += !!(to_string(i).size() % 2);
  }
  cout << a << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:https://atcoder.jp/contests/abc156/tasks/abc156_f>
 問題文============================================================
 F - Modularness
 =================================================================
 解説=============================================================
 
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    int k,q; cin >> k >> q;
    vector<int> d(k); for(auto& in:d) cin >> in;
    
    for(int unchi = 0; unchi < q; unchi++){
        int n,x,m; cin >> n >> x >> m;
        
        vector<int> dm(k);
        for(int i = 0; i < k; i++) dm[i] = d[i]%m;

        ll zero = 0;
        
        for(int i = 0; i < min(k,n-1);i++){
            if(dm[i] == 0){
                zero += ((n-1)-(i+1))/k + 1;
            }
        }
        
        ll a0_div_m = x/m;
        ll an_1 = x;
        for(int i = 0; i < min(k,n-1);i++){
            ll cnt = ((n-1)-(i+1))/k+1;
            an_1 += dm[i]*cnt;
        }
        ll an_1_div_m = an_1/m;
        
        ll X = zero + (an_1_div_m - a0_div_m);
        
        cout << (n-1) - X << endl;
    }

    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    solve(0);
    // cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 384
import java.util.*;
public class Main {
    public static void main(String [] args){
        Scanner sc = new Scanner(System.in);
        int N  =sc.nextInt();
        int num = N/2;
        float opt;
        if(N%2==0) opt = (float)num/N;
        else opt = (float)(num+1)/N;
        System.out.println(opt);
    }
}

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

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(ll i = (ll)(a); i < (ll)(b); i++)
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; }
const ll INF = 1LL << 60;

int divceil(int a, int b){
    return (a+b-1) / b;
}
int main(){
    int k,q; cin >> k >> q;
    vector<int> d(k);
    rep(i,k) cin >> d[i];
    rep(qi,q){
        int n,x,m;
        cin >> n >> x >> m;
        ll last = x;
        ll eq=0;
        rep(i,k){
            ll num = divceil(n-1-i,k);
            last += (d[i]%m)*num;
            if(d[i]%m==0)eq+=num;
        }
        ll ans = n-1 - (last/m - x/m) - eq;
        cout << ans << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
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; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e18;

class UnionFind {
public:
	vector <lint> par; // 各元の親を表す配列
	vector <lint> siz; // 素集合のサイズを表す配列(1 で初期化)

	// Constructor
	UnionFind(lint sz_) : par(sz_), siz(sz_, 1ll) {
		for (lint i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}
	void init(lint sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1ll);  // resize だとなぜか初期化されなかった
		for (lint i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}

	// Member Function
	// Find
	lint root(lint x) { // 根の検索
		while (par[x] != x) {
			x = par[x] = par[par[x]]; // x の親の親を x の親とする
		}
		return x;
	}

	// Union(Unite, Merge)
	bool merge(lint x, lint y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;
		// merge technique（データ構造をマージするテク．小を大にくっつける）
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}

	bool issame(lint x, lint y) { // 連結判定
		return root(x) == root(y);
	}

	lint size(lint x) { // 素集合のサイズ
		return siz[root(x)];
	}
};

lint N, M, K, L;
vector<lint> to[100000];
int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);	
	cin >> N >> M;
	UnionFind tree(N);
	REP(i, N) {
		cin >> K;
		REP(j, K) {
			cin >> L; L--;
			to[L].push_back(i);
		}
	}
	REP(i, M) {
		REP(j, SZ(to[i]) - 1) {
			if (!tree.issame(to[i][j], to[i][j + 1])) {
				tree.merge(to[i][j], to[i][j + 1]);
			}
		}
	}
	REP(i, N - 1) {
		if (!tree.issame(i, i + 1)) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
}


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

int main() {
  int A, B;
  cin >> A >> B;
  int n = 0;
  
 
  
  for ( int X = A; X < B + 1; X++ ) {
    int first, second, fourth, fifth;
    int x = X;
    
    first = x % 10;
    x = x / 10;
    second = x % 10;
    x = x / 100;
    fourth = x % 10;
    x = x / 10;
    fifth = x % 10;
    
    if ( first == fifth && second == fourth ) {
      n++;
    }
  }
  cout << n << endl;
}

Measured memory_bytes: 3568
import copy
import math
import time
import statistics
import math
import itertools
import bisect
import sys
from decimal import *
from collections import deque


def get_int():
    return int(input())

def get_string():
    return input()

def get_int_list():
    return [int(x) for x in input().split()]

def get_string_list():
    return input().split()

def get_int_multi():
    return map(int, input().split())

def get_string_char_list():
    return list(str(input()))

# print("{} {}".format(a, b))
# a_list = [0] * a
sys.setrecursionlimit(10 ** 6)

def main():
    start = time.time()

    n = get_int()
    a = get_int_list()

    ans = 0
    wk = 0
    for i in range(n):
        wk = max(wk, a[i])
        if a[i] < wk:
            ans += wk - a[i]






    print(ans)

    #print(time.time() - start)


if __name__ == '__main__':
    main()

Measured memory_bytes: 35508
#include <bits/stdc++.h>
//登録しよう！→ https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define gre greater //sortを降順にする
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示

void solve(long long N, long long K){
  if(K == 1)cout << 0 << endl;
  else cout << N-K << 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(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    solve(N, K);
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
ll f[1<<6][355],ans;
int n,C,L[15];
int main(){
	cin>>n>>C;
	for(int i=0;i<n;++i)cin>>L[i];
	sort(L,L+n);
	int tot=0,t=(1<<n-1)-1;
//	do{
//        ans+=f[(1<<n-1)-1][n*C];
//    }while(next_permutation(L,L+n-1));
	do{
		++tot;memset(f,0,sizeof(f));
		f[0][n*L[n-1]]=1;
		for(int i=1;i<=n*C;++i){
			if(i%n){
				int id=i%n-1,t=min(i+L[id]*n,n*C);
            for(int s=0;s<1<<n-1;++s)
//				for(int s=0;s<=t;++s){
            if(!(s>>id&1))
            for(int k=i;k<=n*C;++k)
            f[s|1<<id][max(k,t)]+=f[s][k];
//					if(!(s>>id&1)){
//						for(int k=i;k<=n*C;++k){
//							f[s|(1<<id)][max(t,k)]+=f[s][k];
//						}
//					}
				}
			}
//		}
//        ++tot;
//        memset(f,0,sizeof f);
//        f[0][n*L[n-1]]=1; 
//        for(int i=1;i<=n*C;++i)if(i%n){
//            const int id=i%n-1,t=min(i+L[id]*n,n*C);
//        }
		ans+=f[t][n*C];
	}while(next_permutation(L,L+n-1));
	printf("%.16lf\n",1.0*ans/tot/pow(C,n-1));
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> vec = {};
  int a;
  cin >> a;
  vec.push_back(a);
  for (int i = 1; i < N; i++) {
    cin >> a;
    if (a != vec.at(vec.size()-1))
    vec.push_back(a);
  }
  long long P = 1000;
  long long S = 0;
  int V = vec.size();
  for (int i = 0; i < V; i++) {
    if (vec.size() == 1)
      break;
    if (i == 0 && vec.at(0) < vec.at(1)) {
      S = P/vec.at(0);
      P -= S * vec.at(0);
      continue;
    }
    if (i > 0 && i < V-1 
        && vec.at(i-1) < vec.at(i) && vec.at(i) > vec.at(i+1)) {
      P += S * vec.at(i);
      S = 0;
      continue;
    }
    if (i > 0 && i < V-1 
        && vec.at(i-1) > vec.at(i) && vec.at(i) < vec.at(i+1)) {
      S = P/vec.at(i);
      P -= S * vec.at(i);
      continue;
    }
    if (i == V-1 && vec.at(i-1) < vec.at(i)) {
      P += S * vec.at(i);
    }
  }
  cout << P << endl;
}


Measured memory_bytes: 3636
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N = int(input())
        S = input().rstrip()

        dp = [[0 for i in range(N + 1)] for j in range(N + 1)]
        ans = 0
        for i in range(N)[::-1]:
            for j in range(N)[::-1]:
                if S[i] == S[j]:
                    dp[i][j] = min(dp[i + 1][j + 1] + 1, abs(i - j))
                    ans = max(ans, dp[i][j])
        print(ans)


# Run main
if __name__ == '__main__':
    AtCoder().main()


Measured memory_bytes: 247560
#include<stdio.h>

int main(void){
	int i,j,k;
	
	int bingo[3][3];
	for(i=0;i<3;i++){
		for(j=0;j<3;j++){
			scanf("%d",&bingo[i][j]);
		}
	}
	
	int n;
	scanf("%d",&n);
	
	int m;
	for(k=0;k<n;k++){
		scanf("%d",&m);
		for(i=0;i<3;i++){
			for(j=0;j<3;j++){
				if(bingo[i][j]==m){
					bingo[i][j]=0;
				}
			}
		}
	}
	int count;
	
	for(i=0;i<3;i++){
		count=0;
		for(j=0;j<3;j++){
			if(bingo[i][j]==0){
				count++;
			}
		}
		if(count==3){
			printf("Yes");
			return 0;
		}
	}
	
	for(i=0;i<3;i++){
		count=0;
		for(j=0;j<3;j++){
			if(bingo[j][i]==0){
				count++;
			}
		}
		if(count==3){
			printf("Yes");
			return 0;
		}
	}
	
	count=0;
	for(i=0;i<3;i++){
		if(bingo[i][i]==0){
			count++;
		}
	}
	if(count==3){
			printf("Yes");
			return 0;
	}
	
	count=0;
	for(i=0;i<3;i++){
		if(bingo[i][2-i]==0){
			count++;
		}
	}
	if(count==3){
			printf("Yes");
			return 0;
	}
	
	printf("No");
	return 0;
}

Measured memory_bytes: 128
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>
using namespace std;
using ll = long long;
constexpr ll INF = 1010000000000000017LL;
constexpr ll mod = 1000000007;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
    string s,t;cin>>s>>t;

    int ans=t.size();

    rep(start, s.size()-t.size()+1){
        int diff=0;
        rep(i,t.size()){
            if(t[i]!=s[start+i]) ++diff;

        }
        ans=min(ans,diff);
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int a[200];
int main(){
	int n;scanf("%d",&n);
	double sum=0;
	rep(i,n){
		scanf("%d",&a[i]);
		sum+=a[i];
	}
	sum/=n;
	double Min=INT_MAX;
	int id=-1;
	rep(i,n){
		if(abs(sum-a[i])<Min){
			Min=abs(sum-a[i]);
			id=i;
		}
	}
	cout<<id<<endl;
}

Measured memory_bytes: 764
#include <iostream>
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head



const int N = 1e6+10;
int n, T, tot;
ll L, ans;
struct {int ch[2];} tr[N<<2];
char s[N];

void add(int &o, char *s) {
	if (!o) o = ++tot;
	if (*s) add(tr[o].ch[*s=='1'],s+1);
}
void dfs(int o, ll d) {
	if (!o) ans ^= d&-d;
	else dfs(tr[o].ch[0],d-1),dfs(tr[o].ch[1],d-1);
}

int main() {
	scanf("%d%lld", &n, &L);
	REP(i,1,n) scanf("%s", s),add(T,s);
	dfs(T,L+1);
	puts(ans?"Alice":"Bob");
}









Measured memory_bytes: 2688
import sys
def input():
    return sys.stdin.readline()[:-1]

n = int(input())
a_li = list(map(int, input().split()))
if 0 in a_li:
    print(0)
else:
    res = a_li[0]
    for x in a_li[1:]:
        res *= x
        if res > 10**18:
            print(-1)
            break
    else:
        print(res)




Measured memory_bytes: 84524
import heapq

def binary_search(data, value):
    left = 0            # 探索する範囲の左端を設定
    right = len(data) - 1            # 探索する範囲の右端を設定
    while left <= right:
        mid = (left + right) // 2            # 探索する範囲の中央を計算
        if data[mid] == value:
            # 中央の値と一致した場合は位置を返す
            return mid
        elif data[mid] < value:
            # 中央の値より大きい場合は探索範囲の左を変える
            left = mid + 1
        else:
            # 中央の値より小さい場合は探索範囲の右を変える
            right = mid - 1
    return -1            # 見つからなかった場合

n, k = map(int, input().split())
a = list(map(lambda x: int(x) - 1, input().split()))
way = [0]
hq = [0]
heapq.heapify(hq)
posi = 0
cycle = 0
while True:
    if binary_search(hq, a[posi]) != -1:
        rest = way.index(a[posi])
        cycle -= (rest - 1)
        break
    way.append(a[posi])
    heapq.heappush(hq, a[posi])
    posi = a[posi]
    cycle += 1
# print(way)
# print(cycle)
if k < len(way):
    print(way[k] + 1)
else:
    print(way[(k-rest) % cycle + rest] + 1)

Measured memory_bytes: 110688