akhauriyash/Code-Regression huggingface dataset:
numof500 = int(input())
numof100 = int(input())
numof50  = int(input())
moneyneeded = int(input())
 
counter = 0
for i in range(numof500 + 1):
  for j in range(numof100 + 1):
    for k in range(numof50 + 1):
      if 500 * i + 100 * j + 50 * k == moneyneeded:
        counter += 1
 
print(counter)

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

const int N = 1e6+1;

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

vector<int> prime;

void enum_prime() {
  vector<bool> is_prime(N, true);
  for (int i = 2; i < N; ++i) {
    if (is_prime[i] == false) continue;
    prime.push_back(i);
    for (int j = 2*i; j < N; j += i) is_prime[j] = false;
  }
  return;
}

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  enum_prime();
  bool p = true;

  int c = 0;
  rep(i, n) if (a[i] > 1) ++c;
  if (c > prime.size()) p = false;
  else {
    vector<int> b(n);
    vector<int> cp(prime.size(), 0);
    rep(i, n) b[i] = a[i];
    rep(i, n) {
      if (b[i] == 1) continue;
      for (int j = 0; prime[j] <= 1000; ++j) {
        if (b[i] % prime[j] == 0) {
          if (cp[j] == 1) p = false;
          cp[j] = 1;
        }
        while (b[i] % prime[j] == 0) b[i] /= prime[j];
      }
      if (b[i] > 1) {
        int j = lower_bound(prime.begin(), prime.end(), b[i]) - prime.begin();
        if (cp[j] == 1) p = false;
        cp[j] = 1;
      }
    }
  }

  int g = a[0];
  for (int i = 1; i < n; ++i) g = gcd(g, a[i]);

  if (p) cout << "pairwise coprime" << endl;
  else if (g == 1) cout << "setwise coprime" << endl;
  else cout << "not coprime" << endl;

  return 0;
}

Measured memory_bytes: 11952
#include <bits/stdc++.h>
#define int long long int
#define IOS ios_base::sync_with_stdio(false), cin.tie(NULL);
#define fr(i,a,b)  for(int i=a;i<=b;i++)
#define rf(j,b,a)  for(int j=b;j>=a;j--)
#define frr(k,a,b) for(int k=a;k<=b;k++)
#define mp make_pair
#define pb push_back
#define MOD 1000000007
#define ss second
#define ff first

using namespace std;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
#define E 2000 
bool sortinrev(const pair<int,int> &a,  
               const pair<int,int> &b) 
{ 
     if(a.first==b.first)
     {
     return (a.second < b.second); 
     }
     else
     {
       return (a.first > b.first); 
     }
     
} 
bool sortin(const pair<int,int> &a,  
               const pair<int,int> &b) 
{ 
     return (a.second < b.second);   
} 
signed main()
{   
  IOS


int n,k;
cin>>n;
int dp[n+1][4];
int arr[n+1][4];
for(int i=1;i<=n;i++)
{
for(int j=1;j<=3;j++)
{
  cin>>arr[i][j];
}
}
dp[1][1]=arr[1][1];
dp[1][2]=arr[1][2];
dp[1][3]=arr[1][3];

for(int i=2;i<=n;i++)
{
int t1 =  max(dp[i-1][2],dp[i-1][3]);
int t2 =  max(dp[i-1][1],dp[i-1][3]);
int t3 =  max(dp[i-1][2],dp[i-1][1]);
dp[i][1]= arr[i][1]+t1;
dp[i][2]= arr[i][2]+t2;
dp[i][3]= arr[i][3]+t3;
}

int ans = max(dp[n][1],max(dp[n][2],dp[n][3]));
cout<<ans<<endl;
}




Measured memory_bytes: 9844
from math import log2

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

Bits = [0 for _ in range(41)]
for i, a in enumerate(A):
    b = bin(a)[2:]
    for i in range(len(b)-1, -1, -1):
        Bits[len(b)-i-1] += int(b[i])

P = 0
for i in range(40, -1, -1):
    b = Bits[i]
    if b <= N-b and P + 2**i <= K:
        P += 2**i
#print(P)
ans = 0
for a in A:
    ans += P^a
print(ans)

Measured memory_bytes: 14620
#include <bits/stdc++.h>
#define rep(i,n) for (ll i=0; i<(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
int main(){
    char c; cin >> c;
    if (c=='a' || c=='e' || c=='i' || c=='o' || c=='u') cout << "vowel" << endl;
    else cout << "consonant" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <string>
#include <vector>
 
using namespace std;
typedef long long ll;
using gra = vector<vector<ll>>;
using gram = vector<unordered_map<ll,ll>>;
 
typedef unsigned long long ull;
 
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; }
 
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <class T> T dup(T a, T b) { return (a + b - 1) / b; }
template <class T> T modpow(T x, T p, T m) { T a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
// template <class T> void prim(T a) { for(ll i=0;i<a.size();++i) { cout << a[i]; } cout << "\n"; }
template< typename T >
T mod_pow(T x, T n, const T &p) {
  T ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= p;
    (x *= x) %= p;
    n >>= 1;
  }
  return ret;
}
 
