akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main() {
    string S;
    cin >> S;

    int ans = 1e9;
    for (int i = 0; i < 2; i++) {
        int t = 0;
        for (int j = 0; j < S.size(); j++) {
            t += (S[j] != (i + j) % 2 + '0');
        }
        ans = min(ans, t);
    }
    cout << ans << endl;
}


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

public struct Dish
{
    public int Time;
    public int Score;

    public Dish(int time, int score)
    {
        Time = time;
        Score = score;
    }
}

public struct State
{
    public int Time;
    public bool Use;

    public State(int time, bool use)
    {
        Time = time;
        Use = use;
    }

    public override bool Equals(object obj)
    {
        if (!(obj is State))
        {
            return false;
        }
        var that = (State)obj;
        return Time == that.Time && Use == that.Use;
    }

    public override int GetHashCode()
    {
        return (Time << 16) ^ (Use ? 1 : 0);
    }

    public static bool operator ==(State left, State right)
    {
        return left.Equals(right);
    }

    public static bool operator !=(State left, State right)
    {
        return !(left == right);
    }
}

public class Solution
{
    public static void Main()
    {
        var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var N = vals[0];
        var T = vals[1];
        var dishs = new List<Dish>();
        for (int i = 0; i < N; i++)
        {
            vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            dishs.Add(new Dish(vals[0], vals[1]));
        }
        // [時刻,last使用] = score
        var stats = new Dictionary<State, long>();
        stats.Add(new State(0, false), 0);
        foreach (var dish in dishs)
        {
            foreach (var cur in stats.ToList())
            {
                var state = cur.Key;
                var score = cur.Value;

                if (state.Time + dish.Time < T)
                {
                    var nextState = new State(state.Time + dish.Time, state.Use);
                    var s = score + dish.Score;
                    if (!stats.ContainsKey(nextState) || stats[nextState] < s)
                    {
                        stats[nextState] = s;
                    }
                }
                if (!state.Use)
                {
                    var nextState = new State(state.Time, true);
                    var s = score + dish.Score;
                    if (!stats.ContainsKey(nextState) || stats[nextState] < s)
                    {
                        stats[nextState] = s;
                    }
                }
            }
        }

        var bestScore = stats.Values.OrderByDescending(v => v).First();
        Console.WriteLine(bestScore);
    }
}

Measured memory_bytes: 35316
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>

using namespace std;

int main() {
	int H, W, D;
	cin >> H >> W >> D;
	vector<vector<int>> A(H, vector<int>(W));
	vector<pair<int, int>> LA(H * W + 1);
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> A[i][j];
			LA[A[i][j]] = make_pair(i, j);
		}
	}

	vector<vector<int>> cost(D, vector<int>((H * W) / D + 1));
	for (int i = 1; i <= H * W; i++) {
		int M = i % D;
		int Q = i / D;
		if (Q == 0) cost[M][Q] = 0;
		else {
			pair<int, int> a = LA[i - D];
			pair<int, int> b = LA[i];
			cost[M][Q] = cost[M][Q - 1] + abs(a.first - b.first) + abs(a.second - b.second);
		}
	}

	int Q;
	cin >> Q;
	for (int i = 0; i < Q; i++) {
		int L, R;
		cin >> L >> R;
		cout << cost[R % D][R / D] - cost[L % D][L / D] << endl;
	}


	system("pause");
	return 0;
}

Measured memory_bytes: 6648
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <string>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))




__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
  int n; cin>>n;
	vector<string> s(n); rep(i,n) cin>>s[i]; sort(ALL(s));
	vector<pair<int, string> > p;
	int cnt = 1;
	int m_cnt = -1;
	reps(i,n-1){
		if(s[i-1]==s[i]) cnt++;
		else{
			p.PB(MP(cnt,s[i-1]));
			chmax(m_cnt,cnt);
			cnt = 1;
		}
	}
	p.PB(MP(cnt,s[n-1]));
	chmax(m_cnt,cnt);
	// sort(RALL(p));
	rep(i,p.size()){
		if(p[i].first==m_cnt){
			cout<<p[i].second<<endl;
		}
	}

  return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll,ll> pii;
typedef double ld;
typedef pair<ld, ld> pdd;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

struct Tri{ 
  ll ai;
  ll bi;
  bool operator< (const Tri &F) const {
    return (ai + bi) < (F.ai + F.bi);
  }
};

int main(){
  fastIO;
  ll k;
  int n;
  cin >> n >> k;
  if(2 * k - 1 > n){
    cout << "-1\n";
    return 0;
  }
  vector<Tri> sol(n);
  int d = n/2;
  for(int i = 0 ; i < n; i ++ ){
    sol[i].ai = k + i;
    sol[i].bi = k + n + (i + n - d) % n;
  }
  /*
  if(n > 1){
    swap(sol[n-2].bi, sol[n-1].bi);
  }
  */
  sort(sol.begin(), sol.end());
  for(int i = 0 ; i < n; i ++ ){
    cout << sol[i].ai << " " << sol[i].bi << " " << k + 2 * n + i << "\n";
  }
  return 0;
}


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

int main(){
  int N;
  string S;
  cin >> N;
  cin >> S;
  int count = 0;
  for(int i=0; i<N; i++){
    if(i < N-2 && S[i]=='A' && S[i+1]=='B' && S[i+2]=='C')count++;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <set>
#include <string>
#include<string.h>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <cctype>
using namespace std;
typedef long long ll;

bool check(int k,int a,int b){
	for(int i=a;i<=b;i++){
		if(i%k==0) return true;
	}
	return false;
}

int main(){
	int k,a,b;
	scanf("%d",&k);
	scanf("%d %d",&a,&b);
	if(check(k,a,b)){
		printf("OK\n");
	} else{
		printf("NG\n");
	}
	return 0;
}

Measured memory_bytes: 3684
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))
#define SET(a,c) memset(a,c,sizeof(a))

