akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
    os << "{ ";
    REP(i, vec.size()) {
        os << vec[i] << " ";
    }
    os << "}";

    return os;
}

ll pow_mod(ll a, ll p) {
    ll res = 1;
    while(p) {
        if (p & 1) res = (res * a) % MOD;
        a = (a * a) % MOD;
        p >>= 1;
    }

    return res;
}


ll mod_inv(ll a, ll m) {
    ll b = m, u = 0, v = 1;
    while(a) {
        ll t = b / a;
        swap(b -= t * a, a);
        swap(u -= t * v, v);
    }

    return (u % m + m) % m;
}

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

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}


#ifdef LOCAL
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif


int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    int N; ll X;
    cin >> N >> X;
    ++N;

    ll p[N+1];
    p[0] = 0;
    REP(i, N+1) {
        p[i+1] = p[i] * 2 + 1;
    }

    ll r = p[N] * 2 - 1;
    ll l = 0;

    ll ans = p[N];

    while(1) {
        ll bn = r - l;
        ll mid = (bn + 2 - 1) / 2 + l;
        N = max(0, N-1);
        if (X > mid) {
            l = mid;
            --r;
        } else {
            ans -= p[N];

            if (X == mid) break;
            --ans;
            ++l;
            r = mid - 1;
        }
        if (l >= r) break;
    }

    cout << fixed << setprecision(20);
    cout << ans << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define Rep(i,n) for(int i=1;i<=(n);++i)
using LL = long long;
using ULL = unsigned long long;

const LL INF = 1e18;

