akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define SIZE(a) int((a).size())
#define out(a) cout<<(a)<<endl;
const int INF=INT_MAX;
const int MAX = 510000;
const ll MOD = 1000000007;

int main(){
  int n;cin>>n;
  vin x(0),y(0),xx(n),yy(n);
  set<int> s1,s2;
  vvb g(8,vb(8,false));
  rep(i,0,n){
    int x1,y1;cin>>x1>>y1;
    s1.insert(x1+y1);s2.insert(x1-y1);
    g[x1][y1]=true;
    xx[i]=x1;yy[i]=y1;
  }
  rep(i,0,8){
      if(find(xx.begin(),xx.end(),i)==xx.end()){x.push_back(i);}
      if(find(yy.begin(),yy.end(),i)==yy.end()){y.push_back(i);}
    }
  
  do{
      bool ok=true;
      set<int> ss1=s1,ss2=s2;
      rep(i,0,8-n){
        if(find(ss1.begin(),ss1.end(),x[i]+y[i])!=ss1.end()){ok=false;break;}
        else{ss1.insert(x[i]+y[i]);}
        if(find(ss2.begin(),ss2.end(),x[i]-y[i])!=ss2.end()){ok=false;break;}
        else{ss2.insert(x[i]-y[i]);}
      }
      if(ok){
        rep(i,0,8-n){
          g[x[i]][y[i]]=true;
        }
        rep(i,0,8){
          rep(j,0,8){
            if(g[i][j]){cout<<'Q';}
            else{cout<<'.';}
          }
          cout<<endl;
        }
        break;
      }
  }while(next_permutation(x.begin(),x.end()));
  
}



Measured memory_bytes: 3160
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    x=INT()
    a=INT()
    b=INT()
    print((x-a)%b)
if __name__ == '__main__':
    do()

Measured memory_bytes: 3068
/// wa ^3^

#pragma GCC optimize("O3")

#include<bits/stdc++.h>
                           
#define x first
#define y second
#define pb push_back
#define sz(x) (int) x.size()
 
using namespace std;
 
using ll = long long;
using pii = pair<int, int>;                                   

const int MOD = 1e9 + 7;
const int INF32 = 1e9 + 1e2;

template<typename T> istream 
&operator>>(istream &a, vector<T> &v) { 
for (auto& x : v) a >> x; return a; }

void stndrtn() {
#ifdef accepted
    freopen(".in", "r", stdin);
#endif        
}

const bool flag = 0;

void maincode() {
    string s;
    cin >> s;
    stack<char> st;
    for (char c : s) {
        if (c == 'S') 
            st.push(c);
        else if (!st.empty() && st.top() == 'S')
            st.pop();
        else
            st.push(c);
    }
    cout << sz(st);
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr), stndrtn();
    int ts = 1;
    if (flag) 
        cin >> ts;
    while (ts--)
        maincode(); 
    return 0;
}



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

int main() {
  string S; cin >> S;
  int N = S.size();
  int start_i = -1, max_l = 0;
  for (int i = 0; i < N; i++) {
    if (S[i] != 'A' && S[i] != 'C' && S[i] != 'G' && S[i] != 'T') start_i = i;
    max_l = max(max_l, i - start_i);
  }
  cout << max_l << endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include <algorithm>
#include <stdlib.h>
#include <stack>
#include <queue>
using namespace std;
char A[810][810] = {}; 
int D[810][810] = {}; 
int INF = 1145141919; 
int H, W, K; 
int Sx, Sy; 
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; 
void bfs(){
	queue<pair<int, int>> que;
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			D[i][j] = INF;
		}
	}
	que.push(pair<int, int>(Sx, Sy)); 
	D[Sx][Sy] = 0; 
	while(que.size()){
		pair<int, int> p = que.front(); que.pop(); 
		for(int i = 0; i < 4; i++){
			int nx = p.first + dx[i], ny = p.second + dy[i]; 
			if(nx >= 0 && nx < H && ny >= 0 && ny < W && 
				A[nx][ny] != '#' && D[nx][ny] == INF){
				que.push(pair<int, int>(nx, ny)); 
				D[nx][ny] = D[p.first][p.second] + 1; 
			}
		}
	}
}
int main(){
	cin >> H >> W >> K; 
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			cin >> A[i][j]; 
			if(A[i][j] == 'S'){
				Sx = i, Sy = j; 
			}
		}
	}
  	bfs(); 
	int ans = 700000; 
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			if(D[i][j] == INF) continue; 
			int b = min({i, H - 1 - i, j, W - 1 - j}); 
			int tmp = 0; 
			if(D[i][j] <= K) tmp = 1 + (b + K - 1) / K; 
			else tmp = (D[i][j] + b + K - 1) / K; 
			ans = min(ans, tmp);
		}
	}
	cout << ans << endl; 
}

Measured memory_bytes: 3456
n = input()
l = len(n)
ans = 0
for i in range(2**(l-1)):
    m = n
    b = list(bin(i)[2:])
    if len(b) < l-1:
        b = ["0"]*(l - 1 - len(b)) + b
    temp = 0
    for j, bb in enumerate(b):
        if bb == "1":
            ans += int(m[temp:j+1])
            temp = j+1
    ans += int(m[temp:])
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <algorithm> //next_permutation
#define REP(i,n) for(ll i=0;i<n;i++)

