akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int N = 500005;
int n, q, a[N], lp[N], ans[N], seg[4 * N];
//////////////////
pair<int, int> nxt[N];
struct A
{
    int l, r, idx;
} quer[N];
bool cmp(A lhs, A rhs)
{
    if (lhs.r != rhs.r)
        return lhs.r < rhs.r;
    else
        return lhs.idx < rhs.idx;
}
void upd(int idx, int start, int end, int id)
{
    if (start > end || start > id || end < id)
        return;
    else if (start == end)
        seg[idx] ++;
    else
    {
        int mid = (start + end) / 2;
        upd(2 * idx + 1, start, mid, id);
        upd(2 * idx + 2, mid + 1, end, id);
        seg[idx] = seg[2 * idx + 1] + seg[2 * idx + 2];
    }
}
int query(int idx, int start, int end, int l, int r)
{
    if (start > end || start > r || end < l)
        return 0;
    else if (start >= l && end <= r)
        return seg[idx];
    else
    {
        int mid = (start + end) / 2;
        int ls = query(2 * idx + 1, start, mid, l, r);
        int rs = query(2 * idx + 2, mid + 1, end, l, r);
        return (ls + rs);
    }
}
int main(int argc, char const *argv[])
{
    cin >> n >> q;
    for (int i = 0; i < n; ++i)
    {
        lp[i] = -1;
        cin >> a[i];
        a[i] --;
    }
    for (int i = n - 1; i >= 0; --i)
    {
        nxt[i].second = i;
        if (lp[a[i]] == -1)
            nxt[i].first = n;
        else
            nxt[i].first = lp[a[i]];
        lp[a[i]] = i;
    }
    for (int i = 0; i < q; ++i)
    {
        cin >> quer[i].l >> quer[i].r;
        quer[i].l --;
        quer[i].r --;
        quer[i].idx = i;
    }
    sort(nxt, nxt + n);
    sort(quer, quer + q, cmp);
    int j = n - 1;
    for (int i = q - 1; i >= 0; --i)
    {
        while (j >= 0 && nxt[j].first > quer[i].r)
        {
            upd(0, 0, n - 1, nxt[j].second);

            j --;
        }
        ans[quer[i].idx] = query(0, 0, n - 1, quer[i].l, quer[i].r);
    }
    for (int i = 0; i < q; ++i)
    {
        cout << ans[i] << '\n';
    }
    return 0;
}


Measured memory_bytes: 23472
#include<bits/stdc++.h>
using namespace std;
int gcd(int a, int b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
  
// Function to find gcd of array of 
// numbers 
int findGCD(int a,int b,int c) 
{ 
    int arr[3];
    arr[0]=a;
    arr[1]=b;
    arr[2]=c;
    int result = arr[0]; 
    for (int i = 1; i < 3; i++) 
        result = gcd(arr[i], result); 
  
    return result; 
} 
int main()
{
     long long int p,sum=0;
     cin>>p;
     for(int i=1;i<=p;i++)
     {
      for(int j=1;j<=p;j++)
      {
        for(int k=1;k<=p;k++)
        {
          sum = sum+findGCD(i,j,k);
        }
      }
     }
     cout<<sum<<endl;







}

Measured memory_bytes: 3636
#include <algorithm>
#include <list>
#include <cmath>
#include <cassert>
#include <deque>
#include <iostream>
#include <vector>
#include <iomanip>
#include <set>
#include <queue>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>

using namespace std;

typedef int64_t ll;
typedef long double ld;
typedef pair<int, int> pii;

const int SZ = 200000 + 100;
const ll MOD = 1e9 + 7;

ll n, k;
ll ans;

ll sqr(ll val) {
    return (val * val) % MOD;
}

ll power(ll val, ll step) {
    if (step == 0) return 1ll;
    return (step % 2 == 0 ?  sqr(power(val, step / 2)) :
                             sqr(power(val, step / 2)) * val ) % MOD;
}

ll x[SZ];
ll y[SZ];

int solve() {
    cin >> n >> k;
    k = min(k, n - 1);

    x[0] = 1;
    for (ll i = 1; i <= (n - 1); ++i) {
        x[i] = x[i - 1];
        x[i] = (x[i] * (n - i)) % MOD;
        x[i] = (x[i] * power(i, MOD - 2) ) % MOD;
    }

    y[0] = 1;
    for (ll i = 1; i <= n; ++i) {
        y[i] = y[i - 1];
        y[i] = (y[i] * (n - i + 1)) % MOD;
        y[i] = (y[i] * power(i, MOD - 2) ) % MOD;
    }

    ll ans = 0;
    for (ll i = 0; i <= k; ++i) {
        ans += x[i] * y[i];
        ans %= MOD;
    }
    while (ans < 0) ans += MOD;
    cout << ans << endl;

    return 0;
}

int main() {
    ios_base::sync_with_stdio(false);

    //freopen("input.txt", "r", stdin);

    solve();

    return 0;
}


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

struct Tscore {
    int t_id;
    int AC_num;
    int penalty;
    int WA_num[11];

    Tscore(int id) {
        t_id = id;
        AC_num = 0;
        penalty = 0;
        for (int i = 0; i < 11; i++) WA_num[i] = 0;
    }

    bool operator < (const Tscore& right) const {
        if (AC_num == right.AC_num) {
            if (penalty == right.penalty) {
                return t_id < right.t_id; // ???????????????????°??????????
            }
            return penalty < right.penalty; // ??????????????£????°??????????
        }

        return AC_num > right.AC_num; // ??£?§£??°????????????
    }
};

int main(void) {

    int T, P, R;
    while (cin >> T >> P >> R, T||P||R) {
        vector<Tscore> teams;
        for (int i = 0; i < T; i++) {
            teams.emplace_back(i+1);
        }
        int tID, pID, time;
        string message;
        for (int i = 0; i < R; i++) {
            cin >> tID >> pID >> time >> message;
            if (message == "CORRECT") {
                teams[tID-1].AC_num++;
                teams[tID-1].penalty += teams[tID-1].WA_num[pID]*1200 + time;
            } else {
                teams[tID-1].WA_num[pID]++;
            }
        }

        sort(teams.begin(), teams.end());
        for (int i = 0; i < T; i++) {
            cout << teams[i].t_id << " " << teams[i].AC_num << " " << teams[i].penalty << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3168
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
 
struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};
 
typedef struct node * NodePointer;
 
NodePointer nil;
 
NodePointer listSearch(int key){
  /* your code */
  NodePointer cur;
  
  cur=nil->next;
  while(cur!=nil && cur->key!=key)
   cur=cur->next;   
  return cur;
}
 
void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}
 
void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}
 
void deleteNode(NodePointer t){
  /* your code */
  t->prev->next=t->next;
  t->next->prev=t->prev;}
 
void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}
 
