akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder_Tutorial
{
    class Program
    {
        static void Main(string[] args)
        {
            int K = int.Parse(Console.ReadLine());
            string S = Console.ReadLine();

            if (S.Length <= K)
            {
                Console.WriteLine(S);
            }
            else
            {
                Console.WriteLine("{0}...", S.Substring(0, K));
            }
        }
    }
}


Measured memory_bytes: 27532
#include <bits/stdc++.h>
using namespace std;
#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n)-1;i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(b)-1;i>=(a);--i)
#define ALL(a) a.begin(),a.end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
    if (a < b) { a = b; return true; }
    return false;
}
template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
    if (a > b) { a = b; return true; }
    return false;
}
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
    os << "{";
    int a = 0;
    for (auto &tp : mp) {
        if (a) os << ", "; a = 1;
        os << tp;
    }
    return os << "}";
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    os << p.first << ":" << p.second;
    return os;
}

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

    int N, K; cin >> N >> K;

    ll l = -1, r = 1e18;
    while (r - l > 1) {
        ll mid = (l + r) / 2;
        ll M = mid;
        REP(i, N-1) {
            M -= M / K + 1;
            if (M < 0) break;
        }
        if (M >= 0) r = mid;
        else l = mid;
    }
    cout << r << endl;

    return 0;

}



Measured memory_bytes: 3220
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<stack>
using namespace std;
typedef long long ll;
ll a[1111111];
int main()
{
	ll n;
	cin>>n;
	for(int i=0;i<n;i++)
		scanf("%lld",&a[i]);
	ll xx=a[0];
	for(int i=1;i<n;i++)
		xx=__gcd(xx,a[i]);
	cout<<xx<<endl;	
	
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s,t;
    cin>>s>>t;
    int n=s.length();
    int m=t.length();
    if(n>m){
        cout << "GREATER"<<endl;
    }
    else if(n<m){
        cout<<"LESS"<<endl;
    }
    else{
        for(int i=0;i<n;i++){
            if(s[i]>t[i]){
                cout << "GREATER"<<endl;
                return 0;
            }
            else if(s[i]<t[i]){
                cout<<"LESS"<<endl;
                return 0;
            }
        }
        cout << "EQUAL"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
int main() {
    ll n,k,s;
    std::cin >> n>>k>>s;
    
    for (int i = 0; i < k; i++) {
        std::cout << s<<" ";
    }
    for (int i = 0; i < n-k; i++) {
        if(s==1e9){
            std::cout << 1<<" ";    
        }else{
            std::cout << 1000000000<<" ";
        }
    }
    std::cout << std::endl;
}

Measured memory_bytes: 1280
def gcd(x, y):
    a, b = x, y
    r = a % b
    while r != 0:
        a, b = b, r
        r = a % b
    return b

def divisors(x):
    D = []
    for i in range(1, int(x**0.5) + 1):
        if x % i == 0:
            D.append(i)
            if i != x**0.5:
                D.append(x // i)
    D.sort()
    return D

def isprime(x):
    t = 1
    for i in range(2, int(x**0.5) + 1):
        if x % i == 0:
            t = 0
            break
    if t == 1 and x != 1:
        return True
    else:
        return False


a, b = map(int, input().split())

CD = divisors(gcd(a, b))

ans = 1
for cd in CD:
    if isprime(cd):
        ans += 1

print(ans)


Measured memory_bytes: 3276
import java.util.*;
 
public 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 = 1; i < N; i++){
            A[i] = sc.nextInt();
        }
        int[] B = new int[N];
        for(int i = 1; i < N; i++){
            B[A[i]-1]++;
        }
        for(int i = 0; i < N; i++){
            System.out.println(B[i]);
        }
    }
} 

Measured memory_bytes: 60512
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	int n,h;
	cin>>n>>h;
	int a[n],b[n];
	for(int i=0;i<n;i++) cin>>a[i]>>b[i];
	int maxi=0;
	for(int i=0;i<n;i++)
	{
		if(maxi<a[i]) maxi=a[i];
	}
	sort(b,b+n);
	int g=0;
	int i=n;
	while(i>0)
	{
		i--;
		if(b[i]>maxi)
		{
			h-=b[i];
			g++;
		}
		else break;
		if(h<=0) break;
	}
	while(h>0)
	{
		h-=maxi;
		g++;
	}
	cout<<g<<"\n";
	return 0;
}

Measured memory_bytes: 1024
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd
from itertools import permutations, combinations, product, accumulate, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
#from fractions import gcd
from decimal import *
import heapq
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

n = INT()
a = LIST()
b = [0 for _ in range(n)]
b[0] = a[0]
for i in range(1, n):
    b[i] = b[i - 1] + a[i]
    b[i] %= mod
ans = 0
for i in range(n - 1):
    ans += a[i] * (b[-1] - b[i])
    ans %= mod
print(ans)

Measured memory_bytes: 110244
#include<bits/stdc++.h>
#define int long long
using namespace std;
int f[90005];
signed main() {
	for(int i=1;i<=100;i++){
		for(int j=1;j<=100;j++){
			for(int k=1;k<=100;k++){
				f[i*i+j*j+k*k+i*j+j*k+k*i]++;
			}
		}
	}
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cout<<f[i]<<endl;
	}
	return 0;
}


