akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;
using ll = long long;

template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_V(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_M(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}

const int MOD = 1e9 + 7;

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    V<int> s(n + 1), t(m + 1);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &s[i]);
    }
    for (int i = 0; i < m; ++i) {
        scanf("%d", &t[i]);
    }
    s[n] = -1, t[m] = -2;

    VV<int> dp0(n + 10, V<int>(m + 10, 0)), dp1(n + 10, V<int>(m + 10, 0));
    dp0[0][0] = 1;
    for (int i = 0; i < n + 1; ++i) {
        for (int j = 0; j < m + 1; ++j) {
            (dp0[i + 1][j] += dp0[i][j]) %= MOD;
            (dp1[i][j] += dp0[i][j]) %= MOD;
            (dp1[i][j + 1] += dp1[i][j]) %= MOD;
            if (s[i] == t[j]) {
                (dp0[i + 1][j + 1] += dp1[i][j]) %= MOD;
            }
        }
    }
    cout << dp1[n][m] << endl;

    return 0;
}

Measured memory_bytes: 32000
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define rep(i,n) for(int i=0;i<n;i++)

int main() {
	int N,K,X,Y;
  	cin>>N>>K>>X>>Y;
  	int sum=0;
  	if(N<=K) sum+=N*X;
  	else sum+=K*X+(N-K)*Y;
  	cout<<sum<<endl;
}

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

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;

const int mod = 998244353;
const ll inf = 3e18 + 5;

int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }  

int main(){
    string s, t;
    cin >> s >> t;
    int diff = 1001;
    int n = s.size();
    int m = t.size();
    for(int i = 0; i <= n - m; i++){
        int cnt = 0;
        for(int j = 0; j < m; j++){
            if(s[i + j] != t[j])
                cnt++;
        }
        diff = min(diff, cnt);
    }
    cout << diff;
}



Measured memory_bytes: 3620
#include <iostream>
#include <cmath>
#include <string>
 
using namespace std;
 
int main()
{
	int A, B, C, cnt ;
	
	cin >> A >> B >> C ;
	
	cnt = 0 ;
	
	if( (A==5?1:0)+(A==7?4:0)+(B==5?1:0)+(B==7?4:0)+(C==5?1:0)+(C==7?4:0) == 6 )
	{
		cout << "YES" << endl ;
	}else{
		cout << "NO" << endl ;
	}
	
	return 0 ;
}


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

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if(a==b){
    if(b==c){
      cout << 1 << endl;
    }
    else{
      cout << 2 << endl;
    }
  }
  else if(a==c){
    cout << 2 << endl;
  }
  else if(b==c) {
    cout << 2 << endl;
  }
  else {
    cout << 3 << endl;
  }
}

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

using namespace std;