#define mod 1000000007LL
#define INF 10000000000000000LL
 
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep1(i, n) for (ll i = 1; i <= n; ++i)
#define rrep(i, n) for (int i = (n - 1); i >= 0; --i)
#define rrep1(i, n) for (int i = n; i > 0; --i)
 
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
//#define modpow(x, p, m) { ll a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
 
#define m0(h) memset(h, 0, sizeof(h))
#define m1(h) memset(h, 1, sizeof(h))
#define m(h, n) memset(h, (n), sizeof(h))
#define all(n) (n).begin(),(n).end()
#define bit(n) (1LL << (n))
#define pb push_back
 
//#ifdef LOCAL
//
//#define dpri(...) fprintf(stderr, __VA_ARGS__)
//#define pria(g) rep(i,g.size()){ cout << i << "{"; rep(j,g[i].size()) cout << g[i][j] << " "; cout << "}" << "\n"; }
//#else
//#define dpri(...) 42
//#define pria(g) 42
//#endif
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // ---------------------
  // コーディング開始
  // ---------------------
  ll h,n;
  cin >> h >> n;
  ll a;
  ll ans=0;
  rep(i,n){
    cin >> a;
    ans +=a;
  }
  if(h<=ans) pri( "Yes");
  else pri("No");
  return 0;
}


Measured memory_bytes: 256
from sys import stdin
import sys
import math

# A, B, C = [int(x) for x in stdin.readline().rstrip().split()]
# A = list(map(int, input().split()))
s = int(input())
if s % 1000 == 0:
    print('0')
    sys.exit()
print(((s//1000)+1)*1000-s)


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

class unionfind {
    vector<int> par, sz;

public:
    unionfind(int n) {
        for (int i = 0; i < n; i++) {
            par.push_back(i);
            sz.push_back(1);
        }
    }

    int find(int n) {
        if (par.at(n) == n) return n;
        return find(par.at(n));
    }

    void merge(int m, int n) {
        m = find(m);
        n = find(n);
        if (m == n) return;
        if (sz.at(m) > sz.at(n)) swap(m, n);
        par.at(m) = n;
        sz.at(n) += sz.at(m);
    }

    int maxgroup() {
        int res = 0;
        for (int x : sz) {
            res = max(res, x);
        }
        return res;
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    unionfind t(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        t.merge(a, b);
    }
    cout << t.maxgroup() << endl;
}


Measured memory_bytes: 5044
#include <iostream>
using namespace std;
int main(void){
	long long int a[4],ans;
	int i,j;
	cin >> a[0] >> a[1] >> a[2] >> a[3];
	ans = a[1]*a[3];
	for (i=0;i<2;i++) {
		for (j=2;j<4;j++) {
			if (ans < a[i]*a[j]) {
				ans = a[i]*a[j];
			}
		}
	}
	cout << ans << '\n';
}


Measured memory_bytes: 3648
#include "bits/stdc++.h"
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << endl

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  
 string s;
 cin>>s;
 vector<int>rem(2020);
 rem[0]=1;
 
 int n=(int)s.length();
 long long pow=1;
 long long val=0;
 long long ans=0;
 for(int i=n-1;i>=0;i--){

      val+=((s[i]-'0')*pow);
      
      ans+=rem[val%2019];
      
      rem[val%2019]++;

      pow*=10;

      pow%=2019;
      val%=2019;
        
 }
cout<<ans<<endl; 

       
  return 0;
}


Measured memory_bytes: 3720
#include<iostream>
#include<string.h>
#include<string>
using namespace std;

int StrtoInt(char *s){
	int num = 0;
	while(*s!='\0'){
		if( *s >= '0' && *s <= '9' ){
			num = num*10 + *s - '0';
			++s;
		}
	}
	return num;
}

char* UpBabbleSort(char *r, const char *s){
	strcpy(r,s);

	for(int j=0;j<8;++j){
		for(int i=0;i<8-j;++i){
			if( r[i] <= r[i+1] ){
				char t = r[i];
				r[i] = r[i+1];
				r[i+1] = t;
			}
		}
	}
	r[8]='\0';
	return r;
}

char* DownBabbleSort(char *r, const char *s){
	UpBabbleSort(r,s);
	char temp[8+1];

	for(int i=0;i<8;++i)
		temp[i] = r[7-i];
	for(int i=0;i<8;++i)
		r[i] = temp[i];
	
	return r;
}



int main(){
	int n;
	char s[8+1];
	int max, min;
	char smax[9];
	char smin[9];
	int i;

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

		max = StrtoInt(UpBabbleSort(smax,s));
		min = StrtoInt(DownBabbleSort(smin,s));
		cout << max-min << endl;
	}
}

Measured memory_bytes: 1172
#include <bits/stdc++.h>
//登録しよう！→ https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define gre greater //sortを降順にする
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示
const string YES = "Yes";
const string NO = "No";

void solve(std::string S){
  bool ans = true;
  for (size_t i = 0; i < S.length(); i++) {
    if((i+1)%2 == 0 &&!(S[i] == 'L' || S[i] == 'U' || S[i] == 'D')){
      ans = false;
    }
    if((i+1)%2 == 1 &&!(S[i] == 'R' || S[i] == 'U' || S[i] == 'D')){
      ans = false;
    }
  }
  cout << (ans?"Yes":"No") << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
    std::cin >> S;
    solve(S);
}


Measured memory_bytes: 768
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int x = in.nextInt();

			out.println(x < 1200 ? "ABC" : "ARC");

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}


Measured memory_bytes: 20436
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;

int H,W;
char field[9][9];
int dx[2] = {0,1};
int dy[2] = {1,0};

bool DFS(int x,int y) {
  if (x == H - 1 && y == W - 1) {
    return true;
  } else {
    bool res = false;
    for (int i = 0; i < 2; i++) {
      int fx = x + dx[i];
      int fy = y + dy[i];
      if (field[fx][fy] == '#' && fx <= H - 1 && fy <= W - 1) {
        if (DFS(fx,fy)) {
          res = true;
        }
      } 
    }
    return res;
  }
}

int main() {
  cin >> H >> W;
  int cnt = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> field[i][j];
      if (field[i][j] == '#') {
        cnt++;
      }
    }
  }
  bool ans = true;
  if (!DFS(0,0)) {
    ans = false;
  }
  if (H + W - 1 != cnt) {
    ans = false;
  }
  if (ans) {
    cout << "Possible" << endl;
  } else {
    cout << "Impossible" << endl;
  }
  return 0;
}

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

