akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <time.h>
#include <queue>
#include <list>
#include <string.h>
#define sf scanf
#define pf printf
#define lf double
#define ll long long
#define p123 printf("123\n");
#define pn printf("\n");
#define pk printf(" ");
#define p(n) printf("%d",n);
#define pln(n) printf("%d\n",n);
#define s(n) scanf("%d",&n);
#define ss(n) scanf("%s",n);
#define ps(n) printf("%s",n);
#define sld(n) scanf("%lld",&n);
#define pld(n) printf("%lld",n);
#define slf(n) scanf("%lf",&n);
#define plf(n) printf("%lf",n);
#define sc(n) scanf("%c",&n);
#define pc(n) printf("%c",n);
#define gc getchar();
#define re(n,a) memset(n,a,sizeof(n));
#define len(a) strlen(a)
#define LL long long
#define eps 1e-6
using namespace std;
const double pi = 3.1415926535;
/*
https://codeforces.com/contest/1106/problems
https://codeforces.com/contest/1106/submit
*/

int main() {
    int n ;
    s(n)
    if(n < 1200){
        puts("ABC");
        
    }else {
        puts("ARC");
        }
    return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    int n; std::cin >> n;
    std::vector<std::vector<long long>>
        cnt(10, std::vector<long long>(10));
    for (int i = 1; i <= n; i++) {
        int w = i;
        while (w >= 10) w /= 10;
        cnt[w][i%10]++;
    }
    long long ans = 0;
    for (int i = 1; i < 10; i++) {
        for (int j = 1; j < 10; j++) {
            ans += cnt[i][j] * cnt[j][i];
        }
    }
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 3636
a = int(input())
b = int(input())
c = int(input())
x = int(input())

ans = 0
for i in range(0, a+1):
    for j in range(0, b+1):
        for k in range(0, c+1):
            if 500 * i + 100 * j + 50 * k == x:
                ans += 1

print(ans)


Measured memory_bytes: 3064
import string
al = string.ascii_lowercase
N = int(input())

def dfs(s, mx):
    if len(s) == N:
        print(s)
    else:
        for i in range(mx):
            c = al[i]
            if c == al[mx-1]:
                dfs(s+c, mx+1)
            else:
                dfs(s + c, mx)

dfs('', 1)

Measured memory_bytes: 4960
#include <stdio.h>
int main()
{
    int n , i;
    int a[10000];
    long int min = 1000000, max = -1000000, sum = 0;
    
    scanf("%d", &n);
    
    for ( i = 1; i <= n ; i++)
    {
        scanf("%ld",&a[i]);
         
         sum = sum + a[i];
         
         if(max <= a[i]){
             max = a[i];
         }
         if(min >= a[i]){
             min = a[i];
         }
    }
    printf("%ld %ld %ld\n",min , max , sum);
    
    return 0;
}


Measured memory_bytes: 2112
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import itertools
import random
from collections import deque
from decimal import *
import queue

input = sys.stdin.readline

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	A,B,C = inputMap()
	K = inputInt()

	if A < B and B < C:
		print("Yes")
		sys.exit()

	for i in range(K):
		if A >= B:
			B *= 2
			continue

		if B >= C:
			C *= 2
			continue

	if A < B and B < C:
		print("Yes")
	else:
		print("No")

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
if __name__ == "__main__":
	main()


Measured memory_bytes: 76828
N, W = map( int, input().split())
WV = [ list( map( int, input().split())) for _ in range(N)]
dp = [0]*(W+1)
for i in range(N):
    w, v = WV[i]
    for i in range(W,-1,-1):
        if i >= w:
            dp[i] = max( dp[i], dp[i-w]+v)
        else:
            break
print( dp[-1])


Measured memory_bytes: 41580
package main

import (
	"fmt"
)

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func main() {
	var n int
	fmt.Scan(&n)
	lcm := 1
	var a int
	for i := 0; i < n; i++ {
		fmt.Scan(&a)
		lcm = lcm * a / gcd(lcm, a)
	}
	fmt.Println(lcm)
}



Measured memory_bytes: 1144
#include <stdio.h>

int main(void)
{
	int i, s, sum;
	sum = 0;
	for (i = 0; i < 5; i++){
		scanf("%d", &s);
		s = (s < 40) ? 40 : s;
		sum += s;
	}
	printf("%d\n", sum / 5);
	
	return (0);
}

Measured memory_bytes: 600
#!/usr/bin/env pypy3


def gen_cands(a, b, c, x, y):
    for z in range(0, max(2 * x, 2 * y) + 1, 2):
        x0 = max(0, x - z // 2)
        y0 = max(0, y - z // 2)
        money = a * x0 + b * y0 + c * z
        yield money


def solve(a, b, c, x, y):
    return min(gen_cands(a, b, c, x, y))


def main():
    a, b, c, x, y = (int(z) for z in input().split())
    print(solve(a, b, c, x, y))


if __name__ == '__main__':
    main()


Measured memory_bytes: 40428
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c,n) for(int i=c;i<n;i++)

int main(){
  int n,len,ans=0;
  string str,str1,str2;
  cin>>n>>str;
  len=str.size();

  rep(i,0,n){
    int cnt=0;
    str1=str.substr(0,i+1);
    str2=str.substr(i+1,len-(i+1));
    sort(str1.begin(),str1.end());
    rep(j,0,str1.size()){
      if(str1.substr(j,1)==str1.substr(j+1,1)){str1.erase(j+1,1);j--;}
    }
    sort(str2.begin(),str2.end());
    rep(j,0,str1.size()){
      rep(k,0,len-(i+1)){
        if(str1.substr(j,1)==str2.substr(k,1)){cnt++;break;}
      }
    }
    ans=max(ans,cnt);

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


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

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	long long a[n],b[n];
	multiset<pair<long long,int>> memo;
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
	}
	for (int i = 0; i < n; ++i)
	{
		cin>>b[i];
		if (a[i]!=b[i])
		{
			memo.insert(make_pair(b[i],i));
		}
	}
	long long ans=0LL;
	while (memo.size()>0)
	{
		auto i=memo.end();
		--i;
		auto p=*i;
		int l=(p.second-1+n)%n,r=(p.second+1)%n;
		memo.erase(i);
		b[p.second]-=a[p.second];
		if (b[p.second]/(b[l]+b[r])==0)
		{
			cout<<"-1\n";
			return 0;
		}
		ans+=b[p.second]/(b[l]+b[r]);
		b[p.second]%=(b[l]+b[r]);
		b[p.second]+=a[p.second];
		if (a[p.second]!=b[p.second])
		{
			memo.insert(make_pair(b[p.second],p.second));
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define dd(x) cout << #x << " = " << x << ", "
#define de(x) cout << #x << " = " << x << endl
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
int fa[60];
void init(int x){ rep(i,1,x+1) fa[i]=i;}
int Find(int x) { return fa[x] == x ? fa[x] : Find(fa[x]);}
void Union(int x,int y){
    x=Find(x);
    y=Find(y);
    fa[x]=y;
}
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    pii G[60];
    rep(i,0,m){
        int u,v;
        scanf("%d%d",&u,&v);
        G[i]=mp(u,v);
    }
    int ans=0;
    rep(i,0,m){
        init(n);
        rep(j,0,m){
            if(j != i) Union(G[j].fi,G[j].se);
        }
        int t=Find(1);
        rep(j,2,n+1) if(Find(j)!=t){ans++;break;}
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <ostream>
#include <vector>

const double kEpsilon = 1e-10;
inline bool equals(double a, double b)
{
    return fabs(a - b) < kEpsilon;
}

class Point
{
  public:
    double x, y;

    Point() = default;
    Point(double x, double y) : x(x), y(y)
    {
    }

    Point operator+(const Point &p)
    {
        return Point(x + p.x, y + p.y);
    }
    Point operator-(const Point &p)
    {
        return Point(x - p.x, y - p.y);
    }
    Point operator*(const double k)
    {
        return Point(x * k, y * k);
    }

    double SquaredNorm()
    {
        return x * x + y * y;
    }
    double abs()
    {
        return sqrt(this->SquaredNorm());
    }

    bool operator<(const Point &p) const
    {
        return x != p.x ? x < p.x : y < p.y;
    }
    bool operator==(const Point &p) const
    {
        return fabs(x - p.x) < kEpsilon && fabs(y - p.y) < kEpsilon;
    }

    double dot(const Point &p) const
    {
        return x * p.x + y * p.y;
    }
    double cross(const Point &p) const
    {
        return x * p.y - y * p.x;
    }
};

double dot(const Point &p1, const Point &p2)
{
    return p1.x * p2.x + p1.y * p2.y;
}
double cross(const Point &p1, const Point &p2)
{
    return p1.x * p2.y - p1.y * p2.x;
}

using Vector = Point;

struct Segment
{
    Point p1, p2;

    Segment() = default;
    Segment(Point p1, Point p2) : p1(p1), p2(p2)
    {
    }
};

int ccw(Point &p0, Point &p1, Point &p2)
{
    auto a = p1 - p0;
    auto b = p2 - p0;

    auto cross_z = a.cross(b);

    if (cross_z > 0.0)
        return 1;
    else if (cross_z < 0.0)
        return -1;
    else
    {
        auto dot_prod = a.dot(b);
        if (dot_prod < 0.0)
            return 100;
        else if (b.abs() > a.abs())
            return -100;
        else
        {
            return 0;
        }
    }
}

bool intersection(Segment &s1, Segment &s2)
{
    return ccw(s1.p1, s1.p2, s2.p1) * ccw(s1.p1, s1.p2, s2.p2) <= 0.0 &&
           ccw(s2.p1, s2.p2, s1.p1) * ccw(s2.p1, s2.p2, s1.p2) <= 0.0;
}

int main()
{
    Segment s1, s2;
    int q;
    std::cin >> q;

    for (size_t i = 0; i < q; ++i)
    {
        std::cin >> s1.p1.x >> s1.p1.y;
        std::cin >> s1.p2.x >> s1.p2.y;
        std::cin >> s2.p1.x >> s2.p1.y;
        std::cin >> s2.p2.x >> s2.p2.y;

        if(intersection(s1, s2))
          std::cout << 1 << std::endl;
        else {
          std::cout << 0 << std::endl;
            }
        }
}



Measured memory_bytes: 3232
#include<iostream>
using namespace std; // 575

int main() {
	int A, B, C;
	cin >> A >> B >> C;
	cout << B + min(C, A + B + 1);
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

Cに対しB+A-1枚の解毒クッキーがいる
*/

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 解説通りに実装したソースコード
 */
public class Main {

	private static final long MOD = 1_000_000_007L;

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt(), m = scanner.nextInt();
			// 階乗を保存する配列
			long[] factorial = new long[m + 1];
			factorial[0] = 1;
			IntStream.rangeClosed(1, m).forEach(i -> factorial[i] = factorial[i - 1] * i % MOD);
			// 階乗^-1を保存する配列
			long[] revFactorial = new long[m + 1];
			revFactorial[m] = modPow(factorial[m], MOD - 2);
			IntStream.rangeClosed(1, m).map(i -> m - i)
					.forEach(i -> revFactorial[i] = revFactorial[i + 1] * (i + 1) % MOD);
			long answer = 0L;
			for (int i = 0; i <= n; i++) {
				// (−1)^i × n_C_i
				long result = ((0 == (i & 1)) ? 1 : -1) * factorial[n] % MOD * revFactorial[i] % MOD
						* revFactorial[n - i] % MOD;
				result = (result + MOD) % MOD;
				// m_P_i × (m-i_P_n-i)^2
				result = result * factorial[m] % MOD * revFactorial[m - i] % MOD * factorial[m - i] % MOD
						* factorial[m - i] % MOD * revFactorial[m - n] % MOD * revFactorial[m - n] % MOD;
				answer = (answer + result) % MOD;
			}
			System.out.println(answer);
		}
	}

	/**
	 * n^m mod MOD を計算する
	 * 
	 * @param n
	 * @param m
	 * @return n^m mod MOD
	 */
	private static long modPow(long n, long m) {
		long result = 1L;
		while (m > 0) {
			if (1 == (m & 1)) {
				result = result * n % MOD;
			}
			n = n * n % MOD;
			m >>= 1;
		}
		return result;
	}
}


Measured memory_bytes: 45888
#include<bits/stdc++.h>
#define N 300005
using namespace std;
int val[N];
int n,m;
void solve(int l,int r){
	val[1]++;val[r-l+1]--;
	for(int i=1,ne,lastl=1e9;i<=r;i=ne+1){
		if(i<=l) ne=min(l/(l/i),r/(r/i));
		else ne=r;
		if(l/i<lastl){
			if(l/i>=r-l){
				val[l/i+1]++,val[min(lastl,r/i)+1]--;
			}else{
				val[r-l+1]++,val[min(lastl,r/i)+1]--;
				return;
			}
			lastl=l/i;
		}
	}
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1,l,r;i<=n;i++){
		scanf("%d%d",&l,&r);
		solve(l-1,r);
	}
	for(int i=1;i<=m;i++) printf("%d\n",val[i]+=val[i-1]);
	return 0;
}

Measured memory_bytes: 1280
#include<stdio.h>
#include<string.h>
int main(void)
{
	int n,m,d,x[100][100],i,k,v,y,flg;
	char a[101];
	scanf("%d %d %d",&n,&m,&d);
	
	for(i=0;i<n;i++){
		scanf("%s",a);
		for(k=0;k<m;k++){
			x[i][k]=0;
			if(a[k]=='#') x[i][k]=1;
		}
	}
	y=0; 
	for(i=0;i<n;i++){
		for(k=0;k<m-(d-1);k++){
			flg=0;
			for(v=k;v<k+d;v++){
				if(x[i][v]==1){
					flg=1; break;
				}
			}
			if(flg==0) y++; 
		}
	}
	for(k=0;k<m;k++){
		for(i=0;i<n-(d-1);i++){
			flg=0;
			for(v=i;v<i+d;v++){
				if(x[v][k]==1){
					flg=1; break;
				}
			}
			if(flg==0) y++;
		}
	}
	printf("%d\n",y);
	return 0;
}

Measured memory_bytes: 2684
# ABC115a
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

d = int(input())
print('Christmas', end='')
if d < 25:
    print(' Eve', end='')
if d < 24:
    print(' Eve', end='')
if d < 23:
    print(' Eve', end='')


Measured memory_bytes: 2940
#include <iostream>
#include <queue>

using namespace std;
int w ,h ,cheese;
char Map[1010][1010];
int dis[1010][1010];
typedef pair<int,int> p ;
p pos[11];
int sx , sy;
int INF= 1<<30;
int move[4][2] = {1,0,-1,0,0,-1,0,1};
int BFS(int x, int y ,int ax ,int ay)
{
	dis[x][y]= 0;
	if (x==ax && y ==ay) return 0 ;
	queue<p> que;
	que.push(make_pair(x ,y));
	
	while (!que.empty())
	{
		p f = que.front();que.pop();
		int X =f.first;
		int Y =f.second;
		
		for (int dir=0;dir<4;dir++)
		{
			int X1 = X+move[dir][0];
			int Y1 = Y+move[dir][1];
			if (X1 <1 || X1>h || Y1<1 || Y1 >w || Map[X1][Y1]=='X' || dis[X1][Y1]!=INF ) continue;
			if(X1==ax && Y1==ay ) return dis[X][Y]+1;
			dis[X1][Y1]= dis[X][Y]+1;
			que.push(make_pair(X1,Y1));
		}
	}
}

int main ()
{
	cin >> h >>w >>cheese ;
	for (int i=1;i<=h ;i++)
		for (int j=1;j<=w;j++)
		{
			cin >>Map[i][j];
			if (Map[i][j]=='S')
				{
					sx = i ;
					sy = j;
				}
			else if (Map[i][j] >='1' && Map[i][j]<='9')
				{
					pos[Map[i][j]-'0'] = make_pair(i,j);
				}
		}
	int stept= 0 ;
	for (int i=1;i<=cheese ;i++)
		{
			fill (dis[0],dis[0]+1020100,INF);
			stept += BFS(sx ,sy, pos[i].first,pos[i].second);
			sx = pos[i].first;
			sy = pos[i].second;
		}
	cout <<stept<<endl;
	return 0;
}


Measured memory_bytes: 8136
import kotlin.math.*

fun str() = readLine()!!
fun int() = str().toInt()
fun long() = str().toLong()

fun read(d:String = " ") = str().split(d)
fun <T> list(d:String = " ",f:String.()->T) = read(d).map {f(it)}
fun list() = list {toInt()}

fun <T> MutableList<T>.removeLast() = this.removeAt(this.lastIndex)

const val mod = 1000000007L

fun main() {
	abc000X()
}

fun abc000X() {
	val (r,c,k) = list()
	val value = Array(r) {LongArray(c) {0L}}
	for(i in 1..k) {
		val (r,c,v) = list()
		value[r-1][c-1] = v.toLong()
	}

	val dp = Array(r) {Array(c) {LongArray(4) {0L}}}

	for(i in 0 until r) {
		for(j in 0 until c) {
			if(i>0)
				for(k in 0..3)
					dp[i][j][0]=max(dp[i][j][0],dp[i-1][j][k])
			if(j>0)
				for(k in 0..3)
					dp[i][j][k]=max(dp[i][j][k],dp[i][j-1][k])

			for(k in 3 downTo 1)
				dp[i][j][k]=max(dp[i][j][k],dp[i][j][k-1]+value[i][j])
		}
	}
	println(dp[r-1][c-1].max())
}


Measured memory_bytes: 736388
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    ll N,P;
    cin >> N >> P;
    map<ll,ll> mp;
    ll pp = P;
    for(ll i = 2;i * i <= P;i++){
        while(pp % i == 0){
            mp[i]++;
            pp /= i;
            continue;
        }
    }
    mp[pp]++;
    ll ans = 1;
    for(auto p:mp){
        //cout << p.first << " " << p.second << endl;
        rep(i,0,p.second / N){
            ans *= p.first;
        }
    }
    cout << ans << endl;
}

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

A = [[int(i) for i in input().split()] for _ in range(n)]

count = 0
ans = "No"

for i in range(n):
    if A[i][0] == A[i][1] and count == 0:
        count = 1
    elif A[i][0] == A[i][1] and count == 1:
        count = 2
    elif A[i][0] == A[i][1] and count == 2:
        ans = "Yes"
        break
    else:
        count = 0


print(ans)


Measured memory_bytes: 9196
#include<bits/stdc++.h>
using namespace std;
void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
int main(){
  int a, b, c, d;
  rd(a);
  rd(b);
  rd(c);
  rd(d);
  if (a+b > c+d){
    wt_L("Left");
    putchar_unlocked('\n');
  }
  if (a+b < c+d){
    wt_L("Right");
    putchar_unlocked('\n');
  }
  if (a+b == c+d){
    wt_L("Balanced");
    putchar_unlocked('\n');
  }
  return 0;
}
// cLay varsion 20170910-1

// --- original code ---
// {
//   int a, b, c, d;
//   rd(a, b, c, d);
//   if (a+b > c+d) wt("Left");
//   if (a+b < c+d) wt("Right");
//   if (a+b == c+d) wt("Balanced");
// }

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import static java.lang.System.*;

class FastScanner {
  private final InputStream in = System.in;
  private final byte[] buffer = new byte[1024];
  private int ptr = 0;
  private int buflen = 0;
  private boolean hasNextByte() {
      if (ptr < buflen) {
          return true;
      }else{
          ptr = 0;
          try {
              buflen = in.read(buffer);
          } catch (IOException e) {
              e.printStackTrace();
          }
          if (buflen <= 0) {
              return false;
          }
      }
      return true;
  }
  private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
  private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
  public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
  public String next() {
      if (!hasNext()) throw new NoSuchElementException();
      StringBuilder sb = new StringBuilder();
      int b = readByte();
      while(isPrintableChar(b)) {
          sb.appendCodePoint(b);
          b = readByte();
      }
      return sb.toString();
  }
  public long nextLong() {
      if (!hasNext()) throw new NoSuchElementException();
      long n = 0;
      boolean minus = false;
      int b = readByte();
      if (b == '-') {
          minus = true;
          b = readByte();
      }
      if (b < '0' || '9' < b) {
          throw new NumberFormatException();
      }
      while(true){
          if ('0' <= b && b <= '9') {
              n *= 10;
              n += b - '0';
          }else if(b == -1 || !isPrintableChar(b)){
              return minus ? -n : n;
          }else{
              throw new NumberFormatException();
          }
          b = readByte();
      }
  }
  public int nextInt() {
      long nl = nextLong();
      if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
      return (int) nl;
  }
  public double nextDouble() { return Double.parseDouble(next());}
}

class Main {
  public static final int MOD = 1000000007;
  public static final int INF = 1000000000;
  public static void main(String[] args) {
    FastScanner sc = new FastScanner();
    int H = sc.nextInt();
    int W = sc.nextInt();
    int D = sc.nextInt();
    int number[][] = new int[H*W+10][3];
    for(int i=1; i<=H; i++){
      for(int j=1; j<=W; j++){
        int A = sc.nextInt();
        number[A][0] = j;
        number[A][1] = i;
      }
    }
    for(int i=1; i<=D; i++){
      number[i][2] = 0;
      int n = i;
      while(n + D <= H * W){
        number[n+D][2] = number[n][2] + Math.abs(number[n][0]-number[n+D][0]) + Math.abs(number[n][1]-number[n+D][1]);
        n += D;
      }
    }
    int Q = sc.nextInt();
    for(int i=0; i<Q; i++){
      int L = sc.nextInt();
      int R = sc.nextInt();
      out.println(number[R][2] - number[L][2]);
    }
  }

  public static int gcd(int a, int b){
    if(b == 0) return a;
    return gcd(b, a%b);
  }
}

Measured memory_bytes: 58528
//
//  main.cpp
//  leetcode
//
//  Created by caokai on 2016/11/23.
//  Copyright © 2016年 caokai. All rights reserved.
//

#include <cstdlib>
#include <algorithm>
#include <list>
#include <string>
#include <vector>
#include <cstdio>
using namespace std;
struct region {
    region (int w, int h): w(w), h(h), regions(h, vector<int>(w, 0)){}
    int w, h;
    vector<vector<int>> regions;
    void change (int i, int xi, int yi) {
        switch (i) {
                case 1:
                for (auto & ve: regions) for (int j = 0; j < xi; j++) ve[j] = 1;
                break;
            case 2:
                for (auto & ve: regions) for (int j = xi; j < ve.size(); j++) ve[j] = 1;
                break;
                case 3:
                for (int j = 0; j < yi; j++) regions[j] = vector<int>(w, 1);
                break;
                case 4:
                for (int j = yi; j < h; j++) regions[j] = vector<int>(w, 1);
                break;
        }
    }
    int count() {
        int sum = 0;
        for (auto & ve: regions) for (auto in: ve) sum += in;
        return w * h -sum;
    }
};
int main(int argc, const char * argv[]) {
    int w, h, n;
    scanf("%d %d %d", &w, &h, &n);
    region test(w, h);
    while( n--) {
        int x, y, z;
        scanf("%d %d %d", &x, &y, &z);
        test.change(z, x, y);
    }
    printf("%d\n", test.count());
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <bits/stdc++.h> 
  
using namespace std;
  
#define $(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define endl '\n'
#define x first
#define y second    
#define int long long
#define double long double       
#define vec vector            
#define pb push_back
#define pii pair<int, int>
#define pdd pair<double, double> 
#define beg begin
  
#ifdef LOCAL
    #define dbg(x) cerr << #x << " = " << x << endl;
#else 
    #define dbg(x)
#endif 
 
void solve(); signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);                                       
    // freopen("output.txt", "w", stdout);
#endif
    srand(time(0));
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);  
    cout.setf(ios::fixed); cout.precision(9);    
    solve();   
    return 0;
} 

const int MAXN = 2e5 + 10, INF = 1e18;
int t[MAXN * 4];

void upd(int v, int tl, int tr, int l, int r, int add) {
    if (tr < l || tl > r) {
        return;
    }
    if (l <= tl && tr <= r) {
        t[v] -= add;
        return;
    }
    int tm = (tl + tr) / 2;
    upd(v * 2, tl, tm, l, r, add);
    upd(v * 2 + 1, tm + 1, tr, l, r, add);
}

int gt(int v, int tl, int tr, int id) {
    if (tr < id || tl > id) {
        return 0;
    }
    if (tl == tr) {
        return t[v];
    }
    int tm = (tl + tr) / 2;
    int ans1 = gt(v * 2, tl, tm, id);
    int ans2 = gt(v * 2 + 1, tm + 1, tr, id);
    return ans1 + ans2 + t[v];
}

void solve() {
    int n, d, a;
    cin >> n >> d >> a;
    vec<pii> x(n);
    for (int i = 0; i < n; ++i) {
        cin >> x[i].x >> x[i].y;
    }
    sort(all(x));

    // for (int i = 0; i < n; ++i) {
    //     cout << x[i].x << " " << x[i].y << endl;
    // }

    int ans = 0;
    for (int i = 0; i < n; ++i) {
        int cur = gt(1, 0, n - 1, i);
        x[i].y += cur;
        if (x[i].y <= 0) continue;
        pii tmp = {x[i].x + 2 * d, INF};
        int id = upper_bound(all(x), tmp) - x.beg();
        int cnt = (x[i].y + a - 1) / a;
        ans += cnt;
        upd(1, 0, n - 1, i, id - 1, a * cnt);
    }

    cout << ans << endl;
}   

Measured memory_bytes: 9216
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		string[] input = Console.ReadLine().Split(' ');
		string s = input[0];
		string t = input[1];
    input = Console.ReadLine().Split(' ');
    int a = int.Parse(input[0]);
    int b = int.Parse(input[1]);
    string u = Console.ReadLine();

    if(s == u) a--;
    else b--;

		Console.WriteLine(a+" "+b);
	}
}


