akhauriyash/Code-Regression huggingface dataset:
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
using namespace std;

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

	deque<int> dq;
	int q;
	cin >> q;
	REP(i, q) {
		int mode;
		cin >> mode;
		switch(mode) {
			case 0:
				int d, x;
				cin >> d >> x;
				if(d == 0) dq.push_front(x);
				else dq.push_back(x);
				break;
			case 1:
				int p;
				cin >> p;
				cout << dq.at(p) << endl;
				break;
			case 2:
				int d2;
				cin >> d2;
				if(d2 == 0) dq.pop_front();
				else dq.pop_back();
				break;
		}
	}
}


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

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

    int x = a[0];
    int ans = 1;
    for(int i = 1; i < n; i++) {
        if(x > a[i]) {
            x = a[i];
            ans ++;
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 1024
from heapq import heappush, heappop, heapify
import sys
input = sys.stdin.readline

N = int(input())
a = [int(i) for i in input().split()]

dpl = [0] * (N * 3)
dpr = [0] * (N * 3)
l = [a[i] for i in range(N)]
r = [-a[i] for i in range(2*N, 3*N)]
heapify(l)
heapify(r)

dpl[N-1] = sum(l)
for i in range(N, 2*N) :
    heappush(l, a[i])
    m = heappop(l)
    dpl[i] = dpl[i-1] + a[i] - m
    
dpr[2*N] = -sum(r)
for i in range(2*N-1, N-1, -1) :
    heappush(r, -a[i])
    M = heappop(r)
    dpr[i] = dpr[i+1] + a[i] + M

M = -float('inf')
for i in range(N-1, 2*N) :
    M = max(M, dpl[i]-dpr[i+1])
print(M)
    

Measured memory_bytes: 122384
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int lld;

const lld mod = 1e9+7;
const lld INF = 1e9;
//const lld MAXN = 1e9;

int main()
{
	lld m,n,k;

	cin >> n >> m >> k;

	for(int i = 0; i <= n; i++)
	{
		for(int j = 0; j <= m; j++)
		{
			if (i * m + j * n - 2 * i * j == k)
			{
				cout << "Yes" << endl;
				return 0;
			}
		}
	}

	cout << "No" << endl;

	return 0;
}

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

int main() {
  int h, w;
  cin >> h >> w;
  
  string pic[h];
  for (int i = 0; i < h; i++) cin >> pic[i];
  
  for (int i = 0; i < w + 2; i++) cout << '#';
  cout << endl;
  for (int i = 0; i < h; i++) {
    cout << '#';
    cout << pic[i];
    cout << '#' << endl;
  }
  for (int i = 0; i < w + 2; i++) cout << '#';
  cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int l = a + b;
    int r = c + d;
    if(l == r) cout << "Balanced" << endl;
    else if(l > r) cout << "Left" << endl;
    else cout << "Right" << endl;
}


Measured memory_bytes: 256
// ConsoleApplication1.cpp : Defines the entry point for the console application.
//

#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <queue>

#define MAXCHAR 255

using namespace std;

int _MAX = 0;
int maxIndex = 0;
vector<int> integers;

int main()
{
	int n;
	int k;
	cin >> n >>k;

	int currentTotal = 0;
	for (int i = 0; i < n; i++)
	{
		int input = 0;
		cin >> input;
		integers.push_back(input);
		if (i < k)
		{
			currentTotal += input;
			_MAX = currentTotal;
			continue;
		}
		currentTotal -= integers[i - k];
		currentTotal += input;
		if (currentTotal >= _MAX)
		{
			_MAX = currentTotal;
			maxIndex = i - k + 1;
		}
	}
	double output = 0;
	for (int i = maxIndex; i < maxIndex + k; i++)
	{
		double a = integers[i];
		output += (a + 1) / 2;
	}
	cout.precision(15);
	cout << fixed <<output << endl;
	// change number of digits for cout
	return 0;
}

Measured memory_bytes: 1400
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<i_i, int> p_i;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
template<class T> using vv=vector<vector< T > >;
typedef deque<int> di;
typedef deque<deque<int> > ddi;

// cout vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len - 1) s << "\t";
    }
    return s;
}

// cout 2-dimentional vector
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
    int len = vv.size();
    for (int i = 0; i < len; ++i) {
        s << vv[i] << endl;
    }
    return s;
}

vvi board;
vi gl;
int ans;

void dfs( vi current, int moves ) {
  // procedure of move
  if ( moves >= 10 ) { return; }
  vvi search = {{1,0}, {0,1}, {-1,0}, {0,-1}};
  for ( auto v : search ) {
    vi next = {current[0]+v[0], current[1]+v[1]};
    if ( board[next[0]][next[1]] < 0 ) {
      continue;
    }
    next = current;
    while ( board[next[0] + v[0]][next[1] + v[1]] >= 0 ) {
      next[0] += v[0];
      next[1] += v[1];
      if ( next[0] == gl[0] && next[1] == gl[1] ) {
        ans = min(ans, moves + 1);
        return;
      }
    }
    if ( board[next[0] + v[0]][next[1] + v[1]] == -2 ) {
      continue;
    }
    if ( board[next[0] + v[0]][next[1] + v[1]] == -1 ) {
      board[next[0] + v[0]][next[1] + v[1]] = 0;
      dfs( next, moves + 1 );
      board[next[0] + v[0]][next[1] + v[1]] = -1;
    }
  }
  return;
}

