akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int INF = 1<<27;
const int MAX = 51;

int dis_d[MAX][MAX],in,s,d,G[MAX];
int min_d[MAX];
bool used[MAX];

int prim(){
  for(int i = 0 ; i < d ; i++){
    min_d[i] = INF;
    used[i] = false;
  }

  min_d[0] = 0;
  int res = 0;

  while(true){
    int v = -1;

    for(int u = 0 ; u < d ; u++){
      if(!used[u] && (v == -1 || min_d[u] < min_d[v])) v = u;
    }

    if(v == -1) break;
    used[v] = true;
    res += min_d[v];

    for(int u = 0 ; u < d ; u++){
      min_d[u] = min(min_d[u],dis_d[v][u]);
    }
  }

  return res;
}

int main(){
  while(cin >> s >> d , s + d){
    fill(G,G+MAX,INF);

    for(int i = 0 ; i < s ; i++){
      for(int j = 0 ; j < d ; j++){
	cin >> in;
	if(!in) continue;
	G[j] = min(G[j],in);
      }
    }
    fill(dis_d[0],dis_d[MAX],INF);

    for(int i = 0 ; i < d ; i++){
      dis_d[i][d] = dis_d[d][i] = G[i];
    }    

    for(int i = 0 ; i < d-1 ; i++){
      for(int j = i + 1 ; j < d ; j++){
	cin >> in;
	if(!in) continue;
	dis_d[i][j] = dis_d[j][i] = in;
      }
    }       
    d++;

    cout << prim()<< endl;
  }

  return 0;
}

Measured memory_bytes: 1168
/*Read the problem carefully before starting to work on it*/
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;

//ll ncr(ll n,ll r){ll ans=1;r=min(r,n-r);for (int i=1;i<=r;i++){ans*=(n-r+i);ans/=i;}return ans;}

#define pb push_back
#define eb emplace_back
#define mp(x,y) make_pair(x,y)
#define mod 1000000007

double PI=3.1415926535897932384626;

//template<typename T> T power(T x,T y,ll m=mod){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}

//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ost;

#define fi first
#define se second

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s,t;
	cin>>s>>t;
	ll ans=0;
	for(ll i=0;i<3;i++)
	{
	    if(s[i]==t[i])
	        ans++;
	}
	cout<<ans;
    return 0;
}


//252908XL

Measured memory_bytes: 256
def clc(a, b, c, p, t):
    if c == 0:
        b = a[0]
        return clc(a, b, c + 1, True, t) + clc(a, b, c + 1, False, t)
    elif c == len(a)-1:
        if p:
            return t + int(b) + int(a[c])
        else:
            return t + int(b + a[c])
    else:
        if p:
            t += int(b)
            b = a[c]
        else:
            b += a[c]
        return clc(a, b, c + 1, True, t) + clc(a, b, c + 1, False, t)


s = input()
print(clc(s, "", 0, True, 0) if len(s) != 1 else s)


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <list>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <numeric>
#include <unordered_set>
#include <unordered_map>
#include <chrono>
#include <random>
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long
#define PI 3.14159265358979323846
#define min(a,b) ((a<b)?(a):(b))
#define max(a,b) ((a<b)?(b):(a))
#define abs(a) ((a>0)?a:-(a))
#define pii pair<int,int>

const double eps = (double)1e-6;
const int maxn = 1e4+5;
const ll mod = 1e9+7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int dp[maxn];
pii cast[(int)(1e3+5)];  //{magic, damage}

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

    fill(dp,dp+maxn,(int)(3e8));
    int h,n; cin >> h >> n;
    int a,b;
    for (int i = 1; i <= n; i++) {
        cin >> a >> b;
        cast[i] = {b,a};
    }
    sort(cast+1,cast+1+n);

    int minmagic = cast[1].first;  //mini.first
    dp[0] = 0;
    for (int i = 1; i <= cast[1].second; i++) dp[i] = minmagic;

    for (int i = cast[1].second+1; i <= h; i++) {
        for (int j = 1; j <= n; j++) {
            if (i - cast[j].second < 0) dp[i] = min(dp[i], cast[j].first);
            else dp[i] = min(dp[i], dp[i-cast[j].second] + cast[j].first);
        }
    }

    cout << dp[h] << endl;

}



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

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

int main() {
    int n, q; 
    string s;
    cin >> n >> q >> s;

    vector<int> d(n);
    for(int i=1; i<n; i++){ 
        d[i] = d[i-1] + (s.substr(i-1, 2) == "AC" ? 1 : 0);
    }

    int l, r;
    rep(i, q){
        cin >> l >> r;
        cout << d[r-1] - d[l-1] << endl;
    }
    return 0;
}


Measured memory_bytes: 1408
#include <stdio.h>          // printf(), scanf(), getchar()
#include <stdlib.h>         // exit()
#include <stdbool.h>

const char NUL = '\0';

bool
ope_line()
{
	char train[52];
	int t = 25, s = 25;
	for (int i = 0; i < 52; ++i)
		train[i] = NUL;

	int c = getchar();
	train[t] = c;

	int a = getchar();
	while (a != '\n' && a != EOF)
	{
		int b = getchar();
		c = getchar();
		if (a == '<' && b == '-')
		{
			train[--t] = c;

			if (t < s)
				s = t;
		}

		else if (a == '-' && b == '>')
			train[++t] = c;

		a = getchar();
	}

	printf("%s\n", &train[s]);

	if (a == EOF)
		return false;

	return true;
}

int
main(int argc, char **argv)
{
	int n;
	scanf("%d\n", &n);

	for (int i = 0; i < n; ++i)
	{
		if (!ope_line())
			break;
	}

	return 0;
}

Measured memory_bytes: 1756
import java.util.Scanner;

class C {
    public static void main(String... args) {
        final Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        final int[][] A = new int[N][2];
        for(int i = 0; i < 2; i++)
            for(int j = 0; j < N; j++)
                A[j][i] = sc.nextInt();
        final int[][] dp = new int[N + 1][2];
        for(int i = 0; i < N; i++) {
            dp[i + 1][0] = dp[i][0] + A[i][0];
            dp[i + 1][1] = Math.max(dp[i + 1][0], dp[i][1]) + A[i][1];
        }
        System.out.println(dp[N][1]);
    }
}
public class Main {
    public static void main(String... args) {
        C.main(args);
    }
}

