akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <vector>
#include <valarray>
#include <array>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <complex>
#include <random>

using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr int TEN(int n) {return (n==0)?1:10*TEN(n-1);}

template<class T>
T pow(T x, ll n) {
    T r = 1;
    while (n) {
        if (n & 1) r *= x;
        x *= x;
        n >>= 1;
    }
    return r;
}

template<uint MD>
struct ModInt {
    uint v;
    ModInt() : v(0) {}
    ModInt(ll v) : v(normS(v%MD+MD)) {}
    uint value() const {return v;}
    static uint normS(const uint &x) {return (x<MD)?x:x-MD;};
    static ModInt make(const uint &x) {ModInt m; m.v = x; return m;}
    const ModInt operator+(const ModInt &r) const {return make(normS(v+r.v));}
    const ModInt operator-(const ModInt &r) const {return make(normS(v+normS(MD-r.v)));}
    const ModInt operator*(const ModInt &r) const {return make((ull)v*r.v%MD);}
    ModInt& operator+=(const ModInt &r) {return *this=*this+r;}
    ModInt& operator-=(const ModInt &r) {return *this=*this-r;}
    ModInt& operator*=(const ModInt &r) {return *this=*this*r;}
    static ModInt inv(const ModInt &x) {
        return pow(ModInt(x), MD-2);
    }
};
using Mint = ModInt<TEN(9)+7>;

int x, y, z;
Mint dp[110][1<<17];
bool used[110][1<<17];
Mint solve(int n, int f) {
    f &= (1<<18)-1;
    assert(f & 1);
    if (f & (1<<z) and f & (1<<(y+z)) and f & (1<<(x+y+z))) return 0;
    if (n == 0) return 1;
    if (used[n][f>>1]) return dp[n][f>>1];
    used[n][f>>1] = true;
    Mint ans = 0;
    for (int i = 1; i <= 7; i++) {
        ans += solve(n-1, (f<<i) | 1);
    }
    ans += solve(n-1, 1)*3;
    return dp[n][f>>1] = ans;
}

int main() {
    int n;
    cin >> n >> x >> y >> z;
    cout << (pow(Mint(10), n) - solve(n, 1)).value() << endl;
    return 0;
}


Measured memory_bytes: 61184
import math
def action(x,K):
    x=abs(x-K)
    return x
N,K=map(int,input().split())
if N>K:
    N=N-math.floor((N-K)/K)*K
n=N
while True:
    N=action(n,K)
    if N>n:
        print(n)
        break
    n=N

Measured memory_bytes: 9096
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
	string s;
	int ans1,ans2;
	ans1 = -1;
	ans2 = -1;
	cin >> s;
	for(int i=0;i<s.size()-1;i++){
		if(s[i]==s[i+1]){
			ans1=i+1;
			ans2=i+2;
		}
	}
	for(int j=0;j<s.size()-2;j++){
		if(s[j]==s[j+2]){
			ans1=j+1;
			ans2=j+3;
		}
	}
	cout << ans1 <<" "<< ans2 <<endl;
	return 0;
}

Measured memory_bytes: 512
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> time;
  int sum=0;
  for(int i=0;i<n;i++){
    int t;
    cin>>t;
    time.push_back(t);
    sum+=t;
  }
  int temp=sum;
  int m;
  cin>>m;
  for(int i=0;i<m;i++){
    int p,x;
    cin>>p>>x;
    sum-=(time[p-1]-x);
    cout<<sum<<endl;
    sum=temp;
    }
  
  return 0;
}


Measured memory_bytes: 256
#include <vector> 
#include <list> 
#include <map> 
#include <set> 
#include <deque> 
#include <queue> 
#include <stack> 
#include <bitset> 
#include <algorithm> 
#include <functional> 
#include <numeric> 
#include <utility> 
#include <sstream> 
#include <iostream> 
#include <iomanip> 
#include <cstdio> 
#include <cmath> 
#include <cstdlib> 
#include <cctype> 
#include <string> 
#include <cstring> 
#include <ctime> 

using namespace std;

#define _int64 long long

int a[110000];

int main()
{
  int i,n,tmp,best,bi;
  scanf("%d",&n);
  for (i=0;i<n;i++)
    scanf("%d",&a[i]);
  sort(a,a+n);
  bi=-1;best=-1;
  for (i=0;i+1<n;i++)
  {
    tmp=a[i];
    if (a[n-1]-tmp<tmp) tmp=a[n-1]-tmp;
    if (tmp>best)
    {
      best=tmp;
      bi=i;
    }
  }
  printf("%d %d\n",a[n-1],a[bi]);
  return 0;
}

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

using namespace std;

const int ms_c = 31;
int d[ms_c][ms_c];
const int ms = 500 + 17;
int colors[ms][ms];

