akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
using ll = long long;

class UnionFind{
    public:
        UnionFind(){
            UnionFind(0);
        }
        UnionFind(int N){
            par.resize(N);
            rnk.resize(N);
            for(int i=0;i<N;i++){
                par[i] = i;
                rnk[i] = 0;
            }
        }

        int root(int x){
            return par[x] = par[x] == x ? x : root(par[x]);
        }

        bool same(int x, int y){
            return root(x) == root(y);
        }

        void unite(int x, int y){
            x = root(x); y = root(y);
            if(x == y) return;

            if(rnk[x] < rnk[y]){
                par[x] = y;
            }else{
                par[y] = x;
                if(rnk[x] == rnk[y]){
                    rnk[x]++;
                }
            }
        }
    private:
        vector<int> par, rnk;
};

struct town{
    ll x,y,id;
    town(){};
    town(int x,int y, int id) : x(x), y(y), id(id){};
};

struct edge{
    ll from, to, cost;
    edge(){};
    edge(int f, int t, int c) : from(f), to(t), cost(c){};
    bool operator<(const edge &e) const {
        return cost < e.cost;
    }
};

bool comp_x(const town &a, const town &b){
    return a.x < b.x;
}
bool comp_y(const town &a, const town &b){
    return a.y < b.y;
}

int main(){
    int N; cin >> N;
    vector<town> ts(N);
    for(int i=0;i<N;i++){
        int x,y; cin >> x >> y;
        ts[i] = town(x,y,i);
    }

    vector<edge> es;
    sort(ts.begin(), ts.end(), comp_x);
    for(int i=0;i<N-1;i++){
        es.push_back(edge(ts[i].id, ts[i+1].id, abs(ts[i].x-ts[i+1].x)));
    }
    sort(ts.begin(), ts.end(), comp_y);
    for(int i=0;i<N-1;i++){
        es.push_back(edge(ts[i].id, ts[i+1].id, abs(ts[i].y-ts[i+1].y)));
    }

    sort(es.begin(), es.end());
    ll ans = 0ll;
    UnionFind uf = UnionFind(N);

    for(auto e : es){
        if(!uf.same(e.from, e.to)){
            uf.unite(e.from, e.to);
            ans += e.cost;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 10608
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N; cin >> N;
  int c = 0;
  int num = 1;
  for(int i = 0; i < N; i++){
    int t; cin >> t;
    if(t == num){
      num++;
    }else{
      c++;
    }
  }
  cout << (c == N ? -1 : c) << endl;
}


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

int main() {
  int A, B;
  cin >> A >> B;
  if (A <= 5) cout << 0 << endl;
  else if (A <= 12) cout << B / 2 << endl;
  else cout << B << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define int long long
  #define endl "\n"
  #define all(v) v.begin(),v.end()
  #define double long double
  #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 cases int testcases;cin>>testcases; while(testcases--)
  const int N = 200005;


int32_t main()
{

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    IOS
    int x;
    cin>>x;
    if(x>=30)
        cout<<"Yes \n";
    else
        cout<<"No \n";
    return 0;
}

Measured memory_bytes: 3652
import itertools

n,m = map(int, input().split())

line = [[0 for i in range(n)] for j in range(n)]

for i in range(m):
    a,b = map(int, input().split())
    line[a-1][b-1] = 1
    line[b-1][a-1] = 1

ans = 0

p = [i for i in range(1, n)]

for x in itertools.permutations(p):
    x = list(x)
    x.insert(0,0)
    for i in range(n-1):
        if not line[x[i]][x[i+1]]:
            break
        if i == n-2:
            ans += 1

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int inf = 6e18;
const int mod = 1e9 + 7;

signed main() {
    int N;
    cin >> N;
    vector<pair<int, int>> arm(N);
    for(int i = 0; i < N; i++) cin >> arm[i].first >> arm[i].second;
    for (int i = 0; i < N; i++) {
        int temp = arm[i].first;
        arm[i].first = temp - arm[i].second ;
        arm[i].second = temp + arm[i].second;
    }
    auto sorting = [&](pair<int, int> a, pair<int, int> b) {
        return a.second < b.second;
    };
    sort(arm.begin(), arm.end(), sorting);
    int ans = 0;
    int before = -inf;
    for (int i = 0; i < N; i++) {
        if (arm[i].first >= before) {
            ++ans;
            before = arm[i].second;
        }
    }
    cout << ans << endl;
}


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

int main(void)
{
  int n;
  cin >> n;
  bool can = false;
  for(int i = 1; i <= 9; i++)
  {
    for(int j = 1; j <= 9; j++)
    {
      if(n == i * j)
      {
        can = true;
        break;
      }
    }
  }
  if(can)
  {
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;  
  }
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)
	var n int64
	n = int64(len(s))
	var a [26]int64
	for i := int64(0); i < n; i++ {
		a[s[i]-'a']++
	}
	ans := n * (n - 1) / 2
	ans ++
	for i := 0; i < 26; i++ {
		ans -= a[i] * (a[i] - 1) / 2
	}
	fmt.Println(ans)
}


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

using ll = long long;
using Pl = pair<ll, ll>;

ll N, X, D;
map<ll, vector<Pl>> mp;
ll offset = 1ll << 61;
int main() {
    cin >> N >> X >> D;
    if (D < 0) X = -X, D = -D;
    if (D == 0) {
        if (X != 0) cout << N + 1 << endl;
        else cout << 1 << endl;
        return (0);
    }
    for (ll i = 0; i <= N; i++) {
        ll left  = i*X + D*i*(i-1)/2;
        ll right = i*(X+(N-i)*D) + D*i*(i-1)/2;
        mp[(left%D+D)%D].emplace_back((left+offset)/D, 1);
        mp[(left%D+D)%D].emplace_back((right+offset)/D + 1, -1);
    }
    ll sum = 0;
    for (auto &m : mp) {
        auto &v = m.second;
        sort(begin(v), end(v));
        ll cnt = 0;
        ll i = 0;
        while (i < v.size()) {
            ll pos = v[i].first;
            if (i > 0 && cnt > 0) sum += pos - v[i - 1].first;
            while (pos == v[i].first) cnt += v[i].second, i++;
        }
    }
    cout << sum << endl;
    return (0);
}

Measured memory_bytes: 25216
#include <bits/stdc++.h>
#define rep(i,n)    for(long long i = 0; i < (n) ; ++i)
#define orep(i,n)   for(long long i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(long long i = (n)-1; i >= 0; --i) // down rep
#define srep(i,s,t) for(long long i = (s); i < (t); ++i)  // set rep
#define rng(x)  (x).begin(),(x).end()

  // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)


using namespace std;
using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vl  = vector<ll>;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

template<typename T> void pv2(vector<vector<T>> vec) {
  for(auto& v : vec) pv(v);
}


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

  ll ans = 0;
  orep(i,n-1) {
    ans += (n-1) / i;
  }
  cout << ans << endl;

  return 0;
}


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

using namespace std;
#define INF (1<<28)
#define DEKAI 1000000007
#define lp(i,n) for(int i=0;i<n;i++)
#define int long long
pair<int,int> check[100001];
int a[100001];
int ans,n;

signed main(){
  cin>>n;
  lp(i,n) cin>>a[i];
  int logs=1;
  lp(z,n){
    if(check[z].second!=0) continue;
    int now=z;
    int cnt=1;
    while(1){
      if(check[now].second!=logs&&check[now].second!=0) break;
      if(check[now].second==logs){
        ans+=cnt-check[now].first;
        break;
      }
      check[now]={cnt,logs};
      now=(now+a[now])%n;
      cnt++;
    }
    logs++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 5444
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#define ll long long
using namespace std;
int a,b,c,n,o;
int maxx,minn=10000;
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&o);
		maxx=max(maxx,o);
		minn=min(minn,o);
	}
	printf("%d",maxx-minn);
}

