akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;

int sumOfEachDegit(int n){
  int sum = 0;
  while(n > 0){
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

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

  int N, A, B;
  cin >> N >> A >> B;
  
  int res = 0;
  for(int i = 1; i <= N; i++){
    int sum = sumOfEachDegit(i);
    if(sum >= A && sum <= B) res += i;
  }

  cout << res << endl;
}


Measured memory_bytes: 256
N, K = gets.chomp.split(" ").map(&:to_i)
x = []
y = []
N.times do
    xx,yy = gets.chomp.split(" ").map(&:to_i)
    x << xx
    y << yy
end

x_sort = x.sort
x_pos = {}
x_sort.each_with_index do |v,i|
    x_pos[v] = i
end

y_sort = y.sort
y_pos = {}
y_sort.each_with_index do |v,i|
    y_pos[v] = i
end

#p x_pos
#p y_pos

a = Array.new(x_pos.size+1,0).map { Array.new(y_pos.size+1,0)}

0.upto(N-1) do |i|
    a[x_pos[x[i]]+1][y_pos[y[i]]+1] = 1
end

0.upto(N) do |i|
    1.upto(N) do |j|
        a[i][j] = a[i][j-1] + a[i][j]
    end
end
0.upto(N) do |i|
    1.upto(N) do |j|
        a[j][i] = a[j-1][i] + a[j][i]
    end
end

ans = 10 ** 30
0.upto(N-2) do |i|
    (i+1).upto(N-1) do |j|
        0.upto(N-2) do |k|
            (k+1).upto(N-1) do |l|
                t = a[x_pos[x_sort[j]]+1][y_pos[y_sort[l]]+1] + a[x_pos[x_sort[i]]][y_pos[y_sort[k]]] - a[x_pos[x_sort[i]]][y_pos[y_sort[l]]+1] - a[x_pos[x_sort[j]]+1][y_pos[y_sort[k]]]
                if t >= K
                    s = (x_sort[j] - x_sort[i]) * (y_sort[l] - y_sort[k])
                    ans = s if s < ans
                end
            end
        end
    end
end
        

puts ans

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;


int main() {
    string S,T; cin >> S >> T;

    int s = S.size();
    int t = T.size();

    int ans = INF;
    REP(i,s-t+1){
        int cnt = 0;
        REP(j,t){
            if(S[i+j] != T[j]) cnt++;
        }

        ans = min(ans,cnt);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
n, m = input().split()

n = int(n)
m = int(m)

s = [0] * m
c = [0] * m

for i in range(m):
    s[i], c[i] = input().split()

found_data = True
s = [int(i) for i in s]
if n != 1:
    for i in range(10 ** n - 10 ** (n - 1)):
        found_data = True
        word = str(i + 10 ** (n - 1))
        for j in range(m):
            if word[s[j]-1] != c[j]:
                found_data = False
                break
        if(found_data):
            print(word)
            break
else:
    for i in range(10):
        found_data = True
        word = str(i)
        for j in range(m):
            if word[s[j]-1] != c[j]:
                found_data = False
                break
        if(found_data):
            print(word)
            break

if not (found_data):
    print("-1")


Measured memory_bytes: 38384
N = int(input())
h = list(map(int,input().split()))

memo = [0]*N
memo[0] = 0
memo[1] = abs(h[0]-h[1])

for i in range(2,N):
  a = memo[i-1] + abs(h[i]-h[i-1])
  b = memo[i-2] + abs(h[i]-h[i-2])
  memo[i] = min(a,b)
print(memo[N-1])

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

int main(){
    int N;
    cin >> N;
    int A[100000];
    int ans = 0;

    for (int i = 0; i < N; ++i) {
        cin >> A[i];
        if (A[i] % 2 == 1) ans++;
    }

    if (ans % 2 == 1) cout << "NO" << endl;
    else cout << "YES" << endl;

}

Measured memory_bytes: 640
import java.util.*;
 
class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		System.out.println(C>(A-B) ? C-(A-B) : 0);
	}
}

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

namespace AOJ0030
{
    class Program
    {
        static void Main()
        {
            foreach (var values in ReadInputs())
            {
                Console.WriteLine(Choose(values[0], values[1]).Count());
            }
        }

        public static IEnumerable<int[]> ReadInputs()
        {
            string line;
            while ((line = Console.ReadLine()) != null && line != "0 0")
            {
                yield return line.Split(' ').Select(int.Parse).ToArray();
            }
        }

        public static IEnumerable<int[]> Choose(int n, int s)
        {
            if (n < 0 || n >= 10) throw new ArgumentOutOfRangeException();

            return Choose(n, s, new List<int>());
        }

        private static IEnumerable<int[]> Choose(int n, int s, List<int> choosen)
        {
            if (n == 0)
            {
                if (choosen.Sum() == s)
                {
                    yield return choosen.ToArray();
                }

                yield break;
            }

            if (choosen.Sum() > s)
            {
                yield break;
            }

            // やりすぎじゃないかな
            foreach (var item in from number in Enumerable.Range(0, 10)
                                 where !choosen.Any() || number > choosen.Max()
                                 let newChoosen = new List<int>(choosen) {number}
                                 from result in Choose(n - 1, s, newChoosen)
                                 select result)
            {
                yield return item;
            }
        }
    }
}

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


#define f(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define char_f(i,a) for(int i=(int)(a);(char)s[i]!='\0';i++)
#define rf(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define llf(i,a,b) for(long long int i=(long long int)(a);i<=(long long int)(b);i++)
#define llrf(i,a,b) for(long long int i=(long long int)(a);i>=(long long int)(b);i--)



#define ll long long
#define fi first
#define se second
#define pb push_back
#define pop pop_back
#define mem(ara) memset((ara),0,sizeof(ara))
#define memn(ara) memset((ara),-1,sizeof(ara))
#define bb begin()
#define ee end()
#define em emplace
#define eb emplace_back





#define si set<int>
#define sd set<double>
#define sll set<long long int>
#define ss set<string>
#define sc set<char>

#define pii pair<int,int>
#define pli pair<long long int,int>
#define pil pair<int,long long int>
#define pll pair<long long int,long long int>
#define pci pair<char,int>
#define pic pair<int,char>
#define pcl pair<char,long long int>
#define plc pair<long long int,char>

#define pss pair<string,string>
#define pcc pair<char,char>

#define pis pair<int,string>
#define psi pair<string,int>
#define pls pair<long long int,string>
#define psl pair<string,long long int>
#define pdd pair<double,double>
#define pcs pair<char,string>
#define psc pair<string,char>



#define vi  vector<int>
#define vll vector<long long int>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vii vector<pii>



#define mod 1000000007
#define mx (1<<30)-1
#define llmx (1ll<<62)
#define n_size 100005
#define g_size 10000005
double PI=acos(-1);



///unsigned int uMAX=4294967295;
///unsigned ll int ullMAX=18446744073709551615;





int arr[g_size];



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

	ll int n,m,T,res,a,b;

	ll int maxi=-mx,mini=mx,count=0;

	ll int i,j,k;

	bool flag;

	string s1,s2;

	char s[100000];

	int ara[n_size],ara2[n_size];

	cin>>n>>k;

	pll p[n];
    cin>>a>>b;
    p[0].fi=a;
    p[0].se=b;
	f(i,1,n-1){
        cin>>a>>b;
        p[i].fi=a;
        p[i].se=b;
    }
    sort(p,p+n);
    f(i,0,n-1)
    {
        count+=p[i].se;
        if(k<=count){
            cout<<p[i].fi<<endl,exit(0);
        }
    }

}


