akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;

class Main {

    public static void main(String[] args) {

	final Scanner stdin = new Scanner(System.in);

	while ( true ) {

	    final int m = stdin.nextInt();
	    final int n = stdin.nextInt();

	    if ( n == 0 && m == 0 ) {
		break;
	    }	    

	    int[] ws = new int[n];
	    for ( int i = 0; i < n; i++ ) {
		ws[i] = stdin.nextInt();
	    }

	    int right = 1500000;
	    int left = 0;
	    for ( int i = 0; i < 100; i++ ) {
		final int middle = ( right + left ) / 2;
		if ( canPut( ws, middle, m ) ) {
		    right = middle;
		} else {
		    left = middle;
		}
	    }
	    System.out.println( right );
	}	
    }

    static int sum( int[] ar ) {
	int sum = 0;
	for ( int a : ar ) {
	    sum += a;
	}
	return sum;
    }

    static int min( int[] ar ) {
	int min = Integer.MAX_VALUE;
	for ( int a : ar ) {
	    min = Math.min( min, a );
	}
	return min;
    }

    static boolean canPut( int[] ws, int maxWidth, int m ) {
	int count = 1;
	int wSum = 0;
	for ( int w : ws ) {
	    if ( w > maxWidth ) {
		return false;
	    }
	    if ( wSum + w <= maxWidth ) {
		wSum += w;
	    } else {
		count++;
		wSum = w;
	    }
	}
	return count <= m;
    }    
}

Measured memory_bytes: 21160
#include <iostream>
using namespace std;
int main(){
  int n;
  cin>>n;
  //1,2,4,8,16,32,64
  if(n>=64) cout<<"64"<<endl;
  else if(n<64&&n>=32) cout<<"32"<<endl;
  else if(n<32&&n>=16) cout<<"16"<<endl;
  else if(n<16&&n>=8) cout<<"8"<<endl;
  else if(n<8&&n>=4) cout<<"4"<<endl;
  else if(n==1) cout<<"1"<<endl;
  else cout<<"2"<<endl;
  
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main(void){
   int x,y,i,j;
   for(;;){
      scanf("%d %d",&y,&x);
      if(x+y==0) break;
      for(i=0;i<y;i++){
         for(j=0;j<x;j++)
            if(i*j==0 || i+1==y || j+1==x)
               printf("#");
            else
               printf(".");
         printf("\n");
      }
   printf("\n");
   }
   return 0;
}


Measured memory_bytes: 2044
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)

	var ans int
	fmt.Scan(&ans)

	for i := 1; i < n; i++ {
		var a int
		fmt.Scan(&a)
		ans = gcd(ans, a)
	}

	fmt.Println(ans)
}

func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	r := a % b
	for r != 0 {
		a = b
		b = r
		r = a % b
	}
	return b
}


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

using namespace std;

const int C_SIZE = 1000;
const int D_SIZE = 2002;

/*struct bigraph{
	int size; //頂点数
	int edge[C_SIZE][C_SIZE]; //辺の情報
};*/

/*bigraph bg_new(int n){
	bigraph G;
	G.size=n;
	for(int i=0; i<n; i++) for(int j=0; j<n; j++) G.edge[i][j]=0;
	return G;
}*/

/*bigraph max_matching(bigraph G){
	int n=G.size;
	int m=2*n+1;
	int edge[2*(C_SIZE+1)][2*(C_SIZE+1)]={};
	for(int i=1; i<=n; i++)
	{
		edge[0][i]=1;
		for(int j=0; j<n; j++)
		{
			if(G.edge[i-1][j]!=0) edge[i][(n+1)+j]=1;
		}
	}
	for(int i=n+1; i<m; i++) edge[i][m]=1;
	while(1)
	{
		stack<int> s;
		int parent[2*(C_SIZE+1)];
		bool done[2*(C_SIZE+1)]={};
		done[0]=true;
		s.push(0);
		while(!s.empty())
		{
			int v=s.top();
			s.pop();
			bool bre=false;
			for(int u=0; u<m; u++)
			{
				if(edge[v][u]==1)
				{
					if(!done[u])
					{
						parent[u]=v;
						if(u==m) bre=true;
						done[u]=true;
						s.push(u);
					}
				}
			}
			if(bre) break;
		}
		if(!done[m]) break;
		int tmp=m;
		while(tmp!=0)
		{
			edge[parent[tmp]][tmp]*=(-1);
			tmp=parent[tmp];
		}
	}
	for(int i=0; i<n; i++)for(int j=0; j<n; j++)
	{
		G.edge[i][j]=(-1)*edge[i+1][n+1+j];
	}
	return G;
}*/

int edge[D_SIZE][D_SIZE];

int main()
{
	int n, k, a, b;
	int x, y;
	cin >> x >> y;
	n=max(x, y);
	cin >> k;
	int Gedge[C_SIZE][C_SIZE]={};
	for(int i=0; i<k; i++)
	{
		cin >> a >> b;
		Gedge[a][b]=1;
	}
	int m=2*n+1;
	for(int i=1; i<=n; i++)
	{
		edge[0][i]=1;
		for(int j=0; j<n; j++)
		{
			if(Gedge[i-1][j]!=0) edge[i][(n+1)+j]=1;
		}
	}
	for(int i=n+1; i<m; i++) edge[i][m]=1;
	while(1)
	{
		stack<int> s;
		int parent[D_SIZE];
		bool done[D_SIZE]={};
		done[0]=true;
		s.push(0);
		while(!s.empty())
		{
			int v=s.top();
			s.pop();
			bool bre=false;
			for(int u=0; u<=m; u++)
			{
				if(edge[v][u]==1)
				{
					if(!done[u])
					{
						parent[u]=v;
						if(u==m) bre=true;
						done[u]=true;
						s.push(u);
					}
				}
			}
			if(bre) break;
		}
		if(!done[m]) break;
		int tmp=m;
		while(tmp!=0)
		{
			edge[parent[tmp]][tmp]=0;
			edge[tmp][parent[tmp]]=1;
			tmp=parent[tmp];
		}
	}
	for(int i=0; i<n; i++)for(int j=0; j<n; j++)
	{
		Gedge[i][j]=edge[n+1+j][i+1]-edge[i+1][n+1+j];
	}
	int ans=0;
	for(int i=0; i<n; i++)for(int j=0; j<n; j++)
	{
		if(Gedge[i][j]==1) ans++;
	}
	cout << ans << endl;
	/*
	for(int i=0; i<n; i++)for(int j=0; j<n; j++)
	{
		if(Gedge[i][j]==1) cout << i+1 << ' ' << j+1 << endl;
	}
	*/
	return 0;
}


