akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,s,n) for(int i=s;i<n;i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define all_acc(x) (x).begin(),(x).end(),0LL
#define int long long
using namespace std;
using P=pair<int,int>;
using Graph=vector<vector<int>>;
using ll=long long;

void output(vector<int> s){
    int n=s.size();
    for(int i=0;i<n;i++){
        if(i!=0) cout<<" ";
        cout<<s[i];
    }
    cout<<endl;
}

int accumulate(int* a,int n){
    return accumulate(a,a+n,0LL);
}

int accumulate(vector<int> a){
    return accumulate(a.begin(),a.end(),0LL);
}

//幅優先探索。このままだと連結してないとダメ。
//disは各座標への距離。行けない場合は-1にしている。
//chaは各座標の情報。文字で格納している。
//sはスタートの座標
//gはゴールの座標
int bfs(vector<vector<int>> dis,vector<vector<char>>cha,pair<int,int>s,pair<int,int>g){
    int h=dis.size();
    int w=dis.at(0).size();

    queue<pair<int,int>> Q;
    Q.push(s);
    dis.at(s.first).at(s.second)=0;

    while(dis.at(g.first).at(g.second)==-1 && Q.size()!=0){
        int y,x;//今の座標
        y=Q.front().first; x=Q.front().second;
        Q.pop();

        int dy[4]={1,0,-1,0};
        int dx[4]={0,1,0,-1};
        for(int i=0;i<4;i++){
            int ey=y+dy[i];
            int ex=x+dx[i];
            if(ex<0||ey<0||ex>=w||ey>=h) continue;
            if(cha[ey][ex]=='#'||dis[ey][ex]!=-1) continue;
            dis[ey][ex]=dis[y][x]+1;
            Q.push(make_pair(ey,ex));
        }
    }

    return dis.at(g.first).at(g.second);
}

int count_white(vector<vector<char>> grid){
    int h=grid.size(); int w=grid[0].size();
    int ans=0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(grid[i][j]=='.') ans++;
        }
    }
    return ans;
}

signed main(){ 
   int h,w; cin>>h>>w;
   vector<vector<char>> grid(h,vector<char>(w));
   vector<vector<int>> dis(h,vector<int>(w,-1));

   for(int i=0;i<h;i++){
       for(int j=0;j<w;j++){
           cin>>grid[i][j];
       }
   }

   int white=count_white(grid);

   int distance=bfs(dis,grid,make_pair(0,0),make_pair(h-1,w-1));
   //cout<<white<<endl;
   //cout<<distance<<endl;
   if(distance==-1){
       cout<<-1<<endl;
   }else{
       cout<<white-(distance+1)<<endl;
   }
}  

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

const long long MOD = 1000000007;

