akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL<<60;
typedef pair<ll, ll> P;

int main() {
    vec d(2);
    cin>>N>>d[0]>>d[1];
    vec a(N);
    rep(i,N) cin>>a[i];
    mat dp(N, vec(2, 0)), sum(N, vec(2, 0));
    vec last(2, 0);
    dp[0][0] = dp[0][1] = sum[0][0] = sum[0][1] = 1;
    bool debug = false;
    reps(i,1,N){
        rep(j,2){
            //if(i == 4 && j == 1) debug = true;
            if(abs(a[i] - a[i-1]) >= d[j]) dp[i][j] = dp[i-1][j];
            auto ite = upper_bound(ALL(a), a[i] - d[j]);
            ll m = ite - a.begin();
            m = min(m, ll(i) - 1);
            (dp[i][j] += dp[m][1 - j] * (last[1 - j] <= m))%=MOD;
            //if(last[1 - j] > 0) (dp[i][j] += MOD - sum[min(last[1 - j] - 1, m)][1 - j])%=MOD;
            //debug = false;
        }
        rep(j,2) {
            //sum[i][j] = (sum[i-1][j] + dp[i][j])%MOD;
            if(abs(a[i] - a[i-1]) < d[j]) last[j] = i;
        }
        //cout<<last[0]<<' '<<last[1]<<endl;
        //cout<<dp[i][0]<<' '<<dp[i][1]<<endl;
    }
    cout<<(dp[N - 1][0] + dp[N - 1][1])%MOD<<endl;
}

Measured memory_bytes: 12032
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] cumulativeSum = new long[n];
        HashMap<Long, Long> map = new HashMap<>();
        long ans = 0;
        cumulativeSum[0] = sc.nextInt();
        map.put(cumulativeSum[0], 1L);

        for (int i = 1; i < n; i++) {
            cumulativeSum[i] = cumulativeSum[i - 1] + sc.nextInt();
            Long v = map.get(cumulativeSum[i]);
            if (v == null) {
                v = 0L;
            }
            map.put(cumulativeSum[i], ++v);
        }
        for (Long key : map.keySet()
             ) {
            Long v = map.get(key);
            if (key == 0) {
                v++;
            }
            if (v == 1) {
                continue;
            }
            ans +=  v * (v - 1) / 2;
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 102840
// WARNING: Add compile option "-std=c++11" for C++11 compile.

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;


/*--- Macro ---*/
#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 mp make_pair
#define pb push_back


/*---  Type ---*/
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;


/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;

// 4-direction
int dy4[] = {0,  1, -1,  0};
int dx4[] = {1,  0,  0, -1};

// 8-direction
int dy8[] = {0,  1,  1,  1,  0, -1, -1, -1};
int dx8[] = {1,  1,  0, -1, -1, -1,  0,  1};

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

// dp[i][0] := i桁目まで見て、Lと全ての桁が一致する(a, b)の組み合わせ数
// dp[i][1] := i桁目まで見て、L未満になることが確定している(a, b)の組み合わせ数
int dp[100001][2];

int main() {
  string L;
  cin >> L;
  int n = L.size();

  dp[0][0] = 1;
  rep(i, n) {
    if(L[i] == '0') {
      dp[i+1][0] = dp[i][0];
      dp[i+1][1] = (dp[i][1] + (dp[i][1]*2)%MOD) % MOD;
    } else {
      dp[i+1][0] = (dp[i][0] * 2) % MOD;
      dp[i+1][1] = ((dp[i][0]+dp[i][1])%MOD + (dp[i][1]*2)%MOD) % MOD;
    }
  }
  cout << (dp[n][0] + dp[n][1]) % MOD << endl;

  return 0;
}

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

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

  string s;
  cin >> s;

  int ans = 1;
  for (int i = 0; i < n - 1; i++) {
    if (s[i] != s[i + 1]) ans++;
  }

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

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



bool solve(long long x, long long N, long long K, vector<long long> A, vector<long long> F) {
    long long tmp = 0;
    for (int i = 0; i < N; i++){
        long long res = A[i] - x / F[i];
        if (res < 0) continue;
        tmp += res;
    }
    if (tmp <= K) return true;
    else return false;
}


int main() {
    long long N, K; cin >> N >> K;
    vector<long long> A(N); for (long long i = 0; i < N; i++) cin >> A[i];
    vector<long long> F(N); for (long long i = 0; i < N; i++) cin >> F[i];

    sort(A.begin(), A.end());
    sort(F.rbegin(), F.rend());

    long long left = 0;
    long long right = 1e18;
    for (int i = 0; i < 70; i++) {
        long long mid = (right + left) / 2;
        if (solve(mid, N, K, A, F)){
            right = mid;
        } else {
            left = mid;
        }
    }

    cout << right << endl;
    return 0;
}


Measured memory_bytes: 6552
#include<bits/stdc++.h>
#include <vector>
#include <algorithm>
#define ll long long
#define mod 1000000007
#define test int t; cin>>t; while(t--)
#define f for(int i=0;i<n;i++)
#define f1 for(int i=1;i<n-1;i++)
#define read(x) ll x; cin>>x;
#define TIME  cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";

using namespace std;
/*ll gcd(ll a , ll b){return b==0?a:gcd(b,a%b);}
int combi(int n, int k)
{
    int C[k+1];
    memset(C, 0, sizeof(C));

    C[0] = 1;

    for (int i = 1; i <= n; i++)
    {
        for (int j = min(i, k); j > 0; j--)
            C[j] = C[j] + C[j-1];
    }
    return C[k];
}
int factorial(int n)
{
    return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);
}
ll power(ll x,ll n)
{
    if(n==0) return 1;
    if(n&1) return x*power(x,n/2)*power(x,n/2);
    else
        return power(x,n/2)*power(x,n/2);
}*/
int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    static const auto _ = []() {
        ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
        return 0;
    }();
    int t;
    cin>>t;
   if(t>=400 && t<=599)
       cout<<8<<endl;
    if(t>=600 && t<=799) cout<<7<<endl;
    if(t>=800 && t<=999) cout<<6<<endl;
    if(t>=1000 && t<=1199) cout<<5<<endl;
    if(t>=1200 && t<=1399) cout<<4<<endl;
    if(t>=1400 && t<=1599) cout<<3<<endl;
    if(t>=1600 && t<=1799) cout<<2<<endl;
    if(t>=1800 && t<=1999) cout<<1<<endl;

//TIME
}

Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {

//    	File file = new File("test.txt");
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);
    	long h = sc.nextLong();
    	sc.close();
    	System.out.println(cntUp(h));
    }

    static long cntUp(long h){
    	if(1 == h){
    		return 1L;
    	}
    	else{
    		return cntUp(h / 2) * 2 + 1;
    	}
    }
}

