akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
#define M 1000000007
ll fermat(ll number,ll exponent)
{
    if(exponent==1)
        return number;

    ll ans=fermat(number,exponent/2);

    ans=(ans*ans)%M;
    if(exponent%2)
        ans =(ans * number)%M;

    return ans;

}
int sieve[1000001];
int coun[1000001];
void sieveOfEratosthenes(){

int i,j;
for(i=1;i<=1000000;i++)
        sieve[i]=i;

    for(i=2;i<=1000;i++)
         if(sieve[i]==i)
        for(j=2*i;j<=1000000;j+=i)
            sieve[j]=min(sieve[j],i);

}



void expo(int a)
{
    if(a==1)
        return ;
    int pri=sieve[a];
    int cou=1;
    while(a>1)
    {
        a=a/sieve[a];

        if(pri==sieve[a])
          cou++;
          else

          {
              coun[pri]=max(coun[pri],cou);
              cou=1;
              pri=sieve[a];
          }



    }
    coun[pri]=max(coun[pri],cou);

}

int main()
{

    int i,j;
    sieveOfEratosthenes();
    long long int mul_prime=1;

    int n;
    cin>>n;
    int a[n];
    int lar=1;

    for(i=0;i<n;i++)
    {
        cin>>a[i];
        lar=max(lar,a[i]);

        expo(a[i]);


    }
    for(i=2;i<=lar;i++)
        if((sieve[i]==i) && coun[i])

    {
        for(j=1;j<=coun[i];j++)
            mul_prime=(mul_prime*i)%M;

    }

    ll ans=0;


    for(i=0;i<n;i++)
    {

        ll inverse=fermat(a[i],M-2);

        ans=(ans+(mul_prime*inverse)%M)%M;


    }




    cout<<ans<<endl;





    return 0;
}


Measured memory_bytes: 7808
import numpy as np
import sys
from functools import lru_cache

def main():
    n, q = map(int, input().split())
    ab = [[],[]]
    
    for i in range(n-1):
        na,nb = map(int, input().split())
        ab[0].append(na)
        ab[1].append(nb)

    px = [[],[]]
    for i in range(q):
        np,nx = map(int, input().split())        
        px[0].append(np)
        px[1].append(nx)
    
    # print(n,q,ab,px)
    count = [0 for i in range(n)]

    oya_list = [0 for i in range(n)]
    for i in range(len(ab[1])):
        oya_list[ab[1][i]-1] = ab[0][i]
    
    for i in range(len(px[1])):
        count[px[0][i]-1] += px[1][i]
        
    for i in range(1,n):

        count[i] += count[oya_list[i]-1]
    
    print(' '.join(map(str,count)))


if __name__ == '__main__':
    main()

Measured memory_bytes: 69448
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;


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

	cin >> N >> H >> W;
	vector<int>v(N*W + 1);
	for (int i = 0; i < N; i++) {
		cin >> K;
		if (i & 1) {
			v[i*W - K]++;
			v[i*W + W - K]--;
		}
		else {
			v[i*W + K]++;
			v[i*W + W + K]--;
		}
	}
	for (int i = 1; i <= N * W; i++)v[i] += v[i - 1];
	int ans = 0;
	for (int i = 0; i < N*W; i++) {
		if (!v[i])ans += H;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3236
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use std::cmp::*;
use std::collections::*;
use std::mem::*;

fn main() {
    let (r, w, e) = (std::io::stdin(), std::io::stdout(), std::io::stderr());
    let mut io = IO::new(r.lock(), w.lock(), e.lock());
    let n = io.read::<usize>();
    let mut v = vec![2; 10000001];
    v[1] = 1;
    for i in 2..n + 1 {
        for j in 2..n * 2 {
            if i * j > n {
                break;
            }
            v[i * j] += 1;
        }
    }
    let mut ans = 0;
    for i in 1..n + 1 {
        ans += i * v[i];
    }
    io.writeln(ans);
}

static MX: usize = 1010101;
static MOD: i64 = 1000000007;
static INF: i64 = std::i64::MAX >> 1;
// IO
use std::io::*;
struct IO<R: Read, W: Write, E: Write> {
    Read: R,
    Write: BufWriter<W>,
    Error: BufWriter<E>,
}
impl<R: Read, W: Write, E: Write> IO<R, W, E> {
    fn new(r: R, w: W, e: E) -> IO<R, W, E> {
        IO {
            Read: r,
            Write: BufWriter::new(w),
            Error: BufWriter::new(e),
        }
    }
    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
    {
        let next: String = self
            .Read
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect();
        next.parse().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    fn chari(&mut self) -> Vec<i64> {
        self.chars()
            .iter()
            .map(|&c| (c as u8 - b'0') as i64)
            .collect::<Vec<i64>>()
    }
    fn readn<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect::<Vec<_>>()
    }
    fn readmat<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n).map(|_| self.readn(m)).collect()
    }
    fn write<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
    }
    fn writeln<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
        self.Write.write(b"\n");
    }
    fn debug<S: std::fmt::Debug>(&mut self, val: S) {
        writeln!(self.Error, "(debug) {:?}", &val);
    }
    fn debug2<S: std::fmt::Debug, T: std::fmt::Debug>(&mut self, val1: S, val2: T) {
        writeln!(self.Error, "(debug2) {:?} -> {:?}", val1, val2);
    }
    fn debug3<S: std::fmt::Debug, T: std::fmt::Debug, U: std::fmt::Debug>(
        &mut self,
        val1: S,
        val2: T,
        val3: U,
    ) {
        writeln!(
            self.Error,
            "(debug3) {:?} -> {:?} -> {:?}",
            val1, val2, val3
        );
    }
}