int main() {
	string a, b;
	cin >> a >> b;
	reverse(b.begin(), b.end());
	if (a == b) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
N,M = map(int,input().split())

inf = []
sup = []

for i in range(0,M):
	L,R = map(int,input().split())
	inf.append(L)
	sup.append(R)
	
inf = max(inf)
sup = min(sup)

ran = sup - inf

if ran >= 0:
	print(ran + 1)
else:print(0)

Measured memory_bytes: 11008
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;

#define INF 1e18
#define int long long

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

    int ans = 0;
    int w_cnt = 0;
    for(int i = 0; i < s.size(); i++) {
        if(s[i] == 'W') {
            ans += i - w_cnt;
            w_cnt++;
        }
    }

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


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>

#define MAX 1000000000
typedef unsigned long long ULL;
typedef long long LL;

using namespace std;

int main(){
    int N;
    int ans;
    int count;
    int *a;
    int i;

    cin >> N;
    a = new int[N];
    for(i=0;i<N;i++){
        cin >> a[i];
    }
    sort(a,a+N);
    ans = 0;
    count = 1;
    for(i=1;i<N;i++){
        if( a[i] == a[i-1]){
            count++;
        }else{
            if( count % 2 == 1){
                ans++;
            }
            count  = 1;
        }
    }
    if( count % 2 == 1 ){
        ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
#include<stdio.h>
int b[100][100];
int c[100];
int main(){
	int a;
	while(scanf("%d",&a),a){
		for(int i=0;i<100;i++){
			c[i]=1;
			for(int j=0;j<100;j++)b[i][j]=0;
		}
		for(int i=0;i<a;i++){
			int p;scanf("%d",&p);
			for(int j=0;j<p;j++){
				int q;
				scanf("%d",&q);q--;
				b[i][q]=1;
			}
		}
		int e;
		scanf("%d",&e);
		for(int i=0;i<e;i++){
			int f;
			scanf("%d",&f);f--;
			for(int j=0;j<a;j++)if(!b[j][f])c[j]=0;
		}
		int v=0;for(int i=0;i<a;i++)v+=c[i];
		if(v!=1)printf("-1\n");
		else{
			for(int i=0;i<a;i++)if(c[i])printf("%d\n",i+1);
		}
	}
}

Measured memory_bytes: 1080
def main():
    N = int(input())
    A = [[i for i in input().split()] for j in range(N)]
    X = input()
    ans = 0
    flag = False
    for a, b in A:
        if a == X:
            flag = True
            continue
        if flag:
            ans += int(b)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
//////////////////////////////////////////////
///  Fear is temporary, Regret is forever  ///
///               sat7978                  ///
///         extreme      blood             /// 
//////////////////////////////////////////////
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e6+100;
#define ll long long
#define pb push_back
#define S second
#define F first
void flash(){
    ios_base::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);
  	cout.setf(ios::fixed);
  	cout.setf(ios::showpoint);
  	cout.precision(2);
}


int main() {
    flash(); 
    int t;
    t=1;
    //cin>>t;
    while(t--){
        string s;
        cin>>s;
        int arr[256]={0};
        for(int i=0;i<s.length();i++){
            arr[(int)s[i]]++;
        }
        int f=0;
        int cnt=0;
        for(int i=0;i<256;i++){
            if(arr[i]==2) cnt++;
        }
        if(cnt==2) cout<<"Yes";
        else cout<<"No";
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const long long INF = 1e10;
const long long MOD = 1e9+7;
using Graph = vector<vector<ll>>;
using pll = pair<ll, ll>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}

// 0 false, 1 true 
// string to int : -48
// a to A : -32
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll n, m, k; cin >> n >> m >> k;

    vector<long long> vec_a(n);
    vector<long long> sum_a(n + 1);
    rep(i, n){
        cin >> vec_a[i];
        sum_a[i+1] = vec_a[i] + sum_a[i];
    }

    vector<long long> vec_b(m);
    vector<long long> sum_b(m + 1);
    rep(i, m){
        cin >> vec_b[i];
        sum_b[i+1] = vec_b[i] + sum_b[i];
    }
    /*
    rep(i, n+1){
        cout << sum_a[i] << " ";
    }
    br;
    rep(i, m+1){
        cout << sum_b[i] << " ";
    }
    br;
    */

    ll ans = 0;
    for(ll i = 0; i <= n; i++){
        ll tmp = k - sum_a[i];
        if(tmp == 0){
            ans = max(ans, i);
            continue;
        }else if(tmp < 0){
            continue;
        }

        ll tmp_b = lower_bound(sum_b.begin(), sum_b.end(), tmp) - sum_b.begin();
        if(i + tmp_b <= k){
            
            if(sum_b[tmp_b] == tmp){
                ans = max(ans, i+tmp_b);
            }else{
                ans = max(ans, i+tmp_b-1);
            }

            //cout << tmp << " " << i << " " << tmp_b << endl;
             
        }
        /*
        for(ll j = 1; j <= m; j++){
            if(sum_a[i] + sum_b[j] <= k){
                ans = max(ans, i+j);
            }
        }
        */
    }
    cout << ans << endl;

    /*
    vector<long long> vec_a(n);
    queue<ll> que_a;
    for(long long i = 0; i < n; i ++){
        cin >> vec_a[i];
        que_a.push(vec_a[i]);
    }
    vector<long long> vec_b(m);
    queue<ll> que_b;
    for(long long i = 0; i < m; i ++){
        cin >> vec_b[i];
        que_b.push(vec_b[i]);
    }
    vec_a.push_back(1e10);
    vec_b.push_back(1e10);

    ll a = 0, b = 0;
    ll res = 0;
    ll count = 0;
    while(true){
        if(vec_a[a] > vec_b[b]){
            if(res + vec_b[b] > k){
                break;
            }
            res += vec_b[b];
            b++;
            count++;
            
        }else if(vec_a[a] < vec_b[b]){
            if(res + vec_a[a] > k){
                break;
            }
            res += vec_a[a];
            a++;
            count++;
        }else{
            if(res + vec_a[a] > k){
                break;
            }
            res += vec_a[a];
            a++;
            count++;
        }
        if(a == n && b == m){
            break;
        }
    }

    cout << "res = " << res << endl;
    cout << count << endl;
    */


}

Measured memory_bytes: 9592
#include<iostream>
#include<vector>
#include<string>

using ll = long long;

int main(){
    int n;
    std::cin >> n;
    std::vector<ll> vec(n + 1, 0);
    for(ll x = 1;  x * x < n; x++){
        for(ll y = 1; y * y <= n; y++){
            for(ll z = 1; z * z <= n; z++){
                ll tmp = x * x + y * y + z * z + x * y + y * z + z * x;
                if(tmp <= n){
                    vec[tmp]++;
                }
            }
        }
    }

    for(int i = 1; i <= n; i++){
        std::cout << vec[i] << std::endl;
    }
    return 0;
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
#include <chrono>
#include <math.h>
using namespace std;
using ll = long long;
using ld = long double;
using namespace std::chrono; 
#define fo(i,z,n) for(int i = z;i<n;i++)
#define Fo(i,z,n) for(ll i = z;i<n;i++)
#define INT_BITS 32
#define mod 1000000007
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> > 
#define pb push_back
#define f first
// #define s second
#define int long long
#define float long double
#define all(c) (c).begin(), (c).end()
#define endl '\n'
#define pi 3.14159265358979323846

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

int pow(int a,int b){
	if(b == 0)return 1;
	int res = pow(a,b/2);
	res = res*res;
	if(b&1)res *= a;
	return res;
}

int32_t main()
{
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     cout.tie(0);
   	
 //    int t;
 //     cin >> t;

 //     while(t--){


 // }

int x;
cin >> x;
int a = 0;
int b = 0;
int p = 5;
fo(i,-300,300){
	fo(j,i+1,300){
		if(pow(j,p) - pow(i,p) == x){
			a = j;
			b = i;
			break;
		}
	}
}
cout << a << ' ' << b << endl;





return 0;
	
	}




Measured memory_bytes: 3640
#include<iostream>
#include<vector>
using namespace std;
int main()
{
    int N;  cin >> N;
    long s, ans;
    s = 0;
    std::vector<long> v(N,0), u(N), a(N);
    for(int i=0; i<N; i++){
        int A;  cin >> A;
        a[i] = A;
        v[A-1]++;
    }
    for(int i=0; i<N; i++){
        u[i] = v[i]*(v[i]-1)/2;
        s += u[i];
    }
    for(int i=0; i<N; i++){
        ans = s;
        cout << ans - v[a[i]-1] + 1 << '\n';
    }
}

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

long long gcd(long long C,long long D)
{
	if(C==0 || D==0)return 0;
	long long r;
	for(;;){
		r = C%D;
		if(r==0)break;
		C = D;
		D = r;
	}
		return D;
}

long long lcm(long long C,long long D)
{
	if(C==0 || D==0)return 0;
	long long E;
	E = C*(D/gcd(C,D));
	return E;
}

int main(){
	
	long long A;
	long long B;
	long long C;
	long long D;
	long long sum;
	long long sum1;
	long long sum2;
	long long tmp;
	long long ans;
	
	
	cin >> A;
	cin >> B;
	cin >> C;
	cin >> D;
	
	if(A%C==0){
		sum = (B/C-A/C)+1;
	} else {
		sum = B/C-A/C;
	}
	if(A%D==0){
		sum1 = (B/D-A/D)+1;
	} else {
		sum1 = B/D-A/D;
	}
	if(A%lcm(C,D)==0){
		sum2 = (B/lcm(C,D)-A/lcm(C,D))+1;
	} else {
		sum2 = B/lcm(C,D)-A/lcm(C,D);
	}
	tmp = sum+sum1-sum2;
	ans = B-A+1-tmp;
	
	cout << ans << endl;
	
	return 0;
}	

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
def main():
    INF = float('inf')
    N = int(input())
    d = [[int(x) for x in input().split()]for _ in range(N)]
    ans = 0
    flag = True
    for i in d:
        ans += sum(i)
    ans //= 2
    max_d = 0
    for k in range(N):
        for i in range(N):
            for j in range(N):
                if(i==j or j==k or i==k or d[i][j]==INF):continue
                max_d = max(max_d,d[i][j])
                if(d[i][j]==d[i][k] + d[k][j]):
                    ans -= d[i][j]
                    d[i][j] = INF
                    d[j][i] = INF
                elif(d[i][j]>d[i][k] + d[k][j]):
                    flag = False
    print(ans if (ans >= max_d)and flag else -1)

if __name__ == '__main__':
    main()


Measured memory_bytes: 49640
def check(table)
  result = 0
  if table.sum <= 2
    table.find {|x| x == 2}
  else
    (1..7).each do |i|
      tmp = table.dup
      if tmp[i].nonzero? and tmp[i + 1].nonzero? and tmp[i + 2].nonzero?
        3.times {|x| tmp[i + x] -= 1}
        return true if check(tmp)
      end
    end
    (1..9).each do |j|
      tmp1 = table.dup
      if tmp1[j] >= 3
        tmp1[j] -= 3
        return true if check(tmp1)
      end
    end
    false
  end
end

$<.readlines.map(&:chomp).map {|n| n.chars.map(&:to_i)}.each do |data|
  table = Array.new(10, 0)
  data.each {|i| table[i] += 1}
  result = (1..9).map do |i|
    added = table.dup
    added[i] += 1
    next if added[i] > 4
    check(added) ? i : nil
  end.compact
  puts result.empty? ? 0 : result.join(" ")
end


Measured memory_bytes: 6876
#include <bits/stdc++.h>
#define int long long int
#define all(v) v.begin(),v.end()
#define ov(v) for(int i=0;i<(v).size();i++)cout<<v[i]<<" ";cout<<endl;
#define N 10000
using namespace std;
void solve()
{
	int n;
	cin>>n;
	vector<int>v(n);
	int mx,x,ans = 0;
	cin>>mx;
	for(int i = 1;i<n;i++)
	{
		cin>>x;
		ans+=max(0LL,mx-x);
		mx = max(x,mx);
	}
	cout<<ans<<endl;

}
signed main() 
{
	// int t;
	// cin>>t;
	// while(t--)
	solve();
	return 0; 
}

Measured memory_bytes: 4840
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 2010;
bool board[maxn][maxn];
int n, m;
int len[2][maxn][maxn];
void init(bool asd)
{
	//cout << asd << " : " << endl;
	for(int i = 1; i <= m; i ++)
		len[asd][1][i] = m + 1;
	for(int i = 2; i <= n; i ++)
	{
		int p = 0;
		for(int j = 1; j <= m; j ++)
		{
			p = max(p, j);
			for(p; p <= m && board[i][p] == (board[i - 1][p] ^ asd); p ++);
			//cout << i << " " << j << " " << p << endl;
			len[asd][i][j] = p;
		}
	}
	/*
	for(int i = 1; i <= n; i ++)
	{
		for(int j = 1; j <= m; j ++)
			cout << len[asd][i][j] << " ";
		cout << endl;
	}
	*/
}
int ans = 0;
int sta[maxn], cnt = 0;
int l[maxn];
void get(int x)
{
	//cout << x << " ---------------------- " << endl;
	cnt = 0;
	sta[++ cnt] = 1;
	l[1] = 0;
	for(int i = 2; i <= n; i ++)
	{
		l[i] = max(len[0][i][x], len[1][i][x]) - x;
		//cout << i << " " << l[i] << endl;
		while(cnt > 0 && l[sta[cnt]] > l[i])
		{
			//cout << sta[cnt] << " : " << endl;
			ans = max(ans, (i - sta[cnt - 1]) * l[sta[cnt]]);
			//cout << ans << endl;
			cnt --;
		}
		sta[++ cnt] = i;
	}
	while(cnt > 0)
	{
		ans = max(ans, (n - sta[cnt - 1] + 1) * l[sta[cnt]]);
		cnt --;
	}
}
int main()
{
	std::ios::sync_with_stdio(false);
	cin >> n >> m;
	for(int i = 1; i <= n; i ++)
	{
		for(int j = 1; j <= m; j ++)
		{
			char a;
			cin >> a;
			if(a == '#')
				board[i][j] = 1;
			else
				board[i][j] = 0;
		}
	}
	init(0);
	init(1);
	for(int a = 1; a <= m; a ++)
		get(a);
	cout << max(ans, max(n, m)) << endl;
	return 0;
}

Measured memory_bytes: 35712
#include<iostream>
#include<string>
 
using namespace std;
 
int main(){
    int n,m;
	int a[1000];
	int b[1000];
	int c[1000];
	int e,o;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<m;i++){
		cin>>b[i];
	}
	for(int i=0;i<n;i++){
		c[i]=0;
	}
	for(int i=0;i<n;i++){
		int j=0;
		while(true){
			if(b[i]>=a[j]){
				c[j]+=1;
				break;
			}
			j++;
		}
	}
	e=c[0];
	o=0;
	for(int i=0;i<n;i++){
		if(e<c[i]){
			o=i;
			e=c[i];
		}
	}
	cout<<o+1<<endl;
    return 0;
} 

Measured memory_bytes: 1172
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(inti=a;i<=b;i++)

typedef long long int ll;
typedef vector<int>vi;
typedef pair<int,int>pi;



int main()
{

int n ;
cin>>n;

int arr[n];
for(int i = 0 ; i< n ; i++)
    cin>>arr[i];

    int ans = INT_MAX;
for(int pos = 0 ; pos <=100 ; pos++)
{
    int curr = 0 ;
    for(int i = 0 ; i< n ; i++)
     curr+=(arr[i]-pos)*(arr[i]-pos);

     ans= min(ans, curr);
}
std::cout<<ans<<endl;
 return 0;
}


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



int n;
int a[610][610];
int b[610][610];
const unsigned long long sd=13131;
unsigned long long has1[610][610];
unsigned long long has2[610][610];
void cal(int a[][610],unsigned long long has[][610])
{
    unsigned long long pw=1;
    for(int i=1;i<=2*n;i++)
        for(int j=1;j<=2*n;j++)
        {
            unsigned long long w=pw*a[i][j];
            has[i][j]=has[i-1][j]+has[i][j-1]-has[i-1][j-1]+w;
            pw*=sd;
        }
}
unsigned long long sum(unsigned long long a[][610],int x,int y,int x1,int y1)
{
    return a[x1][y1]-a[x1][y-1]-a[x-1][y1]+a[x-1][y-1];
}
unsigned long long pc[610];
unsigned long long pr[610];
int check(int x,int y)
{
    unsigned long long A=sum(has1,y,x,n+y-1,n+x-1);
    unsigned long long B=sum(has2,x,y,n+x-1,n+y-1);
    if(y>x)
    {
        A*=pc[y-x];
        B*=pr[y-x];
    }
    else
    {
        B*=pc[x-y];
        A*=pr[x-y];
    }
//    printf("%llu %llu\n",A,B);
//    printf("%d %d %d %d\n",y,x,n+y-1,n+x-1);
//    printf("%d %d %d %d\n",x,y,n+x-1,n+y-1);
    return A==B;
}
char s[610];
int main()
{
    scanf("%d",&n);
    pc[0]=pr[0]=1;
    for(int i=1;i<=2*n;i++)
        pc[i]=pc[i-1]*sd;
    for(int i=1;i<=2*n;i++)
        pr[i]=pr[i-1]*pc[2*n];
    for(int i=1;i<=n;i++)
    {
        scanf("%s",s+1);
        for(int j=1;j<=n;j++)
        {
            a[i][j]=s[j]-'a'+1;
            b[j][i]=a[i][j];
        }
    }
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
        {
            a[i][j+n]=a[i][j];
            a[i+n][j]=a[i][j];
            a[i+n][j+n]=a[i][j];
            b[i][j+n]=b[i][j];
            b[i+n][j]=b[i][j];
            b[i+n][j+n]=b[i][j];
        }

//    for(int i=1;i<=2*n;i++,puts(""))
//        for(int j=1;j<=2*n;j++)
//            printf("%d ",a[i][j]);
//    puts("****");
//    for(int i=1;i<=2*n;i++,puts(""))
//        for(int j=1;j<=2*n;j++)
//            printf("%d ",b[i][j]);
//    puts("*****");


    cal(a,has1);
    cal(b,has2);
    int ans=0;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
        {
            ans+=check(i,j);
        }
    printf("%d\n",ans);
	return 0;
}



Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
#define ll long long  int
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)

void solve()
{
       ll n,k;
       cin>>n>>k;
       ll arr[n],i,z=0;
       for(i=0;i<n;i++)
       	cin>>arr[i];
       ll sum=0,sum1=0;
       for(i=0;i<k;i++)
       {
       	 sum=sum+arr[i];
       	 sum1=sum1+arr[i];
       }
       for(i=k;i<n;i++)
       {
       	if(arr[z]!=0)
          sum1=sum1-arr[z];
          z++;
          sum1=sum1+arr[i];
          if(sum1>sum)
          	cout<<"Yes"<<endl;
          else
          	cout<<"No"<<endl;
          sum=sum1;
       }
    }
int main()
{
    fast();
    {
      solve();
    }
    return 0;
}



Measured memory_bytes: 5184
#include <bits/stdc++.h>
using namespace std;
const int maxn=100010;
int n,ans;
pair<int,int> a[maxn];
int main() {
	//freopen("2.txt","r",stdin);
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i].first),a[i].second=i;
	sort(a+1,a+(n+1));
	for (int i=1;i<=n;i++)
		if (a[i].second%2!=i%2) ans++;
	printf("%d\n",ans/2);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