using namespace std;

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

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

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

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

    int n;
    ll sum, d[112345], a[112345];

    cin >> n;
    REP(i, n)
    {
        cin >> a[i];
        sum += a[i];

        if (i > 0)
            d[i - 1] = a[i] - a[i - 1];
    }

    if (n == 1)
    {
        cout << "YES" << endl;
        return 0;
    }

    d[n - 1] = a[0] - a[n - 1];

    if (sum % ((ll)n * (ll)(n + 1) / 2))
    {
        cout << "NO" << endl;
        return 0;
    }

    ll t = sum / ((ll)n * (ll)(n + 1) / 2);

    ll cnt = 0;
    REP(i, n)
    {
        d[i] -= t;

        if (d[i] % n || d[i] > 0)
        {
            cout << "NO" << endl;
            return 0;
        }

        cnt -= d[i] / n;
    }

    if (cnt == t)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int A,B,C,X,ans=0;

int main(){
cin>>A>>B>>C>>X;
  for(int a=0;a<=A;a++)
  {
     for(int b=0;b<=B;b++)
     {
        for(int c=0;c<=C;c++)
        {
          if(500*a+100*b+50*c==X)
          {
            ans++;
          }
        }
     }
  }
  cout<<ans<<endl;
}





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

int A[26];
int B[26];

int main()
{
    string a,b;
    cin>>a>>b;
    for(int i=0;i<a.length();i++)
        A[a[i]-'a']++;
    for(int i=0;i<b.length();i++)
        B[b[i]-'a']++;
    sort(A,A+26);
    sort(B,B+26);
    for(int i=0;i<26;i++)
        if(A[i]!=B[i]){
            cout<<"No";
            return 0;
        }
    cout<<"Yes";
    return 0;
        
}


Measured memory_bytes: 776
import collections

N = int(input())
S = []
for n in range(N):
    S.append(input())

c = collections.Counter(S)
most_common = c.most_common()
#print(most_common)

max_count = most_common[0][1]

# for t in most_common:
#     print(t[1])
c_list = [t[0] for t in most_common if t[1] == max_count]
# print(sorted(c_list))

out = sorted(c_list)
for o in out:
    print(o)


Measured memory_bytes: 49176
#include <iostream>
#include <string>
 
using namespace std;
 
int main()
{
    string str, action;
    int q;
    int i;
    int a, b;
 
    cin >> str;
 
    cin >> q;
 
    for (i = 0; i < q; i++){
        cin >> action;
        if (action == "print"){
            cin >> a >> b;
            for (int j = a; j <= b; j++){
                cout << str[j];
            }
            cout << endl;
        }
        else if (action == "reverse"){
 
            cin >> a >> b;
 
            string temp;
 
            int k = 0;
 
            for (int j = a; j <= b; j++){
                temp[k] = str[j];
                k++;
            }
            k = 0;
            for (int j = b; j >= a; j--){
                str[j] = temp[k];
                k++;
            }
        }
        else if (action == "replace"){
            cin >> a >> b;
 
            string str2;
 
            cin >> str2;
 
            int k = 0;
 
            for (int j = a; j <= b; j++){
                str[j] = str2[k];
                k++;
            }
        }
    }
 
    return 0;
}

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

using namespace std;
const int N = 25;
int a[N], b[N], c[N];

int main()
{
    int n; cin >> n;
    for (int i = 1; i <= n; i ++) cin >> a[i];
	for (int i = 1; i <= n; i ++) cin >> b[i];
  	for (int i = 1; i <= n - 1; i ++) cin >> c[i];
  	int ans = 0;
	for (int i = 1; i <= n; i ++) {
      ans += b[a[i]];
      if (a[i] + 1 == a[i + 1]) ans += c[a[i]];
    }
  	cout << ans << "\n";
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//{akari : 1D, yukari : 2D, maki : 3D} vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//{akane : ascending order, aoi : decending order} priority queue
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Libraries ---------------------------------//

//------------------------------- Dubug Functions ---------------------------//

inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}

//------------------------------- Solver ------------------------------------//