int main()
{
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    cout << max(0, h2*60+m2-h1*60-m1-k) << endl;
	return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <tuple>
#include <atcoder/lazysegtree>

#define MOD (998244353LL)

typedef long long ll;
typedef std::tuple<ll,ll,ll> tll;

ll mae[10][200001];
ll mae2[200001];

void prepare_mae() {
  for (int i = 0; i < 9; i++) {
    mae[i][0] = 0;
    for (int j = 1; j <= 200000; j++) {
      mae[i][j] = mae[i][j-1];
      mae[i][j] *= 10;
      mae[i][j] %= MOD;
      mae[i][j] += i+1;
    }
  }
  mae2[0] = 1;
  for (int j = 1; j <= 200000; j++) {
    mae2[j] = mae2[j-1];
    mae2[j] *= 10;
    mae2[j] %= MOD;
  }
}

tll op(tll a, tll b) {
  if (std::get<0>(b) > std::get<0>(a)) {
    a.swap(b);
  }
  if (std::get<0>(b) == -1LL) {
    return a;
  }
  ll second = std::get<1>(a);
  second *= mae2[std::get<0>(a) - std::get<0>(b)];
  second %= MOD;
  ll third = std::get<2>(a) + std::get<0>(a) - std::get<0>(b);
  second += std::get<1>(b);
  second %= MOD;
  return std::make_tuple(std::get<0>(b), second, third);
}

tll e() {
  return std::make_tuple<ll,ll,ll>(-1LL,0LL,0LL);
}

tll mapping(int f, tll x) {
  if (f == 0) return x;
  ll second = mae[f-1][std::get<2>(x)];
  return std::make_tuple(std::get<0>(x), second, std::get<2>(x));
}

int composition(int f, int g) {
  if (f == 0) return g;
  return f;
}

int id() {
  return 0;
}

int main() {
  prepare_mae();
  int N, Q;
  std::cin >> N >> Q;
  std::vector<tll> vec(N);
  for (int i = 0; i < N; i++) {
    vec[i] = std::make_tuple(N - 1 - i, 1LL, 1LL);
  }
  atcoder::lazy_segtree<tll,op,e,int,mapping,composition,id> seg(vec);
  for (int i = 0; i < Q; i++) {
    int Li, Ri, Di;
    std::cin >> Li >> Ri >> Di;
    seg.apply(Li - 1, Ri, Di);
    std::cout << std::get<1>(seg.all_prod()) << std::endl;
  }
  return 0;
}


Measured memory_bytes: 36240
#include<algorithm>
#include<cstring>
#include<cctype>
#include<cstdio>
#define rep(i,x,y) for(int i=x; i<=y; ++i)

using namespace std;
char s[200005];
int n,A,B,C,D;

bool check(int A,int B)
{
	rep(i,A+1,B-1) if(s[i]=='#' && s[i+1]=='#') return 0;
	return 1;
}

int main()
{
	scanf("%d%d%d%d%d",&n,&A,&B,&C,&D);
	scanf("%s",s+1);
	if(!check(A,C) || !check(B,D)) return puts("No"),0; 
	if(C<D) return puts("Yes"),0;
	rep(i,B,D) if(s[i-1]=='.' && s[i]=='.' && s[i+1]=='.') return puts("Yes"),0;
	return puts("No"),0;
}		

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

int main() {
  string ans="Impossible";
  long n;
  cin >> n;
  vector<long> a(n);
  vector<long> b(100);
  for(long i=0;i<n;i++) {
    cin >> a[i];
    b[a[i]-1]++;
  }
  for(long i=0;i<50;i++) {
    bool p=true;
    for(long j=0;j<100;j++) {
      if(i==j&&b[j]!=2) p=false;
      if((i<j&&i+i>=j)&&b[j]<2) p=false;
      if(i>j&&b[j]!=0) p=false;
      if(i+i<j&&b[j]!=0) p=false; 
    }
    if(p) ans="Possible";
  }
  for(long i=0;i<49;i++) {
    bool p=true;
    for(long j=0;j<100;j++) {
      if(i==j&&b[j]!=1) p=false;
      if((i<j&&i+i+1>=j)&&b[j]<2) p=false;
      if(i>j&&b[j]!=0) p=false;
      if(i+i+1<j&&b[j]!=0) p=false; 
    }
    if(p) ans="Possible";
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
inline int read()
{
	int x;char c;
	while((c=getchar())<'0'||c>'9');
	for(x=c-'0';(c=getchar())>='0'&&c<='9';)x=x*10+c-'0';
	return x;
}
const int MOD=998244353;
struct mint{int x;mint(int x=0):x(x){}};
inline mint operator+  (mint a,mint b){return a.x+b.x<MOD?a.x+b.x:a.x+b.x-MOD;}
inline mint operator-  (mint a){return MOD-a.x;}
inline mint operator-  (mint a,mint b){return a+-b;}
inline mint operator*  (mint a,mint b){return 1LL*a.x*b.x%MOD;}
inline mint operator<< (mint x,int y){mint r=1;for(;y;y>>=1,x=x*x)if(y&1)r=r*x;return r;}
inline mint operator~  (mint x){return x<<MOD-2;}
inline mint operator/  (mint a,mint b){return a*~b;}
inline mint&operator+= (mint&a,mint b){return a=a+b;}
inline mint&operator-= (mint&a,mint b){return a=a-b;}
inline mint&operator*= (mint&a,mint b){return a=a*b;}
inline mint&operator<<=(mint&x,int y){return x=x<<y;}
inline mint&operator/= (mint&a,mint b){return a=a/b;}
#define MN 1000000
mint F[MN+5],R[MN+5],ans;
inline mint C(int n,int m){return F[n]*R[m]*R[n-m];}
inline mint RC(int n,int m){return R[n]*F[m]*F[n-m];}
int main()
{
	int n,m,i,j;
	n=read();m=read();
	for(F[0]=i=1;i<=MN;++i)F[i]=F[i-1]*i;
	for(R[i=MN]=~F[MN];i--;)R[i]=R[i+1]*(i+1);
	for(i=1;i<=n&&i<=m;++i)ans+=C(n,i)*C(m,i)*RC(n+m,i+i);
	printf("%d",ans/2+max(n,m));
}

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



int main(){
    ll n;
    cin >> n;
    P x[n];
    ll mmax=0;
    ll mmin=3e9;
    for(ll i=0;i<n;i++){
        cin >> x[i].first >> x[i].second;
        mmax=max(mmax,x[i].first+x[i].second);
        mmin=min(mmin,x[i].first+x[i].second);
    }
    ll memo1=mmax-mmin;
    P memo2;
    memo2.first=0;
    memo2.second=1e9;
    P memo3;
    memo3.first=1e9;
    memo3.second=0;
    for(ll i=0;i<n;i++){
        if(abs(x[i].first-1e9)+abs(x[i].second-0)<abs(memo2.first-1e9)+abs(memo2.second-0)){
            memo2.first=x[i].first;
            memo2.second=x[i].second;
        }
        if(abs(x[i].first-0)+abs(x[i].second-1e9)<abs(memo3.first-0)+abs(memo3.second-1e9)){
            memo3.first=x[i].first;
            memo3.second=x[i].second;
        }
    }
    ll memo4=memo2.first-memo3.first+memo3.second-memo2.second;
    cout << max(memo1,memo4) << endl;
    return 0;
}  

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

signed main(void)
{
	int k, n;
	string s;

	cin >> s >> k;
	n = s.size();
	rep(i, n)
	{
		if (s[i] == 'a') continue;
		if (26 - (s[i] - 'a') <= k)
		{
			k -= 26 - (s[i] - 'a');
			s[i] = 'a';
		}
	}
	if (k > 0)
	{
		k %= 26;
		s[n - 1] += k;
		if (s[n - 1] > 'z') 
			s[n - 1] = s[n - 1] % ('z' + 1) + 'a';
	}
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define FT first
#define SC second

using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef pair<int, int> pint;
const int INF = 1e9;
const double EPS = 1e-9;



int main()
{
  int n ;
  cin >> n ;
  int ans = 0 ;
  
  REP(i,n){
    int a, b ;
    cin >> a >> b ;
    ans += b-a+1 ;
  }
  
  cout << ans <<endl ;

  return 0 ;
}


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

using namespace std;

typedef long long ll;
typedef vector<vector<int>> Graph;

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

    ll n,m;cin>>n>>m;
    Graph g(n);
    for(int i=0;i<m;i++){
        int a,b;cin>>a>>b;a--;b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vector<int> v(n,-1); // -1:not visited
    ll res=n*(n-1)/2-m;
    bool f = true;
    queue<int> q;
    v[0]=0;
    q.push(0);
    while(!q.empty()){
        int p=q.front();q.pop();
        int col=v[p];
        for(int i=0;i<(int)g[p].size();i++){
            int next=g[p][i];
            if(v[next]==-1){
                v[next]=1-col;
                q.push(next);
            }
            else if(v[next]+col==1) continue;
            else{
                f=false;
            }
        }
    }
    if(!f){
        cout<<res<<endl;
        return 0;
    }
    ll cnt=0;
    for(int i=0;i<n;i++) if(v[i]) cnt++;
    //cout<<cnt<<endl;
    res -= cnt*(cnt-1)/2;
    cnt = n-cnt;
    res -= cnt*(cnt-1)/2;
    cout<<res<<endl;
}


Measured memory_bytes: 6272
n, m = [int(a) for a in input().split()]

S = [[int(i) for i in input().split()[1:]] for _ in range(m)]

mask = [sum([2 ** (x-1) for x in s]) for s in S]

p = [int(a) for a in input().split()]




count = 0
for j in range(2**n):
    for i in range(m):
        on_switch = [int(k) for k in list(format(j & mask[i], 'b'))]
        if not sum(on_switch) % 2 == p[i]:
            count -= 1
            break
    count += 1

print(count)


Measured memory_bytes: 3064
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))

from collections import Counter

n = readint()
a = readints()
q = readint()

count = Counter(a)
s = sum(a)

ans = []
for _ in range(q):
    b,c = readints()
    s += (c-b) * count[b]
    ans.append(s)
    count[c] += count[b]
    count[b] = 0
printrows(ans)




Measured memory_bytes: 102516
#include<bits/stdc++.h>
#define ll long long
#define clr(x,i) memset(x,i,sizeof(x))
using namespace std;
const int N=1005;
const ll mod=1e9+7;
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*10+ch-'0',ch=getchar();}
    return x*f;
}
int n,m,k,s[11][N],pos[11],f[11][N],g[11][N],sum[11];
char str[11][N];
int calc(int len)
{
	int ret=0;
	for(int i=0; i<len; i++) for(int j=1; j<=m; j++) if(f[i][j]>k) return 1e9;
	clr(sum, 0);
	for(int j=1; j<=m; j++){
		int vis=0;
		for(int i=0; i<len; i++) if(sum[i]+f[i][j]>k) vis=1;
		if(vis) {
			ret++;
			for(int i=0; i<len; i++) sum[i]=f[i][j];
		}
		else for(int i=0; i<len; i++) sum[i]+=f[i][j];
	}
	return ret;
}
int main()
{
	n=read(),m=read(),k=read();
	int tot=0;
	for(int i=0; i<n; i++){
		scanf("%s",str[i]+1);
		for(int j=1; j<=m; j++) s[i][j]=(str[i][j]=='1');
	}
	int ans=1e9;
	for(int i=0; i<(1<<n-1); i++){
		int num=0; clr(f, 0);
		for(int j=0; j<n-1; j++) if((1<<j)&i) pos[++num]=j;
		pos[0]=-1; pos[num+1]=n-1;
		for(int j=0; j<=num; j++){
			for(int k=pos[j]+1; k<=pos[j+1]; k++)
				for(int l=1; l<=m; l++) f[j][l]+=s[k][l];
		}
		ans=min(ans, num+calc(num+1));
	}
	printf("%d\n",ans);
	return 0;
}

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

