akhauriyash/Code-Regression huggingface dataset:
from collections import deque
s=deque(list(input()))
q=int(input())
direction=0 #0:順 1:逆

for i in range(q):
    query=input()
    if query[0]=='1':
        direction=direction^1
    elif query[0]=='2':
        i,f,c=query.split()
        if f=='1' and direction==0:
            s.appendleft(c)
        elif f=='1' and direction==1:
            s.append(c)
        elif f=='2' and direction==0:
            s.append(c)
        elif f=='2' and direction==1:
            s.appendleft(c)


if direction==0:
    print(''.join(s))
else:
    x=[]
    for i in range(len(s)):
        x.append(s[-1-i])
    print(''.join(x))


Measured memory_bytes: 87912
#include<bits/stdc++.h>
using namespace std;
const int mo=1000000007;
long long dp[2002][2002],sum[2002][2002];
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	int a=n-m;
	dp[0][0]=1;
	sum[1][0]=dp[1][0]=1;
	for(int i=1;i<=n;i++)dp[1][i]=1,sum[1][i]=sum[1][i-1]+1;
	for(int i=2;i<=n;i++){
		dp[i][0]=1;
		sum[i][0]=1;
		for(int j=1;j<=n;j++){
			dp[i][j]=sum[i-1][j]%mo;
			sum[i][j]=(sum[i][j-1]+dp[i][j])%mo;
		}
	}
	for(int i=1;i<=m;i++){
		long long ans=0;
		if(a>=i+1)ans+=(dp[i+1][a-i-1]*dp[i][m-i])%mo;
		if(a>=i)ans+=((dp[i][a-i]*dp[i][m-i])*2)%mo;
		if(a>=i-1)ans+=(dp[i-1][a-i+1]*dp[i][m-i])%mo;
		printf("%lld\n",ans%mo);
	}
	return 0;
}

Measured memory_bytes: 62848
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define REPA(x, v) for(auto&& x:v)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(v.rbegin(),v.rend())
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> void pr_vec(vector<T> &v, char ep=' '){int n=v.size();REP(ni,n){cout<<v[ni];if(ni!=n-1)cout<<ep;}cout<<endl;};
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    int X;
    cin >> X;
    Yes(X>=30);
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fill fill_n
#define pf push_front
#define pb push_back
#define FOR(i,l,r) for(int i=l;i<r;i++)
#define ROF(i,r,l) for(int i=r;i>=l;i--)
#define comp(v) (v).begin(),(v).end()
#define ff first
#define ss second
#define infile freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
typedef vector<int> vi;
typedef vector<ll> vli;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvli;
const int M = 1e9+7;
const int N = 2e5;
ll po(int,int);


void solve(){
    int n;cin>>n;
    ll a[n];
    ll ans=0;
    FOR(i,0,n){
        cin>>a[i];
        ans = (ans^a[i]);
    }
    
    FOR(i,0,n){
        cout<<(ans^a[i])<<" ";
    }
    
    
}





int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    int t=1;
    //cin>>t;
    FOR(i,1,t+1){
        //cout<<"Case #"<<i<<": "; 
        solve();
    }
    
	return 0;
	
	
}


ll po(int a,int b){
    if(b==0) return 1;
    ll ans=1;
    if(b%2==0){
        ans = po(a,b/2)%M;
        ans=(ans%M * ans%M)%M;
    }
    else{
        ans = po(a,(b-1)/2)%M;
        ans = (ans%M * ans%M * a)%M;
    }
    return ans%M;
}


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

#define pb push_back
#define mp make_pair
#define fs first
#define se second

typedef long long LL;

string s;

int main() {
  //  freopen("test.txt","r",stdin);
    cin >> s;
    cout << s[0] << s.size() - 2 << s[s.size() -1];
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N, Q = [int(x) for x in input().split()]

edge = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = [int(x) for x in input().split()]
    edge[a - 1].append(b - 1)
    edge[b - 1].append(a - 1)

cost = [0] * N
for _ in range(Q):
    p, x = [int(x) for x in input().split()]
    cost[p - 1] += x

next = [0]
s_next = {0}
for i in next:
    for v in edge[i]:
        if v in s_next:
            continue
        s_next.add(v)
        next.append(v)
        cost[v] += cost[i]

print(" ".join(map(str, cost)))





Measured memory_bytes: 129572
#include<stdio.h>
int main()
{
	char x[3];
	int i;
	scanf("%s",&x);
	for(i=0;i<3;i++)
	{
		if(x[i]=='9')
		x[i]='1';
		else if(x[i]=='1')
		x[i]='9';
	}	
	printf("%s",x);

}

Measured memory_bytes: 128
import java.io.*;
import java.util.*;

class Main {

	public static void main(String[] args) throws Exception {
		final Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long[] A = new long[N];
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextLong();
		}
		solve(N, A);
	}

	static void solve(int N, long[] A) {
		long[] sum = new long[N + 1];
		for (int i = 0; i < N; i++) {
			sum[i + 1] = sum[i] + A[i];
		}

		int l = 1;
		int r = 3;
		long answer = Long.MAX_VALUE;
		for (int i = 2; i < N - 1; i++) {
			while (l < i - 1 && Math.abs(sum[i] - sum[l] * 2) >
					Math.abs(sum[i] - sum[l + 1] * 2)) {
				l++;
			}

			while (r < N - 1 && Math.abs(sum[N] - sum[i] - (sum[r] - sum[i]) * 2) >
					Math.abs(sum[N] - sum[i] - (sum[r + 1] - sum[i]) * 2)) {
				r++;
			}

			long[] a = new long[]{sum[l], sum[i] - sum[l], sum[r] - sum[i], sum[N] - sum[r]};
			Arrays.sort(a);

			answer = Math.min(answer, Math.abs(a[3] - a[0]));
		}

		System.out.println(answer);
	}
}


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

