akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define int                 long long
#define FF(i,a,b)           for(int i=a;i<b;i++)
#define BF(i,a,b)           for(int i=a;i>=b;i--)
#define vi                  vector<int>
#define MAP                 map<int,int>
#define pb                  push_back
#define MP                  make_pair
#define F                   first
#define S                   second
#define pi                  pair<int,int>
#define all(v)              v.begin(),v.end()
#define PIE                 3.1415926535897932384626433832795
#define FastIO              ios::sync_with_stdio(0); cin.tie(0);cout.tie(0)
//#define ordered_set         tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
/*

    order_of_key (k) : Number of items strictly smaller than k .
    find_by_order(k) : K-th element in a set (counting from zero).

*/
/**************************************************************************************/
                       /*Global Variables*/
const int mod = 1e9+7;
const int N = 2e5+10;
const int inf = 3e18;

/**************************************************************************************/
template <typename A>istream& operator>>(istream& input,vector<A>& x) {for(auto& i:x)input>>i;return input;}
template<typename A>ostream& operator<<(ostream& output,vector<A>& x) {for(auto& i:x)output<<i<<' ';return output;}
int add(int a, int b){return (a%mod + b%mod + mod)%mod;}
int sub(int a, int b){return (a%mod - b%mod + mod)%mod;}
int mul(int a, int b){return ((a%mod)*(b%mod) + mod)%mod;}
int Power(int a,int b)
{
    int res=1;
    while(b)
    {
        if(b&1)res*=a;
        a*=a;
        b>>=1;
    }
    return res;
}
signed main()
{
    FastIO;
    int T=1;
    //cin>>T;
    while(T--)
    {
        vi a(5);
        cin>>a;
        for(int i=0;i<5;i++)
        {
            if(a[i]==0)
            {
                cout<<i+1<<"\n";
                break;
            }
        }
    }

}
/*
|| Do what you can with all you have,wherever you are. ||

|| Knowing is not enough, we must apply. Wishing is not enough, we must do. ||

|| A goal is a dream with deadline. ||

|| Whether you think you can or you think you can't, you're right. ||

|| A year from now you may wish you had started today ||
*/



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

int main(){
 while(1){
   int m,f,r;
   cin>>m>>f>>r;
   if(m == -1 && f == -1 && r == -1) break;
   string ans;
   if(m == -1|| f == -1) ans = "F";
   else if(m + f >= 80) ans = "A";
   else if(m + f >= 65) ans = "B";
   else if(m + f >= 50) ans = "C";
   else if(m + f >= 30){
	if(r >= 50) ans = "C";
	else ans = "D" ;
   }
   else ans = "F";
   cout<<ans<<endl;
   }
}


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

using namespace std;

int dim[105], a, b;
int main(){

    while(true){
	fill(dim, dim + 105, 0);
	while(true){
	    if(cin >> a >> b);
	    else return 0;

	    if(a == 0 && b == 0)break;
	    dim[a]++;dim[b]++;	    
	}
	int ok = true;
	if(dim[1] % 2 == 0)ok = false;
	if(dim[2] % 2 == 0)ok = false;
	for(int i = 3;i < 105;i++){
	    if(dim[i] % 2 == 1)ok = false;
	}
	if(ok)cout << "OK"<<endl;
	else cout <<"NG"<<endl;
    }
    return 0;
}

Measured memory_bytes: 1152
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;

int W,H;

bool sima[52][52];
bool checkmap[52][52];

int dx[9]={-1,0,1,-1,0,1,-1,0,1};
int dy[9]={-1,-1,-1,0,0,0,1,1,1};


int saiki(int x, int y) 
{
	if(sima[x][y]==1){sima[x][y]=0;}
	else if(sima[x][y]==0){return 0;}

	rep(i,9){
		saiki(x+dx[i], y+dy[i]);
	}

	return 1;
}

int main() {

	while(cin >> W >> H) {
		int count=0;
		if (W == 0 && H == 0) { break; }

		rep(h,H) {
			rep(w,W) {
				sima[w][h] = 0;
				checkmap[w][h] = 0;
			}
		}

		rep(h,H) {
			rep(w,W) {
				cin >> sima[w+1][h+1];
			}
		}

		REP(h,1,H+1){
			REP(w,1,W+1){
				if(sima[w][h]==1){
					saiki(w,h);
					//cout << w << ":" << h << endl; 
					count++;	
				}
			}
		}
/*
	cout << "map" << endl; 

		rep(h,51){
			rep(w,51){
				cout << sima[w][h] << " ";
			}
			cout << endl;
		}


	
	cout << "checkmap" << endl; 

		rep(h,51){
			rep(w,51){
				cout << checkmap[w][h] << " ";
			}
			cout << endl;
		}
*/

		cout << count << endl;
	}

	return 0;
}

Measured memory_bytes: 1236
// D - Lunlun Number
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int k = 0, K; cin>>K; //候補の個数
	queue<ll> q;
	rp(i, 1, 10) q.push(i); //最上位桁かつ候補の初期値
	while(q.size()){
		ll n = q.front(); q.pop(); //候補を取り出す
		if(++k >= K){ //候補が K 番目なら解
			cout<< n <<endl;
			return 0;
		}
		//m = n%10 + {-1,0,+1}: 登録した候補の第一位に差分を加算して次の第一位へ
		rp(m, n%10-1, n%10+2) if(0<=m && m<=9) q.push(n*10+m); //第一位が [0,9] の範囲内なら末尾に追加
	}
}