Measured memory_bytes: 13140
import java.io.*;
import java.math.*;
import java.util.*;
import java.util.regex.*;


public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static long cnt=0;
	public static PrintWriter pw = new PrintWriter(System.out);
	public static void main(String[] args) throws Exception {
//		solveA(args);
//		solveB(args);
		solveC(args);
//		solveD(args);
//		solveE(args);
//		solveF(args);
		if(in!=null){
			in.close();
		}
		pw.flush();
		pw.close();
	}

	public static void solveA(String[] args) throws Exception{
		int L= nextInt();
		int R= nextInt();
		int d= nextInt();
		int ans=0;
		for(;L<=R;L++) {
			if(L%d==0) {
				ans++;
			}
		}
		pw.println(ans);
	}
	public static void solveB(String[] args) throws Exception{
		int N = nextInt();

		int[] a = nextInts();
		int ans = 0;
		for(int i=0;i<N;i++) {
			if(i%2==0&&a[i]%2==1) {
				ans++;
			}
		}

		pw.println(ans);
	}
	public static void solveC(String[] args) throws Exception{
		int N = nextInt();
//		long x=System.currentTimeMillis();
		for(int i=1;i<=N;i++) {
			pw.println(fc(i));
		}
//		pw.println(System.currentTimeMillis()-x);
	}

	public static int fc(int n) {
		int ans = 0;
		int m = (int)Math.sqrt(n);
		for(int x=1;x<=m;x++) {
			for(int y=1;y<=m;y++) {
				for(int z=1;z<=m;z++) {
					long tmp =  x*x+y*y+z*z+x*y+y*z+x*z;
					if(tmp==n) {
						ans++;
					}else if(tmp>n) {
						break;
					}
				}
			}
		}
		return ans;
	}

	public static void solveD(String[] args) throws Exception{

	}


	public static void solveE(String[] args) throws Exception{

	}

	public static void solveF(String[] args) throws Exception{

	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}

}



