akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <climits>
#define MAX 300000
#define INF INT_MAX
using namespace std;

int D[MAX];
int n = 1;
int inf;

void initRMQ(int n_){
    while(n < n_) n *= 2;
    for(int i = 0; i < 2*n-1; i++){
        D[i] = INF;
    }
}

int query(int a, int b, int k, int l, int r){
    if(r <= a || b <= l) return INF;
    if(a <= l && r <= b) return D[k];

    int vleft, vright;
    vleft = query(a,b,2*k+1,l,(l+r)/2);
    vright = query(a,b,2*k+2,(l+r)/2,r);
    return min(vleft,vright);
}

int findMin(int a, int b){
    return query(a,b+1,0,0,n);
}

void update(int k, int a){
    k += n-1;
    D[k] = a;
    while(k > 0){
        k = (k-1)/2;
        D[k] = min(D[2*k+1],D[2*k+2]);
    }
}

int main(){
    int q, com, x, y, n_, min;
    cin >> n_ >> q;
    initRMQ(n_);
    for(int i = 0; i < q; i++){
        cin >> com >> x >> y;
        if(com == 0) update(x,y);
        else cout << findMin(x,y) << endl;
    }
    return 0;
}


Measured memory_bytes: 4104
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <stdlib.h>
#include <math.h>

int main(void)
{
	int h, w;
	int i, j, k;
	int sum = 0;
	int count;
	int grid_w[2000][2000] = {{0}};
	int grid_h[2000][2000] = {{0}};
	char str[2000][2001];
	
	scanf("%d%d", &h, &w);
	
	for(i = 0; i < h; i++) {
		scanf("%s", str[i]);
	}
	
	// 横方向で何個連続してるかカウント
	for(i = 0; i < h; i++) {
		count = 0;
		for(j = 0; j < w; j++) {
			if(str[i][j] == '#') {
				grid_w[i][j] = 0;
				if(count > 0) {
					for(k = 0; k < count; k++) {
						grid_w[i][j - k - 1] = count;
					}
				}
				count = 0;
			} else {
				count++;
			}
		}
		if(str[i][j - 1] == '.') {
			for(k = 0; k < count; k++) {
				grid_w[i][j - k - 1] = count;
			}
		}
	}
	
	// 縦方向で何個連続してるかカウント
	for(j = 0; j < w; j++) {
		count = 0;
		for(i = 0; i < h; i++) {
			if(str[i][j] == '#') {
				grid_h[i][j] = 0;
				if(count > 0) {
					for(k = 0; k < count; k++) {
						grid_h[i - k - 1][j] = count;
					}
				}
				count = 0;
			} else {
				count++;
			}
		}
		if(str[i - 1][j] == '.') {
			for(k = 0; k < count; k++) {
				grid_h[i - k - 1][j] = count;
			}
		}
	}
	
	for(i = 0; i < h; i++) {
		for(j = 0; j < w; j++) {
			if(grid_w[i][j] + grid_h[i][j] - 1 > sum) {
				sum = grid_w[i][j] + grid_h[i][j] - 1;
			}
		}
	}
	
	printf("%d\n", sum);
	
	return 0;
}

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

int main(){

  char s[101];
  char p[101];
  int s_len;
  int p_len;
  int work;
  int j;
  bool flg=false;

  cin >> s;     s_len=strlen(s);
  cin >> p;     p_len=strlen(p);

  for(int i=0; i<s_len; i++){
    work = i;
    for(j=0; j<p_len; j++){
      if(work+j>=s_len)
	work = -j;
      if(p[j]!=s[work+j])break;
    }
    if(j == p_len){
      flg = true;
      break;
    }

  }

  if(flg == true)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;


  return 0;
}

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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<int,int>
#define V vector<int>
#define M map<int,int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int,V,greater<int>>

#define pb(a) push_back(a)
#define mp make_pair

#define dump(x)  cout << #x << " = " << (x) << "\n";
#define COUT(x) cout<<(x)<<"\n"

int main()
{
    int x = 0;
    cin >> x;
    vector<int> a(x);

    REP(i, x)
    {
        cin >> a[i];
    }
    sort(a.begin(), a.end());

    COUT(a[a.size() - 1] - a[0]);

    return 0;
}

Measured memory_bytes: 256
a,b,c,x,y = map(int, input().split())
min_price = 10**100
for n_ab in range(0, 2*max(x, y) + 1, 2):
    price = c * n_ab
    rest_x = x - n_ab//2
    if rest_x <= 0:
        rest_x = 0
    rest_y = y - n_ab//2
    if rest_y <= 0:
        rest_y = 0 
    price += rest_x * a + rest_y * b
    min_price = min(min_price, price)

print(min_price)

Measured memory_bytes: 39408
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
	int n,sum=0;
            scanf("%d",&n);
            int a[n];
            for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		sum+=a[i];
	}
	
            sort(a,a+n);
	int j=0;
	if(sum%10==0)
	{
		while(sum%10==0&&j<n)
		{
			if(a[j]%10!=0)
			{
				sum-=a[j];
			}
			j++;
		}
	}

	if(j==n)
		printf("0");
	else
		printf("%d",sum);
            return 0;
	
}

Measured memory_bytes: 256
function main(input) {
  // 入力値（文字列）を改行で区切る
  const inputList = input.split(/\n/);
  const numList = inputList[1].split(/\s/).map(ip => formatNum(ip));
  var count = 0;
  for (var i = 1; i < numList.length - 1; i++) {
    if (Math.max(numList[i - 1], numList[i], numList[i + 1]) !== numList[i] &&
        Math.min(numList[i - 1], numList[i], numList[i + 1]) !== numList[i]) {
      count++;
    }
  }
  console.log(count);
};

// 文字列を数値に変換
function formatNum(str) {
  return Number(str);
};

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 21192
k=int(input())
a=[1,2,3,4,5,6,7,8,9]
now=0

