akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define rrep(i,a) for(int i=(int)a-1;i>=0;--i)
#define REP(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RREP(i,a,b) for(int i=(int)a-1;i>=b;--i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n) / gcd(n, m)*abs(m);//gl=xy
}
 
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;
}
 
using namespace std;

void solve(){
  while(1){
    int n,x;
    cin>>n>>x;
    if((n==0)&&(x==0))return;
    int cnt=0;
    rep(i,n){
      REP(j,i+1,n){
        REP(k,j+1,n){
          if(i+j+k+3==x)++cnt;
        }
      }
    }
    cout<<cnt<<"\n";
  }
}

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


Measured memory_bytes: 3164
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {n: usize, a: [usize; n], b: [usize; n], c: [usize; n-1]};
    let a: Vec<usize> = a.iter().map(|x| x - 1).collect();
    let mut sum = 0;
    let mut index = n;

    for &i in a.iter() {
        sum += b[i];
        if i == index + 1 {
            sum += c[index];
        }
        index = i;
    }

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


Measured memory_bytes: 2176
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):#要素xが属するグループの根を返す
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):#要素xが属するグループと要素yが属するグループとを併合する
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):#要素xが属するグループのサイズ（要素数）を返す
        return -self.parents[self.find(x)]

    def same(self, x, y):#要素x, yが同じグループに属するかどうかを返す

        return self.find(x) == self.find(y)

    def members(self, x):#要素xが属するグループに属する要素をリストで返す
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):#すべての根の要素をリストで返す
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):#グループの数を返す
        return len(self.roots())

    def all_group_members(self):#all_group_members O(N)かかるので注意
        return {r: self.members(r) for r in self.roots()}
    
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
 

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

uf=UnionFind(n+1)
ab=[]
cd=[]
for i in range(m):
    ab.append(list(map(int,input().split())))

for i in range(k):
    cd.append(list(map(int,input().split())))



for i in range(m):
   # print("gn")
    a=ab[i][0]
    b=ab[i][1]
    if uf.same(a,b)==False:
        uf.union(a,b)
friend=[]
for i in range(1,n+1):#グループ分けをする（友達でも友達候補でもブロック関係でもカウント
    friend.append(uf.size(i))

block=[1]*n
for i in range(m):#友達のところは友達候補にならない
    a=ab[i][0]-1
    b=ab[i][1]-1
    block[a]+=1
    block[b]+=1
"""
for i in range(n):
    print(block[i],end=" ")
print()
"""
for i in range(k):
    a=cd[i][0]
    b=cd[i][1]
    if uf.same(a,b)==True:#そもそも友達候補関係になってなかったら
        block[a-1]+=1
        block[b-1]+=1

"""
for i in range(n):
    print(friend[i],end=" ")
print()"""
"""
for i in range(n):
    print(block[i],end=" ")
print()
"""
for i in range(n):
    print(friend[i]-block[i],end=" ")
#print()

Measured memory_bytes: 58164
s=input()
t=input()
n=len(s)
nn=len(t)
k=nn-n
ans=0
for i in range(n-nn+1):
    tmp=0
    for j in range(nn):
        if t[j]==s[i+j]:
            tmp+=1
    if tmp>ans:
        ans=tmp
print(nn-ans)

Measured memory_bytes: 9036
import java.util.*;

public class Main {
    public static void main(String[] args)  {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        HashSet<String>hs = new HashSet<String>();
        
        for(int i = 0; i < n; i++){
            String command = sc.next();
            if(command.equals("insert")){
                hs.add(sc.next());
            }else{
                if(hs.contains(sc.next())){
                    System.out.println("yes");
                }else{
                    System.out.println("no");
                }
            }
        }
    }
}


Measured memory_bytes: 260004
W, a, b = map(int, input().split())

apos = [a, a + W]
bpos = [b, b + W]

secis_left = False if bpos[1] > apos[1] else True
if bpos[0] - apos[1] <= 0 and not secis_left:
    print(0)
    exit(0)
elif apos[0] - bpos[1] <= 0 and secis_left:
    print(0)
    exit(0)

dist = [abs(apos[0] - bpos[1]), abs(bpos[0] - apos[1])]

print(min(dist))


Measured memory_bytes: 3064
#include <iostream>
#include <map>
#include <ctime>
#include <vector>
#include <climits>
#include <algorithm>
#include <random>
#include <cstring>
#include <cstdio>
#include <map>
#include <set>
#include <bitset> 
#include <queue>
#define inf 0x3f3f3f3f
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define rep(i, a, n) for(register int i = a; i <= n; ++ i)
#define per(i, a, n) for(register int i = n; i >= a; -- i)
#define ONLINE_JUDGE
using namespace std;
typedef long long ll;
const int mod=1e9+7;
template<typename T>void write(T x)
{
    if(x<0)
    {
        putchar('-');
        x=-x;
    }
    if(x>9)
    {
        write(x/10);
    }
    putchar(x%10+'0');
}
 
template<typename T> void read(T &x)
{
    x = 0;char ch = getchar();ll f = 1;
    while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
    while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;};
ll ksm(ll a,ll n){//看是否要mod 
	ll ans=1;
	while(n){
		if(n&1) ans=((ans%mod)*(a%mod))%mod;
		a=((a%mod)*(a%mod))%mod;
		n>>=1;
	}
	return ans%mod;
}
//==============================================================
#define int ll
const int maxn=2e5+10;
ll a[maxn],n;
map<ll,ll> cnt;

