akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<typename T> inline istream& operator>>(istream &i, vector<T> &v) {rep(j, size(v)) i >> v[j]; return i;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T> T gcd(T a, T b) {if(b==0)return a; else return gcd(b,a%b);}
template<class T> T lcm(T a, T b) {return a/gcd(a,b)*b;}
template<class T = int> using V = vector<T>;
template<class T = int> using VV = vector<V<T>>;
bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    V<> a(n);
    cin >> a;
    sort(all(a));
    cout << a[n - 1] - a[0] << endl;
}


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

string s;

int main(void)
{
	int n, k, i;

	cin >> n >> k >> s;

	int ans = 0;
	for (i = 0; i < s.size() - 1; i++)
		if (s[i] == s[i + 1])
			++ans;

	cout << min(ans + 2 * k, n - 1);
	return 0;
}

Measured memory_bytes: 512
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1
//{
#include<bits/stdc++.h>
using namespace std;
#define hi cerr<<"hi"<<endl;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1
#define sysp system("pause")
#define PI acos(-1)
#define pf push_front
#define ins insert
#define fh(x,v) for(auto x:v)

//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
unsigned XorShift(void){static unsigned x = 123456789;static unsigned y = 362436069;static unsigned z = 521288629;static unsigned w = 88675123;unsigned t;t = x ^ (x << 11);x = y; y = z; z = w;return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));}
//}

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<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};
//template<class T>vector<T> var_vec(size_t a){return vector<T>(a);}
//template<class T, class... Ts>auto var_vec(size_t a, Ts... ts){return vector<decltype(var_vec<T>(ts...))>(a, var_vec<T>(ts...));}

//}

const int MAX = 510000;
//const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

main(){
	int n,k;cin>>n>>k;
	COMinit();
	for(int i=1;i<=k;i++){
		dump((COM(k-1,i-1)*COM(n-k+1,i))%MOD);
	}
}



Measured memory_bytes: 12160
#include<iostream>
#include<string>
#include<cstring>
#include<cctype>
using namespace std;
int main(){
	string s;bool check[3]={false,false,false};
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(isdigit(s[i]))check[0]=true;
		if(islower(s[i]))check[1]=true;
		if(isupper(s[i]))check[2]=true;
	}
	cout<<((s.size()>=6&&check[0]&&check[1]&&check[2])?"VALID":"INVALID")<<endl;
	return 0;
}

Measured memory_bytes: 1180
A = int(input())
B = int(input())
C = int(input())
X = int(input())
count = 0
for i in range(A+1):
    for j in range(B+1):
        for l in range(C+1):
            if 500*i + 100*j + 50*l == X:
                count += 1
print(count)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
const int M=4e3+10;
const int mod=1e9+7;
int gi() {
    int x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
int n,m=2000,a[N],b[N],fac[N],inv[N],ifac[N],f[M][M];
int C(int n,int m) {
    if(n<0||m<0||n<m) return 0;
    return 1ll*fac[n]*ifac[m]%mod*ifac[n-m]%mod;
}
int main() {
    cin>>n;
    for(int i=1;i<=n;i++) a[i]=gi(),b[i]=gi();
    fac[0]=1;for(int i=1;i<=4*m;i++) fac[i]=1ll*fac[i-1]*i%mod;
    inv[1]=1;for(int i=2;i<=4*m;i++) inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
    ifac[0]=1;for(int i=1;i<=4*m;i++) ifac[i]=1ll*ifac[i-1]*inv[i]%mod;
    for(int i=1;i<=n;i++) f[-a[i]+m+1][-b[i]+m+1]++;
    for(int i=1;i<=2*m+1;i++)
        for(int j=1;j<=2*m+1;j++) f[i][j]=((f[i][j]+f[i][j-1])%mod+f[i-1][j])%mod;
    int ans=0;
    for(int i=1;i<=n;i++) {
        ans=(ans+f[a[i]+m+1][b[i]+m+1])%mod;
        ans=(ans-C(2*(a[i]+b[i]),2*a[i])+mod)%mod;
    }
    ans=1ll*ans*inv[2]%mod;
    printf("%d\n",ans);
    return 0;
}
//orzgzy
//鸡贼明年进队超稳


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

int main(){
    int a,b;
    char op;
    while(1){
        cin>>a>>op>>b;
        if(op=='?') break;
        if(op=='+') printf("%d\n",a+b);
        if(op=='-') printf("%d\n",a-b);
        if(op=='*') printf("%d\n",a*b);
        if(op=='/') printf("%d\n",a/b);
        
    }
    return 0;
}



Measured memory_bytes: 3208
#include <bits/stdc++.h>
using namespace std;
int main(){
long long N,A,B;
  cin>>N>>A>>B;
long long sum=0;
  sum=N/(A+B)*A;
  if(N%(A+B)<=A ){
  sum+=N%(A+B);
  }
  else{
  sum+=A;
  }
  cout<<sum<<endl;
}

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

//def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define revrepeat(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define foreach(e, v) for (auto &e : v)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
constexpr int MOD = 1e9 + 7;
constexpr int INF = __INT_MAX__;               // 2^31 - 1
constexpr long long INFLL = __LONG_LONG_MAX__; // 2^61 - 1
constexpr int MAX_N = 1e5 + 5;
constexpr double PI = acos(-1);

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() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll k, n;
    cin >> k >> n;
    vl a(n);
    rep(i, n) cin >> a[i];

    ll l, r;
    ll ans = INF;
    rep(i, n) {
        if (i - 1 < 0)
            l = a[n - 1];
        else
            l = a[i - 1];
        if (i == n - 1)
            r = a[0];
        else
            r = a[i + 1];

        ll l_dist = abs(l - a[i]);
        ll r_dist = abs(r - a[i]);
        chmin(l_dist, k - l_dist);
        chmin(r_dist, k - r_dist);
        ll dist = min(k - l_dist, k - r_dist);
        // debug(l_dist);
        // debug(r_dist);
        // debug(dist);
        chmin(ans, dist);
    }
    out(ans);
    return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<n; i++)