Measured memory_bytes: 1792
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

ll nl, nm;

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

  int a, b;
  cin >> a >> b;
  cout << ( (a*b)%2 ? "Odd" : "Even" ) << endl;
  
  return 0;
}


Measured memory_bytes: 256
//
// Created by 伊東麻沙美 on 2019/10/22.
//

#include<iostream>
#include<algorithm>

using namespace std;


int main(){

    int A,B,C;
    cin>>A>>B>>C;

    if(B>=A){
        if((A*C)<=B){
            cout<<C;
        }else{
            cout<<B/A;
        }

    }
    if(B<A){
        cout<<0;
    }
    return 0;
}

Measured memory_bytes: 256
N = int(input())
TA = [list(map(int, input().split())) for i in range(N)]
T, A = 1, 1

for t, a in TA:
    z = max(T//t, A//a)
    if (T > t*z) or (A > a*z):
        z += 1

    T = t * z
    A = a * z

print(T+A)


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

int main(){
    string s;
    cin >> s;
    rep(i,3){
        if(s[i] == '1') cout << '9';
        else cout << '1';
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<queue>
using namespace std;
typedef pair<int,int> P;
int n;
int t[200][2];
int u[200][2];

P change(P p){
  while(t[p.first][p.second]==1
	&&t[p.first+1][p.second]==1)p.first++;
  while(t[p.first][p.second]==2)p.first--;
  return p;
}

void solve(){
  queue<P> Q;
  P a=P(0,0),b=P(0,1);
  a=change(a);
  b=change(b);
  u[a.first][a.second]=0;
  u[b.first][b.second]=0;
  Q.push(a);
  Q.push(b);
  while(!Q.empty()){
    P p=Q.front();Q.pop();
    p=change(p);
    if(p.first==n-1){cout<<u[p.first][p.second]<<endl;return;}
    for(int i=0;i<3;i++){
      P np=P(p.first+i,1-p.second);
      np=change(np);
      if(u[np.first][np.second]==-1&&np.first<=n){
	u[np.first][np.second]=u[p.first][p.second]+1;
	Q.push(np);
      }
    }
  }
  cout<<"NA"<<endl;
}

void init(){
  for(int j=0;j<2;j++){
    for(int i=0;i<200;i++){
      t[i][j]=0;
      u[i][j]=-1;
    }
  }
}

int main(){
  while(cin>>n&&n){
    init();
    for(int j=0;j<2;j++)
      for(int i=0;i<n;i++)
	cin>>t[i][j];
    solve();
  }
  return 0;
}

Measured memory_bytes: 1204
package main

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

func main() {
	scanner := makeScanner(1024)
	a := eGetInt(scanner)
	b := eGetInt(scanner)
	c := eGetInt(scanner)
	x := eGetInt(scanner)
	count := 0
	for i := 0; i <= a; i++ {
		for j := 0; j <= b; j++ {
			for k := 0; k <= c; k++ {
				sum := i*500 + j*100 + k*50
				if sum == x {
					count++
				}
			}
		}
	}
	fmt.Println(count)
}

////////////////////////////////////////////////////////////////////////////////
// ライブラリ
////////////////////////////////////////////////////////////////////////////////
func makeScanner(maxByte int) *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]uint8, 0, 8192), maxByte)
	return scanner
}
func makeWordScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanWords)
	return scanner
}
func eGetLine(r *bufio.Scanner) string {
	if r.Scan() {
		return r.Text()
	}
	err := r.Err()
	if err != nil {
		log.Fatal(err)
	}
	// EOF
	return ""
}

func eGetInt(r *bufio.Scanner) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetInt64(r *bufio.Scanner) int64 {
	line := eGetLine(r)
	return eAtoInt64(line)
}
func eGetFields(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Fields(line)
}
func eGetInts(r *bufio.Scanner) []int {
	fields := eGetFields(r)
	ints := make([]int, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoi(fields[i])
	}
	return ints
}
func eGetInt64s(r *bufio.Scanner) []int64 {
	fields := eGetFields(r)
	ints := make([]int64, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoInt64(fields[i])
	}
	return ints
}
func eGetChars(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Split(line, "")
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}
func eAtoInt64(s string) int64 {
	n, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		log.Fatal(err)
	}
	return n
}


Measured memory_bytes: 640
while gets
  n,m=$_.split.map(&:to_i)
  break if n==0 and m==0
  mem=(1..n).map{|i| i}
  idx=m-1
  while mem.size>1
    mem.delete_at(idx)
    idx=(idx+m-1)%mem.size
  end
  puts mem
