akhauriyash/Code-Regression huggingface dataset:
// Problem : C - Subarray Sum
// Contest : AtCoder - Keyence Programming Contest 2020
// URL : https://atcoder.jp/contests/keyence2020/tasks/keyence2020_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

//Macros

#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define inf 1e10
#define PI acos(-1.0)
#define int long long
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 100005

//Solution

void solve(){
    int n,k,s;
    cin>>n>>k>>s;
    if(s == 1e9){
        for(int i=0;i<k;i++) cout<<1000000000<<' ';
        for(int i=0;i<n-k;i++) cout<<1<<' ';
    } else {
        for(int i=0;i<k;i++) cout<<s<<' ';
        for(int i=0;i<n-k;i++) cout<<s+1<<' ';
    }
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int tests;
    //cin>>tests;
    tests = 1;
    while(tests--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3620
h,w,k=map(int,input().split())
L=[0]*w
f=1
past=0
for i in range(h):
    s=list(input())
    for j in range(w):
        if '#' not in s:
            L.append(L[i*w+j])
        else:
            if s[j]=='.':
                L.append(f)
            else:
                if past==1:
                    f += 1
                else:
                    past=1
                L.append(f)
            if j==w-1:
                f += 1
                past=0

L=L[w:(h+1)*w]
zero=L.count(0)
z=zero//w
for i in range(w):
    num=L[zero+i]
    for j in range(z):
        L[i+j*w]=num

for i in range(h):
    ans=L[w*i:w*(i+1)]
    ans=[str(x) for x in ans]
    print(' '.join(ans))

Measured memory_bytes: 7340
int main()
{
	int n;
	int i, j,k;
	char d[100];
	int cnt = 0;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &d[i]);
	}
	for (j = 0; j < n; j++) {
		for (k = j + 1; k < n; k++) {
			cnt += d[j] * d[k];
		}
	}
	printf("%d", cnt);
	return 0;

}

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

int main()
{
    int K, N, O, i;
    cin >> N >> K;
    i = 0;
    O = 1;
    while (i < N)
    {
        i++;
        if (2 * O > O + K)
        {
            O += K;
        }
        else
        {
            O *= 2;
        }
    }
    cout << O << endl;
}

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

// m<10^4 ？
// n<100  ？

int main(){
	int n,m,cut;
	while(cin>>n>>m>>cut && n&&m){
		vector<int> dp(n*m+1,0), tmp(n*m+1,0);
		dp[0]=1;


		for(int i=1; i<=n; i++){
			// サイコロ：i個

			for(int j=(i*m); j>=i; j--){
				// サイコロi個で出せる目の値：j

				for(int k=1; k<=m; k++){
					// サイコロの目：1~m
					// サイコロ1個抜いてみた値：(j-k)
					if(j-k>=0){
						// j-k が出せる
						// そうなら、当然 j も出せる
						tmp[j] += dp[j-k];
						// tmpに一時退避させておく
					}
				}
			}

			for(int j=0; j<=i*m; j++){
				// 一時退避させといたやつをdpに戻す
				dp[j]=tmp[j];
				tmp[j]=0;
			}
		}

		// dp[i] : n個のサイコロの目の合計値が(i)になる場合の数

		double under=0, over=0;
		for(int i=1; i<=n*m; i++){
			under += dp[i];
			over += dp[i] * max(i-cut,1);
		}

		printf("%.8lf\n",over/under);
	}

	return 0;
}



Measured memory_bytes: 3296
// 基本テンプレート (縮小版)

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
typedef pair<int, int> pii;
typedef long long ll;
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int N, M;
map<pii, int> id;
vector<int> stations[100010];
vector<pii> G[1500010];
int dist[1500010];
int cnt = 0;

int getId(int p, int a) {
    pii pr = make_pair(p, a);
    if(id.count(pr)) return id[pr];
    else return id[pr] = cnt++;
}

signed main() {
    cin >> N >> M;
    rep(i,0,M) {
        int p, q, c; cin >> p >> q >> c;
        p--; q--;
        int u = getId(p, c), v = getId(q, c);
        G[u].push_back(make_pair(v, 0));
        G[v].push_back(make_pair(u, 0));
        stations[p].push_back(c);
        stations[q].push_back(c);
    }
    rep(i,0,N) {
        rep(j,0,stations[i].size()) {
            int cmp = stations[i][j];
            int u = getId(i, cmp), v = getId(i, 0);
            G[u].push_back(make_pair(v, 0));
            G[v].push_back(make_pair(u, 1));
        }
    }

    rep(i,0,500010) dist[i] = INF;
    int init = getId(0, 0), goal = getId(N-1, 0);
    priority_queue< pii, vector<pii>, greater<pii> > q;
    dist[init] = 0;
    q.push(make_pair(0, init));
    while(!q.empty()) {
        pii t = q.top();
        q.pop();
        int cur = t.second, cost = dist[cur];
        for(auto to : G[cur]) {
            if(dist[to.first] > dist[cur] + to.second) {
                dist[to.first] = dist[cur] + to.second;
                q.push(make_pair(dist[to.first], to.first));
            }
        }
    }
    cout << (dist[goal] == INF ? -1 : dist[goal]) << endl;
}

Measured memory_bytes: 115320
#include<stdio.h>
#include<string.h>

int main(void){
  int n;
  int d1[101],d2[101];
  scanf("%d",&n);

  int flag = 0;
  for(int i = 0;i<n;i++){
   scanf("%d %d",&d1[i],&d2[i]); 
    if(d1[i]==d2[i]) flag++;
    else flag = 0;
    if(flag == 3){
     printf("Yes");
      return 0;
    }
  }
  
  printf("No");
  return 0;
}