Measured memory_bytes: 4068
#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long

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

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

    const bool ans = b - a == c - b;
    cout << (ans ? "YES" : "NO") << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

const int MAX = 3000000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

int K;
string s;

int main() {
  COMinit();

  cin >> K >> s;
  int S = static_cast<int>(s.size());

  int res = 0;
  for (int i = 0; i <= K; i++) {
    int tmp = (modpow(25, K - i, MOD) * modpow(26, i, MOD)) % MOD;
    tmp = (tmp * COM(S + K - i - 1, S - 1)) % MOD;
    res = (res + tmp) % MOD;
  }
  cout << res << endl;

  return 0;
}

Measured memory_bytes: 75636
#include<bits/stdc++.h>
using namespace std;
int main()
{
	double h,w,x,y;
	cin>>w>>h>>x>>y;
	cout<<fixed << setprecision(15) <<w*h/2.0<<" ";
	if(2.0*x==w&&2.0*y==h)
	{
		cout<<"1";
	}
	else
	{
		cout<<"0";
	}
	return 0;
} 

Measured memory_bytes: 256
// skip until line 65
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <istream>
#include <iterator>
#include <sstream>
#include <list>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
using namespace std;

#define BR "\n"
#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define ALL(cont) begin(cont),end(cont)
#define AS_MOD(a, b) ((((a) % (b) ) + (b)) % (b))
#define MO(a) AS_MOD(a,mod)
#define FEACH(it, cont) for(auto (it) = begin(cont); it!=end(cont);++it)
#define FEACHR(it, cont) for(auto (it) = rbegin(cont); it!=rend(cont);++it)
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define getll() ([](){ll s;scanf("%lld", &s);return s;})()
#define getld() ([](){ld s;scanf("%Lf", &s);return s;})()
#define prl(P) printf("%lld", P)
#define prd(P) printf("%.10Lf", P)
#define pr(P) printf(P)
#define MAX(V, T) V=max(V,T)
#define MIN(V, T) V=min(V,T)

#define DumpArray(cont, from, to) for(int __i=from;__i<to;++__i) {cout<<"(" <<__i<<": " << cont[__i]<<")";} cout<<endl;

/*
 * ***_bound(6)
 * 5 6 6 6 6 6 7 7 7
 *   ^lower    ^upper
 * void reverse(c.begin(), c.end())
 *
 * graph
 * seg tree
 * dp
 * brute force
 */
struct Comparator{
    int operator()(int l, int r) const {
        return r<l;
    }
};
struct Vec;
//set<int, Comparator> S;

// solution below
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;

#define MAX_N (2*100000)
int main() {
    cout.precision(10);
    cout << fixed;
    int N;
    cin >>N;
    N%=10;
    if (N==2||N==4||N==5||N==7||N==9) {
        cout << "hon"<<endl;
        exit(0);
    }
    if (N==3) {
        cout << "bon" <<endl;
        exit(0);
    }
    cout<<"pon"<<endl;
}


Measured memory_bytes: 3596
#include <iostream>
#include <vector>
using namespace std;
int main(){
  long long int N, K;
  cin >> N >> K;
  vector<long long int> w(N), d(N);
  for(int i = 0; i < N; ++i){
    cin >> w[i] >> d[i];
  }
  unsigned long long int ng = 0LL, ok = 2E18+1LL;
  while(ok-ng > 1){
    unsigned long long int m = (ok+ng)/2LL, t = 0LL;
    for(int i = 0; i < N; ++i){
      if(m >= w[i]){
        t += (m - w[i])/d[i] + 1LL;
        if(t >= K) break;
      }
    }
    if(t >= K) ok = m;
    else ng = m;
  }
  cout << ok << endl;
  return 0;
}


Measured memory_bytes: 1792
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String op = sc.next();
		int x = sc.nextInt(), y = sc.nextInt();
		List<Integer> d[] = new ArrayList[2];
		d[0] = new ArrayList<>();
		d[1] = new ArrayList<>();
		
		int sum[] = new int[2];
		int cnt = 0;
		int dir = 0;
		for(int i=0;i<op.length();i++){
			if(op.charAt(i) == 'T'){
				if(cnt != 0){
					d[dir].add(cnt);
					sum[dir] += cnt;
					cnt=0;
				}
				dir = 1-dir;
			}
			else{
				cnt++;
			}
		}
		if(cnt!=0){
			d[dir].add(cnt);
			sum[dir] += cnt;
		}
		
		if(op.charAt(0)=='F'){
			int f = d[0].remove(0);
			sum[0] -= f;
			x-=f;
		}
		
		int dpx[] = new int[8001];
		int dpy[] = new int[8001];
		dpx[0] = 1;
		dpy[0] = 1;
		
		for(int i=0;i<d[0].size();i++){
			int val = d[0].get(i);
			for(int j=8000;j>=val;j--){
				if(dpx[j-val]==1){
					dpx[j] = 1;
				}
			}
		}
		for(int i=0;i<d[1].size();i++){
			int val = d[1].get(i);
			for(int j=8000;j>=val;j--){
				if(dpy[j-val]==1){
					dpy[j] = 1;
				}
			}
		}
		
		if(check(dpx, dpy, x, y, sum)){
			System.out.println("Yes");
		}
		else{
			System.out.println("No");
		}
	}
	static boolean check(int dpx[], int dpy[], int x, int y, int sum[]){
		x = Math.abs(x);
		y = Math.abs(y);
		
		if(sum[0]<x || sum[1]<y)
			return false;
		
		boolean ok1 = false;
		for(int i=0;i<=sum[0];i++){
			if(dpx[i]==1 && Math.abs(sum[0]-i-i) == x){
				ok1 = true;
			}
		}
		boolean ok2 = false;
		for(int i=0;i<=sum[1];i++){
			if(dpy[i]==1 && Math.abs(sum[1]-i-i) == y){
				ok2 = true;
			}
		}
		
		return ok1 && ok2;
	}
}