using namespace std;
typedef long long ll;
//typedef pair<int, int> P;

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

  ll n,m;
  cin>>n>>m;
  vector <ll> a(n);
  REP(i,n){cin>>a[i];}
  sort(a.begin(),a.end());
  ll l=0;
  ll r=a[n-1]*2+1;
  while (l+1<r){
    ll c=(l+r)/2;
    ll num=0;
    REP(i,n){
      num+=n-(lower_bound(a.begin(),a.end(),c-a[i])-a.begin());
      //各iに対して手を固定、c-a[i]（合計がc）以下のものの数をnから引く、つまり合計c以上を足していく
    }
    if (num>=m){
      l=c;//数が多すぎということはcが小さすぎ
    }else{
      r=c;
    }
  }
  //ここまででちょうど良いlが求まる,l以上がM個存在
  vector <ll> sum(n+1);
  for (int i=1; i<n+1; i++){
    sum[i]=sum[i-1]+a[i-1];
  }
  //手の数の小さいものからの和
  ll count = 0;
  ll ans = 0;
  REP(i,n){
    ll v =upper_bound(a.begin(),a.end(),l-a[i])-a.begin();
    //各iについて手を固定、合計l未満のものの数
  
    count+=n-v;
    //和がlより大きいの数の累積（l含まず）
    ans+=(n-v)*a[i]+sum[n]-sum[v];
    //a[i]と握手した場合、a[i]をn-v回、vより大きいものの和を全てたす

  }
  ans += (m-count)*l;
  //ちょうどlのもの（countですでに入っていないもの）
  cout<<ans;
}


Measured memory_bytes: 1792
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop

#------------------------------------------#

BIG_NUM = 2000000000
HUGE_NUM = 9999999999999999
MOD = 1000000007
EPS = 0.000000001

#------------------------------------------#

class Edge:
    def __init__(self,arg_to,arg_cost):
        self.to = arg_to
        self.cost = arg_cost

class Info:
    def __init__(self,arg_node_id,arg_sum_cost):
        self.node_id = arg_node_id
        self.sum_cost = arg_sum_cost

    def __lt__(self,arg):
        return self.sum_cost < arg.sum_cost


V = int(input())
min_dist = [BIG_NUM]*V
G = [[] for i in range(V)]

for loop in range(V):
    node_id,tmp_num,*table = list(map(int,input().split()))
    for i in range(0,len(table),2):
        G[node_id].append(Edge(table[i],table[i+1]))


min_dist[0] = 0
Q = []

heappush(Q, Info(0,0))

while len(Q) > 0:
    info = heappop(Q)
    if info.sum_cost > min_dist[info.node_id]:
        continue
    for edge in G[info.node_id]:
        if min_dist[edge.to] > info.sum_cost+edge.cost:
            min_dist[edge.to] = info.sum_cost+edge.cost
            heappush(Q, Info(edge.to,min_dist[edge.to]))


for i in range(V):
    print("%d %d"%(i,min_dist[i]))





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

int main()
{
    vector<tuple<string, int, int>> v;

    int n, i, x;
    string str;

    cin>>n;

    for(i=1; i<=n; i++){
        cin>>str>>x;

        v.push_back(make_tuple(str, -1*x, i));
    }

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

    for(i=0; i<v.size(); i++){
        cout<<get<2>(v[i])<<endl;
    }
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;






int main(void) {
	string S;
	cin >> S;
	for(int i=0; i < S.length() -8; i++) {
		cout << S[i];
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int n,k,d,e,tot=0;
	bool s[1005]={0};
	cin>>n>>k;
	for(int i=1;i<=k;i++)
	{
		cin>>d;
		for(int j=1;j<=d;j++)
		{
			cin>>e;
			s[e]=true;
		}
	}
	for(int i=1;i<=n;i++)
	{
		if(s[i]==false)
		{
			tot++;
		}
	}
	cout<<tot;
	return 0;
}

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

using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n); i > 0; i--)
#define all(n) n.begin(), n.end()
#define print(n) cout << n << endl

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    ll x,y=100,ans=0;
    cin >> x;

    while(y<x){
        y *= 1.01;
        ans++;
    }
    print(ans);
    return 0;
}

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

