akhauriyash/Code-Regression huggingface dataset:
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
import sys
from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; cnt = 0; ansli = []; tmpli = []; candili = []; stillset = set()
eps = 1.0 / 10 ** 10; mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]; ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]; ddn9 = ddn + [(0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]#WideIntPoint
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def s_list(): return list(input())
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]#HeightString
def mi(n): return [wi() for _ in range(n)]#MatrixInt
def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)]#NumberGrid
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]
def grid(n): return [s_list() for _ in range(n)]

n = i()
d = wi()

time = [[] for _ in range(13)]

for t in d:
    time[t].append(t)

for idx, kosu in enumerate(time):
    if len(kosu) >= 3:
        print(0)
        exit()

if n > 11:
    if len(time[0]) >= 1 or len(time[12]) > 1:
        print(0)
        exit()
    else:
        print(1)
        exit()

time = functools.reduce(lambda a, b: a + b, time)
ans = INF; A = 0

for ti in itertools.product([0, 1], repeat=len(time)):  # 11**2
    kyu = []
    for kk in range(len(ti)):
        if ti[kk] == 0:
            kyu.append(time[kk])
        else:
            kyu.append(24 - time[kk])
    kyu.append(0)

    for k in itertools.combinations(kyu, 2):  # nC2
        ans = min(ans, abs(k[0] - k[1]), 24 - abs(k[0] - k[1]))
    A = max(ans, A)
    ans = INF  # 初期化を忘れない
print(A)

Measured memory_bytes: 70124
#include<iostream>
#include<cmath>
#include<string>

using namespace std;

int main(){
        int k,n;cin>>n>>k;
        string s;cin>>s;
        s+="3";
        int block =0;
        int bs[100005];
        for(int i=1;i<=n;i++){
                if(s[i]!=s[i-1]){
                        bs[block] = i;
                        block++;
                }
        }
        //for(int i=0;i<block;i++)cout<<bs[i]<<endl;

        int kk = 0;
        int ans = 0;

        for(int i=0;i<block;i++){
                int basep = -1;
                if(s[bs[i]-1] == '0'){
                        basep = max(basep,i-2*k);
                } else {
                        basep = max(basep,i-2*k-1);
                }
                int diffp;
                if(basep == -1) diffp=0;
                else diffp = bs[basep];
                ans = max(bs[i]-diffp,ans);
        }

        cout<<ans<<endl;
        return 0;
}


Measured memory_bytes: 896
#include <stdio.h>
#include <string.h>

#define M 1000000
#define NIL  (-1)
#define L 14

char H[M][L];

int getChar(char ch) {
    if(ch ==   'A') return 1;
    else if (ch == 'C') return 2;
    else if (ch == 'G') return 3;
    else if (ch == 'T') return 4;
    else return 0;
}

long long getKey(char str[]) {
    long long sum = 0,p = 1, i;
    for (i = 0; i < strlen(str); i++) {
        sum += p*(getChar(str[i]));
        p *= 5;
    }
    return sum;
}

int h1(int key) {return key % M; }
int h2(int key) {return 1 + (key % (M - 1));}

int find(char str[]) {
    long long key,i,h;
    key = getKey(str);
    for (i = 0;; i++) {
        h = (h1(key) + i * h2(key)) % M;
        if (strcmp(H[h],str) == 0) return 1;
        else if (strlen(H[h]) == 0) return 0;
    }
    return 0;
}

int insert(char str[]) {
    long long key,i,h;
    key = getKey(str);
    for (i = 0; ; i++) {
        h = (h1(key) + i * h2(key)) % M;
        if (strcmp(H[h],str) == 0) return 1;
        else if (strlen(H[h]) == 0) {
            strcpy(H[h],str);
            return 0;
        }
    }
    return 0;
}

int main() {
    int i,n = 0;
    char str[L],com[9];
    for (i = 0; i < n; i++) H[i][0] = '\0';
    scanf("%d",&n);
    for (i = 0; i < n; i++) {
        scanf("%s %s",com,str);
        //printf("com: %s str: %s\n",com,str);
        if (com[0] == 'i') {
            insert(str);
        } else {
            if( find(str) ) {
                printf("yes\n");
            } else {
                printf("no\n");
            }
        }
    }
    return 0;
}


Measured memory_bytes: 15292
#include<bits/stdc++.h>
using namespace std;
int main()
{
int fiyear,finyear,co=0,now=0;
while(cin>>fiyear>>finyear&&fiyear!=0&&finyear!=0){
if(now!=0)cout<<endl;
else now=1;
for(int i=fiyear;i<=finyear;i++){
if(i%4==0){
co=1;
if(i%100!=0||i%400==0)cout<<i<<endl;
}
}
if(co==0)cout<<"NA"<<endl;
co=0;
}
}

Measured memory_bytes: 1160
using System;
public class Contest
{
	public static void Main(string[] args)
	{
		string p = Console.ReadLine();
		int o = int.Parse(p);
		int m = o / 100;
		int q = m * 100 + m * 10 + m;
		if(o > q) q += 111;
		Console.WriteLine(q);
	}
}

Measured memory_bytes: 13140
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_6_A
#include<bits/stdc++.h>
#pragma warning(disable:4996)
#ifdef _MSC_VER
#  define __builtin_popcount __popcnt
#endif
#define int long long
using namespace std;
using ll = long long;
using ld = long double;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
inline void my_io() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	cout << fixed << setprecision(10);
}
 
struct edge {
	int from, to, cap, rev;
};
vector<vector<edge>>g;//グラフの隣接リスト表現
vector<int>level;//sからの距離(辺何本分離れているか)
vector<int>iter;//どこまで調べ終わったか
int v, e;

