akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    int n, m, a, b;
    cin >> n >> m;
    unordered_map<int, vector<int>> e;
    for(int i = 0; i < m; i++) {
        cin >> a >> b;
        e[a-1].push_back(b-1);
        e[b-1].push_back(a-1);
    }
    unordered_set<int> visit = {0};
    vector<int> ans(n, 0);
    vector<int> dq = {0};
    while(!dq.empty()) {
        vector<int> new_dq;
        for(int node: dq) {
            for(int neibor: e[node]) {
                if (visit.count(neibor) == 0) {
                    visit.insert(neibor);
                    new_dq.push_back(neibor);
                    ans[neibor] = node;
                }
            }
        }
        dq.swap(new_dq);
    }
    if (visit.size() != n) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
        for(int i = 1; i< n; i++)
            cout << ans[i]+1 << endl;
    }
    return 0;
}


Measured memory_bytes: 17440
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i <= n; i++)
int n, a[3], t;
double p[305][305][305];

int main(){
  scanf("%d", &n);
  rep(i,n-1){
    scanf("%d", &t);
    a[t-1]++;
  }
  rep(i,a[2]) rep(j,n-a[0]) rep(k,n) if(i+j+k) p[i][j][k] = (n + (i?p[i-1][j+1][k]*i:0) + (j?p[i][j-1][k+1]*j:0) + (k?p[i][j][k-1]*k:0)) / (i+j+k);
  printf("%.10lf\n", p[a[2]][a[1]][a[0]]);
}


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

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

    int ans = 0;
    for(int bit = 0; bit < (1 << n); bit++){
        bool isok = true;
        for(int i = 0; i < n; i++){
            for(int j = 0; j < y[i].size(); j++){
                if(bit & (1 << i)){
                    if((bool)(bit & (1 << (x[i][j]-1))) != y[i][j]) isok = false;
                }
            }
        }

        if(isok){
            int coans = 0;
            int tmp = bit;
            while(tmp){
                if(tmp & 1) coans++;
                tmp >>= 1;
            }
            if(ans < coans) ans = coans;
        }
    }

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

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

int main(void) {
  int num, i;
  long long int area, enable, count = 0;

  // for文の回数
  scanf("%d", &num);

  for (i = 0; i < num; i++) {
    enable = 0;
    scanf("%lld", &area);
    for (long long int x = 1; (2*x*x)+(2*x)<=area; x++) {
      if ((area - x) % ((x * 2) + 1) == 0) {
        enable = 1;
        break;
      }
    }
    if (enable == 0) {
      count += 1;
    }
  }
  printf("%lld\n", count);

  return 0;
}



Measured memory_bytes: 1960
N = int(input())
b = list(map(int, input().split()))

res = []
for _ in range(N):
    flag = False
    for i in range(len(b)-1, -1, -1):
        if b[i] == i+1:
            res.append(b.pop(i))
            flag = True
            break
    if flag == False:
        print(-1)
        exit()

res.reverse()
for i in range(N):
    print(res[i])

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