Measured memory_bytes: 80168
from collections import defaultdict as dd
from itertools import product

N,M,X=map(int,input().split())
a = [list(map(int,input().split())) for _ in range(N)]
res = 10**18
gen = [0,1]
for ls in product(gen,repeat=N):
    tmp = 0
    tmp2 = [0]*M
    for i in range(N):
        if ls[i] == 1:
            tmp += a[i][0]
            for j in range(M):
                tmp2[j] += a[i][j+1]
    for j in range(M):
        if tmp2[j] < X:
            tmp = 10**18
            break
    if tmp < res:
        res = tmp

if res == 10**18:
    print(-1)
else:
    print(res)


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

using namespace std;


int dig(long long n) {
    return n ? dig(n / 10) + 1 : 0;
}

long long g(long long n, long long div) {
    long long ans = 0;
    long long s = 1;
    int d = dig(n);
    for (long long i = dig(div); i <= d; i++) {
        long long l = s, r = 10 * n;
        while (l != r) {
            long long m = (l + r) / 2;
            if (dig(div * m) > i) {
                r = m;
            } else {
                l = m + 1;
            }
        }
        ans += 1ll * i * min(l - s, n / div + 1 - s);
        s = l;
    }
    return ans;
}

long long f(long long n) {
    return (n / 3) * 4 + (n / 5) * 4 + g(n, 1) - g(n, 3) - g(n, 5) + g(n, 15);
}

int main() {
    long long s;
    cin >> s;
    --s;
    long long l = 0, r = 1e18 / 4;
    while( l != r ){
        long long m = (l + r + 1) / 2;
        if( f(m) < s ){
            l = m;
        }else{
            r = m - 1;
        }
    }

    long long lo = s - f(l);
    stringstream ss;
    for(long long i = l+1 ; i <= l + 20 ; i++){
        if( i % 15 == 0 ){
            ss << "FizzBuzz";
        }else if( i % 3 == 0 ){
            ss << "Fizz";
        }else if( i % 5 == 0 ){
            ss << "Buzz";
        }else{
            ss << i;
        }
    }
    cout << ss.str().substr(lo, 20) << endl;
    return 0;
}



Measured memory_bytes: 3212
s=list(map(int,input().split()))
a=s[0]
b=s[2]
for i in range(200):
  if a<=0:
    break
  if b<=0:
    break
  b=b-s[1]
  a=a-s[3]
if a<=0:
  if b<=0:
    print('Yes')
  else:
    print('No')
else:
  print('Yes')

Measured memory_bytes: 9208
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cstdio>
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define RREP(i,x) for(int i=(x);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();++i)
const int INF = 1000000000;


class DP{
public:
	int cost, n, x;
	
	DP(){}
	DP(int cc, int nn, int xx){
		cost = cc;x=xx;n=nn;
	}
	
	bool operator< (const DP &opp) const {
		return cost>opp.cost;
	}
};
int memo[105][105];
int N, M, L, K, A, H;
main(){
	int i,j;
	while(cin >> N >> M >> L >> K >> A >> H, N){
		vector< vector<pii> > g(N);
		set<int> freeze;
		REP(i, L){
			int x;
			cin >> x;
			freeze.insert(x);
		}
		REP(i, K){
			int x, y, t;
			cin >> x >> y >> t;
			g[x].push_back(pii(y, t));
			g[y].push_back(pii(x, t));
		}
		REP(i, N)REP(j, M+1) memo[i][j] = INF;
		priority_queue<DP> dp;
		DP S;
		dp.push(DP(0, A, M));
		while(!dp.empty()){
			S = dp.top();
			dp.pop();
			if(S.n == H) break;
			FOR(it, g[S.n]){
				DP T=S;
				T.x -= it->second;
				if(T.x < 0) continue;
				T.n = it->first;
				T.cost += it->second;
				if(memo[T.n][T.x] > T.cost){
					memo[T.n][T.x] = T.cost;
					dp.push(T);
				}
				if(freeze.count(T.n)){
					while(++T.x <= M){
						T.cost ++;
						if(memo[T.n][T.x] > T.cost){
							memo[T.n][T.x] = T.cost;
							dp.push(T);
						}
					}
				}
			}
		}
		if(S.n == H) cout << S.cost << endl;
		else cout << "Help!" << endl;
	}
	return 0;
}

Measured memory_bytes: 1628
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt(), d = sc.nextInt();
		if(a + b > c + d) {
			System.out.println("Left");
		} else if(a + b == c + d) {
			System.out.println("Balanced");
		} else {
			System.out.println("Right");
		}
	}
}


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