void add_edge(int from,int to, int cap) {//from→to　容量capの辺をグラフに追加
	g[from].push_back(edge{ from,to,cap,(int)g[to].size() });
	g[to].push_back(edge{ to,from ,0,(int)g[from].size() - 1 });
}
void dinic_bfs(int s) {//sからの最短距離(辺何本分離れているか)をbfsで計算する
	fill(level.begin(),level.end(),-1);
	queue<int>que;
	level[s] = 0;
	que.push(s);
	while (!que.empty()) {
		int v = que.front();
		que.pop();
		for(int i=0;i<g[v].size();i++){
			edge &e = g[v][i];
			if (e.cap > 0 && level[e.to] < 0) {
				level[e.to] = level[v] + 1;
				que.push(e.to);
			}
		}
	}
}
int dinic_dfs(int v, int t, int f) {//増加パスをdfsで探す
	if (v == t) {
		return f;
	}
	for (int &i = iter[v]; i < g[v].size(); i++) {//同じところを何度も通らないように枝刈りしている
		edge &e = g[v][i];
		if (e.cap > 0 && level[v] < level[e.to]) {
			int d = dinic_dfs(e.to, t, min(f, e.cap));
			if (d > 0) {
				e.cap -= d;
				g[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}
int max_flow(int s, int t) {
	int flow = 0;
	for (;;) {
		dinic_bfs(s);
		if (level[t] < 0) {
			return flow;
		}
		fill(iter.begin(), iter.end(), 0);
		int f;
		while ((f = dinic_dfs(s, t, numeric_limits<int>::max())) > 0) {
			flow += f;
		}
	}
}
signed main() {
	cin >> v >> e;
	g.resize(v);
	level.resize(v);
	iter.resize(v);
	for (int i = 0; i < e; i++) {
		int from, to, cap;
		cin >> from >> to >> cap;
		add_edge(from, to, cap);
	}
	cout << max_flow(0, v - 1) << endl;
	return 0;
}




Measured memory_bytes: 3244
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n;
    cin >> n;
    VI a(n);
    REP(i,n) cin >> a[i];
    int ans = 0;
    int x = 0;
    REP(i,n){
        if (a[i] >= x) ans++;
        x = max(x, a[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <vector>
#include <stack>
#include <map>
#include <bitset>
#define ri register
#define inf 0x7fffffff
#define E (1)
#define mk make_pair
#define int long long
//#define double long double
using namespace std;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch-'0'), ch=getchar();
    return s*w;
}
void print(int x) { if(x<0) x=-x, putchar('-'); if(x>9) print(x/10); putchar(x%10+'0'); }
int n; string s; map<string,int> Q;
signed main()
{
    n=read();
    for(ri int i=1;i<=n;i++)
    {
        cin>>s;
        Q[s]++;
    }
    printf("AC x %lld\n",Q["AC"]);
    printf("WA x %lld\n",Q["WA"]);
    printf("TLE x %lld\n",Q["TLE"]);
    printf("RE x %lld\n",Q["RE"]);
    
    return 0;
}

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

int main() {
  LL N; 
  cin >> N;
  LL i = 1;
  while (i * i <= N) {i++;}
  
  LL a;
  for (LL j = i - 1; j > 0; j--) {
    if (N % j == 0) {
      a = j;
      break;
    }
  }
  
  cout << (a - 1) + (N/a - 1) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include <cassert>
#include<string>
#include<vector>
#include <utility>
#include <math.h>
using namespace std;
int a = 0, b = 0, c = 0, d = 0, e[1050] = {}, f[100010] , counto = 0, counto1 = 1145148;
double syo = 0, su = 0;
char mado[105][105];
bool mazi[110], gi[110];
pair<int, int>n[110];
vector<int> r;
int main() 
{
	cin >> a >> b ;
	for (int i = 0; i < a; i++) {
		for (int j = 0; j < b; j++) {
			cin >> mado[i][j];
			if (mado[i][j] == '#') {
				mazi[i] = true;
				gi[j] = true;
			}
		}
	}
	for (int i = 0; i < a; i++) {
		for (int j = 0; j < b; j++) {
			if (mazi[i] == true && gi[j] == true) {
				cout << mado[i][j];
				counto++;
			}
		}
		if (counto != 0) {
			cout << endl;
		}
		counto = 0;
	}
	return 0;
}

Measured memory_bytes: 384
i = int(input())
mozi = ""
while i>26:
    q, mod = divmod(i, 26)
    if mod == 0:
        q = q-1 
        mod = 26
    mozi = mozi + chr(mod+96)
    i = q
if i == 0:
    i = 26
mozi = mozi + chr(i+96)
kotae = mozi[::-1]
print(kotae)

Measured memory_bytes: 8988
/*  -*- coding: utf-8 -*-
 *
 * 1608.cc: Selection of Participants of an Experiment
 */

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

/* constant */

const int MAX_N = 1000;
const int INF = 1 << 30;

/* typedef */

/* global variables */

int as[MAX_N];

/* subroutines */

/* main */

int main() {
  for (int n; scanf("%d", &n) > 0 && n > 0;) {
    for (int i = 0; i < n; i++) scanf("%d", as + i);
    sort(as, as + n);

    int mind = INF;
    for (int i = 1; i < n; i++) {
      int d = as[i] - as[i - 1];
      if (mind > d) mind = d;
    }

    printf("%d\n", mind);
  }

  return 0;
}



Measured memory_bytes: 3252
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll MOD = 1000000007;
const ll INF = 10000000000000;
#define all(v) v.begin(), v.end()

int main(){
  ll R,C,B=0;
  cin >> R >> C;
  vector<string> X(R);
  rep(i,R){
    cin >> X.at(i);
    rep(j,C){
      if(X.at(i).at(j)=='#'){
        B++;
      }
    }
  }

    queue<P> Q;
    vector<vector<ll>> D(R,vector<ll>(C,INF));
    Q.push(P(0,0));
    D.at(0).at(0)=0;
    while(!Q.empty()){
      ll y,x;
      y=Q.front().first;
      x=Q.front().second;
      Q.pop();
      if(y!=R-1&&D.at(y+1).at(x)==INF&&X.at(y+1).at(x)!='#'){
        D.at(y+1).at(x)=D.at(y).at(x)+1;
        Q.push(P(y+1,x));
      }
      if(y!=0&&D.at(y-1).at(x)==INF&&X.at(y-1).at(x)!='#'){
        D.at(y-1).at(x)=D.at(y).at(x)+1;
        Q.push(P(y-1,x));
      }
      if(x!=C-1&&D.at(y).at(x+1)==INF&&X.at(y).at(x+1)!='#'){
        D.at(y).at(x+1)=D.at(y).at(x)+1;
        Q.push(P(y,x+1));
      }
      if(x!=0&&D.at(y).at(x-1)==INF&&X.at(y).at(x-1)!='#'){
        D.at(y).at(x-1)=D.at(y).at(x)+1;
        Q.push(P(y,x-1));
      }
    }
  if(D.at(R-1).at(C-1)==INF){
    cout << -1 << endl;
  }else{
  cout << R*C-B-1-D.at(R-1).at(C-1) << endl;
  }
}

Measured memory_bytes: 3628
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

//const int INF=5e8;
int n,m;
vector<int> g[100005];
vector<int> ans;
bool vis[100005];
void dfs(int v,int p){
  ans.pb(v);
  vis[v]=true;
  for(auto to:g[v]){
    if(to==p || vis[to]) continue;
    dfs(to,v);
    break;
  }
  if(p==-1){
    vector<int> tmp=ans;
    ans.clear();
    for(auto to:g[v]) if(!vis[to]){
      dfs(to,v);
      break;
    }
    reverse(ALL(ans));
    tmp.insert(tmp.begin(),ALL(ans));
    ans=tmp;
  }
}
int main(){
  cin>>n>>m;
  REP(i,m){
    int a,b;scanf("%d%d",&a,&b);--a;--b;
    g[a].pb(b);
    g[b].pb(a);
  }

  dfs(0,-1);
  cout<<ans.size()<<endl;
  for(auto e:ans) printf("%d\n",e+1);
  return 0;
}





Measured memory_bytes: 17016
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll p=pow(10,9)+7;
ll phi(ll n) {
    ll result = n;
    for (ll i = 2; i * i <= n; i++) {
        if(n % i == 0) {
            while(n % i == 0)
                n /= i;
            result -= result / i;
        }
    }
    if(n > 1)
        result -= result / n;
    return result;
}
ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;      
    x = x % p;  
   while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1; 
        x = (x*x) % p; 
    } 
    return res; 
} 

ll modInverse(ll n, ll p) 
{ 
    return power(n, p-2, p); 
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    ll x,n,i,j;
    cin>>s;
    sort(s.begin(),s.end());
    char a=s[0];
    char b=s[2];
    if(a!=b)
    {
        if(s[1]==a&&s[3]==b)
        cout<<"Yes";
        else
        cout<<"No";
    }
    else 
    cout<<"No";
    return 0;
    
}
    


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const ll LINF = 1001001001001001;
const int MOD = 1000000007;

template <typename T>
void print(const T &v);

set<ll> factorization(ll num)
{
    set<ll> mp;

    ll tmp = num;
    for (ll i = 2; i * i <= num; i++)
    {
        while (tmp % i == 0)
        {
            mp.insert(i);
            tmp /= i;
        }
    }
    if (tmp != 1)
    {
        mp.insert(tmp);
    }
    return mp;
}

int main()
{
    ll a, b;
    cin >> a >> b;
    ll mini = min(a, b);
    set<ll> sa, sb;
    sa = factorization(a);
    sb = factorization(b);
    ll cnt = 1;
    for (auto aa : sa)
    {
        if (sb.count(aa))
        {
            ++cnt;
        }
    }
    cout << cnt << endl;
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << ' ';
        cout << v[i];
    }
    cout << endl;
};

Measured memory_bytes: 3632
#include"bits/stdc++.h"
using namespace std;
#define int long long
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
typedef pair<int, int> P;
constexpr long long inf = 1e17;
constexpr int mod = 998244353;
int dp[3005][3005];
signed main() {
	int a, b, c, d; cin >> a >> b >> c >> d;
	int x = c - a, y = d - b;
	dp[a][b] = 1;
	
	for (int i = a; i <= c; i++) {
		for (int j = b; j <= d; j++) {
			if (i != a) {
				dp[i][j] += dp[i - 1][j] * j; dp[i][j] %= mod;
			}
			if (j != b) {
				dp[i][j] += dp[i][j - 1] * i; dp[i][j] %= mod;
			}
			if (i != a && j != b) {
				dp[i][j] -= dp[i - 1][j - 1] * (i - 1)*(j - 1) % mod;
				dp[i][j] = (dp[i][j] + mod) % mod;
			}
		}
	}

	cout << dp[c][d] << endl;
}

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

int main() {
  int n,x;
  cin>>n>>x;
  vector<int>vec(n);
  for(int i=0;i<n;i++) {
    int a;
    cin>>a;
    vec.at(i)=a;
    x-=a;
  }
  sort(vec.begin(),vec.end());
  int e=x/vec.at(0);
  cout<<n+e<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <math.h>
#include <set>
#include <map>
#include <numeric>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define _printV(vec) for(int i = 0; i < SZ(vec); i++){cout << vec[i];if (i==SZ(vec)-1){cout<<endl;}else{cout << " ";}}
#define printV(vec) cout<<#vec<<":";_printV(vec)
#define _printA(arr,n) for(int i = 0; i < n; i++){cout << arr[i];if (i==n-1){cout<<endl;}else{cout << " ";}}
#define printA(arr) cout<<#arr<<":";_printA(arr,sizeof(arr)/sizeof(arr[0]))
#define LLINF (1LL<<62)
#define puts(var) cout<<#var<<":"<<var<<" "
typedef long long ll;

int main()
{
  string S;
  cin >> S;
  int cnt = 0;
  REP(i,S.length()){
    if(S[i]=='2'){
      cnt++;
    }
  }
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
    String A = "1100000011";
    String B = "1000000010000000100000001";
    String C = "1111";
    String D = "1000000110000001";
    String E = "11000000011";
    String F = "100000001100000001";
    String G = "110000011";
    String[] blocks = {A, B, C, D, E, F, G};
    String[] dic = {"A", "B", "C", "D", "E", "F", "G"};
    
    void run(){
        Scanner sc = new Scanner(System.in);        
        while(sc.hasNext()){
            String str = new String();
            for(int _ = 0; _ < 8; _++){
                str += sc.next();
            }
            System.out.println(dic[solve(str)]);
        }
    }
    int solve(String str){
        for(int i = 0; i < 8 * 8; i++){
            for(int ii = 0; ii < 7; ii++){
                if( 8 * 8 < i + blocks[ii].length()){
                    continue;
                }
                String s = str.substring(i, i + blocks[ii].length());
                if(s.equals(blocks[ii])){
                    return ii;
                }
            }
        }
        return -1;
    }
    public static void main(String[] args){
        new Main().run();
    }
}

Measured memory_bytes: 20596
# Problem B - Guidebook

# input
N = int(input())
restaurant = {}
for i in range(N):
    s, p = input().split()
    p = int(p)
    if s in restaurant:
        restaurant[s].append((i+1, p))
    else:
        restaurant[s] = [(i+1, p)]

# dict sort
restaurant = sorted(restaurant.items(), key= lambda x:x[0])

# price sort
for r in restaurant:
    tmp = r[1]
    result = sorted(tmp, key= lambda x:x[1], reverse=True)
    for i in result:
        print(i[0])


Measured memory_bytes: 3064
until (a = gets.to_i).zero?
  given = [a] + 4.times.map {gets.to_i}
  
  hands = given.uniq
  if hands.size == 3 || hands.size == 1
    result = [3] * 5
  else
    point = (hands[0] - hands[1]) % 3 == 2 ? 1 : 2
    result = given.map do |hand|
      hand == hands[0] ? point : 3 - point
    end
  end
  
  puts result
end


Measured memory_bytes: 6876
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;
 
static inline int left(int i) {
  return 2 * i;
}

static inline int right(int i) {
    return 2 * i + 1;
}

static void maxHeapify(vector<int>& A, int i) {
  const int l = left(i);
  const int r = right(i);

  const int H = A.size() - 1;
  int largest = 0;
  if (l <= H && A[l] > A[i]) {
     largest = l;
    } else {
      largest = i;
    }

    if (r <= H && A[r] > A[largest]) {
      largest = r;
    }
    
    if (largest != i) {
      swap(A[i], A[largest]);  
      maxHeapify(A, largest);
    }    
}

static void buildMaxHeap(vector<int>& A) {
  const int H = A.size() - 1;
  for (int i = H / 2; i > 0; i--) {
    maxHeapify(A, i);
  }
}

static vector<int> A;

int main() {
  int h;
  cin >> h;

  A.resize(h + 1);

  int k;
  for (int i = 1; i < A.size(); i++) {
    cin >> k;
    A[i] = k;
  }
  
  buildMaxHeap(A);
  
  for (int i = 1; i < A.size(); i++) {
    cout << " " << A[i];
  }
  cout << endl;

  return 0;
}



Measured memory_bytes: 4684
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; }
    void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; }

    void solve()
    {
        int N = cin.nextint;
        int K = cin.nextint;
        var X = cin.scanlong;
        var A = X.Where(i => i >= 0).OrderBy(i => i).ToArray();
        var B = X.Where(i => i < 0).Select(i => -i).OrderBy(i => i).ToArray();

        long ans = long.MaxValue;
        for (int i = 0; i <= A.Length; i++)
        {
            if (K < i) break;
            int need = K - i;
            if (B.Length < need) continue;
            long right = 0;
            if(i > 0) right = A[i - 1];
            long left = 0;
            if (need > 0) left = B[need - 1];
            var ret = Math.Min(right * 2 + left, right + left * 2);
            chmin(ref ans, ret);
        }
        WriteLine(ans);
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 25824
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#define INF 100000000000LL
using namespace std;
typedef long long int ll;

int main()
{
	int n;
	scanf("%d", &n);
	ll a[100000], b[100000], c[100000];
	for(int i=0; i<n; i++){
		scanf("%lld", &a[i]);
	}
	for(int i=0; i<n; i++){
		scanf("%lld", &b[i]);
	}
	for(int i=0; i<n; i++){
		scanf("%lld", &c[i]);
	}
	sort(a, a+n);
	sort(b, b+n);
	sort(c, c+n);
	ll ans=0;
	for(int i=0; i<n; i++){
		ll x=lower_bound(a, a+n, b[i])-a;
		ll y=c+n-upper_bound(c, c+n, b[i]);
		ans+=(x*y);
	}
  printf("%lld\n", ans);
	return 0;
}

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

int main(){

    int n,m;

    cin >> n >> m;

    vector<vector<ll>> values(n, vector<ll>(3));

    for(auto& line : values)
        for(auto& val : line)
            cin >> val;

    ll answer = -1e18;

    auto solve = [&](int bit){

        vector<vector<ll>> vec = values;

        for(int i = 0; i < 3; ++i)
            if(bit&(1<<i))
                for(int j = 0; j < n; ++j)
                    vec[j][i] *= -1;
        
        priority_queue<ll> que;

        for(int i = 0; i < n; ++i)
            que.push(accumulate(vec[i].begin(), vec[i].end(), 0LL));

        ll sum = 0;
        
        for(int i = 0; i < m; ++i){
            sum += que.top();
            que.pop();
        }

        answer = max(answer, sum);

    };

    for(int i = 0; i < (1<<3); ++i)
        solve(i);

    cout << answer << endl;

    return 0;
}

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


void solve(long long a){
    cout << a + a * a + a * a * a << endl;
}

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


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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
//#define MOD 1000000007
#define INF LLONG_MAX/2

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
void vin(Vi &v){REP(i,0,(v).size()) cin>>v[i];}
void vin(Vi &v,Vi &v2){REP(i,0,(v).size()) cin>>v[i]>>v2[i];}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
void accum(Vi &v){REP(i,1,(v).size()) v[i]+=v[i-1];}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}


void solve(long long n, std::vector<long long> p){
    int ans=0,now=INF;
    REP(i,0,n){
        // if(i==0){
        //     ans++;
        //     now=p[i];
        // }else{
            if(now>p[i]){
                ans++;
                now=p[i];
            }else{
                // now=p[i];
            }
        // }
    }
    cout<<ans<<endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
signed main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> P(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&P[i]);
    }
    solve(N, std::move(P));
    return 0;
}


Measured memory_bytes: 1792
import sys

def gcd(a, b): return gcd(b, a % b) if b else abs(a)

k = int(sys.stdin.readline().rstrip())

def main():
  res = 0
  cnt = [0] * (k + 1)
  for i in range(1, k + 1):
    for j in range(1, k + 1):
      cnt[gcd(i, j)] += 1
  for i in range(1, k + 1):
    for j in range(1, k + 1):
      res += gcd(i, j) * cnt[i]
  print(res)

if __name__ ==  '__main__':
    main()

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

int main()
{
	string s;
	int q;
	cin >> s >> q;
	vector<tuple<int, int, char>> query(q);
	for (int i = 0; i < q; i++) {
		int t_in;
		cin >> t_in;
		int f_in = 0;
		char c_in = ' ';
		if (t_in == 2) {
			cin >> f_in >> c_in;
		}
		query.at(i) = make_tuple(t_in, f_in, c_in);
	}

	bool dir = true;
	string space(300000, ' ');
	int size = s.size();
	int mae = 299999;
	int usiro = 300000 + size;
	s = space + s + space;
	bool b_mae = false;
	bool b_usiro = false;

	for (auto query_ele : query) {
		int t = get<0>(query_ele);
		int f = get<1>(query_ele);
		char c = get<2>(query_ele);

		if (t == 1) {
			dir = !dir;
		}
		if (t == 2) {
			if (dir == true) {
				if (f == 1) {
					s[mae] = c;
					mae--;
					b_mae = true;
				} else {
					s[usiro] = c;
					usiro++;
					b_usiro = true;
				}
			} else {
				if (f == 1) {
					s[usiro] = c;
					usiro++;
					b_usiro = true;
				} else {
					s[mae] = c;
					mae--;
					b_mae = true;
				}
			}
		}
	}

	mae++;
	usiro--;
	/*if (b_mae == true) {
		mae++;
	}
	if (b_usiro == true) {
		usiro--;
	}*/
	int length = usiro - mae + 1;
	string ans = s.substr(mae, length);

	if (dir == false) {
		reverse(ans.begin(), ans.end());
	}

	cout << ans << endl;
}


Measured memory_bytes: 4216
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>

template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

// [l, r) from l to r
struct range {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr range(int l_, int r_): l(l_), r(std::max(l_, r_)) { }
  constexpr itr begin() const { return l; }
  constexpr itr end() const { return r; }
};

// [l, r) from r to l
struct revrange {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr revrange(int l_, int r_): l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr itr begin() const { return r; }
  constexpr itr end() const { return l; }
};

int main() {
  int N;
  std::cin >> N;
  N %= 10;
  if (N == 3) {
    std::cout << "bon\n";
  }
  else if (N == 0 || N == 1 || N == 6 || N == 8) {
    std::cout << "pon\n";
  }
  else {
    std::cout << "hon\n";
  }
  return 0;
}


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

int main(int argc, char const *argv[]) {
  int a,b; cin>>a>>b;
  int mean = (a + b) / 2;
  if((a % 2 == 1 && b % 2 != 1) || (a % 2 != 1 && b % 2 == 1)){
    mean++;
  }
  cout << mean << "\n";
  return 0;
}


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

#define STRING(str) #str

template <typename T >
void print_vec_1d(vector<T> x, string name) {
	cout << name << endl;
	cout << "[ ";
	for (int i=0;i<x.size();i++) {
		cout << x[i];
		if (i != x.size()-1) cout << ", ";
		else cout << " ]" << endl;
	}
}

int op(int a, int b) {
	return max(a, b);
}

int e() {
	return int(-1);
}

int target = 0;

bool f(int X) {
	return X<target;
}

int main() {
	int N, Q;
	cin >> N >> Q;
	segtree<int, op, e> seg(N);
	for (int i=0;i<N;i++) {
		int A;
		cin >> A;
		seg.set(i, A);
	}

	for (int i=0;i<Q;i++) {
		int T;
		cin >> T;
		if (T == 1) {
			int X, V;
			cin >> X >> V;
			seg.set(X-1, V);
		} else if (T == 2) {
			int L, R;
			cin >> L >> R;
			cout << seg.prod(L-1, R) << endl;
		} else { // T == 3
			int X, V;
			cin >> X >> V;
			target = V;
			cout << seg.max_right<f>(X-1)+1 << endl;
		}
	}
}

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

int main(int argc, char const *argv[])
{
    int n,m,in1;
    cin >> n >> m;

    int** A = new int *[n];
    for (int i=0; i<n; i++) {
        A[i] = new int[m];
        for (int j=0; j<m; j++) {
            cin >> in1;
            A[i][j] = in1;
        }
    }

    int* b = new int[m];
    for (int j=0; j<m; j++) {
        cin >> in1;
        b[j] = in1;
    }

    int c,c1,c2;
    for (int i=0; i<n; i++) {
        c = 0;
        for (int j=0; j<m; j++) {
            c +=  A[i][j] * b[j];
        }
        cout << c << endl;
    }
    delete[] A;
    delete[] b;
    A=0;
    b=0;
}


Measured memory_bytes: 3144
module ABC132

  ! <module>s to import
  use, intrinsic :: iso_fortran_env

  ! require all variables to be explicitly declared
  implicit none

  ! accessibility of <subroutine>s and <function>s in this <module>
  public  :: task_B
  private :: judge_sequence

  ! contained <subroutine>s and <function>s are below
  contains

  subroutine task_B

    ! variables for this <subroutine>
    integer(INT32) :: len_sequence
    integer(INT32) :: answer

    ! arrays for this <subroutine>
    integer(INT32), dimension(:), allocatable :: val_sequence

    ! support variables for this <subroutine>
    integer(INT32) :: index

    ! STEP.01
    ! read out the given data
    read(unit=INPUT_UNIT, fmt=*) len_sequence
    allocate( val_sequence(1:len_sequence) )
    read(unit=INPUT_UNIT, fmt=*) val_sequence(1:len_sequence)

    ! STEP.02
    ! calculate the answer of this task
    answer = 0_INT32

    do index = 2, len_sequence - 1, 1
      if ( judge_sequence( val_sequence(index-1:index+1:1) ) ) answer = answer + 1
    end do

    ! STEP.03
    ! deallocate the allocatable arrays
    deallocate( val_sequence )

    ! STEP.04
    ! output the answer of this task
    write(unit=OUTPUT_UNIT, fmt='(I0)', advance='yes') answer

    ! STEP.END
    return

  end subroutine task_B

  function judge_sequence (sequence) result(stat)

    ! arguments for this <function>
    integer(INT32), dimension(1:3), intent(in) :: sequence

    ! return value of this <function>
    logical :: stat

    if ( sequence(1) .gt. sequence(2) .and. sequence(2) .gt. sequence(3) ) then
      stat = .true.
    else if ( sequence(1) .lt. sequence(2) .and. sequence(2) .lt. sequence(3) ) then
      stat = .true.
    else
      stat = .false.
    end if

    ! STEP.END
    return

  end function judge_sequence

end module ABC132


program main

  ! <module>s to import
  use, non_intrinsic :: ABC132

  ! require all variables to be explicitly declared
  implicit none

  call task_B

end program main

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
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; }

