akhauriyash/Code-Regression huggingface dataset:
main () {
    int n, t, res[200001], bp = 200001 - 1, fp = 0;

    scanf("%d\n", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &t);
        if (i % 2) {
            res[bp--] = t;
        } else {
            res[fp++] = t;
        }
    }

    if (n % 2 == 0) {
        /* printf("forward: "); */
        for (int i = bp + 1; i < 200001; i++) printf("%d ", res[i]);
        for (int i = 0; i < fp; i++) printf("%d ", res[i]);
        /* puts(""); */
    } else {
        /* printf("backward: "); */
        for (int i = fp - 1; i >= 0; i--) printf("%d ", res[i]);
        for (int i = 200001 - 1; i > bp; i--) printf("%d ", res[i]);
        /* puts(""); */
    }
}


Measured memory_bytes: 2816
def gcd(a,b):
  if(a<b):
    a,b=b,a
  if(b==0):
    return a
  c= a%b
  return gcd(b,c)

n=int(input())
ans=0
for i in range(1,n+1):
    for j in range(1,n+1):
        d=gcd(i,j)
        for k in range(1,n+1):
            ans+=gcd(d,k)
print(ans)

Measured memory_bytes: 71528
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define fo(i,n) for(int i=0;i<(n);i++)
#define inp(a) int a;cin>>a;
#define inpa(a,n)vector<int> a(n);fo(i,n)cin>>a[i];
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
using namespace std;

#define int ll
// #define MAX 20
#define INF (int)1e18

template<class T> ostream& operator<<(ostream& cout,vector<T> V)
{cout<<"[ ";for(auto v:V)cout<<v<<' ';return cout<<']';}
template<class L,class R> ostream& operator<<(ostream& cout,pair<L, R> P)
{return cout<<'('<<P.F<<','<< P.S<<')';}


int n;
vector<pair<int,int>> a;
int dp[2001][2001];

int fdp(int rem,int right)
{
	if(rem==0)
		return 0;
	
	int &ans=dp[rem][right];
	if(ans!=-1)
		return ans;
	int done=n-rem;
	int left=done-right;
	
	int ind=a[rem-1].S;
	int val=a[rem-1].F;
	ans=0;
	ans=val*(n-1-right-ind)+fdp(rem-1,right+1);
	ans=max(ans,val*(ind-left)+fdp(rem-1,right));
	
	// cerr<<rem<<','<<right<<" : "<<ans<<'\n';
	
	return ans;
}

signed main()
{
	fio
	cin>>n;
	a.resize(n);
	fo(i,n)
	{
		cin>>a[i].F;
		a[i].S=i;
	}
	memset(dp,-1,sizeof(dp));
	sort(all(a));
	cout<<fdp(n,0)<<'\n';
	printclock;
}