Measured memory_bytes: 24660
#include <bits/stdc++.h>
#define int long long
#define N 1001
using namespace std;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
typedef pair<int,int> P;
int n;
char G[N][N];

typedef pair<P,int>PP;
int getIdx(const vector<PP>&V,const PP &a,const PP &b){
  int f = (a.first.first + b.first.first)%4;
  int s = (a.first.second + b.first.second + 1)%2;
  for(int i=0;i<(int)V.size();i++)  if(V[i].first == P(f,s)) return i;
  assert(0);
}

int judge(vector<PP> sta,int turn){
  vector<P> v;
  for(PP p:sta) while(p.second--) v.push_back(p.first);
  assert((int)v.size()==2);
  P a = v[0], b = v[1];
  return
    turn ^ a.second ^ b.second ^
    (a.first==2 || a.first == 3) ^
    (b.first==2 || b.first == 3);
}

map<vector<PP>,bool> mem;
int dfs(vector<PP> sta,int turn){
  int sum = 0;
  for(PP p:sta) sum += p.second;
  if(sum == 2) return judge(sta,turn);
  if(mem.count(sta)) return mem[sta];

  int res = turn;
  for(PP &a:sta)
    for(PP &b:sta){
      a.second--; b.second--;
      if(a.second < 0 || b.second < 0) {a.second++;b.second++;continue;}
      int idx = getIdx(sta,a,b); sta[idx].second++;
      int result = dfs(sta,!turn);
      a.second++, b.second++, sta[idx].second--;
      turn == 0? (res |= result):(res &= result);
    }
  return mem[sta] = res;
}

void visit(int pos,int num,vector<int> &used,vector<int> &par){
  par[pos] = num;
  if(used[pos]++) return;
  for(int to=0;to<n;to++) if(G[pos][to]=='Y') visit(to,num,used,par);
}

vector<PP> prepare(){
  vector<int> par(n),used(n,0);
  int cnt = 0;
  for(int i=0;i<n;i++) if(used[i] == 0) visit(i,cnt++,used,par);

  vector<P> A(cnt,P(0,0)); //nodes,edges;
  for(int i=0;i<n;i++){
    A[par[i]].first++;
    for(int j=0;j<n;j++) A[par[i]].second+=G[i][j] == 'Y';
  }
  for(P &a:A) a.first%=4, a.second=(a.second/2)%2;

  map<P,int> M;
  for(int i=0;i<4;i++)
    for(int j=0;j<2;j++) M[P(i,j)] = 0;
  for(P a:A) M[a]++,M[a]%=4;
  vector<PP> V;
  for(PP m:M) V.push_back(m);
  return V;
}


signed main(){
  cin >> n;
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++) cin>>G[i][j];
  vector<PP> v = prepare();
  int ans = dfs(v,0);
  cout<<(ans?"Taro":"Hanako")<<endl;
  return 0;
}