int arr[3][ms_c];
pair<int, int> cost[3][ms_c];


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;

    vector<int> can;

    can.push_back(1);

    for(int i = 1; i <= 5; ++i)
    {
        int v = 1;

        for(int j = 1; j <= i; ++j)
            v *= 9;

        can.push_back(v);
    }


    for(int i = 1; i <= 6; ++i)
    {
        int v = 1;

        for(int j = 1; j <= i; ++j)
            v *= 6;

        can.push_back(v);
    }

    sort(can.begin(), can.end());


    int value = n;
    int amount = 0;

    vector<int> dp(100000 + 17, 0);
    for(int i = 0; i < can.size(); ++i)
    {
        dp[can[i]] = 1;
    }


    for(int i = 2; i <= n; ++i)
    {
        if(dp[i])
            continue;

        dp[i] = 1;

        int v = -2;

        for(int j = 0; j < can.size(); ++j)
        {
            if(i - can[j] >= 1)
            {
                if(v < 0)
                    v = dp[i - can[j]];
                else
                    v = min(v, dp[i - can[j]]);
            }
            else
                break;
        }

        dp[i] += v;
    }


    cout << dp[n] << '\n';







}




Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

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

    if(s == "zyxwvutsrqponmlkjihgfedcba") {
        out(-1);
        re0;
    }

    if(s.size() < 26) {
        cout << s;
        for(char c = 'a'; c <= 'z'; c++) {
            bool ok = true;  // cがsに現れなければtrue
            rep(i, s.size()) {
                if(s[i] == c) {
                    ok = false;
                    break;
                }
            }
            if(ok) {
                cout << c << endl;
                re0;
            }
        }
    }

    ll i;  // s[i]からs[25]をsの接尾辞であって文字が左から右に降順に並んでいるもののうち最長のものとする
    for(i = 25; i >= 1; i--) {
        if(s[i-1] < s[i]) {
            break;
        }
    }
    
    for(char c = s[i-1]; c <= 'z'; c++) {
        bool ok = true;  // cがs[0]からs[i-1]に現れなければtrue
        rep(j, i) {
            if(c == s[j]) {
                ok = false;
                break;
            }
        }
        if(ok) {
            s[i-1] = c;
            break;
        }
    }
    
    out(s.substr(0, i));
    re0;
}

Measured memory_bytes: 256
def solve(N,h):
    dp=[0]*N
    dp[1]=abs(h[1]-h[0])
    for i in range(2,N):
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
    return dp[N-1]

N=int(input())
h=list(map(int,input().split()))
print(solve(N,h))

Measured memory_bytes: 13908
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = 1001;
const ll MOD = (1e9)+7;

ll modPow(ll b, ll e) {
	if(!e) return 1;
	else if(e == 1) return b;
	else return modPow(b*b % MOD, e >> 1) * modPow(b, e & 1) % MOD;
}

int n, a, b, c, d;
ll C[MAX][MAX], dstr[MAX][MAX], dp[MAX][MAX];
int main() {
	cin >> n >> a >> b >> c >> d;
	C[1][0] = C[1][1] = 1;
	for(int i = 2; i <= n; i++) {
		C[i][0] = C[i][i] = 1;
		for(int j = 1; j < i; j++) C[i][j] = (C[i-1][j-1] + C[i-1][j]) % MOD;
	}
	for(int i = 1; i <= n; i++) {
		dstr[i][1] = 1;
		for(int j = 2; i*j <= n; j++)
			dstr[i][j] = dstr[i][j-1] * C[i*j][i] % MOD * modPow(j, MOD - 2) % MOD;
	}
	dp[0][a-1] = 1;
	for(int i = 0; i <= n; i++) {
		for(int j = a; j <= b; j++) {
			dp[i][j] = dp[i][j-1];
			for(int k = c; k <= d && j*k <= i; k++) {
				dp[i][j] += dp[i-j*k][j-1] * C[i][j*k] % MOD * dstr[j][k] % MOD;
				dp[i][j] %= MOD;
			}
		}
	}
	cout << dp[n][b] - dp[n][a-1];
}


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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;

const ll e5 = 1 << 20;
const ll mod = 1000000007;
const ll e3 = 1 << 13;
const ll INF = 1ll << 60;

ll n,m;
ll a[e5];
ll ans = 0;

int main(){
  cin >> n >> m;
  for(ll i = 0;i < m;i++){
    ll l,r;
    cin >> l >> r;
    a[l]++;
    a[r+1]--;
  }
  for(ll i = 1;i <= n;i++){
    a[i] += a[i-1];
  }
  for(ll i = 1;i <= n;i++){
    if(a[i] == m) ans++;
  }
  cout << ans << endl;

}


