akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;
const ll MOD = 1e9+7; ll LLINF = 1LL << 60; int INF = INT_MAX;

//

int main(){
    int a,b; cin>>a>>b;
    cout<<(a+b)%24<<endl;
}

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

namespace ABC080A
{
    class Program
    {
        static void Main(string[] args)
        {
            int n, a, b,x;

            var word = Console.ReadLine().Split(' ');

            n = int.Parse(word[0]);
            a = int.Parse(word[1]);
            b = int.Parse(word[2]);
            if (a * n < b)
                x = (a * n);

            else x = b;



            Console.WriteLine(x);

            Console.ReadKey();
        }
    }
}


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

int main() {
  int a;
  int b;
  int c;
  string s;

  cin >> s;
  a = stoi(s) / 100;
  b = (stoi(s) - a * 100) / 10;
  c = stoi(s) % 10;
  cout << a + b + c << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main (){
int i,a=0,j;
char k[101],l[101],b;
scanf ("%s",k);
scanf ("%s",l);
for (i=0;k[i]!=0;i++){
	if(strcmp(k,l)==0)
	{
	a++;
		break;	
	}
	b=k[0];
	for(j=0;k[j]!=0;j++)
	{
	k[j]=k[j+1];	
	}
	k[strlen(k)]=b;
}
if(a==1){
	printf ("Yes");}
	else
	{
		printf ("No");
	}
	return 0;
	}


Measured memory_bytes: 128
// writer: w33z8kqrqk8zzzx33
#include <bits/stdc++.h>
using namespace std;
 
#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define log(a) cerr<<"\033[32m[DEBUG] "<<#a<<'='<<(a)<<" @ line "<<__LINE__<<"\033[0m"<<endl
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
using ll=long long;
using pii=pair<int, int>;
//#define int ll
const int MOD = 1000000007;

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int v, k; cin >> v >> k;
    int ans = 0;
    while(v) {
        ans++;
        v /= k;
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
=begin
N
A1
...
An
=end

n = gets.chomp.to_i
as = n.times.map do
  gets.chomp.to_i
end

as2 = as.sort_by {|i| i * -1}

as.each do |a|
  if a == as2[0]
    puts as2[1]
  else
    puts as2[0]
  end
end


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

void solve(long long N, long long A, long long B){
	cout << ((B - A) % 2 == 0 ? "Alice" : "Borys") << endl;
}

int main(){	
	long long B;
	long long N;
	long long A;
	scanf("%lld",&N);
	scanf("%lld",&A);
	scanf("%lld",&B);
	solve(N, A, B);
	return 0;
}



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

char map[20][20];
int W,H;
int cnt;

void fac(int y,int x){
  map[y][x]='#';
  cnt++;
  
  if(map[y+1][x]=='.' && y < H-1)
    fac(y+1,x);
  if(map[y-1][x]=='.' && y > 0)
    fac(y-1,x);
  if(map[y][x+1]=='.' && x < W-1)
    fac(y,x+1);
  if(map[y][x-1]=='.' && x > 0)
    fac(y,x-1);  
}

int main(){
  int i,j;
  int x,y;

  while(1){
    cin >> W >> H;

    if(W+H==0)
      break;
    
    for(i=0;i<H;i++){
      for(j=0;j<W;j++){
	cin >> map[i][j];
	if(map[i][j]=='@'){
	  x=j; y=i; 
	} //@position      
      }
    }
    
    cnt=0;
    fac(y,x); //release cnt
    cout << cnt << endl;
  }
  return 0;
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
#define lli long long
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    lli n;
    cin>>n;
    double s,ss,a;
    a=(double)n/3;
    cout<<fixed<<setprecision(6)<<a*a*a<<endl;
}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

N = I()

divisor = []
for i in range(1,int(N**.5)+1):
    if N % i == 0:
        divisor.append(i)
        if i != N//i:
            divisor.append(N//i)

ans = 0
for d in divisor:
    m = d-1
    if N//d < m:
        ans += m

print(ans)


Measured memory_bytes: 66184
#include<iostream>
#include<cstring>

using namespace std;

int main()
{
    string  s, t;
    cin >> s >> t;

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

    string  u;
    cin >> u;

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

    cout << a  << " " << b;
}

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

ll d[222][222];
bool seen[10];
ll an=1e9,sum=0,r;
ll R[10];


void dfs(int i,ll len=1){
    if(len==r)an=min(an,sum);
    seen[i]=1;
    rep(j,0,r){
        if(seen[j])continue;
        seen[j]=1;
        sum+=d[R[i]][R[j]];
        dfs(j,len+1);
        seen[j]=0;
        sum-=d[R[i]][R[j]];
    }
    seen[i]=0;
}

int main(){
    ll n,m;cin>>n>>m>>r;
    rep(i,0,r){cin>>R[i];R[i]--;}
    rep(i,0,n)rep(j,0,n)d[i][j]=1e9;
    rep(i,0,n)d[i][i]=0;
    rep(i,0,m){
        ll a,b,c;
        cin>>a>>b>>c;
        a--;b--;
        d[a][b]=c;
        d[b][a]=c;
    }
    rep(k,0,n){
        rep(i,0,n){
            rep(j,0,n){
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
    rep(i,0,r){
        sum=0;
        dfs(i);
    }
    cout<<an<<endl;
}
    









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

typedef long long ll;
#define MOD1 1000000007
#define MOD2 1000000009
#define fr(a,b) for(ll i=a;i<b;i++)
#define end "\n"


int32_t main(){
#ifdef _MSC_VER
    _CRT_SECURE_NO_WARNINGS
#endif
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
#pragma warning(suppress: 4101) srand(time(nullptr));
    cout << setprecision(20) << fixed;
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
   string s;
   cin>>s;
   int count=1;
    for (int i = 1; i < 3; ++i) {
        if(s[i]==s[i-1] && s[i]=='R')
            count++;
    }
    if(s[0]==s[1] && s[1]==s[2] && s[0]=='S')
        count=0;
    cout<<count<<endl;
    return 0;
}

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

using namespace std;

#define ll long long
#define pb push_back
#define vi vector<int>
#define bn(n) (n).begin(), (n).end()
#define FOR(n) for(int i = 0; i < (int)n; i++)
#define MX 1e5


void solve() {
    int x, a, b;
    cin >> x >> a >> b;
    if (a-b >= 0) {
        cout << "delicious\n";
    } else if ((b-a) <= x) {
        cout << "safe\n";
    } else {
        cout << "dangerous\n";
    }
}

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

    int t = 1, i = 1;
    //cin >> t;
    while(t--) {
        //cout << "Case #" << i << ": ";
        solve();
        //i++;
    }
    return 0;
}


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

int main()
{
	int n;
	cin >> n;
	string now,last;
	set<string> st;
	int flag =  1;
	for(int i = 0;i < n;i++)
	{
		cin >> now;
		if(i == 0){ st.insert(now);last = now ;continue;}
		if(last.back() == now[0] and st.find(now) == st.end())
		{
			st.insert(now);
			last = now;
		}
		else
		{
			// cout << i << endl;
			// cout << last.back() << " " << now[0] << endl;
			flag = 0;
			break;
		}
	}
	if(flag) 
		cout << "Yes" << endl;
	else 
		cout << "No" << endl;
}

Measured memory_bytes: 256
hw = gets.chomp.split
h = hw[0].to_i
w = hw[1].to_i

s = []
h.times do
    input = gets.chomp
    s << input
end

def top h, w, s
    top = 0
    h -= 1
    w -= 1
    3.times do |i|
        top += 1 if h >= 0 && w + i >= 0 && s[h][w + i] == "#"
    end
    return top
end

def middle h, w, s
    middle = 0
    w -= 1
    2.times do |i|
        middle += 1 if w + i * 2 >= 0 && s[h][w + i * 2] == "#"
    end
    return middle
end

def bottom h, w, s, hh
    bottom = 0
    h += 1
    w -= 1
    3.times do |i|
        bottom += 1 if h < hh && w + i >= 0 && s[h][w + i] == "#"
    end
    return bottom
end

def mine h, w, s, hh
    mines = top(h, w, s) + middle(h, w, s) + bottom(h, w, s, hh)
    return mines
end

h.times do |i|
    w.times do |j|
        if s[i][j] == "#"
            print "#"
        else
            print mine(i, j, s, h)
        end
    end
    print "\n"
end

Measured memory_bytes: 1788
n=int(input())
lst = list(map(int,input().split()))
cnt = 0
height = 0
for j in range(n):
  if j == n-1:
    if lst[j] >= height:
      continue;
    else:
      cnt += 1
  else:
    if lst[j] - lst[j+1]<=1 and lst[j] >= height:
      if lst[j] > height:
        height = lst[j] - 1
    else:
      cnt += 1
if cnt == 0:
  print("Yes")
else:
  print("No")

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

int main() {
	int A, B;
	string S;
	cin >> A >> B >> S;

	int Q = 0;

	for (int i = 0; i < S.size(); i++) {
		if (S[i] == '-') Q++;
	}

	if (S[A] == '-' && Q == 1) {
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;
	
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;


public class Main {
	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));       
		try {
			String line;
			while(true){
				/* input */
				line = br.readLine();

				int w = Integer.parseInt(line.split(" ")[0]);
				int h = Integer.parseInt(line.split(" ")[1]);
				if(w == 0 && h == 0){
					return;
				} 
				int[][] field = new int[h][w];
				int[] pos = new int[2]; 
				for(int i=0;i<h;i++){
					String str = br.readLine();
					for(int j=0;j<w;j++){
						if(str.charAt(j)=='.'){
							field[i][j] = 1;
						} else if(str.charAt(j)=='#'){
							field[i][j] = 0;
						} else {
							field[i][j] = 2;
							pos[0] = i;
							pos[1] = j;
						}
					}
				}
				/* processing */
				int res = search(pos[0],pos[1],field,h,w);
				
				/* output */
				System.out.println(res);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public static int search(int posi, int posj, int[][] field,int h,int w){
		int sum = 1;
		field[posi][posj] = 2;
		
		//up
		if(posi>0&&field[posi-1][posj]==1){
			sum += search(posi-1,posj,field,h,w);
		}
		//right
		if(posj<w-1&&field[posi][posj+1]==1){
			sum += search(posi,posj+1,field,h,w);
		}
		
		//down
		if(posi<h-1&&field[posi+1][posj]==1){
			sum += search(posi+1,posj,field,h,w);
		}
		
		//left
		if(posj>0&&field[posi][posj-1]==1){			
			sum += search(posi,posj-1,field,h,w);
		}

		return sum;
	}
	
}

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

int main()
{
	int N;
	cin >> N;
	A[0] = 0;
	A[N+1] = 0;
	int sum = 0;
	rep(i,N)
	{
		cin >> A[i+1];
		sum += abs(A[i+1]-A[i]);
	}
	sum += abs(A[N+1]-A[N]);
	rep(i,N)
	{
		int temp = sum;
		temp -= abs(A[i]-A[i+1]);
		temp -= abs(A[i+1]-A[i+2]);
		temp += abs(A[i]-A[i+2]);
		cout << temp << endl;
	}
	return 0;
}

Measured memory_bytes: 3976
W, H, N = map(int, input().split())
l = []
x_low_max = 0
y_low_max = 0
x_high_min = W
y_high_min = H
area = 0
for i in range(N):
    l.append(list(map(int, input().split())))
    a = l[i][2]
    if a == 1:
        if x_low_max < l[i][0]:
            x_low_max = l[i][0]
    elif a == 2:
        if x_high_min > l[i][0]:
            x_high_min = l[i][0]
    elif a == 3:
        if y_low_max < l[i][1]:
            y_low_max = l[i][1]
    elif a == 4:
        if y_high_min > l[i][1]:
            y_high_min = l[i][1]
# print(l)
# print("{} {} {} {}".format(x_low_max, x_high_min, y_low_max, y_high_min))

if x_high_min > x_low_max and y_high_min > y_low_max:
    area = (x_high_min - x_low_max) * (y_high_min - y_low_max)

print(area)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;
#define int long long
int32_t main(){
	int n; cin>>n;
	vector<int> a(n);
	for(int i = 0; i < n; i++){
		cin>>a[i];
	}
	int ans = 0;
	while(true){
	rep(i, n){
		if(a[i] % 2 != 0){
			cout<<ans<<endl;
			return 0;
		}
		a[i] /= 2;
		if(i == n - 1) ans++;
		}
	}
	
}


Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())

ans = 0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if i*500 + j*100 + k*50 == X:
                ans += 1

print(ans, flush=True)


Measured memory_bytes: 9160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    if(a > b) swap(a, b);
    for(int i = 0; i < b; i++) cout << a;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <set>
#include <iomanip>
#include <vector>

using namespace std;

int main() {
	int n, a, b;
	cin >> n >> a >> b;
	if ((b - a) % 2)
		cout << "Borys" << endl;
	else
		cout << "Alice" << endl;
	


#ifdef DIMA_DEBUG
	system("pause");
#endif // DIMA_DEBUG

}

Measured memory_bytes: 256
#include<stdio.h>
int main (void){
 int n,i,l,s;
 int z;
 scanf("%d",&n);
 for(i=0;i<n;i++){
  scanf("%d",&z);
  if(!i){
   s=z;
   l=z;
  }else{
   if(s>z)
    s=z;
   if(l<z)
    l=z;
  }
 }
 printf("%d\n",(l-s));
}



Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <iostream>
#include <functional>
#include <algorithm>
#include <climits>
#include <string>
#include <vector>
#include <map>
#include <cmath>

using namespace std;

#define println(s) cout << s << '\n';
#define rep(i, n) for (int i=0; i<int(n); i++)
#define all(c) (c).begin(), (c).end()


char str[10001];

int main() {
  while(cin >> str) {
    int count_joi = 0;
    int count_ioi = 0;
    for (int i=0; i<strlen(str)-2; i++) {
      if (str[i+0] == 'J' && str[i+1] == 'O' && str[i+2] == 'I') count_joi++;
      if (str[i+0] == 'I' && str[i+1] == 'O' && str[i+2] == 'I') count_ioi++;
    }
    println(count_joi);
    println(count_ioi);
  }
  return 0;
}

Measured memory_bytes: 1144
#include<vector>
#include<algorithm>
using namespace std;
int main(){
	int n,r,p,c;
	while(cin>>n>>r,n){
		vector<int> d(n),e(n); for(int i=0;i<n;i++)d[i]=n-i;
		for(int i=0;i<r;i++)cin>>p>>c,e=d,copy(d.begin(),d.begin()+p-1,e.begin()+c),
		copy(d.begin()+p-1,d.begin()+p-1+c,e.begin()),d=e;
		cout<<d[0]<<endl;
	}
	return 0;
}

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

int main(){
  int N;
  cin >> N;

  int res;
  res = 0;
  if(N <= 111){
    res = 111;
  } else if(N <= 222){
    res = 222;
  } else if(N <= 333){
    res = 333;
  } else if(N <= 444){
    res = 444;
  } else if(N <= 555){
    res = 555;
  } else if(N <= 666){
    res = 666;
  } else if(N <= 777){
    res = 777;
  } else if(N <= 888){
    res = 888;
  } else if(N <= 999){
    res = 999;
  }

  cout << res << endl;
}


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

typedef long long ll;
typedef pair<ll, ll> P;

const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const int int_inf = 100000000;
const double eps = 1e-9;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int k, n;
    cin >> k >> n;
    vector <int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];

    int m = -1;
    for (int i = 0; i < n; i++) {
        chmax(m, a[i+1] - a[i]);
    }
    chmax(m, k - a[n-1]+ a[0]);
    
    cout << k - m << endl;
    
    return 0;
}



Measured memory_bytes: 1024
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def debug(table, *args):
    ret = []
    for name, val in table.items():
        if val in args:
            ret.append('{}: {}'.format(name, val))
    print(' | '.join(ret), file=sys.stderr)


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


def main():
    R = I()
    print(2 * R * math.pi)


if __name__ == '__main__':
    main()


Measured memory_bytes: 68276
import sys
import fractions
input = sys.stdin.readline


mod = 10 ** 9 + 7
N = int(input().strip())
A = list(map(int, input().strip().split(" ")))

lcm = 1
for a in A:
    lcm = a // fractions.gcd(a, lcm) * lcm

ans = 0
for a in A:
    ans += lcm // a

print(ans % mod)

Measured memory_bytes: 6072
# frozen_string_literal: true

require 'prime'

module Residue
  MODULO = 1_000_000_007
  def self.inv(x)
    extgcd(x, MODULO)[0] % MODULO
  end

  def self.pow(x, i)
    retun 1 if i == 0
    r = 1
    i %= (MODULO - 1)
    while i > 0
      r = (r * x) % MODULO if (i & 1) != 0
      x = (x * x) % MODULO
      i >>= 1
    end
    r
  end

  def self.extgcd(a, b)
    x_2 = 1
    x_1 = 0
    y_2 = 0
    y_1 = 1
    r_2 = a
    r_1 = b
    loop do
      q, r = r_2.divmod(r_1)
      x = x_2 - q * x_1
      y = y_2 - q * y_1
      break if r == 0

      x_2 = x_1
      x_1 = x
      y_2 = y_1
      y_1 = y
      r_2 = r_1
      r_1 = r
    end
    [x_1, y_1, r_1]
  end
end


primes = Prime.each(1_000_000).to_a
n = gets.to_i
an = gets.split(' ').map(&:to_i)
pn = an.map { |ai| Prime.prime_division(ai) }
lcm_div = primes.zip(Array.new(primes.size, 0)).to_h
pn.each do |hi|
  hi.each do |arr|
    k, v = arr
    lcm_div[k] = v if lcm_div[k] < v
  end
end
lcm_div.reject! { |_k, v| v == 0 }
lcm_prod=1
lcm_div.each do |k, v|
  lcm_prod=(lcm_prod * Residue.pow(k, v)) % Residue::MODULO
end
res=an.sum do |ai|
  (lcm_prod * Residue.inv(ai))%Residue::MODULO
end % Residue::MODULO
p res


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

int main(){
    int A[9];
    int ans[9];

    for (int i = 0; i < 9; i++){
        cin >> A[i];
    }

    int N;
    cin >> N;

    for (int i = 0; i < N; i++){
        int B;
        cin >> B;
        for (int j = 0; j < 9; j++){
            if (B == A[j]){
                A[j] = 0;
            }
        }
    }

    if (A[0] == 0 && A[1] == 0 && A[2] == 0){
        cout << "Yes" << endl;
    }
    else if (A[3] == 0 && A[4] == 0 && A[5] == 0){
        cout << "Yes" << endl;
    }
    else if (A[6] == 0 && A[7] == 0 && A[8] == 0){
        cout << "Yes" << endl;
    }
    else if (A[0] == 0 && A[3] == 0 && A[6] == 0){
        cout << "Yes" << endl;
    }
    else if (A[1] == 0 && A[4] == 0 && A[7] == 0){
        cout << "Yes" << endl;
    }
    else if (A[2] == 0 && A[5] == 0 && A[8] == 0){
        cout << "Yes" << endl;
    }
    else if (A[0] == 0 && A[4] == 0 && A[8] == 0){
        cout << "Yes" << endl;
    }
    else if (A[2] == 0 && A[4] == 0 && A[6] == 0){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    
}


Measured memory_bytes: 256
import java.util.Scanner;


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

	int n = sc.nextInt();
	int[] A = new int[n];
	for(int i=0; i<n; i++){
	    A[i] = sc.nextInt();
	}
	int q = sc.nextInt();
	int[] m = new int[q];
	for(int i=0; i<q; i++){
	    m[i] = sc.nextInt();
	}

	int[][] num = new int[n][2001];
	for(int i=0; i<n;i++){
	    for(int j=0;j<=2000;j++){
		if(j==0){
		    num[i][j] = 1;
		}else{
		    num[i][j] = 0;
		}
	    }
	}
	num[0][A[0]] = 1;
	for(int i=1; i<n;i++){
	    for(int j=0;j<=2000;j++){
		for(int k=0;k<i;k++){
		    if(num[k][j]==1){
			if(j+A[i]>2000){
			    continue;
			}
			num[i][j+A[i]]=1;
		    }
		}
	    }
	}
	

	for(int i=0;i<q;i++){
	    int flag = 0;
	    for(int j=0;j<n;j++){
		if(num[j][m[i]]==1){
		    flag = 1;
		}
	    }
	    if(flag==1){
		System.out.println("yes");
	    }else{
		System.out.println("no");
	    }
	}
    }
}



Measured memory_bytes: 27388
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// #include<ext/pb_ds/tag_and_trait.hpp>
// using namespace __gnu_pbds;
using namespace std;
using ll=long long;
#define double long double
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
// using llset=tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define print(v) cout<<v<<endl
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define printYES cout<<"YES"<<endl
#define printNO cout<<"NO"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas x,ddatas y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

int main(){
  // startupcpp();
  // ll test;cin>>test;while(test--){
  ll i,j,N,H,W,ans;
  string s,t,u;
  cin>>s>>t;
  cin>>N>>H;
  cin>>u;
  print(N-(s==u));
  print(H-(t==u));
  return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vl dx={-1,-1,-1,0,0,1,1,1};
vl dy={1,-1,0,1,-1,1,0,-1};
int main(){
  string k;ll d;cin>>k>>d;
  ll dp[10010][2][110];
  //vector<vvl> dp(10010,vvl(2,vl(110)));
  dp[0][0][0]=1;
  ll n=k.size();
  rep(i,n){
    rep(j,d){
      rep(dig,10){
        dp[i+1][1][(j+dig)%d]+=dp[i][1][j];
        dp[i+1][1][(j+dig)%d]%=MOD;
      }
      rep(dig,k[i]-'0'){
        dp[i+1][1][(j+dig)%d]+=dp[i][0][j];
        dp[i+1][1][(j+dig)%d]%=MOD;
      }
      dp[i+1][0][(j+(k[i]-'0'))%d]+=dp[i][0][j];
      dp[i][0][j]%=MOD;

    }

  }
  //rep(i,n+1){
    //rep(j,d){
      //cout<<dp[i][1][j]<<" "<<dp[i][0][j]<<" ";
    //}
    //cout<<endl;
  //}
  cout<<(dp[n][0][0]+dp[n][1][0]-1+MOD)%MOD<<endl;

  
}

Measured memory_bytes: 17408
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
    #ifdef HOME
        freopen("input.txt", "r", stdin);
    #else 
        ios_base::sync_with_stdio(0);
        cin.tie(0);    
    #endif

    int n;
    cin >> n;
    int a, b;
    cin >> a >> b;
    vector <int> p(n);
    int c1 = 0, c2 = 0, c3 = 0;
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
        if (p[i] <= a) ++c1;
        else if (p[i] <= b) ++c2;
        else ++c3;
    }   
    cout << min(min(c1, c2), c3) << '\n';

    #ifdef HOME
        cerr << "TIME : " << (double)clock()/CLOCKS_PER_SEC<<'\n';
    #endif
}   

Measured memory_bytes: 256
<?php
list($h, $w) = ints();
for ($i = 0; $i < $h; ++$i) list($s[]) = strs();
for ($i = 0; $i < $h; ++$i) {
    for ($j = 0; $j < $w; ++$j) {
        if ($i < $h - 1 && $s[$i][$j] !== $s[$i + 1][$j]) {
            $g[$i][$j][] = [$i + 1, $j];
            $g[$i + 1][$j][] = [$i, $j];
        }
        if ($j < $w - 1 && $s[$i][$j] !== $s[$i][$j + 1]) {
            $g[$i][$j][] = [$i, $j + 1];
            $g[$i][$j + 1][] = [$i, $j];
        }
    }
}
$seen = array_fill(0, $h, array_fill(0, $w, false));
$ans = 0;
for ($i = 0; $i < $h; ++$i) {
    for ($j = 0; $j < $w; ++$j) {
        if (!$seen[$i][$j]) {
            list($cb, $cw) = dfs($i, $j);
            $ans += $cb * $cw;
        }
    }
}
echo $ans;
function dfs($i, $j)
{
    global $g, $seen, $s;
    $seen[$i][$j] = true;

    $res = $s[$i][$j] === '#' ? [1, 0] : [0, 1];
    if (is_null($g[$i][$j])) return $res;
    foreach ($g[$i][$j] as list($ni, $nj)) {
        if ($seen[$ni][$nj]) continue;
        list($cb, $cw) = dfs($ni, $nj);
        $res[0] += $cb;
        $res[1] += $cw;
    }
    return $res;
}

function strs()
{
    return explode(' ', trim(fgets(STDIN)));
}
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 428744
N = int(input())
H = list(map(int, input().split()))

flg = 1
for i in range(N-1):
    if H[i+1] - 1 >= H[i]:
        H[i+1] -= 1
    elif H[i+1] < H[i]:
        flg = 0
        break
if flg == 1:
    print('Yes')
elif flg == 0:
    print('No')

Measured memory_bytes: 20628
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    ll n;
    cin >> n;
    map<ll,ll>mp;
    vector<ll>index(1000000);
    if(n==1){
        cout << 0 << endl;
        return 0;
    }
    REP(i,1000000){
        index[i]=((ll)i+1)*((ll)i+2)/2;
    }
    SORT(index);
    
    
    FOR(i,2,(ll)ceil(sqrt(n))+1){
        while(n%i==0){
            n/=i;
            mp[i]++;
        }
    }
    if(n>1)mp[n]++;
    ll answer = 0;

    for(auto itr = mp.begin(); itr != mp.end(); ++itr) {
        auto Iter1 = lower_bound(ALL(index), itr->second+1);
        answer+=(Iter1-index.begin());
        //cerr << itr->first  <<" " <<  itr->second << endl;
        //cerr << Iter1-index.begin() << endl;
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 11244
#include <stdio.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define max(a, b) ((a) > (b) ? (a) : (b))

int main(void)
{
    int n, k, p[200001];
    double ans = 0;
    double e[200001] = {0}, tmp[2] = {0};
    scanf("%d%d", &n, &k);
    rep(i, n)
        scanf("%d", &p[i]);

    rep(i, n) for (int j = 1; j <= p[i]; j++)
        e[i] += (double)j / (double)p[i];

    rep(i, k)
        ans += e[i];

    tmp[0] = ans;
    rep(i, n - k)
    {
        tmp[1] = tmp[0] - e[i] + e[i + k];
        ans = max(ans, tmp[1]);
        tmp[0] = tmp[1];
    }

    printf("%.12f\n", ans);
    return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n;
  	cin >> n;
  	// array
  	int h[n];
  	for (int i = 0; i < n; i++)
      cin >> h[i];
  int res = 0;
  for (int i = 0; i < n-1; i++)
    res += max(0,h[i]-h[i+1]);
  res += h[n-1];
  cout << res <<'\n';

	return 0;
}

Measured memory_bytes: 256
/*** akshaykumar99 ***/
 
#include<bits/stdc++.h> 
using namespace std;
 
const long long MOD = 1e9+7;
const long double PI = acos(-1);
const long long N = 5e5+1;
 
typedef long long ll;
typedef long double ld;

void test_case()
{
	ll n, kk;
	cin >> n >> kk;
	vector<ll> p(n+1), c(n+1);
	for(int i = 1; i <= n; i++)
		cin >> p[i];
	for(int i = 1; i <= n; i++)
		cin >> c[i];

	vector<ll> res1[n+1];
	for(int i = 1; i <= n; i++)
	{
		vector<bool> done(n+1, 0);
		ll curr = i;
		while(!done[curr])
		{
			res1[i].push_back(c[p[curr]]);
			done[curr] = 1;
			curr = p[curr];
		}
	}
	ll ans[n+1];
	for(int i = 1; i <= n; i++)
		ans[i] = LLONG_MIN;
	for(int i = 1; i <= n; i++)
	{
		ll k = kk;
		vector<ll> v = res1[i];
		ll ans1 = 0, zz = 0, nn = v.size();
		for(int j = 0; j < min(k, nn); j++)
		{
			ans1 += v[j];
			ans[i] = max(ans[i], ans1);
			zz += v[j];
		}
		k -= min(nn, k);
		ll xx = (k - nn) / nn;
		xx = max(xx, 0ll);
		ans1 += zz * xx;
		ans[i] = max(ans[i], ans1);
		k -= xx * nn;
		for(int j = 0; j < min(k, nn); j++)
		{
			ans1 += v[j];
			ans[i] = max(ans[i], ans1);
		}
		k -= min(nn, k);
		for(int j = 0; j < min(k, nn); j++)
		{
			ans1 += v[j];
			ans[i] = max(ans[i], ans1);
		}
	}
	ll fans = LLONG_MIN;
	for(int i = 1; i <= n; i++)
	{
		fans = max(fans, ans[i]);
	}
	cout << fans << '\n';

}
 
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL); 
    ll tc=1;
    // cin>>tc;
    while(tc--)
        test_case();
    return 0;
}

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


 const int MAX = 1001;
const int MOD = 1000000007;



signed main(){
    int n,m;
    cin>>n>>m;
    int l[n],r[n],t,ok,ng,mid;
    int ans[m+1]={},ans2[m+1]={};
      for(int i=0;i<n;i++)cin>>l[i]>>r[i];
    for(int i=0;i<n;i++){
       // cin>>l>>r;
       ng=sqrt(r[i]);
        for(int j=1;j<=ng;j++){
             if(r[i]%j<=r[i]-l[i]){
                ans[j]++;
                 ok=r[i]/j;
                 //ng=r/(j+1);
                 if(ok>ng){
                 ans2[ok]--;
                 ans2[max(r[i]/(j+1),max((l[i]-1)/j,ng))]++;
             //   cerr<<l/j<<endl;
                //cerr<<ng<<endl;
                 }
            }
           
           
        }
    }
    t=0;
    for(int i=1;i<=m;i++){
        t+=ans2[i-1];
      //  cerr<<ans[i]<<' '<<t<<endl;
        cout<<ans[i]+t<<endl;

    }

    

   return 0;
}

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

using namespace std;

int main()
{
    long long n;

    cin >> n;

    string result = "";

    while(1)
    {
        n--;

        if(n < 0)
        {
            break;
        }

        int c = n % 26;
        n /= 26;

        result = ((char)(c + 'a')) + result;

        //cout << "   adding " << ((char)(c + 'a')) << " currently " << result << endl;
    }

    cout << result << endl;
}


Measured memory_bytes: 3608
import sys

def main():
    input = sys.stdin.readline
    S = input().strip()
    S = S.replace('BC', 'D')

    ans = 0
    cnt = 0
    for c in S:
        if c == 'A':
            cnt += 1
        elif c == 'D':
            ans += cnt
        else:
            cnt = 0

    return ans


if __name__ == '__main__':
    print(main())


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

int main(){
    vector<int> a(3);
    for (int i = 0; i < 3; i++) cin >> a.at(i);
    vector<bool> odd(3, 0);
    int oddcount = 0;
    int res = 0;

    for (int i = 0; i < 3; i++) {
        if (a.at(i) % 2 != 0) {
            oddcount++;
            odd.at(i) = 1;
        }
    }

    if (oddcount == 1) {
        for (int i = 0; i < 3; i++) {
            if (odd.at(i) == 0) a.at(i)++;
        }
        res++;
    }
    else if (oddcount == 2) {
        for (int i = 0; i < 3; i++) {
            if (odd.at(i) == 1) a.at(i)++;
        }
        res++;
    }
    sort(a.begin(),a.end());
    res += ((a.at(2) * 2 - a.at(0) - a.at(1)) / 2);
    cout << res << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(true){
int H = sc.nextInt();
int W = sc.nextInt();
if(H == 0 && W == 0){
break;
}
for(int i = 0; i<H; i++){
for(int j = 0; j<W; j++){
if(i%2 == 0){
if(j%2 == 0){
System.out.print("#");
}else{
System.out.print(".");
}
}else{
if(j%2 == 0){
System.out.print(".");
}else{
System.out.print("#");
}
}
}
System.out.println();
}
System.out.println();
}
sc.close();
}
}