Measured memory_bytes: 4064
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int deg[100005],p[100005];
vector <int> e[100005];
int cnt=0;
queue <int> q;
int dp[100005],pos[100005];
int main(int argc, char** argv) {
	int n,m;
	cin >> n >> m;
	for(int i=1;i<=m;i++)
	{
		int u,v;
		cin >> u >> v;
		e[u].push_back(v);
		++deg[v];
	}
	for(int i=1;i<=n;i++)
		if(!deg[i]) q.push(i);
	while(!q.empty())
	{
		p[++cnt]=q.front();
		pos[q.front()]=cnt;
		q.pop();
		for(auto v:e[p[cnt]])
		{
			--deg[v];
			if(!deg[v])
				q.push(v);
		}
	}
	int ans=0;
	for(int i=n;i>=1;i--)
	{
		for(auto v:e[p[i]])
			dp[i]=max(dp[i],1+dp[pos[v]]);
		ans=max(ans,dp[i]);
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 7296
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
typedef vector<vector<ll>> mat;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<60;
double pi=3.141592653589793238462643383279L;
double eps=1e-9;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll popcount(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;cin>>n;
    bool used[55556];
    fill(used,used+55556,false);
    vector<int> v;
    rep(i,2,55556){
        if(used[i])continue;
        v.push_back(i);
        for(int j=i;j<=55555;j+=i)used[j]=true;
    }
    vector<int> w;
    rep(i,0,v.size()){
        if(v[i]%5==1)w.push_back(v[i]);
    }
    rep(i,0,n)cout<<w[i]<<" ";
    cout<<endl;
}










Measured memory_bytes: 384
x, y = input().split()

dict = { 'A':10 , 'B':11 , 'C':12 , 'D':13, 'E':14, 'F':15 }

if dict[x] > dict[y]:
  print('>')
elif dict[x] == dict[y]:
  print('=')
else:
  print('<')

Measured memory_bytes: 3060
import scala.io.StdIn
import scala.math.sqrt

object Main{
    def main(args: Array[String]){
        val sc = new java.util.Scanner(System.in)
        val n = sc.nextInt // 最初の数字を読み取る
        val list = List.fill(n)(sc.nextInt) // nextIntがn回呼ばれる
        var count = 0;
        for(j <- list)if(isPrime(j)) count = count + 1
            
        
        println(count)
    }
    
    def isPrime(x: Int): Boolean = {
        if(x == 2){
            return true
        }
        
        if(x < 2 || x % 2 == 0){
            return false
        }
        
        var i = 3;
        while(i <= sqrt(x)){
            if(x % i == 0){
                return false
            }
            i += 2
        }
        return true
    }
}


Measured memory_bytes: 60144
#include<stdio.h>
#include<algorithm>
using namespace std;
int c[110000];
int d[110000];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++)scanf("%d",c+i);
	for(int i=0;i<a;i++)d[i]=c[i];
	long long ret=0;
	for(int i=0;i<a;i++)ret+=c[i];
	for(int i=1;i<a;i++){
		for(int j=0;j<a;j++){
			d[j]=min(d[j],c[(j+a-i)%a]);
		}
		long long tmp=(long long)b*i;
		for(int j=0;j<a;j++)tmp+=d[j];
		ret=min(ret,tmp);
	}
	printf("%lld\n",ret);
}

Measured memory_bytes: 128
x1,y1,x2,y2 = map(int,input().split())
x3 = y1 - y2 + x2
y3 = x2 - x1 + y2
x4 = x1 + y1 - y2
y4 = y1 + x2 - x1
print("%d %d %d %d" %(x3,y3,x4,y4)) 

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

long long n,a[200005],sum;

int main()
{
	scanf("%lld",&n);
	for(long long i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
	}
	for(long long i=1;i<n;i++)
	{
		if(a[i+1]<a[i])
		{
			sum+=a[i]-a[i+1];
			a[i+1]+=a[i]-a[i+1];
		}
	}
	printf("%lld",sum);
	return 0;
}

Measured memory_bytes: 5264
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#define debug(x) cerr << #x << ':' << x
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef long long ll;

int main(){
    int sx,sy, gx,gy;
    cin >> sx >> sy >> gx >> gy;

    REP(i,gy-sy) cout << "U";
    REP(i,gx-sx) cout << "R";
    REP(i,gy-sy) cout << "D";
    REP(i,gx-sx) cout << "L";
    cout << "L";
    REP(i,gy-sy+1) cout << "U";
    REP(i,gx-sx+1) cout << "R";
    cout << "D";
    cout << "R";
    REP(i,gy-sy+1) cout << "D";
    REP(i,gx-sx+1) cout << "L";
    cout << "U";
    return 0;
}

Measured memory_bytes: 256
s = gets.chomp.chars.map(&:to_i)
a = [1, -1]
b = ["", "+", "-"]
a.each {|x| a.each {|y| a.each{|z|
    if s[0] + s[1] * x + s[2] * y + s[3] * z == 7 
        puts "%d%s%d%s%d%s%d=7" % [s[0], b[x], s[1], b[y], s[2], b[z], s[3]]
        exit
    end
    }}}

Measured memory_bytes: 1788
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [n, a, b] <- getIntList
    print $ min (n * a) b

Measured memory_bytes: 380
#include <bits/stdc++.h>
#define rep(i,n); for(ll i = 0; i < ll(n); i++)
using namespace std;
typedef long long ll;
ll MOD = 1000000007;
int gcd(int a, int b){ //a>=0,b>=0,￢(a=b=0)
  while(min(a,b)>0){if(a<b)swap(a,b);a=a%b;}return max(a,b);
}



int main(){
  int n;
  cin>>n;
  string ans;
  int a,b,c,d;
  a = n/1000;
  b = (n-1000*a)/100;
  c = (n%100)/10;
  d = n%10;
  ostringstream s,t,u,v;
  s<<a;t<<b;u<<c;v<<d;
  string A = s.str();
  string B = t.str();
  string C = u.str();
  string D = v.str();
  int k = a+b+c+d;
  if(k==7) ans=A+"+"+B+"+"+C+"+"+D;
  else if (k == 7+2*b) ans=A+"-"+B+"+"+C+"+"+D;
  else if (k==7+2*c) ans=A+"+"+B+"-"+C+"+"+D;
  else if (k==7+2*d) ans=A+"+"+B+"+"+C+"-"+D;
  else if (k==7+2*b+2*c) ans=A+"-"+B+"-"+C+"+"+D;
  else if (k==7+2*b+2*d) ans=A+"-"+B+"+"+C+"-"+D;
  else if (k==7+2*c+2*d) ans=A+"+"+B+"-"+C+"-"+D;
  else if (k==7+2*d+2*b+2*c) ans=A+"-"+B+"-"+C+"-"+D;
  ans += "=7";
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int N;
    cin>>N;
    if (N%10==3){
    cout << "bon" << endl;
    }
    else if(N%10<=1 or N%10==6 or N%10==8 ){
    cout << "pon" << endl;
    }else{
    cout <<"hon" << endl;
    }
 }

