akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#define N 8
#define F -1
#define NF 1
#define True 2
#define False 0
void putQueen(int);
void printBoard();
int row[N],col[N],dpos[15],dneg[15];
int x[N][N];

int main(){
  int k,r,c,i,j;

  for(i=0;i<N;i++){
    row[i]=F;
    col[i]=F;
  }
  for(i=0;i<2*N-1;i++){
    dpos[i]=F;
    dneg[i]=F;
  }
  
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      x[i][j]=False;
    }
  }
  scanf("%d",&k);

  for(i=0;i<k;i++){
    scanf("%d%d",&r,&c);
    x[r][c]=True;
  }
  
  putQueen(0);
  
  return 0;
    
}

void putQueen(int i){
  int j;
  if(i == N){
    printBoard();
    return;
  }
 
  for(j=0;j<N;j++){
    if(col[j] == NF || dpos[i+j] == NF || dneg[i-j+N-1]==NF){
      continue;
    }
    row[i]=j;
    col[j] = NF;
    dpos[i+j] = NF;
    dneg[i-j+N-1] = NF;
    putQueen(i+1);
    row[i] = F;
    col[j] = F;
    dpos[i+j] = F;
    dneg[i-j+N-1] = F;
  }
}

void printBoard(){
  int i,j;

  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(x[i][j]==True){
	if (row[i]!=j){
	  return;
	}
      }
    }
  }
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i]==j){
	printf("Q");
      }
      else printf(".");
    }
    printf("\n");
  }

}



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

#define int long long
#define MOD 1000000007

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T>
void print(T x)
{
    std::cout << x << '\n';
}
typedef long long ll;

int sum_l[200001];
int sum_r[200001];

void fun(int x)
{
    int temp = 0;
    int temp2 = 0;
    rep(i, x + 1)
    {
        temp += i;
        sum_l[i] = temp;
        temp2 += (x - i);
        sum_r[i] = temp2;
    }
}

