akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn digit(a: usize) -> usize {
    let mut ans = 0;
    let mut a = a;
    while a > 0 {
        ans += a%10;
        a /= 10;
    }
    ans
}

fn main() {
    input!{
      n: usize,
    }
    let mut ans = 1 << 10;
    for a in 1..n {
        let b = n - a;
        ans = min(digit(a) + digit(b), ans);
    }
    println!("{}", ans);
}


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

#define pb push_back
#define all(a) (a).begin(), (a).end()

typedef long long ll;
typedef pair<int, int> pii;

template<typename T> using V = vector<T>;

// borrowed from neal's code
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

#ifdef DEBUG
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

const double PI = acos(-1);

int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);
    int r; cin >> r;
    cout << 2 * PI * r;
}

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

using namespace std;

const int N =  2E5+7;
string s[N];
unordered_map<string,bool> g;

int main()
{
    int n; cin >> n;
    for(int i = 1 ;i <= n;i++) 
    {
        cin >> s[i];
        g[s[i]] = false;
    }
    
    
    long long res = 0;
    for(int i = 1 ;i <= n; i ++)
    {
        if(!g[s[i]])
        {
            res ++;
            g[s[i]] = true;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 23972
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,n){
        cin >> a[i];
    }
    int j=0;
    sort(a.begin(),a.end());
    while(1){
        j=0;
        while(a[j]==0){
            j++;
        }
        if(j==n-1){
            break;
        }
        //cout << j<<endl;
    for(int i=1+j;i<n;i++){
        a[i] = a[i]%a[j];
       // cout << a[i]<< " ";
    }
    //cout <<endl;
    sort(a.begin(),a.end());
    //rep(i,n){
    //    cout << a[i] << " ";
    //}
    //cout <<endl;
    }
    cout << a[n-1]<<endl;

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,b) FOR(i,0,b)
using namespace std;
const int SIZE=1+1e6;
int loves[SIZE];
int main() {
	int N;
	cin.tie(0);
	cin >> N;
	FOR(i,1,N+1){
		cin >> loves[i];
	}
	int ans=0;
	FOR(i,1,N+1){
		if(i==loves[loves[i]]) ans++;
	}
	cout << ans/2 << endl;
	return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#define INF 10000000000000000LL

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int n, m, k[2000];
	ll l, s[100001], ss[100001];
	cin>>n>>m>>l;
	for(int i=0; i<n; i++){
		cin>>k[i];
	}
	ss[0]=0;
	for(int i=1; i<=m; i++){
		cin>>s[i];
		ss[i]=ss[i-1]+s[i];
	}
	sort(k, k+n);
	if(n==3){
		cout<<(ss[k[1]]-ss[k[0]-1])/l+(ss[k[2]]-ss[k[1]-1])/l+(ss[k[2]]-ss[k[0]-1])/l<<endl;
		return 0;
	}
	ll dp[2000][2000];
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			dp[i][j]=INF;
		}
	}
	dp[0][1]=0;
	for(int i=0; i<n; i++){
		for(int j=1; j<n; j++){
			if(i<j-1){
				dp[i][j]=min(dp[i][j], dp[i][j-1]+(ss[k[j]]-ss[k[j-1]-1])/l);
			}
			if(i-1>j){
				dp[i][j]=min(dp[i][j], dp[i-1][j]+(ss[k[i]]-ss[k[i-1]-1])/l);
			}
			if(j==i+1){
				for(int t=1; t<i; t++){
					dp[i][j]=min(dp[i][j], dp[i][t]+(ss[k[j]]-ss[k[t]-1])/l);
				}
			}
			if(i==j+1){
				for(int t=0; t<j; t++){
					dp[i][j]=min(dp[i][j], dp[t][j]+(ss[k[i]]-ss[k[t]-1])/l);
				}
			}
		}
	}
	ll ans=(ss[k[1]]-ss[k[0]-1])/l+(ss[k[n-1]]-ss[k[n-2]-1])/l+min(dp[n-1][n-2], dp[n-2][n-1]);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 35952
//{{{
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop,~))(__VA_ARGS__)
#define loop(n) rep2(_loop_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define repN(a) repX a
#define repX(a0,a1,a2,x,...) x
const int MOD = 1e9+7;
//}}}

int main(){
	string s;
	cin >> s;
	int ans=0;
	rep(i, 4){
		if(s[i]=='+'){
			ans++;
		}else{
			ans--;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <utility>
#include <climits>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define F first
#define S second
#define OUT(x) cout << x << "\n"
using namespace std;
using point = pair< int,int >;
using ll = long long;

int main() {
    int n, x;
    cin >> n >> x;

    ll A[n];

    REP(i, n) {
        scanf("%lld", &A[i]);
    }

    ll cnt = 0;
    REP(i, n - 1) {
        if (A[i] + A[i + 1] > x) {
            ll diff = A[i] + A[i + 1] - x;
            cnt += diff;
            A[i + 1] = max(0LL, A[i + 1] - diff);
        }
    }

    OUT(cnt);

    return 0;
}



Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout<<(x)<<endl
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), n)
#define ub(v,n) upper_bound(v.begin(), v.end(), n)
//#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7; const int MAX = 200020;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 1e9;

int main(){
  int n,x;
  vector<int> L(n);

  cin >> n >> x;
  REP(i,n) cin >> L[i];

  int d = 0,res = 1;

  REP(i,n){
    d += L[i];
    if (d <= x) res++;
  }

  cout << res << endl;

}

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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++)cin >> a.at(i);
  sort(a.begin(),a.end());
  cout << a.at(n-1)-a.at(0) << endl;
}

