akhauriyash/Code-Regression huggingface dataset:
import collections

n = int(input())
v = list(map(int, input().split()))

s = len(set(v))
if s == 1:
    print(n // 2)
    exit()

odd = v[::2]
even = v[1::2]
mo = collections.Counter(odd).most_common(2)
me = collections.Counter(even).most_common(2)

if mo[0][0] != me[0][0]:
    print(n - mo[0][1] - me[0][1])
elif len(mo) == 1:
    print(n - mo[0][1] - me[1][1])
elif len(me) == 1:
    print(n - mo[1][1] - me[0][1])
else:
    print(n - max(mo[0][1] + me[1][1], mo[1][1] + me[0][1]))


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

ll gcdExtended(ll a, ll b, ll *x, ll *y); 
  
// Function to find modulo inverse of b. It returns 
// -1 when inverse doesn't 
ll modInverse(ll b, ll m) 
{ 
    ll x, y; // used in extended GCD algorithm 
    ll g = gcdExtended(b, m, &x, &y); 
  
    // Return -1 if b and m are not co-prime 
    if (g != 1) 
        return -1; 
  
    // m is added to handle negative x 
    return (x%m + m) % m; 
} 
  
// Function to compute a/b under modlo m 
ll modDivide(ll a, ll b, ll m) 
{ 
    a = a % m; 
    ll inv = modInverse(b, m); 
    if (inv == -1) 
       cout << "Division not defined"; 
    else
        return (inv*a)%m;
    //   cout << "Result of division is " << (inv * a) % m; 
    return -1;
} 
  
// C function for extended Euclidean Algorithm (used to 
// find modular inverse. 
ll gcdExtended(ll a, ll b, ll *x, ll *y) 
{ 
    // Base Case 
    if (a == 0) 
    { 
        *x = 0, *y = 1; 
        return b; 
    } 
  
    ll x1, y1; // To store results of recursive call 
    ll gcd = gcdExtended(b%a, a, &x1, &y1); 
  
    // Update x and y using results of recursive 
    // call 
    *x = y1 - (b/a) * x1; 
    *y = x1; 
  
    return gcd; 
} 


int main(){
    ll n;
    cin >> n;
    ll ar[n];
    ll sos=0;
    ll su=0;
    for(int i=0;i<n;i++){
        cin >> ar[i];
        su=((su+ar[i])%hell);
        sos=((sos+((ar[i]*ar[i])%hell))%hell);
    }
    
    ll ssu=(su*su)%hell;
    
    ll diff=(ssu-sos+hell)%hell;
    
    ll ans=modDivide(diff,2,hell);
    cout << ans ;
    
    
    return 0;
}

Measured memory_bytes: 5152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n, k;
    cin >> n >> k;
    int x[n];
    rep(i, 0, n) cin >> x[i];

    ll ans = 1e18;
    for (int i = 0; i <= n - k; i++) {
        ll mn = 0;
        if (x[i + k - 1] <= 0) mn = - x[i];
        else if (0 <= x[i]) mn = x[i + k - 1];
        else mn = min(-x[i], x[i + k - 1]) + x[i + k - 1] - x[i];
        ans = min(ans, mn);
    }

    cout << ans << endl;
    return 0;
}


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

using namespace std;

void solve(void)
{
	int n, k;
	cin >> n >> k;
	vector<int> two, three, six;
	for (int i = 1; i <= 30000; i++)
	{
		if (i % 2 == 0 && i % 3 == 0)
		{
			six.push_back(i);
		}
		else if (i % 2 == 0 && i != 2 && i != 4)
		{
			two.push_back(i);
		}
		else if (i % 3 == 0 && i != 3 && i != 9)
		{
			three.push_back(i);
		}
	}
	vector<int> ans;
	if (n == 3)
	{
		cout << "2 5 63" << endl;
		return;
	}
	if (n == 4)
	{
		cout << "2 5 20 63" << endl;
		return;
	}
	ans.push_back(2);
	ans.push_back(3);
	ans.push_back(4);
	ans.push_back(9);
	n -= 4;
	for (int i = 0; i < two.size()-1 && n >= 2; i += 2)
	{
		ans.push_back(two[i]);
		ans.push_back(two[i+1]);
		n -= 2;
	}
	for (int i = 0; i < three.size()-1 && n >= 2; i += 2)
	{
		ans.push_back(three[i]);
		ans.push_back(three[i+1]);
		n -= 2;
	}
	for (int i = 0; i < six.size() && n; i++)
	{
		ans.push_back(six[i]);
		n--;
	}
	for (int i = 0; i < ans.size(); i++)
	{
		cout << ans[i] << (i == ans.size()-1 ? '\n' : ' ');
	}
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 640
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String A = sc.next();
    String B = sc.next();
    int dA = A.length();
    int dB = B.length();
    if(dA<dB){
      System.out.println("LESS");
      return;
    }else if(dA>dB){
      System.out.println("GREATER");
      return;
    }else{
    }
    if(A.equals(B)){
      System.out.println("EQUAL");
      return;
    }
    for(int i=0;i<dA;i++){
     if(Integer.parseInt(A.substring(i,i+1))>Integer.parseInt(B.substring(i,i+1))){
       System.out.println("GREATER");
       return;
     }else if(Integer.parseInt(A.substring(i,i+1))<Integer.parseInt(B.substring(i,i+1))){
       System.out.println("LESS");
       return;
     }else{
       continue;
     }
    }
    System.out.println("EQUAL");
  }
  

  
}

Measured memory_bytes: 22996
#include <stdio.h>
 
#define S(num)  ((num) * (num))
#define H(n)    ((5.0) * (n) - (5.0))
 
