akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>

#include<vector>
using namespace std;
int qread()
{
    int ans=0;char c=getchar();
    while(c<'0' or c>'9') c=getchar();
    while(c>='0' and c<='9') ans=ans*10+c-'0',c=getchar();
    return ans;
}
void qwrite(int num)
{
    if(num>=10) qwrite(num/10);
    putchar('0'+num%10);
}
void qwriteln(int num) {qwrite(num);puts("");}

vector<int> ans[1000];
int main()
{
    int n;scanf("%d",&n);

    bool bk=0;
    for(int s1=1;s1<=1000;s1++)
    {
        if(s1*(s1+1)/2==n)
        {
            puts("Yes");bk=1;

            for(int t=1;t<=s1;t++) ans[1].push_back(t),ans[1+t].push_back(t);

            int now=s1;
            for(int a=2;a<=s1+1;a++)
            {
                for(int b=a+1;b<=s1+1;b++)
                {
                    now++;
                    ans[a].push_back(now);
                    ans[b].push_back(now);
                }
            }

            printf("%d\n",s1+1);
            for(int i=1;i<=s1+1;i++)
            {
                printf("%d ",ans[i].size());
                for(int t=0;t<(int)ans[i].size();t++) printf("%d ",ans[i][t]);
                puts("");
            }
            break;
        }
    }
    if(!bk) puts("No");
}


Measured memory_bytes: 2304
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

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

    if(N < 105) {
        cout << 0;
    }
    else if (105 <= N && N <= 134) {
        cout << 1;
    }
    else if (135 <= N && N <= 164) {
        cout << 2;
    }
    else if (165 <= N && N <= 188) {
        cout << 3;
    }
    else if (189 <= N && N <= 194) {
        cout << 4;
    }
    else if (195 <= N) {
        cout << 5;
    }

    cout << endl;
    return 0;
}

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

using namespace std;

const double EPS = 1e-2;

struct pt {
  long long x, y;
  double ang;
  pt(int _x = 0, int _y = 0) : x(_x), y(_y) {
    ang = atan2(y, x);
  }
};

bool cmp(const pt& a, const pt& b) {
  if(a.ang == b.ang)
    return abs(a.x) + abs(a.y) < abs(b.x) + abs(b.y);
  return a.ang < b.ang;
}

long long score(long long a, long long b) {
  return a*a + b*b;
}

bool valid(double x) {
  return x < M_PI;
}

double angle(double a, double b) {
  return b-a;
}

int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  vector <pt> X;
  for(int i=0; i<n; i++)
  {
    int x, y;
    cin >> x >> y;
    X.push_back(pt(x,y));
  }
  sort(X.begin(), X.end(), cmp);
  int l = 0;
  long long res = 0, tttx = 0, ttty = 0;
  for(int p=0; p<n; p++) {
    while(l - p < n and
          valid(((l/n == p/n) ? 0 : +2*M_PI) + angle(X[p%n].ang, X[l%n].ang))) {
      tttx += X[l%n].x;
      ttty += X[l%n].y;
      res = max(res,score(tttx, ttty));
      l++;
    }
    tttx -= X[p%n].x;
    ttty -= X[p%n].y;
    res = max(res, score(tttx, ttty));
  }
  cout << fixed << setprecision(20) << sqrt(1.0*res) << "\n";
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)
#define ROP(i, n)       for(int i = 1 ; i <= n ; i++)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define VECOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define SORT(obj) sort(ALL(obj))
#define GSORT(obj) sort(ALL(obj) , greater<int>())
#define P pair<int , int>
#define V vector<int>
#define VLL vector<long long>
#define M map<int, int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

int main(void) {

	ios::sync_with_stdio(false);	cin.tie(0);
    int n, m;  cin >> n >> m;
    int ans = n*(n-1)/2 + m*(m-1)/2;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void) {
    while(1){
        string s;
        cin >> s;
        if(s == "-") break;
        int m;
        cin >> m;
        for(int i = 0; i < m; i++){
            int h;
            cin >> h;
            string sx = s.substr(0, h), sy = s.substr(h);
            s = sy + sx;
        }
        cout << s << endl;
    }
    return 0;
}


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

using namespace std;

const int max_n = 200222, inf = 1000111222;

int h, w, n;
vector<int> all_x[max_n];
set<pair<int, int>> all;

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    scanf("%d%d%d", &h, &w, &n);
    for (int i = 0; i < w; ++i) {
        all_x[i].push_back(h);
        all.insert({h, i});
    }
    for (int i = 0; i < h; ++i) {
        all.insert({i, w});
    }
    for (int i = 0; i < n; ++i) {
        int x, y;
        scanf("%d%d", &x, &y);
        --x;
        --y;
        all.insert({x, y});
        all_x[y].push_back(x);
    }
    for (int i = 0; i < w; ++i) {
        sort(all_x[i].begin(), all_x[i].end());
    }
    int x = 0, y = 0, ans = h, cur = 0;
    while (true) {
        int mn = *upper_bound(all_x[y].begin(), all_x[y].end(), x);
        //cout << x << " " << y << " " << cur << " " << mn << ": " << cur + mn - x << endl;
        ans = min(ans, cur + mn - x);
        if (all.count({x + 1, y})) {
            break;
        }
        ++x;
        if (!all.count({x, y + 1})) {
            ++y;
        }
        ++cur;
    }
    printf("%d\n", ans);
    return 0;
}


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

int N;
int A[20];
int x[20][20];
int y[20][20];

int counter(int x){
    if(x==0) return 0;
    return counter(x >> 1) + (x & 1);
}