signed main()
{
    ll n, k;
    cin >> n >> k;
    ll sum = 0;

    if (n < k)
    {
        cout << "1" << endl;
        return 0;
    }

    fun(n);

    for (int i = k; i <= n + 1; i++)
    {
        int temp = (sum_r[i - 1] - sum_l[i - 1] + 1) % MOD;

        sum += temp;
        sum %= MOD;
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 6748
#include<iostream>

using namespace std;

int main() {
	int H, W;

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

		if (H + W == 0)break;

		for (int i = 0; i < H; i++) {
			if (i == 0 || i == H - 1) {
				for (int j = 0; j < W; j++) {
					cout << "#";
				}
			}
			else {
				for (int j = 0; j < W; j++) {
					if (j == 0 || j == W - 1)
						cout << "#";
					else
						cout << ".";
				}
			}
			cout << endl;
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1152
#include<iostream>
using namespace std;
int Max(int a,int b,int c){
  if(a<b){
    if(b<c) return c;
    else return b;
  }
  else{
    if(a<c) return c;
    else return a;
  }
}
int Pow(int n,int m){
  int pow=1;
  for(int i=0;i<m;i++) pow*=n;
  return pow;
}
int main(){
  int a,b,c;
  cin >> a >> b >> c;
  int k;
  cin >> k;
  cout << a+b+c+Max(a,b,c)*Pow(2,k)-Max(a,b,c) << "\n";

  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
for i in range(n):
    if b[i] <= a[i]:
        ans += b[i]
    else:
        ans += a[i]
        b[i] -= a[i]
        if a[i+1] <= b[i]:
            ans += a[i+1]
            a[i+1] = 0
        else:
            ans += b[i]
            a[i+1] -= b[i]
print(ans)

Measured memory_bytes: 81892
N = int(input())
ashi = list(map(int, input().split()))
arr = [0]*N
arr[1] = abs(ashi[1]-ashi[0])

for i in range(2,N,1):
    arr[i] = min(arr[i-1]+abs(ashi[i]-ashi[i-1]),arr[i-2]+abs(ashi[i]-ashi[i-2]))

print(arr[N-1])


Measured memory_bytes: 13980
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair< int, int> P;
struct edge{ll to, cost; };

static const double EPS = 1e-8;
static const double PI = 3.141592653589;
static ll INF = 999999999999;
int mod = 1000000007;

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define MIN(a,b)    (a) < (b) ? (a):(b)
#define MAX(a,b)    (a) > (b) ? (a):(b)
#define debug(x) cerr << #x << " = " << x << endl;
int dx[] = {1,-1,0,0,1,-1,1,-1};
int dy[] = {0,0,1,-1,-1,1,1,-1};

using namespace std;


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


    int flag = -1;
    REP(i, s.size() - 2) {
        if (s[i] == s[i + 1]) {
            flag = i;
            break;
        }
        if (s[i] == s[i + 2]) {
            flag = i;
            break;
        }
        if (s[i + 2] == s[i + 1]) {
            flag = i;
            break;
        }

    }
    if(flag != -1){
        cout << flag + 1 << " " << flag + 3 << endl;
    }else{
        if(s.size() == 2 && s[1] == s[0]){
            cout << "1 2" << endl;
        }else
        cout << "-1 -1" << endl;


    }
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

typedef pair<string, int> P;

int main() {
    int N;
    cin >> N;
    vector<pair<P, int>> R(N);
    for (int i = 0; i < N; i++) {
        string s; int p;
        cin >> s >> p;
        R[i] = pair<P, int>(P(s, -p), i + 1);
    }

    sort(R.begin(), R.end());

    for (int i = 0; i < N; i++)
        cout << R[i].second << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include <numeric>
#include<queue>
#include<climits>


#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 LLONG_MAX / 2;
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;
typedef pair<ll,int> LL_IP;

const ll INF = LLONG_MAX;

#define ARRAY_MAX 100005
#define N_MAX 45
#define AB_MAX 15
#define INF 1e9

int dp[N_MAX][N_MAX * AB_MAX][N_MAX * AB_MAX];

int main(){

    int n,ma,mb;
    cin >> n >> ma >> mb;
    vector<int> a(n),b(n),c(n);
    REP(i,n){
        cin >> a[i] >> b[i] >> c[i];
    }

    for(int i = 0;i <= n;i++){
        for(int j = 0;j <= N_MAX*AB_MAX;j++){
            for(int k = 0;k <= N_MAX*AB_MAX;k++){
                dp[i][j][k] = INF;
            }
        }
    }


    dp[0][0][0] = 0;
    
    for(int i = 1;i <= n;i++){
        for(int j = 0;j <= N_MAX*AB_MAX;j++){
            for(int k = 0;k <= N_MAX*AB_MAX;k++){
                if(dp[i-1][j][k] == INF){
                    continue;
                }
                dp[i][j][k] = min(dp[i][j][k],dp[i-1][j][k]);
                dp[i][j+a[i-1]][k+b[i-1]] = min(dp[i][j+a[i-1]][k+b[i-1]],dp[i-1][j][k]+c[i-1]);
            }
        }
    }
    int ans = INF;

    for(int i = 1;i <= N_MAX*AB_MAX;i++){
        for(int j = 1;j <= N_MAX*AB_MAX;j++){
            if(i*mb == j*ma){
                ans = min(ans,dp[n][i][j]);
            }
        }
    }

    if(ans == INF){
        ans = -1;
    }
    cout << ans << endl;




    return 0;
}

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

#define int long long
#define fi first
#define se second
#define otp(n) cout << n;
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define ctv(v) rep(i,(v).size()) ct(v[i])
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define repv(i,v) for(int i=0;i<(v).size();i++)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define pb(n) push_back(n);

#define MAX 1000000007

int n,m;

main() {
    cin >> n >> m;
    if (n<m) swap(n,m);
    if (n==m) {
        int ans=1;
        rep1(i,n) ans = (ans*i)%MAX;
        ans = ((ans*ans)%MAX*2)%MAX;
        ct(ans)
    }
    else if (n==m+1) {
        int ans=1;
        rep1(i,n) ans = (ans*i)%MAX;
        rep1(i,m) ans = (ans*i)%MAX;
        ct(ans)
    }
    else ct(0)
}

Measured memory_bytes: 256
#十字で合流する場合
n=int(input())
ud=[[[],[]] for i in range(200001)]
rl=[[[],[]] for i in range(200001)]
from bisect import *
cross=[[dict(),dict()] for i in range(4)]
for i in range(n):
    x,y,u=input().split()
    x,y=int(x),int(y)
    if u=="U":
        ud[x][0].append(y)
        if x+y in cross[0][1]:
            cross[0][1][x+y].append(x)
        else:
            cross[0][1][x+y]=[x]
        if x-y in cross[1][1]:
            cross[1][1][x-y].append(x)
        else:
            cross[1][1][x-y]=[x]
    elif u=="D":
        ud[x][1].append(y)
        if x+y in cross[3][1]:
            cross[3][1][x+y].append(x)
        else:
            cross[3][1][x+y]=[x]
        if x-y in cross[2][1]:
            cross[2][1][x-y].append(x)
        else:
            cross[2][1][x-y]=[x]
    elif u=="R":
        rl[y][0].append(x)
        if x+y in cross[0][0]:
            cross[0][0][x+y].append(x)
        else:
            cross[0][0][x+y]=[x]
        if x-y in cross[2][0]:
            cross[2][0][x-y].append(x)
        else:
            cross[2][0][x-y]=[x]
    else:
        rl[y][1].append(x)
        if x+y in cross[3][0]:
            cross[3][0][x+y].append(x)
        else:
            cross[3][0][x+y]=[x]
        if x-y in cross[1][0]:
            cross[1][0][x-y].append(x)
        else:
            cross[1][0][x-y]=[x]

for i in range(200001):
    ud[i][0].sort()
    ud[i][1].sort()
    rl[i][0].sort()
    rl[i][1].sort()

ans=[]
for i in range(200001):
    l1,l2=len(ud[i][0]),len(ud[i][1])
    if l1 and l2:
        for j in ud[i][0]:
            b=bisect_left(ud[i][1],j)
            if b!=l2:
                ans.append(ud[i][1][b]-j)
    l1,l2=len(rl[i][0]),len(rl[i][1])
    if l1 and l2:
        for j in rl[i][0]:
            b=bisect_left(rl[i][1],j)
            if b!=l2:
                ans.append(rl[i][1][b]-j)

for i in range(4):
    for j in range(2):
        for k in cross[i][j]:
            cross[i][j][k].sort()

for i in range(4):
    for j in cross[i][1]:
        if j in cross[i][0]:
            l=len(cross[i][0][j])
            if i%2==1:
                for k in cross[i][1][j]:
                    b=bisect_left(cross[i][0][j],k)
                    if b!=l:
                        ans.append(2*cross[i][0][j][b]-2*k)
            else:
                for k in cross[i][1][j]:
                    b=bisect_right(cross[i][0][j],k)-1
                    if b!=-1:
                        ans.append(2*k-2*cross[i][0][j][b])

if len(ans):
    print(min(ans)*5)
else:
    print("SAFE")

Measured memory_bytes: 232160
//This code is written by Shammi Anand
#include<bits/stdc++.h>
using namespace std;

#define ll              long long
#define Max(a,b,c)      max((a),max((b),(c))
#define Min(a,b,c)      min(a,min(b,c))
#define pb              push_back
#define mp              make_pair
#define f               first
#define s               second
#define mod             1000000007
#define nl              "\n"
#define w(x)            int x; cin>>x; while(x--)

const int N = 1e5 + 5;
ll n, dp[N][4], days[N][4];

ll profit(int selected, int count) {
	if (count == 0) {
		return 0;
	}
	if (dp[count][selected] != -1) {
		return dp[count][selected];
	}
	if (selected == 0) {
		return dp[count][selected] = max(profit(1, count - 1) + days[count][1], max(profit(2, count - 1) + days[count][2], profit(3, count - 1) + days[count][3]));
	}
	if (selected == 1) {
		return dp[count][selected] = max(profit(2, count - 1) + days[count][2], profit(3, count - 1) + days[count][3]);
	}
	if (selected == 2) {
		return dp[count][selected] = max(profit(1, count - 1) + days[count][1], profit(3, count - 1) + days[count][3]);
	}
	if (selected == 3) {
		return dp[count][selected] = max(profit(2, count - 1) + days[count][2], profit(1, count - 1) + days[count][1]);
	}
	return 0;
}


int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> days[i][1] >> days[i][2] >> days[i][3];
	}
	memset(dp, -1 , sizeof(dp));
	cout << profit(0, n) << endl;
	return 0;
}

Measured memory_bytes: 17616
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {
	private	static	BufferedReader br = null;

	static {
		br = new BufferedReader(new InputStreamReader(System.in));
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		short[][]	map = null;
		int			num = 0;

		while ((num = parseNum()) != 0) {
			map = new short[num][num];
			fill(map);
		}
	}

	private static void fill(short[][] map) {
		int		max = map.length * map.length;
		int[]	pos = { map.length / 2, map.length / 2 + 1};

		map[pos[1]][pos[0]] = 1;
		for (int n = 2; n <= max; n++) {
			pos[0] = (pos[0] + 1) % map.length;
			pos[1] = (pos[1] + 1) % map.length;
			if (map[pos[1]][pos[0]] != 0) {
				pos[0] = (pos[0] + map.length - 1) % map.length;
				pos[1] = (pos[1] + 1) % map.length;
			}
			map[pos[1]][pos[0]] = (short)n;
		}

		for (int i = 0; i < map.length; i++) {
			for (int j = 0; j < map.length; j++) {
				System.out.printf("%4d", map[i][j]);
			}
			System.out.println("");
		}
	}

	private static int parseNum() {
		int		num   = 0;
		String	strIn = null;

		if ((strIn = parseStdin()) != null) {
			num = Integer.parseInt(strIn);
		}
		
		return num;
	}

	private static String parseStdin() {
		String	strNum = null;

		try {
			String line = br.readLine();
			if (line != null) {
				if (!line.isEmpty()) {
					strNum = line;
				}
			}
		}
		catch (IOException e) {}

		return strNum;
	}
}

Measured memory_bytes: 19780
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), A, sum = 0;
		for (int i = 0; i < N; ++i) {
			A = sc.nextInt();
			if (A % 2 == 1) ++sum;
		}
		sc.close();
		if (sum % 2 == 1) System.out.print("NO");
		else System.out.print("YES");
	}
}

Measured memory_bytes: 48616
#include<bits/stdc++.h>
#define rint register int 
#define ll long long 
using namespace std;
ll ans,A[101010];
int n;
int main(){
	cin>>n;
	for(rint i=1;i<=2*n;++i) cin>>A[i];
	sort(A+1,A+2*n+1);
	for(rint i=1;i<=2*n;i+=2) ans+=A[i];
	cout<<ans;  
	return 0;
}

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

using i64 = int64_t;

int main(){
    int n;
    cin >> n;
    cout << 0 << endl;
    string zero;
    cin >> zero;
    if(zero == "Vacant")return 0;
    int low = 0, high = n;
    for(int i=1;i<20;++i){
        int q = (low + high) / 2;
        cout << q << endl;
        string s;
        cin >> s;
        if(s == "Vacant")return 0;
        if(q % 2 == 0 && s == zero || q % 2 == 1 && s != zero)low = q;
        else high = q;
    }

    return 0;
}


Measured memory_bytes: 852
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <utility>
#include <numeric>
#include <functional>
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <algorithm>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define INF 1e9
#define MOD 1e9+7
#define ll long long

using namespace std;
int main(void){
    int n,m;
    cin>>n>>m;
    vector<vector<int>> v(n,vector<int>(n,0));
    rep(i,0,m){
        int to,from;
        cin>>to>>from;
        to--;from--;
        v[to][from]++;
        v[from][to]++;
    }
    
    rep(i,0,n){
        int count=0;
        rep(j,0,n){
            count+=v[i][j];
        }
        cout<<count<<endl;
    }
    
    
    
    return 0;
}


Measured memory_bytes: 256
import itertools

n=int(input())
div = 1
for i in range(1,n+1):
    	div*=i
xy = [[int(i) for i in input().split()] for i in range(n)]

_sum = 0

for _list in itertools.permutations([i for i in range(n)]):
	distance = 0
	for i in range(n-1):
    		distance += ((xy[_list[i]][0] - xy[_list[i+1]][0])**2 + (xy[_list[i]][1] - xy[_list[i+1]][1])**2)**0.5
	_sum += distance
print(_sum/div)

Measured memory_bytes: 3064
#include <stdio.h>

using namespace std;

int calcMax(int a,int b){
	int tmp;
	if(a > b){
		while(b != 0){
			tmp = b;
			b = a%b;
			a = tmp;
		}
		return a;
	}else{
		while(a != 0){
			tmp = a;
			a = b%a;
			b = tmp;
		}
		return b;
	}
}



int calcMin(int a,int b){
	int max_common = calcMax(a,b);
	return (a/max_common)*b;
}

int main(){
	int a,b;
	while(scanf("%d %d",&a,&b)!=EOF){
		printf("%d %d\n",calcMax(a,b),calcMin(a,b));
	}

    return 0;
}



Measured memory_bytes: 2724
#include <iostream>

using namespace std;

int main(){
    int n;
    cin >> n;
    int n4, n3, n2, n1;

    n4 = n / 1000;
    n = n - (n4 * 1000);
    n3 = n / 100;
    n = n - (n3 * 100);
    n2 = n / 10;
    n = n - (n2 * 10);
    n1 = n;

    int cnt = 0;

    if(n4 == 2){
        cnt = cnt + 1;
    }else{}

    if(n3 == 2){
        cnt = cnt + 1;
    }else{}

    if(n2 == 2){
        cnt = cnt + 1;
    }else{}

    if(n1 == 2){
        cnt = cnt + 1;
    }else{}
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int N; cin >> N;
	string s; cin >> s;
	vector<int>black(N, 0);
	rep(i, 0, N) {
		if (s[i] == '#')black[i]++;
	}
	rep(i, 1, N)black[i] += black[i - 1];
	int ans = min(black[N - 1], N - black[N - 1]);
	rep(i, 1, N) {
		chmin(ans, black[i - 1] + (N - i) - (black[N - 1] - black[i - 1]));
	}
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 1300
/**Lucky Boy**/
#include <bits/stdc++.h>
#define FOR(i, a, b) for (long long i = (a); i <= (b); ++i)
#define FORD(i, a, b) for (long long i = (a); i >= (b); --i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define maxc 1000000007
#define maxn 1003
#define maxm 500005
#define pii pair <int,int>
#define Task ""
template <typename T> inline void read(T &x){char c;bool nega=0;while((!isdigit(c=getchar()))&&(c!='-'));if(c=='-'){nega=1;c=getchar();}x=c-48;while(isdigit(c=getchar())) x=x*10+c-48;if(nega) x=-x;}
template <typename T> inline void writep(T x){if(x>9) writep(x/10);putchar(x%10+48);}
template <typename T> inline void write(T x){if(x<0){putchar('-');x=-x;}writep(x);putchar(' ');}
template <typename T> inline void writeln(T x){write(x);putchar('\n');}
using namespace std;
vector <int> ans;
int a[] = {3,5,7},n;
bool dd[10];
bool check(int x)
{
    memset(dd,0,sizeof dd);
    while (x)
    {
        dd[x % 10] = 1;
        x /= 10;
    }
    return dd[3] && dd[5] && dd[7];
}
void Dfs(int cur,int h)
{
    ++h;
    if (check(cur)) ans.pb(cur);
    if (h == 10) return;
    FOR(i,0,2) Dfs(cur * 10 + a[i],h);
}
int main()
{
    ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL);
    //freopen(Task".inp", "r",stdin);
    //freopen(Task".out", "w",stdout);
    Dfs(0,0);
    sort(ans.begin(),ans.end());
    cin >> n;
    int hh = 0;
    for (int v : ans)
        if (v > n) break;
        else ++hh;
    cout << hh;
    return 0;
}


Measured memory_bytes: 512
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int MaxN = 44, MaxC = 0x3f3f3f3f;

int dp[444][444];
int a[MaxN], b[MaxN], c[MaxN];

int n;

int main( void )
{
  int ma, mb;
  while (scanf("%d %d %d", &n, &ma, &mb) != EOF)
  {
    int res = MaxC;
    memset (dp, MaxC, sizeof dp);
    for (int i = 0; i < n; i++)
      scanf("%d %d %d", &a[i], &b[i], &c[i]);
    dp[0][0] = 0;
    for (int i = 0; i < n; i++)
      for (int j = 443; j >= a[i]; j--)
        for (int k = 443; k >= b[i]; k--)
        {
          dp[j][k] = min(dp[j][k], dp[j-a[i]][k-b[i]] + c[i]);
          if(j % ma == 0 && k % mb == 0 && j / ma == k / mb)
            res = min(res, dp[j][k]);
        }
  
    
    
    
    if (res >= MaxC)
      res = -1;
    printf("%d\n", res);
  }
  return 0;
}

Measured memory_bytes: 896
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        s: chars,
        t: chars
    }
    'outer: for i in 0..n + 1 {
        for j in i..n {
            if s[j] != t[j - i] {
                continue 'outer;
            }
        }
        println!("{}", i + n);
        return;
    }
}


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

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