Measured memory_bytes: 23892
#include <stdio.h>
#include <iostream>

using namespace std;

double keisan (double b,int k) {
	if (k == 1) {
		return b;
	} else if (k % 2  == 0){
		return keisan(b*2,k-1);
	} else {
		return keisan(b/3,k-1);
	}
}

int main() {
	double a;
	double b;
	while (cin >> a) {
		b = 0;

		for (int i = 1; i <= 10; i++) {
			b += keisan(a,i);
		}

		printf("%.8f\n",b);
	}
	return 0;
}

Measured memory_bytes: 1236
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <cassert>
using namespace std;

typedef long long ll;

#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define FOREQ(i, a, b) for (int i = (a); i <= (int)(b); ++i)
#define DEC(i, k) for (int i = (k); i >= 0; --i)
#define FORIT(i, c) for (__tyoeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define SZ(v) (int)((v).size())
#define MEMSET(v, h) memset((v), (h), sizeof(v))
#define FIND(m, w) ((m).find(w) != (m).end())
#define ALL(c) (c).begin(), (c).end()

int m, n;
double probability[20][20];
double memo[18][1 << 16];

inline int bsf(int x) {
    __asm__("bsf %1, %0;" :"=r"(x) :"r"(x));
    return x;
}

double calc(int room, int rest) {
    if (!isnan(memo[room][rest])) { return memo[room][rest]; }
    if (room == n) { return 1.0; }
    if (rest == 0) { return 0.0; }
    double ret = 0.0;
    int cand = rest;
    while (cand != 0) {
        int cat = bsf(cand);
        cand -= cand & -cand;
        if (!((1 << cat) & rest)) { continue; }
        int nrest = rest ^ (1 << cat);
        double win = 0.0;
        double p = 1.0;
        FOREQ(i, room, n) {
            win += p * (1.0 - probability[cat][i]) * calc(i, nrest);
            p *= probability[cat][i];
        }
        ret = max(ret, win);
    }
    return memo[room][rest] = ret;
}

int main() {
    scanf("%d %d", &m, &n);
    MEMSET(probability, 0);
    REP(cat, m) {
        REP(room, n) {
            scanf("%lf", &probability[cat][room]);
        }
    }
    MEMSET(memo, -1);
    printf("%.9lf\n", calc(0, (1 << m) - 1));
}

Measured memory_bytes: 0
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(long long i=0;i<n;++i)
#define REPR(i,n) for(long long i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(v) {for(long long sitr=0;sitr<v.size();++sitr){cin>>v[sitr];}}

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

using namespace std;

typedef pair<int,int> pii;

class cake{
  public:
    int b, w, d;
    cake(int birth, int width, int depth):
      b(birth), w(width), d(depth) {}

    bool operator<(const cake& r) const{
      if(b != r.b){
        return b < r.b;
      }else{
        return w*d < r.w * r.d;
      }
    }
};

bool compare_area(const cake&r, const cake&l){
  return r.w*r.d < l.w*l.d;
}

int main(){

  int n, w, d;
  vector<cake> C;
  while(true){
    cin >> n >> w >> d;
    if(n == 0 && w == 0 && d == 0){
      break;
    }

    C.clear();
    C.push_back(cake(0,w,d));
    REP(i,n){
      int p, s;
      cin >> p >> s;
      p--;

      sort(C.begin(), C.end());

      s = s %(C[p].w + C[p].d);
      if(s < C[p].w){
        C.push_back(cake(i+1, C[p].w - s, C[p].d));
        C[p] = cake(i+1, s, C[p].d);
      }else{
        s -= C[p].w;
        C.push_back(cake(i+1, C[p].w, C[p].d - s));
        C[p] = cake(i+1, C[p].w, s);
      }
    }

    sort(C.begin(), C.end(), compare_area);
    REP(i,n){
      cout << C[i].d * C[i].w << " ";
    }
    cout << C[n].d * C[n].w << endl;
  }

  return 0;
}




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