#define rep(i,n) for(int (i) = 0;i < (int)(n);(i)++)
int main(){
    int n,x;
    int cnt;
    while(1){
        cnt = 0;
        cin >> n >> x;
        if(n == 0 && x == 0) break;
        for(int i = 1; i <= n - 2; i++){
            for(int j = i + 1; j <= n - 1; j++){
                for(int k = j + 1; k <= n; k++){
                    if(i + j + k == x) cnt++;
                }
            }
        }
        cout << cnt << endl;
    }
}



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

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}

int n;
vector<string> s;

int calc(int l, int d){
}

bool solve(){
    cin >> n;
    if(!n)
        return false;
    s.resize(n);
    for(int i = 0; i < n; ++i)
        cin >> s[i];
    for(int i = 0; i < n; ++i){
        for(int j = 1; j < s[i].size(); ++j)
            if(!('a' <= s[i][j - 1] && s[i][j - 1] <= 'z') && 'a' <= s[i][j] && s[i][j] <= 'z'){
                s[i][j - 1] = '+';
                break;
            }
    }
    for(int j = 0; j < 1100; ++j){
        int fl = -1;
        for(int i = 0; i < n; ++i){
            bool out = (s[i].size() <= j || ('a' <= s[i][j] && s[i][j] <= 'z'));
            bool pl = (s[i].size() > j && s[i][j] == '+');
            if(out){
                fl = -1;
                continue;
            }
            if(pl){
                if(fl != -1){
                    for(int k = fl + 1; k < i; ++k)
                        s[k][j] = '|';
                }
                fl = i;
                continue;
            }
        }
    }
    calc(0, 0);
    for(auto x : s){
        for(int i = 0; i < x.size(); ++i)
            if(x[i] == '.')
                x[i] = ' ';
        cout << x << endl;
    }
    return true;
}

signed main(){
    while(solve());
}



Measured memory_bytes: 3832
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph= vector<vector<int>>; 
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define fi first 
#define se second
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
// ミント
const int mod = 1e9+7 ;
  //998244353;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
//昆布
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
  mint p(int n,int k){
    return fact[n]*ifact[n-k] ;
  }
  }  c(200000);
 
mint modpow(ll a,ll b){
 if(b==0) return 1 ;
 mint c= modpow(a,b/2) ;
 if(b%2==1) return c*c*a ;
 else return c*c ;
}

mint komb(ll n,ll m){
  mint x=1 ;mint y=1 ;
  rep(i,m){
    x*= n-i ;
    y*= i+1 ;
  }
  return x/y ;
}

 map<ll,ll> factor(ll n){  //素因数とオーダーをマップで管理
  map <ll,ll> ord ;  
  for(ll i=2;i*i<=n;i++){
        if(n%i==0){
            int res=0;
            while(n%i==0){
                n/=i;
                res++;
            }
            ord[i]=res;
        }
    }
   if(n!=1) ord[n]++;
   return ord ;
 }
 


int main(){
   ll s; cin>>s ;
   ll k= s/3 ;
   mint ans=0 ;
   rep2(i,1,k){
     ll now= s-i*3 ;
      mint b= (c(now+i-1,now)) ;
      ans+= b ;
   }
   cout<<ans<<endl ;
     return 0;
  }
   



Measured memory_bytes: 6176
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    N, M = map(int, input().split())

    t = (N - M) * 100 + M * 1900
    t *= (2 ** M)
    print(t)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3956
#include <iostream>
#include <map>

using namespace std;
using ll = long long;

ll mypow(ll b, ll n) {
    if (n == 0) return 1;
    if (n == 1) return b;
    if (n % 2 == 0) {
        return mypow(b * b, n / 2);
    } else {
        return mypow(b, n - 1) * b;
    }
}

// n < 2^kなる最小の2^kを返す
ll minbeki(ll n) {
    ll ret = 1;
    while (n >= ret) {
        ret *= 2;
    }
    return ret;
}

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

    map<ll, int> cnt;
    // 値とボールの個数を管理

    for (int i = 0; i < N; ++i) {
        ll a;
        cin >> a;
        if (cnt.find(a) == cnt.end()) cnt[a] = 0;
        ++cnt[a];
    }

    int ans = 0;

    // cntをkeyが大きい方から見ていく
    for (auto itr = cnt.rbegin(); itr != cnt.rend(); ++itr) {
        ll b = itr->first;
        if (cnt[b] == 0) continue;

        ll a = minbeki(b) - b;
        // bとペアになりうるaを求める

        if (a == b) {
            // bと書かれたボール同士でペアを作る
            ans += cnt[b] / 2;
        } else {
            if (cnt.find(a) == cnt.end()) continue;
            // aと書かれたボールが存在しなければ次へ

            // 少ない方に合わせてペアを作る
            ans += min(cnt[a], cnt[b]);
            cnt[a] -= min(cnt[a], cnt[b]);
        }
    }

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


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

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