const int INF = 1000000000;

int main(){
  int H,W;
  cin >> H >> W;
  int CH,CW, DH,DW;
  cin >> CH >> CW >> DH >> DW;
  CH--; CW--; DH--; DW--;
  vector< string > s(H);
  REP(i,H) cin >> s[i];

  REP(y,H) REP(x,W) d[y][x] = INF;
  d[CH][CW] = 0;

  queue< pair<int, int> > q, nq;
  nq.emplace( CH, CW );

  int step = 0;
  while(1) {
    if ( nq.empty() ) break;
    swap(q, nq);

    // BFS
    while( !q.empty() ) {
      auto v = q.front(); q.pop();
      int h = v.first;
      int w = v.second;
      // 5x5の範囲をしてnextキューに
      for(int iy=-2; iy<=2; iy++ )
        for(int ix=-2; ix<=2; ix++ ) {
          if (iy==0 && ix==0) continue;
          if (abs(iy)==1 && ix==0) continue;
          if (abs(ix)==1 && iy==0) continue;
          int ny = h + iy;
          int nx = w + ix;
          if ((nx < 0) || (nx >=W) || (ny < 0) || (ny >=H) ) continue;
          if ( (s[ny][nx] == '.') && (d[ny][nx] > d[h][w]+1)) {
            d[ny][nx] = d[h][w]+1;
            nq.emplace( ny, nx );
          }
        }
      // 普通に4方向にBFS
      REP(i,4) {
        int ny = h + dy[i];
        int nx = w + dx[i];
        if ((nx < 0) || (nx >=W) || (ny < 0) || (ny >=H) ) continue;
        if ( (s[ny][nx] == '.') && (d[ny][nx] > d[h][w])) {
          d[ny][nx] = d[h][w];
          q.emplace(ny, nx);
        }
      }
    }

//    REP(y,4) {
//      REP(x,4) cout << d[y][x] << " ";
//      cout << endl;
//    }
  }

  if ( d[DH][DW] == INF ) d[DH][DW] = -1;
  cout << d[DH][DW] << endl;
}