int main(void)
{
    float in_data;
    float time;
    float high;
    int i;
     
    while (scanf("%f", &in_data) != EOF){
        in_data*=in_data/19.6;
        i = 0;
        while (1)if (++i*5.-5 >= in_data) break;
         
        printf("%d\n", i);
    }
     
    return (0);
}

Measured memory_bytes: 624
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,a[101],v,j,t=0;
    cin>>n;
    for (int i=0; i<n; i++)
        cin>>a[i];
    for (int i=0; i<n; i++)
      for (int j=n-1; j>=i+1; j--){
      	  if (a[j]<a[j-1]){
      	      t++;
			  v=a[j];
			  a[j]=a[j-1];
			  a[j-1]=v;	
		  }
	  }
	cout<<a[0];
	for (int i=1; i<n; i++)
	    cout<<' '<<a[i];
	cout<<endl;
	cout<<t<<endl;
    return 0;
} 


Measured memory_bytes: 3084
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
#define INF 1000000000000000000LL
typedef pair<ll, ll>pii;
vector<pii>pat[100000];
ll d1[100000], d2[100000];
bool flag[100000];
ll mod = 1000000007;
ll dp1[100000], dp2[100000];
int main()
{
	int num, way;
	scanf("%d%d", &num, &way);
	int st, go;
	scanf("%d%d", &st, &go);
	st--, go--;
	for (int i = 0; i < way; i++)
	{
		int za, zb, zc;
		scanf("%d%d%d", &za, &zb, &zc);
		za--, zb--;
		pat[za].push_back(make_pair(zb, zc));
		pat[zb].push_back(make_pair(za, zc));
	}
	fill(d1, d1 + num, INF), fill(d2, d2 + num, INF);
	priority_queue<pii>que;
	que.push(make_pair(0, st));
	fill(flag, flag + num, false);
	for (;;)
	{
		if (que.empty())break;
		pii z = que.top();
		que.pop();
		ll d = -z.first, v = z.second;
		if (flag[v])continue;
		flag[v] = true;
		d1[v] = d;
		for (int i = 0; i < pat[v].size(); i++)que.push(make_pair(-d - pat[v][i].second, pat[v][i].first));
	}
	que.push(make_pair(0, go));
	fill(flag, flag + num, false);
	for (;;)
	{
		if (que.empty())break;
		pii z = que.top();
		que.pop();
		ll d = -z.first, v = z.second;
		if (flag[v])continue;
		flag[v] = true;
		d2[v] = d;
		for (int i = 0; i < pat[v].size(); i++)que.push(make_pair(-d - pat[v][i].second, pat[v][i].first));
	}
	ll len = d1[go];
	dp1[st] = dp2[go] = 1;
	que.push(make_pair(0, st));
	fill(flag, flag + num, false);
	for (;;)
	{
		if (que.empty())break;
		pii z = que.top();
		que.pop();
		ll v = z.second;
		if (flag[v])continue;
		flag[v] = true;
		for (int i = 0; i < pat[v].size(); i++)
		{
			if (d1[v] + d2[pat[v][i].first] + pat[v][i].second == len)
			{
				dp1[pat[v][i].first] = (dp1[pat[v][i].first] + dp1[v]) % mod;
				que.push(make_pair(-d1[pat[v][i].first], pat[v][i].first));
			}
		}
	}
	que.push(make_pair(0, go));
	fill(flag, flag + num, false);
	for (;;)
	{
		if (que.empty())break;
		pii z = que.top();
		que.pop();
		ll v = z.second;
		if (flag[v])continue;
		flag[v] = true;
		for (int i = 0; i < pat[v].size(); i++)
		{
			if (d2[v] + d1[pat[v][i].first] + pat[v][i].second == len)
			{
				dp2[pat[v][i].first] = (dp2[pat[v][i].first] + dp2[v]) % mod;
				que.push(make_pair(-d2[pat[v][i].first], pat[v][i].first));
			}
		}
	}
	ll ans = dp1[go] * dp1[go] % mod;
	for (int i = 0; i < num; i++)
	{
		for (int j = 0; j < pat[i].size(); j++)
		{
			ll s = i, t = pat[i][j].first;
			ll d = pat[i][j].second;
			if (d1[s] + d + d2[t] == len)
			{
				if (d1[s] + d1[s] < len&&d2[t] + d2[t] < len)
				{
					ll z = dp1[s] * dp2[t] % mod;
					ans = (ans + mod - z * z % mod) % mod;
				}
			}
		}
		if (d1[i] == d2[i] && d1[i] + d2[i] == len)
		{
			ll z = dp1[i] * dp2[i] % mod;
			ans = (ans + mod - z * z % mod) % mod;
		}
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 20340
#include<iostream>
using namespace std;
int main(){
  int x ,y ,h ,w ,n ,size ,price ,total=0;
  while( true ){
    cin >> n;
    if( n == 0 ){
      break;
    }
    for( int j=0 ; j<n ; j++ ){
      cin >> x >> y >> h >> w;
      size = x + y + h;
      if( size <= 60 && w <= 2 ){
	price = 600;
      }
      
      else if( size <= 80 && w <= 5 ){
	price = 800;
      }
      
      else if( size <= 100 && w <= 10 ){
	price = 1000;
      }
      
      else if( size <= 120 && w <= 15 ){
	price = 1200;
      }
      
      else if( size <= 140 && w <= 20 ){
	price = 1400;
      }
      
      else if( size <= 160 && w <= 25 ){
	price = 1600;
      }

      else{
	price = 0;
      }

      total += price;
    }
    cout << total << endl;
    total = 0;
  }
}

Measured memory_bytes: 1160
def main():
    while True:
        n,m,p = map(int,input().split())
        if (n,m,p) == (0,0,0):
            return
        ps = [int(input()) for _ in range(n)]
        pool = sum(ps) * 100
        pool = pool * (100-p) // 100 
        if ps[m-1] == 0:
            print(0)
        else:
            print(pool // ps[m-1])

if __name__ == '__main__':
    main()


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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N;
    map<string, int> bucket;

    for(int i = 0; i < N; ++i){
        string s;
        cin >> s;
        bucket[s]++;
    }

    cin >> M;
    for(int i = 0; i < M; ++i){
        string t;
        cin >> t;
        bucket[t]--;
    }

    int res = 0;
    for(auto x : bucket){
        if(x.second > res) res = x.second;
    }

    cout << res << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include<iostream>
using namespace std;
#define pii pair<int,int>
#define ll long long
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define gap ' '
#define abs(x) ((x)>0?(x):-(x))
#define INF 1e18
#define mod  10000007
int main()
{
 ios::sync_with_stdio(0);
    cin.tie(0);
    int n,w;
    cin>>n>>w;
    vector<pii> v;
    for(int i=0;i<n;i++)
    {
        int W,V;
        cin>>W>>V;
        v.pb({W,V});

    }
    ll dp[n+1][w+1];
    for(int i=0;i<=n;i++)
        for(int j=0;j<=w;j++)
        dp[i][j]=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<=w;j++)
        {
            if(j-v[i-1].fi>=0) dp[i][j]=max(dp[i-1][j-v[i-1].fi]+v[i-1].se,dp[i-1][j]);
            else dp[i][j]=dp[i-1][j];
        }
    }
    ll mx=0;
for(int i=0;i<=w;i++)
    mx=max(mx,dp[n][i]);
cout<<mx;
}


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

int main()
{
    char s[10] = {0};
    scanf("%s",s);
    int i, j, k;
    int max = 0;
    for(i=0;i<10;i++){
        k = 0;
        for(j=i;j<10;j++){
            if (s[j] == 'A' || s[j] == 'T' || s[j] == 'G' || s[j] == 'C'){
                k++;
            }else{
                break;
            }
        }
        if(k > max){
            max = k;
        }
    }
    printf("%d\n",max);
    return 0;
}

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


int main() {
    string s;
    cin >> s;
    vector<int> d(26,0);
    rep(i,s.length())d[s[i]-'a']++;
    rep(i,26){
        if(d[i] > 1){
            cout << "no\n";
            return 0;
        }
    }
    cout << "yes\n";
    return 0;
}
/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

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

template <typename TYPE>
void print_vec(const vector<TYPE>& v){
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
  cout << endl;
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   " << endl;
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}
 
int main(){
	int N, X, Y;
	cin >> N >> X >> Y;
	X--; Y--;

	
	
	//BFS解法
	//vec[i]: ノードiと隣接してるノードの列
	vector<vector<ll>> vec(N, vector<ll>());
	for(int i=0; i<N-1; i++){
		vec[i].push_back(i+1);
		vec[i+1].push_back(i);
	}
	vec[X].push_back(Y);
	vec[Y].push_back(X);
	//cout << " vec:" << endl; print_vec2(vec);
	vector<ll> ans(N+1, 0);//cnt[k]:歩数kかかる組み合わせ
	typedef pair<int, int> P;
	for(int s=0; s<N; s++){
		vector<ll> cost(N, -1);//ノードsからの最小手数
		queue<P> q;// first:注目ノード, second:注目ノードの親
		q.push(P(s, -1));
		cost[s] = 0;
		while(!q.empty()){
			int node = q.front().first;
			int parent = q.front().second;
			q.pop();
			for(int j=0; j<vec[node].size(); j++){
				int child = vec[node][j];
				//if(child == parent) continue;//
				if(cost[child] != -1) continue;//
				cost[child] = cost[node] + 1;
				q.push(P(child, node));
			}
			//if(s==0){cout << " cost: "; print_vec(cost);}
		}

		for(int i=0; i<cost.size(); i++){
			ans[cost[i]]++;
		}

	}
	for(int i=1; i<=N-1; i++){
		cout << ans[i]/2 << endl;
	}

	//数学的な解法 //解説PDFの解法
	// vector<ll> ans(N+1, 0);//cnt[k]:歩数kかかる組み合わせ
	// for(int s=0; s<=N-2; s++){
	// 	for(int g=s+1; g<=N-1; g++){
	// 		ll steps1 = g - s;//XYの道を使わない歩数
	// 		ll steps2 = abs(s-X) + 1 + abs(Y-g); //XYの道を使う歩数
	// 		ll mn = (steps1 < steps2) ? steps1 : steps2;
	// 		ans[mn]++;
	// 	}
	// }

	// for(int i=1; i<=N-1; i++){
	// 	cout << ans[i] << endl;
	// }

}


Measured memory_bytes: 3704
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
	string a, b;
	int c = 0;
	cin >> a >> b;
	for (int i = 0; i < a.size(); i++) {
		if (a[i] != b[i]) {
			c++;
		}
	}
	cout << c;
}