int main(){
    string s;
    cin >> s;
    if(s.at(0) == s.at(1) || s.at(1) == s.at(2) || s.at(2) == s.at(3)) cout << "Bad" << endl;
    else cout << "Good" << endl;
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
typedef double          D;
typedef long long int   LL;
typedef long double     LD;
#define OR              ||
#define AND             &&
#define nl              '\n'
#define S               string
#define inf             INT_MAX
#define SQR(a)          (a) * (a)
#define pb              push_back
#define GCD(a, b)       __gcd(a, b)
#define PI              2.0*acos(0.0)
#define LCM(a, b)       (a * b) / GCD(a, b)
#define mem(a,b)        memset(a,b,sizeof(a))
#define srtv(v)         sort(v.begin(),v.end())
#define T               int t; cin>>t; while(t--)
#define Rep(i,a,b)      for(int i = a; i <= b; i++)
#define rep(i,a,b)      for(int i = a; i >= b; i--)
#define boost		    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define inout           freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)

#define si(x)           scanf("%d",&x)
#define pi(x)           printf("%d",x)
#define ss(str)         scanf("%s",str)
#define pl(x)           printf("%lld",x)
#define sl(x)           scanf("%lld",&x)
#define sii(x,y)        scanf("%d %d",&x,&y)
#define sll(x,y)        scanf("%lld %lld",&x,&y)
#define siii(x,y,z)     scanf("%d %d %d",&x,&y,&z)
#define slll(x,y,z)     scanf("%lld %lld %lld",&x,&y,&z)
using namespace std;



/*
int bs(int l,int r)
{
    int mid,res=inf;

    while(l<=r)
    {
        mid=l+(r-l)/2;

        if(check(mid,0)|| check(mid,1))
        {
            res=min(res,mid);
            r=mid-1;
        }
        else
            l=mid+1;

    }


    return res;
}*/


int main()
{
    LL n,m,k,x;
    slll(n,m,k);

    LL first[n+5];
    LL second[m+5];
    first[0]=0;
    second[0]=0;

    Rep(i,1,n)
    {
        sl(first[i]);
        first[i]+=first[i-1];
    }

    Rep(i,1,m)
    {
        sl(second[i]);
        second[i]+=second[i-1];
    }


    int firstbound=-1;

    rep(i,n,1)
    {
        if(first[i]-first[0]<=k)
            {
                firstbound=i;
                break;
            }
    }


    int Secondbound=-1;

    rep(i,m,1)
    {
        if(second[i]-second[0]<=k)
            {
                Secondbound=i;
                break;
            }
    }

    if(firstbound==-1  && Secondbound==-1)
    {
        printf("0\n");
    }
    else
    {
        LL res=-1,rem;

        int j=0;
        if(firstbound!=-1)
        rep(i,firstbound,0)
        {
            rem=k-(first[i]-first[0]);

            while(rem>=second[j+1]-second[0])
            {

                if(j>=m)
                    break;
                j++;
            }

            //cout<<rem<<" "<<i<<" "<<j<<nl;

            LL cmp=i+j;

            res=max(res,cmp);

            if(j>=m)
                break;
        }


        j=0;

        if(Secondbound!=-1)
        rep(i,Secondbound,0)
        {
            rem=k-(second[i]-second[0]);

            while(rem>=first[j+1]-first[0])
            {

                if(j>=n)
                    break;
                j++;
            }


            LL cmp=i+j;

            res=max(res,cmp);

            if(j>=n)
                break;
        }

        cout<<res<<nl;
    }






    return 0;

}
/*
*/


Measured memory_bytes: 6784
#include<stdio.h>
#include<vector>
#include<iostream>
#include<algorithm>
#include<iterator>

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

class Rectangles {  // 矩形が入り得る領域のx,yに対してO(xy)
    public:
    ll n, x, y;  // [0,x),[0,y)
    std::vector<ll> xs;  // n番目の長方形の左上のx座標->n*2, 右下のx座標->n*2+1
    std::vector<ll> ys;
    std::vector<std::vector<ll>> ex;

    Rectangles(ll n, ll x, ll y) : n(n), x(x), y(y){
        xs.assign(n*2+1, 0); ys.assign(n*2+1, 0);
        ex.assign(y+1, std::vector<ll>(x+1, 0));
    }

    void push(ll num, ll x1, ll y1, ll x2, ll y2){
        xs[num*2]=x1; xs[num*2+1]=x2;
        ys[num*2]=y1; ys[num*2+1]=y2;
    }
    void build(){
        for(ll i=0; i<n; i++){
            ex[ys[i*2]][xs[i*2]]++;
            ex[ys[i*2+1]][xs[i*2]]--;
            ex[ys[i*2]][xs[i*2+1]]--;
            ex[ys[i*2+1]][xs[i*2+1]]++;
        }
        for(ll xx=0; xx<x; xx++)for(ll yy=0; yy<y; yy++) ex[yy+1][xx] += ex[yy][xx];
        for(ll yy=0; yy<y; yy++)for(ll xx=0; xx<x; xx++) ex[yy][xx+1] += ex[yy][xx];
    }
    ll max_overlap(){
        ll max=-1;
        for(ll xx=0; xx<=x; xx++)for(ll yy=0; yy<=y; yy++)if(ex[yy][xx]>max){
            max = ex[yy][xx];
        }
        return max;
    }
};

int main(){
    ll n, x1, y1, x2, y2;
    cin >> n;
    Rectangles rc(n, 1001, 1001);
    REP(i,n){
        cin >> x1 >> y1 >> x2 >> y2;
        rc.push(i, x1, y1, x2, y2);
    }
    rc.build();
    /*
    REP(y,4){
        REP(x,4)cout << rc.ex[y][x] << " ";
        cout << endl;
    }*/
    cout << rc.max_overlap() << endl;
}


Measured memory_bytes: 13888
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
typedef pair<int,int> P;
 
int main() {
  int n,m;
  cin >> n >> m;
  map<int,int> ma;
  for(int i=0; i<m; i++) {
    int x,y;
    cin >> x >> y;
    if(ma.count(y)) ma[y]=min(ma[y],x);
    else ma[y]=x;
  }
  ma[0]=0;
  vector<P> a;
  for(map<int,int>::iterator it=ma.begin(); it!=ma.end(); it++) {
    a.push_back(P(it->F,it->S));
  }
  m=a.size();
  sort(a.begin(),a.end());
  int d[m+1];
  fill(d,d+m+1,100000);
  d[0]=0;
  for(int i=1; i<m; i++) {
    int M=a[i].S;
    for(int j=i-1; j>=0; j--) {
      d[i]=min(d[i],d[j]+(a[i].F-a[j].F)+(a[i].F-M)*2);
      M=min(M,a[j].S);
    }
  }
  int ans=n-a[m-1].F+d[m-1]+1;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1224
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

N = int(input())
x = N*800
y = N // 15 * 200

print(x-y)


Measured memory_bytes: 8512
#include<bits/stdc++.h>
using namespace std;
int main()
{
    map<string,int> m;

    int64_t i,j,k,N;
    string s;

    cin>>N;

    while(N--){
        cin>>s;
        m.insert({s,0});

    }
    cout<<m.size()<<endl;
    return 0;
}


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

#define ll long long
#define pb push_back

int main(){

	int N, H, W;
	cin >> N >> H >> W;
	cout << (N - H + 1) * (N - W + 1) << endl;

	return 0;
}


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

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

using namespace std;

const int IINF = INT_MAX;

enum Symbol { EXPS,EXPE,TERMS,TERME,FACTOR };

int exp(string &s,int &cur){

  stack<Symbol> sstack;
  stack<int> vstack;
  stack<char> ostack;
  sstack.push(EXPS);
  ostack.push('@'); // dammy;
  while( !sstack.empty() ){
    Symbol syb = sstack.top();
    char opr;
    int v1,v2,value;
    switch(syb){
    case EXPS:
      sstack.pop();
      sstack.push(EXPE);
      sstack.push(TERMS);
      break;

    case EXPE:
      opr = ostack.top();
      if( opr == '+' || opr == '-' ) {
        ostack.pop();
        v1 = vstack.top(); vstack.pop();
        v2 = vstack.top(); vstack.pop();
        vstack.push(((opr=='+')?(v2+v1):(v2-v1)));
      }
      if( s[cur] == '+' || s[cur] == '-' ){
        sstack.push(TERMS);
        ostack.push(s[cur++]);
      } else {
        sstack.pop();
      }
      break;

    case TERMS:
      sstack.pop();
      sstack.push(TERME);
      sstack.push(FACTOR);
      break;

    case TERME:
      opr = ostack.top();
      if( opr == '*' || opr == '/' ){
        ostack.pop();
        v1 = vstack.top(); vstack.pop();
        v2 = vstack.top(); vstack.pop();
        vstack.push(((opr=='*')?(v2*v1):(v2/v1)));
      }

      if( s[cur] == '*' || s[cur] == '/' ){
        sstack.push(FACTOR);
        ostack.push(s[cur++]);
      } else {
        sstack.pop();
      }
      break;

    case FACTOR:
      if( s[cur] == '(' ){
        ++cur;
        sstack.push(EXPS);
        ostack.push('(');
      } else if( s[cur] == ')' ){
        ++cur;
        sstack.pop();
        ostack.pop();
      } else if( '0' <= s[cur] && s[cur] <= '9' ) {
        value = 0;
        while( '0' <= s[cur] && s[cur] <= '9' )( value *= 10 ) += s[cur++] - '0';
        vstack.push(value);
        sstack.pop();
      } else assert(false); // invalid form
      break;

    default:
      break;
    }

  }
  assert(vstack.size() == 1);
  return vstack.top();
}

int main(){
  int T;
  cin >> T;
  cin.ignore();
  while(T--){
    string s;
    int cur = 0;
    getline(cin,s);
    cout << exp(s,cur) << endl;
  }
  return 0;
}

Measured memory_bytes: 1220
import sys
import math
import itertools as it
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":
    n = I()
    a = Intl()
    m = sum(a)
    s = list(it.accumulate(a))
    ans = []
    for i in range(n):
        ans.append(abs(s[i]-(m-s[i])))
    print(min(ans))

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

int n;
vector<pair<int, int>> v(3, make_pair(-1, 0));

int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++){
		int a;
		scanf("%d", &a), a ^= i & 1;
		if (v.empty() || v.back().first != a){
			v.emplace_back(a, 1);
		}
		else v.back().second++;
	}
	int res = 0;
	for (int i = 0; i + 2 < v.size(); i++){
		res = max(res, v[i].second + v[i + 1].second + v[i + 2].second);
	}
	printf("%d\n", res);
}