Measured memory_bytes: 1792
n,m,x,y = map(int,input().split())
xi = [int(i) for i in input().split()]
yi = [int(i) for i in input().split()]

xi.append(x)
yi.append(y)

ans = 0
for i in range(-100,100):
    check = 0
    for j in xi:
        if i <= j:
            check = 1
    for k in yi:
        if i > k:
            check = 1
    if check == 0:
        ans = 1
        break
if ans == 1:
    print('No War')
else:
    print('War')
    



Measured memory_bytes: 3064
#include<iostream>
#include<vector>

using namespace std;

int main(){
	int N;
  	cin>>N;
  	vector<unsigned long long> vec(N);
  	for(int i=0; i<N; i++) cin>>vec[i];
  	if(N==1){
      cout<<"Yes"<<endl;
      return 0;
      
    }
  	for(int i=N-2; i>=0; i--){
      //cout<<vec[i]<<" "<<vec[i+1]<<endl;
      if(vec[i] > vec[i+1]){
        if(vec[i]-vec[i+1]>1){
          cout<<"No"<<endl;
          return 0;
        }else{
          vec[i]--;
        }
      }
    }
  	cout<<"Yes"<<endl;
  	return 0;
}
		
      

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
using namespace std;

int main() {
	int d;
	while (cin >> d) {
		int ans = 0;
		for (int i = 0; i < 600/d; i++) {
			ans += i*d*i*d*d;
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3088
#include<stdio.h>
int main()
{
  char a[256][11];
  char b[256][11];
  int wla[256];
  int wlb[256];
  int n,m;
  int i,j,k,l;
  int open=0;
  int clear;
  
  scanf("%d\n",&n);
  for(i=0;i<n;i++)
    {
      for(j=0;;j++)
	{
	  scanf("%c",&a[i][j]);
	  if(a[i][j]=='\n')
	    {
	      wla[i]=j;
	      break;
	    }
	}
    }
  scanf("%d\n",&m);
  for(i=0;i<m;i++)
    {
      for(j=0;;j++)
	{
	  scanf("%c",&b[i][j]);
	  if(b[i][j]=='\n')
	    {
	      wlb[i]=j;
	      break;
	    }
	}
      clear=0;
      for(k=0;k<n;k++)
	{
	  if(wla[k]==wlb[i])
	    {
	      for(j=0;j<wla[k];j++)
		{
		  if(a[k][j]!=b[i][j]) break;
		}
	      if(j==wla[k])
		{
		  open=(open+1)%2;
		  if(open==0) printf("Closed by ");
		  else printf("Opened by ");
		  for(j=0;j<wlb[i];j++) printf("%c",b[i][j]);
		  printf("\n");
		  clear=1;
		}
	    }
	  if(clear>0) break;
	}
      if(clear==0)
	{
	  printf("Unknown ");
	  for(j=0;j<wlb[i];j++) printf("%c",b[i][j]);
	  printf("\n");
	}
    }
  return 0;
}

Measured memory_bytes: 592
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

using ll = long long;
using ull = unsigned long long;


int main()
{
    long double a, b, c;
    cin >> a >> b >> c;
    // sqrt(a) + sqrt(b) < sqrt(c)
    // a + 2*sqrt(a*b) + b < c
    if (a + 2*sqrtl(a*b) + b < c) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
const ll INF = 1LL << 60;

int main(){
	string s; cin >> s;
	rep(i, s.size()){
		if(s[i] == ',') cout << " ";
		else cout << s[i];
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  int Y[101]={0};
  int M[101]={0};
  int D[101]={0};
  cin>>n;
  for(int i=1;i<=n;i++)
  {
    cin>>Y[i]>>M[i]>>D[i];
  }
  int premium=0;
  for(int i=1;i<=999;i++)
  {
    if(i%3!=0)
  {
    premium=premium+19*5+20*5;
  }else{
    premium=premium+20*10;
  }
  }
  premium++;
  int date[101]={0};
  for(int i=1;i<=n;i++)
  {
    for(int k=1;k<=Y[i]-1;k++)
    {
      if(k%3!=0)
      {
        date[i]=date[i]+19*5+20*5;
      }else{
        date[i]=date[i]+20*10;
      }
    }
    if(Y[i]%3!=0)
    {
      for(int l=1;l<=M[i]-1;l++)
      {
        if(l%2!=1)
        {
          date[i]=date[i]+19;
        }else{
          date[i]=date[i]+20;
        }
      }
    }else{
      for(int l=1;l<=M[i]-1;l++)
      {
        date[i]=date[i]+20;
      }
    }
    date[i]=date[i]+(D[i]);
  }
  for(int i=1;i<=n;i++)
  {
    cout<<premium-date[i]<<endl;
  }
  return 0;
}



Measured memory_bytes: 3084
#include <iostream>
#include <vector>

int main() {
    std::vector<int> input;
    while (true) {
        int tmp;
        std::cin >> tmp;
        if (tmp == 0)
            break;
        else
            input.push_back(tmp);
    }
    for (int i=0; i<input.size(); ++i)
        std::cout << "Case " << i+1 << ": " << input[i] << std::endl;
    return 0;
}


Measured memory_bytes: 3244
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

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

    vector<string> hantei = {"dream", "dreamer", "erase", "eraser"};

    reverse(S.begin(), S.end());

    for (int i = 0; i < 4; i++)
    {
        reverse(hantei.at(i).begin(), hantei.at(i).end());
        //cout << hantei.at(i) << endl;
    }

    bool ans = true;
    string str;
    string match;
    
    for (int i = 0; i < S.size()-1; )
    {
        str =  S.substr(i, 3);
        for (int j = 0; j < 4; j++)
        {
            if (str == hantei.at(j).substr(0, 3))
            {
                match = hantei.at(j);
                goto matchok;
            }
        }
        ans = false;
        goto LAST;
matchok:
        for (int j = 0; j < match.size(); i++, j++)
        {
            if (S.at(i) != match.at(j))
            {
                ans = false;
                goto LAST;
            }

            // cout << S.at(i) << " " << match.at(j) << " " << endl;
            
        }
        
    }

LAST:
    if (ans == true)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
    
    

}


Measured memory_bytes: 512
import java.util.*;
import java.awt.geom.*;

public class Main{
	double EPS = 1.0e-08;
	class C implements Comparable<C>{
		double distance;
		int pos;
		public C(double distance, int pos) {
			this.distance = distance;
			this.pos = pos;
		}
		@Override
		public int compareTo(C o) {
			if(this.distance < o.distance) return -1;
			if(this.distance > o.distance) return 1;
			return 0;
		}
		
	}
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		int dataset = sc.nextInt();
		while(dataset-- > 0){
			int xa = sc.nextInt();
			int ya = sc.nextInt();
			int xb = sc.nextInt();
			int yb = sc.nextInt();
			Line2D newline = new Line2D.Double(new Point2D.Double(xa, ya), new Point2D.Double(xb, yb));
			int n = sc.nextInt();
			Line2D [] llist = new Line2D[n];
			int [] posdata = new int[n];
			for(int i = 0; i < n; i++){
				int xs = sc.nextInt();
				int ys = sc.nextInt();
				int xt = sc.nextInt();
				int yt = sc.nextInt();
				llist[i] = new Line2D.Double(new Point2D.Double(xs, ys), new Point2D.Double(xt, yt));
				int o = sc.nextInt();
				int pos = sc.nextInt();
				posdata[i] = (o == 0 ? pos ^ 1 : pos);
			}
			ArrayList<C> intersect = new ArrayList<Main.C>();
			for(int i = 0; i < n; i++){
				if(newline.intersectsLine(llist[i])){
					Point2D intersectP = intersectPtSS(newline, llist[i]);
					double dis = intersectP.distance(newline.getP1());
					intersect.add(new C(dis, posdata[i]));
				}
			}
			if(intersect.size() == 0){
				System.out.println(0);
				continue;
			}
			Collections.sort(intersect);
			int prev = intersect.get(0).pos;
			int count = 0;
			for(int i = 1; i < intersect.size(); i++){
				if(prev != intersect.get(i).pos){
					count++;
					prev = intersect.get(i).pos;
				}
			}
			System.out.println(count);
		}
	}
	
	private Point2D intersectPtSS(Line2D l, Line2D m){
		Point2D lVec = sub(l.getP2(), l.getP1());
		Point2D mVec = sub(m.getP2(), m.getP1());
		Point2D m1l1Vec = sub(m.getP1(), l.getP1());
		double a = cross(m1l1Vec, lVec);
		double b = cross(lVec, mVec);
		if(Math.abs(a) < EPS && Math.abs(b) < EPS){
			return null;
		}
		double t = a / b;
		double resx = m.getX1() + t * mVec.getX();
		double resy = m.getY1() + t * mVec.getY();
		return new Point2D.Double(resx, resy);
	}

	private double cross(Point2D p1, Point2D p2) {
		double res = p1.getX() * p2.getY() - p1.getY() * p2.getX();
		return res;
	}

	private Point2D sub(Point2D p2, Point2D p1) {
		return new Point2D.Double(p2.getX() - p1.getX(), p2.getY() - p1.getY());
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().doit();
	}
}

Measured memory_bytes: 120024
#include <iostream>
#include <algorithm>
#include <array>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <tuple>
#include <queue>
#include <vector>
#include <cmath>
#include <random>
#include <math.h>
#include <random>



#define REP(i, n) for(int (i) = 0; (i) < (n); ++(i))
#define rREP(i, n) for(int (i) = (n) - 1; (i) >= 0; --(i))
#define ALL(TheArray) TheArray.begin(), TheArray.end()

using lli = long long int;
using pii = std::pair<int, 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;
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



int inf = 2e9;

using coordinate = std::pair<int, int>;
using myDatum = std::pair<coordinate, int>;
std::vector<myDatum> Vertices;

std::vector<std::vector<std::pair<int, int>>> E;


int main(void){
    int n; scanf("%d", &n);
    Vertices.resize(n);
    REP(i, n){
        auto& ptr = Vertices[i].first;
        scanf("%d%d", &ptr.first, &ptr.second);
        Vertices[i].second = i;
    }
    E.resize(n);

    std::sort(Vertices.begin(), Vertices.end());
    for(int x = 1; x < n; x++){
        int x0, x1, v0, v1;
        x0 = Vertices[x-1].first.first;
        x1 = Vertices[x].first.first;
        int cost = x1 - x0;
        v0 = Vertices[x-1].second;
        v1 = Vertices[x].second;
        E[v0].push_back({cost, v1});
        E[v1].push_back({cost, v0});
    }
    std::sort(Vertices.begin(), Vertices.end(), [](myDatum& a, myDatum& b){
        if(a.first.second != b.first.second) return a.first.second < b.first.second;
        if(a.first.first != b.first.first) return a.first.first < b.first.first;
        return a.second < b.second;
    });
    for(int y = 1; y < n; y++){
        int y0, y1, v0, v1;
        y0 = Vertices[y-1].first.second;
        y1 = Vertices[y].first.second;
        int cost = y1 - y0;
        v0 = Vertices[y-1].second;
        v1 = Vertices[y].second;
        E[v0].push_back({cost, v1});
        E[v1].push_back({cost, v0});
    }


    // Prim
    lli ans = 0;
    std::vector<bool> Yet(n, true);
    std::priority_queue<pii, std::vector<pii>, std::greater<pii>> pQ;
    Yet[0] = false; for(pii& nv : E[0]) pQ.push(nv);
    while(not pQ.empty()){
        pii h = pQ.top(); pQ.pop();
        if(not Yet[h.second]) continue;
        Yet[h.second] = false;
        ans += h.first;
        for(pii& nv : E[h.second]){
            if(Yet[nv.second]){
                pQ.push(nv);
            }
        }
    }
    printf("%lld\n", ans);





    return 0;
}

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

#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;

int h[maxn];

int main() {
    int n, res = 0;
    scanf("%d", &n);
    for (int i = 1, f; i <= n; i++) {
        scanf("%d", &h[i]);
        f = 1;
        for (int j = 1; j < i; j++) if (h[j] > h[i]) {
            f = 0;
            break;
        }
        if (f) res++;
    }
    printf("%d\n", res);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n,m=inf;
string s;

int main(){
	cin>>s;
	n=s.size();
	for(int i=0;i<n-2;i++){
		string t=s.substr(i,3);
		m=min(m,abs(753-atoi(t.c_str())));
	}
	cout<<m<<endl;
}

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


int main(){
    int x;
    cin >> x;
    if(x==1){
        cout << 0<<endl;
    }if(x==0){
        cout << 1<<endl;
    }
    return 0;
}

Measured memory_bytes: 3632
//59
#include<iostream>
#include<cmath>

using namespace std;

int main(){
  for(double a,l,x;cin>>a>>l>>x;){
    double s=l+x/2;
    cout<<fixed<<sqrt((l+a/2)*a/2*a/2*(l-a/2))+2*sqrt(s*(s-l/2-x/2)*(s-l/2-x/2)*x/2)<<endl;
  }
  return 0;
}

Measured memory_bytes: 1280
N = int(input())
XY = []
for i in range(N):
    XY.append([])
    A = int(input())
    for a in range(A):
        x, y = map(int, input().split())
        XY[i].append([x, y])

answer = 0
for p in range(0, 2**N):
    ok = True
    h = 0
    for i in range(N):
        if p & (1 << i):
            h += 1
            for x, y in XY[i]:
                x -= 1
                if y == 0: # unkind
                    if p & (1 << x):
                        ok = False
                if y == 1: # x is honest
                    if not p & (1 << x):
                        ok = False
    if ok:
        answer = max(answer, h)
print(answer)


Measured memory_bytes: 3188
#include<iostream>
#include<vector>
#include<queue>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
  int x,b,a;
  cin >> x >>a >>b;

  if (b-a<=0){
   cout <<"delicious"; 
  }else if (b-a <= x){
    cout <<"safe"; 
  }else{
	cout <<"dangerous"; 
  }
  

    return 0;
}






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

using namespace std;

#define LL long long
#define DD double
#define Pb push_back
#define Bp pop_back
#define Pf push_front
#define Fp pop_front
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define X first
#define Y second
#define mx1 10
#define mx2 110
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

typedef vector<LL> Vl;
typedef vector<DD> Vd;
typedef vector<bool> Vb;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef pair<DD, DD> Pdd;
typedef vector<Pll> Vpl;
typedef vector<Pdd> Vpd;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
typedef deque<LL> Dl;

LL _set(LL N, LL pos) {return N = N | (1 << pos);}
LL _reset(LL N, LL pos) {return N = N & ~(1 << pos);}
bool _check(LL N, LL pos) {return (bool)(N & (1 << pos));}
bool _upper(char a) {return a >= 'A' && a <= 'Z';}
bool _lower(char a) {return a >= 'a' && a <= 'z';}
bool _digit(char a) {return a >= '0' && a <= '9';}

LL dx[] = {1, -1, 0, 0, -1, -1, 1, 1};
LL dy[] = {0, 0, 1, -1, -1, 1, -1, 1};

///**************************DONE****************************///

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

    map<char, int> mp;
    for(int i = 0; i < n; i++){
        string s;
        cin >> s;

        if(s[0] == 'M')
            mp['M']++;
        if(s[0] == 'A')
            mp['A']++;
        if(s[0] == 'R')
            mp['R']++;
        if(s[0] == 'C')
            mp['C']++;
        if(s[0] == 'H')
            mp['H']++;
    }

    vector<int> v;
    if(mp.size() < 3)
        return cout << 0 << '\n', 0;

    for(auto i: mp)
        v.Pb(i.Y);

    LL ans = 0, L = v.size();
    for(int i = 0; i < L; i++){
        for(int j = i + 1; j < L; j++){
            for(int k = j + 1; k < L; k++)
                ans += 1ll * v[i] * v[j] * v[k];
        }
    }

    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3580
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<math.h>

#define REPS(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const int mod = 1e9 + 7;
const long double pi = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;

int main() {
	int N, K;
	int g;
	cin >> N >> K;

	// N <= K + (K-1)(g-1)
	g = ceil((double)(N - K) / (K - 1) + 1);

	cout << g;
	system("pause");
	return 0;
}

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

inline int pow2(int x){
	return ( 1 << x );
}

int main(){
	int n;
	int dp[100000];

	while( cin >> n , n ){
		//ツ渉可甘コツ可サ
		int t[20][20] = {0};
		for(int i=0 ; i < pow2(n) ; i++ ){
			dp[i] = (1<<30)-1;
		}
		
		for(int j=0 ; j < n ; j++ ){
			for(int i=0 ; i < n+1 ; i++ ){
				cin >> t[j][i];
			}
		}
		dp[0] = 0;
		for(int T=0 ; T < pow2(n) ; T++ ){
			for(int j=0 ; j < n ; j++ ){
				for(int i=0 ; i < n ; i++ ){
					//ツスツテツーツジjツづーツクツδ環アツつオツづつ「ツづ按つゥツづつスツづァ
					if( !( T & pow2(j) ) ){
						if( T & pow2(i) ){
							dp[T+pow2(j)] = min( dp[T+pow2(j)] , dp[T]+ t[j][i+1] );
						}else{
							dp[T+pow2(j)] = min( dp[T+pow2(j)] , dp[T]+ t[j][0] );
						}
					}
				}
			}
		}
		cout << dp[ pow2(n)-1 ] << endl;
	}
}

Measured memory_bytes: 1128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char a = sc.next().charAt(0);
		char b = sc.next().charAt(0);
		if(a == 'H' && b == 'H'
				||
				a == 'D' && b == 'D') {
			System.out.println('H');
		} else {
			System.out.println('D');
		}

	}

}


Measured memory_bytes: 22868
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <queue>

typedef long long ll;
const ll LL_MAX (1LL<<60);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

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

    ll n, k;
    ll r, s, p;
    cin >> n >> k;
    cin >> r >> s >> p;

    string t;
    cin >> t;

    ll score(0);

    rep(i,0,t.size())
    {
        if (0<=i-k && t[i] == t[i-k])      
        {
            t[i] = '-';
            continue;
        }

        ll pnt(0);
        if (t[i]=='r') pnt=p;
        else if (t[i]=='s') pnt=r;
        else pnt=s;
    
        score += pnt;
    
        //cout << t[i-k] << ' ' << score << endl;
    }

    cout << score << endl;

    return 0;
}


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