Measured memory_bytes: 35220
#include<bits/stdc++.h>
int a[114];
int b[114];
int c[114];
int d[114];
using namespace std;
signed main(){
    int n,m;
    cin>>n>>m;
    for(int i=0;i<n;i++){
        cin>>a[i];
        cin>>b[i];
    }
    for(int i=0;i<m;i++){
        cin>>c[i];
        cin>>d[i];
    }
    int kyori=1145141919;
    int ans=0;
    for(int i=0;i<n;i++){
        kyori=1145141919;
        for(int l=0;l<m;l++){
            int ma=abs(c[l]-a[i])+abs(d[l]-b[i]);
            if(ma<kyori){
                kyori=ma;
                ans=l+1;
            }
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  int n, s;
  scanf("%d", &n); scanf("%d", &s);
  int i;
  int a[s];
  int b[s];
  int c=0;
  for (i=0; i<s;i++){
    scanf("%d", &a[i]);
  }
  b[s-1]=n-a[s-1]+a[0];
  c=b[s-1];
  for (i=0; i<s-1; i++){
    b[i]=a[i+1]-a[i];
    if (c<b[i]){
      c=b[i];
    }
  }
  printf("%d", n-c);
  
  return 0;
}

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

int main() {
  int a; int b; int c; int d;
  cin >> a >> b >> c >> d;
  if(a+b == c+d){
    cout << "Balanced" << endl;
  }
  else if(a+b >= c+d){
    cout << "Left" << endl;
  }
  else{
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 4e3 + 100;
int r[3][N];

signed main(){
 int n; cin >> n;
 string s; cin >> s;
 map<char,int> mm;
 mm['R'] = 0;
 mm['G'] = 1;
 mm['B'] = 2;
 for(int i = 1 ;i <=n ; ++i){
    for(int j = 0;j < 3 ; ++j)
      r[j][i] = r[j][i-1];
    if(s[i-1] == 'R')
      r[0][i]++;
    else if(s[i-1] == 'G')
      r[1][i]++;
    else
      r[2][i]++;
  }

 int ans = 0;
 for(int i = 0;i < n ; ++i){
    for(int j = i+2;j < n ; ++j){
      if(s[i] == s[j]) continue; 
      for(int k = 0; k < 3 ; ++k){
        if(!(k == mm[s[i]] || k == mm[s[j]])){
          //cout << s[i] << ' ' << s[j] << endl;

          //cout << mm[s[i]] << ' ' << mm[s[j]] << endl;
          //cout << i << ' ' << j << ' ' << k << endl;
          ans += r[k][j+1] - r[k][i]; 
          if((i+j)%2 == 1) break;
          if(mm[s[(i+j)/2]] == k) --ans;
        }
      }
    }
 }
 cout << ans << endl;
}



Measured memory_bytes: 3708
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#define ll long long int
#define ull unsigned long long int
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define mod 1000000007
vector<int> g[100005];
ll dp[100005][2];
void dfs(int u,int p)
{
    // 0->white
    // 1->black
    dp[u][0]=1;
    dp[u][1]=1;
    // cout<<"u "<<u<<" p "<<p<<"\n";
    for(int v:g[u]){
        // cout<<"IN\n";
        if(v==p)
            continue;
        dfs(v,u);
        dp[u][0] = (dp[u][0]*dp[v][0])%mod + (dp[u][0]*dp[v][1])%mod;
        dp[u][0] %= mod;
        dp[u][1] = (dp[u][1]*dp[v][0])%mod ;
        dp[u][1] %= mod;
        // cout<<dp[u][0]<<" "<<dp[u][1]<<"\n";
        // dp0 = dp[u][0];
        // dp1 = dp[u][1];
    }
    // dp[u][0]=dp0;
    // dp[u][1]=dp1;
    // cout<<dp[u][0]<<" "<<dp[u][1]<<"\n";
}
int main()
{
    fast;
    int n;
    cin>>n;
    for(int i=0;i<n-1;i++)
    {
        int u,v;
        cin>>u>>v;
        g[u].pb(v);
        g[v].pb(u);
    }
    dfs(1,-1);
    // for(int i=1;i<=n;i++)cout<<dp[i][0]<<" ";cout<<"\n";
    // for(int i=1;i<=n;i++)cout<<dp[i][1]<<" ";cout<<"\n";
   
    cout<<(dp[1][0]+dp[1][1])%mod<<"\n";
return 0;
}

Measured memory_bytes: 14208
#include<stdio.h>
int main()
{
    int a1, a2, a3, t;

    scanf("%d %d %d", &a1, &a2, &a3);

    t=a1+a2+a3;

    if(t>=22)
    {
        printf("bust\n");
    }
    else
    {
        printf("win\n");
    }

    return 0;
}

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

int main(){
  
  int n;
  cin>>n;
  
  string s[n];
  for(int i=0 ; i<n ; ++i){
    cin>>s[i];
	sort(s[i].begin(),s[i].end());
    
  }
  
  sort(s,s+n);
  
  long long ans = 0 , cnt=1;
  for(int i=1 ; i<n ; ++i)
    if(s[i] == s[i-1]){
      ans += cnt;
      cnt++;
    }
  	else
      cnt=1;
  
  cout<<ans;
}

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


int main() {
  string S;
  cin >> S;
  int count =0;
  for(int i=0;i<S.size()/2;i++){
    if(S[i]==S[S.size()-1-i]){
      continue;
    }else{
      count++;
    }
  }
    cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define rep(i, a, n) for (int i=(a); i<(n); i++)
#define per(i, a, n) for (int i=(a); i>(n); i--)
typedef long long ll;
const int maxn = 2e5+5;
const int mod = 1e9+7;
using namespace std;

void solve() {
	string s;
	cin >> s;
	ll l = s.size();
	if (s[l-1]=='s') s+="es";
	else s+='s';
	cout << s << '\n';
}

int main(int argc, char * argv[]) 
{
	ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef DEBUG
	freopen("C:/Users/Fish_Brother/Desktop/in", "r", stdin);
	//freopen("C:/Users/Fish_Brother/Desktop/out", "w", stdout);
#endif

	//int t; cin >> t; while(t--)
	solve();

    return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
int main(void)
{
	int c1,c5,c10,c50,c100,c500,sum=0;
	scanf ("%d%d%d%d%d%d",&c1,&c5,&c10,&c50,&c100,&c500);
	sum=c1*1+c5*5+c10*10+c50*50+c100*100+c500*500;
	if (sum>=1000)
	printf ("1\n");
	else
	printf ("0\n");
	return 0;
}

Measured memory_bytes: 584
#include<iostream>
#include <stdio.h>
#include <string.h>
#include <map>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

using namespace std;
using ll = long long;

int main()
{
    // 整数の入力
    std::map<std::string,int> mp;
    int a;
    cin >> a;
    rep(i,a){
        string c;
        cin >> c;
        mp[c] = 0;
    }

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

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

int main() {
  int N, M;
  int ans = 0;
  cin >> N >> M;

  vector<vector<char>> A(2001, vector<char>(2001));
  vector<vector<char>> B(2001, vector<char>(2001));

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

  for(int i = 0; i < N; i++) {
    for(int j = 0; j < M; j++) {
      cin >> B[i][j];
    }
  }

 for(int i = 0; i < N; i++) {
    for(int j = 0; j < M; j++) {
      if(A[i][j] != B[i][j])
        ans++;
    }
  }

 cout << ans <<	endl;

  return 0;
}


Measured memory_bytes: 10796
#include <iostream>
#include <algorithm>
#define ll long long

using namespace std;

int main()
{
	int n, k, arr[100005], cnt = 0;
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> arr[i];
	for (int i = 0; i < n; i+=k-1)
	{
		if (i == n - 1)break;
		else cnt++;
	}
	cout << cnt;
	return 0;
}


Measured memory_bytes: 640
from functools import lru_cache
import sys

sys.setrecursionlimit(10**6)

N = int(input())
h = list(map(int, input().split()))

@lru_cache(maxsize=None)
def recur(i):
    if i == N - 1:
        return 0
    return min(abs(h[i] - h[i + 1]) + recur(i + 1), abs(h[i] - h[min(N - 1, i + 2)]) + recur(min(N - 1, i + 2)))

print(recur(0))

# dp = [0]*(N + 1)
# for i in range(N):


Measured memory_bytes: 268448
import random
import copy
def evaluateSatisfaction(d, c, s, ans):
    score = 0
    last = [-1 for i in range(26)]
        
    for i in range(d):
        
        score += s[i][ans[i]]
        last[ans[i]] = i
        for j in range(26):
            if j != ans[i] or True:
                score -= c[j]*(i - last[j])
    return score
    
def valuationFunction(d,c,s,contestType,day,last):

    return s[day][contestType]

def Input():
    d = int(input())
    c = list(map(int, input().split()))
    s = [list(map(int, input().split())) for i in range(d)]
    #s[3][25] =   contest(25+1) of day(3+1)
    return d, c, s

def evolution(d, c, s, ans):
    score_before = evaluateSatisfaction(d, c, s, ans)
    ans_after = copy.copy(ans)

    idx1 = random.randint(0,d-1)
    idx2 = random.randint(0,d-1)
    
    tmp = ans_after[idx1]
    ans_after[idx1] = ans_after[idx2]
    ans_after[idx2] = tmp

    score_after = evaluateSatisfaction(d,c,s,ans_after)

    if score_after > score_before:
        return ans_after
    else:
        return ans

if __name__ == "__main__":
    d, c, s = Input()
    
    #print("val =", evaluateSatisfaction(d, c, s, [1, 17, 13, 14, 13]))

    #calc start
    ans = [0 for i in range(d)]
    last = [-1 for i in range(26)]
    for i in range(d):
        evalValueList = [0 for j in range(26)]
        for j in range(26):
            evalValueList[j] = valuationFunction(d, c, s, j,i,last)

        max_idx = 0
        max = evalValueList[0]

        for j in range(26):
            if (max < evalValueList[j]):
                max_idx = j
                max = evalValueList[j]
        
        ans[i] = max_idx
        last[ans[i]] = i


    for i in range(100):
        ans = evolution(d, c, s, ans)
        #print(evaluateSatisfaction(d,c,s,ans))

    for x in ans:
        print(x+1)

Measured memory_bytes: 10088
#include <bits/stdc++.h>
#define ll long long
const ll MAX=100050;
const ll modn=1e9+7;
using namespace std;
ll a[200050];
ll n,k;
ll ans;
void fz(ll l,ll r){
    //cout<<l<<"  "<<r<<endl;
    if(l>=r) {
        ans=l;
        return;
    }
    ll m=(l+r)/2;
    ll sum=0;
    for(int i=1;i<=n;i++){
        sum+=a[i]/m;
        if(a[i]%m==0)
            sum--;
    }
    if(sum<=k)
        fz(l,m);
    else fz(m+1,r);
}
void slove(){

    cin>>n>>k;
    ll maxn=0;
    for(int i=1;i<=n;i++) {
        cin >> a[i];
        maxn=max(maxn,a[i]);
    }
    fz(1,maxn);
    cout<<ans;
}

int main() {
    int _;
    //scanf("%d",&_);
    _=1;
    while(_--) {
        slove();
    }
    return 0;
}

Measured memory_bytes: 5100
#include <stdio.h>
#include <stdlib.h>
int compare(const void *a, const void *b) {
	return *(int*)a - *(int*)b;
}
int main() {
	int h[5], c[4];
	while (scanf("%d,%d,%d,%d,%d ", h, h+1, h+2, h+3, h+4) != EOF) {
		qsort(h, 5, sizeof(int), compare);
		c[0] = h[0] == h[1];
		c[1] = h[1] == h[2];
		c[2] = h[2] == h[3];
		c[3] = h[3] == h[4];
		if (c[0] + c[1] + c[2] + c[3] == 1) {
			puts("one pair");
		}
		else if (c[0] > c[1] && c[2] != c[3]) {
			puts("two pair");
		}
		else if (c[0] < c[1] && c[2] < c[3]) {
			puts("two pair");
		}
		else if (c[0] == c[1] && c[1] != c[2] && c[2] == c[3]) {
			puts("three card");
		}
		else if (c[0] < c[1] && c[2] > c[3]) {
			puts("three card");
		}
		else if (c[0] & c[1] & !c[2] & c[3]) {
			puts("full house");
		}
		else if (c[0] & !c[1] & c[2] & c[3]) {
			puts("full house");
		}
		else if (c[0] & c[1] & c[2] & !c[3]) {
			puts("four card");
		}
		else if ((!c[0]) & c[1] & c[2] & c[3]) {
			puts("four card");
		}
		else if (h[1]-h[0] + h[2]-h[1] + h[3]-h[2] + h[4]-h[3] == 4) {
			puts("straight");
		}
		else if (h[0]==1 && h[1]==10 && h[2]==11 && h[3]==12 && h[4]==13) {
			puts("straight");
		}
		else {
			puts("null");
		}
	}
	return 0;
}

Measured memory_bytes: 588
// B. 

#include <sstream>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cstring>

using namespace std;

int main(int argc, char *argv[])
{
	map<int, int> m;
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		int a;
		cin >> a;
		m[a] += 1;
	}
	int ans = 0;
	map<int, int> f;
	for (int i = 0; i <= 30; ++i) {
		int b = 1 << i;
		for (auto kv : m) {
			if (kv.first == b - kv.first) {
				f[kv.first] += 1;
			} else {
				int r = b - kv.first;
				if (r < kv.first) {
					break;
				}
				if (m.find(r) != m.end()) {
					f[kv.first] += 1;
					f[r] += 1;
				}
			}
		}
	}
	for (int i = 30; i >= 0; --i) {
		int b = 1 << i;
		for (auto kv : m) {
			if (f[kv.first] != 1) {
				continue;
			}
			if (kv.first == b - kv.first) {
				int cnt = kv.second / 2;
				ans += cnt;
				m[kv.first] -= cnt * 2;
			} else {
				int r = b - kv.first;
				if (r > 0 && m.find(r) != m.end()) {
					int cnt = min(kv.second, m[r]);
					ans += cnt;
					m[kv.first] -= cnt;
					m[r] -= cnt;
				}
			}
		}
	}
	for (int i = 30; i >= 0; --i) {
		int b = 1 << i;
		for (auto kv : m) {
			if (kv.first == b - kv.first) {
				int cnt = kv.second / 2;
				ans += cnt;
				m[kv.first] -= cnt * 2;
			} else {
				int r = b - kv.first;
				if (r < kv.first) {
					break;
				}
				if (r > 0 && m.find(r) != m.end()) {
					int cnt = min(kv.second, m[r]);
					ans += cnt;
					m[kv.first] -= cnt;
					m[r] -= cnt;
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 18944
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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

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

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

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


template <typename T>
T amarinasi(T a,T b){
    if(a%b==0)
{
    return a/b;
}
else if(a%b>0)
{
    return a/b+1;
}
else
{
    return a/b-1;
}
}


//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

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

int main(){
ll x,y;
cin>>x>>y;
ll cnt=0;
while(x<=y){
    cnt++;
    x*=2;
}
cout<<cnt<<endl;
}








Measured memory_bytes: 256
R, G, B, N = map(int, input().split())

res = 0

for i in range(N // R + 1):
    for j in range((N - R * i) // G + 1):
        b = N - R * i - G * j
        if b >= 0 and b % B == 0:
            res += 1

print(res)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<ll>())
#define ll long long
#define rep(i, s, g) for (ll i = (s); i < (g); i++)
#define MOD 1000000007
#define vfind(v, target) find(v.begin(), v.end(), target)
#define notFound(v, target) (vfind(v, target) == v.end())

using namespace std;

int main()
{
  ll N, K; cin >> N >> K;
  vector<pair<ll, ll>> AB(N);
  rep(i, 0, N) {
  	ll a, b; cin >> a >> b;
    AB[i] = make_pair(a, b);
  }
  vsort(AB);
  rep(i, 0, N) {
  	if (AB[i].second >= K) {
    	cout << AB[i].first << endl;
      	return 0;
    } else {
    	K -= AB[i].second;
    }
  }
}

Measured memory_bytes: 1792
package main

import "fmt"

func main() {
	//            0  1  2  3  4  5  6  7  8  9 10 11 12
	g := [...]int{0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1}
	var x, y int
	fmt.Scan(&x, &y)
	if g[x] == g[y] {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if(a >= 10 || b >= 10) {
			System.out.println(-1);
		} else {
			System.out.println(a * b);
		}
	}

}


Measured memory_bytes: 23124
n = int(input())
ans = 0

A = [["".join(sorted(input()))] for _ in range(n)]
A.sort()

k = 0

for i in range(n-1):
    if k > 1:
        k = k-1
        ans += k
    else:
        k = 0
        a = A[i]
        for j in range(n-i-1):
                if a == A[j+i+1]:
                    ans += 1
                    k += 1
                else:
                    break

print(ans)


Measured memory_bytes: 20004
#include <bits/stdc++.h>
    using namespace std;
    #define rep(i,a,b) for(int i =a; i<b;++i)
    #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define endl "\n"
    typedef   long long int ll;
    //int dp[100005];
    const int N = 4e5+5;
    const int mod = 998244353;
    ll cnt[N],a[N],n,I,temp[N],q,first,x[N],payload[N];

int main()
{
    IOS;
    int t = 1;
   // cin>>t ;
    while(t--)
    {
        int a,b,c;
        cin>>a>>b>>c;
        int val = ((max(b+c,a)-a) >=0 ) ? (max(b+c,a)-a) : 0;
        cout<<val ;
    }
}


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

int main(int argc, const char * argv[]) {
    int n;
    cin >> n;
    ll x, max, min;
    max = -1;
    min = 10000000000;
    for (int i = 0; i < n; i++) {
        cin >> x;
        if (x > max) {
            max = x;
        }
        if(x < min){
            min = x;
        }
    }
    cout << abs(max - min) << endl;
    return 0;
}


Measured memory_bytes: 256
#import pysnooper
#import os,re,sys,operator,math,heapq,string
#from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby
from sys import stdin,setrecursionlimit
#from copy import deepcopy

setrecursionlimit(10**6)

def rec(pp,xx=-1):
    for i in gragh[pp]:
        if i==xx:
            continue
        ans[i]+=ans[pp]
        rec(i,pp)

n,q=map(int,stdin.readline().rstrip().split())
ans=[0]*n
gragh=[[]*n for _ in range(n)]
for _ in range(n-1):
    a,b=map(int,stdin.readline().rstrip().split())
    a-=1
    b-=1

    gragh[a].append(b)
    gragh[b].append(a)
for _ in range(q):
    p,x=map(int,stdin.readline().rstrip().split())
    ans[p-1]+=x
rec(0)
print(*ans)


Measured memory_bytes: 268464
n=list(map(int,input().split()))
a=list(map(int,input().split()))
s=sum(a)
c=s/(4*n[1])
x=0
for i in range(0,n[0]):
    if a[i]>=c:
        x=x+1
    else:
        continue
if x>=n[1]:
    print("Yes")
else:
    print("No")

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

int main()
{
    std::size_t D;
    std::cin >> D;
    std::array<std::uint16_t, 26> Cs;
    for(auto& c : Cs)
    {
        std::cin >> c;
    }

    std::vector<std::array<std::uint16_t, 26>> ss(D);
    for(std::size_t i=0; i<D; ++i)
    {
        for(std::size_t c=0; c<26; ++c)
        {
            std::cin >> ss[i][c];
        }
    }

    std::array<std::uint16_t, 26> last_day;
    last_day.fill(0);

    const auto calc_score = [&](const std::size_t day, const std::size_t held) {
        std::int32_t score = ss[day-1][held];
        for(std::size_t c=0; c<26; ++c)
        {
            if(c == held) {continue;}
            score -= Cs[c] * (day - last_day[c]);
        }
        return score;
    };

    for(std::size_t day=1; day<=D; ++day)
    {
        std::uint16_t contest = 65535;
        std::int32_t  s_diff  = std::numeric_limits<std::int32_t>::min();
        for(std::size_t c=0; c<26; ++c)
        {
            const auto delta = calc_score(day, c);
            if(s_diff < delta)
            {
                s_diff  = delta;
                contest = c;
            }
        }
        last_day[contest] = day;
        std::cout << contest + 1 << std::endl;
    }
    return 0;
}


Measured memory_bytes: 3656
/*

ÂoÂbÂOÂÃÂÃ¼ÂÃªÂÃ©ÂFÂBÂÃÂdÂÂ³ÂÃ°ÂÂÂÃÂÃÂÂµÂÃÂÂ¤ ÂÂ x ÂÃÂÂ·ÂÃ©
ÂÂ±ÂÃÂdÂÂ³ÂÂ¿ÂÃ¥ÂÂ¤ÂÃÂÃÂÃÂÃ©ÂÃ¦ÂÂ¤ÂÃÂAÂFÂBÂÃ°ÂoÂbÂOÂÃÂÃ¼ÂÃªÂÃ©ÂpÂ^Â[ÂÂÂÂÂÃ°ÂlÂÂ¦ÂÃ©

x ÂÃ°ÂÂÂÃÂÃ©ÂÃÂA(W - x) ÂÃÂÂºÂÃÂdÂÂ³ÂÃÂFÂBÂÃÂAÂSÂÃÂoÂbÂOÂÃÂÃ¼ÂÃªÂÃÂÂ¯ÂÃªÂÃÂÃÂÃ§ÂÃÂÂ¢
  ÂÂÂÂ±ÂÃÂlÂÂ½ÂÂ¿ÂÃÂdÂÂ³ÂÃÂÂÂvÂÃ° pre[W - x] ÂÃÂÂ·ÂÃ©

ÂÂ ÂÃÂAÂoÂbÂOÂÃÂÃ¼ÂÃªÂÃ§ÂÃªÂÃ©ÂcÂÃ¨ÂÃÂdÂÂ³ÂÃ (x - pre[W - x]) ÂÃÂÂ ÂÃ©

ÂÃÂÃÂÃ¨ÂAÂoÂbÂOÂÃÂdÂÂ³ÂÃ° x ÂÃÂÂ·ÂÃ©ÂÂ½ÂÃÂÃÂpÂ^Â[ÂÂÂÂÂÃÂA
Âu(x - pre[W - x]) ÂÃÂdÂÂ³ÂÃ° (W - x + 1) ÂÃÂÃ£ÂÃÂdÂÂ³ÂÃÂFÂBÂÃÂÃÂÂ»ÂÂ·ÂÃ©ÂpÂ^Â[ÂÂÂÂÂvÂÃÂÃÂÃ©


ÂÂ±ÂÃÂÃ¨ÂÂÂÃ°ÂADPÂÃÂÂ©ÂOÂvÂZÂÃÂÂ©ÂgÂÃÂÃÂÂÂÂÂÂ·ÂÃªÂÃÂÂ¢ÂÂ¢

 */
import java.util.*;
import java.io.*;

public class Main{
  public static void main(String[] args)throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    final int MOD = 1000000007;

    while(br.ready()){
      String[] s = br.readLine().split(" ");
      int N = Integer.parseInt(s[0]);
      int W = Integer.parseInt(s[1]);
      ArrayList<Integer> wal = new ArrayList<Integer>();
      int[] pre = new int[W + 2];

      for(int i = 0; i < N; i++){
        int x = Integer.parseInt(br.readLine());

        if(x <= W){
          pre[x] += x;
          wal.add(x);
        }
      }

      for(int i = 0; i < W; i++){
        pre[i + 1] += pre[i];
      }

      Collections.sort(wal);
      Integer[] w = (Integer[])wal.toArray(new Integer[0]);
      N = w.length;

      int[] idx = new int[W + 2];
      Arrays.fill(idx, -1);

      int[][] dp = new int[N + 2][W + 2];
      dp[N][0] = 1;

      for(int i = N; i > 0; i--){
        for(int j = 0; j <= W; j++){
          dp[i - 1][j] += dp[i][j];
          dp[i - 1][j] %= MOD;

          if(j + w[i - 1] <= W){
            dp[i - 1][j + w[i - 1]] += dp[i][j];
            dp[i - 1][j + w[i - 1]] %= MOD;
          }
        }

        if(w[i - 1] <= W){
          idx[w[i - 1]] = i - 1;
        }
      }

      idx[W + 1] = N;
      for(int i = W + 1; i > 0; i--){
        if(idx[i - 1] == -1){
          idx[i - 1] = idx[i];
        }
      }

      int ans = 0;

      for(int x = 0; x <= W; x++){
        if(x < pre[W - x]) continue;
        ans += dp[ idx[W - x + 1] ][ x - pre[W - x] ];
        ans %= MOD;
      }

      System.out.println(ans);
    }
  }
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
	int n, d;
	cin >> n >> d;
	d = d * 2 + 1;
	cout << n / d + (n % d > 0 ? 1 : 0) << endl;
}


Measured memory_bytes: 3596
#include <cstdio>
#include <algorithm>
using namespace std;
const int N=200010;
int n;
int a[N],b[N],maxw;
int c[N],d[N];
void readData(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		maxw=max(maxw,a[i]);
	}
	for(int i=1;i<=n;i++){
		scanf("%d",&b[i]);
		maxw=max(maxw,b[i]);
	}
}
inline int bit(int i){
	return 1<<i;
}
int calc(int l,int r){ // [l,r]
	return upper_bound(d+1,d+1+n,r)-lower_bound(d+1,d+1+n,l);
}
void solve(){
	int ans=0;
	for(int k=0;(1<<k)<=(maxw<<1);k++){
		int t=1<<k;
		for(int i=1;i<=n;i++){
			c[i]=a[i]%(t<<1);
			d[i]=b[i]%(t<<1);
		}
		sort(c+1,c+1+n);
		sort(d+1,d+1+n);
		for(int i=1;i<=n;i++){
			int sum=calc(t-c[i],t*2-1-c[i])+calc(t*3-c[i],t*4-1-c[i]);
			ans^=t*(sum&1);
		}
	}
	printf("%d\n",ans);
}
int main(){
	readData();
	solve();
	return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
 

int main()
{
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  
  int d,n;cin>>d>>n;
  int ans=(n+(n-1)/99)*round(pow(100,d));
  cout(ans);
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void){
    // Your code here!
    char str[11];
    char str_plus[20];
    int len,patt;
    long long ans = 0;
    
    scanf("%10s",str);
    
    len = strlen(str);
    for(int i=0;i<1<<len-1;i++){
        int tmp = i;
        int index=0;
        for(int j=0;str[j]!='\0';j++){
            str_plus[index++] = str[j];
            if(tmp & 1 == 1){
                str_plus[index++] = '+';
            }
            tmp >>= 1;
        }
        str_plus[index] = '\0';
        
        long long tmpans = 0;
        for(int j=0,z;str_plus[j]!='\0';){
            
            tmpans = str_plus[j]-'0';
            for(z=1;str_plus[j+z]!='\0';z++){
                if(str_plus[j+z] == '+'){
                    j=j+z;
                    z=0;
                    break;
                }
                tmpans = tmpans * 10 + (str_plus[j+z]-'0');
            }
            
            ans += tmpans;
            if(str_plus[j+z] == '\0'){
                break;
            }
            else{
                j++;
            }
            
        } 
    }
    
    printf("%lld\n",ans);
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
long long f(string T) {
    long long ans = 0;
    string now;
    int n = T.size();
    for (int i = 0; i < n; i++) {
        if(T.at(i) != '+') {
            now += T.at(i);
        }
        else {
            ans += stoll(now);
            now = "";
        }
        if (i == n-1) ans += stoll(now);
    }
    return ans;
}

int main() {
    string S;
    cin >> S;
    int n = S.size();
    
    long long ans = 0;
    for (int bit = 0; bit < (1<<(n-1)); ++bit) {
        string t;
      	t += S.at(0);
        for (int i = 0; i < n-1; i++) {
            if (bit & (1<<i)) {
                t += '+';
            }
            t += S.at(i+1);
        }
        ans += f(t);
    }
    cout << ans << endl;
}

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

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

const ll mod = 1e9 + 7;

int main() {
	ll n, m;
	cin >> n >> m;

	if (n < m) swap(n, m);

	if (abs(n-m) > 1){
		cout << 0 << endl;
		return 0;
	}

	ll ans = 1;
	if (n == m){
		FOR(i,1,n) ans = (ans * i) % mod;
		ans = (ans * ans) % mod;
		ans = (2 * ans) % mod;
	}else{
		FOR(i,1,m) ans = (ans * i) % mod;
		ans = (ans * ans) % mod;
		ans = (n * ans) % mod;
	}

	cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

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

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

    if (s[2] == s[3] && s[4] == s[5]) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

 

Measured memory_bytes: 256
from collections import deque

n=int(input())
l=[list(map(int,input().split())) for i in range(n-1)]

tree=[[]for _ in range(n)]
for a,b in l:
  a-=1
  b-=1
  tree[a].append(b)
  tree[b].append(b)

ans_num=0
for i in tree:
  ans_num=max(ans_num,len(i))

dq=deque()
dq.append((0,0))

seen=set()
seen.add(0)

ans_dict={}
while dq:
  x,color=dq.pop()

  i=0
  for nx in tree[x]:
    if nx in seen:
      continue

    i+=1
    if i==color:
      i+=1

    seen.add(nx)
    dq.append((nx,i)),
    ans_dict[x+1,nx+1]=i
    ans_dict[nx+1,x+1]=i

print(ans_num)
for i in l:
  print(ans_dict[tuple(i)])

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

#define ii pair <ll, ll>
#define iii pair <ll, ii>
#define ll long long
#define X first
#define Y second

const int N = 2E5 + 10;

int n, Root[N], Ranked[N], type = 1;
ii a[N], x[N], y[N];

void Input()
{
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i].X >> a[i].Y;
}

int Find_Root(int u)
{
    if (u == Root[u]) return u;
    return Root[u] = Find_Root(Root[u]);
}

bool Union(int u, int v)
{
    u = Find_Root(u);
    v = Find_Root(v);
    if (u == v) return false;

    if (Ranked[u] > Ranked[v]) swap(u, v);
    Root[u] = v;
    Ranked[v] += Ranked[u];

    return true;
}

ll Modify(int u, int v, int type)
{
    ll x = abs(a[u].X - a[v].X);
    ll y = abs(a[u].Y - a[v].Y);
    if (type == 1) return min(x, y);
    else return max(x, y);
}

void Solve(int type)
{
    ll res = 0;
    priority_queue <iii, vector <iii>, greater <iii> > PQ;
    for (int i = 1; i <= n; i++) x[i] = {a[i].X, i};
    for (int i = 1; i <= n; i++) y[i] = {a[i].Y, i};
    sort(x + 1, x + 1 + n);
    sort(y + 1, y + 1 + n);

    for (int i = 1; i < n; i++) {
        int u = x[i].Y;
        int v = x[i + 1].Y;
        ll Dist = Modify(u, v, type);
        PQ.push({Dist, {u, v}});

        u = y[i].Y;
        v = y[i + 1].Y;
        Dist = Modify(u, v, type);
        PQ.push({Dist, {u, v}});

    }
    for (int i = 1; i <= n; i++) Root[i] = i, Ranked[i] = 1;

    int k = n - 1;
    while (k && PQ.size()) {
        ll Distance = PQ.top().X;
        int u = PQ.top().Y.X;
        int v = PQ.top().Y.Y;
        PQ.pop();
        if (Union(u, v)) {
            k--;
            res += Distance;
        }
    }

    cout << res;
}

#define task "test"
int main()
{
    if (fopen(task ".inp", "r")) {
        freopen(task ".inp", "r", stdin);
        freopen(task ".out", "w", stdout);
    }
    int testcase = 1;
    /// cin >> testcase;
    while (testcase--) {
        Input();
        Solve(type);
    }
}




Measured memory_bytes: 16620
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long


int t,n;
string str;

int32_t main()
{
	IOS;
	int a,b,c;
	cin>>a>>b>>c;
	cout<<c<<" "<<a<<" "<<b;
	
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#include <stdlib.h>
#include <time.h>
#include <chrono>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

ll d;
vector<ll> c(26 + 1, 0);
vector<vector<ll>> s(365 + 1, vector<ll>(26 + 1, 0));

ll scoring(vector<int> t)
{
    ll ans = 0;
    vector<ll> last(26 + 1, 0);

    for (int i = 1; i <= d; i++)
    {
        ans += s[i][t[i]];
        ans -= c[t[i]] * (i - last[t[i]]) * (i - last[t[i]] - 1) / 2;
        last[t[i]] = i;
    }

    for (int i = 1; i <= 26; i++)
    {

        ans -= c[i] * (d - last[i] + 1) * (d - last[i]) / 2;
    }

    return ans;
}

int main(void)
{
    srand(time(NULL));
    cin >> d;

    for (int i = 1; i <= 26; i++)
    {
        cin >> c[i];
    }

    for (int i = 1; i <= d; i++)
    {
        for (int j = 1; j <= 26; j++)
        {
            cin >> s[i][j];
        }
    }

    vector<int> BestT(d + 1, 1);

    for (int i = 1; i <= d; i++)
    {
        BestT[i] = rand() % 26 + 1;
    }

    double BestScore = scoring(BestT);
    double score;

    auto start = chrono::system_clock::now();
    vector<int> t(d + 1, 1);

    double T0 = 1e6;
    double T1 = 1e3;
    double TL = 1980;

    ll count = 0;

    while (1)
    {
        ll msec;

        msec = chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now() - start).count();

        if (msec >= TL)
        {
            break;
        }

        double T = powf(T0, 1 - msec / TL) * powf(T1, msec / TL);

        t = BestT;

        t[rand() % d + 1] = rand() % 26 + 1;

        score = scoring(t);

        double p = exp((score - BestScore) / T);

        if (p > (double)rand() / RAND_MAX)
        {
            BestT = t;
            BestScore = score;
        }

        count++;
    }

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


Measured memory_bytes: 4376
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;

const double PI = acos(-1.0);
struct Point{
    double x,y;
};

void koch(int n, Point a, Point b) {
    // 递归结束
    if (n == 0)
        return;
    // 三等分点s,t ，(u 是 s,t 上方的点)
    Point s, t, u;
    // 角度从度转成弧度
    double th = PI * 60.0 / 180.0;
    s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
    s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
    t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
    t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;
    u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
    u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;


    koch(n - 1, a, s);
    printf("%.8f %.8f\n", s.x, s.y);
    koch(n - 1, s, u);
    printf("%.8f %.8f\n", u.x, u.y);
    koch(n - 1, u, t);
    printf("%.8f %.8f\n", t.x, t.y);
    koch(n - 1, t, b);
}
int main(){
    Point a, b;
    int n;
    scanf("%d", &n);

    // 初始化
    a.x = a.y = 0;
    b.x = 100, b.y = 0;
    printf("%.8f %.8f\n", a.x, a.y);
    koch(n, a, b);
    printf("%.8f %.8f\n", b.x, b.y);
    return 0;
}



Measured memory_bytes: 3204
s=input()
n=len(s)
mod=2019
d=0
p=1
ml=[0]*mod
for i in range(1,n+1):
  k=int(s[-i])
  d+=p*k
  d%=mod
  ml[d]+=1
  p*=10
  p%=mod
ans=0
for i in ml:
  ans+=i*(i-1)//2
print(ans+ml[0])

Measured memory_bytes: 9256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main{
	static final int INF = Integer.MAX_VALUE;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		List<String> list = new ArrayList<String>();
		while(sc.hasNext()) {
			String s = sc.next();
			//if(s.equals("0")) break;
			list.add(s);
		}
		sc.close();
		int h = list.size();
		int m = list.size() / 2;
		int[][] dp = new int[h + 1][m + 1];
		//dp[0][0] = Integer.parseInt(list.get(0));
		for(int i = 0; i < h; i++) {
			String[] t1 = list.get(i).split(",");
			int l = t1.length;
			int[] t = new int[l];
			for(int j = 0; j < l; j++) {
				t[j] = Integer.parseInt(t1[j]);
			}
			if(i < m) {
				for(int j = 0; j < l; j++) {
					dp[i + 1][j] = Math.max(dp[i + 1][j], dp[i][j] + t[j]);
					dp[i + 1][j + 1] = Math.max(dp[i + 1][j + 1], dp[i][j] + t[j]);
				}
			}else {
				for(int j = 0; j < l; j++) {
					if(j == 0) {
						dp[i + 1][j] = Math.max(dp[i + 1][j], dp[i][j] + t[j]);
					}else if(j == l - 1) {
						dp[i + 1][j - 1] = Math.max(dp[i + 1][j - 1], dp[i][j] + t[j]);
					}else {
						dp[i + 1][j - 1] = Math.max(dp[i + 1][j - 1], dp[i][j] + t[j]);
						dp[i + 1][j] = Math.max(dp[i + 1][j], dp[i][j] + t[j]);
					}

				}
			}

		}
//		for(int i = 0; i < h; i++) {
//			for(int j = 0; j <= m; j++) {
//				System.out.printf("%d ", dp[i][j]);
//			}
//			System.out.println();
//		}
		System.out.println(dp[h][0]);
	}
}


Measured memory_bytes: 28408
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

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

		FastScanner sc = new FastScanner();
		String n[] = sc.next().split("");

		boolean result = true;
		for (int i = 0; i < n.length; i++) {
			if (n[i].equals((i + 1) % 2 == 0 ? "R" : "L")) {
				result = false;
				break;
			}
		}

		System.out.println(result ? "Yes" : "No");
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
            return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
            }
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
            }
        }

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
        }

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 21332
N,x=map(int,input().split())
a=list(map(int,input().split()))
ans=0
for i in range(N-1):
    ex=sum(a[i:i+2])-x
    if ex>0:
        ans+=ex
        if a[i+1]>=ex:
            a[i+1]-=ex
        else:
            a[i+1]=0
            a[i]-=ex-a[i+1]
print(ans)

Measured memory_bytes: 63856
n, m, l = gets.split.map(&:to_i)

matrix_A = []
matrix_B = []
matrix_C = []

n.times{
    matrix_A.push(gets.split.map(&:to_i))
}

m.times{
    matrix_B.push(gets.split.map(&:to_i))
}

n.times{|i|
    line = []
    l.times{|j|
        sum = 0
        m.times {|k|
            sum += matrix_A[i][k] * matrix_B[k][j]
        }
        line.push(sum)
    }
    matrix_C.push(line)
}


n.times{|i|
    puts(matrix_C[i].join(" "))
}


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

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;
const ll MOD = 1000000007;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

int n, m, r;

struct edge {
	int from;
	int to;
	int cost;
};

vector<edge> edges;
vector<ll> dist;

bool solve(int start) {
	dist.resize(n, INT_MAX);
	dist[start] = 0;

	int cnt = 1;
	while (true) {
		bool isUpdate = false;
		for (auto e : edges) {
			if (dist[e.from] != INT_MAX && dist[e.to] > dist[e.from] + e.cost) {
				if (cnt == n) {
					return true;
				}

				dist[e.to] = dist[e.from] + e.cost;
				isUpdate = true;
			}
		}

		if (!isUpdate) {
			break;
		}
		cnt++;
	}

	return false;
}

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

	cin >> n >> m >> r;

	for (int i = 0; i < m; i++) {
		int s, t, d;
		cin >> s >> t >> d;
		edges.push_back({ s, t, d });
	}

	if (solve(r)) {
		cout << "NEGATIVE CYCLE" << endl;
		return 0;
	}

	for (auto v : dist) {
		cout << (v != INT_MAX ? to_string(v) : "INF") << endl;
	}

	return 0;
}



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

typedef pair<ll,ll> P;
const ll MO = 1000000007;

int main(){
    string s,t;
    cin >> s >> t;
    if(s==t.substr(0,t.size()-1)){
        cout << "Yes" << endl;
    }else{
        cout <<"No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <tuple>
#include <stack>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
typedef long long ll;
using namespace std;
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
char upper(char c){
	return c-0x20;
}
char lower(char c){
	return c+0x20;
}
int main() {
	string a,b; cin >> a >> b;
	if (a.size() > b.size()){
		print("GREATER");
	}else if (a.size() < b.size()){
		print("LESS");
	}else {
		rep(i,a.size()){
			if (a[i] > b[i]){
				print("GREATER");
				return 0;
			}else if (a[i] < b[i]){
				print("LESS");
				return 0;
			}
		}
		print("EQUAL");
	}
}

Measured memory_bytes: 768
#include <stdio.h>
#include <string.h>

int main() {
    int n, pTaro = 0, pHanako = 0;
    char taro[101], hanako[101];
    scanf("%d", &n);
    for (int i=0; i<n; i++) {
        *taro = '\0';
        *hanako = '\0';
        scanf("%s %s", taro, hanako);
        if (strcmp(taro, hanako) == 0) {
            pTaro++;
            pHanako++;
        } else if (strcmp(taro, hanako) > 0) {
            pTaro += 3;
        } else {
            pHanako += 3;
        }
    }
    printf("%d %d\n", pTaro, pHanako);
    return 0;
}


Measured memory_bytes: 2132
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever for (;;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return ~n & 1; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first; is >> p.second; return is; }
using namespace std;
// clang-format on

string f(string s, int y, int m, int d) {
  ostringstream ss;
  ss << s << ' ' << y << ' ' << m << ' ' << d;
  return ss.str();
}

main {
  int y, m, d;
  while (cin >> y >> m >> d) {
    if (y < 1868 || (y == 1868 && m < 9) || (y == 1868 && m == 9 && d < 8)) {
      cout << "pre-meiji" << endl;
      continue;
    }
    if ((1868 <= y && y < 1912) || (y == 1912 && m < 7) || (y == 1912 && m == 7 && d <= 29)) {
      cout << f("meiji", y - 1868 + 1, m, d) << endl;
      continue;
    }
    if ((1912 <= y && y < 1926) || (y == 1926 && m < 12) || (y == 1926 & m == 12 && d <= 24)) {
      cout << f("taisho", y - 1912 + 1, m, d) << endl;
      continue;
    }
    if ((1926 <= y && y < 1989) || (y == 1989 && m < 1) || (y == 1989 && m == 1 && d <= 7)) {
      cout << f("showa", y - 1926 + 1, m, d) << endl;
      continue;
    }
    cout << f("heisei", y - 1989 + 1, m, d) << endl;
  }
}

Measured memory_bytes: 3012