akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){

  while(x->left != NIL) x=x->left;

  return x;

}

Node treeMaximum(Node x){

  while(x->right != NIL) x=x->right;

  return x;

}

Node treeSearch(Node u, int k){

  if(u == NIL || k == u->key) return u;

  if(k < u->key) return treeSearch(u->left,k);

  else return treeSearch(u->right,k);

}

Node treeSuccessor(Node x){

  if(x->right != NIL) return treeMinimum(x->right);
  Node y = x->parent;
  while(y != NIL && x==y->right){
    x=y;
    y=y->parent;
  }
  return y;

}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if(z->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z);

  if(y->left != NIL) x = y->left;
  else x = y->right;

  if(x != NIL) x->parent = y->parent;

  if(y->parent == NIL) root=x;
  else if(y == y->parent->left) y->parent->left = x;
  else y->parent->right = x;

  if(y!=z) z->key = y->key;

  return y;
    


}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;

  if(y == NIL) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;

}

void inorder(Node u){

  if(u != NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }

}
void preorder(Node u){

  if(u != NIL){
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 20496
use std::io::*;
use std::str::*;

const MOD: i32 = 1000000007;

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

fn main() {
    let mut n: u64 = read().unwrap();
    let org = n;

    let mut sum = 0;
    loop {
        if n < 10 {
            sum += n;
            break;
        }
        sum += n % 10;
        n = n / 10;
    }

    if org % sum == 0 {
        println!("Yes");
        return;
    }
    println!("No");
}


Measured memory_bytes: 4352
#include <iostream>
#include <cmath>
#include<vector>
#include <algorithm>
#include <utility>
#include<stack>
#include<queue>
#include<map>
#include <fstream>

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long

int n,d;
        long long parni[100010],neparni[100010];
        long long x[100010];

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

        int n,tmp;
        cin>>n;
        parni[0]=neparni[0]=0;
        long long sum=0;
        for( int i=1;i<=n;i++ ){
            cin>>tmp;
           // x[i]=tmp;
            sum+=tmp;
            if( i%2==0 ) {
                    parni[i] = parni[i-1] + tmp;
                    neparni[i] = neparni[i-1];
            }
            else {
                    parni[i]=parni[i-1];
                    neparni[i] = neparni[i-1] + tmp;
            }
        }
        long long res;
        for( int i=1;i<=n;i++ ){
         //   res[i] = sum;
         res=sum;
            if( i%2 == 1 )  res-= (2*( parni[n] - parni[i] ) + 2*( neparni[i-1]  ));
            else res -= (2*( neparni[n] - neparni[i] ) + 2*( parni[i-1]  ));
            cout << res << " ";
           // cout<<endl;
          //  cout << i << " " << n << " " << parni[n] - parni[i] << " " << neparni[i-1]<< " " << sum << " " << res <<  endl;
        }
            cout<<endl;
      return 0;
    }



























Measured memory_bytes: 2944
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long lint;


int main(){
   lint a,b;
   cin >> a >> b;
   
   lint x=max(a,b), y=min(a,b),tmp;
   while(y!=0){
      tmp = y;
      y = x%y;
      x = tmp;
   }
   //cout << x << endl;
   cout << a*b/x << endl;
   
   return 0;
}


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

int main()
{
    int n;
    cin >> n;
    int chng,paid = -1;
    for(int i = 1;paid < n; i++){
        paid = i*1000;
        chng = abs(n-paid);
    }

    cout << chng;

    return 0;
}


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


void solve(long long K){
    int res = 0;
    for (int i = 1; i <= K; i++) {
        for (int j = 1; j <= K; j++) {
            for (int k = 1; k <= K; k++) {
                res += __gcd(i, __gcd(j, k));
            }
        }
    }
    cout << res <<endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long K;
    scanf("%lld",&K);
    solve(K);
    return 0;
}


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

using namespace std;
const long long MOD=1e9+7;

int main(){
  long long n, c;
  vector<long long> v;
  cin >> n;
  long long prev=-1;
  for(int i=0;i<n;i++){
    cin >> c;
    if(c!=prev){
      v.push_back(c);
      prev = c;
    }
  }
  if(n==1){
    cout << 1 << endl;
    return 0;
  }
  long long dp[200009];
  map<long long, long long> mp;
  dp[0] = 1;
  mp[v[0]] = 1;
  for(int i=1;i<v.size();i++){
    dp[i] = (mp[v[i]] + dp[i-1])%MOD;
    mp[v[i]] = (dp[i-1]+mp[v[i]])%MOD;
  }
  cout << dp[v.size()-1] << endl;
}



Measured memory_bytes: 18580
a, b = [int(i) for i in input().split()]

import sys
if b == 1:
    print(0)
    sys.exit(0)

count = a
if count >= b:
    print(1)
else:
    ans = 2
    while True:
        count += (a - 1)
        if count >= b:
            print(ans)
            break
        ans += 1


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

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

		int n = scanner.nextInt();

		int [] arr = new int[n*2];

		for (int i = 0; i < n*2; i++) {
			arr[i] = scanner.nextInt();
		}

		Arrays.sort(arr);

		int sum = 0;

		for (int i = 1; i < n*2; i+=2) {
			sum += Math.min(arr[i-1], arr[i]);
		}

		System.out.println(sum);
	}
}


Measured memory_bytes: 22740
import math
import numpy as np
import queue
from collections import deque
import heapq

n = int(input())