Measured memory_bytes: 9480
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		
		int rating = 0;
		if(400 <= x && x < 600) {
			rating = 8;
		} else if(600 <= x && x < 800){
			rating = 7;
		} else if(800 <= x && x < 1000) {
			rating = 6;
		} else if(1000 <= x && x < 1200) {
			rating = 5;
		} else if(1200 <= x && x < 1400) {
			rating = 4;
		} else if(1400 <= x && x < 1600) {
			rating = 3;
		} else if(1600 <= x && x < 1800) {
			rating = 2;
		} else if(1800 <= x && x < 2000) {
			rating = 1;
		} else {
			throw new IllegalArgumentException("レーティングが不正です。");
		}
		System.out.println(rating);
	}
}


Measured memory_bytes: 35724
#include<iostream>
using namespace std;
int main(){
	int color[]={0,0,0,0,0,0,0,0};
	int N;
	int A;
	int cnt=0;
	int ANS=0;
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>A;
		if(A<3200)color[A/400]+=1;
		else cnt++;
	}
	for(int i=0;i<8;i++){
		if(color[i]!=0)ANS++;
	}
	if(cnt==0&&ANS==0){
		cout<<"0"<<" "<<"0"<<endl;
		return 0;
	}
	if(ANS==0){
		cout<<"1 "<<cnt<<endl;
		return 0;
	}
	if(ANS==1){
		cout<<"1 "<<cnt+1<<endl;
		return 0;
	}
	cout<<ANS<<" "<<ANS+cnt<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  if ("SUN" == S) {
    cout << 7 << endl;
  }
  
  else if ("MON" == S) {
    cout << 6 << endl;
  }
  
  else if ("TUE" == S) {
    cout << 5 << endl;
  }
  
  else if ("WED" == S) {
    cout << 4 << endl;
  }
  
  else if ("THU" == S) {
    cout << 3 << endl;
  }
  
  else if ("FRI" == S) {
    cout << 2 << endl;
  }
  
  else if ("SAT" == S) {
    cout << 1 << endl;
  }
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);