end

Measured memory_bytes: 8636
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define fix(n) cout<<fixed<<setprecision(n)
#define co(n) cout<<n<<endl
#define all(n) (n).begin(),(n).end()
using namespace std;
typedef long long ll;
const ll mod=1000000007;
double pi=3.1415926535;

int main(){
  int n,cc;
  double c=0,ans=100000000;
  cin>>n;
  int a[n];
  rep(i,0,n){
    cin>>a[i];
    c+=a[i];
  }
  c/=n;
  rep(i,0,n){
    if(ans>abs(c-a[i])){
      cc=i;
      ans=abs(c-a[i]);
    }
  }
  co(cc);
  
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string str = Console.ReadLine();
		int N = int.Parse(str);
		int []A = new int[N];
		for(var i=0;i<N;i++){
			string str2 = Console.ReadLine();
			A[i] = int.Parse(str2);
		}
		Array.Sort(A);
		int count = 0;
		int ci = N-1;
		int nd = 1000;
		while(ci >= 0){
			if(A[ci] < nd){
				count += 1;
				nd = A[ci];
			}
			ci -= 1;
		}
		Console.WriteLine(count);
	}
}

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

int main(void){
    int a,b;
    cin>>a>>b;
    int dig=int(log10(b)+1);
    int num=a*pow(10,dig)+b;
    for(int i=1;i<=1000;i++){
        if(num==i*i){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3896
N = int(input())
S = input()
 
def z_algo(s):
    s_length = len(s)
    l, r = 0, 1
    Z = [0]*s_length
    Z[0] = s_length
    for i in range(1, s_length):
        if r<i:
            l, r = i, i
            while r<s_length and s[r]==s[r-l]:
                r += 1
            Z[i] = r-i
            r -= 1
        else:
            k = i-l
            if i+Z[k]-1<r:
                Z[i] = Z[k]
            else:
                l = i
                while r<s_length and s[r]==s[r-l]:
                    r += 1
                Z[i] = r-i
                r -= 1
    return Z

ans = 0
for i in range(N):
    z = z_algo(S[i:])
    for j in range(i, N):
        ans = max(ans, min(j-i, z[j-i]))
print(ans)

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

int cmp_str(const void *a,const void *b){
        char *a_char = (char *)a;
        char *b_char = (char *)b;
    return strcmp( a_char, b_char );
}

int main(void){
    int n;
    scanf("%d",&n);
    int i, j;
    int count = 1;
    char s[n][20];
    for(i=0;i<n;i++){
        scanf("%s",s[i]);
    }

    qsort(s, n, sizeof(s[0]), cmp_str);
    for(i=0;i<n-1;i++){
        if(strcmp(s[i],s[i+1]) != 0){
            count++;
        }
    }

/*    for(i=0;i<n;i++){
        printf("%s\n",s[i]);
    }
*/

    printf("%d\n",count);
    return 0; 
}


Measured memory_bytes: 9132
#include<bits/stdc++.h>
using namespace std ;
int main()
{
	int n , m ;
	cin >> n >> m ;
	if(n <= m)  for(int i = 1 ; i <= m ; i ++)  cout << n ;
	else  for(int i = 1 ; i <= n ; i ++)  cout << m ;
	return 0 ; 
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int i,j=0,k,tmp,ans=0;
  int N;
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d ",&tmp);
    if(i==0){
      k = tmp;
    }
    else{
      if(k >= tmp){
        j++;
        k=tmp;
      }
      else{
        j=0;
        k=tmp;
      }
      if(ans < j)
        ans=j;
    }
  }
  printf("%d\n",ans);
  return 0;
}

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

int n,m,k,l,a[101][101],d[101],t;
queue<int> q;

int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>l>>m;
        for(int j=0;j<m;j++){
            cin>>k;
            a[l][k]=1;
        }
        d[i+1]=-1;
    }
    d[1]=0;
    q.push(1);
    while(!q.empty()){
        t=q.front();
        q.pop();
        for(int i=1;i<=n;i++){
            if(a[t][i]){
                if(d[i]==-1){
                    d[i]=d[t]+1;
                    q.push(i);
                }
            }
        }
    }
    for(int i=1;i<=n;i++){cout<<i<<' '<<d[i]<<endl;}
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
  
int main() {
    int H,W;
    cin >> H >> W;
   vector<char> data(W);
   
   for (int i=0;i<W+2;i++){
       cout << '#';
   }
   cout <<  endl;
   
   for (int i=0;i<H;i++) {
       cout << '#';
       for (int j=0;j<W;j++) {
          cin >> data.at(j);
          cout << data.at(j);
       }
       cout << '#' << endl;
       
       
   }
   
   for (int i=0;i<W+2;i++){
       cout << '#';
   }
   cout << endl;
   }

 

Measured memory_bytes: 3632
//https://onlinejudge.u-aizu.ac.jp/challenges/sources/JOI/Prelim/0632?year=2017

#include <bits/stdc++.h>

using namespace std;

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

    char a[256][256];
    memset(a, '#', sizeof(a));

    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cin >> a[i][j];
        }
    }

    int ans = 0;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            bool yoko = true;
            for (int k = 0; k < d; ++k) {
                if (a[i][j + k] == '#') {
                    yoko = false;
                    break;
                }
            }
            if (yoko) ans++;

            bool tate = true;
            for (int k = 0; k < d; ++k) {
                if (a[i + k][j] == '#') {
                    tate = false;
                    break;
                }
            }
            if (tate) ans++;
        }
    }

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

/*
 * (i,j)を起点として縦横にd-1マス伸ばせるかどうか調べる。
 * サイズが小さいので判定はゆるめ。
 * 
 */


Measured memory_bytes: 3132
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n,a[400],cnt[400];
int main(){
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<n;i++){
		while(a[i]%2==0){
			a[i]/=2;
			cnt[i]++;
		}
	}
	sort(cnt,cnt+n);
	cout<<cnt[0]<<endl;
	return 0;
}

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