Measured memory_bytes: 1024
/*BISMILLAH
THE WHITE WOLF
NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<long long> vll;
typedef vector<int> vi;

#define io ios_base::sync_with_stdio(false)
#define pb push_back

#define eb emplace_back
#define mod   1000000007
#define PI 2*acos(0.0)
#define all(r)(r).begin(),(r).end()
#define dbg(a) cout<<#a<<" ->->->-> "<<a<<"\n"
#define inf 1000000000000000000
#define N 2000
int dirx[] = {1, -1,0, 0}, diry[] = {0, 0, 1, -1};

int n,m, sx, sy, dx, dy;
ll dp[N][N];
int ck[N][N];

//=============================================ASIFAZAD==============================================//


int32_t main()
{
    io;
    int h, w, m;
    cin>>h>>w>>m;
    vi col(h+5), row(w+5);
    set<pii> inp;
    for(int i = 0;i < m; i++)
    {
        int u, v;
        cin>>u>>v;
        col[u]++;
        row[v]++;
        inp.insert({u, v});
    }
    int a1 = 0, a2  =0, ic, ir, ma1 = -1, ma2 = -1;
    vi f, s;
    for(auto x: col)
        ma1 = max(ma1, x);
    for(auto x: row)
        ma2 = max(ma2, x);
    for(int i = 0; i<= h; i++)
    {
        if(col[i] == ma1)
            f.pb(i);
    }
    for(int i = 0; i<= w; i++)
    {
        if(row[i] == ma2)
            s.pb(i);
    }
    ll ans = ma1 + ma2 - 1;
    bool ck = 0;
    for(auto x: f)
    {
        for(auto y: s)
        {
            if(ck)
                break;
            if(inp.count({x, y}) == 0)
            {
                ck = 1;
                break;
            }
        }
    }
    if(ck)
        ans++;
    cout<<ans;
    return 0;
}


Measured memory_bytes: 23804
#include <cstdio>
#include <vector>
#include <deque>
#include <algorithm>
#include <utility>
using namespace std;
vector<int> s;
typedef struct node{
	int pos,dist,p;
	vector<pair<int,int> > queries;
	vector<int> v;
};
node arr[110000];
int ans[110000]={};
deque<pair<int,int> >dq;
void dfs(int x,int lv){
	arr[x].dist=lv;
	for(auto &it:arr[x].v){
		dfs(it,lv+1);
	}
}
void dfs2(int x){
	s.push_back(x);
	for(auto &it: arr[x].queries){
		ans[it.second]=arr[x].dist-arr[it.first].dist+(arr[s[arr[it.first].dist]].pos<arr[it.first].pos);
	}
	for(auto &it:arr[x].v){
		dfs2(it);
	}
	s.pop_back();
}
int main(){
	int n,l;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&arr[i].pos);
	}
	scanf("%d",&l);
	for(int i=1;i<=n;i++){
		dq.push_back({arr[i].pos,i});
		while(arr[i].pos>dq.front().first+l){
			arr[dq.front().second].p=i-1;
			dq.pop_front();
		}
	}
	while(!dq.empty()){
		arr[dq.front().second].p=n;
		dq.pop_front();
	}
	for(int i=1;i<n;i++){
		arr[arr[i].p].v.push_back(i);
	}
	int q,a,b;
	scanf("%d",&q);
	for(int i=1;i<=q;i++){
		scanf("%d %d",&a,&b);
		if(a>b)swap(a,b);
		arr[a].queries.push_back({b,i});
	}
	dfs(n,0);
	dfs2(n);
	for(int i=1;i<=q;i++){
		printf("%d\n",ans[i]);
	}
}

Measured memory_bytes: 18424
#include<bits/stdc++.h>
using namespace std;
#define optimizar_io ios_base::sync_with_stdio(0); cin.tie(0);
#define fore(i, a, b) for(int i = a; i < b; i++)
#define fori(i, a, b) for(int i = a; i <= b; i++)
#define pb push_back
#define popb pop_back
#define mk make_pair
#define fi first
#define se second
#define endl '\n'
#define MAX 1000005
typedef long long int lli;
typedef long double ld;
const double PI = acos(-1.0);
ld eps = 1e-9;

vector<int> bucket(MAX, 0);
bool is(set<int> &s, int n) {
	if(bucket[n] >= 2) return false;
	for(int i = 1; i * i <= n; i++) {
		if(!(n % i)) {
			if(s.count(i) && i != n) return false;
			if(i * i != n) {
				if(s.count(n / i) && (n / i) != n) return false;
			}
		}
	}
	return true;
}
int main() {
	optimizar_io
	int n; cin >> n;
	vector<int> v(n);
	set<int> s;
	fore(i, 0, n) {
		cin >> v[i];
		bucket[v[i]]++;
		s.insert(v[i]);
	}
	int cont = 0;
	fore(i, 0, n) {
		if(is(s, v[i])) cont++;
	}
	cout << cont << endl;
}

Measured memory_bytes: 17168
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <set>
using namespace std;
typedef long long int LL;

const int MAX = 100+24;
char g[MAX][MAX];
bool r[MAX], c[MAX];
int main(){
    int h,w;
    while(~scanf("%d %d",&h,&w)){
        memset(r, false, sizeof r);
        memset(c, false, sizeof c);
        for(int i =0;i<h;i++){
            scanf("%s",g[i]);
        }
        for(int i = 0;i<h;i++){
            bool flag = true;
            for(int j =0;j<w;j++){
                if(g[i][j] == '#'){
                    flag = false;
                    break;
                }
            }
            if(flag){
                r[i] = true;
            }
        }
        for(int i = 0;i<w;i++){
            bool flag = true;
            for(int j =0;j<h;j++){
                if(g[j][i] == '#'){
                    flag = false;
                    break;
                }
            }
            if(flag){
                c[i] = true;
            }
        }
        for(int i =0;i<h;i++){
            for(int j =0;j<w;j++){
                if((!r[i]) && (!c[j])){
                    printf("%c", g[i][j]);
                }
            }
            printf("\n");
        }
    }
    return 0;
}


Measured memory_bytes: 256
// Problem : A - Takoyaki
// Contest : AtCoder - AtCoder Beginner Contest 176
// URL : https://atcoder.jp/contests/abc176/tasks/abc176_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
ordered_set;	

#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, int> para;
const ll inf = 1e18 + 7;
const ll maxN = 1e6 + 5;
const ll MOD = 1e9 + 7;

// sprawdz MODULO!
int main() {
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	ll n, x, t;
	cin >> n >> x >> t;
	cout << ((n + x - 1) / x) * t;
	return 0;
}
 


Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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

ll gcd(ll a, ll b)
{
    if (a % b == 0)
    {
        return (b);
    }
    else
    {
        return (gcd(b, a % b));
    }
}

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

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

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


template <typename T>
T amarinasi(T a,T b){
    if(a%b==0)
{
    return a/b;
}
else if(a%b>0)
{
    return a/b+1;
}
else
{
    return a/b-1;
}
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

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

int main(){
ll n,d;
cin>>n>>d;
cout<<amarinasi(n,d*2+1)<<endl;
}










Measured memory_bytes: 256
from itertools import combinations
from collections import Counter


def main():
    n = int(input())
    if n == 1:
        print(1)
        exit()

    XY = [list(map(int, input().split())) for _ in range(n)]
    d = []
    for A, B in combinations(XY, 2):
        x1, y1 = A[0], A[1]
        x2, y2 = B[0], B[1]
        p, q = x2 - x1, y2 - y1
        d.append((p, q))
        d.append((-p, -q))
    # print(d)
    # print(Counter(d))

    C = Counter(d)
    ans = 0
    for v in C.values():
        ans = max(ans, v)
    print(n - ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3828
import sys

INPUT = lambda: sys.stdin.readline().rstrip()
MAP = lambda: map(int, INPUT().split())

sys.setrecursionlimit(10 ** 9)
INF = float('inf')


def main():
    N, T = MAP()

    ans = INF
    for i in range(N):
        c, t = MAP()
        if t <= T: ans = min(ans, c)

    print("TLE" if ans == INF else ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  string S;
  cin >> S;
  int si = S.size();
  char alp[] = {'A','B','C','D','E','F','G','H','I','J','K',
                'L','M','N','O','P','Q','R','S','T','U','V',
                'W','X','Y','Z'};
  int S_[10003];
  for (int i = 0; i < si; i ++) {
    for (int j = 0; j < 26; j ++) {
      if (S[i] == alp[j]) {
        S_[i] = (j + N) % 26;
        break;
      }
    }
  }
  for (int i = 0; i < si; i ++) cout << alp[S_[i]];
  cout << endl;
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
using ll = long long;
using namespace std;

int main(){
	ll n,m,r;
	cin>>n>>m>>r;
	ll rr[10];
	rep(i,0,r)cin>>rr[i];
	ll a[22000],b[22000],c[22000];
	rep(i,0,m)cin>>a[i]>>b[i]>>c[i];

	ll dp[220][220];
	rep(i,0,220){
		rep(j,0,220){
			if(i==j)dp[i][j]=0;
			else if(i!=j) dp[i][j]=100000000;
		}
	}
	rep(i,0,m) dp[a[i]][b[i]]=c[i];
	rep(i,0,m) dp[b[i]][a[i]]=c[i];

	rep(k,0,n+1){
		rep(i,0,n+1){
			rep(j,0,n+1){
				dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
			}
		}
	}

	sort(rr,rr+r);
	ll ans=100000000;
	ll x=0;
	while(next_permutation(rr,rr+r)){
		rep(i,1,r)x+=dp[rr[i]][rr[i-1]];
		ans=min(ans,x);
		x=0;
	}
	cout<<ans;
}

Measured memory_bytes: 1152
#include<iostream>
using namespace std;
int dp[5<<17],bt,m,n,x;
main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>x;
		if(bt==-1)
		{
			cout<<"No"<<endl;
		}
		else if(x>500000)
		{
			m=500001;
			cout<<"Yes"<<endl;
		}
		else if(bt>x)
		{
			cout<<"No"<<endl;
		}
		else if(bt==x)
		{
			if(m>x)cout<<"No"<<endl;
			else
			{
				cout<<"Yes"<<endl;
				bt=-1;
			}
		}
		else
		{
			cout<<"Yes"<<endl;
			dp[x]++;
			if(m<x)m=x;
			while(dp[x]==2)
			{
				dp[x]=0;
				if(m==x)m--;
				dp[--x]++;
			}
			while(dp[bt+1])bt++;
		}
	}
}



Measured memory_bytes: 5036
n = gets.to_i
a = n.times.map {gets.to_i}

x = [1 << 31]

a.each do |b|
    i = x.bsearch_index {|e| e >= b}
    if i.nil? 
        x[-1] = b
    elsif i == 0
        x.unshift(b)
    else
        x[i-1] = b
    end
end

puts x.size - 1

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

int dfs(vector<vector<int>> &used, int H, int &nH, int w){
    
    if(used.at(nH).at(w) == -1 && nH < H){
        int tmp = nH + 1;
        used.at(nH).at(w) = dfs(used, H, tmp, w);
        return used.at(nH).at(w);
    }
    else{
        return used.at(nH).at(w);
    }

}

int rdfs(vector<vector<int>> &used, int H, int &nH, int w){
    
    if(used.at(nH).at(w) == -1 && nH > 1){
        int tmp = nH - 1;
        used.at(nH).at(w) = rdfs(used, H, tmp, w);
        return used.at(nH).at(w);
    }
    else{
        return used.at(nH).at(w);
    }

}

int main() {
    int H, W; cin >> H >> W;
    ll K; cin >> K;

    vector<vector<char>> s(H+2, vector<char>(W+2, '#'));
    vector<vector<int>> used(H+2, vector<int>(W+2, -1));
    int cnt = 1;
    rep(i, H){
        rep(j, W){
            cin >> s.at(i+1).at(j+1);
            if(s.at(i+1).at(j+1) == '#'){
                used.at(i+1).at(j+1) = cnt;
                cnt++;
            }
        }
    }

    for(int i=1; i<H+1; i++){
        int c = 0;
        for(int j=1; j<W+1; j++){
            if(s.at(i).at(j) == '#'){
                if(c==0){
                    c++;
                    for(int k=1; k<W+1; k++){
                        if(k==j) continue;
                        if(used.at(i).at(k) == -1){
                            used.at(i).at(k) = used.at(i).at(j);
                        }
                        else break;
                    }
                }
                else{
                    for(int k=j+1; k<W+1; k++){
                        if(used.at(i).at(k) == -1){
                            used.at(i).at(k) = used.at(i).at(j);
                        }
                        else break;
                    }
                }
            }
        }
    }

#if 1
    for(int i=1; i<H+1; i++){
        for(int j=1; j<W+1; j++){
            if(i==H){
                if(used.at(i).at(j) == -1){
                    int ni = i-1;
                    used.at(i).at(j) = rdfs(used, H, ni, j);
                }
            }
            else if(used.at(i).at(j) == -1){
                int ni = i+1;
                used.at(i).at(j) = dfs(used, H, ni, j);
            } 
        }
    }
#endif

    for(int i=1; i<H+1; i++){
        for(int j=1; j<W+1; j++){
            cout << used.at(i).at(j);
            if(j!=W) cout << " ";
        }
        cout << endl;
    }

}


Measured memory_bytes: 1280
#include <iostream>
#include <ostream>
#include <tuple>
#include <cassert>
#include <vector>
#include <algorithm>

using ll = long long;

using namespace std;

template<class T>
ostream& operator<<(ostream& os, const vector<T>& vs) {
    if (vs.empty()) return os << "[]";
    os << "[";
    bool fst = true;
    for (auto&& v : vs) {
        if (fst) fst = false;
        else os << ",";
        os << v;
    }
    return os << "]";
}

vector<ll> divisors(ll x) {
    vector<ll> div;
    ll n = 1;
    for (; n * n < x; n++) {
        if (x % n == 0) {
            div.emplace_back(n);
            div.emplace_back(x/n);
        }
    }
    if (x % n == 0) div.emplace_back(n);
    return div;
}

namespace {
    ll B;
    bool input() {
        cin >> B;
        if (B == 0) return false;
        return true;
    }

    void solve() {
        auto div = divisors(2LL * B);
        auto calc_s = [&](ll L) {
            ll double_s = 2LL * B / L - (L - 1LL);
            if (double_s % 2LL == 1LL) return -1LL;
            return double_s / 2LL;
        };
        reverse(div.begin(), div.end());
        auto ans_s = -1LL;
        auto ans_l = -1LL;
        for (auto d : div) {
            auto s = calc_s(d);
            if (s <= 0) continue;
            ans_s = s;
            ans_l = d;
            break;
        }
        cout << ans_s << ' ' << ans_l << endl;
    }
}

int main() {
    while (input()) {
        solve();
    }
    return 0;
}



Measured memory_bytes: 3052
#include <bits/stdc++.h>
#define ll long long int
using namespace std;

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

    if(s[2] == s[3]){
        if(s[4] == s[5]){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
int main(){
  using namespace std;
  string S;
  cin >> S;
  sort(S.begin(), S.end());
  if(S[0]==S[1] && S[1]!=S[2] && S[2]==S[3]){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

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

int main() {
  int64_t K, N;
  cin >> K >> N;

  vector<int64_t> A(N);
  for (int64_t i = 0; i < N; i++) {
    cin >> A[i];
  }

  int64_t mx = K - (A[N - 1] - A[0]);
  for (int64_t i = 1; i < N; i++) {
    int64_t d = A[i] - A[i - 1];
    mx = max(d, mx);
  }

  cout << K - mx << endl;

  return 0;
}


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

typedef long long ll;

const long long MOD = 1000000007;
long long modpow(long long a, long long n, long long m)
{
    long long ans = 1;
    while (n)
    {
        if (n & 1)
        {
            ans = (ans * a) % m;
        }
        a = (a * a) % m;
        n >>= 1;
    }
    return ans;
}
long long acombi(long long n, long long a)
{
    long long ans = 1, ans1 = 1;
    for (long long i = n - a + 1; i <= n; i++)
    {
        ans *= i % MOD;
        ans %= MOD;
    }

    for (long long i = 2; i <= a; i++)
        ans1 = (ans1 * i) % MOD;
    ans1 = modpow(ans1, MOD - 2, MOD);
    return ((ans % MOD) * ans1) % MOD;
}

void dfs(string s, char mx, ll N)
{
    if (s.length() == N)
    {
        cout << s.c_str() << endl;
    }
    else
    {
        for (char c = 'a'; c <= mx; c++)
        {
            dfs(s + c, ((c == mx) ? (char)(mx + 1) : mx), N);
        }
    }
}

int bfs(int a, int b, int h, int w, char tmp[][101])
{
    int ans[101][101] = {0};
    char c[101][101] = {0};
    queue<pair<int, int>> s;

    for (int i = 0; i<=h; i++){
        for(int j=0; j<=w; j++){
            c[i][j] = tmp[i][j];
        }
    }

    s.push(make_pair(a, b));

    while (s.size() > 0)
    {

        pair<int, int> tmp = s.front();
        s.pop();
        c[tmp.first][tmp.second] = '#';
        for (int i = -1; i <= 1; i++)
        {
            for (int j = -1; j <= 1; j++)
            {
                if (tmp.first + i < 1 || tmp.first + i > h)
                {
                    continue;
                }
                if (tmp.second + j < 1 || tmp.second + j > w)
                {
                    continue;
                }
                if (i != 0 && j != 0)
                {
                    continue;
                }
                if (i == 0 && j == 0)
                {
                    continue;
                }
                if (c[tmp.first + i][tmp.second + j] == '#')
                {
                    continue;
                }
                c[tmp.first + i][tmp.second + j] = '#';
                if (ans[tmp.first + i][tmp.second + j] == 0)
                {
                    ans[tmp.first + i][tmp.second + j] = ans[tmp.first][tmp.second] + 1;
                }
                else
                {
                    ans[tmp.first + i][tmp.second + j] = min(ans[tmp.first + i][tmp.second + j], ans[tmp.first][tmp.second] + 1);
                }
                s.push(make_pair(tmp.first + i, tmp.second + j));
            }
        }
    }

    int asd = 0;

    for (int i = 1; i <= h; i++)
    {
        for (int j = 1; j <= w; j++)
        {
            asd = max(a, ans[i][j]);
        }
    }

    return asd;
}

long long combi(long long n, long long k) {
  if (n == k || k == 0)
    return 1;
  else {
    return combi(n - 1, k - 1) + combi(n - 1, k);
  }
}

int main()
{
    double L;
    cin >> L;

    cout << setprecision(10) << (L / 3.0) * (L / 3.0) * (L / 3.0) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,m,a[52][52];
char s[52][52];
int di[]={1,1,1,0,0,-1,-1,-1};
int dj[]={0,1,-1,-1,1,0,-1,1};
int main()
{
    cin >>n>>m;
    for (int i=0;i<=n+1;i++)
    {
        for (int j=0;j<=m+1;j++)
            s[i][j]='.';
    }
    for (int i=1;i<=n;i++)
    {
        for (int j=1;j<=m;j++)
            cin >>s[i][j];
    }
    for (int i=1;i<=n;i++)
    {
        for (int j=1;j<=m;j++)
        {
            if (s[i][j]=='#')
            {
                cout <<s[i][j];
                continue;
            }
            for (int q=0;q<8;q++)
            {
                a[i][j]+= (s[i+di[q]][j+dj[q]]=='#');
            }
            cout <<a[i][j];
        }
        cout <<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>

using namespace std;

int main(){
  int a[31];
  memset(a, 0, sizeof(a));
  for(int i=0;i<28;i++){
    int idx; cin >> idx;
    a[idx] = 1;
  }
  for(int i=1;i<=30;i++)
    if(!a[i]) cout << i << endl;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,m,n) for (int i = m; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << "\n"; }
template <class T, class... Args>
void debug_out(const T &x, const Args &... args) { cout << x << " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

struct LowestCommonAncestor {
  private:
    vector<vector<int> > par;
    vector<int> dist; //from root
    const vector<vector<int> > &G;
    const int root;
    void dfs_(int v, int p, int d) {
      par[0][v] = p;
      dist[v] = d;
      for (auto to : G[v]) {
        if (to != p) dfs_(to, v, d+1);
      }
    }
    int query(int u,int v) {
      assert(u < (int)dist.size());
      assert(v < (int)dist.size());
      if (dist[u] > dist[v]) swap(u,v);
      int k = par.size();
      for (int i=0; i<k; ++i) { //LCAまでの距離を揃える
        if (((dist[v]-dist[u])>>i) & 1) v = par[i][v];
      }
      if (u==v) return u;
      for (int i = k-1; i>=0; --i) {
        if (par[i][u] == par[i][v]) continue;
        u = par[i][u];
        v = par[i][v];
      }
      return par[0][u];
    }
  public:
    LowestCommonAncestor(const vector<vector<int> > &G,int root=0):
    G(G),root(root){
      int n=G.size(), k=1;
      while ((1<<k) < n) k++;
      par.assign(k, vector<int>(n,-1));
      dist.assign(n,-1);
      dfs_(root,-1,0);
      for (int i=0; i<k-1; ++i) {
        for (int v=0; v<n; ++v) {
          if (par[i][v] < 0) par[i+1][v] = -1;
          else par[i+1][v] = par[i][par[i][v]];
        }
      }
    };
    int operator()(int u,int v) { return query(u,v);}
    int get_dist(int u, int v){ return dist[u]+dist[v]-2*dist[query(u,v)];}
    bool is_on_path(int u, int v, int a){ return get_dist(u,a)+get_dist(a,v)==get_dist(u,v);}
};

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int n, u, v;
  cin >> n >> u >> v; u--; v--;
  vector<vector<int> > G(n);
  rep(i,n-1) {
    int a, b;
    cin >> a >> b; a--; b--;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
  }
  LowestCommonAncestor LCA(G);
  int ans = 0;
  rep(i,n) {
    if (LCA.get_dist(u,i) < LCA.get_dist(v,i)) chmax(ans, LCA.get_dist(v,i)-1);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 21048
#include <iostream>

using namespace std;

int main() {
    int n,i,j,k,q;
    cin>>n>>k>>q;
    int a[q],s[n+1];
    for(i=1;i<=n;i++) s[i] = k-q;
    for(i=0;i<q;i++) {
        cin>>j;
        s[j]++;
    }

    for(i=1;i<=n;i++) {
        if(s[i]>0) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
typedef long long LL;
const LL MOD = 998244353;
const int N = 2e5;
LL dp[N+1];
LL PST[N+1];
LL sum(int i, int j)
{
    if(j <= 0)
        return 0;
    if(i <= 0)
        return PST[j];
    else
        return (PST[j]-PST[i-1])%MOD;
}
const int K = 10;
int L[K];
int R[K];
int main()
{
    dp[0] = PST[0] = 0;
    dp[1] = PST[1] = 1;

    int n, k; cin >> n >> k;
    for(int i = 0; i < k; i++)
        cin >> L[i] >> R[i];

    for(int s = 2; s <= n; s++)
    {
        dp[s] = 0;
        for(int i = 0; i < k; i++)
            dp[s] += sum(s-R[i],s-L[i]);
        dp[s] %= MOD;
        PST[s] = (PST[s-1]+dp[s])%MOD;
    }
    cout<<(dp[n]+MOD)%MOD<<endl;
    return 0;
}

Measured memory_bytes: 6768
#include <vector>
#include <algorithm>
#include <bits/stdc++.h>

using namespace std;
using ll =long long;
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
static const ll INF = 1LL << 60;
//Write From this Line

#define MAX_V 10000
vector<int> graph[MAX_V];
bool used_v[MAX_V],used_e[MAX_V][MAX_V];
int ord[MAX_V],lowlink[MAX_V];
int k=0;
void dfs(int v)
{
	used_v[v]=true;
	ord[v]=lowlink[v]=k++;
	for(int i=0;i<graph[v].size();i++){
		if(!used_v[graph[v][i]])
		{
			used_e[v][graph[v][i]]=true;
			dfs(graph[v][i]);
			lowlink[v]=min(lowlink[v],lowlink[graph[v][i]]);
		}
		else if(!used_e[graph[v][i]][v])
			//then,e(v,graph[v][i]) is backward edge
		{
			lowlink[v]=min(lowlink[v],ord[graph[v][i]]);
		}
	}
	return;
}
int main(){
	int n,m;
	cin >> n >>m;
	vector<int> A(m),B(m);
	rep(i,m){
		int a,b;
		cin >> a >>b;
		--a, --b;
		A[i] = a, B[i] = b;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}
	dfs(0);
	ll ans = 0 ;
	rep(i,m){
		if(ord[A[i]] < lowlink[B[i]]) ans ++;
		if(ord[B[i]] < lowlink[A[i]]) ans ++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

void AGC029A()
{
	string S;
	cin >> S;
	int N = S.size();

	ll ct = 0;
	ll ctB = 0;
	for (int i = 0; i < N; ++i)
	{
		if (S[i] == 'B')
			++ctB;
		else
		{
			ct += ctB;
		}
	}
	cout << ct << endl;
}
int main()
{
	AGC029A();
	return 0;
}

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

int i=0;
void co(int a){
  if(a==4){
    cout<<i+4<<endl;
  }else if(a%2==0){
    i++;
    co(a/2);
  }else{
    i++;
    co(a*3+1);
  }
}
    

int main(){
  int s;
  cin>>s;
  if(s==1||s==2){
    cout<<4<<endl;
  }else{
    co(s);
  }
  
}

Measured memory_bytes: 256
function main(input) {
  input=input.trim()
  var s = parseInt(input.split(" ")[0], 10);
const arr = input.split('\n').map((n) => parseInt(n, 10));
arr.shift();
var sum = function(arr){
  var sum = 0;
  for(var i=0; i<arr.length; i++){
    sum += arr[i];
  };
  return sum;
};
var max=Math.max.apply(null, arr)
console.log(sum(arr)-max/2);


}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
import sys
input = sys.stdin.readline
from collections import *

X = int(input())
dp = [False]*(X+1)
dp[0] = True

for i in range(X+1):
    for j in range(100, 106):
        if i-j>=0:
            dp[i] |= dp[i-j]

if dp[X]:
    print(1)
else:
    print(0)

Measured memory_bytes: 41452
#include<iostream>
#include<cmath>

using namespace std;
int main(){
    int n;
    cin >> n;
    int a[n+1],b[n+1],x[n+1];
    
    for(int i=0;i<n+1;i++){
        a[i]=1;
        b[i]=0;
        x[i]=0;
    }
    int an,bn,xn,q;
    cin >> an;
    for(int i=0;i<an;i++){
        cin >> q;
        a[q]=0;
    }
    cin >> bn;
    for(int i=0;i<bn;i++){
        cin >> q;
        b[q]=1;
    }
    cin >> xn;
    for(int i=0;i<xn;i++){
        cin >> q;
        x[q]=1;
    }
    int cnt=0;
    for(int i=1;i<n+1;i++){
        if(a[i]==1||b[i]==1){
            if(x[i]==1){
                cnt++;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3096
#include <iostream>
#include <iomanip>
#include <climits>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <unordered_map>
#include <random>
#define _USE_MATH_DEFINES
#include <math.h>
#include <complex>

using namespace std;

#define INF (int)1e8
#define _INF (int)-1e8  
#define INFLL (long long)1e15
#define _INFLL (long long)-1e15
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> P;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

/*******************************************************/