Measured memory_bytes: 27336
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
const int Inf = 1e9 + 5;

bool isPalindrome(string s) {
    string t = s;
    reverse(t.begin(), t.end());
    return t == s;
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0); 
    double a;
    cin >> a;
    a = a / 3.0;
    a = a * a * a;
    cout << fixed << setprecision(10) << a << endl;
    return 0;
}

Measured memory_bytes: 256
package main

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

////////////////////////////////////////
///        templates                 ///
////////////////////////////////////////

var sc = bufio.NewScanner(os.Stdin)

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

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readBigLine() string {
        buf := make([]byte, 0, 1000000)
        for {
                l, p, e := rdr.ReadLine()
                if e != nil {
                        panic(e)
                }
                buf = append(buf, l...)
                if !p {
                        break
                }
        }
        return string(buf)
}

func strSprit(str string) []string {
        cols := strings.Split(str, " ")
        return cols
}

func parseInt(str string) int {
        n, _ := strconv.Atoi(str)
        return n
}

func intSprit(str string) []int {
        strs := strSprit(str)
        cols := make([]int, len(strs))
        for i, v := range strs {
                cols[i] = parseInt(v)
        }
        return cols
}

////////////////////////////////////////
///        end templates             ///
////////////////////////////////////////
func intAbs(n int) int {

        return int(math.Abs(float64(n)))
}

