akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD 1000000007
 
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template <class T>
void print(T& x){printf("%d\n", x);}
void printvec(vector<int> a){
    rep(i, a.size()-1){
        printf("%d ", a[i]);
    }
    printf("%d\n", a[a.size()-1]);
}
 
int main()
{
    int x;
    cin >> x;
    printf("%d:", x/3600);
    x %= 3600;
    printf("%d:", x/60);
    x %= 60;
    printf("%d\n", x);
    return 0;
}


Measured memory_bytes: 3132
#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){
  Node y;
  if(x->right!=NIL){
    return treeMinimum(x->right);
  }
  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;
  }
  free(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){
    return;
  }
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u==NIL){
    return;
  }
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}

void find(int x){
  Node t;
  t = treeSearch(root, x);
  if ( t != NIL ) printf("yes\n");
  else printf("no\n");
}
  
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);
      find(x);
    } 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: 20472
N = int(input())
a = list(map(int, input().split()))

cnt = 1
ans = 0
ng = 1
for i in range(N):
    if a[i] == cnt:
        cnt += 1
        ng = 0
    else:
        ans += 1

if ng == 1:
    ans = -1

print(ans)

Measured memory_bytes: 24744
import os,re,sys,operator
from collections import Counter,deque
from operator import itemgetter
from itertools import accumulate,combinations,groupby
from sys import stdin,setrecursionlimit
from copy import deepcopy
import heapq

setrecursionlimit(10**6)

n,k=map(int,stdin.readline().rstrip().split())
v=deque([int(i) for i in stdin.readline().rstrip().split()])
ans=0
m=min(n,k)+1
loop=iter((i,j) for i in range(m) for j in range(m-i))
for i in loop:
    now=[]
    heapq.heapify(now)
    aban=k-(i[0]+i[1])
    
    for j in range(i[0]):
        heapq.heappush(now,v[j])
    
    for j in reversed(range(n-1,n-i[1]-1,-1)):
        heapq.heappush(now,v[j])
    
    for j in range(aban):
        if len(now)!=0 and now[0]<0:
            heapq.heappop(now)
        else:
            break
    ans=max(sum(now),ans)
print(ans)

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

