akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
  

int main(){
  int n,sum=0,mi=100000,sa=100000;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a.at(i);
    sum+=a.at(i);
  }
  for(int i=0;i<n;i++){
    if((a.at(i)*n-sum)*(a.at(i)*n-sum)<sa*sa){
      sa=max(a.at(i)*n-sum,sum-a.at(i)*n);
      mi=i;
    }
  }
  cout<<mi<<endl;
  
  
}

Measured memory_bytes: 256
li = input().split()
if ('7' in li) == True:
    if ('5' in li) == True:
        if li[0] == '5':
            if li[1] == '5' or li[2] == '5':
                print("YES")
            else:
                print("NO")
        elif li[1] == '5' and li[2] == '5':
            print("YES")
        else:
            print("NO")
    else:
        print("NO")
else:
    print("NO")

Measured memory_bytes: 3060
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    String S = sc.next();
    int ans=0;
    String tmp="";
    for(int i=0;i<1000;i++){

      tmp=String.format("%03d",i);
      if(isNum(S,tmp,N)){
        ans++;
        //System.out.println(tmp);
      }
    }
    System.out.println(ans);
  }
  static boolean isNum(String S,String tmp,int N){
    //Sの中にtmpがあるかどうか確認する
    //tmpの1文字目があるかどうか
    for(int i=0;i<N;i++){
      if(tmp.substring(0,1).equals(S.substring(i,i+1))){
        //二文字目がそれ以降にあるか
        for(int j=i+1;j<N;j++){
          if(tmp.substring(1,2).equals(S.substring(j,j+1))){
            //3文字目がそれ以降にあるか
            for(int k=j+1;k<N;k++){
              if(tmp.substring(2,3).equals(S.substring(k,k+1))){
                return true;
              }
            }
            return false;
          }
        }
        return false;
      }
    }
    return false;
  }


}
 

Measured memory_bytes: 348960
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(long long int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    long long int n;
    cin>>n;
    vector<long long int> v(n);
    REP(i,n){
        scanf("%lld",&v[i]);
    }

    sort(v.begin(),v.end());
    long long int min_length, max_length,result=0,tyosei;
    REP(i,n-1){
        FOR(j,i+1,n){
           
            min_length = distance(v.begin(), upper_bound(v.begin(), v.end(), abs(v[j] - v[i])));
            max_length = distance(v.begin(), lower_bound(v.begin(), v.end(), v[j] + v[i]));
            //cout << min_length << " " << max_length << endl;
             tyosei = max_length - min_length;
            if(min_length<=i&&i<max_length){
                tyosei--;
            }
            if(min_length<=j&&j<max_length){
                tyosei--;
            }
            result += max(0ll, tyosei);
        }
    }
    cout << result/3 << endl;


    return 0;
}


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

using namespace std;
typedef long long ll;

#define MOD 1000000007

