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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
	ost<<"{"<<p.first<<","<<p.second<<"}";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
	ost<<"{";
	for(int i=0;i<v.size();i++){
		if(i)ost<<",";
		ost<<v[i];
	}
	ost<<"}";
	return ost;
}


template<class T,class Op>
struct QueueAggregation{
	Op op;
	QueueAggregation(const Op &op):op(op){}
	struct Data{
		T val,sum;
		Data(const T &val,const T &sum):val(val),sum(sum){}
	};
	stack<Data>F,B;

	void push(const T &a){
		if(B.empty()){
			B.emplace(a,a);
		}
		else{
			B.emplace(a,op(B.top().sum,a));
		}
	}
	void pop(){
		if(F.empty()){
			F.emplace(B.top().val,B.top().val);
			B.pop();
			while(!B.empty()){
				F.emplace(B.top().val,op(B.top().val,F.top().sum));
				B.pop();
			}
		}
		F.pop();
	}
	T calc(){
		if(F.empty())return B.top().sum;
		if(B.empty())return F.top().sum;
		return op(F.top().sum,B.top().sum);
	}
};

signed main(){
	auto mi=[](int a,int b){return min(a,b);};
	QueueAggregation<int,decltype(mi)>q(mi);

	int N,L;
	scanf("%lld%lld",&N,&L);
	rep(i,L-1){
		int a;scanf("%lld",&a);
		q.push(a);
	}
	vint ans;
	for(int i=L-1;i<N;i++){
		int a;scanf("%lld",&a);
		q.push(a);
		ans.pb(q.calc());
		q.pop();
	}
	rep(i,ans.size()){
		if(i)printf(" ");
		printf("%lld",ans[i]);
	}puts("");
	return 0;
}


Measured memory_bytes: 12932
#include <iostream>
#define REP(a) for(i=0;i<a;i++)

int main(){

   int i, n, m, t0[110], p, t1, t2[101], sum=0;
   scanf("%d",&n);
   REP(n){
     scanf("%d",&t0[i]);
     sum+=t0[i];
   }
   scanf("%d",&m);
   REP(m){
     scanf("%d %d",&p,&t1);
     t2[i]=sum-t0[p-1]+t1;
   }
   REP(m)printf("%d\n",t2[i]);
 }


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>

