akhauriyash/Code-Regression huggingface dataset:
/*
** 散列算法的学习
*/

# include <cstdio>
# include <cstring>

static const int M = 1046527;

int n;
char H[M][14];

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

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

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

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

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

int main() {
	// freopen( "infile", "r", stdin );
	// freopen( "outfile", "w", stdout );
	char com[10], str[15];
	while (scanf( "%d", &n) != EOF ) {
		for ( int i = 0; i < n; i++ ) {
			scanf("%s %s", com, str);
			if ( com[0] == 'i' ) {
				insert(str);
			}
			else {
				if ( find(str) )
					printf("yes\n");
				else
					printf("no\n");
			}
		}
	}
	return 0;
}


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

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

        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadLong;
            var K = cin.ReadLong;

            long ans = 0;
            if(N > K){
                var array = new long[N];
                for(var i = 0 ;i<N;i++){
                    array[i] = cin.ReadLong;
                }
                Array.Sort(array);
                for(var i = 0 ;i<N-K;i++){
                    ans += array[i];
                }
            }

            WriteLine(ans);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream,char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }

        public string Read
        {
            get
            {
                if(inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for(int i = 0;i < tmp.Length;i++)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }

        
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }

}

Measured memory_bytes: 37120
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=1000000;
const int MOD=1000000007;
const int INV3=(MOD+1)/3;
void inc(int &a,int b) { if((a+=b)>=MOD) a-=MOD; }

int n;

int inv[MAXN+1];
int fac[MAXN+1];
int ifac[MAXN+1];
int C(int n,int k) { if(k<0||k>n) return 0; return (ll)fac[n]*ifac[k]%MOD*ifac[n-k]%MOD; }

int dp[MAXN+1][3];
int prob[MAXN+1];
int invp3[MAXN+1];


int solve() {
	inv[1]=1; FORE(i,2,n) inv[i]=(ll)(MOD-MOD/i)*inv[MOD%i]%MOD;
	fac[0]=1; FORE(i,1,n) fac[i]=(ll)fac[i-1]*i%MOD;
	ifac[0]=1; FORE(i,1,n) ifac[i]=(ll)ifac[i-1]*inv[i]%MOD;
	invp3[0]=1; FORE(i,1,n) invp3[i]=(ll)invp3[i-1]*INV3%MOD;

	REPE(i,n) REP(j,3) dp[i][j]=0; dp[0][0]=1;
	REP(i,n) REP(j,3) REP(k,3) if(j!=k) inc(dp[i+1][k],dp[i][j]);
	FORE(i,1,n) prob[i]=(ll)C(n,n-i)*dp[i][1]%MOD*invp3[n-1]%MOD;
	//printf("dp:"); REPE(i,n) printf(" %d",dp[i][1]); puts("");
	//printf("prob:"); REPE(i,n) printf(" %d",prob[i]); puts("");

	int ret=0;
	FORE(i,1,n) {
		int len=(ll)INV3*i%MOD*inv[n]%MOD;
		int fracsmallest=(ll)inv[i]*inv[i]%MOD;
		int cur=(ll)prob[i]*len%MOD*fracsmallest%MOD;
		inc(ret,cur);
	}
	return ret;
}

void run() {
	scanf("%d",&n);
	printf("%d\n",solve());
}

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


Measured memory_bytes: 31488
#include <iostream>
#include<string>
int main() {
	std::string s;
	while (std::cin >> s && s != "-")
	{
		int a, b;
		std::cin >> a;
		while (a--)
		{
			std::cin >> b;
			auto s1 = s.substr(0, b);
			auto s2 = s.substr(b, s.size() - b);
			s = s2 + s1;
		}
		std::cout << s << std::endl;
	}
	return 0;
}



Measured memory_bytes: 3152
#include <iostream>

using namespace std;