const long long INF = 1LL << 60;
bool mem[100010];
int memo[100010];
int N;
int h[100010];
int DFS(int i) {
  ll ans;
    if(mem[i]==true){
        ans= memo[i];
    }
    else if(i==0){
      	ans=0;
      	mem[0]=true;
    }
  else if(i==1){
    	ans=abs(h[1]-h[0]);
   		 memo[1]=ans;
    	mem[1]=true;
  }
    else{
        ans=min(DFS(i-2)+abs(h[i]-h[i-2]),DFS(i-1)+abs(h[i]-h[i-1]));
        memo[i]=ans;
		mem[i]=true;
    }
  return ans;
}
int main(void) {
  	cin>>N;
    mem[0]=true;
    rep(i, N) cin >> h[i];
  	cout<<DFS(N-1)<<endl;
}


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

typedef long long ll;

int N=50;

int main(){
    ll K; cin >> K;
    ll ans[N];
    for(int i=0;i<N;i++){
        ans[i]=N-1;
    }
    ll inc=K/N;
    ll mod=K%N;
    for(int i=0;i<N;i++){
        ans[i]+=inc;
    }
    for(int i=0;i<mod;i++){
        ans[i]+=N;
        for(int j=0;j<N;j++){
            if(j==i) continue;
            ans[j]--;
        }
    }
    cout << N << endl;
    for(int i=0;i<N;i++){
        cout << ans[i] << " ";
    }
}    