void solve(){
    cin >> N;
    for(int i = 1; i <= N; i++) {
        cin >> A[i];
        for(int j = 1; j <= A[i]; j++) {
            cin >> x[i][j] >> y[i][j];
        }
    }
    int ans=0;
    for(int bits = 1;bits <(1 << N); bits++){
        bool ok =true;
        for(int i=1;i<=N;i++){
            if(!(bits & (1 << (i-1)))) continue; 
            //1bitずつbitを調べていく bitの値が0のときcontinue
            for(int j=1;j<= A[i]; j++){
                if(((bits >> (x[i][j]-1))& 1) ^ y[i][j]) ok=false;
                //
            }
        }
        if(ok) ans=max(ans,counter(bits));
    }
    cout<<ans<<endl;
    return;
}

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



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

int get_less_count(const string& s, int index)
{
	int count = 0;
	for (int i = index; i >= 0; i--) {
		if (s.at(i) == '<') {
			count++;
		}
		else {
			break;
		}
	}
	return count;
}

int get_greater_count(const string& s, int index)
{
	int count = 0;
	for (int i = index; i < s.size(); i++) {
		if (s.at(i) == '>') {
			count++;
		}
		else {
			break;
		}
	}
	return count;
}

int main() {
	string S;
	cin >> S;
	int less_count = -1;
	int greater_count = -1;
	char prev_moji = 0;
	long long answer = 0;
	for (int i = 0; i < S.size()+1; i++) {
		if (i < S.size() && S.at(i) != prev_moji) {
			less_count = get_less_count(S, i - 1);
			greater_count = get_greater_count(S, i);
			prev_moji = S.at(i);
		}
		else if (prev_moji == '<') {
			less_count++;
			greater_count = 0;
		}
		else {
			less_count = 0;
			greater_count--;
		}
		answer += max(less_count, greater_count);
	}
	cout << answer << endl;
}

Measured memory_bytes: 900
#include <iostream>
using namespace std;
using ll =long long;
int main(){
  ll a,b,c;
  cin >> a >> b >> c;
  ll x=c-a-b;
  if(x<0){
    cout << "No" << endl;
    return 0;
  }
  if(4*a*b<x*x){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
    int k;
    cin >> k;
    auto f = [](int i){
        for(int j = 2; j * j <= i; ++j ) {
            if(i % j == 0) 
                return 0;
        } return 1;
    };
    for(int i = k; ; ++i ) 
        if(f(i))
            return cout << i , 0;
    
    
}

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

int main(){
  int n;
  cin >> n;
  
  map<string, int> mp;
  
  for(int i = 0; i < n; i++) {
  	string s;
  	cin >> s;
  	mp[s]++;
  }
  int m;
  cin >> m;
  for(int i = 0; i < m; i++) {
  	string t;
  	cin >> t;
  	mp[t]--;
  }
  
  int ans = 0;
  
  for(auto p : mp) {
  	ans = max(ans, p.second);
  }
  
  cout << ans << endl;
}

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

typedef unsigned long long ull;
typedef long long ll;

#define rep(i,x) for(int i=0;i<x;i++)

int main()
{
  ll p = 0, g, N, a, b;
  vector<ll> r;

  cin >> g >> N;
  r.resize(g+1,0);
  rep(i,N)
  {
    cin >> a >> b;
    if(a==1 || a==g)
      if(r[b]>0)
      {
        cout <<  "POSSIBLE" << endl;
        return 0;
      }
      else
        r[b]++;


    if(b==1 || b==g)
      if(r[a]>0)
      {
        cout <<  "POSSIBLE" << endl;
        return 0;
      }
      else
        r[a]++;
  }
  cout << "IMPOSSIBLE" << endl;

  return 0;
}



Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<string>
#define rep(i,n) for(int i=0;i<n;i++)
#define ck(a,b) (0<=(a)&&(a)<b)
using namespace std;
int dx[]={-1,1,0,0},dy[]={0,0,-1,1};
struct S{
	int lx,ly,rx,ry;
	S(int a,int b,int c,int d):lx(a),ly(b),rx(c),ry(d){}
};
bool operator<(const S &a,const S &b){
	if(a.lx!=b.lx)return a.lx<b.lx;
	if(a.ly!=b.ly)return a.ly<b.ly;
	return a.rx!=b.rx?a.rx<b.rx:a.ry<b.ry;
}
bool V[50][50][50][50];
int main(){
	int w,h;
	while(cin>>w>>h,w){
		int lx,ly,rx,ry;
		string cavel[h],caver[h];
		rep(i,h)cin>>cavel[i]>>caver[i];
		rep(i,h)rep(j,w){
			if(cavel[i][j]=='L')ly=i,lx=j,cavel[i][j]='.';
			if(caver[i][j]=='R')ry=i,rx=j,caver[i][j]='.';
		}
		vector<S> F; rep(i,h)rep(j,w)rep(k,h)rep(l,w)V[i][j][k][l]=0;
		F.push_back(S(lx,ly,rx,ry)); V[ly][lx][ry][rx]=1;
		int goal=0;
		while(!F.empty()&&!goal){
			vector<S> nF;
			rep(i,F.size())rep(d,4){
				int clx=F[i].lx,cly=F[i].ly,crx=F[i].rx,cry=F[i].ry;
				int nlx=clx+dx[d],nly=cly+dy[d],nrx=crx-dx[d],nry=cry+dy[d];
				if(!ck(nlx,w)||!ck(nly,h)||cavel[nly][nlx]=='#')nlx=clx,nly=cly;
				if(!ck(nrx,w)||!ck(nry,h)||caver[nry][nrx]=='#')nrx=crx,nry=cry;
				if(nlx==clx&&nly==cly&&nrx==crx&&nry==cry)continue;
				if(cavel[nly][nlx]=='%'^caver[nry][nrx]=='%')continue;
				if(cavel[nly][nlx]=='%'&&caver[nry][nrx]=='%'){
					goal=1; goto END;
				}
				if(!V[nly][nlx][nry][nrx]){
					nF.push_back(S(nlx,nly,nrx,nry));
					V[nly][nlx][nry][nrx]=1;
				}
			}
			F=nF;
		}
		END:cout<<(goal?"Yes":"No")<<endl;
	}
	return 0;
}

Measured memory_bytes: 9252
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <limits>
#include <cmath>

using namespace std;

int main() {
    vector<size_t> a(9, 0);
    cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4] >> a[5] >> a[6] >> a[7] >> a[8];
    size_t n;
    cin >> n;
    for (size_t i = 0; i < n; ++i) {
        size_t b;
        cin >> b;
        auto it = find(begin(a), end(a), b);
        if (it != end(a))
            * it = 0;
    }
    for (size_t i = 0; i < 3; ++i) {
        bool r = true;
        for (size_t j = 0; j < 3; ++j) {
            auto k = j + i * 3;
            if (a[k] > 0) {
                r = false;
                break;
            }
        }
        if (r) {
            cout << "Yes" << endl;
            return 0;
        }
        r = true;
        for (size_t j = 0; j < 3; ++j) {
            auto k = i + j * 3;
            if (a[k] > 0) {
                r = false;
                break;
            }
        }
        if (r) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    if (a[0] == 0 && a[4] == 0 && a[8] == 0 || a[2] == 0 && a[4] == 0 && a[6] == 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define MM 1000000000;
#define INF (ll)1e18
#define pi acos(-1.0)
#define MAX 1000000005
#define NIL -1
ll mod = 1e9+7;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int dp[201010];
int main(){
    ll n, T; cin >> n >> T;
    ll t[n];
    ll ans = 0;
    for(ll i = 0; i < n; i++){
        cin >> t[i];
    }
    for(ll i = 1; i < n; i++){
        ans += min(t[i] - t[i-1], T);
    }
    ans += T;
    cout << ans << endl;
}


Measured memory_bytes: 1792
def main():
    N = int(input())
    A = list(map(int, input().split()))

    ans = 0
    for i in range(1,N):
        if A[i-1] <= A[i]:
            continue
        else:
            cnt = A[i-1] - A[i]
            ans += cnt
            A[i] += cnt
    print(ans)

if __name__ == "__main__":
    main()

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

int main() {
	vector<string> weather = {"Sunny", "Cloudy", "Rainy"};
	string S;
	cin >> S;
	int i;
	for (i = 0; i < 3; i++) {
		if (S == weather.at(i)) break;
	}
	i++;
	i %= 3;
	cout << weather.at(i) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
using P = pair<int, int>;
int dy[4] = {0, 1, 0, -1}, dx[4] = {1, 0, -1, 0};
int n;
vector< vector< int > > v;
vector< vector< bool > > usd;
void print(){
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cout << v[i][j] << " ";
        }
        cout << endl;
    }
}
void calc(int x, int y){
    int mn = 1e9;
    for(int k=0;k<4;k++){
        int nx = x+dx[k];
        int ny = y+dy[k];
        if(nx >= 0 && nx < n && ny >= 0 && ny < n){
            if(v[nx][ny] < mn) mn = v[nx][ny];
        }else{
            mn = 0;
        }
    }
    if(!usd[x][y]) mn++;
    if(mn < v[x][y]){
        v[x][y] = mn;
        for(int k=0;k<4;k++){
            int nx = x+dx[k];
            int ny = y+dy[k];
            if(nx >= 0 && nx < n && ny >= 0 && ny < n && v[nx][ny] > mn){
                calc(nx, ny);
            }
        }
    }
}

int main(void){
    cin >> n;
    vector<int> p(n*n);
    for(int i=0;i<n*n;i++) cin >> p[i];
    v.assign(n, vector<int>(n, 0));
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            v[i][j] = min(min(i, n-1-i), min(j, n-1-j))+1;
        }
    }
    usd.assign(n, vector<bool>(n, false));
    long long ans = 0;
    for(int a: p){
        a--;
        int x = a/n;
        int y = a%n;
        ans += v[x][y]-1;
        usd[x][y] = true;
        calc(x, y);
        // cout << a+1 << " " << ans << endl;
        // print();

    }
    cout << ans << endl;
}


