akhauriyash/Code-Regression huggingface dataset:
#define __mode_debug__
/*   ξ
     ll
   ＿ll＿
 ／  ∞  ＼
│*  Ａ  *│
│*  Ｃ  *│
│*  祈  *│
│*  願  *│
│*      *│
 ￣￣￣￣￣    */
//C++14 (GCC 5.4.1)
#include <bits/stdc++.h>
using namespace std;
#ifdef __mode_debug__
    #define DBG
#else
    #define DBG if(false)
#endif

#define LLINF (1LL<<60)
using ll = long long;
#define mod  1000000007

#define whole(a) (a).begin(),(a).end()
#define rwhole(a) (a).rbegin(),(a).rend()

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define rrepd(i,a,b) for(int i=(a);i>=(b);i--)
#define each(itr,ds) for(auto itr=(ds).begin();itr!=(ds).end();itr++)

template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); }

//DUMP
//  ostream vector<T> , vector<vector<T>> , set<T> ,queue<T> , priority_queue<T> , pair<T,U> , map<T,U>
template<class T> ostream& operator<<(ostream&os,vector<T>&vec){os<<"{ ";rep(i,vec.size()) os<<((i==0)?"":", ")<<i<<":"<<vec[i];os<<" }";return os;}
template<class T> ostream& operator<<(ostream&os,vector<vector<T>>&vec){os<<"{"<<endl;rep(i,vec.size())os<<"\t   "<<i<<":"<<vec[i]<<((i==vec.size()-1)? "":",")<<endl;os<<"\t }";return os;}
template<class T> ostream& operator<<(ostream&os,set<T>&p){os<<"{ ";each(itr,p)  os<<((itr==p.begin())?"":", ")<<*itr;os<<" }";return os;}
template<class T> ostream& operator<<(ostream&os,queue<T>&p){queue<T> q(p);os<<"[< "<<(q.empty()?" <]":"");while(!q.empty()){os<<q.front();q.pop();os<< (q.empty() ? " <]" : ", ");}return os;}
template<class T> ostream& operator<<(ostream&os,priority_queue<T>&p){priority_queue<T> q(p);os<<"[< "<<(q.empty()?" <]":"");while(!q.empty()){os<<q.top();q.pop();os<< (q.empty() ? " <]" : ", ");}return os;}
template<class T,class U> ostream& operator<<(ostream&os,pair<T,U>&p){os<<"("<<p.first<<","<<p.second<<")";return os;}
template<class T,class U> ostream& operator<<(ostream&os,map<T,U>&p){os<<"{ ";each(itr,p)os<<((itr==p.begin())?"":", ")<<itr->first<<":"<<itr->second;os<<" }";return os;}
void dump_f(string &nm,char t){cerr<<endl;}
template<class T,class... Ts> void dump_f(string &nm,char t,T &&x,Ts&&... ts){int l=nm.find_first_of(',');string name(nm,0,l),nx(nm,l+1,-1);if(t=='\n') cerr<<"  "<<name<<"\t: "<<x<<t;else cerr << name<<": "<<x<<","<<t;dump_f(nx,t,forward<Ts>(ts)...);}
template<class... Ts> void dump_m(int &&ln,string &&nm,char t,Ts&&... ts){cerr<<"[ln: "<<ln<<"]"<<t;dump_f(nm,t,forward<Ts>(ts)...);}
#define dump(...) DBG dump_m(__LINE__,#__VA_ARGS__,'\n',__VA_ARGS__)
#define dl(...) DBG dump_m(__LINE__,#__VA_ARGS__,'\t',__VA_ARGS__)

#define lower_bound_idx(V,c) distance(V.begin(),lower_bound(whole(V),c))

int main() {


    ll a,b,c;

    cin >>a >>b>>c;
    cout << ((c-b-a>=0 && 4*a*b <(c-b-a)*(c-b-a)) ? "Yes" : "No") <<endl;


    return (0);
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#include <limits.h>

int main(void){
    char s[12],uppercasecmp[27]="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    scanf("%s",s);
    if (s[0]!='A'){
        printf("WA\n");
        return 0 ;
    }
    for (int i=0; i<27; i++){
        if (s[1]==uppercasecmp[i]){
            printf("WA\n");
            return 0;
        }
    }
    int count=0;
    for (int i=2; i<strlen(s)-1; i++){
        for (int j=0; j<27; j++){
            if (s[i]==uppercasecmp[j]){
                if (j==2){
                    count++;
                } else {
                    printf("WA\n");
                    return 0 ;
                }
            }
        }
    }
    if (count!=1){
        printf("WA\n");
        return 0 ;
    }
    for (int i=0; i<27; i++){
        if (s[strlen(s)-1]==uppercasecmp[i]){
            printf("WA\n");
            return 0;
        }
    }
    printf("AC\n");
	return 0 ;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
long long INF = 1LL << 60;


int main() {
  long long n,m,k,sum=0,a=0,b=0,ans=0;
  cin >> n >> m;
  if (n <= m){
  cout << "unsafe" << endl;
  } else {
    cout << "safe" << endl;
  }
}

Measured memory_bytes: 3636
#include<stdio.h>
int main(void){
 	int a;
  	scanf("%d",&a);
  	a%=10;
  	if(a==3){
    	printf("bon");
    }
  	else if(a==0 || a==1 || a==6 || a==8){
     	printf("pon"); 
    }
  	else{
     	printf("hon") ;
    }
  return 0;
}

Measured memory_bytes: 1704
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
vector<ll> V;
int pre[maxn];
int main() {
    int n;cin>>n;ll sum=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            for(int k=1;k<=n;k++){
                sum+=__gcd(i,__gcd(j,k));
            }
        }
    }cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 3624
import java.sql.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

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

		Scanner scan = new Scanner(System.in);
		int[] list = new int[3];
		for (int i = 0; i < 3; i++) {
			list[i] = scan.nextInt();
		}
		int k = scan.nextInt();
		Arrays.sort(list);
		
		int ans = (int) (Math.pow(2, k) * list[2]) + list[0] + list[1];
		System.out.println(ans);
		
	}
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n, m, c;
    cin >> n >> m >> c;
    vi b(m);
    rep(i, m) cin >> b[i];
    int ans = 0;
    rep(i, n) {
        vi ai(m);
        rep(i, m) cin >> ai[i];
        int sum = 0;
        rep(j, m) sum += ai[j] * b[j];
        sum += c;
        if (sum > 0) ++ans;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
// unolight {{{
#include <bits/stdc++.h>
#include <unistd.h>
#define SZ(x) ((int)(x).size())
#define ALL(c) begin(c),end(c)
#define REP(i,n) for ( int i=0; i<(int)(n); i++ )
#define REP1(i,a,b) for ( int i=(int)(a); i<=(int)(b); i++ )
#define FOR(it,c) for ( auto it=(c).begin(); it!=(c).end(); it++ )
#define MP make_pair
#define PB push_back
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef long long LL;

void RI() {}

template<typename... T>
void RI( int& head, T&... tail ) {
    scanf("%d",&head);
    RI(tail...);
}

template<typename T>
void _dump( const char* s, T&& head ) { cerr<<s<<"="<<head<<endl; }

template<typename T, typename... Args>
void _dump( const char* s, T&& head, Args&&... tail ) {
    int c=0;
    while ( *s!=',' || c!=0 ) {
        if ( *s=='(' || *s=='[' || *s=='{' ) c++;
        if ( *s==')' || *s==']' || *s=='}' ) c--;
        cerr<<*s++;
    }
    cerr<<"="<<head<<", ";
    _dump(s+1,tail...);
}

#define dump(...) _dump(#__VA_ARGS__, __VA_ARGS__);

template<typename A, typename B>
ostream& operator <<( ostream &s, const pair<A,B> &p ) { return s<<"("<<p.first<<","<<p.second<<")"; }

template<typename Iter>
ostream& _out( ostream &s, Iter b, Iter e ) {
    s<<"[";
    for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
    s<<"]";
    return s;
}
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) { return _out(s,ALL(c)); }
template<typename T>
ostream& operator <<( ostream &s, const set<T> &c ) { return _out(s,ALL(c)); }
template<typename A, typename B>
ostream& operator <<( ostream &s, const map<A,B> &c ) { return _out(s,ALL(c)); }
// }}}