signed main()
{
	#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
	//===========================================================
	read(n);rep(i,1,n) read(a[i]);
    sort(a+1,a+1+n);
    ll ans=0;
    int pos=n-1;
    ans+=a[n];
    rep(i,1,n-1){
        cnt[i]+=2;
    }
    n--;
    n--;
    while(n--){
        cnt[pos]--;
        ans+=a[pos];
        if(cnt[pos]==0){
            pos--;
        }
    }
    write(ans);
	//===========================================================
	return 0;
}

Measured memory_bytes: 17688
import sys

def input():
    return sys.stdin.readline()[:-1]

def main():
    N,M = list(map(int,input().split()))

    e_list = [[] for i in range(N)]

    for i in range(M):
        s,t = list(map(int,input().split()))
        s,t = s-1,t-1
        e_list[s].append(t)

    DP = [0]*N
    dp0_min = 10**27

    for x in range(N-1):
        for i in range(N-1):
            if i==x:
                if len(e_list[N-i-2])==1:
                    DP[N-i-2] = DP[e_list[N-i-2][0]]+1
                else:
                    max_room = -1
                    max_path = 0
                    for j in e_list[N-i-2]:
                        if max_path<DP[j]:
                            max_room = j
                            max_path = DP[j]
                        DP[N-i-2] += DP[j]
                    DP[N-i-2] -= DP[max_room]
                    DP[N-i-2] /= len(e_list[N-i-2])-1
                    DP[N-i-2] += 1
            else:
                for j in e_list[N-i-2]:
                    DP[N-i-2] += DP[j]
                DP[N-i-2] /= len(e_list[N-i-2])
                DP[N-i-2] += 1
        dp0_min = min(dp0_min,DP[0])
        DP = [0]*N
    print(dp0_min)

if __name__ == '__main__':
    main()


Measured memory_bytes: 57820
#!/usr/bin/env python3
n = int(input())
b = [-1 for _ in range(n)]
b[0] = b[n-1] = int(1e6)
c = list(map(int, input().split()))
for i in range(n-1):
    b[i+1] = c[i]

ans = 0 
for i in range(n):
    ans += min([b[i-1], b[i]])
print(ans)

Measured memory_bytes: 3064
def checkpalindrome(s):

    for i in range(len(s)):
        if s[i] != s[len(s) - i - 1]:
            return False

    return True

S =  input()

# print(S[:(len(S)-1)//2 ])
# print(S[(len(S)+ 3)//2 -1 :])
# print(checkpalindrome(S))
# print(checkpalindrome(S[:(len(S)-1)//2]))
# print(checkpalindrome(S[(len(S)+ 3)//2 -1 :]))
if checkpalindrome(S) == True and checkpalindrome(S[:(len(S)-1)//2 ]) == True and checkpalindrome(S[(len(S)+ 3)//2 -1 :]) == True :
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define all(a) a.begin(),a.end()
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*pi*/double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*Fibonacci数列*/ll fib(ll x){ll i,fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
/*桁数*/ll dig(ll n){ll d=0,i=0;while(n/10>0){i++;d++;}return d;}
llfor;ll ans=0;////////////////////////////////////////////////////////////
int main(){
 string s;
 cin>>s;
 ll n=s.length();
 
 rep(i,0,n){
  if(s[i]!=s[n-i-1]){
   pn;return 0;
  }
 }
 rep(i,0,n/2){
  if(s[i]!=s[n/2-i-1]){
   pn;return 0;
  }
 }
 py;
 return 0;}



Measured memory_bytes: 3592
#include <iostream>
#include <utility>
#include <queue>
using namespace std;

typedef pair<int, int> Pair;
const int INF = 100000000;

int H, W;
char N;
const int MAX_H = 1010, MAX_W = 1010;
char plant[MAX_H][MAX_W];
int sx, sy;
int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0};
int d[MAX_H][MAX_W];
int mytime;

void bfs() {
    queue<Pair> que;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            d[i][j] = INF;
        }
    }
    char muscle = '1';
    que.push(Pair(sx,sy));
    d[sx][sy] = 0;
    while (que.size()) {
        Pair p  = que.front(); que.pop();
        if (muscle-1 == N) break;
        for (int i = 0; i < 4; i++) {
            int nx = p.first + dx[i], ny = p.second + dy[i];
            if (0 <= nx && nx < H && 0 <= ny && ny < W && plant[nx][ny] != 'X' && d[nx][ny] == INF) {
                que.push(Pair(nx, ny));
                d[nx][ny] = d[p.first][p.second] + 1;
            }
            if (muscle == plant[nx][ny]) {
                while(que.size()) {que.pop();}
                que.push(Pair(nx, ny));
                muscle = muscle + 1;
                mytime += d[nx][ny];
                for (int i = 0; i < H; i++) {
                    for (int j = 0; j < W; j++) {
                        d[i][j] = INF;
                    }
                }
                d[nx][ny] = 0;
                break;
            }
        }
    }
}

void solve() {
    mytime = 0;
    bfs();
    cout << mytime << endl;
}

int main () {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    // IO
    cin >> H >> W >> N;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> plant[i][j];
            if(plant[i][j] == 'S') {sx = i; sy = j;}
        }
    }
    solve();
}


//错误版本突然又正确了，这是什么情况啊？？？？？？？！！！！！！！！


Measured memory_bytes: 8088
#include<bits/stdc++.h>
using namespace std;
int n, f[100001];