Measured memory_bytes: 3920
N, M, X = map(int, input().split())
CA = [list(map(int, input().split())) for i in range(N)]
ans = 10**9
for i in range(1, 2**N):
    tmp = 0
    S = [0]*M
    for j in range(N):
        if(i >> j) % 2 == 1:
            tmp += CA[j][0]
            for k in range(M):
                S[k] += CA[j][k+1]
        if min(S) >= X:
            ans = min(ans, tmp)
if ans == 10**9:
    print(-1)
else:
    print(ans)


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

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

int main(){
    int d, n, m;
    while(std::cin >> d, d){
        std::cin >> n >> m;
        
        int D[100001];
        D[0] = 0;
        D[n] = d;

        FOR(i, 1, n){
            std::cin >> D[i];
        }

        std::sort(D, D+n+1);

        int res = 0;

        REP(i, m){
            int k;
            std::cin >> k;

            int pos = std::lower_bound(D, D+n+1, k) - D,
                dist = D[pos] - k;

            if(pos - 1 >= 0){
                dist = std::min(dist, k - D[pos-1]);
            }

            res += dist;
        }

        std::cout << res << std::endl;
    }
    
}

Measured memory_bytes: 1560
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {

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

		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] P = new int[N];
		String[] ans = new String[M];

		Map<Integer, int[]> citys = new TreeMap<>();

		for(int i=0;i<M;i++) {
			int n = sc.nextInt();
			int y = sc.nextInt();
			int[] info = new int[2];
			info[0] = n;
			info[1] = i;
			citys.put(y, info);
		}

		for(int key : citys.keySet()) {
			int[] c = citys.get(key);
			ans[c[1]] = String.format("%06d%06d", c[0],++P[c[0]-1]);
		}

		for(String a : ans) {
			System.out.println(a);
		}

		sc.close();


	}
}


