akhauriyash/Code-Regression huggingface dataset:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n,m=map(int,input().split())
    num=[tuple(map(int,input().split())) for i in range(m)]
    num.sort()
    min_num=[0,0,0]
    flag=[True,True,True]
    for i in range(m):
        if flag[num[i][0]-1]:
            min_num[num[i][0]-1]=num[i][1]
            flag[num[i][0]-1]=False
        else:
            if min_num[num[i][0]-1]!=num[i][1]:
                print(-1)
                break
    else:
        if n==3:
            if min_num[0]==0:
                if flag[0]==True:
                    print(100+10*min_num[1]+min_num[2])
                else:print(-1)
            else:
                print(100*min_num[0]+10*min_num[1]+min_num[2])

        elif n==2:
            if min_num[0]==0:
                if flag[0]==True:
                    print(10+min_num[1])
                else:print(-1)
            else:
                print(10*min_num[0]+min_num[1]) 
        else:print(min_num[0])
if __name__=='__main__':
    main()

Measured memory_bytes: 38512
import sys

def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def S(): return sys.stdin.readline().rstrip()

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

AB = []
for i in range(N):
    a,b = LI()
    AB.append((a,-b))

from operator import itemgetter

AB = sorted(AB,key = itemgetter(0))

import heapq

L = []
heapq.heapify(L)

ans = 0
r = 0
for i in range(1,M+1):
    for j in range(r,N):
        if AB[j][0] == i:
            heapq.heappush(L,AB[j][1])
        else:
            r = j
            break
    if len(L) >= 1:
        ans -= heapq.heappop(L)

print(ans)

Measured memory_bytes: 89248
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>


using namespace std;
string yn(bool a)
{
  if (a){return "Yes";}
  else{return "No";}
}

int main()
{
  ios::sync_with_stdio(false);
  string s;
  int x,y;
  cin>>s>>x>>y;
  vector<int> a,b;
  bool f=1;
  int tmp=0;
  for(auto itr=s.begin();itr !=s.end();itr++)
  {
    if(*itr=='F'){tmp++;}
    else {
      if(f){a.push_back(tmp);}
      else{b.push_back(tmp);}
      f=!f;
    tmp=0;
  }

  }
  if(f){a.push_back(tmp);}
  else{b.push_back(tmp);}
  x-=a[0];
  x=abs(x);
  y=abs(y);
  a.erase(a.begin());
  int suma=0,sumb=0;
  for(auto itr=a.begin();itr !=a.end();itr++)
  {
    suma+=*itr;
  }
  for(auto itr=b.begin();itr !=b.end();itr++)
  {
    sumb+=*itr;
  }
  int flag=0;
  if((suma-x)%2 or (sumb-y)%2){flag=0;}
  else
  {
    if(suma<x or sumb<y){flag=-2;}
    x=(suma-x)/2;
    y=(sumb-y)/2;
    vector<int> dpx(8001),dpy(8001);
    //for(int i=0;i<8001;i++){dpx[i]=0;dpy[i]=0;}
    dpx[0]=1;dpx[suma]=1;
    dpy[0]=1;dpy[sumb]=1;
    for(auto itr1=a.begin();itr1 !=a.end();itr1++)
    {
      for(int i=x-*itr1;i>-1;i--)
      {
        if(dpx[i]==1){dpx[i+*itr1]=1;}
      }
      if(dpx[x]!=0){flag+=1;break;}

    }
    if(a.size()==0 and x==0){flag+=1;}
    for(auto itr2=b.begin();itr2 !=b.end();itr2++)
    {
      for(int i=y-*itr2;i>-1;i--)
      {
        if(dpy[i]==1){dpy[i+*itr2]=1;}
      }
      if(dpy[y]!=0){flag+=1;break;}
    }
    if(b.size()==0 and x==0){flag+=1;}
  }
  cout<<yn(flag>=2)<<endl;
  return 0;
}

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

int main() {
    int N, T;
    cin >> N >> T;
    vector<int> t(N);
    for (int i = 0; i < N; i++) {
        cin >> t[i];
    }

    ll ans = 0;
    ll end = 0;
    for (int i = 0; i < N; i++) {
        if (end <= t[i]) {
            ans += T;
        } else {
            ans += t[i] + T - end;
        }
        end = t[i] + T;
    }
    cout << ans << endl;
}


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

#define maxn 100000+5

using namespace std;

typedef long long LL;

LL l[maxn],r[maxn],x[maxn],v[maxn],c,ans,m1,m2;
int n;

int main(){
	cin >> n >> c;
	for(int i=1;i<=n;i++){
		cin >> x[i] >> v[i];
	}
	x[n+1]=c;
	for(int i=1;i<=n;i++)
		l[i]=l[i-1]+v[i]-(x[i]-x[i-1]);
	for(int i=1;i<=n;i++)
		l[i]=max(l[i-1],l[i]);
	for(int i=n;i>=1;i--)
		r[i]=r[i+1]+v[i]-(x[i+1]-x[i]);
	for(int i=n;i>=1;i--)
		r[i]=max(r[i+1],r[i]);
	for(int i=1;i<=n;i++){
		ans=max(ans,l[i]);
		ans=max(ans,l[i]+r[i+1]-x[i]);
	}
	for(int i=n;i>=1;i--){
		ans=max(ans,r[i]);
		ans=max(ans,r[i]+l[i-1]-(c-x[i]));
	}
	cout << ans;
	return 0;
} 