const int MAX_N = 200005;
int n, a, b, c, d;
char A[MAX_N];
bool dp[MAX_N] = {};

void input() {
    RI(n, a, b, c, d);
    a--; b--; c--; d--;
    scanf("%s", A);
}

bool canMove() {
    for(int i=a; i<max(c,d); i++) {
        if(A[i]=='#' && A[i+1]=='#') return false;
    }
    return true;
}

bool goodPosition() {
    for(int i=b; i<=d; i++) {
        if(A[i] == '.' && A[i] == A[i-1] && A[i+1] == A[i])
            return true;
    }
    return false;
}

bool solve() {
    if(!canMove()) return false;
    if(c < d || goodPosition()) {
        return true;
    }

    return false;
}

int main( int argc, char *argv[] ) {
    input();
    if(solve()){
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<map>
using namespace std;
int main() {
    int n;
    cin >> n;
    vector<int> ryo(n);
    vector<int> manb(n);
    vector<int> manc(n-1);
    for(int i=0;i<n;i++){
        cin >> ryo[i];
    }
    for(int i=0;i<n;i++){
        cin >> manb[i];
    }
    for(int i=0;i<n-1;i++){
        cin >> manc[i];
    }
    int ans = 0;
    for(int i=0;i<n;i++){
        ans += manb[ryo[i] - 1];
        if(ryo[i+1] - ryo[i] == 1){
            ans += manc[ryo[i]-1];
            // cout << manc[ryo[i]-1] << endl;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
/**
 *  author: mahfuzz
 *  created: 18.11.2019
**/
 
#include <iostream>
#include <string>
using namespace std;
#define debug(x) cout << '>' << #x << ':' << x << endl;
typedef long long ll;
 
 
int main(int argc, char* argv[]){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    
    string s, t;
    cin >> s >> t;
    
    int cnt = 0;
    for(int i = 0; i < 3; i++){
        if(s[i] == t[i])
            cnt++;
    }
    
    printf("%d\n", cnt);
    
    return 0;
}

Measured memory_bytes: 256
import numpy as np

N = int(input())
H_list = list(map(int,input().split()))[::-1]

cnt = 0
for i in range(N):
  temp_H_list = H_list[i:]
#  print(temp_H_list)
  if np.argmax(temp_H_list)==0:
    cnt+=1
    
print(cnt)

Measured memory_bytes: 12508
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = Long.parseLong(sc.next());
        long A = Long.parseLong(sc.next());
        long B = Long.parseLong(sc.next());
        long result = ((N / (A + B)) * A) + Math.min(N % (A + B), A);

        System.out.println(result);
    }
}

Measured memory_bytes: 22740
package main

import "fmt"

func main() {
	var n, y int
	fmt.Scan(&n, &y)

	m, g, s := -1, -1, -1

	for i := 0; i <= n; i++ {
		for j := 0; i+j <= n; j++ {
			if 10000*i+5000*j+1000*(n-i-j) == y {
				m = i
				g = j
				s = n - i - j
			}
		}
	}

	fmt.Println(m, g, s)
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

set<int> st[100000];
bool used[100000];
int idx[100000];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int N, M, Q;
    cin >> N >> M >> Q;
    int a[100000];
    for(int i = 0; i < Q; i++){
        cin >> a[i];
        a[i]--;
        st[a[i]].insert(i);
    }
    vector<int> ans;
    for(int i = Q-1; i >= 0; i--){
        if(!used[a[i]]){
            ans.push_back(a[i]);
            used[a[i]] = true;
        }
    }
    for(int i = 0; i < N; i++) idx[i] = Q;
    for(int i = 0; i < M; i++){
        if(!used[i]) ans.push_back(i);
    }
    //for(int i = 0; i < M; i++) cout << ans[i] << ' ';
    int last = -1;
    for(int i = 1; i < M; i++){
        if(ans[i] < ans[i-1]) last = i-1;
    }
    // cout << last << endl;
    for(int i = 0; i <= last; i++){
        //cout << i << endl;
        for(int j = 0; j < N; j++){
            //cout << j << endl;
            auto ptr = st[ans[i]].lower_bound(idx[j]);
            if(ptr == st[ans[i]].begin()){
                cout << "No" << endl;
                return 0;
            }
            ptr--;
            int m = *ptr;
            idx[j] = m;
            st[ans[i]].erase(m);
        }
    }
    cout << "Yes" << endl;
}

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

#define Pi 3.14159265

main(){
	double a,b,C;
	double Crad;
	double S,c,h;
	
	scanf("%lf %lf %lf",&a,&b,&C);
	
	Crad = C * Pi / 180.0;
	h = b * sin(Crad);
	S = a * b * sin(Crad) * 0.5;
	printf("%.5f\n",S);
	c = sqrt(a*a+b*b-2*a*b*cos(Crad));
	printf("%.5f\n",a+b+c);
	printf("%.5f\n",h);
	return 0;
}

Measured memory_bytes: 652
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#define MAX 100000007
using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

ll ans=0;
ll C[51][51];

void comb(int N){
  for(int i=0;i<=N;i++){
    for(int j=0;j<=i;j++){
      if(j==0 || i==j){
        C[i][j]=1LL;
      }else{
        C[i][j]=C[i-1][j-1]+C[i-1][j];
      }
    }
  }
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int A,B,N;
  cin >> N >> A >> B;
  ll v[50];
  for(int i=0;i<N;i++){
    cin >> v[i];
  }
  comb(N);
  sort(v,v+N);
  reverse(v,v+N);

  double sum=0.0;
  for(int i=0;i<A;i++){
    sum+=v[i];
  }
  double ave = 0.0;
  ave = sum/A;
  int acnt=0,bcnt=0;
  for(int i=0;i<N;i++){
    if(v[A-1]==v[i]){
      acnt++;
      if(i<A){
        bcnt++;
      }
    }
  }
  ll cnt =0LL;

  if(ave==v[A-1]){
    for(int i=A;i<=B;i++){
      cnt+=C[acnt][i];
    }
    cout.precision(20);
    cout << ave << endl;
    cout << cnt << endl;
    return 0;
  } else {
    cnt =C[acnt][bcnt];
    cout.precision(20);
    cout << ave << endl;
    cout << cnt << endl;
    return 0;
  }
}


Measured memory_bytes: 256
#include <stdio.h>

#define N 100

int main() {
	int w, h, n, i, x1, x2, y1, y2;

	scanf("%d%d%d", &w, &h, &n);
	x1 = 0, x2 = w, y1 = 0, y2 = h;
	for (i = 0; i < n; i++) {
		int x, y, a;

		scanf("%d%d%d", &x, &y, &a);
		if (a == 1) {
			if (x1 < x)
				x1 = x;
		} else if (a == 2) {
			if (x2 > x)
				x2 = x;
		} else if (a == 3) {
			if (y1 < y)
				y1 = y;
		} else if (a == 4) {
			if (y2 > y)
				y2 = y;
		}
	}
	printf("%d\n", x1 < x2 && y1 < y2 ? (x2 - x1) * (y2 - y1) : 0);
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

int A[101010], B[101010];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int N;
	cin >> N;
	min_priority_queue<vector<int>>q;
	vector<pair<int, int>>p(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i] >> B[i];
		q.push({A[i],0,i});
		q.push({B[i],1,i});
	}

	ll ans = 0;
	int last = -1;
	ll costnminus2 = 0;
	ll costnminus1 = 0;
	for (int i = 0; i < N; i++) {
		auto v = q.top();
		q.pop();
		int num = v[2];
		if (v[1] == 0)p[num].first++;
		else p[num].second++;
		ans += v[0];
		if (i == N - 3)costnminus2 = ans;
		if (i == N - 2)costnminus1 = ans;
		if (i == N - 1)last = num;
	}

	int cntl = 0;
	int cntr = 0;
	for (int i = 0; i < N; i++) {
		if (p[i].first && p[i].second) {
			puts(ans);
			return 0;
		}
		if (p[i].first)cntl++;
		else cntr++;
	}
	if (!cntl || !cntr) {
		puts(ans);
		return 0;
	}


	if (last == q.top()[2]) {
		q.pop();
		puts(min(costnminus2 + A[last] + B[last],costnminus1 + q.top()[0]));
	}
	else {
		if (p[last].first)puts(ans-A[last]+q.top()[0]);
		else puts(ans-B[last]+q.top()[0]);
	}


	return 0;
}

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

int main(){
	int n, t;
	scanf("%d %d", &n, &t);
	int minimo = 10000;
	for(int i = 0; i<n; i++){
		int ci, ti;
		scanf("%d %d", &ci, &ti);
		if (ti<=t) minimo = min(minimo, ci);
	}
	if (minimo == 10000) puts("TLE");
	else printf("%d\n", minimo);
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

string base;

int main() {
    cin >> base;
    if (base=="A"){
        cout << "T";
    } else if (base=="T"){
        cout << "A";
    } else if (base=="G"){
        cout << "C";
    } else {
        cout << "G";
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= int(b); i++)
#define per(i, a, b) for (int i = (a); i >= int(b); i--)
#define fir first
#define sec second
#define tct template<class type>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const int maxn = 1e6;
int M, n, m, q, G, T, z, fa[maxn + 5], u[maxn + 5], v[maxn + 5], w[maxn + 5], a[maxn + 5];
bool f[2][3][maxn + 5], h[maxn + 5];

inline void red(int &x) { x += x >> 31 & T; }
tct inline void cmax(type &x, type y) { x < y ? x = y : 0; }
tct inline void cmin(type &x, type y) { x > y ? x = y : 0; }

int get(int u, int a, int b) {
	int c = a * 3 + b;
	return c * n + u;
}

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

int find(int x) {
	return fa[x] == x ? x : fa[x] = find(fa[x]);
}

int main() {
	scanf("%d %d %d %d", &n, &m, &q, &M);
	rep(i, 1, m) {
		scanf("%d %d %d", &u[i], &v[i], &w[i]);
		a[i] = w[i];
	}
	G = M;
	sort(a + 1, a + m + 1);
	rep(i, 1, m - 1) G = gcd(G, a[i + 1] - a[i]);
	T = gcd(3 * G, M), z = w[1] % G;
	rep(i, 1, 6 * n) fa[i] = i;
	rep(i, 1, m) {
		(w[i] -= z) /= G;
		rep(a, 0, 1) rep(b, 0, 2) {
			fa[find(get(u[i], a, b))] = find(get(v[i], a ^ 1, (b * 2 + w[i]) % 3));
			fa[find(get(v[i], a, b))] = find(get(u[i], a ^ 1, (b * 2 + w[i]) % 3));
		}
	}
	rep(a, 0, 1) rep(b, 0, 2) {
		memset(h, false, sizeof(h));
		for (int x = (a + 1) % T; !h[x]; h[x] = true, x = 4 * x % T) {
			f[a][b][(1ll * x * z + b * G) % T] = true;
		}
	}
	for (int s, t, r; q --> 0; ) {
		scanf("%d %d %d", &s, &t, &r);
		(r += z) %= T;
		bool res = false;
		rep(a, 0, 1) rep(b, 0, 2) {
			res |= find(get(t, 0, 0)) == find(get(s, a, b)) && f[a][b][r];
		}
		puts(res ? "YES" : "NO");
	}
	return 0;
}

Measured memory_bytes: 12404
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define itn int
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>=1;i--)
#define all(vec) vec.begin(),vec.end()
#define sort(vec) sort((vec).begin(),(vec).end())
#define rsort(vec) sort((vec).rbegin(), (vec).rend())
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=2e9;
const ll lnf=9e18;

int main(){
  ll n,a,b; cin >> n >> a >> b;
  vector<ll> h(n);
  rep(i,n) cin >> h[i];
  ll l=0,r=1e9;
  while(r-l!=1){
    ll mid=(l+r)/2;
    ll cnt=0;
    rep(i,n){
      cnt+=ceil( max((double)h[i]-b*mid,(double)0)/(a-b) );
    }
    if(cnt<=mid) r=mid;
    else l=mid;
  }
  cout << r << endl;
}

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

int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    bool discovered = false;

    rep(i,N){
        cin >> a.at(i);
    }

    int numlight = 1;
    rep(i,N){
        if (numlight == 2){
            discovered = true;
            cout << i << endl;
            break;
        }        
        numlight = a.at(numlight - 1);
    }

    if (!discovered){
        cout << -1 << endl;
    }
}

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

int main(){
  int n;
  cin >> n;
  
  vector<int> d(n);
  for(int i=0; i<n; i++)
    cin >> d.at(i);
  
  sort(d.begin(), d.end());
  reverse(d.begin(), d.end());
  int cnt = 0;
  int pre;
  for(int i=0; i<n; i++){
    if(d.at(i) == pre)
      continue;
    else{
      pre = d.at(i);
      cnt++;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {

	public static void main(String[] args) throws java.lang.Exception
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		ArrayList<Integer> h = new ArrayList<Integer>();
		ArrayList<Integer> w = new ArrayList<Integer>();
		ArrayList<String> strArray = new ArrayList<String>();
		String data;
		int count = 0;
		while(true) {
			strArray.add(br.readLine());
			data = strArray.get(strArray.size() - 1);
			if(data.equals("0 0")) {
				break;
			}
			count++;
		}
		
		for(int i = 0; i < strArray.size(); i++) {
			String s = strArray.get(i);
			String [] ary = s.split(" ", 0);
			h.add(Integer.parseInt(ary[0]));
			w.add(Integer.parseInt(ary[1]));
		}
		int cnt1 = 0, cnt2 = 0;
		for(int k = 0; k < count; k++) {
			for(int i = 0; i < h.get(k); i++) {
				for(int j = 0; j < w.get(k); j++) {
					if(cnt1 % 2 == 1) {
						if(cnt2 % 2 == 0){
							System.out.print('.');
						}else {
							System.out.print('#');
						}
					}else if(cnt1 % 2 == 0){
						if(cnt2 % 2 == 0){
							System.out.print('#');
						}else {
							System.out.print('.');
						}
					}
					cnt2++;
				}
				cnt2 = 0;
				cnt1++;
				System.out.println();
			}
			cnt1 = 0;
			System.out.println();
		}
	}

}

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

int main(){
    string s;
    vector<string>abc(3);
    cin >> s;
    for(int i=0; i<3; i++){
        abc[i]=s[i];
    }
    sort(abc.begin(), abc.end());
    if(abc[0]=="a" && abc[1]=="b" && abc[2]=="c"){
        cout << "Yes" << endl;
    }
    else {
        cout << "No";
    }
    return 0;
    



    
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <algorithm>


#define MAX 32
#define pb push_back
#define mp make_pair

using namespace std;

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

int h,w,n;

bool check(char f[MAX][MAX])
{
	int i1,i2,i3,i4;
	bool tf[MAX][MAX];
	char temp[MAX][MAX];
	int x,y;
	int cnt;
	char c;
	bool b;

	for(i1=1;i1<=h;i1++){
		for(i2=1;i2<=w;i2++){
			if(f[i1][i2]!='.') {
				i1=99;
				break;
			}
		}
	}
	if(i1!=100) return true;

	for(i1=1;i1<=h;i1++){
		for(i2=1;i2<=w;i2++){
			temp[i1][i2]=f[i1][i2];
			tf[i1][i2]=false;
		}
	}

	for(i1=1;i1<=w;i1++){
		cnt=0;
		for(i2=h;i2>1;i2--){
			if(temp[i2][i1]=='.') {
				cnt++;
			}
			if(cnt>0 && temp[i2][i1]!='.') {
				temp[i2+cnt][i1]=temp[i2][i1];
				temp[i2][i1]='.';
			}
		}
	}

	for(i1=1;i1<=h;i1++){
		for(i2=1;i2<=w;i2++){
			if(temp[i1][i2]!='.'){
				c=temp[i1][i2];

				for(i3=0;i3<2;i3++){
					cnt=0;
					y=i1;
					x=i2;
					while(c==temp[y][x]){
						cnt++;
						y+=dy[i3];
						x+=dx[i3];
					}
					if(cnt>=n) {
						y=i1;
						x=i2;
						for(i4=0;i4<cnt;i4++){
							tf[y][x]=true;
							y+=dy[i3];
							x+=dx[i3];
						}
					}
				}
			}
		}
	}

	/*cout<<"a"<<endl;
	for(i1=1;i1<=h;i1++){
		for(i2=1;i2<=w;i2++){
			cout<<temp[i1][i2];
		}
		cout<<endl;
	}*/


	for(i1=1;i1<=h;i1++){
		for(i2=1;i2<=w;i2++){
			if(tf[i1][i2]) temp[i1][i2]='.';
		}
	}

	/*cout<<"b"<<endl;
	for(i1=1;i1<=h;i1++){
		for(i2=1;i2<=w;i2++){
			cout<<temp[i1][i2];
		}
		cout<<endl;
	}*/


	for(i1=1;i1<=w;i1++){
		cnt=0;
		for(i2=h;i2>0;i2--){
			if(temp[i2][i1]=='.') {
				cnt++;
			}
			if(cnt>0 && temp[i2][i1]!='.') {
				temp[i2+cnt][i1]=temp[i2][i1];
				temp[i2][i1]='.';
			}
		}
	}


	/*cout<<"c"<<endl;
	for(i1=1;i1<=h;i1++){
		for(i2=1;i2<=w;i2++){
			cout<<temp[i1][i2];
		}
		cout<<endl;
	}*/

	for(i1=1;i1<=h;i1++){
		for(i2=1;i2<=w;i2++){
			if(f[i1][i2]!=temp[i1][i2]) {
				i1=99;
				break;
			}
		}
	}
	if(i1!=100) {
		//cout<<"x"<<endl;
		return false;
	}

	//cout<<"#";
	return check(temp);
}

int main(void)
{

	int i1,i2;
	char f[MAX][MAX];

	for(i1=0;i1<MAX;i1++){
		for(i2=0;i2<MAX;i2++){
			f[i1][i2]='.';
		}
	}

	cin>>h>>w>>n;
	for(i1=1;i1<=h;i1++){
		for(i2=1;i2<=w;i2++){
			cin>>f[i1][i2];
		}
	}

	for(i1=1;i1<=h;i1++){
		for(i2=1;i2<w;i2++){
			if(f[i1][i2]!='.' || f[i1][i2+1]!='.'){
				swap(f[i1][i2],f[i1][i2+1]);
				//cout<<i1<<" "<<i2<<" ";
				if(check(f)) {
					cout<<"YES"<<endl;
					return 0;
				}
				swap(f[i1][i2],f[i1][i2+1]);

			}
		}
	}



	cout<<"NO"<<endl;

	return 0;
}

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

using namespace std;

int main() {
    string s;
    cin >> s;
    if (s.at(2) == s.at(3) && s.at(4) == s.at(5)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
using namespace std;
const int N = 50;
#define dx(y, x) field[(y) + 5][(x) + 5]
#define dy(a, b, c, d) move[(a) + 5][(b) + 5][(c) + 5][(d) + 5]
#define FOR(a, b) for (int (a) = 0; (a) < (int)(b); ++(a))

int field[N + 25][N + 25] = {false};
bool move[N + 25][N + 25][N + 25][N + 25];

class C{
    public:
        int ty, tx, ky, kx, step;
        C(int tty, int ttx, int kky, int kkx, int s);
};

C::C(int tty, int ttx, int kky, int kkx, int s){
    ty = tty;
    tx = ttx;
    ky = kky;
    kx = kkx;
    step = s;
}

int main(){

    int w, h, stx, sty, skx, sky;
    while(cin >>w >>h){
        if(w == 0 && h == 0) break;

        FOR(i, (N + 25)){
            FOR(j, (N + 25)){
                field[i][j] = 1;
            }
        }

        FOR(i, (N + 25)){
            FOR(j, (N + 25)){
                FOR(k, (N + 25)){
                    FOR(m, (N + 25)){
                        move[i][j][k][m] = false;
                    }
                }
            }
        }

        cin >>stx >>sty >>skx >>sky;
        --stx; --sty; --skx; --sky;

        FOR(i, h){
            FOR(j, w){
                cin >>dx(i, j);
            }
        }

        queue<C> qu;
        C cls(sty, stx, sky, skx, 0);
        qu.push(cls);
        dy(sty, stx, sky, skx) = true;

        int cnt = 0;
        bool endFlg = false;
        int mx[] = {0, 1, 0, -1};
        int my[] = {-1, 0, 1, 0};

        while(!qu.empty()){
            C now = qu.front(); qu.pop();

            if(now.step >= 100) break;
            if(now.ty == now.ky && now.tx == now.kx){
                endFlg = true;
                cout <<now.step <<endl;
                break;
            }

            FOR(i, 4){
                FOR(j, 4){
                    int nty = now.ty + my[i];
                    int ntx = now.tx + mx[i];
                    int nky = now.ky + (my[i] * -1);
                    int nkx = now.kx + (mx[i] * -1);
                    if(!dy(nty, ntx, nky, nkx) && !(dx(nty, ntx) == 1 && dx(nky, nkx) == 1)){

                        if(dx(nty, ntx) == 1){
                            nty = now.ty; ntx = now.tx;
                        }
                        if(dx(nky, nkx) == 1){
                            nky = now.ky; nkx = now.kx;
                        }
                        if(dy(nty, ntx, nky, nkx)) continue;

                        C tmp2(nty, ntx, nky, nkx, now.step + 1);
                        qu.push(tmp2);
                        dy(nty, ntx, nky, nkx) = true;
                    }
                }
            }
        }

        if(!endFlg) cout <<"NA" <<endl;
    }
    return 0;
}

Measured memory_bytes: 32444
N,K = map(int,input().split())
p = list(map(int,input().split()))

for i in range(N):
    p[i] = (p[i]+1)/2
for i in range(N-1):
    p[i+1] += p[i]

ans = []

for i in range(N-K+1):
    if i == 0:
        ans.append(p[K-1])
    else:
        ans.append(p[i+K-1]-p[i-1])
print(max(ans))

Measured memory_bytes: 25060
//author: Harsh Nema
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll INF = 922337203685477;
#define pb push_back
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
#define maxN 100007
using namespace std;
int main(){
  fastio;
  ll a=0,b=0,v=0,w=0,t=0;
  cin>>a>>v>>b>>w>>t;
  if((v-w)*t>=abs(a-b)) cout<<"YES";
  else cout<<"NO";
  return 0;
}


Measured memory_bytes: 3588
//
// Created by Myabu on 2020/01/26.
//

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <math.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <numeric>
#include <iomanip>

using namespace std;


int main(void){
    long long r, D, x;
    
    cin>>r>>D>>x;

    for (int i = 0; i < 10; ++i) {
        x = r*x - D;
        cout<<x<<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 REP(i,n) for(int i=1;i<=n;i++)
typedef long long ll;
const ll M=1000000007;

//べき乗高速化
ll mpow(ll x, ll n){
	ll ans = 1;
	while(n != 0){
		if (n&1) ans = ans * x % M;
		x = x*x % M;
		n  = n >> 1;
	}
	return ans;
}

int main(){
	ll m,n;
	cin >> m >> n;
	cout << mpow(m,n) << endl;
    return 0;
}





Measured memory_bytes: 3112
#include<iostream>
#include<cstring>

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

int main(){
	int w,h;
	char cfield[20][21];
	int ifield[20][20];
	int already[20][20];
	char point;

	while(std::cin >> w >> h && (w || h)){
		rep(i,20){
			memset(cfield[i],'#',20);
			rep(j,20){
				ifield[i][j] = 0;
				already[i][j] = 0;
			}
		}
		int x=-1,y=-1;
		int count = 1;
		int sum;
		rep(i,h){
			std::cin >> cfield[i];
		}
		rep(i,20){
			rep(j,20){
				if(cfield[i][j] == '@'){
					x=i,y=j;
					already[x][y] = 1;
					break;
				}
			}
			if (cfield[x][y] == '@') {
				break;
			}
		}
		while(1){
			rep(i,3) {
				point = cfield[x - 1 + i][y];
				if (point == '@' || point == '.' || point == '#') {
					if (point == '@') {
						already[x - 1 + i][y] = 1;
						ifield[x - 1 + i][y] = 0;
					}
					if (point == '.') {
						if (already[x - 1 + i][y] != 1) {
							ifield[x - 1 + i][y] = 1;
						}else{
							ifield[x - 1 + i][y] = 0;
						}
					}
					if(point == '#'){
						ifield[x - 1 + i][y] = 0;
					}
				}
			}
			rep(j,3) {
				point = cfield[x][y - 1 + j];
				if (point == '@' || point == '.' || point == '#') {
					if (point == '@') {
						already[x][y - 1 + j] = 1;
					}
					if (point == '.') {
						if (already[x][y - 1 + j] != 1) {
							ifield[x][y - 1 + j] = 1;
						}else{
							ifield[x][y - 1 + j] = 0;
						}
					}
					if (point == '#') {
						ifield[x][y - 1 + j] = 0;
					}
				}
			}

			sum = 0;
			rep(i,20){
				rep(j,20){
					sum += ifield[i][j];
					if(ifield[i][j] == 1){
						cfield[i][j] = '@';
						cfield[x][y] = '.';
						x=i,y=j;
					}
				}
			}
			if(sum == 0)break;
			count++;
		}
		std::cout << count << std::endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
using ll=long long;
using Graph=vector<vector<ll> >;
vector<bool> seen;
ll g_num_max=0;
ll g_num=0;
void dfs(const Graph &G, int v) {
    seen[v] = true; // v を訪問済にする
    g_num++;
    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue; // next_v が探索済だったらスルー
        dfs(G, next_v); // 再帰的に探索
    }
}
int main(){
    ll N,M;
    Graph group(200002);
    cin>>N>>M;
    seen.assign(N+1,false);
    for(ll i=1;i<=M;i++){
        ll A,B;
        cin>>A>>B;
        group[A].push_back(B);
        group[B].push_back(A);
    }
    for(ll i=1;i<=N;i++){
        if(seen[i]){
            continue;
        }else{
            g_num=0;
            dfs(group,i);
            g_num_max=max(g_num_max,g_num);
        }
    }
    cout<<g_num_max<<endl;
    return 0;
}

Measured memory_bytes: 23528
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#define MAXN 100010
int head[MAXN], to[MAXN << 1], next[MAXN << 1], tot = 0;
inline void addEdge(int u, int v) {
    next[tot] = head[u], to[tot] = v, head[u] = tot++;
    next[tot] = head[v], to[tot] = u, head[v] = tot++;
}
int n, d[MAXN], f[MAXN], m;
inline bool check(const std::vector<int> &v, int mid) {
    int l = 0, r = v.size() - 1;
    while (l < r) {
        if (l == mid) l++;
        if (r == mid) r--;
        if (v[l] + v[r] > m) return 0;
        l++;
        r--;
    }
    return 1;
}
bool DP(int x, int fa) {
    std::vector<int> g;
    for (int i = head[x]; ~i; i = next[i])
        if (to[i] != fa) {
            if (!DP(to[i], x)) return false;
            g.push_back(f[to[i]]);
        }
    if (g.empty()) {
        f[x] = 1;
        return true;
    }
    if (!(g.size() & 1)) g.push_back(0);
    std::sort(g.begin(), g.end());
    register int l = 0, r = g.size(), ans = -1;
    while (l <= r) {
        int mid = (l + r) >> 1;
        if (check(g, mid))
            ans = mid, r = mid - 1;
        else
            l = mid + 1;
    }
    if (!~ans) return false;
    f[x] = g[ans] + 1;
    return 1;
}
int root = 0;
inline bool judge(int mid) {
    m = mid;
    if (!DP(root, 0)) return 0;
    return f[root] <= m + 1;
}
int main() {
    std::cin >> n;
    memset(head, -1, sizeof(head));
    for (int i = 1; i < n; i++) {
        int u, v;
        std::cin >> u >> v;
        addEdge(u, v);
        d[u]++;
        d[v]++;
    }
    for (int i = 1; i <= n; i++) m += d[i] & 1;
    for (int i = 1; i <= n; i++)
        if (d[i] == 1) {
            root = i;
            break;
        }
    std::cout << (m >>= 1) << ' ';
    register int l = 0, r = n, ans = -1;
    while (l <= r) {
        int mid = (l + r) >> 1;
        if (judge(mid))
            ans = mid, r = mid - 1;
        else
            l = mid + 1;
    }
    std::cout << ans << std::endl;
    return 0;
}

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

#define loop(i,n) for(int i = 0;i < int(n);i++)
#define rloop(i,n) for(int i = int(n);i >= 0;i--)
#define range(i,a,b) for(int i = int(a);i <= int(b);i++)
#define SZ(c) int(c.size())
#define ALL(c) c.begin(), c.end()
#define RALL(c) c.rbegin(), c.rend()
#define PI acos(-1)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1,v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1,v2,v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define endl '\n'

typedef vector<int> vi;
typedef vector<pair<int,int> > vii;
typedef long long ll;
typedef pair<int, int> pii;


const int N = 1e5 + 5;
int p[N] , w[N];
int n;

int f(int u){
    if(u == p[u])return u;
    return p[u] = f(p[u]);
}

bool is_connected(int a , int b){
    return f(a) == f(b);
}

void connect(int a , int b){
    a = f(a);
    b = f(b);
    if(a == b)return;
    if(w[a] < w[b])swap(a,b);
    w[a] += w[b];
    p[b] = a;
}

void init(){
    for(int i = 0 ; i < N ; i++)
        p[i] = i , w[i] = 1;
}


int main()
{

#ifndef ONLINE_JUDGE
	//freopen("in.in", "r", stdin);
	//freopen("out.in", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    init();
    int n , m;
    cin >> n >> m;
    int x,  y , z;
    loop(i,m){
        cin >> x >> y >> z;
        connect(x,y);
    }

    int ans = 0;
    range(i,1,n)ans += (i == f(i));
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll INF=1e18;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    V<ll> a(n);
    cinf(n,a);
    ll ans(n);
    ll x=0;
    rep(i,n) x^=a[i];
    rep(i,n) cout<<(x^a[i])<<' ';
    cout<<endl;
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
//どうしてもわからないときはサンプルで実験　何か見えてくるかも
//頭で考えてダメなら紙におこせ！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
{
    ・全探索できるなら全探索しろ
    ・異常な制約ならそこに注目
}
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'¥n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え('='でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
doubleを扱うときには(abs)ではなく'fabs'!!!
*/

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

#ifdef DEBUG
#include "../include/debug.hpp"
#else
#define debug(...) 42
#define rdfile(...) 42
#endif

const long long mod = 1e9+7;
long long dp[2100][2100];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    // rdfile("_input.txt");

    int N, M;
    cin >> N >> M;

    vector<long long> S(N), T(M);
    for (int i=0; i<N; ++i) cin >> S[i];
    for (int i=0; i<M; ++i) cin >> T[i];

    // init
    for (int i=0; i<=N; ++i) dp[i][0] = 1;
    for (int i=0; i<=M; ++i) dp[0][i] = 1;

    for (int i=1; i<=N; ++i) {
        for (int j=1; j<=M; ++j) {
            if (S[i-1] == T[j-1]) {
                if (i>0) dp[i][j] += dp[i-1][j];
                if (j>0) dp[i][j] += dp[i][j-1];
            } else {
                if (i>0) dp[i][j] += dp[i-1][j];
                if (j>0) dp[i][j] += dp[i][j-1];
                if (i>0 && j>0) dp[i][j] -= dp[i-1][j-1];
            }
            while (dp[i][j] < 0) dp[i][j] += mod;
            dp[i][j] %= mod;
        }
    }
    cout << dp[N][M] << endl;

    return 0;
}


Measured memory_bytes: 33152
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstdlib>
#include<utility>
using namespace std;

int N = 1001001;
int a[1001001];
int p0;
int p1;

void insertx(int x){
	if(p0==0){
		a[N-1] = x;
		p0 = N-1;
	}else{
		a[p0-1] = x;
		p0--;
	}
}
void deletex(int x){
	if(p0<=p1){
		for(int i=p0; i<p1; i++){
			if(x==a[i]){
				for(int j=i; j<p1-1; j++){
					a[j] = a[j+1];
				}
				p1--;
				break;
			}
		}
	}else{
		int f = 0;
		for(int i=p0; i<N; i++){
			if(x==a[i]){
				for(int j=i; j>=p0+1; j--){
					a[j] = a[j-1];
				}
				p0++;
				if(p0==N) p0 = 0;
				f = 1;
				break;
			}
		}
		if(f==0){
			for(int i=0; i<p1; i++){
				if(x==a[i]){
					for(int j=i; j<p1-1; j++){
						a[j] = a[j+1];
					}
					p1--;
					break;
				}
			}
		}
	}
}

void deleteFirst(){
	p0++;
	if(p0==N) p0=0;
}

void deleteLast(){
	p1--;
	if(p1<0) p1 = N-1;
}

int main(){
	int n;
	cin >> n;
	p0 = 0;
	p1 = 0;
	for(int i=0; i<n; i++){
		char s_[100];
		string s;
		int m;
		scanf("%s", s_);
		s = s_;
		if(s=="deleteFirst") deleteFirst();
		else if(s=="deleteLast") deleteLast();
		else{
			scanf("%d", &m);
			if(s=="insert") insertx(m);
			if(s=="delete") deletex(m);
		}
	}

	if(p0<=p1){
		for(int i=p0; i<p1; i++){
			cout << a[i];
			if(i==p1-1) cout << endl;
			else cout << " ";
		}
	}else{
		for(int i=p0; i<N; i++){
			cout << a[i];
			if(i!=N-1) cout << " ";
		}
		for(int i=0; i<p1; i++){
			cout << " " << a[i];
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 5172
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e4 + 10;
int a[N];
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i];
	int ans = INF;
	for (int o = -100; o <= 100; o++)
	{
		int sum = 0;
		for (int i = 1; i <= n; i++)
		{
			sum += o * o + a[i] * a[i] - 2 * o*a[i];
		}
		ans = min(ans, sum);
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
	string S;
	cin >> S;
	int F = stoi(S.substr(0, 2));
	int B = stoi(S.substr(2, 2));
	string Answers[4] = { "YYMM", "NA", "AMBIGUOUS", "MMYY" };
	int ans = 2 * (F <= 12 && F > 0) + (B > 12 || B == 0);
	cout << Answers[ans] << endl;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let mut h: Vec<usize> = (0..n).map(|_| read()).collect();

    let mut ok = true;
    for i in 1..n {
        if h[n-i] < h[n-i-1] {
            if h[n-i-1] - h[n-i] == 1 {
                h[n-i-1] -= 1;
            } else {
                ok = false;
            }
        }
    }
    println!("{}", if ok {"Yes"} else {"No"});
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


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

int ha[105];

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

    for (int i = 0; i < k; i++)
    {
        int d;
        cin >> d;
        for (int j = 0; j < d; j++)
        {
            int a;
            cin >> a;
            ha[a]++;
        }
    }
    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        if (ha[i] == 0)
            ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3596
def resolve():
    from collections import deque
    s = deque(input())
    q = int(input())
    qlist = [input().split() for i in range(q)]
    flip = False
    for j in range(q):
        if qlist[j][0] == "1":
            flip = not flip
        elif qlist[j][1] == "1":
            if flip:
                s.append(qlist[j][2])
            else:
                s.appendleft(qlist[j][2])
        elif qlist[j][1] == "2":
            if flip:
                s.appendleft(qlist[j][2])
            else:
                s.append(qlist[j][2])
    if not flip:
        print("".join(s))
    else:
        s.reverse()
        print("".join(s))
resolve()

Measured memory_bytes: 119128
#include <iostream>
#include <cstdio>
#include <algorithm>

int main(){
    int seq[10];
    for(int i = 1 ; i<= 5; ++ i){
        std::cin >> seq[i];
    }
    int ret = 0;
    int mrk = 10;
    for(int i = 1; i <= 5; ++ i){
        if (seq[i] % 10 == 0) ret += seq[i];
        else {
            if ((seq[i] % 10) < mrk ) {
                mrk = seq[i] % 10;
            }
            ret += (seq[i] / 10 )* 10 + 10;
        }
    }
    ret -= (10 - mrk);
    std::cout << ret;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll  long long int 
using namespace std;
int main()
{
	string s;
	ll num;
	ll mm=1145141919;
	cin>>s;
	for(ll i=0;i<s.size()-2;i++){
		num=(s[i]-'0')*100+(s[i+1]-'0')*10+(s[i+2]-'0');
		if(mm>abs(num-753)) mm=abs(num-753);
	}
	cout<<mm;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define gcd __gcd
#define in(a) scanf("%d",&a)
#define in2(a,b) scanf("%d%d",&a,&b)
#define in3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define read(v,i,n) for(i=0;i<n;i++)in(v[i])
#define twod(mat,i,j,n,m) rep(i,n){rep(j,m)in(mat[i][j]);}
#define sc(ch) scanf("%c",&ch)
#define sstr(str) scanf("%s",str)
#define pr(n) printf("%d ",n)
#define out(n) printf("%d\n",n)
#define llin(a) cin >> a
#define llpr(a) cout << a << " "
#define llout(a) cout << a << endl
#define yes printf("YES\n")
#define no printf("NO\n")
#define lin printf("\n")
#define dbg(v,i,n) for(i=0;i<n;i++)pr(v[i]); lin
#define ck printf("continue\n")
#define all(vec) vec.begin(),vec.end()
#define asc(vec) sort(vec.begin(),vec.end())
#define lower(v,k) lower_bound(v.begin(),v.end(),k)-v.begin()
#define upper(v,k) upper_bound(v.begin(),v.end(),k)-v.begin()
#define tf(mytuple) get<0>(mytuple)
#define ts(mytuple) get<1>(mytuple)
#define tt(mytuple) get<2>(mytuple)
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define viii vector<pair<pair<int,int>,int> >
#define vvii vector<vector<pair<int,int> > >
#define lp(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define M 1000000007
#define S 105
#define N 10005  //check the limits, man
// read the constraint properly (ll vs int)
typedef long long int ll;
ll dp[N][S],ar[N][S];
string str;
int n,d;
ll fun(int i,int s)
{
    if(i==n)
        return (s==0);
    if(ar[i][s]>=0)
        return ar[i][s];
    ar[i][s]=0;
    int j;
    for(j=0;j<10;j++)
        ar[i][s]+=fun(i+1,(s+j)%d);
    ar[i][s]%=M;
    return ar[i][s];
}
ll process(int i,int s)
{
    if(i==n)
        return (s==0);
    if(dp[i][s]>=0)
        return dp[i][s];
    dp[i][s]=0;
    int j;
    for(j=0;j<str[i];j++)
        dp[i][s]+=fun(i+1,(s+j)%d);
    dp[i][s]+=process(i+1,(s+j)%d);
    dp[i][s]%=M;
    return dp[i][s];
}
int main()
{
    int i,j;
    llin(str);
    in(d);
    n=str.size();
    rep(i,n)
    {
        str[i]-='0';
        rep(j,d)
            dp[i][j]=-1,ar[i][j]=-1;
    }
    ll ans=-1;
    lp(j,0,str[0])
        ans+=fun(1,j%d);
    ans+=process(1,j%d);
    llout(ans%M);
}



Measured memory_bytes: 17408
#include "bits/stdc++.h"
using namespace std;
long long max(long long x, long long y)
{
	return x > y ? x : y;
}
long long a[100001], b[100001], c[2][100001], d[2][100001], e[2][100001];
int main()
{	
	int n;
	long long m, mx = 0, inf = 1ll << 60;
	scanf("%d%lld", &n, &m);
	for(int i = 1; i <= n; ++i)
	{
		scanf("%lld%lld", &a[i], &b[i]);
		b[i] += b[i - 1];
	}
	for(int i = 0; i < 2; ++i)
	{
		for(int j = 1; j <= n; ++j)
		{
			d[i][j] = -inf;
			e[i][j] = -inf;
		}
		d[i][0] = 0;
		d[i][0] = 0;
	}
	for(int i = 1; i <= n; ++i)
	{
		c[0][i] = b[i] - a[i];
		d[0][i] = max(d[0][i - 1], c[0][i]);
	}
	for(int i = n; i; --i)
	{
		c[1][i] = b[n] - b[i - 1] - (m - a[i]);
		d[1][i] = max(d[1][(i + 1) % (n + 1)], c[1][i]);
	}
	for(int i = 1; i < n; ++i)
	{
		e[0][i] = c[0][i] + max(0, d[1][i + 1] - a[i]);
	}
	e[0][n] = c[0][n];
	for(int i = n; i > 1; --i)
	{
		e[1][i] = c[1][i] + max(0, d[0][i - 1] - (m - a[i]));
	}
	e[1][1] = c[1][1];
	for(int i = 0; i < 2; ++i)
	{
		for(int j = 0; j <= n; ++j)
		{
			mx = max(mx, e[i][j]);
		}
	}
	printf("%lld\n", mx);
}

Measured memory_bytes: 6528
#include <stdio.h>

int main(void)
{
    int money=100000;
    int i,n;

    scanf("%d",&n);

    for(i=0;i<n;i++){
        money*=1.05;
        int l=money%1000;
        if(l!=0){
            money-=l;
            money+=1000;
        }
    }

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

    return 0;
}

Measured memory_bytes: 1800