akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
//long long
using ll = long long;
 
// pair<int, int>
using PII = pair<int, int>;
 
//最大値、mod
const int MOD = 1000000007;
const int INF = 1000000000;
const long long LINF = 1e18;
const int MAX = 510000;
 
//出力系
#define print(x) cout << x << endl
#define prints(x) cout << fixed << setprecision(10) << x << endl
#define printc(x) cout << setw(2) << setfill('0') << x << endl;
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()
 
//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
 
//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
 
// 最小公倍数
unsigned lcm(unsigned a, unsigned b){
    return a / gcd(a, b) * b; 
}
 
// a = max(a, b), a = min(a, b)
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; }
 
// 階乗(MODをとる)
ll pow_mod(ll num, ll pow, ll mod) {
    ll prod = 1;
    num %= mod;
    while (pow > 0) {
        if (pow & 1) prod = prod * num % mod;
        num = num * num % mod;
        pow >>= 1;
    }
    return prod;
}
 
 
 
// 二項係数(MODとる、1 ≦ k ≦ n ≦ 10^7 程度)
// COMinit()
// COM(x, y)
// とコンビで使う
 
// テーブルを作る前処理
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
//int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};


int main(){
    int N;
    cin >> N;
    int F[N][10];
    REP(i, N)REP(j, 10) cin >> F[i][j];
    int P[N][11];
    REP(i, N)REP(j, 11)  cin >> P[i][j];
    ll ans = -LINF;
    for(int bit = 1; bit < (1 << 10); bit++){
        ll sum = 0;
        for(int i = 0; i < N; i++){
            int cnt = 0;
            for(int j = 0; j < 10; j++) if(bit & (1 << j) && F[i][j]) cnt++;
            sum += P[i][cnt];
        }
        chmax(ans, sum);
    }
    print(ans);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
#define N 220000
using namespace std;
long long a[N],b[N],q[N],l[N];
long long n,f[N],ans,g[N]; 
int main(){
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)scanf("%lld",&a[i]),b[i]=a[i];
	int tail=0;
	f[1]=1;
	for(int i=2;i<=n;i++){
		while(b[i-1]<b[i]){
			b[i-1]*=4,ans+=(i-q[tail]-1)*2LL;
			l[tail]--;
			if(l[tail]==0)tail--;
		}
		if(b[i-1]/b[i]>=4){
			tail++;
			q[tail]=i-1;
			while(b[i-1]/b[i]>=4){
				b[i-1]/=4;
				l[tail]++;	
			}
		}
		f[i]=i+ans;
	}
	tail=0;
	g[1]=0;
	ans=0;
	memset(l,0,sizeof(l));
	for(int i=1;i<=n;i++)b[i]=a[n-i+1];
	for(int i=2;i<=n;i++){
		while(b[i-1]<b[i]){
			b[i-1]*=4,ans+=(i-q[tail]-1)*2LL;
			l[tail]--;
			if(l[tail]==0)tail--;
		}
		if(b[i-1]/b[i]>=4){
			tail++;
			q[tail]=i-1;
			while(b[i-1]/b[i]>=4){
				b[i-1]/=4;
				l[tail]++;	
			}
		}
		g[i]=ans;
	}
	long long bns=1000000000000000LL;
	for(int i=0;i<=n;i++)bns=min(bns,f[i]+g[n-i]);
	printf("%lld",bns);
}

Measured memory_bytes: 10368
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

vector <int> v,a;