Measured memory_bytes: 3600
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll INF=1e15;

int main()
{
    ll n,x;
    cin >> n >> x;
    vector<ll> a(n);
    rep(i,n){
        cin >> a[i];
    }
    ll ans=0;
    rep(i,n-1){
        if(a[i+1]+a[i]>x){
            ll d=a[i+1]+a[i]-x;
            if(d<=a[i+1]){
                a[i+1]-=d;
            }
            else{
                ll dd=d-a[i+1];
                a[i+1]=0;
                a[i]-=dd;
            }
            ans+=d;
        }
    }
    cout << setprecision(30);
    cout << ans << endl;
    return 0;
} 


Measured memory_bytes: 1024
n,m=map(int,input().split())
A=[False]*n
B=[1]*n
A[0]=True
for i in range(m):
  x,y=map(int,input().split())
  if A[x-1]:
    A[y-1]=True
  B[x-1]-=1
  B[y-1]+=1
  if B[x-1]==0:
    A[x-1]=False
print(A.count(True))

Measured memory_bytes: 4596
#include<iostream>
using namespace std;
int main()
{
    int l,r,d,s=0;
    cin>>l>>r>>d;
    for(int i=l;i<=r;i++)
    {  if(i%d==0)
    {
        s++;
    }

    }
    cout<<s<<endl;

    return 0;

}



