akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  int k, x;
  cin >> k >> x;
  for (int i = -1000000; i <= 1000000; i++) {
    if (-k < x-i && x-i < k) {cout << i << " ";}
  }
  cout << endl;
}

Measured memory_bytes: 256
/*
[nikkei2019-qual] D - Restore the Tree
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const int MAX_N = 1e5;

int N, M;
vector<int> g[MAX_N];
bool visited[MAX_N];
int last;
int dep[MAX_N];
int par_dep[MAX_N];
int par[MAX_N];

void dfs(int v) {
    if (visited[v]) {
        return;
    }
    visited[v] = true;

    for (int to : g[v]) {
        dfs(to);
    }
    dep[v] = last--;
}

void solve() {
    last = N;
    for (int i = 0; i < N; i++) {
        dfs(i);
    }

    fill(par, par + N, -1);
    for (int v = 0; v < N; v++) {
        for (int to : g[v]) {
            if (par_dep[to] < dep[v]) {
                par_dep[to] = dep[v];
                par[to] = v;
            }
        }
    }

    for (int i = 0; i < N; i++) {
        cout << par[i] + 1 << endl;
    }
}

int main() {
    cin >> N >> M;
    for (int i = 0; i < N - 1 + M; i++) {
        int a, b;
        cin >> a >> b;
        g[a - 1].push_back(b - 1);
    }

    solve();

    return 0;
}


Measured memory_bytes: 9728
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define ll long long
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB emplace_back
#define PF emplace_front
#define FILL(a,b) memset(a,b,sizeof(a))
#define lwb lower_bound
#define upb upper_bound
using namespace std;
int p[105][105][2],a[105][105];
int n,m;
int cost(bool x,int y){
	RE (!x&&y);
}
int dfs(int x,int y,bool color){
	if(x==n&&y==m)RE 0;
	if(p[x][y][color]!=-1)RE p[x][y][color];
	int re=1e5;
	if(x<n){
		if(a[x+1][y]){
			gmin(re,cost(color,1)+dfs(x+1,y,1));
		}else{
			gmin(re,cost(color,0)+dfs(x+1,y,0));
		}
	}
	if(y<m){
		if(a[x][y+1]){
			gmin(re,cost(color,1)+dfs(x,y+1,1));
		}else{
			gmin(re,cost(color,0)+dfs(x,y+1,0));
		}
	}
	RE p[x][y][color]=re;
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n>>m;
	char c;
	FOR(i,1,n){
		FOR(j,1,m){
			cin>>c;
			if(c=='#')a[i][j]=1;
		}
	}
	FILL(p,-1);
	if(a[1][1]){
		cout<<1+dfs(1,1,1);
	}else cout<<dfs(1,1,0);
	RE 0;
}




Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

void solve() {
    int n, k, p;
    cin >> n >> k;
    vector <int> am;
    vector <int> dig(10, 0);

    for (int i = 0; i < k; ++i) {
        int t;
        cin >> t;
        ++dig[t];
    }

    bool flag = false;
    int N = n;
    while (!flag) {
        n = N;
        flag = true;
        while (n > 0) {
            if (dig[n % 10]) {
                flag = false;
                n = 0;
                ++N;
            } else {
                n /= 10;
            }
        }
    }
    cout << N;
}

int main() {

    solve();
    return 0;
}


Measured memory_bytes: 3124
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m;i >= n;--i)
#define SORT(v, n) sort(v, v+n)
#define VSORT(v) sort(begin(v), end(v))
#define REV(v) reverse(begin(v), end(v))
#define VI vector<int>
#define PB(x) push_back(x)
#define SZ(x) end(x) - begin(x)
#define DEBUG(x) cerr << __LINE__ << ":" << #x << ": " << x << "\n";
//#define int long long
using namespace std;
using lint = long long;
struct Fast{Fast(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};} fast;
const int INF = INT_MAX;
const lint LINF = LLONG_MAX;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
inline void CO(auto &a) {REP(i, SZ(a)) cout << i << ": " << a[i] << "\n";}
//if (IO > 1e5){lint a;	scanf(%lld, &a);	printf("%lld\n", a);}

signed main(){
	int a,p;
	cin >> a >> p;
	cout << (a*3+p) / 2 << endl;
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int n,nxt[100005][2],cnt;
LL ans,l;
char s[100005];
inline void insert()
{
	int x=0;
	int len=strlen(s+1);
	for(int i=1;i<=len;i++)
	{
		if(!nxt[x][s[i]-'0'])
			nxt[x][s[i]-'0']=++cnt;
		x=nxt[x][s[i]-'0'];
	}
}
inline LL lowbit(LL x)
{
	return x&(-x);
}
inline LL dfs(int x,int d)
{
	if(!x&&d)
		return lowbit(l-d+1);
	return dfs(nxt[x][0],d+1)^dfs(nxt[x][1],d+1);
}
int main()
{
	scanf("%d%lld",&n,&l);
	for(int i=1;i<=n;i++)
		scanf("%s",s+1),insert();
	if(!dfs(0,0))
		printf("Bob");
	else
		printf("Alice");
}

Measured memory_bytes: 4224
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

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

	int n; cin >> n;
	int c1 = 0;
	vector<int> input(n); for (auto &i : input) cin >> i, c1 = max(c1, i);
	
	int c2 = 0;
	for (int i = 0; i < n; ++i) if (abs(c1 - input[i] * 2) < abs(c1 - c2 * 2)) c2 = input[i];

	cout << c1 << ' ' << c2 << endl;

	return 0;
}

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


#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(int x = (l);x<=(u);x++)
#define RREP(x,l,u) for(int x = (l);x>=(u);x--)
#define mst(x,a) memset(x,a,sizeof(x))
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define se second
#define fi first
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
#define cl(x) x.clear()

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;

const int maxn = 200010;
const int mod = 1e9+7;
const int MAX = 1000000010;
const double eps = 1e-6;
const double PI = acos(-1);

template<typename T> inline void read(T &x){
x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}

template<typename A,typename B> inline void read(A&x,B&y){read(x);read(y);}
template<typename A,typename B,typename C> inline void read(A&x,B&y,C&z){read(x);read(y);read(z);}
template<typename A,typename B,typename C,typename D> inline void read(A&x,B&y,C&z,D&w){read(x);read(y);read(z);read(w);}
template<typename A,typename B> inline A fexp(A x,B p){A ans=1;for(;p;p>>=1,x=1LL*x*x%mod)if(p&1)ans=1LL*ans*x%mod;return ans;}
template<typename A,typename B> inline A fexp(A x,B p,A mo){A ans=1;for(;p;p>>=1,x=1LL*x*x%mo)if(p&1)ans=1LL*ans*x%mo;return ans;}

int N,M,K;

int C[310][310],f[310][310],g[310][310];

void Work(){
	REP(i,1,K)f[1][i]=1;
	RREP(i,K,1)f[1][i]=(f[1][i]+f[1][i+1])%M;
	REP(i,1,K)g[1][i]=f[1][i];
	REP(i,0,K)g[0][i]=1;
	REP(i,2,N){
		REP(j,1,K)f[i][j]=g[i-1][j+1];
		RREP(j,K,1)f[i][j]=(f[i][j]+f[i][j+1])%M;
		REP(j,1,K)REP(k,1,i)g[i][j]=(g[i][j]+(ll)g[i-k][j]*f[k][j]%M*C[i-1][k-1])%M;
//		REP(j,1,K)printf("%d ",f[i][j]);puts("");
//		REP(j,1,K)printf("%d ",g[i][j]);puts("");
	}
	printf("%d\n",g[N][1]);
}

void Init(){
	read(N,K,M);
	C[0][0]=1;
	REP(i,1,N){
		C[i][0]=1;
		REP(j,1,i)C[i][j]=(C[i-1][j-1]+C[i-1][j])%M;
	}
}

int main(){
	Init();
	Work();
	return 0;
}


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

int main(){
    long long  h,w;
    cin >> h >>w;
    long long ans = 0;
    if(h == 1 || w == 1){
        ans = 1;
    }else if(h % 2 == 0 && w % 2 == 0){
        ans = h * w /2;
    }else if(h % 2 == 0 && w % 2 == 1){
        ans = (h * (w - 1) / 2) + h /2;
    }else if(h % 2 == 1 && w % 2 == 0){
        ans = ((h - 1) * w /2) + w/2;
    }else if(h % 2 == 1 && w % 2 == 1){
        ans = ((h - 1) * (w - 1) /2) + (h + 1)/2 + (w + 1)/2 -1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
// ABC154C - Distinct or Not

#include <bits/stdc++.h>
using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A.at(i);
	}

	sort(A.begin(), A.end());

	bool isFound = false;
	for (int i = 0; i < N - 1; i++) {
		if (A.at(i) == A.at(i + 1)) {
			isFound = true;
			break;
		}
	}

	if (isFound) {
		cout << "NO" << endl;
	} else {
		cout << "YES" << endl;
	}

	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <complex>
#include <set>
#include <map>

using namespace std;

int n, m;
long xyz[1001][3];

long getScore(int idx, int p)
{
    long res = 0;
    for(int i=0; i<3; i++)
    {
        if(p & (1 << i)) res += xyz[idx][i];
        else res -= xyz[idx][i];
    }

    return res;
}

int main(){

    long ans = 0;
    cin >> n; cin >> m;

    for(int i=0; i<n; i++) for(int j=0; j<3; j++) cin >> xyz[i][j];

    for(int i=0; i<8; i++)
    {
        vector<long> vec;
        for(int j=0; j<n; j++)
        {
            vec.emplace_back(getScore(j, i));
        }
        sort(vec.begin(), vec.end(), greater<long>());

        long sum=0;
        for(int j=0; j<m; j++)
        {
            sum += vec[j];
        }
        ans = max(ans, sum);
    }
    
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<numeric>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<map>
#include<utility>
#include<cmath>
#include<tuple>
#include<string>
#include<bitset>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
using namespace std;
typedef long long ll;

int main(){
    string s,t;
    cin>>s>>t;

    if(s.substr(0,s.length())==t.substr(0,t.length()-1)) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 3628
N,M = map(int,input().split())
info = []

for i in range(M):
    a,b = map(int,input().split())
    info.append([a,b])

info = sorted(info,key = lambda x:x[1])

ok = 0
count = 0

for i in range(M):
    if info[i][0] > ok:
        count += 1
        ok = info[i][1] - 1

print(count)

Measured memory_bytes: 22108
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<string>
#include<sstream>
#include<cmath>
#include<climits>
#include<algorithm>
#include<bitset>
#include<set>
#include<stack>
#include<queue>
#include<iomanip>
#include<memory.h>
#include<complex>
using namespace std;  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define rep(i,n) for(ll i=0;i<(n);i++)  
#define pb push_back  
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second  
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-5;
const double PI = M_PI;  
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define SHOWARRAY(ar,i,j) REP(a,i)REP(b,j)cerr<<ar[a][b]<<((b==j-1)?((a==i-1)?("\n\n"):("\n")):(" "))
#define DIV int(1e9+7)
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}

vi v1 = {1,3,5,7,8,10,12};
vi v2 = {4,6,9,11};
vi v3 = {2};

int main(){
  int x,y; cin >> x >> y;
  rep(i,v1.size())
    if(v1[i] == x)
      rep(j,v1.size()){
        if(v1[j] == y){
          cout << "Yes" << endl;
          return 0;
        }
        if(j == v1.size()-1){
          cout << "No" << endl;
          return 0;
        }
      }
  rep(i,v2.size())
    if(v2[i] == x)
      rep(j,v2.size()){
        if(v2[j] == y){
          cout << "Yes" << endl;
          return 0;
        }
        if(j == v2.size()-1){
          cout << "No" << endl;
          return 0;
        }
      }
  if(x == 2 && y == 2)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
using System;

class Program
{
    static void Main()
    {
        string[] array = Console.ReadLine().Split(' ');
        int a = int.Parse(array[0]);
        int b = int.Parse(array[1]);
        int c = int.Parse(array[2]);

        if (a >= b && a >= c) Console.WriteLine(a * 10 + b + c);
        else if (b >= a && b >= c) Console.WriteLine(b * 10 + a + c);
        else if (c >= a && c >= b) Console.WriteLine(c * 10 + a + b);
    }
}

Measured memory_bytes: 11092
N,*A = map(int,open(0).read().split())

s = sum(A)
CS = [0 for i in range(N+1)]
CS[0] = s
for i in range(len(A)):
  CS[i+1] = CS[i] - A[i]
CS.pop(0)

S = 0
for i,a in enumerate(A):
  S+=CS[i]*a
  S = (S%1000000007)
print(S)

Measured memory_bytes: 31692
#include <bits/stdc++.h>
#define maxn 200086

using namespace std;

char s[maxn];
int n;

int main(){
	scanf("%s", s + 1);
	n = strlen(s + 1);
	int x = 0;
	for(int i = 1;i <= n;i++) x = (x * 10 + s[i] - '0') % 9;
	printf(x ? "No" : "Yes");
}

Measured memory_bytes: 3904
var c = 0;

(function(input) {
    var p = input.split('\n');
    var n = Number(p.shift());

    console.log(getKochCurve({x: 0, y: 0}, {x: 100, y: 0}, n).map(function(p) {
        return p.x + ' ' + p.y;
    }).join('\n'));
})(require('fs').readFileSync('/dev/stdin', 'utf8'));

function getKochCurvePoints(p1, p2) {
    var s = {};
    var t = {};
    var u = {};
    s.x = ((2 * p1.x + p2.x) / 3).toFixed(6) - 0;
    s.y = ((2 * p1.y + p2.y) / 3).toFixed(6) - 0;
    t.x = ((p1.x + 2 * p2.x) / 3).toFixed(6) - 0;
    t.y = ((p1.y + 2 * p2.y) / 3).toFixed(6) - 0;
    u.x = ((t.x - s.x) * Math.cos(60 / 180 * Math.PI) - (t.y - s.y) * Math.sin(60 / 180 * Math.PI) + s.x).toFixed(6) - 0;
    u.y = ((t.x - s.x) * Math.sin(60 / 180 * Math.PI) + (t.y - s.y) * Math.cos(60 / 180 * Math.PI) + s.y).toFixed(6) - 0;
    return [s, u, t];
}

function getKochCurve(p1, p2, n) {
    if (n == 0) {
        return [p1, p2];
    }
    var p = getKochCurvePoints(p1, p2);
    p.unshift(p1);
    p.push(p2);
    n--;
    var points = [];
    for (var i = 0; i < p.length - 1; i++) {
        var s = p[i];
        var e = p[i + 1];
        points = points.concat(getKochCurve(s, e, n));
        points.pop();
    }
    points.push(p2);
    return points;
}

Measured memory_bytes: 11100
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)
//#define INF (1LL<<59)

struct data{
    int y,x,num;
};

bool check(vector<int> ps){
    stack<int> stk;
    
    for(auto e:ps){
        if(stk.empty() || stk.top()!=e){
            stk.push(e);
        }else{
            assert(stk.top()==e);
            stk.pop();
        }
    }
    if(stk.empty())return true;
    else return false;
}

int main(){
    int h,w,n;
    cin>>h>>w>>n;
    
    vector<data> v;
    rep(i,n){
        int x,y;
        cin>>y>>x;
        v.pb(data{y,x,(int)i});

        cin>>y>>x;
        v.pb(data{y,x,(int)i});
}
    
    vector<int> ps;
    sort(all(v),[](data a, data b ){return a.x<b.x; });
    for(auto e:v){
        if(e.y==0 && e.x!=w)ps.pb(e.num);
    }
    
    
    sort(all(v),[](data a, data b ){return a.y<b.y; });
    for(auto e:v){
        if(e.x==w && e.y!=h)ps.pb(e.num);
    }
    
    
    sort(all(v),[](data a, data b ){return a.x>b.x; });
    for(auto e:v){
        if(e.y==h && e.x!=0)ps.pb(e.num);
    }
    
    
    sort(all(v),[](data a, data b ){return a.y>b.y; });
    for(auto e:v){
        if(e.x==0 && e.y!=0)ps.pb(e.num);
    }
    
    map<int,int> mp;
    for(auto e:ps){
        mp[e]++;
    }
    
    vector<int> argvec;
    for(auto e:ps){
        if(mp[e]==2)argvec.pb(e);
    }
    assert(argvec.size()%2==0);
    bool res = check(argvec);
    
    
    if(res)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

Measured memory_bytes: 10352
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = (1 << 30) - 1;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

ll A, V, B, W, T;

void solve() {
	cin >> A >> V;
	cin >> B >> W;
	cin >> T;
	if(V <= W) {
		cout << "NO\n";
	}
	else {
		if(abs(A - B) <= T * (V - W)) cout << "YES\n";
		else cout << "NO\n";
	}
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}




Measured memory_bytes: 3852
using System;
using System.IO;

namespace EX160509_1{
    public class Program{
        public static void Main(string[] args){
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            var n = int.Parse(Console.ReadLine());
            var apart = new int[4, 3, 10];

            for(var i = 0; i < n; ++i){
                var input = Console.ReadLine().Split(' ');
                var b = int.Parse(input[0]);
                var f = int.Parse(input[1]);
                var r = int.Parse(input[2]);
                var v = int.Parse(input[3]);

                apart[b - 1, f - 1, r - 1] += v;
            }

            for(var i = 0; i < 4; ++i){
                for(var j = 0; j < 3; ++j){
                    for(var k = 0; k < 10; ++k){
                        sw.Write(" ");
                        sw.Write(apart[i, j, k]);
                    }
                    sw.WriteLine();
                }
                if(i == 3) break;
                sw.WriteLine(new string('#', 20));
            }
            sw.Flush();
        }
    }
}

Measured memory_bytes: 9184
// alt + tab to switch tab


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less 


using namespace __gnu_pbds;
using namespace std ;


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

#define ll long long
#define int long long
#define pb push_back
#define p1da(a,n) for(int i=0;i<(n);i++) cout << *( (a) + (i)) << " "; cout<<endl;
#define g1da(a,n) for(int i=0;i<(n);i++) cin >> *( (a) + (i)) ;
#define fi first
#define se second
#define f(i,n) for(int (i)=0;(i)<(n) ; (i)++ )
#define fr(i,s,e) for(int (i)=s;(i)<=(e) ; (i)++ )
#define pii pair <int,int>
#define p2da(a,row,col) f(i,row){f(j,col) cout << a[(i)][(j)]  <<" "; cout<<endl; }
#define g2da(a,row,col) f(i,row) f(j,col) cin >> a[(i)][(j)] ;
#define p1dv(v) f(i,v.size())cout<<v[(i)]<<" "; cout << endl ;
#define g1dv(v) f(i,v.size()) cin>>v[i] ;
#define debug(...)       dbg (#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void dbg(const char* n, Arg1&& arg1) {cerr << n << " : " << arg1 << endl;}
template <typename Arg1, typename... Args>
void dbg(const char* n, Arg1&& arg1, Args&&... args) {const char*c = strchr(n + 1, ','); cerr.write(n, c - n) << " : " << arg1 << " || "; dbg(c + 1, args...);}
clock_t startTime ; void mainstart(); void mainEnd() ;
#define mod  998244353
#define N 50001



signed main()
{
  mainstart() ;
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);


  int tt = 1 ;
  //cin >> tt ;
  //   https://www.guru99.com/node-js-tutorial.html

// int tc = 1 ;

  while (tt--)
  {
    int n, k ;
    cin >> n >> k ;
    int ans = 0 ;
    fr(i, k, n + 1)
    {
      int minsum = (i - 1) * (i) / 2 ;
      int maxsum = ((i) * ( 2 * n - (i - 1) )) / 2 ;
      ans += maxsum - minsum + 1 ;
      ans %= 1000000007 ;
    }
    cout << ans << endl ;

  }

  mainEnd() ;
  return 0 ;
}

void mainstart()
{
#ifndef ONLINE_JUDGE
  freopen("Input.txt", "r", stdin) ;
  freopen("Output.txt", "w", stdout) ;
#endif
  startTime = clock() ;
}
void mainEnd()
{
  fclose (stdout);
  fclose (stdin);
  clock_t endTime = clock() ;
  cerr << "Run Time is : " << (float)( endTime - startTime ) / CLOCKS_PER_SEC << endl ;
}

Measured memory_bytes: 3800
#include<cstdio>
#include<cstring>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ull, ull> UP;
typedef tuple<int, int, int> T;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void 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;
		}
	}
	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)];
	}
};

int gcd(int a, int b) {
	if (a < b)swap(a, b);
	int k = a % b;
	if (k == 1)return 1;
	if (k == 0)return b;
	int ans = gcd(b, k);
	return ans;
}
int digisum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}


int main() {
	int n, m;
	cin >> n >> m;
	vector<int> a(n);
	vector<int> s(n + 1);
	map<int, int> mp;
	s[0] = 0;
	ll ans = 0;
	REP(i, n) {
		cin >> a[i];
		s[i + 1] = (s[i] + a[i]) % m;
	}
	REP(i, s.size()) {
		ans += mp[s[i]];
		mp[s[i]]++;
	}
	cout << ans << endl;
}



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

int gcd(int x, int y){
  if(x%y == 0) return y;
  else return gcd(y, x%y);
}

int main(){
  int x, y, ans;
  cin >> x >> y;

  if(x >= y) ans = gcd(x, y);
  else ans = gcd(y, x);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3104
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"sort"
	"strconv"
)

func main() {
	n := readi()
	k := readi()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = readi()
		if a[i] == 1 {
		}
	}

	if n == k {
		fmt.Println(1)
		return
	}
	fmt.Println(1 + math.Ceil(float64(n-k)/float64(k-1)))
}

/*-------------------utilities-------------------*/

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func chmin(x *int, y int) bool {
	if *x > y {
		*x = y
		return true
	}
	return false
}