int main() {
  int N,i;
  cin>>N;
  int count=N;
  vector<int> vec(N);
  for(i=0;i<N;i++)cin>>vec[i];
  sort(vec.begin(), vec.end());
  for(i=0;i<N-1;i++){
    if(vec[i]-vec[i+1]==0)count--;
  }
  cout<<count<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

fun main (args: Array<String>) {
  val input = Scanner(System.`in`)
  
  while (input.hasNext()) {
    val lastDigit = input.nextInt() % 10;
    
    when (lastDigit) {
      2, 4, 5, 7, 9 -> println("hon")
      0, 1, 6, 8 -> println("pon")
      3-> println("bon")
      else -> {}
    }
  }
}

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

class Program
{
    static void Main(string[] args)
    {
        var N = int.Parse(Console.ReadLine());
        var inputs = Console.ReadLine().Split(' ');
        var h = new int[N];
        for (int i = 0; i < N; i++)
        {
            h[i] = int.Parse(inputs[i]);
        }

        int count = 0;
        while (true)
        {
            bool started = false;
            int minusCount = 0;
            for (int i = 0; i < N; i++)
            {
                if (h[i] > 0)
                {
                    h[i]--;
                    minusCount++;
                    started = true;
                }
                else if (started)
                {
                    break;
                }
            }

            if (minusCount == 0)
            {
                break;
            }
            count++;
        }

        Console.WriteLine(count);
    }

}



Measured memory_bytes: 13140
// AOJ 1621: Folding a Ribbon
// 2017.12.30 bal4u@uu

#include <stdio.h>
#include <string.h>

char ans[62];
char low[62];

int main()
{
	int n, k;
	long long i, j;

	while (scanf("%d%lld%lld", &n, &i, &j) && n > 0) {
		i--, j--;
		for (k = 1; k <= n; k++) {
			low[n-k] = (i >> (n-k)) & 1;
			if (!low[n-k]) i = ~i;
		}
		for (k = 1; k <= n; k++) {
			ans[k] = (((j >> (n-k)) & 1) == low[k-1])? 'L': 'R';
			if (!low[k-1]) j = ~j;
		}
		ans[n+1] = 0;
		puts(ans+1);
	}
	return 0;
}

Measured memory_bytes: 1808
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pi> vpi;
typedef vector<vi> vii;
typedef map<int, int> mp;
typedef multiset<int> mset;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
typedef vector<int64> vi64;
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define form(i,j,k,l) for(int i=j;i<int(k);i+=l)
#define rform(i,j,k,l) for(int i=int(j);i>int(l);i-=l)
#define rep(i, j) for(int i=0;i<int(j);i++)
#define rrep(i, j) for(int i=int(j);i>=0;i--)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define forc(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define INF (int)1e9
#define INF64 (int64)1e18
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
#define F first
#define S  second
const double pie = acos(-1.0);
template <typename T>
T Max(T x, T y)
{
  return (x > y) ? x : y;
}
template <typename T>
T Min(T x, T y)
{
  return (x > y) ? y : x;
}
int gcd(int n1, int n2)
{
  if (n2 != 0) return gcd(n2, n1 % n2);
  else return n1;
}
#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#else
#define trace(...)
#endif
clock_t time_p = clock();
void rtime() { time_p = clock() - time_p; cerr << "Time Taken : " << (float)1000 * (time_p) / CLOCKS_PER_SEC << "\n";}
int main()
{ fast;
 int n;
  cin >> n;
  int64 arr[n];
  rep(i, n)
  cin >> arr[i];
  int64 ans = 0;
  for (int i = 1; i < n; i++)
  { if (arr[i] < arr[i - 1])
    { ans = ans + (arr[i - 1] - arr[i]);
      arr[i] = arr[i - 1];
    }
  }
  cout << ans;
}

Measured memory_bytes: 5180
// inputに入力データ全体が入る
function Main(input) {
	var ans = 0
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.trim().split("\n")
	// var arr = input.trim().split("\n")
	// var n = input[0].split(' ').map(n => parseInt(n))
	var i = parseInt(input)
	ans = i + (i * i ) + (i * i * i)

	//出力
	console.log(ans)
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//Main(require('fs').readFileSync('./input.txt', 'utf-8'));

Measured memory_bytes: 29688
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;

int main(){
    ll n,m; cin >> n >> m;
    ll ans = 0;
    ans += min(n, m / 2);
    m -= ans * 2;
    ans += m / 4;
    cout << ans << endl;
}

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

int main() {
  int N,a,b;
  a=0;
  b=0;
  cin >> N;
  vector<int> vec(N);
  for (int i; i<N; i++){
   cin >> vec.at(i); 
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  for(int i=0;i<N;i=i+2){
   a=a+vec.at(i);
  }
  for(int i=1;i<N;i=i+2){
    b=b+vec.at(i);
  }
  cout << a-b << endl;
}
    


Measured memory_bytes: 256
#include <iostream>
const int MAXN = 200000, MAXA = 1000000, lnMAXA = 10, MOD = 998244353;
int Prime[MAXA/lnMAXA + 5], size;
//Prime[i]表示第i个质数，size表示筛到现在质数的数量 
bool not_prime[MAXA + 5];
//not_prime[i]为true表示i不是质数，为false则是质数 
int mu[MAXA + 5];
//mu[i]即第i个莫比乌斯函数 
int f[MAXA + 5], h[MAXA + 5], sum, m;
//f[i], h[i]如柿子所述 
int n;

inline int minus_to_mod(int n)
{ return n >= MOD ? n - MOD : n; }

inline int plus_to_mod(int n)
{ return n < 0 ? n + MOD : n; }

//这个函数用来避免不能整除2或res-sum<0的情况 
inline int change(int n) {
	int t = plus_to_mod(n);
	return (t & 1) ? t + MOD : t;
}

//读入 
void input() {
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(0), std::cout.tie(0);
	//cin, cout优化 
	std::cin >> n;
	for(int i = 1; i <= n; ++i) {
		int a;
		std::cin >> a;
		++h[a]; //更新h[a] 
		sum = minus_to_mod(sum + a); //由于a<=1e6，所以最多做一次减法 
		if(m < a) m = a; //更新最大值 
	}
}

//筛 
void sieve() {
	//筛mu 
	not_prime[1] = true;
	mu[1] = 1; 
	for(int i = 2; i <= m; ++i) {
		if(not_prime[i] == false) { //不是质数 
			Prime[size++] = i; //加入质数表 
			mu[i] = MOD - 1; //mu[i]=-1, mod MOD意义下为MOD-1 
		}
		for(int j = 0; j < size && i*Prime[j] <= m; ++j) {
			not_prime[i*Prime[j]] = true;
			if(i%Prime[j] == 0) break;
			mu[i*Prime[j]] = MOD - mu[i];
			//mu[i*Prime[j]]=-mu[i], mod MOD意义下为MOD-mu[i] 
		}
	}
	//筛f 
	for(int i = 1; i <= m; ++i)
		for(int j = 1; i*j <= m; ++j)
			f[i] = (1LL*f[i] + 1LL*h[i*j]*j)%MOD; //别忘了乘1LL 
}

long long solve() {
	//直接算答案 
	int res = 0;
	for(int i = 1; i <= m; ++i)
		for(int j = 1, k = i; k <= m; ++j, k += i)
			res = minus_to_mod(res + 1LL*mu[j]*f[k]%MOD*f[k]%MOD*k%MOD*j%MOD); //疯狂取余 
	return change(res - sum) >> 1;
}

int main() {
	input();
	sieve();
	std::cout << solve() << "\n";
	return 0;
}

Measured memory_bytes: 13312
#include<bits/stdc++.h>
#define ll long long 
#define hell 1000000007
#define F first
#define re 15000000
#define S second
#define pb push_back
#define all(a)  (a).begin(),(a).end()
#define rep(i,a,b) for(ll int i = a;i<b;i++)
#define pi 3.1415926536
#define Mod 998244353
//char a[2000][2000];
using namespace std;
bool check(ll m,ll k,ll n,ll a ,ll b){
  ll rem = n-m;
  if( k > rem*b + a*m)
      return 1;
  else
    return 0;

}
int main()
{   
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);            
    //std::setprecision(20);    
    int tests=1;
      //freopen("input.txt", "r", stdin);   
    //cin>>tests;
  while(tests--)
    { 
      int n;
      cin>>n;
      ll a[n];
      for(int i = 0;i<n;i++)
         cin>>a[i];
      int cnt = 0;
      for(int i = 1;i<n-1;i++){
        vector<int>temp;
        temp.pb(a[i-1]);
        temp.pb(a[i]);
        temp.pb(a[i+1]);

        sort(all(temp));
        if(temp[1] == a[i])
          cnt++;
      }
      cout<<cnt;
    }
    
}

Measured memory_bytes: 256
#include<cstdio>                                         
#include<cctype>
#include<stdio.h>                                  
using namespace std;
                                                  
int main(){
  char ch;                                                                                   
  while(1){
  scanf("%c",&ch);
    if(islower(ch)){
      printf("%c",toupper(ch));
    } else {
      printf("%c",tolower(ch));
    }                                 
    if(ch == '\n') break;
  }
}


Measured memory_bytes: 2532
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define SQ(x) ((x)*(x))
#define Mod(x, mod) (((x)+(mod)%(mod))
#define MP make_pair
#define PB push_back
#define Fi first
#define Se second
#define INF (1<<29)
#define EPS 1e-10
#define MOD 1000000007

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int H, W, N;
int seq[200005];
int ret[200005];
vector<pi>ab;

int value(int h, int w){
  h %= 2*W;
  while(h){
    //    cout << h << " " << w << endl;
    if((h+w)&1){
      if(h > (W-1)-w){
	h -= (W-1)-w + 1;
	w = (W-1);
      }else{
	w += h;
	h = 0;
      }
    }else{
      if(h > w){
	h -= w + 1;
	w = 0;
      }else{
	w -= h;
	h = 0;
      }
    }
  }
  return w;
}

int main()
{
  cin >> H >> W >> N;
  for(int i=0;i<W;i++) seq[i] = i;
  rep(i, N){
    int a, b; cin >> a >> b;
    ab.push_back(pi(a,b));
  }
  sort(ab.begin(), ab.end());
  rep(i,N){
    int a = ab[i].first, b = ab[i].second;
    int h= a-1, l = b-1, r = b;
    //    cout << a << " " << b << " ";
    //    cout  << value(h, l) << " " << value(h, r) << endl;
    swap(seq[value(h, l)] , seq[value(h, r)]);
  }

  //  rep(i, W){ cout << seq[i] << " "; } cout << endl;
  //  rep(i, W){ cout << value(H, i)  << " "; } cout << endl;  
  rep(i, W){
    //     cout << seq[value(H, i)] << " ";
    ret[seq[value(H, i)]] = i+1;
  }//cout << endl;
  rep(i, W) cout << ret[i] << endl;
  return 0;
}

Measured memory_bytes: 5960
a1 = list(input().split())
a2 = list(input().split())
a3 = list(input().split())
n = int(input())
b = [input() for _ in range(n)]
x = []
x.append(a1)
x.append(a2)
x.append(a3)
y = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
for i in range(3):
    for j in range(3):
        for k in range(n):
            if x[i][j] == b[k]:
                y[i][j] = 1
if y[0] == [1, 1, 1] or y[1] == [1, 1, 1] or y[2] == [1, 1, 1]:
    print('Yes')
elif y[0][0] == 1 and y[1][0] == 1 and y[2][0] == 1:
    print('Yes')
elif y[0][1] == 1 and y[1][1] == 1 and y[2][1] == 1:
    print('Yes')
elif y[0][2] == 1 and y[1][2] == 1 and y[2][2] == 1:
    print('Yes')
elif y[0][0] == 1 and y[1][1] == 1 and y[2][2] == 1:
    print('Yes')
elif y[0][2] == 1 and y[1][1] == 1 and y[2][0] == 1:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3188
#こうけ？
def 解():
    import sys
    input = sys.stdin.readline
    N,Q = [int(_) for _ in input().split()]
    S = " " + input() + " "
    aC = [[ _.rstrip() for _ in  _.split()] for _ in sys.stdin.readlines()]
    iL = 0
    iR = N+1
    for t,d in aC[::-1]:
        if t == S[iL+1] and d == "L" and iL < N+1:
                iL += 1
        elif t == S[iL] and d == "R" and 0 < iL:
                iL -= 1

        if t == S[iR-1] and d == "R" and 0 < iR:
                iR -= 1
        elif t == S[iR] and d == "L" and  iR < N+1:
                iR += 1
    if iL < iR:
        print(iR-iL-1)
    else:
        print(0)
解()


Measured memory_bytes: 39504
#include<stdio.h>
#include<string.h>
#define MAX 20000

typedef struct Data{
  int area, pos;
} Data;

Data t[MAX];
int u[MAX];
int n,i;
char str[MAX+1];
int T,U;
int ans,A;
Data B,X;

void D_push(Data d){
  t[T++] = d;
}

Data D_pop(){
  return t[--T];
}

void push(int a){
  u[U++] = a;
}

int pop(){
  return u[--U];
}

void init(){
  ans = T = U = 0;
}

Data makeData(int a, int b){
  Data res;
  res.area = a;
  res.pos = b;
  return res;
}

int main(){
  init();
  scanf("%s", str);
  n = strlen(str);

  for( i = 0 ; i < n ; i++){

    if(str[i] == '/'){

      if( U == 0 ) continue;
      A = pop();
      X = makeData( i-A, A);
      ans += i - A;
      while( T > 0 ){
        B = D_pop();
        if( B.pos < A ){
          D_push(B);
          break;
        }
        X.area += B.area;
        if(B.pos<X.pos) X.pos = B.pos;
      }
      D_push(X);
    }else if( str[i] == '\\' ){
      push(i);
    }

  }

  printf("%d\n%d", ans, T);
  for( i = 0 ; i < T ; i++ ){
    printf(" %d", t[i].area);
  }
  printf("\n");

  return 0;
}



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

using namespace std;

int main()
{
    long long n;
    cin >> n;
    map<long long, int> m;
    while(n%2==0)
    {
       m[2]++;
       n/=2;
    }
    for(long long i = 3; i*i <= n; i+=2)
    {
       while(n%i==0)
       {
          m[i]++;
          n/=i;
       }
    }
    if(n>2)
      m[n]++;
   int cnt = 0;
    for(auto it = m.begin(); it!= m.end(); it++)
    {
       int j;
       for(j =1; j < 100; j++)
       {
          if(j*(j+1)/2 > it->second)
            break;
       }
       cnt = cnt + j - 1;

    }
   cout << cnt;
   return 0;
}


Measured memory_bytes: 3632
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

vector<ll> a;

ll cul(ll x){
    ll L=1;
    ll cnt=0;
    set<ll> S;
    ll r=0;
    ll m=0;
    while(1){
        while(r<a.size() && L+x>a[r]){r++;}
        if(r==a.size()){return cnt+1;}
        if(r==0){return -1;}
        while(m<r && a[m]<L){m++;}
        ll dif=E;
        if(m!=0){dif=L-a[m-1];}
        if(m<r && a[m]<L+x){dif=min(dif,a[m]-L);}
        dif=max(1LL,x-dif);
        cnt++;
        L+=dif;
    }
}



int main(){
    ll n,m;
    while(cin>>n>>m){
        if(n==0){break;}
        a.resize(n);
        for(auto &I:a){cin>>I;}
        ll l=0,r=E;
        while(r-l>3){
            ll mid=l+(r-l)/2;
            ll ret=cul(mid);
            if(ret>=m || ret==-1){l=mid;}
            else{r=mid;}
        }
        for(ll i=r;i>=l;i--){
            if(cul(i)>=m){cout<<i<<endl; break;}
            if(i==l){cout<<-1<<endl;}
        }
    }
    
    return 0;
}



Measured memory_bytes: 4204
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        // sunny cloudy rainy
        Scanner scanner = new Scanner(System.in);
        String current = scanner.nextLine();
        scanner.close();

        String ans = current.equals("Sunny") ? "Cloudy" : current.equals("Cloudy") ? "Rainy" : "Sunny";
        System.out.println(ans);
    }
}