int main() {
  ll x, y; cin >> x >> y;
  if (x % y == 0) cout << -1 << endl;
  else cout << x << endl;
  return 0;
}

Measured memory_bytes: 256
x = int(input())

c_500 = 0
c_5 = 0
while True:
    temp = x - 500
    if temp < 0:
        break
    else:
        c_500 += 1
        x = temp

while True:
    temp = x - 5
    if temp < 0:
        break
    else:
        c_5 += 1
        x = temp

print(c_500 * 2 * 500 + c_5 * 5)


Measured memory_bytes: 9040
n=int(input())
s=input()
moji=[0]*26
for i in range(n):
    moji[ord(s[i])-97]+=1
ans=0
for rightcut in range(n):
    k=0
    temp=moji[:]
    for i in range(rightcut):
        if temp[ord(s[i])-97]>0:
            temp[ord(s[i])-97]-=1
    for j in range(26):
        k+=1 if (temp[j]!=0 and temp[j]!=moji[j] ) else 0
    ans = k if k>ans else ans
print(ans)
  

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
using matrix = vector<vector<uint>>;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;

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

    int K;
    cin >> K;
    ll ans = 0;
    for (int i = 1; i <= K; ++i) {
        for (int j = 1; j <= K; ++j) {
            for (int k = 1; k <= K; ++k) {
                ans += gcd(gcd(i, j), k);
            }
        }
    }

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