int main(void){
    int n,k;
    cin >> n >> k;
    ll c[n], p[n];
    for(int i = 0; i < n; i++)
        cin >> p[i];
    for(int i = 0; i < n; i++)
        cin >> c[i];
    ll ans= -1e9 - 1;
    for(int i = 0; i < n; i++){
        ll mx=-1e9-1;
        ll sum = 0;
        int position;
        int a = p[i] - 1;
        sum += c[a];
        mx = max(mx, sum);
        int times = 1;
        while(a != i && times < k){
            a= p[a] - 1;
            sum += c[a];
            times++;
            mx = max(mx, sum);
        }
        int loop = k / times;
        int left = k % times;
        if(sum <= 0){
            ans = max(mx, ans);
        }
        else{
            sum *= loop - 1;
            a = p[i] - 1;
            for(int j = 0; j < left + times; j++){
                sum += c[a];
                a = p[a] - 1;
                mx = max(mx, sum);
            }
            ans = max(mx, ans);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3708
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  std::string s, t;

  int w;

  std::cin >> s >> w;

  for (int i = 0, size = s.size(); i < size; i += w)
    t.push_back(s[i]);

  std::cout << t << std::endl;

  return 0;
}


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

int main() {
  char c;
  cin >> c;
  
  if (c == 'a') {
    cout << 'b' << endl;
  }
  if (c == 'b') {
    cout << 'c' << endl;
  }
  if (c == 'c') {
    cout << 'd' << endl;
  }
  if (c == 'd') {
    cout << 'e' << endl;
  }
  if (c == 'e') {
    cout << 'f' << endl;
  }
  if (c == 'f') {
    cout << 'g' << endl;
  }
  if (c == 'g') {
    cout << 'h' << endl;
  }
  if (c == 'h') {
    cout << 'i' << endl;
  }
  if (c == 'i') {
    cout << 'j' << endl;
  }
  if (c == 'j') {
    cout << 'k' << endl;
  }
  if (c == 'k') {
    cout << 'l' << endl;
  }
  if (c == 'l') {
    cout << 'm' << endl;
  }
  if (c == 'm') {
    cout << 'n' << endl;
  }
  if (c == 'n') {
    cout << 'o' << endl;
  }
  if (c == 'o') {
    cout << 'p' << endl;
  }
  if (c == 'p') {
    cout << 'q' << endl;
  }
  if (c == 'q') {
    cout << 'r' << endl;
  }
  if (c == 'r') {
    cout << 's' << endl;
  }
  if (c == 's') {
    cout << 't' << endl;
  }
  if (c == 't') {
    cout << 'u' << endl;
  }
  if (c == 'u') {
    cout << 'w' << endl;
  }
  if (c == 'w') {
    cout << 'x' << endl;
  }
  if (c == 'x') {
    cout << 'y' << endl;
  }
  if (c == 'y') {
    cout << 'z' << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define show(x) cout << #x << " = " << (x) << endl;
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl;
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

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

int main () {
  ll a, b, k;
  cin >> a >> b >> k;

  if (k <= a) cout << a-k SP b << endl;
  else if (k <= a + b) cout << 0 SP b - (k-a) << endl;
  else cout << 0 SP 0 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  
  string ans = "";
  
  int temp = 0;
  while(sy + temp < ty){
    ans += 'U';
    temp++;
  }
  
  temp = 0;
  while(sx + temp < tx){
    ans += 'R';
    temp++;
  }
  
  temp = 0;
  while(sy < ty - temp){
    ans += 'D';
    temp++;
  }
  
  temp = 0;
  while(sx < tx - temp){
    ans += 'L';
    temp++;
  }
  
  ans += 'L';
  
  temp = 0;
  while(sy + temp < ty + 1){
    ans += 'U';
    temp++;
  }
  
  temp = 0;
  while(sx - 1 + temp < tx){
    ans += 'R';
    temp++;
  }
  
  ans += 'D';
  ans += 'R';
  
  temp = 0;
  while(sy - 1 < ty - temp){
    ans += 'D';
    temp++;
  }
  
  temp = 0;
  while(sx < tx + 1 - temp){
    ans += 'L';
    temp++;
  }
  
  ans += 'U';
  
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String n = sc.next();
    if (n.charAt(n.length()-1) == '3') {
      System.out.println("bon");
    } else if (n.charAt(n.length()-1) == '0' || n.charAt(n.length()-1) == '1' || n.charAt(n.length()-1) == '6' || n.charAt(n.length()-1) == '8') {
      System.out.println("pon");
    } else {
      System.out.println("hon");
    }
    sc.close();
  }
}

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

int main(void){
    int a,b,h,m;
    scanf("%d%d%d%d",&a,&b,&h,&m);
    long double hm = 30.0l * h + m / 2.0l;
    long double mm = m * 6.0l;
    long double ans;
    long double diff;
    if(hm-mm > 180.0l)diff = hm - mm + 360.0l;
    else diff = hm - mm;
    long double d =  diff/ 180.0l * M_PI;
    if(a > b) ans = sqrtl((cosl(d)*a - b)*(cosl(d)*a - b) + (a*sinl(d))*(a*sinl(d)));
    else ans = sqrtl((cosl(d)*b - a)*(cosl(d)*b - a) + (b*sinl(d))*(b*sinl(d)));
    printf("%.10Lf",ans);
}

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

int main() {
  long count =0;
  long q=0,w=0,e=0,r=0;
  int N; cin>>N;
  vector<long>A(N+1);
  vector<long>B(N);
  rep(i,N+1){
    cin>>A[i];
  }
  rep(i,N){
    cin>>q;
    w=min(q,A[i]+A[i+1]);
    count+=w;
    A[i+1]-=w-min(q,A[i]);
  }
  cout<<count;

}

Measured memory_bytes: 1792
N = int(input())
k1= []
k2= []
count=0
for i in range(N):
    n1,n2= map(int,input().split())
    k1.append(n1)
    k2.append(n2)
for j in range(N-2):
    if k1[j] == k2[j] and k1[j+1] == k2[j+1] and k1[j+2] == k2[j+2]:
        count +=1
if count != 0 :
    print("Yes")
else:
    print("No")
  

Measured memory_bytes: 9208
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <algorithm>
#include <limits.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#define ll long long
#define MSET(x) memset((x), 0, sizeof((x)))
#define MMSET(x) memset((x), -1, sizeof((x)))
#define rep(i, a, b) for ( int (i) = a; (i) < (b) ; (i) ++ )
#define repA(i, a, b) for ( int (i) = a ;  (i) <= (b) ; (i) ++ )
#define repD(i, a, b) for ( int (i) = a; (i) >= (b) ; (i) -- )
#define fi first
#define se second
#define pb push_back
#define mfind(m, item) ((m).find((item)) != (m).end())
#define mp(a,b) make_pair((a),(b))
#define mt(a,b,c) make_pair(make_pair((a),(b)), (c))
#define tfi first.first
#define tse first.second
#define tth second
#define print cout << endl
#define tri pair<pair<int, int>, int>
using namespace std;
int n;
pair<ll, ll> nextSmall(ll a, ll b, ll t1, ll t2){
	ll r = 1000000000000000000, l = 0;
	while ( r - l > 1 ){
		ll m = (l + r)/ 2;
		ll k1 = t1 * m;
		if ( k1 < t1 ){
			r = m;
			continue;
		}
		ll k2 = t2 * m;
		if ( k2 < t2 ){
			r = m;
			continue;
		}
		if ( k1 >= a && k2 >= b ){
			r = m;
			continue;
		}
		else {
			l = m;
			
		}
	}	
	return make_pair(r * t1, r * t2);
}
int main(){
	cin >> n;
	ll a,b;
	a = 1;
	b = 1;
	ll t1, t2;
	for ( ll i = 0 ; i < n ; i ++ ){
		cin >> t1 >> t2;
		pair<ll,ll> temp = nextSmall(a,b,t1, t2);
		a = temp.first;
		b = temp.se;
	}
	cout << a + b << endl;
}

Measured memory_bytes: 256
if __name__ == '__main__':
	K = int(input())

	L = [['0'],['1'],['2'],['3'],['4'],['5'],['6'],['7'],['8'],['9']]

	ans = 0
	count = 9
	check = 0

	if K < 10:
		ans = L[K][0]
		check = 1

	while check == 0:
		newL = [['']] * 10
		for i in range(10):
			newls = []
			if i == 0:
				for s in L[0]:
					newls.append(str(i)+s)
				for s in L[1]:
					newls.append(str(i)+s)
			elif i == 9:
				for s in L[8]:
					newls.append(str(i)+s)
					count += 1
					if count == K:
						ans = newls[-1]
						check = 1
				for s in L[9]:
					newls.append(str(i)+s)
					count += 1
					if count == K:
						ans = newls[-1]
						check = 1
			else:
				for j in range(-1,2):
					for s in L[i+j]:
						newls.append(str(i)+s)
						count += 1
						if count == K:
							ans = newls[-1]
							check = 1

			newL[i] = newls[:]

		L = newL[:]


	print(int(ans))

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

int main(){
    int n ;
    string s ;
    cin >> n ;
    cin >> s ;
    int count = 0 ;
    for( int i = 0 ; i < 1000 ; i++  ){
        int c[3] = { i/100 , i/10%10 , i%10 } ;
        int r = 0 ;
        for(int j = 0 ; j < n ; j++ ){
            if( s[j] == '0' + c[r] ) r++ ;
            if( r ==  3 ) break ;
        }
        if( r == 3 ) count++ ; 
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

main() {
    int64_t n, m;
    cin >> n >> m;

    vector<pair<int64_t, int64_t>> p(n);
    for (auto&& ab : p) {
        cin >> ab.first >> ab.second;
    }
    sort(p.begin(), p.end());

    priority_queue<int64_t> q;
    int64_t ans = 0;
    int64_t idx = 0;
    for (int64_t d = m; d >= 0; --d) {
        while (idx < p.size() && d + p[idx].first <= m) {
            q.push(p[idx].second);
            ++idx;
        }

        if (q.empty()) {
            continue;
        }

        ans += q.top();
        q.pop();
    }

    cout << ans << endl;
}

Measured memory_bytes: 2936
// 6/28 バーチャル参加
#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>;
using Graph = vector<vector<int>>;

int main() {
    int H, W, K;
    cin >> H >> W >> K;
    vector<string> field(H);
    rep(h, H) cin >> field[h];

    int res = 0;

    rep(div, 1<<(H+W)) {
        int black = 0;
        
        vector<bool> b1(H, false);
        vector<bool> b2(W, false);

        rep(i, H+W) {
            if (div>>i&1) {
                if (i < H) b1[i] = true;
                else b2[i-H] = true;
            }
        }

        rep(h, H) {
            rep(w, W) {
                if (b1[h] == false && b2[w] == false && field[h][w] == '#') {
                    black++;
                }
            }
        }

        if (black == K) {
            res++;
        }
    }

    cout << res << endl;
}

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

int main() {
  int h,w;cin>>h>>w;
  string s;
  vector<string> vec(h);
  rep(i,h)cin>>vec[i];
  rep(i,h*2){
    cout<<vec[i/2]<<endl;
  }
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define fi first
#define sc second
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define ANS cout << ans << endl
#define RETURN(x)    \
  cout << x << endl; \
  return 0
clock_t CLOCK;
#define START_TIMER CLOCK = clock()
#define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << endl
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

signed main() {
  init();
  ll N;
  cin >> N;

  ll bt = 0;
  ll bx = 0;
  ll by = 0;
  rep(i, N) {
    ll t, x, y;
    cin >> t >> x >> y;
    ll du = t - bt;
    ll distance = abs(x - bx) + abs(y - by);
    if (du < distance || distance % 2 != du % 2) {
      COUT("No");
      return 0;
    }
    bt = t;
    bx = x;
    by = y;
  }
  COUT("Yes");

  return 0;
}

Measured memory_bytes: 3604
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
inline string getstr(string &s,int l,int r){string ret="";for(int i=l;i<=r;i++)ret.push_back(s[i]);return ret;}
int modpow(int x,int y,int md=mod){if(y==0)return 1;int ret=modpow(x,y>>1,md);ret=(ll)ret*ret%md;if(y&1)ret=(ll)ret*x%md;return ret;}
int dp[303][303][303];
int n,m;
inline void add(int &x,int y){
	x+=y;
	if(x>=mod)x-=mod;
}
int main(){
	cin>>n>>m;
	dp[0][0][n-1]=1;
	for(int i=0;i<m;i++){
		for(int j=0;j<=n;j++){
			for(int k=0;j+k<=n;k++){
				add(dp[i+1][0][k],(ll)dp[i][j][k]*(n-j-k)%mod);
				add(dp[i+1][j][k],(ll)dp[i][j][k]*j%mod);
				if(k)add(dp[i+1][j+1][k-1],(ll)dp[i][j][k]*k%mod);
			}
		}
	}
	cout<<dp[m][0][0]<<endl;
	return 0;
}

Measured memory_bytes: 108416
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

using namespace std;

const int N = 1001010;

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

  int best = 0;
  int n; cin >> n;
  map<string, int> mp;
  for(int i = 0; i < n; ++i) {
    string s; cin >> s;
    mp[s]++;
    if(mp[s] > best) best = mp[s];
  }
  for(auto it: mp) {
    if(it.second == best) cout << it.first << "\n";
  }
}


Measured memory_bytes: 23808
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e19;
const int MOD = (int)1e9 + 7;

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

    int a, b;
    cin >> a >> b;

    cout << (b % a == 0 ? a+b : b-a) << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

def judge(s):
    if s[0] != 'A':
        return False
    if s[2:-1].count('C') != 1:
        return False
    if not s[1:].replace('C', 'c').islower():
        return False
    return True

s = input()
if judge(s):
    print("AC")
else:
    print("WA")



Measured memory_bytes: 2940
#include <bits/stdc++.h>//coded by Nurstan ^_^

#define ll long long
#define pb push_back

#define mp make_pair
#define lb lower_bound
#define ub upper_bound

#define all(x) x.begin(), x.end()
#define F first
#define S second

// fixed << setprecision
// next_permutation(a, a + n)
// set <int> :: iterator it = x.begin(); it != x.end(); it ++

using namespace std;

inline void boost(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
}

int main(){
	boost();
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	string a;
	cin >> a;
	int sum = 0;
	int l = 0, r = 0;
	for(int i = 0; i < a.size(); i ++) {
		if(a[i] == 'S') {
			int x = l, y = r;
			//cout << x << " " << y << " ";
			sum += min(l, r);
			l = 0;
			r = 0;
			if(x > y) {
				int o = x - y;
				l = o;
			}
			l ++;
		}
		else {
			r ++;
		}
	}
	if(a[a.size() - 1] == 'T') {
		int x = l, y = r;
			//cout << x << " " << y << " ";
			sum += min(l, r);
	}
	cout << a.size() - (sum * 2);
	exit(0);
}



Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define dd double
#define MOD1 1000000007
#define MOD2 998244353
#define nl cout<<endl
#define rt ll Q[100005]={0}
#define mp make_pair
#define test() ll t;cin>>t;while(t--)
#define pb push_back
#define ff first    
#define ss second
#define all(v) v.begin(),v.end()
#define s(ar,n) sort(ar,ar+n)
#define rs(ar,n) sort(ar, ar+n, greater<ll>()) 
#define oa(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define ov(a,n) for(ll i=n-1;i>=0;i--)cout<<a[i]<<" ";nl
#define ovp(a,n) for(ll i=0;i<n;i++)cout<<a[i].ff<<" "<<a[i].ss<<endl;
#define maxa(ar,N) *max_element(ar,ar+N)
#define mina(ar,N) *min_element(ar,ar+N)
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef pair<ll,ll> pii;
ll powe(ll n,ll m){if(m==0)return 1;ll t=powe(n,m/2);if(m%2==0)return (t*t);return (((t*t))*n);}
ll mpowe(ll n,ll m,ll MOD){if(m==0)return 1;ll t=mpowe(n,m/2,MOD);t%=MOD;if(m%2==0)return (t*t)%MOD;return (((t*t)%MOD)*n)%MOD;}
ll logtwo(ll n){if(n==1)return 0;if(n==0) return -1;return logtwo(n/2)+1;}
int main()
{
    fastio();
   
    ll n;
    cin>>n;
    ll ans=1;
    for(int i=2;i<n;i++)
    {
        ll temp = 1,x=i;
        for(int j=2;j*j<=x;j++)
        {
            ll c=0;
            if(x%j==0)
            {
                while(x%j==0)
                {
                    c++;
                    x = x/j;
                }
                temp*= (c+1);
            }
        }
        if(x>1)
            temp*=2;
        //cout<<i<<" "<<temp<<endl;
        ans+=temp;
    }
    cout<<ans<<endl;
    
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RNG(i,from,to) for(int i=(from); i<(int)(to); i++)
#define gcd(i,j) __gcd((i), (j))
typedef long long ll;
typedef pair<int, int> pii;
template<typename S, typename T> string to_string(pair<S, T> p) { return "("+to_string(p.first)+","+to_string(p.second)+")"; }
template<typename T> string to_string(T p[2]) { return "["+to_string(p[0])+","+to_string(p[1])+"]"; }
template<typename T> void println(T e){ cout << to_string(e) << endl; }
template<typename T> void println(const vector<T>& v){ cout << "[";for(const auto& e : v){ cout << to_string(e) << ","; }cout << "]";cout << endl; }
template<typename T> void println(const vector<vector<T>>& vv){ for(const auto& v : vv){ println(v); } }
template<typename Iter> void println(Iter first, Iter last){ for(auto it=first; it != last; it++){ cout << *it << " "; }; cout << endl; }
const ll DVSR = 1e9+7;


int main(int argc, char const *argv[])
{
  ll N; cin >> N;
  cout << (N%2 ? N*2 : N) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using P = pair<int,int>;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1000000007
#define INF 100000000000000000
#define EPS 1e-9
const vector<vector<int>> DXY={{-1,0},{1,0},{0,-1},{0,1}};

//----***パーツ***----
#define fi first
#define se second
#define pb push_back
#define re return
#define br break

//----***入出力***---
void print() { std::cout << "\n"; }
template <class T>void print(const T &x) {std::cout << x<<"\n";}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);};}initial_;

signed main(){
  vector<int> dishes(5);
  REP(i,0,5)cin>>dishes[i];
  int ans=0, modulo=INF;
  REP(i,0,5){
    int dish=dishes[i];
    if(dish%10==0){
      ans+=dish;
    }
    else{
      ans+=(dish/10+1)*10;
      modulo=min(modulo,dish%10);
    }
    // debug(ans);
  }
  if(modulo==INF)print(ans);
  else print(ans+modulo-10);

  

}


Measured memory_bytes: 256
def main():
  a, b = map(int, input().split())
  s = input()
  for i in range(len(s)):
    if i == a:
      if s[i] != '-':
       	return False
    else:
      if s[i] == '-':
        return False
  return True
 
if __name__ == '__main__':
  if main():
    print('Yes')
  else:
    print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll,ll> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
ll n,t,dp[3005][3005],ans=-INF;
P x[3005];
void up(ll &x,ll y){
	x=max(x,y);
}
int main(void){
    cin>>n>>t;
    for(int i=0;i<n;i++)cin>>x[i].F>>x[i].S;
    sort(x,x+n);
    for(int i=0;i<=n;i++)for(int j=0;j<=t;j++)dp[i][j]=-INF;
    dp[0][0]=0;
    for(int i=0;i<n;i++){
		for(int j=0;j<=t;j++){
			up(dp[i+1][j],dp[i][j]);
			if(j<t)up(dp[i+1][min(t,j+x[i].F)],dp[i][j]+x[i].S);
		}
	}
	for(int i=0;i<=t;i++)up(ans,dp[n][i]);
	cout<<ans<<endl;
}


Measured memory_bytes: 70784
#include <iostream>
#include<string>
using namespace std;
int main(void){
    string S;
    cin>>S;
    if(S[0]==S[1]){
        cout<<"Bad"<<endl;
    }else if(S[1]==S[2]){
        cout<<"Bad"<<endl;
    }else if(S[2]==S[3]){
        cout<<"Bad"<<endl;
    }else{
        cout<<"Good"<<endl;
    }
    return 0;
    
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"os"
	"strconv"
	"strings"
	// "math"
	"fmt"
	"math/rand"
	"time"
)

var (
	sc = bufio.NewScanner(os.Stdin)
)

const mod = 1e9 + 7

func main() {
	var s = nextLine()
	var L = len(s)

	dp := make([][]int, L+1)
	for i := 0; i < L+1; i++ {
		dp[i] = make([]int, 13)
	}

	dp[0][0] = 1

	for k := 0; k < L; k++ {
		for m := 0; m < 13; m++ {
			if s[k] == '?' {
				for i := 0; i < 10; i++ {
					dp[k+1][(m * 10 + i) % 13] += dp[k][m]
					dp[k+1][(m * 10 + i) % 13] %= mod
				}
			} else {
				var si = int(s[k] - '0')
				dp[k+1][(m * 10 + si) % 13] += dp[k][m]
				dp[k+1][(m * 10 + si) % 13] %= mod
			}
		}
	}

	fmt.Println(dp[L][5])
}

// Input helpers
func init()  {
	rand.Seed(time.Now().UnixNano())
	buf := make([]byte, 0) //ここのサイズは何でもよさそう
	sc.Buffer(buf, 1000000009)
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func spaceLine() []string {
	sc.Scan()
	return strings.Split(sc.Text()," ")
}

func intLine() []int {
	str := spaceLine()
	buf := make([]int,len(str))
	for i,s:=range str{
		buf[i],_ = strconv.Atoi(s)
	}
	return buf
}


Measured memory_bytes: 14720
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int i=0;
  map<int,int>mp;
  while(1){
    i++;
    mp[n]++;
    if(mp[n]==2){
      cout<<i<<endl;
      return 0;
    }
    if(n%2==0){
      n/=2;
    }
    else{
      n=3*n+1;
    }
  }
} 

Measured memory_bytes: 256
#include<bitset>
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<utility>
#include<initializer_list>
#include<tuple>
#include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, a, n) for(int i=(a);i<(int)(n);i++)
#define repc(i, a, n) for(int i=(a);i<=(int)(n);i++)
#define all(t) t.begin(), t.end()
#define rall(t) t.rbegin(), t.rend()
#define mat(type, row, col, init) vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout<<(cond? "Yes":"No")<<endl;
#define YES(cond) cout<<(cond? "YES":"NO")<<endl;
#define DBG(str) cerr<<(str)<<endl;
int main() {
	int n;
	cin >> n;
	vector<ll> a(n);
	rep(i, 0, n)cin >> a[i];
	int cnt = 0;
	rep(i, 0, n) {
		while (a[i] >= 2 &&a[i] % 2 == 0) {
			a[i] /= 2;
			cnt++;
		}
//		cerr << cnt << endl;

	}
	cout << cnt << endl;
	return 0;
}





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

// ?????¬???????????¬??????
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// ???
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long double> vld;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T> int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F> int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T> void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C> void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U> void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U> void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C> void reverse(C& c) { reverse(ALL(c)); }
template<typename C> void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred> void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// ?????°
#pragma region CONST_VAL
constexpr int PI = (2*acos(0.0));
constexpr int EPS = (1e-9);
constexpr int MOD = (int)(1e9+7);
constexpr int INF = 100000000;
#pragma endregion


int main()
{
    int t, p, r;
    while(cin>>t>>p>>r, t) {
        vector<vector<int> > v(t, vector<int>(3, 0));
        for(int i=0; i<t; ++i) v[i][2] = i;
        vector<vector<int> > wa(t, vector<int>(p, 0));
        while(r--) {
            int tid, pid, tim;
            string m;
            cin >> tid >> pid >> tim >> m;
            tid--;
            pid--;
            if(m[0]=='C') {
                v[tid][0]++;
                v[tid][1] += wa[tid][pid]*1200 + tim;
            }
            else wa[tid][pid]++;
        }

        for(int i=0; i<t; ++i) v[i][0] *= -1;
        sort(ALL(v));
        for(int i=0; i<t; ++i) v[i][0] *= -1;
        for(auto u : v) cout << u[2]+1 << " " << u[0] << " " << u[1] << endl;
    }
    return 0;
}

Measured memory_bytes: 3172
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int n;
vector<int> vec, ans;

int main(void)
{
	cin >> n;
	int a;
	for(int i = 0; i < n; i++){
		cin >> a;
		vec.push_back(a);
	}
	
	while(vec.size()){
		bool flag = false;
		for(int i = vec.size()-1; i >= 0; i--){
			if(vec[i] == i+1){
				ans.push_back(vec[i]);
				vec.erase(vec.begin() + i);
				flag = true;
				break;
			}
		}
		if(!flag && vec.size() > 0){
			cout << -1 << endl;
			return 0;
		}
	}
	reverse(ans.begin(), ans.end());
	for(int i = 0; i < ans.size(); i++) cout << ans[i] << endl;
	
	return 0;
}

Measured memory_bytes: 256
//confilm 0LL and 1LL
//confilm cornercases such as 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecVec = vector<Vec>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPR(i, n, 1)
#define co(n) cout << (n) << endl
#define cosp(n) cout << (n) << ' '
#define setp(n) cout << fixed << setprecision(n);
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T& b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a > b){a = b; return true;} return false;}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

int main(void){
	ll n, a;
	cin >> n >> a;
	co(n*n-a);

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int i;
  int alphabet[26] = {};
  char input_str[27];
  scanf("%s", input_str);
  for(i = 0; i < strlen(input_str); i++) {
    alphabet[input_str[i]-'a']++;
  }
  for(i = 0; i < 26; i++) {
    if(alphabet[i] > 1) {
      printf("no\n");
      i--;
      break;
    }
  }
  if(i == 26) {
    printf("yes\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int  long long int
#define pb push_back
#define fe first
#define lb lower_bound 
#define ub upper_bound
#define pii pair<pair<int,int>,pair<int,int> >
#define se second
#define endl "\n"
#define pi pair<int, int>
#define mi          map<int,int>
#define mii         map<pi,int>
#define vi vector<int> 
#define vvi vector<vi>
#define bs   binary_search
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i<=b;i++)	
#define all(c) (c).begin(),(c).end()
#define sz(x)       (int)x.size() 
#define PI 3.14159265358979323846

 const int N=2e5+5;

 int mod= 1e9+7;
 int dx[4]={0,0,+1,-1};
 int dy[4]={+1,-1,0,0};  
 
 
int po(int a, int b) {
	a %= mod;
	int res = 1;
	while (b > 0) {
		if (b & 1)
			res = (res * a) % mod;
		a =(a*a) % mod;
		b >>= 1;
	}
	 return res;	
   }


int n,a[N];


void solve() {
    //~ cin>>n;
    n=5;
    rep(i,0,n) {
		  cin>>a[i];
		}
	int ind=1;
	rep(i,0,n) {
		  if(a[i]==0)
		    ind=i+1;
		}
		cout<<ind<<endl;
		
    
 }

    
int32_t main() {
	cool;
	int t=1;
	//cin>>t;
	while(t--)
	  solve();

return 0;	   
}


Measured memory_bytes: 3628
# -*- coding: utf-8 -*-
N, M = map(int, input().split())
list_drink = []
for n in range(N):
    list_drink.append(list(map(int, input().split())))
    
list_drink.sort()

sum_bottle = 0
sum_money = 0
cnt_lp = 0
while(sum_bottle <= M - 1):
    num_money = list_drink[cnt_lp][0]
    num_bottle = list_drink[cnt_lp][1]
    if sum_bottle + num_bottle >= M:
        sum_money += num_money * (M - sum_bottle)
        sum_bottle = M
    else:
        sum_money += num_money * num_bottle
        sum_bottle += num_bottle
    cnt_lp += 1

print(sum_money)

Measured memory_bytes: 27880
#include<stdio.h>
int main()
{
	int w,h,n,a,x,y,i,w0 = 0,h0 = 0,minw = 0,maxw,minh = 0,maxh,flag = 0;
	scanf("%d %d %d",&w,&h,&n);
	maxw = w;
	maxh = h;
	for(i = 0;i < n;i++)
	{
		scanf("%d %d %d",&x,&y,&a);
		if(a == 1)
		{
			if(minw < x)
				minw = x;
		}
		else if(a == 2)
		{
			if(maxw > x)
				maxw = x;
		}
		else if(a == 3)
		{
			if(minh < y)
				minh = y;
		}
		else
		{
			if(maxh > y)
				maxh = y;
		}
	}
	if((maxw - minw) > 0 && (maxh - minh))
		printf("%d\n",(maxw - minw) * (maxh - minh));
	else
		printf("0\n");
	return 0;
}


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


int main()
{
	int x, a, b;
	cin >> x >> a >> b;
	if (a >= b)
	{
		cout << "delicious";
	}
	else if (a + x >= b)
	{
		cout << "safe";
	}
	else { cout << "dangerous"; }
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define maxn 105 
using namespace std;
int d[maxn][maxn];
int D[maxn][maxn];
int f[maxn][maxn]; 
int main() {
	int A, B;
	scanf("%d%d", &A, &B);
	for(int i = 1; i <= A; ++i) for(int j = 1; j <= B; ++j) scanf("%d", d[i] + j);
	for(int a = 0; a <= 100; ++a) {
		for(int b = 0; b <= 100; ++b) {
			for(int x = 1; x <= A; ++x) {
				for(int y = 1; y <= B; ++y) {
					f[a][b] = max(f[a][b], d[x][y] - x * a - y * b);
				}
			}
		}
	}
	memset(D, 0x3f, sizeof D);
	for(int x = 1; x <= A; ++x) {
		for(int y = 1; y <= B; ++y) {
			for(int a = 0; a <= 100; ++a) {
				for(int b = 0; b <= 100; ++b) {
					D[x][y] = min(D[x][y], x * a + y * b + f[a][b]);
				}
			}
		}
	}
	bool same = true;
	for(int x = 1; x <= A; ++x) 
		for(int y = 1; y <= B; ++y) 
			if(D[x][y] != d[x][y]) same = false;
	puts(same ? "Possible" : "Impossible");
	if(same) {
		puts("202 10401");
		for(int i = 1; i <= 100; ++i) {
			printf("%d %d X\n", i, i + 1);
			printf("%d %d Y\n", i + 101, i + 102);
		}
		for(int a = 0; a <= 100; ++a) 
			for(int b = 0; b <= 100; ++b) 
				printf("%d %d %d\n", a + 1, 202 - b, f[a][b]);
		puts("1 202");
	}
	return 0;
}

Measured memory_bytes: 3860
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
#include <map>
#include <set>
using namespace std;

string makeSub(string s, int l, int r) {
    string t = s.substr(l, r - l + 1);
    return t;
}
int main() {
    string s;
    int k;
    cin >> s >> k;
    int n = s.size() - 1;
    set<string> p;
    map<string, int> q;
    for (int i = 0; i <= n;i++) {
        for (int j = i;j <= min(k+i-1,n);j++) {
            string t = makeSub(s, i, j);
            if (q[t] >= 1) q[t]++;
            else {
                p.insert(t);
                q[t]++;
            }
        }
    }
    set<string>::iterator it = p.begin();
    int l = 1;
    while (l < k) {
        it++;
        l++;
    }
    cout << *it << endl;
}
	

Measured memory_bytes: 2560
// Aizu Vol-5 0589: Production
// 2017.8.30 bal4u@uu

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define HASHSIZ  1100009
typedef struct { char *nm; int id; } HASH;
HASH hash[HASHSIZ+2];

int lookup(char *nm, int len, int id)
{
	HASH *tp;
	int i = (101 * *nm + 103 * *(nm + len - 1) + 107 * len) % HASHSIZ;

	tp = hash + i;
	if (tp->nm != NULL) {
		int inc = *nm + (*(nm + 1) << 1);
		while (1) {
			if (!strcmp(tp->nm, nm)) return tp->id;
			i += inc;
			if (i >= HASHSIZ) i -= HASHSIZ;
			tp = hash + i;
			if (tp->nm == NULL) break;
		}
	}
	tp->nm = nm, tp->id = id;
	return -1;
}

#define MAX 100000
typedef struct { char *nm; int w, s; } T;
T tbl[MAX+2];
char nm[MAX+2][6]; int len;

int cmp(T *a, T *b) 
{
	if (a->w - b->w) return a->w - b->w;
	return strcmp(a->nm, b->nm);
}

int main()
{
	int n, id, w, x;

	scanf("%d", &n); len = 0;
	while (n-- > 0) {
		scanf("%s%d", nm[len], &x);
		w = strlen(nm[len]);
		if ((id = lookup(nm[len], w, len)) < 0) tbl[len].nm = nm[len], tbl[len].s = x, tbl[len++].w = w;
		else tbl[id].s += x;
	}
	qsort(tbl, len, sizeof(T), cmp);
	for (id = 0; id < len; id++) printf("%s %d\n", tbl[id].nm, tbl[id].s);
	return 0;
}

Measured memory_bytes: 2792
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPm(i,n) for(int i=(n)-1;i>=0;i--)
#define REP1(i,n) for(int i=1;i<=(n);i++)
#define mp make_pair
typedef long long ll;
int main(){
    string s;
    cin >> s;
    REP(i,s.length()-1){
        if(s[i] == s[i+1]){
            cout << i+1 << " " << i+2 << endl;
            return 0;
        }
        if(i < s.length()-2 && s[i] == s[i+2]){
            cout << i+1 << " " << i+3 << endl;
            return 0;
        }
    }
    cout << "-1 -1"<< endl;
    return 0;
}


Measured memory_bytes: 512
def main():
  n, m, k = map(int, input().split())
  A = list(map(int, input().split()))
  B = list(map(int, input().split()))
  B.insert(0, 0)

  data = [None] * n
  total = 0
  for i in range(n):
    a = A[i]
    data[i] = (total, total + a)
    total += a
  data.append((total, float('inf')))

  def bi_search(num, l, r):
    if l > r:
      return n

    i = (l + r) // 2

    tail, head = data[i]
    if tail <= num < head:
      return i

    if num < tail:
      return bi_search(num, l, i - 1)

    return bi_search(num, i + 1, r)


  ans = 0
  total = 0
  for j in range(m + 1):
    total += B[j]
    if total > k:
      break

    i = bi_search(k - total, 0, n - 1)
    if i + j > ans:
      ans = i + j

  print(ans)


main()


Measured memory_bytes: 60028
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<iostream>
#include<numeric>
using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	cout << 2 * b - a << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <complex>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>
#include <iterator>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;

int main() {
    i64 n;
    cin >> n;
    vector<i64> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];

    vector<i64> cnt(n + 1);
    for (i64 x : a) cnt[x]++;
    i64 sum = 0;
    for (i64 c : cnt) {
        if (c > 0) sum += c * (c - 1) / 2;
    }
    for (i64 x : a) {
        i64 ans = sum;
        if (cnt[x] >= 2) {
            ans -= cnt[x] * (cnt[x] - 1) / 2;
            ans += (cnt[x] - 1) * (cnt[x] - 2) / 2;
        }
        cout << ans << '\n';
    }
    return 0;
}

Measured memory_bytes: 5760
N, Y = map(int, input().split(" "))
 
A = -1
B = -1
C = -1
 
for a in range(N + 1):
  for b in range(N + 1 - a):
    c = N - a - b
    if 10000 * a + 5000 * b + 1000 * c == Y and 0 <= c:
      A = a
      B = b
      C = c
      
print(A, B, C)

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;

class program{

  static void Main(){
  int N = int.Parse(Console.ReadLine());
  string[] s = new string[N];
  bool canDoShiritori=true;
  for(int i=0;i<N;i++){
    s[i]=Console.ReadLine();
  }
  
  for(int i=0;i<N;i++){
   if(i==0){
    continue; 
   }     
   for(int j=0;j<i;j++){
     if(s[i]==s[j]){
       canDoShiritori=false;
       break;
     }
   }
   if(!canDoShiritori){
     break; 
   }          
   if(s[i].Substring(0,1)!=s[i-1].Substring(s[i-1].Length-1, 1)){
     canDoShiritori=false;
     break;
   }
  }
          
  if(canDoShiritori){
   Console.WriteLine("Yes"); 
  }else{
   Console.WriteLine("No"); 
  }
 }
}

Measured memory_bytes: 11092
def main
  while num = gets
    num = num.chomp.to_i
    puts solve(num).to_s
  end
end

def solve num
  res = 0
  (0..9).each do |a|
    (0..9).each do |b|
      (0..9).each do |c|
        (0..9).each do |d|
          res += 1 if a + b + c + d == num
        end
      end
    end
  end
  res
end


main

Measured memory_bytes: 6092