akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
string s[810];
int n;
int dx[]={1,0,-1},dy[]={1,1,1};
int ful(int y,int x){
    int sum=0;
    while(1){
        x++;
        if(s[y].size()<=x){
            x--;
            break;
        }
        if(s[y][x]==' '){
            x--;
             break;
        }
    }
    s[y][x]='#';sum++;
        if(y+1<n){
          if(x+1<s[y+1].size()&&x-1>=0){
           if(s[y+1][x+1]=='*'&&s[y+1][x-1]=='*'){
              sum+=ful(y+1,x+1);
            }
            else goto L;
         }
          else{L:;int ppp=0;
          r(i,3){
          int yy=y+dy[i];
          int xx=x+dx[i];
           if(yy>=0&&yy<n&&xx>=0)
             if(xx<s[yy].size())
                 if(s[yy][xx]=='*')
                    if(!ppp)
                     sum+=ful(yy,xx),ppp++;}}
           }

    //cout<<y<<x<<endl;r(k,n)cout<<s[k]<<endl;
    return sum;
}
int con(int y,int x){
    int sum=0,p=x,pp=x;
    for(;x<s[y].size();){
        if(s[y][x]=='#'){
            break;
        }
        if(p==pp)s[y][x]='#';
        if(x-1>=0)if(s[y][x-1]=='#'&&s[y][x]=='*')s[y][x]='#';
        sum++;
        x++;p++;
    }
    r(i,3){
        int yy=y+dy[i];
        int xx=pp+dx[i];
        if(yy>=0&&yy<n&&xx>=0)
            if(xx<s[yy].size())
                if(s[yy][xx]=='*')
                    sum+=con(yy,xx);
    }
    return sum;
}
void del(){
    r(i,n)r(j,s[i].size())
      if(s[i][j]=='#')s[i][j]=' ';
}
int main(){

    int ppp=0;

    while(cin>>n,n){

        if(ppp)cout<<"----------"<<endl;

        ppp++;

        string t;

        getline(cin,t);

        r(i,n){

            getline(cin,t);

            s[i]=t;

            //cout<<t<<endl;
        }

        map<int,int>m;

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

            for(int j=0;j<s[i].size();j++){

                int sum=0;

                if(s[i][j]=='*'){

                    sum+=ful(i,j);//r(k,n)cout<<s[k]<<endl;

                    sum+=con(i,j);

                    del();

                    m[sum]++;//cout<<sum<<endl;
                }
                
            }

        }

        for(map<int,int>::iterator it=m.begin();it!=m.end();it++)
            cout<<(*it).first<<' '<<(*it).second<<endl;
        
    }
}

Measured memory_bytes: 3116
import java.util.Scanner;
    public class Main {
    	public static void main(String[] args) {
    		Scanner sc=new Scanner(System.in);
    		int w=0,h=0,ww=sc.nextInt(),hh=sc.nextInt(),n=sc.nextInt();
    		for(int i=0;i<n;i++) {
    			int x=sc.nextInt(),y=sc.nextInt(),a=sc.nextInt();
    			if(a==1&&w<x)w=x;
    			if(a==2&&x<ww)ww=x;
    			if(a==3&&h<y)h=y;
    			if(a==4&&y<hh)hh=y;
    		}
    		System.out.println(w<ww&&h<hh?(ww-w)*(hh-h):0);
    		sc.close();
    	}
    }

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

int main()
{
    int n, y = 0;
    cin >> n;
    char s[n];
    for (int i = 0; i < n; i++)
    {
        cin >> s[i];
        if (s[i] == 'Y')
        {
            y++;
        }
    }
    if (y == 0)
    {
        cout << "Three" << endl;
    }
    else
    {
        cout << "Four" << endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if(a < b && b < c) {
        	System.out.println("Yes");
        }
        else {
        	System.out.println("No");
        }
    }
}


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

int main(){
  ll x,y;
  cin>>x>>y;
  bool ok = true;
  ll sum = 1;
  while(ok){
    if (x*2 <= y){
      sum++;
      x *= 2;
    }
    else {
      ok = false;
    }
  }
  cout << sum << endl;
}

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

typedef long long ll;
const int MOD = 1000000007;

int main() {
  ll N,ans=1;
  string S;
  cin>>N>>S;
  
  for(char c='a';c<='z';c++){
    int n=1;
    for(int i=0;i<N;i++){
      if(c==S[i]) n++;
    }
    ans*=n;
    ans%=MOD;
  }
 
  cout<<ans-1<<endl;
  
  return 0;
  
}


Measured memory_bytes: 512
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   String s1 = sc.next();
   String s3 = sc.next();
   
   if(s1.equals(s3))System.out.println("H");
   else System.out.println("D");
 }
}

Measured memory_bytes: 21844
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	static final PrintStream out = System.out;
	static final Scanner sc = new Scanner(System.in);
	static final long Mod = 1000_000_007L;

	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		System.exit(0);
	}

	void solve() {
		int N = nextInt();

		String res = ":(";
		for(int i=1;i<=N;i++) {
			int t = (int) (i * 1.08);
			if(t == N)res = String.valueOf(i);
		}

		out.println(res);

	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)a[i] = nextInt();
		return a;
	}
	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)a[i] = nextLong();
		return a;
	}
	public int nextInt() {
		return Integer.parseInt(next());
	}
	public long nextLong() {
		return Long.parseLong(next());
	}
	public String next() {
		return sc.next();
	}

	long gcd(long m,long n) {
		if (m<n) return gcd(n,m);
		if (n==0)return m;
		return gcd(n,m%n);
	}
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb(x) push_back(x)
#define vi vector<int>
#define vs vector<string>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pcc pair<char, char>
#define pdd pair<double, double>
#define mll map<long long, long long>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define flsh fflush(stdout)
#define gcd __gcd
#define clr(x) memset(x, 0, sizeof(x))
#define mod 1000000007LL
#define INF 1000000000007
 

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;