Measured memory_bytes: 19924
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

int n;
int xs[100];
int ys[100];
int rs[100];
int cs[100];

int square(int x) { return x * x; }
bool In(int i, int j) {
  double d2 = square(xs[i] - xs[j]) + square(ys[i] - ys[j]);
  double r2 = square(rs[i] + rs[j]);
  if (d2 < r2) { return true; }
  return false;
}

char memo[1 << 24];
int calc(int used) {
  if (memo[used] != -1) { return memo[used]; }
  int ret = __builtin_popcount(used);
  REP(i, n) {
    if ((used >> i) & 1) { continue; }
    REP(k, i) {
      if ((used >> k) & 1) { continue; }
      if (In(k, i)) { goto next; }
    }
    REP(j, i) {
      if ((used >> j) & 1) { continue; }
      if (cs[i] != cs[j]) { continue; }
      REP(k, j) {
        if ((used >> k) & 1) { continue; }
        if (In(k, j)) { goto next; }
      }
      ret = max(ret, calc(used | (1 << i) | (1 << j)));
    }
next:;
  }
  return memo[used] = ret;
}

int main() {
  while (scanf("%d", &n), n) {
    MEMSET(memo, -1);
    REP(i, n) {
      scanf("%d %d %d %d", &xs[i], &ys[i], &rs[i], &cs[i]);
    }
    cout << calc(0) << endl;
  }
}