/* -----  2019/06/16  Problem: ABC 130 A / Link: http://abc130.contest.atcoder.jp/tasks/abc130_a  ----- */


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

	int X, A; cin >> X >> A;
	if (X < A)cout << 0 << endl;
	else cout << 10 << endl;

	return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())





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

	long long n;
	long long ans = 0;
	cin >> n;
	
	for (long long mod = 1; mod * mod < n; mod++) {
		if ((n - mod) % mod == 0) {
			long long x = (n - mod) / mod;
			if (n / x == n % x)ans += x;
		}
	}

	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 256
N,K = map(int,input().split())

cnt=0
if K==0:
  cnt = N*N
else:
  for b in range(1,N+1):
    p=N//b
    q=N%b
    cnt += p * max(0, b-K)
    cnt += max(0,q-K+1)
    #print(p * max(0, b-K),max(0,q-K+1))
    
    
print(cnt)

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

using namespace std;

#define ll long long
#define forn(i, n) for (ll i = 0; i < (ll) n; ++i)
#define sz(a) static_cast<int>(a.size())

char buff[(int) 2e6+ 17];
const ll inf = (ll) 1e9 + 7ll;

const int maxn = (int) 1e5 + 17;

int n;
map<int, int> kek;

bool read() {
    if (scanf("%d", &n) != 1)
        return false;

    return true;
}

int req(int i) {
    printf("%d\n", i);
    fflush(stdout);
    scanf("%s", buff);
    string s = buff;

    if (s == "Vacant") {
        exit(0);
    } else if (s == "Male") {
        return 1;
    } else {
        return 0;
    }
}

void solve() {
    int l = 0, r = n - 1;
    kek[l] = req(l);
    kek[r] = req(r);

    while (l < r) {
        int m = (l + r) / 2;
        kek[m] = req(m);

        if ((kek[l] ^ kek[m]) != ((m - l) & 1))
            r = m;
        else
            l = m;
    }

    req(l);
}

int main() {
#if SEREZHKA
    //freopen("file.in", "r", stdin);
#endif

    //while (read())
    read();
        solve();

    return 0;
}


Measured memory_bytes: 852
m = int(input())
     
def fizz_buzz(i):
  fizz = i % 3
  buzz = i % 5
      
  return (fizz > 0) & (buzz > 0)
     
res = 0
     
for i in range(m):
  use_i = i+1
  if fizz_buzz(use_i):
    res += use_i
        
print(res)

Measured memory_bytes: 9116
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdlib>
#include<utility>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pi acos(-1)
using namespace std;
typedef pair<int,int> p;
typedef long long ll;