int main(void)
{
  int h, w;
  char str[100][100];
  string temp = "";

  cin >> h >> w;
  for(int i=0; i<h; i++) {
    for(int j=0; j<w; j++) {
      cin >> str[i][j];
    }
  }

  for(int i=0; i<2*h; i++) {
    for(int j=0; j<w; j++) {
      temp += str[((i+2)/2)-1][j];
    }
    cout << temp << endl;
    temp = "";
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{

	// #ifndef HAPHAZARD_CODE
	// 	freopen("input.txt","r",stdin);
	// 	freopen("output.txt","w",stdout);
	// #endif

		int m,n,o;
		cin>>m>>n>>o;

		if((n*o)>=m) cout<<"Yes"<<endl;
		else cout<<"No"<<endl;

	//cout<<"HEY "<<n;

	return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<string> s(n);
    for (int i = 0; i < n; i++) {
        cin >> s[i];
    }
    sort(s.begin(), s.end());
    int mx = 1, cnt = 1;
    for (int i = 1; i < n; i++) {
        if (s[i].compare(s[i - 1]) == 0) {
            cnt++;
        } else {
            mx = max(cnt, mx);
            cnt = 1;
        }
    }
    mx = max(cnt, mx);
    cnt = 0;
    for (int i = 0; i < n; i++) {
        if (i == 0 || s[i].compare(s[i - 1]) == 0) {
            cnt++;
        } else {
            mx = max(cnt, mx);
            cnt = 1;
        }
        if (cnt == mx) {
            cout << s[i] << "\n";
        }
    }
    return 0;
}

Measured memory_bytes: 12928
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
#define pll pair<ll,ll>
using ll=long long;
using ld=long double;
const ll INF = 1LL<<60;
const ll mod=1e9+7;
const ll mod2= 998244353;
using namespace std;
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
map<ll,ll> w;
ll n,x,m;

ll fc(ll st,ll p){
    ll pos=0;
    ll t=st;
    ll ans=0;
    while(pos<p){
        ans+=t;
        t=t*t;
        t%=m;
        pos++;
    }
    return ans;
}
int main(){
    ll ans=0;
    cin>>n>>x>>m;
    ll pos=0;
    ll t=x,st=0,e=0,now;
    while(w[t]==0&&pos<n){
        w[t]=pos;
        ans+=t;
        t=t*t;
        t%=m;
        pos++;
        now=t;
        e=w[t];
        st=pos-w[t];
       // cout<<t<<" "<<pos<<" "<<w[t]<<endl;
        
    }
   // cout<<ans<<endl;
    if(t==1)ans+=n-pos;
    else if(t!=0&&pos<n) {
        ll num=n-e;
        ll b=fc(x,e);
       // cout<<num<<endl;
        //cout<<b<<" "<<(ans-b)*(num/st)<<" "<<fc(now,num%st-1)<<endl;
        ans=b+(ans-b)*(num/st)+fc(now,num%st);
    }
    cout<<ans<<endl;
   // cout<<st;
}



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

int main() {
	int x;
	cin >> x;
	cout << x * x;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.next();
        for (int i = 0; i < s.length(); i++) {
            for (int j = i; j < s.length(); j++) {
                if (i != j && s.charAt(i) == s.charAt(j)) {
                    System.out.println("no");
                    return;
                }
            }
        }
        System.out.println("yes");
    }
}


Measured memory_bytes: 22996
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <limits>
#include <sstream>

using namespace std;

int main (void)
{
	for (int j = 0; j < 50; j++)
	{
		long n,e[4000],x[4000],y[4000],co[4000];

		cin >> n;
		if (n == 0)
		{
			break;
		}

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

		for (int i = 0; i < n; i++)
		{
			co[i] = 0;
			for (int k = 0; k < n; k++)
			{
				if (i <= k && e[i] == e[k])
				{
					co[i] += x[k] * y[k];
					if (i != k)
					{
						e[k] = -1;
					}
				}
			}
		}
	int gg = 0;
		for (int i = 0; i < n; i++)
		{
			if (e[i] != -1 && co[i] >= 1000000)
			{	gg += -1;
				cout << e[i] << endl;
			}
			if (i == n - 1 && gg == 0)
			{
				cout << "NA" << endl;
			}
		}
	}
}




Measured memory_bytes: 3052
def solve():
    def bin_l(arr, key):
        l = 0
        r = len(arr) - 1
        while l <= r:
            mid = (l + r)//2
            if arr[mid] > key:
                r = mid - 1
            else:
                l = mid + 1
            
        if l < len(arr):
            return l
        else:
            return None
    
    def bin_s(arr, key):
      l = 0
      r = len(arr) - 1
      while l <= r:
        mid = (l + r) // 2
        if arr[mid] >= key:
          r = mid - 1
        else:
          l = mid + 1
      
      if r >= 0 :
        return r
      else:
        return None
        
    n = int(input())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    C = list(map(int,input().split()))
    A = sorted(A)
    C = sorted(C)
    
    sum = 0
    for b in B:
        a = bin_s(A, b)
        c = bin_l(C, b)
        a = a + 1 if a is not None else None
        c = n - c if c is not None else None
        if a is not None and c is not None:
            sum += a*c
    
    print(sum)

if __name__ == "__main__":
    solve()


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

using namespace std;

template <typename T=int>
struct Fenwick {
    int n;
    vector<T> v;
    
    Fenwick(int size = 100005) : n(size), v(n+1, 0) {}
    inline void add(int p, T val) {
        for (; p <= n; p += (p&-p)) { v[p] += val; }
    }
    inline T query(int p) {
        T tmp = 0;
        for (; p > 0; p -= (p&-p)) { tmp += v[p]; }
        return tmp;
    }
    inline T query(int l, int r) {
        return query(r) - query(l-1);
    }
};

void solve() {
    string s; cin >> s;
    int n = s.size();
    vector<vector<int>> pos(26);
    for (int i = 0; i < n; i++) {
        pos[s[i]-'a'].emplace_back(i);
    }
    vector<int> l(26, 0), r(26);
    vector<int> odd;
    for (int i = 0; i < 26; i++) {
        r[i] = pos[i].size();
        if (r[i]&1) odd.emplace_back(i);;
    }
    if (odd.size() > (n&1)) {
        cout << -1; return;
    }

    vector<bool> trk(n, false);
    vector<int> a(n);
    if (n&1) {
        int i = odd[0];
        int p = pos[i][r[i]/2];
        trk[p] = true;
        a[p] = n/2;
    }
    int L = 0, R = n;
    for (int i = 0; i < n; i++) {
        if (trk[i]) continue;
        int k = s[i]-'a';
        a[i] = L++;
        --r[k];
        a[pos[k][r[k]]] = --R;
        trk[i] = trk[pos[k][r[k]]] = true;
    }
    //for (int i = 0; i < n; i++) {
    //    cout << a[i] << '\n';
    //}
    reverse(a.begin(), a.end());
    long long res = 0;
    Fenwick<int> st(n);
    for (int x: a){
        x++;
        res += st.query(x);
        st.add(x, 1);
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


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

int main(){
  int n;
  long long k;
  cin>>n>>k;
  vector<int> num(n);
  vector<long long> a(100001,0);
  for(int i=0;i<n;i++){
    int x;
    cin>>num[i]>>x;
    a[num[i]]+=x;
  }
  sort(num.begin(),num.end());
  long long z=a[num[0]];
  int i=0;
  while(z<k){
    i++;
    if(num[i-1]==num[i]) continue;
    z+=a[num[i]];
  }
  cout<<num[i]<<endl;
}

Measured memory_bytes: 1532
#define _CRT_SECURE_NO_WARNINGS

#include<fstream>
#include<iostream>
#include<string>
#include<iomanip>
#include<list>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

bool isprime[300000];
int data[150000];

int main(int argc, char **argv){
	int n;
	int cnt;
	int checkcnt = 0;
	for (int i = 0; i < 300000; i++) {
		isprime[i] = true;
	}
	while (cin >> n && n != 0) {
		int cnt = 0;
		for (int i = 2; i <= sqrt(2 * n); i++) {
			for (int j = 2; j <= (2 * n) / i; j++) {
				isprime[i * j] = false;
			}
		}
		for (int i = n + 1; i <= 2 * n; i++) {
			if (isprime[i]) {
				cnt++;
			}
		}
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 1460
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created by S64 on 15/07/28.
 */

// ?????????2??????32???36?§????

class Main {

    public static void main(String _[]) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

        while(true) {
            String[] counts = in.readLine().split(" ");

            int taro = Integer.parseInt(counts[0]);
            int hanako = Integer.parseInt(counts[1]);

            if(taro+hanako < 1)
                break;

            int[] taroCards = new int[taro];
            int[] hanakoCards = new int[hanako];

            for(int i = 0; i < taro; i++)
                taroCards[i] = Integer.parseInt(in.readLine());
            for(int i = 0; i < hanako; i++)
                hanakoCards[i] = Integer.parseInt(in.readLine());

            ArrayList<int[]> results = new ArrayList<int[]>();

            for(int taroKey = 0 ; taroKey < taroCards.length ; taroKey++) {
                int taroCard = taroCards[taroKey];
                for(int hanakoKey = 0 ; hanakoKey < hanakoCards.length; hanakoKey++) {
                    int hanakoCard = hanakoCards[hanakoKey];
                    int taroPoint = 0;
                    int hanakoPoint = 0;
                    {
                        for(int i = 0;i<taroCards.length;i++)
                            taroPoint += (i == taroKey) ? hanakoCards[hanakoKey] : taroCards[i];
                        for(int i = 0;i<hanakoCards.length;i++)
                            hanakoPoint += (i == hanakoKey) ? taroCards[taroKey] : hanakoCards[i];
                    }
                    {
                        if(taroPoint != hanakoPoint)
                            continue;
                        results.add( new int[] {taroCard, hanakoCard} );
                    }
                }
            }
            {
                int[] result = new int[] {0, 0};
                for(int[] v : results) {
                    int old = result[0] + result[1];
                    if(old == 0 || old > v[0] + v[1])
                        result = new int[] { v[0], v[1] };
                }
                if(result[0]+result[1] == 0)
                    System.out.println("-1");
                else
                    System.out.println( String.format("%d %d", result[0], result[1]) );
            }
        }
    }

}

Measured memory_bytes: 19992
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    int h, w;
    cin >> h >> w;
    vector<int> a(26);
    rep(i, h) rep(j, w) {
        char tmp_a;
        cin >> tmp_a;
        ++a[tmp_a-'a'];
    }

//    rep(i, 26) cout << a[i] << " ";
//    cout << endl;

    int g1 = 0;
    int g2 = 0;
    int g4;
    if ( (h&1) && (w&1) ) g1 = 1;

    if ( (h&1) && (w&1) ) g2 = ( h - 1 + w - 1 ) / 2;
    else if ( (h&1)     ) g2 = w / 2;
    else if ( (w&1)     ) g2 = h / 2;

    if ( (h&1) && (w&1) ) g4 = ( h - 1 ) * ( w - 1 ) / 4;
    else if ( (h&1)     ) g4 = ( h - 1 ) * w / 4;
    else if ( (w&1)     ) g4 = ( w - 1 ) * h / 4;
    else                  g4 = h * w / 4;

    int cnt = 0;
    rep(i, 26) {
        if ( cnt == g1 ) break;
        if ( a[i] % 4 == 1 || a[i] % 4 == 3 ) {
            --a[i];
            ++cnt;
        }
    }

    cnt = 0;

    rep(i, 26) {
        if ( cnt == g2 ) break;
        while(1) {
            if ( a[i] % 4 != 2 ) break;
            a[i] -= 2;
            ++cnt;
        }
    }
    int cntg2 = cnt;

    cnt = 0;
    rep(i, 26) {
        if ( a[i] == 0 ) continue;
        while(1) {
            if ( a[i] % 4 != 0 || a[i] == 0 ) break;
            if ( cnt == g4 && cntg2 == g2 ) {
                break;
            }
            if ( cnt == g4 && cntg2 < g2 ) {
                cntg2 += 2;
            } 
            else {
                ++cnt;
            }
            a[i] -= 4;
        }
    }

    rep(i, 26) {
//        cout << a[i] << endl;
        if ( a[i] != 0 ) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
import heapq

N, M = map(int, input().split())

arbList = defaultdict(lambda: [])

for _ in range(N):
    a, b = map(int, input().split())
    arbList[a].append(-b)

arb = []
ans = 0

for day in range(M + 1):
    for b in arbList[day]:
        heapq.heappush(arb, b)
    if arb:
        ans += heapq.heappop(arb)

print(-ans)

Measured memory_bytes: 27676
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,i;
	cin>>n;
	int t[n+1],x[n+1],y[n+1];
	for(i=1;i<=n;i++) cin>>t[i]>>x[i]>>y[i];
	i=0;
	t[0]=0,x[0]=0,y[0]=0;
	while (i<n){
		i++;
		if(!((t[i]-t[i-1])>=(abs(x[i]-x[i-1])+abs(y[i]-y[i-1]))&&((t[i]-t[i-1])-(abs(x[i]-x[i-1])+abs(y[i]-y[i-1])))%2==0)){
			cout<<"No";return 0;
		}
	}
	cout<<"Yes";
	return 0;
}


Measured memory_bytes: 1408
//1
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include<bitset>

using namespace std;
#define loop(i,n) for(int i = 0; i < (n); ++i)
#define loops(i,f,n) for(int i = (f); i < (n); ++i)
#define INF 9999999
#define lint long long int
#define VEC vector<int>
#define VEC2 vector<vector<int>>

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b;
	cin >> a >> b;
	cout << (a + b) / 2<<endl;
}


Measured memory_bytes: 3116
#include <stdio.h>

int main(){
	int n;
	int room[4][3][10]={0};
	
	scanf(" %d", &n);
	for(int i=0; i<n; ++i){
		int b, f, r, v;
		scanf(" %d %d %d %d", &b, &f, &r, &v);
		room[b-1][f-1][r-1] += v;
	}
	
	for(int i=0; i<4; ++i){
		for(int j=0; j<3; ++j){
			for(int k=0; k<10; ++k){
				printf(" %d", room[i][j][k]);
			}
			printf("\n");
		}
		if(i!=3){
			for(int j=0; j<20; ++j)
				printf("#");
			printf("\n");
		}
	}

	return 0;
}



Measured memory_bytes: 2100
"""Quick Sort."""

def partition(A, p, r):
    """Divide list A into A[p:q] whose elements aren't greater than A[q] and
    A[q+1:r] whose elements are greater than A[q].

    Each element of A is a list [x, y].
    x is a character of S, H, C or D (trump suits).
    y is a natural number.
    
    Default value of p is 0.
    The number as a refernce of the division is A[r].
    
    Return the index q.
    """

    x = A[r][1]
    i = p - 1
    for j in range(p, r):
        if A[j][1] <= x:
            i += 1
            A[i], A[j] = A[j], A[i]
    A[i + 1], A[r] = A[r], A[i + 1]
    return i + 1


def quickSort(A, p, r):
    """Sort list A in ascending order with quick sort algorithm.

    Default value of p is 0 (the start index).
    r is 1 less than the length of A (the last index of A).
    """

    if p < r:
        q = partition(A, p, r)
        quickSort(A, p, q - 1)
        quickSort(A, q + 1, r)


def is_stable(A, B):
    """Check the stability of sorted list A.

    A is a sorted list.
    B is a original list.

    Return True or False.
    """

    cA = list(A)
    for x in B:
        i = cA.index(x)
        if i == 0:
            pass
        elif cA[i - 1][1] == x[1]:
            return False
        del cA[i]
    return True



import sys

r = int(sys.stdin.readline()) - 1

A = [x.split() for x in sys.stdin.readlines()]

for i, x in enumerate(A):
    A[i][1] = int(x[1])

B = list (A)

quickSort(A, 0, r)

if is_stable(A, B):
    print('Stable')
else:
    print('Not stable')

for x in A:
    print(*x)

Measured memory_bytes: 37888
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
//#define int long long
template<typename T> inline bool chmax(T& a,T b) { if (a <= b) { a = b; return true; } return false; }
template<typename T> inline bool chmin(T& a,T b) { if (a > b) { a = b; return true; } return false; }
long long Pow(long long x, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 1) return (x * Pow(x, n - 1));
    long long t = Pow(x, n / 2);
    return (t * t);
}
int N;
string S;

bool rollinghash(int M) {
    using ull = unsigned long long;
    const ull B = 1e8+7;
    vector<ull> rh;
    ull ah = 0, t = Pow(B, M);
    for (int i = 0; i < M; i++) ah = ah * B + S[i];
    for (int i = 0; i + M <= N; i++) {
        rh.emplace_back(ah);
        if (i + M < N) ah = ah * B + S[i+M] - S[i] * t;
    }
    
    for (int i = 0; i + M < (int)rh.size(); i++) {
        for (int j = i + M; j < (int)rh.size(); j++) {
            if (rh[i] == rh[j]) { return true; }
        }
    }
    return false;
}


int main() {
    cin >> N >> S;
    
    int ok = 0, ng = N;
    while (abs(ok-ng) > 1) {
        int mid = (ok + ng) / 2;
        if (rollinghash(mid)) ok = mid;
        else ng = mid;
    }
    
    cout << ok << endl;
    return 0;
}

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

using namespace std;

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

	vector<pair<int,int>> arr(m);
	for (int i = 0; i < m; i++)
	{
		cin >> arr[i].first;
		cin >> arr[i].second;
	}

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

	int x = arr[0].first;
	int y = arr[0].second;

	for (int i = 1; i < m; i++)
	{	
		if (arr[i].first > y)
		{
			cout << 0 << endl;
			return 0;
		}

		x = max(x, arr[i].first);
		y = min(y, arr[i].second);

	}

	cout << y - x + 1 << endl;

}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mk make_pair
using namespace std;
ll t,n,m,k;
ll i,j;
ll a[500005], b[500005];
vector<ll>v;
int32_t main(){
    cin>>n;
    ll ans=0;
    for(i=1;i<=n;i++){
        cin>>a[i];
        if(i%2==1&&a[i]%2==1) ans++;
    }
    cout<<ans;
    return 0;
}


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

#define MAXN (100010)

int n;
int a[MAXN], id[MAXN];
int ans[MAXN]; 
//0 means not visited yet
//1 means win
//-1 means lose
std::vector<int> vec[MAXN];

bool cmp(const int &i, const int &j){
	return a[i] < a[j];
}

int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; ++ i){
		scanf("%d", a + i);
		id[i] = i;
	}
	for(int i = 1; i < n; ++ i){
		int u, v;
		scanf("%d%d", &u, &v);
		vec[u].push_back(v);
		vec[v].push_back(u);
	}
	std::sort(id + 1, n + id + 1, cmp);
	for(int i = 1; i <= n; ++ i){
		int u = id[i];
		if(ans[u]) continue;
		ans[u] = -1;
		for(auto v : vec[u]){
			if(!ans[v] && a[v] > a[u]){
			//if(!ans[v] && a[v] != a[u]){
				ans[v] = 1;
			}
		}
	}
	for(int i = 1; i <= n; ++ i){
		if(ans[i] == 1){
			printf("%d ", i);
		}
	}
	printf("\n");
	return 0;
}

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