Measured memory_bytes: 3808
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

int main() {

    int N;
    cin >> N;

    string march = "MARCH";

    vector<string> S(N);
    for (int i = 0; i < N; i++) cin >> S[i];

    vector<long long> dp(5, 0);

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 5; j++) {
            if (S[i][0] == march[j]) {
                dp[j]++;
            }
        }
    }

    long long ans = 0;
    for (int i = 0; i < 5; i++) {
        for (int j = i + 1; j < 5; j++) {
            for (int k = j + 1; k < 5; k++) {
                ans += dp[i] * dp[j] * dp[k];
            }
        }
    }

    cout << ans << endl;

}


























































Measured memory_bytes: 6144
#include <stdio.h>

int	main(void)
{
	char s[6];
	scanf("%s", s);
	int i = 0;
	int count = 0; 
	while (i < 6)
	{
		if (i == 2 || i == 4)
		{
			if (s[i] == s[i + 1])
				count++;
		}
		i++;
	}
	if (count == 2)
		printf("Yes");
	else
		printf("No");
	return (0);
}


Measured memory_bytes: 128
///Astalavista Code........~CodeSlayer007
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define Br cout<<endl;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define int long long
#define double long double
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define PT(x) cout << (x) << endl;
#define SPD_emergency ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int M = 1e9 + 7;
int IM = 1e16;
void PV(vi v) { for (int i = 0 ; i < v.size() ; i++) cout << v[i] << " "; cout << endl;}
void PA(int v[], int n) {for (int i = 0 ; i < n ; i++)cout << v[i] << " " ; cout << endl;}
void IN(int a[], int n, int x = 0) {for (int i = x; i < n + x; i++)cin >> a[i];}
inline void PTN(int n = 1, int a = 0, int b = 0, int c = 0) { if (n--)cout << a << " "; if (n--)cout << b << " "; if (n--)cout << c << " "; cout << endl; }
inline void op() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
// <-------------------------------------------------------------------------------------------------------------------------------------------------------------------------> Ignore This--> memset substr pop_back  insert tuple first second push_back string continue make_pair break deque stack queue sort reverse accumulate  count lower_bound upper_bound next_permutation copy_n __builtin_popcount make_tuple
// <========================================================================================================================================================================

signed  main() {
    SPD_emergency
    
    int i, j, k, x, y, u;
    //int t; cin >> t; while (t--)
    {
        int n, m;
        cin >> n >> k;
        int a[n + 10];
        vi v;
        IN(a, n, 1); //PA(a, n + 1);
        j = a[1];
        map<int, int> mapp;
        mapp[1]++;
        x = 0;
        v.push_back(1);
        while (mapp[j] != 1) {
            //PT(j)if (x > 6) break;
            mapp[j]++;
            v.push_back(j);
            j = a[j];

        }
        //PV(v);
        vi c;
        c.push_back(j);
        j = a[j];
        while (j != c[0]) {
            //if (x > 6) break;
            x++;
            c.push_back(j);
            j = a[j];
            
        }
        //PV(c);
        if (k < v.size()) {
            PT(v[k]);
        }
        else {
            k = k - v.size() ;
            k = k % (c.size());
            PT(c[k]);
        }
    }
    return 0;
}