typedef long long ll;

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main()
{
    ll N;
    ll K;
    cin >> N; 
    cin >> K;

    vector<ll> P(N);
    vector<ll> S(N);

    for(ll i=0; i<N; i++){
        cin >> P[i];
        S[i] = P[i] + 1;
    }

    ll max_ans = 0;
    ll start = 0;
    for(ll i=0; i<K; i++){
        max_ans += S[i];
        start += S[i];
    }
    for(ll i=0; i< N-K; i++){
        max_ans = max(max_ans, start + (S[K+i] - S[i]));
        start = start + (S[K+i] - S[i]);
    }
    double ans;
    ans = max_ans / 2.0;

    cout.precision(15);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3328
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<algorithm>
#include<set>
#include <stdexcept>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
typedef long long ll;
int ceil(int a,int b){// a以上でｂの倍数の最小値を出力//
    return (a+b-1)/b*b;
}
int stoii(string s){//stoi関数の代用 文字列を数値として読み取りint型に変換//
    return atoi(s.c_str());
}
int main (){
    int a,b;
    cin>>a>>b;
    int cnt=0;
    FOR(i,a,b+1){
        string s,t;
        s=to_string(i);
        t=to_string(i);
        reverse(s.begin(),s.end());
        if(s==t) cnt++;
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

int N,M;
vector<int> A;

ll imos[200020];

int main(){
  cin>>N>>M;
  A.resize(N);
  rep(i,N) cin>>A[i];

  ll sum=0;
  for(int i=1;i<N;i++){
      if(A[i-1]<A[i]) sum+=A[i]-A[i-1];
      else sum+=(M-A[i-1])+A[i];

      if(A[i-1]+1==A[i]) continue;

      int tar=A[i];
      if(A[i-1]>A[i]) tar+=M;

      imos[A[i-1]+2]--;
      imos[tar+1]+=(tar-(A[i-1]));
      imos[tar+2]-=(tar-(A[i-1])-1);
  }

  for(int i=1;i<=2*M;i++) imos[i]+=imos[i-1];
  for(int i=1;i<=2*M;i++) imos[i]+=imos[i-1];

  ll ans=sum;
  for(int i=1;i<=M;i++){
      ans=min(ans,sum+(imos[i]+imos[i+M]));
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 2176
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;

int main()
{
    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> students(N);
    for (int i = 0; i < N; ++i)
    {
        int x, y;
        cin >> x >> y;
        students[i] = { x, y };
    }
    vector<pair<int, int>> checkpoints(M);
    for (int i = 0; i < M; ++i)
    {
        int x, y;
        cin >> x >> y;
        checkpoints[i] = { x, y };
    }
    for (const auto &student : students)
    {
        int nearest = -1;
        int minDist = 1000000000;
        for (int ID = 1; ID <= M; ++ID)
        {
            const auto checkPoint = checkpoints[ID - 1];
            const int dist = abs(checkPoint.first - student.first)
                + abs(checkPoint.second - student.second);
            if (dist < minDist)
            {
                minDist = dist;
                nearest = ID;
            }
        }
        cout << nearest << endl;
    }


    return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> h(n);
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
    }
    int highest = 0;
    int ans = 0;
    for (int j = 0; j < n; ++j) {
        if (h[j] >= highest) ans++;
        highest = max(highest, h[j]);
    }
    cout << ans << endl;
}


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

string f(int x, int y) {
    return to_string(x) + " " + to_string(y);
}

int main() {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int a = x2-x1, b = y2-y1;
    cout << f(x2-b, y2+a) << ' ' << f(x1-b, y1+a) << endl;
}


Measured memory_bytes: 256
function Main(input) {
  const tmp = input.trim().split('\n')
  const L = tmp[1].split(' ').map(s => parseInt(s))
  const max = Math.max(...L)

  var rest = []
  var flg = false
  L.forEach(n => {
    if ( n === max && !flg) {
      flg = true
      return
    }
    rest.push(n)
  })

  const total = rest.reduce((prev, current) => prev += current)

  if (total > max) console.log('Yes')
  else console.log('No')
  
}

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

Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;


int main(){
    int A[3];
    cin >> A[0] >> A[1] >> A[2];
    sort(A,A+3);
    if( A[0] == 5 and A[1] == 5 and A[2] == 7) cout << "YES" << endl;
    else cout << "NO" << endl;

}

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

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vector<int> > Mat;
typedef tuple<int, int, int, int> T;

const int MOD = (int)1e9+7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

int main(){
    int A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;

    int water=0, suger=0, waterans=0, sugerans=0;
    double res = -1.0;
    for(int i = 0; 100*A*i <= F; i++){
        
        for(int j = 0; 100*B*j <= F; j++){

            for(int x = 0; C*x <= F; x++){
                
                for(int y = 0; D*y <= F; y++){
                    water = 100*A*i + 100*B*j;
                    suger = C*x + D*y;

                    if(F < water + suger) break;
                    if(water/100*E < suger) break;
                    double tmp = max(res, (double)(100*suger)/(water+suger) );
                    if(res < tmp){
                        waterans = water+suger;
                        sugerans = suger;
                        res = tmp;
                    }
                }
            }

        }
    }

    cout << waterans << " " << sugerans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 10;
char s[maxn][maxn];
int l[maxn];
int n, m;
void no() { puts("Impossible"); exit(0);}
int main()
{
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; ++i) scanf("%s", s[i] + 1);
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= n; ++j)
			if(s[i][j] == '#')
			{
				l[i] = j; 
				break;
			}
	l[n + 1] = n;
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= n; ++j)
		{
			if(l[i] <= j && j <= l[i + 1] && s[i][j] == '.')
				no();
			if(j > l[i + 1] && s[i][j] == '#')
				no();
		}
	puts("Possible");
	return 0;
}
	

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

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

Measured memory_bytes: 256
// a colorful transceivers
#include <stdio.h>
#include <stdlib.h>

int main(void){
    int a, b, c, d;
    scanf("%d %d %d %d", &a, &b, &c, &d);

    if(abs(a - c) <= d){
        printf("Yes\n");
    }else{
        printf("%s\n", (abs(a - b) <= d && abs(b - c) <= d)? "Yes" : "No");
    }
    return 0;
}

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

int main() {

int A,B,C,K; cin >>A>>B>>C>>K;

int sum = 0;

if (K<=A) sum=K;
else if (A<K && K<=A+B) sum=A;
else sum=A+(-1)*(K-A-B);

cout << sum << endl;

}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <unordered_map>
#include <deque>
#include <list>
#include <set>
#include <random>
#include <deque>
#include <unordered_set>

using namespace std;
using ll = long long;
const int BIG = 100000007;


int main() {
    ll x,k,d;
    cin >> x >> k >> d;
    x = abs(x);
    ll o = x / d;
    if(k <= o + 1){
        cout << abs(x - k * d) << endl;
    }
    else{
        ll oo = k - (o + 1);
        if(oo % 2 == 0){
            cout << abs(x - (o + 1) * d) << endl;
        }
        else{
            cout << abs(x - o * d) << endl;
        }
    }
}




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

using namespace std;

struct pattern{
    int x, y, z;
};

long prod(pattern pat, long x, long y, long z){
    return pat.x*x+pat.y*y+pat.z*z;
}

int main(){
    int N, M;
    long del[8][1000];
    long cand[8] = {0};
    long ans = 0;
    pattern pat[8];
    pat[0] = (pattern){1, 1, 1};
    pat[1] = (pattern){1, 1, -1};
    pat[2] = (pattern){1, -1, 1};
    pat[3] = (pattern){1, -1, -1};
    pat[4] = (pattern){-1, 1, 1};
    pat[5] = (pattern){-1, 1, -1};
    pat[6] = (pattern){-1, -1, 1};
    pat[7] = (pattern){-1, -1, -1};
    cin >> N >> M;
    for(int i = 0; i < N; i++){
        long x, y, z;
        cin >> x >> y >> z;
        for(int j = 0; j < 8; j++){
            del[j][i] = prod(pat[j], x, y, z);
        }
    }
    for(int j = 0; j < 8; j++){
        sort(del[j], del[j]+N, greater<long>());
        for(int i = 0; i < M; i++){
            cand[j] += del[j][i];
        }
        ans = max(ans, cand[j]);
    }
    cout << ans << endl;
}

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

public class Main {
	static int[] ansbuget;

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt(); scan.nextLine();
		ansbuget = new int[26];
		final int INF = Integer.MAX_VALUE/10;
		Arrays.fill(ansbuget, INF);
		String[] s = new String[n];

		for (int i = 0; i < n; i++) {
			s[i] = scan.nextLine();
			alpha(s[i]);
		}
		
		String t = "";
		for (int i = 0; i < 26; i++) {
			if (ansbuget[i] != 0) {
				for (int j = 0; j < ansbuget[i]; j++) {
					t = t + (char)('a'+ i);
				}
			}
		}
		System.out.println(t);
	}

	public static void alpha(String s) {

		char[] c = new char[s.length()];
		for (int i = 0; i < s.length(); i++) {
			c[i] = s.charAt(i);
		}

		Arrays.sort(c);//ソート
		char A = 'a';//aの文字コード受け取り
		int a = A;
		int[] buget = new int[26];
		for (int i = 0; i < s.length(); i++) {//文字を数値に変換してバゲット法
			buget[c[i] - a]++;//多分ここで各文字からaのコードが引かれて0~25の数になる
		}

		for (int i = 0; i < 26; i++) {
			if (buget[i] < ansbuget[i]) {
				ansbuget[i] = buget[i];
			}
		}
		return;
	}
}



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

int main(){
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(),vec.end());
  map<int,int> mp;
  
  for(int i=0; i<=1; i++){
    for(int j=1; j*j<=vec.at(i); j++){
      if(vec.at(i) %j == 0){
        int x = vec.at(i) / j;
        int y = j;
        if(mp.count(x)){
          mp[x]++;
        }
        else{
          mp[x] = 1;
        }
        if(x != y){
          if(mp.count(y)){
            mp[y]++;
          }
          else{
            mp[y] = 1;
          }
        }
      }
    }
  }
  
  for(int i=2; i<N; i++){
    vector<int> no(0);
    for(auto itr = mp.begin(); itr != mp.end(); itr++){
      int a = itr->first;
      int b = itr->second;
      if(vec.at(i) %a != 0){
        no.push_back(a);
      }
    }
    for(int j=0; j<no.size(); j++){
      mp[no.at(j)]--;
      if(mp[no.at(j)] == 0){
        mp.erase(no.at(j));
      }
    }
  }
  
  int ans = 0;
  for(auto itr = mp.begin(); itr != mp.end(); itr++){    
    int a = itr->first;
      ans = max(ans,a);
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
while True:
    h, w = [int(i) for i in input().split()]
    if h == w == 0:
        break
    else:
        for i in range(h):
            if i % 2 == 0:
                cnt = 0
                while cnt < w:
                    if cnt % 2 == 0:
                        print("#", end = "")
                        cnt += 1
                    else:
                        print(".", end = "")
                        cnt += 1
                print()
            else:
                cnt = 0
                while cnt < w:
                    if cnt % 2 == 0:
                        print(".", end = "")
                        cnt += 1
                    else:
                        print("#", end = "")
                        cnt += 1
                print()
        print()


Measured memory_bytes: 7008
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 40) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T>
bool chmin(T& a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
bool chmax(T& a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for(int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T>
vector<T> make_v(size_t a) {
    return vector<T>(a);
}
template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T& t, const V& v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T& t, const V& v) {
    for(auto& e : t) {
        fill_v(e, v);
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int ans = 0;
    int a = 0, b = 0, c = 0;
    for(int i = 0; i < n; i++) {
        string s;
        cin >> s;
        int m = s.length();
        for(int j = 0; j < m - 1; j++) {
            if(s[j] == 'A' && s[j + 1] == 'B') {
                ans++;
            }
        }
        if(s[0] == 'B' && s[m - 1] == 'A') {
            c++;
        } else if(s[0] == 'B') {
            b++;
        } else if(s[m - 1] == 'A') {
            a++;
        }
    }
    if(c > 0) {
        ans += c - 1;
    }
    if(a > 0 && c > 0) {
        ans++;
        a--;
    }
    if(b > 0 && c > 0) {
        ans++;
        b--;
    }
    ans += min(a, b);
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int INF=1e9;
int main()
{
    int n,k; cin>>n>>k;
    int arr[n],dp[n]; for(int i=0;i<n;i++) cin>>arr[i];
    dp[0]=0;
    for(int i=1;i<n;i++)
    {
        dp[i]=INF;
        for(int j=i-1,b=0;j>=0&&b<k;j--,b++)
        {
            dp[i]=min(dp[j]+abs(arr[i]-arr[j]),dp[i]);
        }
        //cout<<dp[i]<<endl;
    }
    cout<<dp[n-1]<<endl;
    return 0;
}


Measured memory_bytes: 1024
a = input()
b = input()
c = input()

a_num = 0
b_num = 0
c_num = 0

turn = 'a'

while 1:
    if turn == 'a':
        if len(a) <= a_num:
            win = 'A'
            break
        turn = a[a_num]
        a_num = a_num + 1
    elif turn == 'b':
        if len(b) <= b_num:
            win = 'B'
            break
        turn = b[b_num]
        b_num = b_num + 1
    else:
        if len(c) <= c_num:
            win = 'C'
            break
        turn = c[c_num]
        c_num = c_num + 1

print(win)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,d;
  cin >> a >> b >> c >>d;
  if(a + b > c + d){
  	cout << "Left" << endl;
  }else if(a + b == c + d){
  	cout << "Balanced" << endl;
  }else {
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <tuple>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define repn(i, x) for (int i = 1; i <= (int)(x); i++)
#define repr(i, x) for (int i = ((int)(x) - 1); i >= 0; i--)
#define reprn(i, x) for (int i = ((int)(x)); i > 0; i--)
#define all(x) (x).begin(),(x).end()
typedef long long int64;
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;

int64 gcd(int64 a, int64 b) {
    return b != 0 ? gcd(b, a % b) : a;
}

int64 lcm(int64 a, int64 b) {
		return a / gcd(a, b) * b;
}

//逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
      fac[i] = fac[i-1] * i % MOD;
      inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
      finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
//組み合わせ
long long COM (int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

void solve() {
		int h,n; cin >> h >> n;
		vector<int64> dp(h + 1, INF);
		dp[0] = 0;
		for (int i = 0; i < n; ++i) {
				int a, b; cin >> a >> b;
				for (int j = 0; j < h; ++j) {
					int nj = min(j + a, h);
					dp[nj] = min(dp[nj], dp[j] + b);
				}
		}
		cout << dp[h] << endl;
		return;
}

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



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

if n == 1 then
    puts a[0]
    exit
end

ans = [a[0]]

if n % 2 == 0 then
    1.upto(n-1) do |i|
        if i % 2 == 0 then
            ans.push(a[i])
        else
            ans.unshift(a[i])
        end
    end
else
    1.upto(n-1) do |i|
        if i % 2 == 0 then
            ans.unshift(a[i])
        else
            ans.push(a[i])
        end
    end
end

puts ans.join(" ")

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

using namespace std;


void solve()
{
	int l,r,d;cin >> l >> r >> d;
	int count = 0;
	if (d == 1){
		cout << (r-l)+1 << '\n';
		return;
	}
	else{
		int prev = (l/d);
		int start = d * prev;
		if (l % d == 0){
			count++;
		}
		int i = l+1;
		while ( start <= r){
			start+=d;
			if (start <= r){
				count++;
			}
		}
	}
	cout <<count<<'\n';
}

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

Measured memory_bytes: 3580
#include<iostream>
#define rep(i, n) for (int i = 0; i < (n); i ++)
using namespace std;

int main()
{
  int n;
  cin >> n;
  
  int max = 0, min = 1000000001;
  int tmp;
  rep(i, n)
  {
    cin >> tmp;
    if (tmp > max) max = tmp;
    if (tmp < min) min = tmp;
  }
  
  cout << max - min;
  return 0;
}


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

string dream = "maerd", dreamer = "maerd", erase = "esare", eraser = "sare";

int main(){
    string s;
    cin >> s;
    for(int i=s.size()-1;i>=0;--i){
        if(s[i] == dream[0]){
            int cnt = 0;
            while(i >= 0 && cnt < dream.size() && s[i] == dream[cnt]){
                i--;
                cnt++;
            }
            if(cnt != dream.size()){
                cout << "NO" << endl;
                return 0;
            }
        }else if(s[i] == erase[0]){
            int cnt = 0;
            while(i >= 0 && cnt < erase.size() && s[i] == erase[cnt]){
                i--;
                cnt++;
            }
            if(cnt != erase.size()){
                cout << "NO" << endl;
                return 0;
            }
        }else if(s[i] == 'r'){
            if(s[--i] != 'e'){
                cout << "NO" << endl;
                return 0;
            }
            int cnt = 0;
            if(s[--i] == dreamer[0]){
                while(i >= 0 && cnt < dreamer.size() && s[i] == dreamer[cnt]){
                    i--;
                    cnt++;
                }
                if(cnt != dreamer.size()){
                    cout << "NO" << endl;
                    return 0;
                }
            }else if(s[i] == eraser[0]){
                while(i >= 0 && cnt < eraser.size() && s[i] == eraser[cnt]){
                    i--;
                    cnt++;
                }
                if(cnt != eraser.size()){
                    cout << "NO" << endl;
                    return 0;
                }
            }else{
                cout << "NO" << endl;
                return 0;
            }
        }else{
            cout << "NO" << endl;
            return 0;
        }
        i++;
    }

    cout << "YES" << endl;

    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
int N;
int dfs(int len, int num){
    //cout << len << " " << num << endl;
    if(len == 0){
        if(num > N)return 0;
        int used[10] = {};
        while(num){
            used[num%10]++;
            num /= 10;
        }
        if(used[3] && used[5] && used[7])return 1;
        else return 0;
    }
    int cnt = 0;
    cnt += dfs(len-1, num * 10 + 3);
    cnt += dfs(len-1, num * 10 + 5);
    cnt += dfs(len-1, num * 10 + 7);
    return cnt;
}
main(){
    cin >> N;
    int cnt = 0;
    rep(i,3,10){
        cnt += dfs(i,0);
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256