while len(a)<=100000:
    past=len(a)
    for i in range(now,len(a)):
        if a[i]%10==0:
            a.append(a[i]*10+0)
            a.append(a[i]*10+1)
        elif a[i]%10==9:
            a.append(a[i]*10+8)
            a.append(a[i]*10+9)
        else:
            a.append(a[i]*10+a[i]%10-1)
            a.append(a[i]*10+a[i]%10)
            a.append(a[i]*10+a[i]%10+1)
    now=past

print(a[k-1])

Measured memory_bytes: 11740
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
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 (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b?gcd(b, a%b):a;}
ll lcm(ll a, ll b) { return a*b/gcd(a,b);}

int main(){
  int N; cin >> N;
  ll W; cin >> W;
  vector<ll> weight(N),value(N);
  rep(i,N) cin >> weight.at(i) >> value.at(i);
  vector<vector<ll>> dp(N+1,vector<ll>(W+1 ,0));

  rep(i,N){
    for(int j = 0; j <= W; j++){

      if(j-weight.at(i)>=0){
        chmax(dp.at(i+1).at(j), dp.at(i).at(j-weight.at(i))+value.at(i));
      }

      chmax(dp.at(i+1).at(j), dp.at(i).at(j));
    }
  }

  cout << dp.at(N).at(W) << endl;

}

Measured memory_bytes: 80256
<?php
$time = array();
for ($i = 0; $i < 3; $i++) {
	for ($j = 0; $j < 8; $j++) {
		list($ind, $t) = explode(' ', trim(fgets(STDIN)));
		$time[$i][] = array('index' => $ind, 'time' => $t);
	}
	usort($time[$i], function($a, $b){
		return $a['time'] >= $b['time'] ? 1 : -1;
	});
	echo $time[$i][0]['index'] . " " . $time[$i][0]['time'] . "\n";
	echo $time[$i][1]['index'] . " " . $time[$i][1]['time'] . "\n";

}

$rest = array();
for ($i = 0; $i < 3; $i++) {
	unset($time[$i][0]);
	unset($time[$i][1]);
	$rest = array_merge($rest, $time[$i]);
}

usort($rest, function($a, $b){
	return $a['time'] >= $b['time'] ? 1 : -1;
});

echo $rest[0]['index'] . " " . $rest[0]['time'] . "\n";
echo $rest[1]['index'] . " " . $rest[1]['time'] . "\n";

Measured memory_bytes: 6656
# -*- coding: utf-8 -*-
n = int(input())
inputList = list(map(int, input().split()))

count = 0
while True:
    isEven = True
    for i in range(n):
        isEven &= (inputList[i] % 2 == 0)

    if isEven:
        count = count + 1
        for i in range(n):
            inputList[i] /= 2
    else:
        break

print(count)

Measured memory_bytes: 3188
#[warn(unused_imports)]
use proconio::{
   fastout, input,
   marker::{Bytes, Chars, Isize1, Usize1}
};

#[fastout]
fn main() {
   input! {
      s: String,
   }

   if s=="ABC" {
      println!("ARC");
   }else {
      println!("ABC");
   }
}


Measured memory_bytes: 2140
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;


inline int toidx(int x, int y, int d, int outnode)
{
	return (x * 51 + y) * 8 + d * 2 + outnode;
}

inline int todir(int idx)
{
	return (idx / 2) % 4;
}


int main()
{
	int n, x0, y0, t;
	vector<vector<int> > g(51 * 51 * 8);

	scanf("%d%d%d%d", &n, &x0, &y0, &t);
	for(int i = 0; i < n; ++i) {
		int ax, ay, bx, by;
		scanf("%d%d%d%d", &ax, &ay, &bx, &by);
		for(int x = min(ax, bx); x < max(ax, bx); ++x) {
			g[toidx(x, ay, 0, true)].push_back(toidx(x + 1, ay, 0, false));
			g[toidx(x + 1, ay, 2, true)].push_back(toidx(x, ay, 2, false));
		}
		for(int y = min(ay, by); y < max(ay, by); ++y) {
			g[toidx(ax, y, 1, true)].push_back(toidx(ax, y + 1, 1, false));
			g[toidx(ax, y + 1, 3, true)].push_back(toidx(ax, y, 3, false));
		}
	}
	for(int x = 0; x < 51; ++x) {
		for(int y = 0; y < 51; ++y) {
			for(int d1 = 0; d1 < 4; ++d1) {
				for(int d2 = 0; d2 < 4; ++d2) {
					if(d1 != d2 && d1 % 2 == d2 % 2)
						continue;
					g[toidx(x, y, d1, false)].push_back(toidx(x, y, d2, true));
				}
			}
		}
	}

	vector<bool> mem[2];
	mem[0].resize(51 * 51 * 8);
	mem[1].resize(51 * 51 * 8);

	for(int d = 0; d < 4; ++d)
		mem[0][toidx(x0, y0, d, true)] = true;

	for(int gps_step = 0; gps_step < t; ++gps_step) {

		char temp_buf[32];
		int dist, dir;
		scanf("%d%s", &dist, temp_buf);

		if(temp_buf[0] == 'E') dir = 0;
		if(temp_buf[0] == 'N') dir = 1;
		if(temp_buf[0] == 'W') dir = 2;
		if(temp_buf[0] == 'S') dir = 3;

		for(int step = 0; step < dist * 2; ++step) {

			vector<bool> &cur = mem[step % 2];
			vector<bool> &next = mem[(step + 1) % 2];
			fill(next.begin(), next.end(), false);

			for(int idx = 0; idx < 51 * 51 * 8; ++idx) {

				if(!cur[idx])
					continue;
				for(int i = 0; i < g[idx].size(); ++i) {
					int v = g[idx][i];
					if(step == dist * 2 - 1 && todir(idx) != dir && todir(v) != dir)
						continue;
					next[v] = true;
				}
			}
		}
	}

	for(int x = 0; x < 51; ++x) {
		for(int y = 0; y < 51; ++y) {
			for(int d = 0; d < 4; ++d) {
				int idx = toidx(x, y, d, true);
				if(mem[0][idx] && g[idx].size() > 0) {
					printf("%d %d\n", x, y);
					break;
				}
			}
		}
	}

	return 0;
}

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

