akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    int dx = tx - sx, dy = ty - sy;
    cout << string(dx, 'R') << string(dy, 'U');
    cout << string(dx, 'L') << string(dy, 'D');
    cout << 'D' << string(dx + 1, 'R') << string(dy + 1, 'U') << 'L';
    cout << 'U' << string(dx + 1, 'L') << string(dy + 1, 'D') << 'R';
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
/**
**	author : Raghav
**	codechef:raghav_456
**	codeforces:raghavramola7
**/
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define endl 			"\n"
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void Raghav()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(100);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int32_t main()
{
	Raghav();
		int n;
		cin>>n;
		vector<int> a(n);
		for(int i=0;i<n;i++)
		{
			cin>>a[i];
		}
		sort(a.begin(),a.end(),greater<int>());
 
		queue<int> q;
		q.push(a[0]);
 
		int sum=0;
 
		for(int i=1;i<n;i++)
		{
			int temp=q.front();
			sum+=temp;
			q.pop();
			q.push(a[i]);
			q.push(a[i]);
		}
 
		cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 6428
class Calc:
    def __init__(self, max_value, mod):
        """combination(max_value, all)"""
        fact = [-1] * (max_value + 1)
        fact[0] = 1
        fact[1] = 1
        for x in range(2, max_value + 1):
            fact[x] = x * fact[x - 1] % mod

        invs = [1] * (max_value + 1)
        invs[max_value] = pow(fact[max_value], mod - 2, mod)
        for x in range(max_value - 1, 0, -1):
            invs[x] = invs[x + 1] * (x + 1) % mod

        self.fact = fact
        self.invs = invs
        self.mod = mod

    def nCr(self, n, r):
        r = min(n - r, r)
        if r < 0: return 0
        if r == 0: return 1
        if r == 1: return n
        return self.fact[n] * self.invs[r] * self.invs[n - r] % self.mod

    def nHr(self, n, r):
        return self.nCr(n - 1 + r, r)


class PowPreCalc:
    def __init__(self, *, b, m, mod):
        """(b**m)%mod"""
        res = [1]
        t = 1
        for _ in range(m):
            t = t * b % mod
            res.append(t)
        self._res = res

    def get_pow(self, m):
        """(b**m)%mod"""
        return self._res[m]


def main():
    MOD = 10 ** 9 + 7

    K = int(input())
    S = input()

    N = len(S)

    calc = Calc(max_value=N - 1 + K, mod=MOD)

    p26 = PowPreCalc(b=26, m=K, mod=MOD)
    p25 = PowPreCalc(b=25, m=K, mod=MOD)

    ans = 0
    for tail_len in range(K + 1):
        ans = (ans
               + calc.nCr(N - 1 + K - tail_len, N - 1) * p26.get_pow(tail_len) * p25.get_pow(K - tail_len)
               ) % MOD

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 166308
n = int(input())
a = list(map(int, input().split()))  # N + 1
b = list(map(int, input().split()))  # N
cnt = 0

for i in range(n):
    if a[i] - b[i] >= 0:
        cnt += b[i]
    else:
        cnt += a[i]
        b[i] -= a[i]
        if a[i + 1] >= b[i] >= 0:
            a[i + 1] -= b[i]
            cnt += b[i]
        else:
            cnt += a[i + 1]
            a[i + 1] = 0
print(cnt)

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

int main()
{



        int N, Y;

        cin >> N >> Y;


        int x = 0;
        int y = 0;
        int z = 0;
        for (x = 0; x < N+1; ++x) {

                for (y = 0; y < N-x+1; ++y) {

                        z = N - x - y;
                        if (z < 0) {
                                continue;
                        }
                        if ((10000 * x) + (5000 * y) + (1000 * z) == Y) {

                                cout << x << " " << y << " " << z << endl;
                                return 0;
                        }
                }
        }
        cout << "-1 -1 -1" << endl;


}


Measured memory_bytes: 256
#include<stdio.h>

void
swp(int *a, int *b)
{
        int tmp;
        tmp = *a;
        *a = *b;
        *b = tmp;
}

int
main(int argc, char *argv[])
{
        int a, b, c;
        int i;
        char res[1000] = {0};
        char *itr;

        scanf("%d", &i);
        itr = res;
        for (; i > 0; i--) {
                scanf("%d %d %d", &a, &b, &c);
                if (a > b) swp(&a, &b);
                if (b > c) swp(&b, &c);
                if (a * a + b * b == c * c) *itr = 1;
                itr++;
        }
        *itr = 2;
        itr = res;
        while (*itr != 2)
                printf("%s\n", (*itr++ == 1)? "YES" : "NO");
        return 0;
}

Measured memory_bytes: 580
#include <cstdio>
#include <queue>
#include <algorithm>
#include <cstring>
#define Max_H 1000
#define Max_W 1000
using namespace std; 

typedef pair<int,int> P;

int H,W,N;
int moush;
int minTime;
int dx[]={0,0,1,-1},dy[]={1,-1,0,0};
char map[Max_H+1][Max_W+1];
int d[Max_H+1][Max_W+1];

void solve(){
	memset(d,-1,sizeof(d));
	deque<P> que;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(map[i][j]=='S'){
				que.push_back(P(i,j));
				d[i][j]=0;
				break;
			}
		}
	}
	moush=1;
	while(moush!=N+1){
		P p=que.front();
		que.pop_front();
		for(int i=0;i<=3;i++){
			int tx=p.first+dx[i],ty=p.second+dy[i];
			if(tx<0||ty<0||tx>=H||ty>=W||map[tx][ty]=='X') continue;
			if(d[tx][ty]==-1) {
				if(map[tx][ty]-'0'==moush){
					moush++;
					que.clear();
					que.push_back(P(tx,ty));
					minTime+=d[p.first][p.second]+1;
					memset(d,-1,sizeof(d));
					d[tx][ty]=0;
					break;
				}else{
					que.push_back(P(tx,ty));
					d[tx][ty]=d[p.first][p.second]+1;
				}
			}
		}
	}	 
	printf("%d\n",minTime);
}

