akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
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 func(int n){
    while(n>=10){
        n /=10;
    }
    return n;
}

int main(){

    int n; cin >> n;

    vector<vector<ll>> C(10, vector<ll>(10, 0));
    for(int i=1; i<=n; i++){
        int first = func(i), last = i%10;
        C[first][last]++;
    }
    ll res = 0;
    for(int i=1; i<=n; i++){
        int first = func(i), last = i%10;
        res += C[last][first];
    }
    cout << res << ln;
}



Measured memory_bytes: 256
#include <bits/stdc++.h> 
#include <cstring>
using namespace std;
//typedef
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
//define
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)

int main(){
    int n,k,q;
    cin >> n >> k >> q;
    vi a(q),point(n);
    rep(i,q) cin >> a[i];

    rep(i,n) point.at(i) = k-q;
    rep(i,q) point.at(a.at(i)-1)++;
    rep(i,n){
        if(point.at(i) > 0){
            puts("Yes");
        }else{
            puts("No");
        }
    }
   
 return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <functional>

using namespace std;
using ll = long long;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, pair<ll, ll>> PP;

const ll MOD = 1e9 + 7;
const ll INF = 1 << 30;
const ll INF2 = 9e18;
const double INF3 = 9e14;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define fr first
#define sc second


int main() {
	ll n, a, b, x[100100], ans = 0;
	cin >> n >> a >> b;
	for (int i = 0;i < n;i++)cin >> x[i];
	for (int i = 0;i < n - 1;i++) {
		ans += min((x[i + 1] - x[i])*a, b);
	}
	cout << ans << endl;
	return 0;
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)

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

const int INTINF = 1e9;
const LL LLINF = 1e18;

void solve()
{
    priority_queue<string, vector<string>, greater<string>> PQ;
    string S;
    cin >> S;
    int K;
    cin >> K;
    int N = S.length();

    REP0(i, N)
    {

        for (int k = 1; k <= K; k++)
        { // i から k 文字目までの部分文字列を優先度つきキューに
            string s = "";
            for (int j = 0; i + j < N and j < k; j++)
            {
                s += S[i + j];
            }
            PQ.push(s);
        }
    }

    string ans = PQ.top();
    int rank = 1;
    while (rank < K)
    {
        string prev = ans;
        if (prev != PQ.top())
            rank++;
        ans = PQ.top();
        PQ.pop();
    }
    cout << ans << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}

Measured memory_bytes: 1660
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int a,b,l=100,s=0;
	for(int i=0;i<4;i++){
		cin>>a;
		s+=a;
		l=min(a,l);
	}
	cin>>a>>b;
	cout<<s-l+max(a,b)<<endl;
	return 0;
}

Measured memory_bytes: 1160
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

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

    let a: Vec<usize> = (0..n).map(|_| iterator.next().unwrap().parse().unwrap()).collect();
    let total: usize = a.iter().sum();

    let limit: usize = total / (4 * m);
    let mut count = 0;
    for v in a {
        if (4 * m * v) >= total {
            count += 1;
        }
    }

    return if count >= m {
        "Yes".to_string()
    } else {
        "No".to_string()
    }
}


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

typedef pair<int, int> pii;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

int main() {
	int X; cin >> X;
	for (int i = 1; i <= X; ++i) {
		if (X >= i * 100 && X <= i * 100 + 5 * i) {
			puts("1");
			return 0;
		}
	}
	puts("0");
	return 0;
}

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

int main() {
	char s[10000];
	cin >> s;
	char s0[] = "es";
	char s1[] = "s";
	
	if (s[strlen(s)-1] == 's') {
		strcat(s, s0);
		cout << s << endl;
	}
	else {
		strcat(s, s1);
		cout << s << endl;
	}
}

