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

typedef long long ll;

const int MAXN = 2000;
char grid[2][MAXN];

const ll mod = 1e9 + 7;
ll dp[MAXN];

int main(){
	int N;
	cin >> N;
	cin >> (grid[0] + 1);
	cin >> (grid[1] + 1);
	
	dp[0] = 1; 
	for(int a = 1; a <= N; a++){
		if(grid[0][a] == grid[1][a]){
			//can be endpoint./
			if(a == 1){
				dp[a] = 3;
			} else if(grid[0][a-1] == grid[1][a-1]){
				dp[a] = dp[a-1] * 2 % mod;
			} else {
				dp[a] = dp[a-1];
			}
			//printf("Match A at %i\n", a);
		} else if(grid[0][a-1] == grid[0][a] && grid[1][a-1] == grid[1][a-1]){
			if(a == 2){
				dp[a] = dp[a - 2] * 6 % mod;
			} else if(grid[0][a-2] == grid[1][a-2]){
				dp[a] = dp[a - 2] * 2 % mod;
			} else {
				dp[a] = dp[a - 2] * 3 % mod;
			}
			//printf("Match B at %i\n", a);
		} else {
			//printf("No match at %i\n", a);
		}
		//cout << "dp[" << a << "] = " << dp[a] << endl;
	}
	cout << dp[N];
}

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

int main(){
  int N, K;
  cin >> N >> K;
  vector<long long> H(N);
  for (int i=0;i<N;i++){
    cin >> H[i];
  }
  vector<long long> C(N, 1e17);
  C[0] = 0;
  priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> pq;
  for (int i=0;i<N;i++){
    pq.push(make_pair(C[i], i));
  }
  pair<long long, int> b;
  int r;
  while (!pq.empty()){
    b = pq.top();
    pq.pop();
    r = b.second;
    for (int i=1;i<=K;i++){
      if (r + i <= N - 1){
        if (C[r+i] > abs(H[r] - H[r+i]) + C[r]){
          C[r+i] = abs(H[r] - H[r+i]) + C[r];
          pq.push(make_pair(C[r+i], r+i));
        }
      }
    }
  }
  cout << C[N-1] << endl;
}

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

int main() {
	int n,m,c;
	cin >> n >> m >> c;
	vector<int>B(m);
	rep(i, m) {
		cin >> B[i];
	}
	vector<vector<int>>A(n, vector<int>(m));
	for (int i = 0;i < n;++i) {
		for (int j = 0;j < m;++j) {
			cin >> A[i][j];
		}
	}
	
	int ans = 0;
	for (int i = 0;i < n;++i) {
		int sum = 0;
		for (int j = 0;j < m;++j) {
			sum += A[i][j] * B[j];
		}
		if (sum + c > 0)++ans;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rp(i,n) for(int i=1;i<=(int)n;i++)
int main(){
    int n,m,a;
    cin>>n>>m;
    int sum=0;
    for(int i=0;i<m;i++){
        cin>>a;
        sum+=a;
    }
if(n-sum>=0)cout<<n-sum<<endl;
else cout<<-1<<endl;

}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
using ll = long long;

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    ll N, C; cin >> N >> C;
    vector<ll> x(N), v(N);
    REP(i,N) cin >> x[i] >> v[i];

    vector<ll> csushi(N), ccsushi(N), csushi_max(N+1), ccsushi_max(N+1);
    csushi[0] = v[0]; ccsushi[0] = v[N-1];
    for(int i=0; i < N-1; ++i)  csushi[i+1]  = csushi[i] + v[i + 1];
    for(int i=0; i < N-1; ++i)  ccsushi[i+1] = ccsushi[i] + v[N-2 - i];
    for(int i=0; i < N; ++i) csushi_max[i+1]  = max(csushi_max[i], csushi[i] - x[i]);
    for(int i=0; i < N; ++i) ccsushi_max[i+1] = max(ccsushi_max[i], ccsushi[i] - (C - x[N-1 - i]));

    ll ans = 0;
    REP(i,N) {
        ans = max(ans, csushi[i] - x[i]);
        // return from i
        ans = max(ans, csushi[i] - x[i] * 2 + ccsushi_max[N-1 - i]);
    }

    REP(i,N) {
        ans = max(ans, ccsushi[i] - (C - x[N-1 - i]));
        ans = max(ans, ccsushi[i] - (C - x[N-1 - i]) * 2 + csushi_max[N-1 - i]);
    }

    cout << ans << '\n';
        
    return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
 
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long

int main() {
    fastio;

	int n;
	cin >> n;
	map<int, int> m;

	for(int i = 0; i < n; ++i) {
		string s;
		cin >> s;
		if(s == "AC") m[0]++;
		else if(s == "WA") m[1]++;
		else if(s == "TLE") m[2]++;
		else if(s == "RE") m[3]++; 
	}
	
	cout << "AC x " << m[0] << "\n";
	cout << "WA x " << m[1] << "\n";
	cout << "TLE x " << m[2] << "\n";
	cout << "RE x " << m[3] << "\n";
	
	return 0;
}


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

int main() {
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  int L=A+B;int R=C+D;
  if(L>R){
      cout<<"Left"<<endl;
  }else if(L==R){
      cout<<"Balanced"<<endl;
  }else{
      cout<<"Right"<<endl;
  }
}

Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "functional"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


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

	string s;
	cin >> s;
	int ans = 0;
	for (int i = 0; i < 3; i++) {
		for (int j = i + 1; j < i + 4; j++) {
			if (j >= s.size())break;
			for (int k = j + 1; k < j + 4; k++) {
				if (k >= s.size())break;
				for (int l = k + 1; l < k + 4; l++) {
					if (l + 1 != s.size()) {
						if (s[k + 1] == '0')break;
						continue;
					}
					if (l >= s.size())break;
					int a = 0, b = 0, c = 0, d = 0;
					for (int m = 0; m <= i; m++) {
						a *= 10;
						a += s[m] - '0';
					}
					for (int m = i + 1; m <= j; m++) {
						b *= 10;
						b += s[m] - '0';
					}
					for (int m = j + 1; m <= k; m++) {
						c *= 10;
						c += s[m] - '0';
					}
					for (int m = k + 1; m <= l; m++) {
						d *= 10;
						d += s[m] - '0';
					}
					//cout << i << " " << j << " " << k << " " << l << endl;
					//cout << a << " " << b << " " << c << " " << d << endl;
					if (a <= 255 && b <= 255 && c <= 255 && d <= 255)ans++;
					if (s[k + 1] == '0')break;
				}
				if (s[j + 1] == '0')break;
			}
			if (s[i + 1] == '0')break;
		}
		if (s[0] == '0')break;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3220
import sys
if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))

    target = 1
    for i in range(n):
        if a[i] == target:
            target += 1
    if target == 1:
        print(-1)
        sys.exit(0)

    print(len(a) - (target - 1))

Measured memory_bytes: 24744
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long s;
	cin>>s;
	
	const int v=1000000000;
	
	int x=(v-s%v)%v;
	int y=(s+x)/v;
	
	cout<<"0 0 1000000000 1 "<<x<<" "<<y<<endl;
}

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