Measured memory_bytes: 3692
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int c, n; cin >> c >> n;
	int mid = n / 2;
	int m = (mid + 63) / 64;
	vector<vector<ll>> upper(n, vector<ll>(m)), right(n, vector<ll>(m));
	vector<vector<ll>> lower(n, vector<ll>(m)), left(n, vector<ll>(m));
	
	auto flip = [&](int y, int x){
		if(y < mid) upper[x][y / 64] ^= 1ull << y % 64;
		else{
			int Y = n - 1 - y;
			lower[x][Y / 64] ^= 1ull << Y % 64;
		}
		if(x < mid) left[y][x / 64] ^= 1ull << x % 64;
		else{
			int X = n - 1 - x;
			right[y][X / 64] ^= 1ull << X % 64;
		}
	};
	auto check = [&](){
		return upper == lower && right == left;
	};
	
	rep(i, n){
		string s; cin >> s;
		rep(j, n) if(s[j] == '1') flip(i, j);
	}
	
	int ans = check();
	while(--c){
		int q; cin >> q;
		while(q--){
			int y, x; cin >> y >> x;
			flip(y - 1, x - 1);
		}
		if(check()) ans++;
	}
	cout << ans << endl;
	return 0;
}


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

void solve(long long X, long long Y){
    cout << X + Y / 2 << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long X;
    scanf("%lld",&X);
    long long Y;
    scanf("%lld",&Y);
    solve(X, Y);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long int a,b,s=0,s1=0,v,w,t;
    cin>>a>>v;
    cin>>b>>w;
    cin>>t;
    
    if((v-w)*t>= abs(a-b))
        cout<<"YES";
    else
        cout<<"NO";
}

