akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <memory>
#include <memory.h>
#include <cmath>
#include <fstream>
#include <cmath>
#include <numeric>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <sstream>
#include <cstdlib>
#include <cassert>
#include <cstdio>
#include <map>
#include <iomanip>
#include <list>
#include <cctype>
#include <algorithm>
#include <complex>
#define USE_MATH_DEFINES
using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<int, PP> PPP;
const int INF = 1 << 29;
const double EPS = 1E-10;

namespace std{
	bool operator < (const xy_t &a, const xy_t &b){
		return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
	}
}

double cross(const xy_t &a, const xy_t &b){
	return imag(conj(a) * b);
}

double dot(const xy_t &a, const xy_t &b){
	return real(conj(a)*b);
}

xy_t projection(const line &l, const xy_t &p){
	double t = dot(l.second - l.first, p - l.first) / norm(l.second - l.first);
	return l.first + t * (l.second - l.first);
}

int ccw(xy_t a, xy_t b, xy_t c){
	b -= a; c -= a;
	if(cross(b, c) > 0) return 1;
	if(cross(b, c) < 0) return -1;
	if(dot(b, c) < 0) return +2;
	if(norm(b) < norm(c) ) return -2;
	return 0;
}

bool intersectSP(const line &s, const xy_t &p){
	return abs(s.first - p) + abs(s.second - p) - abs(s.second - s.first) < EPS;
}

bool intersectSS(const line &s, const line &t){
	return ccw(s.first, s.second, t.first) * ccw(s.first, s.second, t.second) <= 0 &&
		ccw(t.first, t.second, s.first) * ccw(t.first, t.second, s.second) <= 0;
}


double distanceSP(const line &s, const xy_t p){
	xy_t r = projection(s, p);
	if(intersectSP(s, r)) return abs(r - p);
	return min(abs(s.first - p), abs(s.second - p));
}

double distanceSS(const line &s, const line &t){
	if(intersectSS(s, t)) return 0.0;
	return min(min(distanceSP(s, t.first), distanceSP(s, t.second)),
		min(distanceSP(t, s.first), distanceSP(t, s.second)));
}

xy_t crosspoint(const line &l, const line &m){
	double a = cross(l.second - l.first, m.second - m.first);
	double b = cross(l.second - l.first, l.second - m.first);
	if(abs(a) < EPS && abs(b) < EPS) return m.first;
	if(abs(a) < EPS) assert(false);
	return m.first + b / a * (m.second - m.first);
}

void doit(int &t, int &n, int &w, char c){
	int tmp;
	if(c == 'n'){
		tmp = n;
		n = t;
		t = 7 - tmp;
	}else if(c == 'e'){
		tmp = t;
		t = w;
		w = 7 - tmp;
	}else if(c == 's'){
		tmp = t;
		t = n;
		n = 7 - tmp;
	}else {
		tmp = w;
		w = t;
		t = 7 - tmp;
	}
}


int main(){
	int n;
	int top, north, west;
	string s;
	while(cin >> n && n){
		top = 1;
		north = 2;
		west = 3;
		for(int i = 0; i < n; i++){
			cin >> s;
			doit(top, north, west, s[0]);
		}
		cout << top << endl;
	}
	return 0;
}

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

int a, b;
string s;