int main() {
  while (true) {
    int w, h;
    cin >> w >> h;
    if ( h == 0 ) { break; }
    board.clear();
    board.resize(h+2, vi(w+2, -2));
    vi st(2); // h, w
    gl.clear();
    gl.resize(2); // h, w
    for (int ih = 1; ih <= h; ih++) {
      for (int iw = 1; iw <= w; iw++) {
        int tmp;
        cin >> tmp;
        if ( tmp == 1 ) {
          tmp = -1;
        }
        if ( tmp == 2 ) {
          st[0] = ih;
          st[1] = iw;
          board[ih][iw] = 0;
        } else if ( tmp == 3 ) {
          gl[0] = ih;
          gl[1] = iw;
          board[ih][iw] = 0;
        } else {
          board[ih][iw] = tmp;
        }
      }
    }
    ans = 100;
    dfs( st, 0 );
    if ( ans > 10 ) {
      ans = -1;
    }

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

Measured memory_bytes: 3080
import sys, math
from functools import lru_cache
from collections import defaultdict
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

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

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N, K = mi()
    P = list(mi())
    C = list(mi())

    # loopを格納
    loops = []
    # 数えたかどうか
    done = [False]*N
    
    for i in range(N):
        # もう数えているならskip
        if done[i]:
            continue

        now = P[i]-1
        T = 1
        s = C[now]
        lst = [now]

        done[now] = True

        # 戻ってくるまでループ
        while now != i:
            now = P[now]-1
            T += 1
            s += C[now]
            lst.append(now)

            done[now] = True

        loops.append((T, s, lst))

    # print(loops)

    ans = -math.inf

    # 各loopごと
    for loop in loops:
        # loopの周期、総和、構成要素を取得
        T, s, lst = loop

        if s <= 0:
            m = -math.inf
            for v in lst:
                now = v
                ss = 0
                for _ in range(min(K, T)):
                    now = P[now]-1
                    ss += C[now]
                    m = max(m, ss)

            ans = max(ans, m)

        else:
            n = max(K//T-1, 0)
            rest = K-n*T
            m = -math.inf

            for v in lst:
                now = v
                ss = 0
                for _ in range(rest):
                    now = P[now]-1
                    ss += C[now]
                    m = max(m, ss)
            
            ans = max(ans, m+n*s)
    print(ans)



if __name__ == '__main__':
    main()

Measured memory_bytes: 69480
n = int(input())
if n == 3:
  print(2)
  print(1, 3)
  print(2, 3)
else:
  ans = []
  core = [n//2-1, n//2, n//2+1, n//2+2]
  for i in range(4):
    for j in range(i+1, 4):
      if i+j != 3:
        ans.append((core[i], core[j]))
  key = n//2-2
  for i in range(key, 0, -1):
    key2 = 2*n//2-i+1
    if n%2:
      key2 -= 1
    for c in core:
      ans.append((i, c))
      ans.append((c, key2))
    core.append(i)
    core.append(key2)
    
  if n%2:
    for c in core:
      ans.append((c, n))
  print(len(ans))
  for a in ans:
    print(*a)
  

Measured memory_bytes: 43120
#include <iostream>

typedef long long ll;

#define FOR(i,a,b) for(ll i = (a);i < (b);++i)
#define REP(i,n) FOR(i,0,n)

#define debug(x) cout << #x << "=" << x << endl;

using namespace std;

int main(void){

    int N;
    cin >> N;

    int a[1000010];

    fill(a,a+N,0);

    REP(i,N){
        int tmp;
        cin >> tmp;
        
        if(tmp == 0){
            a[tmp]++;
            a[tmp+1]++;
        }else{
            a[tmp-1]++;
            a[tmp]++;
            a[tmp+1]++;
        }
    }

    int ans = 1;

    REP(i,N){
        if(a[i] > 0){
            ans = max(ans,a[i]);
        }
    }

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


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

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

int main()
{
  cout << fixed << setprecision(10);
  int S, W;
  cin >> S >> W;
  if(S>W)
  {
    cout << "safe" << endl;
  }
  else
  {
    cout << "unsafe" << endl;
  }
  return 0;
}

Measured memory_bytes: 3624
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

# 解説AC
# https://twitter.com/maspy_stars/status/1185552225474498560
N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

C = list(np.bincount(A).tolist())
C.sort()
deleted = 0
S = N


def solve(k):
    global S, deleted

    k -= deleted
    while k > 0 and C[-1] > S // k:
        S -= C.pop()
        deleted += 1
        k -= 1
    if k > 0:
        return S // k
    return 0


for k in range(1, N + 1):
    print(solve(k))


Measured memory_bytes: 44752
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
using lint = long long;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	vector<int> a(N);
	for (int i = 0; i < N; i++) cin >> a[i];
	sort(a.begin(), a.end(), greater<int>());

	int A = 0, B = 0;
	for (int i = 0; i < N; i++) {
		A += a[i] * !(i & 1);
		B += a[i] *  (i & 1);
	}

	cout << A - B << "\n";

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  if (a == b) {
    cout << a * 2 << endl;
  } else {
    int m = max(a, b);
    cout << m * 2 - 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
# include "iostream"
# include "cstdio"

using namespace std;

const int maxm=5e3+10;
const long long Inf=1e15;

int N,M,P;
int A[maxm],B[maxm];
long long C[maxm],Dis[maxm];

int main(){
	register int i,j;
	scanf("%d%d%d",&N,&M,&P);
	for(i=2;i<=N;i++) Dis[i]=Inf;
	for(i=1;i<=M;i++) scanf("%d%d%lld",&A[i],&B[i],&C[i]),C[i]=P-C[i];
	for(i=1;i<=(N<<1);i++){
		for(j=1;j<=M;j++){
			if(Dis[B[j]]>Dis[A[j]]+C[j] && Dis[A[j]]<Inf){
				if(i<N) Dis[B[j]]=min(Inf,Dis[A[j]]+C[j]);
				else Dis[B[j]]=-Inf;
			}
		}
	}
	printf("%lld",Dis[N]==-Inf?-1:max(0ll,-Dis[N]));
	return 0;
}

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

int main(){
  int N,X[101],i,j,min=1<<30,sum=0;
  cin>>N;
  for(i=0;i<N;i++) cin>>X[i];
  
  for(i=1;i<=100;i++){
    sum=0;
    for(j=0;j<N;j++){
      sum+=(X[j]-i)*(X[j]-i);
    }
    if(sum<min)min=sum;
  }
  
  cout<<min<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;

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

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

const ll mod = 1e9+7;
const int INF = 5*1e3+10;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int solve(string s){
	int n = s.size();
	vector<vector<int>> dp(n+1,vector<int>(n+1,0));
	// string ret;
	int ans=0;
	for (int i = 1; i <= n; i++){
		for (int j = i+1; j <= n; j++){
			if (s[i-1] == s[j-1] && dp[i-1][j-1] < (j - i) ) { 
                dp[i][j] = dp[i-1][j-1] + 1; 
                if (dp[i][j] > ans) { 
                    ans = dp[i][j]; 
                } 
            }else dp[i][j] = 0; 
		}
	}
	return ans;
}

int main()
{
	int n;
	string s;
	cin>>n>>s;
	cout<<solve(s)<<endl;

	return 0;
}

Measured memory_bytes: 98176
const toInt = x=>parseInt(x,10);
const toIntArr = arr=>arr.map(x=>toInt(x));
const abs = x=>x>0?x:-x;
function min(){let rest = arguments,val=rest[0];for(let i=1;i<rest.length;i++)if(rest[i]<val)val = rest[i];return val}
function max(){let rest = arguments,val=rest[0];for(let i=1;i<rest.length;i++)if(rest[i]>val)val = rest[i];return val}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
 
function Main(inputText){
	let input = inputText.split('\n');
	input = input.map(e => toIntArr(e.split(' ')));
	let x = input[0][0], y = input[0][1];
	if(y%2||y<2*x||4*x<y){console.log('No');return 0;}
	console.log('Yes');
	return 0;
}

Measured memory_bytes: 29620
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <map>
#include <set>
#include <array>
#include <queue>
#include <string>
#include <vector>
#include <numeric>
#include <algorithm>
#include <functional>
#define MOD 1000000007
#define INF 11234567890
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;
typedef std::pair<int, int> P;

int N, M, a[51], b[51], c[51], d[51];

int main()
{
	in >> N >> M;
	rep(i, N) { in >> a[i] >> b[i]; }
	rep(i, M) { in >> c[i] >> d[i]; }

	rep(i, N)
	{
		int ans = 0;
		LL dis = INF;
		rep(j, M)
		{
			if (abs(a[i] - c[j]) + abs(b[i] - d[j]) < dis)
			{
				ans = j + 1;
				dis = abs(a[i] - c[j]) + abs(b[i] - d[j]);
			}
		}
		out << ans << std::endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double x1=sc.nextDouble();
        double y1=sc.nextDouble();
        double x2=sc.nextDouble();
        double y2=sc.nextDouble();
        double x3=x2-x1;
        double y3=y2-y1;
        double Lx,Ly,L=0;
        Lx=x3*x3;
        Ly=y3*y3;
        L=Lx+Ly;
        double k;
        k=Math.sqrt(L);
        System.out.println(k);
    }
}


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

int main () {
    int N, K; cin >> N >> K;
    string S; cin >> S;

    S[K-1] = tolower(S[K-1]);
    cout << S << endl;
}

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

int main() {
  int h, w;
  cin >> h >> w;
  while (!(h==0 && w==0)) {
    for (int i = 0; i < h; i++){
      for (int j = 0;  j < w ; j++) {
        if (i == 0 || i == h-1) { cout << "#";}
        else {
          if (j == 0 || j == w-1) { cout << "#"; }
          else {cout << ".";}
        }
      }
      cout << endl;
    }
    cout << endl;
    cin >> h >> w;
  }
}


Measured memory_bytes: 3084
#include <cstdio>
#include <algorithm>

using namespace std;

#define MAXN 100000

int T[4 * MAXN];
int a[MAXN],b[MAXN];

int solve(int id, int l, int r, int x){
    if(r < x) return 0;
    if(l >= x) return T[id];
    int mi = (l + r) >> 1;
    return max(solve(2 * id + 1, l, mi, x), solve(2 * id + 2, mi + 1, r, x));
}

void update(int id, int l, int r, int x, int val){
    if(l > x || r < x) return;
    if(l == r) T[id] = val;
    else{
        int mi = (l + r) >> 1;
        update(2 * id + 1, l, mi, x, val);
        update(2 * id + 2, mi + 1, r, x, val);
        T[id] = max(T[2 * id + 1], T[2 * id + 2]);
    }
}

int main(){
    int N;

    scanf("%d",&N);

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

    sort(b, b + N);
    
    for(int i = 0;i < N;++i){
        int cur = a[i];
        int lo = 0,hi = N - 1,mi;

        while(lo < hi){
            mi = (lo + hi) / 2;

            if(b[mi] < cur) lo = mi + 1;
            else hi = mi;
        }

        a[i] = lo;
    }
    
    int ans = 0;

    for(int i = 0;i < N;++i){
        int best = solve(0, 0, N - 1, a[i]);
        //int best=0;
        update(0, 0, N - 1, a[i], best + 1);
        ans = max(ans, best + 1);
    }

    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 1920
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
#define N 2019
bitset<N> dp[N],d2[N],a[N];
int main()
{
	int n;string s;
	cin>>n;
	rep(i,n){
		cin>>s;
		rep(j,i+1){
			if(s[j]=='0') a[j][i+1]=true;else a[i+1][j]=true;
		}
	}
	//rep(i,n) rep(j,n) cout<<i<<j<<a[i][j]<<endl;
	rep(i,n) dp[i][i]=d2[i][i]=true;
	REP(j,1,n){
		rep(i,n){
			int k=i+j;if(k>=n) continue;
			if((dp[i]&d2[k-1]&a[k]).any()) dp[i][k]=true;
			if((dp[i+1]&d2[k]&a[i]).any()) d2[k][i]=true;
			//cout<<i<<k<<dp[i][k]<<d2[k][i]<<endl;
		}
	}
	int out=0;
	rep(i,n) if((dp[0][i]&d2[n-1][i])) out++;
	cout<<out<<endl;
}


Measured memory_bytes: 1920
function MainB(input){
    const num = input.split('').map(Number);
    if(num.length === 1 && num===0){
        console.log('Yes');
    }
    const sum = num.reduce((a,b)=> a+b);
    console.log(sum%9==0 ? 'Yes' : 'No');
}
MainB(require("fs").readFileSync("/dev/stdin", "utf8").trim());


Measured memory_bytes: 35264
#include<iostream>
#include<functional>
using namespace std;
int main(){
  string s;
  int a=0,b=0;
  cin>>s;
  for(int i=0;i<s.size();i++){
    if(s[i]=='0')
      a++;
    else
      b++;
  }
  cout<<min(a,b)*2<<endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
using namespace std;
const int MOD = 1000000007;
const long long INF = 1000000000000000000;
typedef pair<int, int> P;
typedef unsigned int ui;
typedef long long ll;
int main(){
	int C;
	int c[3][3];
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> C;
			c[i][j] = C;
		}
	}
	int t1 = c[0][1] + c[0][2] + c[1][0] + c[2][0] - c[1][2] - c[2][1];
	int t2 = c[0][1] + c[2][1] + c[1][0] + c[1][2] - c[0][2] - c[2][0];
	int t3 = c[0][2] + c[1][2] + c[2][0] + c[2][1] - c[0][1] - c[1][0];
	if (t1 == 2*c[0][0] && t2 == 2*c[1][1] && t3 == 2*c[2][2]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	char nyaa;
	cin >> nyaa;
	return 0;
}


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

LL weight[200],value[200];
LL dp[107][100005];

LL Solve(LL idx, LL n, LL w){
	if(idx == n)return 0;
	
	if(dp[idx][w] != -1)return dp[idx][w];
	
	LL ans = 0;
	if(w < weight[idx]) ans = Solve(idx+1, n, w);
	else ans = max(value[idx] + Solve(idx+1, n, w - weight[idx]), Solve(idx+1, n, w));
	return dp[idx][w] = ans;
}

int main(){
	LL n,w; cin>>n>>w;
	
	memset(dp,-1,sizeof(dp));
	for(LL i = 0; i < n; i++){
		cin>>weight[i]>>value[i];
	}
	cout<<Solve(0,n,w)<<endl;
	return 0;
}

Measured memory_bytes: 83840
#include <stdio.h>
int main(){
  int n,m,c,ans = 0;
  scanf("%d %d %d",&n,&m,&c);
  int b[m],a[n][m];
  for(int i = 0;i < m;i++){
    scanf("%d",&b[i]);
  }
  for(int i = 0;i < n;i++){
    int cnt = 0;
    for(int j = 0;j < m;j++){
      scanf("%d",&a[i][j]);
      cnt += a[i][j] * b[j];
    }
    if(cnt > -c){
      ans++;
    }
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 128
import fractions

n, ma, mb = map(int,input().split())
a = [0] * (n + 1)
b = [0] * (n + 1)
c = [0] * (n + 1)
for i in range(1, n + 1):
    a[i], b[i], c[i] = map(int,input().split())

#iまでの薬品で、aがj(g),bがk(g)となるときの最小コスト
dp = [[[10 ** 15 for i in range(n + 1)] for j in range(401)] \
    for k in range(401)]

dp[0][0][0] = 0
sa = [0] * (n + 1)
sb = [0] * (n + 1)

for i in range(1, n + 1):
    for j in range(401):
        for k in range(401):
            if j < a[i] or k < b[i]:
                dp[k][j][i] = dp[k][j][i - 1]
            else:
                dp[k][j][i] = min(dp[k][j][i - 1], \
                    dp[k - b[i]][j - a[i]][i - 1] + c[i])

i = 1
ans = 10 ** 15
while True:
    if i * ma > 400 or i * mb > 400:
        break
    ans = min(ans, dp[i * mb][i * ma][n])
    i += 1

if ans == 10 ** 15:
    ans = -1

print(ans)

"""
import fractions

n, ma, mb = map(int,input().split())
a = [0] * (n + 1)
b = [0] * (n + 1)
c = [0] * (n + 1)
for i in range(1, n + 1):
    a[i], b[i], c[i] = map(int,input().split())

#iまでの薬品で、aがj(g),bがk(g)となるときの最小コスト
dp = [[[10 ** 15 for i in range(n + 1)] for j in range(401)] \
    for k in range(401)]

dp[0][0][0] = 0
sa = [0] * (n + 1)
sb = [0] * (n + 1)

for i in range(1, n + 1):
    sa[i] = sa[i - 1] + a[i]
    sb[i] = sb[i - 1] + b[i]

for i in range(1, n + 1):
    for j in range(sa[i] + 1):
        for k in range(sb[i] + 1):
            if j < a[i] or k < b[i]:
                dp[k][j][i] = dp[k][j][i - 1]
            else:
                dp[k][j][i] = min(dp[k][j][i - 1], \
                    dp[k - b[i]][j - a[i]][i - 1] + c[i])

i = 1
ans = 10 ** 15
while True:
    if i * ma > 400 or i * mb > 400:
        break
    ans = min(ans, dp[i * mb][i * ma][n])
    i += 1

if ans == 10 ** 15:
    ans = -1

print(ans)
"""


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

#define REP(i, n) for(int (i) = 0; (i) < (int)(n); (i)++)
#define REPR(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for(int (i) = (m); (i) < (n); (i)++)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define INF 1e9

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 (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;

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

    if (B % A == 0)
    {
        cout << A+B << endl;
    }
    else
    {
        cout << B-A << endl;
    }

    return 0;
}


Measured memory_bytes: 256
N = int(input())
li = list('abcdefghijklmnopqrstuvwxyz')
ans = []
count = 0
num = 0
i = 1
while count < N:
    count += 26 ** i
    num += 1
    i += 1
for j in range(1, num):
    N -= 26 ** j
N -= 1
for j in range(num):
    div, mod = divmod(N, 26)
    ans.append(li[mod])
    N = div
ans = ans[::-1]
for a in ans:
    print(a, end='')


Measured memory_bytes: 9200
#import pysnooper
#import numpy
#import os,re,sys,operator
from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations
from sys import stdin,setrecursionlimit
#from copy import deepcopy
import heapq
#import math
#import string
setrecursionlimit(10**6)
input=stdin.readline

h,w,a,b=map(int,input().split())
ans=[]
for i in range(b):
    ans.append("1"*a+"0"*(w-a))
for i in range(h-b):
    ans.append("0"*a+"1"*(w-a))
print(*ans,sep="\n")

Measured memory_bytes: 5364
n=int(input())
l=[0,0]
from collections import Counter as co
for k,a in co(list(map(int,input().split()))).items():
    if a>=4:l+=[k,k]
    elif a>=2:l.append(k)
    l.sort()
    l=l[-2:]

print(l[0]*l[1])

Measured memory_bytes: 18600
#include <stdio.h>
#include <math.h>

#include <iostream>
#include <vector>
#include <algorithm>

int H, W, N;

int main()
{
	scanf("%d", &H);
	scanf("%d", &W);
	scanf("%d", &N);

	int once_paint_num = H;

	if( H < W ) once_paint_num = W;

	int num = N / once_paint_num;

	printf("%d\n", (N % once_paint_num == 0) ? num : num + 1);

	return 0;
}


Measured memory_bytes: 256
//
//  respect the past, embrace the future
//

#include  <algorithm>
#include  <iostream>
#include  <climits>
#include  <cstdlib>
#include  <cstring>
#include  <cmath>
#include  <cstdio>
#include  <unordered_map>
#include  <map>
#include  <set>
#include  <stack>
#include  <string>
#include  <vector>
#include  <queue>

using namespace :: std;

using vpll = vector <pair <long long, long long> >;
using pll = pair <long long, long long>;
using vll = vector <long long>;
using ll = long long;

#define W (ll) (5e3 + 7)
#define N (ll) (2e6 + 7)
#define M (ll) (1e9 + 7)
#define INF (ll) (2e18)
#define F first
#define S second

inline void fastInputOutput () {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
}

inline void ReadWriteFromFile () {
  freopen("../in.txt", "r", stdin);
  freopen("../out.txt", "w", stdout);
}

int n, m, a, b, c, ans[N];
vpll v[N];
bool h[N];

void f (ll n, ll s = 0) { 
  if (h[n]) return;
  h[n] = 1;
  ans[n] = s & 1;
  for (auto i : v[n])
    if (!h[i.first])
      f(i.first, s + i.second);
}

int32_t main (int argc, char *argv[]) {
  fastInputOutput();
  // ReadWriteFromFile();
  
  cin >> n;
  for (int i = 1; i <= n - 1; i++) {
    cin >> a >> b >> c;
    v[a].push_back({b, c});
    v[b].push_back({a, c});
  }
  f(1);
  for (int i = 1; i <= n; i++)
    cout << ans[i] << '\n';
}

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

#define INF 1001001001
#define MAX 200005

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n+1), d(n+1);
  rep(i,n) cin >> a[i], c[a[i]]++;
  rep(i,n) cin >> b[i], d[b[i]]++;
  rep(i,n+1) if (c[i]+d[i]>n) {
    cout << "No" << endl;
    return 0;
  }

  rep(i,n) c[i+1]+=c[i],d[i+1]+=d[i];
  int x = 0;
  rep(i,n) x = max(x,c[i+1]-d[i]);

  cout << "Yes" << endl;
  rep(i,n) {
    cout << b[(i+n-x)%n];
    if (i==n-1) cout << endl; else cout << " ";
  }

  return 0;
}


Measured memory_bytes: 6384
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define rep(i,n) for(int i=0;i<n;i++)
int gcd(int a, int b){
    int r=1;
    while(r!=0){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}
void revStr(char* str){
    int size = strlen(str);
    int i,j;
    char tmp = {0};
    for(i = 0, j = size - 1; i < size / 2; i++, j--){
        tmp = str[i];
        str[i] = str[j];
        str[j] = tmp;
    }return;
}
struct data{
    int a,b,c;
};

//降順
int compare_int(const void *a, const void *b)
{
    return *(int*)b - *(int*)a;
}
#define MAXSIZE 200000
int list[MAXSIZE];
int tail;

void Init(void){
    tail=0;
}
int Top(void){
    return 0;
}

int Next(int pos){
    if(pos<tail-1){
        return pos+1;
    }else{
        return -1;
    }
}
int Count(void){
    return tail;
}

int Item(int pos){
    if((pos>=0)&&(pos<tail)){
        return list[pos];
    }else{
        return 0;
    }
}
void Add(int value){
    if(tail<MAXSIZE){
        list[tail]=value;
        tail++;
    }
}
void Delete(int pos){
    if((pos>=0)&&(pos<tail)){
        int i;
        for(i=pos;i<tail-1;i++){
            list[i]=list[i+1];
        }
        tail--;
    }
}

int main(){
    int N,M,C;
    scanf("%d%d%d",&N,&M,&C);
    int a[N][M];
    int b[M];
    int cnt=0;
    rep(i,M){
        scanf("%d",&b[i]);
    }
    rep(i,N){
        rep(j,M){
            scanf("%d",&a[i][j]);
        }
    }
    rep(i,N){
        int sum=0;
        rep(j,M){
            sum+=a[i][j]*b[j];
        }
        if(sum+C>0){
            cnt++;
        }else{
            ;
        }
    }
    printf("%d",cnt);
}


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

#define NDEBUG
#include <cassert>


typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define eb  emplace_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair

#define PQ(T) priority_queue<T>
#define RPQ(T) priority_queue<T,vector<T>,greater<T>>

template<class T> inline void amin(T & a, T const & b) { a = min(a, b); }
template<class T> inline void amax(T & a, T const & b) { a = max(a, b); }

inline ll square(ll x) { return x * x; }
inline ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }
template <typename T>
inline T mod(T a, T b) { return ((a % b) + b) % b; }



ll f(ll x, ll c, ll d){
    ll cw = x / c;
    ll dw = x / d;
    ll g = gcd(c,d);
    ll u = c/g * d;
    ll bw = x / u;
    return x - cw - dw + bw;
}

int main() {
    ll a,b,c,d; cin >> a >> b >> c >> d;
    ll ans = f(b,c,d);
    if (a > 1) ans -= f(a-1,c,d);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	char ch;
	while (1) {
		scanf("%c", &ch);

		if (ch >= 'A' && ch <= 'Z') {
			ch += 0x20;
		}

		else if (ch >= 'a' && ch <= 'z') {
			ch -= 0x20;
		}

		else if (ch == '\n') {
			break;
		}
		printf("%c", ch);
	}

	printf("\n");

	return(0);
}


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

set<string> st;

void insertSet(string str, int j) {
  string s1, s2;
  for(int i = 0; i < j; i++) {
    s1 += str[i];
  }
  for(; j < str.length(); j++) {
    s2 += str[j];
  }
  string rs1 = s1;
  string rs2 = s2;
  reverse(rs1.begin(), rs1.end());
  reverse(rs2.begin(), rs2.end());
  st.insert(s1+s2);
  st.insert(rs1+s2);
  st.insert(s1+rs2);
  st.insert(rs1+rs2);
  st.insert(s2+s1);
  st.insert(rs2+s1);
  st.insert(s2+rs1);
  st.insert(rs2+rs1);
}

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

  int m;
  cin >> m;
  string array[m];
  for(int i = 0; i < m; i++) {
    cin >> array[i];
  }

  for(int i = 0; i < m; i++) {
    for(int j = 1; j < array[i].length(); j++) {
      insertSet(array[i], j);
    }
    cout << st.size() << endl;
    st.erase(st.begin(), st.end());
  }
}



Measured memory_bytes: 3348
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;

int main(){
    string str;
    cin >> str;
    int n;
    cin >> n;
    for(int i=0;i<n;i++){
        string q;
        int a,b;
        cin >> q >> a >> b;
        if(q == "print"){
            cout << str.substr(a,b-a+1) << endl;
        } else if(q == "reverse"){
            reverse(str.begin()+a,str.begin()+b+1);
        } else if(q == "replace"){
            string p;
            cin >> p;
            str.replace(a,b-a+1,p);
        }
    }
}



Measured memory_bytes: 3212
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
const ll INF = 1LL << 60;

ll dp[110][200100];

int main() {
    ll N, W; cin >> N >> W;
    rep(i, N) {
        ll w, v; cin >> w >> v;
        rep(j, W+1) {
            chmax(dp[i+1][j], dp[i][j]);
            chmax(dp[i+1][j+w], dp[i][j] + v);
        }
    }
    cout << dp[N][W] << endl;
}

Measured memory_bytes: 114888
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds; 
using namespace std;
using   ll=long long;
using   ld=long double;

#define fast        	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ordered_set 	tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>

#define endl        	"\n"
#define pb          	push_back
#define mp          	make_pair
#define F           	first
#define S           	second
#define int             long long int
#define pll				pair<int , int>

#define ALL(v)      	v.begin(),v.end()
#define ALLR(v)     	v.rbegin(),v.rend()
#define pii         	3.14159265358979323
#define inf     		LLONG_MAX
#define ones(x)     	__builtin_popcount(x)
#define fill(a,b)   	memset(a,b,sizeof(a))
#define mod 			1000000007
#define hell            998244353 

ll mod_pow(ll a,ll b,ll m) 
{
    ll res = 1;
    while(b)	
    {
        if(b&1) 	
        {
        	res=(res*a) % m;
        }
        a=(a*a) % m;
        b>>=1;
    }
    return res;
}

ll mod_inverse(ll a) 
{
	return mod_pow(a , mod-2 , mod);
}

void solve()
{
	int n , m;
	
	cin >> n >> m;
	
	int nn;
	
	cin >> nn;
	
	int a[nn];
	
	for(int i = 0 ;i < nn; ++i) {
		cin >> a[i];
	}
	
	int ans[n+5][m+5];
	
	int x = 0;
	int y = 0;
	
	int rr = 1;
	int ll = 0;
	
	for(int i = 0; i < nn; ++i) {
		while(a[i] > 0) {
			ans[x][y] = i+1;
			a[i]--;
			
			if(rr) {
				y++;
				
				if(y == m) {
					x++;
					rr = 0;
					ll = 1;
					y--;
				}
			}
			else {
				y--;
				if(y == -1) {
					x++;
					rr = 1;
					ll = 0;
					y++;
				}
			}
		}
	}
	
	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < m; ++j) {
			cout << ans[i][j] << " ";
		}
		cout << endl;
	}
}

signed main() {
    fast;
    
    int t = 1;
    
	//cin >> t;
    
    while(t--) {
        solve();
    }
 
    return 0;
}


Measured memory_bytes: 3696
//problem_b.go

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	//"strings"
)

const (
	mod = int(1e9) + 7
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

// -----------------------------------------

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getIntSlice(n int) []int {
	ns := []int{}
	for i := 0; i < n; i++ {
		ns = append(ns, getInt())
	}
	return ns
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func getStringSlice(n int) []string {
	ss := []string{}
	for i := 0; i < n; i++ {
		ss = append(ss, getString())
	}
	return ss
}

// -----------------------------------------

// Sort Fanction

func sortIntSlice(ns []int) []int {
	sort.Sort(sort.IntSlice(ns))
	return ns
}

func rsortIntSlice(ns []int) []int {
	sort.Sort(sort.Reverse(sort.IntSlice(ns)))
	return ns
}

// -----------------------------------------

// Num Fanction

//numModPow(a, n, m) == a^n % m
func numModPow(a int, n int, m int) int {
	result := 1

	for n > 0 {
		if n%2 == 1 {
			result = (result * a) % m
		}

		a = (a * a) % m
		n >>= 1
	}

	return result
}

// numGcd(a, b) == gcd(a, b)
func numGcd(a int, b int) int {
	if b == 0 {
		return a
	}

	return numGcd(b, a%b)
}

// numLcm(a, b) == lcm(a, b)
func numLcm(a int, b int) int {
	return a * b / numGcd(a, b)
}

// numModInv(a, p) == a^(-1) % p
func numModInv(a int, p int) int {
	if a == 1 {
		return 1
	} else {
		return p - numModInv(p%a, p)*(p/a)%p
	}
}

// -----------------------------------------

func solve() {

	flag := true

	s := getString()
	n := len(s)

	for i := 0; i <= (n-1)/2; i++ {
		if s[i] != s[n-(1+i)] {
			flag = false
		}
	}

	s1 := s[0 : (n-1)/2]
	n1 := len(s1)

	for i := 0; i <= (n1-1)/2; i++ {
		if s1[i] != s1[n1-(1+i)] {
			flag = false
		}
	}

	s2 := s[((n+3)/2)-1:]
	n2 := len(s2)

	for i := 0; i <= (n2-1)/2; i++ {
		if s2[i] != s2[n2-(1+i)] {
			flag = false
		}
	}

	if flag {
		fmt.Fprintln(wr, "Yes")

	} else {
		fmt.Fprintln(wr, "No")
	}
}

// -----------------------------------------

func main() {
	maxBufSize := int(1e8)
	sc.Buffer(make([]byte, 4096), maxBufSize)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}


Measured memory_bytes: 640
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#define MAX_N 100001
#define INF 2147483647
#define REP(i,n) for(int i=0;i<(int)(n);i++)
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
using namespace std;
int main()
{
  int N;
  cin >> N;
  if(N % 2 == 0)
    cout << N << endl;
  else
    cout << N * 2 << endl;
  
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}



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

int get_gcd(int a, int b) {
    if (a % b == 0) return b;
    return get_gcd(b, a % b);
}

int main() {
    int a,b;
    while (cin>>a>>b) {
        if (a < b) {
            int tmp = a;
            a = b;
            b = tmp;
        }

        int gcd = get_gcd(a,b);

        int lcm = a / gcd * b;
        cout << gcd << " " << lcm << endl;

    }
    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define MAX 200
#define CMAX 100000
#define INF (1<<29)

int n, m, r;
ll c[MAX][MAX];

void floyd(){
	for(int k=0; k<n; k++){
		for(int i=0; i<n; i++){
			for(int j=0; j<n; j++){
				c[i][j]=min(c[i][j], c[i][k]+c[k][j]);
			}
		}
	}
	return;
}

int main(){
	cin >> n >> m >> r;
	int t[r];
	for(int i=0; i<r; i++){
		cin >> t[i];
		t[i]--;
	}
	sort(t, t+r);

	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			if(i==j) c[i][j]=0;
			else c[i][j]=INF;
		}
	}
	for(int i=0; i<m; i++){
		int a, b, x;
		cin >> a >> b >> x;
		a--; b--;
		c[a][b]=x;
		c[b][a]=x;
	}

	floyd();

	ll ans=-1;
	while(1){
		ll sum=0;
		for(int i=1; i<r; i++){
			sum+=c[t[i-1]][t[i]];
		}
		if(ans==-1) ans=sum;
		else ans=min(ans, sum);
		if(!next_permutation(t, t+r)) break;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
import sys
N, M = map(int, input().split())
ac = [0] * N
wa = [0] * N

for _ in range(M):
    p, s = sys.stdin.readline().split()
    p = int(p) - 1
    if s == "AC":
        ac[p] = 1
    else:
        if not ac[p]:
            wa[p] += 1
acnum = sum(ac)
wanum = sum([c for i, c in enumerate(wa) if ac[i] == 1])
print(acnum, wanum)

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define long long long 

double calcDis(pair<long int,long int> a, pair<long int,long int> b){
	return sqrt(pow(a.first - b.first,2) + pow(a.second - b.second,2));
}

int main(){
   IOS;

   long int n;
   cin>>n;

   vector<pair<long int,long int>> v(n);
   for(long int i = 0; i  < n; i++)
 	cin>>v[i].first>>v[i].second;
 	
  long int numWays = 1;
  for(long int i  = 1; i <= n; i++)
  	numWays *= i;

  vector<long int> p;
  double ans = 0;

  for(long int i = 0; i < n; i++)
  	p.push_back(i);

  for(long int i = 0; i < numWays; i++){
  	double dis = 0;
  	for(long int j = 0; j < p.size() - 1; j++){
  		dis += calcDis(v[p[j]],v[p[j+1]]);	
  	}
  	next_permutation(p.begin(),p.end());
  	ans += dis;
  }   	

  	ans /= numWays;
  	cout<<fixed<<setprecision(10)<<ans;
   return 0;
}

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

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a, i##_len=(b); i<i##_len; i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

#define all(box) box.begin(), box.end()

using namespace std;

using P = pair<int,int>;
using ll = long long;

const long long INF = LLONG_MAX/3;

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; }
inline void Yes (bool condition) { if(condition) { cout << "Yes" << endl; } else { cout << "No" << endl;} }

struct UnionFind{
	std::vector<int> par,siz;
	void init(int n){
		par.resize(n);
		for(int i=0;i<n;i++)par[i]=i;
		siz.resize(n,1);
	}
	UnionFind(int n){
		init(n);
	}
	int root(int n){
		if(par[n]==n)return n;
		else return par[n]=root(par[n]);
	}
	bool issame(int x,int y){
		return (root(x)==root(y));
	}
	bool marge(int a,int b){
		if(issame(a,b))return false;
		else{
			a=root(a),b=root(b);
			if(siz[a]<siz[b])swap(a,b);
			siz[b]+=siz[a];
			par[a]=par[b];
			return true;
		}
	}
	int size(int n){
		return siz[root(n)];
	}
};

long long gcd(long long a,long long b){
    if(b==0)return a;
    return gcd(b,a%b);
}
long long lcm(long long i,long long j){
    return i*(j/gcd(i,j));
}

const int MOD=998244353;
long long fac[510000], finv[510000], inv[510000];
long long MAX=510000;
bool COMinited=false;
long long COM(int n, int k){
	if(COMinited==false){
		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;
    	}
		COMinited=true;
	}
    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;
}
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}
template< typename T >
struct BinaryIndexedTree {
  vector< T > data;

  BinaryIndexedTree(int sz) {
    data.assign(++sz, 0);
  }

  T sum(int k) {
    T ret = 0;
    for(++k; k > 0; k -= k & -k) ret += data[k];
    return (ret);
  }

  void add(int k, T x) {
    for(++k; k < data.size(); k += k & -k) data[k] += x;
  }
};
int cnt(int m,int n){
	//cout<<m<<" "<<n<<endl;
	while(n%m==0){
		n/=m;
	}
	if((n-1)%m==0)return 1;
	else return 0;
}
signed main(){
	int n;
	cin>>n;
	int ret=0;
	for(int i=1;i<=sqrt(n);i++){
		if(n%i==0){
			int a=i,b=n/a;
			if(a!=1)ret+=cnt(a,n);
			if(a!=b)ret+=cnt(b,n);
		}
	}
	n--;
	for(int i=1;i<=sqrt(n);i++){
		if(n%i==0){
			int a=i,b=n/i;
			//cout<<a<<" "<<b<<endl;
			if(a!=1&&(n+1)%a!=0)ret++;
			if(b!=a&&(n+1)%b!=0)ret++;
		}
	}
	cout<<ret<<endl;
}


Measured memory_bytes: 256