int gcd( int x, int y, int* count )
{
	int t;
	*count = 0;
	if( x < y ){
		t = x;
		x = y;
		y = t;
	}
	while( 1 ){
		++*count;
		if( ( t = x % y ) == 0 ){
			break;
		}
		x = y;
		y = t;
	}
	return y;
}

int main()
{
	int x, y;
	while( cin >> x >> y  && ( x != 0 || y != 0 ) ){
		int count = 0;
		int g = gcd( x, y, &count );
		cout << g << " " << count << endl;
	}
	return 0;
}

Measured memory_bytes: 1156
# -*- coding: utf-8 -*-
n = int(input())
xu = []
for i in range(n):
    xu.append([str(i) for i in input().split()])

ans = 0
for i in range(n):
    if xu[i][1] == "JPY":
        ans += int(xu[i][0])
    elif xu[i][1] == "BTC":
        ans += float(xu[i][0]) * 380000
print(ans)


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

int main() {
  int64_t X,o;
  int k=0;
  int z;
  o=100;
  cin >>X;
  while(o<X){
    o=o+o/100;
    k=k+1;
  }
  cout <<k <<endl;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#include <algorithm>
#include <string>
using namespace std;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    cout << min(A, B) + min(C, D) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;
const int N=100086;
int a[N];
int ans[N];
int n;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		ans[a[i]]=i;
	}
	for(int i=1;i<=n;i++)
		printf("%d ",ans[i]);
	printf("\n");
	return 0;
}

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

int main() {
	int A, B;
	string S;
	bool check = true;
	cin >> A >> B >> S;
	for (int i = 0; i < S.size(); i++) {
		if (i != A) {
			int x = S[i];
			if (x < 48 || 57 < x) check = false;
		}
		if (i == A) {
			if (S[i] != '-') check = false;
		}
	}
	if (check) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline bool Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+" ";
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e17;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 200005;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n);
    cins(all(a));
    SORT(a);
    a.push_back(-1);
    int cnt = 1,ans = 0;
    rep(i,n){
        if (a[i] == a[i+1]){
            cnt++;
        }
        else{
            if (a[i] > cnt) ans += cnt;
            else ans += cnt-a[i];
            cnt = 1;
        }
    }
    PRINT(ans);
}


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

int main(){
  string s;
  cin >>s;
  char t1[3]={'R','U','D'};
  char t2[3]={'L','U','D'};
  int p=0,q=0;
  for(int i=0;i<s.size();++i){
    for(int j=0;j<3;j++){
      
      if(i%2==0){
        if(s[i]==t1[j]) p++;
      }
      else{
        if(s[i]==t2[j]) q++;
      }
    }
  }
  if(p+q==s.size()) cout <<"Yes"<<endl;
  else cout <<"No"<<endl;
}
  
          
  

Measured memory_bytes: 3600
import java.util.*;class Main{public static void main(String[]z){int[]a=new int[30];int i=0,e=2,c;for(;i<30;a[i++]=e++)for(;f(e,a)<1;e++);for(Scanner s=new Scanner(System.in);s.hasNext();System.out.println(c))for(c=0,i=2,e=s.nextInt();i<e;++i)if(f(i,a)+f(e-i+1,a)>1)++c;}static int f(int n,int[]s){for(int e:s)if(e>0&&n!=e&&n%e<1)return 0;return 1;}}

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

int main()
{
    double a1,b1,a2,b2;
    cin>>a1>>b1>>a2>>b2;
    cout<<fixed<<setprecision(8)<<sqrt((a1-a2)*(a1-a2)+(b1-b2)*(b1-b2))<<endl;
    return 0;
}



Measured memory_bytes: 3284
#include <iostream>
#include <string>
using namespace std;
int main(){
        int i;
        std::string s, t;
        cin >> s;
        t = "Yes";
        for (i=0;i<=int(s.size()/2);i++){
                if (s[(2*i+1)]==('R')){
                        t= "No";
                }
                if (s[(2*i)]==('L')){
                        t= "No";
                }
        }                
        cout << t;                 
}


Measured memory_bytes: 256
#include <stdio.h>
int gcd(int a,int b){
  int i;
  if(a<b){
    i=a;
    a=b;
    b=i;
  }
  do{
    i=a%b;
    a=b;
    b=i;
  }while(b!=0);
  return a;
}




int main(){
  int n,sum=0,i,j,k;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      for(k=1;k<=n;k++){
        sum=sum+gcd(gcd(i,j),k);
      }
    }
  }
  printf("%d",sum);
  return 0;
}

Measured memory_bytes: 1732
#include <iostream>
#include <string>
#include <vector>
#include<algorithm>
#include <stdio.h>
#include <bitset>
#include<math.h>
#include<list>
#include<map>
using namespace std;
typedef long long ll;
#define PI 3.14159265358979323846  


int main() {
	int n, m;
	vector<int> a, b;
	int ans=0;
	cin >> n >> m;
	if (n > 1) {
		vector<int> nv(n, -1);
		bool ansF = true;
		for (int i = 0; i < m; i++) {
			int k, v;
			cin >> k >> v;
			k = k - 1;
			if (nv[k] == v || nv[k] == -1) {
				nv[k] = v;
			}
			else {
				ans = -999;
			}
		}
		if (ans != -999) {
			for (int i = 0; i < n; i++) {
				if (i == 0 && nv[i] == 0) {
					cout << -1 << endl;
					ansF = false;
				}
				if (nv[i] == -1) {
					if (i == 0) {
						nv[i] = 1;
					}
					else {
						nv[i] = 0;
					}
				}
				//cout << nv[i];
				ans = (ans + nv[i]) * 10;
			}
			ans = ans / 10;
			if (ans) {
				cout << ans << endl;
			}
		}
		else {
			cout << -1 << endl;
		}
	}
	else if(m>0){
		int bv=-1;
		bool frag=true;
		int ans;
		for (int i = 0; i < m; i++) {
			int kx, vx;
			cin >> kx >> vx;
			if (bv == vx || bv == -1) {
				bv = vx;
				ans = vx;
			}
			else {
				frag = false;
			}
		}
		if (frag) {
			cout << ans << endl;
		}
		else {
			cout << -1 << endl;
		}
	}
	else {
		cout << 0 << endl;
	}
}

