akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace d
{
    class Program
    {
        static long fs(long a)
        {
            long ret = 0;
            // i = 0 is special case
            if (a % 4 == 1 || a % 4 == 2)
            {
                ret = ret | (1l << 0);
            }
            for (int i =1; i < 50; i++)
            {
                long stride = 1l << (i+1);
                long mod = a % stride;
                if (mod < stride / 2)
                {
                    // do nothing    
                } else
                {
                    if (mod % 2 == 0)
                    {
                        ret = ret | (1l << i);
                    }
                }
            }
            return ret;
        }
        static void Main(string[] args)
        {
            long a, b;
            {
                var s = Console.ReadLine().Split(' ').ToList().ConvertAll(x => long.Parse(x));
                a = s[0];
                b = s[1];

                long fa = fs(a-1);
                long fb = fs(b);
                Console.WriteLine("{0}", fb ^ fa);
            }

        }
    }
}


Measured memory_bytes: 13268
#include <iostream>
using namespace std;
int main(){
    int a,b,c;
    while ( cin >> a >> b){
        if(cin.eof()){break;}
        c = a+b;
        if (c/1000000>=1)
            cout << "7" << endl;
        else if (c/100000>=1)
            cout << "6" << endl;
        else if (c/10000>=1)
            cout << "5" << endl;
        else if (c/1000>=1)
            cout << "4" << endl;
        else if (c/100>=1)
            cout << "3" << endl;
        else if (c/10>=1)
            cout << "2" << endl;
        else
            cout << "1" << endl;
    }
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
#include <string>
using namespace std;
int main(){
  long A,B; cin>>A>>B;
  long ans=999;
  if (A>B){
    swap(A,B);
  }
  for (int i=1; i<=A; i++){
    if ((B*i)%A == 0){
      ans = B*i;
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,f=0;
  cin >>N;
  for (int i=0;i<N;i++){
    int A,a=0;
    cin >> A;
    while (A>1){
      if(A%2) {
        break;
      }
      else if (!(A%2)) {
        a++;
      }
      A/=2;
    }
    if (f<=a && i!=0){
      f=f;
    }
    else {
      f=a;
    }
  }
  cout << f << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

    int a = scanner.nextInt();
    int b = scanner.nextInt();
    int c = scanner.nextInt();

    if (a < b && b < c) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 17320
#include<bits/stdc++.h>
using namespace std;
int sum[100005],b[100005];
int main()
{
	int l,r,n,q,i,ans;
	string s;
	cin>>n>>q>>s;
	for(i=0;i<s.size();i++)
	 {if(s[i]=='A'&&s[i+1]=='C')
	   sum[i]=1,b[i]=1;
	 }
	for(i=1;i<s.size();i++)
	 sum[i]+=sum[i-1];
	for(i=1;i<=q;i++)
	 {cin>>l>>r;
	  r--;l--;
	  ans=sum[r]-sum[l];
	  if(b[r])ans--;
	  if(b[l])ans++;
	  cout<<ans<<endl;
	 }
}

Measured memory_bytes: 1792
from collections import Counter

N = int(input())
A = list(map(int,input().split()))
C = Counter(A)
Q = int(input())
BC = [0]*Q
for i in range(Q):
    BC[i] = tuple(map(int,input().split()))

su = sum(A)
for b,c in BC:
    numb = C[b]
    C[b] = 0
    C[c] += numb
    su += (c - b) * numb
    print(su)

Measured memory_bytes: 99480
#include <bits/stdc++.h> 
using namespace std; 
#define ll long long int 
#define pb push_back
#define vv vector<ll>
#define MAX 105000
#define fr(i,x) for(int i=0;i<x;i++)
int dx[4] = {-1,0,0,1};
int dy[4] = {0,-1,1,0};

bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    
    if(a.first == b.first) return a.second<b.second;
    return (a.first < b.first); 
}
ll ar[MAX];
void divisor(){
    for (int i = 1; i <= MAX; i++)
    {
        for (int j = i; j <= MAX;j+=i)
        {
            ar[j]++;
            
        }
        
        
    }
    
}
int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    
    ll n,a,b;
    cin >> n >> a >> b;
    if(a==0&&b==0)cout << 0 << endl;
    else if(a==0) cout << 0 << endl;
    else if(b==0)cout << n << endl;
    else
    {
        ll c,r;
        
        c = (n/(a+b));
        r = (n%(a+b));
        r = min(r,a);
        cout << (c*a)+r << endl;
 
        
    }
    
    


}

Measured memory_bytes: 3612
#include "bits/stdc++.h"
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define pi acos(-1.0)
#define ri register int
#define Max(x, y) (((x) > (y)) ? (x) : (y))
#define Min(x, y) (((x) < (y)) ? (x) : (y))
#define Abs(x) ((x) < 0 ? (-(x)) : (x))
#define int long long
const int maxn = 2e5 + 10;
inline int read()
{
    int f = 1, r = 0;
    char c = getchar();
    while (!isdigit(c)) {
        if (c == '-') {
            f = -1;
        }
        c = getchar();
    }
    while (isdigit(c)) {
        r = 10 * r + c - '0';
        c = getchar();
    }
    return f * r;
}
inline void write(int x)
{
    if (x < 0)
        putchar('-'), x = -x;
    if (x > 9)
        write(x / 10);
    putchar(x % 10 + '0');
}
inline void writesp(int x) { write(x), putchar(' '); }
inline void writeln(int x) { write(x), puts(""); }
int H, W, A, B, fac[maxn], inv[maxn];
inline int exgcd(int a, int b, int& x, int& y)
{
    if (b == 0) {
        x = 1, y = 0;
        return a;
    }
    int d = exgcd(b, a % b, x, y);
    int tmp = y;
    y = x - a / b * y;
    x = tmp;
    return d;
}
inline int Inv(int a)
{
    int x, y;
    exgcd(a, MOD, x, y);
    return (x + MOD) % MOD;
}
inline int C(int n, int m)
{
    return fac[n] * inv[n - m] % MOD * inv[m] % MOD;
}
signed main()
{
    fac[0] = 1;
    for (ri i = 1; i < maxn; ++i) {
        fac[i] = fac[i - 1] * i % MOD;
    }
    for (ri i = 0; i < maxn; ++i) {
        inv[i] = Inv(fac[i]);
    }
    H = read(), W = read(), A = read(), B = read();
    if (A == H) {
        writeln(0);
        return 0;
    }
    int ans = C(H + W - 2, H - 1);
    for (ri i = 1; i <= B; ++i) {
        int x = i, y = H - A;
        int tmp1 = C(x + y - 2, y - 1);
        int tmp2 = C(A + W - i - 1, A - 1);
        int tmp = tmp1 * tmp2 % MOD;
        ans = (ans - tmp + MOD) % MOD;
    }
    writeln(ans);
    return 0;
}

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

int main()
{
 int n;
 cin>>n;
 if(n%10==2 || n%10==4 || n%10==5 || n%10==7 ||n%10==9){
   cout<<"hon"<<endl;
 }
 else if(n%10==0 ||n%10==1 ||n%10==6 ||n%10==8 ){
   cout<<"pon"<<endl;
 }
 else
 cout<<"bon"<<endl;

}


Measured memory_bytes: 3604
#include <iostream>

using namespace std;
int main(){
    string X;
    cin>>X;
    int t=0,s=0,cnt=0;
    for(auto c:X){
        if(c=='T'){
            if(s){
                s--;
                cnt+=2;
            }else{
                t++;
            }
        }else{
            s++;
        }
    }
    cout<<X.size()-cnt<<endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int MAXN = 100 * 1000 + 7;
int a[MAXN];
set<int> ra[MAXN];
int main()
{
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
#endif
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
	{
		scanf("%d", &a[i]);
		ra[a[i]].insert(i);
	}
	int res = 0;
	for (int i = 1; i <= n; i++)
	{
		if (a[a[i]] == i)
		{
			//cerr << i << endl;
			res++;
		}
	}
	printf("%d\n", res / 2);
}


Measured memory_bytes: 9984
import collections
n,k = (int(i) for i in input().split())
a = list(int(i) for i in input().split())
c = collections.Counter(a)
values,counts = zip(*c.most_common())
if len(counts) >= k:
 ans = sum(counts[k:])
else:
 ans = 0

print(ans)

Measured memory_bytes: 53808
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;



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

	int n, l, s, ss, i, j, k, s2;
	cin >> n >> l;
	s = 0;
	for (i = 1; i <= n; i++) s += l + i - 1;
	ss = 10000000;
	for (i = 1; i <= n; i++) {
		s2 = s - (l + i - 1);
		if (abs(ss - s) >= abs(s2 - s)) ss = s2;
	}
	cout << ss << "\n";

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)

int main(){
  long n,t;
  cin >> n >> t;
  vector<long> time(n);
  rep(i,n){
    cin >> time.at(i);
  }
  long answer = 0;
  rep(i,n-1){
    answer += min(time.at(i+1)-time.at(i),t);
  }
  cout << answer + t << endl;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    // TODO 自動生成されたメソッド・スタブ
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int h[] = new int[n];

    int max = 0;
    for (int i = 0; i < n; i++) {
      h[i] = sc.nextInt();
      max = Math.max(max, h[i]);
    }

    // 段数分チェック
    int cnt = 0;
    for (int i = 0; i < max; i++) {
      boolean on = false;
      for (int j = 0; j < n; j++) {
        if (h[j] - i > 0) {
          if (!on) {
            on = true;
            cnt++;
          }
        } else {
          on = false;
        }
      }
    }

    System.out.println(cnt);
  }
}


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

#define ll long long int

using namespace std;

int inf=1e9+5;

unordered_map<ll,int> s;
vector<ll> pot;
ll h,w;
void goo(ll x)
{
    ll H,W;
    W=x%inf;
    x-=x%inf;
    H=x/inf;
    for(int i=H-2;i<=H;i++)
    {
        for(int j=W-2;j<=W;j++)
        {
            if(i>=1 && i<=h && j>=1 && j<=w)
            {
                ll res=(ll)i*inf+j;
                pot.push_back(res);
            }
        }
    }
}

int cnt[10];

void doo(ll x)
{
    ll H,W;
    W=x%inf;
    x-=x%inf;
    H=x/inf;
    int res=0;
    if(H>=1 && H+2<=h && W>=1 && W+2<=w)
    {
        for(int i=H;i<=H+2;i++)
        {
            for(int j=W;j<=W+2;j++)
            {
                ll akt=(ll)i*inf+j;
                res+=s[akt];
            }
        }
    }
    else return;
    cnt[res]++;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>h>>w;
    int n; cin>>n;
    vector<ll> a;
    for(int i=0;i<n;i++)
    {
        int x,y; cin>>x>>y;
        a.push_back((ll)x*inf+y);
        s[a[i]]=1;
    }
    for(int i=0;i<n;i++)
    {
        goo(a[i]);
    }
    sort(pot.begin(),pot.end());
    for(int i=0;i<pot.size();i++)
    {
        if(i==0 || pot[i]!=pot[i-1])
        {
            doo(pot[i]);
        }
    }
    ll cnn=0;
    for(int i=1;i<=9;i++)
    {
        cnn+=cnt[i];
    }
    cout<<(ll)(w-2)*(h-2)-cnn<<endl;
    for(int i=1;i<=9;i++) cout<<cnt[i]<<endl;
    return 0;
}


Measured memory_bytes: 126964
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<list>
using namespace std;


int main()
{
	int N,K;
	cin >> N >> K;
	long long out = N - K + 1;

	cout << out << endl;

	return 0;
}

Measured memory_bytes: 888
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long n,m,c=0;
cin>>n>>m;
long long arr[n+1]={0};
for(long long i=0;i<m;i++)
{
    long long l,r;
    cin>>l>>r;
    arr[l]++;
    arr[r+1]--;
}
for(long long i=1;i<=n;i++)
    arr[i]=arr[i]+arr[i-1];
for(long long i=1;i<=n;i++)
{
    if(arr[i]==m)
        c++;
}
cout<<c;
}


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