int main() {

    long long int n, d;
    cin >> n >> d;

    vector< vector< long long int > > v;

    for ( long long int i = 0; i < n; i++ ) {
        vector< long long int > vv;
        for ( long long int j = 0; j < d; j++ ) {
            long long int in;
            cin >> in;
            vv.push_back( in );
        }
        v.push_back( vv );
    }

    long long int ans = 0;

    for ( long long int i = 0; i < n; i++ ) {
        for ( long long int j = i + 1; j < n; j++ ) {
            long long int cnt = 0;
            for ( long long int k = 0; k < d; k++ ) {
                long long int p = v[i][k] - v[j][k];
                cnt += p * p;
            }
            for ( long long int t = 0; t * t <= cnt; t++ ) {
                if ( t * t == cnt ) ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//int N;
//int num=0;
//vector<char> S;
//int cnt=2;
string S;
void solve(){
    cin>>S;
    int sum=0;
    for(int i=0;i<S.length();i++){
        int num=S[i]-'0';
        sum+=num;
    }
    int N=atoi(S.c_str());
    if(N%sum!=0){cout<<"No"<<endl;return;}
    cout<<"Yes"<<endl;
}
int main(){
    solve();

    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce



sys.setrecursionlimit(2147483647)
INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007



n, a = LI()
L = LI()
L = [i - a for i in L]
dp = defaultdict(int)
dp[0] = 1
for i in range(n):
    if L[i] <= 0:
        for j in range(-2500, 2501):
            dp[j] += dp[j - L[i]]
    else:
        for j in range(2500, -2501, -1):
            dp[j] += dp[j - L[i]]


print(dp[0] - 1)

Measured memory_bytes: 40944
n,ma,mb=map(int,input().split())
el=[list(map(int,input().split())) for i in range(n)]
sa=sum(i[0] for i in el)
sb=sum(i[1] for i in el)
sa1=sa+1
sb1=sb+1

inf=10000000000
x=[[inf]*(sb1) for i in range(sa1)]
x[0][0]=0
for i in range(n):
    now=el[i]
    x_sub=[[0]*(sb1) for i in range(sa1)]
    for k in range(sa1):
        for l in range(sb1):
            if x[k][l]!=inf:
                if k+now[0]<sa1:
                    if l+now[1]<sb1:
                        x_sub[k+now[0]][l+now[1]]=x[k][l]+now[2]
    for k in range(sa1):
        for l in range(sb1):
                if x_sub[k][l]!=0:
                    x[k][l]=min(x[k][l],x_sub[k][l])
mi=min(sa//ma,sb//mb)
ans=inf
for i in range(1,mi+1):
    ans=min(ans,x[ma*i][mb*i])
if ans==inf:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 5368
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    x = f()[0]
    a = [0]*10001

    a[1] = 1
    for i in range(2,1000):
        if i*i <= 1000:
            a[i*i] = 1
            k = 3
            while i**k <= 1000:
                a[i**k] = 1
                k += 1
        else:
            break

    for i in range(x, 0, -1):
        if a[i] == 1:
            print(i)
            break


solve()


Measured memory_bytes: 3064
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

from  collections import defaultdict
from collections import Counter
import bisect
from functools import reduce

def main():
    H, N = MI()
    A = LI()
    A_sum = sum(A)
    if A_sum >= H:
        print('Yes')
    else:
        print('No')



if __name__ == "__main__":
    main()



Measured memory_bytes: 87960
// #Badhi moh maya chhe!
/*
AUTHOR NAME:
	         ,--.                         ____                          ,--.
	       ,--.'|   ,---,               ,'  , `.   ,---,              ,--.'|
	   ,--,:  : |  '  .' \           ,-+-,.' _ |  '  .' \         ,--,:  : |
	,`--.'`|  ' : /  ;    '.      ,-+-. ;   , || /  ;    '.    ,`--.'`|  ' :
	|   :  :  | |:  :       \    ,--.'|'   |  ;|:  :       \   |   :  :  | |
	:   |   \ | ::  |   /\   \  |   |  ,', |  '::  |   /\   \  :   |   \ | :
	|   : '  '; ||  :  ' ;.   : |   | /  | |  |||  :  ' ;.   : |   : '  '; |
	'   ' ;.    ;|  |  ;/  \   \'   | :  | :  |,|  |  ;/  \   \'   ' ;.    ;
	|   | | \   |'  :  | \  \ ,';   . |  ; |--' '  :  | \  \ ,'|   | | \   |
	'   : |  ; .'|  |  '  '--'  |   : |  | ,    |  |  '  '--'  '   : |  ; .'
	|   | '`--'  |  :  :        |   : '  |/     |  :  :        |   | '`--'  
	'   : |      |  | ,'        ;   | |`-'      |  | ,'        '   : |      
	;   |.'      `--''          |   ;/          `--''          ;   |.'      
	'---'                       '---'                          '---'        

*/



#include <bits/stdc++.h>

using namespace std;
#define endl "\n"
#define ll long long
#define ld long double
#define pll pair<long long,long long>
#define vll vector<long long>
#define all(x) x.begin(),x.end()
#define pb push_back
#define Fo(i,k,n) for(ll i=k;i<=n;i+=1)
#define deb(x) cout << #x << "=" << x << endl
#define in(a,n) Fo( i,0,n-1)cin>>a[i]
#define out(a,n) Fo( i,0,n-1)cout<<a[i]<<" ";cout<<endl
#define IOS     ios_base::sync_with_stdio(0); cin.tie(NULL);

ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
void fileio()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
}
 
ld maxvolume(ld s) 
{ 
	// finding length 
ld length = s / 3; 

	s -= length; 

	// finding breadth 
	ld breadth = s / 2; 

	// finding height 
	ld height = s - breadth; 

	return length * breadth * height; 
} 




int main() {
	IOS
    ll t=1;
	//cin>>t;	
	
	while(t--)
	{
	 ld s;
	 cin>>s;
	 std::cout << std::fixed;
    std::cout << std::setprecision(6);
	 cout<<(ld)maxvolume(s);
	 
	 
	}
	
    
}

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

using namespace std;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

using ld = long long;
using ll = long long;
struct Edge
{
    int from, to;
    ld cost;
    Edge(int f, int t, ld c) : from(f), to(t), cost(c) {}
};

using Edges = vector<Edge>;
using Graph = vector<Edges>;
constexpr ld inf = 1e15;
constexpr ld eps = 1e-15;
constexpr ll mod = 999999739, mod2 = 999999751;

template<typename T>
T mypow(T a, T b, ll MOD)
{
    if (b == 0)
        return 1;
    T tmp = mypow(a, b / 2, MOD);
    if (b % 2)
        return (((tmp * tmp) % MOD) * a) % MOD;
    else
        return (tmp * tmp) % MOD;
}

vector<ld> d(100010, -inf),d2(100010, -inf);

void dfs(int cur, const Graph &g)
{
    for(const auto e:g[cur])
    {
        int to = e.to;
        ld cost = e.cost;
        if(d[to]!=-inf) continue;
        d[to] = d[cur] * cost % mod;
        dfs(to, g);
    }
}

void dfs2(int cur, const Graph &g2)
{
    for(const auto e:g2[cur])
    {
        int to = e.to;
        ld cost = e.cost;
        if(d2[to]!=-inf) continue;
        d2[to] = d2[cur] * cost % mod2;
        dfs2(to, g2);
    }
}

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

    int n,m;cin >> n>>m;
    Graph g(n+1), g2(n+1);
    for(int i=1;i<=n;i++){
        g[0].push_back(Edge(0, i, 1));
        g2[0].push_back(Edge(0, i, 1));
    }
    vector<Edge> es;
    for(int i=0;i<m;i++)
    {
        int a,b;
        ld x;
        cin >> a >> b >> x;
        // cerr << fixed << setprecision(10) << cost << endl;
        g[a].push_back(Edge(a,b,x));
        g[b].push_back(Edge(b,a,mypow(x, mod-2, mod)));
        es.push_back(Edge(a,b,x));

        g2[a].push_back(Edge(a,b,x));
        g2[b].push_back(Edge(b,a,mypow(x, mod2-2,mod2)));
    }
    d[0] = 1;
    d2[0] = 1;
    dfs(0, g);
    dfs2(0, g2);
    bool f = true;
    for(const auto &e:es)
    {
        int from = e.from, to = e.to;
        ld cost = e.cost;
        //cerr << from << " " << to << " " << cost << endl;
        //cerr << d[from] << " " << d[to] << endl;
        if(d[to] != d[from] * cost % mod) f = false;
        if(d2[to] != d2[from] * cost % mod2) f = false;
    }
    cout << (f ? "Yes" : "No") << endl;
    //cerr << fixed << setprecision(15);
    //cerr << log(1000000000) << endl;
    //cerr << log(999999999) << endl;
}




Measured memory_bytes: 29984
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
# 同一の集合の判定
def same(x, y):
    if find(x) == find(y):
        return True
    else:
        return False
# 集合の併合
def unite(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return
    if par[x] > par[y]:
        x, y = y, x
    par[x] += par[y]
    par[y] = x

# 集合の数
def uCnt(x):
    return -par[find(x)]

N, Q = map(int, input().split())
par = [-1 for i in range(N)]

for i in range(Q):
    tmp = list(map(int, input().split()))
    if tmp[0] == 0:
        unite(tmp[1], tmp[2])
    else:
        if same(tmp[1], tmp[2]):
            print(1)
        else:
            print(0)

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

#define FOR(i, f, n) for(int (i) = (f); (i) < (n); (i)++)
#define RFOR(i, f, n) for(int (i) = (f); (i) >= (n); (i)--)
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define step(i, f, n, a) for(int (i) = (f); (i) < (n); (i)+=a)
#define rstep(i, f, n, a) for(int (i) = (f); (i) >= (n); (i)-=a)
#define p(...) printf(__VA_ARGS__); cout << endl;
#define gets(x) x; cin >> x;
#define puts(x) x; cout << x << endl;
#define list_input(x, n) x[(n)]; for(int (i) = 0; (i) < (n); (i)++) cin >> x[i];
#define lambda(a, b, c) [](const a, const b){ return c ;}
#define key(t, x, compare) [](const t& a, const t& b){ return a x compare b x ;}

using namespace std;

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

int main(){
	ll n, result = 1;
	gets(n)
	FOR(i, 1, n+1){
		result *= i;
		result %= 1000000007;
	}
	puts(result)
}


Measured memory_bytes: 256
N,W = map(int,input().split())
array = [[0] * (W+1) for i in range((N+1))]
for i in range(N):
  wei,V = map(int,input().split())
  for j in range(W):
    if(wei<=j+1):
      if(array[i][j] < array[i][j-wei+1]+V):
        array[i+1][j+1]=array[i][j-wei+1]+V
      else:
        array[i+1][j+1]=array[i][j+1]
    else:
      array[i+1][j+1]=array[i][j+1]
print(array[N][W])

Measured memory_bytes: 120300
#[allow(unused_imports)]
use std::cmp;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    #[allow(unused_mut)]
    let mut s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

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

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

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

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

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

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

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

fn main() {
  input! {
    x: usize,
    y: usize,
    z: usize,
    k: usize,
    aa: [i64; x],
    bb: [i64; y],
    cc: [i64; z],
  }
  let mut ab = Vec::with_capacity(x * y);
  for &a in &aa {
    for &b in &bb {
      ab.push(a + b);
    }
  }
  ab.sort();
  let mut abc = Vec::with_capacity(k * z);
  for &p in ab.iter().rev().take(k) {
    for &c in &cc {
      abc.push(p + c);
    }
  }
  abc.sort();
  for &q in abc.iter().rev().take(k) {
    println!("{}", q);
  }
}


Measured memory_bytes: 45308
#include<bits/stdc++.h> 
#define ll long long
#define pb push_back
#define ld double
using namespace std;

const int MOD = 1e9+7;


 

int main(){
   int n,k;
  cin>>n>>k;
  vector<int> arr(n+1);
  for(int i=1;i<=n;i++)
  cin>>arr[i];
  int dp[n+2][k+1];
  memset(dp,0,sizeof(dp));
  int i,j;
  	dp[0][0]=1; //BASE CASE
	for(i=1;i<=k;i++) dp[0][i]=0; //BASE CASE
	for(i=1;i<=n;i++){
		for(j=1;j<=k;j++)
			dp[i-1][j]=(dp[i-1][j]+dp[i-1][j-1])%MOD;
			
		for(j=0;j<=k;j++){
			ll mn=j-arr[i]-1;
			dp[i][j]=dp[i-1][j];
			if(mn>=0) dp[i][j]=(dp[i][j]-dp[i-1][mn]+MOD)%MOD;
		}
	}
  /*for(int i=1;i<=n;i++)
  {for(int j=0;j<=k;j++)
    cout<<dp[i][j]<<" ";
   cout<<"\n";
  }*/
  cout<<dp[n][k]<<"\n";
return 0; 
}

Measured memory_bytes: 43456
#ABC132-E Hopscotch Addict
"""
グラフを3倍して、
ある二頂点u→vに辺が存在する時
余り0の頂点u→1の頂点v
余り1の頂点u→2の頂点v
余り2の頂点u→0の頂点v
にそれぞれ辺を張った時に、
スタート(頂点S)の余り0の頂点から、
ゴール(頂点T)の余り0への最短パスが答え。
"""
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
n,m = map(int,readline().split())
g = [[] for _ in range(3*n)]
for i in range(m):
    x,y = map(int,readline().split())
    x,y = x-1,y-1
    g[x].append([1,y+n])
    g[x+n].append([1,y+n+n])
    g[x+n+n].append([1,y])


#ダイクストラ法通常版
#O(ElogV)
import heapq
def dijkstra_heap(s,edge):
    #始点sから各頂点への最短距離
    n = len(edge)
    d = [float("inf")] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for e in edge[s]:
        heapq.heappush(edgelist,e)
    while len(edgelist): #キューから値が無くなるまで
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge[1]]: #既に最小距離が確定しているなら
            continue
        v = minedge[1] #vに頂点を代入
        d[v] = minedge[0] #その頂点のコストに重みを代入
        used[v] = False #vには最小距離が入っていることが証明できる(ヒープキューを使用しているため)
        for e in edge[v]: #頂点vから伸びている辺の先をヒープキューに入れてく
            if used[e[1]]:
                heapq.heappush(edgelist,[e[0]+d[v],e[1]])
    return d #回しきったらreturn(たどり着けなかった頂点はinf.)

s,t = map(int,readline().split())
s,t = s-1,t-1

res = dijkstra_heap(s,g)[t]

print(-1 if res == float("inf") else res//3)

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

double calc(double a,double b,double c,double x,double y)
{
    double cost1=0,cost2=0;
    double tx,ty;
    tx=x,ty=y;
    if(a>=2*c)
    {
        cost1=(x*c*2);
        y-=x/2;
        x=0;
        if(y>0)
            cost1+=min(ceil(y)*b,y*c*2);
    }
    else
    {
        if(b>=2*c)
        {
            cost1=(y*c*2);
            x-=y/2;
            y=0;
            if(x>0)
                cost1+=min(ceil(x)*a,x*c*2);
        }
        else
        {
            cost1=x*a;
            cost1+=y*b;
        }
    }
    x=tx;
    y=ty;
    if(b>=2*c)
    {
        cost2=(y*2*c);
        x-=y/2;
        y=0;
        if(x>0)
            cost2+=min(ceil(x)*a,x*c*2);
    }
    else
    {
        if(a>=2*c)
        {
            cost2=(x*2*c);
            y-=x/2;
            x=0;
            if(y>0)
                cost2+=min(ceil(y)*b,y*c*2);
        }
        else
        {
            cost2=x*a;
            cost2+=y*b;
        }
    }
    return min(cost1,cost2);
}
int main()
{
    double a,b,c,x,y;
    scanf("%lf %lf %lf %lf %lf",&a,&b,&c,&x,&y);
    double tx,ty,xx,yy,cost=-1,costf;
    tx=min(x,y);
    xx=x,yy=y;
    if(tx*a+tx*b>=2*tx*c)
    {
        cost=2*tx*c;
        xx-=tx;
        yy-=tx;
        if(xx>0)
        {
            if(a*xx>=c*xx*2)
                cost+=c*xx*2;
            else
                cost+=a*xx;
        }
        else
        {
            if(b*yy>=c*yy*2)
                cost+=c*yy*2;
            else
                cost+=b*yy;
        }
    }
    double cost1=calc(a,b,c,x,y);
    if(cost!=-1)
    {
        costf=min(cost1,cost);
    }
    else
        costf=cost1;
    printf("%0.0f\n",costf);
}


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

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int mod = 1e+9 + 7;

//マクロ
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

int main()
{
  ll n, m;
  cin >> n >> m;
  ll sum = 0;
  rep(i, m)
  {
    ll tmp;
    cin >> tmp;
    sum += tmp;
  }
  if (n < sum)
  {
    cout << -1 << "\n";
  }
  else
  {
    cout << n - sum << "\n";
  }
  return 0;
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    int n,i,c=0,t=0,j,te;
    cin>>n;
    int a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(i=0;i<n-1;i++)
    {
      c=i;
      for(j=i+1;j<n;j++)
      {
          if(a[c]>a[j])
          {
              c=j;
          }
      }
      if(c!=i)
      {
         t++;
         te=a[c];
         a[c]=a[i];
         a[i]=te;
      }
    }
    if(t<=1)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;





    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
using vi = vector<int>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;


int main(){
    string s;
    int Q;
    cin >> s >> Q;
    string mae,usi;
    bool ok = false;
    for(int ind=0;ind<Q;ind++){
        int q;cin>>q;
        if(q==1){
            ok = !ok;
        }else{
            int a;
            string t;
            cin >> a >> t;
            if(a==1 && !ok){
                mae += t;
            }else if(a==1 && ok){
                usi += t;
            }else if(a==2 && !ok){
                usi += t;
            }else{
                mae += t;
            }
        }
    }
    string ans;
    if(!ok){
        reverse(mae.begin(),mae.end());
        ans = mae + s + usi;
    }else{
        reverse(s.begin(),s.end());
        reverse(usi.begin(),usi.end());
        ans = usi + s + mae;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1348
using System;
using System.IO;
using System.Linq;

namespace ABC125A
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                Console.SetIn(new StreamReader(args[0]));
            }

            new Program().Solve();
        }

        void Solve()
        {
            var temp = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var A = temp[0];
            var B = temp[1];
            var T = temp[2];

            Console.WriteLine(T / A * B);
        }
    }
}


Measured memory_bytes: 11348
#include <bits/stdc++.h> 
#define ll long long int
#define ld long double
#define ull unsigned long long
const double pi=3.14159265358979323846;
using namespace std;

bool isPrime(int n) 
{ 
    // Corner cases 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
  
    // This is checked so that we can skip 
    // middle five numbers in below loop 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (int i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
  
    return true; 
} 
ll bigd(ll n) 
{
    ll in=1;
    for (ll i =2; i < n; i++)
    {
        if (n % i == 0) 
        {
            in= i;
            break;
        }    
    }   
    return in;
} 

ll ipow(ll base, ll exp)
{
    ll result = 1;
    for (;;)
    {
        if (exp & 1)
            result *= base;
        exp >>= 1;
        if (!exp)
            break;
        base *= base;
    }
    return result;
}
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    ll n,k;
    cin>>n>>k;
    ll a[n];
    for(ll i=0;i<n;i++)
    cin>>a[i];
    sort(a,a+n);
    ll sum=0;
    for(ll i=0;i<k;i++)
    sum+=a[i];
    cout<<sum<<"\n";


}

Measured memory_bytes: 3620
package main

import "fmt"

func main() {
	var a string
	_, err := fmt.Scanf("%s", &a)
	if err != nil {
		panic(err)
	}
	if a == "AAA" || a == "BBB" {
		fmt.Printf("No\n")
	}else {
		fmt.Printf("Yes\n")
	}
}


Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <cassert>

using namespace std;

typedef long long LL;
typedef pair<int,int> PII;

#define MP make_pair
#define PB push_back
#define FF first
#define SS second

#define FORN(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD(i, n) for (int i = (int)(n) - 1; i >= 0; i--)

#define DEBUG(X) { cout << #X << " = " << (X) << endl; }
#define PR0(A,n) { cout << #A << " = "; FORN(_,n) cout << A[_] << ' '; cout << endl; }

#define MOD 1000000007
#define INF 2000000000

int GLL(LL& x) {
    return scanf("%lld", &x);
}

int GI(int& x) {
    return scanf("%d", &x);
}

int n;

vector<string> board; string row;

int main() {
    GI(n);

    int hashes = 0;

    FORN(i, n) {
        cin >> row;
        board.PB(row);
        for (auto& c : row) hashes += (c == '#');
    }

    if (hashes == 0) {
        printf("-1\n");
        return 0;
    }

    int res = INF;

    FORN(i, n) {
        int idots = 0; for (auto& c : board[i]) idots += (c == '.');

        if (idots == 0) {  // row i is all hashes. use i to fill columns
            int moves = 0;
            FORN(j, n) { FORN(k, n) if (board[k][j] == '.') { moves++; break; } }
            res = min(res, moves);
        }
        else {  // fill up row i first, then use it to fill columns
            int j = 0; while (j < n && board[j][i] == '.') j++;

            int moves = (j == n) ? 1 : 0;  // get something into the ith column

            FORN(j, n) if (board[i][j] == '.') moves++;  // fill up the ith row

            FORN(j, n) FORN(k, n) if (board[k][j] == '.') { moves++; break; }  // fill columns

            res = min(res, moves);
        }
    }

    cout << res << "\n";

    return 0;
}

Measured memory_bytes: 512
#include<cstdio>
int main(){
    int n,a,r[13]={},sum=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a);
        r[a/400]++;
    }
    for(int i=0;i<8;i++){
        if(r[i]>0)sum++;
    }
    printf("%d ",(sum==0)?1:sum);
    for(int i=8;i<13;i++)sum+=r[i];
    printf("%d",sum);
    return 0;
}

Measured memory_bytes: 128
#!python3

def resolve():
    N = int(input())
    A = tuple(map(int, input().rstrip().split()))

    ma = max(*A)

    i = 1
    asum = 0
    while i < ma:
        cc = 0
        for x in A:
            if x & i: cc += 1
        asum += i * (N - cc) * cc
        i <<= 1

    print(asum % (10**9+7))

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 42300
#include<stdio.h>

int main() {
    char s[10];
    int num[110];
    int tail = 0;
    int a, b, tmp;
    int i;

    while(scanf("%s", s) != EOF) {
        if (s[0] == '+' || s[0] == '-' || s[0] == '*') {
            tail--;
            b = num[tail];
            tail--;
            a = num[tail];
            if (s[0] == '+') a = a + b;
            else if (s[0] == '-') a = a - b;
            else if (s[0] == '*') a = a * b;
            num[tail] = a;
            tail++;
        } else {
            tmp = s[0] - '0';
            i = 1;
            while(s[i] != '\0') {
                tmp *= 10;
                tmp += (s[i] - '0');
                i++;
            }
            num[tail] = tmp;
            tail++;
        }
    }

    printf("%d\n", num[0]);
    return 0;
}


Measured memory_bytes: 2104
#include <iostream>

using namespace std;

int main()
{

int x,y;
cin>>x>>y;
int a,b,c;
a=x*y;
b=x-y;
c=x+y;
if(a==0&&b==0&&c==0){
    cout<<0;

}
else if(a>b&&a>=c){
    cout<<a;
}
else if(b>a&&b>=c){
    cout<<b;
}
else if(c>a&&c>=b){
    cout<<c;
}
    return 0;
}

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

using namespace std;

int main(){
    int n,m;
    cin>>n>>m;
    vector<pair<int,int>> mp(n+1);
    mp[0]=make_pair(0,0);
    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < n; ++j) {
            char c;
            cin>>c;
            if(c=='W')mp[j+1].first++;
            else mp[j+1].second++;
        }
    }
    for (int i = 1; i <= n; ++i) {
        mp[i].first+=mp[i-1].first;
        mp[i].second+=mp[i-1].second;
    }
    int ans=n*m+1;
    int ansind=-1;
    for (int i = 0; i <= n; ++i) {
        int l=mp[i].second-mp[0].second;
        int r=mp[n].first-mp[i].first;
        if(ans>l+r){
            ans=l+r;
            ansind=i;
        }
    }
    cout<<ansind<<" "<<ansind+1<<endl;
    return 0;
}