func main() {
        line := nextLine()

        spl := intSprit(line)

        x0 := spl[0]
        y0 := spl[1]
        x1 := spl[2]
        y1 := spl[3]

        xd := intAbs(x0 - x1)
        yd := intAbs(y0 - y1)

        if x0 > x1 {
                if y0 > y1 {
                        fmt.Println(x1+yd, y1-xd, x0+yd, y0-xd)
                } else {
                        fmt.Println(x1-yd, y1-xd, x0-yd, y0-xd)
                }
        } else {
                if y0 > y1 {
                        fmt.Println(x1+yd, y1+xd, x0+yd, y0+xd)
                } else {
                        fmt.Println(x1-yd, y1+xd, x0-yd, y0+xd)
                }
        }
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int n,m;
vector<int> adj[100005];
bool vis[100005];
void dfs(int s){
    vis[s] = true;
    for(int i=0;i<adj[s].size();++i){
        if(!vis[adj[s][i]]) dfs(adj[s][i]);
    }
}
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n>>m;
    while(m--){
        int u,v;
        cin>>u>>v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    int ans = 0;
    for(int i=1;i<=n;++i) if(!vis[i]) dfs(i),ans++;
    cout<<ans-1;
}


Measured memory_bytes: 9616
N = input()
N = int(N)
w = input()
w = list(w)

al = [chr(i) for i in range(ord('A'), ord('Z')+1)]

newlist = ''

for i in w:
  index = al.index(i)
  new = index + N
  if new > 25:
    new = new - 26
  newlist += al[new]
  

print(newlist)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;

public static class Program
{
    public static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var result = new int[n];
        var vals = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        for (int i = 0; i < n; i++)
            result[vals[i] - 1] = i + 1;
        Console.WriteLine(string.Join(" ", result));
    }
}

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

