akhauriyash/Code-Regression huggingface dataset:
n=int(input())
li = list(map(int,input().split()))

ans_li=list()
ans=0
for i in range(101):
  for p in range(n):
    x=(li[p]-i)**2
    ans+=x
    if p==n-1:
      ans_li+=[ans]
      ans=0
    
  
  
  
print(min(ans_li))

Measured memory_bytes: 39280
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
using namespace std;
typedef long long ll;

ll mod = 1e9+7;

int main(){
    int n;
    cin >> n;
    vector<int> a(n+1);
    for (int i=0;i<n+1;i++){
        cin >> a[i];
    }
    ll ans = 0;
    for (int i=0;i<n;i++){
        int b;
        cin >> b;
        if (a[i]>=b){
            ans += b;
        } else {
            ans += min(a[i]+a[i+1],b);
            a[i+1] = max(a[i+1]-(b-a[i]),0);
        }
    }
    cout << ans << endl;
}

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

using namespace std;


int main(){
	int N;
	cin >> N;
	int s[N];
	int sum = 0;
	int minpoint=1000;
	for(int i=0;i<N;i++){
		cin >> s[i];
		sum += s[i];
	}

	if(sum % 10 != 0){
		cout  << sum <<endl;
		return 0;
	}

	else{
		for(int i = 0; i < N; i++){
			if(s[i] % 10 != 0)
				minpoint = min(minpoint, s[i]);
		}
		if(minpoint == 1000)
			cout << 0 << endl;
		else
			cout << sum - minpoint << endl;	
	}

	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <string>
#include <iostream>
#include <limits.h>
#include <algorithm>

#define Int long long
#define rep(i, n) for (Int i = 0; i < n; i++)
#define in(params) cin >> params;
#define p(params) cout << params << endl;
#define mod 1000000007LL

using namespace std;

int main()
{
    Int K, X;
    cin >> K >> X;

    for (Int i = X - K + 1; i < X + K; i++)
    {
        cout << i << " ";
    }

    cout << endl;

    return 0;
}

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

int main(){
    int N; cin >> N;
    vector<int> ar(N);
    for (int n(0); n < N; ++n){
        cin >> ar[n];
    }
    sort(ar.begin(),ar.end());
    int sum(0);
    for (int j(0); j < N-1; ++j){
        sum += ar[j];
    }
    if (sum > ar[N-1]){
        cout << "Yes";
    } else cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<cstdlib>
#define cmax(a,b) (a<(b)?a=(b),1:0)
#define cmin(a,b) (a>(b)?a=(b),1:0)
#define dmin(a,b) ((a)<(b)?(a):(b))
#define dmax(a,b) ((a)>(b)?(a):(b))
#define regsiter register
#define CL fclose(stdin),fclose(stdout)
namespace io
{
	int F()
	{
		int n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=(n<<1)+(n<<3)+ch-'0';
		return F?n:-n;
	}
	long long G()
	{
		long long n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=(n<<1)+(n<<3)+ch-'0';
		return F?n:-n;
	}
}
int cnt[222222];
int main()
{
	int n=io::F(),k=io::F();
	for(register int i=1;i<=n;++i)
		++cnt[io::F()];
	std::sort(cnt+1,cnt+n+1);
	int sum=n;
	for(register int i=n-k+1;i<=n;++i)
		sum-=cnt[i];
	printf("%d\n",sum);
	return 0;
}




Measured memory_bytes: 896
#include <algorithm>
#include <cstdio>
#include <cstdlib>

const int MaxN = 2000;

int N, X, Y;
int Dis[MaxN + 5][MaxN + 5];
int Buc[MaxN + 5];

int main() {
  scanf("%d %d %d", &N, &X, &Y);
  for (int i = 1; i <= N; ++i) {
    for (int j = i; j <= N; ++j) {
      Dis[i][j] = j - i;
      int dx = abs(i - X), dy = abs(j - Y);
      Dis[i][j] = std::min(Dis[i][j], dx + dy + 1);
      Buc[Dis[i][j]]++;
    }
  }
  for (int i = 1; i <= N - 1; ++i) printf("%d\n", Buc[i]);
  return 0;
}

Measured memory_bytes: 15232
#!/usr/bin/env python3
import sys
from itertools import groupby


def solve(N: int, K: int, S: str):
    L = [len(list(g)) for k, g in groupby(S)]
    score = N - len(L)
    plus = min(2*K, len(L)-1)
    score += plus
    print(score)
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, K, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 45424
#include <iostream>
using namespace std;
bool have[101];
int main(void) {
  int N, K;
  cin >> N >> K;

  for (int i = 1; i <= N; i++) {
    have[i]= false;
  }

  for (int i = 1; i <= K; i++) {
    int d;
    cin >> d;
    for (int j = 1; j <= d; j++) {
      int A;
      cin >> A;
      have[A] = true;
    }
  }

  int ans = 0;
  for (int i = 1; i <= N; i++) {
    if (!have[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}


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

#define rp(i, k, n) for (int i = k; i < n; i++)
using ll = long long;
using ld = double;

template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7ll;
// const ll MOD = 998244353;
const double PI=3.14159265358979323846;

int main() {
    int x, y; cin >> x >> y;
    if(x%y == 0) cout << -1 << endl;
    else cout << x << endl;
    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;




int main()
{
    ll n,m;
    cin >> n >> m;
    if(abs(n-m) > 1){
        cout << 0 << endl;
        return 0;
    }
    
    if(n < m) swap(n,m);
    
    vl a(n+1);
    a[1] = 1;
    reps(i,1,n) a[i+1] = a[i]*(ll)(i+1)%mod;

    if(n == m){
        cout << a[n]*a[m]*2%mod << endl;
    }else{
        cout << a[n]*a[m]%mod << endl;
    }
    
    
    
    

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i, n) cin >> p[i];
    int ans = 0;
    rep1(i, n-1){
        vector<int> a(3);
        rep(j, 3) a[j] =p[i-1+j];
        sort(all(a));
        if(a[1] == p[i]) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL a[2003];
int main()
{
    int n;
    LL z, w;
    scanf("%d%lld%lld",&n,&z,&w);
    for(int i=1; i<=n; ++i) scanf("%d",&a[i]);
    if(n == 1) printf("%lld\n",llabs(a[1]-w));
    else
        printf("%lld\n",max(llabs(a[n-1]-a[n]), llabs(a[n]-w)));
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        for (int i = 1; i <= 5; i++) {
            int n = sc.nextInt();
            if (n == 0) {
                System.out.println(i);
                break;
            }

        }
        sc.close();
    }
}


Measured memory_bytes: 35568
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(void)
{
	int n, k;
	cin >> n >> k;
	vector<int> h(n);
	for (int i = 0; i < n; i++) cin >> h[i];
	sort(h.begin(), h.end());
	k = min(n, k);
	long long ans = 0;
	for (int i = 0; i < k; i++)
	{
		h.pop_back();
	}
	for (int i = 0; i < h.size(); i++)
	{
		ans+=h[i];
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,k;
    cin>>n>>k;
    vector<int> v(n);
    for(int i=0;i< n;i++)
    {
        cin>>v[i];
        
    }
    vector<int > dp(n,INT_MAX);
   dp[0]=0;
    for(int i=1;i<n;i++)
    {
      for(int j=1;j<=k;j++){
        
        if(i>=j) dp[i]=min(dp[i],dp[i-j]+abs(v[i-j]-v[i]));
      }
    }
    cout<<dp[n-1]<<'\n';
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define In_The_Name_Of_Allah_The_Merciful ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define Alhamdulillah return 0;
#define debug(n) cerr << "[" << #n << " = " << n << "]" << endl 

struct Fenwick {

    #define T ll

    vector <T> bit;
    int sz;

    void init (int n){
        sz = (1 << (int)ceil(log2(n+1)));
        bit.resize(sz+1);
    }

    T query (int x){
        T sum = 0;
        for(; x ; x -= x&-x){
            sum += bit[x];
        }
        return sum;
    }

    void update(int x , T val){
        for(; x <= sz ; x += x&-x)
            bit[x] += val;
    }

    T Sum (int st , int en){
        return query(en) - query(st-1);
    }

    void Clear (){
        for (int i = 0 ; i <= sz ; ++i)
            bit[i] = 0;
    }


    int FindIdx (T v){
        int l = 1 , r = sz;
        while (l < r){
            int mid = l + (r-l) / 2;
            if (bit[mid] < v)
                l = mid + 1 , v -= bit[mid];
            else
                r = mid;
        }
        return l;
    }

};

void Suhaib_Sawalha (){

    Fenwick fen;
    int n;
    ll k;
    cin >> n >> k;
    int a , b;
    fen.init(1e5);
    while (n--){
        cin >> a >> b;
        fen.update(a,b);
    }

    int mx = 1e5;
    for (int i = 1 ; i <= mx ; ++i){
        ll r = fen.Sum(i,i);
        if (r >= k){
            cout << i;
            return;
        }
        k -= r;
    }

}

int main(){
                                In_The_Name_Of_Allah_The_Merciful   /* بسم الله الرحمن الرحيم  */
#ifndef ONLINE_JUDGE
    freopen("SuhaibSawalha1.txt","r",stdin);
#endif
//int _;for(cin>>_;_;--_,cout<<'\n')
        Suhaib_Sawalha();
                                         Alhamdulillah                    /* الحمد لله */
}

Measured memory_bytes: 4260
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
var w=Arr.shift();
var n=Arr.shift();
var arr=[0];
for(var i=1;i<=w;i++)arr[i]=i;
for(var i=0;i<n;i++){
   var ab=Arr[i].split(",").map(Number);
   var a=ab[0];
   var b=ab[1];
   var x=arr[a];
   arr[a]=arr[b];
   arr[b]=x;
}
arr.shift();
console.log(arr.join("\n"));

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

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

  int x = max(a,b);
  x += max(a+b-max(a,b), max(a,b)-1);
  cout<<x<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);

		int s = sc.nextInt();

		if (s < 3){
			System.out.println(0);
			return;
		}

		long[] ans = new long[s+1];

		for (int i = 3; i<=s; i++){

			ans[i]++;

			for (int j= 3; j<= i-3; j++){
				ans[i] += ans[j];
				ans[i] %= 1000000007;
			}
		}
		System.out.println(ans[s]);
	}
}

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

using namespace std;

int main()
{
	const int MAX_N = 100000;
	int n;
	std::cin >> n;
	int d[MAX_N] = {};
	for (int i = 0; i < n; i++)
		cin >> d[i];

	// dを降順にソート
	int dSize = sizeof(d) / sizeof(d[0]);
	std::sort(d, d + dSize, std::greater<>());

	int halfN = (n / 2) - 1;
	int answer = d[halfN] - d[halfN + 1];

	std::cout << answer;

	return 0;

}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
#define maxN 200000

int n;
int a[maxN+1], b[maxN+1]={0};
int main()
{
    int dem=0, res=0;
    cin >> n;
    cin >> a[1];
    res=a[1];
    b[1]=res;
    for (int i=2;i<=n;i++)
    {
        cin >> a[i];
        if (a[i]<res)
        {
            res=a[i];
        }
        b[i]=res;
    }
    for (int i=1;i<=n;i++)
    {
        if (a[i]<=b[i]) dem++;
    }
    cout << dem;
    return 0;
}



Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
using namespace std;
int main( void )
{
	int n;
	while ( cin >> n && n )
	{
		int max_total = 0;
		int min_total = 1<<24;

		for ( int lpc = 0; lpc < n; lpc++ )
		{
			int sum = 0, s;
			for ( int i = 0; i < 5; i++ )
			{
				cin >> s; sum += s;
			}
			max_total = max( max_total, sum );
			min_total = min( min_total, sum );
		}
		cout << max_total << " " << min_total << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<cstdio>
using namespace std;
void func(int,int);
int a,b;
int x,y;
int cnt;
int kouzi[17][17];

int main(void)
{
	int i,j,n;
	scanf("%d %d",&a,&b);
	while(a!=0 && a!=0){
		for(i=1;i<=b;i++){
			for(j=1;j<=a;j++){
				kouzi[i][j]=0;
			}
		}
		scanf("%d",&n);
		for(i=0;i<n;i++){
			scanf("%d %d",&x,&y);
			kouzi[y][x]=1;
		}
		cnt=0;
		func(1,1);
		printf("%d\n",cnt);
		
		scanf("%d %d",&a,&b);
		
	}
	return 0;
}
void func(int y,int x)
{
	if(a==x && b==y){
		cnt++;
	}
	else{
		if(kouzi[y][x+1]==0 && x+1<=a){
			func(y,x+1);
		}
		if(kouzi[y+1][x]==0 && y+1<=b){
			func(y+1,x);
		}
	}
}
	

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <sstream>
#include <map>
#include <queue>
#include <stack>

using namespace std;

bool ok(char c){
	return '0'<=c && c<='9';
}

bool comp(string x, string y){
	return x.size()>y.size() || (x.size()==y.size() && x>y);
}

string max_str(string x, string y){
	if(comp(x,y)) return x;
	else return y;
}

int main()
{
	int w,h;
	while(cin>>w>>h , w||h){
		
		string mat[100][100];
		string dp[100][100];
		for(int i=0;i<h;i++){
			string s;
			cin>>s;
			for(int j=0;j<s.size();j++) mat[i][j]=s[j];
		}
		
		string ans;
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				if(!ok(mat[i][j][0])) continue;
				if(dp[i][j]=="") dp[i][j]=mat[i][j];
				
				if(i!=0 && dp[i-1][j]!="0"){
					dp[i][j]=max_str(dp[i][j],dp[i-1][j]+mat[i][j]);
				}
				if(j!=0 && dp[i][j-1]!="0"){
					dp[i][j]=max_str(dp[i][j],dp[i][j-1]+mat[i][j]);
				}
				
				ans=max_str(ans,dp[i][j]);
				
			}
		}
		
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1552
#include<stdio.h>
#include<stdlib.h>

int main(int argc, char *argv[]){
	int i,j;
	int n,b,e,q;
	int *a;
	int tmp;

	scanf("%d",&n);
	a=calloc(n,sizeof(int));

	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}

	scanf("%d",&q);
	for(i=0;i<q;i++){
		scanf("%d%d",&b,&e);
		for(j=0;j<(e-b)/2;j++){
			tmp=a[b+j];
			a[b+j]=a[e-1-j];
			a[e-1-j]=tmp;
		}
	}

	for(i=0;i<n;i++){
		printf("%d%c", a[i], " \n"[i + 1 == n]);
	}

	exit(0);
}



Measured memory_bytes: 2148
#include <stdio.h>
#include <stdlib.h>
#include <math.h>



int main()
{
	long long int X=0,money=100;
	
	
	scanf("%lld",&X);

	int year=0;
	
	while(money<X){
		
		money=1.01*money;
		year++;
	}
	
	printf("%d", year);
	

	return 0;
}


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

int main() {
    int a=1,i=0,x=1;
    while (1) {
        cin >> a;
        if (a == 0)break;
            i = i + 1;
            cout << "Case " << i << ": " << a << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPP(i, n) for(int i = 1; i <= n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const ll MOD = 1000000007;

bool binarySearch(int key, vector<int> v, int n) {
    int left = 0;
    int right = n;
    int mid;
    bool ans = false;
    while (left<right) {
        mid = (left + right)/2;
        if(v[mid]==key) {
            ans = true;
            break;
        }
        mid = (key < v[mid] ? right = mid : left = mid+1);
    }
    return ans;
}

int main() {
    int n; cin >> n;
    vector<int> s(n);
    REP(i,n) cin >> s[i];
    int q; cin >> q;
    vector<int> t(q);
    REP(i,q) cin >> t[i];
    int ans = 0;
    REP(i,q) {
        ans += (binarySearch(t[i], s, n));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

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

  int n, k;
  cin >> n >> k;

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

  int ans = -1;
  for (int i = 0; i < n - (k - 1); i++) {
    int l = x[i];
    int r = x[i + (k - 1)];

    bool isLp = l >= 0;
    bool isRp = r >= 0;

    int t;

    if (isLp == isRp) {
      t = max(abs(l), abs(r));
    } else {
      t = abs(max(abs(l), abs(r))) + abs(min(abs(l), abs(r))) * 2;
    }

    if (ans == -1) {
      ans = t;
    } else {
      ans = min(ans, t);
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 640
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    vector<int> v(3);
    cin >> v[0] >> v[1] >> v[2];

    sort(ALL(v));

    int cnt = 0;
    REP(i, 3) cnt += int(v[i] & 1);

    if (cnt == 0 || cnt == 3) {
        print((2 * v[2] - v[1] -v[0]) / 2);
    } else {
        if (v[2] & 1) {
            if (cnt == 2) {
                // odd odd even
                print((2 * v[2] - v[0] - v[1] - 1) / 2 + 2);
            } else {
                // odd even even
                print((2 * v[2] - v[0] - v[1] - 2) / 2 + 1);
            }
        } else {
            if (cnt == 2) {
                // even odd odd
                print((2 * v[2] - v[0] - v[1] - 2) / 2 + 1);
            } else {
                // even even odd
                print((2 * v[2] - v[0] - v[1] - 1) / 2 + 2);
            }
        }
    }

    
}


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

int main(){
    string A, B, C;
    cin >> A >> B >> C;

    if(A[A.size()-1]==B[0] && B[B.size()-1]==C[0]) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


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

typedef std::vector<int> liste;

bool solve(int i,int m,liste& list) {
    if(m==0) {
        return true;
    }
    if(m<0||i>=list.size()) {
        return false;
    }
    return (solve(i+1,m,list)||solve(i+1,m-list[i],list));
} 
    
int main(void){
        
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    int value;
    int n;
    std::cin >> n;
    liste list(n);
    for(int i=0; i<n; i++) {
        std::cin >> list[i];
    } 
    std::cin >> n;
    for(int i=0; i<n; i++) {
        std::cin >> value;
        std::cout << (solve(0,value,list) ? "yes" : "no") << std::endl;
    } 
    
    return 0;
}

Measured memory_bytes: 1196
L = input()
mod = 10**9+7
N = len(L)
DP = [0]*(N+1)
DP[-1] = 1
for i in range(N):
    if L[N-i-1] == '1':
        DP[i] = pow(3,i,mod)+2*DP[i-1]
        DP[i] %= mod
    else:
        DP[i] = DP[i-1]
print(DP[N-1])


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

using namespace std;

#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 rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    vector<int> a(10);
    rep (i, 4) {
        int x;
        cin >> x;
        a[x]++;
    }
    if (a[1] && a[4] && a[7] && a[9]) cout << "YES" << endl;
    else cout << "NO" << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	if(s=="Sunny") cout<<"Cloudy"<<endl;
	if(s=="Cloudy") cout<<"Rainy"<<endl;
	if(s=="Rainy") cout<<"Sunny"<<endl;
	return 0;
}

Measured memory_bytes: 256
import collections
n,ais = int(raw_input()), map(int, raw_input().split())
cc = collections.Counter()
for ai in ais:
	if ai % 4 == 0: cc[0] += 1
	elif ai % 2 == 0: cc[1] += 1
	else: cc[2] += 1

q,h = collections.deque([0]), [[2,1,0],[1],[0]] 
while(n):
	b = False
	for u in h[q[-1]] + [-1]:
		if u == -1: b = True
		if cc[u] > 0:
			q.append(u)
			q.popleft()
			cc[u] -=1
			n -=1
			break
	if b: break

print 'Yes' if n == 0 else 'No'

Measured memory_bytes: 89284
var l,r,m:int64;
    s,t:string;
begin
  readln(r);
  l:=0;
  writeln(l);
  flush(output);
  readln(s);
  t:=s;
  if s='Vacant' then exit;
  while l<=r do
  begin
    m:=(l+r)>>1;
    writeln(m);
    flush(output);
    readln(s);
    if s='Vacant' then exit;
    if m mod 2=0 then
    begin
      if (s=t) then l:=m+1 else r:=m-1;
    end else
    begin
      if (s<>t) then l:=m+1 else r:=m-1;
    end;
  end;
end.

Measured memory_bytes: 760
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  int c=0;
  cin>>N;
  int y=N;
  while(N>0){
    c+=N%10;
    N=N/10;
  }
  int x=y%c;
  if(x==0){
  cout<<"Yes"<<endl;
  }
  if(x!=0){
  cout<<"No"<<endl;
  }
  
}

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

int main(void){
    string n; cin >> n;
    int length = n.size();
    
    for(int i = 0; i < length; i++){
        if(n.at(i) == '7'){
            cout << "Yes" << endl;
            return 0;
        }
    }
    
    cout << "No" << endl;
    
    
    
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define pi acos(-1.0)
int main()
{
    ios;
    double a,b,h,m;
    double angle=0;
    cin>>a>>b>>h>>m;
    angle=abs(h*30-m*6+0.5*m);
    angle=min(angle,360-angle);
    angle=angle*(pi/180.0);
    double c=sqrt(a*a+b*b-2*a*b*cos(angle));
    cout<<fixed<<setprecision(21)<<c<<endl;


}




Measured memory_bytes: 4136
#include "bits/stdc++.h"

using namespace std;

#define int long long
#define ll long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl



int N, L;
int a[123456];

signed main(){

	cin >> N >> L;
	rep(i, N){
		cin >> a[i];
	}
	int t=-1;
	rep(i, N - 1){
		if (a[i] + a[i + 1] >= L){
			t = i; break;
		}
	}
	if (t == -1){
		cout << "Impossible" << endl;
	}
	else{
		cout << "Possible" << endl;
		for (int i = 0; i<t; i++) cout << i + 1 << endl;
		for (int i = N-2; i >=t; i--) cout << i+1 << endl;
	}

	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int T;
	int ac, re, wa, tle;
	cin >> T;
	ac = re = tle = wa = 0;
	string status;
	while(cin >> status)
	{
		if(status == "AC") ac++;
		if(status == "TLE") tle++;
		if(status == "WA") wa++;
		if(status == "RE") re++;
		if(status == "Chtholly") re = 14517814984891981498149817484198749;
  	} 
  	cout << "AC " << "x " << ac << endl;
	cout << "WA " << "x " << wa << endl;
	cout << "TLE" << " x " << tle << endl;
	cout << "RE" << " x " << re << endl;  
}

Measured memory_bytes: 3624
#include <queue>
#include <string>
#include <vector>
#include <iostream>
using namespace std;
int H, W;
int main() {
	cin >> H >> W;
	vector<string> v(H);
	for (int i = 0; i < H; i++) cin >> v[i];
	int N = H * W;
	vector<vector<int> > G(N);
	for (int i = 0; i < H - 1; i++) {
		for (int j = 0; j < W; j++) {
			if (v[i][j] == '#' || v[i + 1][j] == '#') continue;
			G[i * W + j].push_back(i * W + j + W);
			G[i * W + j + W].push_back(i * W + j);
		}
	}
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W - 1; j++) {
			if (v[i][j] == '#' || v[i][j + 1] == '#') continue;
			G[i * W + j].push_back(i * W + j + 1);
			G[i * W + j + 1].push_back(i * W + j);
		}
	}
	int s = -1, g = -1; vector<int> sol;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (v[i][j] == '$') sol.push_back(i * W + j);
			if (v[i][j] == '@') s = i * W + j;
			if (v[i][j] == '%') g = i * W + j;
		}
	}
	vector<int> solt(N, 999999999);
	queue<int> que1;
	for (int i : sol) que1.push(i), solt[i] = 0;
	while (!que1.empty()) {
		int u = que1.front(); que1.pop();
		for (int i : G[u]) {
			if (solt[i] == 999999999) {
				solt[i] = solt[u] + 1;
				que1.push(i);
			}
		}
	}
	vector<int> dist(N, 999999999); dist[s] = 0;
	queue<int> que2; que2.push(s);
	while (!que2.empty()) {
		int u = que2.front(); que2.pop();
		for (int i : G[u]) {
			if (dist[i] == 999999999 && solt[i] > dist[u] + 1) {
				dist[i] = dist[u] + 1;
				que2.push(i);
			}
		}
	}
	cout << (dist[g] != 999999999 ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 5552
#include <regex>
#include "bits/stdc++.h"
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define INF (INT_MAX / 2)
#define LINF (LLONG_MAX / 2)
#define EPS (1.0e-8)
const int MGN = 10;
const int ARY_SZ_MAX = (int)1e7;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>;
using vc = vector<char>; using vvc = vector<vc>;
using vb = vector<bool>; using vvb = vector<vb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>; using psl = pair<string, ll>;


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

  int A,B; cin>>A>>B;

  int ans = 0;
  for(int i=1; i<=3; i++) {
    if (i==A | i==B) continue;
    ans = i;
  }

  cout << ans << endl;

  return 0;
}


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

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

  int N;
  cin >> N;
  string S;
  cin >> S;
  int ans = N;
  for(int i=1;i<N;i++){
    if(S[i] == S[i-1]){
      ans--;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
import sys
lines = sys.stdin.readlines()
line1 = lines.pop(0).split(' ')
line2 = lines.pop(0).split(' ')
line3 = lines.pop(0).split(' ')
N = int(lines.pop(0))

for i in range(N):
  for j in range(3):
    if int(lines[i]) == int(line1[j]):
      line1[j] = -1
    elif int(lines[i]) == int(line2[j]):
      line2[j] = -1
    elif int(lines[i]) == int(line3[j]):
      line3[j] = -1

if (line1[0] == line1[1] == line1[2]) or (line2[0] == line2[1] == line2[2]) or (line3[0] == line3[1] == line3[2]) or (line1[0] == line2[0] == line3[0]) or (line1[1] == line2[1] == line3[1]) or (line1[2] == line2[2] == line3[2]) or (line1[0] == line2[1] == line3[2]) or (line1[2] == line2[1] == line3[0]):
  print('Yes')
else:
  print('No')


Measured memory_bytes: 3064
A = input()
B = input()
C = input()

cur = A[0]
A = A[1:]
for _ in range(len(A)+len(B)+len(C)):
    if cur == 'a':
        if len(A) == 0:
            print('A')
            exit()
        cur = A[0]
        A = A[1:]
    elif cur == 'b':
        if len(B) == 0:
            print('B')
            exit()
        cur = B[0]
        B = B[1:]
    elif cur == 'c':
        if len(C) == 0:
            print('C')
            exit()
        cur = C[0]
        C = C[1:]

Measured memory_bytes: 3064
MODS = 10**9 + 7

def mod_fact(count)
  x = 1
  2.upto(count) do |i|
    x = x * i % MODS
  end
  x
end

n, m = gets.split.map(&:to_i).minmax
case m - n
when 0
  p mod_fact(n)**2 * 2 % MODS
when 1
  p mod_fact(n)**2 * m % MODS
else
  p 0
end


Measured memory_bytes: 1788
#include<iostream>
//#include<fstream>
#include<map>
using namespace std;

enum {X=0, Y=1, Z=2 };

int main(){
	int K,N;
	int *data1[3], *data2[3];	//ファイルの中身の座標をを保存
	
	// データ読み込み
	/*
	ifstream fin("input.txt", ios::in);
	fin >> N >> K;
	for(int x=0; x<3; x++){
		data1[x] = new int[N];
		data2[x] = new int[N];
	}
	for(int n=0; n<N; n++){
		fin >> data1[X][n] >> data1[Y][n] >> data1[Z][n] >> data2[X][n] >> data2[Y][n] >> data2[Z][n];
	}
	fin.close();
	*/
	cin >> N >> K;
	for(int x=0; x<3; x++){
		data1[x] = new int[N];
		data2[x] = new int[N];
	}
	for(int n=0; n<N; n++){
		cin >> data1[X][n] >> data1[Y][n] >> data1[Z][n] >> data2[X][n] >> data2[Y][n] >> data2[Z][n];
	}
	

	//グリットの作成
	map<int, char> gridmap[3];	//重複座標を除去するためにmapを使用
	int *gridstep[3];			//mapは添字でアクセスできないから、普通の配列も併用
	char *grid;					//直方体に分割した領域内の生息範囲を記憶
	for(int x=0; x<3; x++){
		for(int n=0; n<N; n++){
			gridmap[x].insert(make_pair(data1[x][n], -1));
			gridmap[x].insert(make_pair(data2[x][n], -1));
		}
	}
	char gridnum[3] = {0,0,0};
	for(int x=0; x<3; x++){
		gridstep[x] = new int[gridmap[x].size()];
		for(map<int, char>::iterator it = gridmap[x].begin(); it!=gridmap[x].end(); it++, gridnum[x]++){
			gridstep[x][gridnum[x]] = it->first;
			it->second = gridnum[x];
		}
	}
	int griddim = (gridnum[X]-1)*(gridnum[Y]-1)*(gridnum[Z]-1);
	grid = new char[griddim];
	for(int a=0; a<griddim; a++)grid[a] = 0;

	//生息範囲の登録
	for(int n=0; n<N; n++){
		int xyz1[3], xyz2[3];
		for(int x=0; x< 3; x++){
			xyz1[x] = gridmap[x].find(data1[x][n])->second;
			xyz2[x] = gridmap[x].find(data2[x][n])->second;
		}
		for(int xn=xyz1[X]; xn<xyz2[X]; xn++){
			for(int yn=xyz1[Y]; yn<xyz2[Y]; yn++){
				for(int zn=xyz1[Z]; zn<xyz2[Z]; zn++){
					grid[zn + (gridnum[2]-1)*(yn + (gridnum[1]-1)*xn)]++;
				}
			}
		}
	}

	//体積計算
	long long value=0;
	for(int xn=0; xn< gridnum[X]-1; xn++){
		for(int yn=0; yn< gridnum[Y]-1; yn++){
			for(int zn=0; zn< gridnum[Z]-1; zn++){
				if(grid[zn + (gridnum[2]-1)*(yn + (gridnum[1]-1)*xn)] >= K){
					value += (long long)(gridstep[X][xn+1] -gridstep[X][xn])*
										(gridstep[Y][yn+1] -gridstep[Y][yn])*
										(gridstep[Z][zn+1] -gridstep[Z][zn]);
				}
			}
		}
	}
	
	cout << value << endl;


	for(int x=0; x<3; x++){
		delete[] data1[x];
		delete[] data2[x];
		delete[] gridstep[x];
	}
	delete[] grid;
	return 0;
}

Measured memory_bytes: 2060
n = int(input())
xyh = [ list(map(int, input().split())) for _ in range(n)]

for cx in range(101):
  for cy in range(101):
    ch = 0
    for _ in range(2):
      for x, y, h in xyh:
        if x==cx and y==cy:
          if ch!=0:
            if h!=ch:
              break
          else:
            ch = h
        else:
          nh = abs(x-cx) + abs(y-cy)
          if h == 0:
            if nh < ch:
              break
          else:
            nh += h
            if ch == 0:
              ch = nh
            else:
              if ch != nh:
                break
      else:
        continue
      break
    else:
      print(cx, cy, ch)
      exit()

Measured memory_bytes: 3064
from bisect import bisect_left as bisect
from collections import defaultdict


s, t = input(), input()
lens, sets = len(s), set(s)

if not all(i in sets for i in t):
    print(-1)
    exit()

alp = defaultdict(list)
for i, si in enumerate(s):
    alp[si].append(i)

ans, cnt = 1 - lens, 0
for i in t:
    ans += lens * (cnt == 0)
    num = bisect(alp[i], cnt)
    ans += lens * (num == len(alp[i]))
    cnt = (alp[i][num % len(alp[i])] + 1) % lens 
print(ans + (cnt - 1) % lens)


Measured memory_bytes: 81244
#include<iostream>
#include<algorithm>
using namespace std;
int dp[1000], a[1000];
int l[1000], r[1000], m[1000];
int N, Q;
int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> l[i] >> r[i] >> m[i];
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 400; j++) {
			for (int k = l[i]; k <= r[i]; k++) {
				dp[j + k] = max(dp[j + k], dp[j] + m[i]);
			}
		}
	}
	cin >> Q; int OK = 0;
	for (int i = 0; i < Q; i++) {
		cin >> a[i]; 
		if (dp[a[i]] == 0) { OK = 1; }
	}
	if (OK == 1) { cout << "-1" << endl; }
	else {
		for (int i = 0; i < Q; i++) { cout << dp[a[i]] << endl; }
	}
	return 0;
}

Measured memory_bytes: 1176
n = int(input())
play = []
for i in range(n):
    s,t = input().split()
    t = int(t)
    play.append((s,t))
x = input()
flag = False
ans = 0
for s,t in play:
    if x == s:
        flag = True
    elif flag:
        ans += t
print(ans)

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

using namespace std;

#define reps(i, n, m) for (int i = (int) (n); i < (int) (m); i++)
#define rep(i, n) reps(i, 0, (n))
#define all(v) (v).begin(), (v).end()

int main() {
    int n; cin >> n;
    vector<int> v(n);
    rep(i, n) cin >> v[i];
    int q; cin >> q;
    while (q--) {
        int a; cin >> a;
        cout << lower_bound(all(v), a) - v.begin() << endl;
    }
}


Measured memory_bytes: 3100
#include<stdio.h>
#include<stdlib.h>

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))

#define INFTY 99999999

//降順
int desc(const void* a, const void* b){
    return *(int*)b-*(int*)a;
}

//num[i]..数字のiはマッチを何本使うか
int num[10]={0,2,5,5,4,5,6,3,7,6};

int main(void){
    int N,M;
    scanf("%d%d",&N,&M);

    //A[0]~A[N-1]に格納する→降順ソート
    int* A;
    NEW(A,M);
    for(int i=0;i<M;i++){
        scanf("%d",&A[i]);
    }
    qsort(A,M,sizeof(int),desc);

    //digit[i]...マッチi本で最大何桁の数が作れるかを格納
    int digit[N+1];
    digit[0]=0;
    for(int i=1;i<=N;i++) digit[i]=-INFTY;

    for(int i=1;i<=N;i++){
        for(int j=0;j<M;j++){
            if((i-num[A[j]])>=0) digit[i]=MAX(digit[i], digit[i-num[A[j]]]+1);
        }
    }

    int match=N;
    while(match>0){
        for(int j=0;j<M;j++){
            if(digit[match]==digit[match-num[A[j]]]+1 && match-num[A[j]]>=0){
                match-=num[A[j]];
                printf("%d",A[j]);
                break;
            }
        }
    }
    printf("\n");

    return 0;
}

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

using namespace std;
using ll = long long;
ll gcd(ll a, ll b);
int main(){
cin.tie(0);
string str;
ll result=0,temp=0;

cin>>str;

for(ll i=0;i<3;i++){
    if(str[i]=='R')temp++;
    else temp=0;
    if(temp>=result)result=temp;
}
cout<<result;
return 0;
}






ll gcd(ll a, ll b){

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

}


Measured memory_bytes: 3608
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 0
#define dump(o) if(DBG){cerr<<#o<<" "<<(o)<<" ";}
#define dumpl(o) if(DBG){cerr<<#o<<" "<<(o)<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

class Player {
public:
	int id;
	vector<int> g[10];
	vector<int> idx[10];
	vector<int> s;
	int h[10] = {};
	Player(int id, vector<int> s) :id(id), s(s) {
		int game = 0;
		int cnt = 0;
		rep(i, 0, s.size()) {
			assert(game < 10);
			if (cnt == 0) {
				g[game].emplace_back(s[i]);
				idx[game].emplace_back(i);
				if (s[i] == 10) {
					if (game == 9) {
						g[game].emplace_back(s[i + 1]);
						g[game].emplace_back(s[i + 2]);
						idx[game].emplace_back(i + 1);
						idx[game].emplace_back(i + 2);
						break;
					}
					h[game] = 2;
					game++;
				}
				else cnt++;
			}
			else if (cnt == 1) {
				g[game].emplace_back(s[i]);
				idx[game].emplace_back(i);
				if (s[i] + s[i - 1] == 10) {
					if (game == 9) {
						g[game].emplace_back(s[i + 1]);
						idx[game].emplace_back(i + 1);
						break;
					}
					h[game] = 1;
				}
				game++;
				cnt = 0;
			}
		}
	}
	bool operator<(Player that) {
		int a = score(), b = that.score();
		return a == b ? id > that.id:a < b;
	}
	int score() {
		int ret = 0;
		int gs[10] = {};
		rep(i, 0, 10) {
			gs[i] = accumulate(all(g[i]), 0);
			ret += gs[i];
		}
		dump(ret);
		rep(i, 0, 10) {
			if (h[i] >= 1)ret += s[idx[i + 1][0]];
			if (h[i] == 2)ret += s[idx[i + 1][0] + 1];
		}
		dump(ret);
		return ret;
	}
};

//delimiter??£?¶?????????????delimiter?????????
vector<string> split(const string& input, const char& delimiter) {
	vector<string> ret;
	string w;
	for (const char& c : input) {
		if (c == delimiter) {
			if (w.size())	ret.emplace_back(w);
			w.clear();
		}
		else w += c;
	}
	if (w.size())	ret.emplace_back(w);
	return ret;
}

signed main() {
	for (int m; cin >> m&&m;) {
		vector<Player> v;
		cin.ignore();
		rep(i, 0, m) {
			string s;
			getline(cin, s);
			vector<string> v2 = split(s, ' ');
			int id = stoi(v2[0]);
			vector<int> v3;
			rep(j, 1, v2.size())v3.emplace_back(stoi(v2[j]));
			v.emplace_back(id, v3);

			rep(k, 0, 10) {
				dumpc(v[i].g[k]);
			}
			dumpc(v[i].h);
		}
		sort(all(v));
		rrep(i, 0, v.size()) {
			cout << v[i].id << " " << v[i].score() << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3172
/*
ЗАПУСКАЕМ
░ГУСЯ░▄▀▀▀▄░РАБОТЯГИ░░
▄███▀░◐░░░▌░░░░░░░
░░░░▌░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░▄▀▒▒▀▀▀▀▄
░░░▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
░░░▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░░░▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░▄▄▌▌▄▌▌░░░░░ 
*/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define zhfs main
#define mp(a, b) make_pair(a, b)
#define fi first
#define se second
#define re return
#define forn(i, n) for (int i = 1; i <= n; i++)
const int MAXN = 100 * 1000 + 7;
int a[MAXN];
int zhfs()
{
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
#endif
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
	{
		scanf("%d", &a[i]);
	}
	int res = 1;
	bool cani = true, cand = true;
	a[0] = a[1];
	for (int i = 1; i <= n; i++)
	{
		if (a[i] == a[i - 1]) continue;
		if (a[i] > a[i - 1])
		{
			if (!cani)
			{
				cani = true;
				cand = true;
				res++;
				//i++;
			}
			else
			{
				cand = false;
			}
		}
		else
		{
			if (!cand)
			{
				cani = true;
				cand = true;
				res++;
				//i++;
			}
			else
			{
				cani = false;
			}
		}
	}
	printf("%d\n", res);
}



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

#define PI 3.14159265359

int n, m;
array<vector<int>, 100001> A;

void bfs() {
    vector<int> frontier = {1};
    int parent[n+1] = {0};
    int visited[n+1] = {0};
    while (!frontier.empty()){
        vector<int> next;

        for (int &i : frontier){
            for (int &j: A[i]){
                if (!visited[j]){
                    visited[j] = 1;
                    parent[j] = i;
                    next.push_back(j);
                }
            }
        }

        frontier = next;
    }

    for (int i=2; i<=n; i++){
        if (!parent[i]){
            cout << "No";
            return;
        }
    }

    cout << "Yes\n";
    for (int i=2; i<=n; i++){
        
        cout << parent[i] << "\n";
    }
}


void solve() {
    cin >> n >> m;
    int a;
    int b;
    for (int i=0; i<m; i++){
        cin >> a >> b;
        A[a].push_back(b);
        A[b].push_back(a);
    }

    bfs();
}


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

    solve();
}

Measured memory_bytes: 10984
N=int(input())
ac=0
wa=0
tle=0
re=0
for i in range(N):
    result=input()
    if(result=="AC"):
        ac+=1
    elif(result=="WA"):
        wa+=1
    elif(result=="TLE"):
        tle+=1
    else:
        re+=1
print("AC x "+str(ac))
print("WA x "+str(wa))
print("TLE x "+str(tle))
print("RE x "+str(re))

Measured memory_bytes: 9212
k, n = [int(elem) for elem in input().split()]
a_lst = [int(elem) for elem in input().split()]

diff = []
for i, a in enumerate(a_lst[:-1]):
    diff.append(a_lst[i+1] - a)
diff.append((a_lst[0] + k) - a_lst[-1])

res = sum(diff) - max(diff)
print(res)

Measured memory_bytes: 26444
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap



@mt
def slv(N, T, AB):
    AB.sort(key=lambda x: x[0])

    dp = [[0] * (N+1) for _ in range(T)]

    for t in range(T):
        for i in range(len(AB)):
            a, b = AB[i]
            if t >= a:
                dp[t][i] = max(dp[t-a][i-1] + b, dp[t-1][i], dp[t][i-1])
            else:
                dp[t][i] = max(dp[t-1][i], dp[t][i-1])

    B = list(map(lambda x: x[1], AB))
    B.append(0)
    
    dp = dp[-1]
    dp.pop()
    ans = 0
    for i, v in enumerate(dp):
        ans = max(ans, v + max(B[i+1:]))
    return ans


def main():
    N, T = read_int_n()
    AB = [read_int_n() for _ in range(N)]
    print(slv(N, T, AB))


if __name__ == '__main__':
    main()


Measured memory_bytes: 132824
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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;
}

using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 998244353;
const long long INF = 1e16;
#define int long long

const int MAX_N = 1010;
const int MAX_V = 110;



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);	
	string s; cin >> s;
	reverse(ALL(s));
	int tmp = s.size();
	rep(i, s.size() - 4) {
		if (i < s.size() - 5) {
			if (s.substr(i, 6) == "resare") {
				tmp -= 6;
				i += 5;
				continue;
			}
		}
		if (i < s.size() - 6) {
			if (s.substr(i, 7) == "remaerd"){
				tmp -= 7;
				i += 6;
				continue;
			}
		}
		if (s.substr(i, 5) == "maerd") {
			tmp -= 5;
			i += 4;
			continue;
		}
		if (s.substr(i, 5) == "esare") {
			tmp -= 5;
			i += 4;
			continue;
		}
	}
	if (tmp == 0)cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 512