#define DEBUG(x) cout<<"#x"<<": "<<x<<endl

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;

const ll INF = INT_MAX/3;
const ll MOD = 1000000007;
const double EPS = 1e-14;
const int dx[] = {1,0,-1,0} , dy[] = {0,1,0,-1};

typedef struct Btree {
    struct Btree *left;
    struct Btree *right;
} Btree;

Btree temp;

Btree *createTree(string s){
    // cout << "input: " << s << endl;
    int center = -1;
    stack< int > st;

    if( s.size() <= 1 ) {
        return NULL;
    }

    REP(i,s.length()){
        if( s[i] == '(' ){
            st.push(i);
        }else if ( s[i] == ')'){
            st.pop();
        }else if ( s[i] == ',' ){
            if(st.size() == 1) center = i;
        }
    }

    if( center == -1) return NULL;
    Btree *ret = new Btree;
    ret->left = createTree(s.substr(1,center-1));
    ret->right = createTree(s.substr(center+1,s.length()));
    return ret;
}

void dfs(int n,Btree *tree){
    if( tree == NULL) return;
    REP(i,n) cout << " ";
    cout << n << endl;
    dfs(n+1,tree->left);
    dfs(n+1,tree->right);
}

string patternI(Btree *a,Btree *b ){
    string left,right;
    left = "";
    right = "";

    if(a == NULL || b == NULL){
        return "";
    }else {
        left = patternI(a->left,b->left);
        right = patternI(a->right,b->right);
    }

    return "(" + left + "," + right +  ")";
}

string patternU(Btree *a,Btree *b ){
    string left,right;
    left = "";
    right = "";

    if(a == NULL && b == NULL){
        return "";
    } else if(a == NULL && b != NULL) {
        left = patternU(NULL,b->left);
        right = patternU(NULL,b->right);
    }else if(a != NULL && b == NULL) {
        left = patternU(a->left,NULL);
        right = patternU(a->right,NULL);
    }else {
        left = patternU(a->left,b->left);
        right = patternU(a->right,b->right);
    }

    return "(" + left + "," + right +  ")";
}

