akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

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

    int A, B, C;
    cin >> A >> B >> C;
    int K;
    cin >> K;

    int cnt = 0;
    while (A >= B) {
        B *= 2;
        cnt++;
    }
    while (B >= C) {
        C *= 2;
        cnt++;
    }

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

Measured memory_bytes: 3648
Sp = input()
T = input()

def matchFound(s, t):
    for i in range(len(t)):
        if s[i] != "?" and s[i] != t[i]:
            return False
    return True

res = "UNRESTORABLE"
for i in range(len(Sp)-len(T), -1, -1):
    #print(i)
    if matchFound(Sp[i:], T):
        Sp = Sp[:i] + T + Sp[i+len(T):]
        res = Sp.replace("?", "a")
        break;
        
print(res)

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<ld> vld;
typedef vector<string> vstr;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); ++i)
#define TS to_string
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define endl "\n"

ll INF = 1e9;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}

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

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

  ll n, q;
  cin >> n >> q;
  vector<queue<ll>> st(n);

  REP(i,q){
    ll com;
    cin >> com;
    if(com == 0){
      ll t, x;
      cin >> t >> x;
      st[t].push(x);
    }
    else if(com == 1){
      ll t;
      cin >> t;
      if(!st[t].empty()) cout << st[t].front() <<endl;
    }
    else{
      ll t;
      cin >> t;
      if(!st[t].empty()) st[t].pop();
    }
  }
    
  return 0;
}




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

int n;
vector<int> h(2000001);

void maxHeapify(int i){
  int l = 2*i;
  int r = 2*i+1;
  int largest;
  if(l <= n && h.at(l) > h.at(i)){
    largest = l;
  }else{
    largest = i;
  }

  if(r <= n && h.at(r) > h.at(largest)){
    largest = r;
  }
  
  if(largest != i){
    swap(h.at(i),h.at(largest));
    maxHeapify(largest);
  }
}



int main(){
  cin >> n;
  for(int i = 1; i <= n; i++){
    cin >> h.at(i);
  }
  for(int i = n/2;i >= 1;i--){
    maxHeapify(i);
  }
  for(int i = 1; i <= n; i++){
    cout << " " << h.at(i);
  }
  cout << endl;
  return 0;
}


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

int main() {
	vector<int> vec(10);
	for (int i = 0; i < 10; i++) cin >> vec[i];
	sort(vec.begin(), vec.end(), greater<int>());
	cout << vec[0] + vec[1] + vec[2] << " " << flush;
	for (int i = 0; i < 10; i++) cin >> vec[i];
	sort(vec.begin(), vec.end(), greater<int>());
	cout << vec[0] + vec[1] + vec[2] << endl;
	return 0;
}


Measured memory_bytes: 3144
object Main extends App {
        var a = readInt
        var num = readLine
        var max = 0
        var sum = 0
        var j = 0
        for {j <- 0 to a - 1} {
            sum = sum + num.split(" ")(j).toInt
            if (max < num.split(" ")(j).toInt) {
                max = num.split(" ")(j).toInt
            }}
        sum = sum - max
        if (max >= sum) {
            println("No")
        } else {
            println("Yes")
        }
    }

Measured memory_bytes: 27208
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class Main {
	
    public static void main(String[] args) throws IOException{
         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
         while(true) {
             StringTokenizer st = new StringTokenizer(br.readLine());
             int a = Integer.parseInt(st.nextToken());
             String op = st.nextToken();
             int b = Integer.parseInt(st.nextToken());
             
             if(op.equals("+")) System.out.println(a+b);
             else if(op.equals("-")) System.out.println(a-b);
             else if(op.equals("*")) System.out.println(a*b);
             else if(op.equals("/")) System.out.println(a/b);
             else if(op.equals("?")) break;
         }
    }
}


Measured memory_bytes: 24256
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <map>

#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  int D; cin >> D;
  string result;
  if (D==22) result = "Christmas Eve Eve Eve";
  if (D==23) result = "Christmas Eve Eve";
  if (D==24) result = "Christmas Eve";
  if (D==25) result = "Christmas";
  cout << result << endl;
  return 0;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

vector<int> pathes[100050];
int dist[100050][2];

void bfs(int from, int cost, int checker){
    for(int i = 0; i < pathes[from].size(); i++){
        int to = pathes[from][i];
        if(dist[to][checker] <= cost + 1) continue;
        dist[to][checker] = cost + 1;
        bfs(to, cost + 1, checker);
    }
}

int main() {
    //cout.precision(10);
    int n;
    cin >> n;
    for(int i = 1; i < n; i++){
        int a, b;
        cin >> a >> b;
        pathes[a].push_back(b);
        pathes[b].push_back(a);
    }
        for(int i = 1; i <= n; i++){
            dist[i][0] = INF;
            dist[i][1] = INF;
        }
        dist[1][0] = 0;
        dist[n][1] = 0;
        bfs(1, 0, 0);
        bfs(n, 0, 1);
        int counter[2];
        counter[0] = 0;
        counter[1] = 0;
        for(int i = 1; i <= n; i++){
            if(dist[i][0] <= dist[i][1]) counter[0]++;
            else counter[1]++;
        }
    if(counter[1] >= counter[0]){
        cout << "Snuke" << endl;
    } else {
        cout << "Fennec" << endl;
    }
    return 0;
}