Measured memory_bytes: 16000
from collections import defaultdict, deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys
import random
import itertools
import math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt


def LI(): return list(map(int, input().split()))


def LF(): return list(map(float, input().split()))


def LI_(): return list(map(lambda x: int(x)-1, input().split()))


def II(): return int(input())


def IF(): return float(input())


def LS(): return list(map(list, input().split()))


def S(): return list(input().rstrip())


def IR(n): return [II() for _ in range(n)]


def LIR(n): return [LI() for _ in range(n)]


def FR(n): return [IF() for _ in range(n)]


def LFR(n): return [LI() for _ in range(n)]


def LIR_(n): return [LI_() for _ in range(n)]


def SR(n): return [S() for _ in range(n)]


def LSR(n): return [LS() for _ in range(n)]


def gcd(x, y):
    if y == 0:
        return x
    return gcd(y, x % y)


def my_index_multi(l, x):
    return [i for i, _x in enumerate(l) if _x == x]


def sosu(x):
    for i in range(2, int(sqrt(x)+1)):
        if x % i == 0:
            return False
    return True


mod = 1000000007
inf = float('INF')


def A():
    r = II()

    print(r*r)
    return

# B


def B():
    N = II()
    S = input()
    if len(S) % 2 == 0:
        print('No')
        return
    j=S[N//2]
    p=N//2
    for i in S[:N//2]:
        if i != j:
            print('No')
            return
        p+=1
        j=S[p]

    print('Yes')

    return

# C


def C():
    N = II()
    A = LI()
    B = LI()

    L = []
    count = 0
    for i in range(2, int(sqrt(N)+2)):
        if N % i == 0:
            L.append(N/i)
            count = 1
    if count == 0:
        print(N-1)
    else:
        print(int(L[-1]-2+(N/L[-1])))

    return

# D


def D():

    a, b, x = LI()
    BIG = a*a*b/2
    if x > BIG:
        y = 2*b-(2*x/a/a)
        print(math.degrees(math.atan(y/a)))
    else:
        y = 2*x/a/b
        print(math.degrees(math.atan(b/y)))
    return

# E


def E():
    N, K = LI()
    A = LI()
    F = LI()
    A.sort(reverse=True)
    F.sort()
    cost = []
    for i in range(len(N)):
        cost.append(A[i]*F[i])

    a = F[cost.index(max(cost))]

    return

# F


def F():
    N, M = LI()

    value = [0] * M
    power = [0] * M
    for i in range(M):
        a, b = LI()
        value[i] = a
        c = LI()
        L = ['0'] * N
        for k in c:
            L[k - 1] = '1'
        bint = ''.join(L)
        power[i] = int(bint, 2)
    bint = ''.join(list(['1'] * N))
    dp = [inf] * (int(bint, 2)+1)
    t = 0
    cost = 0

    dp[0] = 0
    for s in range(int(bint, 2) + 1):
        for i in range(M):
            t = s | power[i]
            cost = dp[s] + value[i]
            dp[t] = min(dp[t], cost)
    print(-1) if(dp[-1] == inf) else print(dp[-1])

    return

    # you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")


def solution(S):
    # write your code in Python 3.6
    N = len(S)

    pass


# Solve
if __name__ == '__main__':
    B()


Measured memory_bytes: 41584
#include <iostream>
#include <string>
using namespace std;
int main(void){
    // Here your code !
    int N;
    cin >> N;

    int B_all = 1;
    int B_kisuu = 1;
    int A;
    for(int i = 0; i < N; i++){
        cin >> A;
        B_all *= 3;
        B_kisuu = A % 2 == 0 ? B_kisuu * 2 : B_kisuu;
    }
    
    cout << B_all - B_kisuu << "\n";
}


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

if a > b:
    print(0)
    exit()
    
if n == 0:
    print(0)
    eixt()
    
if n == 1:
    if a == b:
        print(1)
        exit()
    else:
        print(0)
        exit()
        
n_s = n - 2
s = b-a

ans = (b-a)*n_s + 1

print(ans)



Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cmath>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
#define mp  std::make_pair
#define ll long long int
#define abs(n) ((n>0)?(n):((n)*(-1)))
#define CEIL(a,b) (((a) + ((b)-1)) / (b))
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
#define VREP_ll(v) for(std::vector<ll>::iterator itr = (v).begin(); itr != (v).end();itr++)
#define VREP_int(v) for(std::vector<int>::iterator itr = (v).begin(); itr != (v).end();itr++)
#define VALL(v) ((v).begin(),(v).end())
#define errln(v) cerr << (v) << endl;
#define println(v) cout << (v) << endl;


ll gcd(ll a,ll b){
  if(a < b) gcd(b, a);
  if(b==0) return (ll)0;
  ll r;
  while ((r=a%b)) {
	a = b;
	b = r;
  }
  return b;
}

ll lcm(ll a,ll b){
	return a*b/gcd(a,b);
}


int main(int argc, const char * argv[]) {
	int n;
	ll m,buf;
	cin >> n >> m;
	set<ll> s;
	REP(i,n){
		cin >> buf;
		s.insert(buf/2);
	}
//	for (auto itr = s.begin(); itr != s.end(); ++itr) {errln(*itr);}
	vector<ll> a(s.rbegin(),s.rend());
	n = a.size();
//	REP(i,n) cerr << a[i] << " ";

	ll l = a[0];
	FOR(i,1,n-1) l = lcm(l,a[i]);
	REP(i,n){
		if((l/a[i])%2==0){
			println(0);
			return 0;
		}
	}
	ll ans = ((m/l)+1)/2;
	println(ans);


	return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
long long gcd(long a,long b)
{
	if(b==0) return a;
	return gcd(b,a%b);
}
long long lcm(long long a,long long b)
{

	return a/gcd(a,b)*b;
}
int main()
{
	int n,i;
	long long t[200],L;
	while(~scanf("%d",&n))
	{
		for (i=0;i<n;i++)
		{
			scanf("%lld",&t[i]);
		}
		L=t[0];
		for (i=1;i<n;i++)
		{
		    if (t[i]%L==0)
		    {
		    	L=t[i];
			}
			else
			{
				L=lcm(L,t[i]);
			}
		}
		printf("%lld\n",L);
	}
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include <map>
using namespace std;
long long int gcd(long long int a,long long int b)
{
if(a==0)
return b;
if(b==0)
return a;
return gcd(b,a%b);
}
long long int lcm(long long int a,long long int b)
{
return (long long)a/gcd(a,b)*b;
}
int main()
{
int a,b;
cin>>a>>b;
cout<<(long long)lcm(a,b);
}


Measured memory_bytes: 3112
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)
typedef long long ll;
static const ll MOD = 1e9 + 7;
static const ll INF = (ll)1 << 62;

static const int MAX = 100001;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
vector<pair<int, int>> adj[MAX];

ll pre[MAX];
ll p[MAX];
ll d[MAX];
ll color[MAX];
priority_queue<pair<int, int>>PQ;
ll n;
void dijkstra(int s) {
	rep(i, 0, n) {
		d[i] = INF;
		pre[i] = INF;
		color[i] = WHITE;
	}

	d[s] = 0;
	p[s] = -1;
	PQ.push(make_pair(s, s)); // ?reverse?
	color[s] = GRAY;

	while (!PQ.empty()) {
		pair<ll, ll> f = PQ.top(); PQ.pop();
		ll u = f.second;

		color[u] = BLACK;

		if (d[u] < f.first * (-1)) continue;

		rep(j, 0, adj[u].size()) {
			ll v = adj[u][j].first;
			if (color[v] == BLACK) continue;
			if (d[v] > d[u] + adj[u][j].second) {
				d[v] = d[u] + adj[u][j].second;
				PQ.push(make_pair(d[v] * (-1), v));
				p[v] = u;
				color[v] = GRAY;
			}
		}
	}
	//rep(i, 0, n) cout << i << " " << (d[i] == INF ? -1 : d[i]) << endl;
	//rep(i, 0, n) cout << i << " " << (p[i] == INF ? -1 : p[i]) << endl;
}

vector<ll> get_path(int t) {
	vector<ll> path;
	for (; t != -1; t = p[t])path.push_back(t);
	reverse(path.begin(), path.end());
	return path;
}

int main()
{
	cin >> n;
	rep(i, 0, n) {
		adj[i].push_back(make_pair((i + 1) % n, 1));
		adj[i].push_back(make_pair((i * 10) % n, 0));
	}

	dijkstra(1);

	cout << d[0] + 1 << endl;
	return 0;
}


Measured memory_bytes: 9468
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    map<pair<string, string>, int> cnt;
    for (int i = 0; i < (1 << n); ++i) {
        string red  = "";
        string blue = "";
        for (int j = 0; j < n; ++j) {
            if (1 << j & i) {
                red += s[j];
            } else {
                blue += s[j];
            }
        }
        reverse(blue.begin(), blue.end());
        cnt[make_pair(red, blue)]++;
    }
    ll ret = 0;
    for (int i = 0; i < (1 << n); ++i) {
        string red  = "";
        string blue = "";
        for (int j = 0; j < n; ++j) {
            if (1 << j & i) {
                red += s[j + n];
            } else {
                blue += s[j + n];
            }
        }
        reverse(red.begin(), red.end());
        ret += cnt[make_pair(red, blue)];
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 87040
h,w=map(int,input().split())
grid=[None]*h
for i in range(h):
  grid[i]=input()
  
L=[[0 for i in range(w)] for j in range(h)]
R=[[0 for i in range(w)] for j in range(h)]
U=[[0 for i in range(w)] for j in range(h)]
D=[[0 for i in range(w)] for j in range(h)]

for i in range(h):
  if grid[i][0]=="#":
    L[i][0]=0
  else:
    L[i][0]=1
  for l in range(1,w):
    if grid[i][l]=="#":
      L[i][l]=0
    else:
      L[i][l]=L[i][l-1]+1
      
  if grid[i][-1]=="#":
    R[i][-1]=0
  else:
    R[i][-1]=1
  for r in range(w-2,-1,-1):
    if grid[i][r]=="#":
      R[i][r]=0
    else:
      R[i][r]=R[i][r+1]+1
      
for j in range(w):
  if grid[0][j]=="#":
    U[0][j]=0
  else:
    U[0][j]=1
  for u in range(1,h):
    if grid[u][j]=="#":
      U[u][j]=0
    else:
      U[u][j]=U[u-1][j]+1
      
  if grid[-1][j]=="#":
    D[-1][j]=0
  else:
    D[-1][j]=1
  for d in range(h-2,-1,-1):
    if grid[d][j]=="#":
      D[d][j]=0
    else:
      D[d][j]=D[d+1][j]+1
      
ans=0
for i in range(h):
  for j in range(w):
    ans=max(ans,L[i][j]+R[i][j]+U[i][j]+D[i][j])

print(ans-3)


Measured memory_bytes: 185604
<?php
fscanf(STDIN, "%d", $N);
$lineInput = trim(fgets(STDIN));
$A = explode(" ", $lineInput);
$arr = array_count_values($A);
for($i=1; $i<=$N; $i++){
    if(array_key_exists($i,$arr)){
      echo($arr[$i]."\n");
    }else{
      echo("0"."\n");
    }
}

?>

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

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

    // solution comes here
    ll N, a, b, c, d, e;
    cin >> N >> a >> b >> c >> d >> e;

    ll m = min({a, b, c, d, e});
    bool x = !(N%m);
    cout << 5 + N/m - x << nl;
}

Measured memory_bytes: 256
import kotlin.math.*
import java.util.*
import java.io.*

fun main() {
    val (a,b,c,d) = readLine()!!.split(" ").map { it.toLong() }
    var x:Long = a*c
    if(x < a*d){
        x = a*d
    }
    if(x < b*c){
        x = b*c
    }
    if(x < b*d){
        x = b*d
    }
    println(x)
}

Measured memory_bytes: 36572