Measured memory_bytes: 3328
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 200005
using namespace std;
typedef long long ll;
struct P{
	int x,id;
}a[N<<1];
int n,sum[N],mx[N<<1],w[N][2];
ll ans=1e18;
bool cmp(P a,P b){
	return a.x<b.x;
}
int main(){
	scanf("%d",&n);
	for(int i=1,x,y;i<=n;i++){
		scanf("%d%d",&x,&y);
		if(x>y) swap(x,y);
		w[i][0]=x;w[i][1]=y;
		a[i].x=x;a[i].id=i;
		a[i+n].x=y;a[i+n].id=i;
	}
	n<<=1;
	sort(a+1,a+n+1,cmp);
	if(a[1].id!=a[n].id){
		for(int i=2,p=1,j=0;i<n;i++){
			while(j+j<n&&p<n-1){
				p++;
				sum[a[p].id]++;
				if(sum[a[p].id]==1) j++;
			}
			if(j+j<n) break;
			ans=min(ans,1LL*(a[p].x-a[i].x)*(a[n].x-a[1].x));
			sum[a[i].id]--;
			if(sum[a[i].id]==0) j--;
		}
	}
	memset(sum,0,sizeof(sum));
	for(int i=n;i;i--){
		sum[a[i].id]++;
		mx[i]=max(mx[i+1],sum[a[i].id]);
	}
	memset(sum,0,sizeof(sum));
	for(int i=1,mn=0,t=0;i<n;i++){
		sum[a[i].id]++;
		if(sum[a[i].id]==2&&!t) mn=a[i].x,t=1;
		if(mx[i+1]==2) continue;
		ans=min(ans,1LL*(a[i].x-a[1].x)*(a[n].x-(t==0?a[i+1].x:mn)));
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 7296
A = 0
B = 1
C = 2


N = int(input())
a = [0] * (N+1)
b = [0] * (N+1)
c = [0] * (N+1)
for i in range(1, N + 1):
    ABC = list(map(int, input().split()))
    a[i] = ABC[A]
    b[i] = ABC[B]
    c[i] = ABC[C]

dp = [[0] * 3 for i in range(N+1)]
dp[1][A] = a[1]
dp[1][B] = b[1]
dp[1][C] = c[1]

for i in range(1, N + 1):
    dp[i][A] = max(dp[i-1][B] + a[i], dp[i-1][C] + a[i])
    dp[i][B] = max(dp[i-1][A] + b[i], dp[i-1][C] + b[i])
    dp[i][C] = max(dp[i - 1][A] + c[i], dp[i - 1][B] + c[i])

print(max(dp[N][A], dp[N][B], dp[N][C]))



Measured memory_bytes: 91212
import java.io.*;
import java.util.*;
import static java.lang.System.out;

public class Main{
    static MyReader in = new MyReader();
    static long MOD = 1000000007;

    public static void main(String[] args){
        int n, a, b; {int[] c = in.ii(); n = c[0]; a = c[1]; b = c[2];}
        long ans = (ModOp.pow(2, n) - 1 + MOD - ModOp.nCr(n, a) + MOD - ModOp.nCr(n, b)) % MOD;
        out.println(ans);
    }

    static class ModOp {
        static long MOD = 1000000007;

        static long pow(long a, long b){
            long ret = 1;
            while(b > 0){
                if(b%2 == 1){
                    ret = ret*a%MOD;
                }
                a = a*a%MOD;
                b /= 2;
            }
            return ret;
        }

        static long mul(int s, int e){
            long ret = 1;
            for(int i = s; i <= e; i++){
                ret = ret*i%MOD;
            }
            return ret;
        }

        static long fact(int n){
            return mul(1, n);
        }

        static long nCr(int n, int r){
            return mul(n-r+1, n) * pow(fact(r), MOD-2) % MOD;
        }

    }

    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }

        String s(){
            try{return readLine();}catch(IOException e){return "";}
        }

        String[] ss(){
            return s().split(" ");
        }

        int i(){
            return Integer.parseInt(s());
        }

        int[] ii(){
            String[] ss = ss();
            int[] ii = new int[ss.length];
            for(int j = 0; j < ss.length; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }

        ArrayList<Integer> li(){
            String[] ss = ss();
            ArrayList<Integer> li = new ArrayList<>();
            for(int j = 0; j < ss.length; j++) li.add(Integer.parseInt(ss[j]));
            return li;
        }

        long l(){
            return Long.parseLong(s());
        }

        long[] ll(){
            String[] ss = ss();
            long[] ll = new long[ss.length];
            for(int j = 0; j < ss.length; j++) ll[j] = Long.parseLong(ss[j]);
            return ll;
        }
    }
}


Measured memory_bytes: 21460
import std.stdio, std.conv, std.string, std.algorithm, std.math, std.array, std.container;

int n;

void solve(int max_i, string prefix) {
  if(prefix.length == n) {
    writeln(prefix);
    return;
  }
  for(int i=0; i<max_i+1; i++) solve(max(i+1, max_i), prefix~('a'+i).to!char);
}

void main() {
  n = readln.chomp.to!int;
  solve(0, "");
}



Measured memory_bytes: 2556
#pragma GCC optimize("Ofast")
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//typedef tree < int , null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> TREE;
#define ll long long
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define pss pair<short,short>
#define pld pair<long double,long double >
#define ld long double
#define piii  pair<pii,int>
#define vii vector<pair<int,int> >
#define st first
#define nd second
#define pll pair<ll,ll>
#define speed ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define M_PI 3.14159265358979323846
//#define int long long
//const int mod=1000000007;
const int mod=998244353;
const int inf=1000000009;
const long long INF=1000000000000000009;
const long long big=1000000000000000;
const long double eps=0.000000000000000000001;
using namespace std;
int DP[105][105][105][105];
char T[105][105];
int funkcja(int a,int b,int c,int d)
{
    if(DP[a][b][c][d]!=-1)
        return DP[a][b][c][d];
    if(a==b&&c==d)
    {
        if(T[a][c]=='.')
            return DP[a][b][c][d]=0;
        return DP[a][b][c][d]=1;
    }
    int wynik=inf;
    if(b>a)
    {
        int aktual=funkcja(a+1,b,c,d);
        if(T[a][c]!=T[a+1][c]&&T[a][c]=='#')
            aktual++;
        wynik=min(wynik,aktual);
    }
    if(d>c)
    {
        int aktual=funkcja(a,b,c+1,d);
        if(T[a][c]!=T[a][c+1]&&T[a][c]=='#')
            aktual++;
        wynik=min(wynik,aktual);
    }
    return DP[a][b][c][d]=wynik;
}
int main()
{
    speed
    int n,m;
    cin>>n>>m;
    for(int i=1; i<=n; i++)
        for(int j=1; j<=n; j++)
            for(int k=1; k<=m; k++)
                for(int l=1; l<=m; l++)
                    DP[i][j][k][l]=-1;
    for(int i=1; i<=n; i++)
        for(int j=1; j<=m; j++)
            cin>>T[i][j];
    cout<<funkcja(1,n,1,m);
    return 0;
}


Measured memory_bytes: 452864
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

vector<int> makeTable(const vector<int>& s) {
    int n = s.size();
    vector<int> ret(n + 1);
    ret[0] = -1;
    int j = -1;
    for (int i = 0; i < n; i++) {
        while (j >= 0 && s[i] != s[j]) j = ret[j];
        j++;
        ret[i + 1] = j;
    }
    return ret;
}

vector<int> kmp(const vector<int>& str, const vector<int>& word) {
    vector<int> table = makeTable(word), ret;
    int m = 0, i = 0, n = str.size();
    while (m + i < n) {
        if (word[i] == str[m + i]) {
            if (++i == (int) (word.size())) {
                ret.push_back(m);
                m = m + i - table[i];
                i = table[i];
            }
        } else {
            m = m + i - table[i];
            if (i > 0) i = table[i];
        }
    }
    return ret;
}

class FXorShift {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        int N;
        cin >> N;
        vector<int> a(N), b(N);
        REP(i, N) cin >> a[i];
        REP(i, N) cin >> b[i];
        vector<int> va(2 * N - 1), vb(N - 1);
        REP(i, 2 * N - 1) va[i] = a[i % N] ^ a[(i + 1) % N];
        REP(i, N - 1) vb[i] = b[i] ^ b[i + 1];

        auto v = kmp(va, vb);
        vector<P> res;
        REP(i, v.size()) {
            int idx = v[i];
            if (idx >= N) continue;
            res.push_back({idx, b[0] ^ a[idx]});
        }
        for (auto kv : res) {
            cout << kv.first << " " << kv.second << endl;
        }
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    FXorShift solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 18000
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main(){
	int n,a,b,c,s;
	cin >> n ;
	for(int i = 0;i<n;i++){
		s=0;
		cin >> a >> b >> c;
		while((c>0)&&(b>0)&&(a>0)){
			c--;
			b--;
			a--;
			s++;
		}
		while((b>0)&&(a>1)){
			b--;
			a-=2;
			s++;
		}
		while(a>2){
			a-=3;
			s++;
		}
		cout << s << "\n";
	}
		
	
return 0;
}

Measured memory_bytes: 1164
#include <iostream>

using namespace std;

string S;
typedef long long ll;
ll dp[100010][4];

int main() {
   int mod = 1000000007;
   cin >> S;
   int N = S.size();
   for (int i=N;i>=0;i--) {
      for (int j=3;j>=0;j--) {
	 if (i==N) {
	    dp[i][j] = (j==3?1:0);
	 } else {
	    dp[i][j] = dp[i+1][j] * (S[i] == '?' ? 3LL : 1LL);
	    if (j<3&&(S[i]=='?'||S[i]=="ABC"[j])) {
	       dp[i][j] += dp[i+1][j+1];
	    }
	    dp[i][j] %= mod;
	 }
      }
   }
   cout << dp[0][0] << endl;
   
   return 0;

}


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

using i64 = int64_t;

#define rep(i, x, y) for (i64 i = i64(x), i##_max_for_repmacro = i64(y); i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

template <typename T>
bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<typename T, size_t size> void fill(T (&ary)[size], const T& val){
    fill_n((T*)ary, size, val);
}

void solve() {
    //const i64 mod = 1'000'000'007;
    string S;
    cin >> S;

    vector<char> cnt(26);
    rep(i,0,S.size()){
        ++cnt[S[i]-'A'];
    }

    i64 k=0;
    rep(i,0,26) if(cnt[i]>=1) ++k;
    if(k!=2){
        cout << "No" << endl;
        return;
    }

    rep(i,0,26){
        if(cnt[i]>0 and cnt[i]!=2){
            cout << "No" << endl;
            return;
        }
    }

    cout << "Yes" << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


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

const ll mod = 1000000007;
struct mint {
    ll x;  // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    mint inv() const {
        return pow(mod - 2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

struct combination {
    vector<mint> fact, ifact;
    // init struct with "n" of "nCk" (maximum number in other words)
    combination(int n) : fact(n + 1), ifact(n + 1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
    }
    // c(n,k) returns mint that contains nCk (mod p (= 1e9+7)) in x
    // i.e.) mint num = c(n,k), then num.x == nCk (mod p (= 1e9+7))
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }
} comb(2000005);

mint g(int r, int c) {
    return comb(r + c + 2, r + 1) - 1;
}

int main() {
    int r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    --r1;
    --c1;

    mint ans = g(r2, c2);
    ans -= g(r1, c2);
    ans -= g(r2, c1);
    ans += g(r1, c1);
    cout << ans.x << endl;
}

Measured memory_bytes: 31488
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define fin <<'\n'
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
//#define int long long
typedef long long ll;
typedef pair < int , int >  pii;
typedef vector < int > vit;
typedef map < string , int > mstit;
typedef vector < pii > vpi ;
typedef greater < pii > gpi;
typedef priority_queue < pii , vpi , gpi > dijk ;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>T abs(T &x){return x<0 ? -x : x;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}


int dp[3030][3030];
string s, t;
inline void solve(){

    cin >> s;
    cin >> t;
    int n = s.size(), m = t.size();
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            if(s[i] == t[j]){
                dp[i+1][j+1] = dp[i][j] + 1;
            }else{
                dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j]);
            }
        }
    }

    string ans;

    int i = n, j = m;

    while(i>=0&&j>=0) {
        if(i > 0 && j > 0 && s[i-1]==t[j-1]){
            ans += s[i-1];
            i--;
            j--;
        }
        else if(i > 0 && dp[i][j] == dp[i-1][j])
            i--;
        else
            j--;
    }

    reverse(ALL(ans));
    
    cout << ans << endl;
    
}
struct xyz{ xyz(){ cin.tie(0), ios::sync_with_stdio(false); cout <<fixed<<setprecision(12);};}xyzzy;signed main(){solve();return 0;}