Measured memory_bytes: 7960
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll ,P> P3;
typedef pair<P ,P> PP;
const ll MOD = ll(1e9+7);
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-6;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()



int main() {
    int cnt  = 0, ans = 0;
    string s;
    cin >> s;
    for(auto &c : s){
        if(c == 'A' || c == 'T' || c == 'C' || c == 'G')cnt++;
        else cnt = 0;
        ans = max(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
   
#include <x86intrin.h>
#include <bits/stdc++.h>   
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;

template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
     
#define F first
#define S second           
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair                                     
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define al 0x3F3F3F3F
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;
const int N = (int)1e4 + 123;
const ll inf = (ll)1e18 + 1;

const double pi = acos (-1.0);
const double eps = 1e-7;                  
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

string k;
int a[N], n, d, dp[2][N][100];

inline int add (int a, int b) {
   a += b;
   if (a >= mod) a -= mod;
   if (a < 0) a += mod;
   return a;
}

int calc (bool sp = 1, int pos = 0, int D = 0) {
   if (pos == n) return (D == 0);
   int &res = dp[sp][pos][D];
   if (res != -1) return res;
   res = 0;
   int r = (sp ? a[pos] : 9);
   for (int i = 0; i <= r; i ++) 
      res = add (res, calc ((sp & (i == a[pos])), pos + 1, (D + i) % d));
   return res;
}

inline void boost () {                    
   ios_base :: sync_with_stdio (NULL);
   cin.tie (NULL), cout.tie (NULL);          
}                                                     

inline void Solve () {
   cin >> k >> d;
   n = sz (k);
   for (int i = 0; i < sz (k); i ++) a[i] = k[i] - '0';
   memset (dp, -1, sizeof dp);
   cout << add (calc (), -1);
}

main () {                                       
// freopen (".in", "r", stdin);    
// freopen (".out", "w", stdout);              
   boost ();
   int tt = 1;
   //cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}
                          

Measured memory_bytes: 9088
N=int(input())
A=[int(x) for x in input().split()]
B=[int(x) for x in input().split()]
C=[int(x) for x in input().split()]

score=0
flag=21#INF
for i in range(N):
    score+=B[A[i]-1]
    if A[i]==flag+1:
        score+=C[A[i-1]-1]
    flag=A[i]
print(score)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll MOD=10000000;
const ll INF=1000000001;
const ll LINF=4000000000000000010;
const double EPS=1e-9;
int main(){
    int h,w;cin>>h>>w;
    char a[510][510],b[510][510],c[510][510];
    for(int i=0;i<h;i++){
        cin>>a[i];
    }
    for(int i=0;i<h;i++){
        bool f=false;
        if(i%2)f=true;
        for(int j=0;j<w-1;j++){
            if(f){
                b[i][j]=a[i][j];
            }else{
                b[i][j]='#';
            }
        }
        b[i][w-1]='.';
        if(f){
            b[i][0]='#';
        }
    }
    for(int i=0;i<h;i++){
        bool f=false;
        if(i%2==0)f=true;
        for(int j=1;j<w;j++){
            if(f){
                c[i][j]=a[i][j];
            }else{
                c[i][j]='#';
            }
        }
        c[i][0]='.';
        if(f){
            c[i][w-1]='#';
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cout<<b[i][j];
        }
        cout<<endl;
    }
    cout<<endl;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cout<<c[i][j];
        }
        cout<<endl;
    }
}


Measured memory_bytes: 1536
import std.stdio, std.string, std.algorithm, std.array, std.range, std.conv,
    std.typecons, std.math, std.container, std.format, std.numeric;

class UnionFind
{
private:
    long[] xs;
public:
    this(ulong size)
    {
        xs = new long[](size);
        fill(xs, -1);
    }

    long find(long i)
    {
        if (xs[i] == -1)
        {
            return i;
        }
        return find(xs[i]);
    }

    void unite(long x, long y)
    {
        x = find(x);
        y = find(y);
        if (x == y)
        {
            return;
        }
        xs[x] = y;
    }

}

void main(string[] args)
{

    long n, q, com, x, y;

    readf("%d %d\n", &n, &q);
    auto uf = new UnionFind(n);

    foreach (_; 0 .. q)
    {
        readf("%d %d %d\n", &com, &x, &y);
        if (com == 0)
        {
            uf.unite(x, y);
        }
        if (com == 1)
        {
            if (uf.find(x) == uf.find(y))
            {
                writeln("1");
            }
            else
            {
                writeln("0");
            }
        }
    }
}



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

int main()
{
  	string s;
    int n, ans;
    cin >> n >> s;
  	for(int i=0; i<=n-3; i++)
    {
      if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C')ans++;
    }
  	cout << ans << endl;
}

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

const int N = 100010;

class Node {
public:
	bool is_terminal;
	int cnt;
	Node *son[26];

	Node() {
		is_terminal = false;
		cnt = 0;
		for (int i = 0; i < 26; i++)
			son[i] = nullptr;
	}
};

class Trie {
public:
	Node *root;

	Trie() {
		root = new Node();
	}

	void insert(string &s) {
		Node *cur = root;
		for (char c: s) {
			int num = c - 'a';
			if (!cur->son[num]) 
				cur->son[num] = new Node();
			cur = cur->son[num];
			cur->cnt++;
		}
		cur->is_terminal = true;
	}
};


int n, q, calc[N][26][26], pref[N];
string s[N];

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> n;
	Trie *trie = new Trie();
	for (int i = 1; i <= n; i++) {
		cin >> s[i];
		trie->insert(s[i]);
	}
	for (int i = 1; i <= n; i++) {
		Node *cur = trie->root;
		for (char c: s[i]) {
			int num = c - 'a';
			for (int j = 0; j < 26; j++) 
				if (j != num && cur->son[j]) 
					calc[i][num][j] += cur->son[j]->cnt;
			cur = cur->son[num];
			if (cur->is_terminal) pref[i]++;
		}
	}
	cin >> q;
	while (q--) {
		int k, ans = 0;
		string alpha;
		cin >> k >> alpha;
		vector<int> order(26);
		for (int i = 0; i < 26; i++)
			order[alpha[i] - 'a'] = i;
		for (int i = 0; i < 26; i++)
			for (int j = 0; j < 26; j++) 
				if (order[i] > order[j])
					ans += calc[k][i][j];
		cout << ans + pref[k] << '\n';
	}
}


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

int main() {
    int N;
    string S, T;
    cin >> N;
    cin >> S >> T;

    string ans = "";
    for(int i=0; i<N; i++) {
        ans += S[i];
        ans += T[i];
    }

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

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

using namespace std;

using ll = long long;

const int N = 1e5 + 10;

int a[N], mem[N], n;

int dp(int i)
{
    if (i > n - 1)
        return 2e9;

    if (i == n - 1)
        return 0;

    if (mem[i] != -1)
        return mem[i];

    int ans = 2e9;

    for (int j = 1; j <= 2; j++)
    {
        ans = min(ans, abs(a[i] - a[i + j]) + dp(i + j));
    }

    return mem[i] = ans;
}

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

    for (int i = 0; i < n; i++)
        scanf("%d", &a[i]);

    memset(mem, -1, sizeof(mem));

    printf("%d", dp(0));
}

Measured memory_bytes: 4096
n = int(input())
h = list(map(int,input().split()))
if n<2:
  print(0)
else:
  mvmn = 0
  maxmvm = 0
  for i in range(1,n):
    if h[i]>h[i-1]:
      mvmn = 0
    else:
      mvmn += 1
      maxmvm = max(maxmvm,mvmn)
  print(maxmvm)

Measured memory_bytes: 14224
#include <iostream>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	int zong;
	cin>>zong;
	int cnt=0;
	for(int i=0;i<=a;i++)
		for(int j=0;j<=b;j++)
			for(int k=0;k<=c;k++)
				if(i*500+j*100+k*50==zong)cnt++;
		cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 256
from collections import deque
#ワープなしで進んだ後にワープを行う
def main():
    H, W = map(int, input().split())
    ch, cw = map(int, input().split())
    dh, dw = map(int, input().split())
    # ######
    # ######
    # ##in##
    # ######
    # ######
    s = ["#"*(W+4)]
    s.append("#"*(W+4))
    for i in range(H):
        s.append("##"+input()+"##")
    s.append("#"*(W+4))
    s.append("#"*(W+4))

    ans = [[-1]*(W+4) for _ in range(H+4)]
    for i in range(H+4):
        for j in range(W+4):
            if s[i][j] == "#":
                ans[i][j] = -2
    ch += 1
    cw += 1
    dh += 1
    dw += 1
    ans[ch][cw] = 0
    # 移動変位
    move = [[-1, 0], [1, 0], [0, -1], [0, 1]]
    magic = [[-2, -2], [-2, -1], [-2, 0], [-2, 1], [-2, 2], [-1, -2], [-1, -1], [-1, 1], [-1, 2],
             [0, -2], [0, 2], [1, -2], [1, -1], [1, 1], [1, 2], [2, -2], [2, -1], [2, 0], [2, 1], [2, 2]]
    # 位置
    mylist = deque([[ch, cw]])
    mylist2 = deque([])
    while len(mylist) > 0:
        x, y = mylist.popleft()
        mylist2.append([x, y])
        for p, q in move:
            v1, v2 = x+p, y+q
            # 移動可能
            if ans[v1][v2] == -1:
                mylist.append([v1, v2])
                ans[v1][v2] = ans[x][y]
        # 動けなくなった場合
        if len(mylist) == 0:
            # 
            while len(mylist2) > 0:
                x2, y2 = mylist2.popleft()
                for v1, v2 in magic:
                    i, j = x2+v1, y2+v2
                    if ans[i][j] == -1:
                        ans[i][j] = ans[x2][y2]+1
                        mylist.append([i, j])
    print(ans[dh][dw])
if __name__ == "__main__":
    main()

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

int main() {
  int H,N;
  cin>>H>>N;
  vector<int>A(N);
  for(int i=0;i<N;i++) cin>>A[i];
  int attack=0;
  for(int i=0;i<N;i++) attack+=A[i];
  if(attack<H) cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
}


Measured memory_bytes: 640
n, k = map(int, input().split())
v = list(map(int, input().split()))
ret = 0
for s in range(n):
    for e in range(s, n + 1):
        t = k - (s + n - e)
        if t < 0:
            continue
        l = sorted(v[:s] + v[e:])
        u = 0
        while u < len(l) and u < t and l[u] < 0:
            u += 1
        ret = max(ret, sum(l[u:]))
print(ret)

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

using namespace std;

void solve()
{
    int n, m;
    cin >> n >> m;
    vector<long> keys(m), dp(1 << n, 1e15);
    dp[0] = 0;
    for (int i = 0; i < m; i++)
    {
        int b;
        cin >> keys[i] >> b;
        int mask = 0;
        while (b--)
        {
            int c;
            cin >> c;
            mask |= 1 << (c - 1);
        }
        vector<long> nx(dp);
        for (int s = 0; s < (1 << n); s++)
        {
            nx[s | mask] = min(dp[s] + keys[i], nx[s | mask]);
        }
        swap(dp, nx);
    }
    cout << (dp.back() == 1e15 ? -1 : dp.back()) << endl;
}

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


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

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
 
#define PRINT(str) printf(#str "\n")
#define yOUT PRINT(Yes)
#define nOUT PRINT(No)
#define YOUT PRINT(YES)
#define NOUT PRINT(NO)
 
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()


using namespace std;
 
int main(void)
{   
    string s,t;
    cin >> s >> t;
    
    sort(all(s));
    sort(all(t),greater<int>());

    if(s < t) yOUT;
    else nOUT;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

vector<ll> node[10004];
ll score[10004];
vector<ll> c;

void dfs(ll id){
    if(score[id] != 0) return;
    score[id] = c.back();
    c.pop_back();

    fore(x, node[id]){
        dfs(x);
    }

}

int main(void){
    ll n;
    cin >> n;

    ll ma = 0;
    ll sum = 0;

    rep(i, 0, n - 1){
        ll t1, t2;
        cin >> t1 >> t2;
        t1--;
        t2--;

        node[t1].push_back(t2);
        node[t2].push_back(t1);
    }


    rep(i, 0, n){
        ll t;
        cin >> t;
        c.push_back(t);
        ma = max(ma, t);
        sum += t;
    }

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

    ll max_node = 0;
    rep(i, 0, n){
        max_node = max(ll(node[i].size()), max_node);
    }

    dfs(max_node);

    cout << sum - ma << endl;

    rep(i, 0, n){
        cout << score[i] << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 1408
require 'prime'
 
n = gets.chomp.to_i
arr = n.prime_division #24 => [[2,3],[3,1]]

ans = 0
arr.each do |div, index|
  cnt = 1
  while index >= cnt
    ans += 1
    index -= cnt
    cnt += 1
  end
end

print ans


Measured memory_bytes: 14412
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
using ll = long long;

int main(){
    int n;
    cin>>n;
    vector<ll> a(n),b(n);
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i];
    }
    ll ans=0;
    for(int i=n-1;i>=0;i--){
        if((a[i]+ans)%b[i]==0) continue;
        ans+=b[i]-(a[i]+ans)%b[i];
    }
    cout<<ans<<endl;
}

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

int main() {
  int n;
  cin >> n;
  string a, b, c;
  cin >> a >> b >> c;
  int m = 0;
  for (int i = 0; i < n; ++i) {
    string d = "";//string(a[i]) + string(b[i]) + string(c[i]);
    d+=a[i]; d+=b[i]; d+=c[i];
    sort(d.begin(), d.end());
    if (d[0] == d[2])
      continue;
    else if (d[0] == d[1] || d[1] == d[2]) {
    	m++;
    }
	else
      m += 2;
  }
  
  cout << m << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>

using namespace std;



int main()
{
    ios_base::sync_with_stdio(false);
    string s,t;
    cin>>s>>t;
    if(s.size()+1==t.size() && s == t.substr(0,s.size())) {
        cout<<"Yes";
    } else {
        cout<<"No";
    }
}


Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
/*
*/
using Graph = vector<bitset<10>>;
ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b, a % b);
}
const ll P =  1000000007;
vector<ll> fact(2020);//fact[i] = factorial(i)

ll factorial(ll n){
   ll ans = 1;
   for(int i = n;i>=1;i--){
     ans *= i;
     ans %= P;
   }
   
   return ans;
}
 
//繰り返し二乗法
ll calc(ll a, ll b, ll p){//aのb乗をpで割った余り
  if(b == 0) return 1;

  else if(b%2 == 0){
    ll d = calc(a,b/2,p);
    return (d*d)%p;
  }
  else if(b%2 == 1){
    return (a * calc(a,b-1,p))%p;
  }
  
}
ll func(ll K,ll i){//K個をi個のグループに分ける
   if(K < i) return 0;
   if(K <= 0 || i <= 0) return 0;
   ll res = 0;
   res = ((fact[K-1] * calc(fact[K-i],P-2,P))%P * calc(fact[i-1],P-2,P)) %P;
   return res;
}
int main(){
   ll N,K;
   cin >> N >> K;
   fact[0] = 1;
   ll ans = 1;
   for(ll i = 1;i<=2010;i++){//fact[i]をメモ
     ans *= i;
     ans %= P;
     fact[i] = ans;
   }

   for(ll i = 1;i<=K;i++){
     cout << func(K,i) * func(N-K+2,i+1) %P << endl;
   }
}

Measured memory_bytes: 256
#include<iostream>
#include<ctime>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<climits>
#include<cstring>
#include<iomanip>
#include<string>
#include<bitset>
#include<set>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<algorithm>
#include<functional>
#include<chrono>
#include<random>

#define y0 asdahsdlkahsdad
#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define taskname "C"
#define BeztDonkey

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

const int nAlpha = 'z' - 'a' + 1, maxN = 2e5 + 1;

deque<int> pos[nAlpha];
static int p[maxN], lab[maxN], n, mid;
ll ans = 0;
string s;

inline void Update(int i, int val) { for (; i <= n; i += i & -i) lab[i] += val; }
inline int Get(int i) { int res = 0; for (; i > 0; i &= i - 1) res += lab[i]; return res; }

int main()
{
    #ifdef BeztDonkey
    auto start = chrono::steady_clock::now();
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen(taskname".inp", "r", stdin);
    //freopen(taskname".out", "w", stdout);

    cin >> s;
    n = s.size();
    for (int i = 0; i < n; ++i) pos[s[i] -= 'a'].push_back(i + 1);
    int dem = 0;
    for (int c = 0; c < nAlpha; ++c)
        if (pos[c].size() & 1) ++dem, mid = pos[c][pos[c].size() >> 1];
    if (dem > 1) return cout << -1, 0;
    for (int i = 1; i <= n; ++i) lab[i] = i & -i;
    for (int dem = n; dem > 1; dem -= 2)
    {
        int _c, _cost = maxN;
        for (int c = 0; c < nAlpha; ++c)
        {
            auto &v = pos[c];
            if (v.size() <= 1) continue;
            int cost = Get(v.front() - 1) + Get(n) - Get(v.back());
            if (cost < _cost) _cost = cost, _c = c;
        }
        ans += _cost;
        auto &v = pos[_c];
        Update(v.front(), -1); v.pop_front();
        Update(v.back(), -1); v.pop_back();
    }
    /*for (int i = 1; i <= n; ++i)
        if (i != mid) Update(i, 1);
    for (int i = 1; i <= n; ++i)
    {
        auto &v = pos[s[i - 1]];
        if (v.back() <= i) continue;
        p[i] = v.back();
        ans += Get(n) - Get(v.back());
        Update(i, -1);
        Update(v.back(), -1);
        v.pop_back();
    }
    if (n & 1)
        for (int i = 1; i <= n; ++i)
            ans += p[i] && (i < mid && p[i] < mid || i > mid && p[i] > mid);*/
    cout << ans;

    #ifdef BeztDonkey
    auto end = chrono::steady_clock::now();
    cerr << "In milliseconds : "
         << chrono::duration_cast<chrono::milliseconds>(end - start).count();
    cerr << '\n' << "In seconds : "
         << chrono::duration_cast<chrono::seconds>(end - start).count() << '\n';
    #endif
    return 0;

}


Measured memory_bytes: 2068
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

//昔の自分は頭いいなぁ

#define PT pair<ll, int>
int N, M, S, T;
int to[400001], d[400001], ne[400001], he[100001];
ll D[100001];
int dp1[100001], dp2[100001];
const int mod = 1e9 + 7;
int search1(int A) {
	if (dp1[A]) return dp1[A] - 1;
	int ret = 0;
	for (int i = he[A]; i; i = ne[i]) {
		if (D[to[i]] == D[A] + d[i]) {
			ret = ret + search1(to[i]);
			if (ret >= mod) ret -= mod;
		}
	}
	dp1[A] = ret + 1;
	return ret;
}

int search2(int A) {
	if (dp2[A]) return dp2[A] - 1;
	int ret = 0;
	for (int i = he[A]; i; i = ne[i]) {
		if (D[to[i]] == D[A] - d[i]) {
			ret = ret + search2(to[i]);
			if (ret >= mod) ret -= mod;
		}
	}
	dp2[A] = ret + 1;
	return ret;
}

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	N = getint();
	M = getint();
	S = getint();
	T = getint();
	int k = 1;
	rep(i, M) {
		int u = getint(), v = getint(), dt = getint() * 2;
		to[k] = v;
		d[k] = dt;
		ne[k] = he[u];
		he[u] = k++;
		to[k] = u;
		d[k] = dt;
		ne[k] = he[v];
		he[v] = k++;
	}

	rep1(i, N) D[i] = 1e18;
	D[S] = 0;

	priority_queue<PT, vector<PT>, greater<PT>> que;
	que.push(mp(0, S));
	while (que.size()) {
		PT p = que.top();
		que.pop();
		int i = p.second;
		if (D[i] != p.first) continue;
		for (int t = he[i]; t; t = ne[t]) {
			int j = to[t];
			ll tmp = D[i] + d[t];
			if (D[j] > tmp) {
				D[j] = tmp;
				que.push(mp(tmp, j));
			}
		}
	}

	ll hanbun = D[T] / 2;
	ll kotae = 0;
	dp1[T] = 2;
	dp2[S] = 2;
	rep1(A, N) {
		if (D[A] == hanbun) {
			ll kari = (ll)search1(A) * search2(A) % mod;
			kotae += kari * kari % mod;
		}
		else if (D[A] < hanbun) {
			for (int i = he[A]; i; i = ne[i]) {
				if (D[A] + d[i] > hanbun && D[A] + d[i] == D[to[i]]) {
					ll kari = (ll)search1(to[i]) * search2(A) % mod;
					kotae += kari * kari % mod;
				}
			}
		}
	}

	printf("%lld", (((ll)search1(S) * search1(S) - kotae) % mod + mod) % mod);

	Would you please return 0;
}