int main()
{
    int n, a, b, i, j, flag = 0;
    long long y;
    cin >> n;
    cin >> y;
    for(i = 0; i <= n; i++)
    {
        for(j = 0; j <= n; j++)
        {
            if((10000*i + 5000*j + 1000*(n-i-j) == y) && (n-i-j >= 0))
            {
                flag = 1;
                a = i;
                b = j;
            }
        }
    }
    if(flag != 1)
    {
        cout << "-1 -1 -1" << endl;
    }
    else
    {
        cout << a << " " << b << " " << n-a-b << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define maxn 300005
using namespace std;
const int mod = 998244353;
int n,N,p[maxn],E[maxn];
int Pow(int a,int b){int s=1;for(;b;b>>=1,a=1ll*a*a%mod) b&1&&(s=1ll*s*a%mod); return s;}
int upd(int x){return x+(x>>31&mod);}
void FWT(int *a,int len,int flg){
	for(int i=2,l=1,v;i<=len;l=i,i<<=1)
		for(int j=0;j<len;j+=i)
			for(int k=j;k<j+l;k++)
				v=a[k],a[k]=upd(v+a[k+l]-mod),a[k+l]=upd(v-a[k+l]);
	if(flg^1) for(int i=0,Inv=Pow(len,mod-2);i<len;i++) a[i]=1ll*a[i]*Inv%mod;
}
int main()
{
	scanf("%d",&n),N=1<<n; int s=0;
	for(int i=0;i<N;i++) scanf("%d",&p[i]),s=upd(s+p[i]-mod);
	s=Pow(s,mod-2);
	for(int i=0;i<N;i++) p[i]=1ll*p[i]*s%mod;
	FWT(p,N,1);
	for(int i=1;i<N;i++) E[i]=1ll*N*Pow(upd(p[i]-1),mod-2)%mod;
	FWT(E,N,-1);
	int x=mod-E[0];
	for(int i=0;i<N;i++) printf("%d\n",upd(E[i]+x-mod));
}

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

int main(){
  int n;
  cin >> n;
  
  if(n % 1000 == 0)cout << 0 << endl;
  else {
    int kake = n / 1000;
    cout << ((kake + 1) * 1000) - n << endl;
  }
}

Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
using namespace std;
static const int MAX = 200000;

int main() {
  int R[MAX], n;
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> R[i];

  int maxv = -2000000000;
  int minv = R[0];
  for (int i = 1; i < n; ++i) {
    maxv = max(maxv, R[i] - minv);
    minv = min(minv, R[i]);
  }

  cout << maxv << endl;
  return 0;
}

Measured memory_bytes: 3860
/*
 * @author Dhruvit
 */
#include<cstring>
#include<math.h>
#include<stdlib.h>
#include <fstream>
#include<algorithm>
#include<vector>
using namespace std;
#define fast ios::sync_with_stdio(false); cin.tie(0);cout.tie(0);
#include<bits/stdc++.h>
#define vi          vector<int>
#define vii         vector<vector<int>>
#define pii         pair<int,int>
#define pb          push_back
#define pf          push_front
#define all(v)      v.begin(),v.end()
class BTAKOYAKIFESTIVAL2019 {
public:
	void solve(std::istream& in, std::ostream& out) {
	    int n;
	    in>>n;
	    int a[n];
	    for(int i=0;i<n;i++){
	        in>>a[i];
	    }
	    int sum =0;
	    for(int i=0;i<n-1;i++){
	        for(int j=i+1;j<n;j++){
	            sum += a[i]*a[j];
	        }
	    }
        out<<sum;
	}
};


signed main() {
    fast;
	BTAKOYAKIFESTIVAL2019 solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

int main(){
  int N;
  cin>>N;
  int M=N;
  int x=0;
  for(int i=0;i<8;i++){
    x+=M%10;
    M/=10;
  }
  if(N%x==0){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}
    



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long n,k;
	cin>>n>>k;
	long long ar[n+1]={0};
	long long arr[n+1]={0};
	for(long long i=1;i<=n;i++){
		cin>>ar[i];
	}
	//arr[1]=ar[1];
	for(long long i=2;i<=n;i++){
		/*cout<<(abs(ar[i]-ar[i-1])+arr[i-1])<<" ";
		cout<<(abs(ar[i]-ar[i-2])+arr[i-2])<<endl;*/
		long long z=k;
		long long mi=9999999999;
		for(long long j=i;j>1&&z>0;j--,z--){
			mi=min(mi,(abs(ar[i]-ar[j-1])+arr[j-1]));
		}
		arr[i]=mi;
	}
	cout<<arr[n]<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(m), b(m);
    vector<vector<int>> c(m, vector<int>(n));
    vector<int> v(m);
    rep(i, m)
    {
        cin >> a[i] >> b[i];
        int sum = 0;
        rep(j, b[i])
        {
            cin >> c[i][j];
            c[i][j]--;
            sum += (1 << c[i][j]);
        }
        v[i] = sum;
    }
    int ans = INF;
    vector<int> dp(1 << n, INF);
    dp[0] = 0;
    rep(i, 1 << n)
    {
        int x = i;
        int ni = 0;
        int sum = 0;
        rep(j, m)
        {
            dp[i | v[j]] = min(dp[i | v[j]], dp[i] + a[j]);
        }
    }
    if(dp[(1 << n) - 1] == INF){
        cout << -1 << endl;
        return 0;
    }else{
        cout << dp[(1<<n)-1] <<"\n";
        return 0;
    }
}

Measured memory_bytes: 384
#include<iostream>
#include <stdio.h>
#include<string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstdint>
#include <map>
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main(){

int n,a;

cin >> n;
cin >> a;

if(n % 500 <= a) cout << "Yes" << endl;
else                    cout << "No" << endl;

return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIII pair< int, pair<int,int> >
const int MXN = 1e5;
const int INF = 1e9;
int a[MXN+5];
ll dp[MXN+5];
int N;

ll rec(int pos){

    if(pos==N) return 0;
    if(dp[pos]!=-1) return dp[pos];
    ll ret = INF;
    for(int i=1; i<=2; i++){
        int next = pos + i;
        if(next<=N){
            ret = min( ret , (ll) rec(next) + abs(a[next]-a[pos]) );
        }
    }

    return dp[pos]=ret;
}

void solve(){

    cin>>N;
    memset(dp,-1,sizeof(dp));
    for(int i=1; i<=N; i++) cin>>a[i];
    cout<< rec(1) << "\n";
}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
}


Measured memory_bytes: 6144
from itertools import product


ABCD = list(input())

OPERATIONS = list(product("+-", repeat = 3))

for operation in OPERATIONS:
    for i in range(3):
        ABCD.insert(2 * i + 1, operation[i])
    if eval("".join(ABCD)) == 7:
        print("".join(ABCD) + "=7")
        exit()
    for i in range(3)[::-1]:
        ABCD.pop(2 * i + 1)


Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <algorithm>
#include <deque>
#include <vector>

typedef long long ll;
using namespace std;

int main(){
  int n;
  string str;
  int i, j, k;

  cin >> n;
  cin >> str;
  int sw[n];
  int tmp;


  sw[0] = 1; sw[1] = -1;
  if(str[0]=='o'){
    tmp = -1;
  }else{
    tmp = 1;
  }
  for(i = 1; i < n-1; i++){
    if(str[i] == 'o'){
      if(sw[i] == 1){
        sw[i+1] = sw[i-1];
      }else{
        sw[i+1] = sw[i-1] * -1;
      }
    }else{
      if(sw[i] == 1){
        sw[i+1] = sw[i-1] * -1;
      }else{
        sw[i+1] = sw[i-1];
      }
    }
  }
  if(sw[n-1] == tmp && ((str[n-1] == 'o' && sw[0] * sw[n-2] * sw[n-1] == 1) || (str[n-1] == 'x' && sw[0] * sw[n-2] * sw[n-1] == -1)) ){
    for(i = 0; i < n; i++){
      if(sw[i] == 1){
        cout << 'S';
      }else{
        cout << 'W';
      }
    }
    cout << endl;
    return 0;
  }

  sw[0] = -1; sw[1] = 1;
  if(str[0]=='o'){
    tmp = -1;
  }else{
    tmp = 1;
  }
  for(i = 1; i < n-1; i++){
    if(str[i] == 'o'){
      if(sw[i] == 1){
        sw[i+1] = sw[i-1];
      }else{
        sw[i+1] = sw[i-1] * -1;
      }
    }else{
      if(sw[i] == 1){
        sw[i+1] = sw[i-1] * -1;
      }else{
        sw[i+1] = sw[i-1];
      }
    }
  }
  if(sw[n-1] == tmp && ((str[n-1] == 'o' && sw[0] * sw[n-2] * sw[n-1] == 1) || (str[n-1] == 'x' && sw[0] * sw[n-2] * sw[n-1] == -1)) ){
    for(i = 0; i < n; i++){
      if(sw[i] == 1){
        cout << 'S';
      }else{
        cout << 'W';
      }
    }
    cout << endl;
    return 0;
  }

  sw[0] = 1; sw[1] = 1;
  if(str[0]=='o'){
    tmp = 1;
  }else{
    tmp = -1;
  }
  for(i = 1; i < n-1; i++){
    if(str[i] == 'o'){
      if(sw[i] == 1){
        sw[i+1] = sw[i-1];
      }else{
        sw[i+1] = sw[i-1] * -1;
      }
    }else{
      if(sw[i] == 1){
        sw[i+1] = sw[i-1] * -1;
      }else{
        sw[i+1] = sw[i-1];
      }
    }
  }
  if(sw[n-1] == tmp && ((str[n-1] == 'o' && sw[0] * sw[n-2] * sw[n-1] == 1) || (str[n-1] == 'x' && sw[0] * sw[n-2] * sw[n-1] == -1)) ){
    for(i = 0; i < n; i++){
      if(sw[i] == 1){
        cout << 'S';
      }else{
        cout << 'W';
      }
    }
    cout << endl;
    return 0;
  }

  sw[0] = -1; sw[1] = -1;
  if(str[0]=='o'){
    tmp = 1;
  }else{
    tmp = -1;
  }
  for(i = 1; i < n-1; i++){
    if(str[i] == 'o'){
      if(sw[i] == 1){
        sw[i+1] = sw[i-1];
      }else{
        sw[i+1] = sw[i-1] * -1;
      }
    }else{
      if(sw[i] == 1){
        sw[i+1] = sw[i-1] * -1;
      }else{
        sw[i+1] = sw[i-1];
      }
    }
  }
  if(sw[n-1] == tmp && ((str[n-1] == 'o' && sw[0] * sw[n-2] * sw[n-1] == 1) || (str[n-1] == 'x' && sw[0] * sw[n-2] * sw[n-1] == -1)) ){
    for(i = 0; i < n; i++){
      if(sw[i] == 1){
        cout << 'S';
      }else{
        cout << 'W';
      }
    }
    cout << endl;
    return 0;
  }

  cout << -1 << endl;



  return 0;
}


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

typedef long long ll;


int main() {
ll n,k,a[15],m=1e18;
cin>>n>>k;
for(int i=0;i<n;i++){
    cin>>a[i];
}
for(int i=0;i<(1<<(n-1));i++){
    ll r=a[0],c=1,d=0;
    for(int j=0;j<n-1;j++){
        if(((i>>j)&1)==1){
            d+=max((ll)0,r-a[j+1]+1);
            r=max(r+1, a[j+1]);
            c++;
        }else if(a[j+1]>r){
          j=n;
          c=0;
        }
    }
    if(c>=k){
        m=min(m,d);
    }
}
cout<<m<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  // freopen("input.txt", "r", stdin);
  string a, b;
  cin >> a >> b;
  int k = b.length();
  int ans = 1e5;
  for(int i = 0; i + k <= (int)a.length(); i++){
    int cnt = 0;
    for(int j = i, n = 0; b[n]; j++, n++){
      cnt += a[j] != b[n];
    }
    ans = min(cnt, ans);
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()
// #define DEBUG 10
 
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
 
const int oo = 1e9 + 7;
const ll mod = 1e9 + 7, maxn = 500050;
const double PI = acos(-1);
 
vector<int> p(maxn, 0);
void init(int n){
    for (int i=0; i<=n; i++){
        p[i] = i;
    }
}
int main (){
    ios_base::sync_with_stdio(false);
    ll x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;

    vector<ll> r(a), g(b), u(c);
    priority_queue<ll> res;

    for (auto &x: r) cin >> x;
    for (auto &x: g) cin >> x;
    for (auto &x: u) cin >> x;
    sort(all(r));
    sort(all(g));
    sort(all(u));

    while (x--){
        res.push( - r.back());
        r.pop_back();
    }

    while (y--){
        res.push( -g.back());
        g.pop_back();
    }

    
    while (!u.empty()){
        x = u.back();
        u.pop_back();
        y = -res.top();
        res.pop();
        res.push(-max(x, y));
    }

    ll ans = 0;

    while (!res.empty()){
        ans += -res.top();
        res.pop();
    }

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

Measured memory_bytes: 9632
N = gets.to_i
arr1 = gets.split.map(&:to_i)
arr2 = gets.split.map(&:to_i)

max = route = arr1[0] + arr2.inject(:+)

for i in 0...N-1 do
  route += arr1[i+1]-arr2[i]
  max = [max, route].max
end
puts max

Measured memory_bytes: 1788
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<stdio.h>
using namespace std;

int main(){
    double r;
    cin >> r;
    //cout << r*r*M_PI << " " << 2.0*r*M_PI << endl;
    printf("%f %f\n",r*r*M_PI,2.0*r*M_PI);
}


Measured memory_bytes: 3204
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <list>
#include <ctime>
#include <sstream>
#include <queue>
#include <stack>
#include <random>
#include <bitset>
#include <numeric>
#include <cassert>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
#define rep(x, b, e) for(int x=(b); x<(e); ++x)
#define ford(x, b, e) for(int x=((int)(b))-1; x>=(e); --x)
#define all(c) c.begin(),c.end()
#define sz(x) ((int)((x).size()))
#define pb push_back
#define st first
#define nd second
#define mp(x,y) make_pair(x,y)
typedef short int sint;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it) {
	*this << ((it != d.b) ? ", " : "") << *it;
  }
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int nax = 2e5+10;
pii wyd[2 * nax];
int n;

int main() {
	ios_base::sync_with_stdio(false);
	cin >> n;
	rep(i, 0, n) {
		cin >> wyd[2*i].st >> wyd[2*i + 1].st;
		wyd[2*i].nd = -1;
		wyd[2*i+1].nd = 1;
	}
	sort(wyd, wyd + (2*n));
	int juzZamk = 0;
	int otw = 0;
	int wsk = 0;
	if (n % 2 == 1) {
		int s1 = -1, s2 = -1;
		while (wsk < 2*n) {
			if (wyd[wsk].nd == -1) {
				++otw;
				if (otw == (n - 1) / 2 + 1) {
					s1 = wyd[wsk].st;
				}
			} else {
				++juzZamk;
				if (juzZamk == (n - 1) / 2 + 1) {
					// printf("juz zamk: %d, t: %d\n", juzZamk, wyd[wsk].st);
					s2 = wyd[wsk].st;
					break;
				}
			}
			++wsk;
		}
		// printf("%d %d\n", s1, s2);
		cout << s2 - s1 + 1 << endl;
	} else {
		int s1 = -1, z1 = -1;
		int s2 = -1, z2 = -1;
		while (wsk < 2 * n) {
			if (wyd[wsk].nd == -1) {
				++otw;
				if (otw == (n - 1) / 2 + 1) {
					s1 = wyd[wsk].st;
				} else if (otw == ((n-1)/2 + 2)) {
					z1 = wyd[wsk].st;
				}
			} else {
				++juzZamk;
				if (juzZamk == (n - 1) / 2 + 1) {
					s2 = wyd[wsk].st;
				} else if (juzZamk == (n-1)/2 + 2) {
					z2 = wyd[wsk].st;
					// break;
				}
			}
			++wsk;
		}
		// printf("%d,%d oraz %d,%d\n", s1,z1, s2,z2);
		int minVal = s1 + s2, maxVal = z1 + z2;
		// printf("%d %d\n", minVal, maxVal);
		cout << maxVal - minVal + 1 + (s2 - z1)*2 << endl;
	}
}

Measured memory_bytes: 6768
#include<bits/stdc++.h>
using namespace std;
long long n,s,cnt,i;
inline int gcd(int x,int y) {
	if(!y) return x;
	return gcd(y,x%y);
}
int main() {
	cin>>n;
    for(int i=1;i<=n;++i) 
    for(int j=1;j<=n;++j) 
    for(int k=1;k<=n;++k) s+=gcd(gcd(i,j),k);
    cout<<s;
	return 0;
}

Measured memory_bytes: 3624
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String input;
		while((input = br.readLine()) != null){
			System.out.println(input.toUpperCase());
		}
	}

}

Measured memory_bytes: 16852
/**
*    author:  yuya1234
*    created: 24.06.2020 16:08:27
**/

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    int n,nn,ans;
    cin>>n;

    nn=2;
    while(n>=nn)
    {
        nn*=2;
    }

    cout<<nn/2<<endl;

    return 0;
}

Measured memory_bytes: 3616
#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;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

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)...);}

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

	map<int,int> c;
	char str[1300];
	char ch;
	while((ch=getchar())!=EOF){
		if(ch>='A' && ch<='Z'){
			ch = tolower(ch);
		}
		if(ch>='a' && ch<='z'){
			c[ch-'a']++;
		}
	}
	REP(i,26){
		out((char)('a'+i),':',c[i]);
	}

	return 0;
}



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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