Measured memory_bytes: 1732
/*by freesteed*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define pb push_back
#define fill(x,c) memset(x,c,sizeof(x))
#define fi first
#define se second
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define caset int ___T; cin>>___T; for(int cs=1;cs<=___T;cs++)
#define get_be(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
//get_be biger & equal
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
const ll mod=1e9+7;
const ll oo=1e9+10;
const int Max = 1e6+10;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll a[Max];
ll n;
void solve(){
	cin>>n;
	double tol=0,t;
	rep(i,0,n){
		cin>>t;
		tol+=(1.0/t);
	}
	cout<<1.0/tol;
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//caset{
		solve();
	//}
  	return 0;
}





Measured memory_bytes: 256
#include <iostream>
using namespace std;
char p[105][105];
int main()
{
    int h, w;
    cin >> h >> w;
    for ( int i = 1; i <= h; i++ )
    {
        for ( int j = 1; j <= w; j++ )
        {
            cin >> p[i][j];
        }
        for ( int k = 1; k <= w; k++ )
        {
            cout << p[i][k];
        }
        cout << "\n";
        for ( int l = 1; l <= w; l++ )
        {
            cout << p[i][l];
        }
        cout << "\n";
    }
}

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

int main(){

    int n;
    cin>>n;

    for(int i=1;true;i++){
        int a=i;
        int cnt=0;
        for(int j=1;j<=a;j++){
            if(a%j==0)cnt++;
        }
        if(cnt==n){
            cout<<a<<endl;
            break;
        }
    }
}

Measured memory_bytes: 1160
import sys
"""
方針：まず左端を固定して実際にPで割ったあまりを計算しながら数値列を伸ばしていけばO(N^2)で計算ができる
文字列の左右を固定した場合に（部分文字列について？）Pで割ったあまりを計算できないか，定式化を考えてみよう．
Ui := S[i:N]をSのi文字以降を評価した整数と置く．便宜上UN+1=0とする．
この時Sのi文字目からj文字目までを評価した整数は(Ui - Uj+1)/10^(j+1-i)と表せる．

"""

sys.setrecursionlimit(10 ** 6)
readline = sys.stdin.readline
read = sys.stdin.read

n, p = [int(i) for i in readline().split()]
s = input()

if p == 2 or p == 5:
    ans = 0
    for i, c in enumerate(s):
        if int(c) % p == 0:
            ans += i + 1
    print(ans)
    exit()


res = [0] * p
res[0] = 1
t = 1
now = 0
for i in s[::-1]:
    i = int(i)
    now += i * t
    now %= p
    res[now] += 1
    t = t * 10 % p
    


ans = 0
for i in res:
    ans += i * (i - 1) // 2

print(ans)



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

int main(){
	string s;

	while ( getline(cin,s) ){
		for (int i=0 ; i<s.size() ; i++){
			if ( s[i]>='a' && s[i]<='z'){
				s[i] = s[i] + ('A'-'a');
			}
		}
		cout << s << endl;
	}
}

Measured memory_bytes: 1168
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

#define P 1000000007
#define N_MAX 10000000
typedef long long int ll;
ll fac[N_MAX+1];
ll inv[N_MAX+1];
ll finv[N_MAX+1];

ll comb(ll n, ll k){
  if(n<0||k<0||n<k) return 0;
  return (((fac[n]*finv[n-k])%P)*finv[k])%P;
}

void init(){
  fac[0] = finv[0] = fac[1] = finv[1] = inv[1] = 1;
  for(int i = 2; i <= N_MAX; i++){
    fac[i] = (fac[i-1]*i)%P;
    inv[i] = ((-(P/i)*inv[P%i])%P+P)%P;
    finv[i] = (finv[i-1]*inv[i])%P;
  }
}
ll pp(ll a, ll b){
  return (a * b)%P;
}
ll perm(ll n, ll k){
  if(n<0||k<0||n<k) return 0;
  return (fac[n]*finv[n-k])%P;
}

int main(int argc, char const *argv[]) {
  init();
  ll n, m;std::cin >> n >> m;
  vll f(1000000, 0);
  ll al = (perm(m, n) * perm(m, n))%P;
  ll sub = 0;

  for(int i=1;i<=n;i++){//被るものがi個
    ll x = perm(m, i);
    ll y = (perm(m-i, n-i) * perm(m-i, n-i))%P;
    ll tmp = pp(comb(n, i), (x*y)%P);
    //std::cout << i << " " << tmp << '\n';
    if(i%2) sub = (sub + tmp)%P;
    else sub = (sub - tmp + P)%P;
  }

  //std::cout << al << '\n';
  std::cout << (al - sub + P)%P << '\n';
  return 0;
}


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

int main() {
	int N;
	cin >> N;
	for (int i = 1; i <= 9; i++) {
		if (N % i == 0 && N / i <= 9) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}

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

using namespace std;

typedef long long ll;

int main() {
    ll n;   cin >> n;
    ll *d = new ll[n];
    for (int i = 0; i < n; i++)
        cin >> d[i];


    if (d[0] != 0) {
        cout << 0 << endl;
        return 0;
    }

    
    sort(d, d+n);

    ll *cnt = new ll[n];
    for (int i = 0; i < n; i++)
        cnt[i] = 0;
    for (ll i = 0; i < n; i++) {
        cnt[d[i]]++;
    }
    
    for (ll i = 0; i < n-1; i++) {
        if (d[i] + 1 < d[i+1]) {
            cout << 0 << endl;
            return 0;
        }
    }

    ll i = 0, c = 0;
    while (i < n && cnt[i++])
        c++;

    if (cnt[0] != 1) {
        cout << 0 << endl;
        return 0;
    }

    ll ans = 1;

    for (int i = 0; i < c-1; i++) {
        if (cnt[i] > 0) {
            for (int j = 0; j < cnt[i+1]; j++) {
                ans *= cnt[i];
                ans %= 998244353;
            }
        }
    }

    cout << ans << endl;
    return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  ll a,b,c,d;cin>>a>>b>>c>>d;
  ll result = a*c;
  result = max<ll>(result, a*d);
  result = max<ll>(result, b*c);
  result = max<ll>(result, b*d);
  if(a<=0 && b>=0)result = max<ll>(result, 0);
  if(c<=0 && d>=0)result = max<ll>(result, 0);

  cout<<result<<endl;

  return 0;
}

Measured memory_bytes: 3672
#include<bits/stdc++.h>
using namespace std;
char P[100001][110];
int main()
{
	long long int N,M=0,A=0,R=0,C=0,H=0;
	scanf("%lld",&N);
	for(int i=0;i<N;i++)
	    {
	    	scanf("%s",P[i]);
	    	if(P[i][0]=='M') M++;
	    	if(P[i][0]=='A') A++;
	    	if(P[i][0]=='R') R++;
	    	if(P[i][0]=='C') C++;
	    	if(P[i][0]=='H') H++;
		}
	long long int sum=0;
	sum=(M*A*R+M*A*C+M*A*H+M*R*C+M*R*H+M*C*H+A*R*C+A*R*H+R*C*H+A*C*H);
	printf("%lld\n",sum);
	return 0;
 } 

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int n, w; std::cin >> n >> w;
  vector<ll> dp(w+1);
  rep(i, n) {
    int wi, v; std::cin >> wi >> v;
    ddrep(j, w) {
      if (j-wi < 0) continue;
      chmax(dp[j], dp[j-wi]+v);
    }
  }
  std::cout << dp[w] << "\n";
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()

using namespace std;

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

int nextInt() {int a; cin >> a; return a;}
char nextChar() {char a; cin >> a; return a;}
double nextDouble() {double a; cin >> a; return a;}
string nextString() {string a; cin >> a; return a;}

void inputVector(vector<int> &v, int &n) {rep(i,n){v.push_back(nextInt());}}
void inputVector(vector<double> &v, int &n) {rep(i,n){v.push_back(nextDouble());}}
void inputVector(vector<string> &v, int &n) {rep(i,n){v.push_back(nextString());}}

signed main() {
    int n;
    while (cin >> n) {
	if (!n) break;

	vector<pair<int, int>> gems;
	rep(i, n) {
	    int x, y;
	    cin >> x >> y;
	    if (x == 10 && y == 10) continue;
	    gems.push_back(make_pair(x, y));
	}

	int x = 10;
	int y = 10;

	int m;
	cin >> m;
	rep(i, m) {
	    char c;
	    int len;
	    cin >> c >> len;

	    rep(j, len) {
		if (c == 'N') y++;
		if (c == 'E') x++;
		if (c == 'W') x--;
		if (c == 'S') y--;
		rep(k, gems.size()) {
		    if (x == gems[k].first && y == gems[k].second) {
			gems.erase(gems.begin() + k);
			break;
		    }
		}
	    }
	}

	cout << (gems.size() ? "No" : "Yes") << endl;
    }

    return 0;
}

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N,M;
int A[101];
vector<int>v;
vector<int>vv;
vector<int>ans;
int main(){
    cin>>N>>M;
    REP(i,M){
        cin>>A[i];
        if(A[i]%2==0){
           v.push_back(A[i]);
        }else{
           vv.push_back(A[i]);
        }
    }
    if(M==1){
       if(A[0]==1){
          cout<<1<<endl;
          cout<<1<<endl;
          cout<<1<<endl;
       }else{
          cout<<A[0]<<endl;
          cout<<2<<endl;
          cout<<A[0]-1<<" "<<1<<endl;
       }
    }else if(M==2){
       cout<<A[0]<<" "<<A[1]<<endl;
       if(A[0]==1){
          cout<<1<<endl;
          cout<<A[1]+1<<endl;
       }else{
          cout<<2<<endl;
          cout<<A[0]-1<<" "<<A[1]+1<<endl;
       }
    }else if(vv.size()>=3){
       cout<<"Impossible"<<endl;
    }else{
       if(vv.size()>=1){
          ans.push_back(vv[0]);
       }
       REP(i,v.size()){
          ans.push_back(v[i]);
       }
       if(vv.size()==2){
          ans.push_back(vv[1]);
       }
       
       REP(i,ans.size()){
           cout<<ans[i];
           if(i!=ans.size()-1){
              cout<<" ";
           }else{
              cout<<endl;
           }
       }
       if(ans[0]==1){
          cout<<ans.size()-1<<endl;
       }else{
          cout<<ans.size()<<endl;
          cout<<ans[0]-1<<" ";
       }
       REP(i,ans.size()){
           if(i==0){
              continue;
           }else if(i==ans.size()-1){
              cout<<ans[i]+1<<endl;
           }else{
              cout<<ans[i]<<" ";
           }
       }
    }
    return(0);
}

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

int main() {
    int n; cin >> n;
    vector<vector<pair<int, int>>> xy(n);
    for (int i = 0; i < n; i++)
    {
        int a; cin >> a;
        for (int j = 0; j < a; j++)
        {
            int x, y; cin >> x >> y;
            x--;
            xy[i].emplace_back(x, y);
        }
    }

    int ans = 0;
    for (int bit = 0; bit < (1<<n); bit++) {
        int tmp = 0;
        bool ok = true;
        for (int i = 0; i < n; i++)
        {
            if (bit & (1<<i)) {
                tmp++;
                for (auto v : xy[i]) {
                    int x = v.first, y = v.second;
                    if (y == 1) {
                        if (!(bit & (1<<x))) ok = false;
                    } else if (y == 0) {
                        if (bit & (1<<x)) ok = false;
                    }
                }
            }
        }
        if (ok) {
            ans = max(ans, tmp);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
const int N = 1005;
int gi()
{
	int x=0,w=1;char ch=getchar();
	while ((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if (ch=='-') w=0,ch=getchar();
	while (ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return w?x:-x;
}
int n,dp[5][N],a[5][N];
int main()
{
	n=gi();
	for (int i=1;i<=2;i++)
		for (int j=1;j<=n;j++)
			a[i][j]=gi();
	for (int i=1;i<=2;i++)
		for (int j=1;j<=n;j++)
			dp[i][j]=max(dp[i-1][j],dp[i][j-1])+a[i][j];
	printf("%d\n",dp[2][n]);
}

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

using namespace std;

void solve()
{
	int a, b;
	cin >> a >> b;
	
	cout << 6 - a - b << '\n';
}

main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int t = 1;
//	cin >> t;

	while(t--)
	{
		solve();
	}
}

Measured memory_bytes: 256
#include <iostream>


using namespace std;

int main()
{
	while(true)
	{
		int H, W;
		cin >> H >> W;
		if(H == 0 && W == 0)
		{
			return 0;
		}
		for(int j = 0; j < W; ++j)
		{
			cout << "#";
		}
		cout << endl;
		for(int i = 0; i < H - 2; ++i)
		{
			cout << "#";
			for(int j = 0; j < W - 2; ++j)
			{
				cout << ".";
			}
			cout << "#" << endl;
		}
		for(int j = 0; j < W; ++j)
		{
			cout << "#";
		}
		cout << endl << endl;
	}
	return 0;
}


Measured memory_bytes: 2996
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;

int main(){
    long long n;
    cin >> n;

    vector<long long> a(n);

    for(long long i = 0; i < n; i++) cin >> a[i];

    
    long long money = 1000;
    long long cnt = 0;
    long long num;
    for(long long i = 0; i < n; i++){
        if(i + 1 < n and a[i] < a[i+1]){
            num = money/a[i];
            cnt += num;
            money -= num*a[i];
        }
        else if(i + 1 < n and a[i] > a[i+1]){
            money += cnt*a[i];
            cnt = 0;
        }
    }

    cout << money + cnt*a[n-1] << endl;
    return 0;
}

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

int main(){
    int n, k;
    cin >> n >> k;
    int a[n];
    for (int i = 0; i < n; ++i){
        a[i] = 0;
    }

    int num;
    int y;
    for (int i = 0; i < k; ++i){
        cin >> num;
        for (int x = 0; x < num; ++x){
            cin >> y;
            a[y-1]+=1;
        }
    }

    int count = 0;
    for (int i = 0; i < n; ++i){
        if (a[i]==0){
            count+=1;
        }
    }

    cout << count << endl;
}


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

#define endl '\n'

void solve(){
    int n; cin >> n;
    n %= 10;
    if (n == 3) cout << "bon\n";
    else if (n == 0 || n == 1 || n == 6 || n == 8) cout << "pon\n";
    else cout << "hon\n";
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t=1; //cin >> t;
    while(t--) solve();
}

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

int N, K;
int A[110];
int dp[100100];

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

    std::cin >> N >> K;

    for(int i=0;i<N;++i){
        std::cin >> A[i];
    }

    for(int i=0;i<K;++i){
        if(dp[i] > 0){
            continue;
        }
        
        for(int j=0;j<N;++j){
            if(i + A[j] <= K){
                dp[i + A[j]] = 1;
            }
        }
    }

    if(dp[K] == 0){
        std::cout << "Second" << std::endl;
    }else{
        std::cout << "First" << std::endl;
    }
}


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

int main(){

    int N,M;
    cin >> N>>M;
    vector<int>A(N);

    for (int i = 0; i < N; i++) cin >>A.at(i);
    
    int sumAll =0;
    for (int a :A) sumAll += a;
    
    int cnt = 0;
    for (int a :A){
     
        if ( a < sumAll/(double)(4*M) ){

        } else{
            cnt ++;
        }

    }

    if (cnt >= M) {
        cout << "Yes" <<endl;
    }else{
     cout << "No" <<endl;
    }    
}




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

int main() {
    int n;
    cin >> n;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++) cin >> a[i];
    vector<int> box(n + 1, 0), res;
    for (int i = n; i > 0; i--) {
        int t = 0;
        for (int j = i; j <= n; j += i) t += box[j];
        if (t % 2 != a[i] % 2) {
            box[i]++;
            res.push_back(i);
        }
    }
    reverse(res.begin(), res.end());
    cout << res.size() << endl;
    for (auto e : res) {
        cout << e << " ";
    }
    cout << endl;
    return 0;
}

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

using namespace std;

#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)

typedef long long ll;
typedef long double ld;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

template<typename T>
T modpower(T a, T n, T mod) {
    T res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    ll res = 0;
    int n, p, len;
    string s;
    cin >> n >> p >> s;
    if (p == 2 || p == 5) {
        int cnt = 0;
        rep (i, n) {
            if ((s[i] - '0') % p == 0) res += i + 1;
        }
        cout << res << endl;
        return 0;
    }
    reverse(s.begin(), s.end());
    vector<int> m(n + 1);
    rep (i, n) m[i + 1] = (s[i] - '0') * (modpower(10, i, p)) % p;
    FOR (i, 1, n + 1) {
        m[i] += m[i - 1];
        m[i] %= p;
    }
    map<int, int> mp;
    rep (i, n + 1) {
        res += mp[m[i]];
        mp[m[i]]++;
    }
    cout << res << endl;
     
    return 0;
}



Measured memory_bytes: 1684
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define INF = numeric_limits<long long>::max();
#define intf int_fast64_t
int main(){
    intf a,b,cnt=0;
    cin >>a >>b;

    for(int i=a;i<b+1;i++){
        if(i/10000==i%10 && (i%10000)/1000==(i%100)/10){
            cnt++;
        }
    }
    cout << cnt <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define N 1000
#define M 1000000007
#define f(i, a, b) for (ll i = (ll)a; i <= (ll)b; i++)
#define rf(i, a, b) for (ll i = (ll)a; i >= (ll)b; i--)
#define po pop_back
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define mp make_pair
#define bs binary_search
#define debug(x) cout << #x << " = " << x << endl
#define ub upper_bound
#define ibs ios_base::sync_with_stdio(false)
#define cti cin.tie(0)
#define all(x) x.begin(), x.end()
#define PI 3.14159265
#define cot cout.tie(0)
using namespace std;
/**
  * @author :: Rishabh
  *
  */