Measured memory_bytes: 8688
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
#define rep(i,strt,end) for(unsigned long long i = strt;i < end;i++)


int main(){
    string s;
    cin >> s;
    long long counter = 0;/*
    rep(i,0,s.length() - 3){
        long long jStop = s.length() - i;
        unsigned long long num = 0;
        rep(j,0,jStop){
            if(s.length() <= i+j)break;
            num += s[i+j] - 48;
            num %= 2019;
            if(num == 0){
                counter++;
            }
            num *= 10;
        }
    }*/
    map<int,unsigned long long> array;
    long slth = s.length();
    reverse(s.begin(),s.end());
    array[0] = 1;
    unsigned int ten = 1;
    unsigned int num = 0;
    rep(i,0,slth){
        num += ten*(s[i]-48);
        num %= 2019;
        //cout << num << endl;
        array[num]++;
        ten *= 10;
        ten %= 2019;
    }
    rep(i,0,2019){
        unsigned long long tmp = array[i];
        //if(tmp > 1)cout << i << endl;
        counter += tmp * (tmp-1) / 2;
    }
    cout << counter << endl;
    //--------------
    return 0;
}

Measured memory_bytes: 3732
MOD = 10**9+7
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()

def init_mod_c(lim=10**6, mod=10**9+7):
    fact = [1, 1] + [0] * (lim-1)
    fact_inv = [1, 1] + [0] * (lim-1)
    inv = [0, 1] + [0] * (lim-1)
    
    for i in range(2, lim+1):
        fact[i] = fact[i - 1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod//i) % mod
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod

    def mod_c(n, m):
        if n < m or n < 0 or m < 0: return 0
        return fact[n] * (fact_inv[m] * fact_inv[n-m] % mod) % mod

    return mod_c

comb = init_mod_c(lim=10**5+10)

mx, mn = 0, 0
for i in range(n):
    mx += a[i] * comb(i, k-1)
    mx %= MOD
    mn += a[i] * comb(n-i-1, k-1)
    mn %= MOD

print((mx - mn) % MOD)


Measured memory_bytes: 19920
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> bool get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'&&t!=EOF; t=getchar());
	if(t=='-')neg=true,t=getchar();if(t==EOF)return false;
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;return true;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) (get1(a)&&get1(b))
#define get3(a,b,c) (get1(a)&&get2(b,c))
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