int main(){
    //freopen("testcase", "r", stdin);

    char s1[100], s2[100], s3[100];
    scanf("%s %s %s", s1, s2, s3);
    char d = 'a'-'A';
    printf("%c%c%c\n", s1[0]-d, s2[0]-d, s3[0]-d);
    return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <cmath>

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define inc( i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec( i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

template<typename T> void swap(T & x, T & y) { T t = x; x = y; y = t; return; }
template<typename T> T abs(T x) { return (0 <= x ? x : -x); }
template<typename T> T max(T a, T b) { return (b <= a ? a : b); }
template<typename T> T min(T a, T b) { return (a <= b ? a : b); }
template<typename T> bool setmin(T & a, T b) { if(a <= b) { return false; } else { a = b; return true; } }
template<typename T> bool setmax(T & a, T b) { if(b <= a) { return false; } else { a = b; return true; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

char s[13];

int main() {
	scanf("%s", s);
	
	inc(i, 4) { printf("%c", s[i]); }
	printf(" %s\n", s + 4);
	
	return 0;
}


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

#define rep(i, n) for(int i=0; i < n; i++)
#define REP(i, n, m) for(int i=n; i < m; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

using namespace std;
using ll=long long;

ll mod=1000000007;

const ll INF = 1LL << 60;

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

int main() {
  int n;cin >> n;
  vector<ll> d(60);
  rep(i,n){
    ll a;cin >> a;
    rep(j,60)if(a & (1LL<<j))d[j]++;
  }

  ll ans=0;
  rep(i,60){
    ans= (ans+(d[i]*(n-d[i]))%mod*((1ll<<i)%mod))%mod;
  }
  cout << ans <<endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <fstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <cstdio>
#include <stack>

using namespace std;


int main()
{
	/* 自然数 */
	int num;
	/* 各桁の数字 */
	int dig;
	/* 和 */
	int sum = 0;
	cin >> num;
	int b = num;

	while (num) {
		dig = num % 10;
		sum = sum + dig;
		num = num / 10;
	}

	int c = b % sum;

	if (c == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
//	final static int MOD = 1000000007;

	public static long ans = 0;

	public static void main(String[] args) {

//		int ans = 0;
		Scanner sc = new Scanner(System.in);
		boolean f = false;

//		long a = sc.nextLong();

		int n = sc.nextInt();


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

		if(n >= 400 && n <= 599) {
			ans = 8;
		} else if(n >= 600 && n <= 799) {
			ans = 7;
		} else if(n >= 800 && n <= 999) {
			ans = 6;
		} else if(n >= 1000 && n <= 1199) {
			ans = 5;
		} else if(n >= 1200 && n <= 1399) {
			ans = 4;
		} else if(n >= 1400 && n <= 1599) {
			ans = 3;
		} else if(n >= 1600 && n <= 1799) {
			ans = 2;
		} else if(n >= 1800 && n <= 1999) {
			ans = 1;
		}

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

//		if(f) {
//			System.out.println("Yes");
//		} else {
//			System.out.println("No");
//		}

		System.out.println(ans);

		sc.close();
	}



}

Measured memory_bytes: 35636
while 1:
    a,b,c=input().split()
    if b=='?':
        break
    a=int(a)
    c=int(c)
    if b=='+':
        print(a+c)
    if b=='-':
        print(a-c)
    if b=='*':
        print(a*c)
    if b=='/':
        print(int(a/c))



Measured memory_bytes: 5596
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstdio>
#include <queue>
#include <map>

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

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> P;

void p(vi v){
	rep(i, v.size()){
		cout << v[i] << ' ';
	}
	cout << endl;
}

void pp(vector<string> v){
	rep(i, v.size()){
		cout << v[i] << endl;
	}
}

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

const char wall = '#';

int seedfill(vector<string> &v, P start){
	queue<P> q;
	q.push(start);
	int count = 0;
	while(!q.empty()){
		P p = q.front();
		q.pop();
		int x = p.first;
		int y = p.second;

		if(v[y][x] != wall){
			v[y][x] = wall;
			count++;
			rep(i, 4){
				q.push(P(x+dx[i], y+dy[i]));
			}
		}
	}
	return count;
}

int solve(vector<string> &v){
	rep(i, v.size()){
		rep(j, v[i].size()){
			if(v[i][j] == '@'){
				return seedfill(v, P(j, i));
			}
		}
	}
	return -1;
}

int main(){

	int W, H;
	while(cin >> W >> H){
		if(!W && !H) break;

		vector<string> field(H+2);
		rep(i, W+2) field[0].push_back(wall);
		field[H+1] = field[0];

		FOR(i, 1, H+1){
			string tmp;
			cin >> tmp;
			field[i] = wall + tmp + wall;
		}

		cout << solve(field) << endl;
	}

	return 0;
}

Measured memory_bytes: 1244
#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 main(){
	int R;
	cin>>R;
	if(R<1200){
		cout<<"ABC"<<endl;
	}else if(R<2800){
		cout<<"ARC"<<endl;
	}else{
		cout<<"AGC"<<endl;
	}
	return(0);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define eps 1e-9
#define maxp 1000400
#define mod 1000000007
#define pi 3.141592653589793238
#define sin(s) scanf("%lld",&s);
#define sout(s) printf("%lld\n",s);
#define in(s) cin>>s
#define in2(a,b) cin>>a>>b
#define in3(a,b,c) cin>>a>>b>>c
#define vll vector<ll>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define endl '\n'
#define sp ' '
#define gear_change ios_base::sync_with_stdio(false),cin.tie(0)
#define nfl(i,n) for(i=0;i<n;i++)
#define sfl(i,s,e) for(i=s;i<e;i++)
#define ufl(i,n) for(i=n-1;i>=0;i--)
ll power(ll x,ll y){
    ll ret=1;
    while(y>0){
        if(y&1)
            ret=(ret*x);
        y/=2;
        x=(x*x);
    }
    return ret;
}
ll get(ll n){
	ll ret=0;
	while(n){
		ret+=n%10;
		n/=10;
	}
	return ret;
}
void solve(){
	ll n,k,i,pos=0;
	cin>>n;
	vll vec(n);
	ll mn=INT_MAX;
	ll mx=INT_MIN;
	nfl(i,n){
		in(vec[i]);
		mx=max(mx,vec[i]);
		mn=min(mn,vec[i]);
	}	
	cout<<mx-mn<<endl;
}	
int main(){
	gear_change;
	ll test=1;
	// in(test);
	while(test--){
		solve();
	}
}	


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

ll make(int d, int mask){
    string s = "";
    rep(i,d){
        if(mask>>i&1) s += '8';
        else s += '2';
    }
    return atoll(s.c_str());
}

const int INF = 19191919;
vector<ll> v;
int V;

const int N = 1<<10;
map<ll,int> dp[N];
int dfs(int d, ll n){
    if(d==V){
        if(n==1) return 0;
        return -INF;
    }
    if(dp[d].count(n)) return dp[d][n];

    int ret = -INF;
    if(n%v[d]==0) ret = max(ret, dfs(d, n/v[d])+1);
    ret = max(ret, dfs(d+1, n));

    return dp[d][n] = ret;
}

int main(){
    ll n;
    cin >>n;
    if(n==1){
        cout << -1 << endl;
        return 0;
    }

    for(int i=1; i<=9; ++i){
        rep(mask,1<<i) v.pb(make(i,mask));
    }
    V = v.size();

    int ans = -1;

    ans = max(ans, dfs(0,n));
    for(int i=10; i<=18; ++i){
        rep(mask,1<<i){
            ll val = make(i,mask);
            if(n%val==0){
                ans = max(ans, dfs(0, n/val)+1);
            }
        }
    }

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



Measured memory_bytes: 78760
#include<iostream>

using namespace std;

int main(void) {
	int r, g, b;
	
	cin >> r >> g >> b;

	if ((r * 100 + g * 10 + b) % 4 == 0) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	return 0;
}

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

int main() {
  int K,S;
  cin >> K >> S;
  
  int count;
  
  for(int x=0;x<=K;++x){
    for(int y=0;y<=K;++y){
      if((x+y)>S || (x+y)<(S-K)){
        continue;
      }
      else if((x+y)>=(S-K)){
        count++;
      }
    }
  }
  cout << count << endl;
  return 0;
}


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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template <class T> bool chmin(T & a, T b) { if (a > b) { a = b; return true; } return false; }
template <class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, k, t, u, v, l;
	cin >> n >> k >> t >> u >> v >> l;
	vi d(n);
	REP(i, n)cin >> d[i];
	vl b(l, 0);
	REP(i, n)b[d[i]] = 1;
	int time = 0, cnt = 0;
	double ans = 0;
	REP(i, l) {
		if (time == 0) {
			if (cnt > 0) {
				cnt--;
				time = t * v;
				if (b[i])cnt++;
			}
			else {
				if (b[i])time = t * v;
			}
		}
		else {
			if (b[i]) {
				if (cnt == k)time = t * v;
				else cnt++;
			}
		}
		if (time > 0) {
			ans += 1.0 / v;
			time--;
		}
		else {
			ans += 1.0 / u;
		}
	}
	cout << setprecision(12) << ans << endl;
}


Measured memory_bytes: 3388
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner num = new Scanner(System.in);
		int s = num.nextInt();
		int m = num.nextInt();
		int n = num.nextInt();
		int a=s;
		int b,c;
		//abcに代入していく
		if(a>=m){
			a=m;
			b=s;
		}
		else{
			b=m;
		}
		
		if(a>=n){
			c=b;
			b=a;
			a=n;
		}
		else if(a<n && b>=n){
			c=b;
			b=n;
		}
		else{
			c=n;
		}
		System.out.println(a+" "+b+" "+c);
	}

}



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

using namespace std;

static const int N = 100;

void mcm() {
    int n = 4;
    int p[n+1], m[n+1][n+1];

    int sample[][4] = {{5, 4}, {4, 6}, {6, 2}, {2, 7}};

    int cnt = 0;
    for (int i = 1; i <= n; i++) {
        p[i -1] = sample[cnt][0];
        p[i] = sample[cnt][1];
        cnt++;
    }
    cout << "Values of p: " << endl;
    for (int i = 0; i <=n; i++) cout << p[i] << " ";
    cout << endl;

    //diagonal part is always 0
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <=n; j++) {
            m[i][j] = 0;
        }
    }

    for (int l = 2; l <= n; l++) {
        for (int i = 1; i <= n - l + 1; i++) {
            int j = i + l - 1;
            m[i][j] = (1 << 21);
            for (int k = i; k <= j; k++) {
                m[i][j] = min(m[i][j], m[i][k] + m[k+1][j] + p[i-1] * p[k] * p[j]);
            }
        }
    }

    cout << "Result table: " << endl;
    for (int i = 1; i <=n; i++) {
        for (int j = 1; j <=n; j++) {
            cout << m[i][j] << " ";
        }
        cout << endl;
    }
}


int main()
{
    int n, p[N+1], m[N+1][N+1];
    cin >> n;

    for (int i = 1; i <=n; i++) {
        cin >> p[i - 1] >> p[i];
    }
    //diagonal part is always 0
    for (int i = 1; i <= n; i++) m[i][i] = 0;

    for (int l = 2; l <= n; l++) {
        for (int i = 1; i <= n - l + 1; i++) {
            int j = i + l - 1;
            m[i][j] = (1 << 21);
            for (int k = i; k <= j; k++) {
                m[i][j] = min(m[i][j], m[i][k] + m[k+1][j] + p[i-1] * p[k] * p[j]);
            }
        }
    }

    cout << m[1][n] << endl;
    //mcm();
    return 0;
}



Measured memory_bytes: 3140
#include<bits/stdc++.h>
#define fr(i,n) for(ll i=0;i<n;i++)
#define ll long long
#define pb push_back
#define endl "\n"
#define mod 1000000007
using namespace std;
int main()
{
	int r;
	cin>>r;
	//double pi = 3.14159;
	double c=2*M_PI*r;
	cout << fixed << setprecision(2) << c <<endl; 
}


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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
  cout << fixed << setprecision(12);
int a,b; cin>>a>>b;
string s = to_string(a)+to_string(b);
int p = 0;
for (char c: s) {
p*=10;
p+=(c-'0');
}

for (int i=1; i*i<=p; i++) {
if (i*i==p) out("Yes");
}

cout<<"No"<<endl;
  

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll) x.size()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define MAX(x, y, z) max(x, max(y, z))
#define MIN(x, y, z) min(x, min(y, z))
#define ANS cout << ans << "\n"
#define RETURN(x)    \
  cout << x << "\n"; \
  return 0
clock_t CLOCK;
#define START_TIMER CLOCK = clock()
#define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << "\n"
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

signed main() {
  init();
  ll a, b, c;
  cin >> a >> b >> c;

  if (a <= c && c <= b) {
    COUT("Yes");
  } else {
    COUT("No");
  }
  return 0;
}

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

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

  scanf("%d", &x);

  while (x > 0) {
    a = x % 10;
    x /= 10;
    sum += a;
  }

  printf("%d\n", sum);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

const ll mod=1e9+7;

//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

typedef pair<ll,ll> P;

ll dp[100010][4];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    ll n=len(s);
    dp[0][0]=1;
    rep(i,n){
      if(s[i]=='A'||s[i]=='?'){
        dp[i+1][0]+=dp[i][0];
        dp[i+1][0]%=mod;
        dp[i+1][1]+=dp[i][1];
        dp[i+1][1]%=mod;
        dp[i+1][2]+=dp[i][2];
        dp[i+1][2]%=mod;
        dp[i+1][3]+=dp[i][3];
        dp[i+1][3]%=mod;
        dp[i+1][1]+=dp[i][0];
        dp[i+1][1]%=mod;
      }
      if(s[i]=='B'||s[i]=='?'){
        dp[i+1][0]+=dp[i][0];
        dp[i+1][0]%=mod;
        dp[i+1][1]+=dp[i][1];
        dp[i+1][1]%=mod;
        dp[i+1][2]+=dp[i][2];
        dp[i+1][2]%=mod;
        dp[i+1][3]+=dp[i][3];
        dp[i+1][3]%=mod;
        dp[i+1][2]+=dp[i][1];
        dp[i+1][2]%=mod;
      }
      if(s[i]=='C'||s[i]=='?'){
        dp[i+1][0]+=dp[i][0];
        dp[i+1][0]%=mod;
        dp[i+1][1]+=dp[i][1];
        dp[i+1][1]%=mod;
        dp[i+1][2]+=dp[i][2];
        dp[i+1][2]%=mod;
        dp[i+1][3]+=dp[i][3];
        dp[i+1][3]%=mod;
        dp[i+1][3]+=dp[i][2];
        dp[i+1][3]%=mod;
      }
    }
    /*
    rep(i,n+1){
      rep(j,4){
        cout<<dp[i][j]<<' ';
      }
      cout<<'\n';
    }
    */
   cout<<dp[n][3]<<endl;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INTINF = 1<<29;
const ll LLINF = 1LL<<61;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int DX[8]={ 0, 1, 0,-1, 1, 1,-1,-1};
const int DY[8]={ 1, 0,-1, 0, 1,-1, 1,-1};


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b;
  cin >> a >> b;
  if(a%3 && b%3 && (a+b)%3 ){
    cout << "Impossible" << endl;
  }else{
    cout << "Possible" << endl;
  }
}


Measured memory_bytes: 256
/* ex3_4
   Acro  */
 
#include <stdio.h> 
int main(void){
    int num,i;
    int ans = 1;
    scanf("%d",&num);
    for(i = 1; i < 10 ; i++){
        /* 1から9まで探索 */
        if(num % i == 0){
            /* 割り切れたとき */
            if(num/i < 10){
                /* 商が10より小さければYes */
                printf("Yes\n");
                ans = 0;
                break;
            }
        }
    }
    if(ans){
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
#include <iomanip>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str(); }
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 2;
const int MOD = 1000000007;
typedef vector<ll> vl;
typedef vector<vl> vvl;

int main() {
	string X;
	cin >> X;
	string ans = "";
	int s = 0, t = 0, p = 0;
	REP(i, X.length()) {
		if (X[i] == 'S') {
			s++;
		}
		else if (X[i] == 'T') {
			t++;
			if (s > 0) {
				s--;
				t--;
			}
		}
	}

	cout << s+t << endl;
	return 0;
}

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


using namespace std;




int main()
{
    long n;
    cin >> n;
    vector<long long> a(100005);
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    long long sum = 0;
    long long tren = 0;
    for(int i = 1; i <= n + 2; i++)
    {
        if(a[i] == 0)
        {
            sum += tren/2;
            tren = 0;
        }
        else
        {
            tren += a[i];
        }
        
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 1024
char S[12];
char out[2<<20];
int outsz,Slen;
main()
{
	int N,K;
	scanf("%d%d ",&N,&K);
	gets(S);
	Slen=strlen(S);
	switch(Slen){
		case 1:
			for(int i=0;i<K;i++)
			{
				out[i*2]=S[0];
				out[i*2+1]='\n';
			}
			break;
		case 2:
			for(int i=0;i<K;i++)
			{
				out[i*3]=S[0];
				out[i*3+1]=S[1];
				out[i*3+2]='\n';
			}
			break;
		case 3:
			for(int i=0;i<K;i++)
			{
				out[i*4]=S[0];
				out[i*4+1]=S[1];
				out[i*4+2]=S[2];
				out[i*4+3]='\n';
			}
			break;
		case 4:
			for(int i=0;i<K;i++)
			{
				out[i*5]=S[0];
				out[i*5+1]=S[1];
				out[i*5+2]=S[2];
				out[i*5+3]=S[3];
				out[i*5+4]='\n';
			}
			break;
		case 5:
			for(int i=0;i<K;i++)
			{
				out[i*6]=S[0];
				out[i*6+1]=S[1];
				out[i*6+2]=S[2];
				out[i*6+3]=S[3];
				out[i*6+4]=S[4];
				out[i*6+5]='\n';
			}
			break;
		case 6:
			for(int i=0;i<K;i++)
			{
				out[i*7]=S[0];
				out[i*7+1]=S[1];
				out[i*7+2]=S[2];
				out[i*7+3]=S[3];
				out[i*7+4]=S[4];
				out[i*7+5]=S[5];
				out[i*7+6]='\n';
			}
			break;
		case 7:
			for(int i=0;i<K;i++)
			{
				out[i*8]=S[0];
				out[i*8+1]=S[1];
				out[i*8+2]=S[2];
				out[i*8+3]=S[3];
				out[i*8+4]=S[4];
				out[i*8+5]=S[5];
				out[i*8+6]=S[6];
				out[i*8+7]='\n';
			}
			break;
		case 8:
			for(int i=0;i<K;i++)
			{
				out[i*9]=S[0];
				out[i*9+1]=S[1];
				out[i*9+2]=S[2];
				out[i*9+3]=S[3];
				out[i*9+4]=S[4];
				out[i*9+5]=S[5];
				out[i*9+6]=S[6];
				out[i*9+7]=S[7];
				out[i*9+8]='\n';
			}
			break;
		case 9:
			for(int i=0;i<K;i++)
			{
				out[i*10]=S[0];
				out[i*10+1]=S[1];
				out[i*10+2]=S[2];
				out[i*10+3]=S[3];
				out[i*10+4]=S[4];
				out[i*10+5]=S[5];
				out[i*10+6]=S[6];
				out[i*10+7]=S[7];
				out[i*10+8]=S[8];
				out[i*10+9]='\n';
			}
			break;
		case 10:
			for(int i=0;i<K;i++)
			{
				out[i*11]='1';
				out[i*11+1]='0';
				out[i*11+2]='0';
				out[i*11+3]='0';
				out[i*11+4]='0';
				out[i*11+5]='0';
				out[i*11+6]='0';
				out[i*11+7]='0';
				out[i*11+8]='0';
				out[i*11+9]='0';
				out[i*11+10]='\n';
			}
			break;
	}
	outsz=K*(Slen+1);
	N-=K;
	for(int i=0;i<N;i++)
	{
		out[outsz+i*2]='7';
		out[outsz+i*2+1]='\n';
	}
	write(1,out,outsz+N*2);
}

Measured memory_bytes: 2304
n, a, b = gets.split.map &:to_i
s=gets.chomp
abc = 0
bc = 0
n.times do |i|
  case s[i]
  when 'c'
  when 'b'
    if abc<a+b && bc < b
      abc += 1
      bc += 1
      puts :Yes
      next
    end
  when 'a'
    if abc<a+b
      abc += 1
      puts :Yes
      next
    end
  else
  end
  puts :No
end

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int N,K;
    cin >> N >> K;
    vector<int> treat(N+1, 0);
    REP(i,K){
        int d;
        cin >> d;
        REP(j,d){
            int a;
            cin >> a;
            treat[a]++;
        }
    }

    int ans = 0;
    REP(i,N){
        if (treat[i+1] == 0){
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;

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

    if (N % 2 == 0) {
        std::cout << (N/2)*(N/2) << std::endl;
    }
    else {
        std::cout << (N/2)*(N/2+1) << std::endl;
    }
    // std::string S;
    // std::cin >> S;



    return 0;
}


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



int main(){
    int N;cin >> N;
    vector<int> v;
    for(int i = 0;i < N;i++){
        int a;cin >> a;
        v.push_back(a);
    }
    vector<int> I(N);
    vector<int> J(N);
    for(int i = 0;i < N;i++){
        I[i] = v[i] + i + 1;
        J[i] = (i + 1) - v[i]; 
    }
    map<ll, int> mp;
    for(int i = 0;i < N;i++){
        mp[J[i]]++;
    }
    ll ans = 0;
    for(int i = 0;i < N;i++){
        mp[J[i]]--;
        ans += mp[I[i]];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 28156
#include <bits/stdc++.h>
using namespace std;
void Main();

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define ALL(v) v.begin(), v.end()
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) a / __gcd(a, b) * b /* 最小公倍数 */

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

void Main() {
    u32 H, A;
    cin >> H >> A;
    cout << (u32)ceil((double)H / A)  << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};

int main(void){
    int A[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int K;
    cin >> K;
    K--;
    cout << A[K] << endl;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n,ar[10000000];
  vector<int>v;
  cin >> n;
  for(int i=0;i<n;i++){
      cin >> ar[i];
  }
  int a=1;
  for(int i=n-2;i>=0;i--){
      if(ar[i]>=ar[i+1])
          a++;
      else{
         v.push_back(a);
         a=1;
      }
  }
  v.push_back(a);
  sort(v.begin(),v.end(),greater<int>());
  cout << v[0]-1 << endl;
    return 0;
}


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

typedef long long LL;
typedef pair<int, int> II;

const int MAXN = 50 + 10;
int n, a[MAXN];

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);

    vector<II> ans;
    int neg = min(0, *min_element(a + 1, a + 1 + n));
    int pos = max(0, *max_element(a + 1, a + 1 + n));
    if (pos >= -neg) {
        int f = max_element(a + 1, a + 1 + n) - a;
        for (int i = 1; i <= n; ++i) {
            if (a[i] < 0) {
                a[i] += a[f];
                ans.push_back(II(f, i));
            }
        }
        for (int i = 2; i <= n; ++i) {
            a[i] += a[i - 1];
            ans.push_back(II(i - 1, i));
        }
    } else {
        int f = min_element(a + 1, a + 1 + n) - a;
        for (int i = 1; i <= n; ++i) {
            if (a[i] > 0) {
                a[i] += a[f];
                ans.push_back(II(f, i));
            }
        }
        for (int i = n - 1; i >= 1; --i) {
            a[i] += a[i + 1];
            ans.push_back(II(i + 1, i));
        }
    }

    printf("%d\n", (int) ans.size());
    for (int i = 0; i < (int) ans.size(); ++i)
        printf("%d %d\n", ans[i].first, ans[i].second);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
map<char,int>mp;
int main(){
	//freopen("readin.txt","r",stdin);
	int n;
	scanf("%d",&n);
	string s;
	cin >> s;
	char c = '(',c1 = ')';
	stack<char>st;
	for(int i = 0;i < s.size();i++){
		if(!st.empty())
			if(st.top() == c && s[i] == c1){
				st.pop();
				continue;
			}
		st.push(s[i]);
	}
	while(!st.empty()){
		mp[st.top()]++;
		st.pop();
	}
	for(int i = 0;i < mp[c1];i++)
		printf("(");
	cout << s;
	for(int i = 0;i < mp[c];i++)
		printf(")");
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string.h>
#include <stack>
#include <set>

const int maxN = 1e6 + 9;

using namespace std;
typedef long long ll;

set<ll> negs, poss;

ll amp(int sta, ll nm){
    ll ret = 0;
    for(int i = 0; i < 17; i++){
        if(1 << i & nm){
            ret |= ll(1) << (i * 2 + sta);
        }
    }
    return ret;
}

void prt(ll x){
    bool out = false;
    for(int i = 50; i >= 0; i--){
        if(ll(1) << i & x){
            out = true;
            cout << 1;
        }
        else if(out){
            cout << 0;
        }
    }
    cout << '\n';
}

//1, -2, 4, -8, 16, -32
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    
    for(int i = 0; i < (1 << 17); i++){
        poss.insert(amp(0, i));
        negs.insert(amp(1, i));
    }
    
    int n;
    cin >> n;
    if(!n){
        cout << "0\n"; return 0;
    }
    
    //if(n < 0) swap(negs, poss);
    
    for(auto it = poss.begin(); it != poss.end(); it++){
        if(negs.find(*it - n) != negs.end()){
            //cout << *it << '\n';
            prt(*it | (*it - n));
            return 0;
        }
    }
    
}


Measured memory_bytes: 12544
#include <iostream>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli> > mat;
typedef vector<vector<bool> > matb;
typedef vector<string> vst;
typedef pair<lli,lli> pll;
typedef pair<double,double> pdd;

vll par;
vll rnk;
void init(lli n){
    par = vll(n);
    rnk = vll(n);
    for(lli i = 0;i < n;i++) par[i] = i;
}
lli find(lli x){
    if(par[x] == x) return x;
    else return par[x] = find(par[x]);
}
void unite(lli x,lli y){
    x = find(x);y = find(y);
    if(x == y) return;
    if(rnk[x] < rnk[y]) par[x] = y;
    else {
        par[y] = x;
        if(rnk[x] == rnk[y]) rnk[x]++;
    }
}
bool same(lli x,lli y){
    return find(x) == find(y);
}

lli n;
vll c,r,l;
vll p;
mat g;
lli ans = 0;

int main(){
    cin >> n;
    g = mat(n,vll(n));
    for(lli i = 0;i < n;i++){
        for(lli j = 0;j < n;j++){
            cin >> g[i][j];
        }
    }
    for(lli i = 0;i < n;i++){
        for(lli j = i+1;j < n;j++){
            if(g[i][j] >= 0) c.push_back(g[i][j]),r.push_back(i),l.push_back(j);
        }
    }
    p = vll(c.size());
    for(lli i = 0;i < p.size();i++) p[i] = i;
    sort(p.begin(),p.end(),[](lli a,lli b){
        return c[a] < c[b];
    });
    init(n);
    for(lli i = 0;i < p.size();i++){
        if(!same(r[p[i]],l[p[i]])) unite(r[p[i]],l[p[i]]),ans += c[p[i]];
    }
    cout << ans << endl;
    return 0;
}

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

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int no = 0;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (a[i] % 2) ++no;
  }
  cout << (no % 2 ? "NO" : "YES") << endl;
  return 0;
}



Measured memory_bytes: 640
IDENTIFICATION DIVISION.
PROGRAM-ID. 167A.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 S          PIC X(12).
01 T          PIC X(12).
01 L1         PIC 9(02).
01 L2         PIC 9(02).
*>
PROCEDURE DIVISION.
  ACCEPT S.
  ACCEPT T.
  UNSTRING S DELIMITED BY ' '
      INTO S COUNT L1.
  UNSTRING T DELIMITED BY ' '
      INTO T COUNT L2.
*>
  IF (L2 = L1 + 1) AND
     (S(1:L1) = T (1:L1))
    DISPLAY 'Yes'
  ELSE
    DISPLAY 'No'
  END-IF. 
*>
  STOP RUN.


Measured memory_bytes: 3780
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>

using namespace std;

typedef long long ll;
const ll nmax = 1e9 + 7;
const ll mod = 998244353;
const long long INF = 1e18;
const double PI = 2 * asin(1);

ll AN(ll A, ll N){
  if (N == 0) return 1;
  else{
    if (N % 2 == 0) {
      return AN(A * A % mod, N / 2) % mod;
    }else{
      return A * AN(A * A % mod, N / 2) % mod;
    }
  }
}

int main(){

  ll N; cin >> N;
  vector <ll> dir(N + 1), rev(N + 1);
  dir[0] = 1;
  for (ll i = 1; i < N + 1; i++){
    dir[i] = dir[i - 1] * i % mod;
  }
  for (ll i = 0; i < N + 1; i++){
    rev[i] = AN(dir[i], mod - 2);
  }

  ll ans = 0;
  ll A, B, K; cin >> A >> B >> K;

  for (ll i = 0; i <= N; i++){
    ll rest = K - A * i;
    if (rest >= 0 && rest % B == 0 && rest / B <= N){
      ll a = i, b = rest / B;
      ll now = dir[N];
      now *= rev[a]; now %= mod;
      now *= rev[N - a]; now %= mod;
      now *= dir[N]; now %= mod;
      now *= rev[b]; now %= mod;
      now *= rev[N - b]; now %= mod;
      ans += now; ans %= mod;
    }else if (rest < 0) {
      break;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4992
m, n = map(int, input().split())

P = 10 ** 9 + 7

# 繰り返し二乗法
def pow(x, n, p):
  r = 1
  while n > 0:
    if n & 1:
      r = (r * x) % p
    x = (x * x) % p
    n >>= 1
  return r

print(pow(m, n, P))



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

void dfs(int x, vector<vector<int>> &da, vector<bool> &ju) {
	int y = da[x].size();
	for (int i = 0;i < y;i++) {
		if (!ju[da[x][i]]) {
			ju[da[x][i]] = true;
			dfs(da[x][i], da, ju);
		}
	}
	return;
}

int main() {
	int n, m, p;
	cin >> n >> m >> p;
	vector<vector<int>> da1(n), da2(n);
	vector<tuple<int, int, int>> da(m);
	vector<bool> ju1(n, false), ju2(n, false);
	ju1[0] = true;
	ju2[n - 1] = true;
	for (int i = 0;i < m;i++) {
		int a, b, c;
		cin >> a >> b >> c;
		da1[a - 1].push_back(b - 1);
		da2[b - 1].push_back(a - 1);
		da[i] = make_tuple(a-1, b-1, p-c);
	}
	dfs(0, da1, ju1);
	dfs(n - 1, da2, ju2);
	vector<tuple<int, int, int>>daa(0);
	for (int i = 0;i < m;i++){
		if (ju2[get<1>(da[i])] && ju1[get<0>(da[i])] && ju2[get<0>(da[i])] && ju1[get<1>(da[i])]) {
			daa.push_back(da[i]);
		}
	}
	m = daa.size();
	vector<int> st(n, INT_MAX);
	st[0] = 0;
	for (int i = 0;i < n;i++) {
		for (int j = 0;j < m;j++) {
			if (st[get<0>(daa[j])] != INT_MAX) {
				st[get<1>(daa[j])] = min(st[get<1>(daa[j])], st[get<0>(daa[j])] + get<2>(daa[j]));
			}
		}
	}
	bool ju = true;
	for (int i = 0;i < m;i++) {
		if (st[get<0>(daa[i])] != INT_MAX) {
			if (st[get<1>(daa[i])] > st[get<0>(daa[i])] + get<2>(daa[i])) {
				ju = false;
				break;
			 }
		}
	}
	if (ju) {
		cout << max(-st[n-1],0);
	}
	else {
		cout << -1;
	}
	cout << endl;
}


Measured memory_bytes: 896
using System;
using System.Collections.Generic;
using System.Linq;

namespace debug
{
    public static partial class Program
    {
        public static void Main()
        {
            var str = Console.ReadLine();
            var dist = str.Distinct();
            if (dist.Count() == 2)
            {
                foreach (var dis in dist)
                {
                    if (str.Count(x => x == dis) != 2)
                    {
                        Console.WriteLine("No");
                        return;
                    }
                }
            }
            else
            {
                Console.WriteLine("No");
                return;
            }
            
            Console.WriteLine("Yes");
        }
    }

    public static partial class Program
    {
        //テンプレここから
        public static long a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z;
        public static long GCD(long aaa, long bbb) => bbb == 0 ? aaa : GCD(bbb, aaa % bbb);
        public static long LCM(long aaa, long bbb) => aaa * bbb / GCD(aaa, bbb);
        public static long ToLong(this double ddd) => (long) ddd;
        public static long ToLong(this string str) => long.Parse(str);
        public static long[] ToLong(this IEnumerable<string> strs) => strs.Select(x => x.ToLong()).ToArray();
        public static long[] ArrayLongs(this string str, char opr = ' ') => str.Split(opr).ToLong();
        public static long Diff(long aaa, long bbb) => Math.Abs(Math.Max(aaa, bbb) - Math.Min(aaa, bbb));
        public static long Sign(this long iii) => Math.Sign(iii);
        public static bool IsEven(this long iii) => iii % 2 == 0;
        public static readonly int[] Dx = {0, -1, 0, 1};
        public static readonly int[] Dy = {-1, 0, 1, 0};
        public const int MOD = 1000000007;
        public const string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        public const string ALPHABET = "abcdefghijklmnopqrstuvwxyz";
        public static long ToLong(this char ccc) => ccc.ToString().ToLong();
        public static string Join(this IEnumerable<string> array, string sep = "") => string.Join(sep, array);
        public static string Join(this IEnumerable<char> array, string sep = "") => string.Join(sep, array);
        public static string JoinToStr(this IEnumerable<long> array, string sep = "")
            => array.Select(xxx => xxx.ToString()).Join(sep);
        //テンプレここまで
    }
}

Measured memory_bytes: 13268
/*
 * Created by KeigoOgawa
 */


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <cmath>

#define INF (int)1e8
#define EPS 1e-10
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define RFOR(i, a, b) for (ll 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--)
#define MIN(a, b) (a > b ? b : a)
#define MAX(a, b) (a > b ? a : b)
#define debug(x) cout << #x << ": " << x << endl
#define all(a) (a).begin(), (a).end()

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;

ll N;

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

    cin >> N;
    FOR(h, 1, 3500) {
        FOR(n, h, 3500) {
            ll x = N * h * n;
            ll y = 4 * h * n - n * N - N * h;
            if (y > 0 && x % y == 0) {
                cout << h << " " << n << " " << x/y << endl;
                return 0;
            }
        }
    }


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define vi vector<int>
#define vvi vector<vector<int>>
#define pii pair<ll,ll>
#define tii tuple<ll,ll,ll>
#define all(v) (v).begin(),(v).end()
#define ll long long
#define ull unsigned long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define ld long double
#define mod 1000000007
#define PI 3.141592653589793238
#define phi 1.638
#define eps 1e-7
#define endl "\n"
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int32_t main() {
    fastio
    string s;
    cin>>s;
    if(s[1] == 'R') {
        cout<<"ABC";
    }
    else {
        cout<<"ARC";
    }
    cout<<endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
const int INF = 0x3f3f3f3f;
const int MOD = 1000000007;
int main() {
  ll n;
  cin >> n;
  multiset<ll> factors;
  for (ll i = 1; i <= sqrt(n); i++) {
    if (n % i == 0)
      factors.insert(i), factors.insert(n / i);
  }
  ll ans = 0;
  for (ll x : factors) {
    ll m = n / x - 1;
    // cout << m << ' ' << endl;
    if (m != 0 && n % m != n / m)
      continue;
    ans += m;
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os, const map<T,U>& mp){ os << "{"; for(auto& p : mp){ os << p << ","; } os << "}"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int,int>;
using vi = std::vector<int>;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int main(){
    int k,t; cin >> k >> t;
    vector<int> a(t);
    rep(i,t){
        cin >> a[i];
    }
    ll sum = accumulate(all(a),0LL);
    ll mx  = *max_element(all(a));
    ll r = sum - mx;

    cout << max(0LL, mx - r - 1) << endl;
}


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

using namespace std;
typedef long long ll;

int main(void)
{
    double n, k;
    cin >> n >> k;
    double c=0, m=1;
    int max_cnt=0;
    for (int i = 1; i <= n; i++){
        int cnt = 0;
        int point = i;
        while (point<k){
            point *= 2;
            cnt++;
        }
        max_cnt = max(cnt, max_cnt);
        double t=1;
        if (max_cnt - cnt >= 1){
            for (int j = 0; j < max_cnt - cnt;j++)t *= 2;
        }
        c += 1.0 * t;
//        cout << c << endl;
    }
    while(max_cnt>0){
        m *= 2.0;
        max_cnt--;
    }
    m *= n;
 //   cout << m << endl;
    double ans = c / m;
    printf("%.12lf\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

typedef long long ll;

ll n;
ll s, e;
vector<ll> ve[100005];
ll a[100005], b[100005];
ll d[100005];

void dfs(ll p, ll q)
{
    if(d[p]) return;
    a[p] = a[q] + 1;
    d[p] = q;
    for(ll i = 0; i < ve[p].size(); i++)
    {
        if(ve[p][i] == q) continue;
        dfs(ve[p][i], p);
        b[p] = max(b[p], b[ve[p][i]] + 1);
    }
    if(ve[p].size() == 0) b[p] = 0;
}

int main()
{
    scanf("%lld%lld%lld", &n, &s, &e);
    for(ll i = 0; i < n - 1; i++)
    {
        ll t1, t2;
        scanf("%lld%lld", &t1, &t2);
        ve[t1].push_back(t2), ve[t2].push_back(t1);
    }
    dfs(e, e);
    ll ans = 0;
    if(a[s] % 2 == 0)
    {
        ans = a[s] / 2 - 1;
        ll t = ans;
        while(t--) s = d[s];
        ans += b[s];
    }
    else
    {
        ans = a[s] / 2 - 1;
        ll t = ans;
        while(t--) s = d[s];
        ans += b[s] + 1;
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 12032
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int n, m;
    cin >> n >> m;
    vi deg(n, 0);
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        deg[a]++;
        deg[b]++;
    }
    for (int i = 0; i < n; ++i) {
        if (deg[i] % 2 == 1) {
            cout << "NO"
                 << "\n";
            return 0;
        }
    }
    cout << "YES"
         << "\n";
    return 0;
}

Measured memory_bytes: 768