void deleteLast(){
  /* your code */
  //deleteNode((nil->prev));
  NodePointer t;
  t=nil->prev;
  deleteNode(t);
}
 
void delete(int key){
  /* your code */
  NodePointer t;
  t=listSearch(key);
  if(t==nil) return;
  deleteNode(t);
         
}
 
 
void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
 
     
   x->next=nil->next;
   nil->next->prev=x;
   nil->next=x;
   x->prev=nil;
  /*
 
   your code
 
 
  */
 
}
 
int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
    if ( com[6] == 'F' ) deleteFirst();
    else if ( com[6] == 'L' ) deleteLast();
      } else {
    delete(key); nd++;
      }
      size--;
    }
  }
 
  printList();
  return 0;
}

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

using namespace std;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define INF 1e9  //
#define INFLL 4e18  //
#define MOD (1e9)+7
#define MP make_pair

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

// a 0x61  z 0x7a  0 0x30

//------------------------------------------------------

int main() {
    int h, w;
    cin >> h >> w;
    string s[h];
    rep(i, h) cin >> s[i];

    rep(i, w + 2) cout << '#';
    cout << endl;

    rep(i, h) cout << '#' << s[i] << '#' << endl;

    rep(i, w + 2) cout << '#';
    cout << endl;

    return 0;
}

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

using namespace std;

#define sz(x) (int) x.size()
#define all(a) a.begin(), a.end()

int n;
vector<pair<int, int>> v;
int mn = 1e9 + 123, mx = -1;

long long calc1() {
    long long red = mx - mn;

    vector< pair<int, int> > blues;
    for (int i = 0; i < n; i++) {
        int from = v[i].second, to = v[i].first;
        blues.push_back({from, to});
    }
    sort(all(blues));

    long long result = 1ll * red * (blues.back().first - blues[0].first);

    long long convertedMin = blues[0].second;
    long long convertedMax = blues[0].second;
    for (int i = 0; i < n; i++) {
        convertedMin = min(convertedMin, 1ll * blues[i].second);
        convertedMax = max(convertedMax, 1ll * blues[i].second);
        long long l = convertedMin;
        long long r = convertedMax;
        if (i + 1 < n) {
            l = min(l, 1ll * blues[i + 1].first);
            r = max(r, 1ll * blues.back().first);
        }
        result = min(result, 1ll * red * (r - l));
    }

    return result;
}

long long f(long long r) {
    long long redFrom = mn, redTo = r;
    long long blueFrom = mx, blueTo = mx;

    for (int i = 0; i < sz(v); i++) {
        long long from = v[i].second, to = v[i].first;
        if (from >= redFrom && from <= redTo) {
            blueFrom = min(blueFrom, to);
        } else {
            blueFrom = min(blueFrom, from);
        }
    }

    return 1ll * (redTo - redFrom) * (blueTo - blueFrom);
}

long long calc2() {
    long long l = mn, r = mx;

    for (int i = 0; i < sz(v); i++) {
        long long from = v[i].second;
        if (from == mn) {
            continue;
        }
        l = max(l, from);
    }

    while (r - l > 5) {
        long long mid1 = l + (r - l) / 3;
        long long mid2 = r - (r - l) / 3;
        if (f(mid1) < f(mid2)) {
            r = mid2;
        } else {
            l = mid1;
        }
    }

    long long result = f(l);
    while (l != r) {
        result = min(result, f(l));
        l++;
    }
    return result;
}

int main() {

    scanf("%d", &n);

    for (int i = 0; i < n; i++) {
        int from, to;
        scanf("%d %d", &from, &to);
        if (from > to) {
            swap(from, to);
        }

        mn = min(mn, from);
        mx = max(mx, to);
        v.push_back({to, from});
    }

    sort(all(v));

    // cerr << calc1() << " " << calc2() << endl;
    cout << min(calc1(), calc2()) << endl;

    return 0;
}


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

int main(){
    int n,m,c;
    cin >> n >> m >> c;
    int b[m];
    for(int i=0;i<m;i++){
        cin >> b[i];
    }   
    int a[m];
    int ans = 0;
    int p;
    for(int i=0;i<n;i++){
        p = 0;
        for(int j = 0;j<m;j++){
            cin >> a[j];
        }   
        for(int j = 0;j<m;j++){
            p = p + a[j]*b[j];
        }   
        if(p + c > 0){ 
            ans++;
        }   
    }   
    cout << ans << endl;
}


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

int main()
{
   ll n,m;
   cin>>n>>m;
   if( n==2 || m== 2)
       cout<<0;
   else
   {
       if( n!= 1)
           n = n-2;
       if( m!= 1)
       {
           m = m-2;
       }
       ll ans = n*m;
       cout<<ans;
   }

}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define per(i, a, b) for(int i=(b)-1; i>=(a); i--)
#define sz(a) (int)a.size()
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define all(a) a.begin(), a.end()
#define pw(x) (1ll<<(x))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef double db;

void file_put() {
    freopen("filename.in", "r", stdin);
    freopen("filename.out", "w", stdout);
}