vector<int> g[3111];
int n,a[3111];
bool dfs(int x,int f=0)
{
	for(auto v:g[x])if(v!=f&&a[x]>a[v]&&!dfs(v,x))return true;
	return false;
}
int main()
{
	get1(n);
	for(int i=1;i<=n;i++)get1(a[i]);
	for(int i=1,u,v;i<n;i++)
	{
		get2(u,v);
		g[u].pb(v);g[v].pb(u);
	}
	for(int i=1;i<=n;i++)if(dfs(i))printf("%d ",i);
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
main()
{
	int a,b;
	cin>>a>>b;
	if(a==b)cout<<"Draw"<<endl;
	else if(a==1)cout<<"Alice"<<endl;
	else if(b==1)cout<<"Bob"<<endl;
	else cout<<(a<b?"Bob":a>b?"Alice":"Draw")<<endl;
}

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

using namespace std;

#define debug(x) '[' << #x << " is: " << x << "] "
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.precision(10);
	cout << fixed;
	string a,b;
	cin>>a>>b;
	int ans  = 0;
	for(int i=0;i<3;i++)
		ans += a[i] == b[i];
	cout << ans << endl;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
height = list(map(int, input().split()))

# N人で遊園地に遊びにいきました。
# ジェットコースターに乗るためには、身長が Kcm以上 必要です。
# 高橋君の仲間たちのうち、一番人気のジェットコースターに乗ることのできる人の数を出力してください。

availability = 0

for i in range(0, N):
    if height[i] >= K:
        availability += 1

print(availability)

Measured memory_bytes: 18388
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 1e18;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main(){
	int n; cin >> n;
	if(n%1000==0)
		cout << 0 << endl;
	else
		cout << 1000-n%1000 << endl;
	return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cfloat>
#include <algorithm>
#include <numeric>
#include <vector>
#include <iterator>
#include <set>
using namespace std;

const double PI=acos(-1);

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

    if((a<0 && b>0)||(a>0 && b<0)||a==0||b==0) cout << "Zero" << endl;
    else if(a>0 && b>0) cout << "Positive" << endl;
    else if((b-a+1)%2 == 0) cout << "Positive" << endl;
    else cout << "Negative" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int dice[6],q,i;
    char c;
    
    for(i=0;i<6;i++){
        scanf("%d",&dice[i]);
    }
    
    scanf("%d",&q);
    for(i=0;i<q;i++){
        int x,y;
        scanf("%d %d",&x,&y);
        if((x==dice[5] && y==dice[4])||(x==dice[4] && y==dice[0])||(x==dice[0] && y==dice[1])||(x==dice[1] && y==dice[5])){
            printf("%d\n",dice[2]);
        }else if((x==dice[0] && y==dice[2])||(x==dice[2] && y==dice[5])||(x==dice[5] && y==dice[3])||(x==dice[3] && y==dice[0])){
            printf("%d\n",dice[4]);
        }else if((x==dice[5] && y==dice[1])||(x==dice[1] && y==dice[0])||(x==dice[0] && y==dice[4])||(x==dice[4] && y==dice[5])){
            printf("%d\n",dice[3]);
        }else if((x==dice[0] && y==dice[3])||(x==dice[3] && y==dice[5])||(x==dice[5] && y==dice[2])||(x==dice[2] && y==dice[0])){
            printf("%d\n",dice[1]);
        }else if((x==dice[2] && y==dice[1])||(x==dice[1] && y==dice[3])||(x==dice[3] && y==dice[4])||(x==dice[4] && y==dice[2])){
            printf("%d\n",dice[5]);
        }else{
            printf("%d\n",dice[0]);
        }
    }
    return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define inf 999999999999
#define N 666666
int arr[N];
int ans[66][66];
map<int,int> vis;
signed main(){
	int n;
	cin>>n;
//	int mod=10;
	for(int i=1;i<=n;i++){
		string temp=std::to_string(i);
		ans[temp[0]-'0'][i%10]++;
		
	}
	int res=0;
	for(int i=1;i<=9;i++){
		for(int j=1;j<=9;j++){
			res+=ans[i][j]*ans[j][i];
		}
	}
	printf("%lld\n",res);
	return 0;
}

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

int main(){
    int a,b,c,d,tao;
    cin >> a >> b >> c>> d;
    while(d >= 0){
        c = c - b;
        if(c <= 0){
            cout <<"Yes"<<endl;
            break;
        }
        a = a - d;
        if(a <= 0){
            cout << "No" <<endl;
            break;
        }
        
    }

}

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

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

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

    ll ans = 0;
    for(int i = 0; i < n; i++){
        ll t = a[i] / 2;
        ans += t;
        a[i] -= t * 2;
        if(a[i] != 0 && i != n - 1){
            if(a[i + 1] != 0){
                ans++;
                a[i] = 0;
                a[i + 1]--;
            }
        }
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 4404
# ABC129D - Lamp
import sys
input = sys.stdin.readline

def main():
    H, W = tuple(map(int, input().split()))
    S = tuple(input().rstrip() for _ in range(H))
    L, R = [[0] * W for _ in range(H)], [[0] * W for _ in range(H)]
    U, D = [[0] * W for _ in range(H)], [[0] * W for _ in range(H)]
    for x1 in range(H):
        for y1 in range(W):
            if S[x1][y1] == ".":  # left and upper sides of S[i][j]
                U[x1][y1] = 1 if x1 == 0 else U[x1 - 1][y1] + 1
                L[x1][y1] = 1 if y1 == 0 else L[x1][y1 - 1] + 1
            x2, y2 = -x1 - 1, -y1 - 1
            if S[x2][y2] == ".":  # right and under sides
                D[x2][y2] = 1 if x2 == H - 1 else D[x2 + 1][y2] + 1
                R[x2][y2] = 1 if y2 == W - 1 else R[x2][y2 + 1] + 1
    ans = max(
        L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3 for i in range(H) for j in range(W)
    )
    print(ans)


if __name__ == "__main__":
    main()

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

int main() {
  string S;
  cin >> S;
  
  if (S == "hi" || S == "hihi" || S == "hihihi" || S == "hihihihi" || S == "hihihihihi") {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }  
}


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

int C[1777771];
int n;
char com[13];
char str[13];

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

int f(){
  int res = 0;
  int i;
  
  for(i = 0;str[i] != '\0';i++) {
    res = res * 4 + g(str[i]);
  }
  return res;
}

int main(void)
{
  int i,n,ans,key;

  scanf("%d",&n);
  for(i = 0;i < n;i++) {
    scanf("%s %s",com,str);

    key = f();

    if(com[0]=='f'){
      ans = C[key % 1777771];
      if(ans) {
	printf("yes\n");
      }
      else {
	printf("no\n");
      }
    }
    else {
      C[key % 1777771]=1;
    }
  }
    return(0);
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[9] = { 0,0, 0, 1, -1, 1, 1, -1, -1 };    int DY[9] = { 0,1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/02/23  Problem: 061_arc_b / Link: https://abc045.contest.atcoder.jp/tasks/arc061_b?lang=en_  ----- */
/* ------問題------

縦 H 行、横 W 列のマス目からなる盤があります。最初、どのマス目も白く塗られています。
すぬけ君が、このうち N マスを黒く塗りつぶしました。i 回目 ( 1≤i≤N ) に塗りつぶしたのは、 上から ai 行目で左から bi 列目のマスでした。
すぬけ君がマス目を塗りつぶした後の盤の状態について、以下のものの個数を計算してください。
各整数 j ( 0≤j≤9 ) について、盤の中に完全に含まれるすべての 3 行 3 列の連続するマス目のうち、黒いマスがちょうど j 個あるもの。

-----問題ここまで----- */
/* -----解説等-----

検索のとき楽になるようにmapの恩恵を受ける。

----解説ここまで---- */

LL H, W, N;

LL ans = 0LL;

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

	cin >> H >> W >> N;
	map<PII, int>Map;
	FOR(i, 0, N) {
		int a, b; cin >> a >> b;
		a--, b--;
		FOR(k, 0, 9) {
			int ny = a + DY[k], nx = b + DX[k];
			if (1 <= ny&&ny < H-1 && 1 <= nx&&nx < W-1) {
				Map[PII(ny, nx)]++;
			}
		}
	}
	VL cnt(10, 0);
	int sum = 0;
	for (auto it = Map.begin(); it != Map.end(); it++) {
		cnt[(*it).second]++;
		sum++;
	}
	cnt[0] = (H-2)*(W-2) - sum;
	FOR(i, 0, 10) {
		cout << cnt[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 56576
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.StringTokenizer;

public class Main {

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return str;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		long nextLong() {
			
			return Long.parseLong(next());
		}

		BigInteger nextBigIntger() {
			BigInteger bb = new BigInteger(next());
			return bb;
		}
	}

	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int n  =sc.nextInt();
		int sum=0;
		for(int i=0;i<n;i++){
			sum+=(Math.abs(sc.nextInt()-sc.nextInt())+1);
		}
		System.out.println(sum);
		
	}
}


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

int main() {
  int x, y, z;
  char n, m;
  cin >> x >> n >> y >> m >> z;
  
  if(y > 4) 
    cout << "TBD" << endl;
  else
    cout << "Heisei" << endl;
}


Measured memory_bytes: 3640
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <iomanip>

typedef long double ld;
typedef long long ll;

using namespace std;


/* TEMPLATE ENDS HERE */

int main() {
	cout << fixed << setprecision(12);	
	int n, x, t;
	cin >> n >> x >> t;
	cout << t * ((n + x - 1) / x) << endl;
	return 0;
}


ll MOD = ((ll)1e9 + 7);

struct mod {
	ll x;

	mod(ll tx = 0) {
		x = tx;
		x %= MOD;
	}
	
	mod& operator=(const ll & tx) {
		x = tx % MOD;
		return *this;
	}
	
	mod& operator=(const mod & m2) {
		x = m2.x;
		return *this;
	}

	mod operator+(const mod& m2) const {
		return mod((x + m2.x) % MOD);
	}

	mod& operator+=(const mod& m2) {
		x += m2.x;
		x %= MOD;
		return *this;
	}

	mod operator-(const mod & m2) const {
		return mod((x - m2.x + MOD) % MOD);
	}

	mod& operator-=(const mod & m2) {
		x -= m2.x;
		x = (x + MOD) % MOD;
		return *this;
	}

	mod operator*(const mod & m2) const {
		return mod((x * m2.x) % MOD);
	}

	mod& operator*=(const mod & m2) {
		x *= m2.x;
		x %= MOD;
		return *this;
	}

	mod mypow(ll k) const {
		mod ret = 1;
		mod cur = x;
		while (k) {
			if (k & 1) {
				ret *= cur;
			}
			cur *= cur;
			k >>= 1;
		}
		return ret;
	}

	mod inv() const {
		return mypow(MOD - 2);
	}

	mod operator/(const mod & m2) const {
		return (*this) * m2.inv();
	}

	mod& operator/=(const mod & m2) {
		x *= m2.inv().x;
		x %= MOD;
		return *this;
	}

	bool operator<(const mod & m2) const {
		return x < m2.x;
	}
};

ostream &operator<<(ostream & os, const mod & m) {
	return os << m.x;
}



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

int main(){
    int i=0, flag=0, j=0;
    string str;
    cin >> str;
    size_t size = str.length();

    for(i=0;i<(size-1)/2;i++){
        if(str[i] != str[size-i-1]){
            flag = 1;
        }
    }
    for(i=0;i<(size-1)/2;i++){
        if(str[i] != str[(size-1)/2-i-1]){
            flag = 1;
        }
    }
    for(i=(size+3)/2-1;i<size;i++){
        if(str[i] != str[size-j-1]){
            flag = 1;
        }
        j++;
    }
    if(flag == 1){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define i64 long long
#define maxn (int)(1e5)
#define pii pair<int,int>
#define L first 
#define R second
#define all(x) x.begin(),x.end()
using namespace std;
bool cmp(int val1, int val2){
	return val1>val2;
}
int main(){
	int A,B,k;
	cin>>A>>B>>k;
	set<int>S;
	int total_number = B-A+1;
	int cnt = 0;
	for(int n=A;n<=B and cnt<min(k,total_number);n++){
		//printf("%d\n",k);
		S.insert(n);
		cnt++;
	}
	cnt =0;
	for(int n=B;n>=A and cnt<min(k,total_number);n--){
		//printf("%d\n",k);
		S.insert(n);
		cnt++;
	}
	set<int>:: iterator it;
	for(it = S.begin(); it!=S.end(); it++) printf("%d\n", *it);
	return 0;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
	for(auto &e:u) fill_v<T>(e,v...);
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int64 N;
	cin >> N;
	if (N%10 == 3) {
	  cout << "bon" << endl;
	} else if (N % 10 == 0 || N%10 == 1 || N%10 == 6 || N%10 == 8) {
	  cout << "pon" << endl;
	} else {
	  cout << "hon" << endl;
	}
}


Measured memory_bytes: 3656
#include <string>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <math.h>
 
using namespace std;
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
 
	int a,b,c,d;
    int kai1,kai2;
	cin >> a >> b >> c >> d;
    kai1 = c/b;
    kai2 = a/d;
    if(c%b != 0){
      kai1++;
    }
    if(a%d != 0){
      kai2++;
    }
    if(kai1 <= kai2){
      cout << "Yes" << "\n";
    }else{
      cout << "No" << "\n";
    }
  
}

Measured memory_bytes: 3652
import java.io.InputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;
import java.util.TreeMap;
import java.math.BigDecimal;
import java.math.BigInteger;
    
public class Main{
 
static final InputStream in=System.in;
static final PrintWriter out=new PrintWriter(System.out);
static final int INF=Integer.MAX_VALUE;
static final long LINF=Long.MAX_VALUE;
 
public static void main(String[] args) throws IOException{
InputReader ir=new InputReader(in);
int t=ir.nextInt();
out.printf("%d:%d:%d\n",t/3600,(t%3600)/60,t%60);
out.flush();
}

static class InputReader {
 private InputStream in;
 private byte[] buffer=new byte[1024];
 private int curbuf;
 private int lenbuf;
 
 public InputReader(InputStream in) {this.in=in; this.curbuf=this.lenbuf=0;}
  
 public boolean hasNextByte() {
  if(curbuf>=lenbuf){
   curbuf= 0;
   try{
    lenbuf=in.read(buffer);
   }catch(IOException e) {
    throw new InputMismatchException();
   }
   if(lenbuf<=0) return false;
  }
  return true;
 }
 
 private int readByte(){if(hasNextByte()) return buffer[curbuf++]; else return -1;}

 private boolean isSpaceChar(int c){return !(c>=33&&c<=126);}
 
 private void skip(){while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++;}

 public boolean hasNext(){skip(); return hasNextByte();}
 
 public String next(){
  if(!hasNext()) throw new NoSuchElementException();
  StringBuilder sb=new StringBuilder();
  int b=readByte();
  while(!isSpaceChar(b)){
   sb.appendCodePoint(b);
   b=readByte();
  }
  return sb.toString();
 }
 
 public int nextInt() {
  if(!hasNext()) throw new NoSuchElementException();
  int c=readByte();
  while (isSpaceChar(c)) c=readByte();
  boolean minus=false;
  if (c=='-') {
   minus=true;
   c=readByte();
  }
  int res=0;
  do{
   if(c<'0'||c>'9') throw new InputMismatchException();
   res=res*10+c-'0';
   c=readByte();
  }while(!isSpaceChar(c));
  return (minus)?-res:res;
 }
 
 public long nextLong() {
  if(!hasNext()) throw new NoSuchElementException();
  int c=readByte();
  while (isSpaceChar(c)) c=readByte();
  boolean minus=false;
  if (c=='-') {
   minus=true;
   c=readByte();
  }
  long res = 0;
  do{
   if(c<'0'||c>'9') throw new InputMismatchException();
   res=res*10+c-'0';
   c=readByte();
  }while(!isSpaceChar(c));
  return (minus)?-res:res;
 }
 
 public double nextDouble(){return Double.parseDouble(next());}
 
 public BigInteger nextBigInteger(){return new BigInteger(next());}
 
 public int[] nextIntArray(int n){
  int[] a=new int[n];
  for(int i=0;i<n;i++) a[i]=nextInt();
  return a;
 }
 
 public char[][] nextCharMap(int n,int m){
  char[][] map=new char[n][m];
  for(int i=0;i<n;i++) map[i]=next().toCharArray();
  return map;
 }
}
}

Measured memory_bytes: 24720
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    s = input()
    chars = list(set(s))
    ans = INF

    for char in chars:
        t = s[:]
        cnt = 0
        while True:
            if len(set(t)) == 1:
                ans = min(ans, cnt)
                break
            l = len(t)
            r = ""
            for i in range(l - 1):
                if t[i] == char or t[i + 1] == char:
                    r += char
                else:
                    r += t[i]
            cnt += 1
            t = r

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 73560