Measured memory_bytes: 12800
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 998244353
#define PI 3.14159265358979323846
#define INF 1 << 30

using namespace std;
typedef long long ll;
typedef pair<int, int> pp;
typedef struct {
	int l, r;
} area;

int main(void) {
	int num, i, j, k;
	cin >> num >> k;
	vector<ll> dp(num + 2, 0);
	vector<area> a(k);
	rep(i, k)
		cin >> a[i].l >> a[i].r;
	dp[1] = 1;
	dp[2] = -1;
	for (i = 1; i < num; i++) {
		rep(j, k) {
			dp[min(i + a[j].l, num + 1)] += dp[i];
			dp[min(i + a[j].r + 1, num + 1)] -= dp[i];
		}
		dp[i + 1] += dp[i];
		dp[i + 1] %= MOD;
	}
	if (dp[num] < 0)
		dp[num] += MOD;
	cout << dp[num] << "\n";
	return 0;
}

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

def main():
    S = int(input())

    x1, y1 = 0, 0
    x2, y2 = 10**9, 1

    x3 = (x2 - (S % x2)) % x2
    y3 = (S + x3) // x2

    print('{} {} {} {} {} {}'.format(x1, y1, x2, y2, x3, y3))


if __name__ == "__main__":
    main()


Measured memory_bytes: 9000
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 1; i < n; i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define P pair<int, int>
typedef long long ll;
const ll mod = 1e9+7;

//繰り返し自乗法による累乗計算
//a**n
ll pow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = pow(a, n/2);
    return res * res;
  }
  return a * pow(a, n-1);
}
//繰り返し自乗法によるmod累乗計算
//a**n (mod)
ll modpow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = modpow(a, n/2);
    return res * res % mod;
  }
  return a * modpow(a, n-1) % mod;
}
//組み合わせ
//nCa
ll com(ll n, ll a){
  ll x = 1, y = 1;
  rep(i,a){
    x *= n-i;
    y *= i+1;
  }
  ll res = x / y;
  return res;
}
//組み合わせ(mod)
//nCa (mod)
ll modcom(ll n, ll a){
  ll x = 1, y = 1;
  rep(i, a){
    x = x * (n-i) % mod;
    y = y * (i+1) % mod;
  }
  ll ans = x * modpow(y, mod-2) % mod;
  return ans;
}
//gcd 最大公約数
ll gcd(ll x, ll y){
  if(x % y == 0) return y;
  return gcd(y, x%y);
}
//lcm 最小公倍数
ll lcm(ll x, ll y){
  return x * y / gcd(x, y);
}
//ngcd n個の最大公約数
ll ngcd(vector<ll> a){
  ll res;
  res = a[0];
  for(ll i = 1; i < a.size() && res != 1; i++) {
    res = gcd(a[i], res);
  }
  return res;
}
//nlcm n個の最小公倍数
ll nlcm(vector<ll> a) {
  ll res;
  res = a[0];
  for (ll i = 1; i < a.size(); i++) {
    res = lcm(res, a[i]);
  }
  return res;
}
// 素数判定
bool isprime(ll x){
  ll i;
  if(x < 2) return false;
  else if(x == 2) return true;
  if(x % 2 == 0) return false;
  for(i = 3; i*i <= x; i += 2){
    if(x % i == 0) return false;
  }
  return true;
}
// 桁和
ll digsum(ll x){
  ll res = 0;
  while(x > 0){
    res += x % 10;
    x /= 10;
  }
  return res;
}


int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  sort(all(a));
  int ans = a[n-1] - a[0];
  cout << ans << endl;
}



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