Measured memory_bytes: 24148
#include"bits/stdc++.h"
using namespace std;

int main() {
	string s, t;
	cin >> s >> t;
	sort(s.begin(), s.end());
	sort(t.begin(), t.end());
	reverse(t.begin(), t.end());
	cout << (s < t ? "Yes" : "No") << endl;
	return 0;
}

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

// Hが 1<= H <= 10と非常に少ないということに気づかなかった
const int MAX_H = 15, MAX_W = 1100;
char S[MAX_W];
int acum[MAX_H][MAX_W]; // 1-indexedにする
int H, W, K;

int white(int a1, int b1, int a2, int b2) {
    return acum[a2][b2] - acum[a2][b1-1] - acum[a1-1][b2] + acum[a1-1][b1-1];
}

int bit_pop(int bits) {
    int res = 0;
    while(bits > 0) {
        if(bits & 1) ++res;
        bits >>= 1;
    }
    return res;
}

void print_bits(int bits) {
    while(bits>0) {
        if(bits&1) printf("1");
        else printf("0");
        bits >>= 1;
    }
    printf("\n");
}

int Piece[MAX_H];
int solve(int bits) {
    vector<int> Section;
    Section.push_back(0);
    for(int i = 1; i < H; ++i) {
        if(bits & 1<<i) Section.push_back(i);
    }
    Section.push_back(H);
    /*
    printf("bits: ");
    print_bits(bits);
    printf("\n");
    for(auto &p : Section) {
        printf("%d ", p);
    }
    printf("\n\n");
    */
    int piece_num = Section.size()-1;
    int res = Section.size()-2;
    for(int i = 0; i < piece_num; ++i) Piece[i] = 0;
    int Add[piece_num];
    for(int j = 1; j <= W; ++j) {
        bool flg = false;
        for(int i = 0; i < piece_num; ++i) {
            Add[i] = white(Section[i] + 1, j, Section[i+1], j);
            if(Add[i] > K) return H + W;
            Piece[i] += Add[i];
            if(Piece[i] > K) flg = true;
        }
        if(flg) {
            ++res;
            for(int i = 0; i < piece_num; ++i) Piece[i] = Add[i];
        }
    }
    return res;
}

