akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <cstring>
#include <cctype>
#include <sstream>
#include <set>
#include <map>
#include <queue>
#include <complex>
using namespace std;
#define REP(i,n) for(int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for(int i = a; i < (int)b; i++)
const int INF = 1<<28;

bool com(const pair<int, pair<int, int> >& left, const pair<int, pair<int, int> >& right) {
	if(left.second.first == right.second.first) {
		if(left.second.second == right.second.second)
			return left.first < right.first;
		else
			return left.second.second < right.second.second;
	}
	else
		return left.second.first > right.second.first;
}

int main() {
	int T, P, R;
	while(cin >> T >> P >> R, T|P|R) {
		vector< pair<int, pair<int, int> > > vp;
		multiset<int> w;
		REP(i, T)
			vp.push_back(make_pair(i+1, make_pair(0, 0)));
		REP(j, R) {
			int tid, pid, time;
			string message;
			cin >> tid >> pid >> time >> message;
			if(message == "CORRECT") {
					vp[tid-1].second.first++;
					vp[tid-1].second.second += w.count(tid * 100 + pid) * 1200 + time;
			}
			else if(message == "WRONG")
				w.insert(tid * 100 + pid);
		}
		sort(vp.begin(), vp.end(), com);
		REP(i, vp.size())
			cout << vp[i].first << ' ' << vp[i].second.first << ' ' << vp[i].second.second << endl; 
	}
	return 0;
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9+7;
#define REP(i,j,n) for(int i=j;i<n;i++)
#define rep(i,n) REP(i,0,n)

map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int64_t n;
    cin >> n;
    map<int64_t, int> mp = prime_factor(n);
    vector<int> ary(50);
    // ary.push_back(1);
    ary[0] = 1;
    REP(i,1,50) ary[i] = ary[i-1] + i+1;
    ll ans = 0;
    for(auto itr = mp.begin(); itr != mp.end(); ++itr) {
        int64_t key = itr->first;
        int value = itr->second;
        auto iitr = upper_bound(ary.begin(), ary.end(), value);
        auto dist = distance(ary.begin(), iitr);
        // cout << key << " " << value << " " << *iitr << " " << dist << endl;
        ans += dist;
    }
    cout << ans << endl;

}


Measured memory_bytes: 3596
N, M = gets.split.map(&:to_i)
Xs = gets.split.map(&:to_i)

Xs.sort!
sum = 0
diff = []

(Xs.length - 1).times do |i|
  diff.push( [Xs[i + 1] - Xs[i], i] ) 
end

diff.sort!{ |b, a| a[0] <=> b[0] }

diff = diff.slice(0, N-1)

diff.sort!{ |b, a| b[1] <=> a[1] }

head = Xs[0]

diff.length.times do |i|
  
  b_i = (diff[i][1])
  
  sum += Xs[b_i] - head

  head = Xs[b_i+1]
  
end

sum += Xs.last - head

puts sum

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

typedef long long ll;
typedef long long LL;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

#ifdef DEBUG
    #define cek(x) cout<<x
#else
    #define cek(x) if(false){}
#endif // DEBUG

