akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(3 * n);
    for(int i = 0; i < 3 * n; i++){
        cin >> a[i];
    }
    int sum = 0;
    priority_queue<int, vector<int>, greater<int> > q;
    for(int i = 0; i < n; i++){
        q.push(a[i]);
        sum += a[i];
    }
    vector<int> l(3 * n);
    l[n - 1] = sum;
    for(int i = n; i < 2 * n; i++){
        int tmp = q.top();
        if(tmp < a[i]){
            q.pop();
            q.push(a[i]);
            sum = sum - tmp + a[i];
        }
        l[i] = sum;
    }
    sum = 0;
    priority_queue<int> p;
    for(int i = 2 * n; i < 3 * n; i++){
        p.push(a[i]);
        sum += a[i];
    }
    vector<int> r(3 * n);
    r[2 * n] = sum;
    for(int i = 2 * n - 1; i >= n; i--){
        int tmp = p.top();
        if(tmp > a[i]){
            p.pop();
            p.push(a[i]);
            sum = sum - tmp + a[i];
        }
        r[i] = sum;
    }
    int ans = -INF;
    for(int i = n - 1; i < 2 * n; i++){
        ans = max(ans, l[i] - r[i + 1]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 8948
#include <bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    #include <ext/pb_ds/detail/standard_policies.hpp>
    using namespace std;
    using namespace __gnu_pbds;
    #define ll long long
    #define int long long
    #define pb push_back
    #define For(i,n) for(ll  i=0;i<n;i++)
    #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) ;clock_t clk = clock();
    #define f(a,b,c) for(ll a=b;a<c;a++)
    #define ld long double
    #define read(t) ll t;cin>>t;
    #define all(x) x.begin(),x.end()
    #define fi first
    #define se second
    #define pii pair<ll,ll>
    #define endl "\n"
    #define sz(x) (int)(x).size()
    #define what_is(x) cerr << #x << " is " << x << endl;
    #define time cerr << "Time (in ms): " << double(clock() - clk) * 1000.0 / CLOCKS_PER_SEC << '\n';
    const double pi=3.14159265358979323846264;
    typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
    typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
/*.....................................................................................................................*/

    ll mod =(ll)1e9+7;
    ll add(ll x,ll y) {return (x+y)%mod;}
    ll mult(ll x, ll y){return ((x%mod )* (y%mod)) % mod;}
    long long binpow(long long x, long long p) 
    {
        if (p == 0) return 1;
    	if (p == 2 || (p & 1)) return mult(x, binpow(x, p - 1));
    	return binpow(binpow(x, p / 2), 2);
    }
    ll modinv(ll a) {return binpow(a,mod-2);}
    // bool check(ll x){}
    ll binsearch(ll l,ll r)
    {
        while(l<r)
        {
            ll mid=(l+r)/2;
            // if(check(mid))r=mid;
            // else l=mid+1;
        }
        return l;
    }
    const ll man=(ll)1005;
    vector<ll>adj[man];
    bool vis[man][man];
    ll d[man],depth[man],par[man];
    void addedge(ll u,ll v){adj[u].pb(v);adj[v].pb(u);}
    ll dx[4]={1,-1,0,0};ll dy[4]={0,0,1,-1};
/*........................................................................................................................*/

signed main()/*Check flow...question galat mat padhna */
{
    fast;   
    ll n,k;
    cin>>n>>k;
    ll a[n];
    For(i,n)cin>>a[i];
    ll ans=0;
    sort(a,a+n);
    For(i,k)ans+=a[i];
    cout<<ans<<endl;
}      


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

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

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

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

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

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

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

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

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

fn main() {
  input! {
    s: chars,
  }
  let mut a1 = 0;
  let mut a2 = 0;
  for (i, &c) in s.iter().enumerate() {
    if i % 2 == 0 {
      if c == '0' {
        a1 += 1;
      } else {
        a2 += 1;
      }
    } else {
      if c == '0' {
        a2 += 1;
      } else {
        a1 += 1;
      }
    }
  }

  println!("{}", cmp::min(a1, a2));
}


Measured memory_bytes: 4352
using System;
using System.IO;
using System.Linq;
using System.Diagnostics;
using System.Threading.Tasks;
using System.Collections.Generic;

namespace _081Acs
{
    class Program
    {
        static void Main(string[] args)
        {
            
            string str = Console.ReadLine();

            var q = str.Where(x => x=='1').ToArray();

            Console.WriteLine(q.Length);
        }
    }
}


Measured memory_bytes: 13268
<?php
  fscanf(STDIN, "%d %d", $n, $m);
  $vote_count = array();

  for ($i=0; $i<$n; $i++) {
    $ka = explode(" ",trim(fgets(STDIN)));
    $k = $ka[0];
    $a = array_slice($ka, 1);
    
    foreach($a as $key => $value) {
      $vote_count[$value]++;
    }
  }

  $ans = 0;
  foreach ($vote_count as $food => $vote) {
    if ($vote >= $n) {
      $ans += 1;
    }
  }

  echo $ans . "\n";
?>

Measured memory_bytes: 4604
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stdint.h>
#include <queue>
#include <bitset>
#include <iomanip>
#include <set>
#include <map>

using namespace std;

#define PI (3.14159265358979323846)
#define INF (2147483647)
#define INF_LL (9223372036854775807)
#define DIV_NUM (1000000007)
typedef long long ll;

// 配列初期化テンプレ
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T& val) {
	std::fill((T*)array, (T*)(array + N), val);
}


int main() {

	int a;
	cin >> a;

	cout << a + a * a + a * a * a << endl;

	return 0;

}


Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {
    public static void main(String [] args) {
        final Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int k = scanner.nextInt();

        long num1 = 0;
        long num2 = 0;
        for (int i = 1; i <= n; ++i) {
            if (i % k == 0) {
                ++num1;
            }
            if (i % k == (k / 2)) {
                ++num2;
            }
        }
        if (k % 2 == 1) {
            System.out.println(num1 * num1 * num1);
        } else {
            long result = num1 * num1 * num1 + num2 * num2 * num2;
            System.out.println(result);
        }
    }
}


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

int main ()
{
  int  x, a, b, c, d, x1, x2;
  cin>>x;
  
  a=x/1000;
  x1=x%1000;
  b=x1/100;
  x2=x1%100;
  c=x2/10;
  d=x2%10;
  
  if(a==b&&b==c || b==c && c==d)
  {
    cout<<"Yes"<<endl;
  }
  else
  {
    cout<<"No"<<endl;
  }
}
 

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


int main() {
    int N,M,C;
    cin >> N >> M >> C;
    vector<vector<int>> A(N,vector<int>(M));
    vector<int> B(M);
    for(int i=0;i<M;i++) cin >> B[i];
    for(int i=0;i<N;i++){
        for(int j=0;j<M;j++) cin >> A[i][j];
    }

    vector<int> sum(N,C);
    int ans=0;
    for(int i=0;i<N;i++){
        for(int j=0;j<M;j++) sum[i]+= A[i][j]*B[j];
    }

    for(int i=0;i<N;i++){
        if(sum[i]>0) ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import sys
n=list(map(int,input().split()))
s=input()
a,b,c=[],s[0],0
if n[0]==1:
    print('0')
    sys.exit()
for i in range(n[0]-1):
    if b==s[i+1]:
        c+=1
    else:
        a.append(c)
        c=0
    b=s[i+1]
if c!=0:
    a.append(c)
if s[-2]==s[-1]:
    a[-1]+=1
else:
    a.append(1)
if n[1]>=len(a)//2:
    print(n[0]-1)
else:
    print(sum(a)+2*n[1]-1)

Measured memory_bytes: 4092
n,k=map(int,input().split())
p=list(map(int,input().split()))
p=p[:]
i=0
t=0
L=[]
while i < k:
    d=p[0]
    for e in p:
        if e < d:
            d=e
    L.append(d)
    p.remove(d)
    i+=1
for e2 in L:
    t+=e2
print(t)

Measured memory_bytes: 9256
a, b = map(int, input().split())

res = 0
i = 0
two = 2
while 1 << i <= b:
    mod_a, mod_b = a % two, b % two
    tmp_a, tmp_b = a - mod_a + two, b - mod_b

    cnt = ((tmp_b - tmp_a) // two) * (two // 2)
    cnt += min(two - mod_a, two // 2)
    cnt += max(mod_b - two // 2 + 1, 0)
    
    if cnt % 2 == 1:
        res += two // 2
    
    two *= 2
    i += 1

print(res)

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

#define FOR(i,n,j) for(int i=(j);i<(n);++i)
#define ssort(n) sort((n).begin(),(n).end())
using ll=long long;
using ld=long double;
typedef pair<int,int> P;
#define repl(i,n) for(ll i=0;i<(n);++i)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl

int main()
{
    ll X,K,D;
    cin >> X >> K >> D;
    X=llabs(X);
    ll mod=X%D;
    ll X_=X-mod;
    ll count=X_/D;
    ll ans=0;
    if(K<=count){
        ans=X-(K*D);
    }else{
        ll A=mod;
        ll B=abs(D-mod);
        if(count%2==0){
            if(K%2==0){
                ans=A;
            }else{
                ans=B;
            }
            
        }else{
            if(K%2==0){
                ans=B;
            }else{
                ans=A;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3628
N=int(input())

S=[input() for _ in range(N)]
S.sort()

label=1
l=1
out=[]
for i in range(N-1):
    if S[i]==S[i+1]:
        l+=1
    else:
        if label<l:
            out=[S[i]]
            label=l
        elif label==l:
            out.append(S[i])
        l=1
if label<l:
    out=[S[-1]]
elif label==l:
    out.append(S[-1])

for i in range(len(out)):
    print(out[i])

Measured memory_bytes: 20676
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

int n;

/*
int sol(int mva,int va,int dep){
  if (dep==1){
    return 0;
  }

  int k10=1;
  REP(i,dep-1){
    k10*=10;
  }
  int bkr=1;
  REP(i,dep-1){
    bkr*=i+1;
  }


  int myno=(va/k10);
  int cnt=0;
  REP(i,n-dep){
    int k20=1;
    REP(ii,dep){
      k20*=10;
    }
    if (((mva/k20)%10)<myno)cnt++;
  }
  return (myno-cnt-1)*bkr+sol(mva,va%k10,dep-1);
}



int main(){
  ll ans=0;
  cin >> n ;
  vi p(n),q(n);
  int pp=0;
  REP(i,n) {
    pp*=10;
    cin>>p[i];
    pp+=p[i];
  }

  int qq=0;
  REP(i,n) {
    qq*=10;
    cin>>q[i];
    qq+=q[i];
  }

  ans=sol(pp,pp,n)-sol(qq,qq,n);
  cout<<sol(pp,pp,n)<<endl;
  cout<<sol(qq,qq,n)<<endl;
  cout<<ans<<endl;
  return 0;
}
*/



int main(){
  int ans0=0;
  int ans1=0;
  cin >> n ;
  vi p(n),q(n);
  int pp=0;
  REP(i,n) {
    pp*=10;
    cin>>p[i];
    pp+=p[i];
  }

  int qq=0;
  REP(i,n) {
    qq*=10;
    cin>>q[i];
    qq+=q[i];
  }



  for(int i=n-1;i>=0;i--){
    int cnt=0;
    for(int j=i+1;j<n;j++){
      if (p[i]>p[j]){
        cnt++;
      }
    }

    int brk=1;
    REP(jj,n-i-1){
      brk*=jj+1;
    }
    ans0+=cnt*brk;
  }




  for(int i=n-1;i>=0;i--){
    int cnt=0;
    for(int j=i+1;j<n;j++){
      if (q[i]>q[j]){
        cnt++;
      }
    }

    int brk=1;
    REP(jj,n-i-1){
      brk*=jj+1;
    }
    ans1+=cnt*brk;
  }




  //ans=sol(pp,pp,n)-sol(qq,qq,n);
  //cout<<sol(pp,pp,n)<<endl;
  //cout<<sol(qq,qq,n)<<endl;
  cout<<abs(ans0-ans1)<<endl;
  return 0;
}

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

public class Main {
	static int mod = 998244353;
	static int DX[] = { -1, 0, 1, 0 }, DY[] = { 0, -1, 0, 1 };
	static final int INF = Integer.MAX_VALUE / 3;
	static final long LINF = Long.MAX_VALUE / 3;

	public static void main(String[] args) {
		FastScanner fs = new FastScanner(System.in);
		int n = fs.nextInt();
		int d[] = fs.nextIntArray(n);
		long memo[] = new long[n];
		for(int i=0;i<n;i++) {
			memo[d[i]]++;
		}
		if(d[0]!=0) {
			System.out.println(0);
			return;
		}
		if(memo[0]!=1) {
			System.out.println(0);
			return;			
		}
		for(int i=1;i<n;i++) {
			if(memo[i]>0&&memo[i-1]==0) {
				System.out.println(0);
				return;
			}
		}
		
		long ans = 1;
		for(int i=1;i<n;i++) {
			if(memo[i]==0)break;
			long t = pow(memo[i-1],memo[i]);
			ans = mul(ans, t);
		}
		System.out.println(ans);
	}

	//MOD culculations
	static long plus(long x, long y) {
		long res = (x + y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long sub(long x, long y) {
		long res = (x - y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long mul(long x, long y) {
		long res = (x * y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long div(long x, long y) {
		long res = x * pow(y, mod - 2) % mod;
		return res < 0 ? res + mod : res;
	}

	static long pow(long x, long y) {
		if (y < 0)
			return 0;
		if (y == 0)
			return 1;
		if (y % 2 == 1)
			return (x * pow(x, y - 1)) % mod;
		long root = pow(x, y / 2);
		return root * root % mod;
	}
}

//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

	public String next() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}

Measured memory_bytes: 37596
#include <stdio.h>
#include <string.h>
int main()
{
	char str[1001];
	gets(str);
	int len=strlen(str),i;
	for(i=2;i<len;i++)
		if((str[i]==str[i-1])&&(str[i]==str[i-2])&&(str[i-1]==str[i-2]))
		{
			printf("Yes\n");
			return 0;
		}
	printf("No\n");
}

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

int main(){
   int K;
   cin >> K;
   vector<long long> ans_array = {1,2,3,4,5,6,7,8,9};
   int i = 0;
   int ans_size = 9;
   while(ans_size < K){
       if (ans_array.at(i) % 10 == 0){
           ans_array.push_back(ans_array.at(i)*10 + 0);
           ans_array.push_back(ans_array.at(i)*10 + 1);
       }
       else if (ans_array.at(i) % 10 == 9){
           ans_array.push_back(ans_array.at(i)*10 + 8);
           ans_array.push_back(ans_array.at(i)*10 + 9);
       }
       else{
           ans_array.push_back(ans_array.at(i)*10 + ans_array.at(i) % 10 - 1);
           ans_array.push_back(ans_array.at(i)*10 + ans_array.at(i) % 10);
           ans_array.push_back(ans_array.at(i)*10 + ans_array.at(i) % 10 + 1);
       }
       ans_size = ans_array.size();
       i++;
   }
   cout << ans_array.at(K - 1) << endl;
}

Measured memory_bytes: 1464
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

int main() {
    string S; cin >> S;
    int N = S.size();

    int dp[N + 1][2] = {};
    dp[0][1] = 1;
    REP(i, 0, N) {
        int n = S[i] - '0';
        dp[i + 1][0] = min(dp[i][0] + n, dp[i][1] + (10 - n));
        dp[i + 1][1] = min(dp[i][0] + n + 1, dp[i][1] + (10 - n - 1));
    }

    cout << dp[N][0] << endl;
    return 0;
}

Measured memory_bytes: 12128
#include "bits/stdc++.h"
using namespace std;
#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
typedef long long ll;

const int INF = 1e9 + 7;
const long long LLINF = 1e18;

int h, w;
string s[51];
int dx[4]={1, 0, -1, 0};
int dy[4]={0, 1, 0, -1};
int main() {
    cin>>h>>w;
    REP(i, 0, h) cin>>s[i];

    bool flag1=false;
    REP(i, 0, h){
        REP(j, 0, w){
            if(s[i][j]=='#'){
                bool flag2=false;
                REP(k, 0, 4){
                    int ny=i+dy[k];
                    int nx=j+dx[k];
                    if(CK(ny, 0, h) && CK(nx, 0, w)){
                        if(s[ny][nx]=='#') flag2=true;
                    }
                }
                if(!flag2) flag1=true;
            }
        }
    }
    if(flag1) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long int lli;

int main(){
	string s;
	int n;
	cin >> s >> n;
	string front="", rear="";
	bool rev = false;
	for(int i=0; i<n; i++){
		int t;
		cin >> t;
		if(t == 1){
			rev = !rev;
		}else{
			int f;
			string c;
			cin >> f >> c;
			if((!rev and f==1) or (rev and f==2)){
				front += c;
			}else{
				rear += c;
			}
		}
	}
	if(!rev){
		reverse(front.begin(), front.end());
		cout << front << s << rear << endl;
	}else{
		reverse(rear.begin(), rear.end());
		reverse(s.begin(), s.end());
		cout << rear << s << front << endl;
	}
	return 0;
}

Measured memory_bytes: 1088
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll i, j, k, n, ans = 0, las;
  scanf("%lld", &n);
  ll a[n];
  for(i = 0; i < n; ++i) scanf("%lld", &a[i]);
  if(a[0]) {
    printf("-1");
    return 0;
  }
  for(i = n - 1; i >= 0; --i) {
    if(i == n - 1) las = a[i];
    else {
      if(las > a[i] && las - a[i] != 1) {
        printf("-1");
        return 0;
      }
      if(las > a[i]) ++ans;
      else ans += las;
      las = a[i];
    }
  }
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 1664
import sys
def I(): return int(sys.stdin.readline().rstrip())
N = I()
dp = [float('INF')]*(N+1)
dp[0] = 0
for i in range(1,N+1):
    dp[i] = dp[i-1]+1
    num6,num9 = 6,9
    while i-num6>=0:
        dp[i] = min(dp[i],dp[i-num6]+1)
        num6 *= 6
    while i-num9>=0:
        dp[i] = min(dp[i],dp[i-num9]+1)
        num9 *= 9
print(dp[-1])


Measured memory_bytes: 3828
s = gets.chop
queue_top = []
queue_last = []
flg = true # true: asc/false: desc
q = gets.to_i
q.times do
  c, *rest = gets.split
  case c
  when '1'
    flg = !flg
  when '2'
    if rest[0] == '1' && flg || rest[0] == '2' && !flg
      queue_top.unshift(rest[1])
    else
      queue_last.push(rest[1])
    end
  end
end
s = queue_top.join + s + queue_last.join
puts flg ? s : s.reverse

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

int main(){

  int N;
  cin >> N;

  vector<char> V;
  for(int i = 0; i < N; i++){
    char c;
    cin >> c;
    V.push_back(c);
  }

  vector<int> w(N);
  for(int i = 0; i < N-1; i++){
    if(V[i] == 'W') w[i+1] = w[i] + 1;
    else w[i+1] = w[i];
  }

  vector<int> e(N);
  for(int i = N-1; i > 0; i--){
    if(V[i] == 'E') e[i-1] = e[i] + 1;
    else e[i-1] = e[i];
  }

  int ans = 1000000;
  for(int i = 0; i < N; i++){
    ans = min(ans,w[i] + e[i]);
  }

  cout << ans << endl;

  return 0;
}
/*
int main(){

  int N;
  cin >> N;

  vector<char> V;
  for(int i = 0; i < N; i++){
    char c;
    cin >> c;
    V.push_back(c);
  }

  int ans = 1000000;
  for(int i = 0; i < V.size(); i++){
    int count = 0;
    for(int j = 0; j < i; j++){
      if(V[j] == 'W') count++;
    }
    for(int j = i+1; j < V.size(); j++){
      if(V[j] == 'E') count++;
    }
    ans = min(ans,count);
    //cout << count << " ";
  }
  cout << ans << endl;

  return 0;
}
*/


Measured memory_bytes: 3064
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

n = int(input())
_ac = 0
_wa = 0
_tle = 0
_re = 0

for _ in range(n):
    word = input()
    if word in 'AC':
        _ac += 1
        continue
    elif word in 'WA':
        _wa += 1
        continue
    elif word in 'TLE':
        _tle += 1
        continue
    elif word in 'RE':
        _re += 1
        continue


print('AC x ' + str(_ac))
print('WA x ' + str(_wa))
print('TLE x ' + str(_tle))
print('RE x ' + str(_re))


Measured memory_bytes: 9184
// C.

#include <iostream>
#include <algorithm>
#include <set>
#include <cstring>

using namespace std;

long long sum[2];
set<int> g[100000];
int color[100000];

bool dfs(int node, int c) {
	color[node] = c;
	++sum[c >= 0];
	for (int next : g[node]) {
		if (color[next] == -c) {
			;
		} else if (color[next] == c) {
			return false;
		} else if (!dfs(next, -c)) {
			return false;
		}
	}
	return true;
}

int main(int argc, char *argv[]) {
	long long n, m, ans;
	cin >> n >> m;
	for (int i = 0; i < m; ++i) {
		int a, b;
		cin >> a >> b;
		--a, --b;
		g[a].insert(b);
		g[b].insert(a);
	}
	if (dfs(0, 1)) {
		ans = sum[0] * sum[1] - m;
	} else {
		ans = (n * (n - 1)) / 2 - m;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 15232
X=int(input())
N=2*X
L=[1 for i in range(N)]
L[0]=0
L[1]=0
for i in range(2,N):
    if L[i]==1:
        for j in range(2*i,N,i):
            L[j]=0
M=X
while(1):
    if L[M]==1:
        print(M)
        break
    M+=1


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

const int MAXN = 100010;
int head[MAXN], to[MAXN << 1], nxt[MAXN << 1], tot;
void addedge(int b, int e) {
	nxt[++tot] = head[b]; to[head[b] = tot] = e;
	nxt[++tot] = head[e]; to[head[e] = tot] = b;
}
int dfs(int u, int b = 0, int fa = 0) {
	int sc = 0;
	for (int i = head[u]; i; i = nxt[i]) if (to[i] != fa)
		sc += dfs(to[i], fa == 0, u);
	if (sc + b > 1) std::cout << "First\n" << std::endl, exit(0);
	return sc ^ 1;
}
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	int n; std::cin >> n;
	for (int i = 1, t1, t2; i < n; ++i)
		std::cin >> t1 >> t2, addedge(t1, t2);
	for (int i = 1; i <= n; ++i) if (!nxt[head[i]]) { dfs(i); break; }
	std::cout << "Second" << std::endl;
	return 0;
}


Measured memory_bytes: 2176
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cassert>
#include<algorithm>
#define llong long long
using namespace std;

const int N = 1e5;
struct Edge
{
	int v,nxt;
} e[(N<<1)+3];
int fe[N+3];
int fa[N+3];
llong a[N+3];
int dgr[N+3];
int n,en;
bool ans;

void addedge(int u,int v)
{
	dgr[u]++;
	en++; e[en].v = v;
	e[en].nxt = fe[u]; fe[u] = en;
}

void dfs(int u)
{
	if(dgr[u]==1) {return;}
	llong tmp = 0ll,mx = 0ll;
	for(int i=fe[u]; i; i=e[i].nxt)
	{
		int v = e[i].v;
		if(v==fa[u]) continue;
		fa[v] = u;
		dfs(v);
		tmp += a[v];
		mx = max(mx,a[v]);
	}
	if(tmp<a[u]) {ans = false;}
	llong lim = min(tmp-mx,tmp/2);
	tmp -= a[u];
	if(tmp>lim) {ans = false;}
	a[u] -= tmp;
//	printf("a[%d]=%lld\n",u,a[u]);
}

int main()
{
	scanf("%d",&n);
	for(int i=1; i<=n; i++) scanf("%d",&a[i]);
	for(int i=1; i<n; i++)
	{
		int u,v; scanf("%d%d",&u,&v);
		addedge(u,v); addedge(v,u);
	}
	if(n==2) {if(a[1]==a[2]) puts("YES"); else puts("NO"); return 0;}
	int rtn = 1; while(dgr[rtn]==1) rtn++;
	ans = true; dfs(rtn);
	if(a[rtn]!=0) {ans = false;}
	if(ans==false) puts("NO");
	else puts("YES");
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i = 0; i < N; i++) { cin >> a[i]; a[i]--; }
  int t = 0;
  int sum = 0;
  while(t != 1) {
    t = a[t];
    sum++;
    if(sum > N) break;
  }
  if(sum > N && t != 1) { cout << -1; return 0; }
  else if(t == 1) { cout << sum; return 0; }
  return 0;
}

Measured memory_bytes: 768
table = [[0 for i in range(13)] for j in range(4)]
cardTypes = ['S', 'H', 'C', 'D']
total = int(input())
card_num = 0

for i in range(total):
    x, y = list(input().split())
    y = int(y)
    if x == 'S':
        table[0][y - 1] = y
    if x == 'H':
        table[1][y -1] = y
    if x == 'C':
        table[2][y -1] = y
    if x == 'D':
        table[3][y -1] = y

for i, row in enumerate(table):
    for j, element in enumerate(row):
        if element == 0:
            print(f"{cardTypes[i]} {j + 1}")
        
    


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

using namespace std;

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

	int k, a, b;
	cin >> k >> a >> b;

	for(int i = a; i <= b; ++i) {
		if(i % k == 0) {
			cout << "OK" << '\n';
			exit(0);
		}
	}

	cout << "NG" << '\n';

	return 0;
}


Measured memory_bytes: 3652
#include <string>
#include <vector>
#include <iostream>
#include <queue>
#include <functional>
#include <algorithm>
#include <random>
#include <cmath>
#include <climits>
#include <iomanip>
#include <cfloat>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
long long int solve(const std::vector<std::string> &state) {
	std::vector<std::vector<int>> ingot(state.size(), std::vector<int>(state.front().size(), 0));
	std::vector<std::vector<int>> orb(state.size(), std::vector<int>(state.front().size(), 0));
	long long int result = 0;
	for (int y = state.size() - 1; y >= 0; --y) {
		for (int x = state[y].size() - 1; x >= 0; --x) {
			if (state[y][x] == 'I') ingot[y][x] = 1;
			else if (state[y][x] == 'O') orb[y][x] = 1;
			if (y + 1 < state.size()) ingot[y][x] += ingot[y + 1][x];
			if (x + 1 < state[y].size()) orb[y][x] += orb[y][x + 1];
			if (state[y][x] == 'J') result += ingot[y][x] * orb[y][x];
		}
	}
	return result;
}
int main() {
	int h, w; std::cin >> h >> w;
	std::vector<std::string> state(h);
	for (auto& line : state) std::cin >> line;
	std::cout << solve(state) << std::endl;
}


Measured memory_bytes: 94128
#!/usr/bin/env python3

def solve(n, m):
    return (100 * n + 1800 * m) * (2 ** m)

def main():
    n, m = input().split()
    n = int(n)
    m = int(m)

    print(solve(n, m))


if __name__ == '__main__':
    main()



Measured memory_bytes: 2940
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,P> PP;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=4999999996000000001;


int main(){
    ll n;
    cin>>n;
    if(n%2==1){
        cout<<0<<endl;
    }else{
        n/=2;
        ll ans=0;
        for(ll m=5;m<=n;m*=5){
            ans+=n/m;
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
using namespace std;
int main(){
    int n, sum=0, mi=1000;
    cin >> n;
    vector<int>s(n);
    for(int i=0; i<n; i++){
        cin >> s[i];
        sum += s[i];
        if(s[i]%10!=0) mi = min(mi,s[i]);
    }
    if(sum%10==0){
        if(mi==1000) cout << 0 << endl;
        else cout << sum - mi << endl;
    }else{
        cout << sum << endl;
    }
    return 0;
}

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

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

    if (N == 0){
        cout << 2 <<endl;
        return 0;
    }else if (N == 1){
        cout << 1 << endl;
        return 0;
    }

    int64_t t0 = 2;
    int64_t t1 = 1;
    int64_t t2;

    for (int i; i < N - 1; i++){
        t2 = t0 + t1;
        t0 = t1;
        t1 = t2;
    }

    cout << t2 << endl;

}

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

using namespace std;

#define pb push_back
#define fi first
#define se second

int L;
vector< pair< pair<int, int>, int> > edge;

int main () {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> L; L --;
    for (int i = 18; i >= 0; --i) if( (1 << i) - 1 <= L) {
        for (int j = 1; j <= i; ++j) edge.pb({ {j, j + 1}, 0}), edge.pb({ {j, j + 1}, (1 << (j - 1) )});
        break;
    }
    while(L > 0) {
        for (int i = 18; i >= 0; --i) if( (1 << i) - 1 <= L) {
            edge.pb({ {i + 1, 20}, L + 1 - (1 << i)});
            L = L - (1 << i);
            break;
        }
    }
    if(L == 0) edge.pb({ {1, 20}, 0});

    cout << 20 << ' ' << edge.size() << '\n';
    for (auto i : edge) cout << i.fi.fi << ' ' << i.fi.se << ' ' << i.se << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {

  long n;
  scanf("%ld", &n);
  long a[n],b[n];
  for (long i = 0; i < n; i++) {
    scanf("%ld %ld", &a[i], &b[i]);
  }
  long button = 0;
  long multiple;
  for (long i = n-1; i >= 0; i--) {
    a[i] += button;
    if (a[i]%b[i] != 0) {
      multiple = a[i]/b[i];
      button += b[i]*(multiple+1)-a[i];
    }
  }
  printf("%ld\n", button);

  return 0;
}

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

int d;
double e;

int main() {
  while (1) {
    scanf("%d%lf", &d, &e);
    if (d == 0 && e == 0.0) return 0;

    double ans = 1.0/0.0;
    for (int i=0; i<=d; i++) {
      ans = min(ans, abs(sqrt(i*i+(d-i)*(d-i))-e));
    }
    printf("%f\n", ans);
  }
}

Measured memory_bytes: 3200
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;
typedef long long ll;

const ll INF = 1145141919810364364;

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

    int n, m, limit;
    cin >> n >> m >> limit;

    vector<vector<ll>> dis(n, vector<ll>(n, INF));
    for (int i = 0; i < m; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        if (c > limit)continue;
        a--;
        b--;
        dis[a][b] = c;
        dis[b][a] = c;
    }

    for (int k = 0; k < n; k++) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
            }
        }
    }

    vector<vector<int>> graph(n);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (dis[i][j] <= limit)graph[i].push_back(j);
        }
    }

    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int s, t;
        cin >> s >> t;
        s--;
        t--;

        queue<int> que;
        que.push(s);
        que.push(-1);
        int depth = 0;
        vector<int> ret(n, -1);
        while (ret[t] < 0) {
            int nowv = que.front();
            que.pop();

            if (nowv < 0) {
                if (que.empty())break;
                que.push(-1);
                depth++;
            } else {
                for (auto nextv:graph[nowv]) {
                    if (ret[nextv] < 0) {
                        que.push(nextv);
                        ret[nextv] = depth;
                    }
                }
            }
        }

        cout << ret[t] << "\n";
    }
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define Cout(s) cout << s << endl;
using ll = long long;
using P = pair<int, int>;

const ll INF = 1ll << 60;
ll MOD = 1e9 + 7;
//int t[10010];

int main()
{

    int n, t, a;
    cin >> n >> t >> a;
    vector<int> h(n);
    REP(i, n)
    cin >> h[i];

    double now = 0.0f;
    double best = 50;
    int ans = n;
    REP(i, n)
    {
        now = t - h[i] * 0.006;
        if (best > abs(a - now))
        {
            ans = i + 1;
            best = abs(a - now);
        }
    }

    Cout(ans);

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}


int n;

main(){
  cin>>n;
  int m=0;
  int s=n;
  while(s){
    m+=s%10;
    s/=10;
  }

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


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

int dp[128][5040];

map<vector<int>, int> enc;
map<int, vector<int> > dec;

int brute(int n, int *d, int *a)
{
	vector<int> v(n);
	int taste[128];
	for (int i = 0; i < n; i++) v[i] = i;
	
	int ans = 0, ctr = 0;
	do {
		int tmp = 0;
		memset(taste, 0, sizeof(taste));
		for (int i = 0; i < v.size(); i++){
			tmp += taste[v[i]];
			for (int _a = max(0, v[i] - d[v[i]]); _a <= min(n - 1, v[i] + d[v[i]]); _a++)
				taste[_a] += a[v[i]];
		}
		ans = max(ans, tmp);
		enc[v] = ctr;
		dec[ctr] = v;
		dp[n - 1][ctr++] = tmp;
	} while (next_permutation(v.begin(), v.end()));
	
	return (ans);
}

int main()
{
	int n;
	int d[128], a[128];
	
	scanf("%d", &n);
	
	for (int i = 0; i < n; i++) scanf("%d", d + i);
	for (int i = 0; i < n; i++) scanf("%d", a + i);
	
	if (n <= 7) return (!printf("%d\n", brute(n, d, a)));
	else brute(7, d, a);
	
	for (int i = 7; i < n; i++){
		for (int j = 0; j < 5040; j++){
			vector<int> v = dec[j], next(8), form(7);
			//i - 7, i - 6, i - 5, i - 4, i - 3, i - 2, i - 1, i をそれぞれ0, 1, 2, 3, 4, 5, 6, 7 とする
			for (int pos = 0; pos < 8; pos++){
				next[pos] = 7;
				for (int k = 0; k < 7; k++){
					next[k + (k >= pos)] = v[k];
				}
				int tmp = 0;
				int taste[128] = {0};
				for (int k = 0; k < 8; k++){
					int p = i - 7 + next[k];
					tmp += taste[p];
					for (int _a = max(i - 7, p - d[p]); _a <= min(i, p + d[p]); _a++)
						if (_a == i || p == i) taste[_a] += a[p];
				}
				int ctr = 0;
				for (int k = 0; k < 8; k++) if (next[k] != 0) form[ctr++] = next[k] - 1;
				int e = enc[form];
				dp[i][e] = max(dp[i][e], dp[i - 1][j] + tmp);
			}
		}
	}
	
	printf("%d\n", *max_element(dp[n - 1], dp[n - 1] + 5040));
	
	return (0);
}

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

using namespace std;
typedef long long ll;

int T, n;
const int maxn = 100;
const int maxv = 1000;
const int maxw = 1000000000;

const ll INF = 1ll<<60;

ll dp[maxn+5][maxv*maxn+5]; //minimal weight for val
ll W;
ll w[maxn];
ll v[maxn];

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> W;
  for(int i = 0; i < n; i++) cin >> w[i] >> v[i];
  int maxj = maxv*n+1;
  for(int i = 0; i < n; i++) for(int j = 0; j < maxj; j++) dp[i][j] = INF;
  dp[0][v[0]] = w[0];
  dp[0][0] = 0ll;
  for(int i = 1; i < n; i++)
  {
    dp[i][0] = 0;
    for(int j = 1; j < maxj; j++)
    {
      dp[i][j] = dp[i-1][j];//bug
      if(v[i]<=j) dp[i][j] = min(dp[i-1][j], dp[i-1][j-v[i]]+w[i]);
    }
  }
  ll ans = 0;
  for(int j = 0; j < maxj; j++)
  {
    //if(dp[n-1][j] != INF) cout << j << ' ' <<dp[n-1][j] << endl;
    if(dp[n-1][j] <= W) ans = j;
  }
  cout << ans << endl;
  //cout << dp[n-1][30];
  return 0;
}


Measured memory_bytes: 80128
#include<stdio.h>

int main(){
	
	int A, B;
	
	scanf("%d %d", &A, &B);
	
	int sum = 0;
	int count = 1;
	
//	for(int i = 1; i<=B; i++){
//		int temp = sum + A;
//		if(temp >= B){
//			break;
//		}
//		else{
//			count++;
//			sum += A-1;
////			printf("Step %d : %d\n", i, sum);
//		}
//	}

	while(count < B){
		count--;
		count += A;
		sum++;
	}
	
	printf("%d\n", sum);
	
	return 0;
}

Measured memory_bytes: 128
N,K = map(int,input().split())
l = [0]*N
for i in range(K):
    d = int(input())
    A = list(map(int,input().split()))
    for a in A:
        a -= 1
        l[a] += 1
ans = 0
for i in range(N):
    if l[i]==0:
        ans += 1
print(ans)

Measured memory_bytes: 67692
#include<bits/stdc++.h>
namespace FastIO{const char* ln="\n";struct Reader{char buf[1<<20],*s,*t;bool EOF_FLG;Reader():s(buf),t(buf),EOF_FLG(false) {};char gt() {return s==t&&((t=(s=buf)+fread(buf,1,1<<20,stdin))==s)?EOF:(*s++);}Reader& operator>>(char* str) {if(EOF_FLG)return *str=0,*this;while((*str=gt())!=' '&&*str!='\n'&&*str!=EOF)++str;if(*str==EOF)EOF_FLG=true;*str=0;return *this;}template<typename T>Reader&operator>>(T&x) {if(EOF_FLG)return *this;char c=0,d;while(c!=EOF&&(c<'0'||c>'9'))d=c,c=gt();if(c==EOF){EOF_FLG=true;return *this;}else x=0;while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+c-'0',c=gt();if(d=='-')x=-x;return *this;}}in;struct Writer{char buf[1<<20],*s,*t;Writer():s(buf),t(buf+(1<<20)){}~Writer(){fwrite(buf,1,s-buf,stdout);}void pt(char c){(s==t)?(fwrite(s=buf,1,1<<20,stdout),*s++=c):(*s++=c);}template<typename T>Writer&operator<<(T x){if(!x)return pt('0'),*this;if(x<0)pt('-'),x=-x;char a[40],t=0;while(x)a[t++]=x%10,x/=10;while(t--)pt(a[t]+'0');return *this;}Writer&operator<<(const char*s) {while(*s)pt(*s++);return *this;}}out;}using namespace FastIO;
namespace ZDY{
	#define ll long long
	#define db double
	#define sht short
	#define MB template <class T>
	#define Fur(i,x,y) for(int i=x;i<=y;i++)
	#define fur(i,x,y) for(i=x;i<=y;i++)
	#define Fdr(i,x,y) for(int i=x;i>=y;i--)
	#define fdr(i,x,y) for(i=x;i>=y;i--)
	#define clr(x,y) memset(x,y,sizeof(x))
	#define cpy(x,y) memcpy(x,y,sizeof(x))
	#define inf 0x3f3f3f3f
	#define fin(s) freopen(s".in","r",stdin)
	#define fout(s) freopen(s".out","w",stdout)
	#define l2(n) (int(log2(n)))
	#define fl(i,x) for(int i=head[x],to;to=e[i].to,i;i=e[i].nxt)
	#define fcin ios::sync_with_stdio(false)
	MB T ABS(T x){return x>0?x:-x;}
	MB T MAX(T x,T y){return x>=y?x:y;}
	MB T MIN(T x,T y){return x<=y?x:y;}
	MB T GCD(T x,T y){return y?GCD(y,x%y):x;}
	void SWAP(int &x,int &y){x^=y;y^=x;x^=y;}
}using namespace ZDY;using namespace std;
#define N 100011
int a[N],n,k;
priority_queue<int>q;
int main(){
	in>>k>>n;
	Fur(i,1,n)in>>a[i];
	sort(a+1,a+n+1);
	int tot=0;
	Fur(i,2,n)tot+=a[i]-a[i-1],q.push(a[i]-a[i-1]);
	Fur(i,1,MIN(k-1,n-1))tot-=q.top(),q.pop();
	out<<tot<<ln;
}

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

const int INF = 1e+8;
const int MAX_W = 101;
// テ・ツ?・テ・ツ環?
int H, W;
long long L;
char c[MAX_W][MAX_W];
// h[c] := テヲツ鳴?・ツュツ?c テ」ツ?ォテ・ツッツセテ・ツソツ愿」ツ?凖」ツつ凝・ツ青妥」ツ??
char h[256] = {0};
// 4 ティツソツ妥・ツつ?
int dx[4] = {0,1,0,-1};
int dy[4] = {-1,0,1,0};
// memo[y][x][d] := (x,y) テ」ツ?ォテ・ツ青妥」ツ??d テ」ツ?ァテ」ツ?淌」ツ?ゥテ」ツつ甘ァツ敖?」ツ?湘」ツ?ョテ」ツ?ォテ」ツ?凝」ツ?凝」ツつ虐tepテヲツ閉ー (テヲツ篠「テァツエツ「テ」ツ?療」ツ?ヲテ」ツ??」ツ?ェテ」ツ??」ツ?ィテ」ツ?催」ツ?ッ INF )
int memo[MAX_W][MAX_W][4];

void debug(int px, int py, int d, int step){
	cout << "[debug] step:" << step << endl;
	char ch;
	if( d == 0 ) ch = '^';
	if( d == 1 ) ch = '>';
	if( d == 2 ) ch = 'v';
	if( d == 3 ) ch = '<';
	
	for(int y=0 ; y < H ; y++ ){
		for(int x=0 ; x < W ; x++ ){
			if( y == py && x == px ){
				cout << ch;
			}else{
				cout << c[y][x];
			}
		}
		cout << endl;
	}
	cout << endl;
}

int main(){
	h['N'] = 0; h['E'] = 1; h['S'] = 2; h['W'] = 3;
	h[0] = 'N'; h[1] = 'E'; h[2] = 'S'; h[3] = 'W';
	
	while( cin >> H >> W >> L, H || W || L ){
		// テ・ツ按敕ヲツ慊淌・ツ個?
		for(int y=0 ; y < H ; y++ ){
			for(int x=0 ; x < W ; x++ ){
				for(int i=0 ; i < 4 ; i++ ){
					memo[y][x][i] = INF;
				}
			}
		}
		
		// テ・ツ?・テ・ツ環?
		for(int y=0 ; y < H ; y++ ){
			cin >> c[y];
		}
		// テ」ツつケテ」ツつソテ」ツδシテ」ツδ暗、ツスツ催ァツスツョテ」ツつ津ィツェツソテ」ツ?ケテ」ツつ?
		int sx, sy, dir;
		for(int y=0 ; y < H ; y++ ){
			for(int x=0 ; x < W ; x++ ){
				if( c[y][x] == 'N' || c[y][x] == 'E' || c[y][x] == 'S' || c[y][x] == 'W' ){
					sx = x;
					sy = y;
					dir = h[c[y][x]];
					c[y][x] = '.';
				}
			}
		}
		
		// テ」ツδュテ」ツδ愿」ツδε」ツδ暗」ツつ津・ツ仰陛」ツ?凝」ツ??
		int px = sx, py = sy, d = dir, mod, step=0, k;
		while( true ){
			//debug(px, py, d, step);
			memo[py][px][d] = step;
			int mx = px + dx[d];
			int my = py + dy[d];
			if( mx < 0 || my < 0 || W <= mx || H <= my || c[my][mx] == '#' ){
				d = (d + 1) % 4;
			}else{
				if( memo[my][mx][d] != INF ){
					mod = (step+1) - memo[my][mx][d];
					k = memo[my][mx][d];
					break;
				}else{
					px = mx;
					py = my;
					step++;
				}
			}
		}
		if( k < L ){
			L -= k;
			L = L % mod;
			L += k;
			L += mod;
		}
		px = sx, py = sy, d = dir, step = 0;
		int ax, ay, ad;
		while( true ){
			if( step == L ){
				ax = px;
				ay = py;
				ad = d;
				break;
			}
			int mx = px + dx[d];
			int my = py + dy[d];
			if( mx < 0 || my < 0 || W <= mx || H <= my || c[my][mx] == '#' ){
				d = (d + 1) % 4;
			}else{
				px = mx;
				py = my;
				step++;
			}
		}
		cout << ay+1 << " " << ax+1 << " " << h[ad] << endl;
	}
}

Measured memory_bytes: 1348
N = int(input())
A = [int(x) for x in input().split()]
print(*A)

for i in range(1, N):
    v = A[i]
    j = i - 1

    while j >= 0 and A[j] > v:
        A[j+1] = A[j]
        j = j - 1
    A[j+1] = v
    print(*A)


Measured memory_bytes: 5976
import itertools
N,M = map(int,input().split())
sides = []
for m in range(M):
    x,y = map(int,input().split())
    sides.append((x,y))
vertex = (i for i in range(2,N+1))
ans = 0
for v in itertools.permutations(vertex, N-1):
    T = 1
    if (1,v[0]) not in sides:
        T = 0
    for i in range(N-2):
        if (v[i],v[i+1]) not in sides and (v[i+1],v[i]) not in sides:
            T = 0
            break
    if T == 1:
        ans += 1
print(ans)



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

vector<int> nx(100010, 0);
vector<int> abx(100010, 0);

ll kurikaeshi(ll a,ll b) {
	ll ans = 1;
	while (b) {
		if (b % 2) {
			ans *= a;
		}
		a *= a;
		b /= 2;
		a %= 1000000007;
		ans %= 1000000007;
	}
	return ans;
}

ll warizan(ll a,ll b) {
	// a÷bを行います
	ll ans = a;
	ans *= kurikaeshi(b, 1000000005);
	ans %= 1000000007;
	return ans;
}

void abSetting(int ab) {
	ll ans = 1;
	for (int i = 0;i <= ab;i++) {
		abx[i] = ans;
		ans *= warizan(ab - i, i + 1);
		ans %= 1000000007;
	}
	abx[ab] = 1;
	return;
}

void nxSetting(int n) {
	ll ans = 1;
	for (int i = 0;i <= n + 1;i++) {
		nx[i] = ans;
		ans *= warizan(n + 1 - i, i + 1);
		ans %= 1000000007;
	}
	return;
}

int main() {
	int N;
	cin >> N;
	vector<int> T(N + 1, 512411);
	int a, b;
	for (int i = 0;i < N + 1;i++) {
		cin >> a;
		if (T[a] < 512411) {
			b = N - i;
			a = T[a];
			break;
		}
		else {
			T[a] = i;
		}
	}
	abSetting(a + b);
	nxSetting(N);
	for (int i = 0;i < N + 1;i++) {
		cout << (nx[i + 1] - abx[i] + 1000000007) % 1000000007 << endl;
	}
}


Measured memory_bytes: 2432
#include <stdio.h>
#include <limits.h>

int main(void){
  int n, m, x, y, i, flag = 0;
  scanf("%d%d%d%d", &n, &m, &x, &y);
  int xmax = INT_MIN;
  int ymin = INT_MAX;
  
  for(i = 0; i < n; i++){
    int xi;
    scanf("%d", &xi);
    if(xi > xmax) xmax = xi;
  }
  for(i = 0; i < m; i++){
    int yi;
    scanf("%d", &yi);
    if(yi < ymin) ymin = yi;
  }
  
  for(i = -100; i < 101; i++){
    if((x < i && i <= y) && xmax < i && ymin >= i){
      flag = 1;
      break;
    }
  }
  if(flag) printf("No War\n");
  else printf("War\n");
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cmath>

using namespace std;

int main(){
    long N, D, output = 0;
    cin >> N;
    cin >> D;

    long* X = (long*)malloc(N*sizeof(long));
    long* Y = (long*)malloc(N*sizeof(long));
    double* distances = (double*)malloc(N*sizeof(double));

    for (long i = 0; i < N; i ++){
        cin >> X[i];
        //prlongf("X[%i] = %i\n", i, X[i]);
        cin >> Y[i];
        //prlongf("Y[%i] = %i\n", i, Y[i]);
    }

    for (long i = 0; i < N; i ++){
        distances[i] = sqrt(pow(X[i],2) + pow(Y[i],2));
        //cout << (distances[i]) << endl;
        if (distances[i] <= D){
            output ++;
        }
    }
    
    cout << output;
}

Measured memory_bytes: 8276
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define YES {cout<<"YES"<<'\n';}
#define NO {cout<<"NO"<<'\n';}
#define Yes {cout<<"Yes"<<'\n';}
#define No {cout<<"No"<<'\n';}
#define yes {cout<<"yes"<<'\n';}
#define no {cout<<"no"<<'\n';}
void YN(bool flg){cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg){cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define out(n) {cout << n << '\n';}
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
int ABS(int a) {if(a<0) a = -a; return a;}
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n /= 2; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);

    int h,w; cin >> h >> w;
    char hw[h][w]; REP(i,h)REP(j,w) cin >> hw[i][j];
    REP(i,h){ /*横*/
        bool flag = 1;
        REP(j,w){if(hw[i][j]=='#') flag = 0;}
        if(flag) REP(j,w) hw[i][j] = '1';
    }
    REP(i,w){ /*縦*/
        bool flag = 1;
        REP(j,h){if(hw[j][i]=='#') flag = 0;}
        if(flag) REP(j,h) hw[j][i] = '1';
    }
    bool super_first = 1;
    REP(i,h){bool first = 1; REP(j,w){if(hw[i][j]!='1'){if(!super_first) if(first) cout << endl; super_first = 0; first = 0; cout << hw[i][j];}}}
    cout << endl;

    return 0;
}

Measured memory_bytes: 256