int main(){
	scanf("%d%d%d",&H,&W,&N);
	for(int i=0;i<H;i++){
		scanf("%s",map[i]);
	}
	solve();
	return 0;
} 



Measured memory_bytes: 7608
#include <bits/stdc++.h>
using namespace std;
const int maxn=100005;

char s[maxn];

int main()
{
    while(~scanf("%s", &s)){
        int ca=0, cb=0, cc=0;
        int len=strlen(s);
        for(int i=0;i<len;i++){
            if(s[i]=='a')ca++;
            if(s[i]=='b')cb++;
            if(s[i]=='c')cc++;
        }
        int mi=min(ca, cb);
        mi=min(mi, cc);
        ca-=mi;
        cb-=mi;
        cc-=mi;
        if(ca<2&&cb<2&&cc<2){
            printf("YES\n");
        }
        else printf("NO\n");
    }
    return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<queue>
#include<string.h>
#include<string>
#include<map>
#include<unordered_set>
#include<stack>
#include<vector>
#include<deque>
#define mod 998244353
using namespace std;
struct str {
	int idx, cnt;
};
int n, m, k, arr[300010];
string s, temp;
map<char, int> mp;
bool chk[30];
int main() {
	cin >> s;
	int cnt = 0;
	for (int i = 0; i < s.size(); i++) {
		mp[s[i]]++;
	}
	if (mp.size() == 2) {
		for (auto i = mp.begin(); i != mp.end(); i++) {
			if (i->second != 2) {
				printf("No");
				return 0;
			}
		}
		printf("Yes");
		return 0;
	}
	else printf("No");
	return 0;
}

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

int main(){
  string S; cin >> S;
  int bcount=0;
  int N=S.size();
  for(int i=0; i<N; i++){
    if(S[i]=='B') bcount++;
  }
  long long num=0;
  for(int i=0; i<N; i++){
    if(S[i]=='B'){
      num+=(N-bcount-i);
      bcount--;
    }
  }
  cout << num << endl;
}

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

int main(){
  int n, r;
  cin >> n;
  vector <int> x(n);
  rep(i,n) cin >> x[i];
  int x2=0;
  int n2=0;
  rep(i,n)x2=max(x2,x[i]);
  vector <int> ans(x2,1001001000);
  vector <int> m(100,-1);
  int tmp=0;
  int curr=0;
  int a=1001001000;
  for(int j=0;j<x2;j++){
    rep(i,n){
      tmp=x[i]-(j+1);
      tmp=abs(tmp);
      //cout << "t" <<tmp << endl;
      if(m[tmp]!=-1){
	curr+=m[tmp];
	//cout << "t2" << m[tmp];
      }
      else{
	//cout << "t2" <<tmp << endl;
	m[tmp]=pow(tmp,2);
	//cout << m[tmp] << endl;
	curr+=m[tmp];
      }
    }
    //cout << curr;
    ans[j]=curr;
    curr=0;
  }
  rep(i,x2)a=min(a,ans[i]);
  cout << a << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
#include <cstdlib>

using namespace std;

int main()
{
	string s = "";
	char ss;
	cin >> s;
	for (int i = 0; i < s.length(); i++)
	{
		if (i % 2 == 0) cout << s[i];
	}

    return 0;
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

template <typename TYPE>
void print_vec(const vector<TYPE>& v){
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
  cout << endl;
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   " << endl;
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}
 




const int D = 365;
vector<int> c(26, 0);
vector<vector<int>> s(D, vector<int>(26, 0));

ll calc_score(vector<int> &t){
  vector<int> last(26, -1);
  ll score = 0;
  for(int d=0; d<D; d++){
    int type = t[d];
    score += s[d][type];
    last[type] = d;
  
    for(int i=0; i<26; i++){
      score = score - c[i] * (d - last[i]);
    }
  }
  return score;
}

int main(){
  int tmp;
  cin >> tmp;
  //vector<int> c(26, 0);
  for(int i=0; i<26; i++) cin >> c[i];
  //vector<vector<int>> s(D, vector<int>(26, 0));
  for(int i=0; i<D; i++){
    for(int j=0; j<26; j++){
      cin >> s[i][j];
    }
  }


  vector<int> t(D);
  for(int i=0; i<D; i++){
    cin >> t[i];
    t[i]--;
  }

  ll M;
  cin >> M;
  vector<int> day(M), q(M);
  
  for(int i=0; i<M; i++){
    cin >> day[i] >> q[i];
    day[i]--;
    q[i]--;
  }

  for(int i=0; i<M; i++){
    t[day[i]] = q[i];
    cout << calc_score(t) << endl;
  }
 
}


Measured memory_bytes: 3868
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n;
    cin >> n;
    vector<int> data(n);
    for (int i = 0; i < n; i++){
        cin >> data.at(i);
    }

    int num = 1;
    int count = 0;
    for (int i = 0; i < n; i++){
        if (num == data.at(i)){
            num ++;
        }
        else{
            count++;
        }
    }

    if (num == 1){
        count = -1;
    }

    cout << count << endl;
}

Measured memory_bytes: 1024
N=gets.to_i
ps=gets.split.map(&:to_i)
qs=gets.split.map(&:to_i)

n = m = 0
(1..N).to_a.permutation.with_index do |a,i|
  n = i if a == ps
  m = i if a == qs
end

puts (n-m).abs


Measured memory_bytes: 2172
mod stdin_reader {
  use std::io::stdin;
  use std::io::Read;

  pub struct StdinReader {
    pub buf: Vec<String>,
    pub cursor: usize,
  }

  pub fn new() -> StdinReader {
    StdinReader::new()
  }

  impl StdinReader {
    pub fn new() -> Self {
      let mut s = String::new();
      let stdin = stdin();
      stdin.lock().read_to_string(&mut s).unwrap();
      let buf = s.split_whitespace().map(|s| s.to_string()).collect();
      return StdinReader { buf: buf, cursor: 0 }
    }

    pub fn next(&mut self) -> Option<String> {
      let val = self.buf.get(self.cursor).cloned();
      self.cursor += 1;
      return val
    }

    pub fn as_i64_opt(&mut self) -> Option<i64> {
      self.next().and_then(|s| s.parse::<i64>().ok())
    }

    pub fn as_i64(&mut self) -> i64 {
      self.as_i64_opt().unwrap()
    }

    pub fn as_vec_i64(&mut self, n: usize) -> Vec<i64> {
      (0..n).map(|_| self.as_i64()).collect()
    }

    pub fn as_f64_opt(&mut self) -> Option<f64> {
      self.next().and_then(|s| s.parse::<f64>().ok())
    }

    pub fn as_f64(&mut self) -> f64 {
      self.as_f64_opt().unwrap()
    }

    pub fn as_vec_f64(&mut self, n: usize) -> Vec<f64> {
      (0..n).map(|_| self.as_f64()).collect()
    }

    pub fn as_usize_opt(&mut self) -> Option<usize> {
      self.next().and_then(|s| s.parse::<usize>().ok())
    }

    pub fn as_usize(&mut self) -> usize {
      self.as_usize_opt().unwrap()
    }

    pub fn as_vec_usize(&mut self, n: usize) -> Vec<usize> {
      (0..n).map(|_| self.as_usize()).collect()
    }
  }
}

mod utils {
  pub fn is_int(n: f64) -> bool {
    let trunc = (n.trunc() as i64) as f64;
    return (n - trunc) < 0.0001
  }
}

fn main() {
  // stdout
  use std::io::{stdout, Write, BufWriter};
  let stdout = stdout();
  let mut writer = BufWriter::new(stdout.lock());

  // stdin
  let mut reader = stdin_reader::new();

  // main
  let n = reader.as_usize();
  let hs = reader.as_vec_i64(n);

  let mut dp = vec![0; n];
  dp[1] = (hs[0] - hs[1]).abs();

  for i in (2..n) {
    let big_jump = dp[i-2] + (hs[i-2] - hs[i]).abs();
    let small_jump = dp[i-1] + (hs[i-1] - hs[i]).abs();
    dp[i] = std::cmp::min(big_jump, small_jump);
  }

  println!("{}", dp[n-1]);
}

Measured memory_bytes: 10492
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		//IDカード枚数
		int N = scanner.nextInt();
		//ゲートの個数
		int M = scanner.nextInt();
		List<Integer> listL = new ArrayList<Integer>();
		List<Integer> listR = new ArrayList<Integer>();
		
		int answer = 0;
		//リスト作成
		for(int i = 0; i < M; i++){
			
			listL.add(scanner.nextInt());
			listR.add(scanner.nextInt());
			
		}
		//全てのゲートを通れるカードの順番はlistLの最大値以上、listRの最小値以下
		Integer l = Collections.max(listL);
		Integer r = Collections.min(listR);
		if (l <= r){
			
			answer = r - l + 1;
		}else{
			
			answer = 0;
		}
		System.out.println(answer);
	}
}