Measured memory_bytes: 166624
n,k = map(int,input().split(' '))
ans = n*(-k*(k-1)//2+(n+2)*(n+1)//2) + k*(k-1)*(2*k-1)//6 - k*(k-1)//2 - (n+1)*(n+2)*(2*n+3)//6 + (n+1)*(n+2)//2 + n-k+2
print(ans%(pow(10,9)+7))

Measured memory_bytes: 9196
a = []
for i in range(3):
  t = [int(x) for x in input().split()]
  a.append(t)
n = int(input())
b = [int(input()) for i in range(n)]
m = [[0 for j in range(3)] for i in range(3)]
for i in range(3):
  for j in range(3):
    for k in b:
      if (a[i][j] == k):
        m[i][j] = 1
for i in range(3):
  if (m[i][0] and m[i][1] and m[i][2]):
    print("Yes")
    exit()
for i in range(3):
  if (m[0][i] and m[1][i] and m[2][i]):
    print("Yes")
    exit()
if ((m[0][0] and m[1][1] and m[2][2]) or (m[0][2] and m[1][1] and m[2][0])):
  print("Yes")
  exit()
print("No")

Measured memory_bytes: 9204
package main

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

func main() {
    r := bufio.NewReader(os.Stdin)
    w := bufio.NewWriter(os.Stdout)
    defer w.Flush()

    var n int
    fmt.Fscan(r, &n)
    
    ans := 0

    for i := 1; i <= n; i++ {
      if len(fmt.Sprint(i)) % 2 == 1 {
        ans++
      }
    } 
    fmt.Fprintln(w, ans)
}


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

int main() {
    int x, y;
    cin >> x >> y;

    while(!(x == 0 && y == 0)) {
        if (x > y) {
            int temp = x;
            x = y;
            y = temp;
        }

        cout << x << " " << y << endl;
        cin >> x >> y;
    }

    return 0;
}


Measured memory_bytes: 3100
from collections import defaultdict


class UnionFind():
    n = 1
    par = [0]
    rnk = [0]

    def __init__(self, size):
        self.n = size
        self.par = [i for i in range(self.n)]
        self.rnk = [0 for i in range(self.n)]

    def find(self, vertex1):
        if self.par[vertex1] == vertex1:
            return vertex1
        else:
            self.par[vertex1] = self.find(self.par[vertex1])
            return self.par[vertex1]

    def unite(self, vertex1, vertex2):
        vertex1 = self.find(vertex1)
        vertex2 = self.find(vertex2)
        if vertex1 == vertex2:
            return
        if (self.rnk[vertex1] < self.rnk[vertex2]):
            self.par[vertex1] = vertex2
        else:
            self.par[vertex2] = vertex1
            if (self.rnk[vertex1] == self.rnk[vertex2]):
                self.rnk[vertex1] += 1

    def same(self, vetrex1, vertex2):
        return self.find(vetrex1) == self.find(vertex2)


N = int(input())
P = [(i,) + tuple(map(int, input().split())) for i in range(N)]
G = UnionFind(N)
P.sort(key=lambda x: x[1])
for i in range(N - 1):
    if P[i][1] == P[i + 1][1]:
        G.unite(P[i][0], P[i + 1][0])
P.sort(key=lambda x: x[2])
for i in range(N - 1):
    if P[i][2] == P[i + 1][2]:
        G.unite(P[i][0], P[i + 1][0])
P.sort(key=lambda x: x[0])
Dx = defaultdict(set)
Dy = defaultdict(set)
for i in range(N):
    j = G.find(i)
    Dx[j].add(P[i][1])
    Dy[j].add(P[i][2])
ans = -N
for j in Dx:
    ans += len(Dx[j]) * len(Dy[j])
print(ans)

Measured memory_bytes: 31028
#include <cstdio>
#define rg register
using namespace std;
typedef long long ll;
const int maxn=200010,mod=1e9+7;
template <typename Tp> inline int getmin(Tp &x,Tp y){return y<x?x=y,1:0;}
template <typename Tp> inline int getmax(Tp &x,Tp y){return y>x?x=y,1:0;}
template <typename Tp> inline void read(Tp &x)
{
    x=0;int f=0;char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') f=1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    if(f) x=-x;
}
int n,m,a,b,ans,fac[maxn],inv[maxn];
inline int c(int n,int m){return m>n?0:(ll)fac[n]*inv[m]%mod*inv[n-m]%mod;}
inline int dec(int x,int y){return x-y<0?x-y+mod:x-y;}
int power(int x,int y)
{
	int res=1;
	for(;y;y>>=1,x=(ll)x*x%mod)
	  if(y&1)
	    res=(ll)res*x%mod;
	return res;
}
int main()
{
	read(n);read(m);read(a);read(b);
	fac[0]=1;
	for(rg int i=1;i<=n+m;i++) fac[i]=(ll)fac[i-1]*i%mod;
	inv[n+m]=power(fac[n+m],mod-2);
	for(rg int i=n+m-1;~i;i--) inv[i]=(ll)inv[i+1]*(i+1)%mod;
	ans=c(n+m-2,n-1);
	for(rg int i=1;i<=b;i++) ans=dec(ans,(ll)c(i+n-a-2,i-1)*c(a+m-i-1,a-1)%mod);
	printf("%d\n",ans);
	return 0;
}

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

int main(){
    string s;
    cin >> s;
    int last = s.size()-2;
    while(last>1){
        if(s.substr(0,last/2)==s.substr(last/2,last/2)&&last%2==0)break;
        else last--;
    }
    cout << last << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){

    int i,j,ii,n,m,count,c;
    int num[1001];
    int flag[1001];


    while(scanf("%d%d",&n,&m),n+m){

        count=0;
        for(i=0;i<1001;i++){
            num[i]=0;
            flag[i]=0;
        }
        for(i=0;i<n+1;i++){
            num[i]=i;
        }
        i=0;
        while(1){
            count=0;
            while(count!=m){
                //puts("+");
                i++;
                if(i>n){
                    i%=n;
                }
 
                if(flag[i]==0){
                    count++;
                }
           }

            //ii=i;

            //printf("%d ",num[i]);
            //if(num[i]==n&&flag[i]==0) i=1;

            flag[i]=1;
            c=0;

            for(j=1;j<=n;j++){
                //puts("*");
                if(flag[j]==0){
                    c++;
                    ii=j;
                }
            }
            if(c==1) break;
        }
        printf("%d\n",num[ii]);
    }
    return 0;
}

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

ll mod(ll a, ll b){
  ll ret=a%b;
  if(ret<0) ret+=b;
  return ret;
}

ll modpow(ll a,ll b,ll c){
  ll res=1;
  while(b>0){
    if(b&1) res=mod(res*a,c);
    a=mod(a*a,c);
    b>>=1;
  }
  return res;
}

int main() {
  ll n;
  cin>>n;
  ll ans=0;
  for(ll i=0;i<n;i++){
    ans+=(i+1)*(n-i);
  }
  for(ll i=0;i<n-1;i++){
    ll u,v;
    cin>>u>>v;u--;v--;
    if(u>v) swap(u,v);
    ans-=(u+1)*(n-v);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3612
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
    n=parseInt(readline())
    w=parseMap(split(readline()))
    s=sum(w)
    s1=0
    ans=10000000
    for i in 1:n
        s1+=w[i]
        ans=min(abs((s-s1)-s1),ans)
    end
    println(ans)
end
main()

Measured memory_bytes: 166436
#include <bits/stdc++.h>
#define endl "\n"

using namespace std;

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

    int last_char = str.size() - 1;

    if(str[last_char] == 's')
    {
        cout << str << "es" << endl;
    }
    else
    {
        cout << str << "s" << endl;
    }

    return 0;
}



Measured memory_bytes: 3616
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};
 
static const double EPS = 1e-8;

ll dp[6][100001]; //dp[pos][buffered char][hidden or not]

const static ll MOD = 100000007;

int main(){
  string text;

  memset(dp,0,sizeof(dp));
  dp[3][0] = 0;
  dp[3][1] = 1;
  dp[3][2] = 2;

  dp[5][0] = 0;
  dp[5][1] = 1;
  dp[5][2] = 2;
  dp[5][3] = 4;
  dp[5][4] = 8;

  for(int text_i = 0; text_i < 100000; text_i++){
    dp[3][text_i + 3] += 1;
    for(int offset = 0; offset <= 2; offset++){
      dp[3][text_i + 3] += dp[3][text_i + offset];
      dp[3][text_i + 3] %= MOD;
    }

    dp[5][text_i + 5] += 1;
    for(int offset = 0; offset <= 4; offset++){
      dp[5][text_i + 5] += dp[5][text_i + offset];
      dp[5][text_i + 5] %= MOD;
    }
  }

  while(cin >> text){
    if(text == "#") break;

    ll res = 1;
    int length = 1;
    for(int text_i = 0; text_i + 1 < text.size(); text_i++){
      if(text[text_i] == text[text_i + 1]){
        length++;
      }
      else{
        if(text[text_i] == '8' || text[text_i] == '0'){
          res = (res * dp[3][length]) % MOD;
          res %= MOD;
        }
        else{
          res = (res * dp[5][length]) % MOD;
          res %= MOD;
        }
        length = 1;
      }
    }

    if(length > 0){
      if(text[text.size() - 1] == '8' || text[text.size() - 1] == '0'){
        res = (res * dp[3][length]) % MOD;
        res %= MOD;
      }
      else{
        res = (res * dp[5][length]) % MOD;
        res %= MOD;
      }
    }
    printf("%lld\n",res % MOD);
  }
}

Measured memory_bytes: 6024
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)