int main(){
    cin >> n;
    vector<int> v;
    v.push_back(0);
    for (int i = 0; i < 7; i++) v.push_back(pow(6,i));
    for (int i = 1; i < 6; i++) v.push_back(pow(9,i));
    sort(v.begin(), v.end());
    f[1] = 1;
    for (int i = 1; i <= n; i++) f[i] = i;
    for (int i = 1; i <= n; i++){
        for (int j = 2; j < v.size(); j++){
            if (v[j] <= i) f[i] = min(f[i], f[i-v[j]] + 1);
        }
    }
    cout << f[n];
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
using namespace std;
using ll = long long;
using lli = long long int;
ll MM = 1000000000;
ll mod = MM + 7;
int main(){
    lli n, k; cin >> n >> k;
    lli h[100010];
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }
    sort(h, h + n);
    ll ans = 1000000000;
    for(int i = 0; i < n-k+1; i++){
        ans = min(ans, h[i+k-1] - h[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
map<int,double> stu;
int num;
double we;
double he;
int main(){
	while(~scanf("%d,%lf,%lf",&num,&we,&he)){
		double bmi = we/(he*he);
		if(bmi>=25){
			cout <<num<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1232
#include <iostream>
using namespace std;
int main(){
	int q,dice[7],x,y,ans[25];
	for(int i=1;i<=6;i++){
		cin>>dice[i];
	}
	cin>>q;
	for(int i=1;i<=q;i++){
		int ans=0;
		cin>>x>>y;
		for(int j=1;j<=6;j++){
			if(x==dice[j])ans=j;
		}
		switch(ans){
			case 1:
				if(y==dice[2]){
					cout<<dice[3]<<endl;
				}else if(y==dice[3]){
					cout<<dice[5]<<endl;
				}else if(y==dice[5]){
					cout<<dice[4]<<endl;
				}else{
					cout<<dice[2]<<endl;
				}
				break;
			case 2:
				if(y==dice[1]){
					cout<<dice[4]<<endl;
				}else if(y==dice[4]){
					cout<<dice[6]<<endl;
				}else if(y==dice[6]){
					cout<<dice[3]<<endl;
				}else{
					cout<<dice[1]<<endl;
				}
				break;
			case 3:
				if(y==dice[1]){
					cout<<dice[2]<<endl;
				}else if(y==dice[2]){
					cout<<dice[6]<<endl;
				}else if(y==dice[6]){
					cout<<dice[5]<<endl;
				}else{
					cout<<dice[1]<<endl;
				}
				break;
			case 4:
				if(y==dice[1]){
					cout<<dice[5]<<endl;
				}else if(y==dice[5]){
					cout<<dice[6]<<endl;
				}else if(y==dice[6]){
					cout<<dice[2]<<endl;
				}else{
					cout<<dice[1]<<endl;
				}
				break;
			case 5:
				if(y==dice[1]){
					cout<<dice[3]<<endl;
				}else if(y==dice[3]){
					cout<<dice[6]<<endl;
				}else if(y==dice[6]){
					cout<<dice[4]<<endl;
				}else{
					cout<<dice[1]<<endl;
				}
				break;
			case 6:
				if(y==dice[2]){
					cout<<dice[4]<<endl;
				}else if(y==dice[4]){
					cout<<dice[5]<<endl;
				}else if(y==dice[5]){
					cout<<dice[3]<<endl;
				}else{
					cout<<dice[2]<<endl;
				}
				break;
		}
	}
	return 0;
}

Measured memory_bytes: 3052
/*-- ILSH  --*/
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back 
#define pop pop_back
#define mp make_pair
#define vii vector < ll >
#define vll vector < ll > 
#define dt cout<<"HERE\n";
#define pii pair < ll , ll >
#define pll pair < ll , ll >
#define vpi vector < pii >
#define vpl vector < pll >
#define fi first
#define se second 
#define sz size 
#define len length 

const ll inf=1e18+1e17;
const ll mod =1e9+7;
using cd= complex < double > ;
//const ll mod = 998244353;
ll modInverse(ll a,ll m){ll m0=m;ll y=0,x=1;if(m == 1)return 0;while(a> 1){ll q=a/m;ll t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=m0;return x;}  
ll powm(ll a,ll b){a=a%mod;ll res=1;while(b){if(b&1)res=(res*a)%mod;a=	(a*a)%mod;b>>=1;}return (res%mod);}
const ll N = 1e6 +5;


void solve(){
	int n,x,t;
	cin>>n>>x>>t;
	cout<<((n/x)+(n%x==0?0:1))*t<<'\n';
}






int main(){
	ios_base::sync_with_stdio(false);
	cin.tie( NULL);
	cout.tie(NULL);
	#ifndef ONLINE_JUDGE
		freopen ("INPUT.txt" , "r" , stdin);
		freopen ("OUTPUT.txt", "w" , stdout);
	#endif
	ll t=1;
	//cin>>t;
	for ( ll i=1;i<=t;i++){

    	solve();
    }
}


Measured memory_bytes: 3632
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define db long double
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define mp make_pair
#define size(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

void dout() { cerr << '\n'; }

template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << " " << H;
    dout(T...);
}

#ifdef LOCAL
    #define dbg(...) cerr << #__VA_ARGS__, dout(__VA_ARGS__)
#else
    #define dbg(...) ;
#endif

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;



int main() {
    ios_base::sync_with_stdio(false), cin.tie(NULL);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif

    int n, k;
    cin >> n >> k;
    int tmp = 1, ans = 0;
    while (true) {
        ans++;
        if ((ll)tmp * k > n) {
            break;
        }
        tmp *= k;
    }
    cout << ans;
}


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

int main() {
   
    int N, M, X;
    cin >> N >> M >> X;
  
    int a[15][15];
  
    for (int i = 0; i < N; ++i){
    
      for(int j=0;j<=M;j++)
      cin >> a[i][j] ;
    }

   
    
  int ans = 100000000;
  int sum[15];
    for (int bit = 0; bit < (1 << N); ++bit) {
        int res = 0;
        
      
      for(int j=1;j<=M;j++){
    sum[j] = 0;
      }
      
        for (int i = 0; i < N; ++i) {
          
            if (bit & (1 << i)) {
              
              for(int j=1;j<=M;j++){
              sum[j] += a[i][j];
              }
              
              res += a[i][0];
            }
        }
bool exist = true;
        for(int j=1;j<=M;j++){
          
        if (sum[j] < X){
          exist = false;
          
       }
          
        }
          
      if(exist){          
      ans = min(ans,res);
      }
      
    }
    
  
  if(ans != 100000000) cout << ans << endl;
  else cout << "-1" << endl;
  
}

Measured memory_bytes: 3620
#include<iostream>
#include<complex>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;
typedef long long int llint;
#define rep(i,n) for(int i=0;i<n;i++)
int main() {
	char s[110];
	cin >> s;
	int tmp = 0;
	rep(i, strlen(s)) {
		if (tmp == 0) {
			if (s[i] == 'C') {
				tmp++;
				continue;
			}
		}
		if (tmp == 1) {
			if (s[i] == 'F') {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

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

        int x = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();

        if(Math.abs(x-a)<Math.abs(x-b)){
            System.out.println("A");
        }
        else{
            System.out.println("B");
        }
    }
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
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; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int l[200010];
int r[200010];

int main(){
    int n, k, c;
    cin >> n >> k >> c;
    string s;
    cin >> s;

    int num = 0;
    int now = 0;
    while(now < n){
        if (s[now] == 'o'){
            l[++num] = now;
            now += c + 1;
        } else{
            now++;
        }
    }

    num = k;
    now = n - 1;
    while(now >= 0){
        if (s[now] == 'o'){
            r[num--] = now;
            if (num <= 0) break;
            now -= c + 1;
        } else{
            now--;
        }
    }

    for (int i = 1; i <= k; ++i) {
        if (l[i] == r[i]){
            cout << l[i] + 1 << endl;
        }
    }
}

Measured memory_bytes: 5260
using System;
using System.Linq;
using System.Collections.Generic;
using System.Collections;
public class Program {
  public static void Main() {
    while (true) {
      int N = cin(), A = cin(), B = cin(), C = cin(), X = cin();
      if (N+A+B+C+X == 0) return;
      int[] Y = ReadIntArray();
      int ans = -1;
      for (int i = 0; i < N; ans++) {
        if (ans > 10000) break;
        if (Y[i] == X) i++;
        X = (A * X + B) % C;
      }
      Console.WriteLine((ans <= 10000) ? ans : -1);
    }
  }

  private static List<int> _var;
  public static int cin() { if (_var == null || _var.Count() == 0) { _var = Console.ReadLine().Split(' ').Select(int.Parse).ToList<int>(); } int ans = _var[0]; _var.RemoveAt(0); return ans; }
  public static void Swap<T>(ref T a, ref T b) {T temp = a;a = b;b = temp;}
  public static string ReadStr() { return Console.ReadLine(); }
  public static int ReadInt() { return int.Parse(Console.ReadLine()); }
  public static double ReadDouble() { return double.Parse(Console.ReadLine()); }
  public static long ReadLong() { return long.Parse(Console.ReadLine()); }
  public static char ReadChar() { return Console.ReadLine()[0]; }
  public static string[] ReadStringArray() { return Console.ReadLine().Split(' '); }
  public static int[] ReadIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
  public static double[] ReadDoubleArray() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
  public static long[] ReadLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
  public static char[] ReadCharArray() { return Console.ReadLine().ToArray(); }
  public static string[] ReadCharStringArray() { return Console.ReadLine().ToCharArray().Select(c => c.ToString()).ToArray(); }
}



Measured memory_bytes: 16412
from collections import deque
N = int(input())
c = deque(list(input()))
cnt = 0
def left(c):
  l = c.popleft()
  return l
def right(c):
  r = c.pop()
  return r
while c:
  l = left(c)
  if l == 'R':
    continue
  else:
    while True:
      if not c:
        break
      r = right(c)
      if r == 'W':
        continue
      else:
        cnt += 1
        break
print(cnt)

Measured memory_bytes: 12372
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;

public class Main {

    private static Scanner sc;

    public static void main(String[] args) {
        Main instance = new Main();
        sc = instance.new Scanner();
        instance.solve();
    }

    private void solve() {
        try {
            int A = sc.nextInt();
            int B = sc.nextInt();
            int C = sc.nextInt();
            int D = sc.nextInt();

            BigInteger abcd[] = new BigInteger[4];
            abcd[0] = BigInteger.valueOf(A).multiply(BigInteger.valueOf(C));
            abcd[1] = BigInteger.valueOf(A).multiply(BigInteger.valueOf(D));
            abcd[2] = BigInteger.valueOf(B).multiply(BigInteger.valueOf(C));
            abcd[3] = BigInteger.valueOf(B).multiply(BigInteger.valueOf(D));

            BigInteger max = abcd[0];

            for(int i = 1; i < abcd.length; i++) {
                if(max.compareTo(abcd[i]) == -1) {
                	max = abcd[i];
                }
            }
        	System.out.println(max);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private class Scanner {
        String[] s;
        int i;
        BufferedReader br;
        String regex = " ";

        public Scanner() {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        @Override
        protected void finalize() throws Throwable {
            try {
                super.finalize();
            } finally {
                destruction();
            }
        }

        private void destruction() throws IOException {
            if (br != null) br.close();
        }

        public String next() throws IOException {
            if (i < s.length) return s[i++];
            String st = br.readLine();
            while (st == "") st = br.readLine();
            s = st.split(regex, 0);
            i = 0;
            return s[i++];
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public Long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }

        public Double nextDouble() throws NumberFormatException, IOException {
            return Double.parseDouble(next());
        }
    }
}

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

//諸機能
#pragma region MACRO 
#define putans(x)  std::cerr << "[ answer ]: " ; cout << (x) << endl
#define dputans(x) std::cerr << "[ answer ]: "; cout << setprecision(27) << (double)(x) << endl
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define RREP(i,a,n) for(int i=(int)(n-1); i>= a; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) begin((a)),end((a))
#define mp make_pair
#define exist(container, n) ((container).find((n)) != (container).end())
#define equals(a,b) (fabs((a)-(b)) < EPS)
#ifdef _DEBUG //ファイルからテストデータを読み込む
std::ifstream ifs("data.txt");
#define put ifs >>
#else //ジャッジシステムでいい感じにやる
#define put cin >>
#endif
#pragma endregion
//デバッグなどの支援
#pragma region CODING_SUPPORT
#ifdef _DEBUG
#define dbg(var0) { std::cerr << ( #var0 ) << "=" << ( var0 ) << endl; }
#define dbg2(var0, var1) { std::cerr << ( #var0 ) << "=" << ( var0 ) << ", "; dbg(var1); }
#define dbg3(var0, var1, var2) { std::cerr << ( #var0 ) << "=" << ( var0 ) << ", "; dbg2(var1, var2); }
#define dbgArray(a,n) {std::cerr << (#a) << "=";  rep(i,n){std::cerr <<(a[i])<<",";} cerr<<endl;} 
#else
#define dbg(var0) {}
#define dbg2(var0, var1) {}
#define dbg3(var0, var1, var2) {}
#define dbgArray(a,n) {}
#endif 
#pragma endregion 
//typedef（書き換える、書き足す可能性ある）
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii; typedef pair<string, string> pss; typedef pair<int, string>pis;
typedef vector<string> vs; typedef vector<int> vi;
#pragma endregion
//諸々の定数(書き換える可能性ある)
#pragma region CONST_VAL
#define PI (2*acos(0.0))
#define EPS (1e-10)
#define MOD (ll)(1e9 + 7)
#define INF (ll)(2*1e9)
#pragma endregion



int main() {
	ll h, w, n; put h >> w >> n;
	vector<pair<ll,ll>> ab; ab.resize(n);
	rep(i, n) {
		put ab[i].first >> ab[i].second;
		ab[i].first--; ab[i].second--;
	}
	vector<ll> k;
		int vx[9] = {-1,0,1,1,1,0,-1,-1,0};
		int vy[9] = {-1,-1,-1,0,1,1,1,0,0};
	rep(i, n) {
		rep(j, 9) {
			if (ab[i].first + vy[j] >= 1 && ab[i].first + vy[j] < h-1)
				if (ab[i].second + vx[j] >= 1 && ab[i].second + vx[j] < w-1) {
					dbg2(ab[i].first + vy[j], ab[i].second + vx[j]);
					k.push_back(w * ( ab[i].first + vy[j] ) + ab[i].second + vx[j]);
				}
		}
	}
	sort(all(k));
	k.push_back(-1);
	int index = 0;
	ll ans[10];
	fill(ans, ans + 10, 0);
	ans[0] = ( h - 2 ) * ( w - 2 );
	ll tmp = k[0];
	REP(i,0, k.size()) {
		if (tmp == k[i]) {
			index++;
		}
		else {
			tmp = k[i];
			ans[index]++;
			index = 1;
			ans[0]--;
		}
	}
	rep(i, 10) {
		putans(ans[i]);
	}
END:
	return 0;
}

	//int n, m; put n >> m;
	//string s1; put s1;
	//string s2; put s2;
	//int l1 = s1.size();
	//int l2 = s2.size();
	//int dp[1001][1001];
	//rep(i, l1+1) {
	//	dp[i][0] = i;
	//}
	//rep(i, l2+1) {
	//	dp[0][i] = i;
	//}
	//rep(i, l1) {
	//	rep(j, l2) {
	//		int cost = (s1[i] == s2[j]) ? 0 : 1;
	//		dp[i + 1][j + 1] = min(dp[i][j+1]+1,min(dp[i+1][j]+1,dp[i][j]+cost));
	//	}
	//}
	//cout << dp[l1][l2] << endl;

Measured memory_bytes: 10092
#include<bits/stdc++.h>
using namespace std;
int f;
char c[100010];
int main(){
	scanf("%s",c);
	for(int i=0;i<strlen(c);i++)
	{
		if(c[i]=='p')
			if(i%2==0) f--;
		if(c[i]=='g')
			if(i%2==1) f++;
	}
	cout<<f;
	return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        int[][] x = new int[N][];
        int[][] y = new int[N][];
        for (int i = 0; i < A.length; i++) {
            A[i] = sc.nextInt();
            if (A[i] == 0) {
                continue;
            }
            x[i] = new int[A[i]];
            y[i] = new int[A[i]];
            for (int j = 0; j < A[i]; j++) {
                x[i][j] = sc.nextInt();
                y[i][j] = sc.nextInt();
            }
        }
        int max = 0;
        int p = (int)Math.pow(2, N);
        for (int i = 0; i < p; i++) {
            boolean ok = true;
            loop: for (int j = 0; j < N; j++) {
                if ((i & (1 << j)) == 0) {
                    continue;
                }
                int human = N - j - 1;
                if (x[human] == null) {
                    continue;
                }
                for (int k = 0; k < x[human].length; k++) {
                    int shift = N - x[human][k];
                    if (y[human][k] == 1) {
                        if ((i & (1 << shift)) == 0) {
                            ok = false;
                            break loop;
                        }
                    } else {
                        if ((i & (1 << shift)) != 0) {
                            ok = false;
                            break loop;
                        }
                    }
                }
            }
            if (ok) {
                max = Math.max(max, Integer.bitCount(i));
            }
        }
        System.out.println(max);
        sc.close();
    }
}

Measured memory_bytes: 22356
# D - Various Sushi

import sys

N, K = map(int, sys.stdin.buffer.readline().split())
td = []
for _ in range(N):
    tmp1, tmp2 = map(int, sys.stdin.buffer.readline().split())
    td.append([tmp1-1, tmp2, -1])

td = sorted(td, key = lambda x: x[1], reverse = True)
t_counter = [0]*N
for idx in range(N):
    t_counter[td[idx][0]] += 1
    td[idx][2] = t_counter[td[idx][0]]

t_set = set([td[idx][0] for idx in range(K)])
ans_list = []
ans = sum([td[idx][1] for idx in range(K)]) + len(t_set)**2
ans_list.append(ans)

a = 0
b = 0
while 1:
    while K - 1 - a >= 0:
        if td[K - 1 - a][2] >= 2:
            ans -= td[K - 1 - a][1]
            a += 1
            break
        a += 1
    if K-1-a < 0:
        break
    while K + b <= N-1:
        if td[K + b][0] not in t_set:
            ans -= len(t_set)**2
            t_set.add(td[K + b][0])
            ans += td[K + b][1] + len(t_set)**2
            b += 1
            break
        b += 1
    ans_list.append(ans)
    if K+b == N:
        break

print(max(ans_list))

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

int descending_compare(const void *a, const void *b){
    if (*(int*)a > *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}

int ascending_compare(const void *a, const void *b){
    if (*(int*)a < *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}


int lower_bound(int *a, int n, int key){
    int left, mid, right;
    left = 0, right = n;
    mid = (left + right)/2;
    while ((left+1 != mid || mid+1 != right) && mid != left){
        if (key > a[mid]){
            left = mid;
        }else{
            right = mid+1;
        }
        mid = (left + right)/2;
    }
    if (a[left] >= key)return left;
    if (a[mid] >= key)return mid;
    if (a[right] >= key)return right;
    return n;
}

unsigned long  gcd(unsigned long x, unsigned long y)
{
        if (y == 0) {
                return x;
        } else {
                return gcd(y, x % y);
        }
}



long long calc(int x){
    long long rtn = 1;
    int i;
    for (i = x; i > 1; i--){
        rtn = (rtn*i);
    }
    return rtn;
}


int main(void){
    int a, b;
    scanf("%d %d", &a, &b);
    if (a+b>9){
        printf("error\n");
    }else{
        printf("%d\n", a+b);
    }







    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int x;
  cin >> x;
  int ans = 1;
  for(int i = 2; i*i<=x; ++i){
    int d = i;
    while(d<=x) d*=i;
    ans = max(ans,d/i);
  }
  cout << ans << endl;
}


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

using namespace std;

template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vector<T>>;
using ll = long long;
using ld = long double;

#define REP(i, s, e) for (ll i = (s); i < (e); ++i)

int main()
{
    int N; cin >> N;
    
    if (N % 2 == 0) cout << 0.5 << endl;
    else cout << setprecision(7) << (ld)(N - N / 2) / N << endl;
    
    return 0;
}

Measured memory_bytes: 256
n, a, b = gets.split.map(&:to_i)

array = (1..n).to_a.map!(&:to_s)
result = []
array.map do |x|
  y = x.chars.map(&:to_i).inject(:+)
  result << x.to_i if (a..b) === y
end
puts result.inject {|sum, n| sum + n }


Measured memory_bytes: 2940
import java.util.*;

public class Main{
  static int[] ans;
  static Map<Integer, Integer> map;
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = Math.max(A,B);
    
    System.out.println(A==B ? C*2 : C+C-1);
  }
}

Measured memory_bytes: 23764
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <math.h>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

/*
// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

// 最小公倍数
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}*/

const int MAX = 100;

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

	int a, b;
	cin >> a >> b;

	// a個の白の連結成分
	// b個の黒の連結成分

	// 長方形(正方形)となる

	// 高さ2、幅1000のフィールドを作る

	vector<vector<char>>field(MAX, vector<char>(MAX,'#'));
	// 上半分を全部白にする
	rep(i, MAX / 2) {
		rep(j,MAX){
			field[i][j] = '.';
		}
	}

	int white = 1;
	int black = 1;

	// 黒を増やす場合　上半分の上から偶数行を一つ置きに黒にする
	// 白を増やす場合 下半分の下から奇数行を一つ置きに白にする

	int bi = 0;
	int bj = 0;
	int wi = MAX - 1;
	int wj = 0;

	while (a != white || b != black) {
		if (a > white) {
			field[wi][wj] = '.';
			wj += 2;
			if (wj >= MAX) {
				wj = 0;
				wi -= 2;
			}
			white++;
		}
		if (b > black) {
			field[bi][bj] = '#';
			bj += 2;
			if (bj >= MAX) {
				bj = 0;
				bi += 2;
			}
			black++;
		}
	}

	cout << MAX <<  " " << MAX << endl;

	rep(i, MAX) {
		rep(j, MAX) {
			cout << field[i][j];
		}
		cout << endl;
	}
	return 0;
}

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

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;

int main(int argc, char const* argv[])
{
  int n;
  cin >> n;
  vector<int> vec;
  for(int i = 0; i < n; i++){
    int a;
    cin >> a;
    vec.pb(a);
  }
  sort(vec.begin(), vec.end());
  int res = 0;
  int i = n - 1;
  while(i >= 0){
    res += vec[i];
    i--;
    if(i < 0)break;
    res -= vec[i];
    i--;
  }
  cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF (1<<30)-1
using ll = long long;
using namespace std;
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; }

int main(){
  int n; cin >> n;
  string s; cin >> s;
  int l = 0, r = 0;
  rep(i,n){
    if(s[i] == '(') r++;
    else{
      if(r) r--;
      else l++;
    }
  }
  rep(i,l) s = "(" + s;
  rep(i,r) s += ")";
  cout << s;
  cout << "\n";
  return 0;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define Rint register int
using namespace std;
typedef long long LL;
const int N = 600003;
int n, q, d[N], tmp[N], tot, ans[N], vvv;
struct Node {
	int s, t, x;
	inline bool operator < (const Node &o) const {return x < o.x;}
} a[N];
int seg[N << 2], tag[N << 2];
inline void build(int x, int L, int R){
	seg[x] = tag[x] = -1;
	if(L == R) return;
	int mid = L + R >> 1;
	build(x << 1, L, mid);
	build(x << 1 | 1, mid + 1, R);
}
inline void pushdown(int x){
	if(tag[x] != -1){
		tag[x << 1] = tag[x << 1 | 1] = seg[x << 1] = seg[x << 1 | 1] = tag[x];
		tag[x] = -1;
	}
}
inline void change(int x, int L, int R, int l, int r, int v){
	if(l <= L && R <= r){
		tag[x] = seg[x] = v;
		return;
	}
	pushdown(x);
	int mid = L + R >> 1;
	if(l <= mid) change(x << 1, L, mid, l, r, v);
	if(mid < r) change(x << 1 | 1, mid + 1, R, l, r, v);
}
inline void dfs(int x, int L, int R){
	if(L == R){
		ans[++ vvv] = seg[x];
		return;
	}
	pushdown(x);
	int mid = L + R >> 1;
	dfs(x << 1, L, mid);
	dfs(x << 1 | 1, mid + 1, R);
}
int main(){
	scanf("%d%d", &n, &q);
	for(Rint i = 1;i <= n;i ++){
		scanf("%d%d%d", &a[i].s, &a[i].t, &a[i].x);
		a[i].s -= a[i].x; if(a[i].s < 0) a[i].s = 0;
		a[i].t -= a[i].x + 1; if(a[i].t < 0) a[i].t = 0;
		tmp[++ tot] = a[i].s; tmp[++ tot] = a[i].t;
	}
	sort(a + 1, a + n + 1);
	for(Rint i = 1;i <= q;i ++) scanf("%d", d + i), tmp[++ tot] = d[i];
	sort(tmp + 1, tmp + tot + 1);
	tot = unique(tmp + 1, tmp + tot + 1) - tmp - 1;
	for(Rint i = 1;i <= n;i ++){
		a[i].s = lower_bound(tmp + 1, tmp + tot + 1, a[i].s) - tmp;
		a[i].t = lower_bound(tmp + 1, tmp + tot + 1, a[i].t) - tmp;
	}
	for(Rint i = 1;i <= q;i ++) d[i] = lower_bound(tmp + 1, tmp + tot + 1, d[i]) - tmp;
	build(1, 1, tot);
	for(Rint i = n;i;i --)
		change(1, 1, tot, a[i].s, a[i].t, a[i].x);
	dfs(1, 1, tot);
	for(Rint i = 1;i <= q;i ++) printf("%d\n", ans[d[i]]);
}

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

int main(){
  int A,B,C;
  cin >> A >> B >> C;
  if(A==B&&B==C){
    cout << "No" << endl;
  }else if(A==B||B==C||C==A){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
typedef long long LL;
 
int num[305][305];
 
 
int main()
{
	int h, w, d, q;
	map < int, pair<int,int> > mp;
	scanf("%d %d %d",&h, &w, &d);
	vector<int> pre(h * w + 5, 0);
	for(int i = 1; i <= h; i++)
	{
		for(int j = 1; j <= w; j++)
		{
			scanf("%d",&num[i][j]);
			mp[num[i][j]] = make_pair(i,j);
		}
	}
	for(int i = 1; i <= d; i++)
	{
		for(int j = 1; i + j * d <= h * w; j++)
		{
			int l = i + (j - 1) * d, r = i + j * d;
			int x = mp[l].first, y = mp[l].second;
			int z = mp[r].first, w = mp[r].second;
			pre[i + j * d] = pre[i + (j - 1) * d] + abs(z - x) + abs(w - y);
		}
	}
	scanf("%d",&q);
	for(int i = 1; i <= q; i++)
	{
		int l, r;
		cin >> l >> r;
		cout << pre[r] - pre[l] << endl;
	}
	return 0;
}

Measured memory_bytes: 7424
a=[]
c=[[False] * 3 for i in range(3)]
for i in range(3):
    a.append(list(map(int,input().split())))
n=int(input())
b=[]
for i in range(n):b.append(int(input()))

for i in b:
    for j in range(3):
        if(i in a[j]):
            t=a[j].index(i)
            c[j][t]=True

ans="No"
for i in range(3):
    if(c[i][0]==True and c[i][1]==True and c[i][2]==True):ans="Yes"
for i in range(3):
    if(c[0][i]==True and c[1][i]==True and c[2][i]==True):ans="Yes"
for i in range(3):
    if(c[i][i]==False):break
else:ans="Yes"

for i in range(3):
    if(c[2-i][i]==False):break
else:ans="Yes"
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define forloop(n) for(int i = 0; i < n; i++)
#define ll long long
 
#define mod 1000000007
long long exp(long long taban, long long us) {
    long long carpan = taban;
    long long temp = us;
    long long res = 1;
    for(int i = 0;;i++){
        if(temp % 2) res = (res*carpan) % mod;
        temp /= 2;
        carpan = (carpan*carpan) % mod;
        if(temp == 0) break;
    }
    return res;
}
ll ebob(ll a, ll b){
	if(!a)return b;
	return ebob(b%a, a);
}
ll ekok(ll a, ll b){
	return (((a*b)%mod)*(exp(ebob(a,b), (ll)mod-2))) % mod;
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	ll h; cin>>h;
	ll carpan = 1;
	ll res = 0;
	while(h > 0){
		h /= 2;
		res += carpan;
		carpan *= 2;
	}
	cout<<res;
	return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n, k := scanInt(), scanInt()
	a := make([]int, n)
	for i := range a {
		a[i] = scanInt()
		a[i]--
	}

	m := map[int]bool{}
	start := -1
	var loop []int
	var cnt int
	for i := 0; ; {
		if m[i] {
			if i == start {
				cnt++
				break
			}
			if start == -1 {
				start = i
			}
			loop = append(loop, a[i])
		}

		m[i] = true
		i = a[i]
		cnt++
		if cnt == k {
			fmt.Println(i + 1)
			return
		}
	}
	fmt.Println(loop[(k-cnt)%len(loop)] + 1)
}


Measured memory_bytes: 13044
n=int(input())
h=list(map(int,input().split()))

p=max(h)
cnt=[]
ct=0


for i in range(p):
    ct=0
    for j in range(len(h)-1):
        if h[j]==p-i:
            if h[j]==h[j+1]:
                h[j]-=1
                if j==len(h)-2:
                    ct+=1
                    h[j+1]-=1
            else:
                ct+=1
                h[j]-=1
        if j==(len(h)-2):
            if h[j]!=p-i and h[j+1]==p-i:
                h[j+1]-=1
                ct+=1
    cnt.append(ct)
    #print(h,ct)


k=sum(cnt)
if len(h)==1:
    print(h[0])
else:
    print(k)



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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;

template<typename T> void ckmin(T& a, const T& b) { a = min(a, b); }
template<typename T> void ckmax(T& a, const T& b) { a = max(a, b); }

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

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

    string str;
    cin >> str;

    bool good = true;
    for (int i = 1; i < sz(str); i++)
        good &= str[i] != str[i-1];

    cout << (good ? "Good" : "Bad") << endl;

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 300;
const int MOD = 1e9 + 7;
int n, m, k;
int dfn[N], low[N], dfsnum;
int sta[N], top, cnt;
int inl[N], lst[N];
vector <int> bi[N], ci[N], V[N];
int pre1[N], pre2[N];
void dfs(int t, int u)
{
    dfn[t] = low[t] = ++ dfsnum;
    for (int i = 0; i < bi[t].size(); ++ i)
        if (bi[t][i] != u)
        if (!dfn[bi[t][i]])
        {
            sta[++ top] = ci[t][i];
            dfs(bi[t][i], t);
            low[t] = min(low[t], low[bi[t][i]]);
            if (low[bi[t][i]] >= dfn[t])
            {
                int p; cnt ++;
                do inl[p = sta[top --]] = cnt;
                while (p != ci[t][i]);
            }
        }
        else
        {
            low[t] = min(low[t], dfn[bi[t][i]]);
            if (dfn[bi[t][i]] < dfn[t]) sta[++ top] = ci[t][i];
        }
}
int val[N], A[N], B[N], C[N][N];
int ans = 1;
int powi(int a, int b) {int c = 1; for (; b; b >>= 1, a = 1ll * a * a % MOD) if (b & 1) c = 1ll * c * a % MOD; return c;}
int main()
{
    cin >> n >> m >> k;
    for (int i = 1; i <= m; ++ i)
    {
        for (int j = 0; j < i; ++ j)
            pre1[i] = (pre1[i] + powi(k, __gcd(j, i))) % MOD;
        pre1[i] = 1ll * pre1[i] * powi(i, MOD - 2) % MOD;
    }
    for (int i = 0; i <= m + k; ++ i)
    {
        C[i][0] = C[i][i] = 1;
        for (int j = 1; j < i; ++ j)
            C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD;
    }
    for (int i = 1; i <= m; ++ i) pre2[i] = C[i + k - 1][i];
    for (int i = 1; i <= m; ++ i)
    {
        int a, b;
        cin >> a >> b;
        bi[a].push_back(b); ci[a].push_back(i);
        bi[b].push_back(a); ci[b].push_back(i);
        A[i] = a; B[i] = b;
    }
    for (int i = 1; i <= n; ++ i)
        if (!dfn[i]) dfs(i, -1);
    for (int i = 1; i <= m; ++ i) V[inl[i]].push_back(i);
    for (int i = 1; i <= cnt; ++ i)
    {
        int c = 0;
        for (int j = 0; j < V[i].size(); ++ j)
        {
            if (val[A[V[i][j]]] != i) val[A[V[i][j]]] = i, c ++;
            if (val[B[V[i][j]]] != i) val[B[V[i][j]]] = i, c ++;
        }
        if (V[i].size() < c) ans = 1ll * ans * k % MOD;
        else if (V[i].size() == c) ans = 1ll * ans * pre1[V[i].size()] % MOD;
        else ans = 1ll * ans * pre2[V[i].size()] % MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    int N;cin>>N;
    cout<<(N+1)/2<<endl;
}


Measured memory_bytes: 256