if n%10 == 3:
    print("bon")
elif n%10 == 2 or n%10 == 4 or n%10 == 5 or n%10 == 7 or n%10 == 9 :
    print("hon")
else:
    print("pon")


Measured memory_bytes: 27152
#include <iostream>

int main() {
	long long N;
	std::cin >> N;
	if (N % 2LL == 1) {
		std::cout << 0 << std::endl;
	}
	else {
		long long sum = 0LL;
		N /= 2;
		while (N >= 5) {
			sum += (N /= 5LL);
		}
		std::cout << sum << std::endl;
	}
	return 0;
}


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

int main() {
 
    int L,R,d;
    int count = 0;

    cin >> L >> R >> d;

    for(int i=L;i<=R;i++){
        if(i%d == 0){
            count++;
        }
    }

    cout << count << endl;


    return 0;
}

Measured memory_bytes: 3588
def main():
    n = int(input())
    if n % 10 == 3:
        print('bon')
    elif n % 10 == 0 or n % 10 == 1 or n % 10 == 6 or n % 10 == 8:
        print('pon')
    else:
        print('hon')
main()

Measured memory_bytes: 9076
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int gcd(int a, int b) {
    if(b==0) return a;
    return gcd(b, a%b);
}
int main() {
    int a, b, c; cin >> a >> b >> c;
    int x = gcd(a, gcd(b, c));
    a/=x, b/=x, c/=x;
    if(gcd(a, b)==1) cout << "YES";
    else cout << "NO";
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
int dx9[9]={0,1,0,-1,1,-1,1,0,-1};
int dy9[9]={0,1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;
// << fixed << setprecision
// --------------------------------------
int n;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n;
  vector<int> a(n);

  int t = 0;
  REP(i, n) cin >> a[i];

  REP(i, n) if(a[i] == t + 1) t++;

  cout << (t == 0 ? -1 : n - t) << endl;
}


Measured memory_bytes: 3988
using System;

namespace Csharp_ITP1 {
    class ITP1_2_A {
        static void Main() {
            string[] c = Console.ReadLine().Split();
            var a = int.Parse(c[0]);
            var b = int.Parse(c[1]);
            string o = string.Empty;
            if (a < b) {
                o = " < ";
            } else if (a > b) {
                o = " > ";
            } else { o = " == "; }
            Console.WriteLine("a" + o + "b");
        }
    }
}


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

int mod = pow(10,9) + 7;

int main() {
    int h,w;
    cin >> h >> w;
    vector<vector<char>> a(h,vector<char>(w));
    for(int i = 0 ; i < h ;i++){
        for(int j = 0; j < w; j++){
            cin >> a[i][j];
        }
    }
    vector<vector<long long int>> dp(h, vector<long long int> (w,0));
    dp[0][0] = 1;
    int flag1 = 0, flag2 = 0;
    for(int i = 1 ; i < w ; i++){
        if(flag1 == 0 && a[0][i] == '.') dp[0][i] = 1;
        if(a[0][i] == '#') flag1 = 1;
    }
    for(int i = 1 ; i < h ; i++){
        if(flag2 == 0 && a[i][0] == '.') dp[i][0] = 1;
        if(a[i][0] == '#') flag2 = 1;
    }

    for(int i = 1; i < h ; i++){
        for(int j = 1; j < w; j++){
            if(a[i][j] == '.'){
                if(a[i-1][j] == '.') dp[i][j] = (dp[i][j] + dp[i-1][j])%mod;
                if(a[i][j-1] == '.') dp[i][j] = (dp[i][j] + dp[i][j-1])%mod;
            }
            else dp[i][j] = 0;
        }
    }

    cout << dp[h-1][w-1];


    return 0;
}

Measured memory_bytes: 12240
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<pair<long long,long long> > vpll;
typedef vector<vector<pair<ll,ll> > > vvpll;
typedef vector<bool> vb;
typedef vector<vb> vvb;

#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define all(x) x.begin() , x.end()
#define pb push_back
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define left (node << 1)
#define right (node << 1) + 1
#define pii pair<int,int> 
#define mii map<int,int>
#define vi vector<int>
#define umii unordered_map<int,int>
#define mod 998244353
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<": " <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl

#define repo(i,o,e) for(int i = o ; i < e ; i++)
#define rep(n) for(int i = 0 ; i < n ; i++)
const ll sz = 1e5+5;
//C'mon
void solve(){
	string s;cin >> s;
	int ans = 0 , cnt = 0;
	for(auto &i:s){
		if(i == 'A' or i == 'C' or i == 'G' or i == 'T')cnt++;
		else {
			ans = max(ans,cnt);
			cnt = 0;
		}
	}
  	ans = max(ans,cnt);
	cout << ans;
}

int main(){
    FIO;
    int t = 1;
	//cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
num = int(input())
text = input()
movedText = ""
for i in text:
  if ord(i) + num > ord("z") or ord(i) + num > ord("Z"):
    movedText += chr(ord(i) - 26 + num)
    continue
  movedText += chr(ord(i) + num)
print(movedText)

Measured memory_bytes: 3060
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());

        // 主処理
        boolean judge = 1000 <= n && n <= 1998;
        String result = judge ? "ABD" : "ABC";

        // 出力
        System.out.println(result);
        sc.close();
    }
}


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