int main(){
    vector<int> v;
    int n,k;
    cin >> n >> k;
    ll h;
    REP(i, n)
    {
        cin >> h;
        v.push_back(h);
    }
    sort(v.begin(), v.end());
    ll ans = 1000000000000000000;
    REP(i, n - k+1)
    {
        if(ans>(v[i+k-1]-v[i]))
            ans = v[i + k - 1] - v[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a,b,sum=0;
  int foreign=0;
  char s[100010];
  cin>>n>>a>>b;
  for(int i=0;i<n;i++){
    cin>>s[i];
    if(s[i]=='a'){
      if(a+b>sum){
        cout<<"Yes"<<'\n';
        sum++;
      }
      else cout<<"No"<<'\n';
    }
    else if(s[i]=='b'){
      if(a+b>sum&&b>foreign){
        cout<<"Yes"<<'\n';
        sum++;
        foreign++;
      }
      else cout<<"No"<<'\n';
    }
    else cout<<"No"<<'\n';
  }
  return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
#define P pair<int,int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define endl '\n'
#define ll long long

signed main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];

    int ans = 1e9;
    for(int i = 1; i <= 100; i++){
        int res = 0;
        for(int j = 0; j < n; j++){
            res += (i - a[j]) * (i - a[j]);
        }
        ans = min(ans,res);
    }
    cout << ans << endl;
}


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

int n;
vector<unsigned long long int> h;

void input() {
    cin >> n;
    h = vector<unsigned long long int>(n);
    for(int i = 0; i< n; i++) {
        cin >> h.at(i);
    }
}

void solve() {
    unsigned long long int tmp = h.at(0);
    unsigned int max = 0;
    unsigned int count = 0;
    for(unsigned int i = 1; i< h.size(); i++) {
        if(tmp >= h.at(i)) {
            ++count;
            if (count > max) {
                max = count;
                //cout << "i: " << i << endl;
                //cout << "tmp: " << tmp << endl;
            }
        } else {
            count = 0;
        }
        tmp = h.at(i);
    }
    cout << max << endl;

}

int main() {
    input();
    solve();

}


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

using namespace std;

#define REP(i, n) for(int i = 0; i < (n); i++)
#define SREP(i, s) for(int i = 0; i < (s.length()); i++)
#define SORT(v, n) sort(v, v+n);
#define GSORT(v, n) sort(v, v+n, greater<int>())
#define REV(a) reverse(begin(a),end(a));

int main(){
	ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////
	int n,a;
	cin >> n >> a;
	cout << pow(n,2)-a << endl;

//////////////////////////////////////////////
}


Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <chrono>
#include <complex>
#include <cstdint>
#include <cstring>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <ostream>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using ll = int64_t;
using vll = vector<ll>;
struct Solution {
    void solve(std::istream& in, std::ostream& out) {
        ll n, t;
        in >> n >> t;
        vll a(n);
        for (int i = 0; i < n; i++) {
            in >> a[i];
        }
        ll ans = 0;
        for (int i = 1; i < n; i++) {
            if (a[i] - a[i - 1] >= t) {
                ans += t;
            }
            else {
                ans += a[i] - a[i - 1];
            }
        }
        ans += t;
        out << ans << '\n';
    }
};
void solve(std::istream& in, std::ostream& out) {
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream& in = cin;
    ostream& out = cout;
    solve(in, out);
    return 0;
}


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

int main() {
    vector<bool> r(8, false);
    int n, m = 0, a;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a;
        if (a < 3200) r[a/400] = true;
        else m++;
    }
    int ans = 0;
    ans += count(r.begin(), r.end(), true);
    int ansma = ans + m;
    int ansmi = max (ans, 1);
    printf ("%d %d", ansmi, ansma);
}

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

