akhauriyash/Code-Regression huggingface dataset:
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define divup(a,b) ( ( (a) + ( (b) - 1u) ) / (b) ) // a/b の余り切り上げ
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
ll mod = 1000000007;

signed main(){
    ll n;
    ll mi=mod,ans=0;
    ll p[200009];
    cin>>n;
    rep(i,n) {
        cin>>p[i];
        mi = min(mi,p[i]);
        if(mi==p[i]) ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1792
from itertools import product

n, m = map(int, input().split())
ks = []
for i in range(m):
    k, *arg = map(int, input().split())
    ks.append((k, arg))
p = list(map(int, input().split()))

res = 0
for pattern in product((0, 1), repeat=n):
    for i in range(m):
        cnt = 0
        k, s = ks[i]
        for j in range(k):
            cnt += pattern[s[j] - 1]
        if cnt % 2 != p[i]:
            break
    else:
        res += 1

print(res)

Measured memory_bytes: 3064
n,m,c = map(int,input().split())
b = map(int,input().split())
b = list(b)
count = 0
for i in range(n):
    sum = 0
    a = map(int, input().split())
    a = list(a)
    for j in range(m):
        sum += a[j] * b[j]
    sum += c
    if sum > 0:
        count += 1
print(count)

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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
typedef double ld;

template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7ll;
const double PI=3.14159265358979323846;


int main() {
    int n, k;
    cin >> n >> k;
    k--;
    string s;
    cin >> s;
    if(s[k] == 'A') s[k] = 'a';
    if(s[k] == 'B') s[k] = 'b';
    if(s[k] == 'C') s[k] = 'c';
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
int main()
{
   ll n,q1;
   cin>>n>>q1;
   vector<vector<ll>>adj(n+1);
   for(ll i=1;i<n;i++)
   {
       ll a,b;
       cin>>a>>b;
       adj[a].pb(b);
       adj[b].pb(a);
   }
   vector<ll>vv(n+1,0),v1(n+1,0);
   for(ll i=0;i<q1;i++)
   {
       ll x,y;
       cin>>x>>y;
       vv[x]+=y;
   }
   ll z=0;
   bool vis[n+1]={0};
   queue<ll>q;
   q.push(1);
   vis[1]=1;
   while(!q.empty())
   {
       ll p=q.front();
       q.pop();
       //z=vv[p];
       //v1[p]+=vv[p];
       //z+=v1[p];
       for(auto u:adj[p])
       {
           if(!vis[u])
           {
               q.push(u);
               vv[u]+=vv[p];
               vis[u]=1;
           }
       }
   }
   for(ll i=1;i<=n;i++)
   cout<<vv[i]<<" ";

}


Measured memory_bytes: 19696
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
ll w[200500], n, m, v, p;
bool check(int d)
{
	if(d>=n-p) return true;
	int lim=w[d]+m;
	ll zan=m*(v-p);
	int cnt=0;
	for(int i=0;i+p<=n;i++)
	{
		if(i==d) continue;
		ll c=min(m,lim-w[i]);
		if(c<0) return false;
		zan-=c;
	}
	return zan<=0;
}
int main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>m>>v>>p;
	for(int i = 0; i < n; i++) cin>>w[i];
	sort(w, w+n);
	ll cnt = 0, l = -1, r = n;
	while(r-l > 1)
	{
		int mid = (l+r)/2;
		if (check(mid)) r = mid;
		else l = mid;
	}
	cout<<n-r;
	return 0;
}


Measured memory_bytes: 1024
package main

import (
  "bufio"
  "fmt"
  "os"
)

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

func main() {
  defer writer.Flush()

  var s string
  scanf("%s\n", &s)
  m := map[string]int{
    "SUN": 7,
    "MON": 6,
    "TUE": 5,
    "WED": 4,
    "THU": 3,
    "FRI": 2,
    "SAT": 1,
  }

  printf("%d\n", m[s])
}


Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define POW(n) ((n) * (n))
#define ALL(a) (a).begin(), (a).end()
#define dump(v) (cerr << #v << ": " << v << endl)
#define cerr                                                                   \
  if (true)                                                                    \
  cerr

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<unsigned long long> vull;

// ll n = to_T<ll>("114514")
template <class T> T to_T(const string &s) {
  istringstream is(s);
  T res;
  is >> res;
  return res;
}
template <class T> string to_s(const T &a) {
  ostringstream os;
  os << a;
  return os.str();
}

void solve(string s) {
  cout << s[0];
  cout << (s.size() - 2);
  cout << s[s.size() - 1] << endl;
}

int main() {
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  solve(s);
  return 0;
}


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

int vct(char a) {
	if (a == 'U')return 2;
	else if (a == 'L')return 1;
	else if (a == 'R')return 3;
	else if (a == 'D')return 4;
	else return 0;
}

int main() {
	string s;
	cin >> s;
	string tc = "akstnhmyrw";
	string fl = "aiueo";

	string ans="";

	for (int i = 0;i < s.size();i++) {
		if (i % 2 == 0) {
			int a = s[i] - '0';
			a = (a + 9) % 10;
			
			if (a != 0)ans.push_back(tc[a]);
			if (a == 9 && s[i + 1] == 'U') {
				ans.pop_back();
				ans.push_back('n');
			}
		}
		else {
			int a = s[i - 1] - '0';
			a = (a + 9) % 10;

			if (a == 9 && s[i] == 'U') {
				ans.push_back('n');
			}
			else ans.push_back(fl[vct(s[i])]);
		}
	}
	cout << ans << endl;
	getchar();
	getchar();
	return 0;
}

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

int main() {
  int n, d;
  cin >> n >> d;
  int p = 2*d + 1;
  cout << (n + (p - 1)) / p << endl;
}

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

#include <bits/stdc++.h>
#include <sys/resource.h>

#define FOR(i,s,e) for(int i=(s);i<(int)(e);i++)
#define FOE(i,s,e) for(int i=(s);i<=(int)(e);i++)
#define REP(i,n)   FOR(i,0,n)
#define ALL(x) (x).begin(), (x).end()
#define CLR(s) memset(s,0,sizeof(s))
#define PB push_back
#define ITER(v)      __typeof((v).begin())
#define FOREACH(i,v) for(ITER(v) i=(v).begin();i!=(v).end();i++)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef map<int,int> mii;
typedef vector<int> vi;
#define x first
#define y second


void set_stack_size() {
    const rlim_t kStackSize = 256 * 1024 * 1024;   // min stack size = 256 MB
    struct rlimit rl;
    int result;

    result = getrlimit(RLIMIT_STACK, &rl);
    if (result == 0)
    {
        if (rl.rlim_cur < kStackSize)
        {
            rl.rlim_cur = kStackSize;
            result = setrlimit(RLIMIT_STACK, &rl);
            if (result != 0)
            {
                fprintf(stderr, "setrlimit returned result = %d\n", result);
            }
        }
    }
}


int n, k;
vector<vector<int>> adj;
vector<int> child;
vector<LL> fact, inv_fact;

const LL MOD = 1000000007;


LL mod_pow(LL x, LL n) {
    if (n == 0) return 1LL;
    LL half = mod_pow(x, n / 2), ret = half * half % MOD;
    if (n % 2) ret = ret * x % MOD;
    return ret;
}


void init() {
    int n = 100000 + 2036;
    fact.resize(n + 1);
    inv_fact.resize(n + 1);

    fact[0] = 1;
    FOE(i, 1, n) fact[i] = fact[i - 1] * i % MOD;
    FOE(i, 0, n) inv_fact[i] = mod_pow(fact[i], MOD - 2);
}


LL npr(LL n, LL r) {
    if (n < r) return 0LL;
    return fact[n] * inv_fact[n - r] % MOD;
}


LL go(LL x, LL parent) {
    LL ans = 1LL;
    for (auto &y: adj[x]) {
        if (y != parent) {
            ans = ans * go(y, x) % MOD;
            ++child[x];
        }
    }
    auto choice = k - 1 - (parent != 0);
    auto mul = npr(choice, child[x]);
    ans = ans * mul % MOD;
    return ans;
}


int main() {
    set_stack_size();

    init();

    while (scanf("%d%d", &n, &k) != EOF) {
        adj.clear();
        adj.resize(n + 1, vector<int>());
        FOR(_, 0, n - 1) {
            int x, y; scanf("%d%d", &x, &y);
            adj[x].PB(y);
            adj[y].PB(x);
        }

        child.clear();
        child.resize(n + 1, 0);

        LL ans = go(1, 0) * k % MOD;
        printf("%lld\n", ans);
    }
    return 0;
}


Measured memory_bytes: 12416
#include <stdio.h>

int gcd(int a, int b) {
  int t;
  while( b ) {
    t = a % b;
    a = b;
    b = t;
  }
  return a;
}

int main(void) {
  int i, j, n;
  scanf("%d", &n);
  int a, t, count = 0;
  for(i = 0; i < n; ++i) {
    scanf("%d", &a);
    if(!i) t = a;
    else t = gcd(a, t);
  }
  while(!(t % 2)) count++, t /= 2;
  printf("%d", count);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll ;
typedef double db;
const double pi = acos(-1) ;
#define pb         push_back
#define forab(i,a,b)       for(int i=(a);i<=(b);i++)
#define CIN	ios_base::sync_with_stdio(0); cin.tie(0)
#define pcase(z,x)     printf("Case %ld: %lld\n",z,x)
#define nw				"\n"


int main(void)
{
	CIN;
	ll tc,l,k,sum=0,x=0,y,z=0,m=1,n=0,ans=0;
	cin>>n;
	int arr[n];
	tc=n;
	while(tc--)
	{
		cin>>arr[x];
		sum+=arr[x++];
	}
	x=sum/n;
	for(ll i=0;i<n;i++)
	{
		z+=abs(arr[i]-x)*abs(arr[i]-x);
	}
	x++;
	for(ll i=0;i<n;i++)
	{
		ans+=abs(arr[i]-x)*abs(arr[i]-x);
	}
	ans=min(ans,z);
	cout<<ans;
}


Measured memory_bytes: 3596
#include<cstdio>

#define ran 202202

int n;
int a[ran];

int main() {
	scanf("%d", &n);
	int ma1 = -1, ma2 = -1;
	for(int i=0;i<n;i++) {
		scanf("%d", &a[i]);
		if (a[i]>=ma1) {
			ma2 = ma1; ma1 = a[i];
		} else
		if (a[i]>=ma2) ma2 = a[i];
	}
	for(int i=0;i<n;i++)
		if(a[i]==ma1) printf("%d\n", ma2);
		else printf("%d\n", ma1);
	
	return 0;
}

Measured memory_bytes: 2304
use std::io::{stdin, Read};

#[allow(unused_macros)]
macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
}

#[allow(unused_macros)]
macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: ty),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    parse!(it, q: usize);
    for i in 0..q {
        parse!(it, a: usize, b: usize);
        let (a, b) = if a < b { (a, b) } else { (b, a) };
        let mut ret = a - 1;
        let s = a * b;
        if a == b {
            ret += b - 1;
        } else {
            let mut ok = 0;
            let mut ng = b;
            while ng - ok > 1 {
                let m = (ok + ng) / 2;
                let t = a + 1 + m;
                if (t / 2) * (t - t / 2) < s {
                    ok = m;
                } else {
                    ng = m;
                }
            }
            ret += ok;
        }
        println!("{}", ret);
    }
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,s,n) for(int i = s; i < n; i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using Graph = vector<vector<pair<int,int>>>;
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll ok = 1;
void f(int k,int a,int b, int c,int n){
  if(b > a && c > b){
    ok = 0;
    return;
  }
  if(k == n){
    return;
  }

  f(k + 1,a * 2,b,c,n);
  f(k + 1,a,b * 2,c,n);
  f(k + 1,a,b,c * 2,n);
  return;
}
int main(){
  int a,b,c,k;
  cin >> a >> b >> c >> k;
  f(0,a,b,c,k);
  if(ok)cout << "No" << endl;
  else cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 3628
#include <stdio.h>

using namespace std;

int main() {
    int W, H, x, y, r;
    scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
    if((x >= r && x <= W-r) && (y >= r && y <= H-r)) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
}



Measured memory_bytes: 2684
#pragma GCC optimize ("O3")
#include<bits/stdc++.h>
#include <queue>
#include <cstring>

#define pb push_back
#define p push

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ll long long

#define getI(a) scanf("%d",&a)
#define getII(a, b) scanf("%d%d",&a,&b)
#define getIII(a, b, c) scanf("%d%d%d",&a,&b,&c)
#define getL(a) scanf("%lld",&a)
#define getLL(a, b) scanf("%lld%lld",&a,&b)
#define getLLL(a, b, c) scanf("%lld%lld%lld",&a,&b,&c)
#define BEND(c) (c).begin(),(c).end()
#define BEND2(c) (c).rbegin(),(c).rend()
#define fi first
#define se second
#define pi 3.1415926535897932384626
#define getS(a) scanf("%s",a)
#define pfb(a) printf("%.10lf\n",a);
#define pfi(a) printf("%d",a);
#define pfii(a, b) printf("%d%d",a,b);
#define pfl(a) printf("%lld",a);
#define pfll(a, b) printf("%lld%lld",a,b);
#define pfd(a) printf("%.12lf\n",a);
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);
#define endl "\n"

#define SIZE  ( int)(1e9 + 7)
#define MAXN (ll) ((1e6+5))
#define K 25
#define  ALPHABET_SIZE  26
//#define N (int)(1e5+10)
#define sag (sol|1)
#define sol (root<<1)
#define ort (bas+son)/2
#define INF (ll )1e18
#define int ll
using namespace std;

typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<pair<int,int>>> vvpi;
typedef vector<long long> vl;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int, int> pii;
typedef pair <ll, ll> pll;
typedef vector<vi> graph ;


signed main ( ) {
    IOS
    ll n , r ;
    cin >> n ;
    vi vec( n + 1);
    ll sum = 0 ;
    for (int i = 1; i <=n ; ++i) {
        cin >> vec [ i];
        sum += vec[i];
    }
    ll c = 0;
    ll k = sum % n;
    ll t = sum / n ;
    if(k > n/2)c=1;
    t += c;
    ll res= 0 ;
    //cout << sum << " " << k << " "<< t << endl;
    for (int j = 1; j <= n ; ++j) {

        res+= ((t - vec[j]) * (t - vec[j]));
    }
    cout << res;
    return 0;
}



















Measured memory_bytes: 256
import java.util.*;
import java.math.*;
public class Main {
	public static void main(String[] args){
		
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		
		long[] num = new long[10000002];
		
		for (int i = 0; i<num.length;i++)
		{num[i]=0;}
	
		for (int i = 1; i<num.length;i++)
		{
			int i2 = i;
			while(i2 < 10000001)
			{
				num[i2]++;
				i2 += i;	
			}
		}
		
		long ans = 0;
		
		for (int i = 1; i < (N+1) ;i++)
		{
          long temp = i*num[i];
			ans += temp;
			}
		System.out.println(ans);
   
        }
		
	}

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

void solve(){
    ll n; cin >> n;
    vector<ll> A(n);
    REP(i, n) cin >> A[i];

    vector<ll> ans;
    ll ans1 = 0;

    REP(i, n){
        if(i%2==0){
            ans1 += A[i];
        }
        else{
            ans1 -= A[i];
        }
    }
    ans.pb(ans1);

    for(int i=0; i<n-2; i++){
        ll ansi = 2*A[i] - ans[i];
        ans.pb(ansi);
    }
    ll ansn = 2*A[n-1] - ans1;
    ans.pb(ansn);

    REP(i, ans.size()){
        cout << ans[i];
        if(i!=ans.size()-1) cout << " ";
        else cout << "\n";
    }

}

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

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int n;
  R n;
  map<int,int> m;
  rep(i,n) {
    int x;
    R x;
    m[x]++;
  }
  int ans=0;
  tr(it,m) {
    int x=it->F,y=it->S;
    if(y<x) ans+=y;
    else ans+=y-x;
  }
  pr(ans);
}

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