int main()
{
    scanf("%d %d %d", &H, &W, &K);
    for(int i = 1; i <= H; ++i) {
        scanf("%s", S);
        for(int j = 1; j <= W; ++j) {
            acum[i][j] = S[j-1] - '0';
        }
    }
    // imos法
    for(int i = 0; i <= H; ++i) {
        for(int j = 0; j < W; ++j) {
            acum[i][j+1] += acum[i][j];
        }
    }
    for(int j = 0; j <= W; ++j) {
        for(int i = 0; i < H; ++i) {
            acum[i+1][j] += acum[i][j];
        }
    }

    /*
    for(int i = 1; i <= H; ++i) {
        for(int j = 1; j <= W; ++j) printf("%d ", acum[i][j]);
        printf("\n");
    }
    */

    int ans = H + W;
    for(int bits = 0; bits < 1<<(H-1); ++bits) {
        ans = min(ans, solve(bits << 1));
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b,c;
    while(1){
        cin>>a>>b>>c;
        if(a<=-1&&b<=-1&&c<=-1)break;
        else if(a<=-1||b<=-1) cout<<"F"<<endl;
        else if(a+b>=80) cout<<"A"<<endl;
        else if(a+b>=65) cout<<"B"<<endl;
        else if(a+b>=50) cout<<"C"<<endl;
        else if(a+b>=30){
            if(c>=50){
                cout<<"C"<<endl;
            }else{
                cout<<"D"<<endl;
            }
        }else cout<<"F"<<endl;
    }
}



Measured memory_bytes: 3116
import sys
n=int(input())
h=list(map(int,input().split()))
for i in range(n-1):
    if h[-i-2]>h[-i-1]:
        if h[-2-i]==h[-i-1]+1:
            h[-2-i]-=1
        else:
            print("No")
            sys.exit()
print("Yes")
    



Measured memory_bytes: 20628
A, B, C = [int(_) for _ in input().split()]


def gcd(x, y):
    if x < y:
        return gcd(y, x)
    elif x % y == 0:
        return y
    else:
        return gcd(y, x % y)


if C % gcd(A, B) == 0:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool palind(string s){
	int left=0,right=s.size()-1;
	while(right>left){
		if(s[right]!=s[left])
		return false;
		else
		right--;
		left++;
	}
	return true;
}
int main(){
     string s;
     cin>>s;
     int n=s.size();
     string s1=s.substr(0,n/2);
     string s2=s.substr(n/2+1,n/2);
     if(palind(s) && palind(s1) && palind(s2))
		 cout<<"Yes"<<endl;
	else
	cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define watch(x) cout << #x << " is " << x << endl;
#define print(a, l, r)          \
	for (int i = l; i < r; i++) \
		cout << a[i] << (i == (r - 1) ? endl : " ");
const long long M = 1000000007;
int main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

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

	if (b % a == 0)
		cout << (a + b) << endl;
	else
		cout << (b - a) << endl;

	return 0;
}

Measured memory_bytes: 256
#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>;

int main() {
  ll l, r;
  cin >> l >> r;
  ll ok = (l+2018)/2019*2019;
  ll ans = 2018;
  if(ok<r) ans = 0;
  else {
    for(ll i = l; i < r; i++) {
      for(ll j = i+1; j <= r; j++) {
        ans = min(ans,i*j%2019);
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
a,b,c,d = map(int,input().split())
n = int(input())
if min(a * 8,b * 4,c * 2,d) == a * 8:
  print(n * 4 * a)
elif min(a * 8,b * 4,c * 2,d) == b * 4:
  print(n * 2 * b)
elif min(a * 8,b * 4,c * 2,d) == c * 2:
  print(n * c)
else:
  print((n//2) * d + (n % 2) * min(a * 4,b * 2,c))

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#define ll int64_t
#define REP(i, n) for (ll i=0; i<n; i++)
using namespace std;

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

    int N, M;
    cin >> N >> M;
    vector<int> k;
    vector<vector<int>> s(M, vector<int>());
    REP (i, M) {
        int K;
        cin >> K;
        k.push_back(K);
        REP (j, K) {
            int S;
            cin >> S;
            S--;
            s[i].push_back(S);
        }
    }
    vector<int> p(M);
    REP (i, M) cin >> p[i];

    // bit全探索
    int ans = 0;
    REP (i, 1<<N) {
        // 電球ごとに点灯チェック
        int light = 0;
        REP (j, M) {
            int on = 0;
            for (auto k : s[j]) {
                if (i & (1<<k)) {
                    on++;
                }
            }
            if (on % 2 == p[j]) light++;
        }
        if (light == M) ans++;
    }

    cout << ans << "\n";
}

Measured memory_bytes: 256
#include <cstring>
#include <vector>
#include <iostream>
using namespace std;
vector<vector<int> > adj(200200);

int depth[200200];
int dfs2(int i, int p, int d=0) {
    depth[i] = d;
    for (int j : adj[i]) if (p != j) dfs2(j, i, d+1);
}

int main() {
    int n; cin >> n;
    if (n == 1) { cout << "First\n"; return 0; }
    for (int i = 1; i < n; i++) {
        int a, b; cin >> a >> b;
        a--; b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    dfs2(0, -1);
    int s, t, dmax = 0;
    for (int i = 0; i < n; i++)
        if (dmax < depth[i]) { dmax = depth[i]; s = i; }
    dmax = 0;
    memset(depth, 0, sizeof(depth));
    dfs2(s, -1);
    for (int i = 0; i < n; i++)
        if (dmax < depth[i]) { dmax = depth[i]; t = i; }
    cerr << s << ' ' << t << ' ' << depth[t] << endl;
    cout << ((depth[t] % 3 != 1) ? "First" : "Second") << endl;
}


Measured memory_bytes: 21376
class PQ{
    var size:Int = 0
    var heap = [Double]()
    
    func add(x:Double){
        heap.append(x)
        size += 1
        var index:Int = size - 1
        while(true){
            if(index == 0){
                break
            }
            let par_index:Int = (index-1) / 2
            if(heap[par_index] <= heap[index]){
                break
            }
            let tmp:Double = heap[index]
            heap[index] = heap[par_index]
            heap[par_index] = tmp
            index = par_index
        }
    }
    
    func getMin() -> Double{
        let res:Double = heap[0]
        var index = 0
        heap[index] = heap[size-1]
        size -= 1
        heap.removeLast()
        while(true){
            let leftIndex:Int = index * 2 + 1
            let rightIndex:Int = index * 2 + 2
            
            if(leftIndex >= size) {
                break
            }
            let L = heap[leftIndex]
            var R:Double = 2000000000
            if(rightIndex < size){
                R = heap[rightIndex]
            }
            
            if(heap[index] <= L && heap[index] <= R){
                break
            }else{
                if(L <= R){
                    let tmp:Double = heap[index]
                    heap[index] = heap[leftIndex]
                    heap[leftIndex] = tmp
                    index = leftIndex
                }else{
                    let tmp = heap[index]
                    heap[index] = heap[rightIndex]
                    heap[rightIndex] = tmp
                    index = rightIndex
                }
            }
        }
        return res
    }
    
}


var X = readLine()!.characters.split{$0==" "}.map{Int(String($0))!}

var N:Int = X[0]
var M:Int = X[1]

var pq = PQ()

var A = readLine()!.characters.split{$0==" "}.map{Int(String($0))!}

for i in 0..<N {
    let n:Int = A[i]
    let x:Double = -Double(n)
    pq.add(x)
}


for _ in 0..<M {
    var min:Double = pq.getMin()
    min /= 2.0
    pq.add(min)
}

var ans:Int = 0

for _ in 0..<N {
    ans += Int(-pq.getMin())
}

print(ans)




Measured memory_bytes: 7736
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define endl '\n'
#define pii pair<ll, ll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define traceloop(x,a) {for(ll i=0;i<x;i++) cerr<<a[i]<<" "; cerr<<endl;}
ll ab(ll x) {return x>0LL?x:-x;}

const ll inf = 1e18 + 5;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll n,W;
    cin>>n>>W;
    vector<ll> w(n),v(n);
    ll sum=0;
    for(int i=0; i<n; i++)
    {
        cin>>w[i]>>v[i];
        sum+=v[i];
    }
    vector<ll> dp(sum+1, inf);
    dp[0]=0;
    for(int item = 0; item<n; item++)
    {
        for(int j=sum; j>=0; j--)
        {
            if(dp[j]>=0 && j+v[item] <= sum)
            {
                dp[j+v[item]] = min(dp[j+v[item]],dp[j]+w[item]);
            }
        }
    }
    //traceloop(sum,dp);
    ll ans = 0;
    for(int i=0; i<=sum; i++)
        if(dp[i]<=W)
            ans = max(ans,(ll)i);
    cout<<ans;
    return 0;
}
    


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

#define int long long

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

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


int N,M;
int A[222222],B[222222];
bool flag1[222222],flag2[222222];

vint G[1111];

int r[1111];
bool used[1111];

void solve(int s){
    memset(r,-1,sizeof(r));
    memset(used,0,sizeof(used));

    for(auto v:G[s]){
        if(r[v]!=-1){
            used[v]=true;
            continue;
        }
        r[v]=v;
        queue<int>que;
        que.push(v);
        while(que.size()){
            int u=que.front();
            que.pop();
            for(auto w:G[u]){
                if(w==s)continue;
                if(r[w]!=-1){
                    if(r[w]!=v)used[w]=true;
                    continue;
                }
                r[w]=v;
                que.push(w);
            }
        }
    }

    queue<int>que;
    rep(i,N)if(used[i])que.push(i);

    while(que.size()){
        int v=que.front();
        que.pop();
        for(auto u:G[v]){
            if(u==s)continue;
            if(used[u])continue;
            used[u]=true;
            que.push(u);
        }
    }

    rep(i,M){
        if(A[i]==s){
            flag1[i]|=used[B[i]];
        }
        if(B[i]==s){
            flag2[i]|=r[A[i]]!=-1;
        }
    }
}

signed main(){
    cin>>N>>M;
    rep(i,M){
        cin>>A[i]>>B[i];A[i]--;B[i]--;
        G[A[i]].pb(B[i]);
    }

    rep(i,N)solve(i);
    rep(i,M){
        if(flag1[i]==flag2[i])puts("same");
        else puts("diff");
    }
    return 0;
}


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

int main()
{
    int m, n;
    int a[100];
    int all = 0;
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        all += a[i];
    }
    sort(a, a + n, greater<int>());
    int x = all / (4 * m) + (bool)(all % (4 * m));
    for (int i = 0; i < m; i++) {
        if (a[i] < x) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

int main() {
	string a, b, c;
	cin >> a >> b >> c;
	int na = a.size();
	int nb = b.size();
	int nc = c.size();
	queue<char> qa, qb, qc;
	rep(i, na) qa.push(a[i]);
	rep(i, nb) qb.push(b[i]);
	rep(i, nc) qc.push(c[i]);
	char turn = 'a';
	while(1) {
		if(turn == 'a') {
			if(qa.empty()) break;
			turn = qa.front();
			qa.pop();
		} else if(turn == 'b') {
			if(qb.empty()) break;
			turn = qb.front();
			qb.pop();
		} else {
			if(qc.empty()) break;
			turn = qc.front();
			qc.pop();
		}
	}
	cout << (char) (turn - 'a' + 'A') << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

int main() {
    int A, B, Q; cin >> A >> B >> Q;
    vector<ll> S(A), T(B);
    REP(i, 0, A) cin >> S[i];
    REP(i, 0, B) cin >> T[i];

    REP(i, 0, Q) {
        ll x; cin >> x;

        int rs = lower_bound(ALL(S), x) - S.begin();
        int ls = rs - 1;
        int rt = lower_bound(ALL(T), x) - T.begin();
        int lt = rt - 1;

        ll dist = 1LL << 60;
        if (rs < A && rt < B) dist = min(dist, max(S[rs], T[rt]) - x);
        if (ls >= 0 && lt >= 0) dist = min(dist, x - min(S[ls], T[lt]));
        if (rs < A && lt >= 0) dist = min(dist, S[rs] - T[lt] + min(abs(S[rs] - x), abs(T[lt] - x)));
        if (rt < B && ls >= 0) dist = min(dist, T[rt] - S[ls] + min(abs(S[ls] - x), abs(T[rt] - x)));
        cout << dist << endl;
    }
    return 0;
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
const int INF=10010010;
const double PI=3.141592653589;


int main(){
  int n; cin>>n;
  string s;cin>>s;
  bool ans=0;
  if(n%2!=0){
    ans=0;
  }else{
    string s1=s.substr(0,n/2);
    string s2=s.substr(n/2,n/2);
    // cout<<s1<<" "<<s2<<endl;
    if(s1==s2)
    ans=1;
  }
  cout<<(ans?"Yes":"No")<<endl;

return 0;
}


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

vector<int> viSort;
int iMaxSize;

void fnTrace()
{
  for (int i = 0; i < iMaxSize; i++)
  {
    if (i) cout << " ";
    cout << viSort[i];
  }
  cout << endl;
}

void insertionSort()
{
  for (int i = 1; i < iMaxSize; i++)
  {
    int iTarget = viSort[i];
    int j = i - 1;
    while (iTarget < viSort[j] &&
           j       >= 0            )
    {
      viSort[j + 1] = viSort[j];
      j--;
    }
    viSort[j + 1] = iTarget;
    fnTrace();
  }
}

int main()
{
  cin >> iMaxSize;
  viSort.resize( iMaxSize );
  for (int i = 0; i < iMaxSize; i++) cin >> viSort[i];

  fnTrace();
  insertionSort();

  return 0;
}

Measured memory_bytes: 1192
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MAX=1e6+7;
const int mod=1e9+7;
string s[MAX];
typedef pair<string,int>pp;
ll mexp(ll a,ll b){ll res=1;while(b>0){if(b%2){res=(res*a);}a=(a*a);b=b/2;}return res;}
int main(){
	int n;
	map<ll ,ll>mp;
	cin>>n;
	ll dp[n+1];
	int c[n+1];
	memset(dp,0,sizeof(dp));
	memset(c,0,sizeof(c));
	for(int i=0;i<n;i++)
		cin>>c[i];
	dp[0]=1;
	mp[c[0]]=1;
	for(int i=1;i<n;i++)
		if(c[i]==c[i-1])
			dp[i]=dp[i-1];
		else{
			dp[i]=mp[c[i]]+dp[i-1];
			dp[i]=dp[i]%mod;
			mp[c[i]]=dp[i];
		}

	cout<<dp[n-1];
}

Measured memory_bytes: 22912
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("-Ofast")
#include <bits/stdc++.h>
using namespace std;

typedef int in;
#define int long long
#define f first
#define s second
#define pb push_back
#define pp push
#define RETURN exit(0)
#define pow(x,y) (int)(pow(x,y))
#define ceil(x) (int)(ceil(x))
#ifndef ONLINE_JUDGE
#define debug(x) cout<<x<<endl;
#else
#define debug(x) 42
#endif
const int MAX=1e4;
const int MOD=1e9+7;
const int MAAX=1e15;
const long double EPS=1e-6;
const int N=1e6;
int power(int x,int y)
{
    if (y == 0)
        return 1;
    int a=power(x,y/2);
    if (y % 2 == 0)
        return a * a % MOD;
    else
        return x * a * a % MOD;
}
long double sq(int x){
    long double s=0,e=x,mid;
    while(e-s>=EPS){
        mid=(s+e)/2;
        if(mid*mid<=x){
            s=mid;
        }
        else{
            e=mid-EPS;
        }
    }
    return s;
}
vector<int> primes;
bool visted[N+5];
void sieve(){
    visted[0]=visted[1]=1;
    for(int i=2;i*i<=N;i++){
        if(visted[i]==0){
            primes.pb(i);
            for(int j=i*i;j<=N;j+=i){
                visted[j]=1;
            }
        }
    }
    for(int i=sqrt(N)+1;i<=N;i++){
        if(visted[i]==0)
            primes.pb(i);
    }
    return;
}

int arr[100010];

in main()
{
    //freopen("in.in","r",stdin);
    //freopen("out.out","w",stdout);
    int tc=1;
    //sieve();
    //scanf("%lld",&tc);
    while(tc--)
    {
        int n;
        cin>>n;
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
        int mn=INT_MAX;
        for(int i=-100;i<=100;i++){
            int x=0;
            for(int j=0;j<n;j++)
                x+=(arr[j]-i)*(arr[j]-i);
            mn=min(mn,x);
        }
        cout<<mn<<endl;
    }
    RETURN;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		 Scanner sc = new Scanner(System.in);
		 while(sc.hasNext()) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();
			int d = sc.nextInt();
			int e = sc.nextInt();
			int ans = 0;
			if(a<0) {
				ans = d + Math.abs(a)*c + b*e;
			}
			else {
				if(a==0)
					ans += d;
				ans += (b-a)*e;
			}
			System.out.println(ans);
	  }	 
	}
}


Measured memory_bytes: 26200
/*
 *
 * Copyright(c) 2016 Taikai Takeda <297.1951@gmail.com> All rights reserved.
 *
 */
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;

//conversion
//------------------------------------------
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();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#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(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))


//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    n*=2;
    

    vector<int> a(n);

    REP(i,n)
        cin >> a[i];

    sort(ALL(a));

    int ans = 0, i = 0;

    if (n % 2==1)
        i+=1;

    while(i < n){
        ans += a[i];
        i+=2;
    }

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


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 10000000000000007LL;
constexpr int inf = 1000000007;

int main() {
    vector<vector<ll>> comb(50 + 1, vector<ll>(50 + 1));
    comb[0][0] = 1;
    for (int i = 0; i <= 49; ++i) {
        for (int j = 0; j <= i; ++j) {
            comb[i + 1][j] += comb[i][j];
            comb[i + 1][j + 1] += comb[i][j];
        }
    }
    int n, a, b;
    cin >> n >> a >> b;
    vector<ll> v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
    sort(v.rbegin(), v.rend());
    if (v[0] != v[a - 1]) {
        double average = 0;
        int cnt_1 = 0;
        for (int i = 0; i < a; ++i) {
            average += v[i];
            cnt_1 += v[i] == v[a - 1];
        }
        average /= a;
        ll cnt_2 = 0;
        for (int i = a; i < n; ++i) {
            cnt_2 += v[i] == v[a - 1];
        }
        cout << fixed << setprecision(10) << average << endl;
        cout << comb[cnt_1 + cnt_2][cnt_1] << endl;
    } else {
        int cnt_same = 1;
        for (int i = 1; i < n; ++i) {
            cnt_same += v[i] == v[0];
        }
        ll cnt = 0;
        for (int i = a; i <= min(b, cnt_same); ++i) {
            cnt += comb[cnt_same][i];
        }
        cout << fixed << setprecision(10) << v[0] << endl;
        cout << cnt << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define mod 1000000007
typedef long long int ll;
int u(const void *a, const void *b){
    return *(ll*)a-*(ll*)b;
}
int d(const void *a, const void *b){
    return *(ll*)b-*(ll*)a;
}
int z(int a){
  if(a<1)a*=-1;
  return a;
}
int min(int a,int b){
  if(a>b)return b;
  return a;
}
int max(int a,int b){
  if(a>b)return a;
  return b;
}
int gcd(int a,int b){
  if(!b)return a;
  return gcd(b,a%b);
}
int kt(ll a){
  int sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
int ks(ll a){
  int sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
int n;
int f(int b,int c){
  return c*((n-1)/b+1);
}
int main(void){
  int n,ans=1;
  scanf("%d",&n);
  int a[n],cnt=1;
  FOR(n){
    scanf("%d",&a[i]);
    if(a[i]){
      cnt++;
    }else{
      ans=max(ans,cnt);
      cnt=1;
    }
  }
  PRN(max(ans,cnt));
  return 0;
}



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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll,ll> P;

vector<vector<P>> v(22);

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

	ll n;cin >> n;
	REP(i, n){
		ll a;cin >> a;
		REP(j, a){
			int x, y;cin >> x >> y;
			x--;
			v[i].EB(x, y);
		}
	}

	ll ans = 0;
	REP(bit, (1<<n)){
		bool flag = true;
		ll cou = 0;
		REP(i, n){
			if(bit & (1<<i))cou++;
			else continue;
			REP(j, v[i].size()){
				int taisyou = ((bit & (1<<v[i][j].FI)) > 0);
				int hantei = v[i][j].SE;
				if(taisyou != hantei){
					flag = false;
				}
				//cout << bitset<5>(bit) << " " << i << " " << j << " " << taisyou << " " << hantei << endl;
			}
		}
		if(flag)ans = max(ans, cou);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
n=int(input())
S=list(map(int,input().split()))
q=int(input())
T=list(map(int,input().split()))
S.sort()

def binary_search(list,item):
    low = 0
    high = len(list)-1
    while low <= high:
        mid = (low+high)//2
        guess = list[mid]
        if guess == item:
            return mid
        if guess > item:
            high = mid-1
        else:
            low = mid+1
    return None
cnt = 0
for i in range(len(T)):
    #print(T[i])
    if binary_search(S,T[i]) != None:
        #print("i",T[i])
        cnt += 1
print(cnt)



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

int main(){
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    if(B - C <= 0) cout <<0 << endl;
    else if(D - A <= 0) cout << 0 << endl;
    else if((C - A)*(B - D)>0) cout << min(abs(A - B), abs(C - D)) << endl;
    else cout << min(abs(B - C),abs(D - A)) << endl;
}


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

int main(){
    string a;
    cin>>a;
    if(a=="Sunny") cout<<"Cloudy"<<endl;
    else if(a=="Cloudy") cout<<"Rainy"<<endl;
    else cout<<"Sunny"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using ull = long long unsigned;
using P = pair<int,int>;
//const int INF=1e+11;
const int NMAX=8;
const int MOD=10000;
const int dbase=80*160;


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
ll h,w;
cin>>h>>w;
vector<string> s(h);
rep(i,h)cin>>s[i];
//cout<<s[1][1];
//vector<vector<int>> vis(h,vector<int> (w,0));

int ans=0;
rep(in,h)rep(jn,w){
	if (s[in][jn]=='#')continue;
	queue<P> q;
	vector<vector<int>> dist(h,vector<int> (w,-1));
	q.push(make_pair(in,jn));
	dist[in][jn]=0;
	int cnt=0;
	while(!q.empty()){
		P temp=q.front();
		q.pop();
		int i,j;
		i=temp.first;
		j=temp.second;
		//cout<<i<<'i'<<j<<'j'<<endl;
		if (i-1>=0 and s[i-1][j]=='.'){
			if (dist[i-1][j]==-1){
			q.push(make_pair(i-1,j));
			dist[i-1][j]=dist[i][j]+1;
			cnt=max(cnt,dist[i-1][j]);
		//	cout<<'l';
	}

		}
	//	cout<<"bef"<<i+1<<"i+"<<j<<'j'<<endl;
		if (i+1<=h-1 and s[i+1][j]=='.'){
	//		cout<<i+1<<"i+"<<j<<'j'<<endl;
			if (dist[i+1][j]==-1){
			q.push(make_pair(i+1,j));
			dist[i+1][j]=dist[i][j]+1;
				cnt=max(cnt,dist[i+1][j]);
}

		//	cout<<'r';

		}
		if (j-1>=0 and s[i][j-1]=='.'){
			if (dist[i][j-1]==-1){
			q.push(make_pair(i,j-1));
			dist[i][j-1]=dist[i][j]+1;
				cnt=max(cnt,dist[i][j-1]);
			}
		//	cout<<'d';
		}
		if (j+1<=w-1 and s[i][j+1]=='.'){
			if (dist[i][j+1]==-1){
			q.push(make_pair(i,j+1));
			dist[i][j+1]=dist[i][j]+1;
				cnt=max(cnt,dist[i][j+1]);
		//		cout<<j+1<<"j+"<<endl;
			}
		//	cout<<'u';
		}



	}
	//dist[i][j]=cnt;
//	cout<<in<<'i'<<jn<<'j'<<cnt<<endl;
	ans=max(ans,cnt);
}

cout<<ans;

}


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

void func(int **a, int x, int y)
{
	int i;
	if(a[y][x] == 0) return ;
	a[y][x] = 0;
	for(i = 1; i <= 3; i++){
		if(x-i >= 0){
			func(a, x-i, y);
		}
		if(x+i < 8){
			func(a, x+i, y);
		}
		if(y-i >= 0){
			func(a, x, y-i);
		}
		if(y+i < 8){
			func(a, x, y+i);
		}
	}
	
	return ;
}

int main(int argc, char **argv)
{
	int **a, n, x, y, i, j, k;
	scanf("%d", &n);

	for(i = 1; i <= n; i++){
		a = (int **)calloc(8, sizeof(int));
		for(j = 0; j < 8; j++){
			a[j] = (int *)calloc(8, sizeof(int));
			for(k = 0; k < 8; k++){
				scanf("%1d", &a[j][k]);
			}
		}
		scanf("%d", &x);
		scanf("%d", &y);
		x--;
		y--;
		func(a, x, y);
		
		printf("Data %d:\n", i);
		for(j = 0; j < 8; j++){
			for(k = 0; k < 8; k++){
				printf("%d", a[j][k]);
			}
			printf("\n");
			free(a[j]);
		}
		free(a);
	}
	
	return 0;
}

Measured memory_bytes: 0
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def solve():
    X = Scanner.int()
    t = 100
    cnt = 0
    while t < X:
        cnt += 1
        t = t + int(t * 0.01)
    print(cnt)


def main():
    # sys.stdin = open("sample.txt")
    solve()


if __name__ == "__main__":
    main()


Measured memory_bytes: 10724
#include<bits/stdc++.h>
using namespace std;
#define INFTY 1<<20
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long int ll;
using ipair = pair<int,int>;
bool operator< (const ipair a, const ipair b){return a.first < b.first;};
const int MOD=1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

struct UnionFind{
    vector<int> d;//d[i]:iの親の番号。根なら木のサイズ*(-1)
    UnionFind(int n=0):d(n,-1){}//全ての木のサイズが１と初期.n点
    
    int find(int x){//根を返す
    if(d[x] < 0) return x;//xが根の時はxを返す
    return d[x] = find(d[x]);
    }

    bool unite(int x,int y){//xとyの木をつなげたらtrue.大きい方に小さい方をつなげる.
    x = find(x);y = find(y);//根を求める
    if(x==y) return false;//同じ木に属していたらつなげる必要なし
    if(d[x]>d[y]) swap(x,y);//yの方がサイズが大きい時は交換する
    d[x] += d[y];//サイズの更新
    d[y] = x;//根の更新
    return true;
    }

    bool same(int x,int y){return find(x)==find(y);}//xとyが同じ木にあるか

    int size(int x){return -d[find(x)];}//xの木のサイズを返す
};
int main(){ 
    
    int n,m;cin>>n>>m;
    set<pair<int,int>> s;
    UnionFind tree(n);
    rep(i,m){
        int a,b;cin>>a>>b;a--;b--;
        if(s.count(pair<int,int>(a,b))==0){
            s.emplace(a,b);
            tree.unite(a,b);
        }

    }
    int ans = 0;
    rep(i,n){
        ans = max(ans,tree.size(i));
    }

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

Measured memory_bytes: 13488
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

struct UnionFind
{
  vector<int> par;
  vector<int> sz;

  UnionFind(int n)
  {
    init(n);
  }

  void init(int n) // 初期化
  {
    par.resize(n);
    sz.resize(n);
    REP(i, n)
    {
      par[i] = i;
      sz[i] = 1;
    }
  }

  int find(int x) // 木の根を求める
  {
    if (par[x] == x)
      return x;
    else
      return par[x] = find(par[x]);
  }

  void unite(int x, int y) // xとyの属する集合を併合
  {
    x = find(x);
    y = find(y);
    if (x == y)
      return;
    if (sz[x] < sz[y])
    {
      par[x] = y;
      sz[y] += sz[x];
    }
    else
    {
      par[y] = x;
      sz[x] += sz[y];
    }
  }

  bool same(int x, int y) // xとyが同じ集合に属するか否か
  {
    return find(x) == find(y);
  }
};

int main()
{
  int N, M;
  cin >> N >> M;
  UnionFind uf(N + M + 1);
  set<int> st;
  REP(i, N)
  {
    int K;
    cin >> K;
    REP(j, K)
    {
      int L;
      cin >> L;
      L--;
      st.insert(L);
      uf.unite(i, N + L);
    }
  }
  if (uf.sz[uf.find(0)] == N + st.size())
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}

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

using namespace std;
using ll = long long;

int main() {
  int n;
  cin >> n;
  vector<pair<string, int>> vp(n);
  for (int i = 0; i < n; i++) {
    cin >> vp[i].first >> vp[i].second;
  }
  string x;
  cin >> x;

  bool sleep = false;
  int time = 0;
  for (int i = 0; i < n; i++) {
    if (sleep) {
      time += vp[i].second;
    }
    if (vp[i].first == x) sleep = true;
  }

  cout << time << endl;
}

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

int main(int argc, char const *argv[])
{
	string s;
	long long k;
	cin>>s>>k;
	long long now=0;
	while (now<k)
	{
		if (s[now]!='1')
		{
			cout<<s[now]<<endl;
			return 0;
		}
		++now;
	}
	cout<<"1\n";
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int n;
    int a;
    int j;
    int x;
    cin >> n;
    int b[n];
    for(int i=0;i<n;i++){
        b[i]=0;
    }
    for(int i=0;i<n;i++){
        cin>>b[i];
    }
    for(int i=0;i<n;i++){
        a=b[i];
        j=i-1;
        while(j>=0 && b[j]>a){
            b[j+1]=b[j];
            j--;
        }
        b[j+1]=a;
        for(int j=0;j<n;j++){
            if(j!=n-1){
                cout << b[j] <<" ";
            }else{
                cout << b[j];
            }
        }cout <<endl;
        
    }
}


Measured memory_bytes: 3096
import java.util.Scanner;
import java.util.Deque;
import java.util.ArrayDeque;

class Main {
  public static void main(String... args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int q = sc.nextInt();
    Deque<String> names = new ArrayDeque<String>(50000);
    Deque<Integer> times = new ArrayDeque<Integer>(50000);

    for (int i = 0; i < n; i++) {
      names.offerLast(sc.next());
      times.offerLast(sc.nextInt());
    }

    execution(q, names, times);
  }

  public static void execution(int q, Deque<String> names, Deque<Integer> times) {
    int time;
    String name;
    int currentTime = 0;

    while(true) {
      try {
        name = names.removeFirst();
        time = times.removeFirst();

        if (time - q <= 0) {
          currentTime += time;
          System.out.println(name + " " + currentTime);
          continue;
        }

        time -= q;
        currentTime += q;

        names.offerLast(name);
        times.offerLast(time);

      } catch (Exception e) {
        break;
      }
    }
  }
}



Measured memory_bytes: 74164
#include<stdio.h>
#include<stdlib.h>
int c[199];
int number=0;

void push(int x){
  number++;
  c[number]=x;
}
int pop(){
  number--;
  return c[number+1];
}
  
int main(){
  char s[199];
  int x,y;
  while(scanf("%s",s)!=EOF){
    switch(s[0]){
    case '+':
      push(pop()+pop());
      break;
    case '*':
      push(pop()*pop());
      break;
    case '-':
      y = pop();
      x = pop();
      push(x-y);
      break;
    default:
      push(atoi(s));
      break;
    }
  }
  printf("%d\n",pop());
  return 0;
}

      



Measured memory_bytes: 2140
s = input()
if s =='SUN':
    print(7)
elif s == 'MON':
    print(6)
elif s == 'TUE':
    print(5)
elif s == 'WED':
    print(4)
elif s == 'THU':
    print(3)
elif s == 'FRI':
    print(2)
elif s == 'SAT':
    print(1)

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

int main() {
    int N;
    cin >> N;
    vector<int> A(N + 1), B(N);
    for (int i = 0; i < N + 1; i++)
        cin >> A[i];
    for (int i = 0; i < N; i++)
        cin >> B[i];

    long long res = 0;
    for (int i = 0; i < N; i++) {
        res += min(A[i], B[i]);
        if (A[i] < B[i]) {
            int t = B[i] - A[i];
            res += min(t, A[i + 1]);
            A[i + 1] = max(0, A[i + 1] - t);
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1024
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int n,m;
vvi G;
vi t;
vi used;
void f(int a){
	t.pb(a+1);
	rep(i,G[a].size())if(used[G[a][i]]==0){
		used[G[a][i]]=1;
		f(G[a][i]);
		break;
	}
}
int main(){
	cin>>n>>m;
	G=vvi(n);
	used=vi(n);
	rep(i,m){
		int a,b;cin>>a>>b;a--;b--;
		G[a].pb(b);
		G[b].pb(a);
	}
	used[0]=1;
	f(0);
	vi a=t;
	t=vi(0);
	f(0);
	cout<<t.size()+a.size()-1<<endl;
	rep(i,a.size()-1)cout<<a[a.size()-1-i]<<" ";
	rep(i,t.size())cout<<t[i]<<" \n"[i==t.size()-1];
}



Measured memory_bytes: 10000
#import numpy as np
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as comb_with

#A = int(input())
#H1,M1,H2,M2,K= map(int,input().split())
#A = list(map(int,input().split()))
#B = list(map(int,input().split()))
S= str(input())
S=list(S)
if S[-1]=='?':
    S[-1]='D'

for i in reversed(range(len(S)-1)):
    if S[i]=='?':
        S[i]='D'
print(''.join(S))


Measured memory_bytes: 10756
n = int(input())
s = [input() for i in range(n)]
ans = []
d = {}
for i in s:
    d.setdefault(i, 0)
    d[i] += 1

maxv = 0
for i in d.values():
    maxv = max(maxv,i)
for i in d.keys():
    if d[i] == maxv:
        ans.append(i)

ans.sort()
for i in ans:
    print(i)


Measured memory_bytes: 35216
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  string T;
  cin >> S >> T;
  int A,B;
  cin >> A >> B;
  string U;
  cin >> U;
  if (S == U ){
    A--;
  }else if ( T == U ){
    B--;
  }
  cout << A << " " << B << endl;
  return 0;
}

Measured memory_bytes: 256