int dp(vector<vector<int>>& v, vector<vector<int>>& mem, int n, int pos) {
    if(n == 0) {
        mem[0][pos] = v[0][pos];
        return mem[0][pos];
    }
    if(pos == 0) {
        int x = mem[n-1][1] > -1?mem[n-1][1]: dp(v, mem, n-1, 1);
        int y = mem[n-1][2] > -1?mem[n-1][2]: dp(v, mem, n-1, 2);
        mem[n][0] = v[n][0] + max(x, y);
        return mem[n][0];
    }
    else if(pos == 1) {
        int x = mem[n-1][0] > -1?mem[n-1][0]: dp(v, mem, n-1, 0);
        int y = mem[n-1][2] > -1?mem[n-1][2]: dp(v, mem, n-1, 2);
        mem[n][1] = v[n][1] + max(x, y);
        return mem[n][1];
    }
    else if(pos == 2) {
        int x = mem[n-1][0] > -1?mem[n-1][0]: dp(v, mem, n-1, 0);
        int y = mem[n-1][1] > -1?mem[n-1][1]: dp(v, mem, n-1, 1);
        mem[n][2] = v[n][2] + max(x, y);
        return mem[n][2];
    }
}

int main() {
    int n, a, b, c;
    cin >> n;
    vector<vector<int>> v(n);
    vector<vector<int>> mem(n, vector<int>(3, -1));
    for(int i = 0; i < n; i++) {
        cin >> a >> b >> c;
        v[i].push_back(a);
        v[i].push_back(b);
        v[i].push_back(c);
    }
    int ans = max(dp(v, mem, n-1, 0), dp(v, mem, n-1, 1));
    ans = max(ans, dp(v, mem, n-1, 2));
    cout << ans;
    return 0;
}

Measured memory_bytes: 15872
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, double> pid;
typedef pair<double, int> pdi;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N;
	string S;
	cin >> N >> S;
	int ans = 0;
	rep(i, 0, N - 1)
	{
		vector<int> L(26, 0), R(26, 0);
		rep(j, 0, i + 1)
		{
			L[S[j] - 'a']++;
		}
		rep(j, i + 1, N)
		{
			R[S[j] - 'a']++;
		}
		int res = 0;
		rep(j, 0, 26)
		{
			if (L[j] > 0 && R[j] > 0)
			{
				res++;
			}
		}
		chmax(ans, res);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <typeinfo>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
    ll n, k;

    cin >> n >> k;
    // cout << n << endl;
    n %= k;
    while (true)
    {
        n = abs(n - k);
        if (n <= k / 2)
        {
            break;
        }
    }

    cout << n << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(i,x) for(auto i=(x).begin(); i!=(x).end();i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};

using namespace std;



int main(){
    int n;
    cin>>n;
    vector<int> v(n);
    rep(i,0,n)cin>>v[i];
    int ans=0;
    rep(i,0,n){
        if(v[v[i]-1]-1==i)ans++;
    }
    cout<<ans/2<<endl;
    
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#define N 210000

using namespace std;
//バケット法を用いて
int main(){
    long long numBall = 0;
    int numDiff = 0;
    int counta = 0;
    int ans = 0;
    int a[N];
    int backet[N] = {0};

    cin >> numBall >> numDiff;
    for(int i = 1; i <= numBall; i++){
        cin >> a[i]; 
        // cout << "a[" <<i << "] is " <<a[i] << endl;
    }

    for(int i = 1; i <= numBall; i++){
        backet[a[i]]++; //a[i]で取得したボールに書いている数のindexに1をプラス
                        //つまり、 backetの中身は、そのindexの数字（ボールに書いてある数字）の数を表す
        // cout << "backet" << a[i] << " is " << backet[a[i]] << endl;

    }

    for(int i= 1; i <= numBall; i++){
        // cout << "backet[" <<i << "] is "<< backet[i] << endl;
        if(backet[i] > 0){
            counta ++;
            // cout << counta << endl;
        }
    }
    sort(backet,backet+numBall + 1);

    if(counta > numDiff){
        for(int i = 1; i <= numBall; i++){
            if(backet[i] > 0){
            // cout << "backet[" <<i << "] is "<< backet[i] << endl;
                ans += backet[i];
                counta--;
                if(counta == numDiff) break;
            }
        }
    }

    cout << ans << endl;







}

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

int n,sz;
ll x,y,w,temp,ans=0,mot,tot;
vector<ll>v[4];
vector<ll>u[4];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>n>>w;

    cin>>x>>y;
    temp=x;
    v[0].push_back(y);
    for(int i=2;i<=n;i++)
    {
        cin>>x>>y;
        v[x-temp].push_back(y);
    }

    for(int i=0;i<=3;i++)
    sort(v[i].begin(),v[i].end(), greater<ll>());

    for(int i=0;i<=3;i++)
    {
        sz=v[i].size();
        //if(sz==0)
        //continue;
        u[i].push_back(0);
        for(int j=0;j<sz;j++)
        {
            u[i].push_back(v[i][j]+u[i].back());
        }
    }


   /* for(int i=0;i<4;i++)
    {
        for(int j=0;j<u[i].size();j++)
        cout<<u[i][j]<<" ";cout<<endl;
    }
*/
    for(int i=0;i<u[0].size();i++)
    for(int j=0;j<u[1].size();j++)
    for(int k=0;k<u[2].size();k++)
    for(int f=0;f<u[3].size();f++)
    {
        tot=(temp*i)+((temp+1)*j)+((temp+2)*k)+((temp+3)*f);
        if(tot>w)
        break;
        mot=u[0][i]+u[1][j]+u[2][k]+u[3][f];
        if(mot>ans)
            ans=mot;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * e.cc: E - Picking Goods
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_H = 3000;
const int MAX_W = 3000;
const int N = 4;

/* typedef */

typedef long long ll;

/* global variables */

int vs[MAX_H][MAX_W];
ll dp[MAX_H][MAX_W][N];

/* subroutines */

inline void setmax(ll &a, ll b) { if (a < b) a = b; }

/* main */

int main() {
  int h, w, k;
  scanf("%d%d%d", &h, &w, &k);

  for (int i = 0; i < k; i++) {
    int y, x, v;
    scanf("%d%d%d", &y, &x, &v);
    y--, x--;
    vs[y][x] = v;
  }

  memset(dp, -1, sizeof(dp));
  dp[0][0][0] = 0;
  if (vs[0][0] > 0) dp[0][0][1] = vs[0][0];

  for (int y = 0; y < h; y++)
    for (int x = 0; x < w; x++)
      for (int i = 0; i < N; i++)
	if (dp[y][x][i] >= 0) {
	  if (x + 1 < w) {
	    setmax(dp[y][x + 1][i], dp[y][x][i]);
	    if (vs[y][x + 1] > 0 && i + 1 < N)
	      setmax(dp[y][x + 1][i + 1], dp[y][x][i] + vs[y][x + 1]);
	  }
	  if (y + 1 < h) {
	    setmax(dp[y + 1][x][0], dp[y][x][i]);
	    if (vs[y + 1][x] > 0)
	      setmax(dp[y + 1][x][1], dp[y][x][i] + vs[y + 1][x]);
	  }
	}

  ll maxd = 0;
  for (int i = 0; i < N; i++)
    setmax(maxd, dp[h - 1][w - 1][i]);

  printf("%lld\n", maxd);
  return 0;
}


Measured memory_bytes: 319624
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        FastScanner scanner = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        int N = scanner.nextInt();
        int cnt = 0;
        for(int i = 1; i <= N; i++) {
            if (i != scanner.nextInt()) cnt++;
        }
        if (cnt <= 2) out.println("YES");
        else out.println("NO");
        out.flush();
    }
    
    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        
        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }
        
        public FastScanner() {
            this(new InputStreamReader(System.in));
        }
        
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        int nextInt() {
            return Integer.parseInt(next());
        }
        
        long nextLong() {
            return Long.parseLong(next());
        }
        
        double nextDouble() {
            return Double.parseDouble(next());
        }
        
        String readNextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        
        int[] readIntArray(int n) {
            int[] a = new int[n];
            for (int idx = 0; idx < n; idx++) {
                a[idx] = nextInt();
            }
            return a;
        }
    }
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