int main()
{
	ibs;
	cti;
	int d,t,s;
	cin>>d>>t>>s;
	double x=double(d)/double(t);
	if(double(s)>=x)
	cout<<"Yes\n";
	else
	cout<<"No\n";
	return 0;
}

Measured memory_bytes: 3648
N, K = [int(a) for a in input().strip().split()]
P = []

P.append(0)
P.append(N-K+1)
for i in range(1, K+1):
    P.append(P[i] * (K - i) * (N - K + 1 - i) // (i * (i + 1)))

for i in range(1, K+1):
    print(P[i]%1000000007)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;

using f80 = long double;
using f64 = double;
using i64 = long long;
using pii = pair<int, int>;

int n, a, b;

int main() {
#ifdef HOME
	freopen("agc.in", "r", stdin);
	freopen("agc.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	cin >> n >> a >> b;

	if ((a + b) % 2 == 0)
		cout << "Alice\n";
	else
		cout << "Borys\n";

	return 0; }


Measured memory_bytes: 256
n = int(input())
for i in range(n):
    x1,y1,x2,y2,x3,y3,x4,y4=map(float,input().split())
    print("YES" if abs((y2-y1)*(x4-x3)-(x2-x1)*(y4-y3)) < 1e-10 else "NO")

Measured memory_bytes: 7604
def f(v,i):s,n=4*2**v-3,2*2**v-1;m=s/2+1;return 0 if(i<1)+(i>s)else[0,f(v-1,i-1),n/2+1,f(v-1,i-m)+n/2+1,n,1][(i>1)+(i>=m)+(i>m)+(i>=s)+(v==0)*3]
print f(*map(int,raw_input().split()))

Measured memory_bytes: 2568
len, qs = gets.split.map(&:to_i)
a = false
s = gets.chomp
is_ac = len.times.map{|i|
    ac = 0
    if a && s[i] == 'C'
        ac = 1
    end
    a = s[i] == 'A'
    ac
}[1..-1]
sums = is_ac.inject([0]){|acc, it| acc.push(acc[-1] + it)}

qs.times{|it|
    s, e = gets.split.map(&:to_i)
    puts sums[e - 1] - sums[s - 1]
}


Measured memory_bytes: 4476
(* Vicfred
 * https://atcoder.jp/contests/abc079/tasks/abc079_a
 * implementation
 * *)
Scanf.scanf "%s\n" (fun s ->
    if s.[1] = s.[2] && (s.[0] = s.[1] || s.[2] = s.[3]) then "Yes" else "No"
) |> print_endline



Measured memory_bytes: 3724
#include <iostream>
#include <algorithm>
#include <cstdio>

using namespace std;

int main(void){
    char data[9];
    int max,min;
    int src;
    int n,i,j,k;
    
    cin>>n;
    for(i=0;i<n;i++){
        cin>>data;
        sort(data,data+8);
        min=0;
        max=0;
        j=1;
        for(k=0;k<8;k++){
            min+=(int)(data[7-k]-'0')*j;
            max+=(int)(data[k]-'0')*j;
            j=j*10;
        }
        src=max-min;
        cout<<src<<endl;
    }
    return(0);
}

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

int arr[200000];
int asum[200000];
 
int main() {
  int N, Q;
  string S;
 
  cin >> N >> Q >> S;

  for (int i = 0; i < N - 1; i++) {
    if (S[i] == 'A' && S[i + 1] == 'C') arr[i] = 1;
  }
  
  for (int i = 1; i < N + 1; i++) {
    asum[i] = arr[i - 1] + asum[i - 1];
  }

  for (int i = 0; i < Q; i++) {
    int l, r;
    cin >> l >> r;
    cout << asum[r - 1] - asum[l - 1] << endl;
  }
}


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

int main()
{
        int size;
        cin >> size;
        vector<int> x(size);
//      cout << "input: "; 
        for (int i=0; i<size; ++i){
                cin >> x[i];
//              cout << x[i] << " ";
        }
//      cout << endl;
        // maximum increment 
        int maximum_increment = x[1] - x[0];
//      if (size == 2) {
//              cout << maximum_increment << endl;
//              return 0;
//      }
        int min = x[0];
        int max = x[0];
        for (int i=1; i<size; ++i) {
                if (x[i] < min) {
                        min = x[i];
                        max = min;
                        continue;
                }
                if (x[i] > max) {
                        max = x[i];
                }
                if (max - min > maximum_increment) {
                        maximum_increment = max - min;
                }
        }   
        cout << maximum_increment << endl;
        return 0;
}



Measured memory_bytes: 3532
N = int(input())
kurai_1 = N % 10
hon_yomi = {
    0:'pon',
    1:'pon',
    2:'hon',
    3:'bon',
    4:'hon',
    5:'hon',
    6:'pon',
    7:'hon',
    8:'pon',
    9:'hon'
}
print(hon_yomi[kurai_1])

Measured memory_bytes: 9068
N = int(input())
list = [int(i) for i in input().split()]

y = None
is_OK = True
for i, h in enumerate(list):
  if i == 0:
    y = h
  if h > y:
    y = h - 1
  if h < y:
    is_OK = False

if is_OK:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 14252
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <stdio.h>
#include <iomanip>

//#include <map>

using namespace std;

void spritStr(string str, vector<string>& v)
{
	while (str.find(' ') != -1)
	{
		v.push_back(str.substr(0, str.find(' ')));
		str.erase(0, str.find(' ') + 1);
	}
	v.push_back(str);
}

int main()
{
	string st;
	getline(cin, st);

	vector<string> vStr;
	spritStr(st, vStr);

	unsigned long a, b, ansI, ansM;
	double ansD = 0.0;
	a = stol(vStr[0]);
	b = stol(vStr[1]);

	ansI = a / b;
	ansM = a % b;
	ansD = static_cast<double>(a) / static_cast<double>(b);

	cout << ansI << " " << ansM << " " << fixed << setprecision(8) << ansD << endl;

	return 0;
}

Measured memory_bytes: 3300
h, w = map(int, input().split())
result = []

while (h and w):
    result.append((h, w))
    h, w = map(int, input().split())

for item in result:
    for i in range(0, item[0]):
        for j in range(0, item[1]):
            print('#', end = '')
        print()
    
    print()


Measured memory_bytes: 7008
A_1 = list(map(int, input().split()))
A_2 = list(map(int, input().split()))
A_3 = list(map(int, input().split()))
A = A_1 + A_2 + A_3
check = [0 for i in range(9)]
n = int(input())
for i in range(n):
  b = int(input())
  if b in A:
    check[A.index(b)] += 1
c_1 = check[0] + check[3] + check[6]
c_2 = check[1] + check[4] + check[7]
c_3 = check[2] + check[5] + check[8]
c_4 = check[0] + check[1] + check[2]
c_5 = check[3] + check[4] + check[5]
c_6 = check[6] + check[7] + check[8]
c_7 = check[0] + check[4] + check[8]
c_8 = check[2] + check[4] + check[6]
c = [c_1,c_2,c_3,c_4,c_5,c_6,c_7,c_8]
if 3 in c:
  print('Yes')
else:
  print('No')

    

Measured memory_bytes: 9260
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

long long n, m, mm;
vector<vector<pair<int, int>>> adj;
vector<vector<int>> edgelist;
vector<long long> edgeid;

vector<bool> touched;

map<long long, long long> dfs(int id) {
	touched[id] = true;
	map<long long, long long> ans, v, vv, c;
	int i, j, k;

	bool hasson = false;

	for (auto p : adj[id]) {
		if (!touched[p.first]) {
			v = dfs(p.first);

			if (!hasson) {
				//first
				hasson = true;
				for (auto a : v) {
					ans[a.first] += a.second;
					ans[a.first | edgeid[p.second]] += a.second;
				}
			}
			else {
				vv.clear();
				for (auto a : v) {
					vv[a.first] += a.second;
					vv[a.first | edgeid[p.second]] += a.second;
				}

				c.clear();
				swap(c, ans);
				for (auto a : vv) {
					for (auto b : c) {
						ans[a.first | b.first] += a.second * b.second;
					}
				}
			}
		}
	}

	if (!hasson) ans[0]++;

	return ans;
}

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

	int i, j, k, a, b;
	cin >> n;
	adj.resize(n + 1);
	for (i = 0; i < n - 1; i++) {
		cin >> a >> b;
		adj[a].push_back({ b, i });
		adj[b].push_back({ a, i });
	}

	cin >> m;
	edgelist.resize(m);
	edgeid.assign(n, 0);
	for (i = 0; i < m; i++) {
		cin >> a >> b;

		vector<bool> used(n + 1, false);
		vector<vector<int>> e(n + 1);
		queue<int> q;
		q.push(a);
		used[a] = true;

		while (!q.empty()) {
			int id = q.front();
			q.pop();

			for (auto p : adj[id]) {
				if (!used[p.first]) {
					used[p.first] = true;
					e[p.first] = e[id];
					e[p.first].push_back(p.second);
					q.push(p.first);
				}
			}
		}

		edgelist[i] = e[b];
		for (auto p : e[b]) {
			edgeid[p] += 1LL << i;
		}
	}

	mm = 1LL << m;
	map<long long, long long> ans;
	touched.assign(n + 1, false);
	ans = dfs(1);

	cout << ans[mm - 1] << "\n";

	return 0;
}


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


def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, m=1, typ=int):
    return [read_h() if m > 1 else typ(input()) for _ in range(n)]