int main() {
	int N;
	bool ans = false;
	cin >> N;
	for(int i = 0; i <= 25; i++){
		for(int j = 0; j <= 14; j++){
			if(i * 4 + j * 7 == N){
				ans = true;
			}
		}
	}
	if(ans){
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstring>
#include <string>
#include <sstream>
#include <bitset>
using namespace std;
#define INF	100000000
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define SS stringstream
#define rep(i,n) for(int i = 0; i < n; i++)
#define SORT(x) sort((x).begin(), (x).end())
#define clr(a,b) memset((a),(b),sizeof(a))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<P> Vp;
typedef priority_queue<P, vector<P>, greater<P> > PQ;

ll pow16(int a){
	ll ret = 1;
	rep(i,a) ret *= 16;
	return ret;
}

ll pow2(int a){
	ll ret = 1;
	rep(i,a) ret *= 2;
	return ret;
}

void solve(){
	ll x[9];
	ll num[33];
	ll add[33];
	ll mod = pow2(32);
	rep(i,33){
		num[i] = 0;
		add[i] = 0;
	}
	rep(i,9){
		string str;
		cin >> str;
		x[i] = 0;
		for(int j = str.size()-1; j >= 0; j--){
			if(0<=str[j]-'0'&&str[j]-'0'<=9) x[i] += (str[j]-'0')*pow16(str.size()-1-j);
			else x[i] += (str[j]-'a'+10)*pow16(str.size()-1-j);
		}
		bitset<32> bs(x[i]);
		rep(j,32){	
			if(i != 8){
				if(bs[j]) num[j]++;
			} else{
				if(bs[j]) num[j]--;
			}
		}
	}
	//rep(i,9) cout << x[i] << " ";
	//cout << endl;
	//rep(i,32) cout << num[i] << " ";
	//cout << endl;
	ll ans = 0;
	rep(i,32){
		//cout << num[i] << " " << add[i] << endl;
		if((num[i]+add[i])%2){
			ans += pow2(i);
			num[i] =7-num[i];
		}
		num[i] += add[i];
		num[i] /= 2;
		bitset<32> bs(num[i]);
		for(int j = i+1; j < 32; j++){
			if(bs[j-i-1]) add[j]++;
		}
		//cout << ans << endl;
	}
	Vi out;
	while(true){
		int tmp = ans % 16;
		out.pb(tmp);
		ans /= 16;
		if(ans == 0) break;
	}
	for(int i = out.size()-1; i >= 0; i--){
		if(out[i] < 10) printf("%d", out[i]);
		else{
			char f = 'a';
			f += out[i]-10;
			printf("%c", f);
		}
	}
	printf("\n");
	return;
}

int main(){
	int n;
	scanf("%d", &n);
	rep(i,n) solve();
}

Measured memory_bytes: 1256
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;

int main(){
        ll n, x, y;
        scanf("%ld %ld %ld", &n, &x, &y);

        std::vector<std::vector<ll>> links(n, std::vector<ll>(0));
        for(ll i=1; i<n; i++){
                links[i-1].push_back(i);
                links[i].push_back(i-1);
        }
        links[x-1].push_back(y-1);
        links[y-1].push_back(x-1);

        std::vector<ll> ans(n, 0);
        for(ll i=0; i<n; i++){
                std::vector<int> dist(n, 1e5), used(n, 0);
                std::queue<P> que;
                que.push(P(i, 0));
                while(!que.empty()){
                        int v, dis;
                        std::tie(v, dis) = que.front();
                        que.pop();
                        used[v] = 1;
                        for(ll to: links[v]){
                                if(!used[to]){
                                        dist[to] = std::min(dist[to], dis);
                                        que.push(P(to, dis+1));
                                }
                        }
                }
                for(ll j=0; j<n; j++){
                        if(dist[j]!=1e5) ans[dist[j]]++;
                }
        }
        for(ll i=0; i<n-1; i++) printf("%ld\n", ans[i]/2);
        return 0;
}

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

int a[200000];

bool cmp(int a, int b){
	return a>b;
}

int main(){
	int n, k, x, dif=0, _max=0;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>x;
		if(a[x]==0)
			dif++;
		a[x] ++;
		_max = max(_max, x);
	}

	if(dif<=k)
		cout<<"0"<<endl;
	else{
		sort(a, a+_max+1, cmp);
		int ans = 0;
		for(int i=k;i<dif;i++)
			ans += a[i];
		cout<<ans<<endl;
	}
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    int ans=0;
    rep(i,n)cin>>a[i];
    rep(i,n){
        //極大値、極小値は前に含める
        while(i+1<n&&a[i]==a[i+1])++i;//イコールのときを１動作に含めると答えが増えてしまうため
        if(i+1<n&&a[i]<a[i+1]){
            while(i+1<n&&a[i]<=a[i+1])++i;
        }
        else if(i+1<n&&a[i]>a[i+1]){
            while(i+1<n&&a[i]>=a[i+1])++i;
        }
        ++ans;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
const int N=1010,M=5010,INF=10000000;
int f[N][M],tot[N],b[N],ne[N],fi[N],minf[N],k,n,x;
void add(int x,int y){
	b[++k]=y; ne[k]=fi[x]; fi[x]=k;
}
void dp(int x){
	for (int k=1; k<=tot[x]; k++) f[x][k]=INF;
	for (int j=fi[x]; j; j=ne[j]){
		dp(b[j]);
		for (int k=tot[x]; k>=0; k--){
			int t1=INF,t2=INF;
			if (k>=tot[b[j]]) t1=f[x][k-tot[b[j]]]+minf[b[j]];//ÏàÍ¬ 
			if (k>=minf[b[j]]) t2=f[x][k-minf[b[j]]]+tot[b[j]];//²»Í¬
			f[x][k]=min(t1,t2);
//			printf("%d %d %d %d\n",x,b[j],k,f[x][k]);
		}
	}
	minf[x]=f[x][0]; for (int i=1; i<=tot[x]; i++) minf[x]=min(minf[x],f[x][i]);
//	printf("hhd:%d %d %d\n",x,tot[x],minf[x]);
	if (minf[x]==INF){
		puts("IMPOSSIBLE");
		exit(0);
	}
}
int main(){
	scanf("%d",&n);
	for (int i=2; i<=n; i++){
		scanf("%d",&x);
		add(x,i);
	}	
	for (int i=1; i<=n; i++) scanf("%d",&tot[i]);
	dp(1);
	puts("POSSIBLE");
}

Measured memory_bytes: 18048
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int S = sc.nextInt();
		int yy = S / 100;
		int mm = S % 100;

		if(1 <= yy && yy <= 12) {
			if(1 <= mm && mm <= 12) {
				System.out.println("AMBIGUOUS");
			}else {
				System.out.println("MMYY");
			}
		}else {
			if(1 <= mm && mm <= 12) {
				System.out.println("YYMM");
			}else {
				System.out.println("NA");
			}
		}

	}

}


Measured memory_bytes: 35660
#include <stdio.h>

int main(void){
    int A, B, C;
    scanf("%d %d %d", &A, &B, &C);

    if(A<C && C<B){
        printf("Yes\n");
        return 0;
    }
    if(A>C && C>B){
        printf("Yes\n");
        return 0;
    }

    printf("No\n");
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>

using namespace std;

bool G[700][700];
int C[700];
int N, M;
int diff;

int inv(int c){
    if(c == 1) return 2;
    if(c == 2) return 1;
    else cout << "wired" << endl;
}

bool dfs(int v, int c){
    C[v] = c;
    if(c == 1) diff++;
    else diff--;
    for(int i = 0; i < N; i++){
        if(!G[v][i]){
            if(C[i] == 0) {
                if(!dfs(i, inv(c))) return false;
            }
            else if(C[v] == C[i]) return false;
        }
    }
    return true;
}

int main(){
    cin >> N >> M;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            G[i][j] = false;
        }
        G[i][i] = true;
    }
    for(int i = 0; i < M; i++){
        int A, B;
        cin >> A >> B;
        A--;
        B--;
        G[A][B] = true;
        G[B][A] = true;
    }
    vector<int> d;
    for(int i = 0; i < N; i++){
        if(C[i] == 0){
            diff = 0;
            if(!dfs(i, 1)){
                cout << -1 << endl;
                return 0;
            }
            d.push_back(abs(diff));
        }
    }
    bool dp[701][701];
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            dp[i][j] = false;
        }
    }
    int cnt_both = 0;
    for(int i = 0; i < N; i++){
        if(C[i] == 0) cnt_both++;
    }
    //cout << cnt_both << endl;
    for(int i = cnt_both; i >= 0; i-=2) dp[0][i] = true;
    for(int i = 0; i < d.size(); i++){
        for(int j = 0; j <= N; j++){
            if(dp[i][j]) {
                dp[i+1][abs(j-d[i])] = true;
                dp[i+1][abs(j+d[i])] = true;
            }
        }
    }
    for(int i = 0; i <= N; i++){
        if(dp[d.size()][i]){
            int n, m;
            n = (N-i)/2;
            m = (N+i)/2;
            //cout << n << ' ' << m << endl;
            cout << (m*(m-1))/2+(n*(n-1))/2 << endl;
            return 0;
        }
    }
}

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