Measured memory_bytes: 12472
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<utility>
#include<initializer_list>
#include<tuple>
#include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(t) t.begin(), t.end()


int main() {
	string s;
	cin >> s;
	int n = s.length();
	int mi = 1 << 30;
	bool isSame = true;
	rep(i, n - 1) {
		if (s[i] != s[i + 1]) {
			isSame = false;
			mi = min(mi, max(i + 1, n - (i + 1)));
		}
	}
	isSame ? mi = n : mi;
	cout << mi << endl;
	return 0;
}





Measured memory_bytes: 512
#include <algorithm>
#include<iostream>
#include<stdio.h>
#include <algorithm>
#include<iostream>
#include<stdio.h>
#include<vector>
#include<set>
#include<string>
#include <iomanip>
#define rep(i,n) for(int i=0; i<(int)n; i++)//n回繰り返す
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
	string S, T; cin >> S;
	int N = S.size();
	rep(i, N) {
		T.push_back('x');
	}
	cout << T << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
const double PI=3.14159265358979323846;
const long long INF = 1LL << 60;

int main() {
	double A, B, H, M;
	cin >> A >> B >> H >> M;
	double a=0, b=0, c=0, x1, y1, x2, y2, z;
	
	// 長針
	z = M * 6.0 / 180.0 * PI;
	x1 = cos(z) * B;
	y1 = sin(z) * B;

	// 短針
	z = (H * 30.0 + 30.0 * (M/60.0)) / 180.0 * PI;
	x2 = cos(z) * A;
	y2 = sin(z) * A;

	a = (x2-x1) * (x2-x1);
	b = (y2-y1) * (y2-y1);
	c = sqrt(a+b);

	cout << fixed << setprecision(15);
	std::cout << c << '\n';
}