#define pb push_back
#define int long long
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
const int MOD = 1000000007;

string S;
int dp[100100][4];

signed main() {
    cin >> S;
    dp[0][0] = 1;
    rep(i, S.size()) {
        if (S[i]=='?') dp[i+1][0] = 3*dp[i][0]%MOD;
        else dp[i+1][0] = dp[i][0];
        
        if (S[i]=='A') dp[i+1][1] = (dp[i][1]+dp[i][0])%MOD;
        else if (S[i]=='?') dp[i+1][1] = (3*dp[i][1]+dp[i][0])%MOD;
        else dp[i+1][1] = dp[i][1];
        
        if (S[i]=='B') dp[i+1][2] = (dp[i][2]+dp[i][1])%MOD;
        else if (S[i]=='?') dp[i+1][2] = (3*dp[i][2]+dp[i][1])%MOD;
        else dp[i+1][2] = dp[i][2];
        
        if (S[i]=='C') dp[i+1][3] = (dp[i][3]+dp[i][2])%MOD;
        else if (S[i]=='?') dp[i+1][3] = (3*dp[i][3]+dp[i][2])%MOD;
        else dp[i+1][3] = dp[i][3];
    }
    cout << dp[S.size()][3] << endl;
}

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

int main(){
  long N,L;cin>>N>>L;
  if(L>0)cout<<(2*L+N)*(N-1)/2;
  else if(L+N-1<0)cout<<(2*L+N-2)*(N-1)/2;
  else cout<<(2*L+N-1)*(N)/2;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    
    int A,B,C,D;
    cin >> A >> B >> C >> D;
    
    int a = max( A,C );
    int b = min( B,D );
    
    cout << max( 0, b-a ) << endl;
    
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	Scanner scan = new Scanner(System.in);
	
	void run() {
		int n = scan.nextInt();
		for (int i = 1; i <= n; i++) {
			if (i % 3 == 0) {
				System.out.print(" " + i);
				continue;
			}
			
			int x = i;
			do {
				if (x % 10 == 3) {
					System.out.print(" " + i);
					break;
				}
				x /= 10;
			} while (x != 0);
			
		}
		System.out.println();
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Main().run();
	}

}

Measured memory_bytes: 28760
program fa
  implicit none
  integer ::i,j
  character(len=4) :: S

  read(*,*) S

  if((S(1:1).eq.S(2:2)).and.(S(3:3).eq.S(4:4)).and.(S(2:2).ne.S(3:3))) then
  write(*,'(a)') 'Yes'
  elseif((S(3:3).eq.S(2:2)).and.(S(3:3).ne.S(4:4)).and.(S(1:1).eq.S(4:4))) then
  write(*,'(a)') 'Yes'
  elseif((S(4:4).eq.S(2:2)).and.(S(3:3).ne.S(4:4)).and.(S(1:1).eq.S(3:3))) then
  write(*,'(a)') 'Yes'
  else
  write(*,'(a)') 'No'
  endif



end program fa

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <math.h>
#include <string>


using std::cout;
using std::cin;



void oneCase () {
    int a;
    cin >> a;
    std::string l;
    std::getline(std::cin, l);
    std::getline(std::cin, l);
    if (l.size() % 2 == 0) {
        if (l.substr(0, l.size() / 2) == l.substr(l.size() / 2, l.size() / 2)) {
            cout <<  "Yes" << "\n";
        } else {
            cout <<  "No" << "\n";
        }
    } else {
        cout <<  "No" << "\n";
    }
}