Measured memory_bytes: 3200
using System;
class p0003
{
    static void Main(string[] args)
    {
        int cnt = int.Parse(Console.ReadLine());
        while (0 < cnt--)
        {
            int[] intAry = new int[3];
            var ary = Console.ReadLine().Split(' ');
            for(int i=0; i<3; i++)
            {
                intAry[i] = int.Parse(ary[i]);
                intAry[i] = intAry[i] * intAry[i];
            }


            Array.Sort(intAry);
            //var x = int.Parse(ary[0]) * int.Parse(ary[0]);
            //var y = int.Parse(ary[1]) * int.Parse(ary[1]);
            //var z = int.Parse(ary[2]) * int.Parse(ary[2]);
            Console.WriteLine((intAry[0] + intAry[1] == intAry[2]) ? "YES" : "NO");
        }
    }
}

Measured memory_bytes: 5560
#include<bits/stdc++.h>
using namespace std;
int main(){
	int m,d,ans=0;scanf("%d%d",&m,&d);
	for(int i=4;i<=m;i++){
		for(int j=22;j<=d;j++){
			if((j%10)>=2&&((j%10)*(j/10))==i)ans++;
		}
	}
	printf("%d\n",ans);
	return 0;
} 

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

int digitsum(int x){
    int ret = 0;
    while(x > 0){
        ret += x%10;
        x /= 10;
    }
    return ret;
}