Measured memory_bytes: 77952
//love yjl forever
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int INF=0x3f3f3f3f,N=2e5+5;
ll n,k;
ll a[N];
ll upp(ll x,ll y)
{
	ll z=x/y;
	if(z*y!=x)
		z++;
	return z;
}
bool ok(ll mid)
{
	ll s=0;
	for(int i=1;i<=n;i++)
	{
		s+=upp(a[i],mid)-1;
	}
	return s<=k;
}
int main()
{
/*	freopen("","r",stdin);
	freopen("","w",stdout);*/
	ll i;
	cin>>n>>k;
	ll l,r;
	l=r=1;
	for(i=1;i<=n;i++)
		scanf("%d",&a[i]),r=max(r,a[i]);
	int ans=0;
	while(l<=r)
	{
		int mid=l+r>>1;
		if(ok(mid))
		{
			ans=mid;
			r=mid-1;
		}
		else 
			l=mid+1;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 5232
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

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

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

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

	vector<bool> cansum(40001);
	int n, q;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	
	for (int tmp = 0; tmp < (1 << n); tmp++) {
		int sum = 0;
		for (int i = 0; i < n; i++) {
			if (tmp & (1 << i))
				sum += a[i];
		}
		cansum[sum] = true;
	}
	cin >> q;
	while (q--) {
		int m;
		cin >> m;
		if (cansum[m])
			cout << "yes" << endl;
		else
			cout << "no" << endl;
	}
}


Measured memory_bytes: 3088
n = int(input())
w = list(map(int, input().split()))

ans = float('inf')
s1 = 0
s2 = sum(w)

for i in range(n):
    s1 += w[i]
    s2 -= w[i]
    ans = min(ans, abs(s2 - s1))

print(ans)


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

int main() {
  int n, W;
  cin >> n >> W;
  vector<ll> dp(W + 1);
  rep(i, n) {
    int w, v;
    cin >> w >> v;
    for (int j = W - w; j >= 0; j--) dp[j + w] = max(dp[j + w], dp[j] + v);
  }
  cout << dp[W] << endl;
}

Measured memory_bytes: 1024
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::{vec, cmp, num};
use std::collections::HashSet;


struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner {cin: cin}
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
                    .skip_while(|c| c.is_whitespace())
                    .take_while(|c| !c.is_whitespace())
                    .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

// create Vec<char> from String
#[allow(dead_code)]
fn to_chars(s: String) -> vec::Vec<char> {
    let mut cs = s.chars();
    let mut res = vec::Vec::new();
    while let Some(c) = cs.next() {
        res.push(c);
    }
    res
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);
    let mut nums = HashSet::new();
    for _i in 0..3 {
        let a: i32 = sc.read();
        nums.insert(a);
    }
    println!("{}", nums.len());
}

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