vector<long long> divisor(long long n) {
  vector<long long> res;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      res.push_back(i);
      if (n / i != i) res.push_back(n / i);
    }
  }
  sort(res.begin(), res.end());
  return res;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin >> n;
  auto div1 = divisor(n-1);
  int ans = 0;
  rep(i, div1.size()) {
    if (div1[i] >= 2) {
      ans++;
    }
  }
  auto div2 = divisor(n);
  rep(i, div2.size()) {
    if (div2[i] < 2)
      continue;
    ll num = n;
    while (num >= div2[i]) {
      if (num%div2[i] == 0)
        num /= div2[i];
      else {
        num %= div2[i];
        break;
      }
    }
    if (num == 1 && *lower_bound(div1.begin(), div1.end(), div2[i]) != num)
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>

using namespace std;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(long long i=(a),i##Len_=(b);i<i##Len_;i++)
typedef long long ll;

int main()
{
    ll N;
    ll cnt =0;

    cin >> N;

    vector <ll> p(N);

    REP(i,N)
    {
        cin >> p[i];
    }

    for(ll i = 1; i < N-1; i++)
    {
        if(p[i] < p[i-1] && p[i] < p[i+1])continue;
        if(p[i] > p[i-1] && p[i] > p[i+1])continue;
        cnt++;
    }

    cout << cnt << endl;

}



Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		int h = sc.nextInt();
		int w = sc.nextInt();
		String[] pic = new String[h];
		for(int i = 0; i < h; i++){
			pic[i] = sc.next();
		}
		
		//char[][] pic_ = new char[2 * h][w];
		for(int i = 0; i < h; i++){
			System.out.println(pic[i]);
			System.out.println(pic[i]);
		}
		
		sc.close();
	}

}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'