def main():
    c = read_v(n=3, m=3)

    # Assume a_1 = 0 without loss of generality
    a = [0, 0, 0]
    b = c[0]
    for i in (1, 2):
        a[i] = c[i][0] - b[0]

    # Check if Takahashi is correct
    for i in range(3):
        for j in range(3):
            if c[i][j] != a[i] + b[j]:
                print('No')
                return

    print('Yes')


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <limits.h>

#define ll long long

using namespace std;

int main(){

    int n,l;

    cin >> n >> l;

    int sum = 0;
    int a = INT_MAX;

    for(int i = 1; i <= n; i++){
        sum = sum + l + i - 1;
        a = min(abs(a), abs(l + i - 1));
        if(l + i - 1 < 0) a = -1 * a;
    }

    cerr << a << endl;

    cout << sum - a << endl;

    return 0;
}       

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

using namespace std;

typedef long long ll;
typedef long double Double;

bitset<1024> dp[1024];

bitset<1024> masks[10];
bitset<1024> inv_masks[10];

bool f(string s) {
    for (auto &c : s) if (c == 'u') c = ' ';
    stringstream ss(s);

    memset(dp, 0, sizeof(dp));
    vector<string> vs;
    string t;

    while (ss >> t) vs.push_back(t);


    set<pair<int, int> > itms;

    for (auto t : vs) {
        int lock = 0;
        for (int i = 0; i < t.size(); i++) {
            itms.insert({lock, t[i] - '0'});
            if (lock >> (t[i] - '0') & 1) {
                return false;
            }
            lock |= (1 << (t[i] - '0'));
        }
    }
    dp[0][0] = true;

    for (auto itm : itms) {
        for (int locked = 0; locked < 1024; locked++) {
            int new_locked = locked | itm.first;
            if ((locked & itm.first) == 0) {
                const int shift = (1 << itm.second);
                bitset<1024> compress =
                        (dp[locked]) | ((dp[locked] & masks[itm.second]) >> shift);
                dp[new_locked] |= (compress & masks[itm.second]) | ((compress & inv_masks[itm.second]) << shift);
            }
        }
    }
    for (int i = 1; i < 1024; i++) {
        int j = i;
        while (j) {
            if (dp[i][j]) {
                return false;
            }
            j = (j-1) & i;
        }
    }
    return true;
}