Measured memory_bytes: 3640
#include <iostream>
#include<string.h>
using namespace std;
int main(void){
    // Here your code !
    int n,m,k,x;
    cin>>n>>m>>k;
    bool check[1000000];
    memset(check,false,1000000*sizeof(bool));
    for(int i=0;i<n+1;i++){
        for(int j=0;j<m+1;j++){
            check[i*j+(n-i)*(m-j)]=true;
        }
    }
    if(check[k]){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
}

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

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

typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//定数
#define INF 1000000000005 //10^9:極めて大きい値,∞
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

int main(){
    ll N;
    cin>>N;
    int n=sqrt(N);
    ll ans=INF;
    for(ll a=1;a<=n;a++){
        if(N%a==0){
            ll b=N/a;
            ans=min(ans,a+b-2);
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

int dx[8] = {0,1,0,-1};
int dy[8] = {1,0,-1,0};

int main(){
    int n,j = 0;
    char e[27] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    string s;
    cin>>n;
    
    cin>>s;
    
    for(int i = 0; i < s.size();i++){
        for(int j = 0; j < 26; j++){
            if(s[i] == e[j]){
                s[i] = e[(j+n)%26];
                
                if((j+n)%26 < 0){
                    s[i] = e[((j+n)%26)+26];
                }
                break;
                }
        }
        cout<<s[i];
    }

    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
using System;

class E
{
	static void Main()
	{
		var n = Array.ConvertAll($"0{Console.ReadLine()}".ToCharArray(), x => x - '0').AsSpan();
		var r = 0;
		for (int i = n.Length - 1; i >= 0; i--)
			if (n[i] < 5 || n[i] == 5 && n[i - 1] < 5)
			{
				r += n[i];
			}
			else
			{
				r += 10 - n[i];
				n[i - 1]++;
			}
		Console.WriteLine(r);
	}
}


Measured memory_bytes: 38136
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
// Welcome to my source code!

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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    set<int> mod;
    for (int i = a, n = b * a; i <= n; i += a) mod.insert(i % b);
    if (mod.find(c) != mod.end()) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

#define all(v)  begin(v), end(v)
#define endl    '\n';
#define int     long long
#define pii     pair<int, int>
#define sz(x)   (int) x.size()

void test_case() {
    string s, t;
    cin >> s >> t;

    int x = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] != t[i]) {
            x++;
        }
    }
    cout << x << endl;
}

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

    int t = 1;
    // cin >> t;

    while (t--) { 
        test_case();
    }
    return 0;
}


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

int main(){
    int n; cin >> n;
    vector<int> h(n);
    for(int i=0; i<n; i++) cin >> h[i];
    bool ans = true;

    for(int i=0; i<n; i++){
        if(h[i-1]-h[i] >= 1 && i!=0){ // 前より小さかったらアウト
            ans = false; break;
        }else if(h[i+1]>h[i] && i!=n-1){ // 次が大きかったら小さくしておく
            h[i+1]--;
        }
    }
    if(ans) cout << "Yes" << endl;
    else    cout << "No" << endl;

    return 0;
}

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

#define rep(i,n) for(ll i=0;i<n;i++)
#define REP(i,a,n) for(ll i=a;i<n;i++)

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tiii;
typedef pair<ll, ll> pll;

const int INF = 100000000;
const ll LINF = 1e18+5;

int main() {
    ll H, W;
    cin >> H >> W;
    char S[20][20] = {};
    rep(i,H) {
        rep(j,W) {
            cin >> S[i][j];
        }
    }
    ll dist[400][400] = {};
    rep(i,400) {
        rep(j,400) {
            dist[i][j] = INF;
        }
    }
    rep(i, H*W) {
        ll h = i / W;
        ll w = i % W;
        if(S[h][w] == '#') continue;
        dist[i][i] = 0;
        if(h!=0 && S[h-1][w] == '.') {
            dist[i][(h-1)*W+w] = 1;
        }
        if(w!=0 && S[h][w-1] == '.') {
            dist[i][h*W+w-1] = 1;
        }
        if(w!=W-1 && S[h][w+1] == '.') {
            dist[i][h*W+w+1] = 1;
        }
        if(h!=H-1 && S[h+1][w] == '.') {
            dist[i][(h+1)*W+w] = 1;
        }
    }

    rep(k, H*W) {
        rep(i, H*W) {
            rep(j, H*W) {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }

    ll max = -1;
    rep(i, H*W) {
        ll h = i / W;
        ll w = i % W;
        if(S[h][w] == '#') continue;
        rep(j, H*W) {
            if(dist[i][j] > 10000) continue;
            if(max < dist[i][j]) max = dist[i][j];
        }
    }
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 1536
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const int INF = 2000000000;

    int N,K,A[101],ans;

int main(){
    ios_base::sync_with_stdio(false);
    cin>>N>>K;
    REP(i,N)cin>>A[i];
    REP(i,N){
        ans+=std::min(abs(A[i]-K),A[i])*2;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

main() {
  int a,b;
  scanf("%d %d",&a,&b);
  if(a>b){
    printf("a > b\n");
  }else if(a<b){
    printf("a < b\n");
  }else if(a==b){
    printf("a == b\n");
  }
}



Measured memory_bytes: 2072
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<cmath>
#include<set>
#include<stack>
#define ll long long
#define pb push_back
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)>(y)?(y):(x))
#define cls(name,x) memset(name,x,sizeof(name))
using namespace std;
const int inf=1e9+10;
const ll llinf=1e16+10;
const int maxn=5e2+10;
const int maxm=2e5+10;
const int mod=1e9+7;
const double pi=acos(-1.0);
int H,W,h,w;
int ans[maxn][maxn];
int main()
{
    //freopen("in.txt","r",stdin);
    while(~scanf("%d %d %d %d",&H,&W,&h,&w))
    {
        if(H%h==0&&W%w==0)
        {
            printf("No\n");
            continue;
        }
        else printf("Yes\n");
        int a1,b1,a2,b2;
        if(h==1||w==1) a1=1;
        else a1=(h+w-1);
        b1=h*w-a1;
        a2=0;
        for(int i=0;i<H;i++)
            for(int j=0;j<W;j++)
            if((i%h==0&&h!=1)||(j%w==0)&&w!=1) a2++;
        b2=H*W-a2;

        //printf("[%d %d %d %d]\n",a1,b1,a2,b2);
        int ta=b1+b2;
        int tb=-(a1+a2);
        //if(a1*ta+b1*tb>0)
        //    swap(ta,tb);
        for(int i=0;i<H;i++)
        {
            for(int j=0;j<W;j++)
            {
                if((i%h==0&&h!=1)||(j%w==0)&&w!=1)
                    printf("%d",ta);
                else printf("%d",tb);
                if(j==W-1) printf("\n");
                else printf(" ");
            }
        }
    }
    return 0;
}


Measured memory_bytes: 2048
import java.util.*;

public class Main {
    private static final int MOD = 1_000_000_007;
    private static final String YES = "Yes";
    private static final String NO = "No";

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int Q = sc.nextInt();
        int[] a = new int[N-1];
        int[] b = new int[N-1];
        int[] p = new int[Q];
        int[] x = new int[Q];
        for (int i=0; i<N-1; i++) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
        }
        for (int i=0; i<Q; i++) {
            p[i] = sc.nextInt();
            x[i] = sc.nextInt();
        }

        int[] ans = solve(N, Q, a, b, p, x);
        for (int i=0; i<N; i++) {
            if (i != 0) System.out.print(" ");

            System.out.print(ans[i]);
        }
        System.out.println();
    }

    private static int[] solve(int N, int Q, int[] a, int[] b, int[] p, int[] x) {
        int[] ans = new int[N];
        List<Integer>[] child = new List[N];
        for (int i=0; i<N; i++) {
            child[i] = new ArrayList();
        }

        for (int i=0; i<N-1; i++) {
            child[a[i]-1].add(b[i]-1);
            child[b[i]-1].add(a[i]-1);
        }
        for (int i=0; i<Q; i++) {
            ans[p[i]-1] += x[i];
        }

        Queue<Integer> queue = new LinkedList();
        queue.add(0);

        boolean[] history = new boolean[N];

        while (queue.size() > 0) {
            int node = queue.poll();
            int val = ans[node];

            history[node] = true;

            for (int i=0; i<child[node].size(); i++) {
                int childNode = child[node].get(i);

                if (history[childNode]) continue;

                ans[childNode] += val;
                queue.add(childNode);
            }
        }

        return ans;
    }
}

Measured memory_bytes: 185548
import java.util.*; 
import java.lang.*; 


public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
                
                int D = scan.nextInt();
                int T = scan.nextInt();
                int S = scan.nextInt();
                
                if(S*T<D){
                    System.out.println("No");
                }else{
                    System.out.println("Yes");
                }
                                         
        }
}