int main(){
	int a,b;
	cin>>a>>b;
	if(a%3==0 || b%3==0 || (a+b)%3==0)cout<<"Possible"<<endl;
	else cout<<"Impossible"<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, m, l = map(int, input().split())
    cost = [[f_inf] * n for _ in range(n)]
    for i in range(n):
        cost[i][i] = 0
    for _ in range(m):
        a, b, c = map(int, input().split())
        cost[a - 1][b - 1] = c
        cost[b - 1][a - 1] = c

    for k in range(n):
        for i in range(n):
            for j in range(n):
                cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j])

    res = [[f_inf] * n for _ in range(n)]
    for i in range(n):
        for j in range(n):
            if cost[i][j] <= l:
                res[i][j] = 1

    for k in range(n):
        for i in range(n):
            for j in range(n):
                res[i][j] = min(res[i][j], res[i][k] + res[k][j])

    q = int(input())
    for _ in range(q):
        s, t = map(int, input().split())
        print(-1 if res[s - 1][t - 1] == f_inf else res[s - 1][t - 1] - 1)


if __name__ == '__main__':
    resolve()


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

int main() {
  
  int A, B, C, K; cin >> A >> B >> C >> K;
  
  int maxNumber = max(A, max(B, C));
  
  int tmp = maxNumber;
  
  for (int i = 0; i < K; i++) tmp *= 2;
  
  cout << A + B + C + tmp - maxNumber << endl;
  
}

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

using namespace std;

int main()
{
	int n;
	cin >> n;
	int a[n];
	int ans = 1;
	int even= 0;
	for(int i = 0;i<n;i++)
		cin >> a[i],ans *= 3;
	for(int i = 0;i < n;i++)
		even += !(a[i]&1);

	cout << ans - (1<<even)	<< endl;
	return 0;
}

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

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

  char a[] = { 'A', 'C', 'G', 'T' };

  string s;
  cin >> s;

  int ans = 0, stroke = 0;

  for (auto c : s) {
    bool ok = false;

    for (int i = 0; i < 4; ++i) if (c == a[i]) ok = true;

    if (ok) ++stroke;
    else stroke = 0;

    ans = max(ans, stroke);
  }

  cout << ans << '\n';

  return (0);
}


Measured memory_bytes: 3660
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

using Graph = vector<vector<int>>;

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

    Graph tree(n + 1);
    vector<pair<int, int>> edgelist;

    for (int i = 0; i < n - 1; i++)
    {
        int a, b;
        cin >> a >> b;
        tree[a].push_back(b);
        tree[b].push_back(a);
        edgelist.push_back(make_pair(a, b));
    }

    int maxdeg = 0;
    int mdnode = 0;
    for (int v = 1; v <= n; v++)
    {
        if (maxdeg < (int)tree[v].size())
        {
            maxdeg = (int)tree[v].size();
            mdnode = v;
        }
    }

    vector<int> dist(n + 1, -1);
    queue<int> que;
    vector<int> color(n + 1, 0);
  
    dist[mdnode] = 0;
    que.push(mdnode);

    while (!que.empty())
    {
        int v = que.front();
        que.pop();
        int newcolor = 1;
        for (auto &&nv : tree[v])
        {
            if (dist[nv] != -1)
                continue;
            dist[nv] = dist[v] + 1;
            que.push(nv);

            if (newcolor == color[v])
                newcolor++;
            color[nv] = newcolor;
            newcolor++;
        }
    }

    cout << maxdeg << endl;
    for (auto &&pair : edgelist)
    {
        int c;
        if (dist[pair.first] > dist[pair.second])
            c = color[pair.first];
        else
            c = color[pair.second];
        cout << c << endl;
    }

    return 0;
}

Measured memory_bytes: 7668
#include <bits/stdc++.h>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

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

    cout << (n == m ? "Yes" : "No") << endl;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    int x, k, q;
    cin >> x >> k;
    vector<i_i> query;
    for(int i = 1; i <= k; i++){
        int r;
        cin >> r;
        query.push_back({r, -1});
    }
    cin >> q;
    for(int i = 1; i <= q; i++){
        int t, a;
        cin >> t >> a;
        query.push_back({t, a});
    }
    sort(query.begin(), query.end());
    int a = 0;
    int b = x;
    int c = 0;
    int now = 0;
    int direction = -1;
    int before;
    for(int index = 0; index < query.size(); index++){
        int maxi = b + c;
        int mini = a + c;
        before = now;
        now = query[index].first;
        int delta = now - before;
        {
            //cout << direction << " " << before << " " << now << " " << a << " " << b << " " << c << endl;
        }
        if(direction == -1){
            if(delta <= mini){
                c -= delta;
                //b += delta;
                //b = min(b, x - c);
             } else if(delta >= maxi){
                 a = 0;
                 b = 0;
                 c = 0;
             } else {
                 a = delta - c;
                 int delta2 = a + c;
                 //c = -a;
                 c -= delta2;
                 //b += delta2;
                 //b = min(b, x - c);
             }
        }
        if(direction == 1){
            if(delta <= (x - maxi)){
                c += delta;
                //a -= delta;
                //a = max(a, -c);
             } else if(delta >= (x - mini)){
                 a = 0;
                 b = 0;
                 c = x;
             } else {
                 //a = delta - c;
                 b = x - c - delta;
                 int delta2 = c - x + b;
                 //c = -a;
                 //c = x - b;
                 c -= delta2;
                 //a += delta2;
                 //a = max(a, -c);
                 //a = max(a, 0);
             }
        }
        if(query[index].second == -1){
            direction = -direction;
            continue;
        }
        int first = query[index].second;
        //continue;
        if(first < a){
            cout << a + c << endl;
        } else if(first < b){
            //cout << "a" << endl;
            //cout << first << " " << c << endl;
            cout << first + c << endl;
        } else {
            cout << b + c << endl;
        }
    }
    return 0;
}


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