Measured memory_bytes: 4160
#include<bits/stdc++.h>
using namespace std;
#define Mod(n) n % 1000000007
const int dx[8] = {1, 0, -1, 0, -1, 1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};
int main()
{    
    string s;
    cin >> s;
    int abmin = 10000;
    for(int i = 0;i < (int)s.size() - 2;i++){
        abmin = min(abmin,abs(753 - stoi(s.substr(i,3))));
    }
    cout << abmin << '\n';
}



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

using namespace std;

#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x
#define ll long long
static const ll MAX = 1000000;
static const ll INFTY = 1e12;
static const ll MOD = 1000000007;

template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };

struct edge {
    ll to, cost;
};

using Graph = vector<vector<int>>;
using _Graph = vector<vector<edge>>;


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

// 深さ優先探索
vector<bool> seen;
vector<int> colors;

int H, W, N;
int sx, sy, gx, gy; 
vector<vector<char>> field;
vector<vector<int>> dist;
//vector<pair<int, int>> gx, gy;
deque<pair<int, int>> que;

typedef vector<vector<int> > Matrix;

const int INF = 100000000;


int main() {


    int A, B;
    cin >> A >> B;
    if(B % A == 0)cout << A+B;
    else cout << B-A;


}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <string.h>
//#include <bits/stdc++.h>

using namespace std;

long long k, n, m;
long long a[300300];

int main () {
    cin >> n >> m;
    if ( n == 1 || m == 1 ) {
        cout << 1; return 0;
    }
    if ( (n * m) % 2 == 0 ) {
        cout << (m * n) / 2;
    }
    else {
        cout << (n * m) / 2 + 1;
    }
}


Measured memory_bytes: 888
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<string>
#include<cmath>
#define eps 1e-9
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<ll,ll> LLP;
const int MAXN=2e5+10;
const int INF=0x3f3f3f3f;
const ll LLINF=0x3f3f3f3f3f3f3f3f;
const int MOD=1e9+7;
const int LOGN=20;
int arr[MAXN];
int ans[MAXN];
bool isprime(ll tmp)
{
    for(ll i=2;i*i<=tmp;++i)
    {
        if(tmp%i==0)
            return false;
    }
    return tmp!=1;
}
signed main()
{
    ll a,b;
    scanf("%lld%lld",&a,&b);
    ll gcd=__gcd(a,b);
    int cnt=0;
    if(isprime(gcd))
    {
        puts("2");
        return 0;
    }
    for(ll i=2;gcd!=1;++i)
    {
        if(gcd%i==0)
        {
            cnt++;
            while(gcd%i==0)
                gcd/=i;
            if(isprime(gcd))
            {
                cnt++;
                break;
            }
        }
    }
    printf("%d\n",cnt+1);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define int long long
#define pb push_back 
#define ins insert
#define rs resize
#define br break;
#define cont continue;
#define vi vector<ll>
#define vll vector<long long>
#define si set<ll>
#define sll set<long long>
#define pii pair<ll,ll>
#define pll pair<long long, long long>
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);
#define vec vector
#define cend cout<<endl;
#define sc second
#define fr first
#define retz return 0;
#define ll_MAX (ll)(1e9*1e9)
#define ll_MIN (ll)(-1e9*1e9)
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b)  for(int i=a; i<=b; i++)
#define repd(i,a,b) for(int i=a; i>=b; i--)
#define ps(arr, n) for(int i=1; i<n; i++)arr[i]+=arr[i-1];
#define inp(arr, n)for(int i=0; i<n; i++)cin>>arr[i];
#define out(arr, n)for(int i=0; i<n; i++)cout<<arr[i];
#define inp1(arr,n,m)for(int i=0; i<n; i++)for(int j=0;j<m;j++)cin>>arr[i][j];
#define out1(arr,n,m)for(int i=0; i<n; i++)for(int j=0;j<m;j++)cin>>arr[i][j];
#define loop(q) for(auto it:q)
#define loop1(q) for(auto&it:q)
#define db1 cout << "*" << endl
#define db2 cout << "YES" << endl
using namespace std;
using namespace __gnu_pbds; 
#define oset(X) tree<X,null_type,less<X>, rb_tree_tag, tree_order_statistics_node_update> 
#define roset(X) tree<X,null_type,greater<X>, rb_tree_tag, tree_order_statistics_node_update>  
#define okey order_of_key //lower_bound_set
#define ofind find_by_order
#define cyes cout << "Yes" << endl;
#define cno cout << "No" << endl;
#define mod 1000000007
#define mod2 998244353
#define INT_MAX1 900000000
//////////////////////////////////////////////////////////////////////////////////////////////

int n;
int c[4];
double dp[301][301][301];
bool v[301][301][301];

double s1(int c1, int c2, int c3)
{
    if(c1<0 || c2<0 || c3<0)
        return 0;
    if(c1==0 and c2==0 and c3==0)
        return 0;
    if(v[c1][c2][c3])
        return dp[c1][c2][c3];
    v[c1][c2][c3] = 1;
    int c0 = n-c1-c2-c3;
    dp[c1][c2][c3] = 1 + ((double)c1*s1(c1-1,c2,c3))/n + ((double)c2*s1(c1+1,c2-1,c3))/n + ((double)c3*s1(c1,c2+1,c3-1))/n;
    return dp[c1][c2][c3] = (n*dp[c1][c2][c3])/(c1+c2+c3);
}

void solve()
{
    cin >> n;
    rep(i,0,n-1)
    {
        int x;
        cin >> x;
        c[x]++;
    }
    cout << setprecision(25) << s1(c[1],c[2],c[3]) << endl;
}

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

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