Measured memory_bytes: 37900
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pi M_PI
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int n,m;
  cin >> n >> m;
  ll a[n];
  rep(i,n) R a[i];
  ll dp[5555][55],ans=0;
  mem(dp);
  dp[0][0]=1;
  rep(i,n)rrep(j,n+1)rrep(k,5555)if(k+a[i]<5555) dp[k+a[i]][j+1]+=dp[k][j];
  rep(i,5555)REP(j,1,n+1)if((double)i/j==m) ans+=dp[i][j];
  pr(ans);
}

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


Measured memory_bytes: 2688
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
using namespace std;
#define ll long long
#define INF 1000000007
using P=pair<int,int>;
int main(){
    
    int n;
    cin>>n;
    int a[20];
    for(int i=0;i<n;i++)cin>>a[i];
    int count=0;
    for(int i=0;i<n-2;i++){
        if(min({a[i],a[i+1],a[i+2]})!=a[i+1]&&max({a[i],a[i+1],a[i+2]})!=a[i+1])count++;
    }
    cout<<count<<endl;
    return 0;
}


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

int main() {
  int n,ans=0;
  cin>>n;
  vector<int> b(n-1);
  rep(i,n-1) {
    cin>>b[i];
  }
  rep(i,n){
    if(i==0){
      ans+=b[i];
      continue;
    }
    if(i==n-1){
      ans+=b[n-2];
      continue;
    }
    ans+=min(b[i-1],b[i]);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
import sys
from collections import deque

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

n, m = map(int, readline().split())
ab = map(int, read().split())

graph = [[] for _ in range(n+1)]
for a, b in zip(ab, ab):
    graph[a].append(b)
    graph[b].append(a)

ans = [0] * (n + 1)
visited = [0] * (n + 1)
root = 1
visited[root] = 1
q = deque([root])
while q:
    v = q.popleft()
    for w in graph[v]:
        if visited[w]:
            continue
        visited[w] = 1
        ans[w] = v
        q.append(w)
 
print('Yes')
print(*ans[2:], sep='\n')


Measured memory_bytes: 55968
#include<bits/stdc++.h>
using namespace std;
long long n,m;
int main()
{
	scanf("%lld%lld",&n,&m);
	if(2*n<=m)
	{
		printf("%lld\n",n+(m-2*n)/4);
	}else
	{
		printf("%lld\n",m/2);
	}
}

Measured memory_bytes: 3820
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;


public class D
{
	public static void Main()
	{
		string[] args;
		
		args = Console.ReadLine().Split(' ');
		int N = Int32.Parse(args[0]);
		int M = Int32.Parse(args[1]);
		int R = Int32.Parse(args[2]);

		int[] r = new int[R];
		args = Console.ReadLine().Split(' ');
		for(int i = 0; i < R; i++)
			r[i] = Int32.Parse(args[i]) - 1;  // 0-index

		int[,] d = new int[N,N];
		for(int i = 0; i < N; i++)
			for(int j = 0; j < N; j++)
				d[i,j] = (i == j) ? 0 : Int32.MaxValue/N;

		for(int i = 0; i < M; i++)
		{
			args = Console.ReadLine().Split(' ');
			int A = Int32.Parse(args[0]) - 1;  // 0-index
			int B = Int32.Parse(args[1]) - 1;  // 0-index
			int C = Int32.Parse(args[2]);
			d[A,B] = C;
			d[B,A] = C;
		}

		// Warshall-Floyd
		for(int k = 0; k < N; k++)
			for(int i = 0; i < N; i++)
				for(int j = 0; j < N; j++)
					d[i,j] = Math.Min(d[i,j], d[i,k] + d[k,j]);

		// brute force
		int ans = Int32.MaxValue;
		int[] perm = new int[R];
		for(int i = 0; i < R; i++)
			perm[i] = i;  // { 0, 1, 2, ..., R-1 }
		do
		{
			int tmp = 0;
			for(int i = 0; i <= R-2; i++)
				tmp += d[r[perm[i]], r[perm[i+1]]];
			ans = Math.Min(ans, tmp);
		} while (nextPermutation(ref perm));

		Console.WriteLine(ans);
	}

	private static bool nextPermutation(ref int[] array)
	{
		int len = array.Length;
		int i = len - 2;
		while((i >= 0) && (array[i] > array[i + 1]))
			i--;
		if(i < 0)
			return false;

		int pivot = array[i];
		int j = i + 1;
		while((j < len - 1) && (array[j + 1] > pivot))
			j++;
		
		int tmp = array[i];
		array[i] = array[j];
		array[j] = tmp;
		
		Array.Reverse(array, i + 1, len - i - 1);

		return true;
	}
}





Measured memory_bytes: 15272
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define PI 3.1415926535897932384626433832795
int MOD=1e9+7;
int powmod(int a,int l, int md){int res=1;while(l){if(l&1)res=res*a%md;l/=2;a=a*a%md;}return res;}
typedef long long ll; typedef vector<ll> vi; typedef pair<ll, ll> ii; typedef vector<ii> vii;
#define pb push_back
int __set(int b, int i) {return b|(1<<i);} //set ith bit
int __unset(int b, int i) {return b&!(1<<i);}
int __check(int b, int i) {return b&(1<<i);} //returns 0 if ith bit is 0
int mul(int a, int b) {return ((a%MOD)*(b%MOD))%MOD;}
int add(int a, int b) {return (a+b)%MOD;}
int sub(int a, int b) {return (((a-b)%MOD)+MOD)%MOD;}
int __div(int a, int b) {return mul(a, powmod(b, MOD-2, MOD));} //if MOD is prime;
const int inf = 0xFFFFFFFFFFFFFFFL; //very large number
priority_queue<int, vector<int>, greater<int> > pq; //for min priority_queue
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
clock_t time_p=clock();
void time()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}

int32_t main(void)
{
	IOS;
	int n, m; cin>>n>>m;
	vector<string> mat(n);
	for(int i = 0; i < n; i++) {
		cin>>mat[i];
	}
	int dp[n][m];
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < m; j++)
			dp[i][j]=0;
	}
	dp[0][0]=1;
	for(int i = 1; i < n; i++) {
		if(dp[i-1][0]!=inf && mat[i][0]=='.') {
			// cout<<i<<" "<<dp[i-1][0]<<" ";
			dp[i][0]=dp[i-1][0];
			// cout<<dp[i][0]<<endl;
		}
	}
	for(int j = 1; j < m; j++) {
		if(dp[0][j-1]!=inf && mat[0][j]=='.')
			dp[0][j]=dp[0][j-1];
	}
	for(int i = 1; i < n; i++) {
		for(int j = 1; j < m; j++) {
			if(mat[i][j]=='.') {
				// int mx1=dp[i-1][j], mx2=dp[i][j-1];
				// // if(i==1 && j==2)
				// // 	cout<<mx1<<" "<<mx2<<endl;
				// if(min(mx1, mx2) != inf)
				// 	dp[i][j]=min(mx1, mx2)+1;
				dp[i][j]=(dp[i][j-1]+dp[i-1][j])%MOD;
			}
		}
	}
	// for(int i = 0; i < n; i++) {
	// 	for(int j = 0; j < m; j++)
	// 		cout<<dp[i][j]<<" ";
	// 	cout<<endl;
	// }
	cout<<dp[n-1][m-1]<<endl;
	time();	
	return 0;
}