Measured memory_bytes: 3584
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        boolean judge = false;
        if (s.substring(0, (s.length() - 1) / 2).equals(s.substring((s.length() + 3) / 2 - 1))) {
            StringBuffer sb = new StringBuffer(s.substring(0, (s.length() - 1) / 2));
            String reversed_s = sb.reverse().toString();
            if (s.substring(0, (s.length() - 1) / 2).equals(reversed_s)) {
                judge = true;
            }
        }
        if (judge) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
        sc.close();
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define RFOR(i,m,n) for(int i=m;i>=n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265


int main(){
  double n;
  cin>>n;
  printf("%.10f\n",max(floor(n+1),sqrt(2)*n));


  return 0;
}


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

int main(){
  int n;
  cin >> n;
  long long ans = 0;
  vector<long long> L(n+1);
  if(n == 1){
    ans = 1;
  }else if(n == 2){
    ans = 3;
  }else{
    L.at(0) = 2;
    L.at(1) = 1;
    for(int i = 2;i < n+1;i++){
 	L.at(i) = L.at(i-2) + L.at(i-1);
    ans = L.at(i);
    }
  }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
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; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<string> s(n);
  rep(i, n) cin >> s[i];
  vector<int> l(n), r(n);
  rep(i, n) {
    for (auto e : s[i]) {
      if (e == '(')
        l[i]++;
      else if (!l[i])
        r[i]++;
      else
        l[i]--;
    }
  }
  int lsum = 0, rsum = 0;
  vector<int> idx;
  rep(i, n) {
    if (l[i] && !r[i])
      lsum += l[i];
    else if (!l[i] && r[i])
      rsum += r[i];
    else
      idx.push_back(i);
  }
  vector<pair<int, int>> Lr, lR;
  for (auto i : idx) {
    if (l[i] > r[i])
      Lr.push_back(make_pair(l[i], r[i]));
    else
      lR.push_back(make_pair(l[i], r[i]));
  }
  sort(Lr.begin(), Lr.end(), [](auto x, auto y) {
    if (x.second == y.second)
      return x.first > y.first;
    return x.second < y.second;
  });
  sort(lR.begin(), lR.end(), [](auto x, auto y) {
    if (x.second-x.first == y.second-y.first)
      return x.second < y.second;
    return x.second-x.first < y.second-y.first;
  });
  for (auto e : Lr) {
    lsum -= e.second;
    if (lsum < 0) {
      cout << "No" << endl;
      return 0;
    }
    lsum += e.first;
  }
  for (auto e : lR) {
    lsum -= e.second;
    if (lsum < 0) {
      cout << "No" << endl;
      return 0;
    }
    lsum += e.first;
  }
  if (lsum == rsum)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 42204
// In the name of God

#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>

using namespace std;
#define int long long
const int N = (int) 1e5 + 5, mod = (int) 0;
int x[N];
int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n, a, b;
    cin >> n >> a >> b;
    for (int j = 0; j < n; ++j)
        cin >> x[j];
    int res = 0;
    for (int j = 0; j < n - 1; ++j)
        res += min(b, a * (x[j + 1] - x[j]));
    cout << res << endl;
}


Measured memory_bytes: 1024
require 'prime'
require 'set'
require 'tsort'
include Math
ALP = ('a'..'z').to_a
INF = 0xffffffffffffffff
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def pr?(num);              Prime.prime?(num)                          end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end
n,m = gi
puts (n-1)*(m-1)


Measured memory_bytes: 2684
read_ints = lambda : map(int, raw_input().strip().split())

n = input()
v = read_ints()
c = read_ints()

ans = sum(v) - sum(c)

for i in xrange(1 << n):
    cur = 0
    for j in xrange(n):
        if (i & (1 << j)):
            cur += v[j]
            cur -= c[j]
    ans = max(ans, cur)

print ans

Measured memory_bytes: 32668
#include<iostream>
using namespace std;
int main(){
    int a,b,c,t;
    cin >> a >> b >> c;
    if(a>b) {t=a; a=b; b=t;}
    if(b>c) {t=b; b=c; c=t;}
    if(a>b) {t=a; a=b; b=t;}
    
    cout << a <<" "<< b <<" "<< c <<endl;
    return 0;
}


Measured memory_bytes: 3088
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#define rep(i,N) for(int i=0;i<N;i++)

long long  INF=1000000000000000000;
long long mod=1000000007;
using namespace std;
int N;


void show_ans(int ans[]){
    for(int i=1;i<=N;i++){
            if(ans[i]==0){
                cout<<'S';}
            else{
                cout<<'W';}
    }
    return;
}
int main(){

cin>>N;

string s;
cin>>s;

int  head[2]={0,1};
int  next[2]={0,1};
rep(i,2)rep(k,2){
    int ans[N+2];
    ans[1]=head[i];
    ans[2]=next[k];
    for(int l=2;l<N;l++){
        if(s[l-1]=='o' && ans[l]==0){
            ans[l+1]=ans[l-1];
        }
        else if(s[l-1]=='o' && ans[l]==1){
            ans[l+1]=1-ans[l-1];
        }

        if(s[l-1]=='x' && ans[l]==0){
            ans[l+1]=1-ans[l-1];
        }
        else if(s[l-1]=='x' && ans[l]==1){
            ans[l+1]=ans[l-1];
        }
    }

    ans[N+1]=ans[1];
    ans[0]=ans[N];
    bool cor=true;
    for(int l=1;l<=N;l++){
        if(s[l-1]=='o'){
            if(ans[l]==0){
                if(ans[l+1]!=ans[l-1])cor=false;
            }
            if(ans[l]==1){
                if(ans[l-1]==ans[l+1])cor=false;
            }
        }

        else if(s[l-1]=='x'){
            if(ans[l]==1){
                if(ans[l-1]!=ans[l+1])cor=false;
            }
            if(ans[l]==0){
                if(ans[l-1]==ans[l+1])cor=false;
            }
        }
    }
    if(cor){
        show_ans(ans);
        return 0;
    }
}
cout<<"-1"<<endl;
 return 0;
}
/*
6
ooxoox

SSSWWS

3
oox

-1


10
oxooxoxoox

SSWWSSSWWS
*/

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

vector<int> to[55];
vector<bool> seen;

void dfs(int v, int i, int j){
	seen[v] = true;
	for(auto next: to[v]){
		if(seen[next]) continue;
		if(next == j && v == i) continue;
		if(next == i && v == j) continue;
		dfs(next, i, j);
	}
	return ;
}

int main(){
	int n,m;
	cin >> n >> m;
	seen.resize(n,false);
	vector<pair<int,int>> e(m);
	rep(i,m){
		int a,b;
		cin >> a >> b;
		a--; b--;
		to[a].push_back(b);
		to[b].push_back(a);
		e[i] = make_pair(a,b);
	}
	int ans = 0;
	rep(i,m){
		dfs(0,e[i].first,e[i].second);
		bool ok = true;
		rep(j,n){
			if(!seen[j]) ok = false;
		}
		rep(j,n) seen[j] = false;
		if(!ok) ans++;
	}
	cout << ans << endl;
	
    return 0;
}



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

const int N = 3010;
int n , ti , vis[N][N];
double p[N] , mem[N][N];

double dp(int i , int h){
	if( i == n ) return h > n-h ? 1.0 : 0.0;
	double &ret = mem[i][h];
	int &vs = vis[i][h];
	if(vs == ti) return ret;
	vs = ti;
	return ret = (1.0-p[i]) * dp(i+1 ,h) + p[i] * dp(i+1 , h+1);
}

int main(){
	scanf("%d" , &n);
	for(int i=0 ; i<n ; i++) scanf("%lf"  , p+i);
	ti++;
	cout<<fixed<<setprecision(10)<<dp(0 , 0);
}


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

int main() {
	int debt = 100000; int n; cin >> n;
	for (int i = 0; i < n; i++) {
		debt = debt * 1.05;
		if (debt % 1000 > 0) {
			debt = debt - (debt % 1000) + 1000;
		}
	}
	cout << debt << endl;
	return 0;
}


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

const int mod = 1e9 + 7, N = 1e5 + 10;

ll pw(ll a, ll b) {
    ll r = 1;
    for( ; b ; b >>= 1, a = a * a % mod) {
        if(b & 1) {
            r = r * a % mod;
        }
    }
    return r;
}

ll getinv(ll n) {
    return pw(n, mod - 2);
}

int main() {
    ll a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a + 3);
    cout << (a[0] + a[1]) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, counter = 1;
  cin >> n;
  
  vector<int> h(n);
  for(int i = 0;n > i;i++)
    cin >> h.at(i);
  
  for(int i = 1;n > i;i++){
    for(int j = 0;i > j;j++){
      if(h.at(i) - h.at(j) < 0)
        break;
      if(j == i -1)
        counter++;
    }
  }
  
  cout << counter << endl;
}

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