Measured memory_bytes: 256
n, m, xx, yy = map(int, input().split())
x = list(map(int , input().split()))
y = list(map(int , input().split()))
x.sort()
y.sort()

zx = max(x[-1], xx)
zy = min(y[0], yy)

if yy == x[-1]:
    print('War')
    exit()
if xx == y[0]:
    print('War')
    exit()
if x[-1] == y[0]:
    print('War')
    exit()
if zx > zy:
    print('War')
    exit()

print('No War')

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

struct Solver {
	void solve() {
		long A, B, N;
		cin >> A >> B >> N;
		long x = min( B-1, N );
		long ans = floor( A*x / B ) - A*floor( x/B );
		cout << ans << endl;
	}
};

int main() {
	ios::sync_with_stdio( false );
	cout << fixed << setprecision( 10 );
	Solver().solve();
	return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
#define int long long
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}

int a[3][3], ta = 0;
bool mu = true;

signed main() {
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> a[i][j];
			ta += a[i][j];
		}
	}
	if (ta % 3 != 0)mu = false;
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 3; k++) {
				if (i != j && j != k && i != k) {
					if (ta / 3 != a[i][0] + a[j][1] + a[k][2]) {
						mu = false;
						break;
					}
				}
			}
		}
	}
	if (mu == true)cout << "Yes" << endl;
	else cout << "No" << endl;
	getchar(); getchar();
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 1000000

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

	int N, T;
	cin >> N >> T;
	ll A[N];
	rep(i, 0, N) cin >> A[i];

	ll minArray[N];
	minArray[0] = INF;
	ll tmp_min = A[0];
	rep(i, 1, N) {
		minArray[i] = tmp_min;
		tmp_min = min(tmp_min, A[i]);
	}

	map<int, ll> m;
	ll tmp_max = -INF;
	rep(i, 1, N) {
		ll current_value = A[i] - minArray[i];
		tmp_max = max(tmp_max, current_value);
		m[current_value]++;
	}

	cout << m[tmp_max] << endl;



}


Measured memory_bytes: 8064
//   __                    .__              ________ .________ ________   ______  
//  |  | __  ____    ______|  |__   __ __  /  _____/ |   ____//   __   \ /  __  \ 
//  |  |/ /_/ __ \  /  ___/|  |  \ |  |  \/   __  \  |____  \ \____    / >      < 
//  |    < \  ___/  \___ \ |   Y  \|  |  /\  |__\  \ /       \   /    / /   --   \
//  |__|_ \ \___  >/____  >|___|  /|____/  \_____  //______  /  /____/  \______  /
//       \/     \/      \/      \/               \/        \/                  \/ 

#include<bits/stdc++.h>
#define range 100005
#define mod 1000000007
#define eps 1e-9
#define PI 3.14159265358979323846
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define ALL(V) V.begin(), V.end()
#define _ <<" "<<

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef pair <int, int> ii;
typedef pair<int, pair<int,int> > iii;
typedef vector<ii> vii;
typedef vector<iii> viii;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//freopen("test.txt","r",stdin);
	int n;
	cin>>n;
	int count= 0 ;
	for(int i=1;i<=n;i++) count+=i%2;
	long double output =((long double)count/(long double)n);
	cout<<fixed<<setprecision(10)<<output; 
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rep1(i, n) for (ll i = 1; i < n; i++)
using P = pair<ll, ll>;

int main()
{
    ll r;
    cin >> r;
    cout << 3 * r * r << endl;
    return 0;
}

Measured memory_bytes: 3536
#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string.h>
#include <stdlib.h>
#include <limits>
#include <iomanip>
using namespace std;

int main(){

    int N, K;
    cin >> N >> K;

    int ans = 0;
    do{
        ans++;
        // cout << ans << "\t" << pow(K, ans) << "\t" << N << endl;
    }while( N >= pow( K, ans ) );

    cout << ans << endl;

}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define SZ(x) (int)(x).size()
#define endl '\n'
#define FOR(a, b, c) for (auto a = (b); (a) < (c); ++(a))
#define F0R(a, b) FOR (a, 0, (b))
#define CEIL(a, b) ((a) + (b)-1) / (b)
template <class T>
bool ckmin(T& a, const T& b) {
  return a > b ? a = b, true : false;
}
template <class T>
bool ckmax(T& a, const T& b) {
  return a < b ? a = b, true : false;
}
#ifndef DEBUG
#define DEBUG 0
#endif
#define dout \
  if (DEBUG) std::cerr
#define dvar(...) " [" << #__VA_ARGS__ ": " << mt(__VA_ARGS__) << "] "
template <typename T>
struct IsC {
  template <typename C>
  static char test(typename C::const_iterator*);
  template <typename C>
  static int test(...);
  static const bool value = sizeof(test<T>(0)) == sizeof(char);
};
template <>
struct IsC<string> {
  static const bool value = false;
};
template <typename C>
typename enable_if<IsC<C>::value, ostream&>::type operator<<(ostream&, const C&);
template <typename T1, typename T2>
ostream& operator<<(ostream&, const pair<T1, T2>&);
template <typename... T> using TS = tuple_size<tuple<T...>>;
template<size_t idx, typename... T>
typename enable_if<TS<T...>::value == idx + 1, ostream&>::type
operator<<(ostream& o, const tuple<T...>& t) {
  return o << ", " << get<idx>(t) << ')';
}
template<size_t idx, typename... T>
typename enable_if<0 < idx && idx + 1 < TS<T...>::value, ostream&>::type
operator<<(ostream& o, const tuple<T...>& t) {
  return operator<<<idx + 1>(o << ", " << get<idx>(t), t);
}
template<size_t idx = 0, typename... T>
typename enable_if<1 < TS<T...>::value && !idx, ostream&>::type
operator<<(ostream& o, const tuple<T...>& t) {
  return operator<<<idx + 1>(o << '(' << get<idx>(t), t);
}
template<typename T>
ostream& operator<<(ostream& o, const tuple<T>& t) {
  return o << get<0>(t);
}
template <typename T1, typename T2>
ostream& operator<<(ostream& o, const pair<T1, T2>& p) {
  return o << mt(p.fi, p.se);
}
template <typename C>
typename enable_if<IsC<C>::value, ostream&>::type operator<<(
    ostream& o, const C& c) {
  o << '[';
  for (auto it = c.cbegin(); it != c.cend(); ++it)
    o << *it << (next(it) != c.cend() ? ", " : "");
  return o << ']';
}
template <typename T>
void tprint(vector<vector<T>>& v, size_t width = 0, ostream& o = cerr) {
  if (!DEBUG) return;
  for (auto& vv : v) {
    for (auto& i : vv) o << setw(width) << i;
    o << endl;
  }
}