int main(void){
	cin >> a >> b >> s;
	for(int i = 0; i < s.size(); i++){
		if((i == a && s[i] != '-') || (i != a && s[i] == '-')){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 3612
/*
      author  : nishi5451
      created : 15.08.2020 12:06:13
*/

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;


int main(){
    int n;
    cin 
    >> n;
    double ans=0.0;
    rep(i,n){
        int a;
        cin >> a;
        ans += 1.0/a;
    }
    printf("%.12lf\n",1.0/ans);
    return 0;
}

Measured memory_bytes: 3760
N=int(input())
A=list(map(int,input().split()))

plus=0
zero=0
minus=0

for i in range(N):
    if A[i]>0:
        plus+=1
    elif A[i]<0:
        minus+=1
    else:
        zero+=1
ans=0
m=10**9+10
for i in range(N):
    ans+=abs(A[i])
    m=min(m,abs(A[i]))


if minus%2==0 or zero>0:
    pass
else:
    
    ans=ans-2*m

print(ans)

Measured memory_bytes: 20204
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main()
{
  ll N;
  cin >> N;
  vector<vector<ll>> s(N, vector<ll>(26, 0));
  for (ll i = 0; i < N; ++i) {
    string S;
    cin >> S;
    for (ll j = 0; j < 10; ++j) {
      s.at(i).at(S[j] - 'a') += 1;
    }
  }
  sort(s.begin(), s.end());
  // for (ll i = 0; i < s.size(); ++i) {
  //   for (ll j = 0; j < 26; ++j) {
  //     cout << s.at(i).at(j);
  //   }
  //   cout << "\n";
  // }
  vector<ll> before = s.at(0);
  ll cnt = 0;
  ll ans = 0;
  for (ll i = 0; i < N; ++i) {
    if (s.at(i) == before) {
      cnt += 1;
    }
    else {
      ans += cnt * (cnt - 1) / 2;
      cnt = 1;
      before = s.at(i);
    }
  }
  ans += cnt * (cnt - 1) / 2;
  cout << ans << "\n";
}


Measured memory_bytes: 24448
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <utility>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define MOD 1e9 + 7
#define INF 1e9
#define SENTINEL 2e9
#define PIE 3.1415926535

template <class T>
inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}
template <class T>
inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template <class T>
inline T GCD(T a, T b){if (b == 0) return a; else return GCD(b, a % b);}
template <class T>
inline T LCM(T a, T b) {return (a * b) / GCD(a, b);}

#define itn int

int main() {
    itn n, k;
    cin >> n>>k;
    vector<int> p(n);
    rep(i, n){ cin >> p[i];
    p[i]++;}
    vector<int> s(n + 1);
    s[0] = 0;
    repk(i, 1, n + 1) s[i] = s[i - 1] + p[i - 1];
    //n-k-1
    int ans = -INF;
    rep(i,n-k+1){
        chmax(ans, s[k + i] - s[i]);
    }
    double aans = ans / 2.0;
    cout << fixed<<setprecision(10)<< aans << endl;
}

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

#define FAST_IO                       \
	ios_base::sync_with_stdio(false); \
	cin.tie(0);                       \
	cout.tie(0);

using namespace std;

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

const int MOD = 1e9 + 7;

int main()
{

	FAST_IO;

	string s;
	cin >> s;
	int q;
	cin >> q;
	deque<char> dq;
	for(auto c : s)
		dq.push_back(c);
	bool begin = true, end = true;
	while (q--) {
		int t;
		cin >> t;
		if (t == 1) {
			// reverse the string
			begin = !begin;
			end = !end;
		}
		else {
			int f;
			char c;
			cin >> f >> c;
			if(f == 1) {
				if(begin) 
					dq.push_front(c);
				else
					dq.push_back(c);
			}
			else { // f = 2
				if(end) 
					dq.push_back(c);
				else
					dq.push_front(c);
			}
		}
	}
	if(begin == true) {
		while(!dq.empty()) {
			cout<<dq.front();
			dq.pop_front();
		}
	}
	else {
		while(!dq.empty()) {
			cout<<dq.back();
			dq.pop_back();
		}
	}
	return 0;
}


Measured memory_bytes: 976
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll A[4];
ll a[4];
int id[4]={0,1,2,3};
double cc(int idx){
    switch(idx){
        case 0:return 0.25;
        case 1:return 0.5;
        case 2:return 1;
        case 3:return 2.0;
    }
}
bool cmp(int x,int y){
    return a[x]<a[y];
}
int main(){
    double n;
    cin>>A[0]>>A[1]>>A[2]>>A[3];
    cin>>n;
    a[0]=A[0]*8; a[1]=A[1]*4;
    a[2]=A[2]*2; a[3]=A[3];
    sort(id,id+4,cmp);
    ll ans=0,t;
    while(n > 0){
        for(int i=0;i<4;++i){
            if(id[i]==0) t=(ll)n*4;
            else if(id[i]==1) t=(ll)n*2;
            else if(id[i]==2) t=(ll)n;
            else t=(ll)n/2;
            ans+=t*A[id[i]];
            n-=t*cc(id[i]);
        }
    }
    printf("%lld\n",ans);
    return 0;
}



Measured memory_bytes: 256
import java.util.*;

class Main {
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int  num = scanner.nextInt();//要素数
		int  truck = scanner.nextInt();//トラック数
		
		Allocation(num, truck, scanner);
		
		scanner.close();
	}

	public static void Allocation(int num, int truck, Scanner scanner){
		int[] array = new int[num];
		int sub = 0;
		long max = 0;
		
		//要素を作りながら足す
		for (int i = 0; i < num; i ++) {
			array[i] = scanner.nextInt();
			sub += array[i];
			max = Math.max(max,array[i]);
		}
		
		//2分探索準備
		long left = max;
		long right = sub;
		
		
		//探索
		while (left < right) {
			long p = (left+right)/2;
			int id = 0;
			long sum = 0;
			for (int i = 0; i < num; i ++) {
				if (sum + array[i] > p) {
					sum = array[i];
					id ++;
				}else {
					sum += array[i];
				}
				if (id == truck){
					break;
				}
			}
			if (id == truck){
				left = p + 1;
			}else{
				right = p;
			}
		}
		//出力
		System.out.println(left);
		
	}
}


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int ans = 0;
  if (A < C) {
    if (B >= C) {
      if (B <= D) {
        ans = B - C;
      }
      else {
        ans = D - C;
      }
    }
  }
  else if (A > C) {
    if (D >= A) {
      if (D <= B) {
        ans = D - A;
      }
      else {
        ans = B - A;
      }
    }
  }
  else if (A == C) {
    if (C < D) {
      ans = B - A;
    }
    else {
      ans = D - C;
    }
  }
  cout << ans << '\n';
}

Measured memory_bytes: 256
S=list(map(int,input().split()))
n=int(input())

for i in range(n):
  q=list(map(int,input().split()))
  if q in [[S[3],S[1]],[S[1],S[2]],[S[2],S[4]],[S[4],S[3]]]:
           print(S[0])
           
  if q in [[S[0],S[3]],[S[3],S[5]],[S[5],S[2]],[S[2],S[0]]]:
           print(S[1])
           
  if q in [[S[0],S[1]],[S[1],S[5]],[S[5],S[4]],[S[4],S[0]]]:
           print(S[2])
           
  if q in [[S[4],S[5]],[S[5],S[1]],[S[1],S[0]],[S[0],S[4]]]:
           print(S[3])
           
  if q in [[S[0],S[2]],[S[2],S[5]],[S[5],S[3]],[S[3],S[0]]]:
           print(S[4])
  
  if q in [[S[2],S[1]],[S[1],S[3]],[S[3],S[4]],[S[4],S[2]]]:
           print(S[5])


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

using namespace std;

const int INF = 1001001001;

int n;
int npos;
int p[64], t[64];
int memo[64][128][3];