struct state{
  int pos,bit,cost;
  bool operator < ( const state s )const{
    return cost > s.cost;
  }
};

int N,M,A,B,C;
priority_queue< state > Q;
vector<int> G[100005];

int d[100005][(1<<3)];
int f[100005];
int t[100005];

int main(){
  for(int i=0;i<100005;i++)
    for(int j=0;j<(1<<3);j++)
      d[i][j]=1e9;

  scanf("%d %d %d %d",&N,&A,&B,&C);

  memset(f,-1,sizeof(f));
  for(int i=0;i<A;i++){
    int a;
    scanf("%d",&a);
    a--;

    G[100001].push_back(a);
    G[a].push_back(100001);
    
    f[a]=0;
    Q.push( (state){ a, 1 , 0 } );
    d[a][1]=0;
  }
  for(int i=0;i<B;i++){
    int b;
    scanf("%d",&b);
    b--;

    G[100002].push_back(b);
    G[b].push_back(100002);
    
    f[b]=1;
    Q.push( (state){ b,2,0 } );
    d[b][2]=0;
  }
  for(int i=0;i<C;i++){
    int c;
    scanf("%d",&c);
    c--;

    G[100003].push_back(c);
    G[c].push_back(100003);
    
    f[c]=2;
    Q.push( (state){c,4,0} );
    d[c][4]=0;
  }
  
  cin>>M;
  for(int i=0;i<M;i++){
    int x,y;
    scanf("%d %d",&x,&y);
    x--,y--;
    G[x].push_back(y);
    G[y].push_back(x);
    
  }
  while(!Q.empty()){
    state s=Q.top();Q.pop();
    int pos=s.pos;
    int bit=s.bit;
    int cost=s.cost;
    if( d[pos][bit] < cost )continue;
    t[pos]|=bit;
    
    for(int bb=t[pos];bb>0;bb=(bb-1)&t[pos]){
      for(int B=bb;B>0;B=(B-1)&bb){
        int ncost=d[pos][ (B&bb) ] + d[pos][ bb-(B&bb) ];
        if(d[pos][bb]>ncost){
          Q.push( (state){pos,bb,ncost} );
          d[pos][bb]=ncost;
        }
      }
    }

    for(int to:G[pos]){
      int ncost=cost+1;
      
      if( f[to]!=-1 && f[to]==f[pos]){
        ncost=cost;
      }else if(to>100000||pos>100000){
        ncost=cost;
      }
      
      if(d[to][bit]>ncost){
        d[to][bit]=ncost;
        Q.push( (state){to,bit,ncost} );
      }
    }
  }
  int ans=1e9,id;
  for(int i=0;i<N;i++){
    if( ans > d[i][7] ){
      ans=d[i][7];
      id=i;
    }
  }
  cout<<ans<<' '<<id+1<<endl;
  
  return 0;
}

Measured memory_bytes: 15328
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var hashs = new HashSet<string>();
            for(var i=0;i<N;i++)
            {
                var tmp = Console.ReadLine();
                if (!hashs.Contains(tmp)) hashs.Add(tmp);
            }
            Console.WriteLine(hashs.Count());
        }
    }
}

Measured memory_bytes: 43324
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