int main() {
	int a,b,c;
	cin>>a>>b>>c;
	
	if(a==b && a!=c){
	    cout<<"Yes"<<endl;
	}else if(b==c && a!=b){
	    cout<<"Yes"<<endl;
	}else if(a==c && a!=b){
	    cout<<"Yes"<<endl;
	}else{
	    cout<<"No"<<endl;
	}
	return 0;
}

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

using namespace std;

double getProbability(int i, double k){
    double p = 1.0;
    
    while ((double)i < k){
        i *= 2;
        p *= 0.5;
    }
    return p;
}

int main(void){
    double n, k;
    cin >> n >> k;
    
    double ans = 0.0;
    
    for (int i = 1; i <= n; i++) ans += getProbability(i, k);
    
    ans /= n;
    
    cout << fixed << setprecision(15);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ul;
typedef signed long long ll;
ul over = 1000000007;

mt19937 mt(time(nullptr));
// uniform_int_distribution< int > rand_int(0, 10) // rand[0, 10] inclusive

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  int n, x;
  cin >> n >> x;
  vector< int > s(n);
  for (int i=0; i<n; ++i) cin >> s[i];
  ul ans = 0;
  vector< ul > ai(x+1, 0);
  sort(s.begin(), s.end());
  for (int j=0; j<=x; ++j) ai[j] = j%s[0];
  ul kai = 1;
  for (int i=1; i<n; ++i) {
      kai *= i;
      kai %= over;
      vector< ul > ai2(x+1, 0);
    for (int j=0; j<=x; ++j) {
      ai2[j] = ai[j%s[i]] + ai[j]*i;
      ai2[j] %= over;
    }
    for (int j=0; j<=x; ++j) ai[j] = ai2[j];
  }
  cout << ai[x] << endl;
  return 0;
}


Measured memory_bytes: 1792
#include "stdio.h"
#include "stdbool.h"

void array_reset( int*, int );
int main(){
    int n;
    char mark;
	char enter;
    int rank;
    int spade[13], hert[13], crab[13], dia[13];
    int i;
    
    array_reset( spade, 13 );
    array_reset( hert, 13 );
    array_reset( crab, 13 );
    array_reset( dia, 13 );

    scanf( "%d", &n );
    
    for( i = 0; i < n; i++ ){
        scanf( "%c%c%d", &enter, &mark, &rank );
        switch( mark ){
        case 'S':
            spade[ rank - 1 ] = 1;
            break;
        case 'H':
            hert[ rank - 1 ] = 1;
            break;
        case 'C':
            crab[ rank - 1 ] = 1;
            break;
        case 'D':
            dia[ rank - 1 ] = 1;
            break;
        default:;
        }
    }
    
    for( i = 0;i < 13;i++ ){
        if( spade[i] == 0 ){
            printf( "S %d\n", i + 1 );
        }
    }
    for( i = 0;i < 13;i++ ){
        if( hert[i] == 0 ){
            printf( "H %d\n", i + 1 );
        }
    }
    for( i = 0;i < 13;i++ ){
        if( crab[i] == 0 ){
            printf( "C %d\n", i + 1 );
        }
    }
    for( i = 0;i < 13;i++ ){
        if( dia[i] == 0 ){
            printf( "D %d\n", i + 1 );
        }
    }
    return 0;
}

void array_reset( int* array, int size )
{
    int i;
    for( i = 0; i < size; i++ ){
        *( array + i ) = 0;
    }
}


Measured memory_bytes: 2116
#include<iostream>
using namespace std;
int main(){
long long a,b,k;
cin>>a>>b>>k;
long long r1,r2;

 if(k<=a+b &&k>=a){
  cout<<"0"<<" "<<b-(k-a)<<endl;
}
else if(a>=k) {
  cout<<a-k<<" "<<b<<endl;
}
else {
    cout<<"0"<<" "<<"0"<<endl;
}
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <functional>
using namespace std;
typedef long long ll;


int main() {
	int num;

	cin >> num;

	if (num == 0) {
		cout << "1" << endl;
	}
	else {
		cout << "0" << endl;
	}
}


Measured memory_bytes: 3592
function main(input) {
    const args = input.split(' ');
    const a = parseInt( args[0], 10 );
    const b = parseInt( args[1], 10 );

    if( (a * b) % 2 === 0 ) {
        console.log('Even');
    } else {
        console.log('Odd');
    }
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8') );

Measured memory_bytes: 29572
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N =Integer.parseInt(sc.next());
        int min = Integer.MAX_VALUE;
        int max = Integer.MIN_VALUE;
        for(int i = 0; i < N ;i++){
            int in = Integer.parseInt(sc.next());
            if(min > in){
                min = in;
            }
            if(max < in){
                max = in;
            }
        }
        System.out.println(max-min);
    }
}

Measured memory_bytes: 23764
#include<stdio.h>