Measured memory_bytes: 256
//code by lynmisakura.wish to be accepted!
/****************************/
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include<climits>
#include<set>
#include<bitset>
using namespace std;
/***************************/
typedef long long ll;
typedef vector<ll> vi;
typedef vector<long long> vl;
typedef pair<ll, ll> pi;
typedef vector<pair<ll, ll>> vpi;

//const long long INF = 1LL << 55;

#define itn ll
#define endl '\n'
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ss second
#define ff first
#define dup(x,y) ((x) + (y) - 1)/(y)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(ll i = 0;i < n;i++)
#define rep(i,n) for(ll i = 0;i < n;i++)
#define flush fflush(stdout)
#define rrep(i,n) for(ll i = n - 1;i >= 0;i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define ioboost cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, ll mo) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }

#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

//typedef ll long long
//d:dist,p:path
const ll INF = LONG_MAX;
vector<vector<pair<ll,ll>>> adj(100010,vector<pair<ll,ll>>(0));
vector<ll> dist,path;
void dijkstra(ll s, vector<ll> & d, vector<ll> & p) {
    ll n = adj.size();
    d.assign(n, INF);
    p.assign(n, -1);

    d[s] = 0;
    using pii = pair<ll, ll>;
    priority_queue<pii, vector<pii>, greater<pii>> q;
    q.push({0, s});
    while (!q.empty()) {
        ll v = q.top().second;
        ll d_v = q.top().first;
        q.pop();
        if (d_v != d[v])
            continue;

        for (auto edge : adj[v]) {
            ll to = edge.first;
            ll len = edge.second;

            if (d[v] + len < d[to]) {
                d[to] = d[v] + len;
                p[to] = v;
                q.push({d[to], to});
            }
        }
    }
}

int main(void){
    ioboost;
    int n,m;
    cin >> n >> m;
    //i から　i+1に辺を貼る
    for (int i = 0; i < n - 1; ++i) {
        //adj[i].push_back(make_pair(i+1,0));
        adj[i+1].push_back(make_pair(i,0));
    }
    for (int i = 0; i < m; ++i) {
        int l,r,c;cin >> l >> r >> c;
        l--,r--;
        adj[r].pb(mp(l,c));
        adj[l].pb(mp(r,c));
    }
    dijkstra(0,dist,path);
    if(dist[n - 1] == LONG_MAX){
        cout << -1 << endl;
        return 0;
    }
    cout << dist[n - 1] << endl;
}

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

int main() {
  string S;
  cin >> S;
  int A ;
  A = S.size();
  
  rep(i, A) {
    S.at(i) = 'x';
  }
  
  cout << S << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    char s[52];
    int n;
    int k;
    
    scanf("%d %d\n%s", &n, &k, &s);
    s[n] = '\0';
    s[k - 1] = s[k - 1] + 32;
    
    printf("%s", s);

    return 0;
}

Measured memory_bytes: 1720
N = int(input())
K = int(input())
x = 0
arrayx = list()
if N == 1:
  x = int(input())
  if x <= (K - x):
    print(x * 2)
  else:
    print((K - x) * 2)
  exit(0)
else:
  arrayx = list(map(int,input().split()))

sum = 0
for i in range(N):
  if arrayx[i] <= (K - arrayx[i]):
    sum += arrayx[i] * 2
  else:
    sum += (K - arrayx[i]) * 2
print(sum)

Measured memory_bytes: 9080
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		String input = sc.next();
		if (input.equals("Sunny")) {
			System.out.println("Cloudy");
		} else if (input.equals("Rainy")) {
			System.out.println("Sunny");
		} else {
			System.out.println("Rainy ");
		}
	}
}


Measured memory_bytes: 35616
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<math.h>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

typedef long long i64;
typedef pair<i64,i64> P;


int n;
string s;

int main(){
	cin >> n;
	cin >> s;
	
	for(int i = 0; i < s.size(); i++){
		cout << (char)((s[i]-'A'+n) % 26 + 'A');
	}
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static int N, M;
	static int[] H, W;

	public static void main(String[] args) {
		while (true) {
			N = sc.nextInt();
			if (N == 0) break;
			M = sc.nextInt();
			H = new int[N + 1];
			W = new int[M + 1];
			for (int i = 0; i < N; ++i) {
				H[i + 1] = H[i] + sc.nextInt();
			}
			for (int i = 0; i < M; ++i) {
				W[i + 1] = W[i] + sc.nextInt();
			}
			int[] len = new int[N * (N + 1) / 2 + 2];
			int idx = 1;
			for (int i = 0; i <= N; ++i) {
				for (int j = i + 1; j <= N; ++j) {
					len[idx++] = H[j] - H[i];
				}
			}
			len[len.length - 1] = Integer.MAX_VALUE;
			Arrays.sort(len);
			long ans = 0;
			for (int i = 0; i <= M; ++i) {
				for (int j = i + 1; j <= M; ++j) {
					ans += count(len, W[j] - W[i]);
				}
			}
			System.out.println(ans);
		}
	}

	static int count(int[] len, int v) {
		int l = 0;
		int r = len.length - 1;
		while (r - l > 1) {
			int m = (l + r) / 2;
			if (len[m] < v) {
				l = m;
			} else {
				r = m;
			}
		}
		int lower = l;
		l = 0;
		r = len.length - 1;
		while (r - l > 1) {
			int m = (l + r) / 2;
			if (len[m] <= v) {
				l = m;
			} else {
				r = m;
			}
		}
		int upper = r;
		return upper - lower - 1;
	}

}

