akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

int getSecond(vector<pair<int,int>> vec, int def)
{
    if(vec.size() <= 1)
    {
        return def;
    }
    return vec[1].first;
}

int main()
{
    int n;
    cin >> n;
    map<int,int> odd;
    map<int,int> even;
    for(int i = 0; i < n; ++i)
    {
        int t;
        cin >> t;
        if(i%2==0)
        {
            even[t] += 1;
        }
        else
        {
            odd[t] += 1;
        }
    }

    vector<pair<int,int>> oddPair;
    for(pair<int,int> p: odd)
    {
        oddPair.push_back(make_pair(p.second,p.first));
    }
    sort(oddPair.begin(), oddPair.end(), greater<pair<int,int>>());
    vector<pair<int,int>> evenPair;
    for(pair<int,int> p: even)
    {
        evenPair.push_back(make_pair(p.second,p.first));
    }
    sort(evenPair.begin(), evenPair.end(), greater<pair<int,int>>());

    int oddCnt = n/2;
    int evenCnt = n/2;
    if(oddPair[0].second != evenPair[0].second)
    {
        oddCnt = oddPair[0].first;
        evenCnt = evenPair[0].first;
    }
    else
    {
        int oddT = getSecond(oddPair, 0);
        int evenT = getSecond(evenPair, 0);
        if(oddT < evenT)
        {
            oddCnt = oddPair[0].first;
            evenCnt = evenT;
        }
        else
        {
            oddCnt = oddT;
            evenCnt = evenPair[0].first;
        }
        
    }
    cout << n - oddCnt - evenCnt << endl;
}

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

