akhauriyash/Code-Regression huggingface dataset:
import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def main():
    X = int(input())
    print("Yes" if X >= 30 else "No")


if __name__ == "__main__":
    main()


Measured memory_bytes: 67900
n,m = map(int,input().split())

a = [0 for i in range(m)]
b = [0 for i in range(m)]


for i in range(m):
    a[i],b[i] = map(int,input().split())

a.sort()
c = 0

for i in range(m-1):
    if n <= a[i+1]:
        break
    else:
        c += n-a[i+1]

print(c)



Measured memory_bytes: 5628
a,b = map(int, input().split())
if b>0:
	p = list(map(int, input().split()))
else:
	print(a)
	exit()

n = a
m = a

for i in range(b+1):
	"""
	print(n)
	print(m)
	print("")
	"""
	if n in p:	
		n = n-1			
	else:

		print(n)
		exit()

	if m in p:		
		m = m+1
	else:
		print(m)
		exit()

Measured memory_bytes: 9116
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
    int n;
    ll ans=0;
    cin >> n;
    vector<ll> L(n);
    for(int i=0;i<n;i++){
      cin >> L[i];
    }
    
    for(int i=0; i<n; i++){
        for(int j=i; j<n; j++){
            for(int k=j; k<n; k++){
                if(L[i]==L[j] || L[j]==L[k]||L[k]==L[i])continue;
                else if(abs(L[i]-L[j])<L[k] && L[k]<L[i]+L[j]){
                    ans++;
                }
            }
        }
    }
  
  
  cout << ans << endl; 
  return 0;
}

Measured memory_bytes: 3624
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

N,M,P = inpl()
lines = defaultdict(set)

for _ in range(M):
    a,b,c = inpl()
    a,b = a-1,b-1
    lines[a].add((b,-c+P))

#ベルマンフォード(始点と終点が決まってる時)
def BellmanFord(Start,Goal):
    Costs=[INF]*N
    Costs[Start] = 0
    upd8s = [True]*N
    for i in range(2*N): #2N回ループ(負閉路の検出までみる)
        will_upd8s = [False]*N
        for s in range(N):
            if not upd8s[s]: continue    #前回更新してないので見ない
            for t,c in lines[s]:
                if c + Costs[s] < Costs[t]:
                    Costs[t] = Costs[s]+c
                    will_upd8s[t] = True #更新した点だけ次に見る
                    if i >= N:
                        Costs[t] = -INF

        if i == N-1: #Nループ目のGoalのCostを記録
            tmp = Costs[Goal]

        upd8s = will_upd8s[:]

    if tmp != Costs[Goal]:
        return -INF
    else:
        return Costs[Goal]

ans = -BellmanFord(0,N-1)
if ans == INF:
    print(-1)
else:
    print(max(0,ans))


Measured memory_bytes: 56024
#include<stdio.h>
int main(void){
  int a[10000], b[500], count=0;
  int i, j, n, q;
  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d",&a[i]);

  }
  scanf("%d", &q);
  for(i=0; i<q; i++){
    scanf("%d",& b[i]);

  }
  for(j=0; j<q; j++){
    for(i=0; i<n; i++){
      if(a[i] == b[j]){
	count++;
	break;
      }
    }
  }
  printf("%d\n", count);
  return 0;
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;
using ll = long long;

int main(int argc, const char *argv[])
{
    ll k, x;
    cin >> k >> x;

    if (k * 500 >= x)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
GI = lambda: int(input()); GIS = lambda: map(int, input().split()); LGIS = lambda: list(GIS())

def count_unique_pairs(n):
    return n * (n - 1) // 2

def main():
    GI()
    arr = LGIS()

    d = {}
    for x in arr:
        d[x] = d.get(x, 0) + 1

    tot = sum(count_unique_pairs(v) for v in d.values())
    
    for x in arr:
        print(tot - count_unique_pairs(d[x]) + count_unique_pairs(d[x]-1))

main()


Measured memory_bytes: 88140
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args)throws Exception {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer tokenizer = new StringTokenizer(input.readLine());
        int a = Integer.parseInt(tokenizer.nextToken());
        int b = Integer.parseInt(tokenizer.nextToken());
        int c = Integer.parseInt(tokenizer.nextToken());

        Set<Integer> hashSet = new HashSet<>();
        StringBuilder out = new StringBuilder();
        for (int i = a; i < a+c && i <= b; i++) {
            if (!hashSet.contains(i)){
                out.append(i).append("\n");
                hashSet.add(i);
            }
        }

        for (int i = b - c + 1; i <=b && i > a ; i++) {
            if (!hashSet.contains(i)){
                out.append(i).append("\n");
                hashSet.add(i);
            }
        }

//        System.out.println(hashSet.size());
        System.out.print(out);
    }
}


Measured memory_bytes: 21076
# include<stdio.h>

# include<malloc.h>

void sort(int *, int len);

int main(void)
{
	int len;
	int * pArr;
	int i, j = 0;
	//int a[100000] = {0};
	int sum1 = 0;
	int sum2 = 0;
	//int *p = (int *)malloc(int len)
		//malloc() the return is"void *"也叫干地址
	scanf("%d", &len);
	pArr = (int *)malloc(sizeof(int)*len);;
	for(i=0; i<len; ++i)
	{
		scanf("%d", &pArr[i]);
	}
	
	for(i=0; i<len-1; ++i)
	{
		if(pArr[i]>=pArr[i+1])
		{
			sum1 += 1;
			//a[j] += 1;
		}
		if(pArr[i]<pArr[i+1])
		{
			if(sum1>sum2)
			{
				sum2 = sum1;
			}
			
			sum1 = 0;
			
				//j++;
		}
	}

	if(sum1>sum2)
			{
				sum2 = sum1;
			}

	printf("%d", sum2);
	//sort(a, j+1);

	return 0;
}


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