const long long INF = 0x3f3f3f3f3f3f3f3f;

int a[100010], op[100010];
char buf[5];
long long dp[100010][3];

int main () {
//	freopen("data.in", "r", stdin);
//	freopen("my.out", "w", stdout);
	int n; scanf("%d", &n);
	scanf("%d", &a[1]), op[1] = 0;
	for (int i = 2; i <= n; i++) {
		scanf("%s", buf);
		op[i] = buf[0] == '-' ? 1 : 0;
		scanf("%d", &a[i]);
	}
	dp[0][0] = 0, dp[0][1] = -INF, dp[0][2] = -INF;
	for (int i = 1; i <= n; i++) {
		dp[i][0] = dp[i][1] = dp[i][2] = -INF;
		// not change
		dp[i][0] = max(dp[i][0], dp[i - 1][0] + (op[i] ? -a[i] : a[i]));
		dp[i][1] = max(dp[i][1], dp[i - 1][1] + (op[i] ? a[i] : -a[i]));
		dp[i][2] = max(dp[i][2], dp[i - 1][2] + (op[i] ? -a[i] : a[i]));
		// change
		if (op[i]) {
			dp[i][1] = max(dp[i][1], dp[i - 1][0] - a[i]);
			dp[i][2] = max(dp[i][2], dp[i - 1][1] + a[i]);
		}
		// flush
		dp[i][1] = max(dp[i][1], dp[i][2]), dp[i][0] = max(dp[i][0], dp[i][1]);
	}
	printf("%lld\n", dp[n][0]);
	return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+20;
int main()
{
	int ans=0,n;
	while(cin>>n)
	{
		int x=0;
		string s;
		cin>>s;
		for(int i=0;s[i];i++)
		{
			if(s[i]=='D')
			x--;
			else
			x++;
			
			ans=max(ans,x);
		}	
		cout<<ans<<endl;
	} 
 
	return 0;
}


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

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  // ios_base::sync_with_stdio(0), c
  cout << fixed << setprecision(15);

  ll h, w, n;
  cin >> h >> w >> n;

  set<P> st;
  rep(i, n) {
    ll a, b;
    cin >> a >> b;
    a--, b--;
    st.insert(P(a, b));
  }

  vll vote(10, 0);

  set<P> done;
  for(P p : st){
    ll a, b;
    tie(a, b) = p;
    rep(i, 9){
      ll y = a + dy[i], x = b + dx[i];
      bool ok = 1 <= y && y < h-1 && 1 <= x && x < w-1;
      ok &= done.find(P(y, x)) == done.end();
      if(!ok) continue;
      done.insert(P(y, x));
      ll cnt = 0;  
      rep(j, 9){
        ll ny = y + dy[j], nx = x + dx[j];
        if(st.find(P(ny, nx)) != st.end()) cnt++;
      }
      vote[cnt]++;
    }
  }

  cout << (h-2)*(w-2) - accumulate(vote.begin()+1, vote.end(), 0) << endl;
  repLRE(i, 1, 9) cout << vote[i] << endl;

  return 0;
}


Measured memory_bytes: 66004
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<time.h>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; ++i)
#define FOR(i,n,m) for(long long i=n; i<m; ++i)
#define DUMP(n,a) for(long long dump=0; dump<n; ++dump) { cout<<a[dump]; if(dump!=n-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	vector<ll> a(n);
	REP(i,n) cin>>a[i];
	ll ret=1;
	REP(i,n) {
		if(a[i]%2==0) ret*=2;
		else ret*=1;
	}
	ll buf=1;
	REP(i,n) {
		buf*=3;
	}
	cout<<buf-ret<<endl;
}


Measured memory_bytes: 256
#include<cstdio>

using namespace std;

int n,P,a[5010],f[5010],ans;

void add(int &x,int y){x=(x+y>=P)?x+y-P:x+y;}

int main(){
	scanf("%d%d",&n,&P); a[2]=1,f[0]=1;
	for(int i=3,j=n;i<=j;i++,j--)a[i]=a[j]=i-1;
	for(int i=2;i<=n;i++)
	for(int j=a[i];j<n;j++)add(f[j],f[j-a[i]]);
	for(int i=0;i<n;i++)(ans+=1ll*f[i]*(n-i)%P)%=P;
	printf("%d\n",ans);
} 

Measured memory_bytes: 888
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int a = s.nextInt();
        String S = s.next();
        if(a>=3200){
            System.out.print(S);
        }
        else{
            System.out.println("red");
        }
    }
}


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

#define debug(...) fprintf(stderr, __VA_ARGS__)

#ifndef AT_HOME
#define getchar() IO::myGetchar()
#define putchar(x) IO::myPutchar(x)
#endif

namespace IO {
	static const int IN_BUF = 1 << 23, OUT_BUF = 1 << 23;

	inline char myGetchar() {
		static char buf[IN_BUF], *ps = buf, *pt = buf;
		if (ps == pt) {
			ps = buf, pt = buf + fread(buf, 1, IN_BUF, stdin);
		}
		return ps == pt ? EOF : *ps++;
	}