int main(){
    int n,ma,mb;
    scanf("%d %d %d",&n,&ma,&mb);
    //cin >> n >> ma >> mb;
    vector<int> a(n),b(n),c(n);
    rep(i,n) scanf("%d %d %d",&a[i],&b[i],&c[i]);
    //rep(i,n) cin >> a[i] >> b[i] >> c[i];

    vector<P> one;
    map<int,int> two;
    for(int i=1;i<(1<<(n/2));i++){
        int aa = 0;
        int bb = 0;
        int cc = 0;
        rep(j,n/2){
            if(i>>j&1){
                aa += a[j];
                bb += b[j];
                cc += c[j];
            }
        }
        one.push_back(P(ma*bb-mb*aa,cc));
    }
    for(int i=1;i<(1<<((n+1)/2));i++){
        int aa = 0;
        int bb = 0;
        int cc = 0;
        rep(j,(n+1)/2){
            if(i>>j&1){
                aa += a[j+n/2];
                bb += b[j+n/2];
                cc += c[j+n/2];
            }
        }
        if(two.count(-ma*bb+mb*aa)==0){
            two[-ma*bb+mb*aa] = cc;
        }else{
            two[-ma*bb+mb*aa] = min(two[-ma*bb+mb*aa],cc);
        }
    }

    int ans = INF;
    if(two.count(0)>0) ans = two[0];
    rep(i,one.size()){
        if(one[i].first==0) ans = min(ans,one[i].second);
        if(two.count(one[i].first)==0) continue;

        ans = min(ans,two[one[i].first]+one[i].second);
    }
    printf("%d\n",(ans==INF?-1:ans));
    //cout << (ans==INF?-1:ans) << endl;

    //rep(i,one.size()) cout << one[i].first <<" " << one[i].second << endl;cout << endl;
    //for(auto p:two) cout << p.first <<" " << p.second << endl;
    return 0;
}


Measured memory_bytes: 11600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n;
    cin>>n;
    vector<pair<int,int> >arr(n);
    for(int i=0; i<n; i++){
        cin>>arr[i].second>>arr[i].first;
    }
    sort(arr.begin(),arr.end());
    int s=0;
    int flag=0;
    for(int i=0; i<n; i++){
        if(s+arr[i].second>arr[i].first){
            flag=1;
            break;
        }
        else{
            s+=arr[i].second;
        }
    }
    if(flag)
         cout<<"No";
    else
        cout<<"Yes";
return 0;
}

Measured memory_bytes: 4820
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include<queue>
#include <sstream>
#include <set>
typedef  long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
using namespace std;

const int limit = 50;
int n,m;
bool vis[limit];
bool vec[limit][limit];