Measured memory_bytes: 35840
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int X, A, B;
    cin >> X >> A >> B;
    output((X - A) % B);
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
 
using namespace std;
 
int main(){
  int n, m, a[50], b[50], c[50], d[50];
  cin >> n >> m;
  for(int i = 0; i < n; i++)cin >> a[i] >> b[i];
  for(int i = 0; i < m; i++)cin >> c[i] >> d[i];
  for(int i = 0; i < n; i++){
    int mindist = 300000000;
    int mini = -1;
    for(int cpi = 0; cpi < m; cpi++){
      int dist = abs(a[i] - c[cpi]) + abs(b[i] - d[cpi]);
      if(mindist > dist){
        mindist = dist;
        mini = cpi;
      }
    }
    cout << mini + 1<< endl;
  }
}

Measured memory_bytes: 256
import sys
import math
from copy import deepcopy
from collections import deque
sys.setrecursionlimit(20000000)


def main():
    L, R = map(int, input().split())

    ans = 200000000

    for a in range(L, R+1):
        for b in range(a+1, R+1):
            if a * b % 2019 < ans:
                ans = a * b % 2019
                if ans == 0:
                    print(ans)
                    sys.exit()

    print(ans)


if __name__ == '__main__':
    main()



Measured memory_bytes: 38768
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int nmax=2e5+50;
const int mod=1e9+7;
using namespace std;
ll n,k,i,j,tot,sm,nr,ps,st,a[nmax],pr[nmax],p[nmax],vz[nmax];
vector<ll>vc;
ll dif(ll x,ll y)
{
	if(x>y)return x-y+1;
	return x+n-y+1;
}
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	cin>>n>>k;
	tot=n*k;
	for(i=0;i<n;i++)cin>>a[i];
	for(i=n-1;i>=0;i--)p[a[i]]=i;
	for(i=n-1;i>=0;i--)
	{
		pr[i]=p[a[i]];
		p[a[i]]=i;
	}
	i=0;
	while(1)
	{
		if(!vc.empty())sm+=dif((i-1+n)%n,vc.back());
		if(vz[i])break;
		vc.pb(i);
		vz[i]=1;
		i=(pr[i]+1)%n;
	}
	ps=i;
	if(sm>=tot)
	{
		for(i=1;i<vc.size();i++)
		{
			if(tot-dif((vc[i]-1+n)%n,vc[i-1])>=0)tot-=dif((vc[i]-1+n)%n,vc[i-1]);
			else 
			{
				st=vc[i-1];
				break;
			}
		}
	}
	else
	{
		nr+=dif((ps-1+n)%n,vc.back());
		for(i=vc.size()-1;i>=1;i--)
		{
			if(vc[i]==ps)break;
			nr+=dif((vc[i]-1+n)%n,vc[i-1]);
		}
		tot-=sm;
		tot%=nr;
		for(i++;i<vc.size();i++)
		{
			if(tot-dif((vc[i]-1+n)%n,vc[i-1])>=0)tot-=dif((vc[i]-1+n)%n,vc[i-1]);
			else 
			{
				st=vc[i-1];
				break;
			}
		}
	}
	while(1)
	{
		if(st>=n)break;
		if(pr[st]>st)st=pr[st]+1;
		else cout<<a[st]<<" ",st++;
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 9456
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  string S;
  cin >> N >> S;
  vector<string> T(2);
  T[0] = S.substr(0, N);
  T[1] = S.substr(N, N);
  reverse(all(T[1]));
  vector<map<pair<string, string>, ll>> mp(2);
  rep(n, 2) {
    rep(i, 1<<N) {
      vector<string> s(2);
      rep(j, N) {
        s[(i>>j)&1] += T[n][j];
      }
      mp[n][make_pair(s[0], s[1])]++;
    }
  }
  ll ans = 0;
  for(auto m: mp[0]) {
    ans += m.second * mp[1][m.first];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 108288
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define F first
#define S second

const int maxN = 1e5;
const int inf = 0x3f3f3f3f;
typedef long long ll;

int k;
int dp[maxN];

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//  freopen("abc.inp", "r", stdin); freopen("abc.out", "w", stdout);
  cin >> k;

  queue< pii > q;
  memset(dp, inf, sizeof dp);

  for (int d = 1; d < 10; ++d) {
    dp[d % k] = min(dp[d % k], d);
    q.push({d, d % k});
  }

  while (!q.empty()) {
    pii t = q.front(); q.pop();
    int du = t.S, min_sum = t.F;
    if (min_sum > dp[du]) continue;

    for (int d = 0; d < 10; ++d) {
      int new_du = (du * 10 + d) % k;

      if (dp[new_du] > dp[du] + d) {
        dp[new_du] = dp[du] + d;
        q.push( {dp[new_du], new_du});
      }
    }
  }

  cout << dp[0];
  return 0;
}


Measured memory_bytes: 5188
/*
for (int i = 0; i < N; ++i){}

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <numeric>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<int,int> point;
#define rep(i,n) for(i,0,n)

// int 
// // 各桁の和を計算する関数
// int findSumOfDigits(int n) {
//   int amari = 0;
//   int keta = 0;
//   while (n > 0) { // n が 0 になるまで
//     amari += n % 2;
//     if (keta%2==0)
//     n /= 10;
//   }
//   return sum;
// }
 
ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
} 

int main() {
	// 入力
	ll N, X;
	cin >> N >> X;
	ll x[N+1];
	for (int i = 0; i < N; ++i) cin >> x[i];
	x[N] = X;
 
	// 解法
	sort(x, x + N+1);
	// for (ll i = 0; i < N+1; ++i){
	// 	printf("%lld\n", x[i]);
	// }
	ll diff[N] = {0};
	for (ll i = 0; i < N; ++i) diff[i] = x[i+1] - x[i];
	// for (ll i = 0; i < N; ++i){
	// 	printf("%lld\n", diff[i]);
	// }
	
	ll ans;
	if (N==1) ans = diff[0];
	else{
		ans = gcd(diff[1], diff[0]);
		for (ll i = 1; i < N; ++i){
			ans = gcd(diff[i], ans);
		}
	}
	printf("%lld\n", ans);
}
 


Measured memory_bytes: 1792
A = gets.chomp
B = [0]*A.size
OccurrenceSum = [0]*('z'.ord-'a'.ord+1)
A.each_char.reverse_each.with_index{|c,i|
	B[-i-1] = (OccurrenceSum[c.ord-'a'.ord] += 1) -1
}
p 1+B.map.with_index{|n,i| A.size-1-i-n }.inject(:+)


Measured memory_bytes: 19836
#include <stdio.h>

int main(){
    
    int kloadaNol = 0;
    int a;
    long long b, temp;
    long long ans = 1;
    scanf("%d", &a);

    long long arr[100000];
    for (int i=0; i<a; i++){
        scanf("%lld", &arr[i]);
        if (arr[i] == 0){
            kloadaNol = 1;
        }
    }
    
    if (kloadaNol == 0){
        for(int i = 0 ; i < a ; i++){
            if(arr[i]<=1000000000000000000/ans){
                ans*=arr[i];
            }
            else{
                printf("-1\n");
                return 0;
            }
        }
        printf("%lld\n", ans);
    }
    else{
        printf("0\n");
    }
    
    return 0;
}

Measured memory_bytes: 2480
#include<bits/stdc++.h>
using namespace std;
#define INIT  ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
#define count_bits __builtin_popcount
#define int ll


int t, n, m, k, a[300010], q, l, r;


int32_t main(){
INIT
int d;
cin>>l>>r>>d;
cout<<( (r)/d)-( (l-1)/d);

return 0;
}



Measured memory_bytes: 3608
<?php
fscanf(STDIN, "%d%d", $n, $a);
$p = 1;
foreach(factor($a) as $prime => $count){
  $p*=$prime ** floor($count/$n);
}
echo $p;

function factor($M){
    $rootM = $M**0.5+1;
    for($j = 2; $j <= $rootM; $j++){
        if($M%$j == 0){
            @$map[$j]++;
            $M/=$j;
            $rootM = $M**0.5+1;
            $j--;
        }
    }
    if($M>1){
        @$map[$M]++;
    }
    return $map;
}


Measured memory_bytes: 4728
import java.math.BigDecimal;
import java.math.MathContext;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        BigDecimal bda = new BigDecimal(a);
        BigDecimal bdb = new BigDecimal(b);
        BigDecimal bdc = new BigDecimal(c);
        BigDecimal ab = sqrt(bda,50).add(sqrt(bdb,50));
        System.out.println(sqrt(bdc,50).compareTo(ab) == 1 ? "Yes" : "No");
        sc.close();

    }
    public static BigDecimal sqrt(BigDecimal a, int scale){
        //とりあえずdoubleのsqrtを求める
        BigDecimal x = new BigDecimal(
                Math.sqrt(a.doubleValue()), MathContext.DECIMAL64);
        if(scale < 17) return x;

        BigDecimal b2 = new BigDecimal(2);
        for(int tempScale = 16; tempScale < scale; tempScale *= 2){
            //x = x - (x * x - a) / (2 * x);
            x = x.subtract(
                    x.multiply(x).subtract(a).divide(
                    x.multiply(b2), scale, BigDecimal.ROUND_HALF_EVEN));
        }
        return x;
    }

}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
int n,k,a[150],dp[100005];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n>>k;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(int i=0;i<=k;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(i>=a[j])
            {
                if(dp[i-a[j]]==0)
                {
                    dp[i]=true;
                }
            }
        }
    }   
    if(dp[k]==1)cout<<"First";
    else cout<<"Second";
}

Measured memory_bytes: 640
// Last Change: 03/27/2019 00:34:28.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

const ll six[] = {1, 6, 36, 216, 1296, 7776, 46656, 279936};
const ll nine[] = {1, 9, 81, 729, 6561, 59049, 531441};

int main() {
  ll ipt;
  cin >> ipt;
  const ll N = ipt;

  vector<ll> dp(N + 1, INT64_MAX);
  dp[0] = 0;
  for (ll i = 1; i <= N; ++i) {
    for (int j = 0; j < 8; ++j) {
      if (i - six[j] >= 0) {
        dp[i] = min(dp[i], dp[i - six[j]] + 1);
      }
    }
    for (int j = 1; j < 7; ++j) {
      if (i - nine[j] >= 0) {
        dp[i] = min(dp[i], dp[i - nine[j]] + 1);
      }
    }
    dp[i] = min(dp[i], dp[i - 1] + 1);
  }

  cout << dp[N] << endl;

  //NS::LoopUntilZeroInpput();
}


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

int main(){
  string s;
  int num = 0;
  cin >> s;
  for( int i = 0; i < 4; i++ ){
    if ( s[i] == '+' )
      num++;
    else
      num--;
  }
  cout << num << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define pb push_back
#define F first
#define S second

#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define int long long
#define ll long long
const int M=1e9+7;

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

int expo(int x, int y) {int res=1;x=x%M;while(y>0){if(y&1)res=(1ll*res*x)%M;
	y=y>>1;x=(1ll*x*x)%M;} return res;}
	

signed main(){
	gearup;
	int t = 1;
	//cin >> t;
	while(t--){
		int k, n, mx = 0, ans = 0, prev, first, x;
		cin >> k >> n;
		cin >> prev;
		first = prev;
		for(int i = 1 ; i < n ; i++){
			cin >> x;
			mx = max(x - prev, mx);
			prev = x;
		}
		mx = max((k - prev) + first, mx);
		cout << k - mx;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int W,H,x,y,r;
    cin>>W>>H>>x>>y>>r;
    if(0<=x-r&&x+r<=W&&0<=y-r&&y+r<=H){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}



Measured memory_bytes: 3136
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef struct{
	int height;
	int one_side;
	int other_side;
} Column;

int colcmp(const void *p, const void *q){
	return ((Column*)q)->height - ((Column*)p)->height;
}

int main(void){
	int i;
	int n,m,a;
	Column *col;

	for(;;){
		scanf("%d %d %d",&n,&m,&a);
		if(n==0&&m==0&&a==0) break;
		col = (Column *)calloc(m,sizeof(Column));

		for(i=0;i<m;i++){
			scanf("%d %d %d",&col[i].height,&col[i].one_side,&col[i].other_side);
		}

		qsort(col, m, sizeof(Column), colcmp);
		
		for(i=0;i<m;i++){
			if(col[i].one_side==a){
				a=col[i].other_side;
			}
			else if(col[i].other_side==a){
				a=col[i].one_side;
			}
		}
		printf("%d\n",a);
	}

	return 0;
}

Measured memory_bytes: 1128
#include<iostream>
#include<iomanip>
#include<cstdio>

#include<vector>
#include<queue>
#include<set>
#include<map>
#include<string>

#include<algorithm>
#include<cmath>
#include<numeric>

using namespace std;
typedef long long ll;
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;}

/*

オールN-1から

2N-1, N-2, N-2, N-2, ...., N-2

2N-2, 2N-2, N-3, N-3, ...., N-3

2N-3, 2N-3, 2N-3, 2N-3, ...., N-4
以下同様に
計N回の操作でオールNとなる

a1...a50
K=0なら全部49

K / 50 を取って、剰余が0なら ai = 49+K/50
そうでなければ

*/


int main() {
    ll K; 
    cin >> K;
    vector<ll> a(50,49);
    
    ll Q = K / 50, R = K % 50;
    for (int i = 0; i < 50; i++) a[i] += Q;
    for (int i = 0; i < R; i++) a[i] += 51 - R;
    for (int i = R; i < 50; i++) a[i] -= R;

    cout << 50 << endl;
    for (int i = 0; i < 50; i++) cout << a[i] << " ";
    cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
int a,b,c,d;
cin>>a>>b>>c>>d;
vector<int> vec={a,b,c};
int Max=max(a,c);
int Min=min(a,c);
sort(vec.begin(), vec.end());
int sum1=vec.at(1)-vec.at(0);
int sum2=vec.at(2)-vec.at(1);
if( sum1<=d&&sum2<=d||Max-Min<=d  ) {
        cout<<"Yes"<<endl;
}else{cout<<"No"<<endl;
}
  }
               
            
     




Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import collections

N, K, Q = map(int,input().split())
A = [int(input()) for _ in range(Q)]
c = collections.Counter(A)

for i in range(N):
  if K - Q + c[i+1] > 0:
    print("Yes")
  else:
    print("No")


Measured memory_bytes: 11900
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
 
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long
 
 
 
using namespace std;
void file(){
	#ifndef ONLINE_JUDGE
    	freopen("tst.txt", "r", stdin);
	#endif	
}
int tc;
const int N=3e5+5,M=3e5+5,MOD=1e9+7,OO=1e9;

ll memo[55][55][105];
int n,k,a[55],b[55];
bool vis[55][65][105];
ll solve(int l,int r,int rem){
	if(rem==0)return 0;
	std::vector<int> mn;
	ll &ret = memo[l][r][rem];
	if(vis[l][r][rem])return ret;
	vis[l][r][rem] = 1;
	if(l>r){
		ret = 0;
		for(int i=0;i<min(rem,n);i++){
			if(b[i]>0)break;
			ret -=b[i];
		}
		return ret;
	}
	for(int i=0;i<l;i++)mn.pb(a[i]);
	for(int i=r+1;i<n;i++)mn.pb(a[i]);
	sort(all(mn));
	ret = solve(l,r,rem-1);
	ll curr = 0;
	for(int i=0;i<min(rem,sz(mn));i++){
		if(mn[i]>=0)break;
		curr-=mn[i];
		ret = max(ret,curr);
	}
	if(l<=r){
		if(l<=n-1)
			ret = max(ret,solve(l+1,r,rem-1)+a[l]);
		if(r>0)
			ret = max(ret,solve(l,r-1,rem-1)+a[r]);
	}
	return ret;
}
int main()
{	
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
 //	file();

 	scanf("%d %d",&n,&k);

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

 	sort(b,b+n);

 	printf("%lld\n",solve(0,n-1,k));
}

Measured memory_bytes: 1920
int main(int argc, char *argv[])
{
	int i;
	for (;;)
	{
		int x;
		scanf("%d\n", &x);
		if (x == 0)
		{
			break;
		}
		++i;
		printf("Case %d: %d\n", i, x);
	}
	return 0;
}

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

typedef long long int ll;
typedef pair<ll,ll> p; 

int main(void){
  int N;
  vector<p> v;
  cin >> N;
  for(int i=0;i<N;i++){
    int A,B;
    cin >> A >> B;
    v.push_back(make_pair(B,A));
  }
  sort(v.begin(),v.end());
  ll time = 0;
  for(int i=0;i<N;i++){
    p item = v[i];
    //cout << item.first << endl;
    time = time + item.second;
    if(time > item.first){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}



Measured memory_bytes: 6512
import sys
n,m=map(int,input().split())
ctl=[0]*n
for i in range(m):
  a,b=map(int,input().split())
  ctl[a-1]+=1
  ctl[b-1]+=1
for i in range(n):
  if ctl[i]%2==1:
    print('NO')
    sys.exit()
print('YES')

Measured memory_bytes: 3828
// 
#include <bits/stdc++.h>
#define endl "\n"
#define rep(i,n) for(int i=0;i<int(n);i++)
#define e_b emplace_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ipair;
typedef pair<ll,ll> lpair;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v) //vectorの中身を見る
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
void map_p(map<int,int>& d){cout<<"map: ";for(auto a : d){cout<<"{"<<a.first<<":"<<a.second<<"}";}cout<<endl;} //mapの中身を見る
void set_p(set<int>& d){cout<<"set: ";for(int a : d){cout<<a<<" ";}cout<<endl;} //setの中身を見る

vector<ll> ruia(200010,0);
vector<ll> ruib(200010,0);
bool bs(int mid,int zan){
    return ruib[mid]<=zan;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);

    int n,m,k;
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++){
        int a;
        cin>>a;
        ruia[i]=ruia[i-1]+a;
    }
    for(int i=1;i<=m;i++){
        int b;
        cin>>b;
        ruib[i]=ruib[i-1]+b;
    }
    int ans=0;
    for(int i=0;i<=n;i++){
        ll zan=k-ruia[i];
        int read=i;
        if(zan<0) break;
        int ok=-1,ng=m+1;
        int mid=(ng+ok)/2;
        while(ng-ok>1){
            if(bs(mid,zan)) ok=mid;
            else ng=mid;
            mid=(ok+ng)/2;
        }
        read+=ok;
        ans=max(ans,read);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 6280
#include<bits/stdc++.h>
using namespace std;
#define sync ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int main(){
	sync
	int n,m,c,count=0;
	cin >> n >> m >> c;
	int b[m];
	for(int i=0;i<m;i++) cin >> b[i];
	for(int i=0;i<n;i++){
		int a,tot=0;
		for(int j=0;j<m;j++){
			cin >> a;
			tot+=a*b[j];
		}
		tot+=c;
		if(tot>0) count++;
	}
	cout << count << "\n";
	return 0;
}

Measured memory_bytes: 256
H,W,N = map(int, input().split())
st = [int(i) for i in input().split()]
S = input()
T = input()


def simu(dim1):
    now = [st[0],st[1]]

    if dim1 == 'U':
        dim2,L,step,dim = 'D',H,1,0
    if dim1 == 'D':
        dim2,L,step,dim = 'U',H,-1,0
    if dim1 == 'L':
        dim2,L,step,dim = 'R',W,1,1
    if dim1 == 'R':
        dim2,L,step,dim = 'L',W,-1,1

    for i in range(N):
        if S[i] == dim1:
            now[dim] -= step
        if now[dim] < 1 or now[dim] >= L+1:
            return True
        if T[i] == dim2:
            if step == 1:
                if now[dim] < L:
                    now[dim] += step
            else:
                if now[dim] > 1:
                    now[dim] += step
    return False
        
Dim = ['U','D','R','L']
for d in Dim:
    if simu(d):
        print('NO')
        exit()
print('YES')

Measured memory_bytes: 42120
import sys

N, M = [int(i) for i in input().split()]
X = [int(i) for i in input().split()]

if N >= M:
    print(0)
    sys.exit()

X.sort()
dist =[]
for i in range(M-1):
    dist.append(X[i+1] - X[i])

dist.sort()
print(sum(dist[0:M-N]))

Measured memory_bytes: 13840
# AGC024B - Backfront
def main():
    N, *P = map(int, open(0))
    dp = [0] * (N + 1)
    for i in P:
        dp[i] = dp[i - 1] + 1
    ans = N - max(dp)
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 18864
#include <stdio.h>

#define DIRT '*'
#define MIN(x, y) ((x) < (y) ? (x) : (y))

int main(){
  int n, i, j, map[1002][1002], max;
  char s[1001];

  while(scanf("%d", &n) && n){
    for(i = 0; i < n; ++i){
      scanf("%s", s);
      for(j = 0; j < n; ++j) map[i][j] = s[j] == DIRT ? 0 : 1;
    }

    /*    for(i = 0; i < n; ++i){
      for(j = 0; j < n; ++j) printf( j ? " %d" : "%d", map[i][j]);
      puts(""); 
      } */
    for(i = 1; i < n; ++i)
      for(j = 1; j < n; ++j)
	if(map[i][j] != 0)
	  map[i][j] = MIN(map[i - 1][j - 1], MIN(map[i - 1][j], map[i][j - 1])) + 1;
    max = 0;
    for(i = 0; i < n; ++i)
      for(j = 0; j < n; ++j)
	max = max < map[i][j] ? map[i][j] : max;

    printf("%d\n", max);
  }
  return 0;
}

Measured memory_bytes: 4528
#include <iostream>

using namespace std;

bool ACGT(char s){
  return s=='A' || s=='C' || s=='G' || s=='T';
}

int main(void){
  string S;
  cin >> S;
  int i, j;
  int count_max = 0;
  for(i=0; i<S.length(); i++){
    int count = 0;
    for(j=i; ACGT(S[j]); j++)
      count++;
    count_max = max(count_max, count);      
  }

  cout << count_max << endl;

  return 0;
}


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

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

    vector <long> price(n);
    map <long, int> a;// a[値段]=本数
    rep(i,n){
        long c;
        int d;
        cin >> c >> d;

        if(a.count(c)) a.at(c) += d;
        else a[c] = d;

        price[i] = c;
    }

    sort(all(price));
    price.erase( unique (  price.begin() , price.end() ) , price.end() );

    long count = 0;
    long sum = 0;

    for(long x:price){
        if((count + a.at(x)) >= m){
            sum += x * (m-count);
            break;
        }

        else{
            count += a.at(x);
            sum += x * a.at(x);
        }
    }

    cout << sum << endl;
}