int main(){
    int n, a, b;
    cin >> n >> a >> b;

    int sum = 0;
    for(int i = 1; i <= n; i++){
        int tmp = digitsum(i);
        if(a <= tmp && tmp <= b)    sum += i;
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
from collections import deque
from collections import Counter
import math
import itertools

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

ans = [0,0,0,1,1,1,2]
mod = 10**9+7
for i in range(4,2001):
	ans.append((ans[-1]+ans[i])%mod)

print(ans[readInt()])

Measured memory_bytes: 9548
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#define debug(...) \
  { cerr << "# " << __VA_ARGS__ << "\n"; }
#else
#define debug(...)
#define FPEN
#endif
const int maxn = 200009;
typedef long long i64;
typedef pair<i64, i64> pi64;
typedef pair<int, int> pi;
const i64 MOD = 119 << 23 | 1;
class {
 public:
  int A[111][111], B[99][99][13000];
  int n, m;
  void solve() {
    cin >> n >> m;
    for (int i = 1; i <= n; ++i)
      for (int j = 1; j <= m; ++j) cin >> A[i][j];
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= m; ++j) {
        int t;
        cin >> t;
        if (t > A[i][j])
          A[i][j] = t - A[i][j];
        else
          A[i][j] -= t;
      }
    }
    B[1][1][A[1][1]] = 1;
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= m; ++j) {
        for (int k = 0; k < 13000; ++k) {
          if (B[i][j][k]) {
            B[i + 1][j][abs(k - A[i + 1][j])] = 1;
            B[i + 1][j][abs(-k - A[i + 1][j])] = 1;
            B[i + 1][j][abs(-k + A[i + 1][j])] = 1;
            B[i + 1][j][abs(k + A[i + 1][j])] = 1;
            B[i][j + 1][abs(k - A[i][j + 1])] = 1;
            B[i][j + 1][abs(-k - A[i][j + 1])] = 1;
            B[i][j + 1][abs(-k + A[i][j + 1])] = 1;
            B[i][j + 1][abs(k + A[i][j + 1])] = 1;
          }
        }
      }
    }
    for (int i = 0; i < 13000; ++i)
      if (B[n][m][i]) {
        cout << i << "\n";
        return;
      }
  }
} NSPACE;
int main() {
  FPEN;
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  NSPACE.solve();
}