Measured memory_bytes: 4736
b=[]
c=[]
d=[]
s=[]
for i in range(3):
    a=list(map(int,input().split()))


    b.append(a)

    s.append(a)
p=[]
q=[]
for i in range(3):
    r=[]

    for j in range(3):
        r.append(b[j][i])
        if i==j:
            p.append(b[i][j])
        if i+j==2:
            q.append(b[i][j])

    r.sort()

    c.append(r)

d.append(p)
d.append(q)

l=0
n=int(input())

for k in range(n):
    m=int(input())
    for i in range(3):
        for j in range(3):
            if s[i][j] == m:
                s[i][j] = 0
            if c[i][j] == m:
                c[i][j] = 0
        if sum(s[i]) == 0:
            l += 1

        if sum(c[i]) == 0:
            l += 1

    for i in range(2):
        for j in range(3):
            if d[i][j] == m:
                d[i][j] = 0
        if sum(d[i]) == 0:
            l += 1

if l > 0:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
long long n,a,b,yu,z,zs;
int main()
{
	cin>>n>>a>>b;
	for(int i=1;i<=n;i++)
	{
		yu=0;
		z=i;
		for(;z>0;z/=10)
		yu+=z%10;
		if(a<=yu&&yu<=b)
		zs+=i;
	}
	cout<<zs<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
using ll = long long;
using ld = long double;
#define vpl vector<pair<long long,long long>>
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
using pll = pair<long long,long long>;
#define cY cout<<"Yes"<<endl
#define cN cout<<"No"<<endl
const long long INF = 1LL << 60;
long long MOD = 1000000007;
const long double pi = 3.1415926535897932;
#define pb push_back
#define mp make_pair
#define mt make_tuple
//(mod m)でのaの逆元を計算する
//a/b(mod m)=a(mod m)*modinv(b,m)
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

//最大最小の入れ替え
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;
}