int main(){
	int x,y,m,t;
	cin >> x >> y;

	if( x<y ){
		t = x;
		x = y;
		y = t;
	}

	while(1){
		m = x%y; // %??????????????????
		if( m==0 ) break;
		
		x = y; // x???y?????????
		y = m; // y???m??????????????¨??§?¬???? y???m??§??????
	}

	cout << y << "\n";
	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h> 
 
using namespace std;
 
 template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 

int main(){
    string s;
    cin>>s;
    int N=SZ(s)-1;
    LL sum=0;
    for(int i=0;i<(1<<N);i++){
        LL tmp=s[0]-'0';
        for(int j=0;j<N;j++){
            if(i&(1<<j)){
                sum+=tmp;
                tmp=(s[j+1]-'0');
            }else{
                tmp*=10;
                tmp+=(s[j+1]-'0');
            }
        }
        sum+=tmp;
    }
    cout<<sum<<endl;
    return 0;
}


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

string s;
int p;

string readChipher();
string readString();
string readLetter();

string readChipher(){
  string res="";
  while(p<s.length() && s[p]!=']'){
    res+=readString();
  }
  return res;
}

string readString(){
  string res="";
  if(s[p]=='['){
    p++;//'['???
    res+=readChipher();
    p++;//']'???
    reverse(res.begin(), res.end());
  }
  else{
    res+=readLetter();
  }
  return res;
}

string readLetter(){
  string res="";
  int cnt=0;
  while(s[p]=='+' || s[p]=='-'){
    if(s[p]=='+')cnt++;
    if(s[p]=='-')cnt--;
    p++;
  }

    char tmp=s[p];
    p++;
    if(tmp=='?')res+="A";
    else res+=(((tmp-'A')+(26*4)+cnt)%26+'A');

  return res;
}

int main(){
  while(cin>>s, s!="."){
    p=0;
    cout<<readChipher()<<endl;
  }
  return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#ifdef DEBUG
#include "_debug.cpp"
#include "callable.hpp/callable.hpp"
#endif
#define endl '\n'
using namespace std;
using ll = long long;
#define N 5000
int A, B;
int a[N], b[N];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> A >> B;
    for(int i = 0; i < A; i++) {
        cin >> a[i];
    }
    for(int i = 0; i < B; i++) {
        cin >> b[i];
    }
    int ans = 0;
    for(int s = 0; s < B; s++) {
        int aptr = 0;
        int bptr = s;
        for(int e = s; e < B; e++) {
            while(aptr < A and bptr <= e) {
                if(a[aptr] == b[bptr]) {
                    aptr++;
                    bptr++;
                } else {
                    aptr++;
                }
            }
            if(bptr == e + 1) {
                ans = max(ans, e - s + 1);
            }
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3228
/// Bismillahir Rahmanir Rahim
/* Mohammad Morsalin
   Dept of ICE, NSTU
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define mp make_pair
//#define endl "\n"
#define int long long
#define f0(n) for(int i=0;i<n;i++)
#define ms(x) memset(x,0,sizeof(x))
#define ms2d(x,m,n) memset(x, 0, sizeof(x[0][0]) * m * n)
#define uniq(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define pi pair<int,int>
#define tc(t) int t;cin>>t;while(t--)
#define bits(n) __builtin_popcount(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define ins insert
#define ALL(v) v.begin(),v.end()
#define highest(x) numeric_limits<x>::max()
#define lowest(x) numeric_limits<x>::min()
#define Inf INFINITY
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define fi first
#define se second
#define PI acos(-1)
#define sz(a) (int)a.size();
#define IOS ios::sync_with_stdio(false);
using namespace std;
int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a);}
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const long long MOD = 1000000007;
double sq(double x) {return x*x;}
template<typename T>inline T Bigmod(T base, T power, T MOD){
    T ret=1;
    while(power)
    {
        if(power & 1)ret=(ret*base)%MOD;
        base=(base*base)%MOD;
        power>>=1;
    }
    return ret;
}

bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}
signed main()
{
    IOS
    string s,t;
    cin>>s>>t;
    int ans=11000;
    for(int i=0;i<(int)s.size()-t.size()+1;i++){
        string d=s.substr(i,t.size());
        int mis=0;
        //cout << d << endl;
        for(int j=0;j<(int)d.size();j++){
            if(d[j]!=t[j])mis++;
        }
        ans=min(mis,ans);
    }
    cout << ans << endl;
    return 0;
}
///Alhamdulillah


Measured memory_bytes: 3612
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
typedef tuple<int, int, int> t3;
typedef pair<ll, ll> pll;
typedef long double ldouble;
typedef pair<double, double> pdd;

vector <int> E[2][100010];
int par[2][100010];
int N;

int ans[100010];
int now;
int from[800080];
vector <int> F[800080];
int color[800080];

void dfs(int x, int c) {
	color[x] = c;
	for(int e : F[x]) if(color[e] == 0) dfs(e, -c);
}

void solve(){
	scanf("%d", &N);
	for(int i=1;i<=N;i++) {
		scanf("%d", par[0]+i);
		if(par[0][i] != -1) E[0][par[0][i]].pb(i);
	}
	for(int i=1;i<=N;i++) {
		scanf("%d", par[1]+i);
		if(par[1][i] != -1) E[1][par[1][i]].pb(i);
	}
	for(int i=1;i<=N;i++) {
		int a = sz(E[0][i]);
		int b = sz(E[1][i]);
		if(a % 2 != b % 2) {
			puts("IMPOSSIBLE");
			return;
		}
	}
	puts("POSSIBLE");
	now = N;
	for(int i=1;i<=N;i++) from[i] = i;
	for(int i=1;i<=N;i++) {
		int L = max(sz(E[0][i]), sz(E[1][i]));
		if(L == 1) L = 3;
		if(L == 2) L = 4;
		if(L == 0) continue;
		vector <int> use;
		rep(u, L-2) use.pb(++now);
		rep(u, 2) {
			int z = 0;
			int t = (L - sz(E[u][i])) / 2;
			while(t--) { E[u][i].pb(use[z]); from[use[z]] = i; ++z; }
			int p = E[u][i][0];
			for(int j=1;j<sz(E[u][i]);j++) {
				int nxt = E[u][i][j];
				F[p].pb(nxt); F[nxt].pb(p);  //printf("%d - %d\n", p, nxt);
				if(j != sz(E[u][i]) - 1) {
					p = use[z++];
					from[p] = i;
				}
			}
		}
	}
	for(int i=1;i<=now;i++) if(color[i] == 0) dfs(i, 1);
	for(int i=1;i<=now;i++) ans[from[i]] += color[i];
	for(int i=1;i<=N;i++) printf("%d ", ans[i]); puts("");
}

int main(){
	int T = 1; // scanf("%d", &T);
	while(T--) {
		solve();
	}
	
	return 0;
}


Measured memory_bytes: 44272
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan =new Scanner(System.in);
		String s = scan.next();
		int len = s.length();
		int count = 0;

		for(int i=0;i< len/2 ;i++) {
			if(s.charAt(i) != s.charAt(len-1-i)){
				count ++;
			}
		}

		System.out.println(count);
	}
}


Measured memory_bytes: 23764
#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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;
}

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

ll mod_pow(ll x, ll n, ll mod) {
	ll res = 1LL;
	while (n > 0) {
		if (n & 1) res = res * x % mod;
		x = x * x % mod;
		n >>= 1;
	}
	return res;
}

ll mod_inv(ll x, ll mod) {
	return mod_pow(x, mod - 2, mod);
}

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

	ll n;
	cin >> n;
	Array x(n, 0);
	REP(i,n) cin >> x[i];

	Array sum(n, 0);
	REP(i, n-1) {
		sum[i + 1] += sum[i] + mod_inv(i + 1, MOD);
	}

	ll ans = 0;
	REP(i, n-1) {
		(ans += sum[i+1] * (x[i + 1] - x[i]) % MOD) %= MOD;
	}

	ll a = 1;
	REP(i, n - 1) {
		(a *= (i + 1)) %= MOD;
	}
	(ans *= a) %= MOD;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1792
S = input()

ans = 0  # a1, a2, ... , ai の総和
a = 0   # a[i+1]
d = 0   # <> からの距離
p = '_'  # S[i-1]

for i in range(len(S)):
    if p == '>' and S[i] == '<':
        if a > 0:
            ans -= a*d
        elif a < 0:
            ans += -a*(d+1)
        a = 1
    elif S[i] == '<':
        a += 1
    elif p == '<' and S[i] == '>':
        a -= 1
        d = 1
    elif S[i] == '>':
        a -= 1
        d += 1
    ans += a
    p = S[i]
    # print(i, S[i], a, d, ans)

if S[-1] == '>':
    if a > 0:
        ans -= a*d
    elif a < 0:
        ans += -a*(d+1)


print(ans)


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

using namespace std;
const int N = 405;
unsigned long long dp[N][N],s[N][N],v[N];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i<=n; i++)
        cin >> v[i];
    for (int i = 1; i<=n; i++)
        for (int j = i; j<=n; j++)
            s[i][j] = s[i][j-1]+v[j];
    for (int i = 1; i<=n; i++)
        for (int j = i; j<=n; j++)
            dp[i][j] = 1e18;
    for (int i = 1; i<=n; i++)
        dp[i][i] = 0;
    for (int i = n-1; i>=1; i--)
        for (int j = i+1; j<=n; j++)
            for (int z = i; z<=j; z++)
                dp[i][j] = min(dp[i][j],dp[i][z]+dp[z+1][j]+s[i][j]);
    cout << dp[1][n];
}


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

int find(string str, const string& word) {
  int count = 0;
  for (string::size_type pos = 0; (pos = str.find(word, pos)) != string::npos; pos += word.size()) {
    ++count;
  }
  return count;
}

int main(){
    int N;
    cin >> N;
    vector<string> S(N);
    vector<int> last(N);
    vector<int> first(N);
    int count = 0;
    int count_ab = 0;
    int last_ = 0;
    int first_ = 0;
    for(int i = 0; i < N; i++){
        cin >> S[i];
        string str = S[i];
        int s = 0;
        count += find(str, "AB");
        if(str[0] == 'B'){
            first_ += 1;
        }
        if(str[str.length() -1 ] == 'A'){
            last_ += 1;
        }
        if((str[0] == 'B' )&& (str[str.length() -1 ] == 'A')){
            count_ab += 1;
        }
    }
    count += min(first_,last_);
    if((count_ab > 0) && (count_ab == first_) && (count_ab == last_)){
        count -= 1;
    }
    std::cout << count << endl;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int>P;
int dp[1010][1010];
int main(){
	int n;cin>>n;
	vector<P>V(n);
	for(int i=0;i<n;i++)cin>>V[i].second>>V[i].first;
	sort(V.begin(),V.end());
	for(int i=0;i<1010*1010;i++)dp[i/1010][i%1010]=1e9;
	dp[0][0]=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<=i;j++){
			dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
			if(dp[i][j]+V[i].second<=V[i].first){
				dp[i+1][j+1]=min(dp[i+1][j+1],dp[i][j]+V[i].second);
			}
		}
	}
	int ans=0;
	for(int i=n;i>=0;i--){
		if(dp[n][i]!=1e9){
			ans=i;
			break;
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var x = cin.ReadInt;
            var a = cin.ReadInt;
            var b = cin.ReadInt;
            if (a >= b)
            {
                Console.WriteLine("delicious");
            }
            else if (b <= x + a)
            {
                Console.WriteLine("safe");
            }
            else
            {
                Console.WriteLine("dangerous");
            }
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}

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

using namespace std;

typedef long long ll;

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

	int a, b, c;
	cin >> a >> b >> c;

	cout << min(b / a, c) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int h1,h2,m1,m2,k;
	cin>>h1>>m1>>h2>>m2>>k;
	int total=0;
	if(m1<=m2) total=(h2-h1)*60+m2-m1;
	else total=(h2-h1-1)*60+60-m1+m2;
if(k<=total)
		printf("%d\n",total-k );
else printf("0\n");
}

Measured memory_bytes: 3764
import * as fs from 'fs';

const input = fs.readFileSync('/dev/stdin', 'utf8');

_c(input);

function _c(input: string) {
  const [_nmk, _A, _B] = input.split('\n');
  let k = parseInt(_nmk.split(' ')[2]);
  const A = _A.split(' ').map((s) => parseInt(s));
  const B = _B.split(' ').map((s) => parseInt(s));

  const a = calcSummaries(A, k);
  const b = calcSummaries(B, k);

  let count = 0;
  let maxJ = b.length - 1;

  for (let i = 0; i < a.length; i++) {
    for (let j = maxJ; j >= 0; j--) {
      if (a[i] + b[j] <= k) {
        count = Math.max(i + j, count);
        maxJ = j;
        break;
      }
    }
  }

  console.log(count);
}

/**
 * 机から i 冊 読んだときにかかる時間を a[i] に格納
 */
function calcSummaries(times: number[], limit: number) {
  const sums = [0];
  for (let i = 0; i < times.length; i++) {
    const sum = sums[i] + times[i];
    if (sum <= limit) {
      sums[i + 1] = sum;
    } else {
      break;
    }
  }
  return sums;
}


Measured memory_bytes: 63780
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<list>
#include<queue>
#include<functional>
#include<limits.h>
#include<string.h>
#include<algorithm> 
using namespace std;

signed main() {
	int n, t; cin >> n >> t;
	int ans = INT_MAX;
	for (int i = 0; i < n; i++) {
		int a, b; cin >> a >> b;
		if (b <= t)ans = min(ans, a);
	}
	if (ans == INT_MAX) {
		puts("TLE");
	}
	else	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define pb push_back
#define mp make_pair
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector< ii > vii;
typedef long long LL;
int a[105];
int main()
{
	int n, m;
	scanf("%d %d", &n, &m);
	if(m == 1)
	{
		printf("%d\n", n);
		if(n == 1)
		{
			printf("1\n1");
			return 0;
		}
		printf("2\n");
		printf("%d %d\n", 1, n-1);
		return 0;
	}
	int cnt = 0;
	for(int i = 0; i< m; i++)
	{
		scanf("%d", a+i);
		if(a[i]%2) cnt++;
	}
	if(cnt>2)
	{
		printf("Impossible\n");
		return 0;
	}
	for(int i = 1; i< m-1; i++)
	{
		if(a[i]%2)
		{
			if(a[0]%2) swap(a[i], a[m-1]);
			else swap(a[i], a[0]);
		}
	}
	for(int i = 0; i< m; i++) printf("%d ", a[i]);
	printf("\n");
	vector<int> ans;
	if(a[0]> 1) ans.pb(a[0]-1);
	for(int i = 1; i< m-1; i++) ans.pb(a[i]);
	ans.pb(a[m-1]+1);
	printf("%d\n", ans.size());
	for(int i = 0; i< (int) ans.size(); i++) printf("%d ", ans[i]);
	printf("\n");
	return 0;
}

Measured memory_bytes: 256
n = gets.to_i
s = gets.chomp.bytes

cnt = 0
(n-2).times do |i|
 j = i + 1
 k = j + 1
 while k < n
  cnt += 1 if s[i] != s[j] && s[i] != s[k] && s[j] != s[k]
  j += 1
  k += 2
 end
end

puts s.count(82) * s.count(71) * s.count(66) - cnt

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

ll binpow(ll a,ll b,ll mod){
    ll ret=1;
    while(b>0){
        if(b&1){
            ret=ret*a%mod;
        }
        a=a*a%mod;
        b=b>>1;
    }
    return ret;
}

int main(){

    ll h;
    cin >> h;
    ll cnt=1L;
    ll ans = 0L;
    while(h>0){
        h/=2;
        ans+=cnt;
        cnt*=2;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
// Exponential

#include <iostream>
#include <cmath>

using namespace std;

int main(){
	int X;
	cin >> X;

	int maxv = 1;

	for (int b = 2; b <= X; ++b){
		for (int p = 2; ; ++p){
			int power = (int)pow(b, p);
			//cout << power << endl;
			if (power > X)
				break;
			else
				maxv = max(maxv, power);
		}
	}

	cout << maxv << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;


public class Main {
    public static void main(String[] args) {
        // 自分の得意な言語で
        // Let's チャレンジ！！

        Scanner sc = new Scanner(System.in);
        String[] line = sc.nextLine().split(" ");
        
        int A = Integer.parseInt(line[0]);
        int B = Integer.parseInt(line[1]);
        int C = Integer.parseInt(line[2]);
        
        int[] array = new int[B+1];

        boolean solved = false;
        int l =1;

        while(!solved){

            int newA = A * l;

            int amari = newA % B;
          	if(amari == C){
                solved = true;
                break;
            }

            if(array[amari] == 1){
                break;
            }

            array[amari] = 1;

            l++;
        }

        if(solved){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    }
       
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
 
// cout<<fixed<<setprecision(10);
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

const int NM = 1e5 + 10;
int bb[NM];
int aa[NM];

int main() {
    int N, x; cin >> N >> x;
    rep(i, N) {
        int t; cin >> t;
        aa[i] = t;
        bb[i] = t;
    }

    // bに対しgreedy
    if(bb[0] > x) {
        bb[0] = x;
    }
    for(int i=0; i<N-1; i++) {
        if(bb[i] + bb[i+1] > x) {
            bb[i+1] = x-bb[i];
        }
    }
    // 操作回数を取得
    ll ans = 0;
    rep(i, N) {
        ans += (aa[i] - bb[i]);
    }
    cout << ans << endl;
    return 0;
}


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

#define REPI(x) for(int i=0;i<x;i++)
#define REPJ(x) for(int j=0;j<x;j++)

#define REPISE (s,e) for(int i=s,i<e;i++)
#define REPJSE (s,e) for(int j=s,j<e;j++)

using namespace std;

int main ()
{
  int M,N;
  long long resn=1,resm=1;
  cin >> N >> M;

  for (int i=1;i<=2;i++)
  {
    if (N>=0)
    {
      resn *= N;
      N--;
    }

    if (M>=0)
    {
      resm *= M;
      M--;
    }
  }
  cout << resn/2 + resm/2 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 998244353LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

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

  vector<vector<lint>> dp(n + 1, vector<lint> (s + 1, 0));

  for (int i = 0; i <= n; i++) dp[i][0] = 1;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= s; j++) {
      dp[i + 1][j] += dp[i][j];
      dp[i + 1][j] %= MOD;

      if (j + a[i] <= s) {
        dp[i + 1][j + a[i]] += dp[i][j];
        dp[i + 1][j + a[i]] %= MOD;
      }
    }
  }

  lint ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += dp[i][s];
    ans %= MOD;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 70784
#include <bits/stdc++.h>
using std::string;
using std::vector;
using std::pair;
using lint = long long;

std::map<lint, lint> h;
int main() {
	lint n; scanf("%lld", &n);
	for (lint i = 0; i < n; i++) {
		lint a; scanf("%lld", &a);
		h[a]++;
	}
	vector<lint> vec;
	vector<lint> four;
	for (auto &t : h) {
		if (t.second >= 2)vec.push_back(t.first);
		if (t.second >= 4) four.push_back(t.first);
	}
	lint ans = 0;

	if (vec.size() >= 2) {
		ans = std::max(ans, vec.back() * vec[vec.size() - 2]);
	}
	if (!four.empty()) {
		ans = std::max(ans, four.back() * four.back());
	}
	printf("%lld", ans);
}

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

int main(){
    int a[3][3];
    bool c[3][3] = {false};
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            cin >> a[i][j];
        }
    }
    int n; cin >> n;
    for(int k = 0; k < n; k++){
        int b; cin >> b;

        for(int i = 0; i < 3; i++){
            for(int j = 0; j < 3; j++){
                if(b == a[i][j]){
                    c[i][j] = true;
                }
            }
        }
    }

    for(int i = 0; i < 3; i++){
        bool flag = true;
        for(int j = 0; j < 3; j++){
            flag = flag && c[i][j];
        }
        if(flag){
            cout << "Yes" << endl;
            return 0;
        }
    }
    for(int i = 0; i < 3; i++){
        bool flag = true;
        for(int j = 0; j < 3; j++){
            flag = flag && c[j][i];
        }
        if(flag){
            cout << "Yes" << endl;
            return 0;
        }
    }
    if(c[0][0] && c[1][1] && c[2][2]){
        cout << "Yes" << endl;
        return 0;
    }else if(c[0][2] && c[1][1] && c[2][0]){
        cout << "Yes" << endl;
        return 0;
    }

    cout << "No" << endl;
    return 0;
}

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

int main(){
	int N; cin>>N;
	int r = 0, n = 0;
	vector<int> A(N);
	rep(i, N){ cin>>A[i]; n = max(n, A[i]); }
	int half = n/2;
	rep(i, N) if(abs(half - r) > abs(half - A[i])) r = A[i];
	cout<< n <<" "<< r <<endl;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	string s;
	cin>>s;
	map<char,ll>a;
	for(ll i=0;i<s.size();i++){
		a[s[i]]++;
	}
	bool ch=true;
	for(auto itr=a.begin();itr!=a.end();itr++){
		ll val=itr->second;
		if(val!=2){
			ch=false;
		}
    }
    cout << (ch?"Yes":"No");
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define F(i,x) for(i=x;i<N;i++)
int main(){
  for(int N;cin>>N&&N;){
    int A[N],i,j;
    F(i,0)cin>>A[i];
    F(i,0){
      F(j,i+1)if(A[j-1]+1!=A[j])break;
      if(i)cout<<" ";cout<<A[i];
      if(j>i+1){cout<<'-'<<A[j-1];i=j-1;}
    }cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        
        //時間の値を代入する
        int time = sc.nextInt();

        //時間、分、秒の計算する
        int h = time / 3600;
        int m = time % 3600 / 60;
        int s = time % 60 % 60;
        
        //時間、分、秒の値を表示する
        System.out.println(h + ":" + m + ":" + s);
    }
}



Measured memory_bytes: 26372
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
    
int main() {
  ll q,h,s,d,n;
  cin>>q>>h>>s>>d>>n;
  q*=8;
  h*=4;
  s*=2;
  int buy=min({q,h,s,d});
  if (buy==d) 
    cout<<(n/2)*d+(n%2)*min({q,h,s})/2<<endl;
  else
    cout<<buy/2*n<<endl;
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int main() {
    int W, H, x, y, r;
    scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

    if (!(0<=x && x<=W && 0<=y && y<=H))
        return !printf("No\n");

    if (!(x>=r && W-x>=r && y>=r && H-y>=r))
        return !printf("No\n");

    printf("Yes\n");
    return 0;
}

Measured memory_bytes: 2724
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    string s;
    cin >> s;
    int n = s.length();
    if(n == 2) cout << s << endl;
    if(n == 3) {
        reverse(s.begin(), s.end());
        cout << s << endl;
    }
    return 0;
}

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

using namespace std;

int main() {

	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	int m1, d1, m2, d2;
	cin >> m1 >> d1 >> m2 >> d2;
	if (d1 > d2) cout << 1 << '\n';
	else cout << 0 << '\n'; 
	return 0;
}

Measured memory_bytes: 256
o = input()
e = input()

password = ""

if len(o) == len(e):
    for i in range(len(o)):
        password += o[i]
        password += e[i]
else:
    for i in range(len(o)-1):
        password += o[i]
        password += e[i]
    password += o[-1]
print(password)

Measured memory_bytes: 3060
# -*- coding: utf-8 -*-


def main():
    import sys
    input = sys.stdin.readline

    k = int(input())
    a, b = map(int, input().split())

    for i in range(a, b + 1):
        if i % k == 0:
            print('OK')
            exit()

    print('NG')


if __name__ == '__main__':
    main()


Measured memory_bytes: 9028
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

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

    ll x[n];
    rep(i,  n)cin >> x[i];

    ll dp[n+1][n+1][n*a+1];
    rep(i, n+1)rep(j, n+1)rep(k, n*a+1)dp[i][j][k] = 0;

    dp[0][0][0] = 1;
    rep(i, n)rep(j, n+1)rep(k, n*a+1){
        if(k - x[i] < 0)dp[i+1][j][k] = dp[i][j][k];
        else if(j > 0)dp[i+1][j][k] = dp[i][j][k] + dp[i][j-1][k-x[i]];
    }

    ll ans = 0;
    for(int i = 1; i <= n; ++i){
        ans += dp[n][i][a*i];
    }


    cout << ans << endl;
}


Measured memory_bytes: 54384
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <forward_list>
#include <random>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

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

    int n;
    cin >> n;
    vector< LL > v(n);
    for( int i = 0; i < n; ++i ) {
        cin >> v[i];

    }

    LL col[3] = {};
    LL res = 1;
    for( int i = 0; i < n; ++i ) {
        LL cnt = 0;
        if( v[i] == col[0] ) ++cnt;
        if( v[i] == col[1] ) ++cnt;
        if( v[i] == col[2] ) ++cnt;
        res = (res * cnt) % MOD;
        if( v[i] == col[0] ) col[0]++;
        else if( v[i] == col[1] ) col[1]++;
        else if( v[i] == col[2] ) col[2]++;

    }
    cout << res << endl;
    return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

int main() {
    int n;
    cin >> n;
    int ok = 1;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if (ok && a % 2) {
            ok = 0;
        }
    }
    cout << (!ok ? "first" : "second") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
typedef long long ll;
long long mod = 1e9 + 7;
const int iINF = 0x3f3f3f3f;
const long long INF = 1LL << 60;
using namespace std;

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

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

int main()
{
  string s;
  string t;
  cin >> s >> t;
  rep(i, s.size())
  {
    if (s[i] != t[i])
    {
      cout << "No" << endl;
      return 0;
    }
  }

  if (s.size() == t.size() - 1)
  {
    cout << "Yes" << endl;
    return 0;
  }

  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main(int argc, char *argv[])
{
	int n,i,f,g=1;
	long long a[100000];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%lld",&a[i]);
	}
	if(a[1]>a[0])f=1;
	if(a[1]<a[0])f=-1;
	if(a[1]==a[0])f=0;
	for(i=2;i<n;i++)
	{
		if(f==0&&a[i]>a[i-1]){f=1;}
		if(f==0&&a[i]<a[i-1]){f=-1;}
		if(f==1&&a[i]<a[i-1]){g++;f=0;}
		if(f==-1&&a[i]>a[i-1]){g++;f=0;}
	}
	printf("%d\n",g);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
using namespace std;

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

int inf = 1e9;
const int N = 2e4 + 5;

int dp[N];

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int h,n;
	cin >> h >> n;
	fill(dp,dp+N,inf);
	dp[0] = 0;
	rep(i,0,n){
		int a,b;
		cin >> a >> b;
		rep(i,0,N-a){
			gmin(dp[i+a],dp[i] + b);
		}
	}
	cout << *min_element(dp+h,dp+N) << '\n';
}
	

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define fir first
#define se second
#define ll long long
#define mp make_pair
#define pb push_back
#define quickio(a) ios::sync_with_stdio(a)
#define cl(a,b) memset(a,b,sizeof(a))
using namespace std;
const int maxn=2e5+10;
const ll mod=1e9+7;
const double eps=1e-7;
const int maxm=1e6+10;
int vis[50050];
int A(int a)
{
	if(a==1) return 9;
	else return 1;
}
int main()
{
	int a,b,c;
	scanf("%1d",&a);
	scanf("%1d",&b);
	scanf("%1d",&c);
	cout<<A(a)<<A(b)<<A(c)<<endl;
	return 0;
 } 

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<iomanip>
#include<cstdio>
#include<stack>
#include<queue>
using namespace std;
typedef long long ll;
int main(){
	string s,ans;
	int k;
	cin>>k;
	cin>>s;
	ans=s;
	int len=s.length() ;
	if(len>k) {
		ans=s.substr (0,k)+"...";
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3104
if isfile("mystdin.txt");mystdin=open("mystdin.txt","r");redirect_stdin(mystdin);end
pI(x)=parse(Int,x)
pM(x::Array{SubString{String},1})=map(pI,x)
bits(n)=[[i+1 for i=0:n if b&(1<<i)!=0] for b=0:(1<<n)-1]
function main()
  h,w,k=pM(split(readline()))
  c=Array[Int64[i=='#' for i=chomp(readline())] for j=1:h]
  tate=bits(h);yoko=bits(w)
  ans=0
  for i=tate
    for j=yoko
      s=0
      for t=i
        for y=j
          s+= c[t][y]==1
        end
      end
      ans+= s==k
    end
  end
  println(ans)
end
main()
if isdefined(Base, :mystdin);close(mystdin);end


Measured memory_bytes: 180620
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint,time,random
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

def cal(T):
    res = 0
    last = [0] * 26
    for day in range(D):
        t = T[day]; t -= 1
        last[t] = 0
        res += s[day][t]
        for i in range(26):
            if i == t: continue
            last[i] += 1
            res -= c[i] * last[i]
    return res
start_time = time.time()
n = 26
D = inp()
c = inpl()
s = [inpl() for _ in range(D)]
last = [0] * n
res = [-1] * D
for d in range(D):
    ans = -1
    mx = -INF
    for i in range(n):
        now = s[d][i]
        for j in range(n):
            if i == j: continue
            now -= s[d][j] * (last[j]+1)
        if now > mx:
            mx = now
            ans = i
    res[d] = ans+1
    for j in range(n):
        last[j] += 1
        if j == ans: last[j] = 0
score = cal(res)
# print(now_score)
while time.time() - start_time < 1.7:
    td,tq = random.randrange(0,D), random.randrange(1,n+1)
    old_q = res[td]
    res[td] = tq
    now = cal(res)
    if now > score:
        score = now
    else:
        res[td] = old_q

for x in res:
    print(x)

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

int main () {
  int N; cin >> N;
  vector<int> A(N+1);
  vector<int> B(N);
  vector<int> C(N);
  int ANS=0;
  int a;
  
  for(int i=0; i<N; i++){
    cin >> A[i];
  }
  A[N] = 0;
  for(int i=0; i<N; i++){
    cin >> B[i];
  }
  for(int i=0; i<N-1; i++){
    cin >> C[i];
  }
  
  
  for(int i=0; i<N; i++){
    ANS += B[i];
    if(A[i]+1 == A[i+1]){
      ANS += C[A[i]-1];
    }
  }
  
  
  cout << ANS << endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
using namespace std;

#define REP(i,n) for(int i=0;(i)<(n);(i)++)

vector<int> adjacencyList[100005];//??£??\?????????

int n;
int color[100005];//????????????????????°?????????????±???????????????????


void dfs(int r, int c) {
	stack<int> S;
	S.push(r);
	color[r] = c;
	while (!S.empty()) {
		int u = S.top(); S.pop();
		for (int i = 0;i < adjacencyList[u].size();i++) {
			int v = adjacencyList[u][i];
			if (color[v] == -1) {
				color[v] = c;
				S.push(v);
			}
		}
	}
}

void assignColor() {
	REP(i, n) color[i] = -1; //?????????

	//?????????
	int next_color = 1;
	REP(i, n) {
		if (color[i] == -1) {
			dfs(i, next_color++);
		}
	}
}


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

	int s, t;
	REP(i, m) {
		cin >> s >> t;
		adjacencyList[s].push_back(t);
		adjacencyList[t].push_back(s);
	}

	assignColor();//?????????

	int q;
	cin >> q;
	REP(i, q) {
		cin >> s >> t;//s??????t?????????????????¨???????????¨???

		(color[s] == color[t]) ? cout << "yes" : cout << "no";
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 8924