signed main() {
  ll a,b;
  cin >> a >> b;
  cout << max(a-2*b, (ll)0) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for(int (i) = (m); (i) < (n); (i)++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

int main()
{	
	int a, b;
	cin >> a >> b;
	int ans = 0;
	if(a>2*b) ans = a-2*b;
	cout << ans << endl;
}


Measured memory_bytes: 256
s = input()
p = int(input())

dir = 0
mae = []
usi = []

for _ in range(p):
  Q = input().split()
  if Q[0] == "1":
    dir = not dir
  else:
    if (int(Q[1]) - 1) == dir:
      mae.append(Q[2])
    else:
      usi.append(Q[2])
      
ans = "".join(mae[::-1]) + s + "".join(usi)
      
if not dir:
  print(ans)
else:
  print(ans[::-1])

Measured memory_bytes: 12200
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq
import itertools
import operator


inf = float('inf')


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types):
    if len(types) == 1:
        return [types[0](input()) for _ in range(n)]
    return zip(*(
        [t(x) for t, x in zip(types, input().split())]
        for _ in range(n)
    ))


# inputs
S = ""


def set_inputs():
    global S
    S = get_str()
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    ans = 0
    tmp = 0
    for c in S:
        if c in "ACGT":
            tmp += 1
            ans = max(ans, tmp)
        else:
            tmp = 0
    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size,n=1,init=nil) #nに配列の次元数、sizeに配列の大きさ、initに初期値を投げることでその配列を返す
  if n==1
    return Array.new(size){init}
  else
    return Array.new(n).map{Array.new(size){init}}
  end