Measured memory_bytes: 512
N=int(input())
a=list(map(int, input().split()))
a.sort()
A=0
B=0
is_A=True
while len(a)>0:
  if is_A:
    A+=a.pop()
  else:
    B+=a.pop()
  is_A = not is_A
print(A-B)


Measured memory_bytes: 3060
#![allow(unused_imports, unused_variables, dead_code)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

trait InputValue {
    fn parse(s: &str) -> Self;
}

fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

macro_rules! parse_single_value {
        ($($t:ty),*) => {
            $(
                impl InputValue for $t {
                    fn parse(s: &str) -> $t { s.parse().unwrap() }
                }
            )*
    	}
    }
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
    	($($t:ident),*) => {
    		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
    			fn parse(s: &str) -> ($($t),*) {
    				let mut tokens = s.split_whitespace();
    				let t = ($($t::parse(tokens.next().unwrap())),*);
    				t
    			}
    		}
    	}
    }
parse_tuple!(A, B);
parse_tuple!(A, B, C);

// ===

fn main() {
    let (n, a, b): (usize, i64, i64) = read();
    let x: Vec<i64> = readnc();
    let mut total = 0;
    for i in 1..n {
        total += min((x[i] - x[i-1]) * a, b);
    }
    println!("{}", total);
}

Measured memory_bytes: 8444
# 1. 最大公約数を求める(ユークリッドの互除法)
# 2. 最大公約数を素因数分解する。
# 3. 2.の結果に含まれる素因数の種類の数＋１が答え

from fractions import gcd

def main():
  a, b = map(int, input().split())
  print(num_facto(gcd(a,b)) + 1)  
  