#define name ""
#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)
#define long long long 
#define db double
#define pii pair <int, int> 
#define pll pair <long, long>
#define all(c) c.begin(), c.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
template <class T> inline void chmin(T& a, const T& val) { if (a > val) a = val; }
template <class T> inline void chmax(T& a, const T& val) { if (a < val) a = val; }
template <class T> long sqr(T& a) { return 1ll * a * a; }
template <class T> void compress(vector <T> &a){
  sort(all(a));
  a.resize(unique(all(a)) - a.begin());
}

const db pi = acos(-1.00);
const db eps = 1e-6;
const int INF = 1e9;
const int MOD = 998244353;
const int dx[4] = {0, 0, -1, 1};
const int dy[4] = {-1, 1, 0, 0};

const int N = 4e5+1;
int n, m, k;
long fact[N], ifact[N];

long POW(long x, long n){
  if (n == 0) return 1;
  long y = POW(x, n / 2);
  y = y * y % MOD;
  if (n % 2) return x * y % MOD;
  else return y;
}

int main()
{
  fastio;
  cin >> n >> m >> k;
  fact[0] = 1;
  for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * i % MOD;
  ifact[n] = POW(fact[n], MOD - 2); ifact[0] = 1;
  for (int i = n - 1; i > 0; i--) ifact[i] = ifact[i + 1] * (i + 1) % MOD;
  auto C = [&](int k, int n){
    return (fact[n] * ifact[k] % MOD) * ifact[n - k] % MOD;
  };
  long res = 0;
  for (int i = 0; i <= k; i++){
    long memo = m * POW(m - 1, n - i - 1) % MOD;
    res += memo * C(n - i - 1, n - 1) % MOD;
    res %= MOD;
  }
  cout << res;
  return 0;
}


Measured memory_bytes: 6712
#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;
typedef pair<int,int> P;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
vector<P> graph[100010];
vector<ll> dist;
int Q,K;
void dfs(int now, ll d){
    if(dist[now])return;
    dist[now] = d;
    for(auto p:graph[now]){
        dfs(p.first, d + p.second);
    }
}
main(){
    int N;
    cin >> N;
    rep(i,0,N-1){
        int a,b,c;
        cin >> a >> b >> c;
        a--;b--;
        graph[a].push_back(P(b,c));
        graph[b].push_back(P(a,c));
    }
    cin >> Q >> K;
    K--;
    dist = vector<ll>(N);
    dfs(K, 1);
    //rep(i,0,N)cout << dist[i] << " \n"[i==N-1];
    rep(i,0,Q){
        int a,b;
        cin >> a >> b;
        cout << dist[a-1] + dist[b-1] - 2 << endl;
    }
}

Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std;
const long long maxn=2e6+10;
const long long inf=0x3f3f3f3f;
const long long mod=1e9+7;
int n,k;
char c[maxn];
long long quick_pow(long long a,long long b)
{
	long long res=1;
	while(b)
	{
		if(b&1)
			res=res*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return res;
}
long long fac[maxn],inv[maxn];
long long C(int n,int m)
{
	return fac[n]*inv[m]%mod*inv[n-m]%mod;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    cin>>k>>c;
    long long n=strlen(c);
    fac[0]=1;
    for(int i=1;i<maxn;i++)
    	fac[i]=(fac[i-1]*i)%mod;
    inv[maxn-1]=quick_pow(fac[maxn-1],mod-2);
    for(int i=maxn-2;i>=0;i--)
    	inv[i]=(inv[i+1]*(i+1))%mod;
    long long res=0;
    for(long long i=0;i<=k;i++)
    	res=(res+quick_pow(26,i)*C(n-1+k-i,n-1)%mod*quick_pow(25,k-i)%mod)%mod;
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 35868
//
// Created by Nihith on 22-02-2020.
//
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n,mean=0;
    ll max_stamina=(1e18);
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++){
        cin>>arr[i];
        mean+=arr[i];
    }
    mean/=n;
    //cout<<max_stamina<<endl;
    for(int k:{0,1}){
        ll cur_stamina=0LL;
        for(int i=0;i<n;i++){
            cur_stamina+=(mean+k-arr[i])*(mean+k-arr[i]);
        }
        max_stamina=min(max_stamina,cur_stamina);
    }
    cout<<max_stamina<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>  // abs() for integer
 
int main()
{
    long A, V, B, W, T, a_position, b_position;
    std::cin >> A >> V;
    std::cin >> B >> W;
    std::cin >> T;
 
    if (A < B) {
        a_position = A + V * T;
        b_position = B + W * T;
    } else {
        a_position = A - V * T;
        b_position = B - W * T;
    }
    
    if ((A > B && a_position <= b_position) || (A < B && a_position >= b_position)) {
        std::cout << "YES";
    } else {
        std::cout << "NO";
    }
}

Measured memory_bytes: 3128
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

ll l, r, cnt1;
ll cnt2;
ll tmp = 2018;
bool judge;

int main() {

	cin >> l >> r;
	REP(i, l, r + 1) {
		REP(j, i + 1, r + 1) {

			if (tmp > (ll)(i)* (ll)(j) % 2019) {
				tmp = (ll)(i)* (ll)(j) % 2019;
			}
			if (tmp == 0)break;
		}
		if (tmp == 0)break;
	}


	cout << tmp << endl;

	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	int a,b,i;
	scanf("%d%d",&a,&b);
	char s[10];
	if(a<b) for(i=0;i<b;i++) s[i]='0'+a;
	else for(i=0;i<a;i++) s[i]='0'+b;
	s[i]='\0';
	printf("%s",s);
	return 0;
}

Measured memory_bytes: 128
import sys

if sys.platform =='ios':
	sys.stdin=open('input_file.txt')
	
#+++++
import fractions
#a,b = map(int, input().split())
n = int(input().strip())
aa=list(map(int,input().split()))
i = 1
count = 0
for a in aa:
	if a != i:
		count += 1
	else:
		i += 1
		
if count == n:
	print('-1')
else:
	print(count)


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

using namespace std;

int main(){

  char data[15][15];
  int n;

  cin >> n;

  for(int i = 0; i < 15; i++){
    for(int j = 0; j < 15; j++){
      data[i][j] = '0';
    }
  }
  for(int i = 0; i < n; i++){

    for(int j = 4; j <= 11; j++){
      for(int k = 4; k <= 11; k++){
	cin >> data[k][j];
      }
    }

    int x, y;
    cin >> x >> y;
    //cout << x <<' ' << y << endl;
    queue<int> X;
    queue<int> Y;
    X.push(x+3);
    Y.push(y+3);

    while(!X.empty()){
      x = X.front();
      y = Y.front();
      X.pop();
      Y.pop();
      //cout << x <<' ' << y << "data = " << data[x+3][y+3] << endl;
      data[x][y] = '0';
      for(int j = x+1; j < x+4; j++){
	if(data[j][y] == '1'){
	  X.push(j);
	  Y.push(y);
	}
	data[j][y] = '0';
      }
      for(int j = y+1; j < y+4; j++){
	if(data[x][j] == '1'){
	  X.push(x);
	  Y.push(j);
	}
	data[x][j] = '0';
      }

      for(int j = x-1; j > x-4; j--){
	if(data[j][y] == '1'){
	  X.push(j);
	  Y.push(y);
	}
	data[j][y] = '0';
      }
      for(int j = y-1; j > y-4; j--){
	if(data[x][j] == '1'){
	  X.push(x);
	  Y.push(j);
	}
	data[x][j] = '0';
      }
    }
    cout << "Data" << " " << i+1 << ":" <<endl;
    for(int j = 4; j <= 11; j++){
      for(int k = 4; k <= 11; k++){
	cout <<  data[k][j];
      }
      cout << endl;
    }
  }
  return 0;
}

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

counter = [0] * 10001
for x in range(1, 100+1):
    n1 = x * x
    if n1 >= N:
        continue
    for y in range(x, 100+1):
        n2 = n1 + y * y + x * y
        if n2 >= N:
            continue
        for z in range(y, 100+1):
            n = n2 + z * z + y * z + z * x
            if 1 <= n <= 10000:
                if x == y and y == z:
                    counter[n] += 1
                elif x == y or y == z:
                    counter[n] += 3
                else:
                    counter[n] += 6
for i in range(1, N+1):
    print(counter[i])


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

int main() {
  int h, w;
  cin >> h >> w;

  vector<string> s(h);
  for (auto&& e : s) cin >> e;

  //  差分の配列を用意しておく
  const int dx[8] = {1, 0, 1, -1, 0, 1, -1, -1};
  const int dy[8] = {0, 1, 1, 0, -1, -1, 1, -1};

  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (s.at(i).at(j) == '#') continue;

      int bomb = 0;
      for (int d = 0; d < 8; d++) {
        const int ii = i + dx[d];
        const int jj = j + dy[d];

        // 端の場合の処理
        if (ii < 0 or h <= ii) continue;
        if (jj < 0 or w <= jj) continue;

        if (s.at(ii).at(jj) == '#') bomb++;
      }
      s.at(i).at(j) = char(bomb + '0');
    }
  }

  for (auto&& e : s) cout << e << endl;
}

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