Measured memory_bytes: 3636
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    for i in range(2*N+1):
        if int(i*1.08)==N:
            print(i)
            exit()
    print(":(")
if __name__ == '__main__':
    main()

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

int main()
{
    int D, G;
    cin >> D >> G;
    vector<int> p(D), c(D);
    for(int i=0;i<D;i++){
        cin >> p[i] >> c[i];
    }
    int res = numeric_limits<int>::max();
    for(unsigned int bit=0; bit < (1<<D); bit++){
        int num = 0;
        int score = G;
        for(int i=0; i<D; i++){
            if(bit & (1<<i)){
                auto s = 100 * (i+1);
                score -= c[i];
                score -= p[i] * s;
                num += p[i];
            }
        }
        if(score <= 0){
            res = min(res, num);
            continue;
        }
        for(int i=D-1; i>=0; i--){
            if(bit & (1<<i)) continue;
            auto s = 100 * (i+1);
            if(p[i] * s >= score){
                auto m = (score + s - 1) / s;
                score -= m * s;
                num += m;
                break;
            }else{
                score -= p[i] * s;
                num += p[i];
            }
        }
        if(score <= 0){
            res = min(res, num);
        }
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoderBeginnerContest117Third
{
    class Program
    {
        static void Main(string[] args)
        {
            // 整数の入力
            //int N = int.Parse(Console.ReadLine());
            // スペース区切りの整数の入力
            string[] input1 = Console.ReadLine().Split(' ');
            int N = int.Parse(input1[0]);
            int M = int.Parse(input1[1]);
            if (N >= M) // コマの数が座標数より多いなら終わり
            {
                Console.WriteLine("0");
                return;
            }
            int[] X = new int[M];
            int[] width = new int[M - 1];
            string[] input2 = Console.ReadLine().Split(' ');
            for (var i = 0; i < M; i++)
            {
                X[i] = int.Parse(input2[i]);
            }
            Array.Sort(X);
            for (var i = 0; i < M-1; i++)
            {
                width[i] = X[i + 1] - X[i];
            }
            Array.Sort(width);
            Array.Reverse(width);
            //
            long ans=width.Sum();
            for(var i = 0; i < N-1; i++)
            {
                ans -= width[i];
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 17504
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <cmath>
#include <stdio.h>
#include <sstream>
#define int_inf 1000000000 //1e9
#define ll_inf  1000000000000000000 //1e18
using namespace std;
template <typename T> std::string to_string(const T& t){
	std::ostringstream os; os<<t; return os.str();
}
int n;
long long solve(int i);
long long solve1(int i, int time);
vector<int> c, s, f;

int main(){
	cin >> n;
	c.resize(n-1); s.resize(n-1); f.resize(n-1);
	for(int i=0; i<n-1; i++){
		cin >> c[i] >> s[i] >> f[i];
	}
	
	for(int i=0; i<n; i++){
		cout << solve(i) << endl;
	}
	return 0;
}

long long solve1(int from, int time){//i->i+1
	if(from==n-1) return 0;
	else if(s[from]>=time){
		return s[from]+c[from];
	}
	else if(time%f[from]==0){
		return c[from];
	}
	int k=(time+f[from])/f[from];
	return f[from]*k + c[from];
}

long long solve(int from){//i->n
	long long time=0;
	for(int i=from; i<n-1; i++){
		if(i==n-1) return 0;
		else if(s[i]>=time){
			time= s[i]+c[i];
		}
		else if(time%f[i]==0){
			time += c[i];
		}
		else{
			int k=(time+f[i])/f[i];
			time = f[i]*k + c[i];
		}
//cout << time << " ";
	}
	return time;
}


Measured memory_bytes: 256