void solve()
{
    int n, m;
    cin >> n >> m;
    akari<int> hs(n);
    for (int i = 0; i < n; i++)
    {
        cin >> hs[i];
    }
    yukari<int> g(n);
    while (m--)
    {
        int a, b;
        cin >> a >> b;
        a--, b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        bool ok = 1;
        for (int j : g[i])
        {
            if (hs[i] <= hs[j])
            {
                ok = 0;
            }
        }
        if (ok)
        {
            ans++;
        }
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 8784
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using intpair=pair<int,int>;
using llpair=pair<ll,ll>;
using llvec=vector<ll>;
using llmat=vector<vector<ll>>;
#define PI 3.141592653589793
#define llmattp(name,a,b,num) name(a,vector<ll>(b,num))
#define INTINF 1<<30
#define LLINF 1LL<<60
#define ABS(x) ( (x)>0 ? (x) : -(x) )
#define gsort(vbeg,vend) sort(vbeg,vend,greater<>())

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

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

ll gcd(ll a, ll b) { //最大公約数
	if(a==0||b==0) return 0;
	if(a<b) swap(a,b);
	ll tmp = a%b;
	while(tmp!=0) {
		a = b;
		b = tmp;
		tmp = a%b;
	}
	return b;
}

ll factorial(ll x) { //階乗
	ll f=1;
	for(ll i=2; i<x; i++) {
		f*=i;
	}
	return f;
}

ll nPr(ll n, ll r) {
	ll result=1;
	for(ll i=r+1; i<=n; i++) result*=i;
	return result;
}

ll nCr(ll n, ll r) {
	if (n == r) { return 1; }
	if (r > n) { return 0; }

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

	if (n == 0) { return 0; }
	if (r == 0) { return 1; }
	if (r == 1) { return n; }

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

	return (ll)result;
}

ll GreaterBinarySearch(ll *array, ll key, ll max, ll min) { //にぶたんgreater
	if(array[max]<array[min]) {
		return NULL;
	} else {
		ll mid = max + (min-max)/2;
		if(array[mid]<key) {
			return GreaterBinarySearch(array,key,max,mid-1);
		} if(array[mid]>key) {
			return GreaterBinarySearch(array,key,mid+1,min);
		} else {
			return mid;
		}
	}
}

int DigitNum(ll n) { //桁数
	int digit=0;
	ll wari=1LL;
	while(n/wari) {
		digit++;
		wari*=10;
	}
	return digit;
}

bool IsPrime(ll num) { //素数判定
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

	double sqrtNum = sqrt(num);
	for (ll i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// 素数ではない
			return false;
		}
	}

	// 素数である
	return true;
}

vector<ll> Divisor(ll x) { // 約数列挙
	vector<ll> result;
	ll i=1LL;
	for( ; i*i<x; i++) {
		if(x%i) continue;
		result.push_back(i);
		result.push_back(x/i);
	}
	if(i*i==x&&x%i==0)
		result.push_back(i);
	
	sort(result.begin(),result.end());
	return result;
}

vector<llpair> PrimeFact(ll x) { // 素因数分解 {素因数,指数}
	vector<llpair> result;
	ll ex=0LL;
	if(x%2==0) {
		while(x%2==0) {
			x/=2;
			ex++;
		}
		result.push_back({2,ex});
	}

	for(ll i=3LL; i*i<=x; i+=2) {
		if(x%i) continue;

		ex=0LL;
		while(x%i==0) {
			x/=i;
			ex++;
		}
		result.push_back({i,ex});
	}

	if(x!=1) result.push_back({x,1});

	return result;
}

bool Palind(string s) { //回文判定
	return s == string(s.rbegin(), s.rend());
}

struct Node{
	vector<int> next;
	int prev;
	ll cnt;
};

int main() {
	int N; cin>>N;
	ll K; cin>>K;
	
	ll A[N]; for(int i=0; i<N; i++) cin>>A[i];
	sort(A,A+N);

	ll mingcd=A[0];
	for(int i=1; i<N; i++) {
		mingcd=gcd(mingcd,A[i]);
	}

	if(A[N-1]>=K&&K%mingcd==0)
		cout<<"POSSIBLE"<<endl;
	else
		cout<<"IMPOSSIBLE"<<endl;
}


Measured memory_bytes: 1024
"use strict";
const main = arg => {
  let N = arg.split(" ")[0]*1;
  let D = arg.split(" ")[1]*1 + 1;
  let count = 0;
  while(N > 0){
  	N = N - 2*D;
    N = N + 1;
    count++;
  }
  console.log(count);
  
}

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


Measured memory_bytes: 7372
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <functional>
#include <array>

using namespace std;

int main(){
    int D, N;
    cin >> D >> N;

    int ans = 0;
    while(N > 0){
        ans += pow(100, D);
        int po = pow(100, D+1);
        if(ans % po != 0){
            --N;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define print(x,y) (cout << (x) << (y))
#define inf INT_MAX
#define sz(x) (ll)x.size()
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair< int , pii> piii;
typedef pair<int,bool> pib;
typedef vector<pii> vii;
typedef vector<pib> vib;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef pair<string,string> pss;
typedef vector<pss> vss;
const int MOD = 1e9 + 7; //998244353;


int main(){
   int n , w;
   cin >> n >> w;
   int weight[n];
   int cost[n];
   for(int i = 0;i<n;i++)cin >> weight[i] >> cost[i];
   ll dp[w+1];
   fill(dp , dp + w + 1 , 0);
   for(int i = 0;i<n;i++){
       for(int j = w - weight[i];j>=0;j--){
           dp[j + weight[i]] = max(dp[j + weight[i]] , dp[j] + cost[i]);
       }
   }
   ll ans = 0;
   for(ll i : dp)ans = max(i , ans);
   cout << ans;
}





Measured memory_bytes: 1024
#pragma region Macros
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;
#pragma endregion

void solve() {
    int n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for (int i=0; i<n; i++) {
        cin >> a.at(i);
    }
    vector<ll> alt;
    for (int i=0; i<n; i++) {
        ll cur = 0;
        for (int j=i; j<n; j++) {
            cur += a.at(j);
            alt.push_back(cur);
        }
    }
    sort(alt.begin(), alt.end(), greater<ll>());
    ll res = 0;
    for (int i=50; i>=0; i--) {
        int cnt = count_if(alt.begin(), alt.end(), [i, res](ll a){ return (a & (res + (1LL << i))) == (res + (1LL << i));});
        if (cnt >= k) {
            res += (1LL << i);
        }
    }
    cout << res << "\n";
}

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

    solve();

    return 0;
}


Measured memory_bytes: 6000
#include <iostream>
#include <assert.h>
#include <vector>

#include <cmath>
#include <algorithm>
#include <string>
#include <set>
#include <climits>

#define N 4
#define N2 16

using namespace std;

// const int N = 4;
// const int N2 = 16;

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


struct Node
{
	int puzzle[N2];
	int space;
	int md;
};

class Npuzzle
{
private:
	Node s_node;
	int limit;
	int md[N2][N2];
	// vector<int> path;
	int ans;
public:
	Npuzzle() {
		s_node = Node();
		int in[N2];
		for (int i = 0; i < N2; ++i)
		{
			int tmp;
			scanf("%d", &tmp);
			// cin >> tmp;
			if(tmp == 0) {
				tmp = N2;
				s_node.space = i;
			}
			s_node.puzzle[i] = tmp;
		}
		set_md();
		s_node.md = get_md_sum(s_node.puzzle);
	}

	int get_md_sum(int *puzzle) {
		int sum = 0;
		for (int i = 0; i < N2; ++i)
		{
			if(puzzle[i] == N2) continue;
			sum += md[i][puzzle[i]-1];
		}
		return sum;
	}

	void set_md() {
		for (int i = 0; i < N2; ++i)
		{
			for (int j = 0; j < N2; ++j)
			{
				md[i][j] = abs(i / N - j / N) + abs(i % N - j % N);
			}
		}
	}

	bool dfs(Node cur_n, int depth, int pre) {
		if(cur_n.md == 0 ) {
			ans = depth;
			return true;
		}
		if(depth + cur_n.md > limit) return false;
		int s_x = cur_n.space / N;
		int s_y = cur_n.space % N;
		for (int i = 0; i < 4; ++i)
		{
			Node new_n = cur_n;
			int new_x = s_x + dx[i];
			int new_y = s_y + dy[i];
			if(new_x < 0  || new_y < 0 || new_x >= N || new_y >= N) continue; 
			if(max(pre, i) - min(pre, i) == 2) continue;

			//incremental manhattan distance
			new_n.md -= md[new_x * N + new_y][new_n.puzzle[new_x * N + new_y] - 1];
			new_n.md += md[s_x * N + s_y][new_n.puzzle[new_x * N + new_y] - 1];

			swap(new_n.puzzle[new_x * N + new_y], new_n.puzzle[s_x * N + s_y]);
			new_n.space = new_x * N + new_y;
			// assert(get_md_sum(new_n.puzzle) == new_n.md);
			// return dfs(new_n, depth+1, i);
			if(dfs(new_n, depth + 1, i)){
				// path[depth] = i;
				return true;
			}
		}
		return false;
	}

	void ida_star() {
		for (limit = s_node.md; limit < 1000; ++limit)
		{
			// path.resize(limit);
			if(dfs(s_node, 0, -10)) {
				cout << limit << endl;
				// string str = "";
				// for (int i = 0; i < limit; ++i)
				// {
				// 	str += dir[path[i]];
				// }
				// cout << str << endl;
				return;
			}
		}
	}

	void exec() {
		ida_star();
	}
};


int main() {
	Npuzzle np = Npuzzle();
	np.exec(); 
}

Measured memory_bytes: 3244
char a[17]="0 0";main(i,j){for(;a[2]=*a=48,scanf("%[^\n]\n",a+5),a[8];puts(a)){for(i=4;++i<9;)for(j=4;++j<9;)a[j+5]-a[i]||a[(i!=j)*2]++;}exit(0);}

Measured memory_bytes: 0
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

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

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;
  
  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;
    
    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }
    
    res.push_back({i,ex});
  }
  
  if(n != 1) res.push_back({n,1});
  
  return res;
  
}