#define INF 1e9
#define llINF 1e18
#define MOD 1e9+7
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
using namespace std;
int main(){
  int n;cin>>n;
  vector<int>num(n);
  bool flag=true;
  for(int i=0;i<n;i++){
    cin>>num[i];
  }
  if(num[0]!=0)flag=false;
  for(int i=1;i<n;i++){
    if(num[i]-num[i-1]>1){flag=false;break;}
  }
  if(flag){
    ll ans=num[n-1];
    for(int i=n-2;i>0;i--){
      if(num[i]==num[i+1]){ans+=num[i];
      }else if(num[i]<num[i+1]){
	;
      }else{
	ans+=num[i];
      }
    }
    cout<<ans<<endl;
  }else{
    cout<<-1<<endl;
  }
  return 0;
}


Measured memory_bytes: 1152
#include "bits/stdc++.h"
using namespace std;
 
int main(){
  string n;
  cin>>n;
  if(n[0]==n[1]&&n[1]==n[2]||n[3]==n[1]&&n[1]==n[2]){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
 
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <boost/algorithm/string/join.hpp>
#include <boost/range/irange.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using boost::irange;
using boost::algorithm::join;

typedef long long ll;
typedef unsigned long long ull;
//typedef long double ld;

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

constexpr ll MOD = 1e9+7;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/4;
constexpr int INF=inf<int>;
constexpr ll LINF=inf<ll>;

#define Sort(x) sort(begin(x),end(x))
#define Reverse(x) reverse(begin(x),end(x))
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ull<<(n))
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,v) REP(i,(v).size())

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
    #define endl "\n"
  }
} before_main_function;

// ========== end of template ==========