// void solve()
// {
//     ll r;
//     cin>>r;
//     // cout<<r<<"\n";
//     ld ans=2.0*3.14159*r;
//     cout<<ans<<"\n"; 
// }

// void solve()
// {
//     ll n,m;
//     cin>>m>>n;
//     ll i;
//     ll a[n];
//     ll sum=0;
//     for(i=0;i<n;i++)
//     {
//         cin>>a[i];
//         sum+=a[i];
//     }
//     if(sum>m)
//     {
//         cout<<"-1\n";
//     }
//     else{
//         cout<<m-sum<<"\n";
//     }
// }


void solve()
{
   ll n;
   cin>>n;
   vll v[n];
   ll i;
   ll x,y;
   for(i=0;i<n-1;i++)
   {
       cin>>x;
       x--;
       v[x].pb(i);
   }

   for(auto it:v)
   {
       cout<<sz(it)<<"\n";
   }
}


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


if (fopen("input.txt","r" ))
  {
     freopen("input.txt", "r", stdin);
     freopen("output.txt", "w", stdout);
  }
cout<<setprecision(20);


ll t=1;


// cin>>t;


while(t--)
{
solve();
} 


return 0;
}

Measured memory_bytes: 14596
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long int lli;

int main(){
	int n;
	cin >> n;
	vector<lli> a(n+1, 0);
	map<lli, lli> b;
	b[0] = 1;
	for(int i=1; i<=n; i++){
		cin >> a[i];
		a[i] += a[i-1];
		b[a[i]]++;
	}
	
	lli ans = 0;
	for(auto it : b){
		lli t = it.second;
		ans += t*(t-1)/2;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 14336
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdint>
#include <vector>

int main() {
  std::int_fast32_t n, l;
  std::cin >> n >> l;

  std::vector<std::string> s(n);
  for (std::int_fast32_t i = 0; i < n; ++i) {
    std::cin >> s[i];
  }

  std::sort(s.begin(), s.end());

  for (const std::string& s_i : s) {
    std::cout << s_i;
  }
  std::cout << std::endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>
#include <iomanip>
#include <tuple>

using namespace std;
const long long mod=1e9+7;
const long long INF=1LL<<60;

int main(){
    vector<int> a(3);
    cin>>a[0]>>a[1]>>a[2];
    sort(a.begin(),a.end());
    cout<<a[2]*10+a[1]+a[0]<<endl;

}
 
   

Measured memory_bytes: 384
n = int(input())
a = list(map(int, input().split())) + [0]
a.sort(reverse=True)
for i in range(n):
    if a[i + 1] <= i + 1:
        y = a[i + 1:].count(i + 1)
        x = i - a[i] - 1
        if x % 2 == 0 and y % 2 == 0:
            print('Second')
        else:
            print('First')
        break


Measured memory_bytes: 14212
while(True):
  n = input()
  if(n == 0):
    break
  a = 0
  b = 0
  for i in range(n):
    (l, r) = map(int, raw_input().split())
    if(l > r):
      a += l + r
    elif(l < r):
      b += l + r
    else:
      a += l
      b += r
  print "%d %d" % (a, b)
  

Measured memory_bytes: 4508
n = int(input())
a = list(map(int,input().split()))
a = sorted(a)
if a[0] == 0:
  print(0)
  exit()

ans = 1
for i in range(n):
  tmp = a[i]
  if a[i] == 0:
    print(0)
    exit()
  if ans > 10**18:
    print(-1)
    exit()
  ans*=tmp
  
if ans > 10**18: 
  print(-1)
else:
  print(ans)


Measured memory_bytes: 21780
// I am Varun Das from Jadavpur University
#include <bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define mod 1000000007
#define ll long long
#define dbg(x) cerr << #x << " = " << x << endl
#define INF LLONG_MAX
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a,b) for(int i=a;i>=b;i--)
#define nax 503405
using namespace std;

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//cout<<fixed<<setprecision(12);
double n;
cin>>n;
cout<<pow(n,3);

	return 0;
}

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

typedef long long LL;

const int N=18;
const LL INF=(1LL<<60)-1;

int n;
LL a[N+9];

void into(){
  scanf("%d",&n);
  for (int i=1;i<=n;++i)
	scanf("%lld",&a[i]);
}

map<int,map<int,LL> >dp[N+9][N+9];

LL Dfs_dp(int l,int r,int x,int y){
  if (dp[l][r][x].find(y)!=dp[l][r][x].end()) return dp[l][r][x][y];
  if (l+1==r) return 0;
  LL res=INF;
  for (int i=l+1;i<r;++i) res=min(res,Dfs_dp(l,i,x,x+y)+Dfs_dp(i,r,x+y,y)+a[i]*(x+y));
  return dp[l][r][x][y]=res;
}

void outo(){
  printf("%lld\n",Dfs_dp(1,n,1,1)+a[1]+a[n]);
}

int main(){
  into();
  outo();
  return 0;
}

Measured memory_bytes: 22944
a, b = gets.split.map(&:to_i)
 
#f(0,a)を求める
def f(a)
  sum = 0
  i = 0
  #各桁の1の数を数える
  while (i < (10**12).bit_length) do
    cnt = 0
    #周期2**(i+1)→一応ビット演算しとく
    cycle = 1 << (i+1)
    #周期内の1の数を数える
    cnt += (a+1)/cycle * cycle/2
    #はみ出た分を足す
    rest = (a+1)%cycle - cycle/2
    cnt += rest if rest > 0
    #1の数が奇数ならその桁にビットを立てる
    if (cnt%2 == 1) then
      sum += 1 << i
    end
    i += 1
  end
  return sum
end
#f(a,b) = f(0,a-1)^f(0,b)
puts f(a-1)^f(b)

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


int main() {
    string S, T;
    cin >> S >>T;
    
    vector<int> start(26, -1);
    vector<int> goal(26, -1);
    
    for (int i = 0; i < S.size(); i++) {
        int a = S[i] - 'a';
        int b = T[i] - 'a';
        
        if (start[a] != -1 || goal[b] != -1) {
            if (start[a] != b || goal[b] != a) {
                cout << "No" << endl;
                return 0;
            }
        }
        else {
            start[a] = b;
            goal[b] = a;
        }
    }
    cout <<"Yes"<< endl;
    
}




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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
 
#define nl '\n'
 
#define y1 aza_ibagaliev
 
#define f first
#define s second
	
#define ed end()
#define bg begin()
#define rbg rbegin()
 
#define rv reverse
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define ppf pop_front
 
#define sz size()
#define all(x) x.bg, x.ed
 
#define pll pair < ll, ll >
#define pii pair < int, int >
 
#define sqr(x) ((x) * 1ll * (x))
#define sqrd(x) ((x) * 1.0 * (x))
 
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
 
#define rnl cout << "----------------------------------------" << nl
 
#define bit __builtin_popcount
 
inline ll bip(ll x, ll n, ll mod){ll res=1;while(n){if(n & 1){res=(res*x)%mod;}x=(x*x)%mod;n>>=1;}return res;}
        	
const int ppr = 257;
const ll INF = 2e18;
const int inf = 2e9;
const int mod = 1e9 + 7;
const int N = 1e5 + 123;
const ld pi = 3.1741592653589793238462643;
 
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

ll a, b, c;

main() {             	
//  freopen(".in", "r", stdin);
//  freopen(".out", "w", stdout);

//	srand(time(NULL));

	cin >> a >> b >> c;
	
	cout << (a + b + c >= 22 ? "bust" : "win");
                            
    return 0;                                        
}

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

#define ff first
#define ss second
#define pb push_back
#define ll long long
#define mod 1000000007
#define ull unsigned long long
#define mst(ss,b) memset(ss,b,sizeof(ss));
#define pl(x) cout << #x << "= " << x << endl;
const int inf=0x3f3f3f3f;
const int N=1e5+10;

int a[N];

int  main(){
    int n;
    scanf("%d", &n);
    for(int i=1; i<=n; i++){
        int x; scanf("%d", &x);
        a[x]=1;
    }
    int ans=0;
    for(int i=1; i<N; i++){
        if(a[i])ans++;
    }
    if(ans%2==0)ans--;
    printf("%d", ans);
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <climits>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define srep(i, begin, end) for (__typeof(end) i = begin; i != end; i++)
#define si(x) int x = scanInt();
#define sll(x) LL x = scanLong();
#define sci(x) int x; scanf("%d", &x);
#define scll(x) LL x; scanf("%lld", &x);
#define pi(x) printf("%d ", x)
#define pll(x) printf("%lld ", x)
#define nl printf("\n")
#define clr(a) memset(a, 0, sizeof(a))
#define PB push_back
#define MP make_pair
using namespace std;
typedef unsigned int UI; // 32 bit integer
typedef long int LI; // 32 bit integer
typedef unsigned long int ULI; // 32 bit unsigned integer
typedef long long int LL; // 64 bit integer
typedef unsigned long long int ULL; // 64 bit unsigned integer
typedef long double LD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef deque<int> DI;
typedef deque<LL> DLL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
const LL MOD = 1e9+7;

/* Fast I/O */
inline int scanInt() {
	int n = 0;
	char ch = getchar();
	int sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(int)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

inline LL scanLong() {
	LL n = 0;
	char ch = getchar();
	LL sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(LL)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

const LD PI = 3.14159265358979323846;

int main() {
	sll(a); sll(b); sll(h); sll(m);
	LD ha = (2 * PI * (h * 60 + m)) / (12 * 60); // angle of hour hand
	LD ma = 2 * PI * m / 60;

	LD hx = a * cos(ha), hy = a * sin(ha);
	LD mx = b * cos(ma), my = b * sin(ma);

	LD ds = sqrt((hx-mx) * (hx-mx) + (hy-my) * (hy-my));
	cout << fixed << setprecision(12) << ds << endl;
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t,n,a,b;
    t = 1;
    while(t--) {
     cin >> n >> a >> b;
     cout << min(a * n, b) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){

	int i, j, k, n, x, way, sum;

	while(1){

		way = 0;
		
		scanf("%d %d", &n, &x);

		if((n == 0) && (x == 0)){
			break;
		}

		for(i = 1; i <= n; i++ ){
			for(j = 1; j <= n; j++){
				for(k = 1; k <= n; k++){
					sum = i + j + k;
					if((sum == x) && (i < j) && (j < k)){
						way++;
					}
				}
			}
		}

		printf("%d\n", way);

	}

		

	return 0;
}

Measured memory_bytes: 600
#include <stdio.h>
#include <math.h>

int sisya(double x);

int main(void)
{
    int a,b,i;
    int sum;
    double ave;

    sum = 0;
    ave = 0.0;
    i = 0;
    while (scanf("%d,%d", &a, &b) != EOF)
    {
        sum += a * b;
        ave += b;
        i++;
    }
    printf("%d\n", sum);
    printf("%d\n", sisya(ave / i));

    return(0);
}
int sisya(double x)
{
    //printf("<%lf>", x);
    double y;
    y = x - floor(x);
    if (y >= 0.5){
        return (floor(x) + 1);
    }else{
        return (floor(x));
    }

}


Measured memory_bytes: 2028
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    string a[n], b[m];
    rep(i, n) cin >> a[i];
    rep(i, m) cin >> b[i];
    
    for (int i = 0; i + m - 1< n; ++i) {
        for (int j = 0; j + m - 1 < n; ++j) {
            bool ok = true;
            rep(k, m) {
                rep(l, m) {
                    if (a[i+k][j+l] != b[k][l]) ok = false;
                }
            }
            if (ok) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void) {
	int a, b; cin >> a >> b;
	int port = 1, res = 0;

	while (port < b) {
		
		if (res == 0) {
			port += a - 1;
		}
		else {
			port += a;
		}
		res++;
		if (port >= b) break;
		port--;
	}

	cout << res << endl;

	return 0;
}

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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x,ll y,ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}
void ans(bool x,string y,string z){if(x)cout<<y<<endl;else cout<<z<<endl;}   
ll gcd(ll x,ll y){ll r;while((r=x%y)!=0){x=y;y=r;}return y;}

int main(){
  ll i,j,o;
  ll res=0,res1=INF,res2=-INF,buf=0,buf1=0,buf2=0,buf3=0,buf4=0,sum=0;
  ll l=0,r=0;
  bool judge = true;
  ll n;cin>>n;
  vector<ll>a(n);
  vector<pair<ll,ll>>b;
  for(i=0;i<n;i++){
    cin>>a[i];
  }
  sort(ALLR(a));
  vector<ll>c,d,e;
  for(i=0;i<n;i++){
    if(a[i]>0){c.push_back(a[i]);l++;}
    else if(a[i]<0){d.push_back(a[i]);r++;}
    else{buf3++;c.push_back(0);l++;};
  }
  sort(ALLR(c));
  sort(ALL(d));
  //cout<<l spa r<<endl;
  if(r==0){
    if(l!=2){
    b.push_back({c.back(),c[c.size()-2]});
    buf=c.back()-c[c.size()-2];
    c.pop_back();
    c.pop_back();
    }
    else{
      b.push_back({c[c.size()-2],c.back()});
      buf=c[c.size()-2]-c.back();
      c.pop_back();
      c.pop_back();
    }
  }
  else if(l>=2){
    b.push_back({d.back(),c.back()});
    buf=d.back()-c.back();
    c.pop_back();
    d.pop_back();
  }
  else if(l!=0){
    b.push_back({c.back(),d.back()});
    buf=c.back()-d.back();
    c.pop_back();
    d.pop_back();
  }
  else if(l==0){
    b.push_back({d.back(),d[d.size()-2]});
    buf=d.back()-d[d.size()-2];
    d.pop_back();
    d.pop_back();
  }
  sort(ALL(c));
  sort(ALLR(d));
  //cout<<c.size()<<endl;
  if(!c.empty()){
    for(i=0;i<c.size()-1;i++){
      res+=c[i];
      b.push_back({buf,c[i]});
      buf=buf-c[i];
      //cout<<buf<<endl;
    }
    b.push_back({c.back(),buf});
    buf=c.back()-buf;
    //cout<<"tsts"<<endl;
  }
  for(i=0;i<d.size();i++){
    res-=d[i];
    b.push_back({buf,d[i]});
    buf-=d[i];
  }
  cout<<buf<<endl;
  for(i=0;i<n-1;i++){
    cout<<b[i].first spa b[i].second<<endl;
  }

  
  return 0;
}

Measured memory_bytes: 5872
#include <stdio.h>
#include <string.h>
#define T_MAX 1000001
#define P_MAX 10001
   
int main(){
  char T[T_MAX];
  char P[P_MAX];
  int i, S1, S2;
       
  scanf("%s",T);
  scanf("%s",P);
     
  S1=strlen(T);
  S2=strlen(P);
       
  for(i=0;i<S1;i++){
    if(strncmp(&T[i],P,S2)==0)printf("%d\n",i);
  }
           
  return 0;
       
}

Measured memory_bytes: 1548
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define bs binary_search
#define vl vector<ll>
#define pll pair<ll,ll>
#define vpl vector<pair<ll,ll> >
#define mll map<ll,ll>
#define mcl map<char,ll>
#define pqll priority_queue<ll>
#define mpl map<pair<ll,ll>,ll >
#define msl map<string,ll>
#define mset(a,k) memset(a,k,sizeof(a));
#define len length()
#define fr(a,b,c) for(ll a=b;a<c;a++)
void in(ll *a,ll n){fr(i,1,n+1){cin>>a[i];}}
void out(ll *a,ll n){fr(i,1,n+1){cout<<a[i]<<" ";}}
void out(vl v){fr(i,0,(ll)v.size())cout<<v[i]<<" ";}
void out(ll a){cout<<a;}
void out(string s){cout<<s;}
void fast(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}


int main(){
	fast();
	ll n,k;
	cin>>n>>k;
	if((n*500)>=k){
		cout<<"Yes\n";
	}
	else{
		cout<<"No\n";
	}
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
static int const N = 100;
int main() {
	int M[N][N];
	int n, u, k, v;

	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) M[i][j] = 0;
	}
	for (int i = 0; i < n; i++) {
		cin >> u >> k;
		u--;
		for (int j = 0; j < k; j++) {
			cin >> v;
			v--;
			M[u][v] = 1;
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (j) cout << " ";
			cout << M[i][j];
		}
		cout << endl;
	}
}




Measured memory_bytes: 3116
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int INT_INF = 2147483647;
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 int MOD = 1000000007;

map< int, int > prime_factor(ll n) {
  map< int, int > ret;
  for(int i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

int main(){
  int n;
  cin >> n;
  map<int,int> ans;
  for(int i = 0;i<n;i++){
    map<int,int> t;
    t = prime_factor(i+1);
    for(auto p:t){
      ans[p.first]+=p.second;
    }
  }
  ll res = 1;
  for(auto p:ans){
    res *= p.second+1;
    res %= MOD;
  }
  cout << res << endl;
  return 0;
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
  
  ll n;
  cin >> n;
  vector<ll> x(n);
  vector<ll> sorted(n);
  rep(i, 0, n) {
    cin >> x[i];
    sorted[i] = x[i];
  }
  sort(sorted.begin(), sorted.end());
  
  ll median = n/2 -1;
  rep(i, 0, n) {
    ll ans;
    if(x[i] <= sorted[median]) ans = sorted[median+1];
    else ans = sorted[median];
    cout << ans << "\n";
  }
}

Measured memory_bytes: 5376
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int n,A,B;
string s;
int main(void){
  cin >> n >> A >> B;
  cin >> s;
  int a,b;
  a = b = 0;
  for(int i = 0; i < n; i++){
    if(s[i] == 'a' && a+b < A+B){
      a++;
      cout << "Yes" << endl;
    }else if(s[i] == 'b' && a+b < A+B && b < B){
      b++;
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }
}


Measured memory_bytes: 896
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <map>
#include <utility>
#include <list>
#include <climits>
#include <bitset>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define ll long long int

int main(){
    int h, w, a, b;
    cin >> h >> w >> a >> b;
    cout << h * w - b * h - w * a + a * b << endl;
    return 0;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tommy6073
 */

#include <iostream>
#include <string>
#include <deque>

using namespace std;

class DBrickBreak {
public:
    void solve(std::istream& in, std::ostream& out) {
        long long N;
        in >> N;
        long long a[N];
        for (int i = 0; i < N; ++i) {
            in >> a[i];
        }

        long long i = 1;
        bool satisfied = false;
        for (long long j = 0; j < N; ++j) {
            if (a[j] == i) {
                satisfied = true;
                ++i;
                continue;
            }
        }

        if (satisfied) {
            out << N - i + 1;
        } else {
            out << -1;
        }
    }
};


int main() {
	DBrickBreak solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int N;

namespace MF
{
#define MAXN 100000
#define MAXM 100000
#define wint i64
const wint wEPS = 0;
const wint wINF = 1LL << 60LL;
int n, m, ptr[MAXN], next[MAXM], zu[MAXM];
wint capa[MAXM], tof;
int lev[MAXN], see[MAXN], que[MAXN], *qb, *qe;
void init(int _n) {
	n = _n; m = 0; memset(ptr, ~0, n * 4);
}
void ae(int u, int v, wint w0, wint w1 = 0) {
	next[m] = ptr[u]; ptr[u] = m; zu[m] = v; capa[m] = w0; ++m;
	next[m] = ptr[v]; ptr[v] = m; zu[m] = u; capa[m] = w1; ++m;
}
wint augment(int src, int ink, wint flo) {
	if (src == ink) return flo;
	wint f;
	for (int &i = see[src]; ~i; i = next[i]) if (capa[i] > wEPS && lev[src] < lev[zu[i]]) {
		if ((f = augment(zu[i], ink, min(flo, capa[i]))) > wEPS) {
			capa[i] -= f; capa[i ^ 1] += f; return f;
		}
	}
	return 0;
}
bool solve(int src, int ink, wint flo = wINF) {
	wint f;
	int i, u, v;
	for (tof = 0; tof + wEPS < flo; ) {
		qb = qe = que;
		memset(lev, ~0, n * 4);
		for (lev[*qe++ = src] = 0, see[src] = ptr[src]; qb != qe; ) {
			for (i = ptr[u = *qb++]; ~i; i = next[i]) if (capa[i] > wEPS && !~lev[v = zu[i]]) {
				lev[*qe++ = v] = lev[u] + 1; see[v] = ptr[v];
				if (v == ink) goto au;
			}
		}
		return 0;
	au:	for (; (f = augment(src, ink, flo - tof)) > wEPS; tof += f);
	}
	return 1;
}
}

bool mult(i64 a, i64 b)
{
	if (a < 0) a *= -1;
	if (b < 0) b *= -1;
	return b % a == 0;
}

int main()
{
	scanf("%d", &N);
	vector<int> As;
	for (int i = 0; i < N; ++i) {
		int v;
		scanf("%d", &v);
		if (v != 0) As.push_back(v);
	}
	N = As.size();

	MF::init(N + 2);
	int s = N, t = N + 1;
	for (int i = 0; i < N; ++i) {
		if (As[i] < 0) {
			MF::ae(s, i, -As[i]);
		} else {
			MF::ae(i, t, As[i]);
		}
	}
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) if (i != j) {
			if (mult(i + 1, j + 1)) {
				//printf("%d %d\n", i, j);
				MF::ae(i, j, 1LL << 50LL);
			}
		}
	}
	MF::solve(s, t);
	i64 mof = MF::tof;
	i64 sum = 0;
	for (int i = 0; i < N; ++i) sum += max(0, As[i]);
	printf("%lld\n", sum - mof);

	return 0;
}


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

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n, m, k, ans = 0;
    cin>>n>>m>>k;
    char a[n][m];
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            cin>>a[i][j];
        }
    }
    for(int b1 = 0; b1 < (1<<n); b1++){
        for(int b2 = 0; b2 < (1<<m); b2++){
            int black = 0;
            for(int i=0; i<n; i++){
                for(int j=0; j<m; j++){
                    if((((b1>>i)&1) == 0) && ((b2>>j)&1) && a[i][j] == '#')
                        black++;
                }
            }
            if(black == k)
                ans++;
        }
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <cstring>

typedef struct{
	char name[100];
	int win;
	int lose;
	int prior;
}team;

void swap(team *p, team *q){
	team tmp = *p;
	*p = *q;
	*q = tmp;
}

int main(){
	while(1){
		int n, a;
		char c[100];
		team t[10];
		
		scanf(" %d", &n);
		if(n==0) break;
	
		for(int i=0; i<n; i++){
			scanf(" %s", c);
			strcpy(t[i].name, c);
			t[i].win=0;
			t[i].lose=0;
			t[i].prior=i;
			
			for(int j=0; j<n-1; j++){
				scanf(" %d", &a);
				if(a==0) ++t[i].win; 
				else if(a==1) ++t[i].lose;
			}
		}
		
		for(int i=0; i<n; i++){
			for(int j=0; j<n; j++){
				if( (t[i].win > t[j].win) || (t[i].win==t[j].win && t[i].lose < t[j].lose) ||  (t[i].win==t[j].win && t[i].lose==t[j].lose && t[i].prior < t[j].prior) )
					swap(&t[i], &t[j]);
			}
		}
	
		for(int i=0; i<n; i++)
			printf("%s\n", t[i].name);

	}

	return 0;
}

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

using namespace std;

const int Nmax = 500;

int n, H, i, x, y, A, B, C, D, grad[Nmax];
bool ok, used[Nmax];
vector<int> v[Nmax];

void dfs(int node)
{
    used[node] = 1;
    ok |= (grad[node] != 0);
    for(auto it : v[node])
        if(!used[it]) dfs(it);
}

int main()
{
   // freopen("input", "r", stdin);

    cin >> n >> H;
    for(i=1; i<=n; ++i)
    {
        cin >> A >> B >> C >> D;
        x = (C ? C : A + H);
        y = (D ? D + H : B);

        v[x].push_back(y);
        v[y].push_back(x);
        ++grad[x]; --grad[y];
    }

    ok = 1;
    for(i=1; i<=H && ok; ++i) ok &= (grad[i] <= 0);
    for(; i<= 2*H && ok; ++i) ok &= (grad[i] >= 0);

    for(i=1; i <= 2 * H && ok; ++i)
        if(!used[i] && v[i].size())
        {
            ok = 0;
            dfs(i);
        }

    cout << (ok ? "YES" : "NO") << '\n';

    return 0;
}


Measured memory_bytes: 1664
n=int(input())
s=input()
ans=0
for i in range(0,10):
    si=s.find(str(i))
    if si<0:
        continue
    for j in range(0,10):
        sj=s[si+1:].find(str(j))
        if sj<0:
            continue
        for k in range(0,10):
            sk=s[si+1:][sj+1:].find(str(k))
            if sk>=0:
                ans+=1
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<cstring>
#include<sstream>
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
typedef long long ll;
typedef unsigned long long ull;
////////////////////////////////////////////////////////////

int main(){
	int n,m;
	cin >> n >> m;
	string s;
	cin >> s;
	
	vector<ull> pow(300010) , hs(300010) , ans;
	
	ull b = mod;

	pow[0] = 1;
	hs[0] = 0;	

	rep(i,0,s.size()){
		pow[i+1] = pow[i] * b;
		hs[i+1] = (hs[i]*b+s[i]);
	}
	
	ll l=0 , r=1;


	rep(i,0,m){
		string in;
		cin >> in;
		if( in == "R++") r++;
		else if( in == "R--") r--;
		else if( in == "L++") l++;
		else l--;

		ull num = hs[r]-hs[l]*pow[r-l];
		ans.push_back(num);

	}
	
	vsort(ans);
	

	ans.erase( unique(ans.begin() , ans.end() ) , ans.end() );
	cout << ans.size() << endl;
	

	ret 0;
}


Measured memory_bytes: 12184
N = gets.to_i
A = gets.chomp.split.map(&:to_i)

DEBUG = false

oper = Array.new(A.size)

current = 99
(A.size - 1).downto(0){ |i|
  puts A[i] if DEBUG
  if A[i] > current
    puts :sell if DEBUG
    oper[i] = :sell
    current = A[i]
  elsif A[i] < current
    puts :buy if DEBUG
    oper[i] = :buy
    current = A[i]
  else
    oper[i] = nil
  end
}


wallet = 1000
stock_num = 0
oper.each.with_index{ |o, i|
  case o
  when :buy
    price = A[i]
    buy_num = wallet / price
    wallet = wallet - buy_num * price
    stock_num = stock_num + buy_num
  when :sell
    price = A[i]
    wallet = wallet + stock_num * price
    stock_num = 0
  end
}

puts wallet


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

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		// for (; solver.hasNext();) {
		// solver.readBody(in.readLine());
		// }
		// solver.solve();
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split(" ");
		// N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		int A = Integer.parseInt(strArr[0]);
		int B = Integer.parseInt(strArr[1]);
		int C = Integer.parseInt(strArr[2]);
		int X = Integer.parseInt(strArr[3]);
		int Y = Integer.parseInt(strArr[4]);
		int ans = Integer.MAX_VALUE;
		for (int c = 0; c / 2 <= X || c / 2 <= Y; c += 2) {
			int amt = 0;
			if (c / 2 < X) {
				amt += ((X - c / 2) * A);
			}
			if (c / 2 < Y) {
				amt += ((Y - c / 2) * B);
			}
			amt += c * C;
			if (amt < ans)
				ans = amt;
		}
		System.out.println(ans);
	}

	public boolean hasNext() {
		return cnt < N;
	}

	public void readBody(String str) {
		// System.out.println(str);
		cnt++;
	}

	public void solve() {
	}
}


Measured memory_bytes: 21972
#!/usr/bin/env python3
import sys
from itertools import chain

# form bisect import bisect_left, bisect_right, insort_left, insort_right
# from collections import Counter
# import numpy as np


def solve(N: int, A: "List[int]"):
    total = 0
    for a in A:
        total ^= a
    return [total ^ a for a in A]


def main():
    tokens = chain(*(line.split() for line in sys.stdin))
    # N, a = map(int, line.split())
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    ans = solve(N, A)
    print(" ".join([str(a) for a in ans]))


if __name__ == "__main__":
    main()


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

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

    int N;
    cin >> N;
    vector<int> imosu(100010);
    imosu[0] += 1;
    imosu[imosu.size() - 1] -= 1;
    for (int i = 0; i < N; i++) {
        int a, b;
        cin >> a >> b;
        imosu[a] += 1;
        imosu[b + 1] -= 1;
    }
    for (int i = 1; i < imosu.size(); i++) {
        imosu[i] = imosu[i] + imosu[i - 1];
    }
    int ans = 0;
    for (int i = 0; i < imosu.size(); i++) {
        if (i <= imosu[i]) {
            ans = max(i - 1, ans);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3356
-- Your code here!
import Data.List.Split

main = do
    ins <- getLine
    let tmp = (splitOn " " ins)
    let ab = map read tmp :: [Int]
    (putStrLn . oddEven) (foldr (*) 1 ab)

oddEven n
    | (n `mod` 2) == 1 = "Odd"
    | otherwise      = "Even"


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



		


int main(){
	
	long long a,b;
	cin>>a>>b;
	if(a*b<=0){
		cout<<"Zero"<<endl;
	}
	else{
		if(a>0||(a+b)%2!=0){
			cout<<"Positive"<<endl;
		}
		else{
			cout<<"Negative"<<endl;
		}
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <map>
#include <iostream>
using namespace std;
using LL = long long;

int main() {
  map <int, int> dp[2];
  int n, m, t = 0;
  scanf("%d %d", &n, &m);
  dp[t][0] = 0;
  for (int i = 0; i < n; i ++) {
    // iが奇数のとき t は 1 になる
    t ^= 1;
    dp[t].clear();
    int w, v;
    scanf("%d %d", &w, &v);
    for (auto x : dp[t ^ 1]) {
      // dp[t ^ 1] で古いほうの配列を取り出し，
      // dp[t][...] で新しいほうの配列を更新している．
      int wt = x.first, va = x.second;
      // このアイテム(w,v)を使わない場合の更新
      dp[t][wt] = max(dp[t][wt], va);
      // 重みが許容量以下のときは，アイテムを使う場合と使わない場合でmaxをとる
      if (wt + w <= m)
        dp[t][wt + w] = max(dp[t][wt + w], va + v);
    }
  }
  int ans = 0;
  // 最後に更新したtを用いてdp[t]を取り出す
  for (auto x : dp[t])
    ans = max(ans, x.second);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512
n = gets.to_i
rooms = Array.new(4).map{Array.new(3).map{Array.new(10,0)}}
n.times do
  b, f, r, v = gets.split.map(&:to_i)
  rooms[b-1][f-1][r-1] += v
end

rooms.each_with_index do |ridge, i|
  ridge.each do |floor|
    puts " " + floor.join(' ')
  end
  puts "####################" unless i == rooms.length - 1
end


Measured memory_bytes: 6900
import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;

public class Main {

  static final int N = 100000;
  static final int Q = 50000;
  static int n, q;
  static int s[], t[];

  public static int binary_search(int x) {
    int l = -1;
    int r = n-1;
    int m;
    while (r-l > 1) {
      m = (l+r)/2;
      if (x <= s[m]) 
        r = m;
      else
        l = m;
    }
    
    return ((s[r]==x) ? r : -1);
  }

  public static void main(String[] args) {
    int i;
    Scanner sc = new Scanner(System.in); 
    n = Integer.parseInt(sc.next());
    s = new int[n];
    for (i=0; i<n; i++)
      s[i] = Integer.parseInt(sc.next());

    q = Integer.parseInt(sc.next());
    t = new int[q];
    for (i=0; i<q; i++)
      t[i] = Integer.parseInt(sc.next());

    int res = 0;
    for (i=0; i<q; i++)
      if (binary_search(t[i]) != -1)
        res++;

    System.out.println(res);
  }
}

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

using namespace std;

#define PB push_back  
#define MP(A, B) make_pair(A, B)  
#define fi first  
#define se second  

#define gcd(a,b) __gcd(a,b)
#define pi acos(-1.0)
#define pii pair<int,int>
#define ll long long  
#define MAX 1000005  
#define MOD 1000000007  
#define INF 0x3f3f3f3f  
#define EXP 1e-8  
#define lowbit(x) (x&-x)  
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}

struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
}; 


long long A[200005] = {0}, C[15] = {0}, skill[15] = {0};
long long ans = LONG_MAX;
long long n, k; 
long long v[200005] = {0}, t[200005] = {0};

int main() {
    cin >> n >> k;
    for (int i = 1; i <= n; ++i) cin >> A[i];
    long long now = 1, cnt = 0, s = 0;
    while (!v[now]) {
        v[now] = cnt;
        cnt++;
        now = A[now];
        t[cnt] = now; 
    }
    t[0] = 1;
    cnt -= v[now];
    // for (int i = 0; i <= cnt; ++i) cout << t[i] << ' ';
    // cout << endl;
    // for (int i = 0; i <= cnt; ++i) cout << v[i] << ' ';
    // cout << endl;
    // cout << cnt << endl;
    if (k < v[now]) cout << t[k] << endl;
    else 
    cout << t[(k-v[now])%cnt+v[now]] << endl;
    return 0;
}

Measured memory_bytes: 8312
#include <stdio.h>
#include <math.h>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) cerr << #x << "=" << static_cast<bitset<16> >(x) << endl;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 100000000;
typedef double D;
const D EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={-1, 0, 1, 0}, dy[4]={0, -1, 0, 1};
using namespace std;
typedef pair<int, int> PII;

struct  P {
	int x, y;
	P() {}
	P(int x_, int y_) : x(x_), y(y_) {}
};
/** Problem1165 : Pablo Squarson's Headache **/
int main()
{
	int N;
	const int ddx[4]={-1, 0, 1, 0}, ddy[4]={0, -1, 0, 1};
	while (cin>>N, N) {
		vector<P> cubes;
		cubes.push_back(P(0, 0));
		
		rep(i, N-1) {
			int n, d;
			cin>>n>>d;
			cubes.push_back(P(cubes[n].x+ddx[d], cubes[n].y+ddy[d]));
		}
		
		int maxX=0, maxY=0, minX=INF, minY=INF;
		rep(i, N) {
			maxX = max(maxX, cubes[i].x);
			maxY = max(maxY, cubes[i].y);
			minX = min(minX, cubes[i].x);
			minY = min(minY, cubes[i].y);
		}
		
		cout << maxX-minX+1 << " " <<  maxY-minY+1 << endl;
	}
}

Measured memory_bytes: 1204
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<vector>
#include<algorithm>
#include<functional>
#include<map>
using namespace std;
int INF=10000000;
int w,h;
int ans;
//予算、容量、初期酸素
int f,m,o;
int fie[11][11];
//x,bit,y,air
int cost[11][1<<10][11][51];

void dfs(int x,int bit,int y,int air,int c){
	if(air<=0)return;
	if(!((bit >> x)& 1)){
		if(fie[x][y]>0)air=min(air+fie[x][y],m);
		if(fie[x][y]<0)c+=abs(fie[x][y]);
		bit |= 1<< x;
	}
	if(c>f)return;
	if(cost[x][bit][y][air]<=c)return;
	cost[x][bit][y][air]=c;
	if(y==h-1)ans=min(ans,c);
	else{
		dfs(x,0,y+1,air-1,c);
		if(x-1>=0)dfs(x-1,bit,y,air-1,c);
		if(x+1<w)dfs(x+1,bit,y,air-1,c);
	}
}

int main(void){
	while(1){
		ans=INF;
		for(int i=0;i<=10;i++){
			for(int j=0;j<=10;j++){
				for(int bit=0;bit<=(1<<10)-1;bit++){
					for(int k=0;k<=50;k++){
						cost[i][bit][j][k]=INF;
					}
				}
			}
		}
		scanf("%d%d",&w,&h);
		if(w==0 && h==0)break;
		scanf("%d%d%d",&f,&m,&o);
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				scanf("%d",&fie[j][i]);
			}
		}
		for(int i=0;i<w;i++){
			dfs(i,0,0,o-1,0);
		}
		if(ans==INF)cout << "NA" << endl;
		else cout << ans << endl;
	}	
    return 0;
}

Measured memory_bytes: 25904
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn=200+10;
int vis[maxn][maxn];
struct Node
{
    int x,y;
    Node(){}
    Node(int a,int b):x(a),y(b){}
};
vector<Node >G;
int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    if(n==0)
    {
         printf("-1\n");
        return 0;
    }
    int m=n-1;
    int sum=(m)*(m-1)/2;
    if(k>sum)
    {
        printf("-1\n");
        return 0;
    }
    for(int i=1;i<=m;i++)
    {
        G.push_back(Node(i,n));
    }
 
    int i=1,j=2;
    while(sum!=k)
    {
        sum--;
        G.push_back(Node(i,j));
        j++;
        if(j==m+1) i++,j=i+1;
    }
 
    printf("%d\n",G.size());
    for(int i=0;i<G.size();i++)
    {
        printf("%d %d\n",G[i].x,G[i].y);
    }
}

Measured memory_bytes: 3828
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    int n,a,b,c,d,e,f,kekka;
    cin>>n>>a>>b>>c>>d;
    if(n%a==0){
        e=n/a;
    }else if(n%a>0){
        e=n/a+1;
    }
    if(n%c==0){
        f=n/c;
    }else if(n%c>0){
        f=n/c+1;
    }
    kekka=min(e*b,f*d);
    cout<<kekka<<endl;
}


Measured memory_bytes: 3116
n = gets.to_i
ans = "No"
cnt = 0
n.times{ |i|
  a, b = gets.split(" ").map(&:to_i)
  if a == b
    cnt += 1
    if cnt >= 3
      ans = "Yes"
    end
  else 
    cnt = 0
  end 
}
puts ans

Measured memory_bytes: 14396
/**
 *    author        : Sudipta Banik Trisha 
 *    created       : August 21, 2020 12:28 PM
 *    Problem Name  : B - Buffet
 *    Problem Limit : 2000 ms , 1024 MB
 *    Problem Url   : https://atcoder.jp/contests/abc140/tasks/abc140_b
 *    @genarated by : ai-virtual-assistant
**/

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

int main(){
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;

    int a[n+1] , b[n+1], c[n+1];
    int sum = 0;

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

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

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

    for(int i=0; i<n-1; i++){
        if(a[i]+1 == a[i+1]){
            sum += c[a[i]-1];
        }
    }
    cout << sum << endl;
    return 0 ;
}


Measured memory_bytes: 3592
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_set>
#include <bitset>
#include <time.h>
#include <limits.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define szz(x) (int)x.size()
#define sz(x) (int)x.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
typedef tuple<int, int, int> t3;

const ll mod = 1e9 + 7;
ll dp[3030][3030];
int N;
char X[3030];

ll get_sum(int a, int l, int r) {
	return (dp[a][r] - (l ? dp[a][l-1] : 0) + mod) % mod;
}

int main() {
	scanf("%d", &N);
	scanf("%s", X + 1);
	for(int i=0;i<N;i++) dp[1][i] = 1;
	for(int i=1;i<N;i++) {
		for(int j=1;j<=N-i;j++) dp[i][j] = (dp[i][j] + dp[i][j-1]) % mod;
		for(int j=0;j<=N-i;j++) {
			if(X[i] == '>') dp[i+1][j] = get_sum(i, j+1, N-i);
			else dp[i+1][j] = get_sum(i, 0, j);
		}
	}
	printf("%lld\n", dp[N][0]);
	return 0;
}


Measured memory_bytes: 71936
/************************************************
 *Author*        :skyNebula
 *Created Time*  : 一  1/14 15:48:48 2019

*********************************************/

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <stack>


using namespace std;
#define debug(x) cout << #x << " " << "=" << " " << (x) << endl;
#define ms(a,b) memset(a,b,sizeof(a);
typedef pair<int, int> pii;
typedef long long LL;
const int mod = 1e9 + 7;
const int MaxN = 1e6;

int n,m,x,y;
int a[MaxN],b[MaxN];

int main()
{
    cin >> n >> m >> x >> y;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = 0; i < m; i++){
        cin >> b[i];
    }
    a[n] = x;
    b[m] = y;

    sort(a,a+n+1);
    sort(b,b+m+1);
    if(a[n] >= b[0]){
        cout << "War" << endl;
    }
    else
        cout << "No War" << endl;

    return 0;
}


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

int main() {

  int N, K;
  cin >> N >> K;

  vector<int> h(N);
  for(int i = 0; i < N; i++) {
    cin >> h[i];
  }

  sort(h.begin(), h.end(), std::greater<int>());

  int answer = 1000000010;

  for (int i = 0; i < N - K + 1; i++) {
    answer = min(answer, h[i] - h[i + K - 1]);
  }

  cout << answer << endl;

  return 0;

}

Measured memory_bytes: 640
n = gets.to_i
a = gets.split(" ").map(&:to_i)

h = {}
a.each do |x|
  h[x] ||= 0
  h[x] += 1
end

sum = 0
h.each do |k, v|
  sum += v * (v-1) / 2
end

a.each do |x|
  puts sum - (h[x] - 1)
end

Measured memory_bytes: 30084