Measured memory_bytes: 20620
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt(), M = sc.nextInt();
        DJSet dj = new DJSet(N);
        for (int i = 0; i < M; i++) {
            dj.union(sc.nextInt()-1, sc.nextInt()-1);
        }
        System.out.println(dj.countSet()-1);
        sc.close();

    }

}

class DJSet {
    /**
     * 各要素の親を保持する配列。
     * 自信が根である要素は負の数を持つ。
     * （負の数の場合、絶対値がその集合の要素数）
     */
    public int[] upper;

    /**
     * コンストラクタ。
     * @param n 対象となる要素数
     */
    public DJSet(int n) {
        upper = new int[n];
        Arrays.fill(upper, -1);
    }

    /**
     * 要素xが含まれる集合のrootを求める。
     * rootを求める過程で経路圧縮しrootが親になるようにする。
     * @param x 要素x
     * @return 要素xが含まれる集合のroot
     */
    public int root(int x) {
        return upper[x] < 0 ? x : (upper[x] = root(upper[x]));
    }

    /**
     * 要素xと要素yが同じ集合か判定する。
     * @param x 要素x
     * @param y 要素y
     * @return 要素xと要素yが同じ集合であればtrue、そうでなければfalseを返す。
     */
    public boolean same(int x, int y) {
        return root(x) == root(y);
    }

    /**
     * 要素xと要素yを含むそれぞれの集合を合併する。
     * 要素数の多い集合のrootを残し、少ないほうのrootをその下に合併する。
     * @param x 要素x
     * @param y 要素y
     * @return 要素xと要素yを含むそれぞれの集合を合併できたらtrue、もともと同じ集合で合併しなかったらfalseを返す。
     */
    public boolean union(int x, int y) {
        x = root(x);
        y = root(y);
        if (x != y) {
            if (upper[y] < upper[x]) {
                int t = x;
                x = y;
                y = t;
            }
            upper[x] += upper[y];
            upper[y] = x;
        }
        return x != y;
    }

    /**
     * 集合の数を数える。
     * @return 集合の数
     */
    public int countSet() {
        int c = 0;
        for (int u : upper) {
            if (u < 0)
                c++;
        }
        return c;
    }

    /**
     * 要素ｘが含まれる集合の要素数を数える。
     * @param x 要素ｘ
     * @return 要素ｘが含まれる集合の要素数
     */
    public int countElement(int x) {
        return upper[root(x)] * -1;
    }
}

Measured memory_bytes: 59232
N, M = list(map(int, input().split()))
X = list(map(int, input().split()))

X.sort()

T = [X[i + 1] - X[i] for i in range(M - 1)]
T.sort()

for i in range(N - 1):
  if T == []:
    break
  del T[-1]
  
Ans = 0
for i in T:
  Ans += i

print(Ans)

Measured memory_bytes: 56872
#include <iostream>
#include <vector>
#include <tuple>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <string>
using namespace std;
#define ForInt(i, n) for (int i = 0; i < (n); ++i)
#define ForIntInit(i, begin, n) for (int i = (begin); i < (n); ++i)
using int64 = long long;

int main()
{
    string s, t;
    cin >> s;
    cin >> t;
    int n = s.length();
    string ss = s + s;
    vector<vector<int>> table(26);
    ForInt(i, 26)
    {
        table[i].reserve(n + 1);
    }
    string al = "abcdefghijklmnopqrstuvwxyz";

    ForInt(i, n + 1)
    {
        int ch = al.find(ss[i]);
        ForIntInit(j, table[ch].size(), i + 1)
        {
            table[ch].push_back(i);
        }
    }
    ForInt(i, 26)
    {
        if (table[i].empty()) continue;
        int val = table[i][0] + n;
        ForIntInit(j, table[i].size(), n)
        {
            table[i].push_back(val);
        }
    }

    int tLen = t.length();
    int64 index = 0;
    int cur = 0;
    ForInt(i, tLen)
    {
        int ch = al.find(t[i]);
        if (table[ch].empty())
        {
            cout << -1 << endl;
            return 0;
        }
        cur = index % n;
        index += table[ch][cur] - cur;
        ++index;
    }

    cout << index << endl;

    return 0;
}


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