int main(){
  ll n; cin >> n; vl num(100001); ll sum = 0;
  
  rep(i,n){
    ll x; cin >> x;
    sum += x;
    num[x]++;
  }
  
  ll q; cin >> q;
  
  rep(i,q){
    ll b,c; cin >> b >> c;
    
    sum += (c-b)*num[b];
    num[c] += num[b];
    num[b] = 0;
    cout << sum << endl;
  }
  
  
}

Measured memory_bytes: 4060
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0083
"""
import sys
import datetime


def solve(yyyy, mm, dd):
    d = datetime.datetime(yyyy, mm, dd)
    meiji_start = datetime.datetime(1868, 9, 8)
    taisho_start = datetime.datetime(1912, 7, 30)
    showa_start = datetime.datetime(1926, 12, 25)
    heisei_start = datetime.datetime(1989, 1, 8)

    result = 'not initialized'
    if d < meiji_start:
        result = 'pre-meiji'
    elif meiji_start <= d < taisho_start:
        result = 'meiji {} {} {}'.format(d.year-meiji_start.year+1, mm, dd)
    elif taisho_start <= d < showa_start:
        result = 'taisho {} {} {}'.format(d.year-taisho_start.year+1, mm, dd)
    elif showa_start <= d < heisei_start:
        result = 'showa {} {} {}'.format(d.year-showa_start.year+1, mm, dd)
    else:
        result = 'heisei {} {} {}'.format(d.year-heisei_start.year+1, mm, dd)
    return result


def main(args):
    for line in sys.stdin:
        yyyy, mm, dd = [int(x) for x in line.strip().split(' ')]
        result = solve(yyyy, mm, dd)
        print(result)


if __name__ == '__main__':
    main(sys.argv[1:])

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

using namespace std;

int main(){
  int x;
  int gcd;
  
  cin >> x;
  
  if(360 % x == 0){
    cout << 360/x << endl;
    return 0;
  }
  
  gcd = __gcd(360, x);
  cout << 360/gcd << endl;
  
  return 0;
}

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

int main() {
    int n,m;
    cin >> n >> m;
    string b;
    bool flag = false;
    int s[5];
    char c[5];
    for(int i=0;i<m;i++) cin >> s[i] >> c[i];
    int num;
    if(n == 1) num = 0;
    else num = pow(10,n-1);
    for(int i=num;i<pow(10,n);i++) {
        bool f1 = true;
        b = to_string(i);
        for(int j=0;j<m;j++) {
            if(b[s[j]-1] != c[j]){
                f1 = false;
                break;
            }
        }
        if(f1) {
            flag = true;
            cout << i << endl;
            return 0;
        }
    }
    cout << "-1" << endl;
}

Measured memory_bytes: 256
#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 n,l;
	cin >> n >> l;
	vector<string> s(n);
	rep(i,n) cin >> s[i];
	sort(s.begin(),s.end());
	rep(i,n){
		cout << s[i];
	}
	cout << endl;
}

Measured memory_bytes: 3640
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

const mod = 1000000007

// 1MB
const ioBufferSize = 1 * 1024 * 1024

var sc = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	sc.Split(bufio.ScanWords)
	return sc
}()

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

type Drink struct {
	Price int
	Stock int
}

type Drinks []Drink

func (d Drinks) Len() int {
	return len(d)
}

func (d Drinks) Less(i, j int) bool {
	return d[i].Price < d[j].Price
}

func (d Drinks) Swap(i, j int) {
	d[i], d[j] = d[j], d[i]
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func main() {
	n, m := nextInt(), nextInt()
	d := make([]Drink, n)

	for i := 0; i < n; i++ {
		d[i] = Drink{nextInt(), nextInt()}
	}
	sort.Sort(Drinks(d))

	res := 0
	for i := 0; i < n && m > 0; i++ {
		c := min(d[i].Stock, m)
		res += d[i].Price * c
		m -= c
	}

	fmt.Println(res)
}


Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    string s;
    cin >> s;
    if(s.size()%2){
        puts("No");
        return 0;
    }
    int n = s.size();
    for (int i = 0; i < n; ++i) {
        if(i%2 == 0 && s[i] != 'h'){
            puts("No");
            return 0;
        }
        if(i%2 == 1 && s[i] != 'i'){
            puts("No");
            return 0;
        }
    }
    puts("Yes");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
string s[3];
for(int i=0;i<3;i++){
    cin>>s[i];
    if(islower(s[i].at(0)))s[i].at(0)=static_cast<char>(toupper(s[i].at(0)));
}
cout<<s[0].at(0)<<s[1].at(0)<<s[2].at(0);
  return 0;
}


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

using namespace std;

#define pb push_back
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(x) x.begin(),x.end()
#define debug(x) cout << x << endl;
#define FOR(x) for(int i =0; i < (x) ; i++)

int main(){
  IOS;
  int n, m;
  cin >> n >> m;
  if(n == m){
  	cout << "Yes";
  }
  else{
  	cout << "No";
  }
  //edit
  return 0;
}


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

using namespace std;
#define lint long long



int main() {
    string S;
    cin >> S;
    
    int N = S.size();
    
    for(int i = 0; i <= N / 2; ++i){
        if(abs(S[i] - S[N - 1 - i]) == 2 | abs(S[i] - S[N - 1 - i]) == 1 ){
        } else {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 512
=begin
－－－－－－－－－－－－－－
N = 入力の長さ
a[] = 数列
num[] = a数列値の約数をカウント
ans = num[i] == 1 の数
－－－－－－－－－－－－－－
1: 1 ~ 10^6 の配列 num を作成
2: a をループ.a[i]とその倍数の値に 1 を加算する
  2.1: a[i] を j とした時に num[j] と num[jの倍数] に 1を加算していく
3: num[i] をループ. 1 の時 ans に 1 を加算する
4: ans を出力する
=end

N = gets.to_i;
a = gets.split.map(&:to_i);
num = Array.new(1000000,0);
max = 0;
(0..(N-1)).each{|i| max = a[i] if a[i] > max};
num[0] = 2;
ans = 0;

for i in 0..(N-1) do
  j = plus = a[i];
  while(j <= max) do
    num[j] = num[j].to_i + 1;
    j += plus;
  end
end

a.each do |i|
  ans += 1 if num[i] == 1;
end

puts ans

Measured memory_bytes: 35188
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const long Mod = 1000000007;

    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var spl = input.ReadLine().Split(' ');
        var n = int.Parse(spl[0]);
        var m = int.Parse(spl[1]);
        var c = int.Parse(spl[2]);

        var bb = ToIntArray(input.ReadLine(), m);
        var aaa = new int[n][];
        for(int i=0; i<n; i++) {
            aaa[i] = ToIntArray(input.ReadLine(), m);
        }

        var co = 0;
        foreach(var aa in aaa) {
            var sum = 0L;
            for(int i=0; i<m; i++) {
                sum += aa[i] * bb[i];
            }
            if (sum > -c) co++;
        }

        return co;
    }

    static int[] ToIntArray(string strs, int n) {
        var ret = new int[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = int.Parse(spl[i]);
        return ret;
    }
}


Measured memory_bytes: 11220
S = input()

f = int(S[:2])
b = int(S[2:])

if 0 < f <= 12:
    if 0 < b <= 12:
        print('AMBIGUOUS')
    else:
        print('MMYY')
else:
    if 0 < b <= 12:
        print('YYMM')
    else:
        print('NA')


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

bool solve() {
    ll A, B, C, K;
    cin >> A >> B >> C >> K;
    for ( int i = 0; i < K; i++ ) {
        if ( B <= A ) B *= 2;
        else if ( C <= B ) C *= 2;
    }
    if ( A < B && B < C) return true;
    return false;
}

int main() {
    string ans = solve() ? "Yes" : "No";
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3620
import java.util.Scanner;
public class Main {
        public static void main(String[] args) {
         
          Scanner sc = new Scanner(System.in);
         
          String s = sc.next(); 
          String t = sc.next();

         String T1 = t.substring(s.length() - 0); // ｔの末尾一文字だけを取り出せる


           if(t.equals(s+T1)) 
           {
             System.out.println("Yes");
           }
        else{
           System.out.println("No");
            }
         }
      }





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

using namespace std;
int MAX = 10001;

class Tree;

class Node {
public:
	enum KindOfNode {
		ROOT, LEAF, INTERNAL
	};
	Node(Tree* tree);
	Tree* tree;
	int parentNodeID;
	int id;//id
	vector<int> childrenNodeID;
	bool operator<(const Node& rhs)const;
	KindOfNode getKindOfNode()const;
	string getNameOfKindOfNode()const;
	string getChildrenListName()const;
	int getDepth()const;
};

class Tree {
public:
	vector<Node> nodes;
	void init();
	void printNodesInfo()const;
};

Node::Node(Tree* treePtr): tree(treePtr), parentNodeID(-1), id(-1), childrenNodeID(vector<int>()){}

bool Node::operator<(const Node& rhs)const { return id < rhs.id; }
Node::KindOfNode Node::getKindOfNode()const {
	if (parentNodeID == -1)return ROOT;
	if (childrenNodeID.empty()) return LEAF;
	return INTERNAL;
}
string Node::getNameOfKindOfNode()const {
	const KindOfNode kind = getKindOfNode();
	if (kind == ROOT)return "root";
	if (kind == LEAF)return "leaf";
	if (kind == INTERNAL)return "internal node";
	return "error";
}
string Node::getChildrenListName()const {
	const size_t k = childrenNodeID.size();
	if (k==0) {
		return "[]";
	}
	else {
		string ret;
		ret.reserve(k * 2);
		ret += ("[" + to_string(childrenNodeID.front()));
			
		for (size_t i = 1; i != k; ++i) {
			ret += (", " + to_string(childrenNodeID.at(i)));
		}
		ret += "]";
		return ret;
	}
}
int Node::getDepth()const {
	int currentParentNodeID = parentNodeID;
	int depth = 0;
	while (currentParentNodeID != -1) {
		++depth;
		currentParentNodeID = tree->nodes.at(currentParentNodeID).parentNodeID;
	}
	return depth;
}

void Tree::init() {
	int n;
	cin >> n;
	nodes.resize(n,Node(this));
	for (int i = 0; i != n; ++i) {
		int id; cin >> id;
		Node& targetNode = nodes.at(id);
		targetNode.id = id;
		int k; cin >> k;
		targetNode.childrenNodeID.resize(k);
		for (int j = 0; j != k; ++j) {
			int child; cin >> child;
			targetNode.childrenNodeID.at(j) = child;
			nodes.at(child).parentNodeID = id;
		}
	}
}
void Tree::printNodesInfo()const {
	for (auto& node : nodes) {
		cout << "node " << node.id
			<< ": parent = " << node.parentNodeID 
			<< ", depth = " << node.getDepth() 
			<< ", " << node.getNameOfKindOfNode() 
			<< ", "<<node.getChildrenListName()
			<< endl;
	}
}

int main()
{
	try {
		Tree tree;
		tree.init();
		tree.printNodesInfo();
	}
	catch (...) {
		//cout << "error" << endl;
	}

	

	return 0;
}


Measured memory_bytes: 8092
from collections import Counter
n,*a=map(int,open(0).read().split())
b=[a[i]+(i+1) for i in range(n)]
c=[(i+1)-a[i] for i in range(n)]
k=set(b)&set(c)
b=Counter(b)
c=Counter(c)
ans=0
for i in k:
  ans+=b[i]*c[i]
print(ans)

Measured memory_bytes: 64024
#include <bits/stdc++.h>
    using namespace std;
    int N,K,cost[100001];
    int h[100001];
    int main()
    {
        cin>>N>>K;

        for(int i = 1; i<=N; i++){
            cin>>h[i];
            cost[i] = INT_MAX;
        }
        cost[1] = 0;
        cost[2] = abs(h[2] - h[1]);

        for (int i = 3; i<=N; i++){
            for(int j = 1; j<=K; j++){
                if(i-j>0){
                    cost[i] = min(cost[i], cost[i-j] + abs(h[i] - h[i-j]));
                }
            }
        }

        cout<<cost[N]<<endl;
        return 0;
    }


Measured memory_bytes: 4360
use std::cmp::min;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let n: usize = sc.read();
    let mut a: Vec<i64> = sc.vec(n);
    let a0 = a[0];
    let ans1 = solve(&a);

    a[0] = 1;
    let ans2 = solve(&a) + (a0 - 1).abs();

    a[0] = -1;
    let ans3 = solve(&a) + (a0 + 1).abs();

    let ans = min(ans1, min(ans2, ans3));
    println!("{}", ans);
}

fn solve(a: &Vec<i64>) -> i64 {
    if a[0] == 0 {
        return 1 << 50;
    }
    let mut ans = 0;
    let mut sum = a[0];
    for i in 1..a.len() {
        if sum > 0 {
            let require = -sum - 1;
            if a[i] > require {
                ans += a[i] - require;
                sum += require;
                assert_eq!(sum, -1);
            } else {
                sum += a[i];
                assert!(sum < 0);
            }
        } else {
            let require = -sum + 1;
            if a[i] < require {
                ans += require - a[i];
                sum += require;
                assert_eq!(sum, 1);
            } else {
                sum += a[i];
                assert!(sum > 0);
            }
        }
    }
    ans
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

using namespace std;

const double pi = acos(-1.0);

int main()
{
    double a, b, x;
    cin >> a >> b >> x;
    x /= a;
    double th;
    if(x <= (a*b) / 2){
        double l = 2 * x / b;
        th = atan2(b, l) / pi * 180;
    }
    else{
        double l = 2 * x / a - b;
        th = atan2(b-l, a) / pi * 180;
    }
    printf("%.10lf\n", th);
}


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

int main() {
  int P;
  int Q;
  int R;
  cin >> P;
  cin >> Q;
  cin >> R;
  int a;
  a = P + Q;
  if ( a > P + R ) a = P + R;
  if ( a > R + Q ) a = R + Q;
  cout << a << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main()
{
    int n,i,c=0,a,b;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d%d",&a,&b);
        if(a==b){
            c++;
        }
        else{
            if(c<3){
                c=0;
            }

        }
    }
    if(c>=3){
    printf("Yes\n");}
    else{
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 1652
#include<iostream>
#include<queue>
#include<memory>
#include<map>
#include<set>
#include<unordered_map>
#include<array>
#include<vector>
#include<algorithm>
#include<list>
#include<limits>
#include<stdio.h>
#include<math.h>
#include<string>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using lst = list<ll>;

const ll MOD = 1000000007;

int main()
{
	int A1, A2, A3;
	cin >> A1 >> A2 >> A3;

	if (A1 + A2 + A3 >= 22)
	{
		cout << "bust" << endl;
	}
	else 
	{
		cout << "win" << endl;
	}


	return 0;
}

Measured memory_bytes: 256
fun main(args:Array<String>) {
    val s = readLine()!!
    var firstBlack = s.indexOf('B')
    if(firstBlack < 0) {
        println(0)
        return
    }
    var ans = 0L
    for(i in (0 until s.length)) {
        if(i < firstBlack) {
            continue
        }
        if(s[i] == 'W') {
            ans += (i-firstBlack)
            firstBlack++
        }
    }
    println(ans)
}


Measured memory_bytes: 40496
N = int(input())
A = list(map(int, input().split()))
A.sort()

max_A = A[-1] + 1
ans = [0] * max_A

for i in A:
    ans[i] += 1
    if ans[i] == 1:
        for j in range(i*2, max_A, i):
            ans[j] = 2

print(ans.count(1))


Measured memory_bytes: 32232