Measured memory_bytes: 407936
using System;
using System.Linq;
using System.ComponentModel;
using System.Collections.Generic;

namespace ConsoleApp1 {
    public class Class {
        static void Main(string[] args) {
            var N = long.Parse(Console.ReadLine());
            long ans = 0;
            if (N % 1000 != 0) {
                ans = 1000 - (N % 1000);
            }
            Console.Write(ans);
        }
    }
}

Measured memory_bytes: 27540
// Copyright 2020 yaito3014
#include <bits/stdc++.h>

int main() {
  using namespace std;
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (auto& e : A) cin >> e;
  for (int i = 0; i < K; ++i) {
    vector<int> B(N + 1, 0);
    for (int j = 0; j < N; ++j)
      ++B[clamp(j - A[j], 0, N)], --B[clamp(j + A[j] + 1, 0, N)];
    partial_sum(cbegin(B), cend(B), begin(B));
    copy_n(cbegin(B), N, begin(A));
    if (all_of(cbegin(A), cend(A), [=](int n) { return n == N; })) break;
  }
  for (const auto& e : A) cout << e << ' ';
  cout << '\n';
}


Measured memory_bytes: 4992
program b172

implicit none
character(len=200000) :: s, t
integer :: i, x

x = 0

read *, s
read *, t