Measured memory_bytes: 256
from collections import defaultdict
from heapq import heappop, heappush

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0] * (n)

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def same_check(self, x, y):
        return self.find(x) == self.find(y)

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
               self.rank[x] += 1

N, M = list(map(int, input().split()))
uf = UnionFind(N)

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

for i in range(M):
    x, y = list(map(int, input().split()))
    uf.union(x, y)

D = defaultdict(list)
for i in range(N):
    D[uf.find(i)].append(a[i])

for i in D:
    D[i] = sorted(D[i])

ans = 0
Q = []

x = len(D)
for i in D:
    if len(D[i]) == 1:
        ans += D[i][0]
    else:
        ans += D[i][0]
        m = len(D[i])
        for j in range(1, m):
            heappush(Q, D[i][j])

if len(D) == 1:
    print(0)
else:
    if N >= 2 * len(D) - 2:
        for i in range(len(D) - 2):
            x = heappop(Q)
            ans += x
        print(ans)
    else:
        print("Impossible")


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  string s;

  int k;
  cin >> s >> k;
  char ans = '1';
  rep(i, k) {
    if (s[i] != '1') {
      ans = s[i];
      break;
    }
  }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 1000007
#define INF63 1061109567
#define INF127 9187201950435737471
#define F first
#define S second
#define ll long long
#define N 100010
#define M 110
using namespace std;
ll n,b,w[M],v[M],dp[N][M],ans=0;
int main(){
	ll i,j;
	cin>>n>>b;
	w[0]=0;
	v[0]=0;
	for(i=1;i<=n;i++)
	{
		cin>>w[i]>>v[i];
	}
	memset(dp,0,sizeof(dp));
	for(i=1;i<=b;i++)
	{
		for(j=1;j<=n;j++)
		{
			dp[i][j]=max(dp[i][j],dp[i][j-1]);
			if(i>=w[j])
			{
				dp[i][j]=max(dp[i][j],dp[i-w[j]][j-1]+v[j]);
			}
		}
	}
	for(i=0;i<=b;i++)
	{
		ans=max(ans,dp[i][n]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 86144
#include <bits/stdc++.h>
 
#define f(i,a,b) for( ll i = a; i < b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ones(x) (ll) __builtin_popcount(x)
#define fs first
#define sc second
#define pb push_back
#define po pop_back
#define mp make_pair  
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ller ios::sync_with_stdio(false);cin.tsie(nullptr);cout.tie(nullptr)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define PI 3.1415926535
using namespace std;
typedef long long ll;
typedef long double ld; 
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;
const ll mod = 1e9+7;
const ll MAX = 12;
const ll inf = 1e9+7;


int main() {
	fastio;
	ll n,ind=0;
	cin>>n;
	f(i,1,2e6){
		ind=(ind*10+7)%n;
		if(!ind){cout<<i<<endl;return 0;}
	}
    cout<<-1<<endl;
	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  int ans = 0;
  if (k <= a) {
    cout << k << endl;
  }
  else if (k-a <= b) {
    cout << a << endl;
  }
  else {
    cout << a - (k-a-b) << endl;
  }

  return 0;
}

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

int main(){
    int a, b, c, d, x;
    cin >> x;
    a = x / 1000;
    b = (x % 1000) / 100;
    c = (x % 100) / 10;
    d = x % 10;
    int ans;
    int op1 = 1;
    int op2 = 1;
    int op3 = 1;
    for (int i = 0; i < 8; i++){
        op1 *= -1;
        if (i % 2 == 0) op2 *= -1;
        if (i % 4 == 0) op3 *= -1;
        ans = a + b * op1 + c * op2 + d * op3;
        if (ans == 7){
            cout << a << ((op1 > 0) ? '+' : '-');
            cout << b << ((op2 > 0) ? '+' : '-');
            cout << c << ((op3 > 0) ? '+' : '-');
            cout << d << "=7" << endl;
            break;
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define repr(i, a, n) for (int i = (n); i >= (a); --i)
#define ifaxb(a, x, b) if (a < x && x < b)
#define toInt(x) (x - '0')
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define vvs vector<vs>
#define all(x) x.begin(), x.end()
#define INF 2147483647
#define _INF -2147483647
#define pi 3.1415926536
#define MAXN 100004
using namespace std;
typedef long long ll;

int main() {
  int a, b;
  cin >> a >> b;
  int ans = 0;
  // 積雪の差　==　塔の高さの差　より
  // 東側の塔の高さと雪の埋もれていない部分の高さの差を求める
  // 東側の塔の高さは(1+2+3+..+b-a)
  rep(i, 1, b - a + 1) { ans += i; }
  cout << ans - b << endl;
  return 0;
}

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

int main() {
    int n, x, t;
    cin >> n >> x >> t;
    int a = (n + x - 1) / x;
    cout << a * t << '\n';
    return 0;
}


Measured memory_bytes: 3584
<?php
  fscanf(STDIN,"%d %d",$n,$k);
  $h = explode(' ',trim(fgets(STDIN))) ;
$dp[0] = 0 ;

for($i=1;$i<$n;++$i){
	$dp[$i] = 1000000000 ;
}
for($i=1;$i<$n;++$i){
  $list=[$dp[$i]];
  for($j=1;$j<=$i&&$j<$k+1;++$j){
   		  $list[] = $dp[$i-$j]+abs($h[$i]-$h[$i-$j]) ;
   //var_dump($list);
} 
    $dp[$i] = min($list) ;
  //var_dump($dp) ;
}
echo $dp[$n-1] ;

Measured memory_bytes: 18932
def l(): return [int(a) for a in input().split(" ")] 
ka = l()
lis = [a + 1 for a in range(ka[0])]
for a in range(ka[1]):
  input()
  q = l()
  for b in q:
    if b in lis:
      lis.pop(lis.index(b))
print(len(lis))
  


Measured memory_bytes: 9172
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int iINF = 1001001001;
const long long llINF = 1LL << 60;
int main()
{
	// ACB160-E, 1051, 
	int x, y, a, b, c;
	cin >> x >> y >> a >> b >> c;
	vector<int> p(a), q(b), r(c);
	ll ans = 0;
	rep(i, a) cin >> p[i];
	rep(i, b) cin >> q[i];
	rep(i, c) cin >> r[i];
	sort(p.rbegin(), p.rend());
	sort(q.rbegin(), q.rend());
	sort(r.begin(), r.end());
	p.resize(x); q.resize(y);
	rep(i, x) ans += p[i];
	rep(i, y) ans += q[i];
	while (1) {
		if (p.size() == 0) {
			if (q.back() < r.back()) {
				ans -= ll(q.back());
				ans += ll(r.back());
				q.pop_back();
				r.pop_back();
			}
			else break;
		}
		else if (q.size() == 0) {
			if (p.back() < r.back()) {
				ans -= ll(p.back());
				ans += ll(r.back());
				p.pop_back();
				r.pop_back();
			}
			else break;
		}
		else if (p.back() < q.back()) {
			if (p.back() < r.back()) {
				ans -= ll(p.back());
				ans += ll(r.back());
				p.pop_back();
				r.pop_back();
			}
			else break;
		}
		else {
			if (q.back() < r.back()) {
				ans -= ll(q.back());
				ans += ll(r.back());
				q.pop_back();
				r.pop_back();
			}
			else break;
		}
		if (r.size() == 0) break;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4580
#include<bits/stdc++.h>
using namespace std;
int a[1000], b[1000];
long long int n, k, sum=0;
long long int y, z=0, m=1, t=0;

int fun(int i)
{

    for(int j=0; j<n; j++)
    {
        if(a[j]%i!=0)
        {
            b[z++]=a[j]%i;
            // cout << b[z-1]<< " ";
        }
    }
    sort(b, b+z);

    int l=0, r=z-1;
    // cout << i;
    while(l<r)
    {
        if(b[l]%i==0)
        {
            l++;
            continue;
        }
        if(b[r]%i==0)
        {
            r--;
            continue;
        }
        long long int u=min(b[l]%i, i-b[r]%i);

        //cout << b[l]  << "   " << b[r] <<"   " <<u<< " "<<i << endl;
        b[l]-=u;
        b[r]+=u;
        y+=u;
        //cout << "    " << u;
        if(y>k)
        {
              y=0,m=1, z=0;
            return 0;
        }
    }
      y=0,m=1, z=0;
    return 1;
}

int main()
{

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

    for(long long int i=1; i*i<=sum; i++)
    {
        y=0,m=1, z=0;
        if(sum%i==0)
        {

            if(fun(sum/i))
            {
                cout << sum/i ;
                return 0;
            }
            else if(fun(i))
            {

                t=max(t, i);
            }
        }
    }
    cout << t;
    return 0;
}


Measured memory_bytes: 3648
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void) {
  char s[11], t[12];
  int i = 0;
  scanf("%s", s);
  scanf("%s", t);
  while (s[i] != '\0') {
    if (s[i] != t[i]) {
      printf("No\n");
      exit(0);
    }
    i++;
  }
  printf("Yes\n");
  return 0;
}


Measured memory_bytes: 1628
#include<iostream>
using namespace std;
int main()
{
	int a,b,n;
	while(cin>>a>>b>>n)
	{
		a=a%b;
		int ans=0;
		for(int i = 1; i < n+1; ++i)
		{
			a*=10;
			ans+=a/b;
			a=a%b;
		}
		cout<<ans<<endl;
	}
  return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
int main(void){
  int a,b,c,i,j;
  int d=0;
  scanf("%d%d",&a,&b);
  for(i=0;i<=a;i++){
    for(j=0;j<=a-i;j++){
      c=a-i-j;
      d=10000*i+5000*j+1000*c;
      if(d==b){
        printf("%d %d %d",i,j,c);
        return 0;
      }
    }
  }
printf("-1 -1 -1");
  return 0;
}

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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll INF = 1LL<<60;
//int INF = numeric_limits<int>::max();

int main(int, char**) {
	string x; cin >> x;
	int rem = 0;
	int cnt = 0;
	for (int i=0; i<x.size(); i++) {
		char c = x[i];
		if (c=='S') {
			cnt++;
		} else if (cnt>0) {
			rem++;
			cnt--; 
		}
	}
	cout << x.size() - 2*rem << endl;
	return 0;
}

Measured memory_bytes: 3716
function Main (input) {
  input = input.split("\n").map(inp => inp.split(" "));
  var S, T, A, B, U;
  S = input[0][0];
  T = input[0][1];
  A = parseInt(input[1][0], 10);
  B = parseInt(input[1][1], 10);
  U = input[2][0];
  if (U == S) {
    A--;
  }
  else if (U == T) {
    B--;
  }
  console.log("%d %d", A, B);
}


Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
function Main(input) {
  input = input.split("\n");
  var A = parseInt(input[0].split(" ")[0]);
  var B = parseInt(input[0].split(" ")[1]);
  var C = parseInt(input[0].split(" ")[2]);
  if((A==B&&A!=C)||(A==C&&A!=B)||(B==C&&A!=B)){
    var ans = "Yes";
  }else{
    var ans = "No";
  }

  console.log('%s', ans);
  return ans;
}

function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
def digitSum(n):
    # 数値を文字列に変換
    s = str(n)
    # １文字ずつ数値化し配列にする。
    array = list(map(int, s))
    # 合計値を返す
    return sum(array)

a = int(input())
b = digitSum(a)
if a % 9 == 0:
  if b % 9 == 0:
    print('Yes')
  else:
    print('No')
else:
  print('No')


Measured memory_bytes: 11016
k = int(input())
import math
 
a = 0
ans = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        for k in range(1,k+1):
            a = math.gcd(i, j)
            ans = ans + math.gcd(a, k)
            
print(ans)

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

#pragma ide diagnostic ignored "OCUnusedGlobalDeclarationInspection"
#pragma ide diagnostic ignored "OCUnusedMacroInspection"
using namespace std;

#define sqr(a) ((a)*(a))
#define forn(i, n) for(int i = 0; i < (int)n; ++i)
#define nrof(i, n) for(int i = (int)n - 1; i >= 0; --i)
#define rep(i, k, n) for(int i = (int)k; i < (int)n; ++i)
#define per(i, k, n) for(int i = (int)k - 1; i >= (int)n; --i)
#define x first
#define y second
#define mp make_pair
#define sz(a) (int)(a.size())
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double dd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int N = 1009;
const int M = 2e3 + 9;
const int INFINT = 1e9 + 9;
const ll INFLL = 1e18 + 9;
const ll MOD = (ll) (1000000007);

vector<int> dx = {-1, 0, 1, 0};
vector<int> dy = {0, -1, 0, 1};

void solve() {

    vector<bool> prime(N, true);
    prime[0] = prime[1] = false;
    for (int i = 2; i < N; ++i) {
        if (prime[i]) {
            if (i * 1ll * i < N) {
                for (int j = i * i; j < N; j += i) {
                    prime[j] = false;
                }
            }
        }
    }

    vector<int> prm;
    forn(i, N) if (prime[i]) prm.pb(i);


    int n;
    cin >> n;
    vector<int> a(n);
    forn(i, n) cin >> a[i];
    int g = a[0];
    forn(i, n) {
        g = __gcd(g, a[i]);
    }
    if (g != 1) {
        cout << "not coprime" << endl;
        return;
    }

    forn(i, sz(prm)) {
        int cnt = 0;
        forn(j, n) {
            if (a[j] % prm[i] == 0) ++cnt;
            while (a[j] % prm[i] == 0) a[j] /= prm[i];
        }
        if (cnt > 1) {
            cout << "setwise coprime" << endl;
            return;
        }
    }

    unordered_set<int> p;
    forn(i, n) if (a[i] > 1) {
            if (p.count(a[i])) {
                cout << "setwise coprime" << endl;
                return;
            }
            p.insert(a[i]);
        }

    cout << "pairwise coprime" << endl;
}

int main() {
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int t = 1;
//    cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 7112
#include<bits/stdc++.h>
using namespace std;
typedef long long int llint;
typedef long int lint;
typedef vector<char> vchar;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
#define vsort(v) sort((v).begin(), (v).end())
#define vreverse(v) reverse((v).begin(), (v).end())
#define pb(a) push_back(a)
#define INF 1000000007
int main(){
  lint n,i,mid;cin>>n;
  vint x(n),c(n);for(i=0;i<n;i++){cin>>x[i];c[i]=x[i];}
  vsort(c);
  mid=n/2-1;//xxoxxx
  for(i=0;i<n;i++){
    if(x[i]<=c[mid]){cout<<c[mid+1]<<endl;} 
    else{cout<<c[mid]<<endl;}
  }
}

Measured memory_bytes: 3712
#include <iostream>

using namespace std;

int main()
{
  int n,i,j;
  int count = 0;
  cin >> n;
  
  for(i = 1; i <= n; i++){
    cin >> j;
    if((i%2 != 0) && (j%2 != 0)) count++;
  }
  
  cout << count;
}


Measured memory_bytes: 3644
#include <iostream>
#include <cmath>
using namespace std;
bool checkNotOdd(int n)
{
    if(n % 2 == 0)
    {
        return false;
    }
    else
    {
        return true;
    }

}
bool check(int n)
{
    for(int i = 2;i <= sqrt(n);i++)
    {
        if(n % i == 0)
        {
            return false;
        }
    }
    return true;
}

int main()
{
    int n;
    cin >> n;
    int t = 0;
    for(int i = 0;i < n;i++)
    {
        int a;
        cin >> a;
        bool flg = true;
        flg = checkNotOdd(a);
        if(flg)
        {
            flg = check(a);
        }
        if(flg || a == 2)
        {
            t++;
        }
    }
    cout << t << endl;
}

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

int n,k,Xor;
char ch[200010];
deque <bool> Q;

void work()
{
	scanf("%d %d\n%s",&n,&k,ch+1);
	for (int i=1; i<=n; i++)  Q.push_back(ch[i]=='A');
	for (int i=1; i<=2*n&&i<=k; i++)
		if (Q.front()^Xor)  Q.pop_front(),Q.push_front(Xor);
		else  Q.pop_front(),Q.push_back(Xor),Xor^=1;
	if (k<=2*n)
		for (int i=1; i<=n; i++)  putchar(Q.front()^Xor?'A':'B'),Q.pop_front();
	else
		{
			if (n&1)  putchar(k&1?'A':'B');
			for (int i=1; i<=n/2; i++)  printf("BA");
		}
}

int main()
{
	work();
	return 0;
}


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

int N;
int main () {
  cin >> N;
  cout << N/3 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long int
#define mod(x) ((x % MOD) + MOD) % MOD
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define RFORE(i,a,b) for(int i=(b);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define LB(c,x) (int)(lower_bound(ALL(c),x)-(c).begin())
#define UB(c,x) (int)(upper_bound(ALL(c),x)-(c).begin())
#define COUNT(c,x) (UB(c,x)-LB(c,x))
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (bool)((s).find(e)!=(s).end())
#define PB push_back
#define MP make_pair
#define DEL(v) decltype(v)().swap(v)
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
using namespace std;
template<typename T1, typename T2> using P = pair<T1,T2>;
template<typename T> using V = vector<T>;
struct edge { int from, to; int cost; };
bool operator< (const edge &edge1, const edge &edge2) { return edge1.cost < edge2.cost; };
const int INF = 1e18;
const int MOD = 1e9+7;

template<typename T> ostream& operator << (ostream& s, const V<T>& v) {
   s << "[";
   for (int i = 0; i < v.size(); i++) { s << v[i]; if (i < v.size() - 1) s << " "; }
   s << "]";
   return s;
}

void topological_sort(const V<V<int>>& G, int s, V<int>& idx) {
   queue<int> que;
   que.push(s);
   idx.PB(s);
   while (!que.empty()) {
      int i = que.front(); que.pop();
      for(int j = 0; j < G[i].size(); j++) {
         int to = G[i][j];
         que.push(to);
         idx.PB(to);
      }
   }
}

signed main()
{
   int N; cin >> N;
   V<int> P(N), X(N);
   FOR(i, 1, N) {
      cin >> P[i]; P[i]--;
   }
   FOR(i, 0, N) {
      cin >> X[i];
   }

   V<V<int>> G(N);
   FOR(i, 1, N) {
      G[P[i]].PB(i);
   }

   V<int> idx;
   topological_sort(G, 0, idx);

   V<int> dp1(N, INF);
   RFOR(i, 0, N) {
      int id = idx[i];
      V<V<int>> dp2(G[id].size()+1, V<int>(X[id]+1, INF));
      dp2[0][0] = 0;

      FOR(j, 0, G[id].size()) {
         int to = G[id][j];

         FORE(x, 0, X[id]) {
            if (x + X[to] <= X[id]) {
               dp2[j+1][x + X[to]] = min(dp2[j+1][x + X[to]], dp2[j][x] + dp1[to]);
            }
            if (x + dp1[to] <= X[id]) {
               dp2[j+1][x + dp1[to]] = min(dp2[j+1][x + dp1[to]], dp2[j][x] + X[to]);
            }
         }
      }

      FORE(x, 0, X[id]) {
         dp1[id] = min(dp1[id], dp2[G[id].size()][x]);
      }

      if (dp1[id] == INF) {
         cout << "IMPOSSIBLE" << endl;
         return 0;
      }
   }

   cout << "POSSIBLE" << endl;

   return 0;
}


Measured memory_bytes: 2404
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define endl '\n'
#define mod 1000000007
#define inf 1000000000000000000
const double pi = acos(-1);
const int sz = 200002;
int n, m, q, k;
string s, t;
int main() {
	io
	char c;
	cin>>c;
	cout<<(c >= 'A' && c <= 'Z' ? 'A' : 'a');
}


Measured memory_bytes: 3648
#include<stdio.h>
static const int N=100;

int main(){
  int M[N][N],n,u,k,v,i,j;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      M[i][j]=0;
    }
  }

  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v]=1;
    }
  }

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(j>0){
	printf(" ");
      }
      printf("%d",M[i][j]);
    }
    printf("\n");
  }

  return 0;
}
    
  



Measured memory_bytes: 2108
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class t>
using table = vector<vector<t>>;
const ld eps=1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.answer"

vector<int>sos;
void hurui(const int amax) {
	static bool flag = false;
	if (flag)return;
	sos = vector<int>(amax + 1, true);
	sos[0] = false; sos[1] = false;
	for (int i = 2; i <= amax; ++i) {
		if (sos[i]) {
			for (int j = 2 * i; j <= amax; j += i)sos[j] = false;
		}
	}
}

int main() {
	hurui(100000);
	ld a;
	while (cin >> a) {
		if (!a)break;
		int ans = 0;
		for (int i = 2; i <= a/2; ++i) {
			int j = a - i;
			if (sos[i] && sos[j])ans++;
		}
		cout << ans << endl;

	}
	return 0;
}

Measured memory_bytes: 3036
from collections import defaultdict


def main():
    X, Y = map(int, input().split())
    award = defaultdict(int)
    award[1] = 300000
    award[2] = 200000
    award[3] = 100000
    ans = award[X] + award[Y]
    if X == Y == 1:
        ans += 400000
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 38384
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <queue>
#include <cctype>
#include <climits>
#include <stack>
using namespace std;

//?§??????°??????????????°?????¶????????????????????°
int n,m,h,k;

//???????§???????????§????1day???????????°
int s,t,p;

typedef pair<int,int> P;
typedef pair<P,int> PP;
struct edge{
	int to,cost,time,corp;
	
	edge(int to_,int cost_,int time_,int corp_){
		to=to_; cost=cost_; time=time_; corp=corp_;
	}
	
};
vector<edge> G[100];

const int BIT=1<<8;

// i????????????????????????????????????
int pass_corps[BIT];

// pass_cost[bit] bit?????¨?????????????????????????????????
int pass_cost[BIT];

//corps_cost[bit] bit?????¨???corps??????????????????1day??????????????????
int corps_cost[BIT];

const int INF=1e8;

int solve(int use){
	
	// d[time][pos]
	int d[25][BIT];
	for(int i=0;i<25;i++){
		for(int j=0;j<BIT;j++) d[i][j]=INF;
	}
	
	d[0][s]=corps_cost[use];
	priority_queue<PP,vector<PP>,greater<PP> > q;
	
	// cost,time,pos
	q.push(PP(P(corps_cost[use],0),s));
	while(!q.empty()){
		
		PP pp=q.top(); q.pop();
		
		int cost=pp.first.first,time=pp.first.second,pos=pp.second;
		
		//printf("cost %d, time %d, pos %d\n",cost,time,pos);
		
		if(pos==t) return cost;
		
		if(d[time][pos]<cost) continue;
		
		for(int i=0;i<G[pos].size();i++){
			edge e=G[pos][i];
			int to=e.to,ncost=cost+e.cost,nt=time+e.time,ncorp=e.corp;
			
			//printf("to %d, ncost %d, nt %d ncorp %d\n",to,ncost,nt,ncorp);
			
			if(nt>h) continue;
			
			if(use&(1<<ncorp)) ncost=cost;
			if(ncost<d[nt][to]){
				d[nt][to]=ncost;
				q.push(PP(P(ncost,nt),to));
			}
			
		}
		
	}
	
	return INF;
	
}

int main(){
	
	while(cin>>n>>m>>h>>k,n){
		
		for(int i=0;i<100;i++) G[i].clear();
		for(int i=0;i<BIT;i++){
			pass_corps[i]=0;
			pass_cost[i]=corps_cost[i]=INF;
		}
		for(int i=0;i<m;i++){
			int a,b,c,h,r;
			cin>>a>>b>>c>>h>>r;
			a--; b--; r--;
			
			G[a].push_back(edge(b,c,h,r));
			G[b].push_back(edge(a,c,h,r));
		}
		
		cin>>s>>t>>p;
		s--; t--;
		
		for(int i=0;i<p;i++){
			int l,d;
			cin>>l>>d;
			
			int corps=0;
			for(int j=0;j<l;j++){
				int corp;
				cin>>corp;
				corp--;
				corps|=(1<<corp);
			}
			
			pass_corps[i]=corps;
			pass_cost[corps]=d;
		}
				
		//corps_cost[bit] bit?????¨???corps??????????????????1day??????????????????
		corps_cost[0]=0;
		for(int i=0;i<(1<<k);i++){
			if(corps_cost[i]==INF) continue;
			for(int j=0;j<p;j++){
				corps_cost[i|pass_corps[j]]=min(corps_cost[i|pass_corps[j]],corps_cost[i]+pass_cost[pass_corps[j]]);
			}
		}
		
		int res=INF;
		for(int use=0;use<(1<<k);use++){
			if(corps_cost[use]==INF) continue;
			res=min(res,solve(use));
		}
		if(res==INF) res=-1;
		cout<<res<<endl;	
	}
}

Measured memory_bytes: 3152