akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <math.h>
#include <string>
#include <iomanip>
#include <locale>
#include <list>
#include <bitset>
#include <tuple>
using namespace std;
#define FORN(i,m,n) for(int i=(m); i<int(n); i++)
#define PRINTVEC(v) FORN(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define PRINTMAT(m) FORN(j,0,m.size()) {PRINTVEC(m[j]);}
typedef long long ll;

int main(){
  ios_base::sync_with_stdio(false); cin.tie(NULL);
  string s; cin>>s;
  cout<<(s[2] == s[3] && s[4] == s[5] ? "Yes" : "No")<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
int A, B;

int main()
{
	scanf(" %d%d", &A, &B);
	if(A <= 0 && 0 <= B)
		puts("Zero");
	else if(0 < A || (abs(B-A) & 1))
		puts("Positive");
	else
		puts("Negative");
	return 0;
}

Measured memory_bytes: 128
#include<iostream>

using namespace std;

bool p[52][52];
__int128 mem[52][52];

__int128 f(int e,int c){
  if(e==0)return 0;
  if(c==1)return 1;
  if(p[e][c]++)return mem[e][c];
  return mem[e][c]=f(e-1,c-1)+f(e,c-1)+1;
}

int main(){
  int T;
  cin>>T;
  while(T--){
    long long N,E;
    cin>>N>>E;
    for(int i=1;;i++){
      if(f(E,i)>=N){
	cout<<i<<endl;
	break;
      }
    }
  }
}

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

const int SUPER = 999999;
vector<int> graph[100001];

int main(){
    int n, m;
    cin >> n >> m;

    rep(i, m){
        int a, b;
        cin >> a >> b;
        --a; --b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    vector<int> depth(n, SUPER);
    vector<int> predp(n, -1);
    queue<int> q;

    depth[0] = 0;
    q.push(depth[0]);

    while(!q.empty()){
        int prime = q.front(); 
        q.pop();

        for (int sub :graph[prime]){
            if (depth[sub] != SUPER) continue;
            depth[sub] = depth[prime] + 1;
            predp[sub] = prime;
            q.push(sub);
        }
    }

    cout << "Yes" << endl;
    rep(i, n){
        if (i == 0) continue;
        int ans = predp[i] + 1;        
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 10644
#include <bits/stdc++.h>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/range/algorithm/sort.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using boost::irange;
using boost::sort;
using boost::adaptors::reversed;

int main() {
    int n, m = 0;
    cin >> n;
    vector<int> a(n + 1), b(n + 1);
    for (int i = 1; i <= n; i++) cin >> a[i];

    for (int i : irange(1, n + 1) | reversed) {
        bool odd = false;
        for (int j = 2; j * i <= n; j++) if (b[j * i]) odd = !odd;
        m += b[i] = odd != a[i];
    }

    cout << m << endl;
    for (int i = 1; i <= n; i++) if (b[i]) cout << i << " ";
    if (m) cout << endl;
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
#define f(i,j,k) for(int i=j;i<k;i++)
using namespace std;
int main(){
    long long n,m,k,aa,ans=0;
    cin>>n>>m;
    vector<long long> a(m,0) ;
    f(i,0,n){
        cin>>k;
        f(j,0,k){
            cin>>aa;
            a[aa-1]++;
        }
    }
    f(i,0,m){
        if(a[i]==n){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <algorithm>

using namespace std;

int main(){

    int W,H,x,y,r;
    cin >> W >> H >> x >> y >> r;
    bool result = (y+r <= H) && (x+r<=W) && (0 <= y-r) &&(0<=x-r);
    if(result){
        cout << "Yes" << endl;
    }else{
        cout << "No"<< endl;
    }


    return 0;
}



Measured memory_bytes: 3112
# coding: utf-8
# Your code here!
class UnionFind:
    def __init__(self, n):
        self.parent = list(range(n))#親ノード
        self.size = [1]*n #グループの要素数

    def root(self, x): #root(x): xの根ノードを返す．
        while self.parent[x] != x:
            self.parent[x] = self.parent[self.parent[x]]
            x = self.parent[x]
        return x 

    def merge(self, x, y): #merge(x,y): xのいるグループと$y$のいるグループをまとめる
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return False
        if self.size[x] < self.size[y]: #xの要素数がyの要素数より「小さい」とき入れ替える
            x,y=y,x
        self.size[x] += self.size[y] #xの要素数を更新
        self.parent[y] = x #yをxにつなぐ
        return True

    def issame(self, x, y): #same(x,y): xとyが同じグループにあるならTrue
        return self.root(x) == self.root(y)
        
    def size(self,x): #size(x): xのいるグループの要素数を返す
        return self.size[self.root(x)]


n,m = [int(i) for i in input().split()]
 
T=UnionFind(n)
c=0
for _ in [0]*m:
    x,y,z=[int(i) for i in input().split()]
    if not T.issame(x-1,y-1):
        T.merge(x-1,y-1)
        c+=1
 
print(n-c)

Measured memory_bytes: 10612
#include <bits/stdc++.h>
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main()
{
string s;
cin>>s;
s[5]=' ';
s[13]=' ';
cout<<s<<endl;
}

Measured memory_bytes: 256
#A
N = int(input())
h = [int(x) for x in input().split()]
c = [0] * N

for i in range(N):
    if i == 0:
        c[i] = 0
    elif i == 1:
        c[i] = abs(h[1]-h[0])
    else:
        c[i] = min(abs(h[i]-h[i-1])+c[i-1], abs(h[i]-h[i-2])+c[i-2])
print(c[N-1])

Measured memory_bytes: 13928
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<n;++i)
#define mrep(i,n) for(ll i=n;i>=0;--i)
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define inf 1001001001001000
#define mod 1000000007
#define pi 3.1415926535
using namespace std;
 
int main(void){
    ll x,a,b;
    cin>>x>>a>>b;
    x-=a;
    while(x>=0) x-=b;
    cout<<x+b<<endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
    int n, v, j;
    cin >> n;
    int A[n];
    for (int i=0; i<n; i++){
        cin >> A[i];
    }
    for (int i=0; i<n; i++){
        if (i == n-1){
            cout << A[i] << endl;
        } else {
            cout << A[i] << " ";
        }
    }
    for (int i=1; i<n; i++){
        v = A[i];
        j = i-1;
        while (j>=0 && A[j]>v){
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        for (int j=0; j<n; j++){
            if (j == n-1){
                cout << A[j] << endl;
            } else {
                cout << A[j] << " ";
            }
        }
    }
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

const int MOD = 1e9 + 7;

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

    int c[3][3];
    rep(i, 3){
        rep(j, 3){
            cin >> c[i][j];
        }
    }
    int a[3] = {0}, b[3] = {0};

    rep(i, 3){
        b[i] = c[0][i];
    }
    if(c[0][0] - b[0] == c[0][1] - b[1] && c[0][1] - b[1] == c[0][2] - b[2]){
        a[0] = c[0][0] - b[0];
    }
    
    if(c[1][0] - b[0] == c[1][1] - b[1] && c[1][1] - b[1] == c[1][2] - b[2]){
        a[1] = c[1][0] - b[0];
    }
    if(c[2][0] - b[0] == c[2][1] - b[1] && c[2][1] - b[1] == c[2][2] - b[2]){
        a[2] = c[2][0] - b[0];
    }

    bool ok = true;
    rep(i, 3){
        rep(j, 3){
            if(c[i][j] != a[i] + b[j]){
                ok = false;
            }
        }
    }

    cout << (ok ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

void search(int x, int y, int w, int h, int tile[20][20], int& num){
  if(tile[y][x] != 0){
    num++;
    tile[y][x] = 0;
  
    if(x-1 >= 0){
      search(x-1, y, w, h, tile, num);
    }
    if(x+1 < w){
      search(x+1, y, w, h, tile, num);
    }
    if(y-1 >= 0){
      search(x, y-1, w, h, tile, num);
    }
    if(y+1 < h){
      search(x, y+1, w, h, tile, num);
    }
  }
}

int main(void){
  int w, h, x, y;
  char c[20][21];
  int tile[20][20];
  while(1){
    scanf("%d%d", &w, &h);
    if(w==0 && h==0){
      break;
    }
    int num = 0;
    for(int i=0; i<h; i++){
      scanf("%s", c[i]);
    }
    for(int i=0; i<h; i++){
      for(int j=0; j<w; j++){
	if(c[i][j] == '.'){
	  tile[i][j] = 1;
	}else if(c[i][j] == '@'){
	  tile[i][j] = 1;
	  x = j;
	  y = i;
	}else if(c[i][j] == '#'){
	  tile[i][j] = 0;
	}
      }
    }
    search(x, y, w, h, tile, num);
    printf("%d\n", num);
  }
  return 0;
}

Measured memory_bytes: 1048
from sys import stdin

a,b = [int(x) for x in stdin.readline().rstrip().split()]

li = [2,3,4,5,6,7,8,9,10,11,12,13,1]

if li.index(a) > li.index(b):
    print("Alice")
elif li.index(a) == li.index(b):
    print("Draw")
else:
    print("Bob")

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cassert>
#include <tuple>

using namespace std;

using ll = long long;

int main() {
    int n;
    cin >> n;
    
    vector<int> h(n);
    
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }
    
    int maxi = 0;
    int ans = 0;
    
    for (int i = 0; i < n; i++) {
        if (h[i] >= maxi) {
            ans++;
        }       
        
        maxi = max(maxi, h[i]);
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 888
s = list(input())

enzan = ["+","-"]

for a in enzan:
    for b in enzan:
        for c in enzan:
            ans = s[0] + a + s[1] + b + s[2] + c + s[3]
            if eval(ans) == 7:
                print(ans+"=7")
                exit()

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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
using pll = pair<ll,ll>;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
//constexpr ll MOD = (998244353);
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
void dump(){cout<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cout<<h<<", ";dump(forward<Ts>(t)...);}
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}

void solve1();void solve2();
int main(){
  solve1();
  return 0;
}

void solve1(){

  ll n;
  string s;
  cin>>n>>s;

  string t="qazxswedcvfrtgbnhyujmkiolp";
  sort(t.begin(),t.end());
  for(auto& c:s){
    ll a=c-'A';
    a+=n;
    a%=26;
    cout<<char(a+'A');
  }

}

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

const int N=55;
int n,a,b;

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>n>>a>>b;
	vector<ll> arr(n);
	for(ll& x:arr) cin>>x;
	sort(arr.begin(),arr.end(),greater<ll>());
	double res=1.0*accumulate(arr.begin(),arr.begin()+a,0LL)/a;
	cout<<fixed<<setprecision(7)<<res<<'\n';
	ll C[55][55];
	for(int i=0;i<=50;++i)
		C[i][0]=1;
	C[1][1]=1;
	for(int i=2;i<=50;++i)
		for(int j=1;j<=50;++j)
			C[i][j]=C[i-1][j-1]+C[i-1][j];
	int num=0,need=0;
	for(int i=0;i<n;++i){
		if(arr[i]==arr[a-1]){
			++num;
			if(i<a) ++need;
		}
	}
	ll ways=C[num][need];
	for(int i=a;i<b;++i){
		if(arr[i]==arr[0]) 
			ways+=C[num][i+1];
	}
	cout<<ways<<'\n';
}




Measured memory_bytes: 3772
#include <iostream>

using namespace std;

int main(){
  int n;
  while(cin >> n, n){
    int sa = 0, sb = 0;
    for(int i=0;i<n;i++){
      int a, b; cin >> a >> b;
      if(a>b) sa += a+b;
      if(a==b) sa += a, sb += b;
      if(a<b) sb += a+b;
    }
    cout << sa << " " << sb << endl;
  }
}

Measured memory_bytes: 0
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	var grid [100][100]int

	a := getNextInt64(scanner)
	b := getNextInt64(scanner)

	for y := 0; y < 100; y++ {
		for x := 50; x < 100; x++ {
			grid[y][x] = 1
		}
	}
	for y := 0; y < 100; y += 2 {
		for x := 0; x < 49 && b > 1; x += 2 {
			grid[y][x] = 1
			b--
		}
	}
	for y := 0; y < 100; y += 2 {
		for x := 51; x < 100 && a > 1; x += 2 {
			grid[y][x] = 0
			a--
		}
	}
	fmt.Fprintln(writer, fmt.Sprintf("%d %d", 100, 100))

	for y := 0; y < 100; y++ {
		for x := 0; x < 100; x++ {
			if grid[y][x] == 0 {
				fmt.Fprint(writer, ".")
				continue
			}
			fmt.Fprint(writer, "#")
		}
		fmt.Fprintln(writer, "")
	}

	writer.Flush()
}


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

int main() {
  int N;
  cin >> N;
  string S;
  int A = 0, W = 0, T = 0, R = 0;
  for (int i = 0; i < N; i++) {
    cin >> S;
    if (S == "AC")
      A++;
    else if (S == "WA")
      W++;
    else if (S == "TLE")
      T++;
    else if (S == "RE")
      R++;
  }
  cout << "AC x " << A << endl;
  cout << "WA x " << W << endl;
  cout << "TLE x " << T << endl;
  cout << "RE x " << R << endl;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

signed main() {
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    for (int i = 0; i < n - 1; i++) {
        if (s[i] != s[i + 1])
            ans++;
    }
    cout << ans + 1 << "\n";
}

Measured memory_bytes: 512
import sys
sys.setrecursionlimit(10**5)
n = int(input())
xy = []
for i in range(n):
    x, y = map(int, input().split())
    xy.append((i, x, y))
xx = sorted(xy, key=lambda x:x[1])
yy = sorted(xy, key=lambda x:x[2])
li = []
for i in range(n-1):
    li.append((xx[i][0], xx[i+1][0], xx[i+1][1]-xx[i][1]))
    li.append((yy[i][0], yy[i+1][0], yy[i+1][2]-yy[i][2]))
li.sort(key=lambda x:x[2])
class UnionFind():
    def __init__(self, li):
        self.li = li
    def root(self, x):
        if self.li[x]==x:
            return x
        self.li[x] = self.root(self.li[x])
        return self.li[x]
    def unite(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        if rx==ry:
            return
        self.li[ry] = rx
    def same(self, x, y):
        return self.root(x)==self.root(y)
uf = UnionFind(list(range(n)))
ans = 0
for x, y, cost in li:
    if uf.same(x, y):
        continue
    uf.unite(x, y)
    ans += cost
print(ans)

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

int n, A[10000];

int solve(int i,int m){
    if(m==0) return 1;
    if(i>=n) return 0;
    int res = solve(i+1, m) || solve(i+1, m-A[i]);
    return res;
}

int main(){
    
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> A[i];
    }
    
    int q,m;
    cin >> q;
    for(int i=0; i<q; i++){
        cin >> m;
        if(solve(0, m)) cout << "yes" << endl;
        else cout << "no" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3072
#include<stdio.h>
int R=1,C=1,H[2000010],N[2000010];
//評価関数（いまはMIN）
int hyouka(int a,int b){
  if(C<b)return 1;
  if(C<a||b==0)return 0;
  return N[H[a]]<N[H[b]]?1:0;
}
//挿入関数
void hin(int a){
  int i=C++;
  for(N[H[0]=R]=a;hyouka(0,i/2);i/=2)H[i]=H[i/2];
  H[i]=R++;
}
//取り出す関数
int hout(){
  int rt=H[1],i,j=2,k=H[--C];
  for(i=1;hyouka(i,C);i=j)H[i]=H[j=i*2+1-hyouka(i*2,i*2+1)];
  H[j/2]=k;
  return rt;
}
int mitr(int v,int e,int *a,int *b,int *c){
  int i,r,n,s=0,mi,d[100010]={0};
  int p[100010]={0};
  for(i=0;i<e;i++)hin(c[i]);
  for(i=0;i<e;i++){
    mi=hout()-1;
    for(r=++a[mi];p[r];r=p[r]);
    for(;n=p[a[mi]];a[mi]=n)p[a[mi]]=r;
    for(r=++b[mi];p[r];r=p[r]);
    for(;n=p[b[mi]];b[mi]=n)p[b[mi]]=r;
    if(a[mi]-b[mi]){
      s+=c[mi];
      d[a[mi]]<d[b[mi]]?(p[a[mi]]=b[mi]):(p[b[mi]]=a[mi]);
      if(d[a[mi]]==d[b[mi]])d[a[mi]]++;
    }
  }
  return s;
}
int main(){
  int n,i,j,k,l,a[400010],b[400010],c[400010],r=0,x[100010],y[100010];
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d %d",&x[i],&y[i]);
  for(k=0;k<2;k++){
    for(i=0;i<n;i++)hin(k==0?x[i]:y[i]);
    l=hout()-1;
    for(i=1;i<n;i++){
      j=hout()-1;
      a[r]=b[r+1]=j;
      b[r]=a[r+1]=l;//printf("%d %d %d\n",x[j]-x[l],j,l);
      c[r]=c[r+1]=(k==0?x[j]-x[l]:y[j]-y[l]);
      r+=2;
      l=j;
    }
    R=C=1;
  }
  //for(i=0;i<r;i++)printf("%d %d %d\n",a[i],b[i],c[i]);
  printf("%d\n",mitr(n,r,a,b,c));
  return 0;
}
    


Measured memory_bytes: 12032
#include<cstdio>
using namespace std;
int a,b,c,d;
int main(){
	for(int i=1,x;i<=4;i++){
		scanf("%d",&x);
		if(x==1)a=1;
		if(x==9)b=1;
		if(x==7)c=1;
		if(x==4)d=1;
	}
	if(a&b&c&d)printf("YES");
	else printf("NO");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1001001001
#define LINF 1001001001001001001
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

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

int main() {
  
  int H, W, M;
  cin >> H >> W >> M;
  vector<int> h(M), w(M);
  rep(i,M) {
    cin >> h[i] >> w[i];
    h[i]--; w[i]--;
  }

  vector<int> count_h(H, 0), count_w(W, 0);
  rep(i,M) {
    count_h[h[i]]++;
    count_w[w[i]]++;
  }

  int max_h = 0, max_w = 0;
  rep(i,H) max_h = max(max_h, count_h[i]);
  rep(i,W) max_w = max(max_w, count_w[i]);
  ll len_h = 0, len_w = 0;
  rep(i,H) if (count_h[i] == max_h) len_h++;
  rep(i,W) if (count_w[i] == max_w) len_w++;

  ll sum_max = len_h * len_w;

  rep(i,M) {
    if (count_h[h[i]] + count_w[w[i]] == max_h + max_w) sum_max--;
  }

  ll ans = sum_max > 0 ? max_h + max_w : max_h + max_w - 1;
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 8016
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
 int wari(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
 int lcm(int a,int b){
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }
signed main(){
  string a,b,s;
  int c=1;
  cin>>a>>b;
  vector<string> d;
  for(int i=0;i<a.size()-b.size()+1;i++){
    s=a;
    for(int j=0;j<b.size();j++){
      if(a[i+j]!='?'&&a[i+j]!=b[j])
        break;
      else{
        if(a[i+j]=='?')
        s[i+j]=b[j];
        else
          s[i+j]=a[i+j];
      }
      if(j==b.size()-1){
        for(int k=0;k<s.size();k++){
          if(s[k]=='?')
            s[k]='a';
        }
        d.push_back(s);
      }
    }
  }
  if(d.size()==0)
    cout<<"UNRESTORABLE"<<endl;
  else{
    Sort(d);
    cout<<d.at(0)<<endl;
}
}


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

using namespace std;
typedef long long ll;

#define INF (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

vector<ll> a;

ll c[200200];

int main(void)
{
  ll n;
  cin >> n;
  REP(i, n) c[i] = 0;
  a.push_back(0);
  REP(i, n-1) {
    ll a1 ;
    cin >> a1;
    a.push_back(a1);
    c[a1-1]+=1;
  }
  for(ll i = 0; i < n; i++) {
    printf("%lld\n", c[i]);
  }

}


Measured memory_bytes: 6856
// Made by Luis Miguel Baez
// es.luismiguelbaez@gmail.com

#include <bits/stdc++.h>
 
using namespace std;

#define endl '\n'
#define precise(n,k) fixed << setprecision(k) << n
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define uint  unsigned int
#define ll    long long
#define ull   unsigned long long
#define ld    long double

#define pii   pair<int, int>
#define piii  tuple<int, int, int>
#define pll   pair<ll, ll>
#define plll  tuple<ll, ll, ll>

#define X  first
#define Y  second

#define debug(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

string to_string(string s) {
    return '"' + s + '"';
}

string to_string(bool b) {
    return (b ? "true" : "false");
}
 
template <typename A, typename B>
string to_string(const pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

// add templates here

template <typename T>
string to_string(const vector<T> &v) {
    bool first = true;
    string res = "{";
    for (const T &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string((T)x);
    }
    res += "}";
    return res;
}

template<class T>
void println(const T &data) {
#ifndef ONLINE_JUDGE
    cout << to_string((T)data) << endl;
#endif
}

const int MOD = int(1e9+7);
const ll oo  = (ll)(1e9+20);
const ll lloo  = (ll)(1e18)+40;

class Task {
public:
    ll N;
    vector<ll> D;
    
    ll solve(std::istream &in, std::ostream &out) {
        in >> N;
        D.resize(N);
        for(ll i = 0; i < N; ++i) {
            in >> D[i];
        }
        ll ans = 0;
        for(ll i = 0; i < N; ++i) {
            for(ll j = i+1; j < N; ++j) {
                if(i == j) continue;
                ans += D[i]*D[j];
            }
        }
        return ans;
    }
    void run(std::istream &in, std::ostream &out) {
        int t;
        in >> t;
        while(t--) {
            out << solve(in, out) << endl;
        }
    }
    
    void run_void(std::istream &in, std::ostream &out) {
        int t;
        in >> t;
        while(t--) {
            solve(in, out);
        }
    }
};
    
auto main() -> int {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    Task solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    cout << solver.solve(in, out) << endl;
    // solver.run(in, out);
    return 0;
}


Measured memory_bytes: 3612
N, W = [int(x) for x in input().split()]

w, v = [], []
MAX_V = 100001
INF = 1000000000001

for i in range(N):
  wi, vi = [int(x) for x in input().split()]
  w.append(wi)
  v.append(vi)

dp = []
for i in range(N+1):
  dp.append([INF] * MAX_V)

dp[0][0] = 0

for i in range(N):
  for sum_v in range(MAX_V):
    if sum_v - v[i] >= 0:
      dp[i+1][sum_v] = min(dp[i+1][sum_v], dp[i][sum_v - v[i]] + w[i])
      
    dp[i+1][sum_v] = min(dp[i+1][sum_v], dp[i][sum_v])


res = 0
for sum_v in range(MAX_V):
  if dp[N][sum_v] <= W:
    res = sum_v
  
print(res)

Measured memory_bytes: 121324
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define COUT(x) cout << (x) << endl
using namespace std;
typedef pair<int,int> P;
typedef long long int ll;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

int main() {
    int n, m; cin >> n >> m;
    vector<int> a(n);
    rep(i, m) {
        int k; cin >> k;
        rep(j, k) {
            int s; cin >> s;
            s--;
            a[s] |= 1<<i;
        }
    }

    int p = 0;
    rep(i, m) {
        int x; cin >> x;
        p |= x << i;
    }

    int ans = 0;
    for(int s = 0; s <(1<<n); s++) {
        int t = 0;
        rep(i, n) {
            if(s >> i & 1) {
                t ^= a[i];
            }
        }
        if(t == p) ans++;
    }
    COUT(ans);
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
using namespace std;
#define ll long long
const double EPS = 1e-10;
const ll MOD = 7+(1e+9);


int main (){
  ll n;
  cin>>n;
  ll ans=1;
  while(!(n==1||n==2||n==3)){
    ans++;
    if(n%3!=0)n++;
    if(n%3!=0)n++;
    n=n/3;
  }
  cout<<ans<<endl;
}



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

using namespace std;

typedef long long ll;
const ll INF = 1e18;

ll check(ll x, ll sum)
{
  if(x == 0 or sum == 0)
    return 0;
  if(sum == -1)
    return -1;
  if(x > INF/sum)
    return -1;
  return x*sum;
}
int main()
{
  ll n; cin >> n;
  ll sum = 1;
  for(ll i = 0; i < n; i++)
  {
    ll x;
    cin >> x;
    sum = check(x, sum);
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 3644
//参考：https://qiita.com/DaikiSuyama/items/9dba963ba74396b9b7fd
//インクルード(アルファベット順)
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <iterator>      //集合演算(積集合,和集合,差集合など)
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define FIR first    //pairの一つ目の要素
#define SEC second   //pairの二つ目の要素

signed main()
{
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll N, M;
    cin >> N >> M;

    vector<bool> step_one(N + 1, false), step_two(N + 1, false);
    REP(i, M)
    {
        ll a, b;
        cin >> a >> b;

        if (a == 1)
            step_one[b] = true;

        if (b == N)
            step_two[a] = true;
    }

    FOR(i, 1, N)
    {
        if (step_one[i] && step_two[i])
        {
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }

    cout << "IMPOSSIBLE" << endl;

    return 0;
}


Measured memory_bytes: 3120
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_pbds;
#define int long long int
#define pb push_back
#define vec vector<int>
#define fo(i, n) for (int i = 0; i < n; i++)
#define foo(i, a, b) for (int i = a; i < b; i++)
#define mp make_pair
#define deb(x) cout << #x << " --> " << x << endl;
#define deb1a(v) cout << #v << "--->" << endl; for (auto it : v)  cout << it << " "; cout << endl;
#define deb2a(v) cout << #v << "--->" << endl;for (auto it:v){for(auto it1 : it){cout << it1 << " ";}cout<< endl;}
#define deb3a(v) cout << #v << "-->" << endl; for(auto it:v){cout << it.fi << " " << it.se << endl;}
#define mod 1000000007
#define so(v) sort(v.begin(),v.end())
#define fi first
#define se second
#define db1(x) cout<<#x<<"="<<x<<endl
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<endl
int power(int x, unsigned int y, int p){ int res = 1;x = x % p;while (y > 0)  { if (y & 1)res = (res*x) % p;y = y>>1;  x = (x*x)% p;} return res;}
int mI(int a, int m)  {return power(a, m - 2, m);}
vector<vector<int>> dir = {{0, 1}, {0, -1}, {1, 0}, {-1, 0},{1,1},{1,-1},{-1,1},{-1,-1}};



void solve(){
    int n;
    cin >> n;
    cout << n + n * n + n * n * n;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin >> t;
    
    while(t--){
        solve();
    }
}

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

#define ll long long
#define vec vector<ll>
#define sortv(a); sort(a.begin(), a.end());
#define rev(a); reverse(a.begin(), a.end());
#define FOR(i,a,b) for (ll i = (ll)(a); i < (b); i++)
#define ROF(i,a,b) for (ll i = (ll)(b)-1; i >= (a); i--)

ll MOD = 1000000007;
ll INF = 1LL << 60;

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	ll n,k;cin>>n>>k;
	ll out=n%k;
	cout<<min(abs(out-k),out);
}

Measured memory_bytes: 256
def hightMapGenerator(text):
    height_map = []
    current_height = 0
    for letter in text:
        if letter == '\\':
            current_height -= 1
        elif letter == '/':
            current_height += 1
        else :
            pass
        height_map.append(current_height)
    return height_map

def pondChecker(text, height_map):
    # 判定
    all_ponds = []
    pond = []
    for n, letter in enumerate(text):
        if pond == []: # 池オブジェクトが空の場合
            if letter == '\\': # かつ、文字列がa の場合
                max_height = max(height_map[n:])
                if height_map[n] + 1 <= max_height: # 現在地よりも、高度の高い位置があるならば
                    start_index = n
                    pond.append(start_index) # スタート位置としてインデックスする
                else :
                    pass
        else : # 池オブジェクとにスタートが入っている場合
            if height_map[start_index] + 1 == height_map[n]: # スタートインデックスと同じ高さに来たら終わりをインデックスして、初期化
                end_index = n
                pond.append(end_index)
                all_ponds.append(pond)
                pond = []
    return all_ponds
    
def squareCalc(text, pond_height_map):
    square = 0
    current_height = max(pond_height_map)
    for n, letter in enumerate(text):
        if letter == '\\':
            square += current_height - pond_height_map[n] - 0.5
        elif letter == '/':
            square += current_height - pond_height_map[n] + 0.5
        else :
            square += current_height - pond_height_map[n]
    return int(square)

def slicedPondsGenerator(text, height_map, all_ponds):
    sliced_ponds_str = []
    sliced_height_map = []
    for pond in all_ponds:
        start = pond[0]
        end = pond[1] + 1
        sliced_pond_str = text[start:end]
        sliced_height = height_map[start:end]
        sliced_ponds_str.append(sliced_pond_str)
        sliced_height_map.append(sliced_height)
    return sliced_ponds_str, sliced_height_map

text = input()

if '/' not in text:
    print(0)
    print(0)
elif '\\' not in text:
    print(0)
    print(0)
else :
    height_map = hightMapGenerator(text)
    # print(height_map)
    all_ponds = pondChecker(text, height_map)
    if all_ponds == []:
        print(0)
        print(0)
    else :
        # print(all_ponds)
        sliced_ponds_str, sliced_height_map = slicedPondsGenerator(text, height_map, all_ponds)
        # print(ponds_str)
        # print(sliced_height_map)
        squares = []
        for n, pond_str in enumerate(sliced_ponds_str):
            square = squareCalc(pond_str, sliced_height_map[n])
            squares.append(square)

        size_of_ponds = sum(squares)
        num_of_ponds = len(squares)
        output = ' '.join([str(n) for n in squares])
        print(size_of_ponds)
        print(num_of_ponds,output)


Measured memory_bytes: 7208
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
using namespace std;
typedef long long ll;

vector<pair<int, int>> to[100010];
bool visited[100010];
ll dist[100010];
ll gcd(ll a, ll b)
{
   if (b == 0)
   {
       return a;
   }
    return gcd(b, a%b);
}
void dfs(int now, ll d) {
  visited[now] = true;
  dist[now] = d;
  for (auto p : to[now]) {
    if (visited[p.first]) continue;
    dfs(p.first, d + p.second);
  }
}

int main() {
    int n,m;
    cin >> n;
    map<string, int>mp;
    rep(i,0,n){
        string tmp;
        cin >> tmp;
        mp[tmp]++;
    }
    cout <<"AC x" <<" "<<mp["AC"] << endl;
    cout <<"WA x" <<" "<<mp["WA"] << endl;
    cout <<"TLE x" <<" "<<mp["TLE"] << endl;
    cout <<"RE x" <<" "<<mp["RE"] << endl;
    
   
    
    
    return 0;
}


Measured memory_bytes: 5980
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <bitset>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;

struct city_info {
    int p, y, i;
};

string format(int p, int n) {
    string tmp_p = to_string(p);
    if (tmp_p.size() < 6) {
        int size = tmp_p.size();
        for (int i = 0; i < 6 - size; i++) tmp_p = "0" + tmp_p;
    }
    string tmp_n = to_string(n);
    if (tmp_n.size() < 6) {
        int size = tmp_n.size();
        for (int i = 0; i < 6 - size; i++) tmp_n = "0" + tmp_n;
    }
    return tmp_p + tmp_n;
}

int main(int argc, const char * argv[]) {
    int N, M;
    cin >> N >> M;

    vector<city_info> info(M);
    for (int i = 0; i < M; i++) {
        int p, y;
        cin >> p >> y;
        info[i] = city_info{.p = p, .y = y, .i = i};
    }

    auto comp = [](const city_info &lhs, const city_info &rhs) {
        if (lhs.p == rhs.p) return lhs.y < rhs.y;
        return lhs.p < rhs.p;
    };
    sort(info.begin(), info.end(), comp);

    int count = 1;
    int prev = 0;
    vector<string> ids(M);
    for (int i = 0; i < M; i++) {
        city_info c = info[i];
        if (prev == c.p) {
            count += 1;
            ids[c.i] = format(c.p, count);
        } else {
            prev = c.p;
            count = 1;
            ids[c.i] = format(c.p, count);
        }
    }
    for (int i = 0; i < M; i++) {
        cout << ids[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 5368
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    rep(i, N) cin >> a[i];
    
    int ans = 0;
    REP(i, N) {
        if (a[i] == a[i - 1]) {
            ++ans;
            a[i] = 0;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> a(2 * M), b(N);
  for (int i = 0; i < 2 * M; i++)
     cin >> a[i];
  for (int i = 0; i < 2 * M; i++)
    for (int j = 0; j < N; j++)
      if (a[i] == j + 1) b[j]++;
  for (int i = 0; i < N; i++)
    cout << b[i] << endl;
}

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

fun readLn()=readLine()!!
fun readInt()=readLn().toInt()
fun readInts()=readLn().split(" ").map{it.toInt()}
fun readLong()=readLn().toLong()
fun readLongs()=readLn().split(" ").map{it.toLong()}

val out=mutableListOf<String>()
fun printLine(s:String){out.add(s)}
fun output(){println(out.joinToString("\n"))}

fun main(){
    var x=readLong()
    var A=1L
    var A5=1L
    var B5=0L
    while(A5-B5<=x){
        for(B in 0 until A){
            if(A5-B*B*B*B*B==x){
                printLine("$A $B")
                output()
                return
            }
        }
        B5=A5
        A++
        A5=A*A*A*A*A
    }
    A=1L;A5=1L
    while(A5<=x){
        for(B in 1..A){
            if(A5+B*B*B*B*B==x){
                printLine("$A ${-B}")
                output()
                return
            }
        }
        A++
        A5=A*A*A*A*A
    }
}

Measured memory_bytes: 36316
#include <bits/stdc++.h>
#include <algorithm>
#include <math.h>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define INF 999999999
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using llong = long long;
using namespace std;


int main(){
    llong n,m,a,sum=0,ans;
    cin >> n >> m;
    rep(i,m){
        cin >> a;
        sum += a;
    }
    ans = n-sum;
    if(ans >= 0){
        cout << ans << endl;
    }else{
        cout << "-1" << endl;
    }
}


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

import sys
input=sys.stdin.readline

n=int(input())
arr=list(map(int,input().split()))
ans=0
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            tmp=[arr[i],arr[j],arr[k]]
            tmp=sorted(tmp)
            s=set(tmp)
            if len(s)==3 and tmp[0]+tmp[1]>tmp[2]:
                ans+=1
print(ans)

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

#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif

template <class T>
struct SegmentTree{
  using F = function<T(T,T)>;
  F f;
  T inf;
  int n;
  vector<T> node;

  SegmentTree(vector<T> v,T inf,F f):inf(inf),f(f){
    n = 1; while(n < v.size()) n *= 2;
    node.resize(2*n-1,inf);
    for(int i = 0; i < v.size(); i++) node[i+n-1] = v[i];
    for(int i = n-2; i >= 0; i--) node[i] = f(node[2*i+1],node[2*i+2]);
  }

  void update(int k,T val){
    k += n-1;
    node[k] = val;
    while(k > 0){
      k = (k-1) / 2;
      node[k] = f(node[2*k+1],node[2*k+2]);
    }
  }

  T getval(int a,int b){ return getval(a,b,0,0,n); }
  T getval(int a,int b,int k,int l,int r){
    //区間[a, b)の値を返す
    if(r <= a || b <= l) return inf;
    if(a <= l && r <= b) return node[k];
    T vl = getval(a, b, 2*k+1, l, (l+r)/2);
    T vr = getval(a, b, 2*k+2, (l+r)/2, r);
    return f(vl, vr);
  }
};

signed main(){

  int n; cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }

  auto f = [&](int x,int y){
    if(x < y) return y;
    else return x;
  };
  SegmentTree<int> seg(a,-1,f);

  for(int i = 0; i < n; i++){
    cout << f(seg.getval(0,i),seg.getval(i+1,n)) << endl;
  }

  return 0;
}


Measured memory_bytes: 7424
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

ll mod(ll a){
  return (a % 1000000007);
}

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

ll nCr(ll n,ll r){
  if(r == 1) return n;
  else if(r == 0) return 1;
  else return nCr(n-1,r-1)*n/r;
}

int main(){
  ll n; cin >> n; ll ecnt = 0; ll ocnt = 0;
  
  rep(i,n){
    ll x; cin >> x; 
   
    if(x % 2 == 0) ecnt++;
    else ocnt++;
  }
  
  cout << pow(3,n) - pow(2,ecnt) << endl;
  
}


Measured memory_bytes: 256
def main():
    x, n = list(map(int, input().split()))
    if n == 0:
        print(x)
        exit()
    else:
        P = list(map(int, input().split()))
    S = set(range(102)) - set(P)
    ans = float('inf')
    ans_p = 0
    for s in S:
        r = abs(s - x)
        if r < ans:
            ans = r
            ans_p = s
        elif r == ans:
            if ans_p > s:
                ans_p = s
    print(ans_p)
if __name__ == '__main__':
    main()


Measured memory_bytes: 9216
import java.util.*;

class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		
		int n = sc.nextInt();
		Deque dq = new Deque();
		
		for (int i=0; i<n; i++) {
			int mode = sc.nextInt();
			if (mode == 0) {
				if (sc.nextInt() == 0) {
					dq.addFirst(sc.nextInt());
				}
				else {
					dq.addLast(sc.nextInt());
				}
			}
			else if (mode == 1) {
				System.out.println(dq.ar[dq.head+sc.nextInt()]);
			}
			else if (mode == 2) {
				if (sc.nextInt() == 0) {
					dq.removeFirst();
				}
				else {
					dq.removeLast();
				}
			}
		}
		
	}
}

class Deque {
	int ar[];
	int head = 500000, tail = 499999;
	Deque() {
		ar = new int[1000000];
	}
	
	void addFirst(int n) {head--; ar[head] = n;}
	void addLast(int n) {tail++; ar[tail] = n;}
	void removeFirst() {head++;}
	void removeLast() {tail--;}
}


Measured memory_bytes: 299304
n=input()
n=int(n)
ac=0
wa=0
tle=0
re=0

for val in range(n):
  judge=input()
  if judge =='AC':
    ac=ac+1
  elif judge=='WA':
    wa=wa+1
  elif judge=='TLE':
    tle=tle+1
  elif judge=='RE':
    re=re+1
    
print('AC x',ac)
print('WA x',wa)
print('TLE x',tle)
print('RE x',re)

Measured memory_bytes: 9216
import bisect
from collections import deque

n = int(input())
Ps = []
for i in range(n):
    x1,y1,x2,y2 = map(int,input().split())
    if x1 == x2:
        if y2 < y1:
            y1,y2 = y2,y1
        Ps.append((y1,x1,"s",0))
        Ps.append((y2,x1,"g",2))

    else:
        if x2 < x1:
            x1,x2 = x2,x1
        Ps.append((y1,x1,x2,1))
Ps.sort(key=lambda x:x[3])
Ps.sort(key=lambda x:x[0])
N = len(Ps)
ans = 0
X = deque()

for i in range(N):
    query = Ps[i]
    if query[2] == "s":
        X.insert(bisect.bisect_left(X,query[1]), query[1])
    elif query[2] == "g":
        del X[bisect.bisect_left(X,query[1])]
    else:
        ans += bisect.bisect_left(X,query[1]) - bisect.bisect_right(X,query[2])

print(-ans)



Measured memory_bytes: 28508
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7 + 1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl

/*--------------------template--------------------*/

ll H, W, N;
int main()
{
	cin >> H >> W >> N;
	vi v(N), vans;
	REP(i, N) cin >> v[i];
	REP(i, N)
	{
		REP(j, v[i])
		{
			vans.push_back(i + 1);
		}
	}
	REP(i, H)
	{
		REP(j, W)
		{
			if (i % 2 == 0) {
				cout << vans[cnt] << ' ';
				cnt++;
			} else {
				ans = cnt + W - 1;
				cout << vans[ans] << ' ';
				cnt--;
				if (j == W - 1) {
					cnt += 2 * W;
				}
			}
		}
		cout << endl;
	}
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ff              first
#define ss              second
#define f(i,n)          for(int i=0;i<n;i++)
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define rightmostbit(x) __builtin_ffsll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         cout << fixed; cout << setprecision(x); cout << y;
#define pi              3.141592653589793238
#define mk(a,n)         int n;cin>>n;vi a(n);for(int i=0;i<n;i++) cin>>a[i]
#define w(x)            int x; cin>>x; while(x--)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
void g_b()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("error.txt", "w", stderr);
#endif
}
int32_t main()
{
	g_b();
	int n; cin >> n;
	int x = 102;
	vi ans(10005);
	for (int i = 1; i <= x; i++)
	{
		for (int j = 1; j <= x; j++)
		{
			for (int k = 1; k <= x; k++)
			{
				int p = i * i + j * j + k * k + i * j + j * k + k * i;
				if ( p < 10005) ans[p] += 1;
			}
		}
	}

	for (int i = 1; i <= n; i++)
		cout << ans	[i] << endl;
	return 0;

}



Measured memory_bytes: 3648
import scala.collection.mutable.Queue

object Main {
  val scan = new java.util.Scanner(System.in)
  def main(args: Array[String]) {
    val width  = scan.next().toInt
    val height = scan.next().toInt
    if (width != 0 || height != 0) {
      solve(width, height)
      main(args)
    }
  } 

  def solve(width: Int, height: Int) {
    var memo: Array[Array[Int]] = Array.fill(height*2-1, width*2-1)(100000000)
    memo(0)(0) = 0
    for ( i <- 0 until (height*2-1) by 2 ) {
      for ( j <- 0 until (width-1) ) memo(i)(j*2+1) = scan.next().toInt * -1
      if (i+1 < height*2-1) 
        for ( j <- 0 until width     ) memo(i+1)(j*2) = scan.next().toInt * -1
    }

    val q: Queue[(Int, Int)] = new Queue()
    q += ((0,0))
    while (!q.isEmpty) {
      val (cy, cx): (Int, Int) = q.dequeue
      val l: List[(Int, Int)] = List((-1, 0), (1, 0), (0, 1), (0, -1)) 
      for ( (i, j) <- l ) {
        val (nby, nbx) = (i+cy, j+cx)
        val (ny, nx) = (i+i+cy, j+j+cx)
        if (0<=ny && ny<(height*2-1) && 0<=nx && nx<(width*2-1) && memo(nby)(nbx) != -1) {
          if (memo(ny)(nx) > memo(cy)(cx) + 1) {
            memo(ny)(nx) = math.min(memo(ny)(nx), memo(cy)(cx) + 1)
            q += ((ny, nx))
          }
        }
      }
    }
    
    println(List(memo(height*2-2)(width*2-2)).map(x => if (x == 100000000) {0} else {x+1}).head)
  }
}


Measured memory_bytes: 120724
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

const int N = 1000;
ll vals[N];

int main() {
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < n; ++i) cin >> vals[i];

	vector<ll> sums;
	for (int i = 0; i < n; ++i) {
		ll cur = 0;
		for (int j = i; j < n; ++j) {
			cur += vals[j];
			sums.push_back(cur);
		}
	}

	ll res = 0;
	ll bit = (1ll<<60);

	while(bit > 0) {
		int cou = 0;
		for (int i = 0; i < sums.size(); ++i) {
			if (sums[i] & bit) ++cou;
		}
		if (cou >= k) {
			res |= bit;
			for (int i = 0; i < sums.size(); ++i) {
				if (! (sums[i] & bit)) {
					swap(sums[i], sums.back());
					sums.pop_back();
					--i;
				}
			}
		}
		bit >>= 1;
	}

	cout << res << '\n';
}

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

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  long long ans = 0;
  // 1 <= a, b <= n
  // a % b >= k
  for (int b = 1; b <= n; b++) {
    int p = n/b;
    int add = 0;
    add += p * max(0, b-k);
    add += max(0, n % b - k + 1);
    if (k == 0) { add--; }
    ans += add;
  }

  cout << ans << endl;

  return 0;
}

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

int main(){
  char s[3];
  scanf("%s",s);
  
  if(s[0]=='a'&&s[1]=='b'&&s[2]=='c')
    printf("Yes");
  else if(s[0]=='a'&&s[2]=='b'&&s[1]=='c')
    printf("Yes");
  else if(s[1]=='a'&&s[0]=='b'&&s[2]=='c')
    printf("Yes");
  else if(s[1]=='a'&&s[2]=='b'&&s[0]=='c')
    printf("Yes");
  else if(s[2]=='a'&&s[1]=='b'&&s[0]=='c')
    printf("Yes");
  else if(s[2]=='a'&&s[0]=='b'&&s[1]=='c')
    printf("Yes");
  else printf("No");
}

Measured memory_bytes: 128
def kukan(n, a):
    dp = [[0] * n for _ in range(n)]
    for i in range(n):
        dp[i][i] = a[i]
    for i in range(n - 2, -1, -1):
        g0 = dp[i]
        g1 = dp[i + 1]
        for j in range(i + 1, n):
            L = a[i] - g1[j]
            R = a[j] - g0[j - 1]
            dp[i][j] = L if L > R else R
    return dp[0][n - 1]


n = int(input())
a = list(map(int, input().split()))
print(kukan(n, a))


Measured memory_bytes: 234176