do i =1, 200000
 if (s(i:i) == ' ') then
  exit
 else if (s(i:i) == t(i:i)) then
  x = x
 else
  x = x + 1
 end if 
end do

print *, x

end program b172

Measured memory_bytes: 3372
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <cstdarg>
#include <sys/time.h>
#include <fstream>
//#include "cout.h"

using namespace std;

#define SZ(x) ((int)x.size())
#define MSET(x,a) memset(x, a, (int)sizeof(x))
#define PB push_back
#define VI vector < int >
#define PII pair < int, int >
#define LL long long
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define FIT(it,v) for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define OUT(A) cout << #A << " = "<< (A) << endl
#define OUT2(A, B) cout << "(" << #A << ", " << #B << ") = (" << (A) << ", "<< (B) << ")" << endl
template<class T> void chmin(T &t, T f) { if (t > f) t = f; } 
template<class T> void chmax(T &t, T f) { if (t < f) t = f; } 

#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())

int n;
int a[100010];
int c[100010];

void init() {
	MSET(a, 0);
	MSET(c, 0);
}

void input() {
	cin >> n;
	REP(i, n) {
		cin >> a[i+1];
	}
}

void solve() {
	FOR(i, 1, n+1) if(i == a[i]) c[i] = 1;
	int res = 0;
	REP(i, n+1) if(c[i]){
		res++;
		i++;
	}
	cout << res << endl;
}