int main(){
 
  long long i,n,number[1000000],a=0,ans=0; 
  
  scanf("%lld",&n);
  
  for(i = 0; i < n; i++){
    scanf("%lld",&number[i]);
    if(i == 0)continue;
    a = number[i-1] - number[i];
    //printf("number = %lld number-1 = %lld a = %lld\n",number[i] ,number[i-1] ,a);
    
    if(a > 0){
      ans += a;
      number[i] = number[i-1];
    }
    //printf("ans = %lld number = %lld\n",ans ,number[i]);
  }
  
  printf("%lld\n",ans);
  
  return 0;
  
}



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

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


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

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

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

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

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

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


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    ll n;
    cin >> n;
    if(n%2 ==0) cout << n << endl;
    else cout << 2*n << endl;

    return 0;
}

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


Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
  int calen[12] = {31,29,31,30,31,30,31,31,30,31,30,31};
  int month,day;
  int ans = 0;

  while(cin >> month >> day){
    if(month == 0)break;
    
    ans = 0;

    for(int i = 0;i < month-1;i++){
      ans += calen[i];
    }

    ans += day;

    switch (ans % 7) {
    case 0 : cout << "Wednesday" << endl;
      break;
    case 1 : cout << "Thursday" << endl;
      break;
    case 2 : cout << "Friday" << endl;
      break;
    case 3 : cout << "Saturday" << endl;
      break;
    case 4 : cout << "Sunday" << endl;
      break;
    case 5 : cout << "Monday" << endl;
      break;
    case 6 : cout << "Tuesday" << endl;
      break;
    }

  }
}

Measured memory_bytes: 1152
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let n: Vec<char> = read::<String>().chars().collect();
    println!("{}", if n[0] == n[2] { "Yes" } else { "No" });
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


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

long long N, K;
long long a[100005];
long long b[100005];
vector<long long> c;

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

	for(long long i = K + 2 * N; i < K + 3*N; i++){
		c.push_back(i);
	}

	long long cur = 0;
	for(long long i = 0; i < N; i++){
		if(cur >= N){
			cur = 1;
		}
		//cout << "a[" << cur << "] = " <<  K + i << endl;
		a[cur] = K + i;
		cur += 2;
	}

	cur = 1;
	for(long long i = N; i < 2*N; i++){
		if(cur >= N){
			cur = 0;
		}
		//cout << "b[" << cur << "] = " << K + i << endl;
		b[cur] = K + i;
		cur += 2;
	}

	for(long long i = 0; i < N; i++){
		if(a[i] + b[i] > c[i]){
			cout << "-1" << endl;
			return 0;
		}
	}

	for(long long i = 0; i < N; i++){
		cout << a[i] << " " << b[i] << " " << c[i] << endl;
	}
}


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

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

const ll INF=1001001001;

int main(){
   int n;
   cin>>n;
   vector<int>h(n);
   rep(i,n)cin>>h[i];
   vector<ll>dp(n);
   rep(i,n)dp[i]=INF;
   dp[0]=0;
   for(ll i=1;i<(n);i++){
       chmin(dp[i],dp[i-1]+abs(h[i]-h[i-1]));
       if(i>1)chmin(dp[i],dp[i-2]+abs(h[i]-h[i-2]));
   }
   ll ans=dp[n-1];
   cout<<ans<<endl;
}

Measured memory_bytes: 4224
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>

using namespace std;
typedef long long ll;

int dp[105][4][4][4];

ll mod = 1000000007;