	template<typename T>
	inline bool read(T &x) {
		bool op = 0;
		char ch = getchar();
		x = 0;
		for (; !isdigit(ch) && ch != EOF; ch = getchar()) {
			op ^= (ch == '-');
		}
		if (ch == EOF) {
			return false;
		}
		for (; isdigit(ch); ch = getchar()) {
			x = x * 10 + (ch ^ '0');
		}
		if (op) {
			x = -x;
		}
		return true;
	}

	inline int readStr(char *s) {
		int n = 0;
		char ch = getchar();
		for (; isspace(ch) && ch != EOF; ch = getchar())
			;
		for (; !isspace(ch) && ch != EOF; ch = getchar()) {
			s[n++] = ch;
		}
		s[n] = '\0';
		return n;
	}

	inline void myPutchar(char x) {
		static char pbuf[OUT_BUF], *pp = pbuf;
		struct _flusher {
			~_flusher() {
				fwrite(pbuf, 1, pp - pbuf, stdout);
			}
		};
		static _flusher outputFlusher;
		if (pp == pbuf + OUT_BUF) {
			fwrite(pbuf, 1, OUT_BUF, stdout);
			pp = pbuf;
		}
		*pp++ = x;
	}

	template<typename T>
	inline void print_(T x) {
		if (x == 0) {
			putchar('0');
			return;
		}
		static int num[40];
		if (x < 0) {
			putchar('-');
			x = -x;
		}
		for (*num = 0; x; x /= 10) {
			num[++*num] = x % 10;
		}
		while (*num){
			putchar(num[*num] ^ '0');
			--*num;
		}
	}

	template<typename T>
	inline void print(T x, char ch = '\n') {
		print_(x);
		putchar(ch);
	}

	inline void printStr_(const char *s, int n = -1) {
		if (n == -1) {
			n = strlen(s);
		}
		for (int i = 0; i < n; ++i) {
			putchar(s[i]);
		}
	}

	inline void printStr(const char *s, int n = -1, char ch = '\n') {
		printStr_(s, n);
		putchar(ch);
	}
}
using namespace IO;

int x;

void solve() {
	read(x);
	print(360 / std::__gcd(360, x));
}

int main() {
	int T = 1;
	// read(T);
	while (T--) {
		solve();
	}
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  int H,W;cin >> H >> W;
  cout << (N+1-H)*(N+1-W) << endl;
  return 0;
}


Measured memory_bytes: 256
import collections

N = int(input())
A = list(map(int, input().split()))

L = [i + A[i] for i in range(N)]
R = [i - A[i] for i in range(N)]

countL = collections.Counter(L)
countR = collections.Counter(R)

print(sum([countL[n] * countR[n] for n in countL.keys()]))

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

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


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {
	
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			char[] chs = sc.next().toCharArray();
			
			int count = 0;
			char prev = '\0';
			for(final char ch: chs) {
				if(prev != ch) {
					count += 1;
					prev = ch;
				}
			}
			
			System.out.println(count);
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

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

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

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

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

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

int main(void)
{
	int N, K, j;
	double a, count, ans = 0.0;
	cin >> N >> K;

	a = (1.0 / N);

	for (int i = 1; i <= N; i++)
	{
		if (i >= K) {
			ans += a;
		} else {
			j = i;
			count = 1.0;
			while (j < K)
			{
				j *= 2.0;
				count *= 0.5;
			}
			ans += a * count;
		}
	}

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

	return 0;
}

Measured memory_bytes: 384
N, K = map(int, input().split())
h = []
ans = 1000000000

for i in range(N):
    h.append(int(input()))

h = sorted(h)

for j in range(N-K+1):
    if ans > h[j+K-1]-h[j]:
        ans = h[j+K-1]-h[j]
print(ans)


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


typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

#define pb push_back
#define mp make_pair
#define snd second
#define fst first
#define debug printf("--%d--\n",__LINE__)
#define ll long long int

int main(void){
	string s; cin >> s;
	cout << s.substr(0,4) << " " << s.substr(4,8) << endl;
	
	
	
	
	return 0;
}


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

const int N = 1000005;
const int md = 1e9 + 7;

int n, dp[N];
int sum;
int ans;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n;

	dp[0] = 1;
	dp[1] = n;
	sum = 0;
	for (int i = 2; i <= n; ++i) {
		dp[i] = dp[i-1]; // 1,...
		dp[i] = (dp[i] + 1LL * (n-1) * (n-1)) % md; // c,d,... (c,d > 1)
		dp[i] = (dp[i] + sum) % md; // c,1,... (c + 1 <= i)
		dp[i] = (dp[i] + (n - i + 1)) % md; // c,1,1,1... (c + 1 > i)
		sum = (sum + dp[i-2]) % md;
		//cerr << i << ' ' << dp[i] << endl;
	}

	cout << dp[n] << endl;
}

Measured memory_bytes: 4224
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long x = sc.nextLong();
        long y = sc.nextLong();
        long n = Math.min(x,y);
        long m = Math.max(x,y);
        if(n == 1 && m == 1){
            System.out.println(1);
            return;
        }
        else if(n == 1 && m != 1){
            System.out.println(m-2);
            return;
        }
        System.out.println((n-2)*(m-2));
    }
}


Measured memory_bytes: 21972