int main(){
	while(true){
		int H;
		cin>>H;
		
		if(H==0)
			break;
		
		int S[10][5];
		for(int y=0;y<H;y++)
			for(int x=0;x<5;x++)
				cin>>S[y][x];
		
		int sco=0;
		
		while(true){
			bool flg =false;
		
			for(int y=0;y<H;y++){
				int m=S[y][2];
				if(m==0)
					continue;

				if(S[y][0]==m && S[y][1]==m){
					sco += m*3;
					S[y][0]=S[y][1]=S[y][2]=0;
					flg=true;
					if(S[y][3]==m){
					sco += m;
					S[y][3]=0;
					if(S[y][4]==m){
					sco += m;
					S[y][4]=0;
					}
					}
				}
				else if(S[y][1]==m&&S[y][3]==m){
					sco += m*3;
					S[y][1]=S[y][2]=S[y][3]=0;
					flg=true;
					if(S[y][4]==m){
					sco += m;
					S[y][4]=0;
					}
				}
				else if(S[y][4]==m&&S[y][3]==m){
					sco += m*3;
					S[y][2]=S[y][3]=S[y][4]=0;
					flg=true;
					}
				}
				if(!flg)
					break;
	
				for(int x=0;x<5;x++){
					for(int y=H-1;y>=0;y--){
						if(S[y][x]!=0)
							continue;
		
						for(int y2=y-1;y2>=0;y2--){
							if(S[y2][x]!=0){
								S[y][x]=S[y2][x];
								S[y2][x]=0;
								break;
							}
						}
					}
				}

			}

			cout<<sco<<endl;
			}
		return 0;
	}



















Measured memory_bytes: 3104
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            string ans = "Yes";
            int N = cin.ReadInt;
            int pt = 0;
            int px = 0;
            int py = 0;
            int t;
            int x;
            int y;
            for(int i = 0;i<N;i++){
                t = cin.ReadInt;
                x = cin.ReadInt;
                y = cin.ReadInt;
                if( (t-pt) < Math.Abs(x-px) + Math.Abs(y-py) || (t-pt)%2 != (Math.Abs(x-px) + Math.Abs(y-py))%2){
                    ans = "No";
                }
                pt = t;
                px = x;
                py = y;
            }
            WriteLine(ans);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator =' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}

Measured memory_bytes: 17360
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0; i < n; i++)