Measured memory_bytes: 9088
import math
o, b = map(int, input().split())
def pi(a):
    s= 0
    a+=1
    p = math.log2(a)
    p = int(p)
    qq=1
    q = 2
    ans =0
    t = 0
    t = a//2
    ans += t%2

    for i in range(1,p+1):
        qq = q

        q*=2
        t = a%(q)
        ans += qq*(max(0,t-qq)%2)
    return ans
print((pi(b)^pi(o))^o)


Measured memory_bytes: 3188
#include <iostream>
#include <vector>

using namespace std;

int main(){
    int N, X;
    while(cin >> N >> X){
        vector<int> x(N+1, 0);
        for(int i=1;i<=N;i++) cin >> x[i];
        vector<long long> sum(N+1, 0);
        for(int i=0;i<N;i++) sum[i+1] = sum[i] + x[i+1];
        long long res = (1LL << 60);
        for(int i=N;i>=1;i--){
            int rest = N;
            long long c = 2;
            long long cur = (long long)(N + i) * X;
            while(rest){
                long long b = max(0, rest - i);
                long long p = (c == 2 ? 5 : 2 * c - 1);
                cur += p * (sum[rest] - sum[b]);
                rest = b;
                ++c;
                if(cur > res) break;
            }
            res = min(res, cur);
        }
        cout << res << endl;
    }
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

const int MOD = 1000000007;

int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> jobs(M);

    rep(i, N) {
        int a, b;
        cin >> a >> b;
        if (a > M) continue;
        jobs[M - a].push_back(b);
    }

    priority_queue<int> q;
    ll ans = 0;
    for (int i = M - 1; i >= 0; i--) {
        for (int b : jobs[i]) {
            q.push(b);
        }

        if (!q.empty()) {
            ans += q.top();
            q.pop();
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 5504
#include <stdio.h>
#include <stdlib.h>
#define N 100

int main(){
  int i,j,m,node,num,n,arr[N+1][N+1];
  scanf("%d",&n);
  if(n<1 || n>100) exit(2);
  for(i=0;i<=n;i++){
    for(j=0;j<=n;j++){
      arr[i][j]=0;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d %d",&node,&num);
    for(j=0;j<num;j++){
      scanf("%d",&m);
      arr[node][m]=1;
    }
  }
  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      if(j>1)printf(" ");
      printf("%d",arr[i][j]);
    }
  printf("\n");
  }
  
  return 0;
}



Measured memory_bytes: 2132
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int a = sc.nextInt();
        sc.close();
        int ans = h%a==0 ? h/a : h/a+1;
        System.out.println(ans);
        
    }
}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
int a[] = {-1, 0, 1, 0};
int b[] = {0, 1, 0, -1};
int n, m;
int check(int x, int y){
    if (x>=0 && x<n && y>=0 && y<m)return 1;
    return 0;
}
int main(){
    // int n, m;
    cin>>n>>m;
    vector<string> v(n);
    for (int i=0; i<n; i++)cin>>v[i];
    int visited[n][m]; memset(visited, 0, sizeof(visited));
    int d[n][m]; memset(d, 0, sizeof(d));
    queue<pair<int, int> > q;
    for (int i=0; i<n; i++)for (int j=0; j<m; j++){
        if (v[i][j] == '#'){
            q.push({i, j});
            visited[i][j] = 1;
        }
    }
    while(!q.empty()){
        pair<int, int> z = q.front(); q.pop();
        int x = z.first, y = z.second;
        for (int i=0; i<4; i++){
            if (check(x+a[i], y+b[i]) && visited[x+a[i]][y+b[i]]==0){
                d[x+a[i]][y+b[i]] = d[x][y] + 1;
                visited[x+a[i]][y+b[i]] = 1;
                q.push({x+a[i], y+b[i]});
            }
        }
    }
    int mx = 0;
    for (int i=0; i<n; i++)for (int j=0; j<m; j++)mx = max(mx, d[i][j]);
    cout<<mx<<endl;
}