int main() {
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 1024; j++) {
            masks[i][j] = j / (1 << i) % 2;
            inv_masks[i][j] = !masks[i][j];
        }
    }
    int n;
    while (cin >> n && n) {
        string s;
        cin >> s;
        cout << (f(s) ? "SAFE" : "UNSAFE") << endl;
    }
}


Measured memory_bytes: 3428
import java.*;
import java.io.*;
import java.util.*; 
 
public class Main
{
	public static void main(String args[]) throws Exception{
		new Main().run();
	}
	
	final int MAX = 500000;
	boolean dp[] = new boolean[MAX];
	int[] primes = new int[MAX];
	int count = 0;
	
	public void run()
	{
		int i,j;
		dp[0] = dp[1] = true;
		for(i=2;i<MAX;i++){
			if(!dp[i] && (i%7==1 || i%7==6)){
				primes[count++] = i;
				for(j=i+i;j<MAX;j+=i){
					dp[j] = true;
				}
			}
		}
		Scanner cin=new Scanner(System.in);
		while(true){
			int num = cin.nextInt();
			if(num==1) return;
			System.out.print(num + ":");
			boolean flag = false;
			for(i=0;i<count;i++){
				if(num%primes[i]==0){
					System.out.print(" " + primes[i]);
				}
			}
			System.out.println();
		}
	}
	
}