#define fi first
#define se second
#define INF 1000000000
#define INFLL 1000000000000000000LL
#define EPS 1e-9
#define PI acos(-1.0)
#define pb push_back
#define TC() while(tc--)
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORN(i,n) for(int i=0;i<=n;i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define REPN(i,a,b) for(int i=a;i<=b;i++)
#define reset(a,b) memset(a,b,sizeof(a))
#define sc(x) scanf("%d",&x)

int main(void){
    #ifdef ccsnoopy
        freopen("D:/Code/in.txt","r",stdin);
    #endif

    int t,n,d;
    sc(t);
    while(t--){
        sc(n);sc(d);
        map<int,int>mapper;
        mapper[d]++;
        FOR(i,n-1){
            int angka;
            for(map<int,int>::iterator it = mapper.begin();it!=mapper.end();it++){
                if(it->second != 0){
                    angka = it->first;
                    break;
                }
            }
            mapper[angka]--;
            mapper[127-angka]++;
            mapper[angka^(127-angka)]++;
        }
        ll tot = 0;
        for(map<int,int>::iterator it = mapper.begin();it!=mapper.end();it++){
            tot += it->second * (it->first);
        }

        cout << tot << endl;

    }


    return 0;
}





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

int main() {
  int n, d, a;
  scanf("%d %d %d", &n, &d, &a);
  
  vector<pair<int, int>> monsters;
  for (int i = 0; i < n; i++) {
    int x, h;
    scanf("%d %d", &x, &h);    
    monsters.emplace_back(x, (h + a - 1) / a);
  }

  sort(monsters.begin(), monsters.end());
  
  vector<pair<int, int>> exploded;
  long long ans = 0, s = 0;
  int p = 0;
  for (int i = 0; i < n; i++) {
    while (p < exploded.size() && monsters[i].first > exploded[p].first) {
      s -= exploded[p].second;
      p++;
    }

    int remaining = monsters[i].second - s;
    if (remaining > 0) {
      ans += remaining;

      exploded.emplace_back(monsters[i].first + d * 2, remaining);
      s += remaining;
    }
  }

  printf("%lld\n", ans);

  return 0;
}

Measured memory_bytes: 4848
N, M = map(int, input().split())
to = [[] for _ in range(N)]

for _ in range(M):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    to[a].append(b)
    to[b].append(a)


res = 0
def dfs(v, seen):
    global res
    if seen == [1] * N:
        res += 1
        return
    for nv in to[v]:
        if not seen[nv]:
            seen[nv] = 1
            dfs(nv, seen)
            seen[nv] = 0


def main():
    seen = [0] * N
    seen[0] = 1
    dfs(0, seen)
    print(res)


if __name__ == "__main__":
    main()


Measured memory_bytes: 74536
//Kyokai no Kanata //
#include<bits/stdc++.h>

using namespace std;

typedef pair<int,int> II;
typedef vector<II> VII;
typedef vector<int> VI;
typedef vector< VI > VVI;
typedef long long int LL;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define SET(a,b) memset(a,b,sizeof(a))

#define si(n) scanf("%d",&n)
#define dout(n) printf("%d\n",n)
#define sll(n) scanf("%lld",&n)
#define lldout(n) printf("%lld\n",n)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr<<name<<" : "<<arg1<<endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names,Arg1&& arg1,Args&&... args){
  const char* comma=strchr(names+1,',');
  cerr.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1,args...);
}
#else
#define trace(...)
#endif
float  inf=std::numeric_limits<double>::infinity();
LL INF=std::numeric_limits<LL>::max();
//FILE *fin = freopen("in","r",stdin);
//FILE *fout = freopen("out","w",stdout);
pair<LL,int> R[4];
bool cmp(pair<LL,int> a,pair<LL,int> b){
  return a.F*b.S<b.F*a.S;
}
int main(){
  for(int i=0;i<4;i++){
    sll(R[i].F),R[i].S = i>0? R[i-1].S*2 :1;
  }
  LL n;sll(n);n*=4;
  sort(R,R+4,cmp);
  LL ans=0;
  for(int i=0;i<4 && n;i++){
    ans+=(n/R[i].S)*R[i].F;
    n%=R[i].S;
  }
  lldout(ans);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define REP1(i,n) for(int i=1;i<=n;++i)
#define ALL(c) (c).begin(),(c).end()
int main(){
	string a,b;
	cin >> a >> b;
	bool flag=false;
	rep(j,a.size()-b.size()+1){
		bool ok=true;
		rep(i,b.size()){
			if(b[i]!='_' && b[i]!=a[i+j]){
				ok=false;
				break;
			}
		}
		if(ok){
			flag=true;
			break;
		}
	}
	if(flag) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 1188
#include<stdio.h>
 
int main(void)
{
int a, b, c;
int i;
scanf("%d %d %d", &a, &b, &c);
if(b-a+1 <= c || b-a+1 <= 2*c){
for(i=a; i<=b; i++){
printf("%d\n", i);
}
}else{
for(i=0;i<c;i++){
printf("%d\n", a+i);
}for(i=c-1;i>=0;i--){
printf("%d\n", b-i);
}
}
return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(){
  
  int a,b,i,ans,sub,height = 0;
  scanf("%d%d",&a,&b);
  
  sub = b - a;
  for(i = 1; i <= sub; i++){
    height += i;
  }
  
  ans = height - b;
  printf("%d",ans);
  
  return 0;
  
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
using P = pair <int, int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

ll MOD = 1000000007;
ll INF =1<<30;

int main(){
    string s,t;
    cin >> s>>t;
    int n = t.size();
    int ans = n+1;
    rep(i,s.size()){
        if(i+n-1>s.size()-1)continue;
        string x = s.substr(i,n);
        int cnt = 0;
        rep(j,n){
            if(x[j]!=t[j])cnt++; 
        }
        ans = min(ans,cnt);
    }
    cout << ans <<endl;
}

Measured memory_bytes: 3608
N = int(input())
A = list(map(int, input().split()))
B = [0] * N

for i in range(N - 1, -1, -1):
    p = A[i]
    j = i + 1
    while i < N:
        if B[i]:
            p ^= 1
        i += j
    B[j - 1] = p

S = [i + 1 for i, c in enumerate(B) if c]

print(len(S))
print(*S)


Measured memory_bytes: 14132
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e5 + 5;

int c[N];

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin >> n;
    vector<int> a;
    vector<int> b;
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        a.push_back(x);
    }
    for(int i = 0; i < n; i++){
        cin >> c[i];
    }
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        b.push_back(x);
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    ll ans = 0;
    for(int i = 0; i < n; i++){
        int x = c[i];
        ll idx = lower_bound(a.begin(), a.end(), x) - a.begin();
        ll idx2 = lower_bound(b.begin(), b.end(), x + 1) - b.begin();
        idx2 = n - idx2;
        ans = ans + idx * idx2;
    }
    cout << ans;

    return 0;
}


Measured memory_bytes: 1784
def main():
    H, W = (int(i) for i in input().split())
    ans = 10**10
    # 縦or横に三分割
    if W % 3 == 0 or H % 3 == 0:
        ans = 0
        return print(ans)
    else:
        ans = min(H, W)

    # 分割の位置を探索
    for w in range(1, W):
        a = H*w
        b = (H//2)*(W-w)
        c = (H-(H//2))*(W-w)
        ans = min(ans, max(a, b, c) - min(a, b, c))
    for h in range(1, H):
        a = h*W
        b = (H-h)*(W//2)
        c = (H-h)*(W-(W//2))
        ans = min(ans, max(a, b, c) - min(a, b, c))
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 39920
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;

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

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

    vector<int> dish(5);
    REP(i, 5) {
        int a;
        cin >> a;
        dish[i] = a;
    }

    int min_r = 10;
    int min_index = 0;
    REP(i, 5) {
        if (dish[i] % 10 < min_r && dish[i] % 10 != 0) {
            min_r = dish[i] % 10;
            min_index = i;
        }
    }
    int sum = 0;
    REP(i, 5) {
        sum += dish[i];
        if (dish[i] % 10 != 0) {
            sum += 10 - (dish[i] % 10);
        }
    }
    if (dish[min_index] % 10 != 0) {
        sum -= (10 - (dish[min_index] % 10));
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    int n, m;
    bool b[112345];

    cin >> n >> m;
    fill(b, b + n + 1, false);
    REP(i, m)
    {
        int a;
        cin >> a;
        b[a] = true;
    }

    ll dp[112345];
    memset(dp, 0, sizeof(dp));

    dp[0] = 1;
    for (int i = 0; i < n; i++)
    {
        REP(j, 2)
        {
            if (!b[i + j + 1])
            {
                (dp[i + j + 1] += dp[i]) %= MOD;
            }
        }
    }

    cout << dp[n] << endl;

    return 0;
}

Measured memory_bytes: 1280
IDENTIFICATION                   DIVISION.
PROGRAM-ID.                      ABC_070_B.
ENVIRONMENT                      DIVISION.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 INP    PIC X(15).
    01 A      PIC 9(3).
    01 B      PIC 9(3).
    01 C      PIC 9(3).
    01 D      PIC 9(3).
    01 mx     PIC 9(3).
    01 mn     PIC 9(3).

    01 ZS     PIC Z(3)9.
    01 DUMMY  PIC X(1).
    01 ans    PIC X(3).

PROCEDURE                        DIVISION.
MAIN.
    ACCEPT INP.

    UNSTRING INP
    DELIMITED BY SPACE
    INTO A B C D.

    COMPUTE mx = FUNCTION MAX(A, C).
    COMPUTE mn = FUNCTION MIN(B, D).

    IF mx < mn THEN
        SUBTRACT mx FROM mn
    ELSE
        MOVE ZERO to MN
    END-IF.

    MOVE mn TO ZS.

    PERFORM UNANS.

    DISPLAY ans(1:FUNCTION STORED-CHAR-LENGTH(ans)).
    STOP RUN.

UNANS                            SECTION.
    UNSTRING
        ZS DELIMITED BY ALL SPACE
        INTO DUMMY ans
    END-UNSTRING.


Measured memory_bytes: 1144
#include<bits/stdc++.h>
using namespace std;
char s[10000],t[10000];
int main(){
	scanf("%s%s",s,t);
	int ans=0,len=strlen(s);
	for(int i=0;i<len;i++)
		if(s[i]==t[i])	++ans;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
n,m = map(int,input().split())
cost = []
for i in range(n):
    a,b = map(int,input().split())
    cost.append([a,b])
cost.sort()
cnt = 0
price = 0
for i in range(n):
    if cnt + cost[i][1] <= m:
        price += cost[i][0] * cost[i][1]
        cnt += cost[i][1]
    else:
        price += (m-cnt)*cost[i][0]
        print(price)
        exit()
print(price)


Measured memory_bytes: 20064
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
#define U(v) cerr << #v << ": " << (v) << endl

template <class T>
struct BIT {
    vector<T> a;
    BIT(int size) : a(size, 0) {}
    T sum(int r) const {
        T sm = 0;
        for (--r; r >= 0; r = (r & r + 1) - 1)
            sm += a[r];
        return sm;
    }
    T sum(int l, int r) const {
        return sum(r) - sum(l);
    }
    T at(int i) const {
        return sum(i, i + 1);
    }
    void add(int i, T v) {
        for (; i < (int)a.size(); i |= i + 1)
            a[i] += v;
    }
    void set(int i, T v) {
        add(i, v - at(i));
    }
};

int main() {
    int n, q;
    cin >> n >> q;
    BIT<long long> bit(n);
    while (q--) {
        int com, x, y;
        cin >> com >> x >> y;
        --x;
        if (com)
            cout << bit.sum(x, y) << endl;
        else
            bit.add(x, y);
    }
    return 0;
}

Measured memory_bytes: 3508
#include<iostream>
#include<cmath>
using namespace std;
int main(){
	int n;
	int a,b,c,d,e,f,g;
	int t=0,x=0,y=0;
	bool s=true;
	int i,j,k;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a>>b>>c;
		d=a-t,e=abs(b-x)+abs(c-y);
		if(d<e || d%2!=e%2)s=false;
	}
	if(s)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
from fractions import Fraction

N,K=map(int,input().split())

case = []
number = []
count = 0
result_a = 0

for i in range(N):
    case.append(i+1)

for j in range(N):
    while case[j] <= K-1:
        case[j] *= 2
        count += 1
    count = 2**count
    number.append(count*N)
    count = 0

for k in range(N):
    number[k] = Fraction(1,number[k])

for l in range(N):
    result_a += number[l]

result_b = float(result_a)
print(result_b)

Measured memory_bytes: 22868
#include<bits/stdc++.h>
using namespace std;
int a[300001]={0};
char c[300001];
int tmp[300001]={0};
int main()
{
    int n,minn=0x7fffffff,i,j;
	scanf("%d",&n);
	getchar();
	for(i=0;i<n;i++)
	{
		scanf("%c",&c[i]);
		if(i==0)
			a[i]=0;
		else if(c[i-1]=='W')
			a[i]=a[i-1]+1;
		else if(c[i-1]=='E')
			a[i]=a[i-1];
	}
	for(i=n-1;i>=0;i--)
	{
		if(i==n-1)
			tmp[i]=0;
		else if(c[i+1]=='E')
			tmp[i]=tmp[i+1]+1;
		else if(c[i+1]=='W')
			tmp[i]=tmp[i+1];
		minn=min(minn,tmp[i]+a[i]);
	}
	printf("%d",minn);
    return 0;
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
const int MOD = 1e9+7;
const int MX = 2e5+5;
const ll  INF = 1e18;
const ld  PI = acos((ld) -1);
template<class T> inline void array_input(T a[], size_t n){for(size_t i = 0; i < n; i++)cin >> a[i];}

long long binExp(long long a, long long b, long long mod){
    long long res = 1;
    while(b > 0){
        if(b % 2) res = res * a % mod;
        a = a * a % mod;
        b /= 2;
    }
    return res;
}

ll gcd(ll a, ll b, ll &x, ll &y){
    x = 1, y = 0;
    int x1 = 0, y1 = 1;
    while(b){
        int q = a/b;
        tie(a, b) = make_tuple(b, a - q * b);
        tie(x, x1) = make_tuple(x1, x - q * x1);
        tie(y, y1) = make_tuple(y1, y - q * y1);
    }
    return a;
}
//#define FILE

int main(){
#ifdef FILE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif // 0

    int n, x, t;
    cin >> n >> x >> t;

    cout << (n+x-1)/x * t << '\n';
    return 0;
}


Measured memory_bytes: 3632
/*
 * main.c
 *
 *  Created on: 2019/04/06
 *      Author: family
 */


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

int main()
{
    int a, b, c, d, e, k;
    int mark = 0;
    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &c);
    scanf("%d", &d);
    scanf("%d", &e);
    scanf("%d", &k);

    if((e - a) > k) {
        mark++;
    }

    if(mark == 0) {
        printf("Yay!\n");
    } else {
        printf(":(\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <stdlib.h>

using namespace std;

int A,B,N;
string huka = "-1";
bool counter = false;

int main(void){
    cin >> N;
    
    for(int i=0; i<10; i++){
        for(int j=0; j<10; j++){
            int temp = i*j;
            if(N == temp){
                counter = true;
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    
    cout <<"No"<< endl;
    return 0;
}



Measured memory_bytes: 256
S = input()
Q = int(input())
line = True
first, last = '',''

for _ in range(Q):
    q = input().split()
    if q[0] == '1':
        line = True if line==False else False
    else:
        if line == True:
            if q[1] == '1':
                first = q[2] + first
            else:
                last = last + q[2]
        elif line==False:
            if q[1] == '1':
                last = last + q[2]
            else:
                first = q[2] + first
S = first+S+last
print(S if line else S[::-1])

Measured memory_bytes: 4592
#include<stdio.h>
#include<string.h>
int main()
{
    const char a[100];
    int l,i,min=1000,x,y;
    scanf("%s",&a);
    l=strlen(a);
    for(i=0;i<l-2;i++)
    {
        x=((a[i]-48)*100)+((a[i+1]-48)*10)+(a[i+2]-48);
        y=753-x;
        if(y<0) y=y*(-1);
        if(y<min) min=y;
    }
    printf("%d",min);
    return 0;
}


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

int main(void){
	int n,k,h[100000];
	int ans=0;
    cin >> n;
	cin >> k;
	for(int i=0;i<n;i++){
		cin >> h[i];
		if(h[i] >= k){
			ans += 1;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=1<<18,INF=1<<30;

int n,dat[2*MAX-1];

void init(int n_){
    n=1;
    while(n<n_) n*=2;
    for(int i=0;i<2*n-1;i++){
        dat[i]=0;
    }
}

void update(int k,int a){
    k+=n-1;
    dat[k]=a;
    
    while(k>0){
        k=(k-1)/2;
        dat[k]=dat[k*2+1]+dat[k*2+2];
    }
}

int query(int a,int b,int k,int l,int r){
    
    if(r<=a||b<=l) return 0;
    if(a<=l&&r<=b) return dat[k];
    else{
        int vl=query(a,b,2*k+1,l,(l+r)/2);
        int vr=query(a,b,2*k+2,(l+r)/2,r);
        return vl+vr;
    }
}


bool compare(pair<ll,int> a,pair<ll,int> b){
    return a.second<b.second;
}

int main(){
    
    int N,K;cin>>N>>K;
    vector<ll> A(N);
    vector<pair<ll,int>> S(N+1);
    for(int i=0;i<N;i++){
        cin>>A[i];
        A[i]-=K;
        S[i+1].first=S[i].first+A[i];
        S[i+1].second=i+1;
    }
    
    sort(all(S));
    
    for(int i=0;i<N+1;i++){
        S[i].first=i;
    }
    
    sort(all(S),compare);
    
    init(N+1);
    
    ll ans=0;
    
    update(S[N].first,1);
    
    for(int i=N-1;i>=0;i--){
        ans+=query(S[i].first,n,0,0,n);
        update(S[i].first,1);
    }
    
    cout<<ans<<endl;
}


Measured memory_bytes: 7040
#include <iostream>
#include <queue>
#include <map>
#include <bitset>
#include <string>
#include <set>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <ctime>
#include <stack>
#include <cstdlib>
#include <numeric>
#include <cassert>
#include <complex>
#include <iterator>
//#include <unordered_map>
using namespace std;
#define maxn 2000007
#define maxm 400007
#define maxq 1000007
#define maxl 1234
#define modn 1000000007
#define scan(a) scanf("%d",&a)
#define scanl(a) scanf("%lld",&a)
#define scanl2(a,b) scanf("%lld%lld",&a,&b)
#define scans(a) scanf("%s",a)
#define scans2(a,b) scanf("%s%s",a,b)
#define scand(a) scanf("%lf",&a)
#define scan2(a,b) scanf("%d%d",&a,&b)
#define scand2(a,b) scanf("%lf%lf",&a,&b)
#define scan3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define scan4(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d)
#define scan5(a,b,c,d,e) scanf("%d%d%d%d%d",&a,&b,&c,&d,&e)
#define print(a) printf("%d\n",a);
#define printl(a) printf("%lld\n",a);
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rrep(i,a,b) for(int i=a;i>= b;i--)
#define fscan(a) fscanf(stream,"%d", &a);
#define mp      make_pair	
#define pb      push_back
#define eb      emplace_back
#define mm(a,b) memset(a,b,sizeof a)
#define log2(n) (double)(log(n) / log(2.0))
#define _crt_disable_perfcrit_locks
#define bll __int128
#pragma warning(disable:4996)
typedef long long ll;
typedef unsigned long long ull;
const int inf = 0x3f3f3f3f;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef map <ll, ll> mll;
typedef pair <ll, ll> pll;
typedef map <int, int> mii;
typedef pair <int, int> pii;
typedef map <char, int> mci;
typedef map <char, char> mcc;
typedef pair <char, int> pci;
typedef complex<double> cd;
typedef vector<complex<double> > vcd;
const double eps = 1e-8;
const double PI = 2 * acos(0.0);

int cc, bb; char ch; inline int F() {
	while (ch = getchar(), (ch < 48 || ch> 57) && ch != '-'); ch == '-' ? cc = bb = 0 : (cc = ch - '0', bb = 1);
	while (ch = getchar(), ch > 47 && ch < 58)cc = (cc << 1) + (cc << 3) + (ch ^ 48); return bb ? cc : -cc;
}
void write(int x) {
	int y = 10, len = 1;
	while (y <= x) { y *= 10; len++; }
	while (len--) { y /= 10; putchar(x / y + 48); x %= y; }
}
int n;
int a[200007];
ll dp[200007][3];
int main() {
	//ios::sync_with_stdio(0);
	//cin.tie(0);
	//FILE* stream = fopen("L:/20.in", "rb+")
	scan(n);
	rep(i, 1, n)
		scan(a[i]);
	mm(dp, 0x3f);
	rep(i, 1, 3)
		dp[i][i - 1] = a[i];
	dp[3][0] = a[1] + a[3];
	rep(i, 4, n) {
		dp[i][0] = dp[i - 2][0] + a[i], dp[i][1] = dp[i - 2][1] + a[i], dp[i][2] = dp[i - 2][2] + a[i];
		dp[i][1] = max(dp[i][1], dp[i - 3][0] + a[i]), dp[i][2] = max(dp[i][2], dp[i - 3][1] + a[i]);
		if (i > 4)
			dp[i][2] = max(dp[i][2], dp[i - 4][0] + a[i]);
	}
	ll res;
	if (n & 1)
		res = max(dp[n][2], max(dp[n - 1][1], dp[n - 2][0]));
	else
		res = max(dp[n][1], dp[n - 1][0]);
	printl(res);
	return 0;
}

Measured memory_bytes: 9232
#include "bits/stdc++.h"

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i,n) for(ll i=1;i<=(ll)(n);i++)
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(ll)(n);i>0;i--)
#define REP(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = 2e18;
const ll MOD = 1000000007;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);


int main() {
  while (true) {
    int m, n;
    cin >> m >> n;
    if (!n) {
      return 0;
    }
    bitset<7368800> b;
    for (int i = m; i < b.size(); i++) {
      if (!b[i]) {
        n--;
        for (int j = 1; i*j < b.size(); j++) {
          b[i * j] = true;
        }
        if (!n) {
          break;
        }
      }
    }
    for (int i = m + 1; i < b.size(); i++) {
      if (!b[i]) {
        cout << i << endl;
        break;
      }
    }
  }
}



Measured memory_bytes: 3908
n, k = map(int, input().split())
a = list(map(int, input().split()))

a = [0] + a
a.sort()
if max(a) < k:
    print("IMPOSSIBLE")
    exit()

for i in range(len(a) - 1):
    if k == a[i]:
        print("POSSIBLE")
        break
    if a[i+1] - a[i] == 0: continue 
    if k % (a[i+1] - a[i]) == 0:
        print("POSSIBLE")
        break
else:
    print("IMPOSSIBLE")

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


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

  int n; cin >> n;
  vector<int> card(n);
  rep(i,n) cin >> card[i];
  sort(card.begin(), card.end(), greater<int>());

  int alice = 0, bob = 0;
  rep(i,n){
    if(i == 0 || i % 2 == 0) alice += card[i];
    else bob += card[i];
  }

  cout << alice - bob << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include "Local_Debug.h"
using namespace std;
#define Endl endl
#define debug(x) cout << #x << " = " << (x) << endl
typedef long long ll;
const int MOD = (int)1e9 + 7;
const int MAXN = (int)2e5 + 5;
ll n, m, t, a[MAXN];
int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	while (cin >> n)
		cout << (n - 1) / 2 << endl;
}
/*
1

999999
*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 	int n;cin>>n;
  	int count,ans=0;
  	
  	for (int i=1;i<=n;i=i+2){
    	for (int j=1;j<=i;j++){
        	if(i % j==0){
            	count++;
            }
        }
      	if(count==8){
        	ans++;
        }
      	count=0;
    }
  	cout<<ans<<endl;
}

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

long long gcd(long long a,long long b){
	if(a==0 || b==0) return max(a,b);	
	else if(a==1 || b==1) return 1;
	else if(a%b == 0 || b%a==0) return min(a,b);
	long long q;
	bool pro =true;
	while(pro){
		q=a%b;
		a=b;
		b=q;
		if(a%b==0){
			return q;
		pro=false;
		}
	}
}

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

signed main(){
	int N;
	cin>>N;
	vector<pair<string,int>> play(N);
	for(int i=0;i<N;i++){
		cin>>play[i].first>>play[i].second;
	}
	string X;
	cin>>X;
	int ans=0;
	bool pro=false;
	for(int i=0;i<N;i++){
		if(play[i].first==X){
			pro=true;
			continue;
		}
		if(pro)ans+=play[i].second;
	}
	
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 1000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
using namespace std;

int n,m,ans;
int a[211111];
signed main(){
    cin>>n>>m;
    rep(i,n)cin>>a[i];
    sort(a,a+n,greater<>());
    rep(i,n){
    	if(m!=0){
    		m--;
    	}
    	else{
    		ans+=a[i];
    	}
    }
    cout<<ans<<endl;
}


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

int main() {
    string S; cin >> S;
    int n = S.size() - 1;
    long long sum = 0;
    for (int bit = 0; bit < (1<<n); bit++) {
        long long lst[10];
        for (int i = 0; i < 10; i++) lst[i] = 0;
        int j = 0;
        lst[0] = S.at(0) - '0';
        for (int i = 0; i < n; i++) {
            if (bit & (1<<i)) j++;
            lst[j] *= 10;
            lst[j] += S.at(i+1) - '0';
        }
        for (int i = 0; i < 10; i++) {
            sum += lst[i];
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let line = read_as_vec::<u64>();
    let (n, a, b) = (line[0], line[1], line[2]);
    if a > b{
        println!("0");
        return;
    }else if a == b{
        println!("1");
        return;
    }else if n < 2{
        println!("0");
        return;
    }
    println!("{}", (a+b*(n-1))+1 - (a*(n-1)+b));
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
//#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(15); //"for float-base
  // problem"
  ll a, b, x, ans;
  cin >> a >> b >> x;
  if (a > 0)
    ans = (b / x) - ((a - 1) / x);
  else
    ans = (b / x) + 1;

  cout << ans << endl;
}

Measured memory_bytes: 3600
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

vector<int> m;
vector<vector<int> > memo;

int solve(int rest, int pos)
{
    if(rest <= 0)
        return 1;

    if(memo[rest][pos] != -1)
        return memo[rest][pos];

    for(int i=1; i<=m[pos]; ++i){
        if(solve(rest - i, (pos + 1) % m.size()) == 0)
            return memo[rest][pos] = 1;
    }
    return memo[rest][pos] = 0;
}

int main()
{
    for(;;){
        int n, s;
        cin >> n >> s;
        if(n == 0)
            return 0;

        m.resize(2*n);
        for(int i=0; i<2*n; ++i)
            cin >> m[i];

        memo.assign(s+1, vector<int>(2*n, -1));
        cout << solve(s, 0) << endl;
    }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        vector<set<int>>cnt(26);
        string s; 
        int q,l,r,t,idx,ans=0,nn;
        char c;
        cin>>nn;
        cin>>s;
        for(int i=0;i<s.size();i++){ 
            cnt[s[i]-'a'].insert(i);
        } 
        cin>>q;
        while(q--){ 
            cin>>t;
            if(t==1){ 
            cin>>idx>>c;
            idx--; 
            cnt[s[idx]-'a'].erase(idx);
            s[idx]=c;
            cnt[s[idx]-'a'].insert(idx);
            } 
            else { 
                ans=0;
                cin>>l>>r;
                l--; r--; 
                for(int i=0;i<26;i++){ 
                    auto it=cnt[i].lower_bound(l);
                    if(it!=cnt[i].end()&&*it<=r)ans++;
                } 
                cout<<ans<<"\n";
            } } 
            
            
            
        return 0;
    }

Measured memory_bytes: 24196
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AOJ
{
	class Program
	{
		static void Main(string[] args)
		{
			var s = "";
			while ((s = Console.ReadLine()) != null)
			{
				var n = int.Parse(s);
				n = (n * n + n + 2) / 2;
				Console.WriteLine(n);
			}
		}
	}
}

Measured memory_bytes: 5604
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[a]; if (a != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)///
struct UnionFind {
	vector<int> par;
	vector<int> ran;

	UnionFind(int n) {
		par.resize(n);
		ran.resize(n);
		REP(i, n) {
			par[i] = i;
			ran[i] = 0;
		}
	}

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

	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 (ran[x] < ran[y]) {
			par[x] = y;
		}
		else {
			par[y] = x;
			if (ran[x] == ran[y]) ran[x]++;
		}
	}
};
struct E {
	int from, to;
	double cost;
	E(int a, int b, double c) {
		from = a; to = b; cost = c;
	}
	E();
	bool operator < (E b) {
		return this->cost < b.cost;
	}
};
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	while (cin >> n, n) {
		vector<double> x(n), y(n), z(n), r(n);
		REP(i, n) {
			cin >> x[i] >> y[i] >> z[i] >> r[i];
		}
		vector<E> v;
		REP(i, n) {
			REP(j, n) {
				v.push_back(E(i, j, max(double(0), sqrt((x[i] - x[j])*(x[i] - x[j]) + (y[i] - y[j])*(y[i] - y[j]) + (z[i] - z[j])*(z[i] - z[j])) - r[i] - r[j])));
			}
		}
		sort(ALL(v));
		UnionFind uf(n);
		double ans = 0;
		REP(i, v.size()) {
			if (!uf.same(v[i].from, v[i].to)) {
				uf.unite(v[i].from, v[i].to);
				ans += v[i].cost;
			}
		}
		cout << fixed << setprecision(3)<<ans << endl;
	}
}

Measured memory_bytes: 3452
#include <iostream>

using namespace std;

int main(){
    int X;
    //X
    int A;
    //A
    cin >> X >> A;
    //標準入力
    if (X < A){
        cout << 0 << endl;
        //XがA未満の場合0と出力する処理
    } else if (A <= X){
        cout << 10 << endl;
        //XがA以上の場合出力する処理
    }
}

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

int main(){
    int n;
    cin>>n;
    vector<vector<int>> v(n+1,vector<int>(3));
    vector<vector<int>> dp(n+1,vector<int>(3));
    for(int i=1;i<=n;i++){
        for(int j=0;j<3;j++) cin>>v[i][j];
    }

    for(int i=1;i<=n;i++){
        for(int j=0;j<3;j++){
            dp[i][j]=max(dp[i-1][(j+1)%3],dp[i-1][(j+2)%3])+v[i][j];
        }
    }
    cout<<max(dp[n][0],max(dp[n][1],dp[n][2]))<<endl;
}

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

using namespace std;

typedef long long ll;

bool check(ll x, vector <ll> a, ll lim){
    for(int i=0;i<a.size();i++){
        a[i]+=x;
    }
    int n=a.size();
    ll req=0;
    for(int i=0;i<a.size();i++){
        req+=max((a[i]-lim+n)/(n+1),0LL);
    }
    if(req>x){
        return 0;
    }
    else{
        return 1;
    }
}

int main(){
    int n;
    cin >> n;
    vector <ll> a(n);
    ll sum=0;
    for(int i=0;i<n;i++){
        cin >> a[i];
        sum+=a[i];
    }
    ll steps = sum-n*n;
    ll ans=0;
    if(steps>0) {
        ll l = -1, r = 1e18;
        while (l + 1 < r) {
            ll mid = (l+r)>>1;
            if(check(steps, a, mid)){
                r=mid;
            }
            else{
                l=mid;
            }
        }
        for(int i=0;i<n;i++){
            a[i]+=steps;
        }
        ll done=0;
        for(int i=0;i<n;i++){
            if(a[i]>r){
                done+=((a[i]-r+n)/(n+1));
                a[i]=a[i]-((a[i]-r+n)/(n+1))*(n+1);
            }
        }
        sort(a.begin(),a.end(),greater<ll>());
        for(ll i=0;i<steps-done;i++){
            a[i]-=n+1;
        }
        ans+=steps;
    }
    while(true){
        bool flag=1;
        for(int i=0;i<n;i++){
            if(a[i]>=n){
                flag=0;
            }
        }
        if(flag){
            break;
        }
        ans++;
        int mx=0;
        for(int i=1;i<n;i++){
            if(a[i]>a[mx]){
                mx=i;
            }
        }
        for(int i=0;i<n;i++){
            if(i==mx){
                a[i]-=n;
            }
            else{
                a[i]++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

#define sqr(x) ((x) * (x))
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define fin(name) freopen(name, "r", stdin)
#define fout(name) freopen(name, "w", stdout)
#define I(x, a) for(auto x : a)
#define F(i, l, r) for(auto i = l; i < r; ++i)
#define E(i, l, r) for(auto i = l; i <= r; ++i)
#define DF(i, l, r) for(auto i = l; i >= r; --i)
#define clean(a) memset((a),0,sizeof (a))
#define sync ios_base::sync_with_stdio(0);cin.tie(0)
#define all(x) (x).begin(),(x).end()
#define ret return
#define cont continue
#define brk break
#define ins insert
#define sz(a) ((int)(a).size())

typedef long long ll;
typedef unsigned long long ull;
typedef long double dbl;
typedef pair <int, int> pii;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)1e9 + 7;
const dbl eps = (dbl)1e-8;
const int maxn = (int)1e5 + 5;
const dbl pi = acos(-1);

int pal[666][666];
int pal2[666][666];
string s[666];

int main() {
//	fin("t.in");
	sync;
	int n;
	cin >> n;
	F(i, 0, n) {
		cin >> s[i];
		s[i] = s[i] + s[i];
	}
	F(i, n, 2 * n)
		s[i] = s[i - n];
	clean(pal);
	clean(pal2);
	F(i, 0, 2 * n) {
		F(j, 0, 2 * n) {
			while (1) {
				int l = pal[i][j];
				int li = i + l, lj = j - l;
				int ri = i - l, rj = j + l;
				if (li >= 2 * n || rj >= 2 * n || lj < 0 || ri < 0 ||
					s[li][lj] != s[ri][rj])
					break;
				++pal[i][j];
			}
			while (1) {
				int l = pal2[i][j];
				int li = i + l + 1, lj = j - l - 1;
				int ri = i - l, rj = j + l;
				if (li >= 2 * n || rj >= 2 * n || lj < 0 || ri < 0 ||
					s[li][lj] != s[ri][rj])
					break;
				++pal2[i][j];
			}
//			cout << pal2[i][j] << " ";
		}
//		cout << endl;
	}
	int ans = 0;
	F(i, 0, n) {
		F(j, 0, n) {
			int fl = 1;
			F(l, 0, n) {
				int x = i + l, y = j + l;
				int need = min(l, n - l - 1) * 2 + 1;
				if (2 * pal[x][y] - 1 < need) {
					fl = 0;
					break;
				}
			}
			F(l, 0, n - 1) {
				int x = i + l, y = j + l + 1;
				int need = (min(l, n - l - 2) + 1) * 2;
				if (2 * pal2[x][y] < need) {
//					cout << i << " " << j << " " << l << " " << need << " " <<  << endl;
					fl = 0;
					break;
				}
			}

			if (fl) {
//				cout << i << " " << j << endl;	
				++ans;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
  int N; cin>>N;
  int M; cin>>M;
  vector<int> mm={6,2,5,5,4,5,6,3,7,6};
  vector<string> cc={"","1","2","3","4","5","6","7","8","9"};
  vector<int> cm(M);
  for(int i=0;i<M;i++){
    cin>>cm[i];
    if(cm[i]==9)
      mm[6]=30000;
    if(cm[i]==5)
      mm[3]=mm[2]=30000;
    if(cm[i]==3)
      mm[2]=30000;
  }
  sort(cm.begin(),cm.end());
  vector<string> ans(N+1,"#");
  vector<int> ansn(N+1,0);
  int ma; string ms;
  for(int i=0;i<N+1;i++){
    if(i==0){
      ans.at(0)=""; continue;
    }
    ma=0; ms="#";
    for(int j=M-1;j>=0;j--){
      if(mm.at(cm.at(j))>i)
        continue;
      if(ans.at(i-mm.at(cm.at(j)))=="#")
        continue;
      if(ansn.at(i-mm.at(cm.at(j)))+1>ma){
        ma=ansn.at(i-mm.at(cm.at(j)))+1;
        ms=cc.at(cm.at(j))+ans.at(i-mm.at(cm.at(j)));
      }
    }
    ans.at(i)=ms; ansn.at(i)=ma;
  }
  //for(int i=0;i<N+1;i++){
  //  cout<<ans.at(i)<<" "<<ansn.at(i)<<endl;
  //}
  cout<<ans.at(N);
}

Measured memory_bytes: 33024
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define REP(i,n) for(int i=0,_n=(n);(i)<(int)_n;++i)
#define RANGE(i,a,b) for(int i=(int)a,_b=(int)(b);(i)<_b;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define PRINT1(table, D0) REP(d0, D0) cout<<table[d0]<<" "; cout<<"\n";
#define PRINT2(table, D0, D1) REP(d0, D0) { REP(d1, D1) cout<<table[d0][d1]<<" "; cout<<"\n"; }
#define PRINT3(table, D0, D1, D2) REP(d0, D0) { REP(d1, D1) { REP(d2, D2) cout<<table[d0][d1][d2]<<" "; cout<<"\n"; } cout<<"\n"; }
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }

#define MOD 1000000007LL
#define INF (1LL<<60)

int main() {
	//ios::sync_with_stdio(false);
	ll N,M,a,b;
	while(cin>>N>>M) {
		vector<bool> fz(N), fn(N);
		REP(i, M) {
			cin>>a>>b;
			a--;b--;
			if(a==0) fz[b]=1;
			if(b==0) fz[a]=1;
			if(a==N-1) fn[b]=1;
			if(b==N-1) fn[a]=1;
		}
		bool ok = false;
		RANGE(i, 1, N-1) {
			if(fz[i]&&fn[i]) ok=true;
		}
		cout<<(ok?"POSSIBLE":"IMPOSSIBLE")<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
if __name__ == "__main__":
    N, K = list(map(int, input().split()))
    sunuke = set()
    for i in range(K):
        d = int(input())
        seq = list(map(int, input().split()))
        for a in seq:
            sunuke.add(a)

    print(N-len(list(sunuke)))

Measured memory_bytes: 9184
#include <stdio.h>
#include <string.h>
int min(int *arr, int len)
{
	int index =0;
	int min =0;
	min = arr[0];
	while (index < len)
	{
		if (min > arr[index])
			min = arr[index];
		index++;
	}

	return(min);
}
int main(void)
{
	int A, B, M;
	
	scanf("%d %d %d", &A, &B, &M);

	int p_a[A+1];
	int p_b[B+1];
	int x[M];
	int y[M];
	int c[M];

	int index = 0;
	while (index < A)
	{
		scanf("%d", &p_a[index]);
		index++;
	}
	index = 0;
	while (index < B)
	{
		scanf("%d", &p_b[index]);
		index++;
	}
	index = 0;
	int p_min = 0;
	//割引使わないパターン
	p_min = min(p_a, A) + min(p_b, B);
	//割引使うパターン
	while (index <M)
	{
		scanf("%d %d %d", &x[index], &y[index], &c[index]);
		if(p_min > p_a[x[index]-1] + p_b[y[index]-1] - c[index])
		{
			p_min = p_a[x[index]-1] + p_b[y[index]-1] - c[index];
		}
		index++;
	}
	printf("%d\n", p_min);
	return (0);
}


Measured memory_bytes: 2176
#include <cstdio>
typedef long long ll;
const int Maxn=300;
ll a[Maxn+5];
int n;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
	}
	ll sum=0;
	for(int i=3;i<=n;i++){
		sum^=a[i];
	}
	ll d=(a[1]+a[2])-sum;
	if(d<0||(d&1)){
		puts("-1");
		return 0;
	}
	d>>=1;
	if(d>a[1]||(d&sum)>0){
		puts("-1");
		return 0;
	}
	ll ans=d;
	for(int i=59;i>=0;i--){
		if((sum>>i)&1){
			if(ans+(1ll<<i)<=a[1]){
				ans+=(1ll<<i);
			}
		}
	}
	if(ans==0){
		puts("-1");
	}
	else{
		printf("%lld\n",a[1]-ans);
	}
	return 0;
}


Measured memory_bytes: 1728