int main() {
    int k = 1;
//    cin >> k;
    for (int i = 0; i < k; ++i) {
        oneCase();
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 5LL << 60;
const ll mod = 1e9 + 7;

int main() {
	ll N, M;
	cin >> N >> M;
	if(abs(N - M) > 1) {
		cout << 0 << "\n";
		return 0;
	}
	ll ans = 2;
	if(N != M) ans--;
	while(N) {
		ans *= N;
		ans %= mod;
		N--;
	}
	while(M) {
		ans *= M;
		ans %= mod;
		M--;
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


int main()
{
    int n;
    cin >> n;
    vector<ll> a;
    vector<ll> b;
    rep(i, n+1){ ll tmp; cin >> tmp; a.push_back(tmp);}
    rep(i, n){ ll tmp; cin >> tmp; b.push_back(tmp);}

    ll ans = 0;
    rep(i, n){
        if (b[i] > a[i]){
            ans+=a[i];
            b[i]-=a[i];
            //次の街
            ans += min(b[i], a[i+1]);
            a[i+1] -= min(b[i], a[i+1]);
        } else {
            ans+=b[i];
            b[i] = 0;
        }
    }

    cout << ans << endl;

}



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

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

ll a, b, c, ans;

int main()
{
    cin.tie(0); cout.tie(0);
    ios_base::sync_with_stdio(false);
    int i, j;

    scanf("%lld%lld%lld", &a, &b, &c);

    if(c==0) return !printf("%lld", b);

    ans++; c--;
    if(c<b)
    {
        b-=c;
        ans+=2*c;
    }
    else
    {
        ans+=b*2;
        c-=b; b=0;

        if(c<a)
        {
            a-=c;
            ans+=c;
        }
        else
        {
            ans+=a;
            c-=a; a=0;
        }
    }
    ans+=b;

    printf("%lld", ans);
    return 0;
}


Measured memory_bytes: 256
using System;

namespace Atcoder20191204
{
    class Program
    {
        static void Main()
        {
            string str = Console.ReadLine();
            string substr = Console.ReadLine();
            int a = -1;
            for (int i = 0; i < str.Length - substr.Length + 1; i++)
            {
                string s = str.Substring(i, substr.Length);
                bool flag = true;
                for (int j = 0; j < substr.Length; j++)
                {
                    if (s[j] != '?' && s[j] != substr[j])
                    {
                        flag = false;
                    }
                }
                if (flag)
                {
                    a = i;
                }
            }
            if (a != -1)
            {
                str = str.Substring(0, a) + substr + str.Substring(a + substr.Length);
                Console.WriteLine(str.Replace('?', 'a'));
                return;
            }
            Console.WriteLine("UNRESTORABLE");
        }
    }

}


Measured memory_bytes: 11092
def main():
    import sys
    input=sys.stdin.readline
    from collections import deque
    inf=10**12

    class MinCostFlow:
        def __init__(self,n):
            self.n=n
            self.edges=[[] for i in range(n)]
        def add_edge(self,fr,to,cap,cost):
            self.edges[fr].append([to,cap,cost,len(self.edges[to])])
            self.edges[to].append([fr,0,-cost,len(self.edges[fr])-1])
        def MinCost(self,source,sink,flow):
            n=self.n; E=self.edges
            mincost=0
            prev_v=[0]*n; prev_e=[0]*n
            while flow:
                dist=[inf]*n
                dist[source]=0
                q=deque([source])
                Flag=[False] *n
                Flag[source]=True
                while q:
                    v=q.popleft()
                    if not Flag[v] :
                        continue
                    Flag[v]=False
                    for i,(w,cap,cost,_) in enumerate(E[v]):
                        if cap>0 and dist[w]>dist[v]+cost:
                            dist[w]=dist[v]+cost
                            prev_v[w],prev_e[w]=v,i
                            q.append(w)
                            Flag[w]=True
                d,v=flow,sink
                while v!=source:
                    d=min(d,E[prev_v[v]][prev_e[v]][1])
                    v=prev_v[v]
                flow-=d
                mincost+=d*dist[sink]
                v=sink
                while v!=source:
                    e=E[prev_v[v]][prev_e[v]]
                    e[1]-=d
                    E[v][e[3]][1]+=d
                    v=prev_v[v]
            return mincost

    n=int(input())
    flow=MinCostFlow(2*n+6)
    s=0
    for i in range(n):
        rx,ry,rc=map(int,input().split())
        s+=rc
        flow.add_edge(0,i+1,rc,0)
        flow.add_edge(i+1,n+1,inf,-rx-ry)
        flow.add_edge(i+1,n+2,inf,rx-ry)
        flow.add_edge(i+1,n+3,inf,-rx+ry)
        flow.add_edge(i+1,n+4,inf,rx+ry)
    for i in range(n):
        bx,by,bc=map(int,input().split())
        flow.add_edge(n+5+i,2*n+5,bc,0)
        flow.add_edge(n+1,n+5+i,inf,bx+by)
        flow.add_edge(n+2,n+5+i,inf,-bx+by)
        flow.add_edge(n+3,n+5+i,inf,bx-by)
        flow.add_edge(n+4,n+5+i,inf,-bx-by)
    print(-(flow.MinCost(0,2*n+5,s)))

if __name__=='__main__':
    main()

Measured memory_bytes: 120284
N = int(input())
A_B = [list(map(int,input().split())) for n in range(N)]

A_B.sort(key=lambda x:x[1])

spend_time = 0
flg = True

for a,b in A_B:
  spend_time += a
  if spend_time > b:
    flg = False
    break
  else:
    continue

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

Measured memory_bytes: 53600
import math
a,b,h,m = map(int,input().split())
long = m/60*360
short = h*30+(m/60*30)
kakudo = abs(long-short)
ans = math.sqrt(a**2 + b**2 - (2*a*b*math.cos(math.radians(kakudo))))
print(ans)


Measured memory_bytes: 62444
N = int(input())
A = [abs(int(input())) for _ in range(N)]
#A.sort()
s = sum(A)

def mulmod(p,q,mod):
  return ((p%mod)*(q%mod))%mod
def powermod(p,n,mod):
  if n==0: return 1
  if n==1: return p%mod
  else:    return powermod(p,n//2,mod)**2 * (p**(n%2)) %mod
def dividemod(p,q,mod):
  # modは素数
  return mulmod(p, powermod(q,mod-2,mod), mod)

mod = 998244353

dp = [[0]*(s+1) for _ in range(N)]
# dp[n][s] An-1(0-index)まで加えて、Rの和がsになるのが何通りか（残りのG,Bまで含めて）
dp[0][0] = 2
dp[0][A[0]] = 1
temp_sum = A[0]

for i in range(1,N):
  for j in range(A[i]):
    dp[i][j] = (dp[i-1][j]*2) %mod
  for j in range(A[i], temp_sum+1):
    dp[i][j] = (dp[i-1][j]*2 + dp[i-1][j-A[i]]) %mod
  for j in range(temp_sum+1, temp_sum+1 + A[i]):
    dp[i][j] = (dp[i-1][j-A[i]]) %mod
  temp_sum += A[i]


def part_sum(a,A):
  p=mod
  #初期化
  N=len(a)
  dp=[[0 for i in range(A+1)] for j in range(N+1)]
  dp[0][0]=1

  #DP
  for i in range(N):
    for j in range(A+1):
      if a[i]<=j: #i+1番目の数字a[i]を足せるかも
        dp[i+1][j]=dp[i][j-a[i]]+ dp[i][j]% p
      else: #入る可能性はない
        dp[i+1][j]=dp[i][j]%p
  return dp[N][A]

ps = part_sum(A, s//2)

if s%2 != 0:
    answer = (powermod(3, N, mod) - 3*sum(dp[N-1][(s+1)//2:]))%mod
else:
    answer = (powermod(3, N, mod) - 3*(sum(dp[N-1][(s+1)//2:]) - ps))%mod



print(answer)


Measured memory_bytes: 376072
N,M = map(int,input().split())
S =[0]*M
for i in range(M):
    k,*s = map(int,input().split())
    S[i] = s

P = list(map(int,input().split()))
ans = 0
for num in range(1<<N):
    Light = [0] * N
    count = 0
    for i in range(N):
        bit = num>>i & 1
        if bit:
            Light[i] = 1
    for i,s in enumerate(S):
        light_count = 0
        p = P[i]
        for si in s:
            if Light[si-1]:
                light_count += 1
        if light_count % 2 == p:
            count+=1
    if count == M:
        ans += 1

print(ans)














Measured memory_bytes: 9232
#include<stdio.h>

#define INF 2001
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define N 101

int n;
int a[N][N];

int prim();

int main()
{
  int i, j;

  scanf("%d", &n);
 
  for(i = 1; i <= n; i++)
    {
      for(j = 1; j <= n; j++)
	{
	  scanf("%d", &a[i][j]);
	  if(a[i][j] == -1)a[i][j] = INF;
	}
    }

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

}

int prim()
{
  int i, key, min, sum = 0;
  int d[N], p[N], color[N];

  for(i = 1; i <= n; i++)
    {
      d[i] = INF;
      p[i] = -1;
      color[i] = WHITE;
    }

  d[1] = 0;
  
  while(1)
    {
      min = INF;
      key = -1;

  for(i = 1; i <= n; i++)
    {
      if(min > d[i] && color[i] != BLACK)
	{
	  key = i;
	  min = d[i];
	}
    }

  if(key == -1)break;
  color[key] = BLACK;
      
      for(i = 1; i <= n; i++)
	{
	  if(color[i] != BLACK && a[key][i] != INF && d[i] > a[key][i])
	    {
	      d[i] = a[key][i];
	      p[i] = key;
	      color[i] = GRAY;
	    }
	}
    }
      
  for(i = 1; i <= n; i++)
    {
      if(p[i] != -1)sum += a[i][p[i]];
    }

  return sum;
}



Measured memory_bytes: 2112
#include <iostream>                                             
#include <vector>                                               
#include <algorithm>                                            
                                                                
using namespace std;                                            
                                                                
int main(void) {                                                
  int n;                                                        
  cin >> n;                                                     
  vector<int> S(n);                                             
  for (int i=0; i<n; i++) {                                     
    cin >> S[i];                                                
  }                                                             
  sort(S.begin(), S.end());                                     
                                                                
  int q;                                                        
  cin >> q;                                                     
  vector<int> T(q);                                             
  for (int i=0; i<q; i++) {                                     
    cin >> T[i];                                                
  }                                                             
                                                                
  int ans = 0;                                                  
  for (int i=0; i<q; i++) {                                     
    if (binary_search(S.begin(), S.end(), T[i])) {              
      ans++;                                                    
    }                                                           
  }                                                             
  cout << ans << endl;                                          
}                                                               
                                                                
                               

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

#define pb push_back
#define ss second
#define ff first
#define N 200005
#define inf 1000000009
#define ll long long
#define all(a) a.begin(),a.end()
#define mid(a,b) (a+b)/2
#define pii pair<int,int>

using namespace std;

int k,n,a[N],d[N],mx;

int main()
{
	scanf("%d%d",&k,&n);
	for(int i = 1;i <= n;i++){
		scanf("%d",a + i);
		d[i] = a[i] - a[i - 1];
		mx = max(mx,d[i]);
	}
	mx = max(mx,k - a[n] + a[1]);
	cout << k - mx;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;

template<typename T> 
map<T,int> factorize(T x){
    map<T,int> mp;
    for (T i = 2; i*i <= x; i++){
        while (x%i == 0) {
            x /= i;
            mp[i]++;
        }
        if (x == 1) break;
    }
    if (x != 1) {
    	mp[x]++;
    }
    return mp;
}

int main() {
	ll N, P;
	cin>>N>>P;
	map <ll, int> f = factorize(P);
	if(P==1){
		cout<<1<<endl;
		return 0;
	}
	ll ans = 1;
	for(auto i :f){
		cerr<<i.first<<": "<<i.second<<endl;
		if(i.second >= N){
			for (int j = 0; j < i.second/N; ++j){
				ans*=i.first;
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 100000 + 100;
int A[Maxn], P[Maxn];
int N, M;
int main()
{
#ifdef hk_cnyali
	freopen("B.in", "r", stdin);
	freopen("B.out", "w", stdout);
#endif
	scanf("%d%d", &N, &M);
	for (int i = 1; i <= N; ++i) A[i] = 1, P[i] = -1;
	P[1] = 1;
	for (int i = 1; i <= M; ++i)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		A[x] --;
		A[y] ++;
		P[y] = max(P[y], P[x]);
		if (!A[x]) P[x] = 0;
	}
	int Ans = 0;
	for (int i = 1; i <= N; ++i)
		if (P[i] > 0)
			++Ans;
	cout<<Ans<<endl;
	return 0;
}

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

int main(){
    long long N, M;
    cin >> N >> M;
    long long one = 1900 * M + 100 * (N - M);
    long long pro = pow(2, M);
    one *= pro;
    cout << one << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    A, B = zip(*[
        map(int, input().split())
        for _ in range(N)
    ])

    # 情報の中で最低点数番目までの人数と、それ未満の人数
    ans = max(A) + min(B)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 59220
package main

import (
	"fmt"
	"time"
)

func main() {

	mainA()

}

const (
	yyyymmdd = "2006/01/02"
)

func mainA() {

	var dateS string
	fmt.Scan(&dateS)

	var res = solvoA(dateS)

	fmt.Println(res)
}

func solvoA(dateS string) string {
	t1, _ := time.Parse(yyyymmdd, dateS)
	t2, _ := time.Parse(yyyymmdd, "2019/04/30")
	var res string
	if t1.Unix() <= t2.Unix() {
		res = "Heisei"
	} else {
		res = "TBD"
	}
	return res
}


Measured memory_bytes: 512
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using lint = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int ctoi(const char c)
{
    if ('0' <= c && c <= '9') { return {c -'0'}; }
    return -1;
}

int main()
{
    optimize_cin();
    string s;
    cin >> s;

    vector<int> a;
    a.clear();
    rep (i, s.length())
    {
        if (s[i] == 'B')
        {
            if (!a.empty())
            {
                a.pop_back();
            }
        }
        else
        {
            a.push_back(ctoi(s[i]));
        }
    }

    for (auto& aa : a)
    {
        cout << aa;
    }
    cout << "\n";
    

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
const int MOD = 1e9+7;
#define PI 3.14159265359
typedef long long ll;
using namespace std;


int main(){
	int a, b, x;
	cin >> a >> b >> x;
	if (a <= x && a+b >= x) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}



Measured memory_bytes: 3596
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        String T = sc.next();
        if (T.substring(0, T.length() - 1).equals(S)) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
        sc.close();
    }
}

Measured memory_bytes: 35732
let () = Scanf.scanf "%d\n" @@ fun n ->
  let es = Array.init (n - 1) @@ fun _ -> Scanf.scanf "%d %d\n" @@ fun u v -> u, v in
  let vs =
    Array.fold_left ( + ) 0 @@
    Array.init n @@ fun i -> (i + 1) * (n - i) in
  Printf.printf "%d\n" @@
  Array.fold_left (fun acc (u, v) ->
    let [u; v] = List.sort compare [u; v] in
    acc - u * (n - v + 1)) vs es

Measured memory_bytes: 14264
N = int(input())
d = [0 for i in range(N)]

for i in range(1,N + 1):
    cnt = 0
    j = i
    while j % 2 == 0:
        cnt += 1
        j /= 2
    d[i-1] = cnt

print(d.index(max(d))+1)

Measured memory_bytes: 38384
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;
typedef vector<VD> VVD;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

vector<P> calc(ll k, ll x, ll y){
    vector<P> ret;
    ll p = 0, q = 0;
    while (x - p + y - q > 2 * k){
        if (x >= p + k){
            p += k;
        }else{
            q += k;
        }
        ret.emplace_back(p, q);
    }
    if (x - p + y - q == k){
        ret.emplace_back(x, y);
        return ret;
    }
    if ((x - p + y - q) % 2 == 1){
        FOR(i,p-k,p+k){
            int j = q + k - abs(p - i);
            if (x >= i && y >= j && x - i + y - j <= 2 * k){
                p = i;
                q = j;
                ret.emplace_back(p, q);
                break;
            }
            j = q - (k - abs(p - i));
            if (x >= i && y >= j && x - i + y - j <= 2 * k){
                p = i;
                q = j;
                ret.emplace_back(p, q);
                break;
            }
        }
    }
    int d = k - (x - p + y - q) / 2;
    if (x - p > y - q) ret.emplace_back(p + k - d, q - d);
    else ret.emplace_back(p - d, q + k - d);
    ret.emplace_back(x, y);
    return ret;
}


int main() {
    ll k, x, y;
    cin >> k >> x >> y;
    bool flipx = false, flipy = false;
    if (x < 0){
        flipx = true;
        x = -x;
    }
    if (y < 0){
        flipy = true;
        y = -y;
    }
    if (k % 2 == 0 && (x + y) % 2 == 1){
        cout << -1 << endl;
        return 0;
    }
    vector<P> ans = calc(k, x, y);
    cout << ans.size() << endl;
    REP(i,ans.size()){
        if (flipx) ans[i].first *= -1;
        if (flipy) ans[i].second *= -1;
        cout << ans[i].first << " " << ans[i].second << endl;
    }
    return 0;
}


Measured memory_bytes: 3952
#include <iostream>
#include <vector>
#include <chrono>
#include <random>
#include <cassert>
#include <cstring>

std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

const int ms = 303;
const int MOD = 998244353;

std::string str;
int n;
bool vis[ms][ms][ms];
int memo[ms][ms][ms];
int bst[ms][ms];
int sum[ms][2];

void go(int on, int zero, int one, int turn) {
	if(vis[on][zero][turn]) return;
	vis[on][zero][turn] = true;
	//std::cout << "visiting " << on << ", " << zero << ", " << one << ", " << turn << "\n";
	memo[on][zero][turn] = one;
	if(turn + 1 == (int) str.size()) return;
	if(zero >= 2) go(on, zero-1, one, turn+1);
	if(one >= 2) go(on, zero, one-1, turn+1);
	if(zero >= 1 && one >= 1) go(on, zero-1, one, turn+1);
	if(zero >= 1 && one >= 1) go(on, zero, one-1, turn+1);
	if(on < (int) str.size()) {
		int nxt = str[on] - '0';
		if(zero >= 1) go(on+1, zero-1+(1-nxt), one+nxt, turn+1);
		if(one >= 1) go(on+1, zero+(1-nxt), one+nxt-1, turn+1);
		if(zero >= 1 || one >= 1) go(on+1, zero, one, turn+1);
	}
	if(on+1 < (int) str.size()) {
		int nxt = str[on] - '0';
		go(on+2, zero+(1-nxt), one+nxt, turn+1);
		nxt = str[on+1] - '0';
		go(on+2, zero+(1-nxt), one+nxt, turn+1);
	}
}

int dp(int on, int zero, int one) {
	if(zero < 0 || one < 0) return 0;
	if(on == n && zero == 0 && one == 0) return 1;
	int &ans = memo[on][zero][one];
	if(ans != -1) return ans;
	ans = 0;
	if(on == n) {
		ans = (dp(on, zero-1, one) + dp(on, zero, one-1)) % MOD;
	} else if(str[on] == '0') {
		ans = (dp(on+1, zero, one) + dp(on, zero, one-1)) % MOD;
	} else {
		ans = (dp(on+1, zero, one) + dp(on, zero-1, one)) % MOD;
	}
	return ans;
}

int main() {
	std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
	std::cin >> str;
	n = (int) str.size();
	go(0, 0, 0, 0);
	for(int i = n-1; i >= 0; i--) {
		sum[i][0] = sum[i+1][0];
		sum[i][1] = sum[i+1][1];
		if(str[i] == '0') sum[i][0]++;
		else sum[i][1]++;
	}
	memset(bst, -1, sizeof bst);
	for(int on = 0; on < ms; on++) {
		for(int zero = 0; zero < ms; zero++) {
			for(int turn = 0; turn < ms; turn++) {
				if(!vis[on][zero][turn]) continue;
				int one = memo[on][zero][turn];
				int f[2] = {zero + sum[on][0], one + sum[on][1]};
				bst[f[0]][f[1]] = std::max(bst[f[0]][f[1]], on);
			}
		}
	}
	memset(memo, -1, sizeof memo);
	int ans = 0;
	for(int zero = 0; zero < ms; zero++) {
		for(int one = 0; one < ms; one++) {
			if(bst[zero][one] < 0) continue;
			int on = bst[zero][one];
			//std::cout << "best for " << zero << ", " << one << " is " << on << ", got " << dp(on, zero - sum[on][0], one - sum[on][1]) << '\n';
			ans = (ans + dp(on, zero - sum[on][0], one - sum[on][1])) % MOD;
		}
	}
	std::cout << ans << '\n';
}

Measured memory_bytes: 120436
// https://atcoder.jp/contests/abc149/tasks/abc149_a
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s, t;
    cin >> s >> t;
    cout << t << s << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;
int main(){
    string s;
    cin >> s;
    int a = stoi(s.substr(0, 2));
    int b = stoi(s.substr(2, 2));
    if(1<=a && a<=12){
        if(1<=b && b<=12) cout << "AMBIGUOUS" << endl;
        else cout << "MMYY" << endl;
    }else if(1<=b && b<=12) cout << "YYMM" << endl;
    else cout << "NA" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <cassert>

using namespace std;

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

#define MP make_pair
#define PB push_back
#define FF first
#define SS second

#define FORN(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD(i, n) for (int i = (int)(n) - 1; i >= 0; i--)

#define DEBUG(X) { cout << #X << " = " << (X) << endl; }
#define PR0(A,n) { cout << #A << " = "; FORN(_,n) cout << A[_] << ' '; cout << endl; }

#define MOD 1000000007
#define INF 2000000000

int GLL(LL& x) {
    return scanf("%lld", &x);
}

int GI(int& x) {
    return scanf("%d", &x);
}

string s;

int main() {
    cin >> s;

    int g = 0;
    int p = 0;

    int res = 0;

    FORN(i, s.size()) {
        if (s[i] == 'g') {
            if (p < g) {
                res++;
                p++;
            }
            else {
                g++;
            }
        }
        else {
            if (p < g) {
                p++;
            }
            else {
                res--;
                g++;
            }
        }
    }

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

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define call(var) cout<<#var<<"="<<var<<endl;
#define dup(x,y) (((x)+(y)-1)/(y))
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
template<class t,class u> inline bool chmax(t&a,u b){if(a<b){a=b;return true;}return false;}
template<class t,class u> inline bool chmin(t&a,u b){if(b<a){a=b;return true;}return false;}

int main(){
    int n,k;cin >> n >> k;
    vi num(n,0);
    rep(i,k){
        int d;cin >> d;
        rep(j,d){
            int a;cin >> a;
            num[a-1]++;
        }
    }
    int ans = 0;
    rep(i,n) if(num[i] == 0) ++ans;
    cout << ans << endl;
}

Measured memory_bytes: 3628
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#include<bits/stdc++.h>
using namespace std;

#if defined(DAIJOBU)
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}

long long f(long long n){
	if(n < 2)return 1;
	return n * f(n - 2);
}

int main(){
	FIO
	
	long long n;cin >> n;
	if(n % 2)cout << 0;
	else{
		//long long tens = n / 10;
		long long ans = 0;
		long long den = 10;
		while(n >= den){
			ans += (n / den);
			den *= 5;
		}
		cout << ans;
	}
	return 0;
}


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

int main(){

  int N;
  cin >> N;
  int cnt = 0;
  
string w[N];
  for(int i = 0;i < N;i++) cin >> w[i];
  
  for(int i = 1;i < N;i++){
  if(w[i - 1].at(w[i - 1].size() - 1) != w[i].at(0)){ 
    cnt++;
    break;
  }
    
  else for(int j = 0;j < i;j++){
  if(w[j] == w[i]){
    cnt++;
    break;
  }
  } 
  }
  
  if(cnt == 0) cout << "Yes" << endl;
     else cout << "No" << endl;

return 0;
  
}

Measured memory_bytes: 256
#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;
bool a[8011];
bool b[8011];
bool check(vector<int>v,int x){
	if(x<0||x>8001)return false;
	REP(i,8001)a[i]=false;
	a[0]=true;
	REP(i,v.size()){
		REP(j,8001){
			b[j]=a[j];
		}
		REP(j,8001){
			if(a[j]==true&&(j+v[i]<8001)){
				b[j+v[i]]=true;
			}
		}
		REP(j,8001){
			a[j]=b[j];
		}
	}
	//cout<<x<<" "<<a[x]<<endl;
	if(a[x]==true)return true;
	return false;
}
int main(){
	string s;
	int x,y;
	cin>>s>>x>>y;
	int count=0;
	int now=0;
	while(now<s.size()&&s[now]=='F'){
		now++;
		count++;
	}
	x-=count;
	x=abs(x);
	y=abs(y);
	vector<int>v;
	vector<int>vv;
	int me=0;
	count=0;
	for(int i=now;i<s.size();i++){
		if(s[i]=='F'){
			count++;
		}else{
			if(me==0){
				v.push_back(count);
			}else{
				vv.push_back(count);
			}
			count=0;
			me=1-me;
		}
	}
	if(me==0){
		v.push_back(count);
	}else{
		vv.push_back(count);
	}
	int sum=0;
	REP(i,v.size()){
		sum+=v[i];
	}
	int sum2=0;
	REP(i,vv.size()){
		sum2+=vv[i];
	}
	
	
	//cout<<sum<<" "<<sum2<<endl;
	if(check(v,(sum-x)/2)&&check(vv,(sum2-y)/2)&&((sum-x)%2==0)&&((sum2-y)%2==0)){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	
	return(0);
}

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

int main(){
  int N;
  cin >> N;
  map<string,int> A;
  for(int i=0;i<N;i++){
    string S;
    cin >> S;
    A[S]++;
  }
  cout << "AC x " << A["AC"] << endl;
  cout << "WA x " << A["WA"] << endl;
  cout << "TLE x " << A["TLE"] << endl;
  cout << "RE x " << A["RE"] << endl;
} 

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

int main() {
  int n;
  cin >> n;
  
  map<string, int> memo;
  
  rep(i, n) {
    string in;
    cin >> in;
    ++memo[in];
  }
  
  int maxi = 0;
  for(auto& x : memo) {
    maxi = max(maxi, x.second);
  }
  
  for(auto& x : memo) {
    if(x.second == maxi) cout << x.first << endl;
  }
    
  return 0;
}


Measured memory_bytes: 25216
p = 10**9+7

def sum_num(n, k):
    ans = 0
    while k <= n+1:
        # print(k, k*n-k*(k-1)+1)
        ans += k*n-k*(k-1)+1
        ans = ans%p
        k += 1
    print(ans)

n, k = [int(i) for i in input().split()]
sum_num(n, k)


Measured memory_bytes: 9208
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <string>
#define INF 1000000000000000000
using namespace std;

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

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

	if (a >8 || b > 8) {
		cout << ":(" << endl;
	}
	else {
		cout << "Yay!" << endl;
	}

	return 0;
}


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

int main(void) {
  int N, M;
  cin >> N >> M;

  int X[M];
  for (int i = 0; i < M; i++) {
    cin >> X[i];
  }

  if (N >= M) {
    cout << 0 << endl;
    return 0;
  }

  sort(X, X + M);

  int tmp[M];
  int sum = 0;
  for (int i = 0; i < M - 1; i++) {
    tmp[i] = X[i+1] - X[i];
    sum += tmp[i];
  }


  sort(tmp, tmp + M - 1, greater<int>());

  int unused = 0;
  for (int i = 0; i < N - 1; i++) {
    unused += tmp[i];
  }

  cout << sum - unused << endl;
}

Measured memory_bytes: 1024
(n, a, b) = gets.chomp.split(' ').map(&:to_i)
s = gets.chomp

s.each_char do |p|
  case p
    when 'a' then
      if a == 0 && b == 0
        puts 'No'
      elsif a == 0 && b > 0
        b -= 1
        puts 'Yes'
      else
        a -= 1
        puts 'Yes'
      end
    when 'b' then
      if b == 0
        puts 'No'
      else
        b -= 1
        puts 'Yes'
      end
    when 'c' then
      puts 'No'
  end
end


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

int n,ans,x;

inline int gcd(int a,int b){return !b?a:gcd(b,a%b);}

int main()
{
	scanf("%d",&n);scanf("%d",&ans);
	for (int i=2;i<=n;i++) scanf("%d",&x),ans=gcd(ans,x);
	printf("%d\n",ans);

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod 1000000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
#define grepq priority_queue<double, std::vector<double>, std::greater<double>>
#define all(v) v.begin(), v.end()
#define PI acos(-1)

const ll INF = 10010001010;
const int inf = 2000000000;
ll lcm(ll a, ll b)
{
    return a * b / __gcd(a, b);
}

typedef tuple<string, int, int> TUP;

bool tuplesort(const TUP &right, const TUP &left)
{
    if (get<0>(right) != get<0>(left))
    {
        return get<0>(left) < get<0>(right);
    }
    if (get<1>(left) != get<1>(right))
    {
        return get<1>(left) > get<1>(right);
    }
    return get<2>(left) < get<2>(right);
}
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll nCr(int n, int r)
{
    ll ans = 1;
    for (int i = n; i > n - r; --i)
    {
        ans = ans * i;
    }
    for (int i = 1; i < r + 1; ++i)
    {
        ans = ans / i;
    }
    return ans;
}

int main()
{
    int N;
    cin >> N;
    vector<vector<int>> A(2, vector<int>(N));
    for (int i = 0; i < N;i++)
    {
        cin >> A[0][i];
    }
    for (int i = 0; i < N; i++)
    {
        cin >> A[1][i];
    }
    ll ans = 0;
    for (int i = 0; i < N;i++)
    {
        ll pre = 0;
        for (int j = 0; j <= i; j++)
        {
            pre += A[0][j];
        }
        for (int j = i; j < N;j++)
        {
            pre += A[1][j];
        }
        ans = max(pre,ans);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
//Night's template
//orzakyrt
#include <iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<vector>
#define R register
#define LL long long
#ifdef __DEBUG__
	#define Debug (fprintf(stderr,"orzyrt\n"),fflush(stderr))
	#define debug(__a...) (fprintf(stderr,__a),fflush(stderr))
	#define setfile(__a) ('orzyrt')
	#define Compile(__a) system("g++ "__a".cpp -lm -o "__a)
#else
	#define Debug ('orzyrt')
	#define debug(__a...) ('orzyrt')
	#define setfile(__a) freopen(__a".in","r",stdin);freopen(__a".out","w",stdout)
	#define Compile(__a) ('orzyrt')
#endif
template<class TT>inline TT Max(R TT a,R TT b){return a<b?b:a;}
template<class TT>inline TT Min(R TT a,R TT b){return a<b?a:b;}
template<class TT>inline TT Abs(R TT a){return a<0?-a:a;}
template<class TT>inline TT cmin(R TT &a,R TT b){(b<a)&&(a=b);}
template<class TT>inline TT cmax(R TT &a,R TT b){(a<b)&&(a=b);}
using namespace std;
template<class TT>inline void read(R TT &x){
	x=0;R bool f=false;R char c=getchar();
	for(;c<48||c>57;c=getchar())f|=(c=='-');
	for(;c>47&&c<58;c=getchar())x=(x<<1)+(x<<3)+(c^48);
	(f)&&(x=-x);
}
//end template
 
namespace Night{
	const int maxn = 200010;
	const int inf = 2147483647;
	int n;
	int min1=inf,min2=inf,max1=-inf,max2=-inf;
	LL ans=1ll<<60;
	multiset<int>a,b;
	struct node{
		int x,y;
		node(){}
		node(R int x,R int y):x(x),y(y){}
		inline bool operator < (R const node &_)const{
			return x<_.x;
		}
	};
	vector<node>v;
	int main(){
		read(n);
		for(R int i=1,xx,yy,x,y;i<=n;++i){
			read(xx);read(yy);
			x=Min(xx,yy);y=Max(xx,yy);
			v.push_back(node(x,y));
			a.insert(x);b.insert(y);
		}
		sort(v.begin(),v.end());
		for(R vector<node>::iterator i=v.begin();i!=v.end();++i){
			a.erase(a.find(i->x));b.erase(b.find(i->y));
			b.insert(i->x);a.insert(i->y);
			cmin(ans,1ll*(*a.rbegin()-*a.begin())*(*b.rbegin()-*b.begin()));
		}
		for(R vector<node>::iterator i=v.begin();i!=v.end();++i){
			cmin(min1,i->x);
			cmin(min2,i->y);
			cmax(max1,i->x);
			cmax(max2,i->y);
		}
		cmin(ans,1ll*(max1-min1)*(max2-min2));
		cout<<ans;
		return 0;
	}
}
int main(){
	return Night::main();
}

Measured memory_bytes: 20592