int gcd(int x ,int y){ 
    int temp;
    while(y!=0){
        temp = x%y;
        x=y;
        y=temp;
    }   
    return x;
}

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

    int a,b,c,t;
    int times;
    int sum=0;
    cin >> times;
    for(int i=1;i<=times;i++){
        for(int j=1;j<=times;j++){
            for(int k=1;k<=times;k++){
                t = gcd(j,k);
                t = gcd(t,i);
                sum = sum + t;
            }   
        }   
    }   
    cout<<sum;
    return 0;

}


Measured memory_bytes: 3652
import math
def main(a, b, x):
    b_floor = b // x

    if(a % x > 0):
        a_ceil = a // x + 1
    else:
        a_ceil = a // x

    print(b_floor - a_ceil + 1)

if __name__ == "__main__":
    a, b, x = [int(x) for x in input().split()]
    main(a, b, x)

def test1(capsys):
    inputs = [4, 8, 2]
    out = 3
    main(*inputs)
    captured = capsys.readouterr()    
    assert captured.out == str(out) + '\n'

def test3(capsys):
    inputs = [0, 5, 1]
    out = 6
    main(*inputs)
    captured = capsys.readouterr()    
    assert captured.out == str(out) + '\n'

def test4(capsys):
    inputs = [9, 9, 2]
    out = 0
    main(*inputs)
    captured = capsys.readouterr()    
    assert captured.out == str(out) + '\n'