int main(){
    int H, W; 
    cin >> H >> W;
    char s[H][W];
    rep(i, H){
        rep(j, W) cin >> s[i][j];
    }
    bool is_can = true;
    rep(i, H){
        rep(j, W){
            if(s[i][j] == '#'){
            int left, right, up, down;
            left = right = up = down = 0;
            if(i - 1 >= 0){
                if(s[i-1][j] == '#') up = 1;
            }
            if(i + 1 <= H-1){
                if(s[i+1][j] == '#') down = 1;
            }
            if(j - 1 >= 0){
                if(s[i][j-1] == '#') left = 1;
            }
            if(j + 1 <= W-1){
                if(s[i][j+1] == '#') right = 1;
            }
            if(left + right + up + down == 0){
                is_can = false;
                break;
            }
            }
        }
        if(!is_can) break;
    }
    if(is_can) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define maxn 100050
#define modu 1000000007
using namespace std;
typedef long long LL;

LL add(LL& x,LL y)  {
    if (x+=y,x>=modu)
        x-=modu;
}

struct Matrix   {
    static const int N=4;
    LL A[N][N];
    Matrix(LL x=0)  {
        memset(A,0,sizeof(A));
        for (int i=0;i<N;++i)
            A[i][i]=x;
    }

    LL* operator [] (const int& x)  {   return A[x];    }

    Matrix operator * (const Matrix& M) const   {
        Matrix Ans;
        for (int i=0;i<N;++i)
            for (int j=0;j<N;++j)
                for (int k=0;k<N;++k)
                    add(Ans.A[i][j],A[i][k]*M.A[k][j]%modu);
        return Ans;
    }

    void print(string s="")    {
        cout<<s<<":"<<endl;
        for (int i=0;i<N;++i)   {
            for (int j=0;j<N;++j)
                cout<<A[i][j]<<" ";
            cout<<endl;
        }
    }
};

int m,n,a,b,c,p[maxn];

void init() {
	c=0;
	a=1;
	b=0;
    //scanf("%d%d%d%d",&m,&n,&a,&b);
	scanf("%d %d",&m,&n);
    for (int i=1;i<=n;++i)
        scanf("%d",p+i);
}

Matrix pw(Matrix A,int k)  {
    Matrix Ans(1);
    for (;k;k>>=1)  {
        if (k&1)
            Ans=Ans*A;
        A=A*A;
    }
    return Ans;
}

void solve()    {
    Matrix A0,A1;
    //A0[0][0]=(9*(a+b+c)+1)%modu,A0[0][1]=18*a%modu,A0[0][2]=A0[0][3]=9;
    A0[0][0]=((a+b+c)+1)%modu,A0[0][1]=2*a%modu,A0[0][2]=A0[0][3]=1;
    A0[1][0]=A0[1][1]=1;
    A0[2][0]=a,A0[2][1]=2*a%modu,A0[2][2]=1;
    A0[3][0]=b,A0[3][3]=1;

    A1[0][0]=1;
    for (int i=1;i<Matrix::N;++i)
        for (int j=0;j<Matrix::N;++j)
            A1[i][j]=A0[i][j];
    Matrix Ans(1);

    // A0.print("A0");
    // A1.print("A1");

    if (0)  {
        for (int i=1,j=1;i<m;++i)  {
            if (j<=n&&p[j]==i)  
                Ans=A1*Ans,++j;
            else
                Ans=A0*Ans;
        }
    }   else    {
        for (int i=1;i<=n;++i)
            Ans=A1*pw(A0,p[i]-p[i-1]-1)*Ans;
        Ans=pw(A0,m-p[n]-1)*Ans;
    }
    --A0[0][0];
    Ans=A0*Ans;
    printf("%lld\n",Ans[0][0]);
}

int main()  {
    init();
    solve();
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> h(N+1,0);
  vector<int> dp(N+1,9999999);
  for(int i=1;i<=N;i++){
  	cin >> h.at(i);
  }
  dp.at(1)=0;
  for(int i=1; i<N; i++){
  	if(i!=1){
      dp.at(i+1)=min(
        dp.at(i)+abs(h.at(i+1)-h.at(i)),
        dp.at(i-1)+abs(h.at(i+1)-h.at(i-1))
      );
    }else{
      dp.at(i+1)=dp.at(i)+abs(h.at(i+1)-h.at(i));
    }
  }
  cout << dp.at(N);
}

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

using namespace std;
using ll = long long;
const int INF = 1e9;


int main()
{
    int n, m; cin >> n >> m;
    vector<vector<int>> dist(n, vector<int>(n, INF));
    for(int i = 0; i < m; i++) {
        int a, b, c; cin >> a >> b >> c;
        dist[a][b] = c;
    }

    vector<vector<vector<int>>> dp(1<<n, vector<vector<int>>(n, vector<int>(n, INF))); //dp[i][j][k] := 集合iを見ていて、今jにいて、kスタート
    for(int i = 0; i < n; i++)dp[(1<<i)][i][i] = 0;


    {// -- bitDP --
        for(int bit = 1; bit < (1<<n); bit++) {
            for(int i = 0; i < n; i++) {
                for(int j = 0; j < n; j++) {
                    for(int k = 0; k < n; k++) {

                        // i -> j / start = k;
                        if(bit & (1<<j) || (bit & (1<<i)) == 0 || i == j)continue;
                        dp[bit | (1<<j)][j][k] = min(dp[bit | (1<<j)][j][k], dp[bit][i][k] + dist[i][j]);

                    }
                }
            }
        }
    }


    int ans = INF;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            if(i == j)continue;
            int bit = (1<<n) - 1;
            ans = min(ans, dp[bit][j][i] + dist[j][i]);
        }
    }
    cout << (ans == INF ? -1 : ans) << endl;

}


Measured memory_bytes: 53840
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N;
  while (cin >> N) {
    vector<double> x(N), y(N);
    for (int i = 0; i < N; i++) cin >> x[i] >> y[i];
    double res = 0;
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        res += hypot(x[i] - x[j], y[i] - y[j]);
      }
    }
    res /= N;
    printf("%.20f\n", res);
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int value = 700;
    for(int i = 0;i < 3;i++) {
        if(s[i] == 'o') {
            value+=100;
        }
    }
    cout << value << endl;
}

Measured memory_bytes: 256
import sys
import copy

readline = sys.stdin.readline

def main():
    N, K = map(int, readline().split())
    a = list(map(int, readline().split()))

    h = [max(a[:i]) for i in range(1, N+1)]
    #print(h)

    mincost = float('inf')
    for i in range(2**N):
        cost = 0
        htmp = copy.copy(h)
        tmp = []
        tmpappend = tmp.append
        for j in range(N):
            if (i>>j) & 1:
                tmpappend(j)
        if len(tmp) != K:
            continue
        #print(tmp)
        for k in tmp:
            if k >= 1 and htmp[k] <= htmp[k-1]:
                maxh = max(htmp[:k])
                cost += maxh - a[k] + 1
                htmp[k] = maxh + 1
        #print("h:{}, cost:{}".format(htmp, cost))
        mincost = min(mincost, cost)

    print(mincost)

if __name__ == "__main__":
    main()


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

using namespace std;


long long int c=1;
int fact(int );

