akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

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

typedef pair<int, int> pii;

int main() {
	string str;
	cin >> str;
	
	vector<pii> pos[26]; // pos, flag: 0start 1end
	
	REP(i, 26) {
		int cnt = str[0] == 'a' + i;
		if (cnt) pos[i].push_back(pii(0, 0));
		
		FOR(j, 1, str.size()) {
			if (cnt) {
				if (str[j] != 'a' + i) {
					pos[i].push_back(pii(j - 1, cnt));
					cnt = 0;
				}
				else
					cnt++;
			}
			else {
				if (str[j] == 'a' + i) {
					pos[i].push_back(pii(j, 0));
					cnt = 1;
				}
			}
		}
		if (cnt) pos[i].push_back(pii(str.size() - 1, cnt));
	}
	
	/*
	REP(i, 26) {
		REP(j, pos[i].size()) {
			int cnt = 0;
			if (j + 3 < pos[i].size() &&
				pos[i][j + 1].second == 1 && pos[i][j + 3].second == 1 &&
				pos[i][j + 2].first - pos[i][j].first + 1 > 3)
				continue;
			
			FOR(k, j + 1, pos[i].size()) {
				if (!(pos[i][j].second == 0 && pos[i][k].second != 0)) continue;
				
				cnt += pos[i][k].second;
				
				int len = pos[i][k].first - pos[i][j].first + 1;
				if (len < 2) continue;
				
				if ((len - len%2) / 2 < cnt) {
					cout << pos[i][j].first + 1 << " " << pos[i][k].first + 1 << endl;
					return 0;
				}
			}
			
		}
	}
	*/
	
	REP(i, 26) {
		for (int j = 0; j < pos[i].size(); j += 2) {
			if (j + 3 < pos[i].size() && pos[i][j + 1].second == 1 && pos[i][j + 3].second == 1 &&
				pos[i][j + 2].first - pos[i][j].first + 1 == 3)
			{
				cout << pos[i][j].first + 1 << " " << pos[i][j + 3].first + 1 << endl;
				return 0;
			}
			
			if (pos[i][j + 1].second >= 2) {
				cout << pos[i][j].first + 1 << " " << pos[i][j + 1].first + 1 << endl;
				return 0;
			}
		}
	}
	cout << "-1 -1" << endl;
	return 0;
}

Measured memory_bytes: 2996
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define Sort(a) sort(a.begin(), a.end())
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;} return false;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;} return false;}
const ll MOD = 1000000007;

ll sum = 0;

ll cal(ll n, ll k){
    sum += (n*(n+1))/2 - ((n-k)*(n-k+1))/2 - (k*(k-1))/2 +1;
    //cout << (n*(n+1))/2 << " - " << ((n-k)*(n-k+1))/2 <<" - "<< (k*(k-1))/2+1 << endl;;
    //cout << sum << endl;
    sum = sum % MOD;
    return 0;
}