int main() {
    int a, b, c, temp;
    cin >> a >> b >> c;
    if (a > b) {
        temp = b;
        b = a;
        a = temp;
    }
    if (a > c) {
        temp = c;
        c = a;
        a = temp;
    }
    if (b > c) {
        temp = b;
        b = c;
        c = temp;
    }
    cout << a << " " << b << " " << c << endl;
    return 0;
}


Measured memory_bytes: 3100
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue, Set}
import scala.util.Random
import java.util.Date

object Main extends App {
  val startTime = new Date().getTime // to milli seconds

  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val D = in.next().toInt
  val c = new Array[Long](26+1)
  val s = Array.ofDim[Long](D+1, 26+1)

  for (i <- 1 to 26) {
    c(i) = in.next().toInt
  }
  for (d <- 1 to D) {
    for (i <- 1 to 26) {
      s(d)(i) = in.next().toInt
    }
  }


  /** functions **/
  def calcScore(t: Array[Int]): Long = {
    val last = new Array[Int](26+1)
    var res = 0L

    for (d <- 1 to D) {
      val ty = t(d)

      res += s(d)(ty)
      last(ty) = d

      for (i <- 1 to 26) {
        res -= c(i) * (d - last(i))
      }
    }

    res
  }


  /** solve **/
  val t = new Array[Int](D+1)
  for (d <- 1 to D) {
    val (_, ty) = s(d).zipWithIndex.max
    t(d) = ty
  }

  val endTime = 1400
  var nowScore = calcScore(t)
  while ((new Date().getTime - startTime) < endTime) {
    for (_ <- 1 to 1000) {
      val d = Random.nextInt(D) + 1
      val ty = Random.nextInt(26) + 1

      val tmp = t(d)
      t(d) = ty
      val score = calcScore(t)
      if (score > nowScore) {
        nowScore = score
      }
      else {
        t(d) = tmp
      }
    }
  }


  for (d <- 1 to D) {
    pw.println(t(d))
  }
  pw.flush()
}

object Sub {
  def print2DimArray[A](mat: Array[Array[A]]): Unit = {
    mat.foreach(lin => println(lin.toList))
  }
}

class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}


Measured memory_bytes: 57624
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define fi first
#define se second
#define endl "\n"
using namespace std;

constexpr int inf = 2147483647;
//constexpr int64_t inf64 = 9223372036854775807;
//constexpr int mod = 1e9+7;

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

  int n;
  cin >> n;

  int res = 0, maxi = -inf;
  rep(i,n) {
    int p;
    cin >> p;
    res += p;
    maxi = max(maxi, p);
  }

  cout << res - maxi/2 << endl;
  return 0;
}


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

int main(){
    int x[4], y[4];
    rep(i, 2){
        cin >> x[i] >> y[i];
    }
    x[2] = x[1]-(y[1]-y[0]);
    y[2] = y[1]+(x[1]-x[0]);
    x[3] = x[0]-(y[1]-y[0]);
    y[3] = y[0]+(x[1]-x[0]);
    for(int i = 2; i < 4; i++){
        cout << x[i] << " " << y[i];
        if(i==2)cout << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N;
    cin >> N;
    vector<int>d(N);
    for(int i = 0; i < N; i++) {
        cin >> d[i];
    }
    int res = 0;
    for(int i = 0; i < N; i++) {
        for(int j = i+1; j < N; j++) {
            res+=d[i]*d[j];
        }
    }
    cout << res << endl;
}

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;

const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

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

	int n; cin >>n;
	VI a(n);
	rep(i, n) cin >> a[i];
	
	rep(k, n) cout << a[k] <<(k==n-1? "\n":" ");
	rep2(i, 1, n){
		int v =a[i], j =i -1;
		while(j >=0 && a[j] > v){
			a[j+1] = a[j]; j--;
		}
		a[j+1] = v;
		rep(k, n) cout << a[k] <<(k==n-1? "\n":" ");
	}
	
	return 0;
}



Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
#define ssd ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define debug_x(x) cout<< #x <<"---> : "<<x<<endl;
#define debug_ve(x) for(auto it: x) cout<<it<<" ";
#define rep(i,a,n) for (int i=a;i<n;i++)
#define _rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef double db;
//std::mt19937 mrand(random_device{}());
//int rnd(int x) { return mrand() % x ; }
const ll mod=1e7;
ll ksm(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

/***********************/

int main(){
    ssd;
    int a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int n;
    cin>>n;
    cout<<a[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 256
n,a=map(int, input().split())
x=list(map(int, input().split()))
x=[i-a for i in x]
d={0:1}
for i in x:
    for j,k in list(d.items()):
        d[i+j]=d.get(i+j,0)+k
print(d[0]-1)

Measured memory_bytes: 3188
/*
    問題をよく読もう！
    論理的に考えよう！
    サンプルを確認しよう!
    絶対に諦めるな！
    工夫をしろ！
    配列は少し多めにとっておく

    Twitterは終わるまでログアウト！
    （間違えて解法をツイートしてはいけないから）

*/
//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include<cstring>
//namespace
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)
//イテレータ
#define all_range(C) begin(C), end(C)
//簡略化
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
typedef pair<string,int> pst;

const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
//最大最小
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) {if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) {if(a<b) a=b;}

//関数

//最大公約数を求める
ll my_gcd(ll x, ll y) {
  ll r;

  while(y!=0) {
    r = x%y;
    x = y;
    y = r;
  }

  return x;
}

//最小公約数を求める
ll my_lcm(ll x, ll y) {

  return (x*y)/my_gcd(x,y);
}

//xのy乗を求める ※参考：10^18乗まで
ll my_pow(ll x, ll y) {
  ll sum = 1;

  while(y>0) {
    sum *= x;
    --y;
  }

  return sum;
}

/*考えを書くスペース

*/

/*おーじさんのやつ
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll>
#define m_p make_pair

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k,x2,y2;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
P p[ohara];
ll p_cou;
bool vi[ohara];
*/
//main.cpp----------------------------
#define MAX 100000

int a, b, h, w;

int main() {
  cin >> a >> b >> h >> w;

  cout << (a-h)*(b-w) << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

typedef long long ll;

int main() {
    ios::sync_with_stdio(false);

    int n, k;
    cin >> n >> k;
    int h[n+2];
    h[0] = h[n+1] = 0;
    for (int i = 1; i <= n; i++) {
        cin >> h[i];
    }

    long long dp[n+2][k+1];
    for (int i = 0; i <= n + 1; i++) {
        for (int j = 0; j <= k; j++) {
            dp[i][j] = i == 0 ? 0 : 1e18;
            for (int x = 0; x <= j && x <= i - 1; x++) {
                dp[i][j] = min(dp[i][j], dp[i-x-1][j-x] + max(h[i] - h[i-x-1], 0));
            }
        }
    }

    cout << dp[n+1][k] << endl;

    return 0;
}


Measured memory_bytes: 1024
K = int(input())
A,B = map(int,input().split())
li = []
for i in range(A,B+1):
    li.append(i)
ans = False
for j in li:
    if j%K == 0:
        ans = True
        break
    else:
        ans = False
if ans == True:print("OK")
else:print("NG")

Measured memory_bytes: 9116
#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
using namespace std;
#define fir first
#define sec second
#define m_p make_pair
#define y1 ygftgfgcdtfgxffgx
#define y2 yfdsesgvtyghftfvv
#define x1 xvyr6cf6fgcfgf676
#define x2 xcr6rfc5r66y6r6fr
#define up_bound upper_bound
#define low_bound lower_bound
#define next_per next_permutation
#define pb push_back
#define i_to_s to_string
typedef priority_queue<int> p_queue;
typedef priority_queue<int, vector<int>, greater<int> > min_p_queue;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll gcd(ll x,ll y){return ((y==0)?x:gcd(y,x%y));}
ll n;
map<int,int>mp;
int a[100010];
int x;
int cnt;
ll res;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>x;
		if(mp[x]==0)a[cnt++]=x;
		mp[x]++;
	}
	for(int i=0;i<cnt;i++){
		if(mp[a[i]]<a[i]){
			res+=mp[a[i]];
			continue;
		}
		res+=mp[a[i]]-a[i];
	}
	cout<<res;
	return 0;
}