end

while true
    h,w=get_i
    break if h.zero? and w.zero?
    h.times do|i|
        w.times do|j|
            if i.zero? or i==h-1 or j.zero? or j==w-1
                print("#")
            else
                print(".")
            end
        end
        print "\n"
    end
    print "\n"
end


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

using namespace std;

using ll = long long;

int main(){
    ll a, b, n;
    cin >> a >> b >> n;
    if(n >= b){
        cout << floor((a * (b - 1) / b)) - a * floor((b - 1) / b);
    }
    else cout << floor((a * n) / b) - a * floor(n / b);
    return 0;
}


Measured memory_bytes: 3784
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>

using namespace std;

bool isPrime[1000001];
bool dp[1000001];
int main()
{
	fill(isPrime, isPrime+1000001, true);
	isPrime[0] = isPrime[1] = false;
	for (int i = 2; i < 1000001; ++i)
	{
		if (isPrime[i])
		{
			for (int j = 2*i; j < 1000001; j += i)
				isPrime[j] = false;
		}
	}

	int n, x;
	while (scanf("%d %d", &n, &x), n | x)
	{
		int v[30];
		for (int i = 0; i < n; ++i)
		{
			int t;
			scanf("%d", &t);
			v[i] = t;
		}

		fill(dp, dp+x+1, false);
		dp[0] = true;
		for (int i = 0; i <= x; ++i)
			if (dp[i])
				for (int j = 0; j < n; ++j)
					if (i + v[j] <= x)
						dp[i + v[j]] = true;

		int ans;
		for (ans = x; ans > 0; --ans)
			if (dp[ans] && isPrime[ans])
				break;
		if (ans)
			printf("%d\n", ans);
		else
			puts("NA");
	}

	return 0;
}