# 処理内容
def main():
    N = int(input())
    A = [0] * N
    B = [0] * N
    for i in range(N):
        A[i], B[i] = map(int, input().split())
    A.sort()
    B.sort()

    if N % 2 == 0:
        ma = A[N//2 - 1] + A[N//2]
        mb = B[N//2 - 1] + B[N//2]
        print(mb - ma + 1)
    else:
        ma = A[(N+1)//2 - 1]
        mb = B[(N+1)//2 - 1]
        print(mb - ma + 1)


if __name__ == '__main__':
    main()

Measured memory_bytes: 78964
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF (ll)1E9
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

template <class T>ostream &operator<<(std::ostream &o, const vector<T> &v)
{
	rep(i, v.size()) {
		o << (i > 0 ? " " : "") << v[i];
	}
	return o;
}

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

class CompareDist
{
public:
	bool operator()(pair<int, int> n1, pair<int, int> n2) {
		return (n1.fs != n2.fs ? n1.fs < n2.fs : n1.sc < n2.sc);
	}
};

int main() {
	int n, m;
	cin >> n >> m;
	vi box(n, 1), x(m), y(m);
	vector<bool> b(n, false);
	b[0] = true;
	rep(i, m) {
		cin >> x[i] >> y[i];
		x[i]--; y[i]--;
	}
	rep(i, m) {
		box[x[i]]--;
		box[y[i]]++;
		if (b[x[i]])b[y[i]] = true;
		if (box[x[i]] == 0)b[x[i]] = false;
	}
	int ans = 0;
	rep(i, n) {
		if (b[i])ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 1408
import java.util.*;

public class Main {    
    
  public static void main(String[] args) {
   
     Scanner sc = new Scanner(System.in);                                      
     
     int N = sc.nextInt();
     int M = sc.nextInt();
     
     boolean from[] = new boolean[N+1];
     boolean   to[] = new boolean[N+1];          
                    
      for(int i = 1;i <= M;i++){
          int a = sc.nextInt();
          int b = sc.nextInt();          
          if(a == 1)
              to[b] = true;
          
          if(b == N)
              from[a] = true;          
      }    
     
      for(int i = 2;i <= N-1;i++){
          if(from[i] && to[i]){
              System.out.println("POSSIBLE");
              return;
          }          
      }
      
      System.out.println("IMPOSSIBLE");      
                  
  }   
}

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

int main() {
    long long n, ret = 0, d = 1000000000000, flg = true;
    std::cin >> n;
    std::vector<long long> a(n), b(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i] >> b[i];
        ret += a[i];
        if (a[i] > b[i] && d > b[i]) d = b[i];
        flg &= (a[i] == b[i]);
    }

    std::cout << (flg ? 0 : ret - d) << std::endl;

    return 0;
}

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

struct ST {
  double price=0; int source=0; int cnt=0;
  bool operator<(const ST& rhs) const
  {
      return price < rhs.price;
  }
};

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int n,m;cin>>n>>m;
  priority_queue<ST> pq;
  for(int i=0;i<n;i++){
    int t;cin>>t;
    pq.push({(double)t, t, 0});
  }

  for(int i=0;i<m;i++){
    auto v = pq.top();pq.pop();
    v.price /= 2.0;
    v.cnt++;
    pq.push(v);
  }

  ll ans=0;
  while(!pq.empty()){
    auto v = pq.top();pq.pop();
    ans += v.source / pow(2.0, v.cnt);
  }

  cout<<ans<<endl;

  return 0;
}


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

const int kN = 1e5 + 5;

int dg[kN], n, m;

int main() {
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= m; ++i) {
		int a, b; scanf("%d%d", &a, &b);
		++dg[a]; ++dg[b];
	}
	bool flag = true;
	for(int i = 1; i <= n; ++i) {
		if(dg[i] % 2 != 0) flag = false;
	}
	printf(flag ? "YES\n" : "NO\n");
	return 0;
}

Measured memory_bytes: 4136
<?php

namespace egg1to3;

class Dice
{
    protected $top;
    protected $front;
    protected $left;
    protected $right;
    protected $back;
    protected $bottom;

    public function __construct($arr)
    {
        $this->top = $arr['top'];
        $this->front = $arr['front'];
        $this->right = $arr['right'];
        $this->left = $arr['left'];
        $this->back = $arr['back'];
        $this->bottom = $arr['bottom'];
    }

    public function parse($str)
    {
        for ($i = 0, $len = strlen($str); $i < $len; $i++) {
            $direction = $str[$i];
            $this->move($direction);
        }

        echo $this->top, PHP_EOL;
    }

    protected function move($direction)
    {
        $top = $this->top;
        switch ($direction) {
            case 'S':
                $this->top = $this->back;
                $this->back = $this->bottom;
                $this->bottom = $this->front;
                $this->front = $top;
                break;
            case 'N':
                $this->top = $this->front;
                $this->front = $this->bottom;
                $this->bottom = $this->back;
                $this->back = $top;
                break;
            case 'E':
                $this->top = $this->right;
                $this->right = $this->bottom;
                $this->bottom = $this->left;
                $this->left = $top;
                break;
            case 'W':
                $this->top = $this->left;
                $this->left = $this->bottom;
                $this->bottom = $this->right;
                $this->right = $top;
                break;
            default:
                new Error('error');
        }
    }
}

$line = trim(fgets(STDIN));
$nums = explode(' ', $line);
$keys = explode(',', 'top,front,left,right,back,bottom');
$arr = array_combine($keys, $nums);
fscanf(STDIN, '%s', $str);

$dice = new Dice($arr);
$dice->parse($str);

Measured memory_bytes: 6676
#include <stdio.h>

void swap(long int  *a, long int  *b) 
{
    long int  tmp = *a;
    *a = *b;
    *b = tmp;
}

long int  get_gcd(long int  a, long int  b) 
{
    long int  tmp;
    while (a % b) {
        tmp = b;
        b = a % b;
        a = tmp;
    }
    return b;
}

int main(void) 
{
    long int  a, b, gcd, lcm;
    while (scanf("%ld %ld", &a, &b) != EOF) {
        if (a < b) {
            swap(&a, &b);
        }
        gcd = get_gcd(a, b);
        lcm = a * b / gcd;
        printf("%ld %ld\n", gcd, lcm);
    }

    return 0;
}


Measured memory_bytes: 2052
c = [list(map(int, input().split())) for i in range(3)]

q1 = c[0][0] - c[0][1] == c[1][0] - c[1][1] == c[2][0] - c[2][1]
q2 = c[0][0] - c[0][2] == c[1][0] - c[1][2] == c[2][0] - c[2][2]
q3 = c[0][0] - c[1][0] == c[0][1] - c[1][1] == c[0][2] - c[1][2]
q4 = c[0][0] - c[2][0] == c[0][1] - c[2][1] == c[0][2] - c[2][2]

print("Yes" if q1 and q2 and q3 and q4 else "No")


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

int main() {
  long N, M, L, A;
  cin >> N >> M >> L;

  int l = __builtin_ctzl(L);
  while (cin >> A) {
    if (__builtin_ctzl(A) != l) goto NG;
    L = L * A / __gcd(L, A);
    if (L / 2 > M) goto NG;
  }

  cout << (M - L / 2) / L + 1 << "\n";
  return 0;
  NG:
  cout << 0 << "\n";
}

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

int main() {
    int N;
    cin >> N;
    int p[N];
    int sorted[N];
    for (int i = 0; i < N; ++i) {
        int n;
        cin >> n;
        p[i] = n;
        sorted[i] = n;
    }
    sort(sorted, sorted + N);
    vector<int> bads;
    for (int i = 0; i < N; i++) {
        if (p[i] != sorted[i]) {
            bads.push_back(i);
        }
    }
    if (bads.empty()) {
        cout << "YES\n";
        return 0;
    }
    if (bads.size() != 2) {
        cout << "NO\n";
    } else {
        cout << "YES\n";
    }
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
struct Point{
	int x,y;
}p[200010];
bool operator <(const Point& a,const Point& b)
{
	return (long long)a.x*b.y<(long long)a.y*b.x;
}
priority_queue<pair<Point,int> >q;
int fa[200010];
int find(int x)
{
	return fa[x]==x?x:fa[x]=find(fa[x]);
}
long long ans=0;
int P[200010];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=2;i<=n;i++)
		scanf("%d",&P[i]);
	for(int i=1;i<=n;i++)
	{
		fa[i]=i;
		int x;
		scanf("%d",&x);
		if(x==0)p[i].x=1;
		else p[i].y=1;
		if(i>1)q.push(make_pair(p[i],i));
	}
	while(!q.empty())
	{
		Point pt=q.top().first;
		int u=q.top().second;
		q.pop();
		if(pt.x!=p[u].x||pt.y!=p[u].y)continue;
		int f=find(P[u]);
		ans+=(long long)p[f].y*p[u].x;
		fa[u]=f;
		p[f].x+=p[u].x;
		p[f].y+=p[u].y;
		if(f>1)q.push(make_pair(p[f],f));
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 7156
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <utility>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <istream>
#include <ostream>

#include <cstdlib>
#include <cmath>
#include <cstdio>

using namespace std;

#define fi first
#define se second
#define mkp make_pair
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define rep(i,n) for(ll i=0; i < (n); ++i)
#define rrep(i,n) for(ll i=((n)-1); i >= 0; --i)

#define OPLT(T) bool operator<(const T & lop_, const T & rop_)
#define OPEQ(T) bool operator==(const T & lop_, const T & rop_)

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

//istream& operator>>(istream& istr, __float128& obj) { double d; istr >> d; obj = d; return istr; };
//ostream& operator<<(ostream& ostr, __float128& obj) { ostr << static_cast<double>(obj); return ostr; };

int main() {
	int H, W; cin >> H >> W;
	vector<vector<string> > v;
	v.resize(H);
	rep(i,H) {
		v[i].resize(W);
		rep(j,W) {
			cin >> v[i][j];
			if(v[i][j] == "snuke") {
				cout << (char)(j+'A') << i+1 << endl;
				return 0;
			}
		}
	}

	return 0;
}


Measured memory_bytes: 256
n,t = map(int,input().split())
c = [tuple(map(int,input().split())) for _ in range(n)]
c.sort()
dp = [-1]*t
dp[0] = 0
ans = 0
for r in range(n):
    a,b = c[r]
    cur = max(dp) + b
    if ans < cur:
        ans = cur
    for i in range(t-a-1,-1,-1):
        if dp[i] >= 0 and dp[i+a] < dp[i] + b:
                dp[i+a] = dp[i] + b
cur = max(dp)
if cur > ans:
    ans = cur
print(ans)

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

using namespace std;

int main(void) {
    int x;
    cin >> x;
    if(400 <= x && x <= 599){
        cout << 8 << endl;
    }
    else if(600 <= x && x <= 799){
        cout << 7 << endl;
    }
    else if(800 <= x && x <= 999){
        cout << 6 << endl;
    }
    else if(1000 <= x && x <= 1199){
        cout << 5 << endl;
    }
    else if(1200 <= x && x <= 1399){
        cout << 4 << endl;
    }
    else if(1400 <= x && x <= 1599){
        cout << 3 << endl;
    }
    else if(1600 <= x && x <= 1799){
        cout << 2 << endl;
    }
    else if(1800 <= x && x <= 1999){
        cout << 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 3620
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from collections import defaultdict


S = str(input())
l,r = 0,1
Sset = 0
prev = ""
while r < len(S):
  if S[l:r] != prev:
    Sset += 1
    prev = S[l:r]
    l,r = r,r+1
  else:
    r += 1

if S[l:r] != prev:
  Sset += 1
print(Sset)

Measured memory_bytes: 3872
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

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

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

using namespace std;

int main() {
	int k,t;
	long long ans = 0;

	cin >> k >> t;
	vector<int> a(t);
	for(int i = 0; i < t; i++){
		cin >> a[i];
	}

	sort(a.begin(),a.end());
	int max = a.back();
	int nokori = 0;
	for(int i = 0; i < t-1; i++){
		nokori += a[i];
	}

	ans = max - nokori - 1;
	if(ans < 0){
		ans = 0;
	}
	// int last = 0;
	// int now = 0;

	// for(int i = 0; i < k; i++){
	// 	vector<int>::iterator maxiter = max_element(a.begin(), a.end());
	// 	int eatpos = distance(a.begin(), maxiter);
	// 	if(eatpos == last){
	// 		do{
	// 			eatpos--;
	// 		}while(a[eatpos] == 0 && eatpos != 0);

	// 		if(eatpos == 0){
	// 			eatpos = distance(a.begin(), maxiter);
	// 			ans++;
	// 		}
	// 		a[eatpos]--;

	// 	}else{
	// 		a[eatpos]--;
	// 		last = eatpos;
	// 	}
	// 	cout << "eat:" << eatpos << endl;
	// }

	cout << ans << endl;

	return 0;
}

/*
NSNNSNSN

NNEW

W


*/

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

int main() {
  int A,B,C;
  cin >> A >> B >> C;
  if ((A == B && A != C) || (B == C && B != A) || (C == A && A != B)){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    int n; cin >> n;
    vint a(n);
    rep(i,n) cin >> a[i];
    ll ans = -1;
    sort(rall(a));
    queue<int> q;
    rep(i,n) q.push(a[i]);
    ll sum = 0;
    rep(i,(n-1)/2) {
        int x = q.front(); q.pop();
        sum += 2*x;
    }
    if (!(n&1)) {
        int x = q.front(); q.pop();
        sum += x;
        x = q.front(); q.pop();
        sum -= x;
    } else {
        int x = q.front(); q.pop();
        sum -= x;
        x = q.front(); q.pop();
        sum -= x;
    }
    rep(i,n/2-1) {
        int x = q.front(); q.pop();
        sum -= 2*x;
    }
    ans = max(sum,ans);
    rep(i,n) q.push(a[i]);
    sum = 0;
    rep(i,n/2-1) {
        int x = q.front(); q.pop();
        sum += 2*x;
    }
    if (!(n&1)) {
        int x = q.front(); q.pop();
        sum += x;
        x = q.front(); q.pop();
        sum -= x;
    } else {
        int x = q.front(); q.pop();
        sum += x;
        x = q.front(); q.pop();
        sum += x;
    }
    rep(i,(n-1)/2) {
        int x = q.front(); q.pop();
        sum -= 2*x;
    }
    ans = max(ans,sum);
    cout << ans << endl;
}

Measured memory_bytes: 4036
N = int(input())
x_list = []
y_list = []
import math

def calc_distance(x1,y1,x2,y2):
  distance_2 = (x1 - x2)**2 + (y1 - y2)**2
  distance = distance_2**0.5
  return distance

for i in range(N):
  x,y = map(int,input().split())
  x_list.append(x)
  y_list.append(y)

distance_list = []
distance_sum = 0
for i in range(N):
  #distance_list.append([])
  for j in range(N):
    distance_sum += calc_distance(x_list[i],y_list[i],x_list[j],y_list[j])
    #distance_list[i].append(calc_distance(x_list[i],y_list[i],x_list[j],y_list[j]))

ans = distance_sum / N 
print(ans)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main()
{int m,n;
cin>>m>>n;
int a[m][n];
for(int i=0;i<m;i++)
{for(int j=0;j<n;j++)
  cin>>a[i][j];}
  int r=0;
for(int i=0;i<m-1;i++)
{
for(int j=i+1;j<m;j++)
{float s=0;
for(int k=0;k<n;k++)
  {s=s+((a[i][k]-a[j][k])*(a[i][k]-a[j][k]));}
  s=sqrt(s);
  if(abs(floor(s)-s)==0)
    r=r+1;
      }}
      cout<<r;}


Measured memory_bytes: 3680
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;


int main(){
    LL x,y;
    cin >> x >> y;
    if(abs(x-y)<=1) puts("Brown");
    else puts("Alice");
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

using namespace std;

const int MAXN=1e6+3;
int N;
int A[MAXN];
bool visited[MAXN];
int appeared[MAXN];

int main(){
    int max_num=0;
    scanf("%d",&N);
    for(int i=0;i<N;i++){
        scanf("%d",A+i);
        max_num=max(max_num,A[i]);
        appeared[A[i]]++;
    }

    bool has_cd=false,not_pair_wise=false;

    for(int i=2;i<=max_num;i++){
        if (visited[i]) continue;
        int c=0;
        for(int k=i;k<=max_num;k+=i) {
            visited[k]=true;
            c+=appeared[k];
        }
        
        if (c==N) has_cd=true;
        if (c>1) not_pair_wise=true;
    }

    if (has_cd) puts("not coprime");
    else if (not_pair_wise) puts("setwise coprime");
    else puts("pairwise coprime");


    return 0;
}

Measured memory_bytes: 10392
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

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

    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        Map<String, Integer> map = new HashMap<>();
        for (int i = 0; i < N; i++) {
            String s = scan.next();
            int x = map.getOrDefault(s, 0);
            map.put(s, x+1);
        }
        List<Pair> list = new ArrayList<>();
        for(String s : map.keySet()) {
            Pair p = new Pair(s, map.get(s));
            list.add(p);
        }
        list.sort(new PairComparator());
        int count = list.get(0).count;
        for (Pair p : list) {
            if (p.count == count) {
                System.out.println(p.S);
            }
        }
    }
    class Pair {
        String S;
        int count;
        Pair(String S, int count) {
            this.S = S;
            this.count = count;
        }
    }
    class PairComparator implements Comparator<Pair> {
        @Override
        public int compare(Pair o1, Pair o2) {
            if (o1.count != o2.count) {
                return -Integer.compare(o1.count, o2.count);
            }
            return o1.S.compareTo(o2.S);
        }
    }
}


Measured memory_bytes: 87172
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main() {
    int x, N;
    int A[1000];
    cin >> N >> x;
    for (int i = 0; i < N; ++i) cin >> A[i];
    sort(A, A + N);
    int count = 0;

    for (int i = 0; i < N; ++i){
        if(x - A[i] < 0) break;
        else{
            x -= A[i];
            count++;
        }
    }

    if(count == N){
        if(x != 0) cout << count - 1 << endl;
        else cout << count << endl;
    }else{
        cout << count << endl;
    }

}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <bitset>
#include <stack>
#include <deque>
#include <set>
#include <unordered_set>
#include <list>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <climits>
#include <ctime>
#include <random>
#define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define eps 1e-9
#define inf 0x3f3f3f3f
#define mod 1000000007
using namespace std;

int main() {
	speed;
	string a, b;
	cin >> a >> b;
	int ans = inf;
	for (int i = 0; i < a.size() - b.size() + 1; ++i) {
		int cur = 0;
		for (int j = 0; j < b.size(); ++j) {
			if (a[i + j] != b[j])
				cur++;
		}
		if (cur < ans)
			ans = cur;
	}
	cout << ans;
}

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

int main(){
	string s,t;
	cin >> s;
	cin >> t;
	int dp[s.length()+1][t.length()+1];
	int dir[s.length()+1][t.length()+1];
	for(int a = 0;a <= s.length();a++) {
		dp[a][0] = 0;
		dir[a][0] = 0;
	}
	for(int a = 0;a <= t.length();a++) {
		dp[0][a] = 0;
		dir[0][a] = 0;
	}
	for(int a = 1;a <= s.length();a++){
		for(int b = 1;b <= t.length();b++){
			if (s[a-1] != t[b-1]){
				dp[a][b] = max(dp[a-1][b],dp[a][b-1]);
				if (dp[a][b] == dp[a-1][b]) dir[a][b] = 1;
				else dir[a][b] = 2;
			}
			else{
				dp[a][b] = max(max(dp[a-1][b],dp[a][b-1]),dp[a-1][b-1]+1);
				if (dp[a][b] == dp[a-1][b]) dir[a][b] = 1;
				else if (dp[a][b] == dp[a][b-1]) dir[a][b] = 2;
				else dir[a][b] = 3; 
			}
		}
	}
	int x = s.length(),y = t.length();
	string ans;
	while(1){
		if (dir[x][y] == 0){
			break;
		}
		else if (dir[x][y] == 1){
			x--;
		}
		else if (dir[x][y] == 2){
			y--;
		}
		else{
			ans += s[x-1];
			x--;
			y--;
		}
	}
	for(int a = ans.length()-1;a >= 0;a--){
		cout << ans[a];
	}
}


Measured memory_bytes: 73388
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<ll(n);i++)
int main() {
    ll n, k;
    cin >> n >> k;
    vector<int>a(n);
    rep(i, n) {
        cin >> a[i];
        a[i]--;
    }
    vector<bool> seen(n, false);
    vector<int>c(0);
    int now = 0;
    seen[now] = true;
    c.push_back(now);
    int st;
    while (true) {
        now = a[now];
        if (seen[now] == true) {
            st = now;
            break;
        }
        seen[now] = true;
        c.push_back(now);
        //cout << now << endl;
    }
    if (k < c.size()) {
        cout << c[k] + 1 << endl;
        return 0;
    }
    rep(i, c.size()) {
        if (c[i] == st) {
            cout << c[(k-i)%(c.size()-i) + i] + 1 << endl;
            break;
        }
    }
//    cout << c.size() << endl;
//    cout << c[k%c.size()] + 1 << endl;
    return 0;
}



Measured memory_bytes: 5104
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A,B;
  cin >> A >> B;
  int res = 0;
  for (int i = A; i <= B; i++){
    string S = to_string(i);
    if (S[0] == S[4] && S[1] == S[3]) res++;
  }
  cout << res;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
int main() {
  ll x, y;
  cin >> x >> y;
  for (ll i = 0; i <= x; i++) {
    ll tsuru = i * 2;
    ll kame = (x - i) * 4;
    if ((tsuru + kame) == y) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 200005
#define ba 47
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
const int MOD = 1000000007;
int N,V = 2000;
int A[MAXN],B[MAXN],dp[4005][4005];
int fac[100005],invfac[100005];
int inc(int a,int b) {
    return a + b >= MOD ? a + b - MOD : a + b;
}
int mul(int a,int b) {
    return 1LL * a * b % MOD;
}
void update(int &x,int y) {
    x = inc(x,y);
}
int C(int n,int m) {
    if(n < m) return 0;
    return mul(fac[n],mul(invfac[m],invfac[n - m]));
}
int fpow(int x,int c) {
    int res = 1,t = x;
    while(c) {
	if(c & 1) res = mul(res,t);
	t = mul(t,t);
	c >>= 1;
    }
    return res;
}
void Solve() {
    read(N);
    for(int i = 1 ; i <= N ; ++i) {read(A[i]);read(B[i]);dp[V - A[i]][V - B[i]]++;}
    fac[0] = 1;
    for(int i = 1 ; i <= 100000 ; ++i) fac[i] = mul(fac[i - 1],i);
    invfac[100000] = fpow(fac[100000],MOD - 2);
    for(int i = 99999 ; i >= 0 ; --i) invfac[i] = mul(invfac[i + 1],i + 1);
    for(int i = 0 ; i <= 2 * V ; ++i) {
	for(int j = 0 ; j <= 2 * V ; ++j) {
	    if(!dp[i][j]) continue;
	    update(dp[i + 1][j],dp[i][j]);
	    update(dp[i][j + 1],dp[i][j]);
	}
    }
    int ans = 0;
    for(int i = 1 ; i <= N ; ++i) {
	update(ans,dp[V + A[i]][V + B[i]]);
	update(ans,MOD - C(2 * (A[i] + B[i]),2 * A[i]));
    }
    ans = mul(ans,(MOD + 1) / 2);
    out(ans);enter;
}

int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


Measured memory_bytes: 65280
#include <bits/stdc++.h>
#define rep(i,n)    for(long long i = 0; i < (n) ; ++i)
#define orep(i,n)   for(long long i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(long long i = (n)-1; i >= 0; --i) // down rep
#define srep(i,s,t) for(long long i = (s); i < (t); ++i)  // set rep
#define rng(x)  (x).begin(),(x).end()

  // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)


using namespace std;
using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vl  = vector<ll>;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

template<typename T> void pv2(vector<vector<T>> vec) {
  for(auto& v : vec) pv(v);
}

int main() {
  int n;
  cin >> n;
  int ans=0;
  rep(i,n) {
    int a;
    cin >> a;
    ans+=(a-1);
  }
  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 256
/*????\¨(Vote)*/
#include <stdio.h>
int main(){
  int i, j, x, y, z, N, M;
  int A[1000] = {0};
  int B[1000] = {0};
  int data[1000] = {0};
  scanf("%d %d", &N, &M);
  for (i = 1; i - 1 < N; i++) {
    scanf("%d", &A[i - 1]);
  }
  for (j = 1; j - 1 < M; j++) {
    scanf("%d", &B[j - 1]);
  }
  for (j = 1; j - 1 < M; j++) {
    x = 0;
    for (i = N; 0 < i; i--) {
      if (A[i - 1] <= B[j - 1]) {
        x = i - 1;
	  }
	}
    data[x]++;
  }
  y = data[0];
  for (i = 1; i - 1 < N; i++) {
    if (y <= data[i - 1]) {
	y = data[i - 1];
	z = i;
    }
  }
  printf("%d\n", z);
  return 0;
}

Measured memory_bytes: 608
#include<stdio.h>
main()
{
int n,c,D=100000,flag=0;
double d;

scanf("%d",&n);

for(c=0;c<n;c++){
    
    flag=0;
    d=D*1.05;
    D=d;
   // printf("%d\n",D);
    if(D%1000!=0){flag=1;}
    D/=1000;
    //printf("%d\n",D);
    D*=1000;
    //printf("%d\n",D);
    if(flag==1)D+=1000;
    //printf("%d\n",D);
}

printf("%d\n",D);

return 0;
}

Measured memory_bytes: 588
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int t = sc.nextInt();
		int a = sc.nextInt();
		int[] array=new int[n];
		double min=9999999;
		int res=0;

		for(int i=0;i<n;i++) {
			array[i]=sc.nextInt();
		}

		for(int i=0;i<n;i++) {
			if(min>Math.abs(a-(t-array[i]*0.006))) {
				min=Math.abs(a-(t-array[i]*0.006));
				res=i+1;
			}
		}
		System.out.println(res);
	}
}

//Arrays.sort(array, (a, b) -> Integer.compare(a[0], b[0]));




Measured memory_bytes: 23636
#include<bits/stdc++.h>
#define MN 100000
#define mod 1000000007
#define pa pair<int,int>
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
pa s[MN+5];
int n,m,a[MN+5],b[MN+5],c[MN+5],f[MN+5];
struct Tree{int l,r,x,s;}T[MN*4+5];
void Build(int x,int l,int r)
{
    if((T[x].l=l)==(T[x].r=r)) return;
    int mid=l+r>>1;
    Build(x<<1,l,mid);Build(x<<1|1,mid+1,r);
}
inline void Mark(int x){T[x].s=1,T[x].x=0;}
void R(int x,int k,int v)
{
    if(T[x].l==T[x].r) {(T[x].x+=v)%=mod;return;}
    if(T[x].s) Mark(x<<1),Mark(x<<1|1),T[x].s=0;
    int mid=T[x].l+T[x].r>>1;
    R(x<<1|(k>mid),k,v);
    T[x].x=(T[x<<1].x+T[x<<1|1].x)%mod;
}
void C(int x,int l,int r)
{
    if(T[x].l==l&&T[x].r==r) return Mark(x);
    int mid=T[x].l+T[x].r>>1;
    if(T[x].s) Mark(x<<1),Mark(x<<1|1),T[x].s=0;
    if(r<=mid) C(x<<1,l,r);
    else if(l>mid) C(x<<1|1,l,r);
    else C(x<<1,l,mid),C(x<<1|1,mid+1,r);
    T[x].x=(T[x<<1].x+T[x<<1|1].x)%mod;
}
int Q(int x,int l,int r)
{
    if(T[x].l==l&&T[x].r==r) return T[x].x;
    int mid=T[x].l+T[x].r>>1;
    if(T[x].s) Mark(x<<1),Mark(x<<1|1),T[x].s=0;
    if(r<=mid) return Q(x<<1,l,r);
    else if(l>mid) return Q(x<<1|1,l,r);
    else return (Q(x<<1,l,mid)+Q(x<<1|1,mid+1,r))%mod;
}
int main()
{
    n=read();m=read();
    for(int i=1;i<=n;++i) a[i]=read();
    for(int i=1;i<=m;++i) b[i]=read();
    for(int i=1,j=0;i<=n;++i)
    {
        while(j<m&&b[j+1]<a[i]) ++j;
        int l=j?a[i]-b[j]:int(2e9),
            r=j<m?b[j+1]-a[i]:int(2e9);
        s[i]=make_pair(l,-r);c[i]=r;
    }
    sort(c+1,c+n+1);int m=unique(c+1,c+n+1)-c-1;
    sort(s+1,s+n+1);n=unique(s+1,s+n+1)-s-1;
    for(int i=1;i<=n;++i) s[i].second=lower_bound(c+1,c+m+1,-s[i].second)-c;
    Build(1,1,m+1);R(1,1,1);
    for(int i=1;i<=n;++i)
    {
        int t=Q(1,1,s[i].second);
        if(s[i].first>1e9) C(1,1,s[i].second);
        if(s[i].second==m&&c[m]>1e9) C(1,s[i].second+1,m+1);
        else R(1,s[i].second+1,t);
    }
    printf("%d\n",T[1].x);
    return 0;
}


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

using namespace std;

#define fastio cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(0)
typedef long long ll;
//#define int ll
#define swap(x, y)((x)^=(y)^=(x)^=(y))
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> matrix;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(c) c.begin(),c.end()
#define mp make_pair
#define pb push_back
#define f first
#define tcase int _; cin>> _; for( ; _; --_)
#define s second
#define endl '\n'
const int MAX = 1e6+1;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1);
const double DEG = 180/PI;
const int MOD = 1e9+7;
int mod(int x, int m){ if(x >= 0) return x % m; if(-x < m) return m-(-x); return mod(x%m, m);}
int gcd (int a, int b) {while(b){a = mod(a, b); swap(a, b);} return a;}
int lcm (int a, int b) {return a / gcd(a, b) * b;}
int fexp(int base, int exp, int m){
	int total = 1;
	while(exp > 0){
		if(exp % 2 == 1){
			total = mod(((mod(total, m)) * (mod(base, m))), m);
			exp--;
		}
		base= mod((mod(base, m) * mod(base, m)), m);
		exp /= 2;
	}
	return mod(total, m);
}

int n;

void solve(){
    cin>> n;
    vi r(4, 0);
    vector<string> st = {"AC", "WA", "TLE", "RE"};
    for(int i = 0; i <n; ++i){
        string s; cin>> s;
        if(s == "AC") r[0]++;
        else if(s == "WA") r[1]++;
        else if(s == "TLE") r[2]++;
        else r[3]++;
    }
    for(int i= 0; i<4; ++i) cout<< st[i] << " x "<< r[i]<< endl;
}

int32_t main(){
	fastio;
	solve();
	return 0;
}



Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    long long K;
    cin >> K;
    vector<unsigned long long> res(50);
    REP(i, 50) { res[i] = 49 + K / 50; }
    K %= 50;
    REP(i, K) {
        res[i % 50] += 51;
        REP(j, 50) { res[j] -= 1; }
    }
    cout << 50 << endl;
    REP(i, 50) { cout << res[i] << " "; }
    cout << endl;
    // calc(res, 2);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

int gcd(int a,int b){
    return b ? gcd(b,a%b) : a;
}

int main(){
    int N;cin >> N;
    vector<int> A(N);
    rep(i,N)cin >> A[i];
    vector<int> gcd_left(N+1,0),gcd_right(N+1,0);

    for(int i=0;i<N;i++){
        gcd_left[i+1]=gcd(gcd_left[i],A[i]);
    }
    for(int i=N-1;i>=0;i--){
        gcd_right[i]=gcd(gcd_right[i+1],A[i]);
    }

    int res = 0;
    for(int i=0;i<N;i++){
        res = max(res,gcd(gcd_left[i],gcd_right[i+1]));
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1408
import math

k = int(input())
total = 0

#0こ
for i in range(1, k+1):
    total += i
#print(total)

#1こ,２こ
for i in range(1, k+1):
    for j in range(i+1, k+1):
        total += math.gcd(i, j) * 3 * 2
#print(total)

#3こ
for i in range(1, k+1):
    for j in range(i+1, k+1):
        for k in range(j+1, k+1):
            total += math.gcd(math.gcd(i, j), k) * 6
print(total) 


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

int main() {
  string s, t; 
  cin >> s >> t;
  
  int sum = 0;
  for(int i = 0; i < 3; i++){
    if(s.at(i) == t.at(i)) sum++;
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAX=1e16;
const int INF=1e6+100;
int main()
{
    int n,a,b;
    cin>>n;
    ll x=1,y=1;
    ll r,l,mid;
    for(int i=0; i<n; i++){
        cin>>a>>b;
        mid=max(x/a,y/b);
        while(mid*a<x || mid*b<y) mid++;
        x=mid*a;
        y=mid*b;
    }
    cout<<x+y<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e9;
const ll MOD = 1e9 + 7;


int main(){
    double l;
    cin >> l;
    cout << setprecision(9) << pow(l/3, 3) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
#define invrep(i,n) for(int64_t i=n-1;i >= 0L;i--)
#define prep(i,n) for(int64_t i=1;i <= (int64_t)(n);i++)
using namespace std;

//////全探索したいときに開けよ////////
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;

void setfspattern_core(int floor,int number,int degree){
  if(floor==degree){
    fspattern.at(fspcnt) = fspattern_draft;
    fspcnt++;
  }else{
    rep(i,number){
      fspattern_draft.at(floor) = i;
      setfspattern_core(floor+1,number,degree);
    }
  }
}

void setfspattern(int number,int degree){
  int64_t array_num = 1;
  fspcnt = 0;
  rep(i,degree){
    array_num *= number;
  }
  fspattern = vector<vector<int>>(array_num,vector<int>(degree));
  fspattern_draft = vector<int>(degree);
  setfspattern_core(0,number,degree);
}

//////nCrのmodを求めたいときに開けよ/////////
//int64_t univMod = 1000000007;
//int64_t factnum = 100000
//vector<int64_t> modfact(factnum);
//vector<int64_t> modinvfact(factnum);

/*void setmodfact(){
  for(int i=0;i<factnum;i++){
    if(i == 0){
      modfact.at(i) = 1;
    }else{
      modfact.at(i) = (modfact.at(i-1)*i)%univMod;
    }
  }
}

int64_t calcmodpower(int64_t a,int64_t n){
  int64_t res = 1;
  while(n != 0){
    if(n & 1){
      res = (res * a) % univMod;
    }
    a = (a*a) % univMod;
    n = n >> 1;
  }
  return res;
}

int64_t calcinverse(int64_t n){
	return calcmodpower(n,univMod-2);
}

void setmodinvfact(){
  for(int i=0;i<factnum;i++){
    if(i==0){
      modinvfact.at(i) = 1;
    }else{
      modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
    }
  }
}

int64_t calcmodcomb(int64_t n,int64_t r){
  return (((modfact.at(n)*modinvfact.at(r))%univMod)*modinvfact.at(n-r))%univMod;
}

int64_t calcmodpositive(int64_t n){
  return (n + ((abs(n)+univMod-1)/univMod)*univMod)%univMod;
}
  
    */


/*
int64_t calcGCD(int64_t a,int64_t b){
	int64_t p = a;
	int64_t q = b;
	int64_t c = a%b;
	while(c != 0){
		p = q;
		q = c;
		c = p%q;
	}
	return q;
}
*/

int main(){
  int n,m,x;
  cin >> n >> m >> x;
  vector<int> risk(n+1);
  rep(i,m){
    int hoge;
    cin >> hoge;
    risk.at(hoge)++;
  }
  rep(i,n){
    risk.at(i+1) += risk.at(i);
  }
  cout << min(risk.at(x),risk.at(n)-risk.at(x)) << endl;
    
    
}

Measured memory_bytes: 256