Measured memory_bytes: 256
#include <cstdlib>
#include <iostream>
#include <typeinfo>
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
  int n, y;
  cin >> n >> y;
  int a = -1, b = -1, c = -1;
  for (int i = 0; i <= n; i++)
  {
    for (int j = 0; j <= n; j++)
    {
      int k = n - i - j;
      if (k < 0)
        break;
      int total = 10000 * i + 5000 * j + 1000 * k;
      if(total==y){
        a = i;
        b = j;
        c = k;
      }
    }
  }
  cout << a << " " << b << " " << c << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <stdio.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <random>

using namespace std;

static const double EPS = 1e-9;
template<class T> bool INRANGE(T x,T a,T b){return a<=x&&x<=b;}
template<class T> void amin(T &a,T v){if(a>v) a=v;}
template<class T> void amax(T &a,T v){if(a<v) a=v;}
int ROUND(double x) { return (int)(x+0.5); }
bool ISINT(double x) { return fabs(ROUND(x)-x)<=EPS; }
bool ISEQUAL(double x,double y) { return fabs(x-y)<=EPS*max(1.0,max(fabs(x),fabs(y))); }
double SQSUM(double x,double y) { return x*x+y*y; }
#define PI  (acos(-1))
#define ARRAY_NUM(a) (sizeof(a)/sizeof(a[0])) 
#define NG (-1)
#define BIG ((int)1e9)
#define BIGLL ((ll)4e18)
#define SZ(a) ((int)(a).size())
#define SQ(a) ((a)*(a))
typedef unsigned long long ull;
typedef long long ll;


int main()
{
	int N;
	cin >> N;
	vector <int> a(N);
	for (int i = 0; i < N; ++i)
	{
		cin >> a[i];
	}

	int bestDist = BIG;

	for (int y=-100;y<=100;++y)
	{
		int dist = 0;
		for (int x : a)
		{
			dist += SQ(x - y);
		}

		amin(bestDist, dist);
	}

	cout << bestDist << endl;

	return 0;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=list(str(x) for x in input())

ans=0
for i in range(n):
    if i < k or (i >= k and t[i]!=t[i-k]):
        if t[i]=='r':
            ans += p
        elif t[i]=='s':
            ans += r
        else:
            ans += s
    else:
        t[i]='e'
print(ans)

Measured memory_bytes: 4212
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
#define MOD 1000000007
using ll = long long;
using namespace std;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n,a,b;
cin>>n>>a>>b;
cout<<min(n*a,b)<<endl;
//system("pause");
return 0;
}

Measured memory_bytes: 256
s = input()
flag = True
if s[0] == "A":
  s2 = s[2:-1]
  if s2.count('C') == 1:
    for i in range(len(s)):
      if i == 0 or i == s.index('C'):
        continue
      else:
        if s[i].lower() != s[i]:
          flag = False
          break
  else:
    flag = False