int calc(int no, int pos, int c, int tm)
{
	npos = max(npos, no + 1);
	if (no == n) return (pos);
	
	int ans = INF;
	int d = abs(p[no] - pos);

	tm += d * (c + 1);
	if (tm > t[no]) return (memo[no][pos][c] = INF);
	if (~memo[no][pos][c]) return (memo[no][pos][c]);

	int a1 = calc(no + 1, 0, 0, t[no] + (c + 2) * p[no]) + d + p[no];
	int a2 = (c < 2 ? calc(no + 1, p[no], c + 1, t[no]) + d : INF);

	ans = min(ans, min(a1, a2));

	return (memo[no][pos][c] = ans);
}

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

		for (int i = 0; i < n; i++){
			scanf("%d %d", p + i, t + i);
		}

		memset(memo, -1, sizeof(memo));

		npos = 0;
		calc(0, 0, 0, 0);

		int ans = memo[0][0][0];

		if (ans < INF) printf("OK %d\n", ans);
		else printf("NG %d\n", npos);
	}

	return (0);
}

Measured memory_bytes: 1292
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; i++)
using ll = long long;
using namespace std;
const int INF = 1e9;

int numToDig(int a) {
    return to_string(a).size();
}

int main() {

    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];

    int mi = INF, cnt = 0;
    ll ans = 0;

    rep(i, N) {
        if (A[i] < 0)
            cnt++;
        A[i] = abs(A[i]);
        mi = min(mi, A[i]);
        ans += A[i];
    }

    if (cnt % 2 == 0)
        cout << ans << endl;

    else
        cout << ans - mi * 2 << endl;

    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fast ios_base::sync_with_stdio(false),cin.tie(nullptr)
#define pi 3.14159265358979323846264338327950L
int main()
{
        fast;
        int t=1;
       // cin>>t;
        while(t--)
        {
                string a;
                cin>>a;
                if(a.compare("ABC")==0)
                        cout<<"ARC"<<endl;
                else
                        cout<<"ABC"<<endl;
        }
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
                                        #include<iostream>
                                        #include<cstdio>
                                        #include<vector>
                                        #include<queue>
                                        #include<map>
                                        #include<cstring>
                                        #include<string>
                                        #include <math.h>
                                        #include<algorithm>
                                    //    #include <boost/multiprecision/cpp_int.hpp>
                                        #include<functional>
                                #define int long long
                                        #define inf  1000000007
                                        #define pa pair<int,int>
                                        #define ll long long
                                        #define pal pair<double,pa>
                                        #define ppa pair<int,int>
                                        #define ppap pair<int,pa>
                                        #define ssa pair<string,int>
                                        #define  mp make_pair
                                        #define  pb push_back
                                        #define EPS (1e-10)
                                        #define equals(a,b) (fabs((a)-(b))<EPS)
                                  #define VI vector<int>
                                        using namespace std;
                                        
                                  class pas{
                                    	public:
                                    	int x,y;
                                    	pas(int x=0,int y=0):x(x),y(y) {}
                                    	pas operator + (pas p) {return pas(x+p.x,y+p.y);}
                                    	pas operator - (pas p) {return pas(x-p.x,y-p.y);}
                                    	pas operator * (int a) {return pas(x*a,y*a);}
                                    	pas operator / (int a) {return pas(x/a,y/a);}
                                    //	double absv() {return sqrt(norm());}
                                    	int norm() {return x*x+y*y;}
                                    	bool operator < (const pas &p) const{
                                    		return x != p.x ? x<p.x: y<p.y;
                                    	}
                                    	bool operator == (const pas &p) const{
                                    		return x==p.x && y==p.y;
                                    	}
                                    };
 

           signed main(){

string s;
      
           	cin>>s;
           	s[3]='8';
           	cout<<s<<endl;
           	return 0;
           }

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

  		long a =  sc.nextLong();
      	long v =  sc.nextLong();
      	long b =  sc.nextLong();
      	long w =  sc.nextLong();
      	long t =  sc.nextLong();
      
      	long dis = (v-w) * t; 
      	
      	if(dis >= Math.abs(a-b)) System.out.println("YES");
      	else System.out.println("NO");
        
	}
}


Measured memory_bytes: 35784
n = int(input())

def fact(x):
  prime = {}
  if x == 1: prime[1] = 1
  for i in range(2,x+1):
    while True:
      if x % i == 0:
        if i in prime:
          prime[i] += 1
        else: prime[i] = 1
        x //= i
      else: break
  return prime

ans = 0

for i in range(n):
  prime = fact(i+1)
  a = 1
  for j in prime:
    a *= (prime[j]+1)
  if a == 8 and (i+1) % 2 == 1:
    ans += 1

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = (0); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define DEBUG(val) cout << #val << " : " << val << endl
#define MOD 1000000007

int main() {
  int n;
  int a[10005];
  int b[10005];
  ll a_sum = 0;
  ll b_sum = 0;

  cin >> n;
  REP(i, n) {
    cin >> a[i];
    a_sum += a[i];
  }
  REP(i, n) {
    cin >> b[i];
    b_sum += b[i];
  }

  ll max_count = b_sum - a_sum;
  ll count = 0;
  ll husai = 0;
  ll a_cnt = 0;
  ll b_cnt = 0;
  REP(i, n) {
    if (a[i] < b[i]) {
      int cnt = (b[i] - a[i] + 1) / 2;
      a_cnt += cnt;
      a[i] += 2 * cnt;
    }
  }
  REP(i, n) {
    if (b[i] < a[i]) {
      int cnt = a[i] - b[i];
      b_cnt += cnt;
    }
  }

  if (b_cnt <= a_cnt) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3680
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>

using namespace std;

int main(){



int n;
cin >>n;
int a[n+1];
for(int i=1;i<=n;i++){
    cin >>a[i];
}
if(n%2==0){
int k=n/2;
for(int i=k;i>=1;i--){
    cout <<a[i*2]<<" ";
}
for(int i=1;i<=k;i++){
    cout <<a[(i-1)*2+1]<<" ";
}

}
else{
    int k=n/2;
    for(int i=k;i>=1;i--){
    cout <<a[i*2+1]<<" ";
}
cout <<a[1]<<" ";
for(int i=1;i<=k;i++){
    cout <<a[i*2]<<" ";
}

}
 return 0;
}

Measured memory_bytes: 2944
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>

#define PB push_back
#define ALL(a)  (a).begin(),(a).end()
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)