int main() {
	init();
    input();
    solve();
	return 0;
}








Measured memory_bytes: 1024
import bisect
A, B, Q = map(int, input().split())
INF = 10 ** 13
s = [-INF] + [int(input()) for i in range(A)] + [INF]
t = [-INF] + [int(input()) for i in range(B)] + [INF]
for q in range(Q):
    x = int(input())
    b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
    res = INF
    for S in [s[b - 1], s[b]]:
        for T in [t[d - 1], t[d]]:
            d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
            res = min(res, d1, d2)
    print(res)

Measured memory_bytes: 12804
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll mod=1e9+7;
int dy[]={1,-1,0,0};
int dx[]={0,0,1,-1};

int main(){
  int N,W;
  cin>>N>>W;
  vector<int> w(N),v(N);

  for(int i=0;i<N;i++){
    cin>>w[i]>>v[i];
  }
  vector<vector<ll>> dp(N,vector<ll>(1e5+1,-1));
  dp[0][0]=0;
  dp[0][w[0]]=v[0];
  for(int i=1;i<N;i++){
    for(int j=0;j<=W;j++){
      dp[i][j]=dp[i-1][j];
      if(j-w[i]>=0) dp[i][j]=max(dp[i][j],dp[i-1][j-w[i]]+v[i]);
    }
  }
  ll ans=0;
  for(int i=0;i<=W;i++){
    ans=max(ans,dp[N-1][i]);
  }
  
  cout<<ans<<endl;
  return 0;
}




Measured memory_bytes: 79488
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
# define ll int64_t
# define str string
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define PI 3.141592653589793
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;



#define INF 2000000000
#define MAX_V 10



bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

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

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

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

ll lcm(ll a,ll b){
   return a/gcd(a,b)*b;
}
const ll MAX = 510000;
const ll MOD = 1000000007;
 
ll fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll 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;
    }
}
 
// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


using graph = vector<vector<ll>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,m;
    cin>>n>>m;
    ll num=gcd(n,m);
    vec<ll> a;
    for(ll i=1;i*i<=num;i++){
        if(num%i==0){
            a.pb(i);
            if(num/i==i) continue;
            a.pb(num/i);
        }
    }
    sort(ALL(a));
    ll e=0;
    rrep(i,a.size()-1){
        ll d=0;
        for(ll j=i-1;j>=0;j--){
            if(gcd(a[i],a[j])==1) d++;
        }
        if(d==i) e++;
    }
    cout<<e+1<<endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define gc getchar
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define x1 uvuvwe
#define y1 onyetvwe
#define x2 onyette
#define y2 ugmewuben
typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
template <typename T> void scan(T &angka){
	angka=0;char input=gc();T kali=1;
	while(!(48<=input&&input<=57)){	if(input=='-')	kali=-1;input=gc();}
	while(48<=input&&input<=57)	angka=(angka<<3)+(angka<<1)+input-48,input=gc();angka*=kali;
}
template <typename T1,typename T2> void scan(T1 &angka1,T2 &angka2){
	scan(angka1);scan(angka2);
}
int main()
{
	int x=0,y=0;
	int n,target;
	scan(n,target);
	for(int i=1;i<=n;i++)
	{
		int input;
		scan(input);
		if(input&1)
			y++;
		else
			x++;
	}
	LL ans;
	if(y==0&&target==0)
		ans=(1LL<<x);
	else if(y==0&&target==1)
		ans=0;
	else
		ans=(1LL<<x)*(1LL<<(y-1));
	cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next()), k = Integer.parseInt(sc.next());
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(sc.next());
        }

        boolean[] dp = new boolean[k + 1];

        for (int i = 1; i <= k; i++) {
            for (int j = 0; j < n; j++) {
                if (i - a[j] >= 0) {
                    dp[i] |= !dp[i - a[j]];
                    if (dp[i]) {
                        break;
                    }
                }
            }
        }

        System.out.println(dp[k] ? "First" : "Second");

    }
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, pair<ll, ll> > P3;