int main(int argc, char** argv) {
  int N;
  cin >> N;

  vi D(N);
  for (auto& d : D) {
    cin >> d;
  }

  ll ret = 0;
  REP(i, N-1) {
    for (int j=i+1; j<N; j++) {
      ret += D[i]*D[j];
    }
  }

  cout << ret << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define pi std::pair<int, int>
#define mkp std::make_pair
#define ll long long
#define pb push_back
#define fi first
#define se second

//{{{IO
namespace IO{
	template <class I> void read(I &x){
		x = 0; char ch = getchar(); bool f = false;
		for(; !isdigit(ch); ch = getchar()) f |= (ch == '-');
		for(; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + ch - '0';
		return ;
	}

	int read_int(){ int x; return read(x), x;}
	ll read_ll(){ ll x; return read(x), x;}
	template <class I>
		void chmax(I &x, I y){x = x > y ? x : y;}
	template <class I>
		void chmin(I &x, I y){x = x < y ? x : y;}
#define ri read_int()
#define rl read_ll()
}
using IO::read_int;
using IO::read_ll;
using IO::chmax;
using IO::chmin;
//}}}

//{{{Mod
namespace Mod{
//	const int mod = 1e9 + 7;
//	const int mod = 1004535809;
	const int mod = 998244353;
	
	inline void MOD(int &x){ x -= x >= mod ? mod : 0;}
	inline void add(int &x, int y){ x = x + y >= mod ? x + y - mod : x + y;}
	inline int Add(int x, int y){ return x + y >= mod ? x + y - mod : x + y;}
	inline void mul(int &x,  int y){ x = 1ll * x * y % mod;}
	inline int Mul(int x, int y){ return 1ll * x * y % mod;}
}
//}}}

#define N 100005

int n, s, cnt;
int x[N], num[N];
ll a[N];

void solve(int l, int r){
	if(l > r) return ;
	if(l == r) return num[++cnt] = l, void();
	if(x[l] > s){
		while(r >= l) num[++cnt] = r--;
		return ;
	}
	if(x[r] < s){
		while(r >= l) num[++cnt] = l++;
		return ;
	}
	if(a[l] >= a[r]){
		num[++cnt] = r; a[l] += a[r]; solve(l, r - 1);
	}
	else{
		num[++cnt] = l; a[r] += a[l]; solve(l + 1, r);
	}
	return ;
}

int main(){
	n = ri; s = ri;
	for(int i = 1; i <= n; ++i)
		x[i] = ri, a[i] = ri;
	solve(1, n); ll res = 0;
//	for(int i = cnt; i >= 1; --i)
//		debug("%d ", num[i]);
	for(int i = cnt; i >= 1; --i) 
		res += abs(x[num[i]] - s), s = x[num[i]];
	printf("%lld\n", res);
	return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		while(true){
			int coin=100;
			int b = cin.nextInt();
			int r = cin.nextInt();
			int g = cin.nextInt();
			int c = cin.nextInt();
			int s = cin.nextInt();
			int t = cin.nextInt();
			if(b+r+g+c+s+t==0){
				break;
			}
			t = t-b*5-r*3;
			int bonusGame=b*5+r*3;
			for(int i =0; i < bonusGame;i++){
				coin+=13;
			}
			for(int i = 0; i < b;i++){
				coin+=12;
			}
			for(int i = 0; i < r;i++){
				coin+=12;
			}
			for(int i = 0; i < g;i++){
				coin+=4;
			}
			for(int i = 0; i < c;i++){
				coin-=1;
			}
			t = t-b-r-g-c-s;
			coin -= t*3;
			System.out.println(coin);
		}
	}

}

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

using namespace std;

int main(){
    string n;
    cin >> n;
    if(n[0] == '7' || n[1] == '7' || n[2] == '7'){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

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

public class Main {

	static int N;

	public static void main(String[] args) {

		FastScanner sc = new FastScanner();
		N = sc.nextInt();

		switch (check(N)) {
		case 1:
			System.out.println(N);
			break;
		case 2:
			System.out.println(9);
			break;
		case 3:
			System.out.println(N - 90);
			break;
		case 4:
			System.out.println(909);
			break;
		case 5:
			System.out.println(N - 9999 + 909);
			break;
		case 6:
			System.out.println(90909);
			break;
		}

	}

	public static int check(int a) {
		return String.valueOf(a).length();
	}

}

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: 21204
#include<iostream>
#include<algorithm>
using namespace std;

int main(){
  int a,b,c;
  cin>>a>>b;
  if(b>a)swap(a,b);
  while(b>0){
    c=a%b;
    a=b;
    b=c;
  }
  cout<<a<<endl;
  return 0;
}



Measured memory_bytes: 3056
#include <bits/stdc++.h>
     
#define pll pair <long long,long long>
#define pb push_back
#define ll long long
#define ff first
#define ss second
#define vll vector <ll>
#define NFS ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl '\n'
#define M 1000000007   
using namespace std;
ll power(ll x, ll y, ll m) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2, m) % m; 
    p = (p * p) % m; 
  
    return (y%2 == 0)? p : (x * p) % m; 
}  
ll modInverse(ll a, ll m) 
{  
    return power(a, m-2, m);  
} 
ll pwr(ll x, ll y,ll p)  
{  
    ll res = 1; 
  
    x = x % p; 
    while (y > 0)  
    {  
        if (y & 1)  
            res = (res*x) % p;  
  
        y = y>>1;   
        x = (x*x) % p;  
    }  
    return res;  
}  

ll cr(ll n,ll x,ll m)
{
	ll res=1;
	for(int i=n;i>=n-x+1;i--)
	{
		res=((res%m)*(i%m))%m;
		res=res%m;
	}
	//cout<<res<<endl;
	for(int i=x;i>=1;i--)
	{
		res=(res*modInverse(i,m))%m;
		res=res%m;
	}
	return res;
}

int main()
{
    NFS
 	ll n,a,b;
 	cin>>n>>a>>b;
 	ll ans=0;
 	ans+=pwr(2,n,M)-1;
 	//cout<<ans<<endl;
 	ll p=cr(n,a,M);
 	ll q=cr(n,b,M);
 	//cout<<p<<" "<<q<<endl;
 	ans=(ans-p+M)%M;
 	ans=(ans-q+M)%M;
 	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  for(int i=0;i<n;i++){
    if(i-a[i]<-1){
      cout<<-1;
      return 0;
    }
  }
  deque<int> deq;
  
  for(int i=0;i<n;i++){
    for(int j=a.size()-1;j>=0;j--){
      if(j+1==a[j]){
        deq.push_front(a[j]);
        a.erase(a.begin()+j);
        break;
      }
    }
  }
  
  for(int e:deq){
    cout<<e<<endl;
  }
}

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

int main(void)
{
	int n, m;
	cin >> n >> m;
	vector<int> ac(n), pena(n);
	for (int i = 0; i < m; i++)
	{
		int p;
		string s;
		cin >> p >> s;
		p--;
		if (ac[p] == 1) continue;
		if (s == "AC") ac[p]=1;
		else
			pena[p]++;
	}
	int AC = 0, PENA = 0;
	for (int i = 0; i < n; i++)
	{
		AC += ac[i];
		if (ac[i] == 1) PENA += pena[i];
	}
	printf("%d %d\n", AC, PENA);
	
}


Measured memory_bytes: 1024
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author CodeMonk
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int a = in.nextInt(), b = in.nextInt(), c = in.nextInt(), d = in.nextInt(), e = in.nextInt(), f = in.nextInt();
            int[] ok = new int[50];
            ok[0] = 1;
            for (int i = 1; i < 50; i++) {
                if (i - a >= 0) ok[i] |= ok[i - a];
                if (i - b >= 0) ok[i] |= ok[i - b];
            }
            int[] ok2 = new int[4000];
            ok2[0] = 1;
            for (int i = 1; i < 4000; i++) {
                if (i - c >= 0) ok2[i] |= ok2[i - c];
                if (i - d >= 0) ok2[i] |= ok2[i - d];
            }
            long mw = 1, ms = -1;
            for (int i = 1; 100 * i <= f && i < 50; i++) {
                for (int j = 0; 100 * i + j <= f && j < 4000; j++) {
                    if (j > i * e) continue;
                    if (ok[i] == 0) continue;
                    if (ok2[j] == 0) continue;
                    if (ms * (100 * i + j) < (100 * mw + ms) * j) {
                        mw = i;
                        ms = j;
                    }
                }
            }
            out.println(mw * 100 + ms + " " + ms);
        }

    }
}