int main() {
    long long int n,m,t,i,j,k,l,a,b,x;
    cin>>k>>x;
    t=x-k+1;
    for(i=0;i<2*k-1;i++)
    {
        cout<<t<<" ";
        t++;
    }

    return 0;
}







Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main(){
    ll a,b,c; cin>>a>>b>>c;
    if(a==b){
        if(a!=c) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }else if(b==c || a==c) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

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

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

int main()
{
    int n,r;
    cin>>n>>r;

    if(n<10)
    {
        cout<<r+100*(10-n)<<endl;;
    }
    else
    {
        cout<<r<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <unordered_set>
using namespace std;
typedef long long ll;

ll mov[13][4] = {
	{2,-1,-1,-1},
	{2,5,-1,-1},
	{0,1,3,6},
	{2,7,-1,-1},
	{5,-1,-1,-1},
	{1,4,6,9},
	{2,5,7,10},
	{3,6,8,11},
	{7,-1,-1,-1},
	{5,10,-1,-1},
	{6,9,11,12},
	{7,10,-1,-1},
	{10,-1,-1,-1},
};

ll sw(ll l, int i, int j) {
	int a, b;
	a = (l >> (4 * i)) & 0xfL;
	b = (l >> (4 * j)) & 0xfL;

	l &= ~(0xfL << (4*i));
	l &= ~(0xfL << (4*j));

	l |= (ll)b << (4 * i);
	l |= (ll)a << (4 * j);

	return l;
}

int main() {
	while(1) {
		ll in = 0;
		for(int i = 0; i < 13; i++) {
			int tmpin;
			cin >> tmpin;
			if(tmpin < 0)
				return 0;
			in |= ((ll)tmpin << (4*i));
		}

		queue<ll> q;
		unordered_set<ll> s;
		q.push(in);
		s.insert(in);
		int ans = -1;
		// debug
		int failcount = 0;
		for(int i = 0; i <= 20; i++) {
			queue<ll> next;
			while(!q.empty()) {
				ll l = q.front(); q.pop();
				if(l == 0xba9876543210) {
					ans = i;
					goto OUTPUT_ANSWER;
				}
				else {
					int cnt = 0;
					for(int j = 0; j < 13; j++) {
						ll t = 0xba9876543210;
						if(((l >> 4*j) & 0xfL) != ((t >> 4*j) & 0xfL)) {
							cnt++;
						}
					}
					if(cnt > 20 - i + 2)
						continue;
				}

				for(int j = 0; j < 13; j++) {
					if(((l >> (4*j)) & 0xfL) == 0) {
						for(int k = 0; k < 4; k++) {
							ll p;
							if(mov[j][k] < 0)
								break;
							p = sw(l, j, mov[j][k]);
							if(s.find(p) == s.end()) {
								s.insert(p);
								next.push(p);
							}
							else {
								failcount++;
							}
						}
					}
				}
			}
			q = next;
		}

OUTPUT_ANSWER:;
		if(ans < 0)
			cout << "NA" << endl;
		else
			cout << ans << endl;
//		cout << failcount << endl;
	}
}

Measured memory_bytes: 5852
#include<stdlib.h>
#include<stdio.h>

int compare(const void* a,const void* b){
  
  return *(int*)a - *(int*)b;

}


int main(void){
  int N;
  scanf("%d",&N);
  int R[N];
  int X[N];
   for(int i = 0;i<N;i++){
     scanf("%d",X+i);
     R[i]=X[i];
    }
      
  
  qsort(X,N,sizeof(int),compare);
  for(int i=0;i<N;i++){
    if(R[i]<=X[N/2-1]){
      printf("%d\n",X[N/2]);
    }
    else{
      printf("%d\n",X[N/2-1]);
    }
  }
  return 0;
}


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

int main() {
    int x,y;
    cin>>x>>y;
    
    if(y%2 != 0) {
        cout<<"No"<<endl;
        return 0;
    }
    
    if((y >= 2*x) and (y <= 4*x)) {
        cout<<"Yes"<<endl;
    } else {
        cout<<"No"<<endl;
    }
    return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vii;


#define F first
#define S second

#define ERR 1e-9

#if !ONLINE_JUDGE && !EVAL
    #define dbg_var(x) cerr << #x << ": " << x << "\n";
    #define dbg_iter(x, y) cerr  << #x << ": " << print_iterable(x, y) << "\n";
#else
    #define dbg_var(x)
    #define dbg_iter(x, y)
#endif // ONLINE_JUDGE

template <typename T1, typename T2>
string print_iterable( T1 begin_iter, T2 end_iter){
    bool first = true;
    stringstream res;
    res << "[ ";
    for(; begin_iter != end_iter; ++begin_iter){
        if(!first) res << ", ";
        first = false;
        res << *begin_iter;
    }
    res << " ]";
    return res.str();
}

void aggMax(int & res, int x){ if(x > res)res = x; }
void aggMin(int & res, int x){ if(x < res)res = x; }

int II(){ int i; cin >> i; return i; }
void OI(int i){ cout << i; }

// constraints
#define MAXN 1000000

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);

    int N = II();
    vi H(N);
    for(auto & x : H) x = II();

    int res = 0, maxx = 0;

    for(int i=0; i<N; i++){
        if(H[i] >= maxx) res++;
        maxx = max(maxx, H[i]);
    }

    cout << res << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;

int main() {
	lli A, B, C;
	cin >> A >> B >> C;

	lli ans = 0;
		if (A % 2 == 1 && B % 2 == 1 && C % 2 == 1) {
			if (A>B) {
				lli X = A;
				A = B;
				B = X;
			}
			if (C <= B) ans = A * C;
			else ans = A * B;
		}
	cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;

int main() {

    char a, b;
    cin >> a >> b;

    if(a == 'H')
        cout << (b == 'H' ? "H" : "D") << endl;
    else
        cout << (b == 'H' ? "D" : "H") << endl;
        


    return 0;
}

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

int main(void)
{ 

	ll n,i,toss;
	double heads,s;
	cin>>n;
	vector <double> dp(n+1,0);
	dp[0]=1;
	for(toss=0;toss<n;toss++)
	{
		cin>>heads;
		for(i=toss+1;i>=0;i--)
		{
			if(i==0)
			s=0;
			else s=dp[i-1]*heads;
			
			dp[i]=s+dp[i]*((double)(1-heads));
			
		}
	}
	double ans=0;
	for(i=(n+1)/2;i<=n;i++)
	ans+=dp[i];
	
	cout << fixed << setprecision(10)<<ans;

}

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

int isprime(int);
  
int main(){
  int n,N[10000],count=0,i;
  int jud;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&N[i]);
  }
  for(i=0;i<n;i++){
    jud = isprime(N[i]);
    if(jud == 1){count++;}
  }
  printf("%d\n",count);

  return 0;
}

int isprime(int x){
  int i;
    
  if(x == 2)return 1;
  if(x < 2 || x%2 == 0)return 0;
  i = 3;
  while(i <= sqrt(x)){
    if(x%i == 0){return 0;}
    i = i + 2;
  }

  return 1;
}



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

int cntCol[555];
int cnt[555];
char grid[555][555];

int main(void) {

    bool canAchieve = false;

    int n = 0; scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf(" %s", grid[i]);
        for (int j = 0; j < n; ++j) {
            if (grid[i][j] == '#') canAchieve = true;
            if (grid[i][j] == '#') ++cntCol[j];
        }
    }
    if (!canAchieve) {
        puts("-1");
        return 0;
    }

    int best = 11111111;

    for (int i = 0; i < n; ++i) {
        int ans = 0;
        memcpy(cnt, cntCol, sizeof cntCol);
        if (grid[i][i] != '#') {
            if (cntCol[i] == 0) {
                ++ans;
                ++cnt[i];
            }
            ++ans;
            ++cnt[i];
        }
        for (int j = 0; j < n; ++j) {
            if (i != j && grid[i][j] == '.') {
                ++ans;
                cnt[j] = 0;
            }
        }
        for (int j = 0; j < n; ++j) {
            if (cnt[j] != n) {
                ++ans;
            }
        }
        best = min(best, ans);
    }
    
    printf("%d\n", best);

    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<cstdio>
#include<cstdlib>

using namespace std;
typedef long long int ll;

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(){
    int n;  cin >> n;

    int x,y;

    for(int i=9;i>0;i--){
        if(n%i==0){
            x=n/i;
            y=i;    //printf("%d,%d\n",x,y);
            break;
        }
    }

    if(x>9 || y>9){
        puts("No");
    }else{
        puts("Yes");
    }
}

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

int main() {
    
    int a, b; cin >> a >> b;
    string s; cin >> s;
    bool can = true;
    for (int i = 0; i < a; i++) {
        int tmp = s[i] - '0';
        if (!(0 <= tmp && tmp <= 9)) can = false;
    }
    if (s[a] != '-') can = false;
    for (int i = a + 1; i < a + b + 1; i++) {
        int tmp = s[i] - '0';
        if (!(0 <= tmp && tmp <= 9)) can = false;
    }
    if (can) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3604
n,k=map(int,input().split())
p=list(map(int,input().split()))
ans=0
a=[]
for i in range(k):
    ans+=p[i]*(p[i]+1)/(2*p[i])
a.append(ans)
for i in range(n-k):
    ans+=p[i+k]*(p[i+k]+1)/(2*p[i+k])-p[i]*(p[i]+1)/(2*p[i])
    a.append(ans)
print(max(a))

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

typedef long long ll;
typedef pair<int,int> ii;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int y,m,d; char c;
	cin>>y>>c>>m>>c>>d;
	cout<<(m<=4?"Heisei":"TBD")<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 2000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
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;}

struct edge{int from, to, cost;};
int V, E, r;
vector<edge> g;
int d[100005];  
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> V >> E >> r;
    rep(i, 0, E) {
        int s, t, u;
        cin >> s >> t >> u;
        edge tmp;
        tmp.from = s, tmp.to = t, tmp.cost = u;
        g.pb(tmp);
    }

    fill(d, d+V, INF);
    d[r] = 0;
    while (1) {
        bool flag = false;
        rep(i, 0, E) {
            edge e = g[i];
            if (d[e.from] != INF && d[e.from] + e.cost < d[e.to]) {
                d[e.to] = d[e.from] + e.cost;
                flag = true;
            }
        }
        if (!flag) break;
    }
    rep(i, 0, V) {
        if (d[i] != INF) cout << d[i] << endl;
        else cout << "INF" << endl;
    }
    return 0;
}


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

using namespace std;
typedef long long ll;

vector<int> adj[100100];

int dp[100100];
bool vis[100100];

void dfs(int node) {
	vis[node] = true;
	for(auto v : adj[node]) {
		if(!vis[v]) dfs(v);
		dp[node] = max(dp[node], dp[v] + 1);
	}
}

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

	for (int i = 0; i < m; i++) {
		int from, to;
		cin >> from >> to;

		adj[from].push_back(to);
	}

	
	for (int i = 1; i <= n; i++) {
		if(!vis[i]) dfs(i);
	}
	
	int maxLen = 0;
	for(int i=1; i <= n; i++) {
		maxLen = max(maxLen, dp[i]);
	}

	cout << maxLen;

	return 0;
}

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