Measured memory_bytes: 2832
N = int(input())

# dp[i]: ちょうどi円を引き出すために必要な操作の最小回数
dp = [0] * (N + 1)

MAX = 10 ** 8

for i in range(1, N + 1):
    # 1
    dp1 = dp[i - 1] + 1

    # 6, 6 ** 2, 6 ** 3,...
    dp6 = MAX
    i6 = 1
    while 6 ** i6 <= i:
        dp6 = min(MAX, dp[i - 6 ** i6] + 1)
        i6 += 1

    # 9, 9 ** 2, 9 ** 3,...
    dp9 = MAX
    i9 = 1
    while 9 ** i9 <= i:
        dp9 = min(MAX, dp[i - 9 ** i9] + 1)
        i9 += 1

    dp[i] = min(dp1, dp6, dp9)

print(dp[N])


    



Measured memory_bytes: 74104
/**
    In the name of Allah, the Most Gracious, the Most Merciful.
**/

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

typedef long long ll;

ll ara[100000];

int main() {
    #ifdef _OFFLINE_
        freopen("in.txt", "r", stdin);
    #endif /// _OFFLINE_

    ll n;
    cin >> n;
    ara[0] = 2;
    ara[1] = 1;
    for(int i=2; i<=n; i++) {
        ara[i] = ara[i-1] + ara[i-2];
    }
    cout << ara[n] << "\n";

    return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;
typedef pair<int,int> pii;
int MOD = 998244353;

signed main(){
    int n;
    cin >> n;
    int maxi = -1;
    int cnt = 0;
    rep(i,n){
        int h;
        cin >> h;
        if(maxi <= h){
            cnt++;
            maxi = h;
        }
    }
    cout << cnt << endl;
    
    
     
    return 0;
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://cf17-final-open.contest.atcoder.jp/tasks/cf17_final_a
// rm -r -f test;oj dl http://abc124.contest.atcoder.jp/tasks/abc124_a


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip>
using namespace std;
#define int long long


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

    int n,k; cin >> n >> k;
    int ans = 0;
    int x = 1000000007;

    for(int i = k;i < n+2;i ++){
        int sum = 0;
        int SUM = 0;
        
        sum = (i-1) * i / 2;
        SUM = (2 * n - i + 1) * i / 2;

        ans += SUM - sum + 1;
        ans %= x;
    }

    cout << ans << endl;
}



Measured memory_bytes: 3660
from sys import stdin

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

for k in range(N):
    A[k] -= k

A.sort()


def get_pity_sum(x):
    pity_sum = 0
    for l in A:
        if A[x] - l >= 0:
            pity_sum += A[x] - l
        else:
            pity_sum += l - A[x]
    return pity_sum


if N % 2 == 1:
    c = get_pity_sum(int((N - 1) / 2))
    if N == 1:
        print(c)
    else:
        print(min(c, get_pity_sum(int((N - 1) / 2 - 1)), c + (A[int((N - 1) / 2) + 1] - A[int((N - 1) / 2)]) * 2, c + (A[int((N - 1) / 2)] - A[int((N - 1) / 2 - 1)]) * 2))
else:
    d = get_pity_sum(int(N / 2))
    print(min(get_pity_sum(int(N / 2)), d + (A[int(N / 2) + 1] - A[int(N / 2)]) * 2))

Measured memory_bytes: 25836
#include <bits/stdc++.h>
#define N 1000005
#define mod 1000000007

using namespace std;

int n,m;
int f[N];
bool vis[N];

int main(){
	cin >> n >> m;f[0] = 1;
	for(int i = 1; i <= m; ++i){
		int a;cin >> a;
		vis[a] = true;
	}
	for(int i = 0; i <= n; ++i){
		if(!vis[i + 1]) (f[i + 1] += f[i]) %= mod;
		if(!vis[i + 2]) (f[i + 2] += f[i]) %= mod;
	}
	cout << f[n];
	return 0;
}

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

int main(void)
{
    int N,C,K,cnt = 0,cust = 0,time = 0;
    cin >> N >> C >> K;

    vector<int> T(N);

    rep(i, N){
        cin >> T[i];
    }

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

    cust++;
    time = T[0];
    for(int i = 1;i < N;i++){
        
        if(cust == C || time+K < T[i]){
            cust = 0;
            time = T[i];
            cnt++;
        }
        cust++;
    }
    
    if(cust > 0)
        cnt++;

    cout << cnt << endl;

    return 0;
}

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

using namespace std;

bool binary_search(unsigned item, vector<unsigned> *seq, unsigned start, unsigned stop)
{
    if (stop - start == 0)
    {
        return false;
    }

    if (stop - start == 1)
    {
        return item == seq->at(0);
    }

    unsigned mid = (start + stop) / 2;
    if (item == seq->at(mid))
    {
        return true;
    }
    else if (item < seq->at(mid))
    {
        return binary_search(item, seq, start, mid);
    }
    else
    {
        return binary_search(item, seq, mid, stop);
    }
}

int main()
{
    unsigned n;
    cin >> n;
    vector<unsigned> S(1);
    cin >> S.at(0);
    for (unsigned _ = 0; _ < n - 1; _++)
    {
        unsigned s;
        cin >> s;
        if (s != S.back())
        {
            S.push_back(s);
        }
    }

    unsigned q;
    cin >> q;
    vector<unsigned> T(q);
    for (unsigned i = 0; i < q; i++)
    {
        cin >> T.at(i);
    }

    unsigned ans = 0;
    for (unsigned t : T)
    {
        if (binary_search(t, &S, 0, S.size()))
        {
            ans++;
        }
    }
    cout << ans << endl;
}



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

int main(){
    int n;
    cin>>n;
    if(n<100) cout<<min(9,n);
    else if(n<1000) cout<<n-90;
    else if(n<10000) cout<<909;
    else if(n<100000) cout<<n-9090;
    else cout<<90909;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    vector<int> a(3);
    for(int i = 0; i < 3; i++)
    {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    cout << a[2] * 10 + a[1] + a[0] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
int main(){
    ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    vector<int> s(m), c(m);
    rep(i, m) cin >> s[i] >> c[i];
    
    int st = 1, end;
    if( n == 1){
        st = 0;
        end = 9;
    } else {
        rep(i,n-1) st*=10;
        end = st*10-1;
    }

    auto bit_num = [](int n,int bit) {
        int dig = 1;
        rep(i,bit-1) dig*=10;
        return (n%(dig*10))/dig;
    };
    for(int i = st; i <= end; i++) {
        bool end = false;
        rep(j,m) {
            if(bit_num(i,n-s[j]+1) != c[j]) end = true;;
        }
        if(end) continue;
        cout << i << endl;
        return 0;
    }
    cout << -1 << endl;
}


Measured memory_bytes: 256
fn main() {
    let mut v: Vec<String> = Vec::new();
    loop {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).ok();
        let va = s.trim();
        if va == "0" {break;}
        v.push(va.to_string());
    }
    for (i, w) in v.iter().enumerate() {
        if w == "0" { break;}
        println!("Case {}: {}", i + 1, w);
    }

}



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

int main(){
    int x;
    cin >> x;
    int n=x;
    int sam=0;
    while(x>0){
        sam += x%10;
        x /= 10;
    }
    if(n%sam==0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const int mod = 1e9+7;
const ll INF = 1e18;
const int inf = 1e8;

void solve()
{
  int a,b; cin>>a>>b;
  cout << (a+b)%24 << endl;
}

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


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt(),t,m=Integer.MAX_VALUE,te[]=new int[300000],tw[]=new int[300000],i;
		String s=new String();
		s=sc.next();
		sc.close();
		if(s.charAt(0)=='E') te[0]++;
		else tw[0]++;
		for(i=1;i<n;i++) {
			if(s.charAt(i)=='E') {
				te[i]=te[i-1]+1;
				tw[i]=tw[i-1];
			}
			else {
				te[i]=te[i-1];
				tw[i]=tw[i-1]+1;
			}
		}
		for(i=0;i<n;i++) {
			t=te[n-1]-te[i];
			if(i>0) t+=tw[i-1];
			if(m>t) m=t;
		}
		System.out.print(m);
	}
}

Measured memory_bytes: 31536
#include<iostream>
#include<cstdio>
#include<string>
#include<math.h>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<map>
#include<numeric>
#include<stack>
#include<queue>
#include<functional>
#include<cassert>
#include<set>
#include<time.h>
#include<cmath>
#include<functional>
#include<cassert>
#define rep(a,b) for(ll a=0;a<b;++a)
#define REP(a,b,c,d) for(ll a=b;a<c;a+=d)
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
#define mod 1000000007
using namespace std;
using ll = long long;
using p_i = pair<int, int>;
int main() {
    string S;cin>>S;
    stack<char> st;
    ll ans=0;
    ll n=S.size(); 
    rep(i,n){
        if(S[i]=='S')st.push('S');
        else if(S[i]=='T'&&st.empty()!=true){
            st.pop();
            ans+=2;
        }
    }
    cout<<n-ans<<endl;
}

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

void solve(std::istream &in, std::ostream &out);

int main() {
#ifdef LOCAL
  freopen("../IO/d.in", "r", stdin);
//  freopen("../IO/d.out", "w", stdout);
#else
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
#endif
  solve(std::cin, std::cout);
  return 0;
}

constexpr int N = (int)2e5 + 1555;
char s[N];
int sm[N], cnt[N], p[N];

void solve(std::istream &in, std::ostream &out) {
  in >> (s + 1);
  int n = strlen(s + 1);
  int64_t ans = 0;
  int p1 = 1;
  cnt[0]++;
  for (int i = n; i >= 1; --i) {
    sm[i] = (p1 * (s[i] - '0') + sm[i + 1]) % 2019;
    p1 = p1 * 10 % 2019;
    ans += cnt[sm[i]]++;
  }
  out << ans << '\n';
}



Measured memory_bytes: 4656
#include <stdio.h>
#include<stdlib.h>
int main(void){
    int H,W,A[101][101],b,c,d,j,i,t=0,sss=0;
    scanf("%d %d",&H,&W);
    for(b=1;b<=H;b++){
        for(c=1;c<=W;c++){
            scanf("%d",&d);
            A[b][c]=d;
        };
    };
    for(b=1;b<=H;b++){
        for(c=1;c<=W;c++){
           for(j=1;j<=H;j++){
              for(i=1;i<=W;i++){
               if(abs(j-b)<=abs(i-c)){
                   t+=A[j][i]*abs(j-b);
               }else{t+=A[j][i]*abs(i-c);}; 
              };
           };if((t<=sss)||((b==1)&&(c==1))){sss=t;};
           t=0;
        };};
    printf("%d\n",sss);
    return 0;
}


Measured memory_bytes: 2120
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int n,a,b;
  cin >> n >> a >> b;
  if(a*n >= b) cout << b << endl;
  else cout << a*n<< endl;
  }


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

struct SegTree {
  SegTree *sl, *sr; // left & right child.
  int l, r;         // the interval of current node.
  ll sum;           // the sum of elements in this node.

  SegTree(int *init, int l, int r) : l(l), r(r) {
    if (l == r) {
      sum = init[l];
      return;
    }

    int m = l + r >> 1;

    // create the two nodes.
    sl = new SegTree(init, l, m);
    sr = new SegTree(init, m + 1, r);

    // calculate the current node.
    sum = sl->sum + sr->sum;
  }

  // query the sum of a[ql..qr]
  int query(int ql, int qr) {
    // current node is exactly what is needed
    if (ql == l && qr == r)
      return sum;

    int m = l + r >> 1;

    if (qr <= m) // query range is in left node
      return sl->query(ql, qr);
    else if (ql > m) // query range is in right node
      return sr->query(ql, qr);
    else // query range crosses both nodes
      return sl->query(ql, m) + sr->query(m + 1, qr);
  }

  // set a[k] = v
  void update(int k, int v) {
    // current node is exact match
    if (l == r && l == k) {
      sum = v;
      return;
    }

    int m = l + r >> 1;

    if (k <= m) // updated node is on the left
      sl->update(k, v);
    else // updated node is on the right
      sr->update(k, v);

    // recalculate current node
    sum = sl->sum + sr->sum;
  }
};

int arr[100005];

int main() {
  // write your solution here...
  int n, q;
  cin >> n >> q;
  SegTree *seg = new SegTree(arr, 1, n);
  for (int i = 0; i < q; i++) {
    int q, x, y;
    cin >> q >> x >> y;
    if (q == 0) {
      seg->update(x, seg->query(x, x) + y);
    } else {
      cout << seg->query(x, y) << endl;
    }
  }
}


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

int main(){
    string s, t, ans;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<char>());
    int i = 0;
    while(i < s.size()){
        if(s[i]-'a'==t[i]-'a'){
            if(i == s.size()-1 && s.size() < t.size()) ans = "Yes";
            else if(i == s.size()-1 && s.size() >= t.size()) ans = "No";
            ++i;
        }
        else if(s[i]-'a'<t[i]-'a'){
            ans = "Yes";
            break;
        }
        else{
            ans = "No";
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

string s;
int dfs(int &pos, bool &is_leaf) {
	vector<int> tok;
	bool loc_is_leaf = false;

	// consume [
	pos++;
	//cerr << "Consume expect [: " << s[pos - 1] << ", next: " << s[pos] << endl;

	while (s[pos] != ']') {
		if (isdigit(s[pos])) {
			//cerr << "Branch 1 " << pos << endl;
			string x;
			while (isdigit(s[pos])) x += s[pos++];
			pos++;
			//cerr << "Returns: " << stoi(x) << endl;
			is_leaf = true;
			return stoi(x);
		} else if (s[pos] == '[') {
			//cerr << "Branch 2 " << pos << endl;
			int v;
			tok.push_back(v = dfs(pos, loc_is_leaf));
			//cout << v << endl;
		}
	}

	// consume ]
	pos++;

	sort(all(tok));
	int x = 0;

	//cout << "Tokens: ";
	//for (int h : tok) cout << h << " ";
	//cout << endl;

	for (int i = 0; i <= tok.size() / 2; i++) {
		if (loc_is_leaf) x += (tok[i] + 1) / 2;
		else x += tok[i];
	}
	return x;
}

int main() {
	int n; cin >> n;
	rep(i, 0, n) {
		cin >> s;
		int p = 0; bool dummy = false;
		cout << dfs(p, dummy) << endl;
	}
}



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

int main() {
	int ab, two = 0, three = 0;
	for (int i = 0; i < 6; ++i) {
		cin >> ab;
		if (ab == 2) ++two;
		else if (ab == 3) ++three;
	}
	if (two == 2 && three == 2) cout << "YES";
	else cout << "NO";
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cassert>
using namespace std;
using P = pair<int, int>;
using VP = vector<P>;

int main() {
    int n, m;
    cin >> n >> m;
    VP v;
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        v.push_back(P(a, b));
    }
    sort(v.begin(), v.end());
    
    VP w;
    w.push_back(v.front());
    for (int i = 1; i < m; i++) {
        int ind = lower_bound(w.begin(), w.end(), v[i]) - w.begin();
        assert(ind > 0);
        if (v[i].first < w[ind - 1].second) {
            w[ind - 1].first = v[i].first;
            w[ind - 1].second = min(w[ind - 1].second, v[i].second);
            continue;
        }
        assert(ind == w.size());
        w.push_back(v[i]);
    }
    cout << w.size() << endl;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
int main(){
  int N;
  long long ans=0;
  cin>>N;
  long long A[N+1],B[N];
  for(int i=0;i<N+1;i++) cin>>A[i];
  for(int i=0;i<N;i++) cin>>B[i];
  for(int i=0;i<N;i++){
    int x;
    x=min(A[i],B[i]);
    ans+=x;
    B[i]-=x;
    x=min(A[i+1],B[i]);
    ans+=x;
    A[i+1]-=x;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1792
n = int(input())
A = list(map(int,input().split()))
q = int(input())
m = list(map(int,input().split()))
sumA = sum(A)
def solve(i,m):
    if m == 0:
        return 1
    if i >= n:
        return 0
    rec =  solve(i+1,m) or solve(i+1, m - A[i])
    return rec
for i in m:
    if i >= sumA:
        print("no")
    else:
        if solve(0,i):
            print("yes")
        else:
            print("no")


Measured memory_bytes: 5620
import math
a=int(input())
b=int(math.sqrt(a))+1

print(str(a)+":",end="")
for i in range(2,b):
    while a%i==0:
        print(" "+str(i),end="")
        a=a//i
if a!=0 and a!=1:
    print(" "+str(a),end="")
print()



Measured memory_bytes: 5660
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int A, B;
  cin>>A>>B;
  cout<<(A+B)%24<<endl;
}


Measured memory_bytes: 3552
S=str(input())
T=str(input())


U=[0]*(len(S)-len(T)+1)
c=[0]*(len(S)-len(T)+1)
for j in range(len(S)-len(T)+1):
    U[j]=S[j:j+len(T)]
    for i in range(len(T)):
        if U[j][i]==T[i] :c[j]=c[j]+1

print(len(T)-max(c))

Measured memory_bytes: 9208
N,M = gets.split.map(&:to_i)
switch = []
M.times do
  switch << gets.split.map(&:to_i)
end
mods = gets.split.map(&:to_i)
ans = 0
(2**N).times do |i|
  light = [0]*(M)
  flg = true
  M.times do |j|
    tmp = 0
    switch[j][0].times do |k|
      s = switch[j][k+1]
      tmp += 1 if i & (2**(s-1)) > 0
    end
    flg = false if tmp % 2 != mods[j]
    #p [i,j,flg,tmp]
  end
  ans += 1 if flg
end
p ans

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define print(obj) cout << obj << endl
#define scan(obj) cin >> obj

typedef long long ll;

using namespace std;

int main(void){
    int n;
    cin >> n;
    int h[n], min[n];
    bool used[n] = {false};
    vector<int> temp;
    rep(i, n){
        cin >> h[i];
        temp.pb(h[i]);
    }
    sort(ALL(temp));
    rep(i, n){
        rep(j, n){
            if(used[j]) continue;
            if(temp[i] == h[j]){
                used[j] = true;
                min[i] = j;
                break;
            }
        }
    }
    int ans = 0;
    rep(i, n){
        int right = 1, left = 1;
        bool flag1 = true, flag2 = true;
        while(true){
            if(min[i] + right > n){
                flag1 = false;
            }
            if(min[i] - left < 0){
                flag2 = false;
            }
            if((h[min[i]] <= h[min[i] + right]) && flag1){
                h[min[i] + right] -= h[min[i]];
                right++;
            } else{
                flag1 = false;
            }
            if((h[min[i]] <= h[min[i] - left]) && flag2){
                h[min[i] - left] -= h[min[i]];
                left++;
            } else{
                flag2 = false;
            }
            if(!flag1 && !flag2){
                ans += h[min[i]];
                h[min[i]] = 0;
                break;
            }
        }
    }
    print(ans);
}

Measured memory_bytes: 256