akhauriyash/Code-Regression huggingface dataset:
P = gets.to_i
As = gets.split.map(&:to_i)

a, ans = As.dup, Array.new(P, 0)
ans[0] = a[0]
(P - 1).times do |i|
  P.times do |j|
    ans[P - 1 - i] += a[j]
    a[j] = (a[j] * j) % P
  end
  ans[P - 1 - i] = ans[P - 1 - i] % P * (P - 1) % P
end
puts ans.join(' ')

Measured memory_bytes: 2044
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy
const char sp =' ';
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	ll n;
	cin >> n;
	ll i,j;
	int count=0;
	for(i=1;i<=n;i++){
        for(j=1;i*j<n;j++){
            count++;
        }
	}
	cout << count;
	return 0;
}

// read the question correctly (ll vs int)
// template by bqi343


Measured memory_bytes: 3612
#include<algorithm>
#include<functional>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define FOR(itr,data) for(__typeof((data).begin()) itr=(data).begin();itr!=(data).end();++itr)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

typedef unsigned long long UInt64;
typedef long long Int64;

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

using namespace std;

typedef pair<int ,int > P;

int n;

int cnt(int y,int m,int d) {
    int res = d;
    for(int i=1;i<y;i++) {
        for(int j=1;j<=10;j++) {
            res=res+19+((j%2==1||i%3==0)?1:0);
        }
    }
    for(int i=1;i<m;i++) {
       res=res+19+((i%2==1||y%3==0)?1:0);
    }
    return res;
}

int main() {
    cin>>n;
    int a = cnt(1000,1,1);
    rep(i,n) {
        int y,m,d;
        cin>>y>>m>>d;
        cout<<a-cnt(y,m,d)<<endl;
    }
    return 0;
}

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

unsigned long long knapsack(vector<unsigned long long>&weight,vector<unsigned long long>&value,int n,int W)
{   vector<vector<unsigned long long>>dp(n+1,vector<unsigned long long>(W+1,0));
    for(int i=1;i<=n;i++)
    {
      for(unsigned long long w = 1;w<=W;w++)
      {   if(w>=weight[i-1])
        dp[i][w] = max(value[i-1]+dp[i-1][w-weight[i-1]],dp[i-1][w]);
          else dp[i][w] = dp[i-1][w];
      }
         
    }
    return dp[weight.size()][W];
}
int main()
{
     int n,W;
  cin>>n>>W;
  vector<unsigned long long>weight(n),value(n);
  for(int i =0;i<n;i++)
  {
    cin>>weight[i]>>value[i];
  }
  cout<<knapsack(weight,value,n,W)<<endl;
}


Measured memory_bytes: 80256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, R ;
  cin >> N >> R;
 
  if (N >= 10) {
    cout << R << endl;
  }
 
  else if (N < 10) {
    cout << R+(100*(10-N)) << endl;
  }
 

}

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

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  if (N == 1 && M == 1) {
    cout << 1 << endl;
  } else if (N == 1) {
    cout << max(0, M - 2) << endl;
  } else if (M == 1) {
    cout << max(0, N - 2) << endl;
  } else {
    cout << (long long)(N - 2) * (M - 2) << endl;
  }
  return 0;
}

Measured memory_bytes: 256
def makePrimeChecker(n):
    isPrime = [True] * (n + 1)
    isPrime[0] = False
    isPrime[1] = False
    for i in range(2, int(n ** 0.5) + 1):
        if not isPrime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            isPrime[j] = False
    return isPrime