Measured memory_bytes: 62832
#include <stdio.h>

/** Application main entry point. */
int main (
  int argc,
  char *argv[ ]
  )
{
  int a, b;

  while ( scanf ( "%d%d", &a, &b ) == 2 )
  {
    int gcd, tmp;

    gcd = a; tmp = b;
    while ( tmp != 0 )
    {
      int temporary = tmp;
      tmp = gcd % tmp;
      gcd = temporary;
    }

    printf ( "%d %d\n", gcd, ( a / gcd ) * b );
  }

  return ( 0 );
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
  
using namespace std;
  
typedef long long int64;
const int64 INF = 1LL << 59;
  
struct edge
{
  int to, cost;
};
struct node
{
  int now, time, type;
};
  
int N, M, X, T[10000];
vector< edge > g[10000];
int64 min_cost[10000][202][3];
  
int bfs()
{
  queue< node > qs[202];
  fill_n(**min_cost, 10000 * 202 * 3, INF);
  qs[0].emplace((node){0, 0, 1});
  min_cost[0][0][1] = 0;
    
  for(int t = 0; true; t++) {
    auto& que = qs[t % 202];
    while(!que.empty()) {
      const node p = que.front();
      que.pop();
      if(t != min_cost[p.now][p.time][p.type]) continue;
      if(p.now == N - 1) return(t);
      for(auto e : g[p.now]) {
        node q = (node){e.to, p.time, p.type};
        if(q.type + T[e.to] == 3) {
          if(q.time + e.cost < X) continue;
          q.time = 0;
          q.type = T[e.to];
        } else if(q.type == T[e.to]) {
          q.time = 0;
        } else {
          q.time = min(X, q.time + e.cost);
        }
        if(t + e.cost >= min_cost[q.now][q.time][q.type]) continue;
        min_cost[q.now][q.time][q.type] = t + e.cost;
        qs[(t + e.cost) % 202].push(q);
      }
    }
  }
}
  
int main()
{   
  scanf("%d %d %d", &N, &M, &X);
  for(int i = 0; i < N; i++) {
    scanf("%d", &T[i]);
    if(T[i] == 0) T[i] = 1;
    else if(T[i] == 1) T[i] = 0;
  }
  for(int i = 0; i < M; i++) {
    int A, B, D;
    scanf("%d %d %d", &A, &B, &D);
    --A, --B;
    g[A].emplace_back((edge){B, D});
    g[B].emplace_back((edge){A, D});
  }
  printf("%d\n", bfs());
}

Measured memory_bytes: 51528
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr ll INF = (ll)1e9;
constexpr double PI = 3.1415926535897932;
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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}


int main() {
	init();

	int N; cin >> N;
	vector<int>A(N), B(N);
	rep(i, 0, N)cin >> A[i];
	rep(i, 0, N)cin >> B[i];
	ll cnt = 0;
	rep(i, 0, N) {
		if (A[i] < B[i]) {
			int tmp = (B[i] - A[i] + 1) / 2;
			cnt += tmp;
			A[i] += 2 * tmp;
		}
	}
	rep(i, 0, N) {
		if (A[i] > B[i]) {
			cnt -= A[i] - B[i];
		}
	}
	cout << (cnt >= 0 ? "Yes" : "No") << "\n";

	return 0;
}

Measured memory_bytes: 3712
package main

import (
	"fmt"
)

func main() {
	var H, W int
	fmt.Scan(&H, &W)

	M := make([]string, H)
	for i := 0; i < H; i++ {
		fmt.Scan(&M[i])
	}

	for i := 0; i < H; i++ {
		for j := 0; j < W; j++ {
			if M[i][j] == '.' {
				continue
			}

			flg := false
			if i > 0 && M[i-1][j] == '#' {
				flg = true
			}
			if i < H-1 && M[i+1][j] == '#' {
				flg = true
			}
			if j > 0 && M[i][j-1] == '#' {
				flg = true
			}
			if j < W-1 && M[i][j+1] == '#' {
				flg = true
			}

			if !flg {
				fmt.Println("No")
				return
			}
		}
	}
	fmt.Println("Yes")
}


Measured memory_bytes: 1776
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
#define fin(ans) cout << (ans) << endl
const int INF = 1<<30;
const ll MOD = 1000000007;