#define mod 1000000007

using namespace std;

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

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int INF = (int)1e9;

int main()
{
	int n;
	cin >> n;
	vector<int> p(n + 1);
	for(int i = 1; i <= n; i++) {
		cin >> p[i];
	}
	int ans = 0;
	for(int i = 1; i <= n; i++) {
		if (i == p[i]) {
			if (i == n) {
				ans++;
			}
			else {
				swap(p[i], p[i + 1]);
				ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
int main()
{
   int a,b,i,j;
   while(1){
   scanf("%d%d",&a,&b);
   if(a==0 && b==0)
    break;
   for(i=0;i<a;i++)
   {
       for(j=0;j<b;j++)
       {

        printf("#");
       }
       printf("\n");
   }
   printf("\n");

   }



}




Measured memory_bytes: 2100
#include <bits/stdc++.h>
using namespace std;
int main(){
  char a,b;
  cin>> a>>b;
  if(a==b){
    cout <<"=" <<"\n";
  }
  else if(a<b){
    cout <<"<"<< "\n";
  }else{
    cout << ">"<<"\n";
  }
}

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

#define LL long long
#define LD long double
#define SC(t,x) static_cast<t>(x)
#define AR(t) vector < t >
#define PII pair < int, int >
#define PLL pair < LL, LL >
#define PIL pair < int, LL >
#define PLI pair < LL, int >
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define PRF first
#define PRS second
#define INIT(ar,val) memset ( ar, val, sizeof ( ar ) )
#define lp(loop,start,end) for ( int loop = start; loop < end; ++loop )
#define lpd(loop,start,end) for ( int loop = start; loop > end; --loop )
#define lpi(loop,start,end) for ( int loop = start; loop <= end; ++loop )
#define lpdi(loop,start,end) for ( int loop = start; loop >= end; --loop )
#define qmax(a,b) (((a)>(b))?(a):(b))
#define qmin(a,b) (((a)<(b))?(a):(b))
#define qabs(a) (((a)>=0)?(a):(-(a)))

const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 20007;

class ftT
{
public:
	void upd ( int p, int x )
	{
		for ( ; p < MAXN; p += p&-p ) data[p] += x;
	}
	
	int sum ( int p )
	{
		int ans = 0;
		for ( ; p; p ^= p&-p ) ans += data[p];
		return ans;
	}
	
private:
	int data[MAXN];
}ft1, ft2;

int n;
int p[MAXN];

void init ();
void input ();
void work ();



int main()
{
	init();
	input();
	work();
}



void init ()
{
	// Init Everything Here
	
	ios::sync_with_stdio ( false );
}

void input ()
{
	// input method
	
	scanf ( "%d", &n );
	lpi ( i, 1, n ) scanf ( "%d", &p[i] );
}

void work ()
{
	// main work
	
	lpi ( i, 1, n ) ft1.upd ( i, 1 ), ft2.upd ( i, 1 );
	
	lpi ( i, 2, n ){
		int np = p[i], pre = p[i-1];
		int nv = ft1.sum ( np ) + ft2.sum( n - np + 1 ), pv = ft1.sum ( pre ) + ft2.sum ( n - pre + 1 );
		ft1.upd ( np, pv - nv + 1 );
		ft2.upd ( n - np + 1, pv - nv + 1 );
	}
	
	lpi ( i, 1, n ) printf ( "%d ", ft1.sum ( i ) );
	putchar ( '\n' );
	lpi ( i, 1, n ) printf ( "%d ", ft2.sum ( n - i + 1 ) );
	putchar ( '\n' );
}

Measured memory_bytes: 896
#include <iostream>
#include <list>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;


int main(){
    list<char> ls;
    string str;
    char ch;
    int n, q1, q2;
    cin >> str >> n;
    rep(i, str.size()){
        ls.push_back(str[i]);
    }
    bool flag = false;
    rep(i, n){
        cin >> q1;
        if(q1 == 1){
            flag = !flag;
        } else {
            cin >> q2 >> ch;
            if(q2 - 1 == flag){
                ls.push_front(ch);
            } else {
                ls.push_back(ch);
            }
        }
    }
    if(flag){
        reverse(ls.begin(), ls.end());
    }
    for(auto it = ls.begin(); it != ls.end(); it++){
        cout << *it;
    }
    cout << endl;
    return 0;
}

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

	public class Main {

		static long mod = 1000000007;

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			String[] t = sc.nextLine().split(" ");
			int n  	   = Integer.parseInt(t[0]);
			//long k = Long.parseLong(t[1].replaceAll("\\.", ""));

			String[] r = sc.nextLine().split(" ");
			long[] bist = new long[n];

			for(int i  = 0; i < n; i ++) {
				bist[i] = Long.parseLong(r[i]) - i - 1;
			}

			Arrays.sort(bist);

			long ans = 0;
			long mid = n % 2 == 0 ? (bist[n / 2] + bist[n / 2 - 1]) / 2 : bist[(n - 1)/ 2];

			for(int i  = 0; i < n; i ++) {
				ans += Math.abs(bist[i] - mid);
			}

			System.out.println(ans);

		}
	}


Measured memory_bytes: 76208
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
//124D Handstand
int main() {
	int n,k,ren=1,ans=0,l;
	string s;
	cin>>n>>k>>s;
	vector<int>pat;
	if(s[0]=='0')pat.push_back(0);
	for(int i=1;i<s.size();i++){
	    if(s[i]==s[i-1])ren++;
	    else{
	        pat.push_back(ren);
	        ren=1;
	    }
	}
	pat.push_back(ren);
	if(s[s.size()-1]=='0')pat.push_back(0);
	l=pat.size();//odd
	//rep(i,pat.size())cout<<pat[i];
	vector<int>wa(l);
	wa[0]=pat[0];
	rep(i,l-1)wa[i+1]=wa[i]+pat[i+1];
	if(k>=l/2){
	    cout<<wa[l-1];
	    return 0;
	}
	else{
	    ans=wa[2*k];
	    for(int i=1;i*2+k*2<l;i++){
	        ans=max(ans,wa[i*2+k*2]-wa[i*2-1]);
	    }
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 1272
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main() {
    string S;
    cin >> S;
    
    int n = 0, w = 0, s = 0, e = 0;
    
    for (auto c : S) {
        if (c == 'N') ++n;
        else if (c == 'W') ++w;
        else if (c == 'S') ++s;
        else ++ e;
    }
    
    string res = "Yes";
    
    if (n + s > 0 && n * s == 0) res = "No";
    if (w + e > 0 && w * e ==0) res = "No";
    
    cout << res << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	  public static void judge(int m,int f,int r) {
		  if(m==-1 && f==-1 && r==-1) {
			  System.exit(0);
		  }
		  if(m==-1 || f == -1) {
			  System.out.print("F");
		  }else {
	
		  if(m+f>=80) {
		 
		  System.out.print("A");
	      }
		  else if(m+f<80 && m+f>=65) {
			
		  System.out.print("B");
	      }
		  else  if(m+f<65 && m+f>=50) {
			 
		  System.out.print("C");		 
	      }
		  else if(m+f<50 && m+f>=30 && r<50) {
			
		  System.out.print("D");
		  }else if(r>=50) {
			 
		  System.out.print("C");
		  }
		  else  if(m+f<30 || r!=-1) {
			  
		  System.out.print("F");
		  }
		  
		  }
	}
		  
	  public static void main(String[] args) {
		  Scanner x = new Scanner(System.in);
		  for(;;) {
		  int data [] = new int[3];
		  for(int i = 0;i<3;i++) {
				data[i]=x.nextInt();
			}		 
		 judge(data[0],data[1],data[2]);
		 System.out.println();
		  }
	  }
	}


Measured memory_bytes: 26304
#include <iostream>
#include <string>
#include <stack>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <stdlib.h>
#include <tuple>
#include <iomanip>
#include <iterator>
#include <stdio.h>
using namespace std;
const double PI = 3.14159265358979323846;


int main() {
    int N;
    cin >> N;
    vector<long long int> balls;
    map<long long int, long long int> sameBalls;
    map<long long int, long long int> memo;
    for (int i = 0; i < N; i++) {
        int A;
        scanf("%d", &A);
        balls.push_back(A);
        sameBalls[A]++;
        memo[A] = 0;
    }

    long long int originalTotalCount = 0;
    for (auto itr = sameBalls.begin(); itr != sameBalls.end(); itr++) {
        if (itr->second >= 2 && memo[itr->first] == 0) {
            long long int calc = itr->second * (itr->second - 1) / 2;
            memo[itr->first] = calc;
            originalTotalCount += calc;
        }
    }

    for (int k = 0; k < N; k++) {

        long long int totalCount = originalTotalCount;
        /*for (auto itr = sameBalls.begin(); itr != sameBalls.end(); itr++) {
            if (itr->second >= 2 && memo[itr->first] == 0) {
                long long int calc = itr->second * (itr->second - 1) / 2;
                totalCount += calc;
                memo[itr->first] = calc;
            }
            else if (memo[itr->first] != 0) {
                totalCount += memo[itr->first];
            }
        }*/
        int ballNumber = balls[k];
        long long int sameBallsCount = sameBalls[ballNumber];
        long long int memoNumber = memo[ballNumber];

        if (sameBallsCount >= 2) {
            totalCount -= memoNumber;

            if (sameBallsCount >= 3) {
                totalCount += (sameBallsCount - 1) * (sameBallsCount - 2) / 2;
            }
        }

        cout << totalCount << endl;

    }

    /*int N;
    cin >> N;
    vector<int> sameBalls;
    vector<int, vector<int>> sameBallIndices;
    for (int i = 0; i < N; i++) {
        int A;
        cin >> A;

    }*/
    return 0;
}

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

int main() {
	double w,h,x,y;
	cin>>w>>h>>x>>y;
	double p,q,t;
	p=w/2;
	q=h/2;
	t=w*h/2;
	cout<<t<<" ";
	if(x==p&&y==q)
	{
	    cout<<"1";
	}
	else
	{
	    cout<<"0";
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <math.h>
#include <map>
using namespace std;

int main() {

	int N;
	cin >> N;
	vector<int> d;
	for (int i = 0; i < N; i++) {
		int tmp;
		cin >> tmp;
		d.push_back(tmp);
	}
	sort(d.begin(), d.end(), greater<int>());
	int count = 0, now = 999;
	for (auto itr = d.begin(); itr != d.end(); itr++) {
		if (now == *itr) continue;
		now = *itr;
		count++;
	}
	cout << count << endl;
	return 0;
}

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

typedef long long ll;

int N;
ll A[100010];

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) cin >> A[i];
    
    ll b = 0;
    ll s = 0;
    sort(A, A + N, greater<>());
    if (N % 2 == 1) {
        if (2 * A[(N-1)/2] > A[(N-1)/2-1] + A[(N-1)/2+1]) {
            for (int i = 0; i < (N - 3) / 2; i++) {
                b += 2 * A[i];
            }
            b += A[(N - 3) / 2] + A[(N - 1) / 2];
            for (int i = 0; i < (N - 1) / 2; i++) {
                s += 2 * A[i + (N + 1) / 2];
            }
        } else {
            for (int i = 0; i < (N - 1) / 2; i++) {
                b += 2 * A[i];
            }
            for (int i = 0; i < (N - 3) / 2; i++) {
                s += 2 * A[i + (N + 3) / 2];
            }
            s += A[(N-1)/2] + A[(N+1)/2];
        }
    } else {
        for (int i = 0; i < N / 2 - 1; i++) {
            b += 2 * A[i];
        }
        b += A[N / 2 - 1];
        for (int i = 0; i < N / 2 - 1; i++) {
            s += 2 * A[i + N / 2 + 1];
        }
        s += A[N / 2];
    }
    cout << b - s << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define Nmax 4002
using namespace std;

int n,nrW[Nmax],nrB[Nmax],posW[Nmax],posB[Nmax];
int add[Nmax][Nmax],DP[Nmax][Nmax];
int val[Nmax];
char type[Nmax];

int main()
{
    cin>>n;
    for (int i=1;i<=2*n;i++){
        cin>>type[i]>>val[i];
        if (type[i]=='W') posW[val[i]] = i;
        else posB[val[i]] = i;
    }

    for (int i=2*n;i>=1;i--){
        if (type[i]=='W'){
            for (int j=0;j<=n;j++){
                add[i][j] = nrW[val[i]] + nrB[j];
            }
            for (int j=val[i];j<=n;j++) nrW[j]++;
        }
        else{
            for (int j=0;j<=n;j++){
                add[i][j] = nrB[val[i]] + nrW[j];
            }
            for (int j=val[i];j<=n;j++) nrB[j]++;
        }
    }

    for (int i=1;i<=2*n;i++){
        for (int j=max(i-n,0);j<=min(i,n);j++){
            int A = (j==0 ? 1e8 : DP[i-1][j-1] + (posW[j] + add[posW[j]][i-j] - i));
            int B = (j>i-1 ? 1e8 : DP[i-1][j] + (posB[i-j] + add[posB[i-j]][j] - i));
            DP[i][j] = min(A, B);
        }
    }

    cout<<DP[2*n][n];


    return 0;
}


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

namespace _2197
{
    public class Program

    {
        public static void Main(string[] args)
        {
            while (true)
            {
                int n = ReadInt();
                if (n == 0) break;

                int res = 0;
                for (int i = 1 ; i < n ; i++)
                {
                    int sum = i;
                    for (int j = i + 1 ; j < n ; j++)
                    {
                        sum += j;
                        if (sum == n) { res++; break; }
                        if (sum > n) break;
                    }
                }
                Console.WriteLine(res.ToString());
            }
        }

        static string ReadSt() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Console.ReadLine()); }
        static long ReadLong() { return long.Parse(Console.ReadLine()); }
        static double ReadDouble() { return double.Parse(Console.ReadLine()); }
        static string[] ReadStAr(char sep = ' ') { return Console.ReadLine().Split(sep); }
        static int[] ReadIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); }
        static long[] ReadLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); }
        static double[] ReadDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); }
        static string WriteAr(int[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }
        static string WriteAr(double[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }
        static string WriteAr(long[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }

    }

}



Measured memory_bytes: 15944
import collections
import numpy as np

n =  int(input())
a = list(map(int,input().split()))

zero = np.zeros(n+1)
c = collections.Counter(a)

for val,key in c.items():
    zero[val] = key

for i in range(len(zero)):
    if i > 0:
        print(int(zero[i]))


Measured memory_bytes: 54388
#include <bits/stdc++.h>
#define int long long
using pii=std::pair<int,int>;
using namespace std;

const int maxn = 2e5 + 5;

int n, x, y;
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    int xpy_ma = -2e18, xpy_mi = 2e18, xmy_ma = -2e18, xmy_mi = 2e18;
    for(int i = 0; i < n; i++)
    {
        cin >> x >> y;
        xpy_ma = max(xpy_ma, x + y);
        xpy_mi = min(xpy_mi, x + y);
        xmy_ma = max(xmy_ma, x - y);
        xmy_mi = min(xmy_mi, x - y);
    }
    cout << max(xpy_ma - xpy_mi, xmy_ma - xmy_mi) << "\n";
    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int digit_sum(int n)
{
    int sum=0;
    while(n) sum+=n%10,n/=10;
    return sum;
}
main()
{
    int n;
    while(~scanf("%d",&n))
    {
        int m=digit_sum(n);
        n%m ? puts("No") : puts("Yes");
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

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

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

int main(){
	int n;
	string a,b,c;
	cin >> n >> a >> b >> c;
	
	int ret = 0;
	rep(i,n){
		if(a[i] == b[i]){
			if(a[i] == c[i]){}
			else ret ++;
		}
		else {
			if(a[i] == c[i] || b[i] == c[i])ret ++;
			else ret += 2;
		}
	}
	cout << ret << endl;
}



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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define pf push_front
#define rep(i, n) for(int i = 0; i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

signed main() {
    int r;
    cin >> r;
    if(r < 1200 && r >= 0){
        cout << "ABC" << endl;
        return 0;
    }
    if(r<2800 && r >= 1200){
        cout << "ARC" << endl;
        return 0;
    }
    cout << "AGC" << endl;
}

Measured memory_bytes: 256
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun <T> Iterable<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)
fun <T> Array<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val N = nextInt()
    val F = Array(N) {
        nextIntList()
    }
    val P = Array(N) {
        nextLongList()
    }
    val ans = rec_bit((0..9).toList(), F, P)
    println(ans)
}

fun rec_bit(seeds: List<Int>, F: Array<List<Int>>, P: Array<List<Long>>, pos: Int = 0, patterns: Array<Int> = emptyArray()): Long {
    return if (pos < seeds.size) {
        val res1 = rec_bit(seeds, F, P, pos + 1, patterns + seeds[pos])
        val res2 = rec_bit(seeds, F, P, pos + 1, patterns)
        Math.max(res1, res2)
    } else if (patterns.isEmpty()) {
        Long.MIN_VALUE
    } else {
        var sum = 0L
        for (n in F.indices) {
            val cnt = patterns.map { F[n][it] }.sum()
            sum += P[n][cnt]
        }
        sum
    }
}


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

using namespace std;


int main()
{
  int N, A[100];
  cin >> N;

  for(int i = 0; i < N; i++) cin >> A[i];

  int ret = 1 << 30;
  for(int i = -100; i <= 100; i++) {
    int sum = 0;
    for(int j = 0; j < N; j++) {
      sum += (A[j] - i) * (A[j] - i);
    }
    ret = min(ret, sum);
  }
  cout << ret << endl;
}

Measured memory_bytes: 256
H, W, h, w = map(int, input().split())
if H%h == W%w == 0:
  print('No')
  exit(0)
print('Yes')
f = 0
a, b = W, w
if not W%w:
  f = 1
  a, b = H, h
l = [0]*(a+1)
l[1] = 10**6
for i in range(2, a+1):
  if i >= b:
    l[i] = l[i-b] - 1
  else:
    l[i] = l[i-1] - 1
assert(l[-1] > 0)
g = [l[i+1] - l[i] for i in range(a)]
if f:
  for x in g:
    print(*([x]*W))
else:
  for _ in range(H):
    print(*g)

Measured memory_bytes: 5340
import java.util.Scanner;
import java.util.Arrays;
import java.util.stream.Stream;
import java.util.stream.IntStream;
import java.lang.StringBuilder;

public class Main {
  public static void main(String[] args ){
    Scanner sc = new Scanner(System.in);

    int N = sc.nextInt();

    int[] H = new int[N];
    for (int i =0; i < N; i++) {
      H[i] = sc.nextInt();
    }

    int canLookSpotCnt = 1;
    for(int i = 1; i < N; i++) {
      boolean flag = true;
      for (int j = 0; j < i; j++) {
        if (H[j] > H[i]) flag = false;
      }
      canLookSpotCnt += flag ? 1 : 0;
    }

    System.out.println(canLookSpotCnt);
  }
}


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

int main()
{
    vector<int> ans;
    while (1)
    {
        int n;
        cin >> n;

        if (n == 0)
        {
            break;
        }

        vector<int> scoreList;

        for (int i = 0; i < n; ++i)
        {
            int input;
            cin >> input;
            scoreList.push_back(input);
        }

        int min = INT_MAX;

        for (int i = 0; i < n; ++i)
        {
            for (int j = 0; j < n; ++j)
            {
                if (i != j)
                {
                    int dif = abs(scoreList[i] - scoreList[j]);
                    if (dif < min)
                    {
                        min = dif;
                    }
                }
            }
        }

        ans.push_back(min);
    }

    for (int i = 0; i < ans.size(); ++i)
    {
        cout << ans[i] << endl;
    }
}



Measured memory_bytes: 3160
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import numpy as np
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

N,K = I()
A = l()

def ok(n):
    t = 0
    for a in A:
        if a <= n:
            continue
        t += math.ceil(a/n)-1
    return t <= K

upper = 1000000000
lower = 0
while abs(lower-upper) > 1:
    m = (upper+lower)//2
    if ok(m):
        upper = m
    else:
        lower = m
print(math.ceil(upper))

Measured memory_bytes: 49472
x = int(input())
l1 = [1]
l2 = list(2**i for i in range(2,11))
l3 = list(3**i for i in range(2,7))
l4 = list(4**i for i in range(2,6))
l5 = list(5**i for i in range(2,5))
l6 = list(6**i for i in range(2,5))
l7 = list(7**i for i in range(2,5))
l8 = list(8**i for i in range(2,5))
l9 = list(9**i for i in range(2,5))
l10 =list(10**i for i in range(2,4))
l11 = list(i**2 for i in range(11,34))
l1 = list(set(l1+l2+l3+l4+l5+l6+l7+l8+l9+l10+l11))
if x in l1:
  print(x)
else:
  l1.append(x)
  l1.sort()
  a = l1.index(x)-1
  print(l1[a])

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

int main(){
  
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  int count = 0;
  
  for(int i=0; i<=A; i++){
    for(int j=0; j<=B; j++){
      for(int k=0; k<=C; k++){
        if(X == (i*500 + j*100 + k*50)){
          count++;
        }
      }
    }
  }
  cout << count << endl;
  
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int n;
  cin >> n;
  vector<int> l(n);
  REP(i, n) cin >> l[i];
  sort(ALL(l));
  int ans = 0;
  for (int i = n - 1; i >= 0; --i) {
    for (int j = i - 1; j >= 0; --j) {
      int a = l[i], b = l[j];
      int ok = j, ng = -1;
      while (1 < abs(ok - ng)) {
        int mid = (ok + ng) / 2;
        int c = l[mid];
        if (abs(a - b) < c) {
          ok = mid;
        } else {
          ng = mid;
        }
      }
      ans += j - ok;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
N = gets.to_i
ary = gets.split.map(&:to_i)
def choose2(n)
  (n * (n - 1)) / 2
end

cnt = Hash.new(0)
ary.map do |a|
  cnt[a] += 1
end

total = 0
cnt.map do |k, v|
  total += choose2(v)
end

ary.map do |a|
  puts total - choose2(cnt[a]) + choose2(cnt[a] - 1)
end

Measured memory_bytes: 31336
using System;
using System.Linq;
namespace aaaaaaaaaaaa
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            var a = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var mae = 0;
            var fumidai = 0l;
            for (int i = 0; i < a.Length; i++)
            {
                if (a[i] < mae)
                {
                    fumidai += mae - a[i];
                }
                if (mae < a[i])
                {
                    mae = a[i];
                }
            }
            Console.WriteLine(fumidai);
        }
    }
}

Measured memory_bytes: 46708
m,d = map(int,input().split())

ans = 0
if(d > 21):
    for i in range(1,m+1):
        for j in range(22,d+1):
            d1 = int(str(j)[1])
            d10 = int(str(j)[0])
            if(d1 > 1):
                if (d1 * d10 == i):
                    ans+=1
                        
print(ans)
                

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    string b = "Bad";
    string g = "Good";
    string s;
    cin >> s;
    char h;
    for(int i = 0; i < 3; i++){
        h = s.at(i);
        if(h == s.at(i + 1)){
            cout << b << endl;
            return 0;
        }
    }
    cout << g << endl;
    return 0;
}