Q = int(input())
L = [0]
isPrime = makePrimeChecker(100000)
for i in range(1, 100000):
    if i&1==1 and isPrime[i] and isPrime[(i+1)//2]:
        L.append(L[-1] + 1)
    else:
        L.append(L[-1])
for i in range(Q):
    l, r = map(int, input().split())
    print(L[r] - L[l-1])


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

int main(){
	int a, b, i, k;
    cin >> a >> b;      //行数をa、列数をbに代入
   
    for (i=0 ; i < b+2; i++){ //最初の行の*の個数は、列数bより2つ多い
      cout << "#" ;//*をb+2個表示
    }
      cout << endl;//次の行に移動
  
    string c;
    for (i=0; i < a; i++){ 
      cout << "#" ;
      cin >> c; //文字列の格納
      cout << c; //格納後,出力  
      cout << "#" << endl;
      }
     for (i=0 ; i < b+2; i++){ //最後の行の*の個数は、列数bより2つ多い
      cout << "#" ;//*をb+2個表示
    }
      }

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

int main(){

  int k;
  cin >> k;
  string s;
  cin.ignore();
  getline(cin,s);
  
    if(s.size() <= k){
      cout << s;
    }else{
      for(int i=0; i < k; i++){
          cout << s[i];
      }
      cout << "...";
  }
 
  
  return 0;
}

Measured memory_bytes: 3620
#include<iostream>
#include<string>
using namespace std;
 
int main(){
	string s, e, ans = "NO";

	cin >> s;

	//高々100文字なので、文字列の抜き出し方（消し方）を全て網羅する
	for(int i = 0; i < s.size(); i++){
		for(int j = 0; j <= s.size() - i; j++){
			e = s;	//erase()すると文字列が変わっちゃうので、元々の文字列を別の変数にコピーした方をいじくる
			if(e.erase(i,j) == "keyence") {	//erase(n, m):文字列のn文字目からn文字消す
				ans = "YES";
			}
		}
	}
 
	cout << ans << endl;
}

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


int main(){
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    
    int n;
    cin>>n;
    
    bool sol = false;
    for(int i=0;i<=50 && !sol;i++){
        //if(i==1) continue;
        for(int j=0;j<=14;j++){
            //if(j==1) continue;
            if(i*4+j*7==n){
                sol = true;
                break;
            }
            
        }
    }
    
    if(sol){
        cout<<"Yes\n";
    }else{
        cout<<"No\n";
    }
    
    return 0;
}


Measured memory_bytes: 256
N = int(input())
ans = []
n = 4/N
for i in range(1,3501):
    flag = True
    for j in range(1,3501):
        if(4*i*j-N*j-N*i==0):
            continue
        k = N*i*j/(4*i*j-N*j-N*i)
        if(int(k)==k and k>0):
            ans=[i,j,int(k)]
            flag = False
            break
    if(not flag):
        break
print(ans[0],ans[1],ans[2])


Measured memory_bytes: 41196
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const long long INF = 1e18;
# define len(x) ((int)(x).size())
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define foreps(i, m, n) for(int i = m;i < n;i++)
# define ALL(x) (x).begin(), (x).end()
# define rall(x) (x).rbegin(), (x).rend()
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 solve(ll N, ll M) {
    if (N == M) return N / 2;
    else if (M <= 1) return 0;

    ll ans = 0;
    if (M < N) return M / 2;
    ans += N, M -= N * 2;
    if (4 <= M) ans += M / 4;
    return ans;
}

int main() {
    ll N, M; cin >> N >> M;
    cout << solve(N, M) << endl;
}

Measured memory_bytes: 3588
#include<iostream>
#include<stack>
#include<climits>
using namespace std;

char o[200];
int d[200],n,j;
string s;
int x(int _){
    if(o[j]>='0'&&o[j]<='9')return o[j++]-'0';
    int k=j,r;
    o[j++]=='*'?r=1:r=0;
    while(d[k]+1==d[j])
        if(o[k]=='*')r*=x(j);
        else r+=x(j);
    return r;
}
int main(){
    while(cin>>n,n){
        d[n]=0;
        for(int i=0;i<n;i++){
            cin>>s;
            o[i]=s[s.length()-1];
            d[i]=s.length();
        }
        j=0;
        cout<<x(0)<<endl;
    }
}

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

int main() {
	int a[4][3][10] = {0};
	int n;
	int b, f, r, v;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d %d %d %d", &b, &f, &r, &v);
			a[b - 1][f - 1][r - 1] = a[b - 1][f - 1][r - 1] + v;
	
	}
	

	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 10; k++) {
				printf(" %d",a[i][j][k]);
			}
			printf("\n");
		}
		if (i == 3) {
			break;
		}
		else {
			printf("####################\n");
		}
		
		
	
	}

}



Measured memory_bytes: 2120
#include "stdio.h"

int day;
int decide;
int pasta[101] = {};
int dp[101][4][4] = {};
int box;
int ans = 0;