int main() {
    ll N,K,sum=0;
    cin >> N >> K;
    ll ans=1;
    rep(i,N+1) sum+=i;
    ll count=0,l=sum,r=sum;
    for (int i = N; i >= K; i--) {
        l-=i;r-=count;
        ans+=r-l+1;
        count++;
    }
    cout << ans%MOD << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
const int inf = INT_MAX / 2;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }


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

    int N;
    cin >> N;
    int L[N];
    rep(i, N) cin >> L[i];

    int ans = 0;
    for (int i = 0; i < N-2; i++) {
        for (int j = i+1; j < N-1; j++) {
            if (L[i] == L[j]) continue;
            for (int k = j+1; k < N; k++) {
                if (L[i] == L[k] or L[j] == L[k]) continue;
                if (L[i] < L[j] + L[k] && L[j] < L[k] + L[i] && L[k] < L[i] + L[j]) ans++;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define SZ(x) ((int)x.size())
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
int n, m, a[110];
int main() {
	scanf("%d%d", &n, &m);
	int s = 0;
	for(int i=1; i<=n; i++) scanf("%d", a+i), s += a[i];
	sort(a+1, a+n+1);
	printf("%d", n + (m - s) / a[1]);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main()
{
  int A,B;
  scanf("%d%d",&A,&B);
  if((A+B)>=A*B & (A+B)>=(A-B)){
      printf("%d",(A+B));
  }
      else if(A*B>=(A+B)&A*B>=(A-B)){
          printf("%d",A*B);
      }
      else if((A-B)>=(A+B)&(A-B)>=A*B){
          printf("%d",A-B);
      }
  
return 0;
}

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

using namespace std;

int main() {

	int  A, B, C, D, P;

	cin >> A >> B >> C >> D >> P;

	int Acy = A * P;
	int Bcy;

	if (C >= P)
		Bcy = B;

	else
		Bcy = B + (P - C) * D;

	cout << min(Acy, Bcy) << "\n";

	

	return 0;

}




Measured memory_bytes: 3076
#include <iostream>

int x, y;

using namespace std;

void swap(int &a, int &b){
	int tmp = a;
	a = b;
	b = tmp;
}


int gcd(){
	int remainder;
	while(1){
		int remainder = x%y;
		if(remainder == 0)break;
		x = y;
		y = remainder;
	}
	return y;
}

int main(){
	cin >> x >> y;
	if (x < y) swap(x, y);
	cout << gcd() << endl;

	return 0;
}


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

int main() {
  string S;
  cin >> S;
  if(S=="SUN"){
    cout << 7;
  }else if(S=="MON"){
    cout << 6;
  }else if(S=="TUE"){
    cout << 5;
  }else if(S=="WED"){
    cout << 4;
  }else if(S=="THU"){
    cout << 3;
  }else if(S=="FRI"){
    cout << 2;
  }else{
    cout <<1;
  }
}


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

using namespace std;

int main(){
	string s;
	getline(cin, s);
	string p;
	getline(cin, p);
	bool ansflag = false;
	for(int i = 0; i < s.length(); i++){
		bool flag = true;
		for(int j = 0; j < p.length(); j++){
			if(s[(i+j)%s.length()] != p[j]){
				flag = false;
				break;
			}
		}
		if(flag){
			ansflag = true;
			break;
		}
	}
	if(ansflag){
		cout << "Yes\n";
	}
	else{
		cout << "No\n";
	}
}


Measured memory_bytes: 3208
// Original macro is in https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = || -> String {
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
    
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [$t:tt]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

// for adhoc read (ex. https://atcoder.jp/contests/abc112/tasks/abc112_a)
#[allow(dead_code)]
fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main() {
    input!{
        h: usize,
        w: usize,
        b: [chars; h],
    }
    let mut tmp= vec![];
    for i in 0..h {
        for j in 0..w {
            if b[i][j]=='#' {
                tmp.push(b[i].clone());
                break;
            }
        }
    }
    let mut ans: Vec<Vec<char>> = vec![];
    let column_size:usize = tmp[0].len();
    let row_size:usize = tmp.len();
    for j in 0..column_size {
        let mut flag = false;
        for i in 0..row_size {
            if tmp[i][j] == '#' {
                flag = true;
            }
        }
        if flag {
            let mut tmp2 = vec![];
            for i in 0..row_size {
                tmp2.push(tmp[i][j]);
            }
            ans.push(tmp2);
        }
    }
    for (j,_) in ans[0].iter().enumerate() {
        for (i,_) in ans.iter().enumerate() {
            if i == ans.len()-1 {
                println!("{}", ans[i][j]);
            } else {
                print!("{}", ans[i][j]);
            }
        }
    }
}



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

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

    vector<int> prime(100);
    int i, j;
    for (i = 1, j = 0; i < min(A, B) + 1; i++)
    {
        if (A % i == 0 && B % i == 0)
        {
            // printf("prime.at(%d) = %d\n", j, i);
            prime.at(j) = i;
            j++;
        }
    }

    cout << prime.at(j - K) << endl;
    return (0);
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(){
	int N;
	cin >> N;
	int cnt1=0;
	int cnt2=0;
	cnt1=N*800;
	cnt2=N/15*200;
	cout << cnt1-cnt2 << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

s=list(ss())
lens=len(s)

wrr=[i for i ,x in enumerate(s) if x=="W"]
lenwrr=len(wrr)
print(sum(wrr)-(lenwrr*(lenwrr-1)//2))

Measured memory_bytes: 87404
#include<stdio.h>
#include<string.h>
int dp[50][3001];
int main(){
	int n,m,s;
	int i,j,k;
	while(1){
	scanf("%d %d %d",&n,&m,&s);
	if(n==0)return 0;
	memset(dp,0,sizeof(dp));
	dp[0][0]=1;
	for(i=1;i<=m;i++){
		for(j=s-i;j>=0;j--){
			for(k=0;k<n*n;k++){
				dp[k+1][j+i]=(dp[k+1][j+i]+dp[k][j])%100000;
			}
		}
	}
	printf("%d\n",dp[n*n][s]);
	}
}

Measured memory_bytes: 1192
import java.util.Scanner;
import java.math.BigDecimal;

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

		// 整数の入力
		String a = sc.next();

		if( Character.isUpperCase( a.charAt( 0 ) )) {
			System.out.println( "A" );
		} else {
			System.out.println( "a" );
		}
	}
}

Measured memory_bytes: 35648
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include<complex>
#include <cassert>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repd(i, n) for (int i = n; i > 0; i--)
#define mod 1000000007
#define MOD 998244353
#define inf 1e20
typedef long long int ll;
typedef pair<ll, ll> pr;
typedef complex<double> com;


int main(){
	int a;
	cin >> a;
	cout << a * 800 - (a / 15) * 200 << endl;
	return 0;
}
//Ctrl+Aを使わない

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ar array
#define db double
#define pi 3.14159265358979323846
#define pow pw
int pw(int a,int b){
    int ans=1;
    while(b){
    if (b%2) ans*=a;
    a*=a;
    b/=2;
    }
    return(ans);
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int a;
    cin>>a;
    cout<<a+a*a+a*a*a;
    return 0;
}

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

typedef long long ll;
vector<vector<ll>> dp;
ll MOD = 1e9+7;
int main()
{
    string S;
    cin >> S;
    int size = S.size();
    dp = vector<vector<ll>>(size + 1, vector<ll>(13));
    dp.at(0).at(0) = 1;
    for(int i = 0; i < size; i++){
        int charNum;
        if(S[i] == '?'){
            charNum = -1;
        }else{
            charNum = S[i] - '0';
        }
        for(int j = 0; j < 10; j++){
            if(charNum != -1 && charNum != j){
                continue;
            }
            for(int k = 0; k < 13; k++){
                dp.at(i + 1).at((k * 10 + j) % 13) += dp.at(i).at(k);
            }
        }
        for(int j = 0; j < 13; j++){
            dp.at(i + 1).at(j) %= MOD;
        }
    }
    cout << dp.at(size).at(5) << endl;
    return 0;
}

Measured memory_bytes: 13696
void main() {
	auto ip = readAs!(long[]), N = ip[0], M = ip[1];
	auto A = readAs!(long[]);
	auto arr = new long[](A.reduce!max+1);
	A.each!(v => arr[v]++);
	auto arr2 = FFT!double.Convolve(arr, arr);
	ulong k = arr2.length-1;
	ulong res;
	while(M > 0 && k > 0) {
		auto use = min(M, arr2[k]);
		M -= use;
		res += k * use;
		k--;
	}
	res.writeln;
}

import std.complex;
// Complex!T は isFloatingPoint!T を要求する。
class FFT(T = double) if(isFloatingPoint!T) {
	static long[] Convolve(E)(E[] g, E[] h) if(isNumeric!E) {
		auto s = g.length + h.length - 1; // 畳み込みの結果の配列サイズ
		auto n = 1;
		while(n < s) n *= 2; // FFTに使う配列のサイズ(2の累乗)
		auto gg = dft(g.to!(T[]) ~ 0.repeat(n - g.length).array.to!(T[]));
		auto hh = dft(h.to!(T[]) ~ 0.repeat(n - h.length).array.to!(T[]));
		auto ff = zip(gg, hh).map!(p => p[0] * p[1]).array;
		ff = dft(ff, true);
		ff[] /= complex!T(ff.length);
		return ff[0..s].map!(v => v.re.round).array.to!(long[]);
	}
	static Complex!T[] dft(T[] f, bool inverse = false) {
		auto f_comp = new Complex!T[](f.length);
		foreach(i, v; f) f_comp[i] = complex!T(v);
		return dft(f_comp, inverse);
	}
	// ifftの場合はf.lengthで割りましょう。
	static Complex!T[] dft(Complex!T[] f, bool inverse = false) {
		auto n = f.length;
		if(n == 1) return f;
		auto f0 = iota(0, n, 2).map!(i => f[i]).array;
		auto f1 = iota(1, n, 2).map!(i => f[i]).array;
		f0 = dft(f0, inverse);
		f1 = dft(f1, inverse);
		const auto zeta = complex!T(cos((2*PI / n).to!T), sin((2*PI / n).to!T));
		Complex!T zeta_pow = 1;
		foreach(i; 0..n) {
			f[i] = f0[i % (n/2)] + (inverse ? 1/zeta_pow : zeta_pow) * f1[i % (n/2)];
			zeta_pow *= zeta;
		}
		return f;
	}
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

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

int main()
{
	int t, n, k, pre, x;
	scanf("%d", &t);
	while (t--){
		scanf("%d%d", &n, &k);
		vector<int> dis;
		for (int i = 0; i < n; ++i){
			if (!i)scanf("%d", &pre);
			else {
				scanf("%d", &x);
				dis.push_back(x - pre);
				pre = x;
			}
		}
		sort(dis.begin(), dis.end());
		if (k < n)printf("%d\n", accumulate(dis.begin(), dis.begin() + n - k, 0));
		else printf("0\n");
	}
	return 0;
}


Measured memory_bytes: 3656
s = list(input())
K = int(input())
sub_list = []
for i in range(1, min(K+1, len(s)+1)):
    for j in range(len(s) - i + 1):
        sub = "".join(s[j:j+i])
        if sub not in sub_list:
            sub_list.append(sub)
sub_list.sort()
print(sub_list[K-1])

Measured memory_bytes: 4084
n = gets.strip.to_i
s = gets.strip
ans = "No"
if s[0..(n / 2 -1)] == s[(n / 2)..(n - 1)]
  ans = "Yes"
end
if s[0..(n / 2 -1)] + s[(n / 2)..(n - 1)] != s
  ans = "No"
end

6
puts ans

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
//const int mod=998244353;
using P = pair<int,int>;
using Pll = pair<ll,ll>;
using ld=long double;
using V=vector<int>;
using Vl=vector<ll>;
using VV=vector<vector<int>>;
using VVl=vector<vector<ll>>;

int main(){
    int a,b,c;cin >>a>>b>>c;
    if(a+b>=c)puts("Yes");
    else puts("No");
}



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

int main(){
	string s;
	cin >> s;
	int n=s.size();
	long long ans=0ll;
	
	vector<int> S;
	for(int pos=0;pos<n;pos++){
		if(s[pos]=='A')S.push_back(1);
		else if(s[pos]=='B'){
			if(pos+1<n && s[pos+1]=='C'){
				S.push_back(2);
				pos++;
			}
			else S.push_back(0);
		}
		else S.push_back(0);
	}
	
	int N=S.size();
	int a=0;
	for(int pos=0;pos<N;pos++){
		if(S[pos]==1)a++;
		else if(S[pos]==2)ans+=a;
		else a=0;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1532
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define all(v) v.begin(), v.end()
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; }
typedef int64_t lint;

// メモ用 DP
vector<int> dp(100010);

// inputs
int N, M;
vector<vector<int>> v(100010);

int rec(int x) {
	// メモ済み
	if (dp[x] > 0) return dp[x];

	int t = 0;
	rep(i, v.at(x).size()) {
		chmax(t, rec(v.at(x).at(i))+1);
	}

	// メモしながら返す
	return dp[x] = t;
}

int main() {
	cin >> N >> M;
	int a=0, b=0, c=0, x, y, z;
	rep(i, M) {
		cin >> x >> y;
		v.at(x-1).push_back(y-1);
	}
	rep(i, N) {
		chmax(a, rec(i));
	}
	cout << a << '\n';
}


Measured memory_bytes: 11104
//defalt
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
typedef pair<int, int> P_i;
typedef pair<double,double> P_d;
#define rep(i,n) for(int i=0;i<(n);++i)
#define alrep(i,j,n) for(int i=0;i<(n);++i)for(int j=i+1;j<(n);++j)
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
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 int MOD=1e9+7;
const long long INF = 1LL << 60;

signed main(){
  int N;
  cin >> N;
  if(N%2==1){
    cout << 0 << endl;
    return 0;
  }
  int div=10,ans=0;
  while(N/div!=0){
    ans+=N/div;
    div*=5;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
H = list(map(int, input().split()))
dai = [list(map(int, input().split())) for i in range(M)]
plus = [i for i in range(N)]


for a, b in dai:
    if H[a - 1] > H[b - 1]:
        plus[b-1] = -1
        continue
    else:
        plus[a-1] = -1
    if H[b - 1] > H[a - 1]:
        plus[a-1] = -1
        continue
    else:
        plus[b-1] = -1
print(len(set(plus))-1)


Measured memory_bytes: 41824
package main

import (
	"fmt"
)

func main() {
	var a int
	var b int
	fmt.Scan(&a, &b)

	if (a >= 13) {
		fmt.Println(b)
	} else if (a <= 12 && a >= 6) {
		fmt.Println(b/2)
	} else {
		fmt.Println(0)
	}
	
}

Measured memory_bytes: 512
K = int(input())
ans = 0
for _ in range(K):
    N, M = map(int, input().split())
    grundy0 = {0}
    grundy1 = {1}
    m = M
    while m // 2 >= N:
        if (m+1)//2%2:
            grundy_l = grundy0
        else:
            grundy_l = grundy1
        m, r = divmod(m, 2)
        if r==0:
            gr0 = grundy0
            grundy0 = {min({0, 1, 2} - grundy0 - grundy_l)}
            grundy1 = {0, 1, 2} - gr0 - grundy0
        else:
            grundy0 = {min({0, 1, 2} - grundy1 - grundy_l)}
            grundy1 = {0, 1, 2} - grundy1 - grundy0
        #print(grundy0, grundy1)
    grundy = grundy1 if (m-N)%2 else grundy0
    #print(grundy)
    ans ^= grundy.pop()
print("tubuann" if ans==0 else "mo3tthi")



Measured memory_bytes: 5624
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long llong;

vector<pair<int, int>> E;

const int MOD = 1000 * 1000 * 1000 + 7;

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        int x;
        scanf("%d", &x);
        E.emplace_back(x, 1);
    }
    for (int i = 0; i < n; i++) {
        int x;
        scanf("%d", &x);
        E.emplace_back(x, -1);
    }
    sort(E.begin(), E.end());
    int bal = 0;
    int ans = 1;
    for (auto e : E) {
        if (bal > 0 && e.second == -1) {
            ans = ((llong)ans * bal) % MOD;
        } else if (bal < 0 && e.second == 1) {
            ans = ((llong)ans * (-bal)) % MOD;
        }
        bal += e.second;
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 2420
#include <cstdio>
#include <cstring>
using namespace std;

#define L 3194304
bool HA[L];
char T[256];

int main() {
    int n, sum, t;
    char c;
    T['A'] = 1, T['C'] = 2, T['G'] = 3, T['T'] = 4;
    scanf("%d", &n);
    while ( getchar() != '\n' );
    for ( register int i = 0; i++ < n; ) {
        sum = 0;
        t = 1;
        bool flag = ( c = getchar() ) == 'i';
        while ( ( c = getchar() ) != ' ' );
        while ( ( c = T[getchar()] ) != 0 ) {
            sum += c * t;
            t *= 4;
        }
        if ( flag ) {
            HA[sum] = true;
        } else {
            puts( HA[sum] ? "yes" : "no" );
        }
    }
    return 0;
}

Measured memory_bytes: 2096
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>

using namespace std;

#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;

ll n = 0, m = 0, k = 0, ans = 0, sum = 0, cnt = 0, temp = 0;
string s;
char c;
bool flag;

//----------------------------------------------------------------------



int main(void) {
  ll n, max, min, nmax, nmin;
  ll x[1000], y[1000];
  vll a;

  cin >> n;

  FOR(i, 0, n) {
	cin >> temp;
	a.push_back(temp);
  }

  max = -100000000;
  min = 100000000;

  FOR(i, 0, a.size()) {
	if (max < a[i]) {
	  max = a[i];
	  nmax = i;
	}
  }

  FOR(i, 0, a.size()) {
	if (min > a[i]) {
	  min = a[i];
	  nmin = i;
	}
  }

  if (max + min >= 0) {
	m = max, n = nmax;
  }else {
	m = min, n = nmin;
  }

  FOR(i, 0, a.size()) {
	a[i] += m;
	x[cnt] = n + 1;
	y[cnt] = i + 1;
	cnt++;
  }

  if (m > 0) {
	FOR(i, 1, a.size()) {
	  a[i] += a[i - 1];
	  x[cnt] = i;
	  y[cnt] = i + 1;
	  cnt++;
	}
  }

  if (m < 0) {
	RFOR(i, 1, a.size()) {
	  a[i - 1] += a[i];
	  x[cnt] = i + 1;
	  y[cnt] = i;
	  cnt++;
	}
  }

  cout << cnt << endl;

  FOR(i, 0, cnt) {
	cout << x[i] << " " << y[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main(){
	char data[6];
	int stack[128];
	int k=0;
	while(scanf("%s",data)!=EOF){
		if(data[0]=='+'){
			k--;
			stack[k-1]=stack[k-1]+stack[k];
		}
		else if(data[0]=='-'){
			k--;
			stack[k-1]=stack[k-1]-stack[k];
		}
		else if(data[0]=='*'){
			k--;
			stack[k-1]=stack[k-1]*stack[k];
		}
		else{
			stack[k]=atoi(data);
			k++;
		}
	}
	printf("%d\n",stack[0]);
	return 0;
}



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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

// n回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;  // 2次元配列
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/
//{0,1,...,n-1}のn個の要素数のbit集合から要素数k個の部分集合探索。
int next_combination(int sub){
    int x = sub & -sub, y = sub + x;
    return(((sub & ~y) / x) >> 1) | y;
}


/*MAIN==================================================*/
signed main(){
    int _StartTime_ = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    // cout << fixed << setprecision(15);

    int n,k; cin >> n >> k;
    --n;--k;
    int FirstBuilding; cin >> FirstBuilding;
    vi a(n); rep(i,n) cin >> a[i];

    if(k==0) {
        cout << 0 << '\n';
        return 0;
    }

    // Kとしてどれを選ぶかを全探索してみる
    ll ans_cost = infll;
    ll highest;
    int bit = (1<<k)-1;
    for(; bit < (1<<n); bit = next_combination(bit)){
        ll cost = 0;
        highest = FirstBuilding;
        for(int i = 0; i < n; ++i) {
            if((bit>>i)&1) {
                ll c = max(0LL, highest+1 - a[i]);
                cost += c;
                if(c!=0) highest = highest+1;
                else highest = a[i];
            }
            else {
                chmax(highest, a[i]);
            }
        }
        chmin(ans_cost, cost);
    }

    cout << ans_cost << '\n';

    // printf("ExcutionTime: %d /ms\n",1000*(int)((clock()-_StartTime_)/CLOCKS_PER_SEC));
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>
#define MN 40002
#define MM 5000001
#define ll long long
#define ld long double
#define inf 0x7fffffff
#define clz 1000000007
#define ers(arr,val) memset(arr,val,sizeof(arr));
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define repd(i,b,a) for(int i=(b);i>=(a);i--)
#define repe(i,u) for(int i=h[u];i;i=e[i].nx)
using namespace std;
char s[200001],t[200001];
int c[270],c2[270];
int main(){
	scanf("%s%s",s,t);
	for(int i=0;s[i];i++){
		if(!c[s[i]]) c[s[i]]=t[i];
		else if(c[s[i]]!=t[i]) return 0*puts("No");
		if(!c2[t[i]]) c2[t[i]]=s[i];
		else if(c2[t[i]]!=s[i]) return 0*puts("No");
	}
	puts("Yes");
	return 0;
}


Measured memory_bytes: 640
S = input()

lst = [1 if S[0]=='<' else -1]
pre = S[0]
for i in S[1:]:
    if i == pre:
        lst[-1] += 1 if i=='<' else -1
    else:
        lst.append(-1 if i=='>' else 1)
    pre = i    
ans = [0]

for i in lst:
    if i > 0:
        ans += list(range(1,i+1))
    else:
        ans[-1] = max(ans[-1], -i)
        ans += list(range(-i-1,-1, -1))

print(sum(ans))

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

#define int long long

signed main()
{
    int n;
    cin >> n;
    vector<int> A(n);
    vector<int> B(n);
    for(int i=0; i<n; ++i) {
        cin >> A[i];
        cin >> B[i];
    }
    int ans = 0;
    for(int i=n-1; i>=0; --i) {
        if((A[i]+ans)%B[i]==0) continue;
        ans += B[i] - (A[i]+ans)%B[i];
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 1792
import math

n = int(input())



def koch(n,x_0,y_0,x_1,y_1):
    if n == 0:
        return    
    x_m1 = x_0 + (x_1- x_0)/3
    y_m1 = y_0 + (y_1 -y_0)/3
    x_m2 = x_0 + (x_1- x_0)* 2/3
    y_m2 = y_0 + (y_1 -y_0) *2/3
    x_m =  (x_m2 - x_m1) * math.cos(math.pi/3) - (y_m2 - y_m1) * math.sin(math.pi/3) + x_m1
    y_m =  (x_m2 - x_m1) * math.sin(math.pi/3) + (y_m2 - y_m1) * math.cos(math.pi/3) + y_m1

    koch(n-1,x_0,y_0,x_m1,y_m1)
    print(x_m1,y_m1)
    koch(n-1,x_m1,y_m1,x_m,y_m)
    print(x_m,y_m)
    koch(n-1,x_m,y_m,x_m2,y_m2)
    print(x_m2,y_m2)
    koch(n-1,x_m2,y_m2,x_1,y_1)
    
print(0,0)
koch(n,0,0,100,0)
print(100,0)

Measured memory_bytes: 8040
#include <iostream>
#include <vector>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)

struct P{
    int x, y;
};

int w, h, illus[110][110], out[110][110], used[110][110];

bool isWithinRange(P p){
    return 0 <= p.x && p.x <= w+1 && 0 <= p.y && p.y <= h+1;
}

std::vector<P> up(const P& p){
    if(p.y % 2 == 0){
        return {{p.x-1, p.y-1}, {p.x, p.y-1}};
    }
    return {{p.x, p.y-1}, {p.x+1, p.y-1}};
}

std::vector<P> down(const P& p){
    if(p.y % 2 == 0){
        return {{p.x-1, p.y+1}, {p.x, p.y+1}};
    }
    return {{p.x, p.y+1}, {p.x+1, p.y+1}};
}

void dfs(int x, int y){
    if(used[y][x]){
        return;
    }

    out[y][x] = 1;
    used[y][x] = 1;

    for(P p : up({x, y})){
        if(isWithinRange(p) && !illus[p.y][p.x]){
            dfs(p.x, p.y);
        }
    }

    for(P p : down({x, y})){
        if(isWithinRange(p) && !illus[p.y][p.x]){
            dfs(p.x, p.y);
        }
    }

    if(isWithinRange({x-1, y}) && !illus[y][x-1]){
        dfs(x-1, y);
    }

    if(isWithinRange({x+1, y}) && !illus[y][x+1]){
        dfs(x+1, y);
    }
}

int main(){
    std::cin >> w >> h;

    FOR(i, 1, h+1){
        FOR(j, 1, w+1){
            std::cin >> illus[i][j];
        }
    }

    REP(i, 110){
        REP(j, 110){
            out[i][j] = 0;
        }
    }

    FOR(i, 1, w+1){
        if(!illus[1][i]){
            dfs(i, 1);
        }

        if(!illus[h][i]){
            dfs(i, h);
        }
    }

    FOR(i, 1, h+1){
        if(!illus[i][1]){
            dfs(1, i);
        }

        if(!illus[i][w]){
            dfs(w, i);
        }
    }

    int res = 0;
    FOR(i, 1, h+1){
        FOR(j, 1, w+1){
            if(!illus[i][j]){
                continue;
            }

            // up
            for(P p : up({j, i})){
                if(isWithinRange(p) && !illus[p.y][p.x] && out[p.y][p.x]){
                    res++;
                }
            }

            //down
            for(P p : down({j, i})){
                if(isWithinRange(p) && !illus[p.y][p.x] && out[p.y][p.x]){
                    res++;
                }
            }

            //left, right
            if(isWithinRange({j-1, i}) && !illus[i][j-1] && out[i][j-1]){
                res++;
            }

            if(isWithinRange({j+1, i}) && !illus[i][j+1] && out[i][j+1]){
                res++;
            }
        }
    }

    std::cout << res << std::endl;
}

Measured memory_bytes: 2528