int main(){
    ll n, k;
    cin >> n >> k;
    for(int i = k; i <= n+1; i++){
        cal(n, i);
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3564
#include<bits/stdc++.h>
#define mod 1000000007;
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long int li;
using namespace std;
int main()
{
    fast_io;
li n,i,max=0,c=0;
cin>>n;
li h[n];
for(i=0;i<n;i++)
{
	cin>>h[i];
}
for(i=0;i<n;i++)
{
	if(h[i]>=h[i+1])
	{
		c++;
	}
	else
	{
		if(c>max)
		max=c;
		
		c=0;
	}
	
}
cout<<max;
return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const int nmax=200005;
ll fact[nmax],finv[nmax],inv[nmax];
 
void inicom(){
    fact[0]=fact[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for (int i = 2; i < nmax; i++){
        fact[i]=fact[i-1]*i%mod;
        inv[i]=mod-inv[mod%i]*(mod/i)%mod;
        finv[i]=finv[i-1]*inv[i]%mod;
    }
}
ll pow(ll n,ll k,ll m){
    ll res=1;
    for(;k>0;k>>=1){
        if(k&1){
            res=(res*n)%m;
        }
        n=(n*n)%m;
    }
    return res;
}

int main(){
    ll n,a,b; cin>>n>>a>>b;
    if(n==2){
        cout<<0<<endl;
        return 0;
    }
    ll ans=(pow(2,n,mod)-1+mod)%mod;
    inicom();
    ll p=finv[a],q=finv[b];//p=(a!)^(-1),q=(b!)^(-1)
    for (int i = 0; i < a; i++){
        p*=(n-i);
        p%=mod;
    }
     for (int i = 0; i < b; i++){
        q*=(n-i);
        q%=mod;
    }
    ans=(ans-p+mod-q+mod)%mod;
    cout<<ans<<endl;
   
}

Measured memory_bytes: 4992
#!/usr/bin/env python3
import sys


def solve(W: int, H: int, x: int, y: int):
    print(W * H / 2, 1 if (2 * x, 2 * y) == (W, H) else 0)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    W = int(next(tokens))  # type: int
    H = int(next(tokens))  # type: int
    x = int(next(tokens))  # type: int
    y = int(next(tokens))  # type: int
    solve(W, H, x, y)


if __name__ == '__main__':
    main()


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

#define REP(i, n) for(long long i = 0; i < (long long)(n); i++)

const string YES = "yes";
const string NO = "no";

void solve(std::string S){
  map<char, int> tab;
  REP(i, S.size()) {
    if(tab.count(S[i]) > 0) {
      cout << NO << endl;
      return;
    }

    tab[S[i]]++;
  }
  cout << YES << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
  std::cin >> S;
    solve(S);
    return 0;
}


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

int main(void) {
	int m,f,r;
	
	while (true)
	{
		cin >> m >> f >> r;
		if (m == -1 && f == -1 && r == -1)	break;
		
		if (m == -1 || f == -1) cout << "F" << endl;
		else if (( m + f ) >= 80) cout << "A" << endl;
		else if (( m + f ) >= 65 && ( m + f ) < 80) cout << "B" << endl;
		else if (( m + f ) >= 50 && ( m + f ) < 65) cout << "C" << endl;
		else if (( m + f ) >= 30 && ( m + f ) < 50 && r >= 50) cout << "C" << endl;
		else if (( m + f ) >= 30 && ( m + f ) < 50) cout << "D" << endl;
		else if (( m + f ) < 30) cout << "F" << endl;
	}

	return 0;
}


Measured memory_bytes: 3096
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    string s,t;
    cin >> s >> t;
    t.pop_back();
    bool ans = s == t;
    cout << (ans? "Yes" : "No") << endl;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  string s;
  ll ans = 0;
  cin >> s;
  int sl = s.size();

  for (int i = 0; i < (1 << (sl - 1)); ++i) {
    string st = {s[0]};
    ll ta = 0;
    for (int j = 0; j < sl; ++j) {
      if (i & (1 << j)) ans += stoll(st), st = "";
      st = st + s[j + 1];
    }
    ans += stoll(st);
  }

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


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

typedef long long ll;

using namespace std;



int main()
{
	multimap<int, int> m;
	
	for (int i = 0; i < 5; i++)
	{
		int a;
		cin >> a;
		int x = a % 10;
		if (x != 0)
		{
			x = 10 -x;
		}

		m.insert(multimap<int, int>::value_type(x, a));
	}
 	
	int ans = 0;
	int count = 0;
	for (auto x : m)
	{
		if (count < 4)
		{
			ans = ans + x.second + x.first;
		}
		else
		{
			ans = ans + x.second;
		}

		count++;
	}

	cout << ans;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string a;
int ans=1000000000;
int main(){
	cin>>a;
	for(int i=1;i<a.length();i++){
		if(a[i]!=a[i-1]){
			ans=min(ans,max(i,int(a.length())-i));
		}
	}
	printf("%d",min(ans,int(a.length())));
	return 0;
}

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

int main(){
	int n,m,d,h,i,j,r,s;
	string str;
	for(;cin>>n,n;cout<<r<<endl){
		vector<int>monster(n);
		for(h=i=0;i<n;i++){
			cin>>monster[i];
			if(h<monster[i])h=monster[i];
		}
		vector<pair<int,int> >_all,_single;
		vector<int>all(h+1),single(h+1);
		for(cin>>i;i--;){
			cin>>str>>m>>str>>d;
			if(d){
				if(str=="All")_all.push_back(make_pair(m,d));
				else _single.push_back(make_pair(m,d));
			}
		}
		for(i=1;i<=h;i++){
			all[i]=9999999;
			single[i]=9999999;
			for(j=0;j<_all.size();j++){
				all[i]=min(all[i],all[max(0,i-_all[j].second)]+_all[j].first);
			}
			for(j=0;j<_single.size();j++){
				single[i]=min(single[i],single[max(0,i-_single[j].second)]+_single[j].first);
			}
		}

		r=9999999;
		for(i=0;i<=h;i++){
			s=all[i];
			for(j=0;j<monster.size();j++)s+=single[max(0,monster[j]-i)];
			if(r>s)r=s;
		}
	}
}

Measured memory_bytes: 1968
#include <cstdlib>
#include <iostream>
    using std::cin;
    using std::cout;
    using std::endl;
#include <stack>
    using std::stack;
#include <string>
    using std::string;

int main() {

    stack<int> S;
    string s;
    int v1, v2;

    while (cin >> s) {
        if (s[0] == '+') {
            v1 = S.top(); S.pop();
            v2 = S.top(); S.pop();
            S.push(v1 + v2);
        } else if (s[0] == '-') {
            v1 = S.top(); S.pop();
            v2 = S.top(); S.pop();
            S.push(v2 - v1);
        } else if (s[0] == '*') {
            v1 = S.top(); S.pop();
            v2 = S.top(); S.pop();
            S.push(v1 * v2);
        } else {
            S.push(atoi(s.c_str()));
        }
    }

    cout << S.top() << endl;
}



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

int main(){
  int N;
  cin >> N;
  
  if(N==1){
    printf("Hello World\n");
  }
  
  if(N==2){
    int A, B;
    cin >> A >> B;
    printf("%d\n", A+B);
  }
  return 0;
}


Measured memory_bytes: 256
s = 'abcdefghij'
sg = s.__getitem__


def dfs(ans):
    if len(ans) == n:
        print(''.join(map(sg, ans)))
        return
    for i in range(max(ans) + 2):
        ans.append(i)
        dfs(ans)
        ans.pop()


n = int(input())
dfs([0])


Measured memory_bytes: 4404
#include"iostream"
#include"cstdio"
using namespace std;
long long a,b,h=0;
long long o,p;
int main()
{
    cin>>a>>b;
    o=a+1;
    p=o-1;
    cout<<min(p,b/2)+max(b-p*2,h)/4;
    return 0;
}

Measured memory_bytes: 256
//↓見なくていいよ！ここから--------------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  myerr("-----start-----");
  var start = new Date();
  Main();
  var end = new Date() - start;
  myerr("----- end -----");
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
	var N = nextInt();
	var count = 0;
	var sum = 0;
	while(true){
		sum += N;
		count++;
		if(sum % 360 == 0){
			myout(count);
			return;
		}
	}
	
	
}


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

	int n;
	cin >> n;
	bool flag = 0;
	rep(i,n) {
		int a; 
		cin >> a;
		if (a%2 == 1) {
			flag = 1;
			break;
		}
	}

	if (flag) {
		cout << "first" << endl;
	} else {
		cout << "second" << endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <map>
#include<vector>

using namespace std;
typedef long long ll;

ll ans,mx,sum,mn=1e8;

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


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

int main(){
  long long N = 0;
  cin >> N;
  long long ans = 0;
  
  for(long long i = 1; i <= N; i++){
    if(i % 3 != 0 && i % 5 != 0){
      ans += i;
    }
  }
  
  cout << ans << endl;
}

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

main()
{

    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    long long i,j,k,l,m,n,p;

    while(cin>>n>>m>>p)
    {

    if(n<0)n*=-1;
    j=n/p;
    l=n%p;
       k=m-j;
       if(k<=0)cout<<n-(m*p)<<endl;
       else{
        if(k%2==0)cout<<l<<endl;
        else {

            cout<<abs(l-p)<<endl;
        }

       }

    }

    return 0;
}


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

int main(){
  int H,W,h,w;
  cin>>H>>W>>h>>w;
  int ans=H*W-(h*W+w*H)+h*w;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3644
N = int(input())
s = []
for i in range(N):
    s.append(input())

M = int(input())
t = []
for i in range(M):
    t.append(input())

import collections
v1 = collections.Counter(s)
v2 = collections.Counter(t)
c = 0
for s in v1.keys():
    _ = v1[s] - v2[s]
    if c < _:
        c = _
print(c)

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

ll pow_f(ll A){
    return A*A*A*A*A;
}

int main(){
    ll X;
    cin >> X;
    ll A,B;
    int state = 0;
    for(ll i=0;i < 200;i++){
        for(ll j=0;j < 400;j++){
            if(j - 200 >= i){
                break;
            }
            if(pow_f(i) - pow_f(j - 200) == X){
                A = i;
                B = j - 200;
                state = 1;
                break;
            }
        }
        if(state == 1){
            break;
        }
    }
    cout << A << " " << B << endl; 
}

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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

lli dp[7000];
bool vis[7000];

void func(long long N, long long T, std::vector<long long> A, std::vector<long long> B){
    vis[0]=true;
    vector<pair<lli,lli>> D(N);
    REP(i,0,N)D[i]=mp(A[i],B[i]);
    sort(D.begin(),D.end());
    REP(i,0,N){
        for(lli j=T-1;j>=0;j--){
            dp[j+D[i].first] = max(dp[j+D[i].first],dp[j]+D[i].second);
        }
    }
    lli ans = 0;
    REP(i,0,7000)ans = max(ans,dp[i]);

    cout<<ans<<endl;
}

int main(){
    // cout << fixed << setprecision(5);

    long long N;
    scanf("%lld",&N);
    long long T;
    scanf("%lld",&T);
    std::vector<long long> A(N);
    std::vector<long long> B(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
        scanf("%lld",&B[i]);
    }
    func(N, T, std::move(A), std::move(B));
    return 0;
}


Measured memory_bytes: 384
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')


def solve():
    n,y = f()

    a = [10, 5, 1]
    y = y//1000

    for i in range(n+1):
        for j in range(n+1-i):
            k = n -i - j
            if i*10 + j*5 + k == y:
                print(i,j,k)
                return
    
    print(-1,-1,-1)
    

solve()


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

int main()
{
  int n,one;
  cin>>n;
  one=n%10;
  if(one==2)
    cout<<"hon"<<endl;
  if(one==4)
    cout<<"hon"<<endl;
  if(one==5)
    cout<<"hon"<<endl;
  if(one==7)
    cout<<"hon"<<endl;
  if(one==9)
    cout<<"hon"<<endl;
  if(one==0)
    cout<<"pon"<<endl;
  if(one==1)
    cout<<"pon"<<endl;
  if(one==6)
    cout<<"pon"<<endl;
  if(one==8)
    cout<<"pon"<<endl;
  if(one==3)
    cout<<"bon"<<endl;
}


Measured memory_bytes: 3636
S=input()
l=['AKIHABARA','KIHABARA','AKIHBARA','AKIHABRA','AKIHABAR',
   'KIHBARA','AKIHBRA','AKIHABR','KIHABRA',
   'AKIHBAR','KIHABAR',
   'KIHBRA','AKIHBR','KIHABR','KIHBAR','KIHBR']
 
if S in l:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
bool chmin(ll & a, ll  b) { if (b < a) { a = b; return 1; } return 0; }
bool chmax(ll & a, ll b) { if (b > a) { a = b; return 1; } return 0; }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N=500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
int main() {
    cin>>n>>m;
    x=INF;
    y=0;
    rep(i,m){
        cin>>a>>b;
        x=min(b,x);
        y=max(a,y);
    }

    cout<<max(0LL,x-y+1)<<endl;
}


Measured memory_bytes: 256
#include <iostream>
    using namespace std;
     
    int main() {
	int n;
	cin>> n;
	int day[n];
	int i;
	for (i=0; i<n; i++){
		cin>> day[i];
	}
	for (i=n-1; i>0 ; i--){
		cout<< day[i]<< " ";
	}
	cout << day[0]<< endl;
    return 0;
    }



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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main() {
    const int A = 26;
    ll n; cin >> n;
    
    string ans;
    do{
        int tmp = n % A;
        char c;
        if(tmp == 0){
            c = 'z';
            n--;
        }else{
            c = 'a' + tmp - 1;
        }
        n /= A;
        ans.pb(c);
    }while(n);
    
    reverse(all(ans));
    cout << ans << endl;
    
    return;
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main() {
    long long n, t; cin >> n >> t;
    long long res = t;
    long long time[n];
    for (int i = 0; i < n; i++)
    {
        cin >> time[i];
    }
    for (int i = 1; i < n; i++)
    {
        res += min(time[i] - time[i-1], t);
    }
    cout << res << endl;
	return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
int main(){
    int n,i,j,v,b,f,r,k;
    int peo[30][11]={0};
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d %d %d %d",&b,&f,&r,&v);
        peo[3*(b-1)+(f-1)][r-1]+=v;
    }
    
    for(k=0;k<4;k++){
        for(i=0;i<3;i++){
            for(j=0;j<10;j++){
                printf(" %d",peo[i+3*k][j]);
            }
            putchar('\n'); 
        
        }
        if(k!=3){
            for(i=0;i<20;i++){
                printf("#");
            }
            putchar('\n');
        }
    }

    
    
    return 0;
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	vector<int>a(1e5+1,0);
	int64_t sum=0;
	for(int i=0;i<n;++i){
		int A; cin>>A;
		++a.at(A);
		sum+=A;
	}
	int q; cin>>q;
	for(int i=0;i<q;++i){
		int b,c; cin>>b>>c;
		sum-=1L*c*a.at(c);
		a.at(c)+=a.at(b);
		sum+=1L*c*a.at(c);
		sum-=1L*b*a.at(b);
		a.at(b)=0;
		cout<<sum<<"\n"s;
	}
}

Measured memory_bytes: 3716
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;
const int INFTY = (1 << 21); // 2097152
// const ll INFTY = (1LL << 60);
const ll MD = 1000000007LL;

int K;
int R[8];

bool isok(int y, int x){
    rep(yy, 8) if(R[yy] != -1 && R[yy] == x) return false;
	rep(yy, 8) if(R[yy] != -1 && (yy + R[yy]) == y + x) return false;
	rep(yy, 8) if(R[yy] != -1 && (yy - R[yy]) == y - x) return false;
	return true;
}

bool dfs(int y){
	if(y == 8) return true;
	if(R[y] != -1) return dfs(y+1);

	for(int x = 0; x < 8; x++){
		if(isok(y, x)){
			R[y] = x;
			bool success = dfs(y+1);
			if(success) return true;
			R[y] = -1;
		}
	}
	return false;
}

void dfs_run(){
	dfs(0);
}

int main() {
	cin >> K;
	rep(i, 8) R[i] = -1;
	rep(i, K){
		int y, x;
		cin >> y >> x;
		R[y] = x;
	}

	dfs_run();

	rep(y, 8){
		rep(x, 8) cout << (R[y] == x ? 'Q' : '.');
		cout << endl;
	}
}

Measured memory_bytes: 3096
# coding: utf-8


def main():
    
    takahashi, aoki, action_count = map(int, input().split(' '))

    if action_count <= takahashi:
        takahashi = (takahashi - action_count)
    elif takahashi < action_count <= (takahashi + aoki):
        aoki = (takahashi + aoki - action_count)
        takahashi = 0
    elif (takahashi + aoki) < action_count:
        takahashi = 0
        aoki = 0
    
    print(takahashi, aoki)

    return 0
    
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi= vector<int>;
using vvi= vector<vi>;
using vd= vector<double>;
using vvd= vector<vd>;
using vc= vector<char>;
using vb= vector<bool>;
using vl= vector<ll>;
#define rep(i,x,n) for(int i=x; i<n; i++)
#define all(x) x.begin(), x.end()

int main(){
  string s;
  cin >> s;
  int n=s.size(),r=0,l=0;
  vi ans(n,0);
  vi tmp(n,0);

  rep(i,0,n){
    if(s[i]=='L'){
      l++;
    }else{
      r++;
    }

    if((s[i]=='L' && s[i+1]=='R') || i==n-1){
      tmp[i-l+1]=0-l;
      l=0;
    }else if(s[i]=='R' && s[i+1]=='L'){
      tmp[i]=r;
      r=0;
    }
  }
  rep(i,0,n){
    if(tmp[i]>0){
      ans[i]+= (tmp[i]+1)/2;
      ans[i+1]+= tmp[i]/2;
    }else if(tmp[i]<0){
      ans[i]-= (tmp[i]-1)/2;
      ans[i-1]-= tmp[i]/2;
    }
  }
  rep(i,0,n){
    cout << ans[i] << " ";
  }


  return 0;
}


Measured memory_bytes: 1408
/*
      author  : nishi5451
      created : 15.08.2020 10:26:03
*/

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


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

    vector<int> b(n+1);
    for(int i=1; i<=n; i++){
        for(int j=1; j<=i; j++){
            b[i]+=a[j];
        }
    }
    int ans = 2e9;
    for(int i=1; i<n; i++){
        ans = min(ans,abs(b[i]-(sum-b[i])));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
 
#define ll long long int
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define INF 0x3f3f3f3f

 
using namespace std;
const int N=601, mod= 1e9+7;
vector<int> g[N];
vector<long double> dp1(N),dp2(N);

int main(){
	ios_base::sync_with_stdio(0);	cin.tie(0);
	int n,m;
	
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int u,v;
		cin>>u>>v;
		g[u].pb(v);
	}
	
	for(int i=n-1;i>0;i--){
		for(auto v:g[i]){
			dp1[i]+=dp1[v]+1;
		}
		dp1[i]/=g[i].size();
	}
	
	long double ans=dp1[1];
	
	
	for(int i=1;i<n;i++){
		if(g[i].size()<2) continue;
		
		int k=-1; long double mx=-1;
		for(auto j:g[i]){
			if( mx<dp1[j] ){
				mx=dp1[j];
				k=j;
			}
		}
		
		dp2[n]=0;
		for(int j=n-1;j>0;j--){
			dp2[j]=0;
			int ct=0;
			for(auto v:g[j]){
				if( i==j && v==k ) continue;
				ct++;
				dp2[j]+=dp2[v]+1;
			}
			dp2[j]/=ct;
		}
		ans=min(ans,dp2[1]);
	}
	
	
	cout<<fixed<<setprecision(8)<<ans<<"\n";
	
}


Measured memory_bytes: 1408
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("5");
            WillReturn.Add("MASHIKE");
            WillReturn.Add("RUMOI");
            WillReturn.Add("OBIRA");
            WillReturn.Add("HABORO");
            WillReturn.Add("HOROKANAI");
            //2
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("4");
            WillReturn.Add("ZZ");
            WillReturn.Add("ZZZ");
            WillReturn.Add("Z");
            WillReturn.Add("ZZZZZZZZZZ");
            //0
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("5");
            WillReturn.Add("CHOKUDAI");
            WillReturn.Add("RNG");
            WillReturn.Add("MAKOTO");
            WillReturn.Add("AOKI");
            WillReturn.Add("RINGO");
            //7
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();

        long MCnt = 0, ACnt = 0, RCnt = 0, CCnt = 0, HCnt = 0;

        foreach (string EachStr in InputList.Skip(1)) {
            if (EachStr[0] == 'M') MCnt++;
            if (EachStr[0] == 'A') ACnt++;
            if (EachStr[0] == 'R') RCnt++;
            if (EachStr[0] == 'C') CCnt++;
            if (EachStr[0] == 'H') HCnt++;
        }

        long Answer = 0;
        Answer += RCnt * CCnt * HCnt;

        Answer += ACnt * CCnt * HCnt;
        Answer += ACnt * RCnt * HCnt;
        Answer += ACnt * RCnt * CCnt;

        Answer += MCnt * CCnt * HCnt;
        Answer += MCnt * RCnt * HCnt;
        Answer += MCnt * RCnt * CCnt;
        Answer += MCnt * ACnt * HCnt;
        Answer += MCnt * ACnt * CCnt;
        Answer += MCnt * ACnt * RCnt;

        Console.WriteLine(Answer);
    }
}


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

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if(a+b < c+d) cout << "Right" << endl;
    if(a+b == c+d) cout << "Balanced" << endl;
    if(a+b > c+d) cout << "Left" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

struct T{
    int x,y,z;
    T(){}
    T(int x, int y, int z):x(x),y(y),z(z){}
};

class union_find {
private:
    vector<ll> par;
    vector<ll> ran;
    vector<ll> m_size;
public:
    union_find(ll n);
    ll find(ll x);
    void unite(ll x, ll y);
    bool same(ll x, ll y);
    ll size(ll x);
};

union_find::union_find(ll n){
    par.resize(n);
    ran.resize(n, 0);
    m_size.resize(n, 1);
    rep(i,n) par[i] = i;
};

ll union_find::find(ll x) {
    if (par[x] == x) return x;
    else return par[x] = find(par[x]);
};

void union_find::unite(ll x, ll y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    ll t = size(x)+size(y);
    m_size[x] = m_size[y] = t;
    if (ran[x] < ran[y]) {
        par[x] = y;
        //size[y] += size[x];
    } else {
        par[y] = x;
        //ize[x] += size[y];
        if (ran[x]==ran[y]) ran[x]++;
    }
};

ll union_find::size(ll x) {
    if (par[x] == x) return m_size[x];
    return size(par[x] = find(par[x]));
}

bool union_find::same(ll x, ll y) {
    return (find(x) == find(y));
};

int main(int argc, char const *argv[]) {
    int n,m; cin>>n>>m;
    vector<T> a;
    a.reserve(n);
    union_find uf(n);
    rep(i,m) {
        int x,y,z; cin>>x>>y>>z;
        z %= 2;
        uf.unite(x-1,y-1);
        a.emplace_back(x,y,z);
    }
    set<int> ans;
    rep(i,n) ans.insert(uf.find(i));
    cout << ans.size() << '\n';
    return 0;
}

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

using namespace std;

using i64 = int64_t;

const i64 MOD = 1e9 + 7;
const i64 INF = 1e18 + 7;


signed main(){
    int n, m, s, t;
    cin >> n >> m >> s >> t;
    --s, --t;
    vector<vector<i64>> poses(m, vector<i64>(3));
    vector<i64> dist(m);

    // edges[n]: [m, m]
    vector<vector<i64>> edges(n + m);

    for(i64 i = 0; i < m; ++i){
        for(auto& x : poses[i]){
            cin >> x;
            --x;
        }
        cin >> dist[i];
        edges[poses[i][0]].emplace_back(n + i);
        edges[poses[i][1]].emplace_back(n + i);
        edges[poses[i][2]].emplace_back(n + i);
        edges[n + i].emplace_back(poses[i][0]);
        edges[n + i].emplace_back(poses[i][1]);
        edges[n + i].emplace_back(poses[i][2]);
    }
    vector<i64> range(n + m, INF);
    priority_queue<pair<i64,i64>, vector<pair<i64,i64>>, greater<pair<i64,i64>>> que;
    range[s] = 0;
    que.emplace(0, s);

    while(!que.empty()){
        i64 rang, pos;
        tie(rang, pos) = que.top();
        que.pop();
        if(rang != range[pos])
            continue;
        for(auto& to : edges[pos]){
            i64 nex = rang + (pos >= n ? dist[pos - n] : 0);
            if(range[to] > nex){
                range[to] = nex;
                que.emplace(range[to], to);
            }
        }
    }

    cout << range[t] << endl;
}



Measured memory_bytes: 27760
#include<stdio.h>
#define len(array) (sizeof(array) / sizeof(int))

void sort(int *array, int len) {
	int i, j, temp;
	for (i = 0; i < len; i++) {
		for (j = 0; j < len - 1 - i; j++) {
			if (array[j] > array[j + 1]) {
				temp = array[j];
				array[j] = array[j + 1];
				array[j + 1] = temp;
			}
		}
	}
}

int main(void) {
	int array[3];
	scanf("%d%d%d", &array[0], &array[1], &array[2]);
	sort(array, len(array));
	printf("%d", array[2] - array[0]);
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();//1 ~ 10^5 = 100000

		int count = 0;
		int N1000 = 90;//Nが999までなら
		int N10000 = 9090;//Nが9999までなら
		int N100000 = 9091;//Nが100000なら

		if(N < 10) {//1 ~ 9
			count = N;
		}else if(N < 100) {//10 ~ 99 = 90個
			count = 9;
		}else if(N < 1000) {//100 ~ 999
			count = N - N1000;
		}else if(N < 10000) {//1000 ~ 9999 = 9000個
			count = 909;
		}else if(N < 100000){//10000 ~ 99999
			count = N - N10000;
		}else {//100000 = 10^5
			count = 90909;
		}

		System.out.println(count);
	}

}


Measured memory_bytes: 22724
import itertools

def main():
    a = [int(input()) for i in range(5)]
    ans = float("inf")
    for i in list(itertools.permutations(a)):
        ans = min(ans, sum(i) + (200 - i[0])%10 + (200 - i[1])%10 + (200 - i[2])%10 + (200 - i[3])%10)
    print(ans)

main()

Measured memory_bytes: 3188
#include<iostream>
#include<cstdio>
#include<string>
#include<cmath>
#include<algorithm>
#include<utility>
#include<vector>

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

using namespace std;

int main(int argc, char const *argv[]) {

    string str;
    cin >> str;
    bool large_c=false;
    if(str[0]!='A'){
        cout << "WA\n";
        return 0;
    }
    for(int i=1;i<str.size();i++){
        if(i==1 || i==str.size()-1){
            if(str[i]<97 || str[i]>122){
                cout << "WA\n";
                return 0;
            }
        }else{
            if(large_c){
                if(str[i]<97 || str[i]>122){
                    cout << "WA\n";
                    return 0;
                }
            }else{
                if(str[i]=='C'){
                    large_c=true;
                    continue;
                }
                if(str[i]<97 || str[i]>122){
                    cout << "WA\n";
                    return 0;
                }

            }
        }
    }
    if(!large_c){
        cout << "WA\n";
        return 0;
    }else
        cout << "AC\n";
    return 0;
}


Measured memory_bytes: 256
// Problem : A - Air Conditioner
// Contest : AtCoder - AtCoder Beginner Contest 174
// URL : https://atcoder.jp/contests/abc174/tasks/abc174_a
// Memory Limit : 1024.000000 MB 
// Time Limit : 2000.000000 milisec 
   

#include<bits/stdc++.h>
#define ll                    long long int
#define pb                    push_back
#define F                     first
#define S                     second
#define mp                    make_pair
#define MOD                   1000000007
#define vi                    vector<int>
#define vll                   vector<ll>
#define pll                   pair<ll,ll>
#define pii                   pair<int,int>
#define all(p)                p.begin(),p.end()
#define mid(s,e)              (s+(e-s)/2)
#define eb                    emplace_back
#define ull                   unsigned long long
#define bug(x)				  cout<<"  [ "#x<<" = "<<x<<" ]"<<endl;
#define KAMEHAMEHA            ios_base::sync_with_stdio(0);
#define RASENGAN              ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
void solve()
{
	int n;
	cin>>n;
	if(n>=30)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
}
int main()
{
    KAMEHAMEHA
	int t=1;
	//cin>>t;
	for(int cn=1;cn<=t;cn++)
	{
		solve();
	}
    return 0;
}



Measured memory_bytes: 3632
#include <stdio.h>
 
 
int main() {
	int N;
	scanf("%d", &N);
	
	for (int i = 1; i < 10; i++){
		if (N % i == 0 && N / i < 10){
			puts("Yes\n");
			break;
		}
		
		else if (i == 9) {
			puts("No\n");
		}
	}
	return 0;
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

constexpr int atcoder_mod = 1e9+7;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	while(true){
		int H=in(),W=in();
		if(!H && !W) break;
		REP(i,H){
			REP(j,W){
				cout << '#';
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}



Measured memory_bytes: 3100
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <math.h>
using namespace std;
#define forn(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define ford(i, a, n) for (int i = (int)(n) - 1; i >= (int)(a); --i)
#define fore(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define printV(vec) for(int i = 0; i < SZ(vec); i++){cout << vec[i];if (i==SZ(vec)-1){cout<<endl;}else{cout << " ";}}
#define printA(arr,n) for(int i = 0; i < n; i++){cout << arr[i];if (i==n-1){cout<<endl;}else{cout << " ";}}
#define LLINF ((1LL<<62))
typedef long long ll;


int main()
{
  int N;
  int C;

  cin >> N >> C;

  int D[C][C];
  forn(i,0,C){
    forn(j,0,C){
      scanf("%d",&D[i][j]);
    }
  }

  int c[N][N];
  forn(i,0,N){
    forn(j,0,N){
      scanf("%d",&c[i][j]);
    }
  }

  int cm[3][30] = {};
  forn(i,0,N){
    forn(j,0,N){
      cm[(i+j)%3][c[i][j]-1]++;
    }
  }

  ll minsum = LLINF;
  forn(i,0,C) forn(j,0,C) if (i!=j) forn(k,0,C) if(i!=k && j!=k){
    ll sum = 0;
    forn(l,0,C){
      sum += cm[0][l]*D[l][i];
      sum += cm[1][l]*D[l][j];
      sum += cm[2][l]*D[l][k];
    }
    minsum = min(minsum,sum);
  }
  cout << minsum << endl;

  return 0;
}


Measured memory_bytes: 1280
use proconio::input;
use proconio::marker::Usize1;
use std::cmp;

fn main() {
    input! {
        n: usize,
        m: usize,
    }
    let mut v = vec![];
    for _ in 0..m {
        input! {
            a: usize,
            b: usize,
            c: [Usize1; b],
        }
        let mut s = 0;
        for &nc in &c {
            s |= 1 << nc;
        }
        v.push((s, a));
    }
    let inf = 1usize << 60;
    let mut dp = vec![inf; 1 << n];
    dp[0] = 0;
    for i in 0..1 << n {
        for &nv in &v {
            let ns = i | nv.0;
            let cost = dp[i] + nv.1;
            dp[ns] = cmp::min(dp[ns], cost);
        }
    }
    if dp[(1 << n) - 1] == inf {
        println!("{}", -1);
    } else {
        println!("{}", dp[(1 << n) - 1]);
    }
}


Measured memory_bytes: 2168
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a.at(i);
    }
    for(int i=n;i>1;i--){
        cout << a.at(i-1) << " ";
    }
    cout << a.at(0) << endl;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int main(){
    int n,m;
    cin>>n>>m;
    vector<string>a(n),b(m);
    rep(i,n)cin>>a[i];
    rep(i,m)cin>>b[i];
    rep(i,n-m+1){
        rep(j,n-m+1){
            if(b[0][0]==a[i][j]){
                bool c=true;
                rep(k,m){
                    rep(l,m){
                        if(b[k][l]!=a[i+k][j+l]){c=false;break;}
                    }
                    if(!c)break;
                }
                if(c){cout<<"Yes";return 0;}
            }
        }
    }
    cout<<"No";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
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; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll tmp1,tmp2,tmp3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;
void swap(ll *x,ll *y){
  ll tmp;
  tmp = *x;
  *x = *y;
  *y = tmp;
}
vector<ll> mul(10,1);
void calcmul(ll k,ll n){
  ll m = 1;
  REP(i,1,n+1){
    mul[i] = mul[i-1] * i;
  }
}

int main() {
  ll n;
  cin >> n;
  vector<ll> vec1(n,0),vec2(n,0),p(n),q(n);
  calcmul(n,n);
  rep(i,n){
    cin >> p[i];
  }
  rep(i,n){
    cin >> q[i];
  }

  ll sum1,sum2;
  rep(i,n){
    tmp1 = p[i]-1;
    ll cou = 0;
    rep(j,tmp1){
      if(vec1[j] == 0){
        cou++;
      }
    }
    vec1[tmp1] = 1;
    sum1 += cou * mul[n-i-1];
  }
  rep(i,n){
    tmp1 = q[i]-1;
    ll cou = 0;
    rep(j,tmp1){
      if(vec2[j] == 0){
        cou++;
      }
    }
    //cout << cou << endl;
    vec2[tmp1] = 1;
    sum2 += cou * mul[n-i-1];
  }
  //cout << sum1 << " " << sum2 << endl;
  cout << abs(sum2 - sum1) << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
#define N_max 50

int main(){
    int N;
    cin >>N;
    int A[N_max];
    int abs_max=0,abs_ind=0;
    for(int i=0;i<N;i++){
        cin >> A[i];
        if(abs_max < abs(A[i])){
            abs_max=abs(A[i]);
            abs_ind=i;
        }
    }
    cout << 2*N-2 <<endl;
    for(int i=0;i<N;i++){
        if(i!=abs_ind) cout << abs_ind+1 << " " << i+1 << endl;
    }
    if(A[abs_ind] >=0){
        for(int i=1;i<N;i++) cout << i << " " << i+1 <<endl;
    }
    else{
        for(int i=N; 1< i ;i--) cout << i << " " <<i-1 <<endl;
    }
}

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
string to_str(ll x){string res; while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return res;}
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//template end



int main(){
    ll n,a,b; scanf("%lld%lld%lld",&n,&a,&b);
    if((a+b)%2==0)printf("%lld\n",(b-a)/2);
    else{
        ll ans=INF*2;
        ll sub=a,bb=b-a-1;
        chmin(ans,sub+bb/2);
        sub=n-b+1; chmin(ans,sub+bb/2);
        printf("%lld\n",ans);
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n;
    cin>>n;
    string s[n];
    long long con1=0,con2=0,con3=0,con4=0;
    for(long long i=0;i<n;++i)
    {
        cin>>s[i];
        for(long long j=0;j<s[i].size()-1;++j)
        {
            if(s[i][j]=='A'&&s[i][j+1]=='B')
            con1++;
        }
        if(s[i][0]=='B')
        {
            con2++;
        }
        if(s[i][s[i].size()-1]=='A')
        con3++;
        if(s[i][0]=='B'&&s[i][s[i].size()-1]=='A')
        con4++;
    }
    if(con2==0&&con3==0&&con4==0)
    cout<<con1<<endl;
    else if(con2==con3&&con3==con4)
    cout<<con1+min(con2,con3)-1<<endl;
    else
    cout<<con1+min(con2,con3)<<endl;
   // cout<<con1<<" "<<con2<<" "<<con3<<" "<<con4<<endl;
    return 0;
    
}

Measured memory_bytes: 768
program C;
    var N,i,A:longint;
    var bo,ca:boolean;
    var Route:array[0..120000]of integer;
    var ans:longint;
begin
    fillchar(Route,sizeof(Route),0);
    readln(N);
    for i:=1 to N do
    begin
        read(A);
        if i=1 then if A mod 2=0 then bo:=true else bo:=false;
        Route[A div 2]:=Route[A div 2]+1;
    end;
    if bo then if Route[0]=1 then ca:=true else ca:=false else if Route[0]=2 then ca:=true else ca:=false;
    if ca then for i:=1 to ((N+1)div 2)-1 do if Route[i]<>2 then ca:=false;
    if ca then
    begin
        ans:=1;
        for i:=1 to N div 2 do ans:=(ans*2) mod 1000000007;
        writeln(ans)  
    end
    else writeln(0)
end.

Measured memory_bytes: 512
#include<iostream>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

struct pos{
  int y,x,p,q,d;
  pos(int A=0,int B=0,int C=0,int D=0,int E=0):y(A),x(B),p(C),q(D),d(E){}
};

int h,w,a;
string g[100];
int dis[100][100][11][11][4];
int dy[] = {1,0,-1,0}, dx[] = {0,-1,0,1};
const int INF = (int)(1e8);

int main(){
  cin >> h >> w >> a;
  rep(i,h)cin >> g[i];
  
  int sy,sx,gy,gx;
  rep(i,h)rep(j,w){
    rep(k,a+1)rep(l,a+1)rep(m,4)dis[i][j][k][l][m] = INF;
    if(g[i][j] == 'S'){
      sy = i; sx = j;
    }else if(g[i][j] == 'G'){
      gy = i; gx = j;
    }
  }

  deque<pos> que;
  if(sy+1<h){
    que.push_back(pos(sy+1,sx,a,a,0));
    dis[sy+1][sx][a][a][0] = 0;
  }
  rep(i,a+1)rep(j,a+1){
    dis[sy][sx][i][j][2] = -1;
  }

  int ans = -1;
  while(que.size()){
    pos P = que.front(); que.pop_front();
    int y = P.y, x = P.x, p = P.p, q = P.q, d = P.d;
    if(y==gy && x==gx){
      ans = dis[y][x][p][q][d];
      break;
    }

    if(g[y][x]=='#')continue;
    int ty = y+dy[d], tx = x+dx[d];
    if(ty>=0 && tx>=0 && ty<h && tx<w){
      if(dis[ty][tx][p][q][d] == INF){
	dis[ty][tx][p][q][d] = dis[y][x][p][q][d];
	que.push_front(pos(ty,tx,p,q,d));
      }
    }

    if(g[y][x]!='.')continue;
    if(p){
      int tp = p-1, tq = q, td = ((d&1)?(d+1)%4:(d+3)%4);
      ty = y+dy[td]; tx = x+dx[td];
      if(ty>=0 && tx>=0 && ty<h && tx<w){
	if(dis[ty][tx][tp][tq][td] > dis[y][x][p][q][d]+1){ 
	  dis[ty][tx][tp][tq][td] = dis[y][x][p][q][d]+1;
	  que.push_back(pos(ty,tx,tp,tq,td));
	}
      }
    }

    if(q){
      int tp = p, tq = q-1, td = ((d&1)?(d+3)%4:(d+1)%4);
      ty = y+dy[td]; tx = x+dx[td];
      if(ty>=0 && tx>=0 && ty<h && tx<w){
	if(dis[ty][tx][tp][tq][td] > dis[y][x][p][q][d]+1){ 
	  dis[ty][tx][tp][tq][td] = dis[y][x][p][q][d]+1;
	  que.push_back(pos(ty,tx,tp,tq,td));
	}
      }
    }
  }
  cout << ans << endl;
}
  

Measured memory_bytes: 19512
INF = 10 ** 9 + 7
N, K = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)

if K == 1:
    print(a[0])
    exit()

if K == N:
    ans = 1
    for i in a:
        ans *= i
        ans %= INF
    print(ans)
    exit()

if a[0] < 0:
    ans = 1
    if K % 2 == 1:
        for i in range(K):
            ans *= a[i]
            ans %= INF
    else:
        for i in range(K):
            ans *= a[-i - 1]
            ans %= INF
    print(ans)
    exit()

sei = []
hu = []
for i in a:
    if i >= 0:
        sei.append(i)
    else:
        hu.append(i)
hu.sort()
seis = []
hus = []
total = []
ans = 1

if K % 2 != 0:
    ans = sei[0] % INF
    for i in range(2, len(sei), 2):
        seis.append(sei[i] * sei[i - 1])
else:
    for i in range(1, len(sei), 2):
        seis.append(sei[i] * sei[i - 1])
for i in range(1, len(hu), 2):
    hus.append(hu[i] * hu[i - 1])

total = hus + seis
total.sort(reverse=True)
for i in range(K // 2):
    ans *= total[i]
    ans %= INF

print(ans)


Measured memory_bytes: 33200
a = Array.new(4, 0)

10.times do
  a[3] = gets.chomp.to_i
  3.times do |i|
    if a[2-i] < a[3-i]
      a[2-i], a[3-i] = a[3-i], a[2-i]
    else
      break
    end
  end
end

print a[0], "\n", a[1], "\n", a[2], "\n"



Measured memory_bytes: 6872