const int M = 100000;

int main() {
	int N;
	cin >> N;
	int a[M];
	for (int i = 0;i<N;i++) cin >> a[i];

	//値ごとにカウント
	int c[M + 1];
	for (int j = 0;j < M + 1;j++) c[j] = 0;

	for (int i = 0;i<N;i++) {
		c[a[i]]++;
	}
	int ans;
	for (int j = 0;j <= M - 2;j++) {
		int k = c[j] + c[j + 1] + c[j + 2];
		if (k>ans) {
			ans = k;
		}
	}
	cout << ans;
}

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

int main() {
    int n, m;
    cin >> n >> m;
    set<int> OR;
    set<int> AND;
    set<int> a;
    set<int> b;
    for(int i = 1; i <= n; i++) {
        int in;
        cin >> in;
        a.insert(in);
        OR.insert(in);
    }
    for(int i = 1; i <= m; i++) {
        int in;
        cin >> in;
        OR.insert(in);
        if(a.find(in) != a.end()) AND.insert(in);
    }
    cout << AND.size() << " " << OR.size() << endl;
    for(auto itr = AND.begin(); itr != AND.end(); itr++) {
        cout << *itr << endl;
    }
    for(auto itr = OR.begin(); itr != OR.end(); itr++) {
        cout << *itr << endl;
    }
    return 0;
}


Measured memory_bytes: 20008
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

s = 0
for i in range(len(A)):
    s += B[i - 1]
    if i < len(A) - 1:
        if A[i] + 1 == A[i + 1]:
            s += C[A[i] - 1]

print(s)


Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<algorithm>
const int N=1e5+5;
int n;
typedef std::pair<int,int> P;
P p[N];
int b[N];
struct Node {
    int v,id;
    bool operator < (const Node &b) const {
        if(v!=b.v) return v<b.v;
        return id<b.id;
    }
}a[N];
bool vis[N];
int main() {
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&p[i].second);
    for(int i=1;i<=n;i++) scanf("%d",&p[i].first);
    std::sort(p+1,p+1+n);
    bool f=true;
    for(int i=1;i<=n;i++) {
        a[i].v=p[i].second;
        a[i].id=i;
        b[i]=p[i].first;
    }
    int cnt=0;
    std::sort(a+1,a+1+n);
    for(int i=1;i<=n;i++) {
        if(a[i].v>b[i]) return !printf("No");
    }
    for(int i=1;i<=n;i++) {
        int j=a[i].id;
        if(vis[j]) continue;
        ++cnt;
        while(!vis[j]) {
            vis[j]=true;
            j=a[j].id;
        }
    }
    if(cnt==1) {
        f=false;
        for(int i=2;i<=n;i++) if(a[i].v<=b[i-1]) f=true;
    }
    printf("%s",f?"Yes":"No");
    return 0;
}


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

using namespace std;
#define rep(i, n) for(int i = 0 ; i < (int)(n) ; i++)
typedef long long ll;
typedef long double Double;

#ifndef INPUTS_DIR
#define INPUTS_DIR "./"
#endif


struct UnionFind {
    vector<int> data;

    UnionFind(int size) : data(size, -1) {}

    bool unionSet(int x, int y) {
        x = root(x);
        y = root(y);
        if (x != y) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }

    bool findSet(int x, int y) {
        return root(x) == root(y);
    }

    int root(int x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }

    int size(int x) {
        return -data[root(x)];
    }
};


void solve(ll N, ll M, vector<ll> p, vector<ll> x, vector<ll> y) {
    UnionFind uf(N);
    for (int i = 0; i < M; i++) {
        x[i]--, y[i]--;
        uf.unionSet(x[i], y[i]);
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
        p[i]--;
        if (uf.findSet(p[i], i)) ans++;
    }
    cout << ans << endl;
}


void main_(istream &cin) {
    ll N;
    ll M;
    cin >> N;
    vector<ll> p(N - 1 + 1);
    cin >> M;
    vector<ll> y(M - 1 + 1);
    vector<ll> x(M - 1 + 1);
    for (int i = 0; i <= N - 1; i++) {
        cin >> p[i];
    }
    for (int i = 0; i <= M - 1; i++) {
        cin >> x[i];
        cin >> y[i];
    }
    solve(N, M, p, x, y);
}

int main() {
#ifdef INTELLIJ
    ifstream ifs(string(INPUTS_DIR) + "in_1.txt");
    if (ifs.is_open()) {
        main_(ifs);
        ifs.close();
    } else {
        cerr << "Error: no input." << endl;
    }
#else
    ios::sync_with_stdio(false);
    cin.tie(0);
    main_(cin);
#endif
}





Measured memory_bytes: 5376
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  map<string, int> mp;
  FOR(i,0,n){
      string s;
      int x;
      cin >> s >> x;
      mp[s] += x;
  }
  FOR(i,1,6){
    for(auto m : mp){
      if(m.first.length() == i) cout << m.first <<  " " << m.second << endl;
    }
  }
}