int main () {
    ll N;
    
    cin >> N;
    
    for (int j = 0; j < 4; j++) {
        for (int k = 0; k < 4; k++) {
            for (int l = 0; l < 4; l++) {
                if (j == 0 && k == 2 && l == 1) continue;
                if (j == 0 && k == 1 && l == 2) continue;
                if (j == 2 && k == 0 && l == 1) continue;
                dp[3][j][k][l] = 1;
            }
        }
    }
    
    for (int i = 3; i < N; i++) {
        for (int j = 0; j < 4; j++) {
            for (int k = 0; k < 4; k++) {
                for (int l = 0; l < 4; l++) {
                    for (int m = 0; m < 4; m++) {
                        if (k == 0 && l == 2 && m == 1) continue;
                        if (k == 0 && l == 1 && m == 2) continue;
                        if (k == 2 && l == 0 && m == 1) continue;
                        if (j == 0 && l == 2 && m == 1) continue;
                        if (j == 0 && k == 2 && m == 1) continue;
                        (dp[i + 1][k][l][m] += dp[i][j][k][l]) %= mod;
                    }
                }
            }
        }
    }
    
    ll ans = 0;
    for (int j = 0; j < 4; j++) {
        for (int k = 0; k < 4; k++) {
            for (int l = 0; l < 4; l++) {
                (ans += dp[N][j][k][l]) %= mod;
            }
        }
    }
    
    cout << ans << endl;
    
    return 0;
    
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int n;
  int a;
  int b;
  scanf("%d", &n);
  scanf("%d", &a);
  scanf("%d", &b);
  if(n*a < b){
    printf("%d", n*a);
  }else{
    printf("%d", b);
  }
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define poly vector<ll>
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
inline char gc(){
	static char buf[100000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x=0;char ch=gc();bool positive=1;
	for(;!isdigit(ch);ch=gc()) if(ch=='-')	positive=0;
	for(;isdigit(ch);ch=gc()) x=x*10+ch-'0';
	return positive?x:-x;
}
inline void write(ll x){
	if(x<0){
		x=-x;putchar('-');
	}
	if(x>=10) write(x/10);
	putchar('0'+x%10);
}
inline void writeln(ll x){write(x);puts("");}
inline void writep(ll x){write(x);putchar(' ');}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=4005,mo=924844033;
int n,m,f[N][N][2],fac[N],a[N],opt;
int main(){
	For(i,fac[0]=1,N-1) fac[i]=(ll)fac[i-1]*i%mo;
	n=read();m=read();
	For(i,1,m) For(o,1,2){
		for(int j=i;j<=n;j+=m) a[++opt]=(j!=i);
	}
	f[0][0][0]=1;
	For(i,1,opt) For(j,0,i){
		f[i][j][0]=(f[i-1][j][0]+f[i-1][j][1])%mo;
		if(a[i]&&j) f[i][j][1]=f[i-1][j-1][0];
	}
	int ans=0;
	For(i,0,n){
		int t=(f[opt][i][0]+f[opt][i][1])%mo;
		t=(ll)t*fac[n-i]%mo;
		if(i&1) ans=(ans+mo-t)%mo;
		else ans=(ans+t)%mo;
	}
	cout<<ans;
}

Measured memory_bytes: 123776
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10;
int n,h[N],a[N];
ll d[N];
int read()
{
	int x=0,f=1;char ch=getchar();
	while (ch<'0'||ch>'9') {if (ch=='-') f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9') x=(x<<1)+(x<<3)+(ch&15),ch=getchar();
	return x*f;
}
int lowbit(int x){return x&-x;}
ll query(int x){ll s=0;for (register int i=x;i>0;i-=lowbit(i)) s=max(s,d[i]);return s;}
void update(int x,ll v){for (register int i=x;i<=n;i+=lowbit(i)) d[i]=max(d[i],v);}
int main()
{
	n=read();
	for (register int i=1;i<=n;++i) h[i]=read();
	for (register int i=1;i<=n;++i) a[i]=read();
	ll ans=0;
	for (register int i=1;i<=n;++i)
	{
		ll t=query(h[i]-1)+a[i];ans=max(ans,t);
		update(h[i],t);
	}
	printf("%lld\n",ans);
	return 0;
}

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

//定数
const long long MOD1=1000000007;
const long long MOD2=998244353;
const long double PI=3.1415926535897932;
const long long MAXLL=9223372036854775807;
const long long INF=2305843009213693951;
const long long dx[]={0,1,0,-1,1,-1,1,-1};
const long long dy[]={1,0,-1,0,1,1,-1,-1};

//型名省略
#define ll long long
#define ull unsigned long long
#define ld long double
#define uld unsigned long double
#define pll pair<long long,long long>
#define tll(n) array<long long,(int)(n)>
#define pcc pair<char,char>
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<pair<long long,long long>>
#define vt(n) vector<array<long long,(int)(n)>>
#define umap unordered_map
#define uset unordered_set
#define Lqueue priority_queue<long long>
#define Squeue priority_queue<long long,vector<long long>,greater<long long>>
#define Fi first
#define Se second
#define mp make_pair
#define eb emplace_back

//マクロ
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rbf(a,x) for(auto& a:x)
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s);i<(long long)(n);i++)
#define bitrep(i,s,n) for(long long i=(s);i<(1LL<<(n));i++)
#define Maxe(x) *max_element((x).begin(),(x).end())
#define Mine(x) *min_element((x).begin(),(x).end())
#define Size(x) ((long long)(x).size())
#define lin(s) getline(cin,(s))
#define Ssort(v) sort((v).begin(),(v).end(),[](auto &left,auto &right){return left.second<right.second;})

//Yes,No
void Yes(bool a){cout<<(a?"Yes":"No")<<endl;}
//YES.NO
void YES(bool a){cout<<(a?"YES":"NO")<<endl;}

//MAX,MIN
template<class T,class U> auto max(T a,U b){return a>b?a:b;}
template<class T,class U> auto min(T a,U b){return a<b?a:b;}

//最大公約数,最小公倍数
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a,long long b){return a/gcd(a,b)*b;}

//累乗
template<typename t>
constexpr t mypow(t a,long long b){
    if(b==0)return 1;
    if(a==0)return 0;
    t x=1;
    while(b>0){
        if(b&1LL)x*=a;
        a*=a;
        b>>=1LL;
        }
    return x;
}
#define pow mypow

//chmin,chmax
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}

//組み合わせ O(r)
template<typename t>
constexpr t nCr(t n,long long r){
    if(r==0)return 1;
    if(n==0)return 0;
    if(n<r)return 0;
    t x=1;
    for(long long i=1;i<=r;i++){
        x*=n-i+1;
        x/=i;
    }
    return x;
}

//main関数
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll a,b,c;
    cin>>a>>b>>c;
    ll n=0;
    rep(i,100000000){
        n+=a;
        n%=b;
        if(n==c){
            YES(true);
            return 0;
        }
    }
    YES(false);
}

Measured memory_bytes: 3652
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var chars = Console.ReadLine().ToList();

        Stack<char> stack = new Stack<char>();

        foreach (char c in chars)
        {
            if (stack.Count == 0)
            {
                stack.Push(c);
            }
            else
            {
                char top = stack.Peek();
                if (top == 'T' || c == 'S')
                {
                    stack.Push(c);
                }
                else
                {
                    stack.Pop();
                }
            }
        }

        Console.WriteLine(stack.Count);
    }
}


Measured memory_bytes: 15968
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  int x, y, z;
  cin >> x >> y >> z;
  int a = x;
  int b = y;
  int c = z;
  swap(a, b);
  swap(a, c);

  cout << a << " " << b << " " << c << ln;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define N 36


typedef struct  {
  char c;
  int value;
} data;


void selectionsort(data *,int);
void bubblesort(data *,int);
void swap(data *,data *);