const ll MOD = ll(1e9 + 7);
const ll LLINF = LLONG_MAX;
const int IINF = INT_MAX;
const int MAX_N = int(1e5) + 5;
const double EPS = 1e-8;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#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++)


int main() {
    int n,m,ans=0, a[MAX_N];
    cin >> n >> m;
    fill(a,a+n,IINF);
    REP(i,m){
        int u,v;
        cin >> u >> v;
        a[u] = min(a[u],v);
    }
    int bmin=IINF;
    REP(i,n){
        bmin = min(bmin,a[i]);
        if(i==bmin-1){
            ans++;
            bmin = IINF;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb(x) push_back(x)

typedef pair<ll,ll> pp;
int lcm(int a, int b)
{
    int lar = max(a, b);
    int small = min(a, b);
    for (int i = lar; ; i += lar) {
        if (i % small == 0)
            return i;
    }
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

bool sortbysec(const pair<ll,ll> &a, const pair<ll,ll> &b) {
    return (a.second < b.second);
}

ll power(ll x, unsigned ll y, ll p){
    ll res = 1;
    x = x % p;
    if (x == 0) return 0;
    while (y > 0){
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

ll lis( ll arr[], ll n )
{
    ll lis[n];
   
    lis[0] = 1;
  
    /* Compute optimized LIS values in bottom up manner */
    for (ll i = 1; i < n; i++)
    {
        lis[i] = 1;
        for (ll j = 0; j < i; j++ )
            if ( arr[i] > arr[j] && lis[i] < lis[j] + 1)
                lis[i] = lis[j] + 1;
    }
  
    // Return maximum value in lis[]
    return *max_element(lis, lis+n);
}

void solve(){
    ll n;
    set<string> s;
    cin >> n;
    for(ll i = 0;i < n;i++){
        string x; cin >> x;
        s.insert(x);
    }
    cout << s.size() << endl;
}

int main()
{
    //ll t; cin >> t; while(t--)
        solve();
}


Measured memory_bytes: 19104
#include<iostream>
#include<cmath>
#include<vector>
#include<string>

using namespace std;

int main(void){
  int loop,seqsize,srch,searchsize,guard_index,count=0;
  cin>>seqsize;
  guard_index=seqsize;
  vector<int> seq(seqsize+1);
  for(int i=0;i<seqsize;i++) cin>>seq.at(i);
  cin>>searchsize;
  vector<int> search(searchsize);
  for(int i=0;i<searchsize;i++) cin>>search.at(i);

  for(int i=0;i<searchsize;i++){
    srch=search.at(i);
    loop=0;
    seq.at(guard_index)=srch;
    while(seq.at(loop)!=srch) loop++;
    if(loop==guard_index) continue;
    count++;
  }
  cout<<count<<endl;
  return 0;
}



Measured memory_bytes: 3132
#include<iostream>
using namespace std;
int main ()
{
    int a[105],i,n,j,temp=0,sum1=0,sum2=0;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            if(a[i]<=a[j])
            {
                temp=a[i];
                a[i]=a[j];
                a[j]=temp;
            }
        }
    }
    for(i=0;i<n;i++)
    {
        if(i%2==0)
            sum1=sum1+ a[i];
        else
            sum2=sum2+ a[i];
    }
    cout<<(sum1-sum2)<<endl;

}


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

int main(){
    string s;
    cin >> s;
    ll ans=0;
    ll l;
    string c;
    l=s.size();
    rep(i,l){
        c=s[i];
        ans+=atoi(c.c_str());
    }

    if(ans%9==0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    

    return 0;
}

Measured memory_bytes: 3752
from collections import deque
n, m = map(int, input().split())
table = [[] for _ in range(n + 1)]
for _ in range(m):
    a, b = map(int, input().split())
    table[a].append(b)
    table[b].append(a)

ans = [0] * (n + 1)
ans[1] = -1
queue = deque()
for s in table[1]:
    ans[s] = 1
    # 注目してるノード番号, ひとつ前の番号
    queue.append((s, 1))
while len(queue) > 0:
    node = queue.popleft()
    for t in table[node[0]]:
        if ans[t] != 0 or t == 0:
            continue
        ans[t] = node[0]
        queue.append((t, node[0]))
if 0 in ans[2:]:
    print("No")
else:
    print("Yes")
    for a in ans[2:]:
        print(a)


Measured memory_bytes: 95124