int main() {
	scanf("%d %d", &day,&decide);
	for (int i = 0; i < decide; i++) {
		scanf("%d", &box);
		scanf("%d", &pasta[box]);
	}
	//for (int i = 1; i < day+1; i++)printf("%d\n", pasta[i]);
	if (pasta[1] == 0) {
		dp[1][0][1] = 1;
		dp[1][0][2] = 1;
		dp[1][0][3] = 1;
	}
	else {
		dp[1][0][pasta[1]] = 1;
	}
	if (pasta[2] == 0) {
		for (int i = 1; i < 4; i++) {
			for (int j = 1; j < 4; j++) {
				dp[2][i][j] += dp[1][0][i];
			}
		}
	}
	else {
		for (int i = 1; i < 4; i++) {
			dp[2][i][pasta[2]] += dp[1][0][i];
		}
	}
	for (int i = 3; i <= day; i++) {
		if (pasta[i] == 0) {
			for (int j = 1; j < 4; j++) {
				for (int k = 1; k < 4; k++) {
					for (int l = 1; l < 4; l++) {
						if (!((l == j)&&(l == k))) {
							dp[i][k][l] += dp[i - 1][j][k];
							dp[i][k][l] %= 10000;
			//				printf("%d??\??????%d %d %d????£?????????????%d??????\n", i,j, k, l, dp[i][k][l]);
						}
					}
				}
			}
		}
		else {
			for (int j = 1; j < 4; j++) {
				for (int k = 1; k < 4; k++) {
					if (!((pasta[i] == j)&&(pasta[i] == k))) {
						dp[i][k][pasta[i]] += dp[i - 1][j][k];
						dp[i][k][pasta[i]] %= 10000;
			//			printf("%d??\??????%d %d %d????£?????????????%d??????\n", i,j, k, pasta[i], dp[i][k][pasta[i]]);
					}
				}
			}
		}
	}
	if (pasta[day] == 0) {
		for (int i = 1; i < 4; i++) {
			for (int j = 1; j < 4; j++) {
				ans += dp[day][i][j];
				ans %= 10000;
			}
		}
	}
	else {
		for (int i = 1; i < 4; i++) {
			ans += dp[day][i][pasta[day]];
			ans %= 10000;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1028
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
typedef long long int ll;

#define INF (1e9)

int N, W;

int main() {
    cin >> N >> W;

    vector<int> w(N), v(N);
    for (int i = 0; i < N; i++) {
        cin >> w[i] >> v[i];
    }

    vector<vector<ll> > dp(N + 1, vector<ll>(W + 1, 0));
    for (int j = 0; j < W + 1; j++) {
        for (int i = 0; i < N + 1; i++) {
            if (i + 1 < N + 1 and j + w[i] < W + 1)
                dp[i + 1][j + w[i]] = max(dp[i][j] + v[i],
                                          dp[i + 1][j + w[i]]);

            if (i + 1 < N + 1)
                dp[i + 1][j] = max(dp[i][j], dp[i + 1][j]);
            // cout << i << ' ' << j << ' ' << dp[i][j] << endl;
        }
    }

    cout << dp[N][W] << endl;
    return 0;
}


Measured memory_bytes: 80256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<iterator>
#include<complex>
#include<stack>
#include "stdio.h"
using namespace std;

#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)

using ll = long long;
using Pii = pair<int, int>;

const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const long long mod_const = 1e9+7;

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

using MIte = multimap<ll, ll, greater<ll> >::iterator;



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

	// long long?
	int N;
	cin >> N;

	vector<int> vL(N, 0);
	rep(i, N) cin >> vL[i];

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

	int ans = 0;
	for (int i = 0; i != N - 2; ++i) {
		if (i != 0) {
//			if (vL[i - 1] == vL[i]) continue;
		}
		for (int j = i + 1; j != N - 1; ++j) {
//			if (vL[j - 1] == vL[j]) continue;

			vector<int>::iterator it1 = lower_bound(vL.begin(), vL.end(), vL[j]); // max(vL[j], vL[j] - vL[i]));
			vector<int>::iterator it2 = lower_bound(vL.begin(), vL.end(), vL[i] + vL[j]);
			int a = (int)(it2 - vL.begin());
			int b = (int)(it1 - vL.begin());
			ans += a - max(b, j + 1);
//			ans += (it2 - it1);
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import java.io.*;

public class Main{
    public static void main(String[] args){
      BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
      try{
      String line = reader.readLine();
      int x = Integer.parseInt(line); 
      System.out.println(x*x*x);
      }catch(IOException e) {
        System.out.println(e);
      }  
    }
}


Measured memory_bytes: 24216
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
using Graph = vector<vector<int>>;
const ll mod=1000000007;
const int MAX_N = 1000;         // n の最大値
 
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
 
int main() {
ll a,b,c;
cin>>a>>b>>c;
if((a<c&&c<b)||(a>c&&c>b)){
cout << "Yes" << endl;}
else{
cout << "No" << endl;}}


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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
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 int MOD = 1000000007;


int main() {
    string s;
    cin >> s;
    int n = s.size();
    if (s[0] == s[1]) {
        cout << "1 2" << endl;
        return 0;
    }

    REP(i, n - 2) {
        if (s[i] == s[i + 2] || s[i + 1] == s[i + 2]) {
            cout << i + 1 << " " << i + 3 << endl;
            return 0;
        }
    }
    cout << "-1 -1" << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
#include <ctime>
#include <complex>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 2020000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    for(auto itr = a.begin(); itr != a.end(); itr++){
		cout << *itr << " ";
	}
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){
	cout << "debug: " << a << " " << b << "\n";
}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << "debug: " << a << " " << b << " " << c << "\n";
}
void mark() {cout << "#" << "\n";}
ll pcount(ll x) {return __builtin_popcountll(x);}
const int mod = 1e9 + 7;
//const int mod = 998244353;

struct UnionFind{
	vl p;
	vl rank;
	vl cnt;

	UnionFind(ll n){
		rank.resize(n,0);
		p.resize(n,0);
		cnt.resize(n,0);
		rep(i,n){
			p[i] = i;
			rank[i] = 0;
			cnt[i] = 1;
		}
	}

	ll find(ll x){
		if(x != p[x]) p[x] = find(p[x]);
		return p[x];
	}

	bool same(ll x, ll y){
		return find(x) == find(y);
	}

	void unite(ll x, ll y){
		x = find(x);
		y = find(y);
		if(x == y) return;
		if(rank[x] > rank[y]){
			p[y] = x;
			cnt[x] += cnt[y];
		}else{
			p[x] = y;
			cnt[y] += cnt[x];
			if(rank[x] == rank[y]) rank[y]++;
		}
	}

	ll size(ll x){
		return cnt[find(x)];
	}
};

int main(){
	int n; cin >> n;
	UnionFind uf(n);
	vector<P> ls(n);
	rep(i,n){
		int x,y; cin >> x >> y; x--;
		ls[x] = P(y,i);
	}
	set<P> se;
	rep(i,n){
		auto itr = se.upper_bound(ls[i]);
		if(itr == se.begin()){
			se.emplace(ls[i]);
		}else{
			for(auto it = se.begin(); it != itr; it++){
				uf.unite(ls[i].second, (*it).second);
			}
			int a = (*se.begin()).first;
			se.erase(se.begin(), itr);
			se.emplace(a,ls[i].second);
		}
	}
	rep(i,n) cout << uf.size(i) << "\n";
}

Measured memory_bytes: 15972
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


bool visited[410][410];
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int H, W;
string S[410];
ll White = 0, Black = 0;
int dfs(int x, int y) {
    visited[x][y] = true;
    if(S[x][y] == '.') White++;
    else Black++;
    rep(k, 4) {
        int xx = x + dx[k];
        int yy = y + dy[k];
        if(xx < 0 || xx >= H || yy < 0 || yy >= W) continue;
        if(visited[xx][yy]) continue;
        if(S[x][y] == S[xx][yy]) continue;
        dfs(xx, yy);
    }
}

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> H >> W;
    
    rep(i, H) cin >> S[i];
    ll ans = 0;
    rep(i, H) {
        rep(j, W) {
            if(visited[i][j]) continue;
            White = 0, Black = 0;
            dfs(i, j);
            ans += White * Black;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 18048
import bisect
n=int(input())
a,b,c=[sorted(map(int,input().split())) for i in range(3)]
ans=0
for i in b:
      x=bisect.bisect_left(a,i)
      y=n-bisect.bisect_right(c,i)
      ans+=x*y
print(ans)

Measured memory_bytes: 22720
#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

struct Node {
	int key;
	Node* next;
	Node* prev;
};

class List {
	private:
		Node* nil;
	
	public:
		List() {
			nil = (Node*)malloc(sizeof(Node));
			nil->key = 0;
			nil->next = nil;
			nil->prev = nil;
		}

		Node* find(int key) {
			for(Node* node = nil->next;node != nil;node = node->next) {
				if(node->key == key) return node;
			}
		}

		void insert(Node* x) {
			x->next = nil->next;
			nil->next->prev = x;
			nil->next = x;
			x->prev = nil;
		}

		void add(int x) {
			Node* tmp = (Node*)malloc(sizeof(Node));
			tmp->key = x;
			insert(tmp);
		}

		void delete_x(int key) {
			Node* x = find(key);
			if(x == nil) return;

			x->prev->next = x->next;
			x->next->prev = x->prev;
			free(x);
		}

		void deleteFirst() {
			Node* x = nil->next;
			x->prev->next = x->next;
			x->next->prev = x->prev;
			free(x);
		}

		void deleteLast() {
			Node* x = nil->prev;
			x->prev->next = x->next;
			x->next->prev = x->prev;
			free(x);
		}

		void show() {
			int space = 0;

			for(Node* node = nil->next;node != nil;node = node->next) {
				if(space) cout << " ";
				cout << node->key;
				space = 1;
			}

			cout << endl;
		}
};

int main() {
	List list;
	int n;
	cin >> n;
	string op;
	int x;

	for(int i = 0;i < n;i++) {
		cin >> op;

		if(op == "insert") {
			cin >> x;
			list.add(x);
		} else if(op == "delete") {
			cin >> x;
			list.delete_x(x);
		} else if(op == "deleteFirst") {
			list.deleteFirst();
		} else if(op == "deleteLast") {
			list.deleteLast();
		}
	}

	list.show();

	return 0;
}




Measured memory_bytes: 34268
#include <cstdio>
using namespace std;

int main()
{
	bool c[2][200];
	int cnt[2];
	
	int n;
	while (scanf("%d", &n), n){
		cnt[0] = cnt[1] = 0;
		for (int i = 0; i < 200; i++){
			c[0][i] = false;
			c[1][i] = true;
		}
		
		for (int i = 0; i < n; i++){
			int a;
			scanf("%d", &a);
			a--;
			
			c[0][a] = true;
			c[1][a] = false;
		}
		
		int field = -1;
		int t = 0;
		while (cnt[0] < n && cnt[1] < n){
			bool f = false;
			for (int i = field + 1; i < 2 * n; i++){
				if (c[t][i]){
					c[t][i] = false;
					cnt[t]++;
					field = i;
					t = !t;
					
					f = true;
					break;
				}
			}
			
			if (!f) {field = -1; t = !t;}
		}
		
		for (int i = 0; i < 2; i++){
			printf("%d\n", n - cnt[!i]);
		}
	}
	
	return 0;
}

Measured memory_bytes: 1028
import numpy as np
n = int(input())
a = [int(i) for i in input().split(" ")]
b = [0 for i in range(n//2)] + a[n//2:]
for i in range(n//2-1, -1, -1):
    if sum(b[i::i+1])%2 != a[i]:
        b[i] = 1
te = sum(b)
if te == 0:
    print(0)
else:
    print(te)
    print(" ".join(map(str, np.where(np.array(b)==1)[0]+1)))

Measured memory_bytes: 24432
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
typedef long long ll;
int main(){
	int n,h,w;
	cin >> n>>h>>w;

	cout << (n-w+1)*(n-h+1) << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        String s = sc.next();

        for(int i = 0; i < s.length() ; i+=2){
            System.out.print(s.charAt(i));
        }
        System.out.println();
    }
}


Measured memory_bytes: 29448
#include <iostream>
#include <algorithm>
#include <map>
#include <string>

#define ll long long

using namespace std;

ll gcd(ll x, ll y){
    if(y == 0){
        return x;
    }else{
        return gcd(y, x%y);
    }
}

int main() {
    int n;
    ll T[100];

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

    for(int i = 1; i < n; i++){
        ll g = gcd(T[i], T[i-1]);
        if(T[i]%T[i-1] != 0 && T[i-1]%T[i] != 0){
            T[i] = T[i-1] / g * T[i];
        }else{
            if(T[i] < T[i-1]){
                T[i] = T[i-1];
            }
        }
    }

    cout << T[n-1] << endl;
}



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

template<typename T> struct BinaryIndexedTree {
    vector< T > data;
    BinaryIndexedTree(int sz) { data.assign(++sz, 0); }
    T sum(int k) {
        if (k < 0) return T(0);
        T ret = 0;
        for (++k; k > 0; k -= k & -k) ret += data[k];
        return (ret);
    }
    T sum(int l, int r) {
        assert(l <= r);
        return sum(r - 1) - sum(l - 1);
    }
    void add(int k, T x) {
        for (++k; k < data.size(); k += k & -k)
            data[k] += x;
    }
};

lint comb(int n) {
    return (lint)n * (n + 1) / 2;
}

const int MX = 200200;
int N;
vector<int> graph[MX];
vector<int> clr[MX];

int l[MX], r[MX], idx;
void euler_tour(int cur, int prv = -1) {
    l[cur] = idx++;
    for (auto& nxt: graph[cur]) {
        if (prv == nxt) continue;
        euler_tour(nxt, cur);
    }
    r[cur] = idx;
}

signed main() {

    cin >> N;
    rep(i, 0, N) {
        int c;  cin >> c;
        clr[--c].emplace_back(i);
    }
    rep(i, 0, N - 1) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        graph[a].emplace_back(b);
        graph[b].emplace_back(a);
    }
    
    euler_tour(0);  // 頂点0を根とするオイラーツアー
    // rep(i, 0, N) cerr << l[i] << ' '; cerr << endl;
    // rep(i, 0, N) cerr << r[i] << ' '; cerr << endl;

    BinaryIndexedTree<int> bit(N);
    rep(i, 0, N) bit.add(i, 1);
    
    // 色cについて求める
    rep(c, 0, N) {
        // 下から順に舐めていく
        vector<pair<int, int>> rev;
        vector<int>& vs = clr[c];
        sort(vs.begin(), vs.end(), [&](int a, int b){
            return l[a] > l[b];
        });
        lint ans = comb(N);
        for (int v: vs) {
            int sub = 1;
            for (int child: graph[v]) {
                if (l[v] > l[child]) continue;
                int sz = bit.sum(l[child], r[child]);
                ans -= comb(sz);
                sub += sz;
            }
            bit.add(l[v], -sub);
            rev.emplace_back(l[v], sub);
        }
        ans -= comb(bit.sum(0, N));
        cout << ans << endl;
        for (auto& e: rev) {
            bit.add(e.first, e.second);
        }
    }

}


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

int main() {
	int num1, num2;

	cin >> num1 >> num2;

	int result;
	result = num1 - num2 * 2;

	if (result >= 0) {
		cout << result << "\n";
	}
	else {
		cout << 0 << "\n";
	}

	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> l(n);
  for (int i = 0; i < n; i++) {
    cin >> l.at(i);
  }
  sort(l.begin(), l.end());
  int ans = 0;
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      int a = l.at(i) + l.at(j);
      auto iter = lower_bound(l.begin(), l.end(), a);
      int b = iter - l.begin() - j - 1;
      ans += b;
    }
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
a,b = map(int, input().split())

lista = [1,3,5,7,8,10,12]
listb = [4,6,9,11]

tmp = a in listb

# print(tmp)

if (a == 2 and b ==2):
    print("Yes")
elif (a in listb and b in listb):
    print("Yes")
elif (a in lista and b in lista):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#pragma once
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////

signed main(){
  string x;cin>>x;stack<char> st;int n = x.length();
  rep(i,n){
    if(st.empty() || st.top() == 'T' || x[i] == 'S'){
      st.push(x[i]);
    }else{
      st.pop();
    }
  }
  cout << st.size() << endl;
}


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

int main(){
    int n, m;
    cin >> n >> m;
    // int A[n-1][m-1];
    int A[100][100];
    for (int i = 0; i < n; ++i){
        for (int j = 0; j < m; ++j) cin >> A[i][j]; 
    }
    // int B[m-1];
    int B[100];
    for (int i = 0; i < m; ++i) cin >> B[i];
    
    
    for (int i = 0; i < n; ++i){
        int ans = 0;
        for (int j = 0; j < m; ++j){
            ans += A[i][j] * B[j];
        }
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3132
/*---------------------------------- NEVER GIVE UP --------------------------------------------*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef double ld;
typedef pair<ll,ll> pii;
typedef tree<ll, null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define debug1(x) cerr<<#x<<" : "<<(x)<<endl
#define debug2(x,y) cerr<<#x<<" : "<<(x)<<" "<<#y<<" : "<<(y)<<endl
#define debug3(x,y,z) cerr<<#x<<" : "<<(x)<<" "<<#y<<" : "<<(y)<<" "<<#z<<" : "<<(z)<<endl
#define fastt ios_base::sync_with_stdio(false); cin.tie(NULL) ; cout.tie(NULL)

const ll modd=1e9+7;
const ll inff=1e18;

ll poww(ll a,ll b){
  ll ans=1;
  while(b){
    if(b&1LL) ans=(ans*a);
    a=(a*a);
    b=b>>1LL;
  }
  return ans;
}

/*-----------------------------------------------------------------------------------------------*/

int main(){
  fastt;
   
  ll x;
  cin >> x;

  ll lcm = 360 * x / __gcd(360LL,x);

  cout << lcm / x << endl;
 
  return 0;
}


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

int A[55], B[55];

int main() {
    int N, a, b, x, y;
    a = b = x = y = 0;
    scanf("%d", &N);
    for (int i = 0; i < N; i++) {
        scanf("%d", &A[i]);
        a = max(a, A[i]);
        b = min(b, A[i]);
        if (a == A[i]) x = i;
        if (b == A[i]) y = i;
    }

    printf("%d\n", 2*N-1);
    if (abs(a) >= abs(b)) {
        for (int i = 0; i < N; i++) printf("%d %d\n", x+1, i+1);
        for (int i = 1; i < N; i++) printf("%d %d\n", i, i+1);
    } else {
        for (int i = 0; i < N; i++) printf("%d %d\n", y+1, i+1);
        for (int i = N; i > 1; i--) printf("%d %d\n", i, i-1);
    }

    return 0;
}

Measured memory_bytes: 256
# input
n, q = map(int, input().split())
a = [0 for i in range(n+1)]
s = input()
for i in range(n):
    a[i+1] = a[i] + (1 if s[i:i+2] == 'AC' else 0)
# for m in re.finditer('AC', s):
#    a[m.start()] = 1
for i in range(q):
    l, r = map(int, input().split())
    print(a[r-1]-a[l-1])

Measured memory_bytes: 7680
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
#include <cmath>
using namespace std;
#define vsort(vec) sort(vec.begin(), vec.end())
#define vreverse(vec) reverse(vec.begin(), vec.end())
using ll =long long;
using ull =unsigned long long;
const ll INF =1001001001;
const double PI = 3.14159265358979323846;
//10億7。　　　100000007

//最大公約数
ll gcd(ll a, ll b){
   if (a%b==0){
       return(b);
   }else{
       return(gcd(b,a%b));
   }
}
//最小公倍数
ll lcm(ll a, ll b){
   return a*b/gcd(a,b);
}


int main(){
cout<<fixed<<setprecision(10);
//cin.tie(0); ios::sync_with_stdio(false);

  ll N;
  cin>>N;
  int AC=0;
  int WA=0;
  int TLE=0;
  int RE=0;
  vector<string> vec(N);
  for(int i=0;i<N;i++){
    cin>>vec[i];
    if(vec[i]=="AC"){
      AC++;}
    if(vec[i]=="WA"){
      WA++;
    }
    if(vec[i]=="TLE"){
      TLE++;
    }
    if(vec[i]=="RE"){
      RE++;
    }
  }
  
  cout<<"AC x "<<AC<<endl;
  cout<<"WA x "<<WA<<endl;
  cout<<"TLE x "<<TLE<<endl;
  cout<<"RE x "<<RE<<endl;
  
}



Measured memory_bytes: 6420
#include <iostream>
#include <string>

using namespace std;

int main(){
    string n;
    cin >> n;
    int num = stoi(n);
    int ans = 0;
    for(int i = 1; i < n.size(); i += 2){
        int cnt = 9;
        for(int j = 1; j < i; j++){
            cnt *= 10;
        }
        ans += cnt;
    }
    if(n.size() % 2){
        for(int i = stoi("1" + string(n.size() - 1, '0')); i <= num; i++){
            ans++;
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
# D - Leaping Tak
n,k = map(int,input().split())
lr = [tuple(map(int,input().split())) for _ in range(k)]
MOD = 998244353

# 累積和を使ってもらうdpを効率よく実現する。

dp = [0 for _ in range(n+1)]
dpsum = [0 for _ in range(n+1)]
dp[1] = 1
dpsum[1] = 1
for i in range(2,n+1):
  for li,ri in lr:
    r = i-li
    if r < 1:
      continue
    l = max(i-ri-1,0)
    dp[i] += dpsum[r]-dpsum[l]
    dp[i] %= MOD
  dpsum[i] += dpsum[i-1]+dp[i]
  dpsum[i] %= MOD
print(dp[n])

Measured memory_bytes: 100224
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef unsigned long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr int INF = 2e9;
constexpr int mod = 1e9+7;

int main() {
  int n;
  ll d;
  cin >> n >> d;
  d *= d;
  int res = 0;
  rep(i,n) {
    ll x, y;
    cin >> x >> y;
    x *= x;
    y *= y;
    if (x + y <= d) res++;
  }  
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

int K, S;

void solve() {
    int ans = 0;
    rep(x, K + 1)rep(y, K + 1) {
        int z = S - x - y;
        if(0 <= z&&z <= K)ans++;
    }
    cout << ans << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    while(cin >> K >> S) {
        solve();
    }
}


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

int main()
{
  ll a;
  cin>>a;
  ll b[a],x=0,y=0,sum=0;
  string s[a];
  for(ll i=0;i<a;i++)
  {
  cin>>s[i]>>b[i];
  sum+=b[i];
  }
  string s2;
  cin>>s2;
  for(ll i=0;i<a;i++)
  {
      if(s2.compare(s[i])==0)
      {
          x=i+1;
          break;
      }
  }
  for(ll i=x;i<a;i++)
  y+=b[i];
  cout<<y<<endl;
}
     
  

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  string a;
  cin>>a;
  char b,c,d,e;
  b=a.at(0);
  c=a.at(1);
  d=a.at(2);
  e=a.at(3);
  if(b==c&&c==d&&d==e)
    cout<<"No";
  else if((b==c&&d==e)||(b==d&&c==e)||(b==e&&c==d)||(c==d&&b==e)||(c==e&&d==b)||(d==e&&b==c))
    cout<<"Yes";
  else
    cout<<"No";
  return 0;
}
    


Measured memory_bytes: 3100
# Your code here!

arr = gets.strip.split
a = arr[0].to_i
b = arr[1].to_i
c = arr[2].to_i


if a == b && a != c && b != c 
  puts "Yes"
elsif a == c && a != b && b != c 
  puts "Yes"
elsif c == b && a != c && b != a 
  puts "Yes"
elsif
  puts "No"
end

Measured memory_bytes: 1788
#include<iostream>
using namespace std;
long dp[1111][1111],mod=1e9+7;
main()
{
	int n,k;cin>>n>>k;
	dp[0][0]=1;
	for(int i=0;i<=n;i++)
	{
		for(int j=!i;j<=k;j++)
		{
			dp[i][j]=((j?dp[i][j-1]:0)+(i<j?0:dp[i-j][j]))%mod;
		}
	}
	cout<<(n<k?0:dp[n-k][k])<<endl;
}



Measured memory_bytes: 11788
#include <bits/stdc++.h>
#define int long long 

using namespace std;
const int maxn = 107;
string s[maxn];

int n, m, dist[maxn][maxn];
deque<pair<int, pair<int, int>>> dq;

int dx[] = {1, 0};
int dy[] = {0, 1};
bool inside(int x, int y)
{
	return (1 <= x && x <= n && 1 <= y && y <= m);
}

int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	if(fopen("test.inp", "r")) freopen("test.inp", "r", stdin);
	fill_n(&dist[0][0], maxn * maxn, 1e9);
	cin >> n >> m;
	for(int i = 1; i <= n; i++)
	{
		cin >> s[i];
		s[i] = ' ' + s[i];
	}
	dist[1][1] = 1;
	dq.emplace_back(1, make_pair(1, 1));
	while(dq.size())
	{
		auto it = dq.front();
		dq.pop_front();
		if(dist[it.second.first][it.second.second] != it.first) continue;
		int x = it.second.first;
		int y = it.second.second;
		for(int i = 0; i < 2; i++)
		{
			int nx = x + dx[i];
			int ny = y + dy[i];
			if(!inside(nx, ny)) continue;
			int cost = (s[nx][ny] != s[x][y]);
			if(dist[nx][ny] > dist[x][y] + cost)
			{
				dist[nx][ny] = dist[x][y] + cost;
				if(cost == 0) dq.emplace_front(dist[nx][ny], make_pair(nx, ny));
				else dq.emplace_back(dist[nx][ny], make_pair(nx, ny));
			}
		}
	}
	int gau = dist[n][m];
	if(s[1][1] == '.') cout << gau / 2;
	else cout << (gau + 1) / 2;

}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
  int A, B, a, b;
  cin >> A >> B >> a >> b;
  cout << a-(b-B) << endl;
  cout << b+(a-A) << endl;
  cout << a-(b-B)-(a-A) << endl;
  cout << b+(a-A)-(b-B) << endl;
}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using Pair = pair<int, int>;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define INF 1000000007
#define SEP " "

int     main()
{
	int a;
	for (int i = 0; i < 5; i++) {
		cin >> a;
		if (a == 0)
		{
			cout << i+1 << endl;
			return (0);
		}
	}
}


Measured memory_bytes: 3632
import java.util.*;

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

        Scanner scan = new Scanner(System.in);
        int  num = scan.nextInt();
        
        while(num != 0){
            //make a dictionaly
            String d_b[] = new String[num];
            String d_a[] = new String[num];
            for (int i=0; i<num; i++){
                d_b[i] = scan.next();
                d_a[i] = scan.next();
            }
            
            //read a sentence
            int len = scan.nextInt();
            String sentence[] = new String[len];
            for (int i=0; i<len; i++){
                sentence[i] = scan.next();
            }
            
            //change a sentence
            for (int i=0; i<len; i++){
                for (int j=0; j<num; j++){
                    if(sentence[i].equals(d_b[j])){//ccan't use ==
                        sentence[i] = d_a[j];
                        break;
                    }
                }
            }
            String str = String.join("", sentence);
            
            System.out.println(str);
            
            num = scan.nextInt();
        }
    }
}


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

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld double
#define built __builtin_popcountll
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll vis[666666];
int const M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e9+10;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll x,y;
    cin >> x >> y;
    ll res=x+ y/2;
    cout << res;
    return 0;
}
/* The judge is never wrong! Your code is buggy 😈
   Look for:
 * * an easier and alternate approach
 * * read the problem statement carefully
 * * if concept is correct and still WA, try with a different implementation
 * * special cases (n=1?)
 * * overflow (ll vs int?)
 * * array bounds
 * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/
 */


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <unordered_set>
#include <unordered_map>
#include <cstring>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
static const int INF = 1000010000;
static const int MOD = 100000;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define SORT(v) sort(v.begin(), v.end());
#define pb push_back
#define mp make_pair
#define np next_permutation
#define pq priority_queue

int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};

struct edge {
	int u, v;
	ll cost;
};

int main() {
	int sum = 0;
	int c[3][3];
	REP(i, 3) {
		REP(j, 3) {
			cin >> c[i][j];
		}
	}
	bool flag = false;
	REP(i, c[0][0] + 1) {
		int a[3], b[3];
		REP(bi, 3) {
			b[bi] = c[0][bi] - i;
		}
		REP(ai, 3) {
			a[ai] = c[ai][0] - b[0];
		}
		if (i != a[0]) break;
		bool t = true;
		REP(x, 3) {
			REP(y, 3) {
				if (c[x][y] != a[x] + b[y]) t = false;
			}
		}
		if (t) flag = true;
	}
	if (flag) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
import java.io.{PrintWriter, _}
import java.util
import java.util._


object Main {
  def main(args: Array[String]): Unit = {
    val inputStream = System.in
    val outputStream = System.out
    val in = new InputReader(inputStream)
    val out = new PrintWriter(outputStream)
    val solver = new Task
    solver.solve(1, in, out)
    out.close()
  }

  class Task {
    def solve(testNumber: Int, in: InputReader, out: PrintWriter): Unit = {
      val a = in.next
      val b = in.next
      val c = in.next
      val d = a + b + c
      if (d.toInt % 4 == 0) out.println("YES") else println("NO")
    }
  }

  class InputReader(val stream: InputStream) extends AutoCloseable {
    //reader = new BufferedReader(new FileReader(stream), 32768);
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer = new StringTokenizer("")


    def next: String = {
      while ( {
        tokenizer == null || !tokenizer.hasMoreTokens
      }) try
        tokenizer = new StringTokenizer(reader.readLine)
      catch {
        case e: IOException =>
          throw new RuntimeException(e)
      }
      tokenizer.nextToken
    }

    def nextLine: String = {
      try
        return reader.readLine
      catch {
        case e: IOException =>
          e.printStackTrace()
      }
      ""
    }

    def nextInt: Int = next.toInt

    def nextLong: Long = next.toLong

    override def close(): Unit = {
    }
  }

}


Measured memory_bytes: 27212
#include<stdio.h>
#include<string.h>
int main()
{
	char s[200];
	int n,i=0;
	gets(s);
	n=strlen(s);
	printf("%c",s[0]);
	for(i=1;i<n;i++)
	if(s[i]>='A'&&s[i]<='Z'&&s[i-1]==' ')
	printf("%c",s[i]);
}

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

#ifdef DONLINE_JUDGE
//freopen("a.in", "r", stdin);
//freopen("a.out","w",stdout); // console output is better (in most cases)
#else
// add i/o method of specific testing system
#endif

using namespace std;

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

    int m, n;
    while (cin >> m >> n, m || n)
    {
        for (int i = 0; i < m; ++i)
        {
            for (int j = 0; j < n; ++j)
            {
                if (i == 0 || j == 0 || i == m - 1 || j == n - 1)
                    cout << "#";
                else
                    cout << ".";
            }
            cout << endl;
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3024
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

int main() {
	int a,b,c;
	cin>>a>>b>>c;
	if(a+b==c || a+c==b || b+c==a){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
import functools

def compr(tup1, tup2):
    if tup1[1] < tup2[1]:
        return -1
    elif tup1[1] == tup2[1]:
        if tup1[2] > tup2[2]:
            return -1
        else:
            return 1
    else:
        return 1


n = int(input())

rests = []

for i in range(n):
    nome, score = input().split()
    rests.append((i, nome, int(score)))

rests.sort(key=functools.cmp_to_key(compr))

for tup in rests:
    print(tup[0] + 1)


Measured memory_bytes: 3572
import sys
input = sys.stdin.readline

N = int(input())
A = [int(x) for x in input().split()]

last = A[0]
direction = 0

answer = 1
for a in A[1:]:
    if direction == 0:
        if last < a:
            direction = 1
        elif last > a:
            direction = -1
        last = a
        continue
    if direction == 1:
        if last <= a:
            last = a
            continue
        else:
            last = a
            direction = 0
            answer += 1
            continue
    if direction == -1:
        if last >= a:
            last = a
            continue
        else:
            last = a
            direction = 0
            answer += 1
            continue

print(answer)

Measured memory_bytes: 14252
#include<stdio.h>
#include<queue>
#define INF 1000
using namespace std;
typedef struct{
	int a,b;
	int t;
}data;
bool con[50][50];
int dp[2500][2500];
int dx[4]={-1,0,0,1};
int dy[4]={0,1,-1,0};
int min(int a,int b){return a<b?a:b;}
int main(){
	queue<data> que;
	int w,h,sx,sy,tx,ty,i,j;
	while(1){
	scanf("%d %d",&w,&h);
	if(w==0)return 0;
	scanf("%d %d",&sx,&sy);
	scanf("%d %d",&tx,&ty);
	for(i=0;i<w*h;i++)for(j=0;j<w*h;j++)dp[i][j]=INF;
	int p;
	for(i=0;i<h;i++)for(j=0;j<w;j++){
		scanf("%d",&p);
		if(p==1)con[i][j]=false;
		else con[i][j]=true;
	}
	data dat;
	dat.a=(sy-1)*w+sx-1;
	dat.b=(ty-1)*w+tx-1;
	dat.t=0;
	dp[dat.a][dat.b]=0;
	que.push(dat);
	int ax,ay,bx,by;
	int nax,nay,nbx,nby;
	while(!que.empty()){
		data d=que.front();
		que.pop();
		if(d.t>=100)continue;
		ax=d.a%w;
		ay=d.a/w;
		bx=d.b%w;
		by=d.b/w;
		for(i=0;i<4;i++){
			if(ax+dx[i]>=0&&ax+dx[i]<w&&ay+dy[i]>=0&&ay+dy[i]<h&&con[ay+dy[i]][ax+dx[i]]){
				nax=ax+dx[i];
				nay=ay+dy[i];
			}else{nax=ax;nay=ay;}
			if(bx-dx[i]>=0&&bx-dx[i]<w&&by-dy[i]>=0&&by-dy[i]<h&&con[by-dy[i]][bx-dx[i]]){
				nbx=bx-dx[i];
				nby=by-dy[i];
			}else{nbx=bx;nby=by;}
			if(dp[nay*w+nax][nby*w+nbx]==INF){
				dp[nay*w+nax][nby*w+nbx]=d.t+1;
				data d2;
				d2.a=nay*w+nax;
				d2.b=nby*w+nbx;
				d2.t=d.t+1;
				que.push(d2);
			}
		}
	}
	int ans=INF;
	for(i=0;i<w*h;i++){
		ans=min(ans,dp[i][i]);
	}
	if(ans==INF)printf("NA\n");
	else printf("%d\n",ans);
	}
}
				

Measured memory_bytes: 26108
c1 = gets.split.map(&:to_i)
c2 = gets.split.map(&:to_i)
c3 = gets.split.map(&:to_i)

b1 = 1000
b2 = 1000
b3 = 1000
ans = 0

(0..100).each do |a1|
  a2 = a1 - (c1[0]-c2[0]) #() = a1-a2
  a3 = a1 + (c3[0]-c1[0]) #() = a3-a1
  if a2 < 0 || a3 < 0 || a2 > 100 || a3 > 100
    next
  else
    b1 = c1[0] - a1 
    b2 = c1[1] - a1
    b3 = c1[2] - a1
    if b1 < 0 || b2 < 0 || b3 < 0 || b1 > 100 || b2 > 100 || b3 > 100
      next
    else      
    score = [[a1, a2, a3], [b1, b2, b3]]
    
    c22 = c2[1] == score[0][1] + score[1][1]
    c32 = c3[1] == score[0][2] + score[1][1]
    c23 = c2[2] == score[0][1] + score[1][2]
    c33 = c3[2] == score[0][2] + score[1][2]
    if c22 && c32 && c23 && c33
      ans += 1
    end
      
    end  
  end
end

if ans > 0 then
  puts 'Yes'
else
  puts 'No'
end

Measured memory_bytes: 1788
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))

s = 0
mn = 1 << 25
for i in range(N):
    t = abs(A - (T - H[i] * 0.006))
    if (mn >= t):
        s = i + 1
        mn = t
print(s)

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

int main() {
  int n;
  cin >> n;
  int b[n-1];
  for (int i=0; i<n-1; i++) cin >> b[i];
  if (n == 2) cout << b[0] * 2 << "\n";
  else {
    int ans=b[0];
    ans += b[n-2];
    for (int i=0; i<n-2; i++) ans += min(b[i], b[i+1]);
    cout << ans << "\n";
  }
}

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

int main(){
  int n;
  cin >> n;
  long long int L0 = 2,L1 = 1;
  for(int i = 0; i < n-1; i++){
    L0 += L1;
    swap(L0,L1);
  }
  cout << L1 << endl;
  return 0;
}


Measured memory_bytes: 256