int main() {
    int h, w;cin >> h >> w;
    vector<string> s(h);

    rep(i, h) {
        cin >> s.at(i);
    }

    bool ans = true;
    rep(i, h) {
        rep(j, w) {
            if (s.at(i).at(j) == '.') continue;
            // 左チェック
            if (j > 0) {
                if (s.at(i).at(j-1) == '#') continue;
            }
            // 右チェック
            if (j < w-1) {
                if (s.at(i).at(j+1) == '#') continue;
            }
            // 上チェック
            if (i > 0) {
                if (s.at(i-1).at(j) == '#') continue;
            }
            // 下チェック
            if (i < h-1) {
                if (s.at(i+1).at(j) == '#') continue;
            }
            ans = false;
        }
    }

    if (ans)
        puts("Yes");
    else
        puts("No");
    return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
double EPS=1e-8;
int main(){
	int a[5010],b[5010];
	int n,m;
	cin>>n>>m;
	REP(i,n)cin>>a[i];
	REP(i,m)cin>>b[i];
	int ans=0;
	REP(i,m){
		int k=i,cnt=0;
		for(int j=0;j<n&&k<m;j++){
			if(a[j]==b[k]){
				cnt++;
				k++;
			}
		}
		ans=max(ans,cnt);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1200
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

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

int main(){
	int n;
	int d[120];
	while(cin>>n,n){
		memset(d, 0, sizeof(d));
		rep(i, n){
			cin>>d[i];
		}
		int x;
		cin>>x;
		int left,right,cnt;
		left =0;
		right =n-1;
		cnt = 0;
		while(right-left>=0){
			int pos =(right+left)/2;
			//cout <<"pos = "<<pos<<endl;
			if(d[pos]<x){
				cnt++;
				left =pos+1;
			}else if(d[pos]>x){
				cnt++;
				right =pos-1;
			}else{
				cnt++;
				break;
			}
		}
		cout <<cnt<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>

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





Measured memory_bytes: 2716
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <bitset>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define sys system("pause")
const int maxn=1e5+10;
using namespace std;
inline ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
inline ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
inline void umax(ll &p,ll q){if(p<q)p=q;}
inline void umin(ll &p,ll q){if(p>q)p=q;}
inline ll read()
{
    ll x=0;int 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;
}
int n,m,k,t,a[maxn],cnt;
int main()
{
    int i,j;
    scanf("%d",&n);
    rep(i,1,n)scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    rep(i,1,n)
    {
        if(a[i]==a[i-1])
        {
            cnt++;
        }
    }
    if(cnt==1)printf("%d\n",n-2);
    else if(cnt==2)
    {
        printf("%d\n",n-2);
    }
    else
    {
        if(cnt&1)printf("%d\n",n-cnt-1);
        else
        {
            printf("%d\n",n-cnt);
        }
    }
    return 0;
}


Measured memory_bytes: 768
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main (){

	int  b1, b2, b3;

	cin >> b1 >> b2 >> b3;


	if(b1 == 1 && b2 == 1){
		cout << "Open" << endl;
	}
	else if(b3 == 1){
		cout << "Open" << endl;
	}
	else {
		cout << "Close" << endl;
	}

	return 0;
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef double D;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
 
#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d %d",&x,&y)
#define rl(x) scanf("%lld",&x)
#define rl2(x,y) scanf("%lld %lld",&x,&y)
#define wd(x) printf("%d" ,x)
#define wd2(x,y) printf("%d %d",x,y)
#define wl(x) printf("%lld",x)
#define wl2(x,y) printf("%lld %lld",x,y)
#define PC(x) putchar(x)
#define GC() getchar()
#define NL printf("\n")
#define SP printf(" ")
 
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define F first
#define S second
#define MP make_pair
#define PB push_back

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define fr(i,s,e) for(int i=s;i<e;i++)
#define frl(i,s,e) for(ll i=s;i<e;i++)
#define frr(i,s,e) for(int i=s-1;i>=e;i--)
#define frv(i,a) for(int i = 0;i<(int)a.size();i++)
#define frvr(i,a) for(int i = a.size()-1;i>=0;i--)
#define tr(i,a) for(typeof(a.begin()) i = a.begin(); i != a.end();i++)

#define mod 1000000007
#define maxn 100009
#define maxr 100009
int main(){
	//sstd::ios::sync_with_stdio(false); cin.tie(NULL);
	ll a,b;
	rl2(a,b);
	ll ans=a-2*b;
	if(ans<0)
		ans=0;
	wl(ans);
	NL;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int mofu(int a, int b, int c) {
	return a < b && b < c && c > b - a && c < a + b;
}

int nyan(int a, int b, int c) {
	return mofu(a, b, c) || mofu(a, c, b) || mofu(b, a, c) || mofu(b, c, a) ||
		mofu(c, a, b) || mofu(c, b, a);
}

int main(void) {
	int N;
	int L[128];
	int i, j, k;
	int sumipe = 0;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%d", &L[i]) != 1) return 1;
	}

	for (i = 0; i < N; i++) {
		for (j = i + 1; j < N; j++) {
			for (k = j + 1; k < N; k++) {
				if (nyan(L[i], L[j], L[k])) sumipe++;
			}
		}
	}

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


Measured memory_bytes: 1736
//Problem link: https://atcoder.jp/contests/dp/tasks/dp_a

#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define INF 0x3f3f3f3f
#define mod 1000000007

int main()
{
	fast;
	ll n;
	cin>>n;
	ll arr[n+5];
	for(ll i=0;i<n;i++)
		cin>>arr[i];
	ll dp[n+5];
	dp[n-1]=0;
	dp[n-2]=abs(arr[n-2]-arr[n-1]);
	for(ll i=n-2;i>=0;i--)
		dp[i]=min(abs(arr[i]-arr[i+1])+dp[i+1],abs(arr[i]-arr[i+2])+dp[i+2]);
	cout<<dp[0];
	return 0;
}

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

using namespace std;

int main() {
  string s;
  cin >> s;
  int n = (int)s.length();
  int m1[n + 1], m2[n + 1];
  m1[0] = 0;
  m2[0] = 0;
  m1[1] = 1;
  m2[1] = -1;
  for (int i = 2; i <= n; ++i) {
    m1[i] = -1;
    if (m2[i - 1] != -1) {
      m1[i] = max(m1[i], m2[i - 1] + 1);
    }
    if (m1[i - 1] != -1 && s[i - 1] != s[i - 2]) {
      m1[i] = max(m1[i], m1[i - 1] + 1);
    }
    m2[i] = -1;
    if (m1[i - 2] != -1) {
      m2[i] = max(m2[i], m1[i - 2] + 1);
    }
    if (m2[i - 2] != -1 &&
        ((i - 2 < 2) ||
         (s[i - 1] != s[i - 3]) ||
         (s[i - 2] != s[i - 4]))) {
      m2[i] = max(m2[i], m2[i - 2] + 1);
    }
  }
  cout << max(m1[n], m2[n]) << endl;
  return 0;
}


Measured memory_bytes: 2180
#include<iostream>
using namespace std;
int calc(int m,int n,int p,int q){
  if( (m==1 && n==0) || (m==0 && n==1) || (m==-1 && n==0) ||
      (m==0 && n==-1) || (m==p && n==q) || (m==-q && n==p) ||
      (m==-p && n==-q) || (m==q && n==-p) || (m==0 && n==0)){
    return 0;
  }
    if( (m*p+n*q) %(m*m+n*n)==0){
      if( (-p*n+m*q)%(m*m+n*n)==0){
	//cout << "baka" << endl;
	//cout << "m " << m<<"n "<<n<< endl;
	return 1;//割り切れる
      }
    }
  //cout << "p " << m<<"q "<<n<< endl;
  return 0;//割り切れない
}

int main(){
  int a,m,n;
  bool flag=0;
  cin>>a;
  for(int i=0;i<a;i++){
    cin>>m>>n;
    flag=0;
    for(int j=-500;j<500;j++){
      for(int k=-500;k<500;k++){
	if(calc(j,k,m,n) == 1){
	  flag=1;
	  break;
	}
      }
      if(flag==1) break;
    }
    if(flag==1){
      cout<<"C"<<endl;
    }else{
      cout<<"P"<<endl;
    }
  }
  return 0;
}

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

namespace ConsoleApp6
{
    class Program
    {
        static void Main(string[] args)
        {
            var sa = Console.ReadLine();
            var ta = Console.ReadLine();

            if (sa == ta)
            {
                Console.WriteLine("Yes");
                return;
            }

            for (int i = 1; i < sa.Length; i++)
            {
                Change(ref sa);
                if (sa == ta)
                {
                    Console.WriteLine("Yes");
                    return;
                }


            }

            Console.WriteLine("No");

        }

        static void Change(ref string s) {

            StringBuilder word = new StringBuilder();
            word.Append(s.Substring(s.Length - 1, 1));
            word.Append(s.Substring(0,s.Length - 1));

            s = word.ToString();
        }
       
    }
}


Measured memory_bytes: 13140
#include <stdio.h>

int main(void)
{
    int s;
    int n = 0;
    scanf("%d", &s);
    if (s / 100000)
        n++;
    if (s % 100000 / 10000)
        n++;
    if (s % 10000 / 1000)
        n++;
    if (s % 1000 / 100)
        n++;
    if (s % 100 / 10)
        n++;
    if (s % 10)
        n++;
    printf("%d\n", n);

    return 0;
}

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

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


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

using namespace std;

int main(){
    int k;
    cin>>k;
    if (k%2==0||k%10==5){
        cout<<-1;
        return 0;
    }
    int ans=1, r=7%k;
    while (r!=0){
        ans++;
        r=(r*10+7)%k;
    }
    cout<<ans<<endl;
}


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

int main() {
	int N, ans = 0;
	cin >> N;
	vector<int> A(N), B(N), C(N);
	for (int i = 0;i < N;i++) {
		cin >> A[i];
		A[i]--;
	}
	for (int i = 0;i < N;i++) {
		cin >> B[i];
	}
	for (int i = 0;i < N - 1;i++) {
		cin >> C[i];
	}
	ans += B[A[0]];
	for (int i = 1;i < N;i++) {
		ans += B[A[i]];
		if (A[i] == A[i - 1] + 1) {
			ans += C[A[i - 1]];
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
/*
 AtCoder XXX 000
 */
 
#include <stdio.h>

int main(void){
  char a,b,c;
  char out[4];
  
  scanf("%c%c%c\n",&a,&b,&c);
  out[0]=a;
  scanf("%c%c%c\n",&a,&b,&c);
  out[1]=b;
  scanf("%c%c%c\n",&a,&b,&c);
  out[2]=c;
  
  printf("%c%c%c",out[0],out[1],out[2]);
  return 0;
}

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

main() {
    int D; cin >> D;
    if(D==25) cout << "Christmas" << endl;
    else if(D==24) cout << "Christmas Eve" << endl;
    else if(D==23) cout << "Christmas Eve Eve" << endl;
    else cout << "Christmas Eve Eve Eve" << endl;

    return 0;
}

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

using namespace std;

string convert(const string &s) {
  string s2 = "";
  for (size_t i = 0; i < s.length(); ++i) {
    if ('A' <= s[i] and s[i] <= 'Z') {
      s2 += s[i];
    } else if ('a' <= s[i] and s[i] <= 'z') {
      s2 += s[i] - 'a' + 'A';
    }
  }
  return s2;
}

int main() {
  string s;
  while (getline(cin, s)) {
    bool is_first = true;
    set<string> palindromes, devils;
    s = convert(s);
    for (int i = 0; i < int(s.length()); ++i) {
      for (int d = 0; d < 2; ++d) {
        for (int w = 0; true; ++w) {
          if (i - w < 0 or int(s.length()) <= i + d + w or s[i - w] != s[i + d + w]) {
            if (w > 1) {
              palindromes.insert(s.substr(i - w + 1, 2 * w - 1 + d));
            }
            break;
          }
          if (w > 1) {
              devils.insert(s.substr(i - w + 1, 2 * w - 1 + d));
          }
        }
      }
    }
    for (set<string>::iterator it = devils.begin(); it != devils.end(); ++it) {
      palindromes.erase(*it);
    }
    for (set<string>::iterator it = palindromes.begin(); it != palindromes.end(); ++it) {
      if (is_first) {
        cout << *it;
        is_first = false;
      } else {
        cout << " " << *it;
      }
    }
    cout << endl;
  }
}

Measured memory_bytes: 1220
from collections import Counter
from functools import reduce
import fractions
import math
import statistics
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]  # LIST INT
def LF(): return [float(x) for x in sys.stdin.readline().split()]  # LIST FLOAT
def LS(): return sys.stdin.readline().split()  # LIST STRING
def MI(): return map(int, sys.stdin.readline().split())  # MAP INT
def II(): return int(sys.stdin.readline())  # INPUT INT
def IS(): return input()  # INPUT STRING
def P(x): return print(x)
def C(x): return Counter(x)
def GCD_LIST(numbers):  # greatest common divisor
    return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers):  # least common multiple
    return reduce(LCM, numbers)
def LCM(m, n):
    return (m * n // fractions.gcd(m, n))


s = IS()
K = II()
substring = []
for i in range(1,K+1):
    for j in range(len(s) - i + 1):
        substring.append(s[j:j+i])
print(sorted(set(substring))[K-1])


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

using namespace std;
using namespace std::chrono;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi; 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)    
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define print(x) cout << x << "\n";
#define REP(i,a,b) for(i=a;i<=b;i++)
#define RAP(i,a,b) for(i=a;i>=b;i--)
#define spa <<" "<<
#define all(x) (x).begin(), (x).end()
ll mod=1000000007;
const int MX=0x3f3f3f3f;

int main(){
    IOS;
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    if(k<=a){
        cout<<k;
    }else if(k<=a+b) cout<<a;
    else cout<<a-k+a+b;
	return 0;
} 

Measured memory_bytes: 3636
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
 
template<class T> inline bool chmax(T &a, T b){
    if(a<b){
        a = b;
        return true;
    }
    return false;
}

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

int main(){
    int k,n;
    cin >> k >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    a.push_back(a[0]+k);
    int mx = 0;
    rep(i,n){
        chmax(mx,a[i+1]-a[i]);
    }
    cout << k-mx << endl;
    return 0;
}

Measured memory_bytes: 2424
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define Time (double)clock()/CLOCKS_PER_SEC
const int N = 1e5 + 7;
vector <int> g[N];
int n, a[N];
int dfs(int u, int p) {
    int sum = 0, mx = 0;
    bool lief = 1;
    for (int v : g[u]) {
        if (v != p) {
            lief = 0;
            int x = dfs(v, u);
            sum += x;
            mx = max(mx, x);
        }   
    }   
    if (lief) return a[u];
    if (sum < a[u]) {
        cout << "NO\n";
        exit(0);
    }   
    int wp = sum - a[u];
    int maxp;
    if (mx * 2 <= sum) maxp = sum >> 1;
    else maxp = sum - mx;
    if (wp > maxp) {
        cout << "NO\n";
        exit(0);
    }   
    return sum - wp * 2;
}   
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    for (int i = 0; i < n - 1; ++i) {
        int u, v; cin >> u >> v;
        g[u].app(v); g[v].app(u);
    }   
    if (n == 2) {
        if (a[1] == a[2]) cout << "YES\n";
        else cout << "NO\n";
        exit(0);
    }   
    int r = -1;
    for (int i = 1; i <= n; ++i) {
        if (g[i].size() > 1) {
            r = i;
        }   
    }   
    if (!dfs(r, r)) cout << "YES\n";
    else cout << "NO\n";
}       

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

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

#define loop(i, n) for(int i = 0;i < n;i++)

int main(void){

    string a, b;
    cin >> a >> b;

    b.pop_back();

    if(a == b) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>

using namespace std;
int main(){
    int n,k;
    cin >> n >> k;
    string s;
    cin >> s;
    int c_RL=0;
    int c_LR=0;
    int sin_c=0;
    for(int i=0;i<s.size()-1;i++){
        if(s[i]=='R'&&s[i+1]=='L'){
            c_RL++;
        }
        if(s[i]=='L'&&s[i+1]=='R'){
            c_LR++;
        }
        if(s[i]==s[i+1]){
            sin_c++;
        }
    }
 //   cout<<sin_c<<endl;
    if(s[0]=='L'){
        c_RL++;
    }else{
        c_LR++;
    }
    if(s[0]=='R'){
        c_RL++;
    }else{
        c_LR++;
    }
    int c_change=min(c_RL,c_LR);
   // cout<<c_change<<endl;
    c_change=min(c_change,k);
    cout<<min(sin_c+2*c_change,n-1)<<endl;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int main(void){
	int x;
	cin >> x;

	int sum=0,ans=0;
	while(sum+ans<x){
		sum+=ans;
		ans++;
	}

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

Measured memory_bytes: 256
#include <stdio.h>
int n, t, e, r, x;
int main() {
	scanf("%d%d%d", &n, &t, &e); r = -1;
	for(int i = 0; i < n; i++) {
		scanf("%d", &x);
		if(t-e<=(t+e)/x*x)r=i+1;
	}
	printf("%d\n", r);
}

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

int h,w,k;
int mp[12][1005]={0};
int a[12]={0};

ll ans=1e9+7;

void check(int t){
    a[t+1]=h;
    ll cnt=t;
    ll last=0;
    bool flag;
    for(int j=1;j<=w;j++){
        flag=true;
        for(int i=1;i<=t+1;i++){
            if(mp[a[i]][j]-mp[a[i]][last]-mp[a[i-1]][j]+mp[a[i-1]][last]>k){
                flag=false;
                break;
            }
        }
        if(!flag){
            if(j-last<=1){
                return ;
            }
            last=j-1;
            cnt++;
        }
    }
    ans=min(ans,cnt);
}

void dfs(int now,int t){
    if(now==h){
        check(t);
        return ;
    }
    a[t+1]=now;
    dfs(now+1,t+1);
    dfs(now+1,t);
}

int main(){
    cin>>h>>w>>k;
    for(int i=1;i<=h;++i){
        for(int j=1;j<=w;++j){
            scanf("%1d",&mp[i][j]);
            mp[i][j]+=mp[i-1][j]+mp[i][j-1]-mp[i-1][j-1];
        }
    }
    dfs(1,0);
    cout<<ans<<endl;
    //Persist for love.
}


Measured memory_bytes: 256
import java.util.*;
class Main {
    public static void main (String[] args) throws java.lang.Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a[] = new int[n];
        for(int i = 0; i < n; i++) a[i] = sc.nextInt();
        for(int i = 0; i < n; i++) {
            if(i != 0) System.out.print(" ");
            System.out.print(a[n - i - 1]);
        }
        System.out.println();
    }
}


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

using namespace std;

int main()
{
	for(int i=1;i<=9;i++){
		for(int j=1;j<=9;j++){
			printf("%dx%d=%d\n",i,j,i*j);
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vt = vector<T>;
template<class T> using vvt = vector<vt<T>>;
template<class T> using ttt = tuple<T,T>;
using tii = tuple<int,int>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define DIV int(1e9+7)
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
//const double PI = M_PI;  
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}
/* Coding space */
int main(){
  int n; cin >> n;
  cout << n/3 << endl;
}

Measured memory_bytes: 256
ans = [int(input())]
while True:
    try:
        inp = list(map(int, input().split(",")))
        l = len(inp)
        if l > len(ans):
            tmp = [-float("inf")] + ans + [-float("inf")]
        else:
            tmp = ans
        ans = []
        for i in range(l):
            ans.append(max([tmp[i] + inp[i], tmp[i + 1] + inp[i]]))
    except:
        break
print(*ans)



Measured memory_bytes: 5620
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int k,x;
    cin >> k >> x;
    if(k*500>=x){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

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

        Scanner sc = new Scanner(System.in);   
        int N = sc.nextInt();

        if(N / 10 == 9 || N % 10 == 9){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }   
    }
}


Measured memory_bytes: 21844
#include <cstdio>
#include <iostream>
#define LL long long
using namespace std;
inline LL read(){
	LL ret=0,p=1;
	char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') p=-1;
	for (;isdigit(ch);ch=getchar()) ret=ret*10+ch-'0';
	return ret*p;
}
int n;
LL a[200000+3],s[200000+3];
int main(){
	n=read();s[0]=0;
	for (int i=1;i<=n;i++) a[i]=read(),s[i]=s[i-1]+a[i];
	LL ans=1e9;ans*=ans;
	for (int i=1;i<n;i++){
		LL t=s[n]-s[i]-s[i];
		if (t<0) t=-t;
		if (t<ans) ans=t;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3328
program abc162b
      implicit none
      integer::n,i
      integer(8)::sum0

         read *,n

         sum0=0
         do i=1,n
            if (mod(i,3)/=0) then
               if (mod(i,5)/=0) then
                  sum0=sum0+i
               end if
            end if
         end do

         print *,sum0

   end program abc162b

Measured memory_bytes: 2856
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>

using namespace std;
typedef long long ll;
#define i_7 1000000007
#define i_5 1000000005

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
typedef pair<double,double>d_d;
#define inf 100000000//10^8

/////////////////////////////////




int main(){
    int n;
    while(cin>>n,n){
        int a[60*60*24+5];
        memset(a,0,sizeof(a));
        for(int i=0;i<=2*n-1;i++){
            int h,m,s;scanf("%d:%d:%d",&h,&m,&s);
            
            if(i%2==0)a[s+60*m+3600*h]++;
            else a[s+60*m+3600*h]--;
        }
        for(int i=1;i<=60*60*24+1;i++){
            a[i]+=a[i-1];
        }
        int max=0;
        for(int i=0;i<=60*60*24+1;i++){
            if(a[i]>max)max=a[i];
        }
        cout<<max<<endl;
    }
    return 0;
}



Measured memory_bytes: 3464
#include<stdio.h>
#include <math.h>

int main(void){
  int A,B;
  scanf("%d %d",&A,&B);
  int C,D;
  C = fmax(A+B,A-B);
  D = fmax(C,A*B);
  printf("%d",D);
  return 0;
}


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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repp(i, n, m) for(int (i) = (n); (i) < (m); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define ldou long double
#define fi first
#define se second
#define setpre(x) std::cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ std::cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 505;

/* ...o(^-^)o... */

int a[MAX][MAX];

void solve(int i, int j, int m){
    int n = j-i+1;
    if(n <= 1) return;
    int k = n/2, l = n-k;
    repp(v, i, i+k) repp(u, i+k, j+1){
        a[v][u] = m;
        a[u][v] = m;
    }
    solve(i, i+k-1, m+1);
    solve(i+k, j, m+1);
}

int main(){
    int n; cin >> n;
    solve(0, n-1, 1);

    rep(i, n-1) repp(j, i+1, n){
        outs(a[i][j]);
        if(j == n-1) out("");
    }
}

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

using namespace std;

int main(void)
{
  int n;
  int g[111][111];
  int s[111][111] = {};
  int res = -99999999;
  scanf("%d", &n);
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < n; j++) {
      scanf("%d", g[i]+j);
      res = max(res,g[i][j]);
      s[i][j+1] += s[i][j]+g[i][j];
    }
  }
  for(int l = 0; l < n; l++) {
    for(int r = l+1; r <= n; r++) {
      int a,b,sum; a=b=sum=0;
      while( a < n || b < n) {
        if( b == n ) {
          while( a < b ) {
            sum -= s[a][r]-s[a][l]; a++;
            if( a != b ) res = max(res,sum);
          }
        } else {
          sum += s[b][r]-s[b][l]; b++;
          while( sum < 0 && a < b ) {
            sum -= s[a][r]-s[a][l]; a++;
          }
          if( a != b ) res = max(res,sum);
        }
      }
    }
  }
  printf("%d\n",res);
  return 0;
}

Measured memory_bytes: 1132
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] var0) {
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int K = scanner.nextInt();

        int[] p = new int[N];

        for (int i = 0; i < N; i++) {
            p[i] = scanner.nextInt();
        }

        Arrays.sort(p);

        int ans = 0;

        for (int i = 0; i < K; i++) {
            ans += p[i];
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 30252
using System;
using System.Linq;
namespace Myatcoder
{
    public class Program
    {
        public static void Main()
        {

            int[] N = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            int[] A = new int[N[0]];
            int idx = 0;
            for (int i = 0; i < N[0]; i++) {
                A[i] = int.MaxValue;
                int[] tmp = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
                if (N[1] >= tmp[1]) {
                    A[idx] = tmp[0];
                    idx++;
                }
            }

            if (idx > 0) Console.WriteLine(A.Min());
            else Console.WriteLine("TLE");
        }
    }
}

Measured memory_bytes: 11348
#include<bits/stdc++.h>
using namespace std;
long long X[100];
int main()
{
  int N;
  cin>>N;
  for(int i=0;i<N;i++)
    cin>>X[i];
  long long Have=1000;
  long long Stock=0;
  Stock=Have/X[0];
  Have%=X[0];
  for(int i=0;i<N;i++)
  	if(X[i]>X[i+1])
    {
      Have+=Stock*X[i];
      if(i==N-1)
        break;
      Stock=Have/X[i+1];
      Have%=X[i+1];
    }
  cout<<Have<<endl;
  return 0;
}


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

int main()
{
    int n;
    cin >> n;
    int c[30], v[30];
    for(int i = 0; i < n; i++){
        cin >> v[i];
    }
    for(int i = 0; i < n; i++){
        cin >> c[i];
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        if(v[i] >= c[i]){
            ans += v[i] - c[i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
  ll i,n,ans = 0;
  cin>>n;
  string s;
  cin>>s;
  for(i=0;i<n-2;i++)
  {
    if(s.substr(i,3) == "ABC") ans++;
  }
  cout<<ans;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll inf = 1e18;
ll mod = 1e9+7;
ll dp[200010][3];
ll n,a[200010];
int main(){
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j < 3; j++) {
            dp[i][j] = -inf;
        }
    }
    dp[0][0] = a[0];
    dp[1][1] = a[1];
    dp[2][2] = a[2];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (i+k+2 > n) break;
                if (j + k > 2) break;
                dp[i+k+2][j+k] = max(dp[i+k+2][j+k], dp[i][j] + a[i+k+2]);
            }
        }
    }
    if (n & 1) {
        cout << max({dp[n-3][0],dp[n-2][1],dp[n-1][2]});
    } else {
        cout << max(dp[n-2][0], dp[n-1][1]);
    }
    cout << endl;
    // for (int i = 0; i < n; i++) {
    //     for (int j = 0; j < 3; j++) {
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    return 0;
}

Measured memory_bytes: 9884
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

vector<pint> go;

int main() {
	int n;
	while(n=in()){
		go.clear();
		int i,next;
		for(i=0;i<n;i++){
			next=in();
			if(i%2==1&&go[go.size()-1].first!=next){
				if(go.size()==1){
					go[0].first=next;
				}else{
					go[go.size()-2].second+=go[go.size()-1].second;
					go.pop_back();
				}
			}
			if(go.size()==0||go[go.size()-1].first!=next){
				pint buf;
				buf.first=next;
				buf.second=1;
				go.push_back(buf);
			} 
			else go[go.size()-1].second++;
//int j;
//for(j=0;j<go.size();j++)cout<<go[j].first<<" "<<go[j].second<<endl;
//cout<<endl;
		}
		int res=0;
		for(i=0;i<go.size();i++){
			if(go[i].first==0)res+=go[i].second;
		}
		cout<<res<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x) cout << #x << " = " << (x) << endl;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define P pair<int, int>
#define V vector<int>
#define M map<int, int>
#define S set<int>
#define itn int
#define tin int
#define tni int
bool dbg = false;
int N, a[100010];
void solve()
{
    int t = 0;
    FORR(i, 1, N)
    {
        if (a[i] != i)
            t++;
    }
    if (t <= 2) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

signed main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> N;
    FORR(i, 1, N)
    {
        cin >> a[i];
    }
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long int> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long int>> vvl;
typedef pair<int, int> pii;
typedef pair<long long int, long long int> pll;
typedef vector<pair<int, int>> vii;
typedef vector<pair<long long int, long long int>> vll;
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define test() long long int t; cin >> t; cin.ignore(); while(t--) 
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define MOD 1000000007
#define SMOD 998244353
#define pq priority_queue
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sp " "
#define inp(a) ll a;cin>>a;cin.ignore()
#define inps(a,b) ll a,b;cin>>a>>b;cin.ignore()
#define out(a) cout<<SP(20)<<a<<'\n'
#define outs(a,b) cout<<SP(20)<<a<<" "<<b<<'\n'
#define ins insert
#define er erase
#define lb lower_bound
#define ub upper_bound
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define inpa(a,n) ll a[n]; for(int i=0; i<n; i++){cin>>a[i];}
#define inpv(a,n) vl a; for(int i=0; i<n; i++){inp(x);a.pb(x);}
#define outa(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}cout<<'\n';
#define outv(v) for(auto i:v){cout<<i<<" ";}cout<<'\n';
set<char> vow = {'a','e','i','o','u','A','E','I','O','U'};
bool check1;
ld xpow(ld n, ll m){if(m==0){return 1;}else{ld x = xpow(n, m/2);if(m&1){ld res = x*x*n;if(res>1e7){check1=1;};return res;}else{ld res = x*x;if(res>1e7){check1=1;}return res;}}}
ll xmod(ll a, ll m){return (((a%m)+m)%m);}
ll xmodpow(ll n, ll m, ll y){if(m==0){return 1;}else{ll x = xmodpow(n, m/2, y);if(m&1){return xmod((xmod((xmod(x,y)*xmod(x,y)),y)*xmod(n,y)),y);}else{return xmod((xmod(x,y)*xmod(x,y)),y);}}}
 
ll n, t;
vll a;
bool vis[3005][3005];
ll dp[3005][3005];

bool comp(pll x, pll y){
    if(x.ff==y.ff){
        return x.ss > y.ss;
    }
    return x.ff < y.ff;
}

ll solve(ll ind, ll time){
    time = min(3000ll, time);
    if(ind==n){
        return 0;
    }
    if(vis[ind][time]){
        return dp[ind][time];
    }
    vis[ind][time] = 1;
    ll x = 0;
    if(time<t){
        x = a[ind].ss + solve(ind+1, time+a[ind].ff);
    }
    ll y = solve(ind+1, time);
    return dp[ind][time] = max(x, y);
}

int main(){
    fast();
 
/* you get what you work for not what you wish for */
    
    cin >> n >> t;
    a.resize(n);
    for(int i=0; i<n; i++){
        cin >> a[i].ff >> a[i].ss;
    }
    sort(all(a), comp);
    ll ans = solve(0, 0);
    cout << ans << endl;
}

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

int descending_compare(const void *a, const void *b){
    if (*(int*)a > *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}

int ascending_compare(const void *a, const void *b){
    if (*(int*)a < *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}


int lower_bound(int *a, int n, int key){
    int left, mid, right;
    left = 0, right = n;
    mid = (left + right)/2;
    while ((left+1 != mid || mid+1 != right) && mid != left){
        if (key > a[mid]){
            left = mid;
        }else{
            right = mid+1;
        }
        mid = (left + right)/2;
    }
    if (a[left] >= key)return left;
    if (a[mid] >= key)return mid;
    if (a[right] >= key)return right;
    return n;
}

unsigned long  gcd(unsigned long x, unsigned long y)
{
        if (y == 0) {
                return x;
        } else {
                return gcd(y, x % y);
        }
}

long long kaijou(int x){
    long long rtn = 1;
    int i;
    for (i = x; i > 1; i--){
        rtn = (rtn*i);
    }
    return rtn;
}

int main(void){
    char s[15];
    scanf("%s", s);
    s[3] = '8';
    printf("%s", s);
    printf("\n");
    return 0;
}


Measured memory_bytes: 128
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    N = INT()
    S = [INPUT() for _ in range(N)]

    l = []
    for s in S:
        tmp_l = []
        for c in s:
            tmp_l.append(ord(c))
        tmp_l = sorted(tmp_l)

        tmp_s = ""
        for n in tmp_l:
            tmp_s += chr(n)
        l.append(tmp_s)

    C = Counter(l)
    ans = 0
    for c in C.values():
        if c > 1:
            ans += factorial(c) // (factorial(c - 2) * factorial(2))

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 31836
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}

	b := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&b[i])
	}
	c := make([]int, n - 1)
	for i := 0; i < n-1; i++ {
		fmt.Scan(&c[i])
	}

	s := 0
	y := len(a) + 1
	for _, v := range a {
		v = v - 1
		s += b[v]
		if y == v - 1 {
			s += c[y]
		}
		y = v
	}

	fmt.Println(s)
}


Measured memory_bytes: 512
a,b=map(str,input().split())

if(a=="A"):
  c=1
if(a=="B"):
  c=2
if(a=="C"):
  c=3
if(a=="D"):
  c=4
if(a=="E"):
  c=5
if(a=="F"):
  c=6
if(b=="A"):
  d=1
if(b=="B"):
  d=2
if(b=="C"):
  d=3
if(b=="D"):
  d=4
if(b=="E"):
  d=5
if(b=="F"):
  d=6
  
if(c>d):
  print(">")
if(c<d):
  print("<")
if(c==d):
  print("=")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n;
  cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; i++) cin >> a[i];
  int s=0;
   for(int i=0; i<n; i++) s ^= a[i];
 // cout << s << endl;
   for(int i=0; i<n; i++) cout << (s^(a[i])) << " ";
}

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

int main(){
	int N;
	cin >> N;
	int V[N], C[N];
	for(int i = 0; i < N; i++) cin >> V[i];
	for(int i = 0; i < N; i++) cin >> C[i];
	int dif = 0;
	for(int i = 0; i < N; i++)
		if(V[i] - C[i] > 0) dif += (V[i] - C[i]);
	cout << dif << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {        
    
  public static void main(String[] args) {              
     
      Scanner sc = new Scanner(System.in);                                    
    
      int A = sc.nextInt();
      int B = sc.nextInt();      
      
      if(A%3 == 0 || B%3 == 0 || (A+B)%3 == 0){
          System.out.println("Possible");
          return;
      }else{
          System.out.println("Impossible");
          return;
      }
      
     
  }     
}


Measured memory_bytes: 22996
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int H, W;
int N;
int a[100010];
int c[110][110];

bool valid(int x, int y) {
  return (0 <= x && x < H && 0 <= y && y < W && c[x][y] == -1);
}

int main () {
  cin >> H >> W;
  cin >> N;
  for (auto i = 0; i < N; ++i) {
    cin >> a[i];
  }
  int d = 0;
  int color = 0;
  int x = 0, y = 0;
  fill(&c[0][0], &c[0][0]+110*110, -1);
  while (color < N) {
    // cerr << x << " " << y << " " << d << endl;
    /*
    for (auto i = 0; i < H; ++i) {
      for (auto j = 0; j < W; ++j) {
        cerr << c[i][j];
        if (j < W-1) {
          cerr << " ";
        } else {
          cerr << endl;
        }
      }
    }
    */
    if (valid(x, y)) {
      c[x][y] = color + 1;
      a[color]--;
      if (a[color] == 0) color++;
    } else if (valid(x + dx[d], y + dy[d])) {
      x += dx[d];
      y += dy[d];
    } else {
      d++;
      d %= 4;
    }
  }
  for (auto i = 0; i < H; ++i) {
    for (auto j = 0; j < W; ++j) {
      cout << c[i][j];
      if (j < W-1) {
        cout << " ";
      } else {
        cout << endl;
      }
    }
  }
}


Measured memory_bytes: 384
#include<stdio.h>
int main()
{
    int p,q,r;
    scanf("%d%d%d",&p,&q,&r);
    
    if ((p+q)<=(p+r))
    {
        
        if((p+q)<=(q+r))
        {
            printf("%d",(p+q));
        }
        else
            printf("%d",(q+r));
    }
    else
    {
        if((p+r)<=(q+r))
            printf("%d",(p+r));
        else
            printf("%d",(q+r));
        
    }
    
    return 0;
}

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

using namespace std;

long long abs(long long a, long long b) {
  if (a > b) return a - b;
  if (a < b) return b - a;
}

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

  n = n % k;

  if (n > abs(n, k)) n = abs(n, k);

  cout << n;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <map>
#include <set>
#include <utility>
#include <queue>
#include <bitset>
#include <math.h>

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin>>n;
    int res=0;
    rep(i,n){
        bool flag=true;
        int a; cin>>a;
        if(a<2)flag=false;
        else if(a==2)flag=true;
        else if(a%2==0)flag=false;
        double sqrta = sqrt(a);
        for(int i=3;i<=sqrta;i+=2){
            if(a%i==0){
                flag=false;
                break;
            }
        }
        if(flag)res++;
    }
    cout<<res<<endl;
}


Measured memory_bytes: 3216