ll arr[10000010];
int spf[10000010];

ll get(ll x){
    ll f = spf[x];
    if(spf[x] == x){
        arr[x] = 2;
        return 2;
    }
    ll temp = 0;
    ll kk = x;
    ll cnt = arr[x/f];
    x = x/f;
    while(x%f==0) x/=f , temp++;
    cnt = cnt/(temp+1);
    cnt = cnt*(temp+2);
    arr[kk] = cnt;
    return cnt;
}



void sol(){
    ll n; cin >> n;
    ll ans=1;
    for(ll i=2;i<=n;i++){
        ans += i*get(i);
     //   cout << get(i) << "\n";
    }
    cout << ans;
}

int main() {
    forr(i,10000010) spf[i] = i;
    for(int i=2;i<=10000000;i++){
        if(spf[i] == i){
            for(int j=2;j*i<=10000000;j++){
                if(spf[i*j] == i*j) spf[i*j] = i;
            }
        }
    }
    arr[1] = 1 , arr[2] = 2;
  //  for(int i=1;i<=20;i++) cout << spf[i] << " ";
    sol();
}


Measured memory_bytes: 120744
import java.util.*;
public class Main {

	public static void main(String[] args) {
		
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int a[]=new int[10001];

	
	for(int j=1;j<=Math.sqrt(n);j++) {
		for(int k=1;k<=Math.sqrt(n);k++) {
			for(int l=1;l<=Math.sqrt(n);l++) {
				int i=j*j+k*k+l*l+j*k+k*l+l*j ;
              if(i<=10000)
				a[i]++;
				
				
			}
		}
	
	}
      int sum=0;
	for(int i=1;i<=n;i++){
 System.out.println(a[i]);
}
     
	}

}