else:
  flag = False

if flag:
  print('AC')
else:
  print('WA')

Measured memory_bytes: 3060
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>
#include <list>

using namespace std;

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

#define rep(i,x) for(Int i = 0; i < (Int)(x); i++)
#define rrep(i,x) for(Int i = ((Int)(x) - 1); i >= 0; i--)
#define _upgrade ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back

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

//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}

Int dx[4] = {1,0,-1,0};
Int dy[4] = {0,1,0,-1};
//const Int INF = 1001002003004005006ll;
const Int mod = 1e9 + 7;
const double PI = 3.14159265358979323846;


// ****************************************CODE***************************************//



int a[100010];

int main(){
        int n;
        cin >> n;
        for(int i = 0; i < n; i++) cin >> a[i];

        n = unique(a,a+n) - a;
        int cnt = 0;
        for(int i = 1; i+1 < n; i++)
        {
                if(a[i] > a[i-1] && a[i] > a[i+1]){
                        cnt++;
                        i++;
                }
                else if(a[i] < a[i-1] && a[i] < a[i+1]){
                        cnt++;
                        i++;
                }
        }

        cout << cnt + 1 << endl;
        return 0;
}













Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <map>

using namespace std;

map <string, int> f;

int main() {
    int n; cin >> n;
    for (int i = 0; i < n; i++) {
        string v; cin >> v;
        f[v]++;
    }
    cout << "AC x " << f["AC"] << "\n";
    cout << "WA x " << f["WA"] << "\n";
    cout << "TLE x " << f["TLE"] << "\n";
    cout << "RE x " << f["RE"] << "\n";
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
typedef double ld;

#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define MOD 1000000007
#define PI 3.14159265


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

    int arr[3];
    cin >> arr[0] >> arr[1] >> arr[2];
    string str = "012";
    int ans = INT_MAX;
    do {
        ans = min(ans , abs(arr[str[1] - 48] - arr[str[0] - 48]) + abs(arr[str[2] - 48] - arr[str[1] - 48]));
    }while(next_permutation(all(str)));
    cout << ans << endl;

    return 0;
}


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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    int a, b; cin >> a >> b;
    if(a%2 && b%2) cout << "Yes" << endl;
    else cout << "No" << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


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

using namespace std;

typedef long long LL;

vector<int>e[100010];
int N;
bool vis[100010];
int sg[100010];

int dfs(int x,int f)
{
	sg[x] = 0;
	for (auto t:e[x])
	if (t!=f)
		sg[x] ^= (dfs(t,x)+1);
	return sg[x];
}

int main()
{
	scanf("%d",&N);
	for (int i=1;i<N;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		e[x].push_back(y);
		e[y].push_back(x);
	}
	printf(dfs(1,0)?"Alice":"Bob");
}

Measured memory_bytes: 10752
use std::io;
use std::cmp;

/// https://beta.atcoder.jp/contests/abc047/tasks/abc047_b
fn main() {
    let (w, h, n) = {
        let i = read::<usize>();
        (i[0], i[1], i[2])
    };

    let mut vec = Vec::new();
    for _ in 0..n {
        let i = read::<usize>();
        vec.push((i[0], i[1], i[2]));
    }

    let mut x_max = w;
    let mut y_max = h;
    let mut x_min = 0;
    let mut y_min = 0;

    while let Some((x_k, y_k, a_k)) = vec.pop() {
        match a_k {
            1 => {
                x_min = cmp::max(x_min, x_k);
            },
            2 => {
                x_max = cmp::min(x_max, x_k);
            },
            3 => {
                y_min = cmp::max(y_min, y_k);
            },
            4 => {
                y_max = cmp::min(y_max, y_k);
            },
            _ => unreachable!(""),
        }
    }
    if x_max >= x_min && y_max >= y_min {
        println!("{}", (x_max - x_min) * (y_max - y_min));
    } else {
        println!("0");
    }
}

#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

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

int main() {
	int n,i,k;
	cin>>n;
	int a[n];
	for(i=0;i<n;i++)
	{
	 cin>>a[i];
	 if(i==0)
	 a[i]-=1;
	 else if(a[i]>a[i-1])
	 a[i]-=1;
	}
	k=1;
	for(i=1;i<n;i++)
	{
	    if(a[i]<a[i-1])
	    {
	    k=0;
	    break;
	    }
	}
	if(k==0)
	cout<<"No"<<endl;
	else
	cout<<"Yes"<<endl;
	return 0;
}

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

int main()
{
  int m,n;
  cin >> n >> m;
  int A[100][100]={0};
  int b[100]={0};

  for(int i=0;i<n;i++)
    {
      for(int j=0;j<m;j++)
	{
	  cin >> A[i][j];
	}
    }
  for(int i=0;i<m;i++)
    {
      cin >> b[i];
    }

  int c[100]={0};
 
  for(int i=0;i<n;i++)
    {
      
      for(int j=0;j<m;j++)
	{
	  c[i]+=A[i][j]*b[j];
	}
    }

  for(int i=0;i<n;i++)
    {
      cout << c[i] << endl;
    }

  return 0;
}
	