count = 0

base = 1

# def calculator(hp):
#     if hp == 1:
#         return 1
#     else:
#         return (2 * calculator(hp // 2))
#
#
# print(calculator(N))

while N != 0:
    count += base
    N //= 2
    base *= 2

print(count)



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

int main(){
    ll N;
    ll ans = 0;
    cin >> N;
    vector<ll> sum(N);
    sum[0] = 1;
    for (ll i = 1; i < N; i++) sum[i]= sum[i-1]+i+1;
    for(ll i = 0; i<N; i++){
        ans += (i+1)*sum[(N/(i+1))-1];
    }
    cout << ans << endl;
}


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

// --------------------------------------------------------------------------------
#define FASTIO	ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll long long 
#define mset(arr,val) memset(arr,val,sizeof(arr))
#define frepi(a,b) for(int i=a;i<=b;++i)
#define int long long
// --------------------------------------------------------------------------------

void solve_main()
{
	string s;cin>>s;
	int maxi = -1;
	int temp = 0;
	int n=s.size();
	for(int i=0;i<n;++i){
		maxi = max(temp,maxi);
		if(s[i]=='S'){
			temp=0;
			continue;
		}
		if(s[i]=='R')
			temp++;
		maxi = max(temp,maxi);
	}	
	cout<<maxi;
}