Measured memory_bytes: 38784
using System;
using System.IO;
using System.Linq;
using System.Text;

class Program
{
    static void Main(string[] args) {
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Console.WriteLine(Solve());
        Console.Out.Flush();
    }

    static object Solve() {
        var O = Console.ReadLine();
        var E = Console.ReadLine();
        var sb = new StringBuilder();
        foreach (var (odd,even) in O.Zip(E)) {
            sb.Append(odd).Append(even);
        }
        if (O.Length > E.Length) sb.Append(O[^1]);
        return sb.ToString();
    }
}

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

const double EPS = 1.0e-10;
int K;
double UB, LB, P, E, T;
double dfs(double lb, double ub, int turn){
    if(T + E + EPS < lb) return 0.0;
    if(ub < T - E - EPS) return 0.0;
    if(T - E + EPS < lb && ub < T + E - EPS) return 1.0;
    double mid = (lb + ub) / 2;
    if(turn == 0)
      return abs(T - mid) <= (EPS + E) ? 1.0 : 0.0;
    double res = 0.0;
    double p1 = 1.0 - P, p2 = P;
    if((T - EPS) <= mid) swap(p1, p2);
    res += dfs(mid, ub, turn - 1) * p1;
    res += dfs(lb, mid, turn - 1) * p2;
    return res;
}
int main(){
    scanf("%d%lf%lf%lf%lf%lf", &K, &LB, &UB, &P, &E, &T);
    printf("%.10f\n", dfs(LB, UB, K));
    return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.first<<","<<p.second<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
#else
#define dbg(...) {}
#endif

int main(){
  int n;
  cin>>n;
  int t,a;
  cin>>t>>a;
  vector<int> v(n);
  rep(i,n) cin>>v[i];
  rep(i,n) v[i] = t*1000 - v[i]*6;
  a *= 1000;

  int ans = 0;
  rep(i,n) if(abs(a - v[i]) < abs(a - v[ans])) ans = i;

  cout << ans+1 << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

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

    int ans = 0;
    int minv = 10000000;
    for(int i=0; i<N; ++i){
        if(minv > abs(a[i])){
            minv = abs(a[i]);
            ans = sum-a[i];
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
using namespace std;
/*
3 8
0 1 2 3 4 5 6 7 8
3 30
4 50
5 60
 */

void solve(long w, int W, long v, vector<long long>& dp){
    for(int i = W; i>=w; i--){
        dp[i] = max(dp[i], v +  dp[i-w]);
    }
}

int main(){
    int n, W;
    cin >> n >> W;
    vector<long long> dp(W+1);
    for(int i = 0; i<n; i++){
        long w, v;
        cin >> w >> v;
        solve(w, W, v, dp);
    }
    cout << *max_element(dp.begin(), dp.end());
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
typedef long long ll;

int main() {
    
    ll N,M,V,P;
    cin>>N>>M>>V>>P;
    vector<ll> A(N);
    rep(i,N)cin>>A[i];
    sort(all(A), greater<ll>());
    //xは0-indexed
    auto check = [&](ll x){
        //0 ~ P-1はOK
        if(x < P){
            return true;
        }
        if(A[x] + M < A[P-1]){
            return false;
        }
        ll sum = 0;
        rep(i,N){
            if(i < P-1 || x <= i)sum+= M;
            else{
                sum += A[x] + M - A[i];
            }
        }
        return M * V <= sum;
    };
    ll ok = -1;
    ll ng = N;
    while(ng - ok > 1){
        ll mid = (ok + ng) / 2;
        if(check(mid)){
            ok = mid;
        }
        else{
            ng = mid;
        }
    }
    cout<<ok + 1<<endl;
}

Measured memory_bytes: 1024
/* C++14 (Clang 3.8.0) for AtCoder */

#include <iostream>
#include <vector>
#include <string>
// #include <cmath>
// #include <math.h>
// #include <map>
// #include <algorithm>

namespace AtCoder {
	using Str = std::vector<std::string>;
	using Num = std::vector<int>;

	class Ans {
	public:
		void showResult(void);
		void increment(void);
		void increment(double);
		void decrement(void);
		void decrement(double);
		double getResult(void);
	private:
		double result;
	};
	void Ans::showResult(void) {
		printf("%.0lf\n", this->result);
	}
	void AtCoder::Ans::increment(void) {
		this->result++;
	}
	void AtCoder::Ans::increment(double value) {
		this->result += value;
	}
	void AtCoder::Ans::decrement(void) {
		this->result--;
	}
	void AtCoder::Ans::decrement(double value) {
		this->result -= value;
	}
	double AtCoder::Ans::getResult(void) {
		return this->result;
	}

	void input(Str* str) {
		str->clear();
		std::string buf = "", row = "";
		std::getline(std::cin, buf);
		for (unsigned int i = 0; i < buf.size(); i++) {
			if (' ' == buf[i]) {
				str->push_back(row);
				row = "";
			} else {
				row += buf[i];
			}
		}
		str->push_back(row);
	}
	void input(Num* num) {
		num->clear();
		std::string buf = "", row = "";
		std::getline(std::cin, buf);
		for (unsigned int i = 0; i < buf.size(); i++) {
			if (' ' == buf[i]) {
				num->push_back(std::atoi(row.c_str()));
				row = "";
			} else {
				row += buf[i];
			}
		}
		num->push_back(std::atoi(row.c_str()));
	}
	void exp(std::string* str,  Str* newStr) {
		std::string pre = *str;
		newStr->clear();
		for (unsigned int i = 0; i < pre.length(); i++) {
			newStr->push_back(pre.substr(i, 1));
		}
	}
}

int main(void) {

	AtCoder::Num s;
	AtCoder::input(&s);

	const int n = s[0];

	AtCoder::Ans* ans = new AtCoder::Ans();

	ans->increment(n / 2);

	int buf = ans->getResult();
	if (n == buf + buf) {
		ans->decrement();
	}

	ans->showResult();

	delete(ans);

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int a,b;
char op;

int main(){
  while(1){
  scanf("%d %c %d",&a,&op,&b);
  switch(op){
    case '?' : return 0;
    case '+' : printf("%d\n",a+b);break;
    case '-' : printf("%d\n",a-b);break;
    case '*' : printf("%d\n",a*b);break;
    case '/' : printf("%d\n",a/b);break;
  }
}
}

Measured memory_bytes: 2684
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
#define ct(a) cout<<a<<endl
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;


int N;
int P[100005];
int cnt;

int main() {
	cin.tie(0);
	cout.tie(0);

	ios::sync_with_stdio(false);

	cin >> N;
	FOR(i, 0, N) {
		cin >> P[i+1];
	}


	FOR(i, 1, N+1) {
		if (P[i] == i) {
			if (i != N) {
				swap(P[i], P[i + 1]);
			}
			else {
				swap(P[i], P[i - 1]);
			}
			cnt++;
		}
	}
	cout << cnt << endl;

	return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
int partition(int* , int , int );
int main(){
  int n,inx,A[100000],tmp,i;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  inx=partition(&A[0],0,n-1);
  //tmp=A[n-1];
  //A[n-1]=A[inx];
  //A[inx]=tmp;
  for(i=0;i<inx;i++){
    if(i>0) printf(" ");
    printf("%d",A[i]);
  }
  printf(" ");
  printf("[");
  printf("%d",A[inx]);
  printf("]");
  for(i=inx+1;i<n;i++){
    printf(" %d",A[i]);
  }
  printf("\n");
  return 0;
}
int partition(int* A, int p, int r ){
  int x,i,tmp,j;
  x = A[r];
  i = p-1;
  for(j=p;j<r;j++){
    if(A[j] <= x){
      i = i + 1;
      tmp=A[i];
      A[i]=A[j];
      A[j]=tmp;
    }
  }
    tmp=A[i+1];
    A[i+1]=A[r];
    A[r]=tmp;
  
  return i+1;
}

Measured memory_bytes: 992
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect# lower_bound etc
#import numpy as np
#from copy import deepcopy
#from collections import deque
import math

def solve():
    N = int(sysread())
    KLR_left, KLR_right = [], []
    counts_l, counts_r = [0] * (N+1), [0] * (N+1)

    for _ in range(N):
        k,l,r = map(int, sysread().split())
        if l>r:
            KLR_left.append((k, l, r))
            counts_l[k] += 1
        else:
            KLR_right.append((k, l, r))
            counts_r[k] += 1

    KLR_left = sorted(KLR_left, key = lambda x:x[0], reverse=True)
    KLR_right = sorted(KLR_right, key=lambda x:x[0])
    queue_left = []
    queue_right = []
    dump = []
    SUM = 0
    for i in range(1, N+1):
        for j in range(counts_l[i]):
            k, l, r = KLR_left.pop()
            heappush(queue_left, (l-r, l, r))
            SUM += l

        while True:
            if len(queue_left)>i:
                l_r, l, r = heappop(queue_left)
                dump.append((l_r, l, r))
                SUM -= l_r
            else:break


    #print(filled_left)
    for i in list(range(1, N+1))[::-1]:
        for j in range(counts_r[i]):
            k, l, r = KLR_right.pop()
            heappush(queue_right, (r-l, l, r))
            SUM += r
        while True:
            if len(queue_right) > N-i:
                try:
                    r_l, l, r = heappop(queue_right)
                except:break
                dump.append((r_l, l, r))
                SUM -= r_l
            else:break
    return SUM

def run():
    T = int(sysread())
    for i in range(T):
        print(solve())



if __name__ == "__main__":
    run()


Measured memory_bytes: 135968
a,b,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

ans=min(a)+min(b)
temp=0

for i in range(m):
  x,y,c=map(int,input().split())
  temp = a[x-1]+b[y-1]-c
  ans = min(ans,temp)

print(ans)

Measured memory_bytes: 18736
#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 mod 1000000007
typedef long long ll;

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

    cout<<(t/a)*b<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define X first
#define Y second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define ini(x, y) memset(x, y, sizeof(x))
#define endl '\n'
#define fastio cin.sync_with_stdio(false); cin.tie(nullptr)
using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MOD = 1e9 + 7;
const int dx[] = { -1, 0, 1, 0, -1, 1, 1, -1 };
const int dy[] = { 0, 1, 0, -1, 1, 1, -1, -1 };

int main() {
	fastio;
	int x;
	cin >> x;

	ll ans = x / 500ll * 1000;
	x %= 500;

	cout << ans + x / 5 * 5;

	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := newInputScanner(true, 64)
	a, b, c := sc.nextInt(), sc.nextInt(), sc.nextInt()
	var answer string
	diff := c - (a + b)
	if diff < 0 {
		answer = "No"
	} else {
		if 4*a*b < diff*diff {
			answer = "Yes"
		} else {
			answer = "No"
		}
	}
	fmt.Println(answer)
}

type inputScanner struct {
	*bufio.Scanner
}

func newInputScanner(enabledScanWords bool, sizeInKB int) *inputScanner {
	scanner := bufio.NewScanner(os.Stdin)
	if enabledScanWords {
		scanner.Split(bufio.ScanWords)
	}
	capacity := sizeInKB * 1024
	buf := make([]byte, capacity)
	scanner.Buffer(buf, capacity)
	return &inputScanner{
		Scanner: scanner,
	}
}

func (inputSc *inputScanner) nextInt() int {
	i, e := strconv.Atoi(inputSc.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (inputSc *inputScanner) nextUInt64() uint64 {
	i, e := strconv.ParseUint(inputSc.nextStr(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

func (inputSc *inputScanner) nextStr() string {
	inputSc.Scan()
	return inputSc.Text()
}


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

int main(){
    int h,w; cin >> h >> w;
    char a[h+2][w+2];
    for(int i = 0; i < h+2; i++){
        for(int j = 0; j < w+2; j++){
            a[i][j] = '.';
        }
    }

    int c = 0;
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            cin >> a[i][j];
            if(a[i][j] == '#') c++;
        }
    }
    int i = 1, j = 1;
    while(i != h || j != w){
        if(a[i+1][j] == '#'){i++; c--; continue;}
        if(a[i][j+1] == '#'){j++; c--; continue;}
        else break;
    }
    if(c == 1) cout << "Possible" << endl;
    else cout << "Impossible" << endl;

    return 0;
}

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

int main() {
  int a,b,c,M,m,n;
  cin >>a>>b>>c;
  
  M=max({a,b,c});
  m=min({a,b,c});
  n=a+b+c-M-m;
  
  if(M==m+n){
    cout <<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main(){
    ll n,t; cin>>n>>t;
    vector<vector<pair<ll,ll>>> dp(n+1,vector<pair<ll,ll>>(t+1,{0,0}));
    //dp[n番目まで][時間]
    rep(i,n){
        ll a,b; cin>>a>>b;
        rep(j,t+1){
            dp[i+1][j]=dp[i][j];
            if(j>a){
                if(dp[i+1][j].first+dp[i+1][j].second<dp[i][j-a].first+b+dp[i][j-a].second){
                    dp[i+1][j].first=dp[i][j-a].first+b;
                    dp[i+1][j].second=dp[i][j-a].second;
                    continue;
                }
            }
            chmax(dp[i+1][j].second,b);
        }
    }
    cout<<dp[n][t].first+dp[n][t].second<<endl;
    return 0;
}

Measured memory_bytes: 141184
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 100000000;
const ll half_inf = 0x3f3f3f3f;
const ll inf = 0x7fffffff;
const ll mod = 998244353;
const ll maxn = 2000005;
string s1,s2; 
int main(){
	cin>>s1;
	cin>>s2;
	for(int i=0;i<s1.size();i++){
		if(s1[i]!=s2[i]){
			printf("No");
			return 0;
		}
	}
	printf("Yes");
	
	return 0;
}





Measured memory_bytes: 3764
N = int(input())
SP = [list(input().split()) for i in range(N)]

sorted_SP = sorted(SP, key=lambda x:int(x[1]), reverse=True)
sorted_SP = sorted(sorted_SP, key=lambda x:x[0])

for i in range(N):
  for j in range(N):
    if sorted_SP[i][0] == SP[j][0] and sorted_SP[i][1] == SP[j][1]:
      print(j+1)
      break

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

char buf[100];

int main(){
	scanf("%s", buf);
	char key[] = "YAKI";
	int l = strlen(buf);
	if(l<4) puts("No");
	else{
		buf[4] = '\0';
		if(strcmp(key, buf) == 0) puts("Yes");
		else puts("No");
	}
}


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

#define fi first
#define se second
#define FO(x, n) for (int x = 0; x < n; ++x)
#define FOR(x, a, b) for (int x = a; x < b; ++x)
#define RFO(x, n) for (int x = n - 1; x >= 0; --x)
#define RFOR(x, a, b) for (int x = b - 1; x >= a; --x)
#define FOR_ITER(x, a) for(auto x = a.begin(); x != a.end(); ++x)

using namespace std;

typedef unsigned char byte;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<string, string> pss;
typedef pair<ll, ll> pll;
inline bool feq(const double& a, const double& b) { return fabs(a - b) < 1e-10; }



int gcd(int a, int b) {
    if (b == 0) {
        return a;
    }
    if (a < b) {
        swap(a, b);
    }
    return gcd(b, a % b);
}



int main(){
//    int n, l;
//    cin >> n >> k;
//    vector<bool> dislike(10, false);
//
//    FOR(i, 0, k) {
//        int t;
//        cin >> t;
//        dislike[t] = true;
//    }


    int a, b, c;

    cin >> a >> b >> c;

    int d = gcd(a, b);

    if (c % d == 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define   mt         make_tuple
#define   Y            imag()
#define   X            real()
#define    clr(v,d)      memset( v, d ,sizeof(v))
#define   angle(n)      atan2((n.imag()),(n.real()))
#define   vec(a,b)       ((b)-(a))
//#define   length(a)      hypot( (a.imag()),(a.real()) )
#define   normalize(a)      (a)/(length(a))
#define    dp(a,b)          (((conj(a))*(b)).real())
//#define    cp(a,b)          (((conj(a))*(b)).imag())
#define    lengthsqrt(a)       dp(a,a)
#define    rotate0( a,ang)    ((a)*exp( point(0,ang) ))
#define    rotateA(about,p,ang)   (rotate0(vec(about,p),ang)+about)
#define    reflection0(m,v)         (conj((v)/(m))*(m))
#define     reflectionA(m,v,p0)     (conj( (vec(p0,v))/(vec(p0,m)) ) * (vec(p0,m)) ) + p0
//#define     same(p1,p2)               ( dp(  vec(p1,p2),vec(p1,p2)) < eps )
#define     point                    complex<double>
#define outfile freopen("out.out", "w", stdout);
#define infile  freopen("in.in", "r", stdin);
#define PI acos(-1)
typedef  long long     ll ;
typedef  unsigned long long ull;
const double eps= (1e-9);
using namespace std;
int dcmp(double a,double b){   return fabs(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
int getBit(int num, int idx) {return ((num >> idx) & 1) == 1;}
ll setBit1(ll num, int idx) {return num | (1ll<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(int num, int idx) {return num ^ (1<<idx);}
void FS(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
const int N=109;
map<pair<int,ll>,ll> mem;
int n,V[N],W[N];
int w;
ll solve(int id,ll co)
{
    if(id==n)
        return 0;
    if(mem.find(mp(id,co))!=mem.end())
        return mem[mp(id,co)];
    ll ans=0;
    if(co+W[id]<=w)
    ans=max(ans,V[id]+solve(id+1,co+W[id]));
    ans=max(ans,solve(id+1,co));
    return mem[mp(id,co)]=ans;
}
int main()
{
    FS();
    cin>>n>>w;
    for(int i=0;i<n;i++)
    {
        cin>>W[i]>>V[i];
    }
    cout<<solve(0,0)<<endl;
}



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

using namespace std;

typedef long long int ll;
typedef vector<ll> vll;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define fin(ans) cout << (ans) << endl;
#define all(a) a.begin(), a.end()

template <typename T>
void V(T &n)
{
  for (ll i = 0; i < n.size(); i++)
  {
    cin >> n[i];
  }
}

template <typename T>
void Sort(T &n, ll a = 0, ll b = 0)
{
  if (b == 0)
  {
    return (sort(n.begin() + a, n.end()));
  }
  else
  {
    return (sort(n.begin() + a, n.begin() + b));
  }
}

template <typename T>
void Reve(T &n, ll a = 0, ll b = 0)
{
  if (b == 0)
  {
    return (reverse(n.begin() + a, n.end()));
  }
  else
  {
    return (reverse(n.begin() + a, n.begin() + b));
  }
}

template <typename T, typename U>
void Copy(T &n, U &m, ll a = 0, ll b = 0)
{
  copy(all(n), m.begin());
}

void Main()
{
  ll n;cin >> n;
  vll a(n), b(n); V(a);
  Copy(a, b);
  Sort(b); Reve(b);
  if(b[0] == b[1])
  {
    rep(i, n)
    {
      fin(b[0])
    }
    exit(0);
  }
  else
  {
    rep(i, n)
    {
      if(a[i] == b[0]) fin(b[1])
      else fin(b[0])
    }
    exit(0);
  }
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20);
  Main();
  return 0;
}


Measured memory_bytes: 4736
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

char ba[20][20];
int dp[2][1<<19][2];
const int mod = 1e5;
int pow3[401];
int qnum[20][20];

inline void add(int &a, int b) {
  a = (a+b) % mod;
}

int main() {
  pow3[0] = 1;
  REP(i,400) pow3[i+1] = (pow3[i] * 3) % mod;
  int h, w;
  while(cin >> h >> w) {
    REP(i,h)REP(j,w)cin>>ba[i][j];
    memset(qnum,0,sizeof(qnum));
    int num = 0;
    for (int i=h-1;i>=0;--i) {
      for (int j=w-1; j>=0; --j) {
        qnum[i][j] = num;
        if (ba[i][j] == '?') num++;
      }
    }
    memset(dp,0,sizeof(dp));
    dp[0][0][0] = 1;
    int ans = 0;
    int ct = 0;
    REP(i,h) {
      REP(j,w) {
        int now = ct&1;
        int nxt = (ct+1)&1;
        REP(S,1<<(w-1)) REP(k,2) dp[nxt][S][k] = 0;
        REP(S,1<<(w-1)) {
          // cout << i << " " << j << " " << S << " " << dp[now][S][0] << " " << dp[now][S][1] << endl;
          int T = S&~(1<<j);
          if (ba[i][j]=='?' || ba[i][j]=='J') {
            add(dp[nxt][T][1], dp[now][S][0]+dp[now][S][1]);
          }
          if (ba[i][j]=='?' || ba[i][j]=='O') {
            add(dp[nxt][T][0], dp[now][S][0]);
            if (j) add(dp[nxt][T|1<<(j-1)][0], dp[now][S][1]);
            else add(dp[nxt][T][0], dp[now][S][1]);
          }
          if (ba[i][j]=='?' || ba[i][j]=='I') {
            if (j<w-1 && (S>>j&1)) {
              add(ans, (ll)(dp[now][S][0]+dp[now][S][1]) * pow3[qnum[i][j]] % mod);
            } else {
              add(dp[nxt][T][0], dp[now][S][0] + dp[now][S][1]);
            }
          }
        }
        ct++;
      }
    }
    cout << ans << endl;
  }
}

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

using namespace std;
using ll = long long;

template <typename K,typename V>
using umap = unordered_map<K,V>;
template <typename V>
using uset = unordered_set<V>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i,n) for(int i=0;i<n;i++)
#define REPD(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(v) v.begin(),v.end()

#define endl "\n"
#define INF 1'000'000'000'000 //10^12
#define MOD 1'000'000'007
//グリッドグラフの範囲チェック
bool range_validation(int y,int x,int h,int w){
    return y>=0 && y<h && x>=0 && x < w;
}
//ビットカウント
int popcount(long bits){
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int gcd(ll a, ll b){
  if(b == 0){
    return a;
  }else{
    return gcd(b,a%b);
  }
}

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);

  int n,k;
  cin >> n >> k;
  vector<int> count(n+1,0);
  int a;
  REP(i,n){
    cin >> a;
    count[a]++;
  }
  vector<int> p;
  REP(i,n+1){
    if(count[i] > 0){
      p.push_back(count[i]);
    }
  }

  sort(ALL(p));

  int len = (int)p.size();
  int res = 0;
  int idx = 0;
  while(len > k){
    res += p[idx];
    idx++;
    len--;
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 4884
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
using namespace std;
int main(){
    char s[10][10];
    for(int i=0;i<8;i++)cin>>s[i];

    cout<<90<<endl;
    for(int i=0;i<8;i++){
        for(int j=7;j>=0;j--)cout<<s[j][i];
        cout<<endl;
    }


    cout<<180<<endl;
    for(int i=7;i>=0;i--){
        for(int j=7;j>=0;j--)cout<<s[i][j];
        cout<<endl;
    }

    cout<<270<<endl;
    for(int i=7;i>=0;i--){
        for(int j=0;j<8;j++)cout<<s[j][i];
        cout<<endl;
    }
}

Measured memory_bytes: 1140
from sys import stdin


def main():
    lines = stdin.readlines()
    N, K = map(int, lines[0].split())
    bn = [0] * (int(1e5) + 1)
    for line in lines[1:]:
        ai, bi = map(int, line.split())
        bn[ai] += bi
    cnt = 0
    for ai, bi in enumerate(bn):
        cnt += bi
        if K <= cnt:
            print(ai)
            break
    return


main()


Measured memory_bytes: 13844
#include<iostream>
#include<string>
#include<stdio.h>
#include<cctype>
#include<algorithm>
#include<climits>
#include<cmath>
#include<map>
#include<vector>
#define INF INT_MAX
using namespace std;

long long N;
string name;

int main(){
	cin >> N;
	while (N != 0){
		N--;
		name += ('a' + (N % 26));
		N /= 26;
	}

	reverse(name.begin(), name.end());
	cout << name << endl;

	return 0;
}

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

using namespace std;

const int INF = 10000000;

class TeamInfo {
public:
	int id;
	char name;
	int win, lost;
};

TeamInfo TeamData[10];
int N;

void init() {
	for (int i = 0; i < 10; i++) {
		TeamData[i].name = '\0';
		TeamData[i].win = TeamData[i].lost = 0;
	}
}

bool cmp(const TeamInfo &t1, const TeamInfo &t2) {
	if (t1.win == t2.win && t1.lost == t2.lost) {
		return t1.id < t2.id;
	}
	if (t1.win == t2.win) {
		return t1.lost < t2.lost;
	}
	return t1.win > t2.win;
}

int main(){
	int num, size;
	string str;

	while (cin >> N, N) {
		getchar();
		init();
		for (int i = 0; i < N; i++) {
			TeamData[i].id = i;
			str = "";
			getline(cin, str);
			//cout << "str:" << str.size() << " " << str << endl;
			TeamData[i].name = str[0];
			//cout << TeamData[i].name << " ";
			size = str.size();
			for (int j = 2; j < size; j += 2) {
				num = str[j] - '0';
				//cout << num << " ";
				if (num == 0) {
					++TeamData[i].win;
				}
				else if (num == 1) {
					++TeamData[i].lost;
				}
			}
		}
		sort(TeamData, TeamData + N, cmp);
		for (int i = 0; i < N; i++) {
			cout << TeamData[i].name << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 3124
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===

def main():
    n = ni()
    a = na()

    dp = [[0 for _ in range(n + 1)] for _ in range(n + 1)]

    for d in range(1, n + 1):
        for l in range(n - d + 1):
            r = l + d

            # second
            if (n - d) % 2:
                dp[l][r] = min(dp[l + 1][r] - a[l], dp[l][r - 1] - a[r - 1])

            # first
            else:
                dp[l][r] = max(dp[l + 1][r] + a[l], dp[l][r - 1] + a[r - 1])

    print(dp[0][n])


if __name__ == '__main__':
    main()


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

using namespace std;

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

const int INF = 1000000000; //
const ll LINF = (ll) 4000000000000000000; //
const ll MOD = (ll) 1000000007; //
const double PI = acos(-1.0); //

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define repll(i,n) for(ll i=0;i<(ll)(n);i++)
#define repll2(i,n) for(ll i=1;i<=(ll)(n);i++)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())

//------------------------------------------------------

int main() {
    ll n, k;
    cin >> n >> k;
    ll a[n];

    rep(i, n) {
        cin >> a[i];
    }

    ll csum_a[n + 1], csum_b[n + 1];
    csum_a[0] = csum_b[0] = 0;

    rep(i, n) {
        csum_a[i + 1] = csum_a[i] + a[i];
        csum_b[i + 1] = csum_b[i] + max(0LL, a[i]);
    }

    ll ans = -LINF;

    //区間を黒で確定する場合

    rep2(i, n) {
        if (i + k > n + 1) break;
        ll subscore = csum_b[n] - csum_b[i + k - 1] + csum_b[i - 1]
                + csum_a[i + k - 1] - csum_a[i - 1];
        ans = max(ans, subscore);
    }

    //区間を白で確定する場合

    rep2(i, n) {
        if (i + k > n + 1) break;
        ll subscore = csum_b[n] - csum_b[i + k - 1] + csum_b[i - 1];
        ans = max(ans, subscore);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2560
N=input()
a=map(int,raw_input().split())
#print N
#print a

b=[]
for i in range(1,N+1):
	b.append( abs((N-i)-(i-1)) )

#print b

a.sort()
b.sort()
if a != b:
	print 0
else:
	k=len(a)/2
	print 2**k%(10**9+7)


Measured memory_bytes: 12648
unittest
{
	assert( [ "4", "2 4", "4 3", "9 3", "100 5" ].parse.expand.solve == 3 );
	assert( [ "2", "8 20", "1 10" ].parse.expand.solve == 1 );
	assert( [ "5", "10 1", "2 1", "4 1", "6 1", "8 1" ].parse.expand.solve == 5 );
	
	assert( [ "3", "10 5", "11 1", "12 1" ].parse.expand.solve == 1 );		// 追加ケース
	assert( [ "3", "10 5", "11 1", "13 1" ].parse.expand.solve == 2 );		// 追加ケース
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	auto xls = new long[ 2 ][ n ];
	foreach( ref ab; xls )
	{
		input.popFront;
		ab = input.front.split.to!( long[] );
	}
	return tuple( xls );
}

auto solve( long[ 2 ][] xls )
{
	// 入力を腕が動く範囲に変換
	auto lrs = new long[ 2 ][ xls.length ];
	foreach( ref lr, xl; lockstep( lrs, xls ) )
	{
		lr = [ xl[ 0 ] - xl[ 1 ], xl[ 0 ] + xl[ 1 ] ];
	}
	lrs.sort!( ( a, b ) => a[ 1 ] < b[ 1 ] );
	
	// 腕が動く範囲の右端がより左にあるロボットを残す
	auto ans = 0L;
	auto p = long.min;
	foreach( lr; lrs )
	{
		if( lr[ 0 ] < p ) continue;
		p = lr[ 1 ];
		ans++;
	}
	return ans;
}


Measured memory_bytes: 5372
#include <iostream>
using namespace std ;
int main () {

int a , b;
cin >> a >> b ;
if (( b== 1 ) && ((a>=2 && a<=13))){
    cout << "Bob";
}
else if (( a== 1 ) && ((b>=2 && b<=13))){
    cout << "Alice";
}
else if (a> b){
    cout << "Alice";
}
else if (a< b){
    cout << "Bob";
}
else {
    cout << "Draw" ;
}

 return 0 ;
}


Measured memory_bytes: 256
n,m = map(int,input().split())
x = list(map(int,input().split()))
dif = []
x.sort()

for i in range(len(x)-1):
    dif.append(abs(x[i]-x[i+1]))
    
dif.sort(reverse=True)

ans = sum(dif[n-1:])
print(ans)

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

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

int main(){
  int n;
  cin >> n;
  int a1;
  cin >> a1;
  for(int i=0; i<n-1; i++){
    int a;
    cin >> a;
    a1=gcd(a1, a);
  }
  cout << a1;
  return 0;
}

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

#define F first
#define S second
#define MP make_pair
#define PB push_back

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
typedef vector < ll > vl;

const int MAXN = 1e5 + 500;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int LOG = 18;
const double EPS = 1e-9;
const double PI = 3.1415926535;

ll dp[105][MAXN], w[105], v[105];

int main() {
    ll N, W, ans = 0;

    cin >> N >> W;
    for(int i = 1; i <= N; i++)
        cin >> w[i] >> v[i];

    for(int i = 1; i <= N; i++)
        for(int j = 0; j <= W; j++)
            if(j < w[i])
                dp[i][j] = dp[i - 1][j];
            else
                dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]);

    for(int i = 0; i <= W; i++)
        ans = max(ans, dp[N][i]);
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 79360