Measured memory_bytes: 35672
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <map>
#include <cstdlib>
using namespace std;
int main()
{
    string s;
    cin >> s;
    if (s[0] == s[1] && s[1] == s[2] || s[1] == s[2] && s[2] == s[3])
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
<?php

 $N = trim(fgets(STDIN));

$Ai = explode(" ", trim(fgets(STDIN)));


for ($i = 1; $i <= $N; $i++){

      $array["$i"] = $Ai[$i-1]; 

}

asort($array);

$count = 0;

   foreach ($array as $a => $b){

           if ($count == $N - 1) {

            echo $a;

           } else {

            echo $a." ";
            $count++;
          }

}

?>

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

int main(){
    int n; cin>>n;
    int ans=0;
    for(int i=0;i<n;i++){
        int a; cin>>a;
        while(a%2==0){
            ans++;
            a/=2;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, ll> Pl;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int mod = 1e+9 + 7;
const int INF = 1e+9;

string youbi[7] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};

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

    string s;
    cin >> s;
    for(int i = 0; i < 7; ++i){
        if(s == youbi[i]){
            cout << 7 - i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import numpy as np

def main():
	A, B, C = map(int, input().split(" "))
	
	tmp = []
	tmp.append(A)
	tmp.append(B)
	tmp.append(C)
	tmp.sort()
	
	a = abs(tmp[1] - tmp[0])
	b = abs(tmp[2] - tmp[1])
		
	print(a + b)
	
if __name__ == "__main__":
	main()


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

int main(void){
    int a, b, c, d, e, f, sai[6][6], n, x, y;
    cin >> a >> b >> c >> d >> e >> f;
    sai[a][b]=c;
    sai[a][c]=e;
    sai[a][d]=b;
    sai[a][e]=d;
    sai[b][a]=d;
    sai[b][c]=a;
    sai[b][d]=f;
    sai[b][f]=c;
    sai[c][a]=b;
    sai[c][b]=f;
    sai[c][e]=a;
    sai[c][f]=e;
    sai[d][a]=e;
    sai[d][b]=a;
    sai[d][e]=f;
    sai[d][f]=b;
    sai[e][a]=c;
    sai[e][c]=f;
    sai[e][d]=a;
    sai[e][f]=d;
    sai[f][b]=d;
    sai[f][c]=b;
    sai[f][d]=e;
    sai[f][e]=c;
    
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> x >> y;
        cout << sai[x][y] << endl;
    }
    return 0;
}



Measured memory_bytes: 3100
n = int(input())

price_list = list()

max_price = -20000000000
min_val = 2000000000

for i in range(n):
   price_list.append(int(input()))

   if i == 0:
      min_val = price_list[0]
      continue

   min_val = price_list[i-1] if min_val > price_list[i-1] else min_val
   max_price = price_list[i] - min_val if price_list[i] - min_val > max_price else max_price

print(max_price) 


Measured memory_bytes: 13584
import math
import itertools

k = int(input().strip())
gcdsum = 0

for a, b, c in itertools.combinations_with_replacement(range(1, k + 1), 3):
    if a == b and b == c:
        gcdsum += math.gcd(math.gcd(a, b), c) * 1
    elif a != b and b == c:
        gcdsum += math.gcd(math.gcd(a, b), c) * 3
    elif a == b and b != c:
        gcdsum += math.gcd(math.gcd(a, b), c) * 3
    elif a != b and b != c:
        gcdsum += math.gcd(math.gcd(a, b), c) * 6
print(gcdsum)

Measured memory_bytes: 9184
/* ファイル名：ITP1_11_B.c*/
/* 内容：ITP1_11_Aと同じように、サイコロを使ったプログラム。	*/
/* 回転させた後の上面と前面の整数が質問として与えられるので、右側の面の整数を答える	*/


/* include	*/
#include <stdio.h>

/* 外部変数宣言	*/

/* プロトタイプ宣言	*/

/* 関数名:main	*/
/* 処理内容:サイコロの上面と前面を取得し、その時の右側の面の整数を答える	*/
int main( void )
{
	/* 内部変数定義*/
	/* 入力・出力*/
	int dice[6];	/* サイコロの各面の数字				*/
	int q;			/* 質問の数(この数だけ質問が来る)	*/
	int up;			/* サイコロの上面					*/
	int front;		/* サイコロの前面					*/
	
	/* 処理	*/
	int i;			/* ループ用変数	*/
	
	/* サイコロの各面の数字を入力	*/
	for(i = 0; i < 6; i++){
		scanf("%d",&dice[i]);
	}
	
	scanf("%d",&q);	/* 質問の数の入力	*/
	
	/* 質問の数だけ処理を繰り返す	*/
	for(i = 0; i < q; i++){
		scanf("%d %d",&up,&front);	/* サイコロの上面と前面の入力	*/
		
		/* 今のサイコロの上面が、入力された上面と違う場合	*/
		if(dice[0] != up){
			/* 入力された上面が、今のサイコロの前面にある場合	*/
			if(dice[1] == up){
				dice_roll(dice,"N");/* 前にひとつ転がす	*/
			}
			/* 入力された上面が、今のサイコロの右面にある場合	*/
			else if(dice[2] == up){
				dice_roll(dice,"W");/* 左にひとつ転がす	*/
			}
			/* 入力された上面が、今のサイコロの左面にある場合	*/
			else if(dice[3] == up){
				dice_roll(dice,"E");/* 右にひとつ転がす	*/
			}
			/* 入力された上面が、今のサイコロの後面にある場合	*/
			else if(dice[4] == up){
				dice_roll(dice,"S");/* 後ろにひとつ転がす	*/
			}
			/* 入力された上面が、今のサイコロの底面にある場合	*/
			else if(dice[5] == up){
				dice_roll(dice,"NN");/* 前にふたつ転がす	*/
			}
			else{
				/* 処理なし	*/
			}
		}
		/* 今のサイコロの上面が、入力された上面と等しい場合	*/
		else{
			/* 処理なし	*/
		}
		
		/* 今のサイコロの前面が、入力された前面と違う場合	*/
		if(dice[1] != front){
			/* 入力された前面が、今のサイコロの右面にある場合	*/
			if(dice[2] == front){
				dice_roll(dice,"R");/* 右に90度回す	*/
			}
			/* 入力された前面が、今のサイコロの左面にある場合	*/
			else if(dice[3] == front){
				dice_roll(dice,"L");/* 右に90度回す	*/
			}
			/* 入力された前面が、今のサイコロの後面にある場合	*/
			else if(dice[4] == front){
				dice_roll(dice,"RR");/* 右に180度回す	*/
			}
			else{
				/* 処理なし	*/
			}
		}
		/* 今のサイコロの前面が、入力された前面と等しい場合	*/
		else{
			/* 処理なし	*/
		}
		
		/* 出力(サイコロの右側の面)を出力	*/
		printf("%d\n",dice[2]);
	}
	
	return 0;
}

/* 関数名:dice_roll	*/
/* 引数：int *d    サイコロのポインタ	*/
/*		 char *c   命令のポインタ		*/
/* 処理内容:サイコロを転がすシミュレーションを行う	*/
/* 			ITP1_11_Aの処理に、左又は右に90度回す処理も追加	*/
void dice_roll(int *d, char *c){
	/* 内部変数定義	*/
	/* 処理	*/
	int i;			/* ループ用変数			*/
	int x;			/* 入れ替え用変数		*/
	
	/*命令を表す文字列の最後までループ	*/
	for(i = 0; c[i] != '\0'; i++){
		switch(c[i]){
			/* 命令を表す文字が'E'の場合	*/
			case 'E':
				/* 右に1つ転がす	*/
				x = d[0];
				d[0] = d[3];
				d[3] = d[5];
				d[5] = d[2];
				d[2] = x;
				break;
			/* 命令を表す文字が'N'の場合	*/
			case 'N':
				/* 前に1つ転がす	*/
				x = d[0];
				d[0] = d[1];
				d[1] = d[5];
				d[5] = d[4];
				d[4] = x;
				break;
			/* 命令を表す文字が'S'の場合	*/
			case 'S':
				/* 後ろに1つ転がす	*/
				x = d[0];
				d[0] = d[4];
				d[4] = d[5];
				d[5] = d[1];
				d[1] = x;
				break;
			/* 命令を表す文字が'W'の場合	*/
			case 'W':
				/* 左に1つ転がす	*/
				x = d[0];
				d[0] = d[2];
				d[2] = d[5];
				d[5] = d[3];
				d[3] = x;
				break;
			/* 命令を表す文字が'R'の場合	*/
			case 'R':
				/* 右に90度回す	*/
				x = d[1];
				d[1] = d[2];
				d[2] = d[4];
				d[4] = d[3];
				d[3] = x;
				break;
			/* 命令を表す文字が'L'の場合	*/
			case 'L':
				/* 左に90度回す	*/
				x = d[1];
				d[1] = d[3];
				d[3] = d[4];
				d[4] = d[2];
				d[2] = x;
				break;
		}
	}
	
}


Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int a,b,c;
string s;
int main(){
	scanf("%d",&a);
	bool flag = false;
	while(a){
		if(a%10==9)flag=true;
		a/=10;
	}
	if(flag)printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 256
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(){return +cin[cid++];}
function nextstr(){return cin[cid++];}
function nextbig(){return BigInt(cin[cid++]);}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var myOut = main();
if(myOut !== undefined)console.log(String(myOut));

function main(){
  var n = next(), k = next();
  var a = nexts(n);
  var ans = xArray(0,n+1);
  for(var j = 0; j < k; j++){
    for(var i = 0; i < n; i++){
      ans[Math.max(0,i-a[i])]++;
      ans[Math.min(n,a[i]+i+1)]--;
    }
    if(ans[0] === n && ans[n] === -n)return xArray(n,n).join(" ");
    for(var i = 1; i < n; i++){
      ans[i] += ans[i-1];
    }
    a = ans;
    ans = xArray(0,n+1);
  }
  return a.slice(0,n).join(" ");
}

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

typedef long long LL;
const LL INF = 1e18;

int dig( LL x ) {
        int ret = 0;
        while( x ) ret++ , x /= 10;
        return ret;
}
int main( int argc , char const *argv[] ) {
        LL n;
        cin >> n;
        LL mn = INF;
        for( LL i = 1; i*i <= n; i++ ) {
                if( n%i == 0 ) {
                        LL x = i , y = n/i;
                        if( x*y == n ) mn = min( mn , 1LL*max( dig(x),dig(y) ) );
                }
        }
        cout << mn << endl;
        return 0;
}


Measured memory_bytes: 256
/*     ####   ####  #               ####  #        ##   #    # #    # ###### #####
	  #      #    # #              #      #       #  #  ##  ## ##  ## #      #    #
	   ####  #    # #               ####  #      #    # # ## # # ## # #####  #    #
		   # #  # # #                   # #      ###### #    # #    # #      #####
	  #    # #   #  #              #    # #      #    # #    # #    # #      #   #
	   ####   ### # ###### #######  ####  ###### #    # #    # #    # ###### #    #
*/
 
#include<bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<string> VS;
typedef vector<pair<LL, LL> > VP;
 
 
#define For(in) for (LL i = 0; i < (n); i++)
#define FOR(in) for(LL i=1; i <= (n); i++)
#define pb push_back
#define srt(v) sort(v.begin(), v.end())
#define rev(v) reverse(v.begin(), v.end())
#define uniq(v) v.erase(unique(v.begin(), v.end()), v.end());
#define exit(); return 0;
#define no "NO"
#define yes "YES"
#define con continue;
 
 
LL concate(LL a, LL b)
{
	ostringstream os;
	os <<a <<b;
	istringstream is(os.str());
	LL c;
	is>> c;
	return c;
}
 
LL binpow(LL a, LL b, LL c)
{
	a %= c;
	LL res = 1 ;
	while(b > 0){
		if(b & 1)
		res = res * a % c ;
		a = a * a % c ;
		b >>= 1;
		//cout<<res<<endl;
	}
	return res;
}
 
LL check(char vowel)
{
	return vowel=='a' || vowel=='e' || vowel=='i' || vowel=='o' || vowel=='u';
}
LL mod = 1e9+7;
 
 
int main()
{
	//LL q,t;
	//cin>>t;
	//while(t--)
	//{
	    LL a=0,b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,r=0,u=0,w=0,x=0,y=0,z=0;
		LL aa[1000];
		LL flag=0, flag1=0, co=0, co1=0, co2=0, co3=0, x1=0, x2=0, y1=0, y2=0, z1=0, z2=0;
		LL ma=0, mi=100000000;
		LL mid=0, temp=0, stop=0, start=0;
		double pi= 3.141592653589793;
		double d1=0.0, d2, d3, d4;
		VLL v,v1,v2,v3,v4,v5,v6,v7,v8,v9,v10;
		VS vs, vs1, vs2, vs3, vs4;
		VP vp, vp1,vp2;
		char ch, ch1, ch2[1001];
		string str, str1, str2, str3, str4, str5;
		pair<LL, LL> pa;
		list<LL> li, li1;
		map<LL, LL> mp, mp1;
		set<LL> st;
		map<LL ,LL> :: iterator imll;
		VLL :: iterator ivll;
		set<LL> :: iterator isll;
		VP :: iterator ivp;
 

		cin>>a>>b>>c;
		if(a*b<=c)cout<<a*b<<endl;
		else cout<<c<<endl;
		
		
	//}
	exit()
 
 
}


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

int gcd(int a,int b){
  return (b?gcd(b,a%b):a);
}

int main(){
  int n,i;
  cin >> n;
  vector<int> a(n+1,0);
  for(i=0;i<n;++i){
    cin >> a[i];
  }
  int mi=1000000000;
  for(i=0;i<n;++i){
    mi=min(gcd(a[i],a[i+1]),mi);
  }
  cout << mi << endl;
  return 0;
}


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

# 1 "<stdin>"
# 1 "<built-in>"
# 1 "<command-line>"
# 31 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 32 "<command-line>" 2
# 1 "<stdin>"

using namespace std;

# 1 "../IO/io.h" 1
inline int readInt() {
    int v;
    int r = scanf("%d", &v);
    return v;
}

inline long long readLong() {
    long long v;
    int r = scanf("%lld", &v);
    return v;
}

inline vector<int> readVecInt(int n) {
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        a[i] = readInt();
    }
    return a;
}


inline void printLine(int v) {
    printf("%d\n", v);
}

inline void printLine(long long v) {
    printf("%lld\n", v);
}

inline void printLine(const vector<int> &a) {
    for (int v: a) {
        printf("%d ", v);
    }
    printf("\n");
}

inline void printLine(const string &s) {
    printf("%s\n", s.c_str());
}
# 5 "<stdin>" 2

int MX = 2e5 + 9;
vector<int> mem(MX, -1);
int calc(int v) {
    if (v == 0) {
        return 0;
    }
    auto &ans = mem[v];
    if (ans == -1) {
        int mod = __builtin_popcount(v);
        ans = calc(v%mod) + 1;
    }
    return ans;
}

int main() {
    int n;
    string s;
    cin >> n >> s;
    int cnt = 0;
    for (char ch: s) {
        if (ch == '1') {
            cnt++;
        }
    }
    reverse(s.begin(), s.end());
    int cnt0 = cnt-1;
    int cnt1 = cnt+1;
    vector<int> pw0(n, 1), pw1(n, 1);
    for (int i = 1; i < n; i++) {
        pw1[i] = (pw1[i-1]*2)%cnt1;
        if (cnt0 > 0) {
            pw0[i] = (pw0[i-1]*2)%cnt0;
        }
    }
    int c0 = 0;
    int c1 = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == '1') {
            c1 = (c1 + pw1[i]) % cnt1;
            if (cnt0 > 0) {
                c0 = (c0 + pw0[i]) % cnt0;
            }
        }
    }
    for (int i = n-1; i >= 0; i--) {
        int ans = 0;
        if (s[i] == '0') {
            ans = calc((c1 + pw1[i])%cnt1) + 1;
        } else if (cnt0 > 0) {
            ans = calc((c0 - pw0[i] + cnt0) % cnt0) + 1;
        }
        cout << ans << "\n";
    }
}


Measured memory_bytes: 6028
h,w=map(int,input().split())
dx=[1,-1,0,0]
dy=[0,0,1,-1]
s=[]
for i in range(h):
    s.append(list(input()))
for i in range(h):
    for j in range(w):
        if s[i][j]=="#":
            for t in range(4):
                if all(s[i+dy[t]][j+dx[t]]!="#" for t in range(4) if 0<=i+dy[t]<=h-1 and 0<= j+dx[t] <= w-1):
                    print("No")
                    exit(0)
                else:
                    pass
print("Yes")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace  std;
template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}
#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

  
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vii = vector<pii>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define re(n) for (int i = 0; i < n; ++i)
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define eb emplace_back

//OutPut
#define ps(x) cout << x << endl;
#define ps_end(x) {ps(x); return;}


const int md = 1e9 + 7; //998244353 ;
const int dir[4][2] = {{-1,0}, {1, 0}, {0, -1}, {0, 1}};
template<class T> bool ckmin(T& a, const T& b) { 
  return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { 
  return a < b ? a = b, 1 : 0; }
ll pw(auto x, auto y) {  ll s = 1; while(y) { if (y & 1) s = s * x % md; x= 1LL * x * x % md; y /= 2; } return s;}

const int maxn = 1e6 + 10;

ll n, m, nq, nk;
string str;

void task() {
  cin >> n >> nq;
  vector<ll> a(n + 1,0), b(n + 1, 0), p(n + 1, 0), q(n + 1, 0);
  a[n] = b[n] = n - 1;
  //a, p means h
  //b, q means w
  int h = n - 1, w = n - 1;
  re(nq) {
    int x, y;
    cin >> x >> y;
    if (x == 1) {
      q[y] = 1;
      y--;
      if (y < w) {
        a[h] -= w - y;
        w = y;
      }
    }
    if (x == 2) {
      p[y] = 1;
      y--;
      if (y < h) {
        b[w] -= h - y;
        h = y;
      }
    }
    debug(h, w);
    debug(a);
    debug(b);
  }
  ll ans = (n - 2) * (n - 2);
  for (int i = n - 1; i >= 2; i--) {
    a[i] = a[i + 1] + a[i];
    b[i] = b[i + 1] + b[i];
    if (p[i]) ans -= a[i] - 1;
    if (q[i]) ans -= b[i] - 1;
  }
  cout << ans << endl;
  //Read the stuff at the bottom
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout<<fixed<<setprecision(20);
  int T = 1;
  //cin >> T;
  for (int ti = 1; ti <= T; ++ti) {
    task();
  }
  return 0;
}

/* stuff you should look for
  * int overflow, array bounds
  * special cases (n=1?)
  * do smth instead of nothing and stay organized
  * write down
*/


Measured memory_bytes: 9524
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <cctype>
#include <unordered_map>
#include <limits>
#include <numeric>
#include <cmath>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<long, long>;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(int i = 0; i<n; i++)
#define rep_s(i, start, n) for(int i= start;  i<n; i++)
#define rep_down(i, n) for(int i = n-1; i>=0; i--)
#define rep_down_s(i, n, start) for(int i = n-1; i>=start; i--)
#define ALL(a) (a).begin(), (a).end()
#define ALL_str(a) (a).cbegin(), (a).cend()

string alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alphabet_lower  = "abcdefghijklmnopqrstuvwxyz";
string numbers = "0123456789";
/*
for (iterator = hash.begin(); iterator != hash.end(); iterator++)
{
// ここで、要素毎の操作を行います。
std::pair<std::string, CMyClass> element = *iterator;

}
*/
/*
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d){
  depth[v] = d;
  //cout <<"v: " << v << endl;
  for (auto &e: tree[v]){
    //cout << "e.to: " << e.to << endl;
    if (e.to == p) continue;
    dfs(e.to, v, d+e.cost);
  }
}
*/
int keta_sum(int num){
  int dig, sum = 0;
  while(num){
    dig = num % 10;
    sum = sum + dig;
    num = num / 10;
  }
  return sum;
}

ll binary_search(ll left_key, ll border, ll low, ll high) {
     // 配列 a の左端と右端
    ll mid = (low+high)/2;
    while (high > low+1) {
       mid = (low+high)/2;
        if (left_key*mid>border) high = mid;
        else if (left_key*mid<border) low = mid;
        else {
          mid =mid-1;
          break;
        }
    }
    return mid;
}

bool IsPrime(ll a){
  ll b = sqrt(a);
  b++;
  while(b-->=2){
    if (a%b==0) return false;
  }
  return true;
}

ll gcd(ll a, ll b){
  ll tmp;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }

  ll r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(void){
  ll N, M, A, B, C, D, E, F, K,L, W, H, P, Q, R, X, Y;
  ll ans;
  cin >> N;
  ll a[N];
  rep(i, N) cin>> a[i];
  ans = 0;
  ll count = 1;
  rep(i, N){
    if (a[i] == count){
      count++;
      continue;
    }
    ans++;
  }
  if (ans == N) cout << -1 << endl;
  else cout << ans << endl;
}


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

string s,t,b="~";

bool OK(string a,string b){
	for(int i=0;i<a.size();i++){
		if(a[i]=='?') continue;
		if(a[i]!=b[i]) return false;
	}
	return true;
}

int main(){
	cin>>s>>t;
	for(int i=0;i<=(int)s.size()-(int)t.size();i++){
		string now=s.substr(i,t.size());
		if(OK(now,t)){
			string ans=s;
			for(int j=0;j<i;j++) if(ans[j]=='?') ans[j]='a';
			for(int j=i;j<i+t.size();j++) ans[j]=t[j-i];
			for(int j=i+t.size();j<s.size();j++) 
				if(ans[j]=='?') ans[j]='a';
			b=min(b,ans);
		}
	}
	if(b=="~") cout<<"UNRESTORABLE"<<endl;
	else cout<<b<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
#define db double
using namespace std;
 
const int MAXN = 200200;
const int MAXE = 400400;
const int INF = 0x3f3f3f3f;
 
template<typename T> inline void CheckMax(T &A, T B) {
	A < B ? A = B : A;
}
 
template<typename T> inline void CheckMin(T &A, T B) {
	A > B ? A = B : A;
}
 
template <typename T> inline void read(T &x) {
    int c = getchar();
    bool f = false;
    for (x = 0; !isdigit(c); c = getchar()) {
        if (c == '-') {
            f = true;
        }
    }
    for (; isdigit(c); c = getchar()) {
        x = x * 10 + c - '0';
    }
    if (f) {
        x = -x;
    }
}
 
int n;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;
#define X first
#define Y second

int a[MAXN];
 
signed main() {
	read(n);
	for(int i = 1; i <= n; i++) read(a[i]);
	int sum = 0, Max = -1;
	for(int i = 1; i <= n; i++) {
		sum += a[i];
		if(a[i] > Max) Max = a[i];
	}
	sum -= Max / 2;
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 384
/*
    Author: aksayushx
*/

#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define all(a) a.begin(),a.end()
#define mp make_pair
#define mod 1000000007
using namespace std;
typedef long long ll;
typedef long double ld;

bool sortbysec(const pair<ll,ll> &a, const pair<ll,ll> &b) 
{ 
    return (a.second < b.second); 
}
ll power(ll x, ll y)  
{  
    ll res = 1; 
    x = x % mod;
    if (x == 0) return 0;
    while (y > 0)  
    {  
        if (y & 1)  
            res = (res*x)%mod;  
        y = y>>1; 
        x = (x*x)%mod;  
    }  
    return res;  
} 

void aksayushx()
{
    int h,w;
    cin>>h>>w;
    vector<string> grid(h);
    for(int i=0;i<h;i++)
    cin>>grid[i];
    ll dp[h][w];
    dp[0][0]=1;
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            char ch=grid[i][j];
            if(i==0 && j==0)
            continue;
            if(ch=='#')
            {
                dp[i][j]=0;
                continue;
            }
            if(i-1>=0 && j-1>=0)
            {
                dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
            }
            else if(i-1>=0)
            {
                dp[i][j]=dp[i-1][j];
            }
            else if(j-1>=0)
            {
                dp[i][j]=dp[i][j-1];
            }
        }
    }
    cout<<dp[h-1][w-1];
    
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int test=1;
    //cin>>test;
    while(test--)
        aksayushx();
    return 0;
}


Measured memory_bytes: 12408
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder1_A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');

            int H = int.Parse(str[0]);
            int W = int.Parse(str[1]);
            int D = int.Parse(str[2]);

            var X = new int[H * W + 1];
            var Y = new int[H * W + 1];

            for(int i = 0; i < H; i++)
            {
                string[] num = Console.ReadLine().Split(' ');
                for(int k = 0; k < W; k++)
                {
                    int a = int.Parse(num[k]);
                    X[a] = i;
                    Y[a] = k;
                }
            }

            var cost = new int[H * W + 1];

            for(int i = 0; i <= D; i++)
            {
                cost[i] = 0;
            }

            for(int i = D + 1; i <= H * W; i++)
            {
                cost[i] = cost[i - D] + Math.Abs(X[i] - X[i - D]) + Math.Abs(Y[i] - Y[i - D]);
            }
            
            int Q = int.Parse(Console.ReadLine());

            for(int i = 0; i < Q; i++)
            {
                string[] lr = Console.ReadLine().Split(' ');
                int L = int.Parse(lr[0]);
                int R = int.Parse(lr[1]);

                Console.WriteLine(cost[R] - cost[L]);
            }

        }
    }
}