Measured memory_bytes: 21016
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long n,k,x1=0,x2=0;
	long long ans=0;
	cin>>n>>k;
	for(int i=1;i<=n;i++)
		if(i%k==0)
			x1++;
		else
			if((i*2)%k==0)
				x2++;
	cout<<x1*x1*x1+x2*x2*x2;//+3*x1*x1;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(int argc, char const *argv[]) {
  int h,w;
  cin>>h>>w;
  char a[h][w];
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>a[i][j];
    }
  }
  //横方向に探索
  for(int i=0;i<h;i++){
    if(a[i][0]=='.'&&a[i][w-1]=='.'){
      for(int j=1;j<w-1;j++){
        if(a[i][j]=='#')  break;
        if(j==w-2){
          for(int k=0;k<w;k++){
            a[i][k]='*';
          }
        }
      }
    }
  }

  //縦方向に探索
  for(int i=0;i<w;i++){
    if(a[0][i]!='#'&&a[h-1][i]!='#'){
      for(int j=1;j<h-1;j++){
        if(a[j][i]=='#')  break;
        if(j==h-2){
          for(int k=0;k<h;k++){
            a[k][i]='*';
          }
        }
      }
    }
  }

// //debug:一回全部表示させてみる
//   for(int i=0;i<h;i++){
//     for(int j=0;j<w;j++){
//       cout<<a[i][j];
//     }
//     cout<<endl;
//   }

  //0以外を出力
  bool flag=0;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(a[i][j]!='*'){
        cout<<a[i][j];
        flag=1;
      }
    }
    if(flag){
      cout<<endl;
      flag=0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        Main m = new Main(sc);
        m.show(m.solve());
        sc.close();
    }
    
	//フィールド
    Scanner sc;
    int N;
    int A;	//すぬけ
    int B;	//ふぬけ
    int C;
    int D;
    String S;
    
    //入力
    Main(Scanner sc) {
        this.sc = sc;
        this.N = sc.nextInt();
        this.A = sc.nextInt();
        this.B = sc.nextInt();
        this.C = sc.nextInt();
        this.D = sc.nextInt();
        this.S = sc.next();
    }
    
    //解答処理
    private String solve() {
        String answer = "Yes";
        
        if (S.charAt(C-1) == '#' || S.charAt(D-1) == '#') {
        	//マスCとマスDどちらかに岩があったらNo
        	answer = "No";
        	return answer;
        }
        
        if (C < D) {
        	String tmp = S.substring(A-1,D);
        	//2連続岩ならNo
        	if (tmp.contains("##")) {
        		answer = "No";
        		return answer;
        	}
        } else {
        	String tmp = S.substring(B-2,D+1);
        	//3連続空きが無ければNo
        	if (!tmp.contains("...")) {
        		answer = "No";
        	}
        }
        
        return answer;
    }
    
    //出力
    public void show(String answer) {
        System.out.println(answer);
    }

}


Measured memory_bytes: 40516