Measured memory_bytes: 256
open Batteries
let n, k = Scanf.sscanf (read_line()) "%d %d" (fun n k -> n,k)
let dp = Array.init n @@ fun a -> 0
let rec loop i =
  if i >= k then () else
  (
    let _ = read_int () in
    List.iter (fun b -> dp.(b-1) <- 1 + dp.(b-1)) @@ (read_line () |> String.split_on_char ' ' |> List.map int_of_string);
    loop (i+1)
  )

let _ = loop 0

let _ = Printf.printf "%d\n" @@ List.fold_left (fun a b -> if b != 0 then a else 1 + a) 0 (Array.to_list dp)





Measured memory_bytes: 6128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    ll n,k;
    cin>>n>>k;
    ll a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    ll ans=0;
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            if(a[i]>a[j]) ans++;
        }
    }
    ans=(ans*k)%MOD;
    ll hoge=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(a[i]>a[j]) hoge++;
        }
    }
    ans+=(k*(k-1)/2)%MOD*hoge%MOD;
    cout<<ans%MOD<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#include <iostream>
#include <list>
#include <cmath>
#include <queue>
using namespace std;
#define fo(i, n) for (ll i = 0; i < n; ++i)
#define ll long long
void sor(vector<ll> &x)
{
    sort(x.begin(), x.end());
}