const int N=1e5+5;
const ll oo=1ll<<62;
int n,a[N],k; ll s[N],pre[N],suf[N],ret=-oo;;

int main() {
//	file_put();
	
	scanf("%d%d",&n,&k);
	rep(i,1,n+1) scanf("%d",&a[i]),s[i]=s[i-1]+a[i];
	rep(i,1,n+1) pre[i]=pre[i-1]+a[i]*(a[i]>0);
	per(i,1,n+1) suf[i]=suf[i+1]+a[i]*(a[i]>0);
	rep(i,1,n-k+2) ret=max(ret,pre[i-1]+suf[i+k]+max(s[i+k-1]-s[i-1],0ll));
	printf("%lld\n",ret); 
	
	return 0;
}



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

int main() {
  int N,Y;
  cin>>N>>Y;
  bool a=true;
  for (int i=0;i<=N;i++) {
    for (int j=0;j<=N;j++) {
      int k=N-i-j;
        if (10000*i+5000*j+1000*k==Y && k>=0) {
          cout <<i<<' '<<j<<' '<<k<<' '<<endl;
          a=false;
          i+=3000,j+=3000,k+=3000;
        }
    }
  }
  if(a) cout <<-1<<' '<<-1<<' '<<-1<<' '<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;
int mod = 1e9 + 7;

int main(void)
{
    int a[3], b[3];
    bool x = false, y = false, z = false, d = false, e = false, f = false;
    for (int i = 0; i < 3;i++){
            cin >> a[i] >> b[i];
            if(a[i]==1&&b[i]==3)
                x = true;
                if(b[i]==1&&a[i]==3)
                x = true;
                if(a[i]==2&&b[i]==3)
                y = true;
                if(a[i]==3&&b[i]==2)
                y = true;
                if(a[i]==2&&b[i]==4)
                z = true;
                if(a[i]==4&&b[i]==2)
                z = true;
                if(a[i]==1&&b[i]==2)
                d = true;
                if(a[i]==2&&b[i]==1)
                d = true;
                if(a[i]==2&&b[i]==3)
                e = true;
                if(a[i]==3&&b[i]==2)
                e = true;
                if(a[i]==3&&b[i]==4)
                f = true;
                if(a[i]==4&&b[i]==3)
                f = true;
    }
    if(x==true&&y==true&&z==true)
        cout << "YES" << endl;
        else if(d==true&&e==true&&f==true)
            cout << "YES" << endl;
            else
                cout << "NO" << endl;
            return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define vite ios_base::sync_with_stdio(false); cin.tie(NULL);
#define tst lli T; cin>>T; while(T--)
#define mod 1000000007
#define MAX 1e9
#define MIN -1e9
#define lli long long int
#define vt vector
#define pb push_back
int main()
{
	vite;
	lli a, b, n,t=0;
	cin >> a >> b >> n;
	for (lli i = a; i <= b;i++)
	{
		if(i%n==0)
			t++;
	}
	cout << t;
	// cout<< endl <<fixed << 1.0 * clock() / CLOCKS_PER_SEC << setprecision(5);
	return 0;
}

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

int main()
{
  string w;
  cin >> w;
  vector<int> cnt('a' + 26);
  for (auto x : w)
    ++cnt[x];
  for (auto x : cnt)
  {
    if (0 != x%2)
    {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
  return 0;
}


Measured memory_bytes: 256
n,m = map(int,input().split())
s = []
c = []
for i in range(m):
    val1,val2 = map(int,input().split())
    s.append(val1)
    c.append(val2)

for i in range(1000):
    if len(str(i)) == n:
        flg = True
        for j in range(m):
            if int(str(i)[s[j] - 1]) != c[j]:
                    flg = False
        if flg:
            print(i)
            break
if not flg:
    print(-1)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <cstdlib>
typedef long long int lld;
const lld mod = 998244353;
const int lim = 5000;
lld texp[lim+1];
lld fact[lim+1];
lld inv[lim+1];
lld myexp(lld x, lld y)
{
    if(!y) return 1;
    if(y%2) return (x * myexp(x*x % mod, y>>1) % mod);
    return myexp(x*x%mod, y>>1);
}
lld binom(int n, int r)
{
    if( r < 0 || r > n) return 0;
    return fact[n] * (inv[r] * inv[n-r] % mod ) % mod;
}
lld H(int n, int r){
    return binom(n+r-1, r);
}

int main()
{
    texp[0] = 1;
    for(int i=1;i<=lim;i++)
        texp[i] = texp[i-1] * 2 % mod;
    fact[0] = 1;
    for(int i=1;i<=lim;i++)
        fact[i] = i * fact[i-1] % mod;
    inv[lim] = myexp(fact[lim], mod-2);
    for(int i=lim-1;i>=0;i--)
        inv[i] = (i+1) * inv[i+1] % mod;

    lld k, n;
    lld tmp = 0;
    scanf("%lld%lld", &k, &n);
    for(int i=2;i<=2*k;i++)
    {
        lld ans = 0;
        int cnt = 0;
        int mid = (i % 2 == 0);
        for(int j=1;j<=k;j++)
        {
            if(i-j <= k && i-j > 0 && j < i-j) cnt++;
        }
        for(int j=0;j<=cnt;j++)
        {
            if(!mid)
            {
                tmp = binom(cnt, j) * texp[j] % mod;
                tmp = tmp * H(k-2*cnt+j, n-j) % mod;
                ans = (ans + tmp) % mod;
            }
            else
            {
                tmp = binom(cnt, j) * texp[j] % mod;
                ans = (ans + tmp * H(k-2*cnt-1+j, n-j)) % mod;
                ans = (ans + tmp * H(k-2*cnt-1+j, n-j-1)) % mod;
            }
        }
        printf("%lld\n", ans%mod);
    }
}

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

int main() {
    int N;
    cin >> N;
    vector<int> H(N);
    for (int i=0;i<N;i++) cin>>H.at(i);
    int Hmax = 0;
    int n = 0;
    for (int i=0;i<N;i++) {
        if (H.at(i)>=Hmax){
            n++;
            Hmax = H.at(i);
        }
    }
    cout << n << endl;
    
    
    
    
    
    
//    int A,B;
//    cin >> A >> B;
//    int c;
//    if (A==B) c=2*A;
//    else if (A>B) c=2*A-1;
//    else c=2*B-1;
//    cout << c << endl;
    
    
    
//    vector<int> a(M);
//    vector<int> b(M);
//    vector<int> n(N);
    
//    for (int i=0;i<M;i++) cin>>a.at(i)>>b.at(i);
//    for (int i=0;i<N;i++) {
//        n.at(i) = 0;
//        for (int j=0;j<M;j++){
//            if (a.at(j)==i+1) n.at(i)++;
//            if (b.at(j)==i+1) n.at(i)++;
//        }
//        cout << n.at(i) << endl;
//    }
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (N, M) = readInputLine().split(" ").map{it.toInt()}
    
    if (N >= M) {
        println(0)
        return
    }
    
    val Xs = readInputLine().split(" ").map{it.toInt()}.toIntArray()
    Xs.sort()
    
    val L = mutableListOf<Int>()
    
    for (i in 1 until M) {
        L.add(Xs[i] - Xs[i - 1])
    }
    
    L.sortDescending()

    println(Xs[M - 1] - Xs[0] - L.take(N - 1).sum())
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 51904
#include<stdio.h>
int main(void){
	
	int n,a,b,c,d;
	int ans;

	while(scanf("%d", &n) != EOF){
		ans=0;
		for(a=0; a<10; a++){
			for(b=0; b<10; b++){
				for(c=0; c<10; c++){
					for(d=0; d<10; d++){
						if(a+b+c+d == n) ans++;
					}
				}
			}
		}
	printf("%d\n",ans); 
	}


}


Measured memory_bytes: 2064
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>
#define MAXN 100005
#define INF 0x3f3f3f3f
#define rint register int
#define LL long long
#define LD long double
using namespace std;

int n, m, cnt, head[MAXN], f[MAXN], ans[MAXN];
vector<int> vec[MAXN], l[MAXN], r[MAXN];

void dfs1(int x, int fa)
{
	f[x] = 1;
	for(rint i = 0; i < vec[x].size(); ++i)
	{
		int to = vec[x][i];
		if(to == fa) continue;
		dfs1(to, x);
		f[x]= 1LL * f[x] * (f[to]+1) % m;
	}
}

void dfs2(int x, int fa, int val)
{
	ans[x] = 1LL * f[x] * (val + 1) % m;
	l[x].resize(vec[x].size());
	r[x].resize(vec[x].size());
	for(rint i = 0; i < vec[x].size(); ++i)
	{
		if(i == 0) l[x][i] = 1;
		else
		{
			if(vec[x][i - 1] == fa) l[x][i] = l[x][i - 1];
			else l[x][i] = 1LL * l[x][i - 1] * (f[vec[x][i - 1]] + 1) % m;
		}
	}
	for(rint i=vec[x].size()-1; i >= 0; --i)
	{
		if(i == vec[x].size() - 1) r[x][i] = 1;
		else
		{
			if(vec[x][i + 1] == fa) r[x][i] = r[x][i + 1];
			else r[x][i] = 1LL * r[x][i + 1] * (f[vec[x][i + 1]] + 1) % m;
		}
	}
	//printf("%d %d %d!!\n", x, fa, val);
	for(rint i = 0; i < vec[x].size(); ++i)
	{
		int to = vec[x][i];
		if(to == fa) continue;
		//printf("%d %d %d!!!\n", to, l[x][i], r[x][i]);
		dfs2(to, x, 1LL * (val + 1) * l[x][i] % m * r[x][i] % m);
	}
}

int main()
{
	scanf("%d%d", &n, &m);
	for(rint i = 1, x, y; i < n; ++i)
	{
		scanf("%d%d", &x, &y);
		vec[x].push_back(y);
		vec[y].push_back(x);
	}
	dfs1(1, 0);
	dfs2(1, 0, 0);
	for(rint i = 1; i <= n; ++i) printf("%d\n", ans[i]);
	return 0;
}

Measured memory_bytes: 24320
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=300005;
const ll INF=1LL<<60;

string S;
map<char,int> to;
vector<pair<int,int>> cnt(62);
int L=0,sum=0;
vector<char> ans;
vector<int> ok;

void DFS(int l,int r,int i,int rem){
    if(!rem) return;
    if(r-l<=0) return;
    int t=0;
    for(int j=l;j<r;j++){
        if(!ok[j]) t++;
    }
    if(t==rem){
        for(int j=l;j<r;j++){
            if(!ok[j]){
                ok[j]=1;
                ans[j]=S[cnt[i].se];
            }
        }
        return;
    }
    
    string Q;
    for(int j=0;j<L;j++) Q+=S[cnt[0].se];
    
    int tt=0;
    for(int j=l;j<r;j++){
        if(!ok[j]){
            tt++;
            Q[j]=S[cnt[i].se];
        }
        
        if(tt==t/2){
            cout<<"? "<<Q<<endl;
            int x;cin>>x;
            x=L-x;
            x-=cnt[0].fi;
            if(x){
                DFS(l,j+1,i,x);
            }
            int y=rem-x;
            if(y){
                DFS(j+1,r,i,y);
            }
            break;
        }
    }
    
}

int main(){
    
    for(char a='a';a<='z';a++) S+=a;
    for(char a='A';a<='Z';a++) S+=a;
    for(char a='0';a<='9';a++) S+=a;
    
    for(int i=0;i<si(S);i++) to[S[i]]=i;
    
    for(int i=0;i<62;i++){
        cout<<"? ";
        for(int j=0;j<128;j++){
            cout<<S[i];
        }
        cout<<endl;
        cin>>cnt[i].fi;
        cnt[i].fi=128-cnt[i].fi;
        L+=cnt[i].fi;
        cnt[i].se=i;
    }
    
    sort(all(cnt),[](auto a,auto b){
        return a.fi>b.fi;
    });
    
    ans.resize(L);
    ok.resize(L);
    
    for(int i=0;i<L;i++){
        cout<<"? ";
        for(int j=0;j<L;j++){
            if(i==j) cout<<S[cnt[0].se];
            else cout<<S[cnt[61].se];
        }
        cout<<endl;
        
        int x;cin>>x;
        x=L-x;
        if(x==cnt[61].fi+1){
            ans[i]=S[cnt[0].se];
            ok[i]=1;
            sum--;
        }
    }
    
    for(int i=1;i<62;i++){
        if(cnt[i].fi==0) continue;
        
        DFS(0,L,i,cnt[i].fi);
    }
    
    cout<<"! ";
    for(int i=0;i<L;i++) cout<<ans[i];
    cout<<endl;
    
}




Measured memory_bytes: 3800
#include <bits/stdc++.h>
#define LL long long
#define mem(i, j) memset(i, j, sizeof(i))
#define rep(i, j, k) for(int i = j; i <= k; i++)
#define dep(i, j, k) for(int i = k; i >= j; i--)
#define pb push_back
#define make make_pair
#define INF INT_MAX
#define inf LLONG_MAX
#define PI acos(-1)
using namespace std;

const int N = 2e4 + 5, up = 4000;

char a[N], b[N], c[N];
bool ab[N], ac[N], bc[N];

int main() {
    scanf("%s", a);
    scanf("%s", b);
    scanf("%s", c);
    int lena = strlen(a);
    int lenb = strlen(b);
    int lenc = strlen(c);

    rep(i, 0, lena - 1) rep(j, 0, lenb - 1)
        if(!(a[i] == b[j] || a[i] == '?' || b[j] == '?')) ab[i - j + up] = 1;
    rep(i, 0, lena - 1) rep(j, 0, lenc - 1)
        if(!(a[i] == c[j] || a[i] == '?' || c[j] == '?')) ac[i - j + up] = 1;
    rep(i, 0, lenb - 1) rep(j, 0, lenc - 1)
        if(!(b[i] == c[j] || b[i] == '?' || c[j] == '?')) bc[i - j + up] = 1;

    int ans = INF;

    rep(i, -4000, 4000) rep(j, -4000, 4000)
        if(!ab[i + up] && !ac[j + up] && !bc[j - i + up]) {
            int L = min({0, i, j});
            int R = max({lena, lenb + i, lenc + j});
            ans = min(ans, R - L);
        }

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

    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
using namespace std;
int main(){
  string s;
  cin >> s;
  int cnt = 0;
  for(int i = 0; i < s.size() / 2; i++){
    if(s[i] != s[s.size() - 1 - i]) cnt++;
  }
  cout << cnt << endl;
}

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

    int a = s[0] - '0' ;
    int b = s[1] - '0' ;
    int c = s[2] - '0' ;
    int d = s[3] - '0' ;

    //cout << a - b - c +d << endl ;


    if(a + b + c + d == 7)
    {
        cout << a << "+" << b << "+" << c << "+" << d  ;

    }
    else if(a + b + c - d == 7)
    {
        cout << a << "+" << b << "+" << c << "-" << d  ;

    }
   else  if(a - b - c + d == 7)
    {
        cout << a << "-" << b << "-" << c << "+" << d  ;

    }
    else if(a - b + c + d == 7)
    {
        cout << a << "-" << b << "+" << c << "+" << d  ;

    }
    else if(a + b - c - d == 7)
    {
        cout << a << "+" << b << "-" << c << "-" << d  ;

    }
    else if(a - b + c - d == 7)
    {
        cout << a << "-" << b << "+" << c << "-" << d  ;

    }
    else if(a - b - c - d == 7)
    {
        cout << a << "-" << b << "-" << c << "-" << d  ;

    }
    else if(a + b - c + d == 7)
    {
        cout << a << "+" << b << "-" << c << "+" << d  ;
    }

    cout << "=7" << endl ;



}


Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        #[allow(unused_mut)]
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        pay_value: i32,
        unlike_number_count: i32,
        unlike_numbers: [i32; unlike_number_count],
    };
    println!("{}", solve(pay_value, unlike_numbers));
}

fn solve(pay_value: i32, unlike_numbers: Vec<i32>) -> String {
    // write solution here
    let mut value = pay_value;
    loop {
        let mut temp_value = value;
        let mut flag = true;
        while temp_value > 0 {
            if unlike_numbers.contains(&(temp_value % 10)) {
                flag = false;
            }
            temp_value /= 10;
        }
        if flag {
            return format!("{}", value)
        }
        value += 1;
    }
}


Measured memory_bytes: 4352
// #include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <limits.h>
#include <string>
#include <stack>
#include <deque>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <time.h>
#include <cassert>
#include <fstream>
#include <stdio.h>
#include<unordered_map>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mapa make_pair
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

template<typename T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }
template<typename T>
void vdeb(std::vector<T> &da) {
	for (int i = 0;i < da.size();i++) {
		if (i == da.size() - 1) std::cout << da[i];
		else std::cout << da[i] << ' ';
	}
	std::cout << std::endl;
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
	for (int i = 0;i < da.size();i++) vdeb(da[i]);
	std::cout << std::endl;
}

using namespace std;

int main(){
	int n,t; cin >> n >> t;
	vector<int> da(n);
	rip(i,n,0) cin >> da[i];
	int k = 0, ma = 0;
	for(int i = n-1;i>-1;i--){
		chmax(ma, da[i]);
		chmax(k, ma-da[i]);
	}
	int ans = 0;
	ma = 0;
	for(int i = n-1;i>-1;i--){
		chmax(ma, da[i]);
		if(ma - da[i] == k) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>
int main(void){
  char S[11000];
  scanf("%s",S);
  int len;
  len = strlen(S);
  if(S[len-1]=='s'){
    S[len]='e';
    S[len+1]='s';
  }
  else{
    S[len]='s';
  }
  printf("%s",S);
  return 0;
}

Measured memory_bytes: 1736
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
vvi cnt(30);
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll ans=0;
  string s,t;cin>>s>>t;
  ll n=s.size(),m=t.size();
  ll kuri=0;
  for(int i=0;i<n;i++)
    cnt[s[i]-'a'].pb(i);
  for(int i=0;i<30;i++){
    cnt[i].pb(llINF);
  }
  ll now=-1;
  for(int i=0;i<m;i++){
    char c=t[i];
    if(cnt[c-'a'].size()==1){cout<<-1<<endl;return 0;}
    if(cnt[c-'a'][cnt[c-'a'].size()-2]>now){
      auto lb=upper_bound(ALL(cnt[c-'a']),now);
      now=*lb;
    }else{
      kuri++;
      now=cnt[c-'a'][0];
    }
  }
  cout<<now+n*kuri+1<<endl;
  return 0;
}


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

int main()
{

        int A, B, C, D;
        cin >> A >> B >> C >> D;

        while (1) {

                C -= B;

                if (C <= 0) {
                        cout << "Yes" << endl;
                        exit(0);
                }

                A -= D;

                if (A <= 0) {
                        cout << "No" << endl;
                        exit(0);
                }
        }




}


Measured memory_bytes: 3636
/* ファイル名：ITP1_5_D.c	*/
/* 内容：次のC++言語のプログラムと同じ動作をする(goto文は使わないように)	*/
/*void call(int n){							*/
/*  int i = 1;                              */
/* CHECK_NUM:                               */
/*  int x = i;                              */
/*  if ( x % 3 == 0 ){                      */
/*    cout << " " << i;                     */
/*    goto END_CHECK_NUM;                   */
/*  }                                       */
/* INCLUDE3:                                */
/*  if ( x % 10 == 3 ){                     */
/*    cout << " " << i;                     */
/*    goto END_CHECK_NUM;                   */
/*  }                                       */
/*  x /= 10;                                */
/*  if ( x ) goto INCLUDE3;                 */
/* END_CHECK_NUM:                           */
/*  if ( ++i <= n ) goto CHECK_NUM;         */
/*                                          */
/*  cout << endl;                           */
/*}                                         */

/* include	*/
#include <stdio.h>

/* 外部変数宣言	*/

/* プロトタイプ宣言	*/

/* 関数名:main	*/
/* 処理内容:1つの整数nが与えられ、1からnまでの3の倍数と3の付く数字を出力する	*/
int main( void )
{
	/* 内部変数定義	*/
	/* 入力	*/
	int n;	/* 入力される変数n	*/
	
	/* 処理	*/
	int i;		/* ループ用兼判定用変数	*/
	int x;		/* 3の付く数字用の判定用変数	*/
	int flag;	/* 3の倍数または3の付く数字かの判定フラグ*/
	
	scanf("%d",&n);	/* nを取得	*/
	
	/* 1からn回だけループ	*/
	for(i = 1; i <= n; i++){
		/* フラグの初期化	*/
		flag = 0;
		
		/* iが3の倍数の場合	*/
		if((i % 3) == 0){
			flag = 1;	/* フラグを立てる	*/
		}
		/* iが3の倍数以外の場合	*/
		else{
			x = i;	/* 3の付く数字化の判定の為に、xにiを代入	*/
			
			while(1){
				/* iが3の付く数字だった場合	*/
				if((x % 10) == 3){
					flag = 1;	/* フラグを立てる	*/
					break;		/* 判定終了	*/
				}
				else{
					/* 処理なし	*/
				}
				
				x = x / 10;		/* xを10で割る(2桁目以降も調べるため)	*/
				
				/* 次の桁が無かった場合	*/
				if(x <= 0){
					break;		/* 判定終了	*/
				}
				else{
					/* 判定続行	*/
				}
			}
		}
		
		/* iが3の倍数または3の付く数字だった場合	*/
		if(flag == 1){
			printf(" %d",i);	/* iをスペースを開けて出力	*/
		}
		else{
			/* 処理なし	*/
		}
	}
	
	printf("\n");
	return 0;
}



Measured memory_bytes: 2120
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

import java.util.*;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        int H = in.nextInt();
        int N = in.nextInt();
        long INF = 1_000_000_000_000_000L;
        int[] A = new int[N];
        int[] B = new int[N];
        long[][] dp = new long[N+1][3*10000+1];
        for (int i=0;i<N+1;i++) {
            for (int j=0;j<3*10000+1;j++) {
                dp[i][j] = INF;
            }
        }
        dp[0][0] = 0;
        for (int i=0;i<N;i++) {
            A[i] = in.nextInt();
            B[i] = in.nextInt();
        }
        for (int i=1;i<N+1;i++) {
            for (int j=0;j<3*10000;j++) {
                if (i-1>=0) {
                    dp[i][j] = Math.min(dp[i][j], dp[i-1][j]);
                }
                if (j-A[i-1]>=0) {
                    dp[i][j] = Math.min(dp[i][j], dp[i][j-A[i-1]]+B[i-1]);
                }
            }
        }

        long ans = INF;
        for (int j=H;j<=H+15000;j++) {
            ans = Math.min(ans, dp[N][j]);
        }
        out.println(ans);

        out.close();
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}


Measured memory_bytes: 317564
#include <iostream>
#include <cmath>
#include <map>
#include <algorithm>

using namespace std;

int main(void){
    map<string, int> blue;
    map<string, int> red;
    int N, M;
    string s;

    cin >> N;
    for(int i=0; i<N; i++){
        cin >> s;
        if(blue.count(s) == 0){
            blue[s] = 1;
        } else {
            blue[s] += 1;
        }
    }     
    
    cin >> M;
    for(int i=0; i<M; i++){
        cin >> s;
        if(red.count(s) == 0){
            red[s] = 1;
        } else {
            red[s] += 1;
        }
    }
    
    int max = 0;
    for(auto item : blue){
        if(blue.count(item.first) != 0){
            int yen = item.second - red[item.first];
            if(yen > max){
                max = yen;
            }
        }
    }

    cout << max;
    return EXIT_SUCCESS;
}

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

int main(){
 ll N,M; cin >> N >> M;
  
  map<ll,ll> mp;
  for(ll i = 0; i < M; i++){
    ll a,b; cin >> a >> b; mp[a]++; mp[b]++;}
  
  for(auto ne: mp){
    if( ne.second % 2 ){ cout << "NO" << endl; return 0;}
  }
  cout << "YES" << endl; return 0;}
    

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

int main() {
  string a;
  
  cin >> a;
  
  if (a == "SUN") {
    cout << "7";
  } else if (a == "SAT") {
    cout << "1";
  } else if (a == "FRI") {
    cout << "2";
  } else if (a == "THU") {
    cout << "3";
  } else if (a == "WED") {
    cout << "4";
  } else if (a == "TUE") {
    cout << "5";
  } else if (a == "MON") {
    cout << "6";
  }   
      
  return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

int result[501][501];

void solve(const vector<int>& ps, int v) {
	if (ps.size() <= 1) return;

	if (ps.size() == 2) {
		result[ps[0]][ps[1]] = v + 1;
		result[ps[1]][ps[0]] = v + 1;
		return;
	}
	
	vector<int> ms(ps.size());
	FOR_LT(i, 0, ms.size()) {
		ms[i] = i & 1;
	}

	FOR_LT(i, 0, ps.size()) {
		FOR_LT(j, 0, ps.size()) {
			if (ms[i] != ms[j]) {
				result[ps[i]][ps[j]] = v + 1;
				result[ps[j]][ps[i]] = v + 1;
			}
		}
	}

	vector<int> ps0;
	vector<int> ps1;
	FOR_LT(i, 0, ps.size()) {
		if (ms[i] == 0) ps0.push_back(ps[i]);
		if (ms[i] == 1) ps1.push_back(ps[i]);
	}
	solve(ps0, v + 1);
	solve(ps1, v + 1);
}

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

	int n; cin >> n;

	vector<int> ps(n);
	FOR_LT(i, 0, n) {
		ps[i] = i;
	}

	solve(ps, 0);

	FOR_LT(i, 0, n) {
		FOR_LT(j, i + 1, n) {
			cout << result[i][j] << " ";
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1536
Flag = True
data = []
while Flag:
    H, W = map(int, input().split())
    if H == 0 and W == 0:
        Flag = False
    else:
      data.append((H, W))
#print(type(W))
for (H, W) in data:
    for i in range(H):
        if i == 0 or i == H-1:
            print('#' * W)
        else:
            print('#' + '.' * (W-2) + '#')
    print('\n', end="")


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

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<double, double> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<string> &o) {
    string a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {
    int a, b, c;
    cin >> a >> b >> c;

    bool ok = (a < c && c < b) || (a > c && c > b);
    string ans = ok ? "Yes" : "No";
    cout << ans << endl;

}


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

using namespace std;

int coin1[501][501]={};//coin[H][W];(y,x)
int coin2[501][501]={};
int c=0;
void Rprint(int y,int x){

    cout <<y <<" "<<x<<" "<<y<<" "<<x+1<<endl;
}

void Uprint(int y,int x){

    cout <<y<<" "<<x<<" "<<y+1<<" "<<x<<endl;
}

void search2 (int y ,int x,int H, int W){
    //迷路の外側か壁なら何もしない
    if ( coin2[y][x]%2==0)return;
    
    else if(x==W &&y==H)return;

    else if(x==W){
        coin2[y+1][x]++;
        Uprint(y,x);
    }
    else{
        coin2[y][x+1]++;
        Rprint(y,x);
    }
}

void search1 (int y ,int x,int H, int W){
    if(x==W &&y==H){
        cout <<c<<endl;
    }
    
    //偶数なら何もしない
    else if ( coin1[y][x]%2==0)return;
    

    else if(x==W){
        coin1[y+1][x]++;
        c++;
    }
    else{
        coin1[y][x+1]++;
        c++;
    }
}


int main(){
int H,W;
cin >>H>>W;

for(int i=1;i<=H;i++){
    for(int l=1;l<=W;l++){
        cin >>coin1[i][l];
        coin2[i][l]=coin1[i][l];
    }
}

//左下から初めて右上に追い込んでいく
for(int i=1;i<=H;i++){
    for(int l=1;l<=W;l++){
        search1(i,l,H,W);
    }
}
for(int i=1;i<=H;i++){
    for(int l=1;l<=W;l++){
        search2(i,l,H,W);
    }
}


 return 0;
}

Measured memory_bytes: 4096
#include<cstdio>
#include<cstdlib>
#include<cstring>

struct Node{
	int key;
	Node *next, *prev;
};

Node *nil;

Node* listSearch(int key){
	Node *cur = nil->next; //番兵の次の要素から辿る
	while ( cur != nil && cur->key != key ){
		cur = cur->next;
	}
	return cur;
}

void init(){
	nil=(Node *)malloc(sizeof(Node));
	nil->next = nil;
	nil->prev = nil;
}

void printList(){
	Node *cur = nil->next;
	int isf = 0;
	while(1){
		if( cur== nil) break;
		if( isf++ >0 ) printf(" ");
		printf("%d",cur->key);
		cur = cur->next;
	}
	printf("\n");
}

void deleteNode(Node *t){
	if( t ==nil ) return; //tが番兵の場合は処理しない
	t->prev->next = t->next;
	t->next->prev = t->prev;
	free(t);
}

void deleteFirst(){
	deleteNode(nil->next);
}

void deleteLast(){
	deleteNode(nil->prev);
}

void deleteKey(int key){
	//検索したノードを削除
	deleteNode(listSearch(key));
}

void insert(int key){
	Node *x = (Node *)malloc(sizeof(Node));
	x->key = key;
	//番兵の直後に要素を追加
	x->next = nil->next;
	nil->next->prev = x;
	nil->next = x;
	x->prev = nil;
}

int main(){
	int key,n,i;
	int size = 0;
	char com[20];
	int np = 0, nd =0;
	scanf("%d",&n);
	init();
	for( i=0; i<n; i++){
		scanf("%s%d", com, &key); //より高速な入力関数を使用
		if( com[0] == 'i'){ insert(key); np++; size++; }
		else if ( com[0] == 'd'){
			if( strlen(com) > 6){
				if ( com[6] == 'F' ) deleteFirst();
				else if (com[6] == 'L') deleteLast();
			}else{
				deleteKey(key); nd++;
			}
			size--;
		}
	}
	
	printList();
	
	return 0;
}




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

using namespace std;

int main(){
    int H,W,K,ans=0;
    cin >> H >> W >> K;
    vector<string> c(H);
    for(int i=0;i<H;i++){
        cin >> c[i];
    }

    for(int i=0;i<pow(2,H);i++){
        for(int j=0;j<pow(2,W);j++){

            int tmp = 0;

            vector<string> cop;

            cop = c;

            for(int k=0;k<H;k++){
                if(i>>k & 1 == 1){
                    for(int n=0;n<W;n++){
                        cop[k][n] = '.';
                    }
                }
            }

            for(int k=0;k<W;k++){
                if(j>>k & 1 == 1){
                    for(int n=0;n<H;n++){
                        cop[n][k] = '.';
                    }
                }
            }

            for(int k=0;k<H;k++){
                for(int n=0;n<W;n++){
                    if(cop[k][n]=='#'){
                        tmp++;
                    }
                }
            }

            if(tmp==K){
                ans++;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 4104
XN = list(map(int, input().split()))

if (XN[1] == 0):
    print(XN[0])
    exit()

P = list(map(int, input().split()))
bucket = [0] * 100
for i in range(XN[1]):
    bucket[P[i] - 1] = 1

#正方向
pcounter = 0
for i in range(XN[0], 101):
    if (i == 101):
        break
    if (bucket[i - 1] == 0):
        break
    pcounter += 1

#負方向
mcounter = 0
for i in range(XN[0], -1, -1):
    if (i == 0):
        break
    if (bucket[i - 1] == 0):
        break
    mcounter += 1


if (pcounter >= mcounter):
    print(XN[0] - mcounter)
else:
    print(XN[0] + pcounter)

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

int main(){
	int N, M; cin >> N >> M;
	vector<int> s(M), c(M);

	for(int i = 0; i < M; ++i){
	 cin >> s[i] >> c[i];
	 s[i]--;
	}

	vector<int> ans(N, 100);
	/*
	for(int i = 0; i < N; ++i){
		cout << ans[i] << " ";
	}cout << endl;
	*/

	for(int i = 0; i < M; ++i){
		if(ans[s[i]] != 100 && ans[s[i]] != c[i]){
			cout << "-1" << endl;
			return 0;
		}
		ans[s[i]] = (ans[s[i]] > c[i]) ? c[i] : ans[s[i]];
	}

	/*
	for(int i = 0; i < N; ++i){
		cout << ans[i] << " ";
	}cout << endl;
	*/

	if(N == 1 && (ans[0] == 0 || ans[0] == 100)) {
		cout << "0" << endl;
		return 0;
	}

	if(ans[0] == 0) {
		cout << "-1" << endl;
		return 0;
	}

	if(ans[0] == 100){
		ans[0] = 1;
	}
	/*
	int ind = 0;
	while(ans[ind] == 100){
		ans[ind] = 1;
		ind++;
	}
	*/

	for(int i = 0; i < N; ++i){
		if(ans[i] == 100) cout << "0";
		else cout << ans[i];
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<ctype.h>
#include<string.h>

int main()
{
  char str[1000]={};
  int i;
  int len;

  gets(str);
  len=strlen(str);

  for(i=0;i<len;i++)
    str[i]=toupper(str[i]);

  printf("%s\n", str);
  return 0;
}

Measured memory_bytes: 524
import java.util.*;

public class Main {

    /* チェックリスト
     * intの範囲を超えていないか
     * TLEしそうな処理の有無
     */
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        for(int i = 1; i <= 9;i++){
            if(n % i == 0){
                int a = n / i;
                if(a >= 1 && a <= 9){
                    System.out.println("Yes");
                    System.exit(0);
                }
            }
        }
        System.out.println("No");
    }
}

Measured memory_bytes: 21844
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			long a = sc.nextLong();
			long b = sc.nextLong();
			long x = sc.nextLong();

			if (a == 0) {
				System.out.println(b / x + 1);
			} else {
				System.out.println(b / x - (a - 1) / x);
			}
		}
	}
}

Measured memory_bytes: 22604
import sys
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(100000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


class v:
    def __init__(self, f):
        self.f = f
        self.v = None
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if self.v is None:
            self.v = n
        else:
            self.v = self.f(self.v, n) 


def main():
    import bisect
    N, C = read_values()
    W = read_lists(N)
    W.sort(key=lambda x: x[1], reverse=True)

    R = []
    for s, t, c in W:
        i = bisect.bisect_left(R, (t, -1))

        while i < len(R):
            if R[i][0] != t:
                break
            if R[i][1] == c:
                break
            i += 1

        if i < len(R):
            del R[i]

        bisect.insort(R, (s, c))
    print(len(R))


if __name__ == "__main__":
    main()

Measured memory_bytes: 29124