def num_facto(n):
  ans = 0
  max_n = int((n ** 0.5) // 1) + 1
  is_prime = [True for x in range(max_n + 1)]
  is_prime[0], is_prime[1] = False, False
  for cursor in two_and_odds(max_n):
    if is_prime[cursor]:
      if n % cursor == 0:
        ans += 1
        while n % cursor == 0:
          n = n // cursor
      for i in range(cursor, max_n, cursor):
        is_prime[i] = False
  if n != 1:
    ans += 1
  return ans

def two_and_odds(max_n):
  if max_n >= 2:
  	yield 2
  for i in range(3, max_n, 2):
    yield i
    
if __name__ == "__main__":
  main()


Measured memory_bytes: 118248
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;
typedef long long ll;

int main(){
   int n;
   cin >> n;
   int d[110];
   rep(i,n) cin >> d[i];

   sort(d, d+n, greater<int>());

   int cnt = 1;
   rep(i,n-1){
      if(d[i] > d[i+1]) cnt++;
   }

   cout << cnt <<endl;


   return 0;
}

Measured memory_bytes: 256
use std::io::{self, Read};
use std::str::FromStr;
use std::i64;
pub struct Scanner<R: Read> {
    reader: R,
}
impl<R: Read> Scanner<R> {
    pub fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }
    pub fn read<T: FromStr>(&mut self) -> T {
        let s = self
            .reader
            .by_ref()
            .bytes()
            .map(|c| c.expect("failed to read char") as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        s.parse::<T>().ok().expect("failed to parse token")
    }
}

// プリムのアルゴリズムを使った最小全域木の探索。
// 指定されたidxを開始点として探索を行う。
fn prim(graph: &Vec<Vec<i64>>, idx: usize) -> i64 {
    let n = graph.len();

    // idxからiに対して訪問にかかるコスト
    let mut cost: Vec<i64> = (0..n).map(|i| graph[idx][i]).collect();
    let mut check = vec![false; n]; // 訪問確認用
    check[idx] = true;
    let mut sum = 0;

    for _ in 0..n-1 {
        // 最小のコストを探索
        let mut m = i64::MAX;
        let mut mid = 0;
        for j in 0..n {
            if check[j] == false && m > cost[j] {
                m = cost[j];
                mid = j;
            }
        }

        // 最小コストの点を追加し、その点からの移動コストを次のコストへ反映させる
        sum += m;
        check[mid] = true;
        for j in 0..n {
            if cost[j] > graph[mid][j] {
                cost[j] = graph[mid][j];
            }
        }
    }

    sum
}

fn solve(graph: &Vec<Vec<i64>>) -> i64 {
    // n < 100で全探索でいいのか？n!通りになるのか
    let n = graph.len();
    let mut min = i64::MAX;
    for i in 0..n {
        let m = prim(&graph, i);
        if m < min {
            min = m;
        }
    }
    min
}

fn main() {
    let sin = io::stdin();
    let sin = sin.lock();
    let mut sc = Scanner::new(sin);

    let n: usize = sc.read();

    let graph: Vec<Vec<i64>> = (0..n).map(|_| {
        (0..n).map(|_| { 
            let v = sc.read::<i64>();
            if v == -1 {
                i64::MAX    // -1をMAXに置き換えて比較しやすくする
            } else {
                v
            }
        }).collect()
    }).collect();

    println!("{}", solve(&graph));
}



Measured memory_bytes: 5040
#include <iostream>
#include <string>

using namespace std;

int main() {
    string N;
    cin >> N;
    for(auto c: N) {
        if(c == '9') {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<ll> > Graph;
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 ll INF = 1e18;

int main(){
    int n;
    cin >> n;
    vector<int>a(n);
    rep(i,n)cin>>a[i];
    int ans = 0;
    rep(i,n){
        if(a[i]%2==1&&(i+1)%2==1)ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3620
#include <stdio.h>
#include <stdlib.h>

void bubbleSort(int *,int);
void swap(int*,int*);

int main(){
  int flag,i,n,a,*tmp;

  scanf("%d",&n);

  tmp = (int*)malloc(n*sizeof(int));

  for(i=0;i<n;i++){
    scanf("%d",&tmp[i]);
  }

  bubbleSort(tmp,n);

   free(tmp);
  return 0;

}

void bubbleSort(int *x,int n){
  int i,j,count=0;
  for(i=0;i<n-1;i++){
    for(j=n-1;j>i;j--){
      if(x[j] < x[j -1]){
	swap(&x[j],&x[j-1]);
	count++;
	  }
    }
    printf("%d ",x[i]);
  }
  printf("%d\n",x[n-1]);
  printf("%d\n",count);
}

void  swap(int *x, int *y)
{
    int  work;   

    work = *x;   
    *x = *y;     
    *y = work;  
}

Measured memory_bytes: 600
#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
#define all(x) x.begin(), x.end()
#define trav(i,a) for(auto &i:a) 
inline int in(){int x;scanf("%lld",&x);return x;}
const int mod=998244353;
int modp(int a,int b)
{
	if(b==0)return 1;
	int u=modp(a,b/2);
	u=(u*u)%mod;
	if(b&1)return (a*u)%mod;
	return u;
}
int32_t main()
{
	int n=in();int s=in();
	vector<int> a(n);for(auto &i:a)i=in();
	vector<vector<int>> dp(n+1, vector<int>(s+1));
	dp[0][0]=modp(2,n);
	int inv2=modp(2,mod-2);
	
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<=s;j++)
		{
			dp[i+1][j]+=dp[i][j];
			dp[i+1][j]%=mod;
			if(j+a[i]<=s)
			{
				dp[i+1][j+a[i]]+=dp[i][j]*inv2;
				dp[i+1][j+a[i]]%=mod;
			}
		}
		
	}
	cout<<dp[n][s];
	
}

Measured memory_bytes: 73764
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<vector<int> > Graph;
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; }

Graph G;
int dp[100010];

int rec(int v){
    if(dp[v]!=-1)return dp[v];
    int res = 0;
    for(int nv:G[v]){
        chmax(res,rec(nv)+1);
    }
    return dp[v]=res;
}

int main(){
    int n,m;
    cin >> n >> m;
    G.resize(n);
    rep(i,m){
        int x,y;
        cin >> x >> y;
        x--;y--;
        G[x].push_back(y);
    }

    rep(i,n){
        dp[i]=-1;
    }
    int ans = 0;
    rep(i,n){
        chmax(ans,rec(i));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 11068
n, k = map(int, input().split())
d = [0] * k
a = [0] * k
for i in range(k):
    d = int(input())
    a[i] = list(map(int, input().split()))

ans = n
p = []

for i in range(k):
    for j in a[i]:
        if not j in p:
            p.append(j)
            ans -= 1

print(ans)

Measured memory_bytes: 67848
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll mod = 1000000007;


void solve(){
    int n,k;
    cin >> n >> k;
    vector<int> h;
    rep(i,n){
        int tmp;
        cin >> tmp;
        h.emplace_back(tmp);
    }
    sort(h.begin(),h.end());
    /*
    h[n-1], h[n-2], ..., h[n-k]
    h[n-2], h[n-3], ..., h[n-k-1]
    ...
    h[k-1], h[k-2], ..., h[0]
    */
    int ans = h[n-1] - h[n-k];
    rep(i,n-k+1){
        ans = min(ans, h[n-1-i]- h[n-k-i]);
    }
    cout << ans << endl;
}

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

Measured memory_bytes: 892
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever for (;;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int n) { return n & 1; }
constexpr bool even(const int n) { return ~n & 1; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first; is >> p.second; return is; }
using namespace std;
// clang-format on

main {
  int n;
  cin >> n;
  vi a(n);
  cin >> a;
  vi move(n + 1);
  loop(i, 1, n) move[i] = (a[i - 1] < a[i]) - (a[i - 1] > a[i]);
  int f = 0, minL = 0, maxR = 0, pre = move[1];
  loop(i, 1, n) {
    if (move[i] == 0) continue;
    if (/*i > 0 &&*/ move[i] != pre) {
      if (move[i] < 0) cmax(f, maxR);
      if (move[i] > 0) cmin(f, minL);
    }
    f += move[i];
    pre = move[i];
    cmax(maxR, f);
    cmin(minL, f);
  }
  cout << maxR - minL + 1 << endl;
}

Measured memory_bytes: 4316
#include<iostream>
#include<string>
#include<algorithm>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <set>
#include <queue>
#include <stack>
#include <map>

using namespace std;
typedef long long LL;
const int INF = int(1e9);
const int MAX  =  10000;

int main()
{
    char a[2][3];
    cin>>a[0]>>a[1];
    if(a[0][0]==a[1][2]&&a[0][2]==a[1][0]&&a[0][1]==a[1][1])
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;


    return 0;
}


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

int alice=0;
int bob=0;
int a[100001];

bool cmp(int x , int y)
{
 	return x > y;
}

int main()
{
	int n,m;
	cin>>n;
	for(int i=1;i<=n;i++)
	cin>>a[i];
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;i+=2)
	{
		alice+=a[i];
			if ( i==n-1 )
			break;	
	}
		
		
	for(int i=2;i<=n;i+=2)
	{
		bob+=a[i];
			if(i==n-1)
			break;
	}
	int ans = alice - bob;
	cout<< ans <<endl;
	return 0;
}

Measured memory_bytes: 256
lis1 = [1]
lis2 = []
lis3 = []

N = int(input())
K = int(input())

for i in range(N):
	lis2.append(2*lis1[i])
	lis3.append(lis1[i] + K)
	if lis2[i] >= lis3[i] :
		lis1.append(lis1[i] + K)
		
	elif lis2[i] < lis3[i] :
		lis1.append(2*lis1[i])
		
print(lis1[N])
		 
	

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

typedef pair<int,int> pi;

int h,w,s;
int u[33][33];

int sum[33][33];
int U;

pi dp[33][33][33][33];

inline void init()
{
    memset(sum,0,sizeof(sum));
    U=0;
    rep(i,33)rep(j,33)rep(k,33)rep(l,33) dp[i][j][k][l]=pi(-1,-1);

}

inline int SUM(int lx, int ly, int rx, int ry)
{
    return sum[ry][rx] - sum[ly-1][rx] - sum[ry][lx-1] + sum[ly-1][lx-1];
}

pi dfs(int lx, int ly, int rx, int ry)
{
    if(dp[lx][ly][rx][ry].fi>=0) return dp[lx][ly][rx][ry];

    pi ret(1,s-U+SUM(lx,ly,rx,ry));

    // ????????????
    for(int i=lx; i<rx; ++i)
    {
        if(U-SUM(lx,ly,i,ry)<=s && U-SUM(i+1,ly,rx,ry)<=s)
        {
            pi A = dfs(lx,ly,i,ry), B = dfs(i+1,ly,rx,ry);
            ret = max(ret, pi(A.fi+B.fi, min(A.se,B.se)));
        }
    }

    // ?¨??????????
    for(int i=ly; i<ry; ++i)
    {
        if(U-SUM(lx,ly,rx,i)<=s && U-SUM(lx,i+1,rx,ry)<=s)
        {
            pi A = dfs(lx,ly,rx,i), B = dfs(lx,i+1,rx,ry);
            ret = max(ret, pi(A.fi+B.fi, min(A.se,B.se)));
        }
    }

    return dp[lx][ly][rx][ry] = ret;
}

int main()
{
    while(scanf(" %d %d %d", &h, &w, &s),h)
    {
        init();

        rep(i,h)rep(j,w)
        {
            scanf(" %d", &u[i+1][j+1]);
            U+=u[i+1][j+1];
        }

        sum[1][1]=u[1][1];
        for(int i=2; i<=w; ++i) sum[1][i] = sum[1][i-1]+u[1][i];
        for(int i=2; i<=h; ++i) sum[i][1] = sum[i-1][1]+u[i][1];
        for(int i=2; i<=h; ++i)for(int j=2; j<=w; ++j) sum[i][j] = sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1] + u[i][j];

        pi a = dfs(1,1,w,h);
        printf("%d %d\n", a.fi, a.se);
    }
    return 0;
}

Measured memory_bytes: 12432
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
/*多倍長整数/cpp_intで宣言
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
*/

//#pragma gcc target ("avx2")
//#pragma gcc optimization ("o3")
//#pragma gcc optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2LL) //等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */


using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

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

ll lcm(ll number1, ll number2) {
	return number1 / gcd(number1, number2) * number2;
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	string s;
	scans(s);
	bool f = true;
	if(not(s.find("N") != string::npos and s.find("S") != string::npos) and not(s.find("S") == s.find("N")))f = false;
	if (not(s.find("W") != string::npos and s.find("E") != string::npos) and not(s.find("W") == s.find("E")))f = false;
	printyn(f);

	Please AC;
}


Measured memory_bytes: 256
import sys
from collections import Counter
from math import gcd
input = sys.stdin.readline
N = int(input())
mod = 10 ** 9 + 7
d = Counter()
a = [tuple(map(int, input().split())) for _ in range(N)]
z = 0
for x, y in a:
  if (x, y) == (0, 0):
    z += 1
    continue
  if y < 0:
    x *= -1
    y *= -1
  if x == 0:
    x = 0
    y = 1
  elif y == 0:
    x = 1
    y = 0
  g = gcd(x, y)
  x //= g
  y //= g
  d[(x, y)] += 1

res = 1
itr = list(d.keys())
#print(itr, d)
for x, y in itr:
  t = 0
  if x <= 0 and (d[(y, -x)] > 0): continue
  if (x, y) == (1, 0):
    t = d[(0, 1)]
  else:
    t = d[(-y, x)]
  v = 0
  v += pow(2, d[(x, y)], mod) - 1
  v %= mod
  v += pow(2, t, mod) - 1
  v %= mod
  v += 1
  v %= mod
  res *= v
  res %= mod
  #print(res, d, d[(x, y)], t)
#print(itr, u, res, z)
print((res - 1 + z) % mod)

Measured memory_bytes: 152096
#include <stdio.h>
   
int main(void){
    int n,x,i,j,k;
    while(1){
    int c=0;
    scanf("%d %d",&n,&x);
    if(n==0 && x==0){
        break;
    }
    for(i=1;i<=n;i++){
        for(j=i+1;j<=n;j++){
            for(k=j+1;k<=n;k++){
                if(i+j+k==x){
                    c++;
                }
            }
        }
    }
    printf("%d\n",c);
    }
    return 0;
}

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

int main() {
  int N,X,A=1000;
  cin>>N>>X;
  for(int i=0;i<N;i++){
    int a;
    cin>>a;
    X-=a;
    A=min(a,A);
  }
  cout<<N+X/A<<endl;
}


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

#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>
#include <string_view>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
using namespace std;

/*----------macros----------*/

//output================
#define endl '\n'
#define fcout(a) cout << fixed << setprecision((int)(a))

//typedef===============
typedef long long       ll;
typedef long double     ld;
typedef pair<int, int>  Pii;
typedef pair<ll, ll>    Pll;

//const number==========
constexpr ll INF9   = (ll)1e9 + 1;
constexpr ll INF18  = (ll)1e18 + 1;
constexpr ll MOD    = 1000000007;
constexpr ll MOD2   = 998244353;
constexpr ld PI     = 3.141592653589793L;

//member================
#define pb push_back
#define eb emplace_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second

//others================
#define all(x)          (x).begin(), (x).end()
#define rall(x)         (x).rbegin(), (x).rend()
#define rep(i, n)       for(int i = 0; (i) < (n); ++(i))
#define reps(i, n)      for(int i = 1; (i) <= (n); ++(i))
#define rrep(i, n)      for(int i = n - 1; (i) >= 0 ; --(i))
#define repbit(bit, n)  for(int bit = 0; (bit) < (1 << (n)); ++(bit))
#define ifbit(bit, i)   if((bit) & (1 << (i)))
#define CtoI(c)         int((c)) - int('0')
#define ItoC(c)         char((c) + '0')

//functions=============
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
//vector<int> dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };

/*--------additional--------*/



/*----------main------------*/

int main() {
/*----------fastio----------*/
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
/*----------solve-----------*/

    int n; string s; cin >> n >> s;
    int cnt = 0;
    for(int i = 2; i < n; ++i){
        if(s[i-2] == 'A' && s[i-1] == 'B' && s[i] == 'C')
            ++cnt;
    }

    cout << cnt << endl;

return 0;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int a=-1; 
  int s=-1;
  int d = -1;
  int n, m; cin>>n>>m;
  for (int i = 0; i <= n;i++)
  {
    for (int j = 0;j<=n-i;j++){
      if(10000*i+5000*j+1000*(n-i-j)==m){
        a = i;
        s = j;
        d = n - i - j;
        cout << a << ' '<<s<<' ' << d << endl;
        return 0;
      }
    }
  }
  cout << a << ' ' << s << ' ' << d << endl;
}



Measured memory_bytes: 256
l,r = map(int,input().split())
ans = 1000000000000000000
if 2019 <= r-l:
    print(0)
    exit()
else:
    for i in range(l,r):
        for j in range(i+1, r+1):
            if ans > (i*j)%2019:
                ans = (i*j)%2019
print(ans)


Measured memory_bytes: 40556
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long a, b, c, x, sum = 0, ans = 0;
    cin >> a >> b >> c >> x;
    for(int i = 0; i <= a; i++)
        for(int j = 0; j <= b; j++)
            for (int k = 0; k <= c && sum <= x; k++, sum = 0)
                if((sum = i * 500 + j * 100 + k * 50) == x)
                    ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>
#include <math.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define repf(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define repr(i, a, b) for (ll i = (ll)a; i > (ll)b; i--)
#define repv(x, arr) for (auto &x : arr)
#define all(v) (v).begin(), (v).end()
#define vec(name, num) vector<ll> name((num), 0);
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int infi = 2147483600;
const ll infl = 1e17;

int main()
{
    ll n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    rep(m,n){
        ll l = c * (n - 1 - m) - m * d;
        ll r = d * (n - 1 - m) - m * c;
        if (l<=b-a && b-a<=r){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define fin <<'\n'
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
//#define int long long
typedef long long ll;
typedef pair < int , int >  pii;
typedef vector < int > vit;
typedef map < string , int > mstit;
typedef vector < pii > vpi ;
typedef greater < pii > gpi;
typedef priority_queue < pii , vpi , gpi > dijk ;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>T abs(T &x){return x<0 ? -x : x;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int n;

int x[100005][5];
int dp[100005][5];
inline void solve(){

    cin >> n;

    for(int i = 0; i < n; i++) {
        for(int j = 0; j < 3; j++) {
            cin >> x[i][j];
        }
    }

    for(int i = 0; i < n; i++) {
        for(int j = 0; j < 3; j++) {
            int k = (j+1)%3, l = (j+2)%3;
            dp[i+1][j] = max(dp[i][k],dp[i][l]) + x[i][j];
        }
    }
    
    
    cout << max({dp[n][0],dp[n][1],dp[n][2]}) << endl;
    
}
struct xyz{ xyz(){ cin.tie(0), ios::sync_with_stdio(false); cout <<fixed<<setprecision(12);};}xyzzy;signed main(){solve();return 0;}


Measured memory_bytes: 4224
//ITP1_6_C_19140837_小島優希也.cpp
//学習番号 19140837    氏名　小島優希也
#include <iostream>
#include <vector>
using namespace std;

int main(void) {
    int n;
    cin >> n;
    vector<vector<vector<int>>> vec(4, vector<vector<int>> (3, vector<int> (10, 0)));
    for (int i = 0; i < n; i++) {
        int b, f, r, v;
        cin >> b >> f >> r >> v;
        vec.at(b - 1).at(f - 1).at(r - 1) += v;
    }

    for (int b = 0; b < 4; b++) {
        for (int f = 0; f < 3; f++) {
            for (int r = 0; r < 10; r++) {
                cout << " " << vec.at(b).at(f).at(r);
            }
            cout << endl;
        }
        if (b != 3) {
            for (int i = 0; i < 20; i++) {
                cout << "#";
            }
            cout << endl;
        }
    }
}




Measured memory_bytes: 3092
h,w=gets.split.map &:to_i
w+=1
a=$<.read.tr("#.\n","10").to_i 2
#m=(~((1<< (w *h))/((1<< w)-1)))                                                
aa=1<< w * h >>	1
(w+h-3).times{
  aa|=(((aa>>1)|(aa>>w)) &a)
#  puts sprintf("%0#{w*h}b", aa).scan(/.{#{w}}/)                                
#  puts ""                                                                      
}
puts aa==a &&a.to_s(2).count('1')==w+h-2 ? "Possible" :	"Impossible"

Measured memory_bytes: 1788
#include "bits/stdc++.h"
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e18;

lint N, K, arr[200000], _arr[200001];
int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	cin >> N >> K;
	REP(i, N) {
		cin >> arr[i];
	}
	REP(i, K) {
		REP(j, N + 1) {
			_arr[j] = 0;
		}
		REP(j, N) {
			_arr[max(0ll, j - arr[j])]++;
			_arr[max(0ll, j + arr[j] + 1)]--;
		}
		lint sum = _arr[0];
		REP(j, N) {
			sum += _arr[j + 1];
			_arr[j + 1] = sum;
		}
		REP(j, N) {
			arr[j] = _arr[j];
		}
		bool flag = true;
		REP(j, N) {
			if (arr[j] != N) flag = false;
		}
		if (flag) break;
	}
	REP(i, N) {
		cout << arr[i] << " ";
	}
	cout << endl;
}

Measured memory_bytes: 6784
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

int main(int argc, char* argv[]){
  std::string s;
  int d, n ;
  std::cin >> d >> n;

  int t = 1;
  if (d == 1){
    t = 100;
  } else if (d == 2){
    t = 10000;
  }
  
  int x = t;
  int c = 0;
  if (d == 0){
    while (true){
      if ((x % 100) != 0){
        c++;
      }
      if (c == n){
        break;
      }
      x += t;
    }
  }
  else if (d == 1){
    while (true){
      if ((x % 100) == 0 && (x % 10000) != 0){
        c++;
      }
      if (c == n){
        break;
      }

      x += t;
    }
  }
  else if (d == 2){
    while (true){
      if ((x % 10000) == 0 && (x % 1000000 != 0)){
        c++;
      }
      if (c == n){
        break;
      }

      x += t;
    }
  }

  std::cout << x << std::endl;      

  return 0;  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(void){
    // Your code here!
    long L,R;
    cin>>L>>R;
    int f=0;
    if(R-L>2018||R%2019==L%2019){
        f=1;
        cout<<0;
    }
    if(f==0){
    int m=3000;
    for(long i=L;i<=R;i++){
        for(long j=L;j<=R&&i!=j;j++){
            if(m>(i*j)%2019){
                m=(i*j)%2019;
            }
        }
    }
    cout<<m;
    }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>

using namespace std;

vector<string>split(string s, char delim){
  int len = s.length();
  string currStr = "";
  vector<string>retVec;
  for(int i = 0;i<len;i++){
    char ch = s[i];
    if(ch==delim){
      retVec.push_back(currStr);
      currStr = "";
    }else{
      currStr += ch;
    }
  }
  retVec.push_back(currStr);
  return retVec;
}

vector<int>strToIntVec(string s){
  int len = s.length();
  //  s = s.substr(1,len-2);
  vector<string>strVec = split(s,' ');
  vector<int>retVec;
  for(int i=0;i<strVec.size();i++){
    int el = atoi(strVec[i].c_str());
    retVec.push_back(el);
  }
  return retVec;
}

class RockGame{
public:
  string canMove(int n, int a, int b, int c, int d, string s){
    string retS = "No";
    bool rocksOKSN = checkRocks(n,a,c,s);
    bool rocksOKFN = checkRocks(n,b,d,s);    
    if(rocksOKSN&&rocksOKFN){
      if(c<d){
	retS = "Yes";
      }else{
	bool canCross = checkCross(n,a,b,c,d,s);
	if(canCross)retS = "Yes";
      }
    }
    return retS;
  }

  bool checkRocks(int n, int i1, int i2,string s){
    bool retV = true;
    for(int i=i1+1;i<(i2-1);i++){
      if((s[i-1]=='#')&&(s[i]=='#')){
	retV = false;
	break;
      }
    }
    return retV;
  }
  
  bool checkCross(int n, int a, int b, int c, int d, string s){
    bool retV = false;
    for(int i=b;i<=d;i++){
      //i-1 is center in string, 0-indexed
      if((s[i-2]=='.')&&(s[i-1]=='.')&&(s[i]=='.')){
	retV = true;
	break;
      }
    }
    return retV;
  }
};

int main(int argc, const char*argv[]){
  RockGame rg;
  string nabcdLn, sLn;
  getline(cin,nabcdLn);
  getline(cin,sLn);
  vector<int>nVec = strToIntVec(nabcdLn);
    string outStr = rg.canMove(nVec[0],nVec[1],nVec[2],nVec[3],nVec[4],sLn);
  cout<<outStr<<endl;
  return 0;
}


Measured memory_bytes: 900
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if (a < b) {
            System.out.println("a < b");
        } else if (a > b) {
            System.out.println("a > b");
        } else {
            System.out.println("a == b");
        }
    }
}

Measured memory_bytes: 26304
#include<bits/stdc++.h>
#define PI 3.141592653589793238462
using namespace std;
typedef long long ll;
typedef long double db;
int pre[200005],p[200005];
int find(int x){
    return (x==pre[x])?x:(pre[x]=find(pre[x]));
}
void merge(int x,int y){
    pre[find(x)]=find(y);
}
int main(){
    int n,m,mx=0;cin>>n>>m;
    for(int i=1;i<=n;i++){
        pre[i]=i;
    }
    for(int i=1;i<=m;i++){
        int x,y;cin>>x>>y;merge(x,y);
    }
    for(int i=1;i<=n;i++){
        p[find(i)]++;
    }
    for(int i=1;i<=n;i++){
        mx=max(mx,p[i]);
    }
    cout<<mx<<endl;
} 

Measured memory_bytes: 10556
#include <math.h>
#include <utility>
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
 
int m;
int n;
int map[10][10] = {0};
int cnt = 0;
int churchx;
int churchy;
int dx[4] = {-1,1,0,0};
int dy[4] = {0,0,-1,1};
 
int saiki( int xinput, int yinput, int nokori ) {
    for ( int i = 0; i < 4; i++ ) {
        int x = xinput;
        int y = yinput;
        if ( nokori == 0 ) {
            if ( y == churchy && x > churchx && i != 0 ) continue;
            if ( y == churchy && x < churchx && i != 1 ) continue;
            if ( x == churchx && y > churchy && i != 2 ) continue;
            if ( x == churchx && y < churchy && i != 3 ) continue;
        }
	
        while(true) {
            x += dx[i];
            y += dy[i];
            if ( x < 0 || x >= m || y < 0 || y >= n ) break;
            
	    if (map[x][y] == 1){
                map[x][y] = 3;
                saiki(x, y, nokori-1);
                map[x][y] = 1;
		break;
            }else if(map[x][y] == 2 ){
                if(nokori == 0){
                    cnt++;
                    return 0;
                }
            }
        }
    }
    return 0;
}
 
int main(){
    while(true) {
        cin >> m;
        cin >> n;
        if ( m == 0 ) break;
        int nokori = 0;
        for ( int i = 0; i < n; i++ ) {
            for ( int j = 0; j < m; j++ ) {
                cin >> map[j][i];
		//unvisited
                if ( map[j][i] == 1 ) {
                    nokori++;
		    
		//is_church
                }else if(map[j][i] == 2) {
                    churchx = j;
                    churchy = i;
                }
            }
        }
	
	cnt = 0;
	saiki( churchx, churchy, nokori );
	cout << cnt << endl;
    
    }
    return 0;
}

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

int main(){
  int n;
  cin >> n;
  long long total=1;
  int odd=1;
  for (int i=0;i<n;i++){
    total*=3;
    int num;
    cin >> num;
    if (num%2==0) odd*=2;
  }
  cout << total-odd << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>

int main() {
	int direct[4] = {0}; // n, s, e, w
	std::string travel;

	std::cin >> travel;

	for (char c : travel) {
		if (c == 'N') direct[0]++;
		else if (c == 'S') direct[1]++;
		else if (c == 'E') direct[2]++;
		else if (c == 'W') direct[3]++;
	}

	if((direct[0] > 0 && direct[1] == 0) || (direct[2] > 0 && direct[3] == 0) ||
		(direct[0] == 0 && direct[1] > 0) || (direct[2] == 0 && direct[3] > 0)){
		std::cout << "No" << std::endl;
	} else {
		std::cout << "Yes" << std::endl;
	}

	return 0;
}

Measured memory_bytes: 256