void solve() {
  int a;
  cin >> a;
  cout << a + a * a + a * a * a << endl;
}

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

  int tt = 1;
  FOR (t, 1, tt + 1) {
    // cout << "Case #" << t << ": ";
    solve();
  }
  
  return 0;
}


Measured memory_bytes: 3648
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String line = scanner.nextLine();
        String[] token = line.split(" ");
        int k = Integer.parseInt(token[0]);
        int x = Integer.parseInt(token[1]);

        int left = x - k + 1;
        int right = x + k - 1;

        for (int i = left; i <= right; i++) {
            System.out.print(i);
            if (i != right) {
                System.out.print(" ");
            } else {
                System.out.println();
            }
        }
    }

}


Measured memory_bytes: 22996
using System;
using System.Text;

namespace ITP1_8_A
{
    class Program
    {
        static void Main(string[] args)
        {
            string text = Console.ReadLine();
            StringBuilder sb = new StringBuilder();
            for(int i = 0; i < text.Length; i++)
            {
                char ch = text[i];
                if ('A' <= ch && ch <= 'Z')
                    sb.Append(char.ToLower(ch));
                else if ('a' <= ch && ch <= 'z')
                    sb.Append(char.ToUpper(ch));
                else
                    sb.Append(ch);
            }
            Console.WriteLine(sb);
        }
    }
}

Measured memory_bytes: 9064
parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseFloat(x::SubString{String}) = parse(Float64, x)
parseFloat(x::Char) = parse(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n,m=parseMap(split(readline()))
    print((100n+1800m)*(2^m))
end
main()

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

void sieve(vector<vector<int>>&g){
	vector<int>sv(g.size(),true);
	for(int i=2;i<sv.size();++i){
		if(!sv.at(i))continue;
		for(int j=i+i;j<sv.size();j+=i){
			sv.at(j)=false;
			g.at(j).emplace_back(i);
		}
	}
}

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	int mx=0;
	vector<int>a(n); for(auto&&i:a)cin>>i,mx=max(mx,i);
	vector<vector<int>>g(mx+1);
	sieve(g);
	vector<int>cnt(mx+1,0);
	bool pair=true;
	for(auto&&i:a){
		if(i!=1&&cnt.at(i)){
			pair=false;
		}
		++cnt.at(i);
		for(auto&&j:g.at(i)){
			if(cnt.at(j)){
				pair=false;
			}
			++cnt.at(j);
		}
	}
	bool one=cnt.at(1);
	cnt.at(1)=0;
	string ans;
	if(pair)ans="pairwise coprime"s;
	else if(one||*max_element(cnt.begin(),cnt.end())<n)ans="setwise coprime"s;
	else ans="not coprime"s;
	cout<<ans<<"\n"s;
}


Measured memory_bytes: 64184
# -*- coding: utf-8 -*-

import sys

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]


    token = lines[0].split()
    a = int(token[0])
    b = int(token[1])
    t = int(token[2])

    return (a, b, t)


def solve(a, b, t):


    return t // a * b


def main():
    # 出力

    print("%s" % solve(*parse_input()))

if __name__ == '__main__':

    main()
	

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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 (b<a) { a=b; return 1; } return 0; }

ll dp[(1<<21)];

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

    //2^21 = 2*10^6
    //O(N*2~N)
    int n;cin>>n;
    int a[n][n];
    rep(i,n)rep(j,n) cin>>a[i][j];
    dp[0]=1;
    rep(bit,(1<<n)-1){
        int k=__builtin_popcount(bit);
        rep(i,n){
            if(a[k][i]==1 and (((bit>>i)&1)==0)){
                dp[bit|(1<<i)]=(dp[bit|(1<<i)]+dp[bit])%mod;
            }
        }
    }
    // rep(i,(1<<n)){
    //     cout<<bitset<3>(i)<<" : "<<dp[i]<<endl;
    // }
    cout<<dp[(1<<n)-1]<<endl;
    return 0;
}


Measured memory_bytes: 16640
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		String str=sc.next();
		char[] c=str.toCharArray();
		for(int i=c.length-1;i>=0;i--){
			System.out.print(c[i]);
		}
		System.out.println();
	}
}

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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
 
Int INF = 1e18;
int inf = 1e9;
Int mod = 1e9+7;

Int d[1001][1001];

int main() {
    Int h, w;
    cin >> h >> w;
    vector<string> s(h);
    for (Int i = 0; i < h; i++) {
        cin >> s[i];
    }
    for (Int i = 0; i < h; i++) {
        for (Int j = 0; j < w; j++) {
            d[i][j] = INF;
        }
    }
    queue<pair<Int, Int>> q;
    for (Int i = 0; i < h; i++) {
        for (Int j = 0; j < w; j++) {
            if (s[i][j] == '#') {
                d[i][j] = 0;
                q.push({i, j});
            }
        }
    }
    while (not q.empty()) {
        pair<Int, Int> p = q.front();
        q.pop();
        Int dy[] = {0, 1, 0, -1};
        Int dx[] = {1, 0, -1, 0};
        for (Int i = 0; i < 4; i++) {
            Int ny = p.fi + dy[i];
            Int nx = p.se + dx[i];
            if (ny < 0 or ny == h or nx < 0 or nx == w) continue;
            if (d[ny][nx] > d[p.fi][p.se] + 1) {
                d[ny][nx] = d[p.fi][p.se] + 1;
                q.push({ny, nx});
            }
        }
    }
    Int res = 0;
    for (Int i = 0; i < h; i++) {
        for (Int j = 0; j < w; j++) {
            res = max(res, d[i][j]);
        }
    }
    dump(res);
    return 0;
}