Measured memory_bytes: 1208
#include<cstdio>
#include<iostream>
#include<cmath>
#include<map>
#include<queue>

using namespace std;
#define N 4
#define N2 16

static const int dx[4] = {0, -1, 0, 1};
static const int dy[4] = {1, 0, -1, 0};
static const char dir[4] = {'r', 'u', 'l', 'd'};
int MDT[N2][N2];

struct Puzzle{
    int f[N2], space, MD;
    int cost;

    bool operator < (const Puzzle &p) const{
        for(int i=0; i<N2; i++){
            if(f[i] == p.f[i]) continue;
            return f[i] < p.f[i];
        }
        return false;
    }
};

struct State{
    Puzzle puzzle;
    int estimated;
    bool operator < (const State &s) const{
        return estimated > s.estimated;
    }
};

int getAllMD(Puzzle pz){
    int sum = 0;
    for(int i=0; i<N2; i++){
        if(pz.f[i] == N2) continue;
        sum += MDT[i][pz.f[i] - 1];
    }
    return sum;
}

int astar(Puzzle s){
    priority_queue<State> PQ;
    s.MD = getAllMD(s);
    s.cost = 0;
    map<Puzzle, bool> V;
    Puzzle u, v;
    State initial;
    initial.puzzle = s;
    initial.estimated = getAllMD(s);
    PQ.push(initial);

    while( !PQ.empty() ){
        State st = PQ.top(); PQ.pop();
        u = st.puzzle;

        if( u.MD == 0 ) return u.cost;
        V[u] = true;

        int sx = u.space / N;
        int sy = u.space % N;
        
        for(int r=0; r<4; r++){
            int tx = sx + dx[r];
            int ty = sy + dy[r];
            if( tx<0 || ty<0 || tx>=N || ty>=N ) continue;
            v = u;

            v.MD -= MDT[tx*N+ty][v.f[tx*N+ty] -1];
            v.MD += MDT[sx*N+sy][v.f[tx*N+ty] -1];

            swap(v.f[sx*N+sy], v.f[tx*N+ty]);
            v.space = tx*N + ty;
            if( !V[v] ){
                v.cost++;
                State news;
                news.puzzle = v;
                news.estimated = v.cost + v.MD;
                PQ.push(news);
            }
        }
    }
    return -1;
}

int main(){
    for(int i=0; i<N2; i++)
        for(int j=0; j<N2; j++)
            MDT[i][j] = abs(i/N - j/N) + abs(i%N - j%N);

    Puzzle in;

    for(int i=0; i<N2; i++){
        cin >> in.f[i];
        if(in.f[i] == 0){
            in.f[i] = N2;
            in.space = i;
        }
    }
    cout << astar(in) << endl;

    return 0;
}


Measured memory_bytes: 257592
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[][] c = new int[3][3];
        for(int i = 0; i < 3; i++){
            for(int j = 0; j < 3; j++){
                c[i][j] = sc.nextInt();
            }
        }

        boolean flag = false;
        if(c[0][0] - c[1][0] == c[0][1] - c[1][1] && c[0][1] - c[1][1] == c[0][2] - c[1][2] &&
           c[0][0] - c[2][0] == c[0][1] - c[2][1] && c[0][1] - c[2][1] == c[0][2] - c[2][2])
            flag = true;

        if(flag) System.out.println("Yes");
        else System.out.println("No");
          
    }
}

Measured memory_bytes: 21844
/*
 ============================================================================
 Name        : ARC_090_C.c
 Author      : 
 Version     :
 Copyright   : Your copyright notice
 Description : Hello World in C, Ansi-style
 ============================================================================
 */

#include <stdio.h>
#include <stdlib.h>

int candynum(int* candy1, int*candy2, int down, int N);

int max(int a, int b){
	return a >= b ? a : b;
}

int main(void) {
	int N;
	int i;
	int nedan_all= 0;

	scanf("%d", &N);
	int *A = (int *) malloc(sizeof(int) * N);


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


	nedan_all = abs(A[0])+ abs(A[N-1]);

	for(i = 1 ; i<N; i++){
		nedan_all = nedan_all +abs(A[i]- A[i-1]);
	}

	printf("%d\n", nedan_all-abs(A[0])- abs(A[1]- A[0])+ abs(A[1]));
	for(i = 1; i < N-1; i++){
		printf("%d\n", nedan_all - abs(A[i]-A[i-1] ) - abs(A[i+1]-A[i]) + abs(A[i+1]-A[i-1]));
	}
	printf("%d\n", nedan_all-abs(A[N-1])- abs(A[N-1]- A[N-2])+ abs(A[N-2]));

	return EXIT_SUCCESS;
}



Measured memory_bytes: 1536
n, m = gets.split.map &:to_i
ps = []
ss = []
 
m.times{
	p, s = gets.chomp.split
	ps << p.to_i
	ss << s
}
 
is_ac = Array.new(n + 1, false)
fault_count = Array.new(n + 1, 0)
 
ps.each_with_index{ |p,i|
	if ss[i] == "WA" then
		if ! is_ac[p] then
			fault_count[p] += 1
		end
	else
		is_ac[p] = true
	end
}
 
count = 0
sum = 0
 
is_ac.each_with_index{ |ac, i|
	if ac then
		count += 1
		sum += fault_count[i]
	end
}
 
puts [count, sum].join(" ")