//約数列挙
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}
//コンビネーション
ll nCr(ll n, ll r) {
    ll ans = 1;
    for (ll i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (ll i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}
//素因数分解
map< ll, ll > prime_factor(ll n) {
  map< ll, ll > ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

//切り上げの割り算は(a + b - 1) / bでできる

//ここから
int main(){
    string S;
    cin>>S;
    ll N=S.size();
    vl Ans(N,0);
    {
        ll count=0;
        rep(i,N){
            if(S[i]=='R'){
                count++;
            }else{
                Ans[i]+=count/2;
                Ans[i-1]+=count-count/2;
                count=0;
            }
        }
        for(ll i=N-1;i>=0;i--){
            if(S[i]=='L'){
                count++;
            }else{
                Ans[i]+=count/2;
                Ans[i+1]+=count-count/2;
                count=0;
            }
        }
    }
    rep(i,N){
        cout<<Ans[i];
        if(i!=N-1)cout<<" ";
        else cout<<endl;
    }
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> sum(n, 0);
  vector<bool> check(n, false);
  int ok = 0, pena = 0;
  rep(i, m) {
    int p;
    string s;
    cin >> p >> s;
    p --;
    if (check[p]) {
      continue;
    } else {
      if (s == "AC") check[p] = true;
      else sum[p] ++;
    }
  }

  rep(i, n) {
    if (check[i]) {
      ok ++;
      pena += sum[i];
    }
  }

  cout << ok << " " << pena << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(s,e) for(ll i=s;i<e;i++ )
typedef pair<ll,ll> P;
const ll mod = 1e9+7;
const ll INF = 100000000000009;
ll i;

int main(){
    ll N;
    cin>>N;
    V A(N);
    rep(0,N)cin>>A.at(i);

    map<ll,ll> kazu;
    rep(0,N){
        if(kazu.count(A.at(i)))kazu[A.at(i)]++;
        else kazu[A.at(i)]=1;
    }
    ll ans=0;
    
        
    for(P x:kazu){
        ans+=x.second*(x.second-1)/2;
    }
    rep(0,N){
        cout<<ans-kazu[A.at(i)]*(kazu[A.at(i)]-1)/2+(kazu[A.at(i)]-2)*(kazu[A.at(i)]-1)/2<<endl;
    }
    

}


Measured memory_bytes: 11008
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <numeric>
#include <functional>
#include <array>
#include <map>
#include <set>

#define INF 1000000007 //1000000000000000003
#define MOD 1000000007
#define MAX 2000005

#define ll long long

//printf("%.10f", );
//cout << fixed << setprecision(10) << heikin << endl;
//vector<vector<int>> data(3, vector<int>(4, -1));
//left + 1 < top

using namespace std;
using P = pair<int, int>;
using Pc = pair<double, int>;
using T = tuple<int, int, int>;
using edge = struct { int to; long long dist; };
const double PI = 3.1415;
long long fact[MAX], inv[MAX];
int dx[] = { -1,0,1,0 };
int dy[] = { 0,-1,0,1 };

//////////////////////////////////

vector<vector<int>> bingo(3, vector<int>(3));
vector<vector<int>> tree(100005);
int color[100005];
map<P, int>colorMap;
int m = 0;

struct BridgeInfo {
	int town1;
	int town2;
	int year;
	BridgeInfo(int t1, int t2, int y) {
		town1 = t1;
		town2 = t2;
		year = y;
	}
};

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

struct UnionFind {
	vector<int>uf;

	UnionFind(int size) :uf(size, -1) {};

	int root(int target) {
		if (uf[target] < 0)return target;
		else return uf[target] = root(uf[target]);
	}

	void merge(int a, int b) {
		a = root(a);
		b = root(b);
		if (a == b)return;
		if (uf[b] < uf[a])swap(a, b);
		uf[a] += uf[b];
		uf[b] = a;
	}
};

ll CalcPow(ll num, ll power) {
	if (power == 0)return 1;
	if (power % 2 == 0) {
		ll half = CalcPow(num, power / 2);
		return (half * half) % MOD;
	}
	else return (num * CalcPow(num, power - 1)) % MOD;
}

ll combination(ll all, ll select) {
	if (all < select) return 0;
	if (all < 0 || select < 0) return 0;
	return fact[all] * (inv[select] * inv[all - select] % MOD) % MOD;
}

void initCombination(int max) {
	fact[0] = fact[1] = 1;
	for (int i = 2; i <= max; ++i) {
		fact[i] = fact[i - 1] * i % MOD;
	}

	inv[max] = CalcPow(fact[max], MOD - 2);
	for (int i = max - 1; 0 <= i; --i) {
		inv[i] = (inv[i + 1] * (i + 1)) % MOD;
	}
}

ll getGcd(ll a, ll b) {
	if (a < b) {
		ll temp = b;
		b = a;
		a = temp;
	}

	ll r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}

/*int getNum(ll target) {

	int bottom = 0;
	int top = 151;
	while (1 < top - bottom) {
		int middle = (top + bottom) / 2;
		if (target < line[middle])top = middle;
		else bottom = middle;
	}
	return bottom;
}*/

int main() {

	int K; cin >> K;
	string S; cin >> S;

	string ans = "";
	int index = S.size() <= K ? S.size() : K;
	for (int i = 0; i < index;++i) {
		ans += S[i];
	}
	if (K < S.size())ans += "...";

	cout << ans << endl;
}




Measured memory_bytes: 5420
n,x,m = list(map(int,input().split()))
import sys

a = [x]
while True:
  res = (a[-1]**2) % m
  if len(a) == n:
    print(sum(a))
    sys.exit()
  elif res == 0:
    print(sum(a))
    sys.exit()
  elif res in a:
    ai = a.index(res)
    aa = a[ai:]
    break
  else:
    a.append(res)

if len(a) >= n:
  print(sum(a[:n]) )
  sys.exit()

shuuki = len(aa)
shuuki_sum = sum(aa)

ans = sum(a) + shuuki_sum * ( (n-len(a)) // shuuki ) + sum( aa[:(n-len(a)) % shuuki] )
print(ans)


Measured memory_bytes: 68584
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define pb            push_back
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

// code
// ------------------------------------------------
int main() {
  int n;
  cin >> n;
  unsigned long long x,ans = 1;

  x = pow(10,9) + 7;

  for(int i = 1;i <= n;i++)
  {
    ans = ((ans * i) % x); 
  }

  cout << ans << endl;


  return 0;
}
// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int ans=0;

        end: {
            while(true) {
                int a = sc.nextInt();
                String op = sc.next();
                int b = sc.nextInt();

                switch (op) {
                    case "+": ans = a+b; break;
                    case "-": ans = a-b; break;
                    case "*": ans = a*b; break;
                    case "/": ans = a/b; break;
                    case "?": break end;
                }

                System.out.println(ans);
            }
        }
    }
}

Measured memory_bytes: 26304
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;

int main() {
	int n;
	cin >> n;
	int *f = new int[n + 1];
	for (int i = 0; i <= n; ++i) {
		f[i] = 0;
	}
	f[0] = 1;
	for (int i = 100; i <= n; ++i) {
		for (int j = i - 105; j <= i - 100; ++j) {
			if (j >= 0 && f[j]) {
				f[i] = 1;
			}
		}
	}
	cout << f[n] << endl;
	return 0;
}

Measured memory_bytes: 640
fun main(args:Array<String>) {
    val omoriCount = readLine()!!.toInt()
    val list = readLine()!!.split(" ").map { it.toInt() }
    val total = list.sum()

    var subTotal = 0
    var minDiff = total
    var ans = -1
    for(i in list.indices) {
        subTotal += list[i]
        if (minDiff > Math.abs(total-subTotal*2)) {
            ans = i+1
            minDiff = Math.abs(total - subTotal*2)
        }
    }
    println(minDiff)
}


Measured memory_bytes: 36080
def power_func(a,b,p):
  """a^b mod p を求める"""
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p
def cmb(n, k, p):
    a = 1
    b = 1
    for i in range(k):
        a *= n-i
        a %= p
        b *= i+1
        b %= p
    return a*power_func(b, p-2, p)%p

MOD = 1000000007
ans1 = 1
n, a, b = map(int, input().split())
ans = power_func(2, n, MOD)-1-cmb(n, a, MOD)-cmb(n, b, MOD)
if ans < 0:
    ans += MOD
if ans < 0:
    ans += MOD
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include <string>
using namespace std;

bool p[10001];
 
void seive(int s){
    for(int i=0;i<=s;i++)p[i]=true;
    p[0]=p[1]=false;
    for(int i=2;i<=s;i++){
        if(p[i]==true){
            for(int j=i*2;j<=s;j+=i)p[j]=false;
        }
    }
}
 
int main(){
   seive(10000);
   int n;
   while(cin>>n&&n){
       while(1){
           if(p[n]==true&&p[n-2]==true){
               cout<<n-2<<" "<<n<<endl;
               break;
           }
           n--;
       }
   }
    return 0;
}


Measured memory_bytes: 3080
// {{{
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
// }}}

using ll = long long;

ll K, A, B;

int main() {
    cin >> K >> A >> B;

    K -= min(K, A-1);

    if (B - A < 2) {
        cout << A + K << endl;
        return 0;
    }

    cout << (A + K / 2 * (B - A) + K % 2) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<set>
#include<stack>
#define pb push_back
#define sz size()
#define For(i,a) for(int i=0;i<(int)a;i++)
using namespace std;

typedef pair<int,int> P;

string grid[1100];
bool v[1100][1100];
int w,h,n;
stack<P> q;
set<P> s;

bool dfs(int y,int x){
  q.push(P(y,x));

  while(q.size()){
    int y = q.top().first, x = q.top().second;
    q.pop();
    
    if(grid[y][x] == 't')return true;
    
    v[y][x] = true;
    int dy[] = {-1,0,1,0},dx[] = {0,1,0,-1};
    
    For(i,4){
      int sy = y + dy[i] , sx = x + dx[i];
      if(sy<0 || sx<0 || h<=sy || w<=sx || v[sy][sx])continue;
      if(grid[sy][sx] == '#'){
	s.insert(P(sy,sx));
	continue;
      }
      q.push(P(sy,sx));
    }
  }
  return false;
}

int main(){
  int x,y;
  cin >> w >> h;

  For(i,h)cin >> grid[i];
  For(i,h)For(j,w)v[i][j] = false;

  while(q.sz)q.pop();
  s.clear();

  if(dfs(0,0))cout << 0 << endl;
  else{
    cin >> n;
    For(i,n){
      cin >> x >> y;
      if(grid[y][x]=='#'){
	grid[y][x] = '.';

	int s1 = s.sz;
	s.insert(P(y,x));
	int s2 = s.sz;
	s.erase(P(y,x));
	if(s1==s2){
	  if(dfs(y,x)){
	    cout << i+1 << endl;
	    return 0;
	  }
	}
      }
    }
    cout << -1 << endl;
  }
}

Measured memory_bytes: 9844
n = int(input())
s = input()

mozi = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]

for x in s:
  number = mozi.index(x) + n
  if number > 25:
    number = number - 26
  print(mozi[number], end="")
  

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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

const int dx[4] = {+1, 0, -1, 0};
const int dy[4] = {0, -1, 0, +1};

string s;

vector<int> z_algorithm(const string &s) {
    vector<int> prefix(s.size());
    for(int i = 1, j = 0; i < s.size(); i++) {
        if(i + prefix[i - j] < j + prefix[j]) {
            prefix[i] = prefix[i - j];
        } else {
            int k = max(0, j + prefix[j] - i);
            while(i + k < s.size() && s[k] == s[i + k]) ++k;
            prefix[i] = k;
            j = i;
        }
    }
    prefix[0] = (int) s.size();
    return prefix;
}

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n; cin >> n;
    cin >> s;
    int ans = 0;
    for(int i=0;i<n;i++){
        vector<int> prefix = z_algorithm(s.substr(i, n-i));
        for(int j=0;j<n-i;j++){
            ans = max(min(prefix[j], j), ans);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
inline 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 << 3) + (x << 1) + (ch ^ 48); ch = getchar();}
	return x * f;
}
const int N = 3e5 + 5;
int n;
int W , B;
int a[N] , sum[N];
inline bool check(int mid)
{
	int minn = 0;
	for(int i = 2;i < n;i += 2) if(sum[i - 1] - minn >= mid) minn = min(minn,sum[i]);
	return sum[n] - minn >= mid;
}
int main()
{
	n = read();
	for(int i = 1;i <= n;i ++)
	{
		a[i] = read(); sum[i] = sum[i - 1];
		if(i & 1) B += a[i] , sum[i] += a[i];
		else W += a[i] , sum[i] -= a[i];
	}
	if(!(n & 1)) printf("%d %d\n",max(B,W),min(B,W));
	else
	{
		int l = -3e8 , r = 3e8 , ans = 0;
		while(l <= r)
		{
			int mid = (l + r) >> 1;
			if(check(mid)) ans = mid , l = mid + 1;
			else r = mid - 1;
		}
		int res = max(W + ans,B);
		printf("%d %d\n",res,W + B - res);
	}
	return 0;
}

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

#if defined(DEBUG)

#include <unistd.h>
#include <sys/fcntl.h>
#define DLOG(...)        cerr << dbgFormat(__VA_ARGS__) << endl
#define DCALL(func, ...) func(__VA_ARGS__)

template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

#else  // defined(DEBUG)

#define DLOG(...)
#define DCALL(func, ...)

#endif // defined(DEBUG)

int main(int argc, char *argv[]) {
#if defined(DEBUG)
  // GDB on Cygwin ignores redirection at run command.
  if (argc == 2) dup2(open(argv[1], 0), 0);
#else
  // For performance.  We should not use C-style stdio functions
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
#endif
  cout << setprecision(20);

  int a; cin >> a;
  string s; cin >> s;
  if (a >= 3200) {
    cout << s << endl;
  }else {
    cout << "red" << endl;
  }
  return 0;
}



Measured memory_bytes: 256
n = int(input())
A = [int(s) for s in input().split()]
print(' '.join(map(str, 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 -= 1
    A[j+1] = v
    print(' '.join(map(str, A)))


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

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

    vector<int> A(2 * N);
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        A[N + i] = K + A[i];
    }

    int ans = INT_MAX;
    for (int i = 1; i + N - 1 < A.size(); i++)
    {
        ans = min(ans, A[i + N - 1] - A[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
ll M,K;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>M>>K;
	vector<ll> ans;
	if(K>=(1<<M)||(M==1&&K==1)){
		ans.push_back(-1);
	}else{
		if(M==1&&K==0){
			REP(i,2)REP(j,2)ans.push_back(i);
		}else{
			for(ll i=(1<<M)-1;i>=0;i--){
				if(i==K)continue;
				ans.push_back(i);
			}
			ans.push_back(K);
			REP(i,1<<M){
				if(i==K)continue;
				ans.push_back(i);
			}
			ans.push_back(K);
		}
	}
	REP(i,ans.size()){
		if(i)cout<<' ';
		cout<<ans[i];
	}
	cout<<endl;
}

Measured memory_bytes: 4080
n = int(input())

N = 10005
pre = [True] * N
pre[0], pre[1] = False, False
for i in range(2, N):
    if pre[i]:
        k = i * 2
        while k < N:
            pre[k] = False
            k += i

R = [i for i in range(1, N)]
preN = list(filter(lambda x: pre[x], R))

rec = []
for i in range(len(preN)):
    if preN[i] % 5 == 1:
        rec.append(preN[i])
    if len(rec) == n:
        break

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

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

int main(){
  string s1, s2;
  cin >> s1 >> s2;
  for(int i = 0;i < s1.size(); i ++){
    for(int j = 0; j < s1.size(); j++ ){
      if ( s1[j] != s2[ ( j + i ) % s1.size() ] ){
        break;
      }
      if ( j == s1.size() - 1 ){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
fn get_line() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn main() {
    let nums: Vec<f64> = get_line()
        .split_whitespace()
        .map(|n| n.parse().unwrap())
        .collect();
    let (x0, y0, x1, y1) = (nums[0], nums[1], nums[2], nums[3]);
    let distance = ((x0 - x1).powi(2) + (y0 - y1).powi(2)).sqrt();
    println!("{}",distance);
}



Measured memory_bytes: 5068
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;

int main()
{
    int64_t N;
    std::string S;
    std::cin >> N;
    std::cin >> S;

    std::vector<int64_t> toE;
    int64_t c = 0;
    for (int64_t i = 0; i < N; ++i) {
        if (S[i] == 'W') {
            c++;
        }
        toE.push_back(c);
    }

    std::vector<int64_t> toW;
    c = 0;
    for (int64_t i = N-1; i >= 0; --i) {
        if (S[i] == 'E') {
            c++;
        }
        toW.push_back(c);
    }
    std::reverse(toW.begin(), toW.end());


    int64_t ans = N-1;
    for (int64_t i = 0; i < N; ++i) {
        int64_t turnToE = 0;
        if (i > 0) {
            turnToE = toE[i-1];
        }

        int64_t turnToW = 0;
        if (i < N-1) {
            turnToW = toW[i+1];
        }
        ans = std::min(ans, turnToE + turnToW);
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 12532
// 参考
// https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// Input macro
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! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

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")
    };
}

// Test Code
macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r"atcoder beginner contest
" => r"ABC",

r"resident register number
" => r"RRN",

r"k nearest neighbor
" => r"KNN",

r"async layered coding
" => r"ALC"
}

use std::cmp;
use std::cmp::{max, min};
use std::collections::HashSet;
use std::f32::MAX;

fn main() {
    println!("{}", solve(&stdin!()));
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        a: String,
        b: String,
        c: String,
    }

    let s: String = vec![
        a.chars().nth(0).unwrap(),
        b.chars().nth(0).unwrap(),
        c.chars().nth(0).unwrap(),
    ]
    .into_iter()
    .collect();

    s.to_uppercase()
}


Measured memory_bytes: 4352
#include <stdio.h>

#define N 5
#define MINIMUM_SCORE 40

int main(void) {
  int sum = 0;
  int a = 0;

  for (int i = 0; i < N; i++) {
    scanf("%d", &a);

    if (a < MINIMUM_SCORE) {
      a = MINIMUM_SCORE;
    }

    sum += a;
  }

  int average = sum / N;
  printf("%d\n", average);

  return 0;
}

Measured memory_bytes: 1028
#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <bitset>
#include <vector>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
using namespace std;
typedef double db;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pa;
typedef unsigned int uint;
typedef unsigned long long ull;
#define w1 first
#define ls (x<<1)
#define w2 second
#define ins insert
#define rs (x<<1|1) 
#define mp make_pair
#define pb push_back
#define mid ((l+r)>>1)
#define sqr(x) ((x)*(x))
#define cle(x) ((x).clear())
#define lowbit(x) ((x)&(-x))
#define SZ(x) (int((x).size()))
#define All(x) (x).begin(),(x).end()
#define ms(x,y) memset(x,y,sizeof (x))
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep2(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define per(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
#define Rep(p,x) for(int (p)=head[(x)];(p);(p)=nxt[(p)]) 
#define Rep2(p,x) for(int (p)=cur[(x)];(p);(p)=nxt[(p)])
template<class T>inline void read(T&num){
	num=0;T f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar();
	num*=f;
}
inline int getgcd(int x,int y){if(!x)return y;return getgcd(y%x,x);}
inline int power(int x,int k,int p){int res=1;for(;k;k>>=1,x=(ll)x*x%p)if(k&1)res=(ll)res*x%p;return res;}
const double pi=acos(-1);	
inline void judge(){
	freopen("input.txt","r",stdin);
} 
//********************************head*************************************
const int maxn=305;
int n,m,ans;
int a[maxn][maxn],cnt[maxn],ban[maxn];
int main(){
	read(n);read(m);ans=n;
	rep(i,1,n)rep(j,1,m)read(a[i][j]);
	while(1){
		int bancnt=0;
		rep(i,1,m)if(ban[i])bancnt++;
		if(bancnt==m)break;
		rep(i,1,m)cnt[i]=0;
		rep(i,1,n)rep(j,1,m)if(!ban[a[i][j]]){
			cnt[a[i][j]]++;
			break;
		}
		int res=0;
		rep(i,1,m)res=max(res,cnt[i]);
		ans=min(ans,res);
		rep(i,1,m)if(cnt[i]==res)ban[i]=1;
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

using ll = long long;

#define ALL(A) A.begin(),A.end()

int main()
{
    ll H,W;
    cin >> H >> W;

    ll answer = 0;

    if(H>1 && W>1)
    {
        if(H%2==0)
        {
            if(W%2==0)
            {
                answer = H * W / 2;
            }
            else
            {
                answer = H / 2 * W;
            }
        }
        else
        {
            if(W%2==0)
            {
                answer = H * W / 2;
            }
            else
            {
                answer = (H-1) * (W-1) / 2;
                answer += (H+W) / 2;
            }
        }
    }
    else
    {
        answer = 1;
    }
    

    cout << answer << endl;

    return 0;
}

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

const int MOD = 1000000007;

int main() {
    int h, w;
    cin >> h >> w;
    string a[h];
    for (int i = 0; i < h; i++) {
        cin >> a[i];
    }
    int dp[h][w];
    dp[0][0] = 1;
    for (int j = 1; j < w; j++) {
        dp[0][j] = (a[0][j] == '.') ? dp[0][j - 1] : 0;
    }
    for (int i = 1; i < h; i++) {
        dp[i][0] = (a[i][0] == '.') ? dp[i - 1][0] : 0;
        for (int j = 1; j < w; j++) {
            dp[i][j] = (a[i][j] == '.') ? (dp[i - 1][j] + dp[i][j - 1]) % MOD : 0;
        }
    }
    cout << dp[h - 1][w - 1] << endl;
    return 0;
}


Measured memory_bytes: 5248
# A
# 若干解説を見た
# 2020/04/27  17:5-
n = int(input())
h = list(map(int, input().split()))

dp = [0]*n
for i in range(1, n):
    if i == 1:
        dp[i] = abs(h[i] - h[i-1])
    else:
        dp[i] = min(dp[i-2] + abs(h[i]-h[i-2]), dp[i-1] + abs(h[i]-h[i-1]))
        
print(dp[-1])

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

using namespace std;
 
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;
const ll mod = 1e9+7;

void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main()
{
 
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	int sm = 0;
	cin >>n;
	VI a(n), xc(200005);
	rep(i,n){
		int z; cin >>z;
		if(z > 100000){
			sm++;
			continue;
		}
		a[i] =z;
		xc[z]++;
	
	}
	
	int ans = n;
	rep(i, 200001){
		if(xc[i] >0 && i < xc[i]) sm += xc[i] -i;
		if(xc[i] >0 && i > xc[i]) sm += xc[i];
	}

	cout << sm <<"\n";
	return 0;
}

Measured memory_bytes: 1408
import java.util.Scanner;
public class Main {
	public static void main(String[] args)throws Exception{
		Scanner stdIn=new Scanner(System.in);
		long A=stdIn.nextLong();
		long B=stdIn.nextLong();
		long K=stdIn.nextLong();
		if(A<K){
			K-=A;A=0;
		}
		else{
			A-=K;K=0;
		}
		B-=K;
		if(B<0)
			B=0;
		System.out.println(A);
		System.out.println(B);
	}
}


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

int main(){
    int x;
    int n;
    cin>>x>>n;
    vector<int> in(n);
    for(int i=0; i<n; i++){
        cin>>in[i];
    }
    if(find(in.begin(), in.end(), x)==in.end()){
        cout<<x<<endl;
        return 0;
    }
    int len=1;
    while(1){
        if(find(in.begin(), in.end(), x-len)==in.end()){
            cout<<x-len<<endl;
            return 0;
        }
        if(find(in.begin(), in.end(), x+len)==in.end()){
            cout<<x+len<<endl;
            return 0;
        }
        len++;
    }
}


Measured memory_bytes: 3624