Measured memory_bytes: 25524
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <fstream>
#include <map>
#include <vector>
//#include <unordered_map>
//#include <unordered_set>
#include <stack>
#include <set>
#include <queue>
#include <list>

using namespace std;
int k[55][30];
int mi[30];
int main()
{
    int n;
    string s;
    cin>>n;
    for(int i=0;i<n;++i)
    {
        cin>>s;
        for(int j=0;j<s.length();++j)
            ++k[i][s[j]-'a'];
    }
    for(int j=0;j<26;++j)
    {
        mi[j]=2333333;
        for(int i=0;i<n;++i)
            mi[j]=min(mi[j],k[i][j]);
    }
    for(int i=0;i<26;++i)
        for(int j=0;j<mi[i];++j)
        putchar(i+'a');
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
from time import time
import random


def main():
    random.seed(0)

    now = time()

    MAX = 26

    d = int(input())
    c = list(map(int, input().split()))
    s = [list(map(int, input().split())) for _ in range(d)]

    t = []
    prev = [0] * MAX
    for day, row in enumerate(s, 1):
        mxi = 1
        mx = 0
        for i, (es, ec) in enumerate(zip(row, c), 1):
            point = es + ec * (day - prev[i - 1])
            if point > mx:
                mx = point
                mxi = i

        prev[mxi - 1] = day
        t.append(mxi)

    print(*t, sep="\n")
    exit()

    last = [0] * MAX

    score = 0
    for day, e in enumerate(t, 1):
        score += s[day-1][e-1]
        last[e-1] = day

        for ec, elast in zip(c, last):
            score -= ec * (day - elast)

    d_li = []
    for i in range(1, d + 1):
        ln = max(1, (-(i - d // 2) ** 2 + d ** 2 // 4) // 500)
        d_li += [i] * ln

    di_max = len(d_li) - 1

    #c_sum = sum(c)
    #c_li = []
    #for i, e in enumerate(c, 1):
    #    c_li += [i] * e

    sc = []
    for row in s:
        app = []
        for i, (es, ec) in enumerate(zip(row, c), 1):
            app += [i] * max(1, (es + ec * d) // 20)

        sc.append(app)

    while time() - now <= 1.85:
        prev_score = score

        di = random.randint(0, di_max)
        ed = d_li[di]
        qi = random.randint(0, len(sc[ed-1]) - 1)
        eq = sc[ed-1][qi]

        q_old = t[ed-1]
        d_prev = {q_old: 0, eq: 0}

        c_old = c[q_old-1]
        c_new = c[eq-1]

        for day, e in enumerate(t, 1):
            if e in d_prev.keys():
                d_prev[e] = day

            score += c_old * (day - d_prev[q_old])
            score += c_new * (day - d_prev[eq])

        score -= s[ed-1][q_old-1]
        score += s[ed-1][eq-1]

        t[ed-1] = eq

        d_prev = {q_old: 0, eq: 0}

        for day, e in enumerate(t, 1):
            if e in d_prev.keys():
                d_prev[e] = day

            score -= c_old * (day - d_prev[q_old])
            score -= c_new * (day - d_prev[eq])

        if prev_score > score:
            t[ed-1] = q_old
            score = prev_score

    print(*t, sep="\n")


if __name__ == "__main__":
    main()


Measured memory_bytes: 83748
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define maxs(x,y) x = max(x, y)
#define mins(x,y) x = min(x, y)
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    ll n, k;
    cin >> n >> k;
    vector<ll> h(n);
    REP(i, n) cin >> h[i];
    
    ll dp[n+k+3];
    REP(i, n+k+3) dp[i] = INF;

    dp[0] = 0;

    RREP(i, 0, n+1) {
        RREP(j, 1, k+1) {
            mins(dp[i+j], dp[i]+abs(h[i]-h[i+j]));
        }
    }

    // REP(i, n) cout << dp[i] << endl;
    

    cout << dp[n-1] << endl;



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

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

using namespace std;

int N, M;
int a[55][55];
int b[1111][1111];

vector<int> sw[1111];

void print()
{
  for(int i = 0; i < N+M; i++) {
    for(int j = 0; j < N+M; j++) cout << b[i][j] << " ";
    cout << endl;
  }
}

int main()
{
  while(cin >> N, N) {
    memset(a, 0, sizeof(a));
    memset(b, 0, sizeof(b));
    for(int i = 0; i < 55; i++) sw[i].clear();
    for(int i = 0; i < N; i++) {
      for(int j = 0; j < N; j++) {
	cin >> a[i][j];
	b[i][j] = a[i][j];
      }
    }
    M = 0;
    sw[0].push_back(0);
    for(int i = 0; i < a[0][1]-2; i++) {
      sw[M].push_back(N+M+1);
      sw[M+1].push_back(N+M);
      M++;
    }
    sw[M].push_back(1);
    M++;
    for(int i = 0; i < M; i++) {
      b[0][N+i] = b[N+i][0] = i+1;
      b[1][N+i] = b[N+i][1] = a[0][1]-i-1;
      for(int j = 0; j < M; j++) b[N+i][N+j] = b[N+j][N+i] = abs(i-j);
    }
    for(int i = 2; i < N; i++) {
      bool judge = false;
      for(int j = 0; j < M; j++) {
	bool flag = false;
	for(int k = 0; k < i; k++) {
	  if(b[N+j][k] + 1 != b[k][i]) flag = true;
	}
	if(flag) continue;
	sw[j].push_back(i);
	for(int k = 0; k < M; k++) b[i][N+k] = b[N+k][i] = b[N+j][N+k] + 1;
	judge = true;
	break;
      }
      if(!judge) {
	for(int j = 0; j < M; j++) {
	  bool check = false;
	  for(int k = 0; k < i-1; k++) {
	    if(b[i][k] - b[N+j][k] != b[i][k+1] - b[N+j][k+1]) check = true;
	  }
	  if(check) continue;
	  int m = M;
	  sw[j].push_back(N+M);
	  sw[M].push_back(j);
	  for(int k = 0; k < b[i][0]-b[N+j][0]-2; k++) {
	    sw[M].push_back(N+M+1);
	    sw[M+1].push_back(N+M);
	    M++;
	  }
	  sw[M].push_back(i);
	  M++;
	  for(int k = m; k < M; k++) {
	    for(int l = 0; l < i; l++) b[l][N+k] = b[N+k][l] = b[l][N+j] + k-m+1;
	    for(int l = m; l < M; l++) b[N+k][N+l] = b[N+l][N+k] = abs(k-l);
	  }
	  for(int k = m; k < M; k++) {
	    b[N+j][N+k] = b[N+k][N+j] = k-m+1;
	    b[i][N+k] = b[N+k][i] = M-k;
	    for(int l = 0; l < m; l++) b[N+l][N+k] = b[N+k][N+l] = b[N+j][N+l] + b[N+j][N+k];
	  }
	  for(int k = 0; k < m; k++) b[i][N+k] = b[N+k][i] = b[N+j][N+k] + b[N+j][N+M-1] + 1;
	  break;
	}
      }
    }
    vector<int> ans;
    for(int i = 0; i < M; i++) ans.push_back(sw[i].size());
    sort(ans.begin(), ans.end());
    for(int i = 0; i < M; i++) cout << ans[i] << (i==M-1 ? '\n' : ' ');
  }  
  return 0;
}

Measured memory_bytes: 7872
#include <iostream>
#define llint long long
#define mod 1000000007

using namespace std;

llint n, m, k;
llint x[25][25];
int y[1<<19][20];
llint dp[21][1<<19];
llint dp2[20][1<<19];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> m >> k;
	n--;
	
	for(int i = 1; i <= m; i++){
		for(int j = 0; j < n; j++){
			x[i][j] = -1;
		}
	}
	
	llint a, b, c;
	for(int i = 1; i <= k; i++){
		cin >> a >> b >> c;
		b--;
		x[a][b] = c;
	}
	
	llint N = 1<<n;
	for(int i = 0; i < N; i++){
		for(int j = 0; j < n; j++){
			if((i & (1<<j)) == 0) continue;
			int t = i & ~(1<<j);
			for(int k = j+1; k < n; k++){
				if((i & (1<<k)) == 0){
					t |= (1<<k);
					break;
				}
			}
			y[i][j] = t;
		}
	}
	
	dp[0][0] = 1;
	for(int i = 0; i < m; i++){
		for(int j = 0; j < n; j++){
			for(int k = 0; k < N; k++){
				dp2[j][k] = 0;
			}
		}
		for(int j = 0; j < N; j++) dp2[n][j] = dp[i][j];
		
		for(int j = n-1; j >= 0; j--){
			for(int k = 0; k < N; k++){
				dp2[j][k] = dp2[j+1][k];
				if(k & (1<<j)) dp2[j][k] += dp2[j+1][y[k][j]], dp2[j][k] %= mod;
			}
		}
		
		for(int j = 0; j < N; j++){
			dp[i+1][j] = dp2[0][j];
			for(int k = 0; k < n; k++){
				if(x[i+1][k] == -1) continue;
				if(((j>>k)&1) != x[i+1][k]){
					dp[i+1][j] = 0;
					break;
				}
			}
		}
	}
	
	llint ans = 0;
	for(int j = 0; j < N; j++) ans += dp[m][j], ans %= mod;
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 207232
#include<iostream>
using namespace std;
int main(){
	int dice[10]; cin >> dice[1] >> dice[2] >> dice[3] >> dice[4] >> dice[5] >> dice[6];
	short int q; cin >> q;
	for (short int i = 0; i < q; i++){
		short int a, b; cin >> a >> b;
		if (dice[1] == a) {
			if (dice[2] == b)cout << dice[3];
			else if (dice[3] == b)cout << dice[5];
			else if (dice[5] == b)cout << dice[4];
			else cout << dice[2];
		}
		else if (dice[2] == a) {
			if (dice[6] == b)cout << dice[3];
			else if (dice[3] == b)cout << dice[1];
			else if (dice[1] == b)cout << dice[4];
			else cout << dice[6];
		}
		else if (dice[3] == a) {
			if (dice[6] == b)cout << dice[5];
			else if (dice[5] == b)cout << dice[1];
			else if (dice[1] == b)cout << dice[2];
			else cout << dice[6];
		}
		else if (dice[4] == a) {
			if (dice[6] == b)cout << dice[2];
			else if (dice[2] == b)cout << dice[1];
			else if (dice[1] == b)cout << dice[5];
			else cout << dice[6];
		}
		else if (dice[5] == a) {
			if (dice[6] == b)cout << dice[4];
			else if (dice[4] == b)cout << dice[1];
			else if (dice[1] == b)cout << dice[3];
			else cout << dice[6];
		}
		else if (dice[6] == a) {
			if (dice[5] == b)cout << dice[3];
			else if (dice[3] == b)cout << dice[2];
			else if (dice[2] == b)cout << dice[4];
			else cout << dice[5];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define MAX 1000002
#define MIN_VALUE -2000000001
using namespace std;
int T[MAX];
int heap;

void maxHeapify(int *A,int i){
    int largest,l=2*i,r=2*i+1;
    if(l<=heap&&A[l]>A[i])largest =l;
    else largest=i;
    if(r<=heap&&A[r]>A[largest])largest=r;
    if(largest!=i){
        swap(A[i],A[largest]);
        maxHeapify(A,largest);
    }
}
void buildMaxHeap(int *A){
    for(int i=heap/2;i>0;i--){
        // for(int j=1;j<=heap;j++)printf(" %d",T[j].k); 
        // printf("\n"); 
        maxHeapify(A,i);
    }
}

int main(){
    int i;
    cin>>heap;
    for(i=1; i<=MAX; i++)if(i<=heap)cin>>T[i];else T[i]=MIN_VALUE;
    buildMaxHeap(T);
    for(i=1;i<=heap;i++)cout<<" "<<T[i];; 
    cout<<endl;
    return 0;
}


Measured memory_bytes: 6968
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007

int main()
{
	long long int n, k;
	cin >> n >> k;
	// qu1: まだ答えの集合に含まれるものとして選ばれたことのないもの　おいしさの大きいものから順に
	// qu2: 今答えの集合に含まれるもの　おいしさの小さいものから順に
	priority_queue<pair<long long int, long long int> > qu1, qu2;
	for(int i = 0; i < n; i++){
		long long int t, d;
		cin >> t >> d;
		t--;
		qu1.push(make_pair(d, t));
	}
	long long int sum = 0;
	long long int cnt[100001] = {};
	for(int i = 0; i < k; i++){
		int d = (qu1.top()).first;
		int t = (qu1.top()).second;
		qu1.pop();
		sum += d;
		cnt[t]++;
		qu2.push(make_pair(-d, t));
	}
	long long int x = 0;
	for(int i = 0; i < n; i++){
		if(cnt[i] > 0) x++;
	}
	long long int ans = sum + x * x;
	while(!qu2.empty()){
		long long int d, t;
		d = -(qu2.top()).first;
		t = (qu2.top()).second;
		qu2.pop();
		if(cnt[t] == 1) continue;
		sum -= d;
		cnt[t]--;
		while(!qu1.empty()){
			d = (qu1.top()).first;
			t = (qu1.top()).second;
			qu1.pop();
			if(cnt[t] > 0) continue;
			sum += d;
			cnt[t]++;
			x++;
			ans = max(ans, sum + x * x);
			break;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 5616
w, h, n = map(int, input().split())
li = []
ans = 0
for i in range(h):
  li.append([0]*w)

for i in range(n):
  x, y, a = map(int, input().split())

  if a == 1:
    for i in li:
      for j in range(x):
        i[j] = 1
  elif a == 2:
    for i in li:
      for j in range(x, w):
        i[j] = 1
  elif a == 3:
    for i in range(h - y,h):
      for j in range(w):
        li[i][j] = 1
  elif a == 4:
    for i in range(h - y):
      for j in range(w):
        li[i][j] = 1

for i in li:
  ans += i.count(0)

print(ans)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main() {
  string s;
  cin >> s;
  int g, p;
  int cnt = 0;
  g = p = 0;
  int _p = s.size() / 2;
  for (int i=0;i<s.size();i++) {
    if (s[i] == 'g') g++;
    else p++;
  }
  if (_p >= g) {
    cout << (p-g) << endl;
  } else {
    cout << (_p - p) << endl;
  }
}


Measured memory_bytes: 512
#include<stdio.h>
#include<math.h>
int main(void)
{
	double n;
	int i;
	double sum;
	double num[1000];
	double ave,s;
	
	while(1)
	{
		sum=0;
		s=0;
		
		scanf("%lf",&n);
		if(n==0)
		{
			break;
		}
		
		for(i=0;i<n;i++)
		{
			scanf("%lf",&num[i]);
			sum+=num[i];
		}
		ave=sum/n;
		
		for(i=0;i<n;i++)
		{
			s+=(num[i]-ave)*(num[i]-ave);
		}
		printf("%lf\n",sqrt(s/n));
	}
	
	return 0;
}


Measured memory_bytes: 2112
/* BISMILLAHIR RAHMANIR RAHIM */
#include<bits/stdc++.h>
using namespace std;
#define ll        long long
#define ull       unsigned long long
#define si(x)     scanf("%d", &x)
#define sll(x)    scanf("%lld", &x)
#define ssll(x,y)    scanf("%lld %lld", &x ,&y)
#define sd(x)     scanf("%lf", &x)
#define l0(i,n)   for(ll i=0; i<n; i++)
#define MAX       100005
#define maxn 	  200002
#define pb 		  push_back
#define mk 		  make_pair
#define endl	  "\n"
#define INF 	  1000000000
#define MOD		  1000000007
#define imie(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int main ()
{
		ios::sync_with_stdio(0);
		cin.tie(0);
		//CODE TONOY
		int a[33] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
		int n;
		cin >> n;
		cout << a[n-1] << endl;
		return 0;  
}  


Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int A = a + b, B = c + d;
  if (A > B)
    cout << "Left" << endl;
  else if (A == B)
    cout << "Balanced" << endl;
  else
    cout << "Right" << endl;
}

Measured memory_bytes: 256
n, a, b = map(int,input().split())
ans = 0
c = int(0)
memo = 0
i = int(0)
for i in range (1, n+1):
    c = 0
    memo = i
    while memo > 0:
        c += int(memo % 10)
        memo = int(memo / 10)
    if c >= a and c <= b:
        ans += i
print(ans)
    


Measured memory_bytes: 3060
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(string, S);
    ll l = S.size();
    while (l)
    {
        if (l >= 5 and (S.substr(l - 5, 5) == "erase" or S.substr(l - 5, 5) == "dream"))
        {
            l -= 5;
        }
        else if (l >= 6 and S.substr(l - 6, 6) == "eraser")
        {
            l -= 6;
        }
        else if (l >= 7 and S.substr(l - 7, 7) == "dreamer")
        {
            l -= 7;
        }
        else
        {
            OUT("NO");
            return 0;
        }
    }
    OUT("YES")
}

Measured memory_bytes: 3704
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<endl;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  int n, m;
  cin >> n >> m;
  cout << (m >= n ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 3604