Measured memory_bytes: 7296
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <numeric>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <memory>
#include <thread>
#include <tuple>

using namespace std;

int n;
vector<pair<int, int>> dat;
vector<pair<int, int>> low, high;
bool check(int cnt) {
  if (cnt - 1 >= n - cnt) return false;
  for (int i = 0; i < cnt; i++) {
    int j = n - cnt + i;
  }
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    dat.emplace_back(l ,r);

    low.emplace_back(r, i);
    high.emplace_back(l, i);
  }
  vector<bool> visit(n);
  sort(low.begin(), low.end());
  sort(high.begin(), high.end(), greater<pair<int,int>>());

  long long ans = 0;
  long long best = 0;
  int s = 0, e = 0;
  int li = 0, hi = 0;
  int cnt1 = 0, cnt2 = 0;
  for (;;) {
    while (li < n && visit[low[li].second]) {
      li++;
    }
    while (hi < n && visit[high[hi].second]) {
      hi++;
    }
    if (li == n && hi == n) break;
    bool uselow;
    if (li == n || cnt2 < cnt1) {
      uselow = false;
    }
    else if (hi == n || cnt1 < cnt2) {
      uselow = true;
    }
    else if (-low[li].first < high[hi].first) {
      uselow = false;
    }
    else {
      uselow = true;
    }
    if (uselow) {
      if (li == n) break;
      visit[low[li].second] = true;
      ans += 2 * (-low[li].first);
      li++;
      cnt1++;
    }
    else {
      if (hi == n) break;
      visit[high[hi].second] = true;
      ans += 2 * (high[hi].first);
      hi++;
      cnt2++;
    }
    best = max(ans, best);
  }
  printf("%lld\n", best);
  return 0;
}


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

#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)

string s;
int q, t, f;
char C;
bool ch;
vector <char> F, T;

int32_t main() {
	cin >> s >> q;
	while(q--) {
		cin >> t;
		if(t == 1) {ch = !ch; continue;}
		cin >> f >> C;
		if(f == 1) {
			if(ch) T.push_back(C);
			else F.push_back(C);
		}
		if(f == 2) {
			if(ch) F.push_back(C);
			else T.push_back(C);
		}
	}
	if(ch) reverse(s.begin(), s.end());
	
	if(ch) swap(F, T);
	reverse(F.begin(), F.end());
	for (auto x : F) cout << x;
	cout << s;
	for (auto x : T) cout << x;
	return 0;
}

Measured memory_bytes: 1024