Measured memory_bytes: 15000
#include <stdio.h>
#include <math.h>

int main() {
  double x1, y1, x2, y2, d;
  scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
  d = sqrt(pow(x1-x2, 2) + pow(y1-y2, 2));
  printf("%lf\n", d);

  return 0;
}

Measured memory_bytes: 652
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,m;
int a[100001],b[100001];
bool used[100001];
vector<int> G[100001];
vector<int> res;
vector<int> res2;

void dfs(int v){
	used[v]=true;
	res.push_back(v);
	for(int i=0;i<G[v].size();i++){
		if(!used[G[v][i]]){
			dfs(G[v][i]);
			break;
		}
	}
}

void dfs2(int v){
	used[v]=true;
	res2.push_back(v);
	for(int i=0;i<G[v].size();i++){
		if(!used[G[v][i]]){
			dfs2(G[v][i]);
			break;
		}
	}
}

int main(void){
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		scanf("%d%d",&a[i],&b[i]);
		a[i]--;
		b[i]--;
		G[a[i]].push_back(b[i]);
		G[b[i]].push_back(a[i]);
	}
	used[a[0]]=true;
	used[b[0]]=true;
	dfs(b[0]);
	dfs2(a[0]);
	printf("%d\n",res.size()+res2.size());
	for(int i=(int)res2.size()-1;i>=0;i--){
		printf("%d%c",res2[i]+1,' ');
	}
	for(int i=0;i<res.size();i++){
		printf("%d%c",res[i]+1,i+1==res.size()?'\n':' ');
	}
	return 0;
}