int32_t main()
{
	FASTIO;
	#ifndef ONLINE_JUDGE
		freopen("/home/suryakant/input.txt","r",stdin);
		freopen("/home/suryakant/output.txt","w",stdout);
	#endif
	
    int t=1;
    //cin>>t;
    while(t--)
    {
    	solve_main();
    }    
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define mod 1000000007

const int sz=1e5+5;
ll inf=1e15;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    // cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        cout<<(1-n);
    }

    return 0;
}

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

#define INF 1000010000
#define nl '\n'
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pdd pair<double,double>
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define sz(c) (c).size()
#define rep(i,n) for( int i = 0; i < n; ++i )
#define repi(i,n) for( int i = 1 ; i <= n; ++i )
#define repn(i,n) for( int i = n - 1 ; i >= 0 ; --i )
#define repf(j,i,n) for( int j = i ; j < n ; ++j )
#define die(s) {std::cout << s << nl;}
#define dier(s) {std::cout << s; return 0;}
#define dbg(var) {std::cout << #var << "  = " << var << nl;}
#define vi vector<int>
typedef long long ll;

using namespace std;


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

	int n;
	cin >> n;
	
	vector<pair<pair<string,int>,int>> v(n);
	int id = 1;
	for(auto& el : v) { cin >> el.fi.fi >> el.fi.se; el.fi.se *= -1; el.se = id++;}
	SORT(v);

	for(auto& el : v) cout << el.se << endl;

	return 0;
}

Measured memory_bytes: 256
import math