Measured memory_bytes: 17596
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <cstdlib>

using namespace std;

int main(){

	while(1){
		int n=0,l,s;
		int cnt = 0;
		string tmp;

		cin >> tmp;
		n = atoi(tmp.c_str());

		if(n == 0)break;
		if(n % 1111 == 0){
			printf("NA\n");
			continue;
		}

		while(n != 6174){
			sort(tmp.begin(),tmp.end());
			s = atoi(tmp.c_str());

			sort(tmp.begin(),tmp.end(),greater<char>());
			l = atoi(tmp.c_str());
			n = l - s;

			for(int i=0,p=1000;i<4;i++,p/=10){
				tmp[i] = '0' + n/p;
				n %= p;
			}
			n = atoi(tmp.c_str());
			cnt++;
		}
		printf("%d\n", cnt);
	}
	return 0;
}

Measured memory_bytes: 1208
#[allow(dead_code)]
fn is_whitespace(c: &char) -> bool {
    c.is_whitespace()
}

#[allow(dead_code)]
fn is_eol(c: &char) -> bool {
    ['\r', '\n'].contains(c)
}

#[allow(unused_macros)]
macro_rules! input {
    ($var:ident, $($r:tt)*) => {
        input_inner!{$var, $($r)*}
    };

    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        #[allow(unused_mut, unused_variables, bare_trait_objects)]
        let mut next = move |f: &Fn(&char)->bool| -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|f(&c))
                .take_while(|c|!f(&c))
                .collect()
        };
        input_inner!{next, $($r)*};
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; eol ]) => {
        $next(&is_eol).split(' ').map(|x| x.parse::<$t>().unwrap()).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, parser) => {
        $next
    };

    ($next:expr, $t:ty) => {
        $next(&is_whitespace).parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap, HashSet};