Measured memory_bytes: 10232
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
using LP=pair<ll,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;

//c

int main() {
    int N;
    cin>>N;
    vector<ll> A(N);
    rep(i,N)cin>>A.at(i);
    ll ans=0;
    ll before=0;
    rep(i,N){
        if(A.at(i)>=before){
            before=A.at(i);
        }
        else{
            ans+=before-A.at(i);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4768
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

typedef long long ll;

struct K {
  int lb, ub, x;
  int id;
};


int ts[200000+10];
K ks[200000+10];
bool operator>(const K& k1, const K& k2) {
  return k1.x > k2.x;
}

struct E {
  int type;
  int id;
  int getT(void) const {
    if(type == 0) return ks[id].lb - ks[id].x;
    if(type == 1) return ks[id].ub - ks[id].x;
    return ts[id];
  }
};
bool operator<(const E& e1, const E& e2) {
  int t1 = e1.getT();
  int t2 = e2.getT();
  if(t1 != t2) return t1 < t2;
  if(e1.type != e2.type) {
    if(e1.type == 0) return true;
    if(e2.type == 0) return false;
    if(e1.type == 1) return true;
    if(e2.type == 1) return false;
  }
  return e1.id < e2.id;
}

E es[600000+10];
int nE;

int ans[200000+10];
bool isValid[200000+10];

int main(void) {
  int n, nQuery;
  scanf("%d%d", &n, &nQuery);
  REP(i, n) {
    int s, t, x;
    scanf("%d%d%d", &s, &t, &x);
    ks[i] = {s*2-1, t*2-1, 2*x, i};
    es[nE++] = {0, i};
    es[nE++] = {1, i};
  }
  REP(i, nQuery) {
    scanf("%d", &ts[i]);
    ts[i] *= 2;
    es[nE++] = {2, i};
  }
  sort(es, es + nE);
  priority_queue<K, vector<K>, greater<K> > q;
  REP(i, nE) {
    E e = es[i];
    if(e.type == 0) {
      isValid[e.id] = true;
      q.push(ks[e.id]);
    } else if(e.type == 1) {
      isValid[e.id] = false;
    } else {
      int id = -1;
      while(!q.empty()) {
        K cur = q.top();
        if(isValid[cur.id]) {
          id = cur.id;
          break;
        } else {
          q.pop();
        }
      }
      if(id == -1) {
        ans[e.id] = -2;
      } else {
        ans[e.id] = ks[id].x;
      }
    }
  }
  REP(i, nQuery) {
    printf("%d\n", ans[i]/2);
  }
  return 0;
}


Measured memory_bytes: 14704
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
using ll = long long;
const ll mod = 1000000007;
const ll INF = 100000000000000000LL;
signed main(){
    int n,k;
    cin>>n>>k;
    int x[111];
    rep(i,n)cin>>x[i];
    int res = 0;
    rep(i,n)res+=min(k-x[i],x[i])*2;
    cout<<res<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
  
  int k,a,b; cin >> k >> a >> b;
  for(int i = a; i <= b; i++){
  if( i % k == 0){cout << "OK" << endl; return 0;}
  }
  cout << "NG" << endl;
 
    return 0;
}


Measured memory_bytes: 3560
if __name__ == '__main__':
    # ?????°??????????????\???
    scores = []
    while True:
        score = [int(x) for x in input().split(' ')]
        if score[0] == -1 and score[1] == -1 and score[2] == -1:
            break
        scores.append(score)

    # ?????°??????????????????????????????
    for s in scores:
        midterm_exam = s[0]
        final_exam = s[1]
        re_exam = s[2]
        if midterm_exam == -1 or final_exam == -1:
            grade = 'F'
        elif midterm_exam + final_exam >=80:
            grade = 'A'
        elif midterm_exam + final_exam >= 65:
            grade = 'B'
        elif midterm_exam + final_exam >= 50:
            grade = 'C'
        elif midterm_exam + final_exam < 30:
            grade = 'F'
        elif re_exam >= 50:
            grade = 'C'
        else:
            grade = 'D'
        print(grade)

Measured memory_bytes: 7664
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vector<int> p(n), q(n), v(n);
  rep(i, n) v[i] = i + 1;
  rep(i, n) cin >> p[i];
  rep(i, n) cin >> q[i];

  map<vector<int>, int> mp;

  do {
    mp[v] = mp.size();
  } while (next_permutation(v.begin(), v.end()));

  cout << abs(mp[p] - mp[q]);

  return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef double db;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pct __builtin_popcount

#define P 1000000007

#define N 200010
int f[N], g[N];

int n, m;
string s;

int main() {
	cin >> n >> m >> s;
	if (s[0] == 'B') {
		for (int i = 0; i < m; i ++)
			s[i] = 'R' + 'B' - s[i];
	}
	if (s == string(m, 'R')) {
		int fbb = 1, fbr = 0, frb = 0, frr = 1;
		for (int i = 1; i < n; i ++) {
			int gbb = fbr;
			int gbr = (fbb + fbr)%P;
			int grb = frr;
			int grr = (frr + frb)%P;
			fbb = gbb;
			fbr = gbr;
			frb = grb;
			frr = grr;
		}
		int S = ((ll)frr + fbr + frb)%P;
		cout << S << endl;
		return 0;
	}
	if (n%2 == 1) {
		puts ("0");
		return 0;
	}

	int l = n;
	for (int i = 0; i < m; ) {
		int j = i;
		while (j < m && s[j] == s[i]) j++;
		if (j == m) break;
		if ((j-i)%2 == 1) {
			if (s[i] == 'R') l = min(l, j-i);
		} else {
			if (i == 0) l = min(l, j+1);
		}
		i = j;
	}

	l = (l+1)/2;
	n /= 2;

	f[0] = 1;
	g[1] = 1;
	for (int i = 1; i <= n; i ++) {
		if (i <= l) f[i] = g[i]; else {
			f[i] = (g[i] - g[i-l]+P)%P;
		}
		g[i+1] = (g[i] + f[i])%P;
	}

	int S = 0;
	for (int i = 0; i < min(l, n); i ++) {
		int T = (g[n-i] - g[n-l]+P)%P;
		// f[n-i-1] + .. + f[n-l];
		(S += T) %= P;
	}

	S = (ll)S*2%P;
	cout << S << endl;
	return 0;
}


Measured memory_bytes: 1352
#include <bits/stdc++.h>
   
using namespace std;
     
#define PB(x) push_back(x)
#define ALL(x) (x).begin(), (x).end()
#define ALLR(x) (x).rbegin(), (x).rend()
#define MP(x) make_pair(x);
    
#define debug(x) cerr << #x << '=' << x << endl;
#define debug2(x, y) cerr << #x << '=' << x << ' ' << #y << '=' << y << endl;
#define debugn(a) for (int x: a) cerr << x << ' '; cerr << endl;
     
#define int long long
     
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<pair<int, int>> vii;
typedef vector<string> vs;
typedef unsigned long long ull;

const int INF = 1e13;
const int mmod = 1000000007;

int32_t main()
{	
	int n;
	cin >> n;
	int a[n], b[n], c[n-1];
	
	for (int& x: a) cin >> x;
	for (int& x: b) cin >> x;
	for (int& x: c) cin >> x;
	
	int ans = 0;
	int last_dish = -2;
	for (int i = 0; i < n; i++) {
		int dish = a[i]-1;
		ans += b[dish];
		if (last_dish + 1 == dish) ans += c[last_dish];
		last_dish = dish;
	}
	cout  << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,t;
    cin>>s>>t;
    int cnt=0;

    for(int i=0;i<3;i++)
    {
        if(s[i]==t[i])
            cnt++;
    }

    cout<<cnt<<endl;

    return 0;
}


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

using namespace std;

int main() {
  int n; cin >> n;
  vector<int> grid(n);
  for(int i=0;i<n;++i) cin >> grid[i];
  int m,a; cin >> m;
  for(int i=0;i<m;++i){
    cin >> a; a--;
    if(grid[a]+1!=grid[a+1] && grid[a]!=2019) grid[a]++;
  }
  for(int i=0;i<n;++i)
    cout << grid[i] << endl;

  return 0;
}



Measured memory_bytes: 3108