def test5(capsys):
    inputs = [1, 1000000000000000000, 3]
    out = 333333333333333333
    main(*inputs)
    captured = capsys.readouterr()    
    assert captured.out == str(out) + '\n'

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

#define ll long long

using namespace std;

int main(){
    int n,a,b;
    string str;
    cin >> n >> a >> b;
    cin >> str;

    int ac = 0,bc = 0;
    int flag = true;
    for(int i = 0;i < n;i++){
        if(a + b > ac + bc && str[i] == 'a'){
            ac++;
            flag = true;
        }else if((a + b > ac+bc && b > bc) && str[i] == 'b'){
            bc++;
            flag = true;
        }else{
            flag = false;
        }
        if(flag){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 896
# coding: utf-8
# Your code here!
# coding: utf-8
# Your code here!
#一時保存
import collections

n=int(input())
li=list(map(int,input().split()))
l=[]
r=[]

for i in range(n):
    if i%2==0:
        l.append(li[i])
    else:
        r.append(li[i])

l_cnt=collections.Counter(l)
r_cnt=collections.Counter(r)


ll=l_cnt.most_common(2)
rr=r_cnt.most_common(2)
#if文多すぎ

if ll[0][0]==rr[0][0]:
    if len(ll)==1 and len(rr)==1:
        print(n//2)
    elif len(ll)==1:
        print(n//2-rr[-1][1])
    elif len(rr)==1:
        print(n//2-ll[-1][1])
    else:
        print((n-max(ll[0][1]+rr[1][1],ll[1][1]+rr[0][1])))
else:
    print(n-ll[0][1]-rr[0][1])





Measured memory_bytes: 19040
#include <stdio.h>

int main(void) 
{
    char str[4]; int i, cnt = 0;
    scanf("%s", str);
    for(i = 0; i < 3; ++i) {
        if(str[i] == '1') { ++cnt; }
    }
    printf("%d\n", cnt);
    return 0;
}

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

int main() {
  int N, a, b;
  cin  >>  N;
  a  =  N  /  10;
  b  =  N  %  1000;
  if (a  %  111  ==  0  ||  b  %  111  ==  0) {
    cout  <<  "Yes"  <<  endl;
  }
  else {
    cout  <<  "No"  <<  endl;
  }
}

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

using namespace std;

#define ABS(X) ((X)<0?-(X):(X))

int main(void){
  vector<int> a = vector<int>(3);

  cin >> a[0] >> a[1] >> a[2];
  sort(a.begin(), a.end());
  cout << ABS(a[1]-a[0]) + ABS(a[2]-a[1]) << endl;



  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll dp[100001];ll k;
ll n;ll a[100001];
ll ans(ll ind){
  if(ind>=n-1)return 0;
  if(dp[ind]!=-1)return dp[ind];
  dp[ind] = numeric_limits<ll>::max();
  for(ll i=1;i<=k;i++){
    if(ind+i<n)
  		dp[ind] = min(ans(ind+i) + abs(a[ind]-a[ind+i]),dp[ind]);
    else break;
  }
  return dp[ind];
}
int main(){
  memset(dp,-1,sizeof(dp));
  cin>>n>>k;for(ll i=0;i<n;i++)cin>>a[i];
  cout<<ans(0)<<endl;
  return 0;
}


Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main(){
    int N,T;
    cin >> N >> T;
    vector<int>A(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }
    int ans = 0,sum = 0,mi = INF;
    for(int i = 0; i < N; i++) {
        mi = min(mi,A[i]);
        if(A[i]-mi > sum) {
            ans = 1;
            sum = A[i]-mi;
        }
        else if(A[i]-mi == sum) {
            ans++;
        }
    }
    cout << ans << endl;
}


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

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

    int A, P;

    cin >> A >> P;

    cout << (A * 3 + P) / 2;
}

Measured memory_bytes: 256
#include <iostream>
int h2(int X, int Y, int H, int x, int y) {
    return std::max(H - std::abs(x - X) - std::abs(y - Y), 0);
}
int main() {
    int N;
    std::cin >> N;
    int x[N];
    int y[N];
    int h[N];
    for (int i = 0; i < N; ++i) {
        std::cin >> x[i] >> y[i] >> h[i];
    }

    int Cx = -1;
    int Cy = -1;
    int Ch = -1;

    for (int X = 0; X <= 100; ++X) {
        for (int Y = 0; Y <= 100; ++Y) {
            int H = -1;
            for (int i = 0; i < N; ++i) {
                if (h[i] <= 0) {
                    continue;
                }
                H = h[i] + std::abs(x[i] - X) + std::abs(y[i] - Y);
                if (H > 0) {
                    break;
                }
            }

            bool ok = true;
            for (int i = 0; i < N; ++i) {
                if (h[i] != h2(X, Y, H, x[i], y[i])) {
                    ok = false;
                    break;
                }
            }

            if (ok) {
                Cx = X;
                Cy = Y;
                Ch = H;
            }
        }
    }

    std::cout << Cx << " " << Cy << " " << Ch << std::endl;

    return 0;
}


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

string prime(int n){
  int i,j;
  string p = "001";
  while(p.size()<=n)p+="10";

  i = 3;
  while(i*i<=n){
    for(j=3*i;j<=n;j+=2*i)p[j] = '0';
    do{
      i+=2;
    }while(p[i]-'1');
  }
  return p;
}

int main(){
  int n;
  string p;
  while(1){
    cin >> n;
    if(!n)break;

    p = prime(n);

    while(n){
      if(p[n]=='1' && p[n-2]=='1'){
	cout << n-2 << " " << n << endl;
	break;
      }
      n--;
    }
  }
}
	

Measured memory_bytes: 968
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        
        // dist[i][j] = 点i→jの直接距離
        // i→jとj→iの距離が同じとは限らない
        int[][] dist = new int[10][10];
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < 10; j++) {
                dist[i][j] = sc.nextInt();
            }
        }
        
        // 「ワーシャルフロイド法」
        // 3つの頂点i, j, kを選んで、
        // i→k→jという道がi→jという道より短ければi→jの距離を更新する
        for (int k = 0; k < 10; k++) {  // 経由点kは必ず一番外側のループ
            for (int i = 0; i < 10; i++) {
                for (int j = 0; j < 10; j++) {
                    dist[i][j] = Math.min(dist[i][j], dist[i][k] + dist[k][j]);
                }
            }
        }
        
        // ans = 点p→1の最短距離の和
        long ans = 0;
        for (int i = 0; i < h * w; i++) {
            int p = sc.nextInt();
            if (p == -1) continue;
            ans += dist[p][1];
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 44776
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def reverse(s):
    return list(reversed(s))


def solve():
    S = {
        'a': reverse(input().strip()),
        'b': reverse(input().strip()),
        'c': reverse(input().strip()),
    }
    current = 'a'
    while S[current]:
        current = S[current].pop()
    return current.upper()


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 62012
#pragma GCC optimize ("O2")
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-label"
#pragma GCC diagnostic ignored "-Wsign-compare"

#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for (ll i = (a); i < (b); ++i)
#define trav(a, A) for (auto & a : A)
#define all(a) (a).begin (), (a).end ()
#define f first
#define s second

typedef long long ll;

const ll MOD = 1e+9+7;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const ll MAXN = 1e+5+7;

ll gcdExtended(ll a, ll b, ll *x, ll *y);

ll modInverse(ll b, ll m)
{
    ll x, y;
    ll g = gcdExtended(b, m, &x, &y);
    if (g != 1)
        return -1;
    return (x%m + m) % m;
}

ll modDivide(ll a, ll b, ll m)
{
    a = a % m;
    ll inv = modInverse(b, m);
    return (inv * a) % m;
}

ll gcdExtended(ll a, ll b, ll *x, ll *y)
{
    if (a == 0)
    {
        *x = 0, *y = 1;
        return b;
    }
    ll x1, y1;
    ll gcd = gcdExtended(b%a, a, &x1, &y1);
    *x = y1 - (b/a) * x1;
    *y = x1;
    return gcd;
}

ll mod_pot (ll num, ll expo)
{
	if (expo == 0) return 1;
	else if (expo == 1) return num % MOD;
	ll ans = 1, mult = mod_pot (num, expo/2);
	if (expo & 1) ans = ans*num;
	ans = (ans*mult % MOD)*mult % MOD;
	return ans;
}

ll mod_c (ll n, ll k)
{
	if (n - k < k) k = n - k;
	ll ans = 1;
	for (; k > 0; --k, --n)
		ans = ans * modDivide (n, k, MOD) % MOD;
	return ans;
}

inline void mod_add (ll & a, ll b)
{
	a += b;
	while (a >= MOD) a -= MOD;
	while (a < 0) a += MOD;
}

int main ()
{
	ios_base::sync_with_stdio (0);
	cin.tie (0);
	ll tc = 1;// cin >> tc;
	while (tc--)
	{
		ll i, j, n, a, b, den_a = 1, den_b = 1;
		cin >> n >> a >> b;
		ll ans = mod_pot (2, n);
		//ll f = mod_fat (a, a + 1 - MAXN/2, MAXN/2);
		ll f = 1;
		for (i = 2; i <= a; ++i)
			f = f * i % MOD;
		mod_add (ans, -1);
		mod_add (ans, -mod_c (n, a));
		mod_add (ans, -mod_c (n, b));
		cout << ans << '\n';
	}

	return 0;
}



Measured memory_bytes: 256