Measured memory_bytes: 5120
# coding: utf-8
S = input()
K = int(input())
fletter = 0 # 最初の文字の連続数を数える
lletter = 0 # 最後の文字の連続数を数える
cletter = 0 # 現在連続している文字の連続数を数える
cng = 0 # 文字変更の必要がある文字をカウント
for i in range(len(S)): # 最初の文字の連続数を数える
    if S[0] == S[i]:
        fletter += 1
    else:
        break
for i in range(len(S)):
    if S[-1] == S[-(i + 1)]:
        lletter += 1
    else:
        break
for i in range(len(S) - 1): # 1文字ずつ連続しているかを判定
    if S[i] == S[i + 1]:
        cletter += 1
    else:
        cng -= - cletter // 2
        cletter = 0
cng -= - cletter // 2 # 最終文字まで到達したら文字変更数の処理
if fletter == len(S): # 文字列の種類数が1種類だったら話がだいぶ変わるようだ
    ans = len(S) * K // 2
elif S[0] == S[-1] and fletter % 2 == 1 and lletter % 2 == 1:
    ans = int((cng + 1) * K - 1)
else:
    ans = int(cng * K)
print(ans) #解答の出力

Measured memory_bytes: 3188
N, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(N)]

INF = 10**15
dp = [INF for _ in range(10**5 + 1)] # dp[価値の総和]:= 重量の総和
dp[0] = 0

for i in range(N):
  w, v = wv[i]
  for j in range(10**5, -1, -1):
    if dp[j] != INF and j + v <=  10**5:
      dp[j+v] = min(dp[j+v], dp[j]+w)

answer = 0
for i in range(10**5+1):
  if dp[i] <= W:
    answer = i
    #break
print(answer)

