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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------


int N;
string S;
ll mo=1000000007;
vector<ll> C,R;
const int PAT=5;
vector<ll> A[PAT];
vector<ll> B[PAT];

ll modpow(ll a, ll n = mo-2) {
	ll r=1;a%=mo;
	while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
	return r;
}


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>S;
	srand(time(NULL));
	FOR(i,PAT) {
		C.push_back(rand()%10000000+10000000);
		R.push_back(modpow(C.back()));
		A[i].push_back(1);
		B[i].push_back(0);
	}
	reverse(ALL(S));
	FORR(c,S) {
		FOR(i,PAT) {
			if(c=='+') {
				A[i].push_back(A[i].back());
				B[i].push_back((B[i].back()+1)%mo);
			}
			if(c=='-') {
				A[i].push_back(A[i].back());
				B[i].push_back((B[i].back()+mo-1)%mo);
			}
			if(c=='>') {
				A[i].push_back(A[i].back()*C[i]%mo);
				B[i].push_back(B[i].back()*R[i]%mo);
			}
			if(c=='<') {
				A[i].push_back(A[i].back()*R[i]%mo);
				B[i].push_back(B[i].back()*C[i]%mo);
			}
		}
	}
	ll ret=0;
	map<vector<ll>,int> memo;
	memo[vector<ll>(PAT,0)]++;
	FOR(j,N) {
		vector<ll> BA(PAT),BAS(PAT);
		FOR(i,PAT) {
			BA[i]=B[i][j+1]*A[i][j+1]%mo;
			BAS[i]=(B[i][j+1]+mo-B[i].back())*A[i][j+1]%mo;
		}
		ret+=memo[BAS];
		memo[BA]++;
	}
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

ll query(ll i){
	cout << i << endl;
	string s;
	cin >> s;
	
	if(s=="Vacant"){
		exit(0);
	}
	else if(s=="Male") return 0;
	else return 1;
}

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

    ll N;
    cin >> N;

    ll lb = 0;
    ll ub = N-1;

    ll L = query(lb);
    ll R = query(ub);

    while(1){
    	if(ub-lb==2){
    		query(lb+1);
    	}
    	ll mid;
    	if((ub-lb)%4==0){
    		mid = (ub+lb)/2;
    	}else{
    		mid = (ub+lb)/2-1;
    	}
    	ll tmp = query(mid);
    	if(tmp == L){
    		lb = mid;
    		L = tmp;
    	}else{
    		ub = mid;
    		R = tmp;
    	}
    }

    return 0;
}

Measured memory_bytes: 852
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;