Measured memory_bytes: 22612
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=110;
int h[N],ans;
void solve(int l,int r)
{
  if(l>r) return;
  int m=110;
  for(int i=l;i<=r;i++) m=min(m,h[i]);
  for(int i=l;i<=r;i++) h[i]-=m;
  ans+=m;
  vector<int> idx;
  for(int i=l;i<=r;i++) if(h[i]==0) idx.push_back(i);
  solve(l,idx[0]-1);
  solve(idx[idx.size()-1]+1,r);
  for(int i=1;i<idx.size();i++) solve(idx[i-1]+1,idx[i]-1);
}
int main()
{
  int n;
  cin>>n;
  for(int i=1;i<=n;i++) cin>>h[i];
  solve(1,n);
  // for(int i=1;i<=n;i++) cout<<h[i]<<" ";
  // cout<<endl;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define int long long int
#define f(i,a,b) for (int i= a; i <b; ++i)
using namespace std;

signed main()
{
	ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    int dp[n];
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    for(int i=2;i<n;i++)
    {
        int x=dp[i-1]+abs(a[i]-a[i-1]);
        int y=dp[i-2]+abs(a[i]-a[i-2]);
        dp[i]=min(x,y);
    }
    cout<<dp[n-1];
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    ll H, N;
    cin >> H >> N;
    ll A[N], B[N];
    rep(i, N) cin >> A[i] >> B[i];
    ll dp[H+1];
    fill(dp, dp+H+1, INF);
    dp[0] = 0;
    rep(i, N){
        rep(j, H+1){
            int k = min(j+A[i], H);
            chmin(dp[k], dp[j]+B[i]);
        }
    }
    cout << dp[H] << endl;
}

Measured memory_bytes: 384
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    mod = 10**9 + 7

    N = int(input())

    #隣接リスト作成
    adj = [[] for _ in range(N)] #頂点数, 場合によって変える
    for _ in range(N-1):
        a,b = map(int, input().split())
        adj[a-1].append(b-1)
        adj[b-1].append(a-1)


    #parent[i]:iの親が格納されてる
    parent = [-1]*(N)
    #order:根からDFSで見る順番に頂点を入れる
    order = []
    d = deque([0])
    #全頂点の親をDFSの要領で決める, 根(頂点0)の親は-1
    while d:
        x = d.pop()
        order.append(x)
        for y in adj[x]:
            if y==parent[x]:
                continue
            parent[y] = x
            d.append(y)

    #dp[i]:iを根とする部分木の場合の数
    dp_b = [1]*(N+1)
    dp_w = [1]*(N+1)

    #orderの逆順で計算していく
    for x in order[::-1]:
        b,w = dp_b[x], dp_w[x]
        p = parent[x]
        dp_b[p] *= w%mod
        dp_w[p] *= (b+w)%mod

    print((dp_b[0]+dp_w[0])%mod)

if __name__ == '__main__':
    main()

Measured memory_bytes: 31920
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <bitset>
#include <cstdio>
#include <set>
#include <stack>
#include <queue>
#include <cassert>
#include <numeric>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
    REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}
#define vi vector<int>
#define vii vector<vector<int>>
#define mii map<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
//#define int ll

const int md = 1000000007;
const int INF = 1<<30;



int main(){
    int n,k; cin >> n >> k;
    if (k == 1) cout << 0 << endl;
    else cout << n - k << endl;
}


Measured memory_bytes: 256
<?php
$haveCardNum = trim(fgets(STDIN));
$cardCheckList = createCardCheckList();
$nullCards = '';
 
for ($i = 0; $i < $haveCardNum; $i++) {
    list($mark, $num) = getSpacesByExplodeTrimInput();
    $cardCheckList[$mark][$num] = 'check';
}
 
foreach ($cardCheckList as $mark => $value) {
    for ($cardNum = 1; $cardNum <= 13; $cardNum++) {
        if (! isset($cardCheckList[$mark][$cardNum])) {
            $nullCards .= sprintf('%s %d', $mark, $cardNum).PHP_EOL;
        }
    }
}

echo $nullCards;
 
function getSpacesByExplodeTrimInput()
{
    return explode(' ', trim(fgets(STDIN)));
}
 
function createCardCheckList()
{
    foreach(array('S', 'H', 'C', 'D') as $mark) {
        $checkList["$mark"] = array_fill(1, 13, null);
    }
    return $checkList;
}

Measured memory_bytes: 15504