void dfs(int x){
    if(vis[x]) return;

    vis[x] = true;

    for(int i=0;i<n;i++){
        if(vec[x][i]){
            dfs(i);
        }
    }
}
int main(){
    int a,b,cnt = 0;
    cin >> n >> m;
    vector<pair<int, int>> edge(limit);
    REP(i,m){
        cin >> a >>b;
        a--;
        b--;
        edge[i] = {a,b};
        vec[a][b] = true;
        vec[b][a] = true;
    }

    REP(i,m){
        REP(l,n) vis[l] = false;

        vec[edge[i].first][edge[i].second] = false;
        vec[edge[i].second][edge[i].first] = false;

        dfs(0);

        bool fl = true;

        REP(j,n){
            if(!vis[j]){
                fl = false;
                break;
            }
        }

        if(fl) cnt ++;

        vec[edge[i].first][edge[i].second] = true;
        vec[edge[i].second][edge[i].first] = true;
    }

    cout << m-cnt  <<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
  static void Main()
  {
    int N = int.Parse(Console.ReadLine());
    string[] points = Console.ReadLine().Split(' ');
    int A = int.Parse(points[0]);
    int B = int.Parse(points[1]);

    List<int> score = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).OrderBy(x => x).ToList();
    var countA = score.Where(x => x <= A).Count();
    var countB = score.Where(x => x > A && x <= B).Count();
    var countC = score.Where(x => x > B).Count();
    int[] a = new int[] {countA, countB, countC};
    int count = a.Min();
    Console.WriteLine(count);
  }
}