func chmax(x *int, y int) bool {
	if *x < y {
		*x = y
		return true
	}
	return false
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return (a * b) / gcd(a, b)
}

func permutations(arr []int) [][]int {
	var helper func([]int, int)
	res := [][]int{}

	helper = func(arr []int, n int) {
		if n == 1 {
			tmp := make([]int, len(arr))
			copy(tmp, arr)
			res = append(res, tmp)
		} else {
			for i := 0; i < n; i++ {
				helper(arr, n-1)
				if n%2 == 1 {
					tmp := arr[i]
					arr[i] = arr[n-1]
					arr[n-1] = tmp
				} else {
					tmp := arr[0]
					arr[0] = arr[n-1]
					arr[n-1] = tmp
				}
			}
		}
	}
	helper(arr, len(arr))
	return res
}

func isPrime(n int) bool {
	if n == 1 {
		return false
	}
	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			return false
		}
	}
	return true
}

func divisor(n int) (res []int) {
	for i := 1; i*i <= n; i++ {
		if n%i == 0 {
			res = append(res, i)
			if i*i != n {
				res = append(res, n/i)
			}
		}
	}
	sort.Ints(res)
	return
}

/*-------------------init-------------------*/

const (
	INF = 1000000000000000000
	MOD = 1e9 + 7
)