Measured memory_bytes: 11900
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<cmath>
#include<iomanip>
#include<math.h>
#define rep(i, n) for(int i=0; i<n; i++)
using namespace std;
typedef long long ll;

int main(){
    int h1,h2,m1,m2,k; cin>>h1>>m1>>h2>>m2>>k;
    h2 -= k/60;
    m2 -= k%60;
    int ans = 60*(h2-h1)+m2-m1;
    cout << ans << endl;
}

Measured memory_bytes: 3596
//This Code was made by Chinese_zjc_.
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <bitset>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <set>
#include <time.h>
// #include<windows.h>
#define int long long
#define double long double
using namespace std;
const double PI = acos(-1);
const double eps = 0.0000000001;
const int INF = 0x3fffffffffffffff;
int floor_sum(int n, int m, int a, int b)
{
    int ans = 0;
    if (a >= m)
    {
        ans += (n - 1) * n * (a / m) / 2;
        a %= m;
    }
    if (b >= m)
    {
        ans += n * (b / m);
        b %= m;
    }

    int y_max = (a * n + b) / m, x_max = (y_max * m - b);
    if (y_max == 0)
        return ans;
    ans += (n - (x_max + a - 1) / a) * y_max;
    ans += floor_sum(y_max, a, m, (a - x_max % a) % a);
    return ans;
}
int T, N, M, A, B;
signed main()
{
    ios::sync_with_stdio(false);
    cin >> T;
    for (int i = 1; i <= T; ++i)
    {
        cin >> N >> M >> A >> B;
        cout << floor_sum(N, M, A, B) << endl;
    }
    return 0;
}

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