int main(void){
    int k;
    string s;

    cin >> k >> s;

    if(k>s.size()){
        k=s.size();
    }

    for(int i=0;i<k;i++){
        cout << s[i] << flush;
    }
    if(k < s.size()){
        cout << "..." << flush;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3632
// $%U%$ $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	ll n,k;
	cin>>n>>k;
	vector<ll> v(n);
	for(auto &i:v)cin>>i;
	ll s=0;
	for(ll i=0; i<k-1; ++i)s+=v[i];
	ll res=0;
	for(ll i=k-1; i<n; ++i){
		s+=v[i];
		res=max(res,s);
		s-=v[i-k+1];
	}
	double ans = (res+k)/2.0;
	cout<<((res+k)>>1);
	if((res+k)&1)cout<<".5";
	cout<<endl;
	return 0;
}



Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main()
{
	int E, Y;
	cin >> E >> Y;
	if (E == 0)
	{
		if (Y <= 1911)
			cout << 'M' << Y - 1867 << endl;
		else if (Y <= 1925)
			cout << 'T' << Y - 1911 << endl;
		else if (Y <= 1988)
			cout << 'S' << Y - 1925 << endl;
		else if (Y <= 2016)
			cout << 'H' << Y - 1988 << endl;
	}
	else if (E == 1)
		cout << Y + 1867 << endl;
	else if (E == 2)
		cout << Y + 1911 << endl;
	else if (E == 3)
		cout << Y + 1925 << endl;
	else if (E == 4)
		cout << Y + 1988 << endl;
	return 0;
}

Measured memory_bytes: 3120
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
#define Inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
int n,m,k;
int a[maxn];
int b[maxn];
int c[maxn];

ll erfen1(int l,int r,int key)
{
    int mid;
    while(l<=r)
    {
        mid=l+(r-l)/2;
        if(a[mid]<key)
        {
            l=mid+1;
        }
        else
        {
            r=mid-1;
        }

    }
    return r;

}

ll erfen2(int l,int r,int key)
{
    int mid;
    while(l<=r)
    {
        mid=(l+r)/2;
        if(c[mid]>key)
        {
            r=mid-1;
        }
        else
        {
            l=mid+1;
        }

    }
    return l;
}

int main()
{
    while(~scanf("%d",&n))
    {
        for(int i=0; i<n; i++)
            scanf("%d",&a[i]);
        for(int i=0; i<n; i++)
            scanf("%d",&b[i]);
        for(int i=0; i<n; i++)
            scanf("%d",&c[i]);
        sort(a,a+n);
        sort(c,c+n);
        ll ans=0;
        for(int i=0; i<n; i++)
        {
            ll pos1=erfen1(0,n-1,b[i]);
            if(pos1<=n-1&&a[pos1]<b[i])
                pos1=pos1+1;
            else
                pos1=0;
            ll pos2=erfen2(0,n-1,b[i]);
           if(pos2>=0&&c[pos2]>b[i])
                pos2=n-pos2;
            else
                pos2=0;
           // printf("pos1=%lld pos2=%lld\n",pos1,pos2);
            ans+=pos1*pos2;
        }
        printf("%lld\n",ans);

    }
    return 0;
}


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

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

const ll mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 1152921504606846976
ll dp[105][100050];

int main()
{
    int n,w; cin >> n >> w;
    ll weight[n],value[n];
    rep(i,n) cin >> weight[i] >> value[i];
    rep(i,n){
        rep(j,w+1){
            dp[i+1][j] = dp[i][j];
            if(j - weight[i] >= 0){
                dp[i+1][j] = max(dp[i][j-weight[i]] + value[i],dp[i][j]);
            }
        }
    }
    cout << dp[n][w] << endl;
}

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

signed main()
{
  cout << fixed << setprecision(10);
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;

  vector<pair<int,int>> p(n);
  for (int i = 0; i < n; ++i) cin >> p[i].first >> p[i].second;

  sort(p.begin(), p.end());
  long double sum = 0, cnt = 0;

  do {
    for (int i = 0; i < n-1; ++i) sum += sqrt(pow(p[i].first - p[i+1].first, 2) + pow(p[i].second - p[i+1].second, 2));

    ++cnt;
  } while (next_permutation(p.begin(), p.end()));

  cout << sum / cnt << endl;

  return (0);
}


Measured memory_bytes: 3796
import sys
sys.setrecursionlimit(10000)
input = sys.stdin.readline

def f(v, vs):
    kminmax = rkoma = fff = ffmx = 0
    for u in d[v]:
        if u in vs:
            continue
        vs.add(u)
        k1, koma, ff = f(u, vs)
        if k1 > kminmax:
            kminmax, ffmx = k1, ff
        rkoma += koma
        fff += ff
    r1 = kminmax+ffmx-fff if kminmax > fff - ffmx else fff % 2
    rkoma += km[v]
    return r1+rkoma, rkoma, fff+rkoma

N = int(input())
km = [0] + [int(i) for i in str(input().strip())]
d = [set() for _ in range(N+1)]
for _ in range(N-1):
    x, y = map(int, input().split())
    d[x].add(y)
    d[y].add(x)
r = 10**10
for i in range(N):
    a, c, fff = f(i+1, {i+1})
    if a == c:
        r = min((fff-c)//2, r)
print(r if r != 10**10 else -1)


Measured memory_bytes: 220808
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define PI 3.14159265358979323846264338327950288
#define mt make_tuple


void love() {
	int n;
	cin>>n;

	pair<int, int> a[n];
	for(int i = 0; i<n; i++) cin>>a[i].first, a[i].second = i+1;

	sort(a, a+n);
	for(int i = 0; i<n; i++) cout<<a[i].second<<" ";
	cout<<endl;
}

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

Measured memory_bytes: 1664
import sys


def solve(n, k, aaa):
    pos = []
    neg = []
    MOD = 10 ** 9 + 7
    for a in aaa:
        if a > 0:
            pos.append(a)
        elif a < 0:
            neg.append(a)
    if len(pos) + len(neg) < k:
        return 0
    if len(pos) == 0:
        if k % 2 == 1:
            if len(neg) < n:
                return 0
            neg.sort(reverse=True)
        else:
            neg.sort()
        ans = 1
        for a in neg[:k]:
            ans = ans * a % MOD
        return ans
    if len(pos) + len(neg) == k:
        if n > k and len(neg) % 2 == 1:
            return 0
        ans = 1
        for a in pos:
            ans = ans * a % MOD
        for a in neg:
            ans = ans * a % MOD
        return ans

    pos.sort()
    neg.sort(reverse=True)
    ans = 1
    r = k

    if r % 2 == 1:
        ans = ans * pos.pop() % MOD
        r -= 1

    while r >= 2:
        if len(pos) <= 1:
            ans = ans * neg.pop() * neg.pop() % MOD
        elif len(neg) <= 1:
            ans = ans * pos.pop() * pos.pop() % MOD
        else:
            pm = pos[-1] * pos[-2]
            nm = neg[-1] * neg[-2]
            if pm > nm:
                ans = ans * pm % MOD
                pos.pop()
                pos.pop()
            else:
                ans = ans * nm % MOD
                neg.pop()
                neg.pop()
        r -= 2

    return ans


n, k, *aaa = map(int, sys.stdin.buffer.read().split())
print(solve(n, k, aaa))


Measured memory_bytes: 27716
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String S =sc.nextLine();
		int[] form = new int[3];
		form[0] =Integer.parseInt(S.substring(0, 2));
		form[1] =Integer.parseInt(S.substring(2, 4));
		if(form[0] > 0 && form[0] < 13){
			yearSurv(form[1]);
		}
		else if(form[0] >= 13 && form[0] < 100){
			monthSurv(form[1]);
		}
		else if(form[0] == 0){
			monthSurv(form[1]);
		}
		else{
			System.out.println("NA");
		}
	}
	
	public static void yearSurv(int year){
		if(year > 0 && year <13 ){
			System.out.println("AMBIGUOUS");
		}
		else if(year >= 13 && year <100){
			System.out.println("MMYY");
		}
		else if(year == 0){
			System.out.println("MMYY");
		}
		else{
			System.out.println("NA");
		}
	}
	
	public static void monthSurv(int month){
		if(month > 0 && month < 13){
			System.out.println("YYMM");
		}
		else{
			System.out.println("NA");
		}
	}
}