int main() {
  int a, b, c, x = 0;
  cin >> a;
  for(int i = 0; i < a; i++){
  	cin >> b >> c;
    x += (c-b) + 1;
  }
  cout << x << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"bytes"
	"errors"
	"fmt"
	"io"
	"io/ioutil"
	"os"
	"strconv"
	"strings"
)

var (
	// ErrLineNotFound -
	ErrLineNotFound = errors.New("lines: line not found")
)

type onError int

const (
	onErrorPanic onError = iota
	onErrorError
)

// Lines represents multi line.
type Lines struct {
	r       io.Reader
	w       io.Writer
	onError onError

	store []string
}

// NewLines create lines from provided input reader.
func New(r io.Reader) *Lines {
	lines, err := newLines(r, ioutil.Discard, onErrorPanic)
	if err != nil {
		panic(err)
	}
	return lines
}

// Line represents single line.
type Line struct {
	store string
	field int
}

// Line return given n line.
func (ls *Lines) Line(n int) *Line {
	line, err := ls.line(n)
	if err != nil {
		panic(err)
	}
	return line
}

func (ls *Lines) line(n int) (*Line, error) {
	if n >= len(ls.store) {
		return nil, ErrLineNotFound
	}
	return &Line{store: ls.store[n]}, nil
}