//const double PI = acos(-1);
using ll = long long;
using ull = unsigned long long;
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;

#define REP(i,n) for (int i = 0; i < (n); i++)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second

string sa,sb;
int ca1[100010], cb1[100010], ca2[100010], cb2[100010];

bool ok(int a, int b, int c, int d) {

  int a1 = (ca1[b] - ca1[a-1])%3;
  int b1 = (cb1[b] - cb1[a-1])%3;
  int a2 = (ca2[d] - ca2[c-1])%3;
  int b2 = (cb2[d] - cb2[c-1])%3;

  return (a1+b1*2)%3 == (a2+b2*2)%3;
}

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

  cin >> sa >> sb;

  REP(i,sz(sa)) {
    ca1[i+1] = (sa[i] == 'A');
    cb1[i+1] = (sa[i] == 'B');
    ca1[i+1] += ca1[i];
    cb1[i+1] += cb1[i];
  }
  REP(i,sz(sb)) {
    ca2[i+1] = (sb[i] == 'A');
    cb2[i+1] = (sb[i] == 'B');
    ca2[i+1] += ca2[i];
    cb2[i+1] += cb2[i];
  }

  int q;
  cin >> q;
  while (q--) {
    int a,b,c,d;
    cin >>a>>b>>c>>d;
    cout << (ok(a,b,c,d)?"YES":"NO") << endl;
  }
  return 0;
}


Measured memory_bytes: 2512
# from pprint import pprint
# import math
# import collections

n = int(input())
# n, k = map(int, input().split(' '))
l = list(map(int, input().split(' ')))

ans = 0
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        for k in range(j + 1, n):
            if l[i] <= l[j] + l[k] and l[j] <= l[i] + l[k] and l[k] <= l[i] + l[j] and l[i] != l[j] and l[j] != l[k] and \
                    l[i] != l[k]:
                if max(l[i], l[j], l[k]) < (l[i] + l[j] + l[k]) / 2:
                    ans += 1
                    # print(l[i], l[j], l[k], i,j,k)

print(ans)


Measured memory_bytes: 9156
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X, i) ((X>>i)&1)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define r_all(a) (a).rbegin(), (a).rend()

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = (1<<30);
const ll INFL = (1L<<62);