Measured memory_bytes: 3200
;; -*- coding: utf-8 -*-
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(defmacro dbg (&rest forms)
  #+swank
  (if (= (length forms) 1)
      `(format *error-output* "~A => ~A~%" ',(car forms) ,(car forms))
      `(format *error-output* "~A => ~A~%" ',forms `(,,@forms)))
  #-swank (declare (ignore forms)))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(declaim (inline println))
(defun println (obj &optional (stream *standard-output*))
  (let ((*read-default-float-format* 'double-float))
    (prog1 (princ obj stream) (terpri stream))))

(defconstant +mod+ 1000000007)

;; Body

(defun main ()
  (let* ((s (coerce (read-line) 'simple-base-string))
         (data (make-array 26 :element-type 'uint32 :initial-element 0)))
    (map () (lambda (c) (incf (aref data (- (char-code c) 97)))) s)
    (println (- (+ 1 (floor (* (length s) (- (length s) 1)) 2))
                (reduce #'+ data
                        :key (lambda (x) (floor (* x (- x 1)) 2)))))))

#-swank(main)



Measured memory_bytes: 20836
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N, K;
  cin >> N >> K;
  vvvl DP = VVVL(N + 2, N + 2, N * N + 2, 0);
  DP[0][0][0] = 1;
  FOR(i, 1, N + 1) REP(j, N) REP(k, N * N + 1) {
    if (k - (2 * j) < 0)
      continue;
    if (j == 0) {
      DP[i][j][k] = (((2 * j + 1) * DP[i - 1][j][k - (2 * j)]) +
                     ((j + 1) * (j + 1) * DP[i - 1][j + 1][k - (2 * j)])) %
                    MOD;
    } else {
      DP[i][j][k] = (((2 * j + 1) * DP[i - 1][j][k - (2 * j)]) +
                     ((j + 1) * (j + 1) * DP[i - 1][j + 1][k - (2 * j)]) +
                     DP[i - 1][j - 1][k - (2 * j)]) %
                    MOD;
    }
  }
  cout << DP[N][0][K] << endl;

  return 0;
}


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

const int N = 1000005;

int n, m, head[N], tot;
struct edge { int to, nxt; } e[N << 1];
void link(int x, int y) {
	e[++tot] = (edge) { y, head[x] }, head[x] = tot;
	e[++tot] = (edge) { x, head[y] }, head[y] = tot;
}

int id[N], f[N], newid[N], dis[N];
std::vector<std::pair<int, int>> g[N];

int find(int x) { return x == f[x] ? x : f[x] = find(f[x]); }

int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::cin >> n >> m; int tot = n;
	for (int i = 0, x, y, z; i < m; ++i)
		std::cin >> x >> y >> z, g[z].emplace_back(x, y);
	for (int c = 1; c <= 1000000; ++c) {
		static std::vector<int> p; p.clear();
		for (auto e : g[c]) p.emplace_back(e.first), p.emplace_back(e.second);
		std::sort(p.begin(), p.end()), p.resize(std::unique(p.begin(), p.end()) - p.begin());
		for (int i = 0; i < p.size(); ++i) id[p[i]] = i, f[i] = i;
		for (auto e : g[c]) f[find(id[e.first])] = find(id[e.second]);
		for (int i = 0; i < p.size(); ++i) if (i == find(i)) newid[i] = ++tot;
		for (int i = 0; i < p.size(); ++i) link(p[i], newid[find(i)]);
	}
	std::queue<int> q; std::memset(dis, -1, sizeof dis), q.push(1), dis[1] = 0;
	while (q.size()) {
		int tmp = q.front(); q.pop();
		for (int i = head[tmp]; i; i = e[i].nxt)
			if (dis[e[i].to] == -1) dis[e[i].to] = dis[tmp] + 1, q.push(e[i].to);
	}
	std::cout << (dis[n] >> 1) << '\n';
	return 0;
}

Measured memory_bytes: 51456
import java.util.*;
public class Main {
public static void main(String args[])
{
  Scanner sp=new Scanner(System.in);
    int n=sp.nextInt();
    int ar[]=new int[n];
    int sc=0;
    int sn=0;
    int pre=0;
    for(int i=0;i<n;i++)
    {
      ar[i]=sp.nextInt();
    }
    for(int i=0;i<n;i++)    
    {
      
       if(pre==ar[i])
          {
              pre=ar[i];
          }
      if(pre<ar[i])
      {
          
        ar[i]-=1;
        pre=ar[i];

      }
      else{
        
        pre=ar[i];
        
      }
    }
    
    pre=0;

    
      for(int i=0;i<n;i++)
    {
      if(pre<=ar[i])
      {
        pre=ar[i];
      }
      else{
        sc++;
      }
    }
    if(sc>0)
    {
System.out.print("No");
    }
    else{
    System.out.print("Yes");
    }

}
}


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

int main()
{
    char s;
    cin>>s;
    if(s=='C')cout<<'G';
    else if(s=='G')cout<<'C';
    else if(s=='A')cout<<'T';
        else if(s=='T')cout<<'A';
    return 0;
}



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

#include <climits>
#include <cmath>
#include <cstring>

#include <iomanip>

using namespace std;

#define FAST       			ios_base :: sync_with_stdio(false); cin.tie(NULL); 
#define endl "\n"

typedef long long int  ll;
typedef unsigned long long int ull;

int g[9][9];

int main()
{
	FAST;
	
    memset(g , 0 , sizeof(g));
	int n,edge;
	cin >> n >> edge;
	while(edge--)
	{
		int u,v;
		cin >> u >> v;
		g[u-1][v-1] = g[v-1][u-1] = 1;
	}
	
	vector<int> a(n);
	for(int i=0 ; i<n ; i++)
	    a[i] = i;
	
	int ans = 0;
	do
	{
	    bool ok = true;
	    for(int i=0 ; i<n-1 ; i++)
	    {
	        if(!g[a[i]][a[i+1]])    ok = false;
	    }
	    if(ok)  ans++;
	}while(next_permutation(a.begin()+1 , a.end()) );

	cout << ans;
	return 0;
}

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

#define endl             '\n' 
#define pii              pair <int,int>
#define pll              pair <long long,long long>
#define sc               scanf
#define pf               printf
#define Pi               2*acos(0.0)
#define ms(a,b)          memset(a, b, sizeof(a))
#define pb(a)            push_back(a)
#define MP               make_pair
#define db               double
#define ll               long long
#define EPS              10E-8
#define ff               first
#define ss               second
#define sqr(x)           (x)*(x)
#define D(x)             cout<<#x " = "<<(x)<<endl
#define VI               vector <int>
#define DBG              pf("Hi\n")
#define MOD              1000000007
#define CIN              ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define SZ(a)            (int)a.size()
#define sf(a)            scanf("%d",&a)
#define sfl(a)           scanf("%lld",&a)
#define sff(a,b)         scanf("%d %d",&a,&b)
#define sffl(a,b)        scanf("%lld %lld",&a,&b)
#define sfff(a,b,c)      scanf("%d %d %d",&a,&b,&c)
#define sfffl(a,b,c)     scanf("%lld %lld %lld",&a,&b,&c)
#define stlloop(v)       for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define loop(i,n)        for(int i=0;i<n;i++)
#define loop1(i,n)       for(int i=1;i<=n;i++)
#define REP(i,a,b)       for(int i=a;i<b;i++)
#define RREP(i,a,b)      for(int i=a;i>=b;i--)
#define TEST_CASE(t)     for(int z=1;z<=t;z++)
#define PRINT_CASE       printf("Case #%d: ",z)
#define LINE_PRINT_CASE  printf("Case %d:\n",z)
#define CASE_PRINT       cout<<"Case "<<z<<": "
#define all(a)           a.begin(),a.end()
#define intlim           2147483648
#define infinity         (1<<28)
#define ull              unsigned long long
#define gcd(a, b)        __gcd(a, b)
#define lcm(a, b)        ((a)*((b)/gcd(a,b)))
 
using namespace std;
 
 
const int fx[]= {+1,-1,+0,+0};
const int fy[]= {+0,+0,+1,-1};
// const int N = 1e5 + 5;
#define piii pair<int, pair<int,int> >

const int N = 1e6 + 5;
vector<int> G[N],aux;
int arr[N*2],occ[N],vis[N];
int main(){
  // CIN;
  int t,n,i,j,k,a,b;
  while(cin >> a >> b)
  {
    string x="Yes",y="No";
    cout << (a==b?x:y) << endl;
  }
}

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

int main() {
  int n,m,r;
  cin>>n>>m>>r;
  int vec[r];
  for(int i=0;i<r;i++){
    cin>>vec[i];
  }
  ll path[n][n];
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(i==j){
        path[i][j]=0;
      }
      else{
        path[i][j]=1e10;
      }
    }
  }
  int a,b;
  ll c;
  for(int i=0;i<m;i++){
    cin>>a>>b>>c;
    a--;
    b--;
    path[a][b]=min(path[a][b],c);
    path[b][a]=min(path[a][b],path[b][a]);
  }
  for(int k=0;k<n;k++){
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
        path[i][j]=min(path[i][j],path[i][k]+path[k][j]);
      }
    }
  }    
  vector<int> one_case;
  for(int i=0;i<r;i++){
    one_case.emplace_back(i);
  }
  ll ans=1e10,p=0;
  do{
    p=0;
    for(int i=0;i<r-1;i++){
      p+=path[vec[one_case.at(i)]-1][vec[one_case.at(i+1)]-1];
    }
    ans=min(ans,p);
  }while(next_permutation(one_case.begin(),one_case.end()));
  cout<<ans<<endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<string.h>
#define ll long long
using namespace std;

char a[10010];

int main()
{
    ll n;
    cin>>n;
    cin>>a;
    ll p=0,q=0,r=0,x=0,y=0,z=0;
    for(ll i=n-1;i>=0;i--){
        if(a[i]=='B') r++;
        if(a[i]=='R') p++;
        if(a[i]=='G') q++;
    }
    ll ans=0;
    for(int i=0;i<n;i++){
        if(a[i]=='B') r--,z++;
        if(a[i]=='R') p--,x++;
        if(a[i]=='G') q--,y++;
        if(a[i]=='R'){
            ans+=y*r+z*q;
            for(int j=0;j<i;j++){
                if(i-j+i>=n) continue;
                if(a[j]!=a[i-j+i]&&a[j]!='R'&&a[i-j+i]!='R') ans--;
            }
        }
        if(a[i]=='G'){
            ans+=p*z+x*r;
            for(int j=0;j<i;j++){
                if(i-j+i>=n) continue;
                if(a[j]!=a[i-j+i]&&a[j]!='G'&&a[i-j+i]!='G') ans--;
            }
        }
        if(a[i]=='B'){
            ans+=p*y+x*q;
            for(int j=0;j<i;j++){
                if(i-j+i>=n) continue;
                if(a[j]!=a[i-j+i]&&a[j]!='B'&&a[i-j+i]!='B') ans--;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int solve(ll a, ll b) {
    ll l = 0, r = 1LL << 31, mv = a * b - 1;
    if (a == b) return (2 * a - 2);
    while((l + 1) < r) {
        ll m = (l + r) / 2;
        ll val = ((m + 1) / 2) * ((m + 1) - (m + 1) / 2);
        if (val > mv) {
            r = m;
        }
        else {
            l = m;
        }
    }
    return l - 1;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int q;
    cin >> q;
    rep(i, q) {
        ll a, b;
        cin >> a >> b;
        cout << solve(a, b) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;
bool check(int n) {
    return 1 <= n && n <= INF;
}
signed main(void) {
    int N; cin >> N;
    VI p(N);
    REP(i, N) scanf("%d", &p[i]);
    VI a(N), b(N);
    VI sum(N);
    REP(i, N) {
        sum[p[i] - 1] = INF - N + i - 1;
    }
    int cnt = 0;
    REP(i, N) {
        a[i] = i + 1 + cnt;
        b[i] = sum[i] - a[i];
        if (i == 0) continue;
        while (a[i] <= a[i - 1] || b[i] >= b[i - 1]) {
            a[i]++;b[i]--;cnt++;
        }
        assert(check(a[i]) && check(b[i]));
    }
    for_each(ALL(a), [](int e){printf("%d ", e);});
    printf("\n");
    for_each(ALL(b), [](int e){printf("%d ", e);});
    printf("\n");
}


Measured memory_bytes: 896
// マージソート
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>

using namespace std;

#define MAX_N 500000
const int INFTY = 2147483647;

int cmp_count = 0;

void mergeSort(int A[], int left, int right);
void merge(int A[], int left, int mid, int right);

int main(void)
{
    int A[MAX_N];
    int n;

    scanf("%d", &n);

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

    // マージソートを実施
    mergeSort(A, 0, n);

    // 結果の表示
    for(int i = 0; i < n; i++)
    {
        if( i )
        {
            printf(" ");
        }

        printf("%d", A[i]);
    }

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

    return 0;
}

// マージソートを実施する関数
void mergeSort(int A[], int left, int right)
{
    // 最小単位まで分割する
    if ( left + 1 < right )
    {
        int mid = ( left + right ) / 2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
  }

  return;
}

// 分割された要素を並び替える関数
void merge(int A[], int left, int mid, int right)
{

    vector<int> L, R;

    int n1 = mid - left;
    int n2 = right - mid;

    // L[0...n1], R[0...n2] を生成
    for(int i = 0; i < n1; i++)
    {
        // 前半部分の配列を作成する
        L.push_back(A[left + i]);
    }

    for(int i = 0; i < n2; i++)
    {
        // 後半部分の配列を作成する
        R.push_back(A[mid + i]);
    }

    // 前半と後半の配列の最後の要素に最大値を入れておく
    // ( 比較時の番兵として使用 )
    L.push_back(INFTY);
    R.push_back(INFTY);

    int i = 0;
    int j = 0;

    for(int k = left; k < right; k++)
    {
        // 前半部分の配列と後半部分の配列を比較する
        if ( L[i] <= R[j] )
        {
            A[k] = L[i];
            i = i + 1;
        }
        else
        {
            A[k] = R[j];
            j = j + 1;
        }

        cmp_count++;
    }
}



Measured memory_bytes: 7348
import java.io.PrintWriter
val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val (a, b, k) = listOfInt()
    val nn = mutableListOf<Int>()

    repeat(k) {
        if (a + it <= b) nn.add(a + it)
        if (b - it >= a) nn.add(b - it)
    }

    nn.distinct().sorted().forEach(::println)
}

fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { it.toInt() }

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 37996
#include <bits/stdc++.h>
typedef long long ll;

#define pll pair<ll,ll>
#define ff first
#define snd second
#define pb push_back
#define vll vector<ll>
#define vpll vector<pll>
#define endl "\n"
#define MOD 1000000007
using namespace std;

ll const N = 1e5+1;

ll exponentMod(ll A, ll B)  
{  
    // Base cases  
    if (A == 0)  
        return 0;  
    if (B == 0)  
        return 1;  
  
    // If B is even  
    ll y;  
    if (B % 2 == 0) {  
        y = exponentMod(A, B / 2);  
        y = (y * y) % MOD;  
    }  
  
    // If B is odd  
    else {  
        y = A % MOD;  
        y = (y * exponentMod(A, B - 1) % MOD) % MOD;  
    }  
  
    return ((y + MOD) % MOD);  
}

void solve()
{
   ll n,k;
   cin>>n>>k;
   ll dp[k+1];
   ll count = 0;
   memset(dp,0,sizeof(dp));
   ll ans = 0;
   for(ll i=k;i>=2;i--)
   {
        ll p = (k/i);
        dp[i] = (dp[i] + exponentMod(p,n))%MOD;
        ll j = i + i;
        while(j<=k)
        {
                dp[i] = (dp[i] - dp[j] + MOD)%MOD;
                j = j+i;
        }
        count = (count + dp[i])%MOD;
        ll temp = (dp[i]* i)%MOD;
        ans = (ans + temp)%MOD;
   }
   
   ll p = exponentMod(k,n)%MOD;
   p = (p - count + MOD)%MOD;
   ans = (ans + p)%MOD;
   
   cout<<ans;
}
 
int main() {
            ios_base::sync_with_stdio(false);
            cin.tie(NULL);
	    int t=1;
	    //cin>>t;
	    while(t--)
	    {
	            solve();
	    }
	    return 0;
}

Measured memory_bytes: 4360
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
    int A, B;
    char op;
    cin >> A >> op >> B;

    if(op == '+') cout << A+B << endl;
    else cout << A-B << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x)+modulo)%modulo)
#define Inf 10000000000000000


int main(){
	
	int N;
	cin>>N;
	
	vector<vector<long long>> a(N,vector<long long>(N,0));
	
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			cin>>a[i][j];
		}
	}
	
	vector<vector<int>> ind(N+1,vector<int>());
	
	vector<long long> num(1<<N,0LL);
	
	for(int i=0;i<(1<<N);i++){
		vector<int> X;
		for(int j=0;j<N;j++){
			if((1<<j)&i){
				X.push_back(j);
			}
		}
		ind[X.size()].push_back(i);
		
		for(int j=0;j<X.size();j++){
			for(int k=j+1;k<X.size();k++){
				num[i] += a[X[j]][X[k]];
			}
		}
	}
	
	vector<long long> dp(1<<N,-Inf);
	dp[0] = 0;
	
	for(int i=1;i<=N;i++){
		for(int j=0;j<ind[i].size();j++){
			int x = ind[i][j];
			do{
				dp[ind[i][j]] = max(dp[ind[i][j]],dp[x]+num[x^ind[i][j]]);
				x = (x-1)&ind[i][j];
			}
			while(x!=ind[i][j]);
		}
	}
	
	cout<<dp.back()<<endl;
	
    return 0;
}


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

int main(){
	const int INF=1<<29;
	for(int n;scanf("%d",&n),n;){
		vector<pair<int,int> >v(n+1);
		vector<vector<int> >m(n+1);
		for(int i=0;i<=n;i++){
			if(i)scanf("%d%d",&v[i].first,&v[i].second);
			m[i].resize(4),fill(m[i].begin(),m[i].end(),INF);
		}
		m[0][0]=0;
		int i=0;
		for(;i<n;i++){
			int f=0,j=0;
			for(;j<4;j++)if(m[i][j]<INF){
				int dist=abs(v[i+1].first-v[i].first),dt=v[i+1].second-v[i].second;
				if(j<3&&dist*(j+1)<=dt)f=m[i+1][j+1]=min(m[i+1][j+1],m[i][j]+dist);
				if(v[i+1].first+v[i].first*(j+1)<=dt)f=m[i+1][1]=min(m[i+1][1],m[i][j]+v[i+1].first+v[i].first);
			}
			if(!f)break;
		}
		if(i<n){
			printf("NG %d\n",i+1);
		}else{
			int r=INF;
			for(int i=0;i<4;i++)r=min(r,m[n][i]+v[n].first);
			printf("OK %d\n",r);
		}
	}
}

Measured memory_bytes: 1036
#include <cstdio>
using namespace std;
int main() {
    int n, m, t, sum, avg;
    for (; ;){
        scanf("%d %d", &n, &m);
        if (n == 0 && m == 0) break;
        avg = m/n, sum = 0;
        for (int i = 0; i < n; i++) {
            scanf("%d", &t);
            if (t >= avg) sum+=avg;
            else sum+= t;
        }
        printf("%d\n", sum);
    }
    return 0;
}



Measured memory_bytes: 2692
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
#define INF 1e9
#define showVector(v) rep(i,0,v.size()){p(v[i]);p(" ")} pl("")
#define p(s) std::cout << s ;
#define pl(s)  std::cout << s << endl;
using namespace std;

// 素数判定 O(√n)
bool is_prime(int n){
    for(int i = 2; i * i <= n; i++){
        if(n % i == 0) return false;
    }
    return true;
}

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

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;
}
int main() {
    string S;
    cin >> S;
    rep(i, 0, S.length()) {
        S[i] = 'x';
    }
    cout << S << endl;
    return 0;
}

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

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
		int a = Integer.parseInt(sc.next());
      	int b = Integer.parseInt(sc.next());
      	int c = Integer.parseInt(sc.next());
      System.out.println(c+" "+a+" "+b);
    }
}

Measured memory_bytes: 22100
#include <bits/stdc++.h>
using namespace std;
 
signed main() {
  int n;
  cin >> n;
  int a[100] = {0};
  double sum;
  for(int i = 0; i < n; i++){
    cin >> a[i];
    sum += a[i];
  }
  int minIndex = 0;
  double avr = sum / n;
  double minDist = abs(avr - a[0]);
  for(int i = 1; i < n; i++){
    if(minDist > abs(avr - a[i])){
      minIndex = i;
      minDist = abs(avr - a[i]);
    }
  }
  cout << minIndex << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

int main(int argc, char **argv) {
	ll a[4], n;
	REP(i, 4) cin >> a[i];
	cin >> n;
	ll c[4];
	a[2] = min(a[2], a[0] * 4);
	a[2] = min(a[2], a[1] * 2);
	cout << (n / 2 * min(a[3], a[2] * 2) + n % 2 * a[2]) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <map>
 
using namespace std;
 
int main(int argc, char** argv) {
  int n, r;
  cin >> n >> r;
  if (n < 10) {
    cout << r + 100 * (10 - n) << endl;
  } else {
    cout << r;
  }
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.AGC_046
{
    class A
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int x = ReadInt();
            long lcm = LCM(x, 360);
            WriteLine(lcm / x);
        }

        static long GCD(long a, long b)
        {
            if (b > a)
            {
                long temp = b;
                b = a;
                a = temp;
            }
            long c = b;
            do
            {
                c = a % b;
                a = b;
                b = c;
            } while (c > 0);
            return a;
        }

        static long LCM(long a, long b)
        {
            long c = GCD(a, b);
            return a * b / c;
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 27488
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using pll = pair<ll, ll>;
using edge = pair<int, ll>;
using Graph = vector<vector<int>>; 
using WeightedGraph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main(){
int a,b;char c;
cin >> a >> c >> b;
int ans = a+b;
if(c=='-')ans = a-b;
cout << ans << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<iostream>
using namespace std;
const int MOD = 1000037;
struct node{
	string s1, s2;
	long long key;
};
vector<node>Hash[MOD];
inline void Hash_Insert(string s1, string s2) {
	string s3 = s1 + s2;
	int h = 0, len = s3.size();
	for(int i=0;i<len;i++)
		h = (h * 131 + s3[i] - 'a' + 1) % MOD;
	for(int i=0;i<Hash[h].size();i++) {
		if( Hash[h][i].s1 == s1 && Hash[h][i].s2 == s2 ) {
			Hash[h][i].key++;
			return ;
		}
	}
	node p;p.s1 = s1, p.s2 = s2, p.key = 1;
	Hash[h].push_back(p);
}
inline long long Hash_Search(string s1, string s2) {
	string s3 = s1 + s2;
	int h = 0, len = s3.size();
	for(int i=0;i<len;i++)
		h = (h * 131 + s3[i] - 'a' + 1) % MOD;
	for(int i=0;i<Hash[h].size();i++)
		if( Hash[h][i].s1 == s1 && Hash[h][i].s2 == s2 )
			return Hash[h][i].key;
	return 0;
}
string S;
int main() {
	int N;
	scanf("%d", &N);
	cin >> S;
	int t = (1<<N) - 1;
	for(int s=0;s<=t;s++) {
		string s1 = "", s2 = "";
		for(int i=0;i<N;i++) {
			if( (1<<i) & s )
				s1.insert(s1.end(), S[i]);
			else s2.insert(s2.begin(), S[i]);
		}
		Hash_Insert(s1, s2);
	}
	long long ans = 0;
	for(int s=0;s<=t;s++) {
		string s1 = "", s2 = "";
		for(int i=0;i<N;i++) {
			if( (1<<i) & s )
				s1.insert(s1.end(), S[i+N]);
			else s2.insert(s2.begin(), S[i+N]);
		}
		ans += Hash_Search(s2, s1);
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 59904
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 100000000000000009
#define int long long
using P = pair<int,int>;

signed main(){
    int n,m;
    cin >> n >> m;
    int ans = 0;
    n -= m;
    ans++;
    while(n > 0){
        n -= m-1;
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;
struct UnionFind
{
    vector<int> Parent;
    UnionFind(int n)
    {
        Parent=vector<int>(n,-1);
    }
    
    int root(int a)
    {
        if(Parent[a]<0) return a;
        return root(Parent[a]);
    }
    
    int size(int a)
    {
        return -Parent[root(a)];
    }
    
    bool connect(int a,int b)
    {
        if(root(a)==root(b)) return false;
        if(size(a)<size(b)) swap(a,b);
        Parent[root(a)]-=size(b);
        Parent[root(b)]=root(a);
        return true;
    }
};
int main()
{
  int n,m,k;
  cin>>n>>m>>k;
  UnionFind friends_all(n);
  vector<vector<int>> friends_direct(n),block(n);
  for (int i = 0; i < m; ++i)
  {
    int a,b;
    cin>>a>>b;
    a--;b--;
    friends_direct[a].push_back(b);
    friends_direct[b].push_back(a);
    friends_all.connect(a,b);
  }
  for (int i = 0; i < k; ++i)
  {
    int c,d;
    cin>>c>>d;
    c--;d--;
    block[c].push_back(d);
    block[d].push_back(c);
  }

  for (int i = 0; i < n; ++i)
  {
    int ans=friends_all.size(i);
    for(const auto& e: block[i]) 
    {
      if(friends_all.root(i)==friends_all.root(e)) ans--;
    }
    for(const auto& e: friends_direct[i]) 
    {
      if(friends_all.root(i)==friends_all.root(e)) ans--;
    }
    ans--;
    cout<<ans<<" ";
  }
}

Measured memory_bytes: 12152