int main(){
  data a[N];
  data b[N];
  char c[2];
  int i,j,n,flag=0;
  
  
  scanf("%d",&n);
  for(i=0;i<n;i++){   
    scanf("%s",c);
    a[i].c=c[0];
    a[i].value=atoi(&c[1]);
    b[i].c=a[i].c;
    b[i].value=a[i].value;
  }
  
  bubblesort(a,n);  
  selectionsort(b,n);
  
  for(i=0;i<n;i++){
    printf("%c%d",a[i].c,a[i].value);
    if(i<n-1)printf(" ");
  }

  printf("\nStable\n");
    
  for(i=0;i<n;i++){
    printf("%c%d",b[i].c,b[i].value);
    if(i<n-1)printf(" ");
  }
  for(i=0;i<n;i++){
    if(a[i].c==b[i].c && a[i].value==b[i].value);
    else flag++;
  }
  if(flag)printf("\nNot stable\n");
  else printf("\nStable\n");

  return 0;
}
void selectionsort(data b[],int n){
  int i,j,min;
  
  for(i=0;i<n;i++){
    min=i;
    for(j=i;j<n;j++){
      if(b[j].value<b[min].value){
	min=j;
      }
    }
    if(i!=min){
      swap(&b[i],&b[min]);

      }
  }
  
}
void bubblesort(data a[],int n)
{
  int i,j;

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

    for(j=n-1;j>i;j--){
      if(a[j].value<a[j-1].value){
	swap(&a[j],&a[j-1]);
      }
    }
  }

}

void swap(data *p,data *q)
{
  data tmp;

  tmp=*p;
  *p=*q;
  *q=tmp;
  
}






Measured memory_bytes: 2048
#include<stdio.h>

#define TRUSS_MAX 1000

#define DIFF_CH_TO_INT 48

#define RESET 0

#define COUNT_RESET 0

#define LOOP 1

#define LOOP_END 0

#define RETURN 0

int main(){

        unsigned char ubW_D_num[TRUSS_MAX];        /* 数字の配列 */

        unsigned short usW_D_ans;             /* 答案用変数 */

        unsigned short usW_C_i;               /* ループ変数 */

        

        /* 無限ループ */

        while(LOOP){

                /* 答案の初期化 */

                usW_D_ans = RESET;

                /* 配列の初期化 */

                for(usW_C_i = COUNT_RESET;usW_C_i < TRUSS_MAX;usW_C_i++){

                        ubW_D_num[usW_C_i] = RESET;

                }

                

                /* 数字の入力 */

                scanf("%s", &ubW_D_num);

                

                /* 各桁の和の計算 */

                for(usW_C_i = COUNT_RESET;ubW_D_num[usW_C_i] != LOOP_END;usW_C_i++){

                        usW_D_ans += ubW_D_num[usW_C_i] - DIFF_CH_TO_INT;

                }

                

                /* 終了処理 */

                if(usW_D_ans == LOOP_END){

                        break;

                }

                

                /* 和の出力 */

                printf("%d\n", usW_D_ans);

        }

        return RETURN;

}




Measured memory_bytes: 2056
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a);i<(b);++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
#define INF 1000000000000000
#define MOD 1000000007
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a : A) cin >> a;} 

struct edge {int to, cost;};
template <typename T>bool chmin(T &a, const T& b) {if (a > b) {a = b; return true;} return false;}


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

int n, m, s, t; cin >> n >> m >> s >> t;
vector<vector<edge>> Gy(n+1), Gs(n+1); // yen と suuke それぞれで最短経路求める。
rep(i, 0, m){
    int u, v, a, b; cin >> u >> v >> a >> b;
    Gy[u].push_back(edge{v, a});
    Gy[v].push_back(edge{u, a});
    Gs[u].push_back(edge{v, b});
    Gs[v].push_back(edge{u, b});
}
VI dy(n+1, INF), ds(n+1, INF); 
dy[s] = ds[t] = 0;

priority_queue<PII, VP, greater<PII>> q; 
// yen での最短経路
q.emplace(0, s);
while(!q.empty()){
    PII p = q.top(); q.pop();
    int v = p.second;
    if (dy[v] < p.first) continue; 
    for (edge e: Gy[v])
        if (chmin(dy[e.to], dy[v] + e.cost))
            q.emplace(dy[e.to], e.to);
}
// snuuke での最短経路
q.emplace(0, t);
while(!q.empty()){
    PII p = q.top(); q.pop();
    int v = p.second;
    if (ds[v] < p.first) continue; 
    for (edge e: Gs[v])
        if (chmin(ds[e.to], ds[v] + e.cost))
            q.emplace(ds[e.to], e.to);
}
rep(i, 1, n+1) ds[i] += dy[i];
VI minid = ds; 
Rrep(i, n-1, 1) minid[i] = min(ds[i], minid[i+1]);
i64 snu = 1e15;
rep(i, 1, n+1){
    cout << snu - minid[i] << "\n";
}


return 0;
}
// 書いて考える．場合分け．情報整理．
// 単純に分かる量から．愚直解を実装して研究．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP(小さい問題から大きな問題)
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性→二分探索
// 存在判定：構成方法，入力の特徴
// 構築問題。極端解を試す。
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// コーナーケース。境界値。
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 16756
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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 T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

int a, b, c;
int main() {
  cin >> a >> b >> c;
  int res = a*100 + b*10 + c;
  if (res % 4 == 0) puts("YES");
  else puts("NO");
}

















Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int p[55];
int ans=0;
int main()
{   
    int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>p[i];
		if(p[i]!=i)
		  ans++;
	}
	if(ans>2)
	  cout<<"NO";
	else
	  cout<<"YES";
	return 0;
}

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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}


// 最大公約数
ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