typedef long long ll;
#define MOD = 1000000007;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) { s >> x; } return s;}
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
#define ANS(a) cout<<a<<endl
void yes(bool f){cout<<(f?"yes":"no")<<endl;}
void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
void YES(bool f){cout<<(f?"YES":"NO")<<endl;}

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

    int N; cin >>N;
    vector<int> h(N); cin >> h;
    vector<int> cost(N);    

    cost[0] = 0;
    cost[1] = abs(h[1]-h[0]);
    for (int i = 2; i < N; i++) {
        int c1, c2;
        c1 = cost[i - 1] + abs(h[i-1]-h[i]);
        c2 = cost[i - 2] + abs(h[i-2]-h[i]);
        cost[i] = min(c1, c2);
    }

    cout << cost[N - 1] << endl;
}


Measured memory_bytes: 1024
n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)

puts a.map(&:to_s).join(' ')

1.upto(n - 1) do |i|
  v = a[i]
  j = i - 1
  while j >= 0 && a[j] > v
    a[j + 1] = a[j]
    j -= 1
  end
  a[j + 1] = v

  puts a.map(&:to_s).join(' ')
end



Measured memory_bytes: 6880
package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	var h, w int
	fmt.Scan(&h, &w)

	s := make([]string, h)
	for i := 0; i < h; i++ {
		fmt.Scan(&s[i])
	}

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

	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			if s[i][j] == '#' {
				continue
			}

			num := 0
			for d := 0; d < 8; d++ {
				ni := i + dy[d]
				nj := j + dx[d]

				if ni < 0 || h <= ni {
					continue
				}
				if nj < 0 || w <= nj {
					continue
				}
				if s[ni][nj] == '#' {
					num++
				}
			}

			s[i] = strings.Replace(s[i], ".", strconv.Itoa(num), 1)
		}
	}

	for i := 0; i < h; i++ {
		fmt.Println(s[i])
	}
}


Measured memory_bytes: 896
n, k = [int(i) for i in input().split()]


def kai(x, p):
    a = 1
    for i in range(1, x + 1):
        a *= i
        a %= p
    return a