int main(){

    while(true){
        char type;
        string t1,t2;
        cin >> type;
        if(cin.eof()) return 0;
        cin >> t1 >> t2;
        Btree *a = createTree(t1);
        Btree *b = createTree(t2);
        if( type == 'i'){
            cout << patternI(a,b) << endl;
        }else if(type == 'u'){
            cout << patternU(a,b) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1316
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

func main() {
	N := ReadInt()
	a := ReadInts(N)
	fmt.Println(LIS(a))
}

const Inf = 1 << 60

// 最長増加部分列
func LIS(a []int) int {
	n := len(a)
	dp := make([]int, n)
	for i := 0; i < n; i++ {
		dp[i] = Inf
	}
	for _, ai := range a {
		i := sort.Search(len(dp), func(i int) bool { return dp[i] >= ai })
		dp[i] = ai
	}
	return sort.Search(len(dp), func(i int) bool { return dp[i] == Inf })
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int) { Scan(&i); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}



Measured memory_bytes: 4324
#include<bits/stdc++.h>
using namespace std;
string s;
int main(){
    cin>>s;
    int t,o,mark=0,a,b;
    char c;
    scanf("%d",&t);
    while(t--){
        scanf("%d",&o);
        if(o==1) mark++;
        else {
            scanf("%d %c",&a,&c);
            if(mark%2==1) {
                    if(a==2) s.insert(s.begin(),c);
                    else s.insert(s.end(),c);
            }
            else {
                    if(a==2) s.insert(s.end(),c);
                    else s.insert(s.begin(),c);
            }
        }
    }
    if(mark%2==1) reverse(s.begin(),s.end());
    cout<<s;
}


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

#define endl '\n'
#define ALL(X) (X).begin(),(X).end()
typedef long long LL;
typedef long double LD;
const int MAX = 100000;
const int MOD = 1000000007;


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

    LL s; cin>>s;
    LL a = sqrt(s)-1;
    while (a*a < s) ++a;
    bool f = false;
    LL r = a*a - s;
    LL t = 0;
    while (r && !t){
        for (LL i=1; i<=a; ++i){
            if (!(r%i) && r/i <= a) { t = i; break; }
        }
        if (!t){
            ++a; r = a*a - s;
        }
    }
    cout<<"0 0 "<<a<<' '<<t<<' '<<(t ? r/t : 0)<<' '<<a<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <utility>
#include <map>
int needleX[4] = { -1,0,1,0 };
int needleY[4] = { 0,1,0,-1 };

#define const INF=1<<21;
int main(){
	int N,M,count=1;
    std::string s;
    char ans;
    long long k;
    std::cin >> s >> k;
    bool flag=true;
    for(size_t i=0;i<std::min((long long)s.size(),k);++i){
        if(s[i]>='2') {
            std::cout << s[i] << std::endl;
            return 0;
        }            
    }
    std::cout << '1' << std::endl;
    
    return 0;
} 

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

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	llong N, M;
	vector<P> xy;

	cin >> N >> M;
	xy.resize(M);
	for(int i = 0; i < M; i++)
		cin >> xy[i].first >> xy[i].second;

	vector<P> ball(N+1, P(0,1));
	ball[1] = P(1,1);

	for(int i = 0; i < M; i++){
		if(ball[xy[i].first].first == 1){
			ball[xy[i].second].first = 1;
			if(ball[xy[i].first].second == 1)
				ball[xy[i].first].first = 0;
		}
		ball[xy[i].first].second--;
		ball[xy[i].second].second++;
	}

	llong ans = 0;
	for(int i = 1; i <= N; i++){
		// cerr << ball[i].first << " " << ball[i].second << endl;
		ans += ball[i].first;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3328
#include <cstdio>
#include <cstring>
#include <queue>
#include <limits.h>
using namespace std;

class board {
  public:
    int a;
    int z;
    int pz;
    board() : a(0), z(0), pz(0) {}
    board(int _a, int _z, int _pz) : a(_a), z(_z), pz(_pz) {}
};

int fact[7] = {1, 2, 6, 24, 120, 720, 5040};

int p2a(int *p) {
  int r = 0;
  int tmp[8];
  for (int i=0; i<8; i++) tmp[i] = i;
  for (int i=0; i<7; i++) {
    r += tmp[p[i]] * fact[6-i];
    for (int j=p[i]+1; j<8; j++) --tmp[j];
  }
  return r;
}

void a2p(int a, int *p) {
  int t = a;
  int x;
  int tmp[8];
  for (int i=0; i<8; i++) tmp[i] = i;
  for (int i=0; i<7; i++) {
    x = t/fact[6-i];
    p[i] = tmp[x];
    for (int j=x; j<7-i; j++) tmp[j] = tmp[j+1];
    t %= fact[6-i];
  }
  p[7] = tmp[0];
}

int main() {
  int p[8];
  int d[8][3] = {
    {1, 4, 0},
    {-1, 1, 4},
    {-1, 1, 4},
    {-1, 4, 0},
    {-4, 1, 0},
    {-4, -1, 1},
    {-4, -1, 1},
    {-4, -1, 0}
  };
  queue<board> q;
  board b;
  int dist[40320];
  bool flg;
  int tmp, z;

  for (int i=0; i<40320; i++) {
    dist[i] = INT_MAX;
  }
  for (int i=0; i<8; i++) {
    p[i] = i;
  }
  tmp = p2a(p);
  dist[tmp] = 0;
  q.push(board(tmp, 0, 0));
  while (!q.empty()) {
    b = q.front(); q.pop();
    a2p(b.a, p);
    for (int i=0; i<3; i++) {
      if (d[b.z][i]) {
        z = b.z + d[b.z][i];
        if (z == b.pz) continue;
        if (z>=0 && z<8) {
          a2p(b.a, p);
          tmp = p[b.z];
          p[b.z] = p[z];
          p[z] = tmp;
          tmp = p2a(p);
          if (dist[tmp] == INT_MAX) {
            dist[tmp] = dist[b.a] + 1;
            q.push(board(tmp, z, b.z));
          }
        }
      }
    }
  }
  while (scanf("%d %d %d %d %d %d %d %d", &p[0], &p[1], &p[2], &p[3], &p[4], &p[5], &p[6], &p[7]) == 8) {
    tmp = p2a(p);
    printf("%d\n", dist[tmp]);
  }

  return 0;
}

Measured memory_bytes: 1240
#include<stdio.h>
int main() {
	int x, y, r, W, H;
	scanf("%d%d%d%d%d", &W, &H, &x, &y, &r);
	if (x <= 0 || y <= 0)printf("No\n");
	else if (x >= W || y >= H)printf("No\n");
	else if (x + r > W || x - r < 0 || y + r > H || y - r < 0)printf("No\n");
	else printf("Yes\n");
	
	return 0;
}

Measured memory_bytes: 580
S = input()
ptn1 = "".join(["1" if i%2==0 else "0" for i in range(len(S))])
ptn2 = "".join(["0" if i%2==0 else "1" for i in range(len(S))])

sum1 = sum([1 if s!=p else 0 for s,p in zip(S,ptn1)])
sum2 = sum([1 if s!=p else 0 for s,p in zip(S,ptn2)])

print(min(sum1,sum2))

Measured memory_bytes: 4068
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main()
{
    ios_base::sync_with_stdio(false);
   cin.tie(nullptr);
  ll n,ans=0;
  cin>>n;
  ll a[n+4];
  for(ll i=1;i<=n;i++)cin>>a[i];
  for(ll i=1;i<=n;i+=2)
    if(a[i]*a[i]%2!=0)ans++;
  cout<<ans<<endl;
}



Measured memory_bytes: 3600
#include<stdio.h>
#define N 8//マス
#define DAN -1;
#define NDAN 0//安全0 危険-1

int row[N],col[N];
int rightd[N*2-1],leftd[N*2-1];

int input[N][N];//Qあったら１　なかったら０
int ans[N][N];//Qあったら１　なかったら０

void Print(){
  int i,j;

  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(input[i][j]==1 && ans[i][j]==0)return;//inputのQが ansにもあるか
    }
  }
  
  for(i=0;i<N;i++){//出力
    for(j=0;j<N;j++){
      if(ans[i][j]==1)printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}

void Queens(int i){//行は固定
  int j;
  
  if(i==N){
    Print();
    return;
  }
    
  for(j=0;j<N;j++){
    if(col[j]==NDAN && rightd[i-j+N-1]==NDAN && leftd[i+j]==NDAN){//安全なら
    
      col[j]=DAN;//Qおいてみる
      rightd[i-j+N-1]=DAN;
      leftd[i+j]=DAN;
      ans[i][j]=1;
    
      Queens(i+1);//次の行へ
   
      col[j]=NDAN;//無理だった、ココにQ奥のやめよう
      rightd[i-j+N-1]=NDAN;
      leftd[i+j]=NDAN;
      ans[i][j]=0;
    }
  }
}


int main(){
  int n,i;
  int x,y;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d%d",&x,&y);
    input[x][y]=1;
  }

  Queens(0);//0行目から探す

  return 0;
}
/*
  Qの個数
  Qの座標xy xy

  Q..で出力


  1.まず入力無視して８個入った完成形作る
  2.出力する前にinputのQの位置と完成した板がただしいか、ここで初めて確認
  3.2がよかったら出力
*/



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



int main (void){

    int n, m;
    cin >> n >> m;
    vector<pair<ll, ll>> vec(n);
    rep(i, n){
        cin >> vec[i].first>> vec[i].second;
    }

    sort(vec.begin(), vec.end());

    ll sum = 0;
    ll count = 0;
    int i = 0;
    while(count <m){
        count += vec[i].second;
        if(count>=m){
            sum+=((vec[i].second-(count-m))*vec[i].first);
            break;
        }
        sum += vec[i].second * vec[i].first;
        i++;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define pb push_back
#define pll pair <ll, ll>
#define mp make_pair
#define pyshnapyshnakaa ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define x first
#define y second
#pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
#define plll pair <pair <ll, ll>, ll>
#define pllll pair <pair <ll, ll>, pair <ll, ll> >
#define psl pair <string, ll>
#define pld pair <ld, ld>
#define all(a) a.begin(), a.end()
#define vvl vector <vector <ll> >
 
typedef long long ll;
 
typedef long double ld;
 
using namespace std;
 
const ll maxn = 1e6 + 100;

ll n, m, k, t;

int main() {
    pyshnapyshnakaa;
    ll q, w, e, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    a--; b--; c--; d--;
    string s;
    cin >> s;
    for (q = a + 1; q <= b; q++) {
        if (s[q] == '#' && s[q - 1] == '#') {
            cout << "No";
            return 0;
        }
    }
    for (q = c + 1; q <= d; q++) {
        if (s[q] == '#' && s[q - 1] == '#') {
            cout << "No";
            return 0;
        }
    }
    if (d > c) {
        cout << "Yes";
        return 0;
    }
    bool found = 0;
    for (q = b; q <= d; q++) {
        if (s[q] == '.' && s[q - 1] == '.' && s[q + 1] == '.') {
            found = 1;
            break;
        }
    }
    if (found) {
        cout << "Yes";
    }
    else {
        cout << "No";
    }
    return 0;
}

Measured memory_bytes: 3696
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <unordered_map>
#include <cmath>
#include <algorithm>

typedef long long ll;
typedef long double ld;

using namespace std;
int main()
{
  ll n, mx = 0;
  string s[200010];
  map<string, ll> poll;

  cin >> n;
  for (ll i = 0; i < n; ++i)
  {
    cin >> s[i];
  }

  for (ll i = 0; i < n; ++i)
  {
    poll[s[i]]++;
    if (mx < poll[s[i]]) mx = poll[s[i]];
  }

  for (auto itr = poll.begin(); itr != poll.end(); ++itr)
  {
    if (itr->second == mx) cout << itr->first << endl;
  }

  return 0;
}


Measured memory_bytes: 26752
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n, d, x, ans;
  cin >> n >> d >> x;
  ans = x;
  rep(i, n){
    int a;
    cin >> a;
    ans += (d - 1) / a + 1;
  }
  cout << ans << endl;
}


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

using namespace std;

#define PI 3.141592653589793
#define FOR(i,a,b) for(int i=int(a);i<int(b);++i)
#define RFOR(i,a,b) for(int i=int(b)-1;i>=int(a);--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)

class Dice{
public:
    Dice()
    {
        face = new int[6];
        move = new int[6];
    }
    ~Dice()
    {
        delete[] face;
        delete[] move;
    }
    void roll(char c)
    {
        REP(i,6) move[i]=face[i];
        if (c == 'L') setLabel(move[0],move[2],move[4],move[1],move[3],move[5]);
        else if (c=='E') setLabel(move[3],move[1],move[0],move[5],move[4],move[2]);
        else if (c=='N') setLabel(move[1],move[5],move[2],move[3],move[0],move[4]);
        else if (c=='S') setLabel(move[4],move[0],move[2],move[3],move[5],move[1]);
        else setLabel(move[2],move[1],move[5],move[0],move[4],move[3]);
    }
    void setLabel(int i,int n) {face[i] = n;}
    void setLabel(int f0,int f1,int f2,int f3,int f4,int f5)
    {
        face[0] = f0;
        face[1] = f1;
        face[2] = f2;
        face[3] = f3;
        face[4] = f4;
        face[5] = f5;
    }
    int getAns() {return face[2];}
    int getLabel(int s) {return face[s];}
    void setDice(int s1,int s2)
    {
        int flag;
        flag = 0;
        REP(i,4) {
            //cout << "s1/" << face[0] << ":" << face[1] << endl;
            if (face[0]==s1) {
                break;
            } else if (i==3) {
                if (flag != 0) break;
                roll('L');
                i=0;
                ++flag;
            }
            roll('N');
        }
        REP(i,4) {
            //cout << "s2/" << face[0] << ":" << face[1] << endl;
            if (face[1]==s2) break;
            roll('L');
        }
    }
private:
    int *face;
    int *move;
};

int main() {
    Dice d[100];
    int N,n,flag,lflag;
    string str;
    cin >> N;
    REP(j,N) {
        REP(i,6) {
        cin >> n;
        d[j].setLabel(i,n);
        }
    }
    REP(k,N) {
        REP(j,N) {
            if (k==j) break;
            lflag = flag = 0;
            REP(i,4) {
                if(d[j].getLabel(0) != d[j].getLabel(1)) break;
                //cout <<  "ll/" << d[j].getLabel(0) << ":" << d[j].getLabel(1) << endl;
                d[j].roll('N');
            
                if (lflag == 0 && d[j].getLabel(0) == d[j].getLabel(1) && i==3) {
                    d[j].roll('L');
                    i = 1;
                    ++lflag;
                }
            }
            if (lflag != 0) continue;
            //cout <<  "ls/" << d[j].getLabel(0) << ":" << d[j].getLabel(1) << endl;
            d[k].setDice(d[j].getLabel(0),d[j].getLabel(1));
          
            REP(i,6) {
                if (d[j].getLabel(i)!=d[k].getLabel(i)) ++flag;
                //cout << "j:" << j << ",k:" << k << ",flag:" << flag << endl;
            }
            if (flag == 0) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}



Measured memory_bytes: 3124
import Data.List
import Control.Monad

input_int :: IO Int
input_int = do
    a <- getLine
    return (read a)

test :: Int -> (Int, Int)
test x = 
    let ns = [(n^5, n) | n <- [0..1000]]
        adds = [(an, bn) | (a, an) <- ns, (b, bn) <- ns, a > b, a - b == x]
        subs = [(an, (-bn)) | (a, an) <- ns, (b, bn) <- ns, a + b == x]
    in  head (adds ++ subs)
    
    
main = do
    x <- input_int
    let (a, b) = test x
    putStrLn ((show a) ++ " " ++ (show b))
        


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

using namespace std;
using   ll=long long;

#define fast            ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define endl            "\n"
#define pb              push_back
#define mp              make_pair
#define F               first
#define S               second
#define int             long long int
#define pll                pair<int , int>

#define ALL(v)          v.begin(),v.end()
#define ALLR(v)         v.rbegin(),v.rend()
#define pii             3.14159265358979323
#define inf             LLONG_MAX
#define ones(x)         __builtin_popcount(x)
#define fill(a,b)       memset(a,b,sizeof(a))
#define mod             1000000007
#define hell            998244353
const int maxn = 2e5 + 1;

vector<vector<int>> a(maxn);

int tot;

int vis[maxn];

void dfs(int u) {
	vis[u] = 1;
	
	tot++;
	
	for(auto v : a[u]) {
		if(!vis[v])  {
			dfs(v);
		}
	}
}

void solve()
{
	int n , m;
	
	cin >> n >> m;
	
	for(int i = 0; i < m; ++i) {
		int x , y;
		
		cin >> x >> y;
		
		a[x].pb(y);
		a[y].pb(x);
	}
	
	int ans = 0;
	
	for(int i = 1; i <= n; ++i) {
		if(!vis[i]) {
			tot = 0;
			
			dfs(i);
			
			//cout << i <<" " << tot << endl;
			
			ans = max(ans , tot);
		}
	}
	
	cout << ans;
}

signed main() {
    fast;

    int t = 1;
   
    //cin >> t;

    while(t--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 21956
#include <iostream>
#include <string>
#include <set>
#include <algorithm>
using namespace std;

int main()
{
  int m;
  while (cin >> m) {
    for (int i = 0; i < m; ++i) {
      string s;
      cin >> s;

      set<string > ans;
      for (unsigned int j = 1; j < s.size(); ++j) {
	string s1 = s.substr(0, j);
	string s2 = s.substr(j);
	ans.insert(s1+s2);
	ans.insert(s2+s1);
	reverse(s2.begin(), s2.end());
	ans.insert(s1+s2);
	ans.insert(s2+s1);
	reverse(s1.begin(), s1.end());
	ans.insert(s1+s2);
	ans.insert(s2+s1);
	reverse(s2.begin(), s2.end());
	ans.insert(s1+s2);
	ans.insert(s2+s1);
      }
      cout << ans.size() << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 996
#include<stdio.h>
#include<string.h>
int main(){
  int n,i;
  char temp[4];
  double money,sum=0.0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%lf %s",&money,temp);
    if(strcmp(temp,"JPY") ==0){
      sum+=money;
    }else{
      sum+=money*380000;
    }
  }
  printf("%lf",sum);
}

Measured memory_bytes: 128
#include<stdio.h>
int main(void)
{
    int a,b;
    
    scanf("%d",&a);
    scanf("%d",&b);
    
    if(a < b){
        printf("a < b\n");
    }
    else if(a > b){
        printf("a > b\n");
    }
    else {
        printf("a == b\n");
    }
    return 0;
}


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

namespace ramuda
{ 
    class Program
    {

        static void Main(string[] args)
        {
            var k = Console.ReadLine();
            var s = Console.ReadLine();
            if (s.Length <= int.Parse(k))
            {
                Console.WriteLine(s);
            }
            else
            {
                Console.WriteLine(s.Substring(0, int.Parse(k)) + "...");
            }

            Console.Read();

        }
    }
}


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

using namespace std;

long long md = 1e9 + 7;

int main()
{
//    freopen("in", "r", stdin);
//    freopen("out", "w", stdout);
    long long ans = 1;
    long long n = 0;
    scanf("%lld", &n);

    for (long long i = 1; i <= n; ++i) {
	ans = ((ans % md) * (i % md)) % md;
    }

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
using namespace std;
const int inf = 1<<30, maxn = 1<<19;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	int a;
	cin >> a;
	cout << a + a*a + a*a*a << '\n';
	return 0;
}


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

int main()
{
    int n, k, min = INT_MAX;
    cin >> n >> k;
    vector<ll> h(n);
    rep(i, n) cin >> h[i];
    sort(h.begin(), h.end());
    for (int i = 0; i < n - k + 1; i++)
    {
        if (min > h[i + k - 1] - h[i])
            min = h[i + k - 1] - h[i];
    }
    cout << min << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
#define rep(i,n) for (int i=0;i<n;++i)
#define REP(i,n) for (int i=1;i<=n;++i)
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define read(x) scanf("%d",&x)

int n;
int a[200005];
vector<int> G[200005];
vector<int> dp;
int ans[200005];
inline void dfs(int u,int pa){
	ans[u]=dp.size();
	for (int i=0;i<G[u].size();++i){
		int v=G[u][i];
		if (v!=pa){
			vector<int>::iterator it=lower_bound(all(dp),a[v]);
			int sav=0;
			if (it==dp.end()){
				dp.pb(a[v]);dfs(v,u);dp.pop_back();
			}
			else{
				int sav=*it;int id=it-dp.begin();dp[id]=a[v];dfs(v,u);dp[id]=sav;
			}
		}
	}
}

int main(){
	ios::sync_with_stdio(false);
	cin>>n;
	REP(i,n) cin>>a[i];
	REP(i,n-1){
		int x,y;cin>>x>>y;
		G[x].pb(y);G[y].pb(x);
	}
	dp.pb(a[1]);
	dfs(1,0);
	REP(i,n) cout<<ans[i]<<endl;
	return 0;
}

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

vector<int> sieveOfEratosthenes(int n) {
  vector<int> primes(n);
  for (int i = 2; i < n; ++i) primes[i] = i;
  for (int i = 2; i * i < n; ++i) {
    if (primes[i]) {
      for (int j = i * i; j < n; j += i) primes[j] = 0;
    }
  }
  // primes.erase(remove(begin(primes), end(primes), 0), end(primes));
  return primes;
}

int main() {
  int n;
  auto v = sieveOfEratosthenes(51001);
  while (cin >> n) {
    for (int i = n - 1; i >= 0; --i) {
      if (v[i]) {
        cout << v[i] << ' ';
        break;
      }
    }
    for (int i = n + 1; i <= 51000; ++i) {
      if (v[i]) {
        cout << v[i] << endl;
        break;
      }
    }
  }
  return 0;
}



Measured memory_bytes: 3072
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
	return list(map(int,input().split()))
def m(): #複数文字
	return map(int,input().split())
def onem(): #Nとかの取得
	return int(input())
def s(x): #圧縮
	a = []
	if len(x) == 0:
		return []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa != x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x): #listをスペースごとに分ける
	return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
	return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
	ll = 0
	rr = r
	while True:
		mid = (ll+rr)//2

	if rr == mid:
		return ll
	if (ここに評価入れる):
		rr = mid
	else:
		ll = mid+1
"""

n = onem()

a = l()

ans = 0

for i in range(n):
	if i % 2 == 0:
		if a[i] % 2 != 0:
			ans += 1
print(ans)


Measured memory_bytes: 65364
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
#include<map>
#include<iomanip>

using namespace std;

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


int main() {
	
	unsigned long long int x, cnt, now;
	
	cin >> x;
	
	now = 0;
	
	cnt = 0;
		
	do{
		cnt++;
		now += cnt;
	} while (now < x);

	
	cout << cnt << endl;

	return 0;
}

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



int main() {
#ifdef HOME
    assert(freopen("in", "r", stdin));
#endif


    int n;
    while (scanf("%d", &n) == 1) {
        vector<int> a(n);
        vector<int> pos(n);
        for (int i = 0; i < n; i++) {
            scanf("%d", &a[i]);
            --a[i];
            pos[a[i]] = i;
        }

        vector<int> frst(1, n - 1);
        for (int i = n - 2; i >= 0; i--) {
            bool nw = 0;
            if (frst.size() == 1) {
                nw = pos[i] > pos[frst.back()];
            } else {
                int p1 = pos[i];
                int p2 = pos[frst.back()];
                int p3 = pos[frst[(int)frst.size() - 2]];

                if ((p2 > p3) != (p1 > p3)) nw = p1 < p2;
                else nw = p1 > p2;
            }
            if (nw) frst.push_back(i);
            else frst.back()--;
        }
        printf("%d\n", (int)frst.size() - 1);
    }


#ifdef HOME
    cerr << "time: " << clock() * 1.0 / CLOCKS_PER_SEC << endl;
#endif
    return 0;
}

Measured memory_bytes: 2936
#include<iostream>
#include<algorithm>
#include<cstdint>
using namespace std;

int main() {
	int64_t A[3];
	cin >> A[0] >> A[1] >> A[2];
	sort(A, A+3);
	if ((A[0] & A[1] & A[2] & 1) > 0) cout << A[0] * A[1];
	else cout << 0;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

1つの直方体上、ということでどこかに分割線があると言える
当然だが、分割線はA/2、B/2、C/2のどれかになる
ここで、どれかが偶数ならそこで分割すれば差は0であり、そうでないなら最も大きい値の所で分割すれば差は残りの2要素の積になる
*/

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(void){
    int N;
    cin >> N;
    vector<char> S(N);
    for(int i=0;i<N;i++){
        cin >> S.at(i);
    }
    int count=0;
    for(int i=0;i<N-2;i++){
        if(S.at(i)=='A'&&S.at(i+1)=='B'&&S.at(i+2)=='C'){
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 3604
local n, a, b, c, d = io.read("*n", "*n", "*n", "*n", "*n", "*l")
local s = io.read()

local function check1(l, r)
  for i = l, r - 1 do
    if s:sub(i, i) == "#" and s:sub(i + 1, i + 1) == "#" then
      return false
    end
  end
  return true
end

local function check2(l, r)
  for i = l, r - 2 do
    if s:sub(i, i) == "." and s:sub(i + 1, i + 1) == "." and s:sub(i + 2, i + 2) == "." then
      return true
    end
  end
  return false
end

if c < d then
  local r = check1(a, c) and check1(b, d)
  print(r and "Yes" or "No")
else
  local r = check1(a, c)
  if not r then print("No")
  else
    r = check2(b - 1, d + 1)
    print(r and "Yes" or "No")
  end
end


Measured memory_bytes: 760
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin>>n>>k;
  string s;
  cin>>s;
  if(s[k-1]=='A'){
    s[k-1]='a';
  }else if(s[k-1]=='B'){
    s[k-1]='b';
  }else{
    s[k-1]='c';
  }
  cout<<s<<endl;
}

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

using namespace std;

int main() {
    int n;
    while (cin >> n) {
        if (n == 0) break;
        vector< pair<int, int> > res;
        for (int i = 0; i < n; i++) {
            int team;
            int m1, s1, m2, s2, m3, s3, m4, s4;
            cin >> team >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
            res.push_back(make_pair((m1+m2+m3+m4)*60+(s1+s2+s3+s4), team));
        }
        sort(res.begin(), res.end());
        cout << res[0].second << endl << res[1].second << endl << res[n-2].second << endl;
    }
    return 0;
}

Measured memory_bytes: 972
seven = 0
five = 0

A,B,C = map(int,input().split())
if A == 7:
    seven += 1
elif A == 5:
    five += 1
if B == 7:
    seven += 1
elif B == 5:
    five += 1
if C == 7:
    seven += 1
elif C == 5:
    five += 1
    
if seven == 1 or five == 2:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3060
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main(){
  int n, m, q;
  int sum[501][501] = {};

  scanf("%d%d%d", &n, &m, &q);

  for(int i=0;i<m;i++){
    int l, r;
    scanf("%d%d", &l, &r);
    r--; l--;
    sum[l][r]++;
  }

  for(int i=n-1;i>=1;i--){
    for(int j=i;j<n;j++){
      sum[i-1][j] += sum[i][j];
    }
  }

  for(int i=0;i<q;i++){
    ll ans = 0;
    int p, q;

    scanf("%d%d", &p, &q);
    p--; q--;

    for(int i=p;i<=q;i++) {
      ans += sum[p][i];
    }

    printf("%lld\n", ans);
  }

  return 0;
}


Measured memory_bytes: 1920
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}

template<class T1, class T2> void chmin(T1 &a, T2 b) { if (a>b)a = b; }

template<class T1, class T2> void chmax(T1 &a, T2 b) { if (a<b)a = b; }
template<class T>
void Add(T &a, const T &b, const T &mod = 1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}
////////////////////////////////////////

int main() {
	int N, M, C;
	int A[21][21];
	int B[21];
	cin >> N >> M >> C;
	for (int i = 0; i < M; ++i) {
		cin >> B[i];
	}
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < M; ++j) {
			cin >> A[i][j];
		}
	}
	int ans = 0;
	for (int i = 0; i < N; ++i) {
		int res = C;
		for (int j = 0; j< M; ++j) {
			res += A[i][j] * B[j];
		}
		if (res > 0) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(void){
    int n,m;
    scanf("%d %d",&n,&m);
    char data1[n][n+1];
    char data2[m][m+1];
    int i,j,k,l;
    for(i = 0;i<n;i++){
        scanf("%s",data1[i]);
    }
    for(i = 0;i<m;i++){
        scanf("%s",data2[i]);
    }
    int flag = 0;
    for(i = 0;i<n;i++){
        for(j = 0;j<n;j++){
            if(data1[i][j] == data2[0][0]){
                for(k = 0;k<m;k++){
                    for(l = 0;l<m;l++){
                            // printf("%d %d %d %d\n",i+k,j+l,k,l);
                            // printf("%c %c\n",data1[i+k][j+l],data2[k][l]);
                        if(data1[i + k][j + l] != data2[k][l]){
                        // printf("d1%c\n",data1[i+k][j+l]);
                        // printf("d2%c\n",data2[k][l]);
                        // printf("test\n");
                        flag = 1;
                            break;
                        }
                        if(l == m-1 && k == m-1){
                            printf("Yes\n");
                            return 0;
                        }
                    }
                    if(flag != 0){
                        flag = 0;
                        break;
                    }
                }
            }
        }
    }
    printf("No\n");
    return 0;
}

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

int main()
{
    string s;
    cin>>s;
    reverse(s.begin(),s.end());
    if(s[0]=='2'||s[0]=='4'||s[0]=='5'||s[0]=='7'||s[0]=='9')cout<<"hon"<<endl;
    else if(s[0]=='3')cout<<"bon"<<endl;
    else  cout<<"pon"<<endl;
}


Measured memory_bytes: 3600
n,m=map(int,input().split())
h=list(map(int,input().split()))
ans=[1]*n
for _ in range(m):
  a,b=map(int,input().split())
  if ans[a-1]:
    if h[a-1]<=h[b-1]:
      ans[a-1]=0
  if ans[b-1]:
    if h[b-1]<=h[a-1]:
      ans[b-1]=0
print(ans.count(1))

Measured memory_bytes: 20124
// ??±???????????¢?´¢(DFS:Depth First Search)
// ICPC Domestic 2004
//
#include <iostream>
using namespace std;

#define LIM 20
int w,h,sx,sy,ans;
bool field[LIM][LIM];
char buff[LIM];
bool flg=true;

void input(void);
void dump(void);
void dfs(int, int);
void solve();


int main(void)
{
    while(true){
        input();
        if(!flg)break; // ????????????????????????????¨??????§????????°??????????????????
        //dump();
        dfs(sx,sy);
        solve();
    }
    return 0;
}

void input(void){
    cin >> w >> h;
    if(w==0 && h==0){
        flg=false;
        return;
    }
    for(int i=0;i<h;++i){
        cin >> buff;
        for(int j=0;j<w;++j){
            if(buff[j]=='#')field[i][j]=false; // ????????????
            else field[i][j]=true; // ?????????
            if(buff[j]=='@'){
                sy=i;
                sx=j;
            }
        }
    }
    ans=0; //?§£????????????????????????????????¨????????????
    return;
}

void dump(void){
    cout << "sx:" << sx << " sy:" << sy << endl;
    for(int i=0;i<h;++i){
        for(int j=0;j<w;++j){
            cout << field[i][j];
        }
        cout << endl;
    }
}

void dfs(int x,int y){
    if(!field[y][x] || x<0 || y<0 || x>=w || y>=h) //????????¢?????????????????´????????´???
        return;
    else{
        field[y][x]=false;
        ++ans;
        dfs(x-1,y); //???
        dfs(x,y-1); //???
        dfs(x+1,y); //???
        dfs(x,y+1); //???
    }
    return;
}

void solve(){
    cout << ans << endl;
}

Measured memory_bytes: 1176
#include <cstdio>
#include <string>
#include <vector>
#include <stack>
#include <algorithm>

#define MOD 1000000007
#define INF 2147483647

typedef long long lint;
using namespace std;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T abs(T num) { return num > 0 ? num : -num; }

int main()
{
	int n;
	scanf("%d", &n);

	if (n < 1000) puts("ABC");
	else puts("ABD");

	return 0;
}

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

int main(){
    ll n;
    cin >> n;
    ll n1, n2 =0;
    ll ans = 1e+13;

    for (ll i = 1; i < sqrt(n)+1;i++)
    {
        if(ans>i+(n/i)-2 && i*(n/i) == n){
            ans = i + (n / i) - 2;
        }
    }
    cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

int main(){
  ll n, k, m=mod;
  cin >> n >> k;
  vector<int> h(n);
  rep(i, n) cin >> h.at(i);
  sort(all(h));
  for(int i = 0; i <= n-k; i++){ 
    m = min(m, (ll)h.at(i+k-1)-h.at(i));
  }
  cout << m;
}

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

int N;
vector<int> G[100010];
int dep[100010];
int sub[100010];

int DFS(int v,int p,int d)
{
    int res = 1;
    dep[v] = d;
    for(int i = 0; i < G[v].size(); i++)
    {
        int w = G[v][i];
        if(w == p)continue;
        res += DFS(w,v,d + 1);
    }
    sub[v] = res;
    return res;
}

vector<int> con(int v)
{
    vector<int> res;
    int now = v,bef = 0;
    while(now)
    {
        int nex = 0;
        int cnt = 0;
        for(int i = 0; i < G[now].size(); i++)
        {
            int w = G[now][i];
            if(w == bef)continue;
            if(sub[w] > 1)nex = w;
            else cnt++;
        }
        res.push_back(cnt);
        bef = now;
        now = nex;
    }
    return res;
}

int main()
{
    scanf("%d",&N);
    for(int i = 0; i < N - 1; i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        G[a].push_back(b);
        G[b].push_back(a);
    }

    int L,R;

    memset(dep,-1,sizeof(dep));
    memset(sub,-1,sizeof(sub));
    DFS(1,0,0);
    int MAX = 0,id;
    for(int i = 0; i <= N; i++)if(MAX < dep[i])
    {
        MAX = dep[i];
        id = i;
    }
    L = id;
    memset(dep,-1,sizeof(dep));
    memset(sub,-1,sizeof(sub));
    DFS(L,0,0);
    MAX = 0;
    for(int i = 1; i <= N; i++)if(MAX < dep[i])
    {
        MAX = dep[i];
        id = i;
    }
    R = id;

    int now = L,bef = 0;
    while(now)
    {
        int nex = 0;
        for(int j = 0; j < G[now].size(); j++)
        {
            int w = G[now][j];
            if(w == bef)continue;
            if(sub[w] > 1)
            {
                if(nex)
                {
                    printf("-1\n");
                    return 0;
                }
                nex = w;
            }
        }
        bef = now;
        now = nex;
    }

    DFS(L,0,0);
    vector<int> vL = con(L);
    DFS(R,0,0);
    vector<int> vR = con(R);

    int st = L;
    for(int i = 0; i < vL.size(); i++)
    {
        if(vL[i] < vR[i])
        {
            st = L;
            break;
        }
        if(vL[i] > vR[i])
        {
            st = R;
            break;
        }
    }
    vector<int> V,ans;
    if(st == L)V = vL;
    else V = vR;

    int top = 1;
    for(int i = 0; i < V.size(); i++)
    {
        if(V[i] == 0)ans.push_back(top++);
        else
        {
            for(int j = 0; j < V[i]; j++)
            {
                ans.push_back(top + j + 1);
            }
            ans.push_back(top++);
            top += V[i];
        }
    }

    swap(ans[N - 1],ans[N - 2]);

    for(int i = 0; i < N; i++)
    {
        printf("%d",ans[i]);
        if(i != N - 1)printf(" ");
    }printf("\n");
    return 0;
}


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

int main(){

//Question
//https://atcoder.jp/contests/abc118/tasks/abc118_b

  //人数と食べ物種類数
  int n,m;
  //好きな食べ物結果配列
  int food[31];
  //カウンタ
  int i,j,k;
  //入力、人ごとの好きな食べ物の数、全員が好きな食べ物の数
  int input,num,result;

  //食事の初期化
  for (i = 0; i <= 30; i++ ) {
    food[i] = 0;
  }

  //人数と種類を入力
  cin >> n >> m;

  for (j=1; j <= n; j++) {
    //人数分の入力
    k = 0;
    while(cin >> input){
      //人ごとの好きな食べ物の入力
      k++;
      //cout << "k:" << k << endl;
      if (k==1){
        //先頭は入力数
        num = input;
        //cout << "input:" << input << endl;
      } else {
        //それ以外は食べ物
        food[input]++;
        //cout << "input:" << input << " food:" <<food[input] << endl;
      }
      if (k > num) {
        //入力数を超えたら終了する
        //cout << "break" << endl;
        break;
      }
    }
  }

  result = 0;
  for (i = 0; i <= 30; i++ ) {
    if (food[i] == n) {
      //全員が好きな食事をカウントする
      result++;
    }
    //cout << food[i];
  }
  cout << result << endl;

  return 0;
}

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

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

fn main() {
    let k: usize = read();
    let x: usize = read();
    println!("{}", if 500 * k >= x { "Yes" } else { "No" });
}

Measured memory_bytes: 4352
'use strict'

function main(s) {

  s = s.split('\n')[0].split(' ');
  const n = Number(s[0]);
  const a = Number(s[1]);
  const b = Number(s[2]);
  let sum = 0;

  for (var i = 1; i <= n; i++) {
    const num = String(i).split('')
                         .map(x => Number(x))
                         .reduce((a, b) => a + b);
    if (a <= num && num <= b) sum += i;
  }

  console.log(sum);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

const int NUM =  1000000000 + 7;

long long fac(int n){
  if(n == 1){
    return 1;
  }
  else{
    return n*(fac(n - 1)%NUM);
  }
}

int main(){
  int n;
  cin >> n;
  long long ans;
  ans = fac(n)%NUM;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792