void rev(vector<ll> &x)
{
    reverse(x.begin(), x.end());
}

ll gcd(ll x, ll y)
{
    if (y == 0)
    {
        return x;
    }
    return gcd(y, x % y);
}

list<ll> a[5];
void bfs(int src)
{
    queue<int> q;
    bool *vis = new bool[5 + 1]{0};
    q.push(src);
    vis[src] = true;
    while (!q.empty())
    {
        int node = q.front();
        cout << node << " ";
        q.pop();
        for (int n : a[node])
        {
            if (!vis[n])
            {
                q.push(n);
                vis[n] = true;
            }
        }
    }
}

ll max(ll x, ll y)
{
    if (x > y)
    {
        return x;
    }
    else
    {
        return y;
    }
}

ll min(ll x, ll y)
{
    if (x > y)
    {
        return y;
    }
    else
    {
        return x;
    }
}

void primeFactors(ll n, vector<ll> &vec)
{

    while (n % 2 == 0)
    {
        vec.push_back(2);
        n = n / 2;
    }

    for (ll i = 3; i <= sqrt(n); i = i + 2)
    {
        while (n % i == 0)
        {
            vec.push_back(i);
            n = n / i;
        }
    }

    if (n > 2)
        vec.push_back(n);
}

ll lcm(ll x, ll y)
{
    return x * y / gcd(x, y);
}