def comb(a, b, p):
    if a < 0 or b < 0:
        return 0
    elif a < b:
        return 0
    c = 1
    c *= kai(a, p)
    c *= pow(kai(b, p), p - 2, p)
    c *= pow(kai(a - b, p), p - 2, p)
    return c % p


p = 10 ** 9 + 7


def kei(i):
    return comb(n-k+1, i, p) * comb(k-1, i-1, p) % p


for i in range(1, k+1):
    print(kei(i))


Measured memory_bytes: 3316
#include<iostream>
using namespace std ;
long long int data[102][11][1102]={} ; //数字,使用個数,合計
	
int main(){
	int n,s ;
	
	data[0][0][0] = 1 ;
	data[0][1][0] = 1 ;
	
	for( int i=0 ; i<101 ; i++ ){
		for( int j=0 ; j<10 ; j++ ){
			for( int k=0 ; k<1001 ; k++ ){
				data[i+1][j][k] += data[i][j][k] ;
				data[i+1][j+1][k+i+1] += data[i][j][k] ;
			}
		}
	}
	
	while(1){
		cin >> n >> s ;
		if( n==0 && s==0 ) break;
		cout << data[100][n][s] << endl ;
	}
	
return 0;
}

Measured memory_bytes: 10732
n, x = map(int, input().split())
a = list(map(int, input().split()))
count = 0
for i in range(n - 1):
    if a[i] + a[i + 1] > x:
        count += a[i] + a[i + 1] - x
        if a[i + 1] >= a[i] + a[i + 1] - x:
            a[i + 1] = x - a[i]
        else:
            a[i + 1] = 0
            a[i] = x
print(int(count))


Measured memory_bytes: 14060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 40;
#define FOR(i,k,n) for(int i=(k);i<(n);++i)
const ll MOD = 1e9 + 7;
 