int main() {
   

    ll n;
    for (int i=1;i<=4;i++){
        cin >> n;
        v.push_back(n);
    }
    sort(v.begin(),v.end());

    a.push_back(1);
    a.push_back(4);
    a.push_back(7);
    a.push_back(9);
    if(v == a){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

}




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

using namespace std;

const int INF = 1e9;
int main()
{
	vector <int> v(5);
	for (int &x : v)
		cin >> x;
	
	for (int i = 0; i < 5; i++)
		if (v[i] == 0)
			cout << i +  1 << "\n";
}

//  3 2 1 3 1 3

//  3 5 6 

Measured memory_bytes: 3596
#include <iostream>

using namespace std;

int a[7][7] = {
	{  0,   300,  500,  600,  700, 1350, 1650},
	{ 300,    0,  350,  450,  600, 1150, 1500},
	{ 500,  350,    0,  250,  400, 1000, 1350},
	{ 600,  450,  250,    0,  250,  850, 1300},
	{ 700,  600,  400,  250,    0,  600, 1150},
	{1350, 1150, 1000,  850,  600,    0, 500},
	{1650, 1500, 1350, 1300, 1150,  500,   0}
};

int d[7][7] = {
	{ 0,  6, 13, 18, 23, 43, 58},
	{ 6,  0,  7, 12, 17, 37, 52},
	{13,  7,  0,  5, 10, 30, 45},
	{18, 12,  5,  0,  5, 25, 40},
	{23, 17, 10,  5,  0, 20, 35},
	{43, 37, 30, 25, 20,  0, 15},
	{58, 52, 45, 40, 35, 15,  0}
};

int main(int argc, char **argv)
{
	int m1, s1, m2, s2, ic1, ic2;
	while(1){
		cin >> ic1;
		if(ic1 == 0){
			break;
		}
		cin >> m1 >> s1;
		cin >> ic2;
		cin >> m2 >> s2;
		ic1--;
		ic2--;
		if(!((m1 == 17 && s1 >= 30)||(m1 == 18)||(m1 == 19 && s1 <= 30))
		&&!((m2 == 17 && s2 >= 30)||(m2 == 18)||(m2 == 19 && s2 <= 30))){
			cout << a[ic1][ic2] << endl;
			continue;
		}
		
		if(d[ic1][ic2] <= 40){
			m1 = a[ic1][ic2]/2;
			m2 = m1 % 50;
			if(m2 != 0){
				m1 = m1 - m2 + 50;
			}
			cout << m1 << endl;
		} else {
			cout << a[ic2][ic1] << endl;
		}
		
	}
	return 0;
}

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

using namespace std;

int x;
char a[1100];

int main() {
    cin >> a;
    for( x=0 ;; x++ ){
        if( a[x] == 49 ) a[x] += 8;
        else if( a[x] == 57 ) a[x] -= 8;
        else break;
    }
    cout << a <<"\n";


}

Measured memory_bytes: 256
// Standard I/O
#include <iostream>
#include <sstream>
#include <cstdio>
// Standard Library
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
// Template Class
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
// Container Control
#include <algorithm>

using namespace std;

#define rep( i, n ) for( int i = 0; i < n; ++i )
#define irep( i, n ) for( int i = n-1; i >= 0; --i )
#define reep( i, s, n ) for ( int i = s; i < n; ++i )
#define ireep( i, n, s ) for ( int i = n-1; i >= s; --i )
#define foreach(itr, x) for( typeof(x.begin()) itr = x.begin(); itr != x.end(); ++itr)

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all( v ) v.begin(), v.end()
#define fs first
#define sc second
#define vc vector

// for visualizer.html
double SCALE = 1.0;
double OFFSET_X = 0.0;
double OFFSET_Y = 0.0;
#define LINE(x,y,a,b) cerr << "line(" << SCALE*(x) + OFFSET_X << ","	\
	<< SCALE*(y) + OFFSET_Y << ","										\
	<< SCALE*(a) + OFFSET_X << ","										\
	<< SCALE*(b) + OFFSET_Y << ")" << endl;
#define CIRCLE(x,y,r) cerr << "circle(" << SCALE*(x) + OFFSET_X << ","	\
	<< SCALE*(y) + OFFSET_Y << ","										\
	<< SCALE*(r) << ")" << endl;

typedef long long ll;
typedef complex<double> Point;

typedef pair<int, int> pii;
typedef pair<int, pii> ipii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector< vector<int> > vii;
typedef vector< vector<double> > vdd;

typedef vector<int>::iterator vi_itr;

const int IINF = 1 << 28;
const int MOD = 1e9+7;
const double INF = 1e30;
const double EPS = 1e-10;
const double PI = acos(-1.0);

// Direction : L U R D
const int dx[] = { -1, 0, 1, 0};
const int dy[] = { 0, -1, 0, 1 };

int main()
{
    int n, x;
    int m[100];
    cin >> n >> x;

    rep(i, n) cin >> m[i];

    int ans = n;
    rep(i, n) x -= m[i];

    sort(m, m + n);

    ans += x / m[0];
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <iostream>
#include <set>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <complex>
#include <map>
#include <queue>
#include <array>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<pii> vii;
typedef vector<string> vs;

int main() {
  int n, m;
  cin >> n >> m;
  vi a(m);
  vi a1, a2;
  for (int i = 0; i < m; ++i) {
    cin >> a[i];
    if (a[i] % 2) a1.push_back(a[i]);
    else a2.push_back(a[i]);
  }
  if (a1.size() > 2) {
    cout << "Impossible\n";
    return 0;
  }
  int it = 0, it1 = 0;
  vi b, resa;
  if (a1.empty()) {
    ++it;
    if (a2[0] > 2) b.push_back(a2[0] - 2);
    b.push_back(1);
    resa.push_back(a2[0]);
  } else {
    ++it1;
    if (a1[0] > 1) b.push_back(a1[0] - 1);
    resa.push_back(a1[0]);
  }
  for (int i = it; i < a2.size(); ++i) {
    b.push_back(a2[i]);
    resa.push_back(a2[i]);
  }
  if (it1 < a1.size()) {
    b.push_back(a1[it1] + 1);
    resa.push_back(a1[it1]);
  } else {
    b.push_back(1);
  }
  for (int i = 0; i < resa.size(); ++i) cout << resa[i] << ' '; cout << endl;
  cout << b.size() << endl;
  for (int i = 0; i < b.size(); ++i) cout << b[i] << ' '; cout << endl;
  return 0;
}

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

int main() {
	int h, w;
	while(1) {
		cin >> h >> w;
		if(h == 0 && w == 0) break;
		for(int i=0; i<w; i++) {
			cout << "#";
		}
		cout << endl;
		for(int i=1; i<h-1; i++) {
			cout << "#";
			for(int j=1; j<w-1; j++) {
				cout << ".";
			}
			cout << "#" << endl;
		}
		for(int i=0; i<w; i++) {
			cout << "#";
		}
		cout << endl;
		cout << endl;
	}
}

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

typedef vector <long> vl;
typedef vector <vl> vvl;

typedef vector <int> vi;
typedef vector <vi> vvi;

int main() {
  
    int N;
    cin >> N;
    vvl dp(N,vl(3,0));
    vvi score(N,vi(3,0));
    
    for(int i = 0; i < N;i++){
        for(int j = 0;j < 3;j++)
            cin >> score[i][j];
    }
    
    for(int i = 0; i < 3;i++){
        dp[0][i] = score[0][i];
    }
    
    for(int day = 1; day < N;day++){
        for(int activity = 0; activity < 3;activity++){
            for(int previousActivity = 0; previousActivity < 3;previousActivity++){
                if(previousActivity != activity){
                    dp[day][activity] = max(dp[day-1][previousActivity] + score[day][activity], dp[day][activity]);
                }
            }
        }
    }
    cout << *max_element(dp[N-1].begin(), dp[N-1].end()) << endl;
    return 0;
    // EDABC
}




Measured memory_bytes: 13616
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int m = sc.nextInt();
        int l = sc.nextInt();
        
        long[][] aij = new long[n][m];
        long[][] bij = new long[m][l];
        long[][] cij = new long[n][l];
        
        for(int i = 0; i < n; i++){
            for(int j = 0; j < l; j++){
                cij[i][j] = 0;
            }
        }
        
        for(int i = 0; i < n; i++){
            for(int j = 0; j < m; j++){
                aij[i][j] = sc.nextLong();
            }
        }
         for(int i = 0; i < m; i++){
            for(int j = 0; j < l; j++){
                bij[i][j] = sc.nextLong();
            }
        }
        
        for(int i = 0; i < n; i++){
            for(int j = 0; j < l; j++){
            	for(int k = 0; k < m; k++){
                	cij[i][j] += aij[i][k]*bij[k][j];
                }
            }
        }
        
        for(int i = 0; i < n; i++){
            for(int j = 0; j < l-1; j++){
               	System.out.print(cij[i][j] + " ");
            }
			System.out.println(cij[i][l-1]);
        }
    }

}