x, y, angle = 0, 0, 0
while True:
    a, b = map(float, raw_input().split(','))
    if (a, b) == (0, 0):
        break
    x += a * math.sin(angle * (math.pi / 180))
    y += a * math.cos(angle * (math.pi / 180))
    angle += b
print int(x)
print int(y)

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

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

        public void Solve(ConsoleInput cin)
        {
            var ans = "No";

            var n = cin.ReadInt;
            var m = cin.ReadInt;

            if (n <= m)
            {
                ans = "Yes";
            }

            WriteLine(ans.ToString());
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}

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

// a^n mod を計算する
int64_t modpow(int64_t a, int64_t n, int64_t mod) {
    int64_t res = 1;
    while (n > 0) {
        if (n%2 == 1) 
        res = res*a % mod;
        a = a*a % mod;
        n=n/2;
    }
    return res;
}
int main(){
#define rep(i, n) for(int64_t i = 1; i <= (int64_t)(n); i++)
  int64_t N,K;
  long long p;
  int64_t answer=0;
  cin>>N>>K;
  vector<int64_t> r(K+1);
  for(int i=1;i<=K;i++){
    p=K/i;
    r[i]=modpow(p, N, 1000000007 );
  }
  //[K/i]のN乗のリスト
  //i番目にiが乗ってる
  //rep(i,K)
    //cout<<r[i]<<endl;
  for(int i=K;i>=1;i--){
    //if(K>=2){
    for(int j=2;j<=K;j++){
      if(j*i>K)
        break;
      r[i]-=r[j*i];
    }  
  }
  //}
  for(int i=1;i<=K; i++){
    answer+=r[i]*(i)%1000000007;
    answer=answer%1000000007;
  }
  if(answer<0)
    cout<<answer+1000000007;
  else
    cout<<answer;
}