int main() {
	int N, M;
	cin >> N >> M;
	long long ans = 1;
	if (abs(N-M) > 1) {
		cout << 0 << endl;
		return 0;
	}
	else {
		int a = min(N, M);
		int b = max(N, M);
		for (int i = 1; i <= a; i++) {
			ans *= i;
			if (ans > MOD) ans %= MOD;
		}
		ans = (ans * ans) % MOD;
		if (a == b)
			ans = (2 * ans) % MOD;
		else
			ans = (b * ans) % MOD;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
if __name__ == "__main__":
	N, M = map(int, input().split())
	ac_list = [0] * (N+1)
	wa_list = [0] * (N + 1)
	for i in range(M):
		p, s = input().split()
		p = int(p)
		if s == "AC":
			ac_list[p] = 1
		else:
			if ac_list[p] == 0:
				wa_list[p] += 1
		# print(prob_list)
	ac = 0
	wa = 0
	for i in range(N+1):
		ac += ac_list[i]
		if ac_list[i] == 1:
			wa += wa_list[i]
	print("{0} {1}".format(ac, wa))


Measured memory_bytes: 4596
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define bit(n,k) (((ll)n>>(ll)k)&1) /*nのk bit目*/
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
//const ll MOD=1000000007LL;
const ll MOD=998244353LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vl dx={-1,-1,-1,0,0,1,1,1};
vl dy={1,-1,0,1,-1,1,0,-1};

int main(){
  ll n;cin>>n;
  deque<ll>three,two,four,six,ans;
  ans.push_back(3);
  ans.push_back(9);
  ans.push_back(2);
  ans.push_back(4);
  for(ll i=1;i<=30000;i++){
    if(i==3||i==9||i==2||i==4)continue;
    if(i%6==3)three.push_back(i);
    if(i%6==2)two.push_back(i);
    if(i%6==4)four.push_back(i);
    if(i%6==0)six.push_back(i);
  }
  if(n==3){
    cout<<2<<" "<<5<<" "<<63<<endl;
    return 0;
  }
  n-=4;
  while(n>0){
    if(three.size()>0&&n!=1){
      ans.push_back(three.front());
      three.pop_front();
      ans.push_back(three.front());
      three.pop_front();
      n-=2;
    }
    else if(two.size()>0&&n!=1){
      ans.push_back(two.front());
      two.pop_front();
      ans.push_back(four.front());
      four.pop_front();
      n-=2;
    }
    else {
      ans.push_back(six.front());
      six.pop_front();
      n--;
    }
         
  }
  rep(i,ans.size()){
    cout<<ans[i];
    if(i==ans.size()-1)cout<<endl;
    else cout<<" ";
  }
}
  


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

int main() {
	int N;
	string S;
	cin >> N >> S;
	char state = ' ';
	int ans = 0;
	for (char c : S) {
		if (c == 'A') state = 'A';
		else if (c == 'B' && state == 'A') state = 'B';
		else if (c == 'C' && state == 'B') {
			ans++;
			state = ' ';
		}
		else state = ' ';
	}
	cout << ans << endl;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main(int argc, char const *argv[])
{
	int x, y, z, K;
	cin >> x >> y >> z >> K;
	vector<ll> a(x), b(y), c(z);
	rep(i, a.size()) cin >> a[i];
	rep(i, b.size()) cin >> b[i];
	rep(i, c.size()) cin >> c[i];

	sort(all(a), greater<ll>());
	sort(all(b), greater<ll>());
	sort(all(c), greater<ll>());

	vector<ll> sum;
	rep(i, a.size()) rep(j, b.size()) rep(k, c.size()) {
		if ((i+1) * (j+1) * (k+1) <= K) sum.push_back(a[i] + b[j] + c[k]);
		else break;
	}
	sort(all(sum), greater<ll>());
	rep(i, K) cout << sum[i] << endl;

	return 0;
}

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

using namespace std;
using ll = long long;

const int MOD = 1e9 + 7;
#define REP(i, n)  for(int i = 0; i < n; ++i)
#define FOR(i, t, n)  for(ll i = t; i <= (ll)n; ++i)
struct edge {
    int from, to;
    ll cost;
};

vector<int> A[101010];
int N, K;
map<pair<int, int>, int> color;

void dfs(int from, int from_col) {
    int c = 1;
    for (int to:A[from]) {
        c == from_col ? color[make_pair(from, to)] = ++c : color[make_pair(from, to)] = c;
        dfs(to, c);
        c++;
    }
    if (K < c-1)K = c-1;
}

int main() {
    cin >> N;
    map<int, pair<int, int>> m;
    REP(i, N - 1) {
        int a, b;
        cin >> a >> b;
        m[i] = make_pair(a, b);
        A[a].push_back(b);
    }
    dfs(1, 0);
    cout << K << endl;
    REP(i, N - 1) {
        cout << color[m[i]] << endl;
    }
    return 0;
}


Measured memory_bytes: 19200
fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(' ').map { it.toInt() }

    val cities = (0 until m).map { i ->
        val (p, y) = readLine()!!.split(' ').map { it.toInt() }
        Triple(i, p, y)
    }.sortedBy { it.third }

    val counter = IntArray(n) { 0 }

    val ids = Array(m) { "" }

    cities.forEach {
        val i = it.first
        val p = it.second
        val x = ++counter[p - 1]
        ids[i] = p.toString().padStart(6, '0') + x.toString().padStart(6, '0')
    }

    ids.forEach {
        println(it)
    }

}

Measured memory_bytes: 96512
using System;


namespace ConsoleApplication13
{
    class Program
    {
        static void Main(string[] args)
        {
            int i = 1;
            int x;
            while (true)
            {
                string s = Console.ReadLine();
                x = int.Parse(s);
                if (x == 0) break;

                if (0 < x)
                {
                    Console.WriteLine("Case"+" "+ i + ":"+" " + x);
                    i++;

                }

            }

        }
    }
}

Measured memory_bytes: 9260
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <string>

int K;
std::string S;

int main() {
  std::cin >> K >> S;
  if (S.length() <= K) {
    std::cout << S << std::endl;
    return 0;
  }
  std::cout << S.substr(0, K) + "..." << std::endl;
  return 0;
}

Measured memory_bytes: 3628
#include<stdio.h>
int main(){
  int n;
  scanf("%d",&n);
  int a[n];
  int ans = 0;
  for(int i=0;i<n;i++)scanf("%d",&a[i]);
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      ans+=a[i]*a[j];
    }
  }
  printf("%d",ans);
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999

using namespace std;


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



ll maze[301][301];
ll maze2[301][301];
int main() {
	int N;
	cin >> N;
	REP(i, N) {
		REP(j, N) {
			cin >> maze[i][j];
		}
	}
	REP(i, N) {
		REP(j, N) {
			REP(k, N) {
				ll a = maze[i][j], b = maze[j][k], c = maze[k][i];
				if (a + b < c || b + c < a || c + a < b) {
					cout << -1 << endl;
					return 0;
				}
			}
		}
	}
	ll sum = 0;
	REP(i, N) {
		REP(j, N) {
			bool ok = false;
			REP(k, N) {
				if (k == i || k == j)continue;
				ll a = maze[i][j], b = maze[j][k], c = maze[k][i];
				if (b + c == a)ok = true;
			}
			if (!ok)sum += maze[i][j];
		}
	}
	cout << sum / 2 << endl;
}

Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#include<cmath>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using pll = pair<ll,ll>;
using vvii = vector<vector<int> >;
using vvll =  vector<vector<ll> >;

const ll inf = 1LL << 60;

ll mpow(ll x, ll n,ll mod){
    ll ans = 1;
    while(n){
        if(n % 2){
            ans = ans * x % mod;
        }
        x = x * x % mod;
        n >>= 1;
    }
    return ans;
}

int main(){
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
    ll K; cin>>K;
    ll waru = 7;
    ll count = 1;
    REP(i,K){
        if(waru % K == 0){
            cout<<count<<endl;
            return 0;
        }
        waru = waru + 7 * mpow(10,count,K) % K;
        count++;
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3684
import  fractions
from functools import reduce
import sys
input = sys.stdin.readline
def main():
    n=int(input())
    a=list(map(int,input().split()))
    # tmp = lcm(*a)
    mod=pow(10,9) + 7
    m=0
    ans=0
    tmp = a[0]
    for i in range(1,len(a)):
        tmp = (tmp*a[i]) // fractions.gcd(tmp,a[i])
    
    for i,v in enumerate(a):
        m=tmp//v
        ans+=m
    ans = ans % mod
    print(ans)


if __name__=='__main__':
    main()


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

int main(){
	int price, num;
	int totalPrice = 0, average;
	float totalNum = 0;
	char hoge;
	float count = 0;
	while(cin >> price >> hoge >> num){
		totalPrice += price * num;
		totalNum += num;
		count++;
	}

	float huga = totalNum/count - (int)(totalNum/count);
	if(0.5 <= huga) average = totalNum/count + 1;
	else average = totalNum/count;
	cout << totalPrice << "\n" << average << endl;

}

Measured memory_bytes: 1164
N = int(input())
W = [int(i) for i in input().split(" ")]
A = [0]
for i in range(N):
	A.append(A[-1]+W[i])
tot = A[-1]
ans = 100000000
for a in A:
	if ans > abs(tot-a*2):
		ans = abs(tot-a*2)
print(ans)

Measured memory_bytes: 3064
N = int(input())
c0=[]
c1=[]
c2=[]
c3=[]
for i in range(N):
    S = input()
    if S == "AC":
        c0.append(S)
    elif S == "WA":
        c1.append(S)
    elif S == "TLE":
        c2.append(S)
    elif S == "RE":
        c3.append(S)

print("AC","x",len(c0))
print("WA","x",len(c1))
print("TLE","x",len(c2))
print("RE","x",len(c3))


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

using namespace std;
typedef long long ll;

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;

  int left = 0, right = 0;
  for (int i = 0; i < N; i++) {
    if (S[i] == ')') {
      left++;
    } else {
      right++;
    }
    if (right > 0 && S[i] == ')') {
      left--;
      right--;
    }
  }
  
  cout << string(left, '(') + S + string(right, ')') << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;


/*
1~nを左から順に配置していく
dp(i,j)=iをjに置く
*/

ll n,A,B,a[5010],dp[5010]={},inf=1e18,ans=1e18;

int main(void){
	cin>>n>>A>>B;
	reg(i,1,n){
		ll x;
		cin>>x;
		a[x]=i;
	}
	reg(i,1,n){
		ll c=inf;
		reg(j,1,n){
			c=min(c,dp[j]);
			if(a[i]<j){
				dp[j]=c+A;
			}else if(a[i]>j){
				dp[j]=c+B;
			}else{
				dp[j]=c;
			}
		}
	}
	reg(i,1,n)ans=min(ans,dp[i]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include<string>
#include<cstring>
#include <cstdio>
#include<utility>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
#include<stack>
#include<set>
#include <limits>
#include <climits>
#include <numeric>
#include<cassert>
#include<cctype>
#include<iterator>
using namespace std;
typedef long long ll;
typedef vector<ll>VI;
typedef vector<bool>VB;
typedef pair<ll,ll>P;
typedef pair<double,double>P_D;
#define VV(T) vector<vector<T>>
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define bitrep(bit,A) for(int bit=A; ;bit=(bit-1)&A)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) (ll)((a).size())
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
#define chmax(x,a) x=c_max(x,a)
#define chmin(x,a) x=c_min(x,a)
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define SORT(c) stable_sort(ALL(c))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX_6 1001001//6
#define MAX_7 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
#define MOD 1000000007
#define INF 1<<30
#define INFTY 1000000000000000001LL
#define MAX_INT INT_MAX
#define Endl '\n'
#define greater greater<int>()
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}

int main(){
    int n;cin>>n;
    vector<vector<P>>a(n);
    rep(i,n){
        int A;cin>>A;
        rep(j,A){
            int x,y;cin>>x>>y;x--;
            a[i].push_back(P(x,y));
        }
    }
    int ans=0;
    for(int bit=0;bit<(1<<n);bit++){
        VI list;
        VI bad_people;
        bool ok=true;
        rep(i,n)if(bit&(1<<i))list.push_back(i);
        for(auto person:list){
            for(auto q:a[person]){
                if(q.se==0){
                if(binary_search(ALL(list),q.fi)){ok=false;break;}
                bad_people.push_back(q.fi);
                }
                if(q.se==1){
                    if(!binary_search(ALL(list),q.fi)){ok=false;break;}
                }
            }
        }
        sort(ALL(bad_people));
        rep(i,list.size())if(binary_search(ALL(bad_people),list[i]))ok=0;
        if(ok==1)chmax(ans,list.size());
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<math.h>
using namespace std;
void make(map<int,int>& ds,int A) {
  int d=2;
  while(A%d==0) {
    ds[d]++;
    A /= d;
  }
  d++;
  while(A>=d*d) {
    while(A%d==0) {
      ds[d]++;
      A /= d;
    }
    d += 2;
  }
  if(A != 1) {
    ds[A]++;
  }
}
long long binpow(long long N,long long C,long MOD) {
  if(C == 0)return 1;
  long long temp = 1;
  if(C%2==1)temp = N;
  return (((long long)powl(binpow(N,C/2,MOD),2.0)%MOD)*temp)%MOD;
}
long long inv(long long N,long MOD) {
  return binpow(N,MOD-2,MOD);
}
int main() {
  int N;
  cin >> N;
  int A[10010];
  map<int,int> ds[10010];
  map<int,int> lc;
  int i,j,ma=0;
  for(i=0;i<N;i++)cin >> A[i];
  for(i=0;i<N;i++) {
    make(ds[i],A[i]);
  }
  for(j=0;j<N;j++)for(auto const& k : ds[j]) {
    if(lc[k.first] < ds[j][k.first])lc[k.first] = ds[j][k.first];
  }
  long long L = 1;
  for(auto const& k : lc) {
    L *= pow(k.first,k.second);
    L = (L-1)%1000000007+1;
  }
  long long temp;
  long long ans = 0;
  for(i=0;i<N;i++) {
    ans += (L * inv(A[i],1000000007))%1000000007;
    ans %= 1000000007;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;
using itn = int;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a); i > (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define itn int
#define double ld
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl lcm(intl a,intl b){
    return a / gcd(a, b) * b;
}
intl digit10(intl a){
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    intl n,m,c;
    cin >> n >> m >> c;
    intl b[m];
    intl a[n][m];
    cin(i,b);
    ccin(i,j,a);
    intl cnt = 0;
    rep(i,n){
        intl d = 0;
        rep(j,m){
            d += a[i][j] * b[j];
        }
        if(d + c > 0)cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
re = 1

li = list(map(int, input().split()))

for i in range(n):
    if re > 1000000000000000000:
        break
    re = re * li[i]
if 0 in li:
    print(0)
elif re > 1000000000000000000:
    print(-1)
else:
    print(re)


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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;


class Solver {
  public:
    bool solve() {
        int A, B; cin >> A >> B;
        if(A > 9 or B > 9) cout << -1 << endl;
        else cout << A * B << endl;
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz size()
#define ll long long
#define all(_v) _v.begin(), _v.end()
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pvllvll pair <vector <ll>, vector <ll> >
#define ld long double
#define veci vector <int>
#define vecll vector <ll>


const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
const double PI = 3.1415926535897932384626433832795;
const double eps = 1e-9;
const int MOD1 = 1e9 + 7;
const int MOD2 = 998244353;

const int kvx[5] = {-2, -1, 0, 1, 2};
const int kvy[5] = {-2, -1, 0, 1, 2};
int d[1010][1010];
char a[1010][1010];
int n, m;

bool check(int x, int y) {
    return (x > 0 && x <= n && y > 0 && y <= m);
}

void solve() {
    cin >> n >> m;
    int sx, sy, ex, ey;
    cin >> sx >> sy >> ex >> ey;
    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= m; ++j)
            cin >> a[i][j], d[i][j] = 1e9;
    d[sx][sy] = 0;
    deque <pii> q;
    q.pb(mp(sx, sy));
    while(!q.empty()) {
        pii fr = q.front();
        q.pop_front();
        int x = fr.f, y = fr.s;
        for(int i = 0; i < 4; ++i) {
            int gx = x + dx[i], gy = y + dy[i];
            if(check(gx, gy) && a[gx][gy] == '.' && d[gx][gy] > d[x][y]) d[gx][gy] = d[x][y], q.push_front(mp(gx, gy));
        }
        for(int i = 0; i < 5; ++i) {
            for(int j = 0; j < 5; ++j) {
                int gx = x + kvx[i], gy = y + kvy[j];
                if(check(gx, gy) && a[gx][gy] == '.' && d[gx][gy] > d[x][y] + 1) d[gx][gy] = d[x][y] + 1, q.pb(mp(gx, gy));
            }
        }
    }
    if(d[ex][ey] == 1e9) cout << -1;
    else cout << d[ex][ey];
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int T = 1;
    ///cin >> T;
    while(T--) solve(), cout << '\n';
    return 0;
}


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


int main() {
  string str;
  cin>>str;
if(str=="hi" || str=="hihi" || str=="hihihi" || str=="hihihihi" || str=="hihihihihi"){cout<<"Yes"<<endl;}
else{cout<<"No"<<endl;}
return 0;
}


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

using namespace std;


int main()
{
    int N;
    string S;
    int K;
    char c;

    cin >> N >> S >>K;

    c = S[K-1];
    for (int i = 0; i < N; i++) {
        if (S[i] != c) {
            cout << "*";
        } else {
            cout << S[i];
        }
    }

    cout << endl;
    return 0;   
}

Measured memory_bytes: 256
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    a,b,c = map(int, readline().split())
    K = int(readline())

    for i in range(K):
        if a >= b:
            b *= 2
        else:
            if b >= c:
                c *= 2
    
    if a < b < c:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()


Measured memory_bytes: 9120
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String A = scanner.next();
		String B = scanner.next();
		String C = scanner.next();

		if (A.substring(A.length()-1, A.length()).equals(B.substring(0, 1))
				&& B.substring(B.length()-1, B.length()).equals(C.substring(0, 1)) ) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}

}

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

int main(){
  int N,i;
  cin >> N;
  long long a[N],sum=0,ans,x=0;
  for(i=0;i<N;i++){
    cin >> a[i];
    sum+=a[i];
  }
  ans = 100000000000000;
  for(i=0;i<N-1;i++){
    x+=a[i];
    sum-=a[i];
    ans = min(ans,abs(x-sum));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#define N 10000
#define M 500
int main(){
  int i,j,n,length,count=0,A[N],B[M];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }

  scanf("%d",&length);
  for(i=0;i<length;i++){
    scanf("%d",&B[i]);
  }
  
  for(i=0;i<length;i++){
    j=0;
    A[n]=B[i];
    while(A[j]!=B[i]){
      j++;
    }
    
      if(j!=n){
	count++;
      }
  }
  
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 640
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		double[] v = new double[N];
		for(int i = 0; i < N; i++) {
			v[i] = stdIn.nextInt();
		}
		Arrays.sort(v);
		
		double temp = (v[0]+v[1])/2;
		for(int i = 2; i < N; i++) {
			temp = (temp+v[i])/2;
		}
		
		System.out.println(temp);

	}

}

Measured memory_bytes: 21076
n=int(input())
L=[[] for i in range(n)]
for i in range(n-1):
    u,v,w=map(int, input().split())
    u-=1
    v-=1
    L[u].append([v,w])
    L[v].append([u,w])
ans=[-1]*n
ans[0]=0
from collections import deque
que=deque([])
que.append(0)
while que:
    v=que.popleft()
    for u, w in L[v]:
        if ans[u]!=-1:
            continue
        ans[u]=(ans[v]+w)%2
        que.append(u)
for a in ans:
    print(a)

Measured memory_bytes: 82720
#include<iostream>
#include<vector>
#include<ctype.h>
using namespace std;

char sentence[1200];

int main(){
    cin.getline(sentence,sizeof(sentence));
    int i=0;
    while(1){
        if(sentence[i]=='\0')break;
        if(isalpha(sentence[i]) && islower(sentence[i])){
            sentence[i] = toupper(sentence[i]);
        }
        else{
            sentence[i] = tolower(sentence[i]);
        }
        cout<<sentence[i];
        i++;
    }
    cout<<endl;
    return 0;
}



Measured memory_bytes: 3096
#include <iostream>
#include <string>    
#include <queue>
using namespace std;
typedef long long ll;
ll h, w;
string str;

int main() {
	cin >> h >> w;
	ll s[h+2][w+2];
	ll p[h+2][w+2];//1 : 0
	for(ll i = 1; i <= h; i++){
		cin  >> str;
		for(ll j = 1; j <= w; j++){
			s[i][j] = (str[j-1] == '.')? 0 : 1;
			p[i][j] = 0;
		}
		s[i][0] = -1; s[i][w+1] = -1;
		p[i][0] = -1; p[i][w+1] = -1;
	}//init
	for(ll j = 1; j <= w; j++){
		s[0][j] = -1; s[h+1][j] = -1;
		p[0][j] = -1; p[h+1][j] = -1;
	}
	
	ll r = 0;
	queue<ll> quex;
	queue<ll> quey;
	bool flag = true;
	ll imax = 1;
	while(flag){
		bool nopush = true;
		for(ll i = imax; nopush && i <= h; i++){
			for(ll j = 1; nopush && j <= w; j++){
				if(nopush && s[i][j] != -1){
					quex.push(i);
					quey.push(j);
					p[i][j] = 1;
					imax = i;
					nopush = false;
				}	
			}
		}
		flag = !nopush;
		ll countw = 0;
		ll countb = 0;
		while(!quex.empty()){
			ll x = quex.front(); quex.pop();
			ll y = quey.front(); quey.pop();
			if(s[x][y] != -1){
				if(p[x][y-1] == 0 && s[x][y] + s[x][y-1] == 1){quex.push(x); quey.push(y-1); p[x][y-1] = 1;}
				if(p[x][y+1] == 0 && s[x][y] + s[x][y+1] == 1){quex.push(x); quey.push(y+1); p[x][y+1] = 1;}
				if(p[x-1][y] == 0 && s[x][y] + s[x-1][y] == 1){quex.push(x-1); quey.push(y); p[x-1][y] = 1;}
				if(p[x+1][y] == 0 && s[x][y] + s[x+1][y] == 1){quex.push(x+1); quey.push(y); p[x+1][y] = 1;}
				if(s[x][y] == 0){countw++;}
				if(s[x][y] == 1){countb++;}
				s[x][y] = -1;
			}
		}
		r += countw*countb;
	}

	cout << r;	
	return 0;
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
using std::cout;
using std::endl;
using std::cin;

int main(){
	int li[10] = {};
	int n; cin >> n;
	for(int i = 0; i < n ;i++){
		int a; cin >> a;
		
		li[std::min(8, a / 400)]++;
	}
	
	int c = 0;
	for(int i = 0; i < 8; i++) if(li[i]) c++;
	
	cout << (c ? c : 1) << " " << c + li[8] << endl;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
li = [int(input()) for _ in range(n)]
li.sort(reverse=True)
point = sum(li)
while True:
    if point % 10 != 0:
        print(point)
        break
    if not li:
        print(0)
        break
    a = li.pop()
    point = point-a
    if point%10 == 0:
        point += a

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#pragma GCC optimize ("O2,unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) {cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;}
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod=1000000007;
const int MAXN=100010, LOG=20;

int n, m, k, u, v, x, y, t, a, b, ans;
int A[MAXN];

int Solve(){
	int x=0, y=0;
	for (int i=1; i<=n; i++){
		if (A[i]&1) y++;
		else x++;
	}
	if (x&1) return 1;
	if (y>=2) return 2;
	int g=0;
	for (int i=1; i<=n; i++){
		if (A[i]&1){
			if (A[i]==1) return 2;
			A[i]--;
		}
		g=__gcd(g, A[i]);
	}
	for (int i=1; i<=n; i++) A[i]/=g;
	return 3-Solve();
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n;
	for (int i=1; i<=n; i++) cin>>A[i];
	if (n>1 && Solve()==1) cout<<"First\n";
	else cout<<"Second\n";
	
	return 0;
}


Measured memory_bytes: 4040
import sys
sys.setrecursionlimit(10 ** 6)
import sys
def input():
    return sys.stdin.readline()[:-1]
N , Q = map(int,input().split())
graph = [[] for _ in range(N)]
point = [0] * N
for _ in range(N - 1):
    a , b = map(int,input().split())
    graph[a - 1].append(b - 1)
    graph[b - 1].append(a - 1)
#print(graph)
for _ in range(Q):
    a , b = map(int,input().split())
    a = a - 1
    point[a] += b
# dfsを用いて累積和を計算する
# 初期状態だと前の値がないためデフォルト引数に-1を代入
def dfs(now , prev = -1):
    for next in graph[now]:
        # 次のノードが前に参照した値の時はcontinue
        if next == prev:
            continue
        # 現在の値を次のポイントに加算することで累積和をとる
        point[next] += point[now]
        # 次のノードと現在のノードを引数にdfsを継続する
        dfs(next , now)

dfs(0)
print(*point)

Measured memory_bytes: 283020
// https://atcoder.jp/contests/agc014/tasks/agc014_a
#include <bits/stdc++.h>
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007      //10^9+7
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define Vec(K, L, N, S) vector<L> K(N, S)
#define rt sqrt
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, k, n, w, ans = -1, count = 0;
  string s, t;
  cin >> a >> b >> c;
  while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0)
  {
    lli d = a, e = b, f = c;
    a = e / 2 + f / 2 + 0.5;
    b = d / 2 + f / 2 + 0.5;
    c = d / 2 + e / 2 + 0.5;
    count++;
    if (count >= 100000)
    {
      cout << ans << endl;
      return 0;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<math.h>
#include<vector>
#include<algorithm>
#include<array>
#include<functional>
#include<iomanip>
#include<ios>
using namespace std;
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)

typedef int value_type; /* ソートするキーの型 */

value_type med3(value_type x, value_type y, value_type z)
/* x, y, z の中間値を返す */
{
    if (x < y)
        if (y < z) return y; else if (z < x) return x; else return z; else
        if (z < y) return y; else if (x < z) return x; else return z;
}

void quicksort(value_type a[], int left, int right,value_type index[])
/* クイックソート
 * a     : ソートする配列 
 * left  : ソートするデータの開始位置
 * right : ソートするデータの終了位置
 * index: index配列
 */
{
    if (left < right) {
        int i = left, j = right;
        value_type tmp, pivot = med3(a[i], a[i + (j - i) / 2], a[j]); /* (i+j)/2ではオーバーフローしてしまう */
        while (1) { /* a[] を pivot 以上と以下の集まりに分割する */
            while (a[i] < pivot) i++; /* a[i] >= pivot となる位置を検索 */
            while (pivot < a[j]) j--; /* a[j] <= pivot となる位置を検索 */
            if (i >= j) break;
            tmp = a[i]; a[i] = a[j]; a[j] = tmp; /* a[i],a[j] を交換 */
            tmp = index[i]; index[i] = index[j]; index[j] = tmp;
            i++; j--;
        }
        quicksort(a, left, i - 1,index);  /* 分割した左を再帰的にソート */
        quicksort(a, j + 1, right,index); /* 分割した右を再帰的にソート */
    }
}


int dfs(int n,int N){
    if (n>N){
        return 0;
    }
    

    int ret;
    
    return ret;
}
int main(){
    int N;
    //string S;
    cin >>N;

    int L[N];
    int max=0;
    int maxp=-1;
    FOR(i,N){
        cin>>L[i];
        if(max<L[i]){
            max=L[i];
            maxp=i;
        }
    }
    int sum=0;
    FOR(i,N){
        if(i-maxp){
            sum+=L[i];
        }
    }
    string ans;
    if(max<sum){
        ans="Yes";
    }else{
        ans="No";
    }
    
    std::cout <<setprecision(16)<< ans<< endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

int main(void){
    int n,l[100],count=0;

    scanf("%d", &n);
    for(int i=0; i<n; i++){
        scanf("%d", &l[i]);
    }

    qsort(l, n, sizeof(int), compare_int);

    for(int i=0; i<n; i++){
        for(int j=i+1;j<n;j++){
            for(int k=j+1;k<n;k++){
                if(l[i] != l[j] && l[j] != l[k] && l[i] != l[k] && l[i] + l[j] > l[k]) {
                    count++;
                    
                }
            }
        }
    }

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


Measured memory_bytes: 1728
from collections import deque

if __name__ == '__main__':

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

	mini = min(a,b)
	d = deque()
	for x in range(1,mini+1):
		a2 = a % x
		b2 = b % x
		if a2 == 0 and b2 == 0:
			d.appendleft(x)
	print(d[k-1])




Measured memory_bytes: 9404
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        long[] A = new long[N];
        long[] B = new long[N];
        for (int i = 0; i < N; i++) {
            A[i] = scan.nextLong();
            B[i] = scan.nextLong();
        }
        long diff = 0;
        for (int i = N - 1; 0 <= i; i--) {
            long target = A[i] + diff;
            long x = (target + (B[i] - 1))/ B[i];
            diff += x * B[i] - target;
        }
        System.out.println(diff);
    }
}


Measured memory_bytes: 90756
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let s = read::<String>().chars().collect::<Vec<_>>();
    let mut buffer = VecDeque::<char>::new();
    let mut ans = 0;
    for i in 0..s.len() {
        if s[i] == 'A' {
            if buffer.is_empty() {
            } else if buffer[buffer.len() - 1] != 'A' {
                buffer.clear();
            }
            buffer.push_back('A');
        } else if s[i] == 'B' {
            if buffer.is_empty() {
            } else if buffer[buffer.len() - 1] != 'A' {
                buffer.clear();
            } else {
                buffer.push_back('B');
            }
        } else {
            // C
            if buffer.is_empty() {
            } else if buffer[buffer.len() - 1] != 'B' {
                buffer.clear();
            } else {
                ans += buffer.len() - 1;
                buffer.pop_back();
            }
        }
    }
    println!("{:?}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

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

int main() {
	int n, a, b;
	int ans;
	cin >> n;
	int nm = n;
    ans = modpow(2, n, 1000000007);
	cin >> a;
	int am = a;
	cin >> b;
	int bm = b;
	ll c0 = 1;
	ll c1 = 1;
	for(int i=0; i<a; i++){
    	c0 *= nm;
   		c0 %= 1000000007;
    	c0 *= modpow(am, 1000000005, 1000000007);
   		c0 %= 1000000007;
    	nm--;
    	am--;
    }
	nm = n;
	for(int i=0; i<b; i++){
    	c1 *= nm;
   		c1 %= 1000000007;
    	c1 *= modpow(bm, 1000000005, 1000000007);
   		c1 %= 1000000007;
    	nm--;
    	bm--;
    }
	ans--;
	if(ans < 0) ans += 1000000007;
	ans -= c0;
	if(ans < 0) ans += 1000000007;
	ans -= c1;
	if(ans < 0) ans += 1000000007;
    cout << ans << endl;
}

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

using namespace std;

int main() {
    int n;
    scanf("%d", &n);

    list<int> lst;
    char op[20];
    int t;

    for (int i = 0; i < n; ++i) {
        scanf("%s", op);

        if (op[0] == 'i') { //insert
            scanf("%d", &t);
            lst.push_front(t);
        } else if (strlen(op) == 11) { //deleteFirst
            lst.pop_front();
        } else if (strlen(op) == 10) { //deleteLast
            lst.pop_back();
        } else { //delete
            scanf("%d", &t);
            for (auto itr = lst.begin(); itr != lst.end(); ++itr) {
                if (*itr == t) {
                    lst.erase(itr);
                    break;
                }
            }
        }
    }

    auto itr = lst.begin();
    printf("%d", *itr);
    itr++;
    for (; itr != lst.end(); itr++)
        printf(" %d", *itr);
    printf("\n");

    return 0;
}


Measured memory_bytes: 34392
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

bool check(int x) {
    int x2 = x;
    for(int i = 2; i*i <= x; i++) {
        int j = i*i;
        while (j < x) {
            j *= i;
        }
        if (j == x)
            return true;
    }
    return false;
}
int main() {
    int x;
    cin >> x;
    int ans = 1;
    for(int i = 2; i <= x; i++) {
        if (check(i))
            ans = max(ans, i);
    }
    cout << ans << endl;

    return 0;
}




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

int main(){
  int height,width;
  while(1){
    cin >> height >> width;
    if(height == 0 && width == 0)break;
    for(int i = 0; i < height; i++){
      if(i == 0 || i == height - 1){
        for(int j = 0; j < width; j++)cout << '#';
        cout << '\n';
      }
      else{
        cout << '#';
        for(int j = 1; j < width - 1; j++)cout << '.';
        cout << "#\n";
      }
    }
    cout << '\n';
  }
  return 0;
}


Measured memory_bytes: 2996
#include <map>
#include <queue>
#include <cmath>
#include <ctime>
#include <vector>
#include <cstdio>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <tr1/unordered_map>
#define mo 1000000007
#define num(x) (x>='0' && x<='9')
typedef unsigned long long ull;
typedef long long ll;
using namespace std::tr1;
using namespace std;
int read(){
    int p=0, q=1;
    char ch=getchar();
    while (!num(ch))
        (ch=='-'?q=-1:0),
        ch=getchar();
    while (num(ch)) p=p*10+ch-'0', ch=getchar();
    return p*q;
}
int power(ll a, int b){
	ll c=1;
	while (b){
		if (b&1) c=c*a%mo;
		a=a*a%mo;
		b>>=1;
	}
	return c;
}
#define N 200005
int n, x[N], y[N];
int main(){
	n=read();
	for (int i=1;i<=n;i++){
		int u=read(), v=read();
		x[i]=u+v;
		y[i]=u-v;
	}
	sort(x+1,x+1+n);
	sort(y+1,y+1+n);
	cout<<max(x[n]-x[1], y[n]-y[1])<<endl;
    return 0;
}

Measured memory_bytes: 5196
import sys
range = xrange
input = raw_input

M = 2501
inf = 3 * 10**18

inp = [int(x) for x in sys.stdin.read().split()]; ii = 0
n = inp[ii]; ii += 1
m = inp[ii]; ii += 1
s = inp[ii]; ii += 1

s = min(M - 1, s)

coupl = [[] for _ in range(n)]
V = []
A = []
B = []
for _ in range(m):
    u = inp[ii] - 1; ii += 1
    v = inp[ii] - 1; ii += 1
    coupl[u].append(2 * _)
    coupl[v].append(2 * _ + 1)
    V.append(v)
    V.append(u)

    A.append(inp[ii]); ii += 1
    B.append(inp[ii]); ii += 1

C = inp[ii + 0: ii + 2 * n: 2]
D = inp[ii + 1: ii + 2 * n: 2]
ii += n

import heapq
DP = [inf] * (n * M)
found = [0] * (n * M)
DP[s] = 0

#heapq.cmp_lt = 
queue = [(0,s)]
while queue:
    _,ind = heapq.heappop(queue)
    if found[ind]:
        continue
    found[ind] = 1
    node,money = divmod(ind, M)
    for eind in coupl[node]:
        v = V[eind]
        ind2 = ind - A[eind >> 1] + M*(v - node)
        if money >= A[eind >> 1] and not found[ind2]:
            val = DP[ind] + B[eind >> 1]
            if DP[ind2] > val:
                DP[ind2] = val
                heapq.heappush(queue, (val, ind2))

    ind2 = ind - money + min(M - 1, C[node] + money)
    val = DP[ind] + D[node]
    if DP[ind2] > val:
        DP[ind2] = val
        heapq.heappush(queue, (val, ind2))

ans = []
for node in range(1, n):
    ans.append(min(DP[node * M + m] for m in range(M)))
print '\n'.join(str(x) for x in ans)

Measured memory_bytes: 90696
#!/usr/bin/env python3
from itertools import *

# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    H , W = map(int,input().split())

    A = [list(input()) for i in range(H)]
    B = list(zip(*A))

    AA = [not all(x=="." for x in a) for a in A]
    BA = [not all(x=="." for x in b) for b in B]

    for a in compress(A,AA):
        for b in compress(a,BA):
            print(b,end="")
        print("")

    # Failed to predict input format
    pass

if __name__ == '__main__':
    main()


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

int main(){
	int a,b;
	
	while(1){
		cin>>a>>b;
		if(a==0 && b==0) break;
		if(a<b){
			cout<<a<<" "<<b<<endl;
		}else{
			cout<<b<<" "<<a<<endl;
		}
	}
}

Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int,int>;

void keiro(const vector<vector<int>> &edge, int v, vector<int> &trace);
int ans = 0;

int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<int>> edge(n, vector<int>(n,0));
    vector<int> trace(n, 0);
    for(int i = 0; i < m; i++){
        int a,b;
        cin >> a >> b;
        edge.at(a - 1).at(b - 1) = 1;
        edge.at(b - 1).at(a - 1) = 1;
    }
    keiro(edge, 0, trace);
    cout << ans << endl;
}

void keiro(const vector<vector<int>> &edge, int v, vector<int> &trace){
    trace.at(v) = 1;
    int sum = 0;
    for(int x : trace){
        sum += x;
    }
    if(sum == edge.at(v).size()){
        ans++;
    }
    else{
        for(int i = 0; i < edge.at(v).size(); i++){
            if(edge.at(v).at(i) == 1 && trace.at(i) == 0){
                keiro(edge, i, trace);
            }
        }
    }
    trace.at(v) = 0;
}

Measured memory_bytes: 3636
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    s = set()
    for a in A:
        if a in s:
            s.remove(a)
        else:
            s.add(a)
    ret = len(s)
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 13208
#include <bits/stdc++.h>
#include<functional>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
using namespace std;
int main()
{
  double W, H, x, y;
  cin >> W  >> H >> x >> y;
  double half = W*H/2;
  if ((x == W/2)&&(y == H/2)){
    cout << half << " 1" << endl;
  }else{
    cout << half << " 0"  << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O0")
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define Rep(i,a,n) for (ll i = (a); i < (n); ++i)
const ll mod = 1e9+7;
const ll INF = 1e18;
#define All(a) (a).begin(),(a).end()
#define Pi acos(-1)
using Graph = vector<vector<ll>>;
using V = vector<ll>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  chrono::system_clock::time_point start,end;
  start = chrono::system_clock::now();

  ll n, m;
  cin >> n >> m;
  vector<pair<ll,ll>> a(n);
  rep(i,n) {
    cin >> a[i].first >> a[i].second;
  }
  sort(All(a));
  ll ans = 0;
  for (ll i = 0; ; ++i) {
    ans += a[i].first * a[i].second;
    m -= a[i].second;
    if (m < 0) {
      ans += a[i].first * m;
      break;
    }
  }
  cout << ans << '\n';

  end = chrono::system_clock::now();
  auto elapsed = chrono::duration_cast< chrono::milliseconds >(end - start).count();
  cerr << elapsed << "ms" << '\n';
}

Measured memory_bytes: 4820