int main() {
  int N; cin >> N;
  vvi abc(3, vi(N));
  rep(i, N) {
    rep(j, 3) {
      cin >> abc[j][i];
    }
  }

  vvi dp(3, vi(N, 0));
  rep(i, 3) {
    dp[i][0] = abc[i][0];
  }

  REP(n, 1, N) {
    rep(pre, 3) {
      rep(now, 3) {
        if (now == pre) continue;
        dp[now][n] = max(dp[now][n], dp[pre][n-1] + abc[now][n]);
      }
    }
  }
  ll ans = 0;
  rep(i, 3) {
    ans = max(ans, dp[i][N-1]);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 5744
main :: IO ()
main = do
    [n,k] <- map read . words <$> getLine :: IO [Double]
    print $ sum [
        let x = ceiling $ logBase 2 (k / i)
         in if i < k then (1.0 / n) * ((1.0 / 2.0) ^ x) else 1.0 / n
        | i <- [1..n] ]

Measured memory_bytes: 1148
#include <bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
#define mp make_pair
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
const ll INF=1LL<<30;
const ll LINF=1LL<<60;
const double eps=1e-5;
const ll MOD=1000000007LL;
template<typename T>void chmin(T &a,T b){a=min(a,b);};
template<typename T>void chmax(T &a,T b){a=max(a,b);};
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int main(){
    ll n;cin>>n;
    vector<ll> a(n+10);
    int co=0;
    ll sum=0;
    int id;
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum+=a[i];
        if(a[i]%2){
            co++;
            id=i;
        }
    }
    bool f=false;
    int k=1;
    while(a[id]>1&&co==1&&n%2){
        a[id]--;
        ll g=a[0];
        for(int i=1;i<n;i++){
            g=__gcd(g,a[i]);
        }
        co=0;
        for(int i=0;i<n;i++){
            a[i]/=g;
            if(a[i]%2){
                id=i;
                co++;
            }
        }
        if(k%2){
            if(co%2&&(co>1||a[id]==1)){
                f=true;
                break;
            }else if(co%2==0){
                break;
            }
        }else{
            if(co%2&&(co>1||a[id]==1)){
                break;
            }else if(co%2==0){
                f=true;
                break;
            }
        }
        k++;
    }
    if(n==1){
        cout<<"Second"<<endl;
        return 0;
    }
    if((sum-n)%2LL>0||f){
        cout<<"First"<<endl;
    }else{
        cout<<"Second"<<endl;
    }
    return 0;
}


Measured memory_bytes: 1152
exec("def nWord(): nWord.cache = raw_input() if not hasattr(nWord, 'cache') or nWord.cache=='' else nWord.cache ; pos = nWord.cache.find(nWord.sep) ; ret, nWord.cache = (nWord.cache, '') if pos==-1 else (nWord.cache[:pos], nWord.cache[pos+1:].lstrip(nWord.sep)) ; return ret") ; exec("nWord.sep = ' '") ; exec("def ___nLine2(): ret, nWord.cache = (raw_input(), nWord.cache if hasattr(nWord, 'cache') else '') if not hasattr(nWord, 'cache') or nWord.cache=='' else (nWord.cache, '') ; return ret") ; exec('def nInt(): return int(nWord())') ; exec('def nFloat(): return float(nWord())') ; exec("def ___nAuto2():\n ret = nWord()\n try: return int(ret)\n except: pass\n try: return float(ret)\n except: return ret") ; exec("def nAuto(n=None): return ___nAuto2() if n is None else [___nAuto2() for i in range(n)]") ; exec("def nLine(n=None): return ___nLine2() if n is None else [___nLine2() for i in range(n)]")

import itertools

A = nAuto(nAuto())
n = 0
ba = 0
for a in reversed(A):
    if ba<=a:
        n += a
    elif a+1==ba:
        pass
    else:
        print(-1)
        exit()
    ba = a

if ba!=0:
    print(-1)
    exit()

print(n)


Measured memory_bytes: 35228
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
const int MOD = 1000000007;
using namespace std;

int main(){
    int n; cin >> n;
    vector<int> come(n);
    REP(i, n){
        int a; cin >> a;
        come[a-1] = i+1;
    }
    REP(i, n){
        if(i) cout << " ";
        cout << come[i];
    }
    cout << "\n";
    return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>

using namespace std;
#define vsort(v) sort(v.begin(), v.end());
#define vunique(v) unique(v.begin(), v.end());

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

	int rslt = N / 3;
	cout << rslt << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int solve_small(int N, int A, vector<int> x){
	int res = 0;
	for (int i = 1; i < (1<<N); ++i){
		int curr = 0;
		rep (j, N){
			if (i & (1<<j)){
				curr += x[j];
			} // end if
		} // end rep
		int cnt = __builtin_popcount(i);
		if (curr == cnt * A){
			cerr << "curr: " << curr << " cnt: " << cnt << endl;
			++res;
		} // end if
	} // end for
	return res;
}

const int MAX_N = 55;
const int MAX_M = 2555;

ll dp[MAX_N][MAX_N][MAX_M]; // dp[j][k][s]:= j 枚目をみて、k 枚選んで xi の合計を s にするような選び方の総数

ll solve_large(int N, int A, vector<int> x){
	int X = A;
	sort(ALL(x));
	X = max(X,x[N-1]);

	memset(dp, 0LL, sizeof(dp));

	rep (j, N+1){
		rep (k, N+1){		
			for (int s = 0; s <= X*N; ++s){
				if (j == 0 && k == 0 && s == 0){
					dp[j][k][s] = 1LL;
				}else
				if (j >= 1 && s < x[j-1]){
					dp[j][k][s] = dp[j-1][k][s];
				}else
				if (j >= 1 && k >= 1 && s >= x[j-1]){
					dp[j][k][s] = dp[j-1][k][s] + dp[j-1][k-1][s-x[j-1]];
				}else{
					dp[j][k][s] = 0LL;
				} // end if
			} // end for
		} // end rep
	} // end rep

	ll res = 0LL;
	for (int k = 1; k <= N; ++k){
		res += dp[N][k][k*A];
	} // end for

	return res;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N, A; cin >> N >> A;
	vector<int> x(N, 0);
	rep (i, N) cin >> x[i];

//	assert(N <= 16);
//	int res = solve_small(N,A,x);
	ll res = solve_large(N,A,x);
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 60672
#include <bits/stdc++.h>
#include<math.h>
#include<algorithm> 
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18
     
struct UnionFind {
    vector<int> d ;
    UnionFind (int n = 0) : d(n, -1) {}
    int find(int x){
        if(d[x] < 0) return x ;
        else {
            return find(d[x]) ;
        }
    }
    bool unite(int x, int y){
        x = find(x) ;
        y = find(y) ;
        if(x == y){
            return false ;
        }
        if(d[x] > d[y]) swap(x, y) ;
        d[x] += d[y] ;
        d[y] = x ;
        return true ;
    }
    bool same(int x, int y) {
        return find(x) == find(y) ;
    }
};



int main () {
    int n, m ;
    cin >> n >> m ;
    int ans = 0 ;
    vector<P> edge  ;
    rep(i, m){
        int a, b ;
        cin >> a >> b ;
        a-- ;  b-- ;
        edge.push_back(P(a, b))  ;
    }
    rep(i, m){
        UnionFind uf(n) ;
        rep(j, m){
            if(j == i){
                continue ;
            }
            else {
                int x = edge[j].first ;
                int y = edge[j].second ;
                uf.unite(x, y) ;
            }
        }
        int st = edge[i].first ;
        int gt = edge[i].second ;
        if(!uf.same(st, gt)){
            ans++ ;
        }
    }
    cout << ans << endl ;
}

Measured memory_bytes: 3640
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<string>
#include<cstdio>
#include<vector>
#include<cassert>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,a,b) for (int i=a; i<=b; i++)
#define per(i,a,b) for (int i=a; i>=b; i--)
#define debug(x) {cout<<(#x)<<" "<<x<<endl;}
using namespace std;
typedef long long LL;

inline int read() {
    int x=0,f=1; char ch=getchar();
    while (!(ch>='0'&&ch<='9')) {if (ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9') {x=x*10+(ch-'0'); ch=getchar();}
    return x*f;
}

const int N = 200005;
const int MOD = 1000000007;

int fac[N],inv[N];
int n,m;

inline int Pow(int a,int b) {
	int ret=1;
	while (b) {
		if (b&1) ret=(LL)ret*a%MOD;
		a=(LL)a*a%MOD; b>>=1;
	}
	return ret;
}



int main() {

	#ifndef ONLINE_JUDGE
	//	freopen("data.in","r",stdin);
	//	freopen("data.out","w",stdout);
	#endif

	n=read(),m=read();
	if (abs(n-m)>1) {puts("0"); return 0;}
	fac[0]=1; rep(i,1,N-1) fac[i]=(LL)fac[i-1]*i%MOD;
	int ans;
	if (abs(n-m)==1) ans=(LL)fac[n]*fac[m]%MOD;
	else ans=(LL)fac[n]*fac[n]*2%MOD;
	printf("%d\n",ans);
	

	return 0;
}


Measured memory_bytes: 1024