Measured memory_bytes: 21588
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int h,w,i=0,j,c=0,n;
    cin >> n;
    h=n;
    while(h>=10)
    {
        h=h%10;
    }
    if(h==2 || h==4 || h==5 || h==7 || h==9)
    {
        cout << "hon" << endl;
    }
    if(h==0 || h==1 || h==6 || h==8)
    {
        cout << "pon" << endl;
    }
    if(h==3)
    {
        cout << "bon" << endl;
    }
    return 0;

}


Measured memory_bytes: 3596
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<string>
#include<vector>
#include<stack>
#include<iomanip>
#define rep(i,n) for(int i=0;i<((int)n);i++)
#define drep(i,n) for(int i=((int)n)-1;i>-1;i--)
#define Rep(i,n0,n) for(int i=n0;i<((int)n);i++)
#define Com(i,j,n) for(int i=0;i<n-1;i++)for(int j=i+1;j<((int)n);j++)
#define W(x) cout<<x<<endl;
#define Debug(x) cout<<"#DEBUG "<<x<<endl;
#define INF (1<<29)
#define INF2 (long long)8*(long long)INF*(long long)INF
#define mod 1000000007

typedef long long ll;

using namespace std;


int min(int x,int y){if(y<x)return y;else return x;}
int max(int x,int y){if(y>x)return y;else return x;}
int fact(int x){int i=1;rep(j,x){i*=(j+1);} return i;}
long long fact(long long x){long long i=1;rep(j,x){i*=(j+1);} return i;}
int gcd(int x, int y)
{
    if(x%y==0)return y;
    else if(y%x==0)return x;
    else return gcd(x%y,y%x);
}
ll gcd(ll x, ll y)
{
    if(x%y==0)return y;
    else if(y%x==0)return x;
    else return gcd(x%y,y%x);
}
//AGC018B
int main()
{
    int n;
    cin >> n;
    bool flag=false;
    rep(i,n/7+1)
    {
        if((n-7*i)%4==0)flag=true;
    }
    if(flag||n%7==0)
    {
        W("Yes")
    }
    else W("No")
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int INF=1e9+5;
int main()
{
  int n;
  scanf("%d",&n);
  vector<int>h(n);
  for(int &x:h)
        scanf("%d",&x);


      vector<int>dp(n,INF);
      dp[0]=0;

  for(int i=0;i<n;i++)
  {
      for(int j:{i+1,i+2})
        if(j<n)
         dp[j]=min(dp[j],dp[i]+abs(h[j]-h[i]));
  }
  cout<<(dp[n-1]);
  return 0;
}


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

public class Main {

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

    void solve() {
        Scanner sc = new Scanner(System.in);
        int[] A = new int[3];
        for (int i = 0; i < 3; i++) {
            A[i] = sc.nextInt();
        }
        Arrays.sort(A);
        System.out.println(Math.abs(A[2] - A[1]) + Math.abs(A[1] - A[0]));
    }
}


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

int main() {
  int n;
  cin >> n;
  int m = 1;
  for(int i = 1; i <= n; i++) m *= i;
  vector<int> p(n), q(n);
  rep(i, n) cin >> p.at(i);
  rep(i, n) cin >> q.at(i);
  int ans = 0;
  for(int i = n; i >= 2; i--) {
    int p_count = 1;
    int q_count = 1;
    for(int j = n-i+1; j < n; j++) {
      if(p.at(n-i) > p.at(j)) p_count++;
    }
    for(int j = n-i+1; j < n; j++) {
      if(q.at(n-i) > q.at(j)) q_count++;
    }
    m /= i;
    ans += m * (p_count - q_count);
  }
  cout << abs(ans) << endl;
}

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

int main(){
	int a, b, c, x, count=0;
	cin >> a >> b >> c >> x;
	for(int i=0; i<=a; i++){
		for(int j=0; j<=b; j++){
			for(int k=0; k<=c; k++){
				if(500*i+100*j+50*k == x)
					count++;
			}
		}
	}
	cout << count << '\n';
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = input().strip().split()
#Bubble sort
b = a[:]
for i in range(n):
    for j in range(n-1,i,-1):
        if b[j][1] < b[j-1][1]:
            b[j],b[j-1] = b[j-1],b[j]
print(' '.join(b))
print('Stable')
#Selection sort
for i in range(n):
    minj = i
    for j in range(i,n):
        if a[j][1] < a[minj][1]:
            minj = j
    a[i],a[minj] = a[minj],a[i]
print(' '.join(a))
print('Stable' if b == a else 'Not stable')

Measured memory_bytes: 7672
using System;
using System.Collections.Generic;
using System.Linq;

class Program {

    static int Main(string[] args) {
        string[] v = Console.ReadLine().Split(' ');

        int n = int.Parse(v[0]);
        int m = int.Parse(v[1]);

        int[,] list = new int[n, m];
        for (int i = 0; i < n; i++) {
            string[] x = Console.ReadLine().Split(' ');

            for (int k = 0; k < m; k++) {
                list[i, k] = int.Parse(x[k]);
            }
        }

        for (int i = 0; i < m; i++) {
            int x = int.Parse(Console.ReadLine());

            for (int k = 0; k < n; k++) {
                list[k, i] *= x;
            }
        }

        for (int i = 0; i < n; i++) {
            int t = 0;
            for (int k = 0; k < m; k++) {
                t += list[i, k];
            }
            Console.WriteLine(t);
        }

        return 0;
    }
}


Measured memory_bytes: 15992
import java.util.Scanner;

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

		String A = sc.next();
		String B = sc.next();
		String C = sc.next();

		if(A.charAt(A.length() - 1) == B.charAt(0)){
			if(B.charAt(B.length() - 1) == C.charAt(0)){
				System.out.println("YES");
			}else{
				System.out.println("NO");
			}
		}else{
			System.out.println("NO");
		}

		sc.close();
	}
}


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