int main(){
    string s; cin >>s;
    int N = s.size();
    int x, y;
    FOR(i,0,N){
        if(s[i]=='A'){
            x=i;
            break;
        }
    }
    FOR(i,0,N){
        if(s[N-i-1]=='Z'){
            y=N-i-1;
            break;
        }
    }
    cout << y-x+1 << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(), v.end()
#define dcout cout << fixed << setprecision(15)
#define arep(i, a) for(auto i : a)
#define F first
#define S second
#define VE vector<int>
#define pb(x) push_back(x)
#define MOD 1000000007
#define INF 10000000000
#define int long long
#define KETA(n) floor(log10(n) + 1)
using namespace std;
signed main() {
    char a, b, c;
    cin >> a >> b >> c;
    int n = (b - '0') * 10 + c - '0';
    if(n % 4 == 0)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}

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

int main(){
  int a, b;
  cin >> a >> b;
  if(a>=13){
    cout << b << endl;
  }
  else{
    if(a>=6){
      cout << b/2 << endl;
    }
    else{
      cout << 0 << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 3600
import sys
sys.setrecursionlimit(10**6)

N = int(input())
es = [[] for _ in range(N)]

for i in range(N-1):
    u,v,w = map(int, input().split())
    u,v = u-1, v-1
    es[u].append((v,w))
    es[v].append((u,w))


ans = [-1] * N

def dfs(node, c):

    ans[node] = c
    for next,w in es[node]:
        # 未着色であれば
        if ans[next] == -1:
            if w % 2 == 0:
                # 距離が偶数なら同じ色
                dfs(next, c)
            else:
                # 距離が異なるなら違う色
                if c == 0:
                    dfs(next, 1)
                else:
                    dfs(next, 0)

dfs(0,0)

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



Measured memory_bytes: 79408
import math

def isPrime(n):
    if n == 1: return False
 
    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
 
    return True
  
num = int(input())
 
res = True
ans = 0
if num > 2 and num%2 == 0:
  num += 1
while(res):
  if isPrime(num):
    print(num)
    break
  num += 2

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;

int main(){ 
  int n;
  cin >> n;
  int ok = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (a & 1) ok = 1;
  }
  if (ok) cout << "first" << endl;
  else cout << "second" << endl;
  return 0;
} 

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	
char a[15];
char b[15];
char c[15];
char k,l;
scanf ("%s %s %s",a,b,c);

for (int i = 0; a[i] != '\0'; i++){
k = a[i];
	
}
for (int i = 0; b[i] != '\0'; i++){
l = b[i];
}

if (k == b[0] && l == c[0]){
	printf ("YES");
}
else {
	printf ("NO");
}
	return 0;
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

#define M 1000000007

int n;
int a[111111],b[111111];

int lba[111111],uba[111111];
int lbb[111111],ubb[111111];

int main(){
	cin.sync_with_stdio(false);
	cin>>n;
	rep(i,n)cin>>a[i];
	rep(i,n)cin>>b[i];
	int minn=0;
	rep(i,n){
		if(minn<a[i]){
			lba[i]=uba[i]=a[i];
			minn=a[i];
		}else{
			uba[i]=a[i];
			lba[i]=1;
		}
	}
	minn=0;
	for(int i=n-1;i>=0;i--){
		if(minn<b[i]){
			lbb[i]=ubb[i]=b[i];
			minn=b[i];
		}else{
			ubb[i]=b[i];
			lbb[i]=1;
		}
	}
	ll res=1;
	rep(i,n){
		if(lba[i]<=ubb[i]&&lbb[i]<=uba[i]){
			res=(res*(min(ubb[i],uba[i])-max(lbb[i],lba[i])+1))%M;
		}else{
			cout<<0<<endl;
			return 0;
		}
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 2688
#include <math.h>
#include <stdio.h>
#define PI 3.14159265359
double min(double x, double y) {
	return x < y ? x : y;
}
int main() {
	int a, b, h, m;
	scanf("%d%d%d%d", &a, &b, &h, &m);
	double an = fabs(6 * m - 0.5 * (h * 60 + m));
	an = min(fabs(360 - an), an);
	long double ans = sqrtl(b * b + a * a - 2 * b * a * cosl(an * PI / 180));
	printf("%.15Lf\n", ans);
	return 0;
}


Measured memory_bytes: 2580
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll mod = 1000000007;

void solve(){
    string s;
    cin >> s;
    int n = s.size();
    int ans = 1e9;
    rep(i,n-2){
        string st = s.substr(i,3);
        int tmp = stoi(st);
        ans = min(ans, abs(tmp-753));
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 256
#!/usr/bin/env python3

'''
Author: andyli
Time: 2020-08-29 19:58:33
'''

import os
from io import BytesIO, IOBase
import sys


def main():
    d,t,s = map(int,input().split())

    print('Yes' if t*s>=d else 'No')
    return


# region fastio
BUFSIZE = 1048576


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = 'x' in file.mode or 'r' not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b'\n') + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode('ascii'))
        self.read = lambda: self.buffer.read().decode('ascii')
        self.readline = lambda: self.buffer.readline().decode('ascii')


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
def input(): return sys.stdin.readline().rstrip('\r\n')

# endregion


if __name__ == '__main__':
    main()


Measured memory_bytes: 62588
N, M = map(int, input().split())

for m in range(M):
    L, R = map(int, input().split())
    if m==0:
        l = L
        r = R
    else:
        if l<L:
            l = L
        if R<r:
            r = R

print(len(list(range(l,r+1))))

Measured memory_bytes: 6900
import sys

sys.setrecursionlimit(10**6)

def dfs(G, v, cur):
    color[v] = cur;

    for next_v in G[v] :
        if not(color[next_v] == -1) :
            if color[next_v] == cur :
                return 0;
            continue;
        if not(dfs(G,next_v,1-cur)):
            return 0;
    return 1;

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

G = [[] for i in range(n)];
for i in range(m) :
    a,b = list(map(int,input().split()));
    G[a-1].append(b-1);
    G[b-1].append(a-1);

color = [-1]*n;

if dfs(G,0,0) :
    print(sum(color)*(n-sum(color))-m);
else :
    print(n*(n-1)//2-m);

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

int n, a[202020];

int main(){
  cin >> n;
  rep(i, n) cin >> a[i];
  
  int cnt = 0;
  rep(i, n) if(a[i] == cnt + 1) cnt++;
  
  cout << ((cnt == 0)? -1 : (n - cnt)) << endl;
  
  return 0;
}

Measured memory_bytes: 1024
package main

import (
	"fmt"
	"math"
)

func main() {
	var n, k, x float64
	fmt.Scan(&n, &k)
	sum := 0.0
	for i := 0; i < int(n); i++ {
		fmt.Scan(&x)
		sum += math.Min(x, k-x) * 2
	}
	fmt.Println(int(sum))
}


Measured memory_bytes: 512
#include <bits/stdc++.h> 
#define ll long long
#define M 1000000007
using namespace std;
int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); 
    ll k,a=100,b,flag=0;
    cin>>k;
    for(int i=1;i<4000;i++)
    {   
        if(a>=k)
        {
            cout<<i-1;break;
        }
        a+=a/100;
    }
    

}

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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

bool enough(LL t, LL A, LL B, vector<LL> &v) {
    LL r = 0;
    for(auto i : v) {
        if(t*B < i) {
            r += (i - t*B)%(A - B) == 0 ? (i - t*B)/(A - B) : (i - t*B)/(A - B) + 1;
        }
    }
    return r <= t;
}

int main() {
    LL N, A, B;
    cin >> N >> A >> B;
    vector<LL> v(N);
    REP(i, N) {
        cin >> v[i];
    }
    LL l = 0;
    LL r = 1e9;
    for(;1 < r - l;) {
        LL mid = (l + r)/2;
        if(enough(mid, A, B, v)) {
            r = mid;
        }else{
            l = mid;
        }
    }
    cout << r << endl;
    return 0;
}



Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#define SWAP(A,B)(A^=B,B^=A,A^=B)
typedef struct
{
	int a;
	int b;
	int c;
} triangle;


char check(triangle *data)
{
	if(data->a < data->b)
		SWAP(data->a,data->b);
	if(data->a < data->c)
		SWAP(data->a,data->c);
	
	data->a *= data->a;
	data->b *= data->b;
	data->c *= data->c;

	if(data->a == data->b + data->c)
		return 1;
	else
		return 0;
}
int main(void)
{
	int datasize;
	triangle data;
	int i;
	char *result;

	scanf("%d",&datasize);
	result=(char*)malloc(sizeof(char)*datasize);
	for(i=0;i<datasize;i++)
	{
		scanf("%d%d%d",&data.a,&data.b,&data.c);
		*(result+i)=check(&data);
	}
	for(i=0;i<datasize;i++)
	{
		if(*(result+i)==1)
			puts("YES");
		else
			puts("NO");
	}
	free(result);
	return 0;
}

Measured memory_bytes: 580
#   AtCoder abc044 a
#   ストレッチ課題

#   入力
n = int(input())    # 宿泊数
k = int(input())    # 単価が切り替わる泊数
x = int(input())    # 単価a
y = int(input())    # 単価b

#   処理
if n <= k:
    fee = n * x
else:
    fee = k * x + (n - k) * y

#   出力
print(fee)


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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

typedef pair<int,int> pi;

const int N=10000;
const int M=20000;
const int INF=123456789;

struct edge{int to,dist,cost;};
vector<edge> G[N];

int u[M],v[M],d[M],c[M];

int D[N];
int PAR[N],COST[N];

int main()
{
    int n,m;
    while(cin >>n >>m,n)
    {
        rep(i,n) G[i].clear();

        rep(i,m)
        {
            scanf(" %d %d %d %d", &u[i], &v[i], &d[i], &c[i]);
            --u[i];
            --v[i];
            G[u[i]].pb(edge{v[i],d[i],c[i]});
            G[v[i]].pb(edge{u[i],d[i],c[i]});
        }

        // dijkstra
        priority_queue<pi,vector<pi>,greater<pi>> que;
        fill(D,D+N,INF);
        fill(COST,COST+N,INF);
        fill(PAR,PAR+N,-1);
        D[0]=0;
        COST[0]=0;

        que.push(pi(0,0));
        while(!que.empty())
        {
            pi p=que.top();
            que.pop();
            int V=p.se;
            if(D[V]<p.fi) continue;
            rep(i,G[V].size())
            {
                edge e=G[V][i];
                if(D[e.to]>D[V]+e.dist || (D[e.to]==D[V]+e.dist && COST[e.to]>e.cost))
                {
                    D[e.to]=D[V]+e.dist;
                    PAR[e.to]=V;
                    COST[e.to]=e.cost;
                    que.push(pi(D[e.to],e.to));
                }
            }
        }

        int ans=0;
        rep(i,n) ans+=COST[i];
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 5560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define nl '\n'
#define vec vector<ll>
#define pr pair<ll,ll>
#define vecp vector< pr >
#define pq priority_queue<ll>
#define pqp priority_queue<pr>
#define ff first
#define ss second
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define fa(x,v) for(auto x:v)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define max4(a,b,c,d) max(a,max3(b,c,d))
#define min4(a,b,c,d) min(a,min3(b,c,d))
#define PI 3.14159265
 const ll MOD=1000000007;
 ll powerm(ll a, ll b, ll MOD) {
    a %= MOD;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return res;
}
ll power(ll a, ll b) {

  ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a ;
        a = a * a ;
        b >>= 1;
    }
    return res;
}
ll binarySearch(ll a[],ll low,ll high,ll key){
    while(low<=high)
    {
        ll mid=low+((high-low)/2);
        if(a[mid]<key)
        {
            low=mid+1;
        }
        else if(a[mid]>key)
        {
            high=mid-1;
        }
        else
        {
            return mid;
        }
    }
    return -1;
}
ll gcd(ll a, ll b) {
   if (b == 0)
      return a;
   return gcd(b, a % b);
}
vec sieve;
void Sieve(int N) {
    const ll maxn = N+1;
    sieve.resize(maxn);
    f(i,0,maxn) sieve[i] = i;
    sieve[1] = -1;
    sieve[0] = -1;
    f(i, 2, maxn) if (i == sieve[i]) for (ll j = 2 * i ; j < maxn ; j += i) if (sieve[j] == j) sieve[j] = i;
}
ll dp[100001][4];
ll rec(ll n,ll*a,ll*b,ll*c)
{
dp[1][1]=a[1];
dp[1][2]=b[1];
dp[1][3]=c[1];
for(ll i=2;i<=n;i++)
{
	dp[i][1]=a[i]+max(dp[i-1][2],dp[i-1][3]);
	dp[i][2]=b[i]+max(dp[i-1][1],dp[i-1][3]);
	dp[i][3]=c[i]+max(dp[i-1][1],dp[i-1][2]);
}
return max3(dp[n][1],dp[n][2],dp[n][3]);
	
}
int main()
{
	fast
ll n;
cin>>n;
ll a[n+1],b[n+1],c[n+1];
f(i,1,n+1)
cin>>a[i]>>b[i]>>c[i];
ll ans=rec(n,a,b,c);
cout<<ans<<nl;
return 0;
}

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

struct data{
	char name[101];
	int price;
	int ren;
	int renkin[101];
};
data im[101];
int visit[101];

int func(int n){
	int c=im[n].renkin[0];
	int ans=0;
	visit[n]=1;
	if(im[n].renkin[0]==0){
		return im[n].price;
	}
	for(int i=1;i<=c;i++){
		if(visit[im[n].renkin[i]]==1){
			ans+=im[im[n].renkin[i]].price;
		}
		else if(im[im[n].renkin[i]].ren==0){
			ans+=im[im[n].renkin[i]].price;
		}
		else {
			ans+=func(im[n].renkin[i]);
		}
	}
	if(ans<im[n].price)
		im[n].price=ans;
	
	return im[n].price;
}
			

int main(void){
	int n,i,j,l;
	while(scanf("%d",&n),n){
		
		int m,k,t;
		char temp[101];
		for(i=0;i<n;i++){
			scanf("%s %d",im[i].name,&im[i].price);
		}
		scanf("%d",&m);
		for(i=0;i<m;i++){
			
			scanf("%s",temp);
			for(j=0;j<n;j++){
				if(!(strcmp(im[j].name,temp))){
					im[j].ren=1;
					break;
				}
			}
			t=j;
			scanf("%d",&k);
			im[t].renkin[0]=k;
			for(j=0;j<k;j++){
				scanf("%s",temp);
				for(l=0;l<n;l++){
					if(!(strcmp(im[l].name,temp))){
						im[t].renkin[j+1]=l;
						break;
					}
				}
			}
		}
		scanf("%s",temp);
		for(i=0;i<n;i++){
			if(!(strcmp(im[i].name,temp))){
				break;
			}
		}
		printf("%d\n",func(i));
		
		for(i=0;i<101;i++){
			visit[i]=0;
			im[i].ren=0;
			im[i].price=0;
		}
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,COUNT) for(int i=0;i<(int)(COUNT);i++)
typedef long long ll;

ll dp[100001];

vector<vector<ll> > graphs;
ll solve(ll S){
  if(dp[S] != -1)
    return dp[S];
  ll N = 0;
  REP(i,graphs[S].size()){
    N = max(solve(graphs[S][i])+1,N);
  }
  return dp[S] = N;

}

int main()
{
  ll N,M,c,to,from,cost,s=0,g;
  cin >> N >> M;
  graphs = vector<vector<ll> >(N,vector<ll>(0));
  REP(i,M){
    cin >> from >> to;
    from--;
    to--;
    graphs[from].push_back(to);
  }
  REP(i,100001)dp[i]=-1;
  ll MA = 0;
  REP(i,N)MA = max(MA,solve(i));
  cout << MA << endl;
  return 0;
}



Measured memory_bytes: 8576
import java.util.Collections;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Arrays;

public class Main {

    // static final int modnum = 1e9 + 7;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();

        LinkedList<Integer> value = new LinkedList<Integer>();

        for (int i = 0; i < N; i++) {
            int in = sc.nextInt();
            value.add(in);
        }

        // Node[] dp = new Node[K+1];
        // dp[0] = new Node(new LinkedList<Integer>(), new LinkedList<Integer>(value));
        // dp[1] =

        long ans = 0;
        for (int al = 0; al <= N && al <= K; al++) {
            int i,j;
            for (i = 0; i <= al; i++) {
                for (j = 0; j <= al - i; j++) {
                    LinkedList<Integer> hand = new LinkedList<Integer>();
                    
                    
                    for(int u=0;u<i;u++){
                        hand.add(value.get(u));
                    }
                    for(int u=0;u<j;u++){
                        hand.add(value.get(value.size() - u - 1));
                    }

                    Collections.sort(hand);
                    // System.out.println(al+":"+i+":"+j+Arrays.toString(hand.toArray()));
                    for (int k = 0; k < K - al && hand.size() > 0; k++) {
                        if (hand.get(0) < 0)
                            hand.remove(0);
                        else
                            break;
                    }
                    // System.out.println(al+":"+i+":"+j+Arrays.toString(hand.toArray()));
                    long ret = 0;
                    for (int num : hand) {
                        ret += num;
                        ans = Math.max(ans, ret);
                    }

                }
            }
        }
        
        System.out.println(ans);
    }
}

Measured memory_bytes: 41952
# open(0)を使うことで，開業にとらわれない入力を行う
#N, *S = map(int,open(0).read().split()) # ひょっとして普通にデバッグの入力ではうまく行かないのかも
N = int(input())
S=[]
for _ in range(N):
    S.append(input())
dic = {}
for s in S:
    if not s in dic:
        dic[s] = [s,0]
    dic[s][1] += 1
#dic_swap = {v: k for k,v in dic.values()} # keyとvalueを入れ替えるdic.valuesでkeyとvalueが要素ごとに取得できることがキー
#dic_swap = {v: k for k,v in dic.values()}
dic_swap = {}
for k,v in dic.values():
    if not v in dic_swap :
        dic_swap[v] = [k]
        continue
    dic_swap[v].append(k)

key_sorted = list(dic_swap.keys())
key_sorted.sort()

v = dic_swap[key_sorted[-1]]
v = list(v)
v.sort()
for vi in v:
    print(vi)


Measured memory_bytes: 53576
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
#include <cctype>
#include <cstdio>
#include <math.h>
using namespace std;
int main(){
    string str;
    cin >> str;
    bool n=false,w=false,s=false,e=false;
    for(int i=0;i<str.length();i++){
        if(str[i]=='N'){
            n=true;
        }else if(str[i]=='W'){
            w=true;
        }else if(str[i]=='S'){
            s=true;
        }else{
            e=true;
        }
    }
    string ans="Yes";
    if(n==true&&s==false){
        ans="No";
    }else if(s==true&&n==false){
        ans="No";
    }
    if(e==true&&w==false){
        ans="No";
    }else if(w==true&&e==false){
        ans="No";
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int W = scn.nextInt();
		int H = scn.nextInt();
		int x = scn.nextInt();
		int y = scn.nextInt();
		int r = scn.nextInt();

		if (x >= r && y >= r && x <= W - r && y <= H - r) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 26152
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <map>

using namespace std;

#define MOD (1000000007)

typedef long long int ll;

string S1;
string S2;

int main()
{
    int N;

    scanf("%d", &N);

    cin >> S1;
    cin >> S2;
    int pos = 0;
    int pre = 0;
    ll ans = 0;
    
    if ( S1[pos] == S2[pos] ) {	// vert
	ans = 3;
	pos += 1;
	pre = 0;
    }
    else {			// hori
	ans = 6;
	pos += 2;
	pre = 1;
    }
    
    while ( pos < N ) {
	if ( S1[pos] == S2[pos] ) { // vert
	    if ( pre == 0 ) {	    // vert vert
		ans *= 2;
		ans %= MOD;
	    }
	    else {		// hori vert
		ans *= 1;
		ans %= MOD;
	    }
	    pre = 0;
	    pos += 1;
	}
	else {
	    if ( pre == 0 ) {	    // vert hori
		ans *= 2;
		ans %= MOD;
	    }
	    else {		// hori hori
		ans *= 3;
		ans %= MOD;
	    }
	    pre = 1;
	    pos += 2;	    
	}
    }

    printf("%lld\n", ans);
    
    return 0;
}


Measured memory_bytes: 256
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, ' '));

            return;
        }

        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;

            var fN = 0;

            foreach (var c in N.ToString())
            {
                fN += (int)(c - '0');
            }

            if (N % fN == 0) WriteLine("Yes");
            else WriteLine("No");
        }
    }

    public static class Extensions
    {
        public static string Reverse(this string sourse)
        {
            char[] chrAry = sourse.ToCharArray();
            Array.Reverse(chrAry);
            return new string(chrAry);
        }
    }

    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: 13268
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}

int n;
vector<vector<pair<int,int>>> v;

//決め打ちしたときに正直者の発言が矛盾していないかをチェックする
bool check(int bit) {
    rep(i,n) {
        for(auto p : v[i]) {
            int x = p.first; //対象の人
            int y = p.second;//0:不親切な人1:正直者
            //正直者の発言だけ見る
            if(!(bit&(1<<i))) continue;
            if(y==1 && !(bit&(1<<x))) return false; //正直者である人が実際には正直者でない
            if(y==0 && bit&(1<<x)) return false; //不親切な人が実際には不親切でない
        }
    }
    return true;
}
int main() {
    cin >> n;
    v.resize(n);
    rep(i,n) {
        int a;
        cin >> a;
        v[i].resize(a);
        rep(j,a) {
            cin >> v[i][j].first >> v[i][j].second;
            v[i][j].first--;
        }
    }
    int ans = 0;
    for(int bit = 0;bit < (1<<n);bit++) {
        if(check(bit)) {
            int cnt = 0;
            rep(i,n) {
                if(bit&(1<<i))cnt++;
            }
            ans = max(ans,cnt);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3604
N, M = gets.split.map(&:to_i)
lists = []
pre = {}
M.times do
  s, t = gets.chomp.split
  t = t.to_i
  lists << [s, t]
  (pre[s] ||= []) << t
end

# p lists
pre.each do |k, v|
  v.sort_by!{|x|x}
end
# p pre
lists.each do |list|
  ind = pre[list[0]].bsearch_index{|x|x >= list[1]} + 1
  puts"#{list[0].rjust(6, "0")}#{ind.to_s.rjust(6, "0")}"
end

Measured memory_bytes: 51452
#include <iostream>
#include <stack>
using namespace std;
int main()
{
    stack<int> s;
    int t;
    while (cin >> t) {
        if (t > 0) s.push(t);
        else if (!s.empty()) {
            cout << s.top() << endl;
            s.pop();
        }
    }
    while (!s.empty()) {
        cout << s.top() << endl;
        s.pop();
    }
    return 0;
}

Measured memory_bytes: 0
n = int(input())
XY = []
for i in range(n):
    a = int(input())
    xy = []
    for j in range(a):
        x, y = map(int, input().split())
        xy.append([x, y])
    XY.append(xy)
ans = 0
for i in range(2 ** n):
    s = [0] * n
    cnt = 0
    case = True
    for j in range(n):
        if (i >> j) & 1:
            s[n - 1 - j] = 1
            cnt += 1
    for k in range(n):
        if s[k] == 1:
            for l in range(len(XY[k])):
                if s[XY[k][l][0] - 1] != XY[k][l][1]:
                    case = False
    if case is True:
        ans = max(ans, cnt)
print(ans)

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

void solve(int n){
	int page[50];
	for(int i=0;i<n;i++){
		scanf("%d ", &page[i]);
	}
	scanf("\n");
	
	int begin = page[0];//?????????????§???????
	int end = page[0];//?????????????????????
	for(int i=1;i<n;i++){
		if(end + 1 == page[i]){
			end = page[i];
		}else{
			if(begin == end){
				printf("%d ", begin);	
			}else{
				printf("%d-%d ", begin, end);
			}
			begin = page[i];
			end = page[i];
		}
	}
	if(begin == end){
		printf("%d", begin);	
	}else{
		printf("%d-%d", begin, end);
	}
	printf("\n");
}

int main() {
	bool first = true;
	while(true){
		int n;//?????¨?????????????????°
		scanf("%d\n", &n);
		if(n==0){
			break;
		}
		solve(n);
	}
	
	return 0;
}

Measured memory_bytes: 1192
obj = {}

n = gets.chomp.to_i
for i in 0...n do
  s = gets.chomp
  if (!obj[s]) then
    obj[s] = 0
  end
  obj[s] += 1
end

n = gets.chomp.to_i
for i in 0...n do
  s = gets.chomp
  if (!obj[s]) then
    obj[s] = 0
  end
  obj[s] -= 1
end


res = 0
obj.each {|(s, k), arr|
  if (obj[s] > res) then
    res = obj[s]
  end
}

puts res


Measured memory_bytes: 1788
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long LL;
const int maxn=1e5+5;
const LL mod=1e9+7;
int read() {
	char ch=getchar();int x=0,f=1;
	while(ch<'0' || ch>'9')	{if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int gcd_(int a,int b) {return b==0?a:gcd_(b,a%b);}
LL fpow(LL a,LL b) {
	LL res=1;
	while(b) {
		if(b&1) res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}
int main() {
//	cout<<"Accepted!\n";
	int n,k,cnt=0;
	cin>>n>>k;
	do {
		n/=k;
		cnt++;
	}while(n);
	cout<<cnt;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for( int i = 0 ; i < n ; i++ )
 
int main() {
  
  int N  ;
  cin >> N ;
  int max = 0 ;
  int ans = 0 ; 
  vector<int> A(N) ; 
  rep(i,N) cin >> A.at(i);
  rep(i,N){
    if( max <= A.at(i) ) {
    ans++;
    max = A.at(i) ;  
    }
  
  }
  cout << ans << endl;
}


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

int main(){
  int64_t N,T;
  cin >> N >> T;
  vector<int64_t> t(N);
  for(int i=0;i<N;i++){
    cin >> t.at(i);
  }
  int64_t ans=0;
  for(int i=1;i<N;i++){
    ans+=min(t.at(i)-t.at(i-1),T);
  }
  ans+=T;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792