using namespace std;

int getside(char c){
	int n = c - '0';
	if(n == 8 || n ==2){
		return 0;
	}
	else if(n % 3 == 0){
		return 1;
	}
	else{
		return -1;
	}
}

int count(string &str, bool preside = true){
	int ans = 0;
	int lastside = getside(str[0]);
	bool rside = preside;
	for(int i = 1; i < str.size(); ++i){
		int nowside = getside(str[i]);
		if(rside && nowside > lastside){
			ans++;
		}
		else if(!rside && nowside < lastside){
			ans++;
		}
		else{
			rside = !rside;
		}
		lastside = nowside;
	}
	//cout << " " << ans << endl;
	return ans;
}


int main(){
	while(true){
		string str; cin >> str;
		if(str == "#")break;
		int ans = min(count(str,true), count(str,false));
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3232
n = input()
s = input()
x = 0
y = 0

for i in range(0, len(s)):
    if s[i:i+1] == 'I':
        x += 1
        if x>y:
            y = x
    if s[i:i+1] == 'D':
        x -= 1

print(y)

Measured memory_bytes: 2940
n=int(input())
a=list(map(int,input().split()))
A=[]
for i in range(n):
  A.append(a[i]-i-1)
A.sort()
b=0
c=0
ans=0
Ans=0
if n%2!=0:
  b=n//2
  for i in range(n):
    ans+=abs(A[i]-A[b])
  print(ans)
else:
  b=n//2
  c=(n//2)-1
  for i in range(n):
    ans+=abs(A[i]-A[b])
    Ans+=abs(A[i]-A[c])
  print(min(ans,Ans))
  


Measured memory_bytes: 25748
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <math.h>
#include <climits>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <map> 
#include <set>
#include <string>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
const ll MD = 1000000007;

/* sample input

abcdefghijklmnopqrstuvwzyx
abcdefghijklmnopqrstuvwzxy
*/

int main()
{
	int num[26] = {};
	int num2[26] = {};
	string str;
	cin >> str;

	for (int i = 0; i < str.length(); i++){
		for (int j = 0; j < 26; j++) {
			if (str[i] == 'a' + j) {
				num[j]++;
			}
		}
	}

	if (str.length() <26 ) {

		for (int j = 0; j < 26; j++) {
			if (num[j] == 0) {
				cout << str << char('a' + j )<< endl;
				return 0;
			}
		}
	}
	//else if (str._Equal("zyxwvutsrqponmlkjihgfedcba")) {
	else if (str=="zyxwvutsrqponmlkjihgfedcba") {
		cout << -1 << endl;
		return 0;
	}
	else if (str.length() == 26) {
		for (int j = 0; j < 26; j++) {
			if (str[j] == 'z') {
				bool flag = false;//zの後ろに昇順部分があるかのフラグ
				int pos = -1;
				for (int k = j + 1; k < 25; k++) {
					if (str[k + 1] > str[k]) {
						flag = true;
						pos = k;
					}
				}
				if (flag) {
					for (int k = pos; k < 26; k++) {
						for (int ii = 0; ii < 26; ii++) {
							if (str[k] == 'a' + ii) {
								num2[ii]++;
							}
						}
					}
					for (int k = 0; k < 26; k++) {
						if (num2[k] == 1 && 'a'+ k > str[pos]) {
							str[pos] = char('a' + k);
							break;
						}
					}
					for (int k = 0; k <= pos; k++) {
						cout << str[k];
					}
					cout << endl;
					return 0;
				}
				else {
					//zの後ろに使われている文字
					for (int k = j; k < 26; k++) {
						for (int ii = 0; ii < 26; ii++) {
							if (str[k] == 'a' + ii) {
								num2[ii]++;
							}
						}
					}
					num2[25]++;
					for (int k = 0; k < 26; k++) {
						if (num2[k] > 0 && 'a' + k > str[j - 1]) {
							str[j - 1] = char('a' + k);
							break;
						}
					}
					for (int k = 0; k < j; k++) {
						cout << str[k];
					}
					cout << endl;
					return 0;
				}
			}

		}
	}

	return 0;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ASC(x) sort(ALL((x)))
#define DESC(x) sort(ALL((x)),greater<ll>())
#define REV(x) reverse(ALL((x)))
#define pb push_back

int main()
{
    ll N, T;
    cin >> N >> T;
    vector<pair<ll,ll>> P(N);
    REP(i,0,N) cin >> P[i].first >> P[i].second;

    ASC(P);
    mat dp(N+1, vec(T, 0));
    ll ans = 0;
    REP(i,0,N) {
        ll t = P[i].first, v = P[i].second;
        REP(j,0,T) {
            dp[i+1][j] = MAX(dp[i+1][j],dp[i][j]);
            if(j - t >= 0) dp[i+1][j] = MAX(dp[i+1][j],dp[i][j-t]+v);
        }
        ans = MAX(ans,dp[i][T-1]+v);
    }

    PR(ans);

    return 0;
}

/*



*/

Measured memory_bytes: 73756
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<queue>
#include<stack>
#include<list>

#define endl "\n"
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;

int main(){
    string sd,t;
    cin>>sd>>t;
    string ans = "UNRESTORABLE";

    if(sd.length() < t.length()){
        cout<<ans<<endl;
        return 0;
    }

    for(int i = 0;i <= sd.length() - t.length();i++){
        string s;
        for(int j=0;j<i;j++){
            if(sd[j] == '?') s += 'a';
            else s += sd[j];
        }

        bool tok = true;
        for(int j=i;j<i + t.length();j++){
            if(sd[j] == '?') continue;
            else if(sd[j] != t[j-i]){
                tok = false;
                break;
            }
        }
        if(!tok) continue;

        s += t;

        for(int j=i + t.length();j<sd.length();j++){
            if(sd[j] == '?') s += 'a';
            else s += sd[j];
        }

        ans = s;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
char S[2100];
char T[2100];
int dp[2100][2100][2][2][2];
int main(){
	int a,b;scanf("%d%d",&a,&b);scanf("%s%s",S,T);
	for(int i=0;i<2100;i++)for(int j=0;j<2100;j++)for(int k=0;k<2;k++)
		for(int l=0;l<2;l++)for(int m=0;m<2;m++)dp[i][j][k][l][m]=-999999999;
	dp[0][0][0][0][0]=0;
	for(int i=0;i<=a;i++){
		for(int j=0;j<=b;j++)for(int k=0;k<2;k++)for(int l=0;l<2;l++)for(int m=0;m<2;m++){
			if(dp[i][j][k][l][m]<0)continue;
			int val=dp[i][j][k][l][m];
			if(k==0&&i<a)dp[i+1][j][k][l][m]=max(dp[i+1][j][k][l][m],val);
			if(l==0&&j<b)dp[i][j+1][k][l][m]=max(dp[i][j+1][k][l][m],val);
			if(m==0&&i<a&&S[i]=='I')dp[i+1][j][1][l][!m]=max(dp[i+1][j][1][l][!m],val+1);
			if(m==0&&j<b&&T[j]=='I')dp[i][j+1][k][1][!m]=max(dp[i][j+1][k][1][!m],val+1);
			if(m==1&&i<a&&S[i]=='O')dp[i+1][j][1][l][!m]=max(dp[i+1][j][1][l][!m],val+1);
			if(m==1&&j<b&&T[j]=='O')dp[i][j+1][k][1][!m]=max(dp[i][j+1][k][1][!m],val+1);
		}
	}
	int ret=0;
	for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)for(int k=0;k<2;k++)
		for(int l=0;l<2;l++){
			ret=max(ret,dp[i][j][k][l][1]);
		}
	printf("%d\n",ret);
}

Measured memory_bytes: 138844
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=1;i<=n;i++)
using namespace std;
int main(){
    ll n,k; cin >> n >> k;
    ll a[n];
    ll p;
    rep(i,n) cin >> a[i];
    ll ans = (n-1)/(k-1);
    if((n-1)%(k-1)!=0) ans++;
    if(ans==0) ans++;
    //k*x-(x-1) >= n; (k-1)x>=n-1
    cout << ans << endl;
}



Measured memory_bytes: 1024
import java.util.*;

class Main {
	Scanner sc = new Scanner(System.in);

	HashMap<Character,String> map=new HashMap<Character, String>();

	public void run() {
		map.put(' ',"101");
		map.put('\'',"000000");
		map.put(',',"000011");
		map.put('-',"10010001");
		map.put('.',"010001");
		map.put('?',"000001");
		map.put('?',"000001");
		map.put('A',"100101");
		map.put('B',"10011010");
		map.put('C',"0101");
		map.put('D',"0001");
		map.put('E',"110");
		map.put('F',"01001");
		map.put('G',"10011011");
		map.put('H',"010000");
		map.put('I',"0111");
		map.put('J',"10011000");
		map.put('K',"0110");
		map.put('L',"00100");
		map.put('M',"10011001");
		map.put('N',"10011110");
		map.put('O',"00101");
		map.put('P',"111");
		map.put('Q',"10011111");
		map.put('R',"1000");
		map.put('S',"00110");
		map.put('T',"00111");
		map.put('U',"10011100");
		map.put('V',"10011101");
		map.put('W',"000010");
		map.put('X',"10010010");
		map.put('Y',"10010011");
		map.put('Z',"10010000");

		while(sc.hasNextLine()){
			String str=sc.nextLine();
			String str1="";
			String res="";
			for(char c:str.toCharArray()){
				str1+=map.get(c);
			}
			while(str1.length()%5!=0)str1+='0';

			for(int s=0,e=5;e<=str1.length();s+=5,e+=5){
				int val=Integer.parseInt(str1.substring(s,e),2);
				if(0<=val && val<26){
					res+=(char)('A'+val);
				}else{
					switch(val){
					case 26:res+=" ";break;
					case 27:res+=".";break;
					case 28:res+=",";break;
					case 29:res+="-";break;
					case 30:res+="'";break;
					case 31:res+="?";break;
					}
				}
			}
			ln(res);
		}
	}

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

	public static void pr(Object o) {
		System.out.print(o);
	}

	public static void ln(Object o) {
		System.out.println(o);
	}

	public static void ln() {
		System.out.println();
	}
}

Measured memory_bytes: 12000
#include<cstdio>
#include<cmath>
using namespace std;
int n;
int main()
{
	scanf("%d",&n);
	int t=0,x=0,y=0;
	bool f=0;
	for(int i=1;i<=n;i++)
	{
		int t1,x1,y1;
		scanf("%d %d %d",&t1,&x1,&y1);
		int dis=abs(x1-x)+abs(y1-y);
		if(dis>t1-t) f=1;
		if((t1-t)%2==1) 
		{
			if(dis%2==0)f=1;
		}
		if((t1-t)%2==0) 
		{
			if(dis%2==1)f=1;
		}
	}
	if(f==0)
		printf("Yes\n");
	else printf("No\n");
}

Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
#define ll long long
#define rep(i,l,r) for(ll i=(l);i<(r);i++)
#define min(p,q)((p)<(q)?(p):(q))

typedef struct edge{ll s,g,c;}E;

ll n,k,ans;
E e[4010];
ll vnow[2010];
ll epre[4010];

ll que[4010];
ll d[2010][2010];
void bfs(int k){
	ll qcnt=1;
	que[0]=k;
	d[k][k]=1;
	rep(i,0,qcnt){
		ll v=que[i];
		for(ll t=vnow[v];t!=-1;t=epre[t])if(!d[k][e[t].g]){
			que[qcnt++]=e[t].g;
			d[k][e[t].g]=d[k][v]+1;
		}
	}
}

int main(){
	scanf("%lld%lld",&n,&k);
	rep(i,0,n)vnow[i]=-1;
	
	rep(i,0,n-1){
		ll a,b;
		scanf("%lld%lld",&a,&b);
		a--;b--;
		e[2*i].s=a;
		e[2*i].g=b;
		epre[2*i]=vnow[a];
		vnow[a]=2*i;
		
		e[2*i+1].s=b;
		e[2*i+1].g=a;
		epre[2*i+1]=vnow[b];
		vnow[b]=2*i+1;
	}

	rep(i,0,n)bfs(i);
	ans=n;
	
	if(k%2==0){
		//kが偶数のとき
		//頂点iを中心にして、距離がk/2より大きな頂点の個数の最小値を求める
		rep(i,0,n){
			ll temp=0;
			rep(j,0,n)if(d[i][j]-1>k/2)temp++;
			ans=min(ans,temp);
		}
	}else{
		//kが奇数のとき
		//辺iを中心にして、距離がk/2.0より大きな頂点の個数の最小値を求める
		//⇔辺の端点どちらかからの距離もk/2より大きな以下同
		rep(i,0,n-1){
			ll temp=0;
			rep(j,0,n)if(min(d[e[2*i].s][j],d[e[2*i].g][j])-1>k/2)temp++;
			ans=min(ans,temp);
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 31744
N = gets.chomp.to_i
a = Array.new(10**5)

gets.chomp.split(" ").map(&:to_i).each.with_index do |v, idx|
  a[v - 1] = idx + 1
end

out = ""
a.each do |v|
  out << v.to_s
  out << " "
end
puts out.chomp

Measured memory_bytes: 13188
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>

using namespace std;

int main()
{
    int k;cin>>k;
    map<pair<int,int>,int> m;
    for(int i=1;i<=k;++i)
    for(int j=1;j<=k;++j)
        m[{i,j}]=__gcd(i,j);
        
    int sum=0;
    for(int i=1;i<=k;++i)
    for(int j=1;j<=k;++j)
    for(int l=1;l<=k;++l)
        sum+=m[{m[{i,j}],l}];
    
    cout<<sum<<endl;
    
    return 0;
}



Measured memory_bytes: 6056
N, M = map(int, input().split())
xyz = [list(map(int, input().split())) for _ in range(N)]
ans = 0
for i in (-1, 1):
  for j in (-1, 1):
    for k in (-1, 1):
      maxp = []
      for p in xyz:
        maxp.append(i * p[0] + j * p[1] + k * p[2])
      maxp.sort(reverse=True)
      aa = sum(maxp[:M])
      if ans <= aa:
        ans = aa
print(ans)


Measured memory_bytes: 3316
package main

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

var sc = bufio.NewScanner(os.Stdin)
func text() string {
  sc.Scan()  
  return sc.Text()
}

func main(){
	
  var num = text()
  var text = text()
  a,_ := strconv.Atoi(num)
  
  if a >= 3200{
    fmt.Println(text)
  }else if a < 3200{
    fmt.Println("red")
  }
}

Measured memory_bytes: 640
N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
from collections import deque
AA = deque(A)
change = []
for _ in range(M):
    b,c = map(int,input().split())
    change.append((c,b))
change.sort(reverse=True)
import sys
flag = True
for c,b in change:
    for i in range(b):
        a = AA.popleft()
        if a<c:
            AA.append(c)
        else:
            flag = False
            AA.append(a)
            print(sum(AA))
            sys.exit()
if flag:
    print(sum(AA))

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

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  int N;
  cin >> N;
  int v[N], c[N];
  for (int i = 0; i < N; i++) cin >> v[i];
  for (int i = 0; i < N; i++) cin >> c[i];

  int ans = 0;
  for (int i = 0; i < N; i++) if (v[i] > c[i]) {
    ans += v[i] - c[i];
  }

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


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <set>
#include <string>
#include <vector>
#include <iomanip>
#include <map>

using namespace std;

#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

typedef long long ll;
typedef long double ld;

const ll SIZE = 1e5 + 10, S2 = 1e7 * 2, MOD = 1e9 + 7;

ll cnt[52][27];
ll pr[SIZE][2], pr2[SIZE][2];


int main() {
    fastInp;

    string s, t;
    cin >> s >> t;
    for (int i = 0; i < s.size(); i++) {
        ll q = 1, q2 = 2;
        if (s[i] != 'A') {
            q = 2;
            q2 = 1;
        }
        pr[i + 1][0] = pr[i][0] + q;
        pr2[i + 1][0] = pr2[i][0] + q2;
    }

    for (int i = 0; i < t.size(); i++) {
        ll q = 1, q2 = 2;
        if (t[i] != 'A') {
            q = 2;
            q2 = 1;
        }
        pr[i + 1][1] = pr[i][1] + q;
        pr2[i + 1][1] = pr2[i][1] + q2;
    }
    ll q;
    cin >> q;
    while (q--) {
        ll l1, r1, l2, r2;
        cin >> l1 >> r1 >> l2 >> r2;

        bool fl = (pr2[r1][0] - pr2[l1 - 1][0]) % 3 == (pr2[r2][1] - pr2[l2 - 1][1]) % 3;
        if (((pr[r1][0] - pr[l1 - 1][0]) % 3 == (pr[r2][1] - pr[l2 - 1][1]) % 3) || fl) {
            cout << "YES\n";
        }
        else {
            cout << "NO\n";
        }
    }
    return 0;
}



Measured memory_bytes: 4048
#include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <numeric>
#include <vector>
#define _for(i, n) for (int i = 0; i < n; i++)

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

template <typename T>
vector<size_t> sort_indexes(const vector<T> &v) {
  vector<size_t> idx(v.size());
  iota(idx.begin(), idx.end(), 0);
  sort(idx.begin(), idx.end(), [&v](size_t i1, size_t i2) { return v[i1] < v[i2]; });
  return idx;
}

// ll gcd(ll a,ll b) {
//   ll gmax = 1;
//   ll aa = (a<b)?a:b;
//   ll bb = (a<b)?b:a;
//   for(ll i = 1;i*i<=aa;i++) {
//     if (aa%i==0) {
//       if (bb%(aa/i) == 0) {
//         gmax = aa/i;
//         break;
//       }
//       if (bb%i == 0) {
//         gmax = i;
//       }
//     }
//   }
//   return gmax;
// }

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

int main() {
  ll n;
  cin >> n;
  ll a[n];
  _for(i, n) cin >> a[i];
  ll gcd_max = 1;
  ll gcd_arr[n];
  ll gcd_arr2[n];
  ll cgcd;
  gcd_arr[0] = a[0];
  gcd_arr2[n - 1] = a[n - 1];
  for (ll i = 1; i < n; i++) gcd_arr[i] = gcd(a[i], gcd_arr[i - 1]);
  for (ll i = 1; i < n; i++) gcd_arr2[n - i - 1] = gcd(a[n - i - 1], gcd_arr2[n - i]);
  _for(i, n) {
    if (i == 0)
      cgcd = gcd_arr2[1];
    else if (i == n - 1)
      cgcd = gcd_arr[n - 2];
    else
      cgcd = gcd(gcd_arr[i - 1], gcd_arr2[i + 1]);
    gcd_max = max(gcd_max, cgcd);
  }
  cout << gcd_max << endl;
  return 0;
}

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

int main(){
  int n;cin>>n;
  vector<int>h(n);
  for(int i=0;i<n;i++){
    cin>>h.at(i);
  }
  vector<int>dp(n);
  dp.at(0)=0;
  dp.at(1)=abs(h.at(1)-h.at(0));
  for(int i=2;i<n;i++){
    dp.at(i)=min(dp.at(i-1)+abs(h.at(i)-h.at(i-1)),dp.at(i-2)+abs(h.at(i)-h.at(i-2)));
  }
  cout <<dp.at(n-1)<<endl;
}

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

int LCS(char [], char []);

int main(){
  int q, i;
  char x[1000], y[1000];

  scanf("%d", &q);

  for(i = 0; i < q; i++){
    scanf("%s%s", x, y);
    printf("%d\n", LCS(x, y));
  }
  return 0;
}

int LCS(char x[], char y[]){
  int m, n, i, j, c[1001][1001];

  m = strlen(x);
  n = strlen(y);

  for(i = 0; i <= m; i++) c[i][0] = 0;
  for(j = 0; j <= n; j++) c[0][j] = 0;

  for(i = 1; i <= m; i++){
    for(j = 1; j <= n; j++){
      if(x[i-1] == y[j-1]) c[i][j] = c[i-1][j-1] + 1;
      else if(c[i-1][j] >= c[i][j-1]) c[i][j] = c[i-1][j];
      else c[i][j] = c[i][j-1];
    }
  }
  return c[m][n];
}

Measured memory_bytes: 4524
#include <cstdio>
#include <list>
#include <vector>

typedef long long i64;

i64 n;

std::list<int> a;
std::vector<int> b;

int main() {
  scanf("%lld", &n);
  ++n;
  int tot = 1;
  a.push_back(1);
  b.push_back(1);
  for (int i = 62 - __builtin_clzll(n); i >= 0; --i) {
    if (n >> i & 1) {
      ++tot;
      a.push_front(tot);
      b.push_back(tot);
    }
    if (i) {
      ++tot;
      a.push_back(tot);
      b.push_back(tot);
    }
  }
  std::vector<int> ans(a.begin(), a.end());
  for (int i = 0; i < b.size(); ++i) ans.push_back(b[i]);
  printf("%d\n", ans.size());
  for (int i = 0; i < ans.size(); ++i) printf("%d ", ans[i]);
  return 0;
}


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

deque<char> d;

int main(){
    string s,ans="";
    cin>>s;
    for(int i=0;i<s.size();i++){
        d.push_back(s[i]);
    }
    bool flag=false;
    int q;
    cin>>q;
    while(q--){
        int t;
        cin>>t;
        if(t==1)
            flag=flag^true;
        else{
            int f;
            char c;
            cin>>f>>c;
            if(flag^(f==1))
                d.push_front(c);
            else
                d.push_back(c);
        }
    }
    
    while(!d.empty()){
        ans.push_back(d.front());
        d.pop_front();
    }
    
    if(flag){
        reverse(ans.begin(),ans.end());
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 1412
#define _USE_MATH_DEFINES

#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;

int main(){
	
	int N, Y;
	cin >> N >> Y;
	
	for(int i = 0; i <= 2000; i++){
		for(int j = 0; j <= 4000; j++){
			int k = N - i - j;
			int rest = Y - i * 10000 - j * 5000;
			if(k < 0){
				break;
			}
			if(k * 1000 == rest){
				cout << i << " " << j << " " << k << endl;
				return 0;
			}
		}
	}
	
	cout << "-1 -1 -1" << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

using namespace std;

int my_abs(int num) {
    if (num > 0)
        return num;
    else
        return -num;
}

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

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

int main() {
    int N, T;
    cin >> N >> T;
    long long ans = 0;
    vector<int> retu(N);

    for (int i = 0; i < N; i++) {
        cin >> retu.at(i);
    }
    for (int j = 0; j < N - 1; j++) {
        if (retu.at(j + 1) - retu.at(j) >= T) {
            ans += T;
        }
        else {
            ans += retu.at(j + 1) - retu.at(j);
        }
    }
    ans += T;

    cout << ans << endl;
}


Measured memory_bytes: 1024
import math
S = int(input())
X1 = 0
Y1 = 0
X2 = 10**9
Y2 = 1
X3 = (X2 - S % X2) % X2
Y3 = math.ceil(S/X2)
print(X1, Y1, X2, Y2, X3, Y3)


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


int main(){
	string s;
	int i, j;
	bool f = 0;
	cin >> s;
	if (s[0] == s[1] && s[1] == s[2] && s[2] == s[3]) f = 0;
	else if ((s[0] == s[1] && s[2] == s[3]) || (s[0] == s[2] && s[1] == s[3]) || (s[0] == s[3] && s[1] == s[2])) f = 1;
	else f = 0;

	cout << (f ? "Yes" : "No") << endl;
	return 0;
}



Measured memory_bytes: 256
def build_line(width, i):
    s = ''
    while len(s) < width:
                s += '#'
    return s

while True:
    h,w = [int(i) for i in input().split()]
    if not (h and w):
        break
    for i in range(h):
        print(build_line(w, i))
    print()



Measured memory_bytes: 5616
#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];
  }
  int s = a[0];
  for (int i = 1; i < n; i++) {
    s ^= a[i];
  }
  for (int i = 0; i < n; i++) {
    cout << (s ^ a[i]) << " ";
  }
  cout << endl;

  return 0;
}

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

using namespace std;

int dp[100005];
int h[100005];
int n;

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

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

    return 0;
}

Measured memory_bytes: 1024
///WRONG LIFE
///DIE(RETRY)
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")

#include "bits/stdc++.h"
using namespace std;

#define pb push_back
#define F first
#define S second
#define f(i,a,b)  for(int i = a; i < b; i++)
#define endl '\n'

using ll = long long;
using db = long double;
using row = vector<int>;
using ii = pair<int, int>;

const int N = 2e5 + 5, M = 26, A = 6561, LG = 19, MOD = 1e9+7;
const int BLOCK = 500;
const long double EPS = 1e-7;
using pii = pair<int,int>;
int dp[3005][3005];
int n, q, x, y;
int a[3005];
const int INV2 = 500000004;
int main(){
#ifdef ONLINE_JUDGE
  ios_base::sync_with_stdio(0);
  cin.tie(0);
#endif // ONLINE_JUDGE

  cin >> n >> q;

  f(i,1,n+1)  cin>>a[i];

  f(i,1,n+1)
    f(j,1,n+1)dp[i][j]=  (a[i] < a[j]);
  ll mul = 1;
  f(i,1,q+1){
    if((mul+=mul)>=MOD)mul-=MOD;
    cin >> x >> y;
    dp[x][y] = dp[y][x] = (dp[x][y] + dp[y][x]) * 1ll * INV2 % MOD;
    f(j,1,n+1){
      if(j == x || j == y)continue;
      dp[j][x] = dp[j][y] =  (dp[j][x] + dp[j][y]) * 1ll * INV2 % MOD;
      dp[x][j] = dp[y][j] =  (dp[x][j] + dp[y][j]) * 1ll * INV2 % MOD;
    }
  }

  ll ans = 0;
  f(i,1,n+1)
    f(j,1,i)ans += dp[i][j];

  cout << ans%MOD * mul % MOD << '\n';


    return 0;
}


Measured memory_bytes: 35456
n = int(input())
taro = 0
hanako = 0

for i in range(n):
    columns = input().rstrip().split()
    tcard = columns[0]
    hcard = columns[1]
    if tcard > hcard:
        taro += 3
    elif hcard > tcard:
        hanako += 3
    else: 
        taro += 1
        hanako += 1
    
print(taro,hanako)


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
int a[3][3],n;
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

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

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










int main() {
    string s;
    cin >> s;
 
    bool ret = true;
    if (s[0] != 'A') ret = false;
 
    int count = 0;
    for (int i = 2; i < s.size() - 1; i++) {
        if (s[i] == 'C')count++;
    }
    if (count != 1)ret = false;
 
    count = 0;
    for (int i = 0; i < s.size(); i++) {
        if (islower(s[i]))count++;
    }
    if (count != s.size() - 2)ret = false;
 
    cout << (ret ? "AC" : "WA") << endl;
    return 0;
}

Measured memory_bytes: 256