func (l *Line) Ints() []int {
	ints, err := l.ints()
	if err != nil {
		panic(err)
	}
	return ints
}

func (l *Line) ints() ([]int, error) {
	var ints []int
	fields := strings.Fields(l.store)
	for _, s := range fields {
		i, err := strconv.Atoi(s)
		if err != nil {
			return nil, err
		}
		ints = append(ints, i)
	}
	return ints, nil
}

// Field specify current field scope.
func (l *Line) Field(n int) *Line {
	clone := l.clone()
	clone.field = n
	return clone
}

func (l *Line) Int() int {
	ints, err := l.ints()
	if err != nil {
		panic(err)
	}
	return ints[l.field]
}

func newLines(r io.Reader, w io.Writer, onError onError) (*Lines, error) {
	lines := &Lines{
		r:       r,
		w:       w,
		onError: onErrorError,
	}
	return lines, lines.init()
}

func (ls *Lines) init() error {
	s := bufio.NewScanner(ls.r)
	for s.Scan() {
		ls.store = append(ls.store, s.Text())
	}
	return s.Err()
}

func (l *Line) clone() *Line {
	clone := *l
	return &clone
}

func main() {
	lines := New(os.Stdin)
	num := lines.Line(0).store

	var b = new(bytes.Buffer)
	for _, n := range num {
		switch n {
		case '9':
			b.WriteString("1")
		case '1':
			b.WriteString("9")
		default:
			b.WriteString(string(n))
		}
	}

	fmt.Println(b.String())
}


Measured memory_bytes: 640
#include<stdio.h>
int main()
{
int k;
int a;
int b;
int i;
int flag=0;

scanf("%d",&k);
scanf("%d %d",&a,&b);


for(i=a;i<b+1;i++){

if(i%k==0){flag=1;}

}


if(flag==0){
printf("NG");
}else{
printf("OK");
}

return 0;
}

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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) {
    if (a.size() < b.size()) {
        a = b;
        return true;
    }
    else if (a.size() == b.size()) {
        if (a < b) {
            a = b;
            return true;
        }
    }
    return false;
}

const long long INF = 1LL << 60;

int main()
{
    int stick[9] = {2, 5, 5, 4, 5, 6, 3, 7, 6};
    int N, M;
    cin >> N >> M;

    int num[M];
    rep(i, M) cin >> num[i];

    vector<string> dp(N + 1, "#");
    dp[0] = "";

    rep(i, N + 1) {
        rep(j, M) {
            if (dp[i] == "#") continue;
            if (i + stick[num[j] - 1] <= N) {
                chmax(dp[i + stick[num[j] - 1]], dp[i] + to_string(num[j]));
            }
        }
    }

    cout << dp[N] << endl;

    return 0;
}

Measured memory_bytes: 33024
# -*- coding: utf-8 -*-
"""
Created on Wed Jul 18 00:01:41 2018

@author: Yuya
"""

n, k = map(int, input().split())

z = list(map(int, input().split()))

n = len(z)
c = 0

for i in range(len(z)):
    if z[i]<0:
        c+=1

d = len(z)-c

mi = 100000000000000000

if c<k:
    x = 0
    y = k-1
    mi = 100000000000000000
    ope = n-k
else:
    x = c-k
    y = c-1
    
    
for i in range(n):
    if y < n:
        if z[x]<0 and z[y]<0:
            k1 = abs(z[x])
            k2 = 0
        elif z[x]>0 and z[y]>0:
            k2 = abs(z[y])
            k1 = 0
        else:
            k1 = abs(z[x])
            k2 = abs(z[y])
            
        if k1<k2:
            tmp=k1*2+k2
        else:
            tmp=k2*2+k1

        if tmp<mi:
            mi = tmp
        x+=1
        y+=1
    else:
        break

print(mi)

Measured memory_bytes: 14844
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;


public class Main {


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

		List<Integer> a = new ArrayList<Integer>();
		List<Integer> b = new ArrayList<Integer>();
		List<String> op = new ArrayList<String>();

		 for(int i=0;;i++){
			 a.add(i, scan.nextInt());
			 op.add(i, scan.next());
			 b.add(i, scan.nextInt());
			 if(op.get(i).equals("?")) break;
		 }



		 for(int i=0;;i++){
			 if(op.get(i).equals("?")) break;
			 if(op.get(i).equals("+")) System.out.println(a.get(i)+b.get(i));
			 if(op.get(i).equals("-")) System.out.println(a.get(i)-b.get(i));
			 if(op.get(i).equals("*")) System.out.println(a.get(i)*b.get(i));
			 if(op.get(i).equals("/")) System.out.println(a.get(i)/b.get(i));
		 }
		 //System.out.println(df.format(s)+" "+df.format(a));

	}

}

Measured memory_bytes: 26152
# ABC155b


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    # 再帰関数を使わない限りPypyで出すこと

    n = int(input())
    a = list(map(int, input().split()))

    for i in a:
        if i % 2 == 0:
            if i % 3 == 0 or i % 5 == 0:
                continue
            else:
                print('DENIED')
                exit(0)
    print('APPROVED')


if __name__ == '__main__':
    main()


Measured memory_bytes: 40680