int main() {
    
    int n; cin >> n;    
    int ans = 0;
    vector<int> num(n + 1, 0); 
    for (int x = 1; x * x <= n; x++) {
        for (int y = 1; y * y <= n; y++) {
            for (int z = 1; z * z <= n; z++) {
                int tmp = 0;
                tmp += x * x + y * y + z * z;
                tmp += x * y + y * z + z * x;
                if (tmp <= n) num[tmp]++;
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        cout << num[i] << endl;
    } 
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <vector>

#define what_is(x) cerr << #x << " is " << x << endl;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

using namespace std;

const int N = 100005;
int a[N];
bool dp[N];

int main() {

    int n, k; cin >> n >> k;
    rep (i, 0, n) cin >> a[i];
    dp[0] = true;
    for (int i = 1; i < N; ++i) {
        bool winning = true;
        for (int j = 0; j < n; ++j) {
            if (i-a[j] >= 0 && dp[i-a[j]]) {
                winning = false;
                break;
            }
        }
        dp[i] = winning;
    }
    if (dp[k]) cout << "Second" << endl;
    else cout << "First" << endl;

    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")

const int maxn = 2e5 + 20, lg = 20, inf = 1e9 + 5;

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

    int n;
    cin >> n;
    int p[n], q[n], a[n];

    long long fact = 1;
    for(int i = 0; i < n; i++){
        cin >> p[i];
        fact *= (i + 1);
        a[i] = i + 1;
    }
    for(int i = 0; i < n; i++)
        cin >> q[i];
    int b = memcmp(p, q, sizeof p);
    long long ans = 0;
    while(memcmp(p, q, sizeof q)){
        ans++;
        next_permutation(p, p + n);
    }
    if(b <= 0)
        cout << ans;
    else
        cout <<fact - ans;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


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

    ll n,k;
    string s;
    cin >> n >> k >> s;
    s[k-1] = s[k-1]+32;
    cout << s << endl; 

    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 256
#include<stdio.h>

int main(){
		char a[111][111];
		int n, m, i, j;
		scanf("%d %d", &n, &m);
		getchar();
		for(i = 0; i < n; i++)
			gets(a[i]);
		for(i = 0; i < n; i++)
			for(j = 0; j < 2; j++)
				puts(a[i]);
		return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <algorithm>
#include <unordered_map>
#define int                long long
#define pb                 push_back
#define pi                 pair<int,int>
#define vi                 vector<int>
#define all(v)             v.begin(),v.end()
#define MOD                1000000007
#define F                  first
#define S                  second
#define FOR(i,r)           for(int i=0;i<r;i++)
#define REP(i,l,r)         for(int i=l;i<r;i++)
#define RER(i,l,r)         for(int i=l;i>=r;i--)
#define print(v)           for(auto i : v)cout << i << ' ';
#define FASTIO             ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mem(arr,k)         memset(arr,k,sizeof(arr));
#define pii                acos(-1.0)
#define PI                 3.1415926535897932385
#define Sin(a)             sin((pi*a)/180)
#define remax(a,b)         a=max(a,b)
#define remin(a,b)         a=min(a,b)
#define bitcount(x)        __builtin_popcountll(x)
#define iceil(n,x)         (((n)-1)/(x)+1)
#define flush              fflush(stdout)
#define pf                 push_front()
#define pob                pop_back()
#define ins                insert
#define mii                map<int,int> 
#define show(x)            for(auto zz:x)cout<<zz<<" ";cout<<"\n";
#define show2(x)           for(auto zz:x)cout<<zz.F<<" "<<zz.S<<"\n";
#define test()             int x;cin >> x;while(x--){solve();}
#define test2()            int x;cin >> x;for(int i=1;i<=x;i++){cout << "Case #" << i << " : ";solve();}
#define watch(x)           cout << (#x) << " is " << (x) << endl
using namespace std;


/* Mathematical Functions */
int power(int x,int y);
bool isPrime(int n);
int modInv(int a,int b);
int gcdExtended(int a,int b,int *x,int* y);
int mpower(int a,int b,int p);

const int inf = (int)1e17;
const int N = (int)3e5+5;

int32_t main(){

	
	FASTIO;
	int a;
	cin >> a;
	cout << a+a*a+a*a*a << endl;
    return 0;

}
int modInv(int a, int m)
{
int x, y;
int g = gcdExtended(a, m, &x, &y);
int res = (x%m + m) % m;
return res;
}
 
int gcdExtended(int a, int b, int *x, int *y)
{
if (a == 0){
    *x = 0, *y = 1;
    return b;
  }
  int x1, y1;
  int gcd = gcdExtended(b%a, a, &x1, &y1);
  *x = y1 - (b/a) * x1;
  *y = x1;
  return gcd;
}
 
int mpower(int x, int y, int p)
{
int res = 1;
x = x % p;
while(y > 0){
    if(y & 1) res = (res*x) % p;
      y = y>>1;
      x = (x*x) % p;
    }
    return res;
}
int power(int x, int y)
{
int res = 1;
while (y > 0){
    if (y & 1) res = res*x;
      y = y>>1;
      x = x*x;
    }
    return res;
}
 
bool isPrime(int n)
{
if (n <= 1)  return false;
  if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
      int p=sqrt(n);
      for(int i=5;i<=p;i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
          return false;
      return true;
}

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    ll N, K;
    cin >> N >> K;
    Vl V(N);
    for (ll i = 0; i < N; i++) {
        cin >> V[i];
    }

    ll ans = 0;
    Vl negas;
    for (ll l = 0; l <= min(N, K); l++) {
        for (ll r = 0; l + r <= min(N, K); r++) {
            ll score = 0;
            negas.clear();
            for (ll i = 0; i < l; i++) {
                score += V[i];
                if (V[i] < 0) {
                    negas.emplace_back(V[i]);
                }
            }
            for (ll i = 0; i < r; i++) {
                score += V[N - 1 - i];
                if (V[N - 1 - i] < 0) {
                    negas.emplace_back(V[N - 1 - i]);
                }
            }

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

            for (ll i = 0; i < min(K - (l + r), (ll)negas.size()); i++) {
                score -= negas[i];
            }

            ans = max(ans, score);
        }
    }

    cout << ans << "\n";
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    long long a[n],b[n],c[n];
    long long cnt[n+1];
    for(int i=0;i<n+1;i++){
        cnt[i] = 0;
    }
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    for(int i=0;i<n;i++){
        cin >> b[i];
    }
    for(int i=0;i<n;i++){
        cin >> c[i];
    }
    sort(a,a+n);
    sort(b,b+n);
    sort(c,c+n);
    for(int i=n-1;i>=0;i--){
        long long *pos;
        pos = upper_bound(c,c+n,b[i]);
        cnt[i] = cnt[i+1] + distance(pos,c+n);
    }
    long long ans=0;
    for(int i=0;i<n;i++){
        long long *pos;
        pos = upper_bound(b,b+n,a[i]);
        ans += cnt[distance(b,pos)];
    }
    cout << ans << endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    double a,b,c,d,e,f;
    double ans = 0;
    double mizu = 0;
    double satou = 0;
    cin >> a >> b >> c >> d >> e >> f;
    for(int i = 0; i <= 30; i++){
        for(int j = 0; j <= 30; j++){
            for(int k = 0; k <= 100; k++){
                for(int l = 0; l <= 100; l++){
                    //操作1,2,3,4をi,j,k,l回ずつ
                    if( 100*a * i + 100*b * j + c * k + d * l <= f ){
                        if( e * (100*a * i + 100*b * j + c * k + d * l)  >= (c * k + d * l) * (100 + e)    ){
                            if( ans <= (c * k + d * l) / (100*a * i + 100*b * j + c * k + d * l) ){
                                ans =  (c * k + d * l) / (100*a * i + 100*b * j + c * k + d * l);
                                mizu = 100*a * i + 100*b * j;
                                satou = c * k + d * l;
                            }
                            
                            
                            
                        }
                    }
                    
                    
                    
                }
            }
        }
    }
    
    cout << mizu + satou << " " <<  satou << endl;
    
    
    
}


Measured memory_bytes: 384
// A Dynamic Programming based solution for 0-1 Knapsack problem 
#include<bits/stdc++.h> 
#define int long long int
// A utility function that returns maximum of two integers 
using namespace std;
//int max(int a, int b) { return (a > b)? a : b; } 

// Returns the maximum value that can be put in a knapsack of capacity W 
int knapSack(int W, int wt[], int val[], int n) 
{ 
int i, w; 
int K[n+1][W+1]; 

// Build table K[][] in bottom up manner 
for (i = 0; i <= n; i++) 
{ 
	for (w = 0; w <= W; w++) 
	{ 
		if (i==0 || w==0) 
			K[i][w] = 0; 
		else if (wt[i-1] <= w) 
				K[i][w] = max(val[i-1] + K[i-1][w-wt[i-1]], K[i-1][w]); 
		else
				K[i][w] = K[i-1][w]; 
	} 
} 

return K[n][W]; 
} 

signed main() 
{ 
	int n,W;
	cin>>n>>W;int wt[n],val[n];
	for(int i=0;i<n;i++)
	{
	    cin>>wt[i];
	    cin>>val[i];
	}
	cout<<knapSack(W, wt, val, n); 
	return 0; 
} 


Measured memory_bytes: 79104
using System;

namespace atcoderA
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int a = int.Parse(Console.ReadLine());
            int b = int.Parse(Console.ReadLine());
            int h = int.Parse(Console.ReadLine());
            Console.WriteLine((a + b) * h / 2);
        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;

int N;
// a：時計回り　ｂ：反時計回り
ll C,X[101010],V[101010],a[101010],b[101010];

int main(){
  cin>>N>>C;
  ll ans=0;
  rep(i,N) cin>>X[i+1]>>V[i+1];

  rep(i,N) a[i+1]=a[i]+V[i+1]-(X[i+1]-X[i]);
  rep(i,N) a[i+1]=max(a[i+1],a[i]);

  X[N+1]=C;
  for(int i=N;i>=0;i--) b[i]=b[i+1]+V[i]-(X[i+1]-X[i]);
  for(int i=N;i>=0;i--) b[i]=max(b[i],b[i+1]);

  for(int i=1;i<=N;i++){
    ans=max(ans,a[i]);
    ans=max(ans,b[i]);
    ans=max(ans,a[i]+b[i+1]-min(X[i],(C-X[i+1])));
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3328
from itertools import *
import sys
md=10**9+7
mis=map(int,sys.stdin.readline().split())

h,w=mis
t=[[0]*(w+1) for _ in range(h+1)]
s=[]
for _ in range(h):
    s+=[input()]

for i,j in product(range(h),range(w)):
    if i==0 and j==0:
        t[i+1][j+1]=1
    elif s[i][j]==".":
        t[i+1][j+1]=(t[i][j+1]+t[i+1][j])%md
    else:
        t[i+1][j+1]=0
print(t[-1][-1])


Measured memory_bytes: 43708
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n;
    std::cin >> n;
    int a[100001];
    int fcnt=0,tcnt=0;
    for (int i = 1; i <= n; i++) {
        std::cin >> a[i];
        if(a[i]%4==0){
            fcnt++;
        }else if(a[i]%2==0){
            tcnt++;
        }
    }
    bool flag=false;
    
    if(fcnt>=n/2 || tcnt/2+fcnt>=n/2){
        flag=true;
    }
    
    
    if(flag){
        std::cout << "Yes" << std::endl;
    }else{
        std::cout << "No" << std::endl;
    }
}


Measured memory_bytes: 768
#include <iostream>
#include <array>
#include <vector>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>

using namespace std;

typedef  pair<int,int> P;
typedef long long LL;
typedef vector<LL> VEC;


const LL INF=1<<30;
const LL MOD=1000000007;

LL gcd(LL a,LL b){
    if(b==0)return a;

    return gcd(b,a%b);
}

LL kaijo(LL n){
    LL ans=1;
    for(LL i=1;i<=n;++i){
        (ans*=i)%=MOD;
    }
    return ans;
}


int main(){
    string s;
    cin>>s;
    if(s[0]==s[2])cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)
#define bg begin()
#define ed end()
#define all(x) x.bg, x.ed
#define vi vector<int>
template <class t, class u>
bool chmax(t &a, u b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class t, class u>
bool chmin(t &a, u b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}
signed main()
{
    ll n;
    cin >> n;
    vector<ll> a;
    rep(i, 5)
    {
        ll b;
        cin >> b;
        a.push_back(b);
    }
    sort(all(a));
    cout << (n + a[0] - 1LL) / a[0] + 4LL << endl;
    return 0;
}

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

#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (long long)(a); i <= (long long)(n); i++)
#define irrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define irrep2(i,a,n) for(int i = (int)(n); i >= (int)(a); i--)

typedef long long ll;
typedef std::vector<int> v_int;
typedef std::vector<v_int > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<v_ll > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<v_string > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<v_bool > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

const double PI = 3.1415926535897932;
const int INF = (int)1e9;
const ll LINF = 1e18;
const int IMOD = 1000000007;
const int dr[4] = {1, 0, -1, 0};
const int dc[4] = {0, 1, 0, -1};

using namespace std; 

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

    v_int ans(s.size());
    
    int r = 0;
    irep(i, s.size()-1) {
        if(s[i] == 'R') r++;
        if(s[i] == 'R' && s[i+1] == 'L') {
            ans[i] += (r+1)/2;
            ans[i+1] += (r)/2;
            r = 0;
        }
    }
    
    int l = 0;
    irrep2(i, 1, s.size()-1) {
        if(s[i] == 'L') l++;
        if(s[i-1] == 'R' && s[i] == 'L') {
            ans[i] += (l+1)/2;
            ans[i-1] += (l)/2;
            l = 0;
        }
    }
    irep(i, s.size()) {
        printf("%d ", ans[i]);
    }
    return 0;
}
/** atcoder **/



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <fstream>
#include <vector>
#include <bitset>
#include <unordered_map>
#include <algorithm>
#include <queue>
#include <math.h>
#include <iomanip>

using namespace std;

/********** TEMPLATE STARTS HERE ***********/

#define IOS ios::sync_with_stdio(false), cin.tie(0);
#define all(v) v.begin(), v.end()
#define F first
#define S second
#define pb push_back
#define PI 3.1415926535897932384626433832795
#define gcd __gcd 
#define digits(n) (int)(log10(n) + 1)

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <long long> vl;
typedef vector <pll> vll;
typedef vector <pii> vii;

const int INF = 0x3f3f3f3f;
const int LINF = 0x3f3f3f3f3f3f3f3f;

template <typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template <typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

/*********** TEMPLATE ENDS HERE *************/

main()
{
	IOS
	
	int A, B, C, x, y;
	
	cin >> A >> B >> C >> x >> y;
	
	int money = A * x + B * y;
	
	if(x > y)
	{	
		money = min(money, C * x * 2);
		money = min(money, C * y * 2 + (x - y) * A);
	}
	else
	{
		money = min(money, C * x * 2 + (y - x) * B);
		money = min(money, C * y * 2);
	}
	
	cout << money;
}

Measured memory_bytes: 256
N=int(input())
A=int(input())
B=int(input())
C=int(input())
D=int(input())
E=int(input())
F=min(A,B,C,D,E)
if N%F==0:
    print(5+(N//F)-1)
else:
    print(5+((N//F)+1)-1)

Measured memory_bytes: 3064
n=int(input())
l=sorted(list(map(int,input().split())))
variety=0
countodd=0
counteven=0
countnow=1
now=l[0]
for i in range(1,n):
  if l[i]==now:
    countnow+=1
  else:
    now=l[i]
    if countnow%2==1:
      countodd+=1
    else:
      counteven+=1
    countnow=1
if countnow!=0:
  if countnow%2==1:
    countodd+=1
  else:
    counteven+=1
if counteven%2==0:
  print(counteven+countodd)
else:
  print(counteven+countodd-1)


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

using namespace std;
typedef long long ll;

const ll mod = 1e9 + 7;

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n; cin >> n;
    ll s = 0, r = 0;
    vector<ll> a(n);
    for (ll &i : a) {
        cin >> i; s += i;
    }
    s %= mod;
    for (ll i : a) {
        s -= i;
        s %= mod;
        r += s * i;
        r %= mod;
    }
    cout << (r + mod) % mod << endl;
    return 0;
}



Measured memory_bytes: 4764
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define repn(i, x) for (int i = 1; i <= (int)(x); i++)
#define repr(i, x) for (int i = ((int)(x) - 1); i >= 0; i--)
#define reprn(i, x) for (int i = ((int)(x)); i > 0; i--)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
void solve() {
	int N; cin >> N;
	vector<int> d(N);
	for (int i = 0; i < N; ++i) {
		cin >> d[i];
	}
	int ans = 0;
	for (int i = 0; i < (N - 1); ++i) {
		for (int j = i + 1; j < N; ++j) {
			ans += (d[i] * d[j]);
		}
	}
	cout << ans << endl;
	return;
}

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

Measured memory_bytes: 256
while True:
    x=int(input())
    if x==0:
        break
    a=1000-x
    b=a//500
    c=a%500
    d=c//100
    e=c%100
    f=e//50
    g=e%50
    h=g//10
    i=g%10
    j=i//5
    k=i%5
    print(b+d+f+h+j+k)


Measured memory_bytes: 5592
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

void maxAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) max(dst, src);
}

enum MOD = (10 ^^ 9) + 7;

void main()
{
    string s;
    string input = sread();
    foreach (c; input)
    {
        switch (c)
        {
        case '0':
            s ~= '0';
            break;
        case '1':
            s ~= '1';
            break;
        case 'B':
            if (!s.empty)
                s.popBack();
            break;
        default:
            assert(0);
        }
    }
    writeln(s);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define ld long double
#define fi first
#define se second
#define all(uiet) uiet.begin(),uiet.end()
#define read(UIET) for(int i = 0; i < n; ++i) cin >> UIET[i]
#define out(UIET) for(int i = 0; i < n; ++i) cout << UIET[i]
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define vpp vector<pair< int, int > >
#define pll pair<int , int >
#define ppll pair < pll , pll >
#define debug(n1) cout << n1 << endl
#define len(a) ((int) (a).size())
#define endl "\n"
#define mod 1000000007
const int INF=(1LL<<60)-1;
const int maxN = 1000001;
string extractStringAtKey(string str, int key){
    char *s = strtok((char *)str.c_str(), " ");
    while(key > 1){
        s = strtok(NULL, " ");
        key--;
    }
    return (string)s;
}
bool prime[maxN + 1];
void seive(){
    memset(prime, true, sizeof(prime));
    for(int i = 2; i * i <= maxN; ++i){
        if(prime[i]){
            for(int j = i * i; j <= maxN; j += i){
                prime[j] = false;
            }
        }
    }
}
int32_t main(){
    SPEED;
    int n;
    cin >> n;
    if(n == 1){
        cout << 1 ;
        return 0;
    }
    int ans = -INF;
    for(int i = 1; i <= n; ++i){
        for(int j = 2; j < 50; ++j){
            int cal = pow(i, j);
            if(cal <= n){
                int res = pow(i, j);
                ans = max(ans, res);
            }
        }
    }
    cout << ans ;
}

Measured memory_bytes: 4212
#include<bits/stdc++.h>
using namespace std;
#define SORT(c) sort((c).begin(),(c).end());
#define pb push_back
#define MP make_pair
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define pi 3.141592653589793
#define ll long long
#define ull unsigned long long
#define w(x) int x;cin>>x;while(x--)
#define fast ios_base::sync_with_stdio(0)
#define sz size()
typedef unsigned long long UL;
template<typename T>inline T  S(T a)
{
    return a*a;
}
template<class T>inline string tostring(T a)
{
    ostringstream os("");
    os << a;
    return os.str();
}
template<typename T>inline ll tolong(T a)
{
    ll res;
    istringstream os(a);
    os>>res;
    return res;
}
template<typename T>inline T gcd(T a, T b)
{
    if (b == 0)return a;
    else return gcd(b, a % b);
}
template<typename T>inline T bigmod(T a, T b, T m)
{
    if (b == 0)return 1;
    else if (b % 2 == 0)return S(bigmod(a, b / 2, m)) % m;
    else return (a % m*bigmod(a, b - 1, m)) % m;
}
const int inf = (int)1e9 + 5;
const ll linf = (ll)1e16 + 5;
const ll modd = (ll)1e9 + 7;
const int mod = 10000007;
/*#define N 20000009
bool prime[N];
vector<ll> prm;
void seive ()
{

    memset(prime, true, sizeof(prime));

    for( ll i=2; i*i<=N; i++)
    {
        if (prime[i] == true)
        {
            prm.pb(i);
            for (ll j=i*i; j<=N; j += i)
                pe[j] = false;
        }
    }
}*/
void pr (int f)
{
    if(f==1)
        cout<<"YES\n";
    else
        cout<<"NO\n";
}
map<int , int >mp;
set<int > s;
multiset<string> :: iterator it;

deque <char> q ;
ll vis [5510000];
int  visited[230];
int main()
{
    fast ;
    int n;
    cin>> n;
    string s;
    cin>> s ;
    int  szz = s.length();
   // cout<<szz<<endl;
    if(szz<=n)
    {
        cout<<s<<endl;
        return 0;
    }
    else
    {
            for(int i=0; i<n; i++)
                cout<<s[i];
        cout<<"...\n";
    }
}






Measured memory_bytes: 3660
import sys
import heapq, functools, collections
import math, random
from collections import Counter, defaultdict

# available on Google, not available on Codeforces
# import numpy as np
# import scipy

MOD = 998244353

def solve(k, grid):  # fix inputs here
    console("----- solving ------")
    console(grid)
    ways = [1]
    psum = [0,1]
    ps = 1

    for i in range(1,k):
        cur = 0
        for a,b in grid:
            if a > i:
                continue
            if b > i:
                b = i
            console(i-a+1,i-b,i)
            cur += psum[i-a+1] - psum[i-b]

        console()
        console(i, cur, ways, psum)
        console()
         
        ways.append(cur%MOD)
        ps += cur
        psum.append(ps%MOD)


    # return a string (i.e. not a list or matrix)
    return ways[-1]%MOD


def console(*args):  # the judge will not read these print statement
    # print('\033[36m', *args, '\033[0m', file=sys.stderr)
    return

# fast read all
# sys.stdin.readlines()

for case_num in [1]:
    # read line as a string
    # strr = input()

    # read line as an integer
    # k = int(input())
    
    # read one line and parse each word as a string
    # lst = input().split()

    # read one line and parse each word as an integer
    k, nrows = list(map(int,input().split()))

    # read matrix and parse as integers (after reading read nrows)
    # lst = list(map(int,input().split()))
    # nrows = lst[0]  # index containing information, please change
    grid = []
    for _ in range(nrows):
        grid.append(list(map(int,input().split())))

    res = solve(k, grid)  # please change
    
    # Google - case number required
    # print("Case #{}: {}".format(case_num+1, res))

    # Codeforces - no case number required
    print(res)


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

int n ;
ll a[300100];
ll ans , sum;

int main(){

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

ans=1ll<<60;
for(int i=2;i<=n;i++)a[i]+=a[i-1];
for(int i=1;i<n;i++)
    ans=min( ans , abs(sum-a[i]-a[i]) );

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


Measured memory_bytes: 1792
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		while(in.hasNext())
		{
			int N=in.nextInt();
			char c[]=in.next().toCharArray();
			int cnt=0;
			for(int i=0;i<N;i++)
			{
				char old[]=in.next().toCharArray();
				for(int j=0;j<old.length;j++)
				{
					boolean judge=true;
					for(int k=1;j+(c.length-1)*k<old.length;k++)//文字間隔を全通り試す
					{
						judge=true;
						for(int l=0;l<c.length;l++)
						{
							if(old[j+l*k]!=c[l])
							{
								judge=false;
								break;
							}
						}
						if(judge)
						{
							cnt++;
							break;
						}
					}
					if(judge)
						break;
				}
			}
			System.out.println(cnt);
		}
	}
}

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

#define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define lli long long int
#define rep(i,n,z) for(int i=z;i<n;i++)
#define rrep(i,z) for(int i=z;i>=0;i--)
#define nl cout<<endl
#define vi vector<int>
#define vlli vector<long long int>
#define umap unordered_map
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define ipair pair <int,int>
#define llipair pair <lli,lli>
#define pq priority_queue
#define displaymatrix(a,m,n) for(int i=0;i<m;i++){for(int j=0;j<n;j++)cout<<a[i][j]<<" ";cout<<endl;}
#define printarray(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}nl;
#define vinput(a,n) vlli a(n);rep(i,n,0)cin>>a[i]
#define ainput(a,n) rep(i,n,0)cin>>a[i]
#define SO(a) sort(a.begin(),a.end())
#define all(x) (x).begin(),(x).end()
#define SOP(a,comp) sort(a.begin(),a.end(),comp)
#define inf INT_MAX
#define endl '\n'

int main()
{
    fastio;
    int n;
    cin>>n;
    vinput(a,n);
    for(int i=n-2;i>=0;i--){
        if(a[i]>a[i+1])a[i]--;
    }
    rep(i,n-1,0){
        if(a[i]>a[i+1]){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}


Measured memory_bytes: 1024
#-swank
(unless (member :child-sbcl *features*)
  (quit
	:unix-status
	(process-exit-code
	  (run-program *runtime-pathname*
				   `("--control-stack-size" "128MB"
					 "--noinform" "--disable-ldb" "--lose-on-corruption" "--end-runtime-options"
					 "--eval" "(push :child-sbcl *features*)"
					 "--script" ,(namestring *load-pathname*))
				   :output t :error t :input t))))

(defun f (x)
  (if (every (lambda (x) (zerop (mod x 2))) x)
	(1+ (f (mapcar (lambda (x) (ash x -1)) x)))
	0))

(princ (f (loop for i below (read) collect (read))))


Measured memory_bytes: 9656
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <iomanip>
using ll = long long;
using uint = unsigned int;
using graph = std::vector<std::vector<ll>>;
using wGraph = std::vector<std::vector<std::pair<ll,ll>>>;
#define rep(i,n) for (int i=0; i < int(n); i++)

using namespace std;
ll MOD7 = 1000000007;
ll MOD9 = 1000000009;
vector<ll> InputVec(ll N){
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    return A;
}
void OutputVec(vector<ll> A){
    for (int i = 0; i < A.size(); ++i) {
        cout << A[i] << ",";
    }
    cout << endl;
}
vector<vector<ll>> InputVec2d(ll H,ll W){
    vector<vector<ll>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<ll>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        for (int xi = 0; xi < W; ++xi) {
            cin >> A[yi][xi];
        }
    }
    return A;
}
vector<vector<char>> InputVec2dStr(ll H,ll W){
    vector<vector<char>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<char>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        string S;
        cin >> S;
        for (int xi = 0; xi < W; ++xi) {
            A[yi][xi] = S[xi];
        }
    }
    return A;
}
void OutputVec2d(vector<vector<ll>> A){
    for (int yi = 0; yi < A.size(); ++yi) {
        for (int xi = 0; xi < A[yi].size(); ++xi) {
            cout << A[yi][xi] << ",";
        }
        cout << endl;
    }
}
graph InputGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    return G;
}
graph InputDGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
    }
    return G;
}
void OutputGraph(graph G){
    for (int i = 0; i < G.size(); ++i) {
        cout << i << ":";
        for (int j = 0; j < G[i].size(); ++j) {
            cout << G[i][j]<< ",";
        }
        cout << endl;
    }
}
void OutputAnswerBool(bool b,bool isUpperCase = false){
    if(b){
        if(isUpperCase){
            cout << "YES" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }else{
        if(isUpperCase){
            cout << "NO" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

int main() {
    ll N;
    cin >> N;
    auto A = InputVec(N);
    ll count = 1;
    ll minus = 1;
    for (int i = 0; i < N; ++i) {
        count *= 3;
        if(A[i] % 2 == 0){
            minus*=2;
        }else{
            minus*=1;
        }
    }
    cout << count - minus << endl;

}


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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	string X;
	cin >> X;
	ll N = 0;
	for(int i = 0; i < X.size(); i++){
		N = N * 10 + X[i] - '0';
	}
	int L = X.size();

	ll t = 1;
	for(int i = 0; i < L; i++){
		t *= 10;
	}

	vector<int> n;
	for(int i = 0; i < 10; i++){
		n.push_back(i);
	}

	ll maxd = -1;
	string ans;
	do{
		ll k = 0;
		for(int i = 0; i < L; i++){
			k = k * 10 + n[i];
		}
		ll d = min(abs(k - N), t - abs(k - N));
		string s = "";
		for(int i = 0; i < L; i++){
			s += '0' + n[i];
		}
		if(maxd < d || maxd == d && ans > s){
			maxd = d;
			ans = s;
		}
	} while(next_permutation(n.begin(), n.end()));

	cout << ans << endl;
}

Measured memory_bytes: 3212
import java.util.Scanner;

/**
 * Created by sd on 2016/11/22.
 */
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int a[] = new int[N];
        for(int I=0;I<N;I++){
            a[I] = sc.nextInt();
        }

        int count = 0;
        for(int i=0; i<N; i++){
            int minj = i;
            for(int j=i; j<N; j++){
                if(a[j] < a[minj]){
                    minj = j;
                }
            }
            if(i != minj){
                count ++;
            }
            int t = a[i];
            a[i] = a[minj];
            a[minj] = t;
        }
        for(int ii=0; ii<N-1; ii++){
            System.out.print(a[ii]+" ");
        }
        System.out.println(a[N-1]);
        System.out.println(count);
    }
}

Measured memory_bytes: 26168
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
ll mod=998244353LL;
long long modpow(long long a, long long n, long long mod=(1LL<<62)){
	long long res = 1;
	while (n > 0){
		if (n & 1)
		res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
const int MAX = 510000;
const ll MOD = 998244353LL;

long long fac[MAX], finv[MAX], inv[MAX];

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

long long COM(int n, int k){ // 二項係数:nCk計算
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main(){
	int n,m,k;
	COMinit();
	ll ans=0LL;
	cin >>n>>m>>k;
	for(int i=0;i<=k;i++){
		ans+=m*modpow(m-1,n-1-i,mod)%mod*COM(n-1,i)%mod;
		ans%mod;
	//	clog<<ans<<endl;
	}
	cout<<ans%mod<<endl;
}

Measured memory_bytes: 15480
#include<stdio.h>

int main(void)
{
	int h,w,i,j;
	while(1){
		scanf("%d %d",&h, &w);
		if(h == 0 && w == 0)break;
		for(i = 1;i <= h;i++){
			for(j = 1;j <= w;j++){
				if(i % 2 != 0 && j % 2 != 0){
				      printf("#");
			        }else if(i % 2 == 0 && j % 2 == 0){
					printf("#");
				}
				else{
			  	      printf(".");
	  	       	        }
			}
			printf("\n");
		}
	printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,a[200005],ans,g=1;
bool flag;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
	{
		scanf("%d",&a[i]);
		if(a[i]==1) flag=1;
	}
	if(!flag) {printf("-1");return 0;}
	for(int i=1;i<=n;++i)
	{
		if(a[i]!=g) ans++;
		else g++;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 1024
/* ex5_3
   offNaria */
#include <stdio.h>

int main(void){
  int height, width, flag = 0;
  char matrix[100][100];
  int row_removed[100] = {0}, col_removed[100] = {0};
  scanf("%d %d", &height, &width);
  for (int i = 0; i < height; i++)
  {
    flag = 1;
    for (int j = 0; j < width; j++)
    {
      scanf(" %c", &matrix[i][j]);
      if (matrix[i][j] == '#')
      {
        flag = 0; //行内に黒があるなら取り除く対象外
      }
    }
    if (flag == 1)
    {
      row_removed[i] = 1; //すべて白の行は取り除く対象
    }
  }
  for (int j = 0; j < width; j++)
  {
    flag = 1;
    for (int i = 0; i < height; i++)
    {
      if (matrix[i][j] == '#')
      {
        flag = 0; //列内に黒があるなら取り除く対象外
      }
    }
    if (flag == 1)
    {
      col_removed[j] = 1; //すべて白の列は取り除く対象
    }
  }
  for (int i = 0; i < height; i++)
  {
    if (row_removed[i] != 1) //取り除く対象の行でないか
    {
      for (int j = 0; j < width; j++)
      {
        if (col_removed[j] != 1) //取り除く対象の列でないか
        {
          printf("%c", matrix[i][j]);
        }
      }
      printf("\n");
    }
  }
  return 0;
}


Measured memory_bytes: 128