int main()
{
	int n, p, stone;
	while (cin >> n >> p, n || p) {
		vector<int> cit(n, 0);
		stone = p;
		for (int i = 0;; i++) {
			if (i == n)
				i = 0;
			if (stone) {
				stone--;
				cit[i]++;
				if (cit[i] == p) {
					cout << i << endl;
					break;
				}
			} else {
				stone = cit[i];
				cit[i] = 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1196
from sys import stdin


def main():
    _in = [_.rstrip() for _ in stdin.readlines()]
    S = _in[0]  # type:str
    T = _in[1]  # type:str
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    ans = float('inf')
    S_ = list(S)
    T_ = list(T)

    for i in range(len(S_)-len(T_)+1):
        s_ = S_[i:i+len(T_)]
        cnt = 0
        for a,b in zip(s_, T_):
            if a == b:
                pass
            else:
                cnt += 1
        ans = min(ans, cnt)
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 67680
p=print
r=range
c=0
def a(i,j,k,l=0):
	global c
	p("+<"[l],i,j,k)
	c = c + 1
def b(i):a(i,i,i+1)
def d(x,i):
	a(x,3,x)
	for t in r(i,i+30):
		b(p:=t+1)
		a(q:=p+1,3,q)
		[*map(b,r(q,i+31))]
		a(i+31,x,t,1)
		b(p)
		a(q,t,q)
p(3934)
a(0,1,3)
a(2,3,3,1)
d(0,9)
d(1,50)
for t in r(60):a(2,2,2);[t-31<s<30!=(a(8+t-s,50+s,5),a(3,5,6,1),a(2,6,2))for s in r(t)]

Measured memory_bytes: 9284
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)

struct INIT{
    INIT(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(0);
        cout << fixed << setprecision(13);
    }
}INIT;

int n;
string s;

int main(){
    cin >> n >> s;
    if(n % 2){
        cout << "No" << endl;
        return 0;
    }
    REP(i, n/2){
        if(s[i] != s[i + n/2]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
    }
    for (ll i = K; i < N; i++) {
        if(A[i-K] < A[i]){
            Yes();
        }
        else{
            No();
        }
    }

}

Measured memory_bytes: 4832
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
using namespace std;
typedef long long ll;
const ll INF = 1e15;
const ll MOD = 1e9 + 7;
int main() {
  ll n, m;
  cin >> n >> m;
  ll p;
  cin >> p;
  ll sx = 0, sy = 0;
  FOR(i, 1, n) {
    ll x;
    cin >> x;
    ll dx = (x - p) % MOD;
    ll xc = (i * (n - i)) % MOD;
    sx += (dx * xc) % MOD;
    sx %= MOD;
    p = x;
  }
  cin >> p;
  FOR(i, 1, m) {
    ll y;
    cin >> y;
    ll dy = (y - p) % MOD;
    ll yc = (i * (m - i)) % MOD;
    sy += (dy * yc) % MOD;
    sy %= MOD;
    p = y;
  }
  cout << (sx * sy) % MOD << endl;
  return 0;
}

Measured memory_bytes: 256
s = input()
chars = []
for i in range(97,123):
    chars.append(chr(i))

if( len(set(s)) == 1):
    print(0)
    exit()

ans = len(s)
for i in chars:
    tmp = s
    tmp_n = ''
    while(True):
        for j in range(len(tmp)-1):
            if((tmp[j] == i)|(tmp[j+1] == i)):
                tmp_n += i
            else:
                tmp_n += tmp[j]

        if( len(set(tmp_n)) == 1):
            ans = min(ans, len(s) - len(tmp_n))
            break

        tmp = tmp_n
        tmp_n = ''

print(ans)

Measured memory_bytes: 41836
#include <stdio.h>
#include <string.h>

int main() {
	char S[100000];
	scanf("%s",S);
	int n=strlen(S),cnt=0;
	for (int i = 0; i < n; i++) {
		if (S[i] == '0') cnt++;
	}
	int answer=((n-cnt) > cnt) ? cnt : (n-cnt);
	answer = 2*answer;
	printf("%d\n",answer);
	return 0;
}

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

int N, M, Q;
int mod = 1e9 + 7;

int main() {
    cin >> N >> M >> Q;
    vector<vector<int>> train(N, vector<int>(N)), ans(N, vector<int>(N));
    for (int i = 0; i < M; i++) {
        int l, r;
        cin >> l >> r;
        if (l == r) {
            ans[l - 1][r - 1]++;
        }
        train[l - 1][r - 1]++;
    }
    
    for (int s = 1; s < N; s++) {
        for (int l = 0; l + s < N; l++) {
            int r = l + s;
            ans[l][r] = ans[l + 1][r] + ans[l][r - 1] - ans[l + 1][r - 1]+ train[l][r];
        }
    }
    for (int i = 0; i < Q; i++) {
        int l, r;
        cin >> l >> r;
        cout << ans[l - 1][r - 1] << endl;
    }
}

Measured memory_bytes: 2944
#include<stdio.h>
int main()
{
	int num;
	scanf("%d", &num);
	int c = 0;
	for (int i = 0; i < num; i++)
	{
		int z;
		scanf("%d", &z);
		c ^= z;
	}
	printf((c & 1) ? "NO\n" : "YES\n");
}

Measured memory_bytes: 128
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<61);
const int inf=(1<<30);
const int nmax=1e5+50;
const int mod=1e9+7;
using namespace std;
int n,m,i;
ll a[nmax],c[nmax],v[nmax],ans=llinf;
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
    cin>>n>>m;
    for(i=1;i<=n;i++)cin>>a[i];
    for(i=1;i<n;i++)
	{
		if(a[i]<a[i+1])
		{
			c[1]+=a[i+1]-a[i];
			c[a[i]+1]-=(a[i+1]-a[i]);
			c[a[i+1]+1]+=a[i+1]-a[i];
			c[a[i]+1]+=a[i+1]+1;
			c[a[i+1]+1]-=(a[i+1]+1);
			v[a[i]+1]++;
			v[a[i+1]+1]--;
		}
		else
		{
			c[1]+=a[i+1]+1;
			c[a[i+1]+1]-=(a[i+1]+1);
			c[a[i+1]+1]+=m+a[i+1]-a[i];
			c[a[i]+1]-=(m+a[i+1]-a[i]);
			c[a[i]+1]+=m+1+a[i+1];
			v[1]++;
			v[a[i+1]+1]--;
			v[a[i]+1]++;
		}
	}
	for(i=1;i<=m;i++)
	{
		c[i]+=c[i-1];
		v[i]+=v[i-1];
		ans=min(ans,c[i]-v[i]*i);
	}
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 2560
fun main(args: Array<String> ) {
  val (N, K) = readLine()!!.split(" ").map { it.toInt() }
    val S = readLine()!!
    S.withIndex().map {
        if(it.index == K -1) {
            it.value.toLowerCase()
        } else {
            it.value
        }
    }.forEach { print(it) }
}

Measured memory_bytes: 36112
/***"In the name of Allah(swt), the most gracious, most merciful. Allah(swt) blesses with knowledge whom he wants."***/
/*** "ALHAMDULILLAH for Everything..." ***/
#include<bits/stdc++.h>
using namespace std;
#define  fastt       ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define  ll         long long
#define  debug      printf("Come here!")
#define  inf        1000000000000000000
#define  pb         push_back
#define  mp         make_pair
#define  sz(a)      a.size()
#define  mem(a,b)   memset(a,b,sizeof(a))
#define  clr(x)     x.clear()
#define  ff         first
#define  ss         second
#define  case(x)    cout << "Case " << x <<": "

#define  md         1000000007
#define  pi         acos(-1.0)
#define  cos(a)     cos(a*pi/180)
#define  sin(a)     sin(a*pi/180)
#define  tan(a)     tan(a*pi/180)
#define  cosi(a)    acos(a)/(pi/180)
#define  sini(a)    asin(a)/(pi/180)
#define  tani(a)    atan(a)/(pi/180)

#define  vl         vector <ll>
#define  vs         vector <string>
#define  vc         vector <char>
#define  vpll       vector < pair <ll, ll> >
#define  vpsl       vector < pair <string, ll> >
#define  vpls       vector < pair <ll, string> >
#define  pql        priority_queue<ll>
#define  minpql     priority_queue<ll,vector<ll>,greater<ll> >

#define  setbits(x)     __builtin_popcountll(x)
#define  zerobits(x)    __builtin_ctzll(x)

#define toll(a) atoll(a.c_str())
string tostr(ll a) {stringstream rr;rr<<a;return rr.str();}
ll pow(ll c,ll d){return d==0?:c*pow(c,d-1);}
ll gcd(ll a,ll b) {return b==0? a:gcd(b,a%b);}
ll lcm(ll a,ll b) {return ((a*b)/gcd(a,b));}

/* mpp.max_load_factor(0.25); mpp.reserve(1024); */
/* cout << fixed << setprecision(12);*/

int main()
{
    fastt;
    ll n, m, k, i, j, x, y, p=0,  h, f=0;
    cin>>n>>m>>x>>y;
    string s="";
    for(i=n; i<x; i++){
        s+="R";
    }
    for(i=m; i<y; i++){
        s+="U";
    }
    for(i=n; i<x; i++){
        s+="L";
    }
    for(i=m; i<y; i++){
        s+="D";
    }
    s+="D";
    for(i=n; i<=x; i++){
        s+="R";
    }
    for(i=m; i<=y; i++){
        s+="U";
    }
    s+="L";
    s+="U";
    for(i=n; i<=x; i++){
        s+="L";
    }
    for(i=m; i<=y; i++){
        s+="D";
    }
    s+="R";
    cout<<s<<endl;
    return 0;
}



Measured memory_bytes: 3660
from random import randint
import sys
input = sys.stdin.readline
INF = 9223372036854775808


def calc_score(D, C, S, T):
    """
    開催日程Tを受け取ってそこまでのスコアを返す
    コンテストi 0-indexed
    d 0-indexed
    """
    score = 0
    last = [0]*26  # コンテストiを前回開催した日
    for d, t in enumerate(T):
        last[t] = d + 1
        for i in range(26):
            score -= (d + 1 - last[i]) * C[i]
        score += S[d][t]
    return score


def update_score(D, C, S, T, score, ct, ci):
    """
    ct日目のコンテストをコンテストciに変更する
    スコアを差分更新する

    ct: change t 変更日 0-indexed
    ci: change i 変更コンテスト 0-indexed
    """
    new_score = score
    last = [0]*26  # コンテストiを前回開催した日
    prei = T[ct]  # 変更前に開催する予定だったコンテストi
    for d, t in enumerate(T, start=1):
        last[t] = d
        new_score += (d - last[prei])*C[prei]
        new_score += (d - last[ci])*C[ci]
    last = [0]*26
    T[ct] = ci
    for d, t in enumerate(T, start=1):
        last[t] = d
        new_score -= (d - last[prei])*C[prei]
        new_score -= (d - last[ci])*C[ci]
    new_score -= S[ct][prei]
    new_score += S[ct][ci]
    return new_score


def local_search():
    pass


def main(D, C, S):
    T = []
    for d in range(D):
        # d日目終了時点で満足度が一番高くなるようなコンテストiを開催する
        max_score = -INF
        best_i = 1
        for i in range(26):
            T.append(i)
            score = calc_score(D, C, S, T)
            if max_score < score:
                max_score = score
                best_i = i
            T.pop()
        T.append(best_i)
    return T


if __name__ == '__main__':
    D = int(input())
    C = [int(i) for i in input().split()]
    S = [[int(i) for i in input().split()] for j in range(D)]
    T = [int(input())-1 for i in range(D)]
    M = int(input())
    DQ = [[int(i)-1 for i in input().split()] for j in range(M)]
    score = calc_score(D, C, S, T)
    for d, q in DQ:
        score = update_score(D, C, S, T, score, d, q)
        T[d] = q
        print(score)


Measured memory_bytes: 97748
#include<bits/stdc++.h>
#define N 18
using namespace std;

bool dp[(1<<N)][N][2];

int main(){
  
  int n;
  
  while(cin>>n){
    
    string num[N];

    for(int i=0;i<n;i++) cin>>num[i];
    
    memset(dp,0,sizeof(dp));

    for(int i=0;i<n;i++)
      for(int j=0;j<2;j++) dp[(1<<i)][i][j]=true;
    
    for(int i=0;i<(1<<n);i++)
      
      for(int j=0;j<n;j++)
	
	for(int k=0;k<2;k++){
	  
	  if(!dp[i][j][k]) continue;

	  for(int l=0;l<n;l++){

	    if(i&(1<<l)) continue;
	    
	    for(int m=0;m<2;m++)
	      
	      if(num[j][k]==num[l][m]) dp[i|(1<<l)][l][!m]=true;
	    
	  }
	  
	}

    bool ans=false;

    for(int i=0;i<n;i++)
      for(int j=0;j<2;j++) ans|=dp[(1<<n)-1][i][j];

    cout<<(ans?"Yes":"No")<<endl;
    
  }
  
  return 0;
}

Measured memory_bytes: 12340
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, x, n) for(int i = x; i < (int)(n); ++i)
#define speed ios::sync_with_stdio(0); cin.tie(0);
int const N = 1e5 + 2;
int a[N];
int main(){
	int n, k;
	cin >> n >> k;
	f(i, 0, n)cin >> a[i];
	sort(a, a + n);
	int mn = 1e9 + 1, hmn, hmx, l = 0;
	f(i, k - 1, n){
		if (a[i] - a[l] <= mn)hmn = a[l], hmx = a[i], mn = a[i] - a[l];
		l++;
	}
	cout << hmx - hmn << endl;
    return 0;
}

Measured memory_bytes: 640
while(True):
  N, M = map(int, input().split())
  if N == 0 and M == 0:
    break
  r = int(input())

  TIME_MINIMUM = 540
  util_times = [[0 for _ in range(721)] for _ in range(M)]

  for i in range(r):
    time, _, stud, sta = map(int, input().split())
    util_times[stud - 1][time - TIME_MINIMUM] += sta * 2 - 1


  q_num = int(input())

  for _ in range(q_num):
    sta, end, stud = map(int, input().split())
    # 配列のコピー
    ut = [
      util_times[stud - 1][i] for i in range(end - TIME_MINIMUM)
    ]
    # 累積和の計算
    for i in range(1, end - TIME_MINIMUM):
      ut[i] = ut[i] + ut[i - 1]
      if (ut[i] < 0):
        print("DEBUG")

    print(sum([1 for i in ut[sta - TIME_MINIMUM:] if i > 0]))





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

int count(string str, int size);

int main() {
  // ここにプログラムを追記
  string a;
  cin >> a;


  cout << count(a, a.size()) << endl;
}

int count(string str, int size){
  int rslt = 0;
  for(int i =0; i<size;i++){
    if(str[i] == '1'){
      rslt++;
    }
  }
  return rslt;

}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
static const int N=100;

bool seq(::vector<int>v){
	int d=v[1]-v[0];
	for(int i=1;i<v.size();i++){
		if(v[i]-v[i-1]!=d)return false;
	}
	return true;
}

int main(){
	::vector<int>a;
	int n,x;
	while(cin>>n&&n){
		a.resize(n+1);
		for(int i=0;i<n+1;i++)cin>>a[i];

		for(int i=0;i<n+1;i++){
			::vector<int>tmp=a;
			tmp.erase(tmp.begin()+i);
			if(seq(tmp)){
				cout<<a[i]<<endl;
				break;
			}
		}
	}
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
using namespace std; 
long long n,a,b,c,k,ans;

string s,t;
int main(){
    cin>>a>>b>>c>>k;
    ans=min(a,k);
    k-=min(a,k);
    if(k>0){
        k-=min(k,b);
    }
    if(k>0){
        ans-=k;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3624
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define FILE_IO freopen("input.txt","r",stdin)
#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define bp __builtin_popcount
#define debug(x) cerr << #x << " = " << x << endl;

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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>void print(T t){for(auto &it : t)cout<<it<<" ";}
inline int powerexp(int a, int b, int m = MOD){ int res = 1;while(b){if(b&1)res = res * a % m;a = a * a % m,b >>= 1;}return res % m;}
inline int modinv(int a){ return powerexp(a,MOD-2,MOD);}
inline int lcm(int a, int b){ int g = __gcd(a,b);return a/g*b;}
inline int add(int x, int y){ x += y; if (x >= MOD) x -=  MOD; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % MOD;}
inline int sub(int x, int y){ x -= y; if (x<0) x += MOD; return x ;}

//-------------------< start here >-------------------------// 

void solve(){
   set<int> s1, s2 ,s3;
   s1 = {1, 3, 5, 7, 8, 10, 12};
   s2  = {4, 6, 9, 11};
   s3 = {2};
   int x, y;
   cin >> x >> y;
   if(s1.find(x) != s1.end() && s1.find(y) != s1.end()) cout << "Yes" << endl;
   else if(s2.find(x) != s2.end() && s2.find(y) != s2.end()) cout << "Yes" << endl;
   else if(s3.find(x) != s3.end() && s3.find(y) != s3.end()) cout << "Yes" << endl;
   else cout << "No" << endl;
    
}

//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr << "time elapsed " << (double)clock()/CLOCKS_PER_SEC << endl;
   #endif
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

from itertools import accumulate

def main():
    N = II()
    P = LI()
    T = [1] * N
    for i, p in enumerate(P):
        T[p - 1] += i
    A = list(accumulate(T))
    B = list(accumulate(T[::-1]))[::-1]
    print(*A)
    print(*B)

    return 0

main()

Measured memory_bytes: 7104
using System;
using System.Linq;

namespace CGcdOnBlackboard
{
    class Program
    {
        static void Main(string[] args)
        {
            // 入力の取得
            var n = int.Parse(Console.ReadLine());
            var inputNums = Console.ReadLine().Split().Select(int.Parse).ToArray();

            // 1つの数字を書き換えて、最大公約数が変わり得るのはUNIQUEな数字のみ
            // UNIQUEな数字に対して、その他の数字の最大公約数を計算して、そのうち最大のものが解答
            var numbersWithCount = inputNums.GroupBy(x => x).Select(g => Tuple.Create(g.Key, g.Count())).ToArray();
            var numbers = numbersWithCount.Select(x => x.Item1).ToArray();
            var uniqueNumbers = numbersWithCount.Where(x => x.Item2 == 1).Select(x => x.Item1).ToArray();

            var maxGcd = 0;
            if (uniqueNumbers.Any())
            {
                foreach (var uniqueNum in uniqueNumbers)
                {
                    var otherGcd = 0;
                    foreach (var number in numbers)
                    {
                        if (number == uniqueNum) continue;
                        otherGcd = Gcd(number, otherGcd);
                        if (otherGcd == 1) break;
                    }
                    if (maxGcd < otherGcd) maxGcd = otherGcd;
                }
            }
            else
            {
                maxGcd = numbers.Aggregate((gcd, num) => Gcd(num, gcd));
            }

            // 解答の出力
            Console.WriteLine(maxGcd);
        }

        static int Gcd(int a, int b)
        {
            if (a < b) return Gcd(b, a);
            if (0 < b) return Gcd(b, a % b);
            return a;
        }
    }
}


Measured memory_bytes: 29660