int main(){
  bool ok = 0;
  int x, y;
  cin >> x >> y;
  for(int i = 0; i <= 50; i ++){
    int d = (y - i * 2) / 4;
    if(d + i == x && d * 4 + i * 2 == y)
      ok = 1;;
  }
  cout << (ok ? "Yes" : "No");
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, k; cin >> n >> k;
	vector<long long> a(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	long long sum = 0;
	for(int i = 0; i < n; i++) if(a[i] > 0) sum += a[i];
	long long best = 0, all = 0, ins = 0;
	multiset<long long> vals;
	for(int i = 0; i < k; i++) {
		if(a[i] > 0){
			vals.insert(a[i]);
			ins += a[i];
		}
		all += a[i];
	}
	best = max(best, sum - ins);
	best = max(best, sum + all - ins);
	for(int i = k; i < n; i++){
		all += a[i];
		if(a[i] > 0){
			vals.insert(a[i]);
			ins += a[i];
		}
		all -= a[i - k];
		if(a[i - k] > 0){
			vals.erase(vals.find(a[i - k]));
			ins -= a[i - k];
		}
		best = max(best, sum - ins);
		best = max(best, sum + all - ins);
	}
	cout << best << endl;
	return 0;
}



Measured memory_bytes: 4608
#!/usr/bin/env python3
from collections import deque

n, x, y = map(int, input().split())
x -= 1
y -= 1

ans = [0 for _ in range(n)]

# 頂点'start'からBFS
def bfs(start):
    inf = 1001001001
    dist = [inf for _ in range(n)]
    q = deque()
    q.append(start)
    dist[start] = 0 

    def push(v, d): 
        if dist[v] != inf: return
        dist[v] = d 
        q.append(v)

    push(start, 0)
    while q:
        v = q.popleft()
        d = dist[v]
        if v-1 >= 0: push(v-1, d+1)
        if v+1 < n: push (v+1, d+1)
        if v==x: push(y, d+1)
        if v==y: push(x, d+1)
    
    for i in range(n):
        ans[dist[i]] += 1
    
for i in range(n):
    bfs(i)
for i in range(1, n): 
    print(ans[i]//2)


Measured memory_bytes: 53340
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    n=II()
    ss=set()
    for _ in range(n):
        s=SI()
        ss.add(s)
    print(len(ss))

main()

Measured memory_bytes: 31052
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;

const long double PI = acos(-1);
constexpr long double EPS = 1e-15;
constexpr int inf = 2e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9+7;
constexpr ll MOD1 = 998244353;
typedef pair<ll,ll> P;

//#define all(v) (v).begin(), (v).end()
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

int main(){
    int n;
    cin >> n;
    vector<vector<int>> sum(n + 1, vector<int>(n + 1, 0));
    REP(i, n){
        int sum_tmp = 0;
        REP(j, n){
            int tmp;
            cin >> tmp;
            sum_tmp += tmp;
            sum[i + 1][j + 1] = sum[i][j + 1] + sum_tmp;
        }
    }
    int ans = -inf;
    REP(i, n + 1) REP(j, n + 1) REP(k, i) REP(l, j){
        int tmp = sum[i][j] - sum[i][l] - sum[k][j] + sum[k][l];
        // cout << tmp << endl;
        if(ans < tmp) ans = tmp;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3176
local p={}
for i=0,101 do
    p[i]=i
end

local x,n=io.read("n","n")
for i=1,n do
    local input=io.read("n")
    p[input]=10000
end

local minabs=10000
for i=0,101 do
    if math.abs(minabs)>math.abs(p[i]-x) then
        minabs=p[i]-x
    end
end
print(minabs+x)

Measured memory_bytes: 2788
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define REEP(i, N) for(ll i = N - 1; i >= 0; --i)
#define FOR(i,m,n) for(ll i = m; i < n; ++i)
#define RFOR(i,m,n) for(ll i = n - 1; i >= m; --i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define PB push_back
#define KIRIAGE(a, b) a += (b - a % b) % b
#define CEIL(c, a, b) if(a % b == 0) { c = a / b;} else { c = a / b + 1;}
#define sp(n) setprecision(n)
#define INF 1000000000
#define MOD 1000000007

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx4[4] = {1, 0, -1, 0};
int dy4[4] = {0, 1, 0, -1};
int dx8[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

int main(void) {
	int N, C, K;
	cin>>N>>C>>K;
	vector<int> t(N);
	REP(i, N) {
		cin>>t[i];
	}
	sort(ALL(t));
	int ans = 0;
	int capa = 0;
	int las = -1;
	REP(i, N) {
		if(las == -1) las = t[i];
		++capa;
		if(i < N - 1 && t[i + 1] - las > K) {
			++ans;
			capa = 0;
			las = -1;
		} else if(capa == C) {
			++ans;
			capa = 0;
			las = -1;
		}
	}
	if(capa > 0) ++ans;
	cout<<ans<<endl;
}



Measured memory_bytes: 768
#include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int f(int a[][100],int b[],int c[],int n){
  int i,j;
  int mn=-1;
  for(i=0;i<n;i++){
    if(c[i]){
      for(j=0;j<n;j++){
	if(a[i][j]!=-1&&c[j]==0&&(b[j]==-1||b[j]>a[i][j]))
	  b[j]=a[i][j];
      }
    }
  }
  for(i=0;i<n;i++){
    if(b[i]!=-1&&c[i]==0&&(mn==-1||b[mn]>b[i]))
      mn=i;
  }
  c[mn]=1;
  return b[mn];
}
int main(){
  int h,i,j;
  int a[100][100],b[100],c[100],m,n;
  int sm;
  while(cin>>n&&n){
    cin>>m;
    memset(a,-1,sizeof(a));
    memset(c,0,sizeof(c));
    for(i=0;i<m;i++){
      int p,q,r;
      scanf("%d,%d,%d",&p,&q,&r);
      a[p][q]=r/100-1;
      a[q][p]=a[p][q];
      c[p]++;
      c[q]++;
    }
    sm=0;
    do{
      h=0;
      for(i=0;i<n;i++){
	if(c[i]==1){
	  for(j=0;a[i][j]==-1;j++);
	  sm+=a[i][j];
	  a[i][j]=-1;
	  a[j][i]=-1;
	  c[i]--;
	  c[j]--;
	  h=1;
	}
      }
    }while(h);
    memset(b,-1,sizeof(b));
    memset(c,0,sizeof(c));
    b[0]=0;
    c[0]=1;
    for(i=1;i<n;i++)
      sm+=f(a,b,c,n);
    cout<<sm<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <vector>
using namespace std;
int main(){
  string s;
  cin >> s;
  int len=s.size();
  string output;
  int i=0;
  while(i<len){
    if(s.at(i)=='0'){
      output.push_back('0');
    }
    else if(s.at(i)=='1'){
      output.push_back('1');
    }
    else if(s.at(i)=='B'){
      if(output.size()>0){
        output.pop_back();
      }
    }
    i++;
  }
  cout << output << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define el "\n"
#define F first
#define S second
#define PI 3.14159265358979323846  /* pi */
#define FOR(i,a,b) for(int i = a; i < b; ++i)
#define FORD(i,a,b) for(int i = a; i >= b; --i)
#define RI(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(n)-1)
#define SQR(x) (x)*(x)
#define all(v)  	((v).begin()),((v).end())
#define degreesToRadians(angleDegrees) (angleDegrees * PI / 180.0) // Converts degrees to radians.
#define radiansToDegrees(angleRadians) (angleRadians * 180.0 / PI) // Converts radians to degrees.
typedef long long ll;
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pll;
typedef long double ld;
typedef vector<int>		vi;
typedef vector<ll>		vll;
typedef vector<pii>		vpii;
typedef vector<pll>		vpll;
const double EPS = 1e-9;
const int N = 1e3+2, M = 3e5+5, OO = 0x3f3f3f3f;
// int dx[] = {1,-1,0,0} , dy[] = {0,0,1,-1}; // 4 Direction
// int dx[] = {1,-1,0,0,1,1,-1,-1}, dy[] = {0,0,1,-1,1,-1,1,-1}; // 8 Direction
// int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1}; // Knight Direction
// int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1}; // Hexagonal Direction

int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
int a,b,c,d;
cin>>a>>b>>c>>d;
for(int i=0;true;i++){
  if(i%2==0){
    c = c-b;
  }
  if(i%2!=0){
    a = a-d;
  }
  if(a<=0){
    cout<<"No"<<endl;
    break;
  }
  if(c<=0){
    cout<<"Yes"<<endl;
    break;
  }
}
	return 0;

}


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

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

#define pb push_back
#define in ,
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

char m[8][8];
int h, w;

int solve(int x, int y) {
  int f1 = false, f2 = false;
  if(!x && !y) f1 = true;
  if(x > 0) if(m[x - 1][y] == '#') f1 = !f1;
  if(y > 0) if(m[x][y - 1] == '#') f1 = !f1;
  if(!f1) return 0;
  if(x == h - 1 && y == w - 1) return 1;
  if(x < h) if(m[x + 1][y] == '#') f2 = !f2;
  if(y < w) if(m[x][y + 1] == '#') f2 = !f2;
  if(!f2) return 0;
  if(x < h) {
    if(m[x + 1][y] == '#') solve(x + 1, y);
    else solve(x, y + 1);
  }else solve(x, y + 1);

}

int main() {
  cin >> h >> w;
  rep(i, 0, h) rep(j, 0, w) cin >> m[i][j];

  cout << (solve(0, 0) ? "Possible" : "Impossible") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(int i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<int,int> Pi;
const int INF=(ll)(1LL<<31)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int all_dice[7][7][4]={
	{{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}},
	{{0,0,0,0},{0,0,0,0},{2,3,5,4},{3,5,4,2},{4,2,3,5},{5,4,2,3},{0,0,0,0}},
	{{0,0,0,0},{1,4,6,3},{0,0,0,0},{3,1,4,6},{4,6,3,1},{0,0,0,0},{6,3,1,4}},
	{{0,0,0,0},{1,2,6,5},{2,6,5,1},{0,0,0,0},{0,0,0,0},{5,1,2,6},{6,5,1,2}},
	{{0,0,0,0},{1,5,6,2},{2,1,5,6},{0,0,0,0},{0,0,0,0},{5,6,2,1},{6,2,1,5}},
	{{0,0,0,0},{1,3,6,4},{0,0,0,0},{3,6,4,1},{4,1,3,6},{0,0,0,0},{6,4,1,3}},
	{{0,0,0,0},{0,0,0,0},{2,4,5,3},{3,2,4,5},{4,5,3,2},{5,3,2,4},{0,0,0,0}}
};

struct dice{
	int u,d,f,b,r,l;
	dice(int _u,int _d,int _f,int _b,int _r,int _l){
		u=_u;
		d=_d;
		f=_f;
		b=_b;
		r=_r;
		l=_l;
	}
};

void fr(dice& a){
	int t=a.u;
	a.u=a.b;
	a.b=a.d;
	a.d=a.f;
	a.f=t;
}
void br(dice& a){
	int t=a.u;
	a.u=a.f;
	a.f=a.d;
	a.d=a.b;
	a.b=t;
}

void lr(dice& a){
	int t=a.u;
	a.u=a.r;
	a.r=a.d;
	a.d=a.l;
	a.l=t;
}
void rr(dice& a){
	int t=a.u;
	a.u=a.l;
	a.l=a.d;
	a.d=a.r;
	a.r=t;
}
int n;
int t,f;
int dd[300][300];
int num_dice[300][300];
int main(){
	while(1){
		REP(i,300)
			REP(j,300)
			dd[i][j]=0;
		REP(i,300)
			REP(j,300)
				num_dice[i][j]=0;
		cin>>n;
		if(n==0)break;
		for(int i=0;i<n;i++){
			cin>>t>>f;
			int nx=150;
			int ny=150;
			dd[ny][nx]++;
			dice a={0,0,0,0,0,0};
			a.u=t;
			a.f=f;
			a.d=7-t;
			a.b=7-f;
			a.l=all_dice[t][f][1];
			a.r=all_dice[t][f][3];
			int flag=1;
			while(flag){
				flag=0;
				for(int j=6;j>=4;j--){
					for(int k=0;k<4;k++){
						if(all_dice[a.u][a.f][k]==j){
							if(dd[ny][nx]>dd[ny+dy[k]][nx+dx[k]]+1){
								dd[ny][nx]--;
								dd[ny+dy[k]][nx+dx[k]]++;
								nx=nx+dx[k];
								ny=ny+dy[k];
								flag=1;
								if(k==0)fr(a);
								if(k==1)lr(a);
								if(k==2)br(a);
								if(k==3)rr(a);
								goto A;
							}
						}
					}
				}
				A:;
				if(flag==0){
					num_dice[ny][nx]=a.u;
				}
			}
		}
		int ans[7]={};
		REP(i,300){
			REP(j,300){
			if(num_dice[i][j]!=0){
				ans[num_dice[i][j]]++;
				//cout<<i<<" "<<j<<endl;
				//cout<<num_dice[i][j]<<endl;
				//cout<<dd[i][j]<<endl;
			}
			}
		}
		for(int i=1;i<=6;i++){
				printf("%d",ans[i]);
				if(i!=6)printf(" ");
		}
		printf("\n");
	}
	return 0;
}	


Measured memory_bytes: 3932
#!/usr/bin/env python
# -*- coding: utf-8 -*-

POSITIONS = ["top", "south", "east", "west", "north", "bottom"]


class Dice(object):

    def __init__(self, initial_faces):
        self.faces = {p: initial_faces[i] for i, p in enumerate(POSITIONS)}
        self.store_previous_faces()

    def store_previous_faces(self):
        self.previous_faces = self.faces.copy()

    def change_face(self, after, before):
        self.faces[after] = self.previous_faces[before]

    def change_faces(self, rotation):
        self.change_face(rotation[0], rotation[1])
        self.change_face(rotation[1], rotation[2])
        self.change_face(rotation[2], rotation[3])
        self.change_face(rotation[3], rotation[0])

    def roll(self, direction):
        self.store_previous_faces()
        if direction == "E":
            self.change_faces(["top", "west", "bottom", "east"])
        elif direction == "N":
            self.change_faces(["top", "south", "bottom", "north"])
        elif direction == "S":
            self.change_faces(["top", "north", "bottom", "south"])
        elif direction == "W":
            self.change_faces(["top", "east", "bottom", "west"])

    def rolls(self, directions):
        for d in directions:
            self.roll(d)


def main():
    dice1 = Dice(input().split())  # standard
    dice2 = Dice(input().split())  # to be rolled
    if dice1.faces["south"] == dice2.faces["west"]:
        dice2.roll("E")
    elif dice1.faces["south"] == dice2.faces["east"]:
        dice2.roll("W")
    while dice1.faces["south"] != dice2.faces["south"]:
        dice2.roll("N")
    for n in range(4):
        if (dice1.faces["top"] == dice2.faces["top"] and
                dice1.faces["east"] == dice2.faces["east"]):
            print("Yes")
            break
        else:
            dice2.roll("E")
    else:
        print("No")

if __name__ == "__main__":
    main()

Measured memory_bytes: 7624
local read = io.read
local insert = table.insert

local h, w, m = read("n", "n", "n")
local grid_t = {}
for i = 1, h do
	grid_t[i] = {}
end

local sum_h_t, sum_w_t = {}, {}
for i = 1, m do
	local hs = read("n")
	local ws = read("n")
	grid_t[hs][ws] = true
	sum_h_t[hs] = sum_h_t[hs] and sum_h_t[hs] + 1 or 1
	sum_w_t[ws] = sum_w_t[ws] and sum_w_t[ws] + 1 or 1
end

local max_h, max_w = 0, 0
local max_h_index_t, max_w_index_t = {}, {}
for i = 1, h do
	if sum_h_t[i] and sum_h_t[i] > max_h then
		max_h = sum_h_t[i]
		max_h_index_t = {i}
	elseif sum_h_t[i] and sum_h_t[i] == max_h then
		insert(max_h_index_t, i)
	end
end
for i = 1, w do
	if sum_w_t[i] and sum_w_t[i] > max_w then
		max_w = sum_w_t[i]
		max_w_index_t = {i}
	elseif sum_w_t[i] and sum_w_t[i] == max_w then
		insert(max_w_index_t, i)
	end
end

local is_dup = true
for i = 1, #max_h_index_t do
	for j = 1, #max_w_index_t do
		if grid_t[max_h_index_t[i]][max_w_index_t[j]] == nil then
			is_dup = false
			break
		end
	end
	if not is_dup then
		break
	end
end

print(is_dup and max_h + max_w - 1 or max_h + max_w)


Measured memory_bytes: 76040
import math
def main():

    N = int(input())
    X = input()

    memo = dict()
    memo[0] = 0
    for i in range(1, N+1):
        v = i
        cnt = 0
        while v > 0:
            cnt += v % 2
            v //= 2
        u = i % cnt
        memo[i] = memo[u] + 1

    cnt = 0
    for i in range(N):
        if X[i] == '1': cnt += 1

    if cnt == 1:
        mod_plus = []
        p = (1 % (cnt + 1))
        for i in range(0, N+1):
            mod_plus.append(p)
            p *= 2
            p %= (cnt + 1)

        v_plus = 0
        for i in range(N):
            if X[i] == '1':
                v_plus = mod_plus[N-1-i]
                break

        for i in range(N):
            if X[i] == '1':
                print(0)
            else:
                u_plus = mod_plus[N-1-i]
                v_plus = (v_plus + u_plus) % (cnt + 1)
                print(1 + memo[v_plus])

    else:
        mod_plus = []
        p = (1 % (cnt + 1))
        for i in range(0, N+1):
            mod_plus.append(p)
            p *= 2
            p %= (cnt + 1)

        mod_minus = []
        p = (1 % (cnt - 1))
        for i in range(0, N+1):
            mod_minus.append(p)
            p *= 2
            p %= (cnt - 1)

        v_plus = 0
        v_minus = 0
        for i in range(N):
            if X[i] == '1':
                v_plus += mod_plus[N-1-i]
                v_minus += mod_minus[N-1-i]
                v_plus %= (cnt + 1)
                v_minus += (cnt - 1)

        for i in range(N):
            if X[i] == '1':
                u = mod_minus[N-1-i]
                v = (v_minus - u) % (cnt - 1)
            else:
                div = cnt + 1
                u = mod_plus[N-1-i]
                v = (v_plus + u) % (cnt + 1)
            print(1 + memo[v])


if __name__ == '__main__':
    main()

Measured memory_bytes: 110592
# usr/bin/python
# coding: utf-8
################################################################################
# Digit Number
# Write a program which computes the digit number of sum of two integers a and b.
#
# Input
# There are several test cases. Each test case consists of two non-negative integers a and b which are separeted by a space in a line. The input terminates with EOF.
#
# Constraints
# 0 ??? a, b ??? 1,000,000
# The number of datasets ??? 200
# Output
# Print the number of digits of a + b for each data set.
#
# Sample Input
# 5 7
# 1 99
# 1000 999
# Output for the Sample Input
# 2
# 3
# 4
#
################################################################################

import math
import fileinput

if __name__ == "__main__":
    for line in fileinput.input():
        a = int(line.split(" ")[0])
        b = int(line.split(" ")[1])
        data_size = int(math.log10(a+b) + 1)
        print(data_size)
    exit(0)
  

Measured memory_bytes: 5700
#![allow(non_snake_case)]
use proconio::input;

struct Loop {
    start: usize,
    start_ord: usize,
    period: i64,
}

// ループと最後にいた町のindを返す
fn calc_period(N: usize, K: i64, As: &[i64]) -> (Option<Loop>, usize) {
    let mut loop_start: Option<usize> = None;
    let mut period: Option<i64> = None;

    // テレポートがループする場合があるので、何番目に訪れたかを記録しておく
    // i番目のタウンは何回目の移動で訪れたか
    let mut ord: Vec<Option<usize>> = vec![None; N];
    ord[0] = Some(0);

    // ループを検知する
    let mut town: usize = 0;
    for k in 1..K + 1 {
        let next = As[town] as usize;

        if ord[next].is_some() {
            loop_start = Some(next);
            period = Some((ord[town].unwrap() - ord[next].unwrap() + 1) as i64);
            break;
        } else {
            ord[next] = Some(k as usize);
            town = next;
        }
    }

    // ループ無く終わった場合
    if period == None {
        return (None, town);
    }

    let loop_instance = Loop {
        start: loop_start.unwrap(),
        start_ord: ord[loop_start.unwrap()].unwrap(),
        period: period.unwrap(),
    };

    return (Some(loop_instance), town);
}

fn main() {
    input! {
        N: usize,
        K: i64,
        tmpAs: [i64; N],
    }

    // 問題文では町の番号は1~Nだが、コード中では0~N-1で管理
    let As: Vec<i64> = tmpAs.iter().map(|a| a - 1).collect();

    let tuple = calc_period(N, K, &As);

    if tuple.0.is_none() {
        println!("{}", tuple.1 + 1);
        return;
    }

    let loop_instance = tuple.0.unwrap();

    // periodを知っているので、
    // loop_startまで、できるだけperiod回す、残り
    let start_ord = loop_instance.start_ord;
    let period = loop_instance.period;

    let rest: i64 = (K - start_ord as i64) % period;
    let mut town: usize = loop_instance.start;
    for _k in 0..rest {
        town = As[town] as usize;
    }

    println!("{}", town + 1);
}


Measured memory_bytes: 9520
#include <stdio.h>
int main(void){
	int n,i,x,y,b,p;
	int q,w;
	
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d %d %d",&x,&y,&b,&p);
		
		
		
		q=x*b+y*p;
		if(b<5)b=5;
		if(p<2)p=2;
		w=(x*b+y*p)*0.8;
		
		if(q<w){
			printf("%d\n",q);
		}else{
			printf("%d\n",w);
		}
	}
	return 0;
}

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

int main(int argc, char **argv)
{
	ll N, A, B; cin >> N >> A >> B;

	ll res{0};
	res += N / (A+B) * A;
	ll r = N % (A+B);
	res += min(r, A);
	std::cout << res << std::endl;
}

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

int main () {
  int N;
  std::cin >> N;
  std::vector<int> data(3*N);
  for (int i=0; i<3*N; i++) {
    std::cin >> data.at(i);
  }
  std::sort(data.rbegin(), data.rend());
  long long int sum = 0;
  for (int i=1; i<2*N+1; i+=2) {
    sum += data.at(i);
  }
  std::cout << sum << std::endl;
}

Measured memory_bytes: 1408
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(),b = sc.nextInt(),c = sc.nextInt(),n = 0;
		for (int d = a;d <= b;d++){
			if(c%d == 0){n++;}
		}
		System.out.println(n);}
}

Measured memory_bytes: 17360
s = int(input())
s = input().rstrip().split(' ')

result = 0


def half(num):
    count = 0
    while ((num % 2) == 0) :
        num = num / 2
        count += 1
    return count


for num in s:
    num = int(num)
    count = half(num)
    if not result:
        result = count

    if count == 0:
        result = 0
        break

    if count < result:
        result = count

print(result)



Measured memory_bytes: 8972
#pragma region header
#include <bits/stdc++.h>
using namespace std;

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;
#pragma endregion

#pragma region const
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#pragma endregion

#pragma region util
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}
#pragma endregion

#pragma region init
struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

int main()
{
	i64 N;
	cin >> N;
	vector<i64> V(N);
	for (auto& v : V)
	{
		cin >> v;
	}
	vector<i64> C(N);
	for (auto& v : C)
	{
		cin >> v;
	}

	i64 ans = 0;
	REP(i, N)
	{
		if (V[i] > C[i])
			ans += V[i] - C[i];
	}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
const int A = 2e5 + 2;
const int mod = 1e9 + 7;

int main() {
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int n, m;
    cin >> n >> m;
    int a[n];
    memset(a, -1, sizeof a);
    bool valid = 1;
    while(m--) {
        int x, y;
        cin >> x >> y, x--;
        if (~a[x] && a[x] != y)
            valid = 0;
        a[x] = y;
    }
    if (n > 1) {
        if (a[0] == 0)
            valid = 0;
        else {
            if (a[0] == -1)
                a[0] = 1;
            for (int i = 1; i < n; i++)
                 if (a[i] == -1)
                    a[i] = 0;
        }
    }
    else {
        if (a[0] == -1) a[0] = 0;
    }
    if (!valid) cout << -1;
    else {
        for (int i = 0; i < n; i++)
            cout << a[i];
    }
    return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define LL_MAX LLONG_MAX
#define ULL_MAX ULLONG_MAX
#define ull unsigned long long
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define pb(x) push_back(x)
#define eb(x) emplace_back(x)
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
#define sort(a) sort(a.begin(),a.end())
#define pii pair<int,int>
#define sz(x) int(x.size())
#define mk make_pair
#define endl '\n'

int main()
{
    IOS;
    int n,k;
    cin>>n>>k;
    vector<int> a(n);

    for (int i = 0; i < n; i++)
    {
        cin>>a[i];
    }
    sort(a);
    int sum=0;
    for (int i = 0; i < k; i++)
    {
        sum+=a[i];
    }
    cout<<sum;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

// ABC105 A - AtCoder Crackers

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, K; cin >> N >> K;
  if(N%K == 0){
    cout << 0 << endl;
  }else{
    cout << 1 << endl;
  }
}

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

int main()
{
    long long a,b,c,n;
    long long a2,b2,c2;
    cin >> a >> b >> c >> n;
    
    int an=0,abn=1;
    /*if(n==0)
    {
        an=1;
    }
    else{
        for(int i=2;i<=n;i++){
            int temp=an;
            an=an+2*abn;
            abn=temp;
        }
    }*/

    int ann;
    if((n%2)==0){
        ann=a-b;
    }
    else{
        ann=b-a;
    }

    if(ann>pow(10,18)){
        cout << "Unfair";
        return 0;
    }

    cout << ann;


    return 0;
}

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

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

    long long ans = 0;
    for (int i = 1; i < N; i++) {
        ans += min(A * (X[i] - X[i - 1]), B);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
// Aizu 2831: Check answers
// 2017.9.21 bal4u@uu

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

char buf[100010];

int main()
{
	int n;
	char *p;

	fgets(buf, 100, stdin); n = atoi(buf);
	if (n > 1) {
		fgets(buf, 100005, stdin); p = buf + 1, n = 1;
		while (*p >= ' ') {
			if (*(p-1) == 'x' && *p == 'x') break;
			p++, n++;
		}
	}
	printf("%d\n", n);
	return 0;
}

Measured memory_bytes: 1848
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#define lp(n) for (int i = 0; i < n; i++)
#define lop(n,i) for (int i = 0; i < n; i++)
#define INT_MAX 2147483647
#define LLINT_MAX 9223372036854775807
#define mod 1000000007
#define ll long long int
using namespace std;

int n;
ll k;
ll cnt;
int a,b;
ll bkt[100010];
int main(){
	cin >> n >> k;
	lp(100010)
		bkt[i] = 0;
	lp(n) {
		cin >> a >> b;
		bkt[a - 1] += b;
	}
	cnt = 0;
	lp(100010) {
		cnt += bkt[i];
		if (cnt >= k) {
			cout << (i+1) << endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 1024
#C
import sys
L, R = list(map(int, input().split()))
if (R - L) == 2019:
    result = 0
else:
    result = 2018
    for i in range(L,R+1):
        for s in range(i+1,R+1):
            x = (i*s)%2019
            if x == 0:
                result = 0
                print(0)
                sys.exit()
            elif result > x:
                result = x
print(result)

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
long long a[10]={0},del[10]={0};
int main(void)
{
    int i,j,pos,minn;
    long long n,ans=0;
    for(i=1;i<=4;++i)scanf("%lld",&a[i]);
    a[1]*=8;a[2]*=4;a[3]*=2;
    scanf("%lld",&n);
    for(i=1;i<=4;++i)
    {
        minn=0x3FFFFFFF;
        for(j=1;j<=4;++j)if(a[j]<minn&&!del[j])minn=a[j],pos=j;
        del[pos]=true;
        switch(pos)
        {
        case 1:
            printf("%lld\n",ans+n*a[1]/2);
            return 0;
        case 2:
            printf("%lld\n",ans+n*a[2]/2);
            return 0;
        case 3:
            printf("%lld\n",ans+n*a[3]/2);
            return 0;
        case 4:
            if(n%2==0){printf("%lld",ans+n*a[4]/2);return 0;}
            ans+=(n/2)*a[4];
            n=1;break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
for i in range(n-m+1):
    for j in range(n-m+1):
        comp = True
        for k in range(m):
            for l in range(m):
                if a[i+k][j+l] != b[k][l]:
                    comp = False
        if comp:
            print("Yes")
            exit(0)
print("No")

Measured memory_bytes: 3060
import math
a = int(input())
# a = 123456789

if a == 0:
    print('0')
    exit(0)

used = []
i = 0
while a != 0:
    if a % 2 == 1:
        used.append(True)
        if i % 2 == 0:
            a -= 1
        else:
            a += 1
    else:
        used.append(False)
    a = a // 2
    i += 1

# print(used)
ans = ''
for elem in reversed(used):
    if elem:
        ans += '1'
    else:
        ans += '0'

print(ans)


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

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

    vector<long long int> a(q), b(q), c(q);
    for(int i=0; i<q; i++){
        cin >> a[i] >> b[i];
        c[i] = sqrt(a[i] * b[i]);
    }
    for(int i=0; i<q; i++){
        long long int ans;

        // Suppose a <= b (without loss of generality).

        // case (1)
        if(c[i] * c[i] < a[i] * b[i]){

            // Best possible pairs = (1, *), ..., (a-1, *), (a+1, *), ..., (c, *), ..., (*, 1).
            // (note : (a, *) is absent since (a, b) is already occupied by Takahashi-kun)

            // There are (essentially) two possibilities for the middle pair (c, *) :
            // 1. (c, c)   -> the last pair is (2c-1, 1) and therefore ans = 2c-2
            // 2. (c, c+1) -> the last pair is (2c  , 1) and therefore ans = 2c-1

            ans = 2 * c[i] - 2;
            if(c[i] * (c[i] + 1) < a[i] * b[i]) ans += 1;
        }

        // case (2)
        if(c[i] * c[i] == a[i] * b[i]){

            // (c, c) must be excluded : (1, *), ..., (a-1, *), (a+1, *), ..., (c-1, c+1), (c+1, c-1), ..., (*, 1)
            // as can be seen, be careful when a = c (= b)

            ans = 2 * c[i] - 3;
            if(c[i] == a[i]) ans += 1;
        }

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

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

using namespace std;

int FindLeast( int needs, int pieces, int val ) {
    int k = 1;
    while ( k*pieces < needs ) ++k;
    return k*val;
}
main() {
    int n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    cout << min( FindLeast( n, a, b ), FindLeast( n, c, d ) ) << endl;
}



Measured memory_bytes: 3104
#include <iostream>
#include <vector>
#include <string>

using namespace std;
int main(void){
    string str;
    char c[3];
    std::cin >> str;
    str.copy(c, 3);
    int r = 700;
    for(auto d : c){
        if(d == 'o') {
            r = r + 100;
        }
    }
    std::cout << r << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(q, l, r) for (int q = l; q <= r; q++)
#define mid (l + r) / 2
#define pl (i << 1)
#define pr (i << 1 | 1)
#define pb push_back
#define mk make_pair
typedef long long ll;
typedef pair<int, int> pi;
const int maxn = 100;
const int INF = 1e9 + 7;
const ll mod = 1e9 + 7;
const ll LINF = 1e14;
int n,a[maxn],b[maxn],c[maxn];

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

    for (int q=1;q<=n;q++)
        scanf("%d",&a[q]);
    for (int q=1;q<=n;q++)
        scanf("%d",&b[q]);
    for (int q=1;q<n;q++)
        scanf("%d",&c[q]);
    
    ll s=0;
    s+=b[a[1]];
    for (int q=2;q<=n;q++)
    {
        s+=b[a[q]];
        if (a[q-1]+1==a[q]) s+=c[a[q-1]];
    }

    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 256
/* winners never quit and quitters never win.
      #swap                                 */
      
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;
#pragma GCC optimize ("-O3")
using ll = long long;
using ld = long double;
const ll mod = 1000000007;
const ll inf = 1000000000000000000;
const ll rk = 256;
const ld PI = 3.141592653589793;

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

template <typename T>
void make_unique(vector<T>& vec) {
  sort(all(vec));
  vec.erase(unique(all(vec)), vec.end());
}

#define endl '\n'
#define pb push_back
#define mp make_pair
#define vc vector
#define fs first
#define sec second
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define pll pair<ll,ll> 
#define pls pair<ll,string>
#define psl pair<string,ll>
#define plc pair<ll,char>
#define pcl pair<char,ll>
#define pss pair<string,string>
#define all(x) (x).begin(), (x).end()
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define T ll t=0;cin>>t;for(ll test=0;test<t;test++)


ll nxt() {
    ll TemporaryVariable;
    cin >> TemporaryVariable;
    return TemporaryVariable;
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

 
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
	//isprime();
	//coeff();
	/*freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);*/
    ll h1=nxt(),m1=nxt(),h2=nxt(),m2=nxt(),k=nxt();
    ll tim=(h2-h1)*60;
    if(m2>=m1)
        tim+=(m2-m1);
    else
    {
        tim-=60;
        tim+=(60-m1);
        tim+=m2;
    }
    cout<<max(0*1LL,tim-k)<<endl;
	printclock;
	return 0;
}

Measured memory_bytes: 3804
#include <iomanip>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  string S;
  cin >> S;

  if (N % 2) {
    cout << "No" << endl;
  } else {
    for (int i = 0; i < N / 2; i++) {
      if (S[i] != S[i + N / 2]) {
        cout << "No" << endl;
        return 0;
      }
    }
    cout << "Yes" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
 
using namespace std;
 
int gcd (long long int a, long long int b) {
	if (b == 0)
		return a;
	else
		return gcd (b, a % b);
}
 
long long int lcd(long long int a, long long int b) {
    return (a * b) / gcd(a, b);
}
 
long long int fact(long long int N) {
    long long int result = 1;
    while(N > 0) {
        result = result * N % MOD;
        N--;
    }
    return result;
}
 
long long int cnk(long long int n, long long int k) {
    return fact(n) / (fact(k) * fact(n - k));
}
 
long long int binpow(long long int a, long long int n) {
    long long int result = 1;
    while(n != 0) {
        if(n % 2 == 1) {
            result = result * a % MOD;
        }
        a = a * a % MOD;
        n /= 2;
    }
    return result;
}
 
long long int powermod(long long int base, long long int power) {
    if (power == 0) {
        return 1;
    }
    else {
        long long int cur = powermod(base, power / 2);
        cur = cur * cur;
        cur = cur % MOD;
        if (power % 2 == 1)
            cur = cur * base;
        cur = cur % MOD;
        return cur;
    }
}
 
int main()
{
    ios::sync_with_stdio(false);
	cin.tie(nullptr);
 
    int a, b;
    cin >> a >> b;
    if(a > 0 && a < 10 && b > 0 && b < 10) {
        cout << a*b;
    }
    else {
        cout << -1;
    }
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
using namespace std;
#define N 1000007
#define Np 80000
typedef unsigned long long int ull;
ull tot;
ull prime[Np], check[N], ya[Np], yb[N];

void makepl() {
    
    ull i, j;
    for (i = 2; i < N; i++) {
        if (!check[i]) {
            prime[tot++] = i;
        }
        for (j = 0; j < tot; j++) {
            if (i * prime[j] > N) {
                break;
            }
            check[i * prime[j]] = 1;
            if (i % prime[j] == 0) {
                break;
            }
        }
    }
    
}

int main(int argc, const char * argv[]) {
    
    makepl();
    ull a, b, cnt = 0;
    cin >> a >> b;
    int i, ta = 0;
    for (i = 0; i < tot; i++) {
        if (a % prime[i] == 0)
            ya[ta++] = prime[i];
        while (a % prime[i] == 0)
            a /= prime[i];
        if (b % prime[i] == 0)
        yb[prime[i]] = 1;
        while (b % prime[i] == 0)
            b /= prime[i];
    }
    for (i = 0; i < ta; i++) {
        if (yb[ya[i]])
            cnt++;
    }
    if (a == b && a != 1) {
        cnt++;
    }
    cout << cnt + 1;
    return 0;
}

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

int main() {
    int A, B, M;
    cin >> A >> B >> M;

    vector <int> reizouko(A);
    vector <int> denshirenji(B);
    int re_min;
    cin >> re_min;
    reizouko[0] = re_min;
    for(int i = 1; i < A; i++){
        int tmp;
        cin >> tmp;
        reizouko[i] = tmp;
        re_min = min(re_min, tmp);
    }
    int de_min;
    cin >> de_min;
    denshirenji[0] = de_min;
    for(int i = 1; i < B; i++){
        int tmp;
        cin >> tmp;
        denshirenji[i] = tmp;
        de_min = min(de_min, tmp);
    }

    int ans = re_min + de_min;
    for(int i = 0; i < M; i++){
        int x, y, c;
        cin >> x >> y >> c;
        int tmp = reizouko[x-1] + denshirenji[y-1] - c;
        ans = min(ans, tmp);
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
S = input()

ans1, ans2 = 0, 0
for i in range(len(S)):
    if i & 1:
        if S[i] == '0':
            ans1 += 1
        else:
            ans2 += 1
    else:
        if S[i] == '1':
            ans1 += 1
        else:
            ans2 += 1

print(min(ans1, ans2))



Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

struct segTreeRangeFreq {
    int n;
    vector<vector<ll>> dat;
    // 初期化 O(NlogN)
    segTreeRangeFreq() {}
    segTreeRangeFreq(vector<vector<ll>> v) {
        n = 1; while(n < (ll)v.size()) n *= 2;
        dat.resize(2*n-1);
        REP(i, v.size()) dat[i+n-1] = v[i];
        for(int i=n-2; i>=0; --i) {
            dat[i].resize(dat[i*2+1].size() + dat[i*2+2].size());
            merge(ALL(dat[i*2+1]), ALL(dat[i*2+2]), dat[i].begin());
        }
    }
    // [a, b) のx以下の個数を返す O(log^2N)
    int query(int a, int b, ll x, int k, int l, int r) {
        if(b <= l || r <= a) return 0;
        if(a <= l && r <= b) return upper_bound(ALL(dat[k]), x) - dat[k].begin();
        int vl = query(a, b, x, k*2+1, l, (l+r)/2);
        int vr = query(a, b, x, k*2+2, (l+r)/2, r);
        return vl + vr;
    }
    int query(int a, int b, ll x) { return query(a, b, x, 0, 0, n); }
};

int main(void) {
    ll n, m;
    cin >> n >> m;
    vector<PII> p(n);
    REP(i, n) cin >> p[i].first >> p[i].second;
    sort(ALL(p));
    vector<ll> l(n), r(n);
    REP(i, n) l[i] = p[i].first, r[i] = p[i].second;

    vector<vector<ll>> v(n);
    REP(i, n) v[i] = {r[i]};
    segTreeRangeFreq seg(v);

    FOR(d, 1, m+1) {
        ll ret = 0, prev = 0;
        for(ll i=d; i<=m; i+=d) {
            // [prev, itr) で右端がi以上のもの
            ll itr = upper_bound(ALL(l), i) - l.begin();
            ret += itr-prev - seg.query(prev, itr, i-1);
            prev = itr;
        }
        cout << ret << endl;
    }

    return 0;
}

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

int main(){
  int N;
  cin >> N;
  string W[N];
  for(int i =0; i<N; i++){
  cin >> W[i]; 
  }
  
string flag1="Yes";
  
for(int i =0; i<N-1; i++){
    
 if( W[i].back() != W[i+1].front() ){
    flag1 = "No" ;
    break;
  }
}

for(int i =0; i<N; i++){
for(int j =i+1; j<N; j++){
 if(W[i]==W[j]){
   flag1 ="No";
   break;
 }
}
}
 
cout << flag1 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    int b[n];
    for(int i=0;i<n-1;i++)
        cin>>b[i];
    a[0]=b[0];
    b[n-1]=12345678;
    for(int i=1;i<n;i++)
        a[i]=min(b[i],b[i-1]);
    int s=0;
    for(int i=0;i<n;i++)
        {s+=a[i];
//        cout<<a[i]<<" ";
        }
        cout<<s;
}


Measured memory_bytes: 256
(defmacro defsolver (name vars &body body)
  `(defun ,name ()
     (let (,@(mapcar #'list
            vars
            (mapcar (constantly '(read))
                vars)))
       ,@body)))

(defsolver solution-b (a b c)
  (do
   ((x c (- (* a x) b))
    (i 0 (1+ i)))
   ((= i 11) 0)
    (if (> x c)
	(format t "~a~%" x))))

(solution-b)

Measured memory_bytes: 13284
num = 0

def solve(cl, cr):
    P = []
    for i in range(cl, cr+1):
        for j in range(1, W+1):
            if S[i][j] == "#":
                P.append(j)
    P.sort()

    for i in range(len(P)):
        v1, v2 = 1, W
        if i >= 1:
            v1 = P[i-1] + 1
        if i < len(P) - 1:
            v2 = P[i]

        global num
        num += 1
        for j in range(cl, cr+1):
            for k in range(v1, v2+1):
                A[j][k] = num


H, W, K = map(int, input().split())
A = [[0 for _ in range(303)] for _ in range(303)]
S = [[" " for _ in range(303)] for _ in range(303)]
cnt = [0] * 303
for i in range(1, H+1):
    row = input()
    for j, c in enumerate(row, 1):
        if c == "#":
            cnt[i] += 1
        S[i][j] = c

vec = []
for i in range(1, H+1):
    if cnt[i] >= 1:
        vec.append(i)
for i in range(len(vec)):
    v1, v2 = 1, H
    if i >= 1:
        v1 = vec[i-1] + 1
    if i < len(vec) - 1:
        v2 = vec[i]

    solve(v1, v2)

for i in range(1, H+1):
    tmp = []
    for j in range(1, W+1):
        tmp.append(str(A[i][j]))
    print(" ".join(tmp))


Measured memory_bytes: 7964