Measured memory_bytes: 13524
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
int main(){
  ll n;
  cin >> n;
  
  vector<ll> l(n+1);
  l[0] = 2; l[1] = 1; 
  
  for(int i=2;i<=n;i++) l[i] = l[i-1]+l[i-2];
  
  cout << l[n] <<endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

int main(){
  int n;
  cin>>n;
  vector<long> vec(n);
  rep(i,n) cin>>vec[i];

  long total = accumulate(all(vec), 0LL);

  long ans = abs(vec[0] - (total-vec[0]));
  long crnt = vec[0];
  repl(i,1,n-1){
    crnt += vec[i];
    ans = min(ans, abs(crnt - (total - crnt)));
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
<?php
$N = (int)fgets(STDIN);
$A = array_map(function ($n) {
    return (int)$n;
}, explode(' ', fgets(STDIN)));

$ans = 0;
for ($i = 1; $i <= $N; $i++) {
    if ($i % 2 === 1 && $A[$i - 1] % 2 === 1) {
        $ans += 1;
    }
}

echo $ans;

Measured memory_bytes: 16128
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
 
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int x,a;
  cin >> x >> a;
  if(x < a) cout << 0 << endl;
  else cout << 10 << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int road[6][2] = {
		{1, 2}, {-1, 3}, {1, -1}, {4, 5}, {5, 2}, {2, 1}
	};
	int i, loc;
	char p[128];
	
	while (scanf("%s", p), p[0] != '#'){
		i = 0;
		loc = 0;
		while (p[i] != '\0'){
			if (loc != -1){
				loc = road[loc][p[i] - '0'];
			}
			i++;
		}
		
		if (loc == 5){
			printf("Yes\n");
		}
		else {
			printf("No\n");
		}
	}
	
	return (0);
}

Measured memory_bytes: 524
N,K,C=map(int,input().split())
S=input()
X=[0]*N
Y=[0]*N
i=0
c=0
while(i<N):
    if S[i]=="o":
        c+=1
        X[i]=1
        i += (C+1)
    else:
        i+=1
if c>K:
    exit()
i = N - 1
while(i>=0):
    if S[i]=="o":
        Y[i]=1
        i -= (C+1)
    else:
        i -= 1
for i in range(N):
    if X[i] and Y[i]:
        print(i+1)

Measured memory_bytes: 50892
def slove():
    import sys
    import fractions
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    l = [0] * (n + 1)
    r = [0] * (n + 1)
    for i in range(n):
        l[i+1] = fractions.gcd(l[i], a[i])
        r[-i-2] = fractions.gcd(r[-i-1], a[-i-1])
    md = 0
    for i in range(n):
        md = max(md, fractions.gcd(l[i], r[i+1]))
    print(md)


if __name__ == '__main__':
    slove()


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

using namespace std;

int main(){
    int n;
    int l, r, ans = 0;
    
    cin >> n;
    
    for(int i = 1; i <= n ; i ++ ) {
        cin >> l >> r;
        ans += r - l + 1;
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
using System;

class Program
{
    static void Main(string[] args)
    {
        var xy = Console.ReadLine().Split(' ');
        if (0 < xy[0].CompareTo(xy[1]))
        {
            Console.WriteLine(">");
        }
        else if (0 > xy[0].CompareTo(xy[1]))
        {
            Console.WriteLine("<");
        }
        else
        {
            Console.WriteLine("=");
        }
    }
}


Measured memory_bytes: 13280
#include <cassert>
#include <cstdint>
#include <tuple>
#include <vector>

template <typename Abelian> class PotentializedUnionFind {

public:
  using value_type = Abelian;
  using reference = value_type &;
  using const_reference = const value_type &;
  using size_type = std::uint_fast32_t;

private:
  std::vector<std::tuple<bool, size_type, value_type>> tree;
  value_type potential(const size_type x) {
    find(x);
    return std::get<2>(tree[x]);
  }

public:
  PotentializedUnionFind(const size_type size)
      : tree(size, std::forward_as_tuple(1, 1, value_type())) {}
  size_type find(const size_type x) {
    assert(x < size());
    if (std::get<0>(tree[x]))
      return x;
    const size_type t = std::get<1>(tree[x]);
    std::get<1>(tree[x]) = find(t);
    std::get<2>(tree[x]) = std::get<2>(tree[t]) + std::get<2>(tree[x]);
    return std::get<1>(tree[x]);
  }
  value_type diff(const size_type x, const size_type y) {
    assert(x < size());
    assert(y < size());
    return potential(y) + (-potential(x));
  }
  bool unite(size_type x, size_type y, value_type d) {
    assert(x < size());
    assert(y < size());
    d = d + diff(y, x);
    x = find(x);
    y = find(y);
    if (x == y)
      return false;
    if (std::get<1>(tree[x]) < std::get<1>(tree[y]))
      std::swap(x, y), d = -d;
    std::get<1>(tree[x]) += std::get<1>(tree[y]);
    tree[y] = std::forward_as_tuple(0, x, d);
    return true;
  }
  bool same(const size_type x, const size_type y) {
    assert(x < size());
    assert(y < size());
    return find(x) == find(y);
  }
  size_type size(const size_type x) {
    assert(x < size());
    return std::get<1>(tree[find(x)]);
  }
  size_type size() const noexcept { return tree.size(); }
  bool empty() const noexcept { return tree.empty(); }
};
 
#include<iostream>
int main(void) {
	int n, m;
	std::cin >> n >> m;
	PotentializedUnionFind<int> T(n);
	while (m--) {
		int l, r, d;
		std::cin >> l >> r >> d;
		--l;--r;
		if (!T.unite(l, r, d)) {
			if (T.diff(l, r) != d) {
				std::cout << "No" << std::endl;
				return 0;
			}
		}
	}
	std::cout << "Yes" << std::endl;
	return 0;
}


Measured memory_bytes: 2560
import heapq
n, m = [ int(v) for v in input().split() ]
a_list = [ -int(v) for v in input().split() ]
a_list = sorted(a_list)

for i in range(m):
    b = heapq.heappop(a_list)
    b = -b
    b //= 2
    heapq.heappush(a_list,-b)

print(-sum(a_list))

Measured memory_bytes: 63984
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>	
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define chsort(s) qsort(s,strlen(s),sizeof(char),cmp)
#define chsort_r(s) qsort(s,strlen(s),sizeof(char),char_cmp_r);
#define TYPE int
#define MEMSET(a) memset(a,0,sizeof(a))
const int mod=(int)1e09+7;

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
double din(void){
	double i;scanf("%lf",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void dprint(double a){
	printf("%.10f\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
long long llabs(long long a){
	return a>0?a:-a;
}
double dmax(double a,double b){
	return a>b?a:b;
}
int cmp(const void *a,const void *b){
	return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
	return *(TYPE *)b-*(TYPE *)a;
}
int char_cmp(const void *a,const void *b){
	return strcmp((char *)a,(char *)b);
}
int char_cmp_r(const void *a,const void *b){
	return strcmp((char *)b,(char *)a);
}
void swap(int *a,int *b){
	int t=*a;
	*a=*b;
	*b=t;
}

int main(void){
	int n=in(),k=in(),ans=0,i,a,f[200001]={};
	rep(i,n){
		a=in();
		f[a]++;
	}
	sort_r(f,n);
	rep(i,k)ans+=f[i];
	print(n-ans);
	return 0;
}

Measured memory_bytes: 1660
#include <stdio.h>
#include <iostream>
#include <string>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <sstream>
#include <fstream>

using namespace std;


int main(void) {

	unsigned long long  N;
	cin >> N;
	unsigned long long A = 0, B = 0;
	unsigned long long Asum = 0, Bsum = 0;

	unsigned long long a[5] = {};
	unsigned long long b[5] = {};

	unsigned long long minu = 0;

	if (N == 100000) {
		cout << 10 << endl;
		return 0;
	}

	for (long i = 1; i < N; i++) {
		A = i;
		B = N - i;

		if (A >= 10000) {
			a[0] = A / 10000;
			A = A % 10000;
			a[1] = A / 1000;
			A = A % 1000;
			a[2] = A / 100;
			A = A % 100;
			a[3] = A / 10;
			A = A % 10;
			a[4] = A;

			//cout << a[0] << "," << a[1] << "," << a[2] << "," << a[3] << "," << a[4] << endl;

		}
		else if (A >= 1000) {
			a[0] = 0;
			a[1] = A / 1000;
			A = A % 1000;
			a[2] = A / 100;
			A = A % 100;
			a[3] = A / 10;
			A = A % 10;
			a[4] = A;
		}
		else if (A >= 100) {
			a[0] = 0; a[1] = 0;
			a[2] = A / 100;
			A = A % 100;
			a[3] = A / 10;
			A = A % 10;
			a[4] = A;
		}
		else if (A >= 10) {
			a[0] = 0; a[1] = 0; a[2] = 0;
			a[3] = A / 10;
			A = A % 10;
			a[4] = A;
		}
		else {
			a[0] = 0; a[1] = 0; a[2] = 0; a[3] = 0;
			a[4] = A;
		}

		if (B >= 10000) {
			b[0] = B / 10000;
			B = B % 10000;
			b[1] = B / 1000;
			B = B % 1000;
			b[2] = B / 100;
			B = B % 100;
			b[3] = B / 10;
			B = B % 10;
			b[4] = B;


		}
		else if (B >= 1000) 
		{
			b[0] = 0;
			b[1] = B / 1000;
			B = B % 1000;
			b[2] = B / 100;
			B = B % 100;
			b[3] = B / 10;
			B = B % 10;
			b[4] = B;
		}
		else if (B >= 100) {
			b[0] = 0; b[1] = 0;
			b[2] = B / 100;
			B = B % 100;
			b[3] = B / 10;
			B = B % 10;
			b[4] = B;
		}
		else if (B >= 10) {
			b[0] = 0; b[1] = 0; b[2] = 0;
			b[3] = B / 10;
			B = B % 10;
			b[4] = B;
		}
		else {

			b[0] = 0; b[1] = 0; b[2] = 0; b[3] = 0;
			b[4] = B;
		}


		Asum = a[0] + a[1] + a[2] + a[3] + a[4];
		Bsum = b[0] + b[1] + b[2] + b[3] + b[4];


		if (minu == 0) {
			minu = Asum+Bsum;
		}
		

		if (Asum + Bsum < minu) {
			minu = Asum + Bsum;;
		}

		//cout << Asum << ","<< Bsum << endl;

	
	}

	

	cout << minu << endl;

	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const double PI = acos(-1);
#define rep(i, n) for (int i = 0; i < (int)(n); i++ )
using namespace std;
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}
int main(){
    int n, m;
    cin >> n >> m;
    long long ans = 0;
    ans += n*(n-1) /2;
    ans += m*(m-1) /2;
    cout << ans << endl;
}

Measured memory_bytes: 3628
n = int(input())

p = [int(input()) for _ in range(n)]



count = 0
climing = 0

if p[0] !=0:
    print(-1)
    exit()

for index in range(len(p) - 1):
    current_num = p[index]
    next_num = p[index + 1]

    if current_num == next_num:
        count += current_num
    elif current_num + 1 == next_num:
        pass
    elif current_num > next_num:
        count += current_num
    else:
        # abort
        print(-1)
        exit()

# 終端処理
count += p[-1]
print(count)


Measured memory_bytes: 11048
#include <bits/stdc++.h>
#define base 1000000007LL
#define ll long long
#define X first
#define Y second
#define pb push_back
#define Scan(a) scanf("%I64d", &a);
#define CLR(a) memset(a,0,sizeof(a))
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define FORE(i,a,b) for(int i=(a),_b=(b); i>=_b; i--)

using namespace std;

typedef pair<int, int> II;
typedef vector<II> vi;

int main()
{
    int t, n;
    ios::sync_with_stdio(0);
    //freopen("inp.txt", "r", stdin);
    cin >> n >> t;
    int Min = 1000000007;
    int res = 0;
    int maxDiff = 0;
    FOR(i,1,n) {
        int k;
        cin >> k;
        Min = min(Min, k);
        if (k - Min == maxDiff) res++;
        else if (k - Min > maxDiff) {
            maxDiff = k - Min;
            res = 1;
        }
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 256
def resolve():
    n, a, b = map(int, input().split())
    s = str(input())

    total, _b, = 0, 0
    for t in s:
        if t == 'a':
            if total < (a + b):
                print('Yes')
                total += 1
            else:
                print('No')

        elif t == 'b':
            if total < (a + b) and _b < b:
                print('Yes')
                _b += 1
                total += 1
            else:
                print('No')
        else:
            print('No')

resolve()

Measured memory_bytes: 4016
# https://atcoder.jp/contests/abc105/tasks/abc105_c
# -2進数
# 前に考えたときはわからなかったけど、数式イジイジしたら解けた


N = int(input())

if N == 0:
    print(0)
    exit()

ans = ''
while N != 0:
    if N & 1:  # 奇数ならbitが立つのは共通する性質
        ans += '1'
        N /= -2
        if N > 0:
            N += 1
        N = int(N)
    else:
        ans += '0'
        N //= -2


print(ans[::-1])


Measured memory_bytes: 2940
import Control.Applicative
import Control.Monad
import Numeric

ssq [x] = x*x
ssq (x:xs) = x*x + ssq xs

var x = ssq x / (fromIntegral.length) x - meanx * meanx where meanx = sum x / (fromIntegral.length) x


main = do
    n <- getLine
    if( n == "0") then return ()
    else do 
      s <- (map read.words) <$> getLine :: IO [Double]
      putStrLn $ showFFloat (Just 7) (sqrt(var s)) ""
      main

Measured memory_bytes: 4804
Aa = [0]*3
for i in range(3):
    Aa[i] = [int(j) for j in  input().split()]
N = int(input())
b = [0] * N
for i in range(N):
    b[i] = int(input())
A = [[False] * 3 for _ in range(3)]
for i in range(N):
    for k in range(3):
        for t in range(3):
            if Aa[k][t] == b[i]:
                A[k][t] = True
for i in range(3):
    if A[0][i] == True and A[1][i] == True and A[2][i] == True:
        print("Yes")
        exit()
for i in range(3):
    if A[i][0] == True and A[i][1] == True and A[i][2] == True:
        print("Yes")
        exit()
if A[0][0] == True and A[1][1] == True and A[2][2] == True:
    print("Yes")
    exit()
if A[0][2] == True and A[1][1] == True and A[2][0] == True:
    print("Yes")
    exit()
print("No")

Measured memory_bytes: 38384
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1e9 + 7;
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;
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B;
    cin >> A >> B;
    cout << (B % A ? B - A : A + B) << endl;
    return 0;
}

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

int main(){
    int n, v;
    cin >> n;
    int a[n];
    for (int j = 0; j < n;j++ ){
        cin >> a[j];
    }
    for (int i = 0; i < n;i++ ){
        int c = n - i - 1;
        v = a[c];
        if (i == 0){
        } else {
            cout << " ";
        }
        cout << v;
    }
    cout << endl;
}


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

int a[510][510];
int n;

void f(int l,int r,int k){
  if(r-l==1)return;
  
  int m=(r+l)/2;
  
  for(int i=l;i<m;i++){
    for(int j=m;j<r;j++){
      a[i][j]=k;
    }
  }
  
  f(l,m,k+1);
  f(m,r,k+1);
}

signed main(){
  cin>>n;
  f(0,n,1);
  
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      cout<<a[i][j]<<" ";
    }
    cout<<endl;
  }
}

Measured memory_bytes: 1536
#include<iostream>
#include<queue>
#include<vector>
#include<set>
#include<memory>
#include<algorithm>
using namespace std;
int solve(vector<vector<int>> &tree, int p, int c){ //#ANT for nodes below c inclusive
                             // assume at least one ANT above or root
  int nc=0;
  int na=0;
  int r =0;
//  vector<int> ii;
  for(auto cc:tree[c]){
    if(cc==p) continue;
    nc++;
    int tmp = solve(tree,c,cc);
    r+=tmp;
    if(tmp>0) na++;
//    else ii.push_back(cc);
  }
  if(na+1 < nc){
    r+=nc-1-na;
//    for(int i=1;i<ii.size();i++) cout<<ii[i]<<',';
  }
//  cout<<r<<endl;
  return r;
}
/*bool dfs_bf(Node *p, Node *c){
    bool tmp = false;
    for(auto cc:c->connected){
      if(cc==p) continue;
      tmp |= dfs_bf(c,cc);
    }
    c->has_bf = tmp || c->connected.size()>=3;
    return c->has_bf;
}*/
int main(){
  int n;
  cin>>n;
  vector<vector<int>> tree(n);
  for(int i=0;i<n-1;i++){
    int a,b;
    cin>>a>>b;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }
  int i3=-1;
  for(int i=0;i<n;i++){
    if(tree[i].size()>=3){
      i3 = i;
      break;
    }
  }
  if(i3<0){
    cout<<1<<endl;
    return 0;
  }
  cout << solve(tree, -1, i3);
  return 0;
}


Measured memory_bytes: 9856
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] ny = scanner.nextLine().split(" ", 2);
        int n = Integer.parseInt(ny[0]);
        int y = Integer.parseInt(ny[1]);

        int y10k = 0;
        int y5k = 0;
        int y1k = 0;

        if (10000 * n < y) {
            System.out.println("-1 -1 -1");
            return;
        }

        for (y10k = y / 10000; y10k >= 0; y10k--) {
            int remY = y - y10k * 10000;
            if (5000 * (n - y10k) < remY) {
                System.out.println("-1 -1 -1");
                return;
            }

            for (y5k = remY / 5000; y5k >= 0; y5k--) {
                int remY2 = remY - y5k * 5000;
                y1k = (n - y10k - y5k);
                if (remY2 == y1k * 1000) {
                    System.out.printf("%d %d %d\n", y10k, y5k, y1k);
                    return;
                } else if (y1k * 1000 < remY2) {
                    break;
                }
            }
        }
        System.out.println("-1 -1 -1");
    }
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000

//aのb乗
int beki(int a,int b){
	int x = 1;
	while(b!=0){
		if(b&1){
			x=mod(x*a);
		}
		a=mod(a*a);
		b>>=1;
	}
	return x;
}

//aの逆元
int gyakugen(int a){
	return beki(a,modulo-2);
}

int main(){
	
	int N;
	cin>>N;
	
	vector<int> A(N);
	for(int i=0;i<N;i++)cin>>A[i];
	
	int X = 1000001;

	vector<int> cnt(X,0);
	for(int i=0;i<N;i++){
		cnt[A[i]] = mod(cnt[A[i]] + A[i]);
	}
	
	vector<int> sum(X,0);
	/*
	for(int i=0;i<N;i++){
		for(int j=0;j<yakusuu[A[i]].size();j++){
			sum[yakusuu[A[i]][j]] = mod(sum[yakusuu[A[i]][j]] + A[i]);
		}
	}*/
	
	for(int i=1;i<X;i++){
		for(int j=i;j<X;j+=i){
			int a = cnt[j];
			sum[i] = mod(sum[i] + a);
		}
	}
	
	vector<int> gyaku(X,0);
	for(int i=1;i<X;i++){
		gyaku[i] = mod(gyaku[i] + gyakugen(i));
		for(int j=2*i;j<X;j+=i){
			gyaku[j] = mod(gyaku[j] - gyaku[i]);
		}
	}
	
	int ans = 0;
	
	for(int i=1;i<X;i++){
		int a = mod(sum[i]*sum[i]);
		a = mod(a*gyaku[i]);
		ans = mod(ans + a);
	}
	
	for(int i=0;i<N;i++){
		ans = mod(ans - A[i]);
	}
	ans = mod(ans * gyakugen(2));
	
	cout<<ans<<endl;
		
		
	
	
	return 0;
}



Measured memory_bytes: 13952