void solve()
{
  // ll N; cin >> N;
  ll N, K; cin >> N >> K;
  // ll x, y, z; cin >> x >> y >> z;
  // ll a, b, c; cin >> a >> b >> c;
  // string s; cin >> s;
  vector<ll> x(N), y(N); rep(i, N) cin >> x[i] >> y[i];
  
  ll ans = 0;

  rep(i, N) {
    if(x[i]*x[i]+y[i]*y[i] <= K*K) ans++;
  }

  cout << ans << endl;
  // cout << (ok?"Yes":"No") << endl;
}


int main(void)
{
  // ll t; cin >> t; rep(i, t)
  solve();
}


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

int K;

int main() {
    cin >> K;
    
    if (K == 1) {
        cout << 1 << endl << 1 << endl;
        return 0;
    }
    
    int n = (K + 3) / 4 * 2;
    cout << n << endl;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            int x = (i + j) % n;
            if (i % 2 && x % n < K - n) {
                x += n;
            }
            cout << x + 1 << " ";
        }
        cout << endl;
    }
}

Measured memory_bytes: 1152
s_ = list(str(input()))
t = list(str(input()))

n = len(s_)
m = len(t)

if m > n:
    print('UNRESTORABLE')
    exit()

import copy
ans = []
for i in range(n-m+1):
    if s_[i] == t[0] or s_[i] == '?':
        temp = copy.copy(s_)
        for j in range(i, i+m):
            #print(i, temp)
            if s_[j] == '?':
                temp[j] = t[j-i]
            elif s_[j] == t[j-i]:
                continue
            else:
                break
        else:
            for k in range(n):
                if temp[k] == '?':
                    temp[k] = 'a'
            ans.append(''.join(temp))
if ans:
    ans.sort()
    print(ans[0])
else:
    print('UNRESTORABLE')


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


int main() {
    int n; cin >> n;
    ll x=0;
    vector<int> c(3,0);
    rep(i,n){
        cin >> x;
        if(x%4==0) c[0]++;
        else if(x%2==0) c[1]++;
        else c[2]++;
    }
    if(c[2]==0){
        cout << "Yes" << endl;
        return 0;
    }
    if(c[0]>0) c[0]++;
    if(c[1]!=0) c[0]--;
    if(c[0]<c[2]){
        cout << "No" << endl;
    }
    else cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
using namespace std;
typedef long long int ll;
#define pb push_back
#define F first
#define S second
#define mkp make_pair
#define pow2(i) (1 << (i))
#define modi(a,b) ((a%b+b)%b)
#define uni(a,b) (((a+b)*(a+b+1)/2)+b)
const int MAXN=1e9+7;
ll int_pow(ll base, ll exp){
	ll result=1;
	while (exp){
		if (exp & 1)
		   result *= base;
		exp/=2;
		base*=base;
	}
	return result;
}
ll a[1000000];
ll lookup[1000000][25];
void preprocess(ll n)
{
	for (ll i = 0; i < n; i++)
		lookup[i][0] = i;
 
	for (ll j=1; (1<<j)<=n; j++)
	{
		for (ll i=0; (i+(1<<j)-1) < n; i++)
		{ 
			if (a[lookup[i][j-1]] < a[lookup[i + (1<<(j-1))][j-1]])
				lookup[i][j] = lookup[i][j-1];
			else
				lookup[i][j] = lookup[i + (1 << (j-1))][j-1];      
		}
	}
}
ll query(ll L, ll R)
{
	ll j = (ll)log2(R-L+1);
	if (a[lookup[L][j]] <= a[lookup[R-(ll)pow(2,j)+1][j]])
		return lookup[L][j];
 
   else return lookup[R-(ll)pow(2,j)+1][j];
}
ll solve(ll i ,ll j){
	if (i>j)return 0;
	if (i==j)return a[i];
	ll d = query(i,j);
	return a[d]*(d-i+1)*(j-d+1)+solve(i, d-1)+solve(d+1, j);
}
int main() {
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll n;cin >> n;
	for (ll i=1;i<=n;i++)cin >> a[i];
	preprocess(n+1);
	cout << solve(1, n);
}

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

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

    int n, k;
    cin >> n >> k;
    vector<ll> a(n + 1, 0), sum(n + 1, 0);
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        sum[i] = sum[i - 1] + a[i];
    }
    vector<ll> v;
    for (int i = 1; i <= n; i++)
    {
        for (int j = i; j <= n; j++)
        {
            v.push_back(sum[j] - sum[i-1]);
        }
    }
    sort(v.begin(), v.end());
    ll res = 0;
    for (int i = 40; i >= 0; i--)
    {
        vector<ll> tmp;
        int cnt = 0;
        for (int j = 0; j < (int)v.size(); j++)
        {
            if (v[j] & 1LL << i)
            {
                cnt++;
                tmp.push_back(v[j]);
            }
        }
        if (cnt < k)
        {
            continue;
        }
        res += 1LL << i;
        v.clear();
        v = tmp;
    }
    cout << res << endl;
}


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

int main() {
	ios_base::sync_with_stdio( false );

	string s;
	cin >> s;

	int result = INT_MAX;

	for( char ch = 'a'; ch <= 'z'; ++ch ) {
		string t = s;
		int op = 0;

		for( ;; ) {
			if( count( t.begin(), t.end(), ch ) == t.size() ) {
				break;
			}

			string u( t.size()-1, ' ' );

			for( int i = 0; i < u.size(); ++i ) {
				if( t[i] == ch || t[i+1] == ch ) {
					u[i] = ch;
				}
			}

			t = u;
			op += 1;
		}

		if( op < result ) {
			result = op;
		}
	}

	cout << result << endl;

	return 0;
}


Measured memory_bytes: 256