Measured memory_bytes: 3988
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <cmath>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define MA(i,j) make_pair(i,j)
#define PA pair<int,int>
#define PB push_back
#define PQ priority_queue<int>
#define PGQ priority_queue<int,vector<int>,greater<int> >
#define VE vector<int>
#define VP vector<PA>
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define MOD 1000000007
#define INF 1000000007
using namespace std;
//
int main(){
  int N,M;
  cin>>N>>M;
  if(N==M){
    long long cnt=1;
    FOR(i,0,2){
      FOR(j,1,N+1){
        (cnt*=j)%=INF;
      }
    }
    cout<<(cnt*2)%INF<<endl;
  }else{
    if(min(N,M)+1<max(N,M)){
      cout<<"0"<<endl;
    }else{
      long long cnt=1;
      FOR(i,1,N+1){
        (cnt*=i)%=INF;
      }
      FOR(i,1,M+1){
        (cnt*=i)%=INF;
      }
      cout<<cnt%INF<<endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define long long ll
int main()
{ 
  int n,i,j,k,count=0;
  cin>>n;
  int arr[n];
  for(i=0; i<n; i++)
  cin>>arr[i];
  sort(arr, arr+n);
  
  for ( i = 0; i < n - 2; ++i)  
    {  k = i + 2;  
      for (j = i + 1; j < n; ++j)  
        {  
            while (k < n && arr[i] + arr[j] > arr[k])  
            ++k;  
            if(k > j)  
            count += k - j - 1;  
        }  
    }  
  
cout<<count;
  

}

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

int n, m, q;
vector<vi> ip;
deque<int> v;
int ans;

void dfs(int cnt, int last)
{
    if (cnt == n)
    {
        int curr = 0;
        for (auto a : ip)
        {
            if (v[a[1]] - v[a[0]] == a[2])
                curr += a[3];
        }
        ans = max(ans, curr);
        return;
    }
    for (int i = last; i <= m; i++)
    {
        v.push_back(i);
        dfs(cnt + 1, i);
        v.pop_back();
    }
}

signed main()
{
    cin >> n >> m >> q;
    for (int i = 0; i < q; i++)
    {
        vi x(4);
        for (int i = 0; i < 4; i++)
            cin >> x[i];
        x[0]--;
        x[1]--;
        ip.push_back(x);
    }
    dfs(0, 1);
    cout << ans;
}

Measured memory_bytes: 3604
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = input()
s1 = []
s2 = [0]

for n in S:
	if n == "A" or n == "C" or n == "G" or n == "T":
		s1.append(1)
	else:
		s1.append(0)

for i in range(len(S)):
	if s1[i] == 0:
		s2.append(0)
	else:
		s2.append(s2[i] + s1[i])

print(max(s2))

Measured memory_bytes: 5196
#include<iostream>
#include<vector>
#include<cstdio>
#include<cstring>
using namespace std;

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

int dfs(int p, int a[7][7], int *visited) {
  if (visited[p]) return 0;
  visited[p] = 1;
  int ret = 1;
  REP(i, 7) if (a[p][i] > 0) ret += dfs(i, a, visited);
  return ret;
}

int main() {
  for (int N; cin >> N; ) {
      int a[7][7] = {};
      int x;
      REP(i, N) {
          cin >> x;
          ++a[x / 10][x % 10];
          ++a[x % 10][x / 10];
      }

      int all = 0;
      int odd = 0;
      REP(i, 7) {
          int sum = 0;
          REP(j, 7) sum += a[i][j];
          if (sum & 1) odd++;
          if (sum) all++;
      }
      bool euler = odd <= 2;
      int visited[7] = {0};
      bool connect = all == dfs(x / 10, a, visited);

      if (euler && connect)
          cout << "Yes" << endl;
      else
          cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
using namespace std;
int	flg[1000001],gen[1000001];
int main(void)
{
	int n,x,j,i,kazu[30],ff;
	
	for(i=2;i<=1000000;i++) flg[i]=1;
	for(i=2;i*i<=1000000;i++){
		if(flg[i]==1){
			for(j=2;j*i<1000000;j++) flg[i*j]=0;
		}
	}
	while(1){
		scanf("%d %d",&n,&x);
		if(n==0 && x==0) break;
		for(i=0;i<n;i++) scanf("%d",&kazu[i]);
		for(i=0;i<=x;i++) gen[i]=0;
		gen[0]=1;
		for(i=0;i<n;i++){
			for(j=0;j<x;j++){
				if(gen[j]==1){
					if(j+kazu[i]<=x) gen[j+kazu[i]]=1;
				}
			}
		}
		ff=0;
		for(i=x;i>=2;i--){
			if(gen[i]==1 && flg[i]==1){
				ff=1;
				break;
			}
		}
		if(ff==0) printf("NA\n");
		else printf("%d\n",i);
	}
	return 0;
}
	

Measured memory_bytes: 8852
from scipy.sparse.csgraph import floyd_warshall

N, M, L = map(int, input().split())
E = [[0] * N for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    E[a - 1][b - 1] = E[b - 1][a - 1] = c

E = floyd_warshall(E)

for i in range(N):
    for j in range(N):
        E[i][j] = (E[i][j] <= L)

E = floyd_warshall(E)

INF = float("inf")

Q = int(input())
for _ in range(Q):
    s, t = map(int, input().split())
    a = E[s - 1][t - 1] - 1
    print(-1 if a == INF else int(a))


Measured memory_bytes: 17500
def main():
    import sys
    from collections import defaultdict
    N,x,y=list(map(int,sys.stdin.readline().split()))
    
    x-=1
    y-=1

    dists=defaultdict(int)
    for i in range(N):
        for j in range(N):#iからまでの経路
            if i>=j:
                continue

            a=j-i
            b=abs(i-x)+abs(j-y)+1

            dists[min(a,b)]+=1

    for k in range(1,N):
        print(dists[k])

main()

Measured memory_bytes: 3956
n = int(input())
a = map(int, input().split())

babies = [(a, i) for i, a in enumerate(a)]

babies.sort(reverse=True)

dp = [[0] * (n+1) for i in range(n+1)]

ans = 0

for l in range(n):
    for r in range(n):
        if l + r == n:
            ans = max(ans, dp[l][r])
            break
        activeness, ind = babies[l+r]
        dp[l+1][r] = max(dp[l+1][r], dp[l][r] + abs(ind - l) * activeness)
        dp[l][r+1] = max(dp[l][r+1], dp[l][r] + abs(ind - (n-1-r)) * activeness)

print(ans)

Measured memory_bytes: 100560
#include <iostream>
#include <string>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <iomanip>
#include <vector>
#include <functional>
#include <algorithm>
#include <cstdio>
#include <random>
#include <ctime>
#include <cstdlib>
#include <unordered_map>
#include <string.h>
#include <iostream>

using namespace std;
typedef long long ll;
typedef pair<int, int> Pint;
typedef pair<ll, ll> Pll;
#define rep(begin, i, end) for (ll i = begin; i < (ll)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    ll N, d;
    cin >> N;
    map<ll, ll> D, T;
    rep(0, i, N)
    {
        cin >> d;
        D[d]++;
    }

    ll M, t;
    cin >> M;
    rep(0, j, M)
    {
        cin >> t;
        T[t]++;
    }
    for (auto m : T)
    {
        if (D[m.first] < m.second)
        {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 25216
#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#include <cmath>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef long double ld;


int main() {
	ll N;
	cin >> N;
	vector<ll>R(N);
	rep(i,N) {
		cin >> R[i];
	}
	ll ans = -1000000001;
	ll minI = R[0];
	for (int j = 1; j < N; ++j){
		ans = max(ans, R[j] - minI);
		minI = min(minI, R[j]);
	}
	
	cout << ans << endl;
	return 0;
}





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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  ll n, h, w; cin >> n >> h >> w;
  int ans = 0;
  for(int i=0;i<n;++i) {
    int a, b; cin >> a >> b;
    ans += a >= h && b >= w;
  }
  cout << ans << endl;

}


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



int main()
{
    string s;
    cin>>s;
    ll x=s.size();
    if(x&1)s.erase(x-1,1),x-=1;
    else s.erase(x-2,2),x-=2;
    if(s.substr(0,(x/2))==s.substr(x/2,x/2)){cout<<x<<endl;return 0;}
    while(1){
        s.erase(x-2,2),x-=2;
        if(s.substr(0,(x/2))==s.substr(x/2,x/2)){cout<<x<<endl;return 0;}
    }

    return 0;
}


Measured memory_bytes: 256
//BISMILLAH
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lli long long int
#define ve vector<int>
#define FOR(n)          for(int i=0; i<(int)(n); ++i)
#define TEST_CASE(t)    for(int z=1;z<=t;z++)
#define PRINT_CASE      printf("Case %d: ",z)
#define pb push_back
#define maxx 100
#define mod 1000000007

int main()
{
    ll a,b,c,d,amix,bmix,cmix,dmix,positivemix,negtivemix;

    cin>>a>>b>>c>>d;

    amix = max(a*c,a*d);
    bmix = max(b*c,b*d);
    cmix  = max(a*c,b*c);
    dmix = max(d*a,d*b);

    positivemix= b*d; //sob value postive hole
    negtivemix = a*c; // sob value neg hole

    ll res1,res2,res3,res4,finalres;

    res1 = max(amix,bmix);
    res2 = max(cmix,dmix);
    res3 = max(res1,res2); //final

    res4= max(positivemix,negtivemix);

    finalres = max(res3,res4);

    cout<< finalres<<endl;






    return 0;
}


Measured memory_bytes: 3624