Measured memory_bytes: 53344
#include <iostream>
#include <string>

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	string str, tar = "keyence";
	cin >> str;
	for (int i = 0; i <= 7; i++) {
		bool ok = true;
		for (int j = 0; j < i && ok; j++) {
			if (str[j] != tar[j]) {
				ok = false;
			}
		}
		for (int j = str.length()-1, k = 6; k >= i && ok; j--, k--) {
			if (str[j] != tar[k]) {
				ok = false;
			}
		}
		if (ok) {
			puts("YES");
			return 0;
		}
	}
	puts("NO");
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<string.h>

#define M 1046527
#define L 14

char H[M][L]; /* Hash Table */

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

/* convert a string into an integer value */
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)); }

int find(char str[]){

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

int insert(char str[]){
  long long k,i,h;
  k = getKey(str);
  for(i=0;;i++)
    {
      h =(h1(k) + i* h2(k))%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(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( 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: 14916
#include <iostream>
using namespace std;
int main(void){
    int n;
    string s;
    cin >> n >> s;
    int l = s.length();
    for(int i=0; i<l; i++){
        if ('Z' < s[i] + n){
            s[i] = (s[i] - 26 + n);
        }else{
            s[i] = (s[i] + n);
        }
    }
    cout << s << endl;
}


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

int main(){

	int n,k;
	cin >> n >> k;

	string a;
	cin >> a;

	deque<int> l,r;

	int ptr=0,p1=0,p2=0;
	if(a[0]=='0'){
		l.push_back(0);
	}
	for(int i=0;i<n;i++){
		if(a[i]=='1'){
			int j=i;
			for(;j<=n;j++){
				if(j==n || a[j]=='0'){
					l.push_back(j-i);
					break;
				}
			}
			i=j;
		}
	}
	for(int i=0;i<n;i++){
		if(a[i]=='0'){
			int j=i;
			for(;j<=n;j++){
				if(j==n || a[j]=='1'){
					r.push_back(j-i);
					break;
				}
			}
			i=j;
		}
	}
	
	int ans = 0;

	l.push_front(0);
	r.push_front(0);

	for(int i=1;i<l.size();i++){
		l[i]=l[i]+l[i-1];
	}
	for(int i=1;i<r.size();i++){
		r[i]=r[i]+r[i-1];
	}

	for(int i=0;i<=k;i++){
		l.push_back( l.back() );
		r.push_back( r.back() );

	}

	for(int i=1;i<=r.size();i++){
		if( i+k-1 < r.size() && i+k<l.size() )
		ans = max( ans , r[i+k-1]-r[i-1] + l[i+k]-l[i-1] );
	}

	cout << ans << "\n";



	return 0;
}

Measured memory_bytes: 1152
import itertools
import functools
import math
from collections import Counter
from itertools import combinations
import re

def main_sum():
    N,K=map(int,input().split())
    P=list(map(int,input().split()))

    for i in range(len(P)):
        P[i] = ( P[i] + 1 ) / 2

    max = sum(P[:K])
    add = max
    for i in range(len(P)-K):
        add = add + P[i+K] - P[i]
        if add > max:
            max = add
    print(max)


main_sum()

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

signed main()
{
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    if(A + B > C + D) { printf("Left\n"); }
    else if(A + B < C + D) { printf("Right\n"); }
    else { printf("Balanced\n"); }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <cassert>

using namespace std;

typedef long long LL;
typedef pair<int,int> PII;

#define MP make_pair
#define PB push_back
#define FF first
#define SS second

#define FORN(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD(i, n) for (int i = (int)(n) - 1; i >= 0; i--)

#define DEBUG(X) { cout << #X << " = " << (X) << endl; }
#define PR0(A,n) { cout << #A << " = "; FORN(_,n) cout << A[_] << ' '; cout << endl; }

#define MOD 1000000007
#define INF 2000000000

int GLL(LL& x) {
    return scanf("%lld", &x);
}

int GI(int& x) {
    return scanf("%d", &x);
}

const int MAXN = 200010;
int p[MAXN], pinv[MAXN];

int n;

set<PII> itvl;

int main() {
    GI(n);

    FOR1(i, n) {
        GI(p[i]);
        pinv[p[i]] = i;
    }

    itvl.insert(MP(1, n));

    LL res = 0;

    FOR1(i, n) {
        int iloc = pinv[i];
        set<PII>::iterator j = itvl.upper_bound(MP(iloc, INF)); j--;
//        DEBUG(j->FF);
//        DEBUG(j->SS);
        res += 1LL * i * (j->SS - iloc + 1) * (iloc - j->FF + 1);

        itvl.insert(MP(j->FF, iloc-1));
        itvl.insert(MP(iloc+1, j->SS));
        itvl.erase(*j);
    }

    cout << res << "\n";
    
    return 0;
}

Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std;
int foo(int a){
  if(a == 0) return 1;
  else return foo(a-1)*10;
}

int main(){
  int ans = 0, n, m, temp, f;

  cin>>n>>m;

  for(int i = n; i <= m; i++ ){
    temp = log10(i);
    //cout<<temp<<" "<<i<<endl;
    
    f = 0;
    for(int j = 0; j <= temp; j++){
      
      if((i/foo(j))%10 != (i/foo(temp-j))%10) f= 1;
    }
    if(f == 0)ans++;//cout<<i<<endl;;
  }

  cout<<ans<<endl;

  return 0;
}


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

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

	string s, t;
	unordered_set<string> d;

	while (n--) {
		cin >> s >> t;
		switch(s[0]) {
		case 'i':
			d.insert(t); break;
		case 'f':
			cout << (d.find(t) != d.end() ? "yes" : "no") << endl;
		}
	}
}


Measured memory_bytes: 32252
#include <iostream>
#include <math.h> //M_PI
#include <cmath>  //pow()
#include <iomanip>

using namespace std;

int main(){
        double r;
        cin >> r;
        
        cout << fixed;
        cout << setprecision(10) << pow(r,2.0) * M_PI  << " " << setprecision(10) << r * 2.0 * M_PI << endl;
}



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

using namespace std;

int sum (int v[2002][2002], int x1, int y1, int x2, int y2) {
  return v[x2][y2] - v[x1 - 1][y2] - v[x2][y1 - 1] + v[x1 - 1][y1 - 1];
}

char ch;
int n, m, q, a[2002][2002], l[2002][2002], c[2002][2002];

int main()
{
  cin >> n >> m >> q;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      cin >> ch;
      a[i][j] = ch - '0';
    }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j<= m; j++)
      if (a[i][j]) {
        if (a[i - 1][j])
          l[i][j] = 1;
        if (a[i][j - 1])
          c[i][j] = 1;
      }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      a[i][j] += a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      l[i][j] += l[i - 1][j] + l[i][j - 1] - l[i - 1][j - 1];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      c[i][j] += c[i - 1][j] + c[i][j - 1] - c[i - 1][j - 1];
  for (int i = 1; i <= q; i++) {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    cout << sum(a, x1, y1, x2, y2) - sum(l, x1 + 1, y1, x2, y2) - sum(c, x1, y1 + 1, x2, y2) << "\n";
  }
  return 0;
}


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

using namespace std;
  
     
    


    void solve(){
          int N;
           cin>>N;
     vector<int>dp(N+1, -1);   
     vector<int>H(N+1);
       
        for(int i = 1; i <= N;++i) cin>>H[i];
        dp[1] = 0;
        dp[2] = abs(H[2] - H[1]);
        for(int i = 3 ; i <= N ; ++i) dp[i]  =  min(dp[i-1] + abs(H[i] - H[i-1]) , dp[i-2] + abs(H[i] - H[i-2]));
        cout<<dp[N]<<'\n';
    }

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int tc = 1;
    //cin>>tc;
    while (tc--)
    {
        solve();
    }
    
    return 0;
}

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

int main()
{
    ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
	long long d,n,c=0;
	double a,b;
	cin>>n>>d;
	while(n--)
	{
		cin>>a>>b;
		if(sqrt(a*a+b*b)<=d)
          	c++;
	}
	cout<<c<<'\n';
	return 0;
}


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

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

    sort(v, v + n);

    double ans = v[0];
    for(int i = 1; i < n; i++){
        ans = (ans + v[i]) / 2;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)
def main():
    h, w = map(int, input().split())
    s = [input() for _ in range(h)]
    dp = [[10**5] * w for _ in range(h)]
    def func(temp, now, flag):
        x, y = now
        if y > h - 1 or x > w - 1:
            return 10**6
        if s[y][x] == "#":
            if not flag:
                temp += 1
            flag = True
        else:
            flag = False
        if x == w-1 and y == h-1:
            return temp
        if dp[y][x] <= temp:
            return 10**6
        dp[y][x] = temp
        piyo = []
        return min(func(temp, (x + 1, y), flag), func(temp, (x, y + 1), flag))
    print(func(0, (0, 0), False))
main()

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

#define int long long


int W, H;
int dxy[] = {1,0};

string &solve(int y, int x, vector<vector<string> > &temp, vector<string> &str){
  if(temp[y][x] != "") return temp[y][x];

  string res, tstr;
  
  for(int i = 0; i < 2; i++){
    int ny = y + dxy[i], nx = x + dxy[1-i];

    // cout<<"nyx "<<ny<<" "<<nx<<" "<<y<<" "<<x<<endl;
    if(ny >= H || ny < 0 || nx >= W || nx < 0) continue;

    if(str[ny][nx] < '0' || '9' < str[ny][nx]) continue;

    tstr = solve(ny,nx,temp,str);
    
    if(res.size() == tstr.size()) res = max(res, tstr);
    else if(res.size() <= tstr.size()) res = tstr;
  }

  temp[y][x] = str[y][x];
  
  temp[y][x] += res;
  
  return temp[y][x];
}

signed main(){

  while(true){
    string ans;
    vector<string> str;
    vector<vector<string> > temp;
    
    cin>>W>>H;

    if(!H && !W) break;

    str.resize(H);
    temp.resize(H,vector<string>(W,""));
    
    for(int i = 0; i < H; i++){
      cin>>str[i];
    }

    for(int i = 0; i < H; i++){
      for(int j = 0; j < W; j++){
	
	if(str[i][j] <= '0' || '9' < str[i][j]) continue;

	if(temp[i][j] == ""){
	  temp[i][j] = solve(i, j, temp, str);
	}
	if(temp[i][j][0] == '0') continue;
	
	if(ans.size() == temp[i][j].size()){
	    ans = max(temp[i][j], ans);
	} else if(ans.size() < temp[i][j].size()) ans = temp[i][j];
	//	cout<<i<<" "<<j<<" "<<temp[i][j]<<" "<<ans<<endl;
      }
    }

    cout<<ans<<endl;

    
  }
  return 0;
}



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

using namespace std;

#define lp(i,n) for(int i = 0; i <n;i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define MP make_pair
#define SZ(v) ((int)((v).size()))
typedef long long ll;

const ll MOD = 1e9 + 7;
const int OO = (int)1e6;
const int N = (int)1e7;

void init(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
ll FindLCM(ll a, ll b) 
{ 
    return (a * b) / __gcd(a, b); 
} 
ll rangeDivisor(ll m, ll n, ll a, ll b) 
{ 
    
    ll lcm = FindLCM(a, b); 
  
    ll a_divisor = n / a - (m - 1) / a; 
    ll b_divisor = n / b - (m - 1) / b; 
  
   
    ll common_divisor = n / lcm - (m - 1) / lcm; 
  
    ll ans = a_divisor + b_divisor - common_divisor; 
    return ans; 
} 
int main() {
	#   ifdef LOCAL_PROJECT
        freopen("in.txt", "r", stdin);
    #   endif
    ll a,b,c,d;
    scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
    ll ans = rangeDivisor(a,b,c,d);
    printf("%lld",max(a,b)-min(a,b)+1-ans);

    
    return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(void) {
    int i,count=0;
    char word[12],text[1001];
    scanf(" %s",word);
    while (1) {
        scanf(" %s",text);
        if (strcmp(text,"END_OF_TEXT")==0) break;
        for (i=0; i<strlen(text); i++) text[i]=tolower(text[i]);
        if (strcmp(text,word)==0) count++;
    }
    printf("%d\n",count);
    return 0;
}

Measured memory_bytes: 552
import math

def is_square(integer):
    root = math.sqrt(integer)
    return integer == int(root + 0.5) ** 2

x = int(input())

divisors = []

for i in range(1, math.ceil(math.sqrt(x)) + 1):
    if x % i == 0:
        divisors.append(i)
        divisors.append(-i)
        divisors.append(x//i)
        divisors.append(-x//i)

dpPairs = []

for delta in divisors:
    if ((x // delta) - delta**4) % 5 != 0:
        continue
    disc = delta**4 + 4 * (x // delta - delta**4) / 5
    if disc < 0 or not is_square(disc):
        continue
    sqdisc = int(math.sqrt(disc) + 0.5)
    if delta ** 2 % 2 != sqdisc % 2:
        continue
    dpPairs.append((delta, (- delta ** 2 - sqdisc) // 2))
    dpPairs.append((delta, (- delta ** 2 + sqdisc) // 2))

for (delta, prod) in dpPairs:
    disc = delta ** 2 + 4 * prod
    if disc < 0 or not is_square(disc):
        continue
    sqdisc = int(math.sqrt(disc) + 0.5)
    if delta % 2 != sqdisc % 2:
        continue
    b = (- delta + sqdisc) // 2
    a = b + delta
    print(a, b)
    break


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

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N;
  cin >> N;
  ll res = 1LL << 58;
  for (ll i = 1; i * i <= N; i++) {
    if (N % i != 0) continue;
    res = min(res, i + N / i - 2);
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 256
def main():
    N = int(input())

    for h in range(1,3501):
        for n in range(1,3501):
            x = 4*h*n - N*n -N*h
            if x <= 0:
                continue
            w, mod = divmod(N*h*n, x)
            if not mod:
                print(h, n, w)
                return

main()

Measured memory_bytes: 3064
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ub              upper_bound
#define lb              lower_bound
#define isrt            insert
#define clr             clear
#define rsz             resize
#define ff              first
#define ss              second
#define lli             long long int
#define pb              push_back
#define pf              push_front
#define mkp              make_pair
#define pii             pair<lli,lli>
#define vi              vector<int>
#define mii             map<lli,lli>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define INF             1e9
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define all(v)          v.begin(),v.end()
#define endl            "\n"
const double PI = acos(-1);

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

lli maxm(lli a, lli b)
{
    return (a >= b ? a : b);
}


lli minm(lli a, lli b)
{
    return (a <= b ? a : b);
}

lli power(lli x, lli y, lli p)
{
    lli res = 1;

    x = x % p;
    if (x == 0)
        return 0;

    while (y > 0)
    {

        if (y & 1)
            res = (res * x) % p;


        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}

lli nCrmodp(lli n, lli r, lli p)
{
    if (r == 0)
        return 1;
    if (r == 1)
        return n;


    lli pro = 1, k = n;
    while (k > r)
    {
        pro *= k;
        pro %= p;
        --k;
    }

    k = 2;
    while (k <= (n - r))
    {
        pro *= power(k, (p - 2), p);
        pro %= p;
        ++k;
    }

    return pro;
}


lli str_num(string str, lli k)
{

    lli n = str.length(), ans = 0;

    for (lli i = 0; i < n; ++i)
        ans = (k * ans + str[i] - '0');


    return ans;
}


lli first_big(lli n, lli k, vector<lli> arr)
{
    lli l, r, ans = n;
    l = 0;
    r = n - 1;

    while (l <= r) {
        lli m = l + (r - l) / 2;

        if (arr[m] > k) {
            ans = m;
            r = m - 1;
        }

        else
            l = m + 1;
    }

    return ans;
}

lli last_small(lli n, lli k, vector<lli> arr)
{
    lli l, r, ans = -1;
    l = 0;
    r = n - 1;

    while (l <= r)
    {
        lli mid = (l + r) / 2;

        if (arr[mid] <= k)
        {
            ans = mid;
            l = mid + 1;
        }
        else
            r = mid - 1;
    }

    return ans;
}

void c_p_c()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

int main()
{
    c_p_c();

    lli s = 0;

    string str;
    cin >> str;
    int n = str.length();

    for (int i = 0; i < n; ++i)
    {
        s += (str[i] - '0');
    }

    if (s % 9 == 0)
        cout << "Yes\n";
    else
        cout << "No\n";
    return 0;
}

Measured memory_bytes: 3720
<?php

$input = explode(' ', trim(fgets(STDIN)));
$n = (int)$input[0];
$m = (int)$input[1];

$array = [];
for ($i=0; $i < $n; $i++) { 
	$input = explode(' ', trim(fgets(STDIN)));
	$a = (int)$input[0];
	$b = (int)$input[1];
	if (isset($array[$a])) {
		$array[$a] += $b;
	}else{
		$array[$a] = $b;
	}
}
ksort($array);

$money = 0;
$get = 0;
foreach ($array as $k => $v) {
	if ($get + $v < $m) {
		$money += $k * $v;
		$get += $v;
	}else{
		$diff = $get + $v - $m;
		$money += ($m - $get) * $k;
		break;
	}
}
echo $money;

Measured memory_bytes: 13048
#define _CRT_SECURE_NO_WARNINGS
#include <math.h>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <iterator>
#include <vector>
#include <string>
#include <string.h>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <map>
#include <regex>
#include <sstream>
#include <utility>
#include <list>
#define endl	'\n'
#define MAX 1000000000
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
int dx[] = { 1,-1,0,0,0,0 };
int dy[] = { 0,0,-1,1,0,0 };
int dz[] = { 0,0,0,0,1,-1 };
int n;
int arr[111];

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

	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> arr[i];

	sort(arr, arr + n);

	int total = 0;
	for (int i = 0; i < n - 1; i++)
		total += arr[i];

	if (arr[n - 1] >= total) cout << "No";
	else cout << "Yes";

	return 0;
}

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;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;

int main() {
    int h, w, k;
    cin >> h >> w >> k;
    vector<string> s(h);
    rep(i,h) cin >> s[i];
    int ans = 0;
    rep(is,1<<h)rep(js,1<<w) {
      int cnt = 0;
      rep(i,h)rep(j,w) {
        if (is>>i&1) continue;
        if (js>>j&1) continue;
        if (s[i][j] == '#') cnt++;
      }
      if (cnt == k) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int h, n;
	cin >> h >> n;
	vector<int> attack(n);
	for(int& x : attack) cin >> x;
	cout << (accumulate(attack.begin(), attack.end(), 0) >= h ? "Yes" : "No") << endl;
}


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

#define REP(i,n) for(int i=0;i<(int)n;i++)
#define REP1(j,n) for(int j=0;j<(int)n;j++)
#define REPD(i,n) for(int i=n;i>=0;i--)
#define REPD1(j,n) for(int j=n;j=>0;j--)
#define REPS(i,n) for(int i=1;i<=(int)n;i++)
#define REPS1(j,n) for(int j=1;j<=(int)n;j++)
#define rep(i,a,n) for(int i=a;i<(int)n;i++)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;

int main(void) {
	int n;
	int ans = 0;
	char s;
	cin >> n;
	REP(i, n) {
		cin >> s;
		if (s == 'Y') ans = 1;
	}
	if (ans == 1) cout <<  "Four" << endl;
	else cout <<"Three" << endl;
	return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;
int32_t main()
{
	int a,b;
	cin>>a>>b;
	int c = a*b;
	cout<<c<<endl;
	return 0;
} 

Measured memory_bytes: 3188
n = int(input())
Ascore = list(map(int,input().split()))
Bscore = list(map(int,input().split()))
count = 0
positive = []
nsum = 0
if sum(Ascore) < sum(Bscore):
    print(-1)
else:
    for a,b in zip(Ascore,Bscore):
        tmp = a-b
        if tmp < 0:
            count += 1
            nsum += tmp
        else:
            positive.append(tmp)
    positive = sorted(positive)[::-1]
    while(nsum<0):
        p = positive.pop(0)
        count += 1
        nsum += p
    print(count)

Measured memory_bytes: 18356
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;

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 _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()





int main() {
    int k;
    cin >> k;
    int now = 7;
    int prev = 7;
    rep (i, 1e6+5) {
        if (now % k == 0) {
            cout << i+ 1 << endl;
            exit(0);
        }
        now += prev * 10;
        prev = prev * 10 % k;
        now %= k;
    }
    cout << -1 << endl;
}



Measured memory_bytes: 3620
# coding: utf-8
# Your code here!
R, G, B, N = list(map(int, input().split()))

answer = 0
for r in range(N//R + 1):
    for g in range((N - r*R)//G + 1):
        if (N-r*R-g*G) % B == 0:
            answer += 1

print(answer)

Measured memory_bytes: 2940
// Matrix Vector Multiplication
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_6_D
//
// Accepted

use std::io::{BufRead, stdin};

fn main() {
    let stdin = stdin();
    let mut stdin = stdin.lock();

    let mut buf = String::new();
    stdin.read_line(&mut buf).unwrap();
    let mut buf = buf.split_whitespace();

    let n: usize = buf.next().unwrap().parse().unwrap();
    let m: usize = buf.next().unwrap().parse().unwrap();

    let mut A: Vec<Vec<usize>> = Vec::with_capacity(n);
    for _ in 0..n {
        let mut buf = String::new();
        stdin.read_line(&mut buf).unwrap();

        A.push(buf.split_whitespace().map(|x| x.parse().unwrap()).collect::<Vec<usize>>());
    }

    let mut b: Vec<usize> = Vec::with_capacity(m);
    for _ in 0..m {
        let mut buf = String::new();
        stdin.read_line(&mut buf).unwrap();

        b.push(buf.trim().parse().unwrap());
    }

    for i in 0..n {
        let mut result = 0usize;
        for j in 0..m {
            result += A[i][j] * b[j];
        }
        println!("{}", result);
    }
}


Measured memory_bytes: 5052
#include<stdio.h>
#include<stdlib.h>
int main()
{
    long double A,B;
    scanf("%Lf",&A);
    scanf("%Lf",&B);
    if(A>B)
	{
    printf("GREATER\n"); 
	} 
	if(A<B)
	{
		printf("LESS\n");
	} 
	if (A==B)
	{
		printf("EQUAL\n");
	}
    system("pause");
}

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

bool a[10];
int n, k;

bool check(int x)
{
    vector < int > b;

    while(x != 0){
        b.push_back(x % 10);

        x /= 10;
    }

    for(int i = 0; i < b.size(); i++){
        if(a[b[i]] == 1) return 0;
    }

    return 1;
}

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

    for(int i = 0; i < k; i++){
        int x;

        cin >> x;

        a[x] = 1;
    }

    while(1){
        if(check(n) == 1){
            cout << n << endl;
            return 0;
        }
        else n++;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll mod=1e9+7;
int dy[]={1,-1,0,0};
int dx[]={0,0,1,-1};

vector<int> tonari[200000];
bool passed[200000]={false};

void dfs(int node,int time){
  passed[node]=true;
  if(time==2) return;
  time++;
  for(auto next:tonari[node]){
    if(passed[next]) continue;
    dfs(next,time);
  }
}

int main(){
  int N,M;
  cin>>N>>M;
  int a,b;
  for(int i=0;i<M;i++){
    cin>>a>>b;
    tonari[a-1].push_back(b-1);
    tonari[b-1].push_back(a-1);
  }

  dfs(0,0);
  
  

  if(passed[N-1]) cout<<"POSSIBLE"<<endl;
  else cout<<"IMPOSSIBLE"<<endl;

  return 0;
}




Measured memory_bytes: 12144
import math

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

ns = [2] * n
ms = [3] * m

cnt = 0
for ni in ns:
  for mi in ms:
    s = ni + mi
    if s%2 == 0:
      cnt += 1

def combinations_count(n, r):
    if r > n: return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
      
nc = combinations_count(len(ns), 2)
mc = combinations_count(len(ms), 2)

print(cnt+nc+mc)

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define sc second

int q;
long long leftsum, rightsum, bsum;
priority_queue<int> maxh;
priority_queue<int, vector<int>, greater<int>> minh;

void print_min() {
  long long med = maxh.top();
  long long lsize = maxh.size() - 1;
  long long rsize = minh.size();

  long long res = bsum;
  res += med * lsize - (leftsum - med);
  res += rightsum - med * rsize;
  cout << med << " " << res << "\n";
}

void update(int a, int b) {
  bsum += b;

  if (maxh.size() == 0 || maxh.top() >= a) {
    maxh.push(a);
    leftsum += a;
  } else {
    minh.push(a);
    rightsum += a;
  }

  if (maxh.size() > minh.size() + 1) {
    leftsum -= maxh.top();
    rightsum += maxh.top();
    minh.push(maxh.top());
    maxh.pop();
  } else if (minh.size() > maxh.size()) {
    leftsum += minh.top();
    rightsum -= minh.top();
    maxh.push(minh.top());
    minh.pop();
  }
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> q;
  for (int t = 0; t < q; ++t) {
    int c;
    cin >> c;
    if (c == 2) {
      print_min();
    } else {
      int a, b;
      cin >> a >> b;
      update(a, b);
    }
  }
  return 0;
}


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

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

using namespace std;
using ll = long long;

int main(void){
    int H, W;
    cin >> H >> W;
    string S[H];
    int visited[H][W];
    rep(i, H) rep(j, W) visited[i][j] = 0;
    vector<pair<int, int>> black;
    rep(i, H) cin >> S[i];
    rep(i, H){
        rep(j, W){
            if(S[i][j] == '#'){
                black.push_back(make_pair(i, j));
            }
        }
    }
    ll ans = 0;
    stack<pair<int, int>> work;
    while(!black.empty()){
        work.push(black[black.size()-1]);
        black.pop_back();
        visited[work.top().first][work.top().second] = 1;
        ll b = 1; //blackから取り出すのは#なので
        ll w = 0;
        //処理
        while(!work.empty()){
            pair<int, int> op = work.top();
            work.pop();
            int x = op.first, y = op.second;
            if(S[x][y] == '#'){
                if(x-1 >= 0 && S[x-1][y] == '.' && visited[x-1][y] == 0){
                    visited[x-1][y] = 1;
                    work.push(make_pair(x-1, y));
                    w++;
                }
                if(y-1 >= 0 && S[x][y-1] == '.' && visited[x][y-1] == 0){
                    visited[x][y-1] = 1;
                    work.push(make_pair(x, y-1));
                    w++;
                }
                if(y+1 <= W-1 && S[x][y+1] == '.' && visited[x][y+1] == 0){
                    visited[x][y+1] = 1;
                    work.push(make_pair(x, y+1));
                    w++;
                }
                if(x+1 <= H-1 && S[x+1][y] == '.' && visited[x+1][y] == 0){
                    visited[x+1][y] = 1;
                    work.push(make_pair(x+1, y));
                    w++;
                }
            }
            else{
                if(x-1 >= 0 && S[x-1][y] == '#' && visited[x-1][y] == 0){
                    visited[x-1][y] = 1;
                    work.push(make_pair(x-1, y));
                    b++;
                }
                if(y-1 >= 0 && S[x][y-1] == '#' && visited[x][y-1] == 0){
                    visited[x][y-1] = 1;
                    work.push(make_pair(x, y-1));
                    b++;
                }
                if(y+1 <= W-1 && S[x][y+1] == '#' && visited[x][y+1] == 0){
                    visited[x][y+1] = 1;
                    work.push(make_pair(x, y+1));
                    b++;
                }
                if(x+1 <= H-1 && S[x+1][y] == '#' && visited[x+1][y] == 0){
                    visited[x+1][y] = 1;
                    work.push(make_pair(x+1, y));
                    b++;
                }
            }
        }
        ans += b*w;
    }
    cout << ans << endl;

    return 0;
}

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

#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
//#define end endl
//#define endl() end()
#define f first
#define s second
#define pb push_back
#define mp make_pair

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

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;

#define MOD 998244353
#define MAX (1<<20)

ll n,m,k;

ll pot[MAX];
ll c[MAX];
ll inv[MAX];

ll ex(ll a, ll b)
{
	if (b == 0)
		return 1;
	if (b == 1)
		return a;

	ll temp = ex(a, b/2);

	temp = temp*temp;
	temp %= MOD;

	if (b%2)
		temp*=a;
	return temp % MOD;
}

void init()
{
	pot[0] = 1;

	for (int i=1; i<n; i++)
	{
		pot[i] = pot[i-1]*(m-1)%MOD;
	}

	c[0] = 1;
	inv[1] = 1;

	for (int i=2; i<n; i++)
	{
		inv[i] = ex(i,MOD-2);
	}


	for (int i=1; i<n; i++)
	{
		c[i] = c[i-1]*(n-i)%MOD;
		c[i]*= inv[i];
		c[i]%= MOD;
	}

}




ll calc(int i)
{
	ll resp = m%MOD;

	resp*=pot[n-i-1];
	resp%=MOD;
	resp*=c[i];
	return resp%MOD;
}


int main(){ _
	char end = '\n';
	//m colors
	//n blocos

	cin >> n >> m >> k;
	init();

	ll resp=0;
	for (int i=0; i<=k; i++)
	{
		resp += calc(i);
		resp %= MOD;
	}
	cout << resp << endl;
	
	exit(0);
}


Measured memory_bytes: 8344
ans = 1
n = gets.chomp.to_i
ary1 = gets.chomp.split(" ").map(&:to_i)
if ary1.include?(0) 
  puts 0
else
  n.times do |i|
    ans = ans * ary1[i]
    if ans > 10**18
      ans = -1
      break
    end
  end
  puts sprintf("%i",ans)
end


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

using namespace std;

int main()
{
  int k, s, ans = 0, z;
  scanf("%d %d", &k, &s);

  for (int i = 0; i <= k; i++)
  {
    for (int j = 0; j <= k; j++)
    {
      z = s - i - j;
      if (0 <= z && z <= k)
      {
        ans++;
      }
    }
  }

  printf("%d", ans);
}

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

using namespace std;

#define sp(x) cout<<setprecision(x);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define print(s) cout<<(s)<<endl
#define lint long long
#define yes "Yes"
#define no "No"

typedef pair<int, int> P;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b; cin>>a>>b;
    if(a==b) print("Draw");
    else if(a==1) print("Alice");
    else if(b==1) print("Bob");
    else if(a<b) print("Bob");
    else if(b<a) print("Alice");
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll,null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set_pair tree<pair<ll,ll>,null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> 

typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef pair<ll,ll> pi; 
#define FOR(i,vv,n) for(ll i=vv;i<n;i++)
#define FORR(i,n,vv) for(ll i=n-1;i>=vv;i--)
#define ve vector 
#define maxe(v) *max_element(v.begin(),v.end())
#define mine(v) *min_element(v.begin(),v.end())
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define eb emplace_back
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp make_pair
#define M 1000000007ll
#define PRECISE cout.precision(18);
#define F first
#define S second




int main(){
 

    FAST
	//PRECISE


string s;
cin>>s;
ll n=s.size();
ll ok=0;
FOR(i,0,n)
if(s[i]!=s[n-i-1]){
	ok++;
	break;
}

FOR(i,0,(n-1)/2)
if(s[i]!=s[(n-1)/2-i-1]){
	ok++;
	break;
}
ll l=n-(n+3)/2+1;
string d=s.substr((n+3)/2-1,l);

FOR(i,0,l)
if(d[i]!=d[l-i-1]){
	//cout<<s[i]<<" "<<s[l+i-1]<<endl;
	ok++;
	break;
}

if(ok)
cout<<"No";
else
cout<<"Yes";
return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, c) for(int i = 0; i < (int) c; ++i)
const int inf = 1000000000; //10^9
using namespace std;

int main() {
    int n;
    cin>>n;
    int mn = inf, mx = -inf;
    vector<int> v(n);
    rep(i, n) {
        cin>>v[i]; 
        mn = min(mn, v[i]);
        mx = max(mx, v[i]);
    }
    int sum = inf;
    for(int i = mn; i <= mx; ++i) {
        int tmp = 0;
        rep(j, n) tmp += (v[j]-i)*(v[j]-i);
        sum = min(sum, tmp);
    }
    cout<<sum;
    return 0;
}

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

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <math.h>
#include <map>
#include <queue>

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n)   FOR(i,0,n)
#define RREP(i,n)   RFOR(i,0,n)

const double INF = 1e+09;
const int MOD = 1e9+7;

using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "{ }"; return ostr;}
    ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}
    ostr << "}";
    return ostr;}

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(void){
  ios::sync_with_stdio(false);

  int k;
  cin >> k;
  queue<ll> que;
  FOR(i, 1, 10) que.push(i);
  vector<ll> a;
  FOR(i, 1, 10) a.push_back(i);
  int tmp = 0;
  while (tmp <= 1e+05 + 100){
    ll x = que.front();
    que.pop();
    FOR(i, -1, 2){
      int d = x % 10 + i;
      if (d < 0 || d > 9) continue;
      ll nx = x * 10 + d;
      que.push(nx);
      a.push_back(nx);
      tmp++;
    }
  }

  cout << a[k-1] << endl;


  return 0;
}



Measured memory_bytes: 1656