counter = Hash.new(0)

A.each do |a|
  counter[a] += 1
end

LIMIT = 10 ** 6

primes = Array.new(2 * LIMIT + 1, false)
ans = 0

A.sort.each do |a|
  next if primes[a]

  ans += 1 if counter[a] <= 1
  v = a

  while v <= LIMIT
    primes[v] = true
    v += a
  end
end

puts ans


Measured memory_bytes: 52684
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define pf push_front
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define SZ(x) (int)(x).size()
#define ft front()
#define bk back()
#define endl '\n'
#define FOR(a, b, c) for (auto(a) = (b); (a) < (c); ++(a))
#define ROF(a, b, c) for (auto(a) = (b); (a) > (c); --(a))
#define F0R(a, b) FOR ((a), 0, (b))
#define R0F(a, b) ROF ((a), (b), -1)
#define CEIL(a, b) ((a) + (b)-1) / (b)
#define SET(a, b) memset((a), (b), sizeof(a))
template <class t>
bool ckmin(t& a, const t& b) {
    return a > b ? a = b, true : false;
}
template <class t>
bool ckmax(t& a, const t& b) {
    return a < b ? a = b, true : false;
}
#ifndef DEBUG
#define DEBUG 0
#endif
#define dout \
    if (DEBUG) std::cerr
#define dvar(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
template <class a, class b>
ostream& operator<<(ostream& o, const pair<a, b>& p);
template <class T>
struct IsC {
    template <class C>
    static char test(typename C::const_iterator*);
    template <class C>
    static int test(...);
    static const bool value = sizeof(test<T>(0)) == sizeof(char);
};
template <>
struct IsC<string> {
    static const bool value = false;
};
template <class C>
typename enable_if<IsC<C>::value, ostream&>::type operator<<(ostream& o,
                                                             const C& c) {
    o << '[';
    for (auto it = c.begin(); it != c.end();)
        o << *it << (++it != c.end() ? ", " : "");
    return o << ']';
}
template <class a, class b>
ostream& operator<<(ostream& o, const pair<a, b>& p) {
    return o << '(' << p.fi << ", " << p.se << ')';
}

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

    int n, m, x;
    cin >> n >> m >> x;

    vi cs(n);
    vvi as(n, vi(m));
    F0R (i, n) {
        cin >> cs[i];
        F0R (j, m)
            cin >> as[i][j];
    }

    auto valid = [&](int i) {
        vi ms(m);
        F0R (j, n) {
            if (i & (1 << j)) {
                F0R (k, m)
                    ms[k] += as[j][k];
            }
        }
        for (int j : ms)
            if (j < x) return false;
        return true;
    };
    int best = -1;
    for (int i = 0; i < (1 << n); ++i) {
        if (valid(i)) {
            dout << bitset<12>(i) << endl;
            int sum = 0;
            F0R (j, n)
                if (i & (1 << j)) sum += cs[j];
            if (~best)
                ckmin(best, sum);
            else
                best = sum;
        }
    }
    cout << best << endl;

    return 0;
}


Measured memory_bytes: 3664
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double a = sc.nextDouble(), b = sc.nextDouble(), h = sc.nextDouble(), m = sc.nextDouble();
        double res = Math.sqrt(a * a + b * b - 2 * a * b * Math.cos(Math.toRadians(Math.abs(h * 30 + 0.5 * m - m * 6))));
        System.out.println(res);
    }
}


Measured memory_bytes: 37596
while 1:
    try:
        l=map(int,raw_input().split(','))
        v2=l.pop()
        v1=l.pop()
        p=v1*float(sum(l))/(v1+v2)
        for i in range(10):
            p-=l[i]
            if p<=0:
                print i+1
                break

    except:
        break

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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define repi(i, n) for(int i=0;i<(int)(n);i++)
#define rep2i(i, s, n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define chmax(s, t) s=max(s,t);
#define chmin(s, t) s=min(s,t); 

#define deg2rad(deg) (((deg)/360)*2*M_PI)
#define rad2deg(rad) (((rad)/2/M_PI)*360)

using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

const ll INF = (1LL<<60);
const int INFi = (1<<29);

/*素数判定*/
bool is_prime(ll n){
    if(n==1) return false;
    for(ll i=2;i*i<=n;i++){
        if(n%i==0) return false;
    }
    return true;
}

/*約数列挙*/
vll enum_divisors(ll n){
    vll l;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            l.push_back(i);
            if(n/i != i) l.push_back(n/i);
        }
    }
   sort(all(l));
   return l;
}

/*素因数分解*/
vector<P> prime_factorize(ll n){
    vector<P> l;
    for(ll i=2;i*i<=n;i++){
        if(n%i!=0) continue;
        ll e = 0;
        while(n%i==0){
            e++;
            n /= i;
        }
        l.push_back({i, e});
    }
    if(n!=1) l.push_back({n, 1});
    return l;
}

/*最小公倍数*/
ll lcm(ll a, ll b){
    return a*b/__gcd(a,b);
}

/*最大公約数*/
ll gcd(ll a, ll b){
    return __gcd(a,b);
}

/*組み合わせ(Combination)*/
const ll CMAX = 1010000;
const ll CMOD = 1e9+7;
ll fac[CMAX], finv[CMAX], inv[CMAX];
// テーブルを作る前処理
void combinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (ll i = 2; i < CMAX; i++) {
		fac[i] = fac[i - 1] * i % CMOD;
		inv[i] = CMOD - inv[CMOD%i] * (CMOD / i) % CMOD;
		finv[i] = finv[i - 1] * inv[i] % CMOD;
	}
}
// 二項係数計算
ll comb(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % CMOD) % CMOD;
}

/*階乗*/
ll factorial(ll n){
    const ll FMOD = 1e9+7;
    ll ret = n;
    for(ll i=n-1;i>0;i--){
        ret*=i;
        ret%=FMOD;
    }
    return (ret?ret:1);
}


int main(){

    ll a, b, c; cin >> a >> b >> c;

    cout << max(c-a+b, 0LL) << endl;

    return 0;
}

Measured memory_bytes: 3636