var (
	readString func() string
)

func init() {
	readString = newReadString(os.Stdin)
}

/*-------------------inputs-------------------*/

func readi() int {
	return int(readi64())
}

func readi64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readf() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}


Measured memory_bytes: 1920
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

K,A,B = MI()

if B-A <= 2:
    print(1+K)
else:
    if K <= A-1:
        print(1+K)
    else:
        K -= A-1
        ans = A
        ans += (B-A)*(K//2) + K % 2
        print(ans)


Measured memory_bytes: 62004
H,W=[int(i) for i in input().split()]
a=[input() for i in range(H)]

R = [[False for i in range(W)] for j in range(H)]
B = [[False for i in range(W)] for j in range(H)]

#前処理
for i in range(H):
	R[i][0] = B[i][-1] = True
	if i%2 == 0:
		for j in range(1,W-1):
			R[i][j] = True
	else:
		for j in range(1,W-1):
			B[i][j] = True

#プロット
for i in range(H):
	for j in range(W):
		if a[i][j] == '#':
			R[i][j] = B[i][j] = True

#描画
for row in R:
	for col in row:
		print('#' if col else '.',end="")
	print()
print()
for row in B:
	for col in row:
		print('#' if col else '.',end="")
	print()



Measured memory_bytes: 11252
#include <iostream>
#include<iomanip>
#include <set>
#include <vector>
#include <map>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
using namespace std;

const int NN=1e5+10;
const int mod=1e9+7;



int main()
{
    long long n;
    scanf("%lld",&n);
    int a=sqrt(n);
    //printf("%lld\n",n);
    long long ans;
    for(int i=a;i>=1;i--){
        if(n%i==0){
            ans=i;
            break;
        }
    }
    long long len=0;
    ans=n/ans;
    //printf("%lld\n",ans);
    while(ans!=0){
        ans=ans/10;
        len++;
    }
    printf("%lld\n",len);
}


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

using namespace std;


int main(){


	string a,b;
	int c;

	cin >> a;

	c=0;

	for(int i=0; i<3; i++ ){
		
		b=a.substr(i,1);
			if(b=="1"){
			c++;
		//	cout <<a[i]<<endl;

		}
	}

	cout << c <<endl;


}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

int n;
int ans, cnt;
void dfs(int digit, string str){
    if(digit<=cnt){
        if(stoi(str)<=n){
            bool ck[3];
            REP(i, 0, 3) ck[i]=false;
            REP(i, 0, str.size()){
                if(str[i]=='7') ck[0]=true;
                else if(str[i]=='5') ck[1]=true;
                else ck[2]=true;
            }

            if(ck[0] && ck[1] && ck[2]) ans++;
        }

        dfs(digit+1, str+"7");
        dfs(digit+1, str+"5");
        dfs(digit+1, str+"3");
    }
    return;
}
int main() {
    cin>>n;

    int tmp=n;
    while(tmp>0){
        tmp/=10;
        cnt++;
    }

    dfs(1, "7");
    dfs(1, "5");
    dfs(1, "3");

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

Measured memory_bytes: 256
import fractions

N = int(input())
A = list(map(int, input().split()))
L = [0] * N
R = [0] * N
for i in range(0, N - 1):
    L[i + 1] = fractions.gcd(L[i], A[i])
for i in range(N - 1, 0, -1):
    R[i - 1] = fractions.gcd(R[i], A[i])
print(max([fractions.gcd(L[i], R[i]) for i in range(N)]))


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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;

#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)

int main (void) {
    int M;
    cin>>M;
    cout<<24 + 24 - M << endl;
    return 0;
}

Measured memory_bytes: 256
C = []
for _ in range(3):
    ci = list(map(int, input().split()))
    C.append(ci)

ans = "No"

for a1 in range(0, 101):
    for a2 in range(0, 101):
        for a3 in range(0, 101):
            if (C[0][0]-a1 == C[1][0]-a2 == C[2][0]-a3) and (C[0][1]-a1 == C[1][1]-a2 == C[2][1]-a3) and (C[0][2]-a1 == C[1][2]-a2 == C[2][2]-a3):
                print("Yes")
                quit()

print(ans)


Measured memory_bytes: 3188
def examA():
    O = SI()
    E = SI()
    ans = ""
    for i in range(len(O)+len(E)):
        if i%2==0:
            ans += O[i//2]
        else:
            ans += E[i//2]
    print(ans)
    return

def examB():
    A = LI()
    A.sort()
    ans = (A[2] - A[0]) // 2 + (A[2] - A[1]) // 2
    if (A[2]-A[0])%2==1:
        ans += 1
        if (A[2]-A[1])%2==0:
            ans += 1
    elif (A[2]-A[1])%2==1:
        ans += 2
    print(ans)
    return

def examC():
    S = SI()
    S.replace("RL","A")
    S.replace("LR","B")
    N = len(S)
    A = [0]*N
    print(S)
    l = 0; r = 0
    for i,s in enumerate(S):
        if s=="A":
            A[i] += r
        elif s=="B":
            A[i] += l
    ans = 0
    print(ans)
    return

def examD():
    def warshall_floyd(n, d):
        # d[i][j]: iからjへの最短距離
        for k in range(n):
            for i in range(n):
                for j in range(n):
                    d[i][j] = min(d[i][j], d[i][k] + d[k][j])
        return d
    H, W = LI()
    C = [LI()for _ in range(10)]
    A = [LI()for _ in range(H)]
    C = warshall_floyd(10,C)
    ans = 0
    for i in range(H):
        for j in range(W):
            a = A[i][j]
            if a==-1:
                continue
            ans += C[a][1]
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**6)

if __name__ == '__main__':
    examD()

"""

"""

Measured memory_bytes: 5232
# https://atcoder.jp/contests/abc104/tasks/abc104_c
# C - All Green
import itertools

D, G = list(map(int, input().split()))
pc_list = []
for _ in range(D):
    p, c = list(map(int, input().split()))
    pc_list.append((p, c))

# 完全にとく or 途中までとく or 全くとかない パターンがある
# 各問題ごとに、完全にとくかどうかの組み合わせ
p_gen = itertools.product([0, 1], repeat=D)

cost_list = []
for pattern in p_gen:
    cost = 0
    point = 0
    for i, solve_flag in enumerate(pattern):
        point += ((i+1) * 100 * pc_list[i][0] + pc_list[i][1]) * solve_flag
        cost += pc_list[i][0] * solve_flag

    if point >= G:
        # 解けた場合
        cost_list.append(cost)
    else:
        # 解けない場合は、完全にといていない問題のうち次に配点が高いもので埋める
        # ただし、完全にとくことはできないので、各問題で使えるのはp-1問まで
        kouho_list = [i for i, solve_flag in enumerate(pattern) if solve_flag == 0]
        kouho_list = sorted(kouho_list, reverse=True)
        is_over = False
        for i in kouho_list:
            for _ in range(1, pc_list[i][0]):
                point += (i+1) * 100
                cost += 1
                if point >= G:
                    is_over = True
                    break
            if is_over:
                break
        if is_over:
            cost_list.append(cost)

ans = min(cost_list)
print(ans)


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

double pi = acos(-1);

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	double a,b,h,m;
	cin >> a >> b >> h >> m;
	double a1 = (h * 30 + (m/60*30)) * (pi/180),a2 = m * (pi / 30);
	double t = fabs(a1-a2);
	double ans = a*a+b*b-2*a*b*cos(t);
	ans = sqrt(ans);
	cout.precision(14);
	cout << fixed << ans << '\n';
	return 0;
}


Measured memory_bytes: 3644
def i():return map(int,input().split())
a,b,c = i()
d,e,f = i()
g,h,i = i()
print('Yes' if (d-a==e-b==f-c) and (g-d==h-e==i-f) and (b-a==e-d==h-g) and (c-b==f-e==i-h) else 'No')

Measured memory_bytes: 3060
import java.util.Scanner;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

public class Main{
	static final Scanner s=new Scanner(System.in);
	static final long[] fal_rnd(int size){
		AtomicInteger l=new AtomicInteger(-1),r=new AtomicInteger(size);
		long[] res=new long[size];
		INS(size).unordered().parallel().mapToLong(Long::parseLong).forEach(v->res[ThreadLocalRandom.current().nextBoolean()?l.incrementAndGet():r.decrementAndGet()]=v);
		return res;
	}
	static final IntStream REPS(int v){
		return IntStream.range(0,v);
	}
	static final Stream<String> INS(long size){
		return StreamSupport.stream(Spliterators.spliterator(s,size,Spliterator.NONNULL&Spliterator.IMMUTABLE),false).limit(size);
	}
	public static void main(String __[]){
		int d,e;
		while (true) {
			d=s.nextInt();
			e=s.nextInt();
			if(d+e==0)return;
			double r=Math.abs(d-e);
			for(int i=1;i<d;i++) {
				r=Math.min(r,Math.abs(e-Math.sqrt(i*i+(d-i)*(d-i))));
			}
			System.out.println(r);
		}
	}
}

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

#define int long long
using ll = long long;
using ld = long double;
using intpair = pair<int, int>;
const int MOD = 1e9 + 7;
inline int mod (ll a, int m = MOD) { return (a % m + m) % m; }
//struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((ll)((a) + (b) - 1)/(ll)(b))

map<int,int> factor(int n){
    map<int,int> m;
    for(int i=2; i*i <= n; i++){
        int p = 0;
        while(n%i==0){
            n /= i;
            p++;
        }
        if(p > 0) m[i] = p;
    }
    if(n != 1) m[n] = 1;
    return m;
}

void factor_lcm(map<int,int> &l, map<int,int> m){
    for(auto [p,e] : m){
        l[p] = max(l[p], e);
    }
}

int modpow(int a, int n, int m = MOD){
    ll ret = 1;
    while(n>0){
        if(n&1) ret = (ret*a) % m;
        a = (a*a) % m;
        n >>= 1;
    }
    return ret % m;
}

int factor_to_modint(const map<int,int> &m){
    int ret = 1;
    for(auto [p,e] : m){
        ret = mod(ret * modpow(p, e));
    }
    return ret;
}

ll modinv(ll a){
    ll b = MOD, p = 1, q = 0;
    ll temp;
    while(b>0){
        temp = a/b;
        a -= temp * b; swap(a, b);
        p -= temp * q; swap(p, q);
    }
    p %= MOD; if(p<0) p += MOD;
    return p;
}

signed main() {
    map<int,int> l;
    int n; cin >> n;
    vector<int> a(n);
    
    rep(i,n){
        cin >> a[i];
        factor_lcm(l, factor(a[i]));
    }
    
    const int L = factor_to_modint(l);
    
    int ans = 0;
    for(int i : a){
        ans = mod(ans + mod(L * modinv(i)));
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 4172
#include <bits/stdc++.h>
using namespace std;
vector<long long int> divisor(long long int n){
  vector<long long int> di;
  for(long long int i=1; i*i<=n; i++){
    if(n%i==0){
      di.push_back(i);
    }
  }
  return di;
}

int keta(long long int n){
  int cnt=0;
  while(n>0){
    n /= 10;
    cnt++;
  }
  return cnt;
}

int main(){
  int ans=99999999;
  long long int n;
  cin >> n;
  vector<long long int> div = divisor(n);
  for(int i=0; i<div.size(); i++){
    ans = min(ans,max(keta(div[i]),keta(n/div[i])));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
MOD = 10**9+7
def solve(n):
    """
    0: {}
    1: {0}
    2: {9}
    3: {0,9}
    """
    dp = [[0]*4 for i in range(n+1)]
    dp[0][0] = 1
    for i in range(n):
        dp[i+1][3] = (10*dp[i][3] + dp[i][2] + dp[i][1]) % MOD
        dp[i+1][2] = (9*dp[i][2] + dp[i][0]) % MOD
        dp[i+1][1] = (9*dp[i][1] + dp[i][0]) % MOD
        dp[i+1][0] = (8*dp[i][0]) % MOD
    return dp[n][3]

n = int(input())
print(solve(n))

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

class Dice{
    vector<int> x;

    void advance_vertical(){ 
        advance(0, 1, 5, 4); // N方向
    }
    
    void advance_horizontal(){ 
        advance(0, 3, 5, 2); // E方向
    }

    void advance_rotation(){
        advance(1, 2, 4, 3);
    }

    void advance(int i, int j, int k, int l){
        int tmp = x[i]; 
        x[i] = x[j];
        x[j] = x[k];
        x[k] = x[l];
        x[l] = tmp;
    }

public:
    Dice(vector<int>& x) : x(x) {}
    
    void roll(const string& command){
        for(const auto c : command){
            if(c == 'E'){
                advance_horizontal();
            }
            else if(c == 'N'){
                advance_vertical();
            }
            else if(c == 'S'){
                for(int i = 0; i < 3; ++i){
                    advance_vertical();
                }
            }
            else{
                for(int i = 0; i < 3; ++i){
                    advance_horizontal();
                }
            }
        }      
    }

    int getNow(){
        return x[0];
    }

    int getRightSide(int top_side, int front){
        for(int i = 0; i < 6; i++){ // 面一つずつ見ていく
            for(int j = 0; j < 4; j++){ // rotate方向 4回す
                if(x[0] == front && x[4] == top_side){
                    return x[2];
                }
                advance_rotation();
            }
            if(i % 2 == 0){
                advance_vertical();
            }
            else{
                advance_horizontal();
            }
        }
        return 0; // 失敗
    }
};

int main(){

    vector<int> x(6);
    for(int i = 0; i < 6; ++i){
        cin >> x[i];
    }
    Dice dice(x);

    int q;
    cin >> q;
    for(int i = 0; i < q; ++i){
        int top_side, front;
        cin >> top_side >> front;
        cout << dice.getRightSide(top_side, front) << endl;
    }

    return 0;
}


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


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int sta=0;
  int flag=0;
  int t=-1;
  int n=s.size();
  int ans[n];
  rep(i,n) ans[i]=0;
  rep(i,n){
    if(sta!=-1){
      if(s[i]=='R') continue;
      else{
	ans[i]+=(i-sta+2)/2;
	ans[i-1]+=(i-sta+1)/2;
	sta=-1;
	t=i-1;
	flag=0;
      }      
    }
    else{
      if(s[i]=='L'){
	if(flag==0){
	  ans[t]+=1;
	  flag=1;
	  t+=1;
	}
	else{
	  ans[t]+=1;
	  flag=0;
	  t-=1;
	}
      }
      else if(s[i]=='R'){
	sta=i;
      }
    }
  }
  rep(i,n) cout << ans[i] << " ";
  cout << "" <<endl;
  return 0;
    

}


Measured memory_bytes: 1104
a=int(input())
s=list(input())
t=[]
list=[chr(i) for i in range(65, 65+26)]
for i in s:
  t.append(list.index(i))
u=[i+a for i in t]
u=[i-26 if i>=26 else i for i in u]
b=[]
for i in u :
  b.append(list[i])
k=""
for s in b:
  k+=s
print(k)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long A,B,C,X,Y = 0;
  cin >> A >> B >> C >> X;
  for (int i = 0; i <= A; i++) {
    for (int j = 0; j <= B; j++) {
      for (int k = 0; k <= C; k++) {
        Y += X == i*500+j*100+k*50;
      }
    }
  }
  cout << Y;
}

Measured memory_bytes: 3600
#include <iostream>

using namespace std;

int main(){
	long long Q, H, S, D, N;
	cin >> Q >> H >> S >> D;
	cin >> N;

	long long q4 = Q * 4;
	long long h2 = H * 2;
	long long minS = q4;

	if (minS > h2) minS = h2;
	if (minS > S) minS = S;

	if (minS * 2 < D) {
		// use minS only
		cout << minS * N << endl;
	} else {
		// use D if possible
		cout << D * (N/2) + minS * (N%2) << endl;
	}

	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
long long a[100010]={0};
long long used[100010]={0};
int main(void)
{
  int n, i, ans = 0;
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%lld", &a[i]);
  }

  for(i = 1; i < n; i++){
    if(a[i] > a[i-1]){
      while(a[i] >= a[i-1] && i < n){
	used[i] = 1;
	used[i-1] = 1;
	i++;
      }
      ans++;
    }
    else if(a[i] < a[i-1]){
      while(a[i] <= a[i-1] && i < n){
	used[i] = 1;
	used[i-1] = 1;
	i++;
      }
      ans++;
    }
  }
  if(used[n-1] != 1) ans++;
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 1664
#define rep(i, a, b) for(int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;

const ll DIV = 998244353;


int main(void) {
   ll N;
   cin>>N;
   ll D[N];
   rep(i,0,N) cin>>D[i];
   if (D[0]!=0) {
      cout<<0<<endl;
      return 0;
   }
   ll Num[N] = {};
   rep(i,0,N) Num[D[i]]++;
   // rep(i,0,N) cout<<Num[i]<<endl;
   if (Num[0]!=1) {
      cout<<0<<endl;
      return 0;
   }
   ll ans = 1;
   ll done = Num[0];
   rep(i,1,N) {
      if (Num[i]==0) break;
      rep(j,0,Num[i]) {
         ans *=Num[i-1];
         ans = ans%DIV;
      }
      // ans *= pow(Num[i-1],Num[i]);
      done += Num[i];
   }
   if (done != N) {
      cout<<0<<endl;
      return 0;
   }
   cout<<ans%DIV<<endl;
   return 0;
}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
 
int main(){
  int N,W;
  cin >> N >> W;
 
  int v[1000],w[1000];
  for(int i=0;i<N;i++){
    cin >> v[i] >> w[i];
  }
 
  int DP[N+1][W+1];
  for(int i=0;i<=W;i++){
    DP[0][i]=0;
  }
 
  for(int i=1;i<=N;i++){
    for(int j=0;j<=W;j++){
      if(j<w[i-1])
        DP[i][j]=DP[i-1][j];
      else{
        if(DP[i-1][j]>DP[i][j-w[i-1]]+v[i-1])
          DP[i][j]=DP[i-1][j];
        else
          DP[i][j]=DP[i][j-w[i-1]]+v[i-1];
      }
    }
  }
 
  cout << DP[N][W] << endl;
 
  return 0;
}


Measured memory_bytes: 7080
#include <bits/stdc++.h>
#define FOR(i, l, r) for(int i = (int)l; i <= (int)r; ++i)
#define FORD(i, l, r) for(int i = (int)l; i >= (int)r; --i)
#define REP(i, r) for(int i = (int)0; i < (int)r; ++i)
#define X first
#define Y second

using namespace std;
const int Nmax = 2e5 + 112;

int n, k, a[Nmax], r[Nmax], ans, pos[Nmax];
pair<int, int> rmq[Nmax][22];

int get(int l, int r, int T) {
    int tmp = log2(r - l + 1);
    if (T == 0) return min(rmq[l][tmp].X, rmq[r - (1 << tmp) + 1][tmp].X);
    else return max(rmq[l][tmp].Y, rmq[r - (1 << tmp) + 1][tmp].Y);
}

int main() {
//    freopen("in.inp", "r", stdin);
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> k;
    FOR(i, 1, n) {
        cin >> a[i];
        rmq[i][0] = {a[i], a[i]};
    }
    FOR(j, 1, 21) {
        for(int i = 1; i + (1 << j) - 1 <= n; ++i) {
            rmq[i][j].X = min(rmq[i][j - 1].X, rmq[i + (1 << (j - 1))][j - 1].X);
            rmq[i][j].Y = max(rmq[i][j - 1].Y, rmq[i + (1 << (j - 1))][j - 1].Y);
        }
    }
    r[n] = n;
    FORD(i, n - 1, 1) {
        if (a[i] < a[i + 1]) r[i] = r[i + 1];
        else r[i] = i;
    }
    FOR(i, 1, n - k + 1) {
        int l = i, rr = min(i + k - 2, r[i]), mid = (l + rr) >> 1;
        while(l != mid && mid != rr) {
            if (get(mid + 1, i + k - 1, 0) >= a[mid]) l = mid;
            else rr = mid;
            mid = (l + rr) >> 1;
        }
        FORD(j, rr, l) {
            if (get(j + 1, i + k - 1, 0) >= a[j]) {
                pos[i] = j;
                break;
            }
        }
    }
    bool check = false;
    FOR(i, 1, n - k + 1) {
        if (r[i] >= i + k - 1) {
            check = true;
            continue;
        }
        if (pos[i] == 0) {
//            cout << i << "*\n";
            ++ans; continue;
        }
        int u = pos[i], v = i + k - 1;
        int p = i + k - 1;
        while(p + 1 <= n && p + 1 <= u + k && a[p + 1] > get(u + 1, v, 1) && a[p + 1] > a[p]) {
            ++p;
        }
        ++ans;
//        cout << i << " = " << p - k + 1 << '\n';
        i = p - k + 1;
    }
    cout << ans + check;
}


Measured memory_bytes: 36992
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main(){
  string a,b;
  cin>>a>>b;
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  reverse(b.begin(),b.end());
  if(a<b)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
n = int(input())
sl = [i+1 for i in range(13)]
hl = list(sl)
cl = list(sl)
dl = list(sl)
for i in range(n):
    mark,num = input().split()
    if mark == 'S':
        sl.remove(int(num))
    elif mark == 'H':
        hl.remove(int(num))
    elif mark == 'C':
        cl.remove(int(num))
    else:
        dl.remove(int(num))
for i in range(len(sl)):
    print('S',sl[i])
for i in range(len(hl)):
    print('H',hl[i])
for i in range(len(cl)):
    print('C',cl[i])
for i in range(len(dl)):
    print('D',dl[i])


Measured memory_bytes: 5612
#include<bits/stdc++.h>
using namespace std;
int k;
char c,b;
string s,a[3];
int main(){
	for(int i=0;i<19;i++){
		if(i==5 || i==13)
			cin>>c,k++;
		else
			cin>>b,a[k]+=b;
	}
	for(int i=0;i<3;i++){
		cout<<a[i]<<" ";
	}
}


Measured memory_bytes: 256