Measured memory_bytes: 45040
#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;
    cin >> n;
    int x[n];
    rep(i,n) {
        cin >> x[i];
    }
    sort(x, x+n);
    int ans = 100100100;
    for(int i = 1; i < 101; i++) {
        int a = 0;
        rep(j,n) {
            a += pow((x[j] - i), 2);
        }
        ans = min(a, ans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

const int dm = 1 << 20;
char dn[dm], * di = dn, dt;
inline void putint(int X) {
	if (X == 0) {
		*di++ = '0';
		*di++ = '\n';
		return;
	}
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = '\n';
}

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


	int H = getint(), W = getint(), D = getint();
	pair<int, int> A[90001];
	A[0] = mp(0, 0);
	rep(i, H) rep(j, W) {
		A[getint()] = mp(i, j);
	}
	vector<int> V[90000];
	rep(i, D) {
		int j = i;
		auto a = mp(0, 0);
		int mae = 0;
		ce(i);
		while (j <= H * W) {
			V[i].pb((mae += (abs(A[j].first - a.first) + abs(A[j].second - a.second))));
			a = A[j];
			j += D;
		}
	}
	int Q = getint();
	rep(i, Q) {
		int l = getint(), r = getint();
		int k = l % D;
		putint(V[k][r / D] - V[k][l / D]);
	}

	fwrite_unlocked(dn, di - dn, 1, stdout);

	Would you please return 0;
}

Measured memory_bytes: 6400
function main(input: string) {
  const lines = input.trim().split('\n')

  const [n] = lines[0].split(' ').map(Number)
  let res = 0
  for (let i = 1; i <= n; i++) {
    if (i >= 100000) {
    } else if (i >= 10000) {
      res += 1
    } else if (i >= 1000) {
    } else if (i >= 100) {
      res += 1
    } else if (i >= 10) {
    } else {
      res += 1
    }
  }
  console.log(res)
}

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


Measured memory_bytes: 11468
import java.io.{BufferedReader, InputStream, InputStreamReader, PrintWriter}
import java.util.StringTokenizer

import scala.collection.mutable
import scala.util.Sorting
import math.{abs, max, min}
import scala.collection.mutable.{ArrayBuffer, ListBuffer}
import scala.reflect.ClassTag

object Main {
  val MOD = 1000000007
  val out = new PrintWriter(System.out)
  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val N = sc.nextInt()
    val A = map(N)(_ => sc.nextLong())
      .grpBy(identity).view
      .map { case(k, v) => k -> v.length }
      .filter(_._2 >= 2).toArray
    Sorting.quickSort(A)(Ordering.by[(Long, Int), Long](_._1).reverse)
    
    val ans = if (A.length > 0 && A(0)._2 >= 4)
      A(0)._1 * A(0)._1
    else if (A.length > 1)
      A(0)._1 * A(1)._1
    else
      0
  
    out.println(ans)
  }


  def main(args: Array[String]): Unit = {
    solve()
    out.flush()
  }


  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = null

    def next: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next.toInt
    def nextLong(): Long = next.toLong
    def nextChar(): Char = next.charAt(0)
  }

  private def rep(n: Int)(f: Int => Unit): Unit = (0 until n) foreach f

  private def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    (0 until n) foreach (i => res(i) = f(i))
    res
  }

  private implicit class ArrayOpts[A](val as: Array[A]) extends AnyVal {
    def maxByOpt[B: Ordering](f: A => B): Option[A] = {
      if (as.nonEmpty) Some(as.maxBy(f)) else None
    }

    def grpBy[K](f: A => K): mutable.Map[K, ArrayBuffer[A]] = {
      val map = mutable.Map.empty[K, ArrayBuffer[A]]
      rep(a => map.getOrElseUpdate(f(a), ArrayBuffer()) += a)
      map
    }

    def rep(f: A => Unit): Unit = {
      as.indices foreach (i => f(as(i)))
    }

    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      var sum = num.zero
      rep(a => sum = num.plus(sum, f(a)))
      sum
    }
  }

  private implicit class IterableOpts[A](val as: Iterable[A]) extends AnyVal {
    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      as.foldLeft(num.zero)((acc, a) => num.plus(acc, f(a)))
    }
  }

}


Measured memory_bytes: 79164
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
using namespace std;

typedef struct
{
    int height;
    int targetMaxHeight;
}Info;

#define ARRAYMAX 100010
Info InfoArray[ARRAYMAX];

#define DEBUG


int main()
{
    int i, j, k, m;

    //printf("size_t:%ld\n", sizeof(size_t));

    for (i = 0;i < ARRAYMAX;i++)
    {
        InfoArray[i].height = 0;
        InfoArray[i].targetMaxHeight = 0;
    }
#if 1
    char str[1000];
    fgets(str, sizeof(str), stdin);

    char* temp;
    temp = strtok(str, " \n");
    // 展望台の数
    int TenbodaiNum = atoi(temp);
 

    // 道の数
    temp = strtok(NULL, " \n");
    int PathNum = atoi(temp);
#else
    int TenbodaiNum, PathNum;
    cin >> TenbodaiNum >> PathNum;
#endif



    //高さの取得
#if 0
    fgets(str, sizeof(str), stdin);

    int hoge = 0;
    temp = strtok(str, " \n");

    while (temp != NULL)
    {
        //if (hoge >= ARRAYMAX) break;
        InfoArray[hoge].height = atoi(temp);
        hoge++;
        temp = strtok(NULL, " \n");
    }
#else
 
    for (i = 0;i < TenbodaiNum;i++)
    {
        cin >> InfoArray[i].height;
    }
#endif







    //道情報取得
    for (i = 0;i < PathNum;i++)
    {
        int iPos1;
        int iPos2;
#if 0
        fgets(str, sizeof(str), stdin);
        temp = strtok(str, " \n");
        iPos1 = atoi(temp) -1;
        temp = strtok(NULL, " \n");
        iPos2 = atoi(temp) -1;
#endif
        cin >> iPos1 >> iPos2;
        iPos1--;
        iPos2--;

        //if (iPos1 >= ARRAYMAX) continue;
        //if (iPos2 >= ARRAYMAX) continue;



        if (iPos1 == iPos2) continue;

        if (InfoArray[iPos1].targetMaxHeight < InfoArray[iPos2].height)
        {
            InfoArray[iPos1].targetMaxHeight = InfoArray[iPos2].height;
        }
        if (InfoArray[iPos2].targetMaxHeight < InfoArray[iPos1].height)
        {
            InfoArray[iPos2].targetMaxHeight = InfoArray[iPos1].height;
        }
    }

    // 判定
   
    int iGoodNum = 0;

    for (i = 0;i < TenbodaiNum;i++)
    {
        //if (i >= ARRAYMAX) continue;
         if (InfoArray[i].height > InfoArray[i].targetMaxHeight) iGoodNum++;
    }



    printf("%d\n", iGoodNum);


    return 0;
}


Measured memory_bytes: 4552
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    c = sum(A)
    for i in range(N):
        a = min(A[i], B[i])
        A[i] -= a
        A[i+1] -= min(A[i+1], B[i] - a)
    return c - sum(A)

print(solve())

Measured memory_bytes: 18624
#include <limits>
using ll = long long;
constexpr int INF = std::numeric_limits<int>::max() / 2;
constexpr ll LNF = std::numeric_limits<ll>::max() / 2;

#include <bits/stdc++.h>
using namespace std;

template <typename T>
void print(vector<T> const &x, string s = "") {
    // cerr << s;
    // copy(x.begin(), x.end(), ostream_iterator<ll>(cerr, ", "));
    // cerr << endl;
}