#[allow(dead_code)]
struct Edge {
    from: usize,
    to: usize,
}

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;
#[allow(dead_code)]
const M: usize = 1_000_000_007;

fn main() {
    input! {
        n: usize, m: usize,
        h: [usize; n],
        edges: [(usize1, usize1); m]
    }

    let mut graph = vec![vec![]; n];
    for &(f, t) in &edges {
        graph[f].push(t);
        graph[t].push(f);
    }
    let mut s = 0;
    for i in 0..n {
        let mut ok = true;
        for &to in &graph[i] {
            ok &= h[i] > h[to];
        }
        if ok {
            s += 1
        }
    }
    print!("{}", s);
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;
const int N=2e6+2;
int n, k;
int v[N];
int sol;
int ap[N];
int main() {
    cin >> n >> k;
    forn(i, n) {
        cin >> v[i];
        ++ap[v[i]];
    }

    sort(ap + 1, ap + n + 1);
    int distinct = 0;

    for(int i = 1; i <= n; ++i) {
        if(ap[i]>=1) ++distinct;
    }

    for(int i = 1; i <= n; ++i) {
        if(distinct > k) {
            if(ap[i] > 0) {
                sol += ap[i];
                --distinct;
            }
        }
    }
    cout << sol;
}


Measured memory_bytes: 5120
"use strict";
function main(input) {
    const line = input.split("\n");
    let arr = line[0].split(" ");
    const A = parseInt(arr[0]);
    const B = parseInt(arr[1]);
    if ((A + B) % 2 === 0) {
        console.log((A + B) / 2);
    } else {
        console.log("IMPOSSIBLE");
    }
    return;
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 29512
k = input()
win_count = 0
lose_count = 0
for i in range (len(k)):
    if k[i] == "o":
        win_count += 1
    else:
        lose_count += 1
if win_count + (15-len(k))>= 8:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 2940
n = int(input())
k = 2
count = set()
while k * k <= n:
    if n % k == 1:
        count.add(k)
        count.add((n-1)//k)
    elif n % k == 0:
        n_copy = n
        while n_copy % k == 0:
            n_copy //= k
        if n_copy % k == 1:
            count.add(k)
    k += 1
if n > 2:
    count.add(n-1)
count.add(n)
print(len(count))


Measured memory_bytes: 3064
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		if (n == 1) {
			System.out.println("Hello World");
		} else {
			int a = sc.nextInt();
			int b = sc.nextInt();
			System.out.println(a+b);
		}
 	}
}


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

int main(){
  map<char,int> m;
  m['I']=1;
  m['V']=5;
  m['X']=10;
  m['L']=50;
  m['C']=100;
  m['D']=500;
  m['M']=1000;
  m['O']=0;
  string s;
  while(cin>>s){
    int ans=0;
    int n=-1;
    char c='O';
    for(string::iterator it=s.begin();it!=s.end();it++){
      if(*it==c) n++;
      else{
	if(m[c]*5==m[*it]||m[c]*10==m[*it]){
	  ans+=m[*it]-m[c]*n;
	  n=0;
	  c=*it;
	  continue;
	}
	else if(n!=-1) ans+=m[c]*n;
	c=*it;
	n=1;
      }
    }
    ans+=m[c]*n;
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1184