ll g(ll x)
{
    for (ll i = 2; i <= sqrt(x); i++)
    {
        if (x % i == 0)
        {
            return i;
        }
    }
    return 0;
}

ll countDivisors(ll n)
{
    ll cnt = 0;
    for (ll i = 1; i <= sqrt(n); i++)
    {
        if (n % i == 0)
        {
            if (n / i == i)
                cnt++;

            else
                cnt = cnt + 2;
        }
    }
    return cnt;
}

void solve()
{
    ll n;
    cin >> n;
    ll x = 0;
    vector<ll> a;
    fo(i, n)
    {
        ll q, w;
        cin >> q >> w;
        if (q == w)
        {
            x++;
        }
        else
        {
            a.push_back(x);
            x = 0;
        }
    }
    int f = 0;
    a.push_back(x);
    fo(i, a.size())
    {
        if (a[i] >= 3)
        {
            f = 1;
            break;
        }
    }
    if (f == 1)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
}

int main()
{

    int t;
    t = 1;
    while (t--)
    {
        solve();
    }
    return 0;
}

//0 3 1 0 5 2 6
//0 0 1 2 3 5 6

Measured memory_bytes: 3688
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		char[] s = in.next().toCharArray(), q = in.next().toCharArray();
		int c = 0;

		for(int i = 0; i < 3; i++)
			if(s[i] == q[i])
				c++;

		System.out.println(c);
		return;
	}
}


Measured memory_bytes: 23764
import java.util.*;
import java.math.*;
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		long[] ar = new long[n];
		for(int i = 0; i < n; i++) {
			ar[i] = in.nextLong();
		}
		Arrays.sort(ar);
		long ans = ar[n - 1];
		int newn = n - 2;
		int i = n - 2;
		while(newn > 0) {
			if((newn - 2) >= 0) {
				newn -= 2;
				ans += ar[i] * 2;
			}else {
				newn -= 1;
				ans += ar[i];
			}
			i -= 1;
		}
		System.out.println(ans);
	}
}

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

#define ll long long int
#define endl '\n'

void testCase()
{
    //ll t; cin>>t; while(t--)
    {
        ll x;
        cin>>x;
        if(x==0)
        cout<<1;
        else
        cout<<0;
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    testCase();
    return 0;
}

Measured memory_bytes: 3636
N,k=gets.split.map &:to_i
s=[0]*(10**5+1)
N.times do
  a,b=gets.split.map &:to_i
  s[a]+=b
end
s.size.times do |i|
  k-=s[i]
  next if 0<k
  p i
  break
end


Measured memory_bytes: 2684