ll compute(vector<ll> v, int K, int Q, vector<int> &seps) {
    int N = v.size();
    sort(seps.begin(), seps.end());
    seps.push_back(N);
    print(seps, "seps: ");
    for (int i = 1; i < (int)seps.size(); i++) {
        sort(v.begin() + seps[i - 1] + 1, v.begin() + seps[i]);
    }
    print(v, "sorted v: ");

    vector<ll> ans;
    ans.reserve(N);
    for (int i = 1; i < (int)seps.size(); i++) {
        ans.insert(ans.end(), v.begin() + seps[i - 1] + 1,
                   v.begin() + seps[i - 1] + 1 +
                       max(0, seps[i] - seps[i - 1] - 1 - K + 1));
    }
    print(ans, "ans: ");
    auto a = *min_element(ans.begin(), ans.end());
    nth_element(ans.begin(), ans.begin() + Q - 1, ans.end());
    sort(ans.begin(), ans.end());
    seps.pop_back();
    return Q <= (int)ans.size() ? ans[Q - 1] - a : LNF;
}

int main() {
    int N, K, Q;
    cin >> N >> K >> Q;
    vector<ll> orig(N);
    for (int i = 0; i < N; i++) { cin >> orig[i]; }

    vector<pair<ll, int>> cp(N);
    for (int i = 0; i < N; i++) {
        cp[i].first  = orig[i];
        cp[i].second = i;
    }
    sort(cp.begin(), cp.end());

    vector<int> seps = {-1};
    ll mi            = compute(orig, K, Q, seps);
    for (auto const &p : cp) {
        seps.push_back(p.second);
        ll res = compute(orig, K, Q, seps);
        if (res == LNF) break; // ??????
        mi = min(mi, res);
    }
    cout << mi << endl;
    return 0;
}


Measured memory_bytes: 384
def resolve():
    import itertools
    h, w, k = map(int, input().split())
    c = [input() for _ in range(h)]
    ans = 0
    for i in itertools.product([True, False], repeat=h):
        for j in itertools.product([True, False], repeat=w):
            black = 0
            for p in range(h):
                for q in range(w):
                    if i[p] and j[q] and c[p][q] == "#":
                        black += 1
            if black == k:
                ans += 1
    print(ans)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9136
#[allow(unused_macros)]
macro_rules ! read_value {($ next : expr , ($ ($ t : tt ) ,* ) ) => {($ (read_value ! ($ next , $ t ) ) ,* ) } ; ($ next : expr , [$ t : tt ; $ len : expr ] ) => {(0 ..$ len ) . map (| _ | read_value ! ($ next , $ t ) ) . collect ::< Vec < _ >> () } ; ($ next : expr , chars ) => {read_value ! ($ next , String ) . chars () . collect ::< Vec < char >> () } ; ($ next : expr , usize1 ) => {read_value ! ($ next , usize ) - 1 } ; ($ next : expr , $ t : ty ) => {$ next () . parse ::<$ t > () . expect ("Parse error" ) } ; }
#[allow(unused_macros)]
macro_rules ! input_inner {($ next : expr ) => {} ; ($ next : expr , ) => {} ; ($ next : expr , $ var : ident : $ t : tt $ ($ r : tt ) * ) => {let $ var = read_value ! ($ next , $ t ) ; input_inner ! {$ next $ ($ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input {(source = $ s : expr , $ ($ r : tt ) * ) => {let mut iter = $ s . split_whitespace () ; let mut next = || {iter . next () . unwrap () } ; input_inner ! {next , $ ($ r ) * } } ; ($ ($ r : tt ) * ) => {let stdin = std :: io :: stdin () ; let mut bytes = std :: io :: Read :: bytes (std :: io :: BufReader :: new (stdin . lock () ) ) ; let mut next = move || -> String {bytes . by_ref () . map (| r | r . unwrap () as char ) . skip_while (| c | c . is_whitespace () ) . take_while (| c |! c . is_whitespace () ) . collect () } ; input_inner ! {next , $ ($ r ) * } } ; }

#[allow(dead_code)]
fn gcd(a: u64, b: u64) -> u64 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}
#[allow(dead_code)]
fn lcm(a: u64, b: u64) -> u64 {
    a / gcd(a, b) * b
}

fn root2(a: u64) -> u64 {
    if a % 2 == 1 {
        0
    } else {
        1 + root2(a >> 1)
    }
}

fn solve(a: &Vec<u64>, m: u64) -> u64 {
    let n = a.len();
    let r: Vec<u64> = a.iter().map(|&e| root2(e)).collect();
    for i in 0..n {
        if r[i] != r[0] {
            return 0;
        }
    }

    let mut l = a[0] / 2;
    for i in 1..a.len() {
        l = lcm(l, a[i] / 2);
        if l > m {
            return 0;
        }
    }

    1 + (m - l) / (2 * l)
}

fn main() {
    input! {
        n: usize,
        m: u64,
        a: [u64; n],
    }
    let ret = solve(&a, m);
    println!("{}", ret);

}


Measured memory_bytes: 3576
import re
N = int(input())
memo_dict = [{} for i in range(N+1)]
def ok(last4):
    if re.match(r".*AGC|.*ACG|A.GC|AG.C|.*GAC", last4):
        return True
    else:
        return False

def dfs(ind, last3):
    if last3 in memo_dict[ind]:
        return memo_dict[ind][last3]
    if ind == N:
        return 1
    cnt = 0
    for c in "ATGC":
        if not ok(last3 + c):
            cnt += dfs(ind + 1, last3[1:] + c)
            cnt %= (1e9+7)
    memo_dict[ind][last3] = cnt
    return cnt
print(int(dfs(0,"TTT")))

Measured memory_bytes: 4048