akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

//1 ?????? n ?????§?????°?????????????????????????????§???????????°?????????????????????????¨????
//x ??¨??????????????????????????°????±???????????????°?????????????????????????????????
public class Main{
	public static void main (String args[]){
		Scanner sc = new Scanner(System.in);

		while(true){
			int n = sc.nextInt();
			int x = sc.nextInt();

			if(x ==0 && n ==0){
				break;
			}
			int count = 0;

			for(int i = 1; i <= n; i++){
				for(int j = i + 1; j <= n; j++){
					for(int k = j + 1; k <= n; k++){

						if(x == (i + j + k)){
							count++;
						}
					}
				}
			}
			System.out.println(count);
		}
		sc.close();
	}
}

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

int inficheck(int i,int infinity)
{
	if(i>=infinity)
	return infinity;
	else
	return i;
}

signed main()
{
	int n;
	cin>>n;
	int wt;
	cin>>wt;
	int infinity=wt+1;
	int w[n],v[n];int vsum=0;
	for(int i=0;i<n;i++)
	{
		cin>>w[i];
		cin>>v[i];
		vsum=vsum+v[i];
	}
	int a[vsum+1],b[vsum+1];
	//initialization:
	a[0]=0;
	for(int i=1;i<=v[0];i++)
	{
		a[i]=w[0];
	}
	for(int i=v[0]+1;i<=vsum;i++)
	{
		a[i]=infinity;
	}
	for(int i=2;i<=n;i++)
	{
		b[0]=0;
		for(int j=1;j<v[i-1];j++)
		{
			b[j]=inficheck(min(a[j],w[i-1]),infinity);
		}
		for(int j=v[i-1];j<=vsum;j++)
		{
			b[j]=inficheck(min(a[j],a[j-v[i-1]]+w[i-1]),infinity);
		}
		for(int j=0;j<=vsum;j++)
		{
			a[j]=b[j];
		}
	}
	for(int i=vsum;true;i--)
    {
        if(a[i]<=wt)
        {
            cout<<i<<endl;
            break;
        }
    }
	return 0;
}


Measured memory_bytes: 1024
/*****************************************************
 *     created by: nayakashutosh9
 * "Winners Never Quit and Quitters Never Win".
*****************************************************/
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("Ofast")
using namespace std;
using namespace __gnu_pbds;
#define int long long int
#define endl '\n'
#define mod 1000000007
#define inf 1e18
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
const int N = 300005;
/**********************************************************************************************/

unordered_map<int, vector<int>> g;
vector<vector<int>> dist;
vector<string> a; vector<vector<bool>> vis;
int d[3] = { -1, 0, 1};
int dd[5] = { -2, -1, 0, 1, 2};
void solve() {
	g.clear(); dist.clear(); a.clear(); vis.clear();
	int h, w; cin >> h >> w;
	dist.resize(h, vector<int>(w, inf));
	int sh, sw, eh, ew; cin >> sh >> sw >> eh >> ew;
	sh--, sw--, eh--, ew--;
	a.resize(h);
	for (int i = 0; i < h; i++) cin >> a[i];
	vis.resize(h, vector<bool>(w, 0));
	dist[sh][sw] = 0;
	set<pair<int, pair<int, int>>> s; s.insert({0, {sh, sw}});
	while (!s.empty()) {
		auto f = s.begin();
		int cx = (*f).second.first;
		int cy = (*f).second.second;
		s.erase(f);
		if (vis[cx][cy]) continue;
		vis[cx][cy] = 1;
		// cout << cx << " " << cy << " " << dist[cx][cy] << endl;
		for (int i : d) {
			for (int j : d) {
				if (i * j != 0) continue;
				if (cx + i >= 0 && cx + i < h && cy + j >= 0 && cy + j < w && a[cx + i][cy + j] == '.' && !vis[cx + i][cy + j] && dist[cx][cy] < dist[cx + i][cy + j]) {
					// cout << g << " " << h << ", ";
					dist[cx + i][cy + j] = dist[cx][cy];
					s.insert({dist[cx + i][cy + j], {cx + i, cy + j}});
				}
			}
		}
		for (int i : dd) {
			for (int j : dd) {
				if (cx + i >= 0 && cx + i < h && cy + j >= 0 && cy + j < w && a[cx + i][cy + j] == '.' && !vis[cx + i][cy + j] && dist[cx][cy] + 1 < dist[cx + i][cy + j]) {
					// cout << g << " " << h << ", ";
					dist[cx + i][cy + j] = dist[cx][cy] + 1;
					s.insert({dist[cx + i][cy + j], {cx + i, cy + j}});
				}
			}
		}
	}
	// for (int i = 0; i < h; i++) {
	// 	for (int j = 0; j < w; j++) cout << dist[i][j] << " ";
	// 	cout << endl;
	// }
	if (dist[eh][ew] == inf) cout << "-1\n";
	else cout << dist[eh][ew] << endl;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int t = 1, z = 1;
	// cin >> t; cin.ignore();
	while (t--) {
		// cout << "Case #" << (z++) << ": ";
		// clock_t start = clock();
		solve();
		// clock_t end = clock();
		// cout << (end-start) << endl;
		//print execution time in ms
	}

	return 0;
}

Measured memory_bytes: 13328
#include<stdio.h>
int main()
{
    int sx,sy,tx,ty,x,y,i;
    scanf("%d %d %d %d", &sx,&sy,&tx,&ty);
    x=tx-sx;
    y=ty-sy;
    for(i=0;i<y;i++)
    {
        printf("U");
    }
    for(i=0;i<x;i++)
    {
        printf("R");
    }
    for(i=0;i<y;i++)
    {
        printf("D");
    }
    for(i=0;i<x;i++)
    {
        printf("L");
    }
    printf("L");
    for(i=0;i<y+1;i++)
    {
        printf("U");
    }
    for(i=0;i<x+1;i++)
    {
        printf("R");
    }
    printf("DR");
    for(i=0;i<y+1;i++)
    {
        printf("D");
    }
    for(i=0;i<x+1;i++)
    {
        printf("L");
    }
    printf("U");
    return 0;
}


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

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

using namespace std;

typedef long long ll;

#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REPD(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FORD(i, a, b) for (int i = b - 1; i >= int(a); i--)
#define WRAP(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w)

#define ALL(x) (x).begin(), (x).end()

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

int main()
{
    ll n, x, m;
    cin >> n >> x >> m;
    vector<int> a;
    set<int> b;
    int c;
    while (1) {
        if (b.find(x) != b.end()) {
            c = x;
            break;
        }
        a.push_back(x);
        b.insert(x);
        x = (x * x) % m;
    }
    ll sum = 0;
    ll sum2 = 0;
    int idx = -1;
    REP(i, a.size())
    {
        if (c == a[i]) {
            idx = i;
        }
        if (idx == -1)
            sum += a[i];
        else
            sum2 += a[i];
    }
    ll ans = 0;
    if (n < idx) {
        REP(i, n)
        {
            ans += a[i];
        }
    } else {
        ans += sum;
        n -= idx;
        ans += sum2 * (n / (a.size() - idx));
        REP(i, n % (a.size() - idx))
        ans += a[idx + i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 5944
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char ch[100001];
    cin>>ch;
    int flag=0;
    for(int i=0;i<strlen(ch);i++)
    {
        if(ch[i]=='C')
            flag=1;
        if(ch[i]=='F'&&flag==1)
        {
            cout<<"Yes";
            return 0;
        }
    }
    cout<<"No";
    return 0;
}

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

vector<int>ans;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    long long n,m;
    cin>>n;
    for(int i=1;i<50001;i++){
        m = i*1.08;
        if(m==n){
            cout<<i;
            return 0;
        }
    }
    cout<<":(";
    
    return 0;
}
 

Measured memory_bytes: 256
function Dice(labels) {
    this.top = labels[0];
    this.back = labels[1];
    this.right = labels[2];
    this.left = labels[3];
    this.front = labels[4];
    this.bottom = labels[5];
};

Dice.prototype.turn = function(direction) {
    switch (direction) {
        case 'W':
            var tmp = this.left;
            this.left = this.top;
            this.top = this.right;
            this.right = this.bottom;
            this.bottom = tmp;
            break;
        case 'N':
            var tmp = this.front;
            this.front = this.top;
            this.top = this.back;
            this.back = this.bottom;
            this.bottom = tmp;
            break;
        case 'E':
            var tmp = this.right;
            this.right = this.top;
            this.top = this.left;
            this.left = this.bottom;
            this.bottom = tmp;
            break;
        case 'S':
            var tmp = this.back;
            this.back = this.top;
            this.top = this.front;
            this.front = this.bottom;
            this.bottom = tmp;
            break;
        case 'R':
            var tmp = this.right;
            this.right = this.front;
            this.front = this.left;
            this.left = this.back;
            this.back = tmp;
            break;
        case 'L':
            var tmp = this.left;
            this.left = this.front;
            this.front = this.right;
            this.right = this.back;
            this.back = tmp;
            break;
    }
};

Dice.prototype.clone = function() {
    return new Dice([this.top, this.back, this.right, this.left, this.front, this.bottom]);
};

Dice.prototype.getRightWithTopAndBack = function(top, back) {
    var dice = this.clone();
    var turns = 'NEEEN'.split('');
    var i = 0;
    do {
        var j = 0;
        do {
            if (dice.top === top && dice.back === back) {
                return dice.right;
            }
            dice.turn('R');
        } while (j++ < 3);
        dice.turn(turns[i]);
    } while (i++ < turns.length);
    return null;
};

(function(input) {
    var p = input.split('\n');
    var labels = p.shift().split(' ').map(Number);
    var dice = new Dice(labels);
    var n = Number(p.shift());
    for (var i = 0; i < n; i++) {
        var ls = p.shift().split(' ').map(Number);
        var top = ls[0];
        var back = ls[1];
        console.log(dice.getRightWithTopAndBack(top, back));
    }
})(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

#define FAST {ios::sync_with_stdio(false); cin.tie(NULL);}
#define pb push_back
#define fi first
#define se second
#define ll long long int
#define f(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007

int r,c;
vector<vector<ll>> grid(3005,vector<ll>(3005,0));

void bfs(){

	queue<pair<ll,ll>> q;
	q.push({0,0}); //{row, column}

	while(!q.empty()){
		auto elem = q.front();
		q.pop();

		if(elem.fi+1 < r && grid[elem.fi+1][elem.se] != -1){
			if(grid[elem.fi+1][elem.se] == 0)
				q.push({elem.fi+1, elem.se});
			grid[elem.fi+1][elem.se] = (grid[elem.fi+1][elem.se] + grid[elem.fi][elem.se])%mod;
		}

		if(elem.se+1 < c && grid[elem.fi][elem.se+1] != -1){
			if(grid[elem.fi][elem.se+1] == 0)
				q.push({elem.fi,elem.se+1});
			grid[elem.fi][elem.se+1] = (grid[elem.fi][elem.se+1] + grid[elem.fi][elem.se])%mod;
		}
	}
}

int main(){

    FAST

    cin>>r>>c;

    for(int i=0;i<r;i++){
    	for(int j=0;j<c;j++){
    		char ch;
    		cin>>ch;
    		if(ch == '#')
    			grid[i][j] = -1;
    	}
    }

    grid[0][0] = 1; 
    bfs();

    cout<<grid[r-1][c-1]<<"\n";
    return 0;
}


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

int main(){
  long long int n,a,b,res;
  cin>>n;
  res=n+1;
  for(int i=2;i<=sqrt(n);i++){
    if(n%i==0){
      b=n/i;
      a=i;
      res=min(res,a+b);
    }
  }
  cout<<res-2;
  return 0;
}


Measured memory_bytes: 3688
#include "bits/stdc++.h"
using namespace std;
int solve(int a, int b){
	int cnt=0,tmp=0;
	int c = b;
	while(c>0){
		c /= 10;
		cnt++;
	}

	if(cnt==1)tmp = a*10;
	if(cnt==2)tmp = a*100;
	if(cnt==3)tmp = a*1000;

	int convert = tmp + b;

	for(int i=1;i<=sqrt(convert);i++){
		if(i*i == convert)return true;
	}

	return false;
}
int main(){
	int a,b;
	cin>>a>>b;

	if(solve(a, b)) cout<< "Yes" <<endl;
	else cout<< "No" <<endl;
	//cout<<solve(a, b)<<endl;


	return 0;
}

Measured memory_bytes: 256
import math
import sys
import os
from operator import mul

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")


N = I()
S = [_S() for _ in range(N)]
ans = 0

s = set()

for i in range(N):
    s.add(S[i])

ans = len(s)

print(ans)

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


int main() {
    long long X,M=100;
    cin >> X;
    for (long long i = 1; i<=1000000000000000000; i++){
        M=M+M/100;
        if (X<=M) {
            cout << i << endl;
            break;
        }
    }

}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>

using namespace std;
int in(){
    int temp;
    scanf("%d",&temp);
    return temp;
}


int main() {
  
    int sx = in();
    int sy = in();
    int tx = in();
    int ty = in();
    
    
    string S;
    
    /// first s->t
    
    for(auto i = 0; i< tx-sx; i++){
        S.push_back('R');
    }
    for(auto i = 0; i< ty-sy; i++){
        S.push_back('U');
    }
    
    /// first t->s
    
    for(auto i = 0; i< tx-sx; i++){
        S.push_back('L');
    }
    for(auto i = 0; i< ty-sy; i++){
        S.push_back('D');
    }
    
    /// second s->t
    S.push_back('D');
    S.push_back('R');
    
    for(auto i = 0; i< tx-sx; i++){
        S.push_back('R');
    }
    for(auto i = 0; i< ty-sy; i++){
        S.push_back('U');
    }
    
    S.push_back('U');
    S.push_back('L');
    
    /// second t->s
    S.push_back('U');
    S.push_back('L');
    
    for(auto i = 0; i< tx-sx; i++){
        S.push_back('L');
    }
    for(auto i = 0; i< ty-sy; i++){
        S.push_back('D');
    }
    S.push_back('D');
    S.push_back('R');
    
    
    
    cout << S << endl;
    
    return 0;
    
}


Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip()


def calc(a):
    #周期2で1桁目は1になる
    cnt1 = (a+1)//2
    ans = cnt1 % 2

    if a % 2 == 0:
        ans ^= a

    return ans    

A, B = map(int, input().split())

print(calc(B)^calc(A-1))

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <tuple>

#define rep(i,n) for(ll i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
using Graph = vector<vector<ll>>;
// cout<<std::fixed<<std::setprecision(10);

int main() {
	int N;
	string S;
	cin >> N >> S;
	bool ans = true;
	if(N%2==1) ans = false;
	rep(i, N/2) {
		if(S[i]!=S[N/2+i]) ans = false;
	} 

	if(ans) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int X, Y;
    scanf("%x%x",&X,&Y);
    if (X<Y){
        printf("<");

    }
    else if(X>Y)
        {
        printf(">");
    }
    if(X==Y)
        {
        printf("=");
    }



    return 0;
}


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

using namespace std;

const int MAXN=2010;
int a[MAXN], n;
int Qorder[MAXN];
bool cmp(const int x, const int y) {
	return a[x]<a[y];
}
int slotspace[MAXN]; // query space = slotspace[slotid];
int belong[MAXN]; //belong[x] = slot_i; query x's slot id which x is using in a[x].
void updateslot(int threshould) {
	int slotid = 0;
	int space=0;
	for (int i=0; i<n; i++) {
		if (a[i] <= threshould) {
			slotspace[slotid] = space;
			space = 0;
			slotid++;
		}else {
			belong[i] = slotid;
			space++;
		}
	}
	slotspace[slotid] = space;
}
int main() {
	int K,Q;
	cin>>n>>K>>Q;
	for (int i=0; i<n; i++) {
		cin>>a[i];
		Qorder[i]=i;
	}
	sort(Qorder, Qorder+n, cmp);

	int ans = 2000000000;
	for (int lastpos=-1, lastnum=0; lastpos+1<n; ) {
		updateslot(lastnum);
		int succ=0;
		for (int p=lastpos+1; p<n; p++) {
			int slotid = belong[Qorder[p]];
			if (slotspace[slotid] >= K)
				succ++, slotspace[slotid]--;
			if (succ == Q) {
				int X = a[Qorder[lastpos+1]];
				int Y = a[Qorder[p]];
				ans = min(ans, Y-X);
				break;
			}
		}
		if (succ != Q)
			break;
		//update var 'lastpos'
		lastnum = a[Qorder[++lastpos]];
		while (lastpos+1 < n) {
			if (a[Qorder[lastpos]] != a[Qorder[lastpos+1]])
				break;
			lastpos++;
		}
	}

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


Measured memory_bytes: 888
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
#include <climits>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define RFOR(i,a,b) for (int i=(a)-1;i>=(b);i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const int MOD = 1e9 + 7;

using namespace std;


struct UnionFind{
	int par[100003];
	int rank[100003];
	UnionFind(int n){
		init(n);
	}
	void init(int n){		REP(i,n){par[i] = i;rank[i] = 0;}}
	int find(int a){
		if(par[a] == a)return a;
		return par[a] = find(par[a]);
	}
	void unite(int x,int y){
		x = find(x);
		y = find(y);
		if(x==y)return;
		if(rank[x]<rank[y])par[x] = y;
		else {
			par[y] = x;
			if(rank[x]==rank[y])rank[x]++;
		}
	}
	bool same(int x,int y){return find(x)==find(y);}
};

struct City{
    int x,y,num,num2;
};

bool xfirst(City& a,City& b){
    return a.x < b.x;
}
bool yfirst(City& a,City& b){
    return a.y < b.y;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;cin>>n;
  vector<City> xf(n),yf(n);
  REP(i,n){
      int x,y;cin>>x>>y;
      xf[i].x = yf[i].x = x;
      xf[i].y = yf[i].y = y;
      xf[i].num = yf[i].num = i+1;
  }
  sort(xf.begin(),xf.end(),xfirst);
  sort(yf.begin(),yf.end(),yfirst);
  vector<City> xf2(n-1),yf2(n-1);
  REP(i,n-1){
      xf2[i].x = xf[i+1].x - xf[i].x;
      yf2[i].y = yf[i+1].y - yf[i].y;
      xf2[i].num = xf[i].num;
      xf2[i].num2 = xf[i+1].num;
      yf2[i].num = yf[i].num;
      yf2[i].num2 = yf[i+1].num;
  }

  sort(xf2.begin(),xf2.end(),xfirst);
  sort(yf2.begin(),yf2.end(),yfirst);
  int ct = 1;
  long long ans = 0;
  UnionFind uni(n);
  int xi = 0,yi = 0;
  int xcost = xf2[0].x,ycost = yf2[0].y;
  bool Xturn = xcost <= ycost;

  while(ct < n){
      if(Xturn){
          if(xf2[xi].x == xcost){
              if(!uni.same(xf2[xi].num,xf2[xi].num2)){
                  uni.unite(xf2[xi].num,xf2[xi].num2);
                  ct++;
                  ans+=xcost;
              }
              xi++;
          }else{
              xcost = xf2[xi].x;
              if(ycost < xcost) Xturn = false;
          }
      }else{
          if(yf2[yi].y == ycost){
              if(!uni.same(yf2[yi].num,yf2[yi].num2)){
                  uni.unite(yf2[yi].num,yf2[yi].num2);
                  ct++;
                  ans+=ycost;
              }
              yi++;
          }else{
              ycost = yf2[yi].y;
              if(xcost <= ycost) Xturn = true;
          }
      }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, lim, v, w, value[110], weight[110], maxval = -1;
  cin >> n >>lim;
  for(int i = 0; i < n; i++) cin >> value[i] >> weight[i];
  int dp[10010];
  fill_n(dp, lim +1, -1);
  dp[0] = 0;
  //全ての重量について調べ上げる
  for(int i = 0; i < n; i++){
    w = weight[i];
    v = value[i];
    for(int j = w; j < lim + 1; j++){
      if(dp[j - w] != -1) dp[j] = max(dp[j - w] + v, dp[j]);
      maxval = max(maxval, dp[j]);
    }
  }
  cout << maxval << endl;
}


Measured memory_bytes: 3136
from itertools import zip_longest

N = input()
len_N = len(str(N))
sum =0

for i in range(2**(len_N-1)):
  hugo = [""]*(len_N-1)
  for j in range(len_N-1):
    if (i>>j)& 1:
      hugo[j]="+"
  #print(hugo)
  formula=""
  for aaa,bbb in zip_longest(N,hugo+[""]):
    formula +=(aaa+bbb)
  sum += eval(formula)

print(sum)

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

typedef long long ll;

using namespace std;

const int inf=1000000007;

int main()
{
    int n;
    scanf("%d",&n);
    if(n>=30)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 3676
n = int(input())
s = [input() for _ in range(n)]

import re
cnt = 0
for i in range(n):#ABでなくAAだと無理だがこれで
    cnt += len(re.findall("AB",s[i]))
    si = s[i].replace("AB","x")
    s[i] = si
ac= 0
bc = 0
abc = 0
for i in range(n):
    if s[i]:
        if  s[i][-1]=="A" and s[i][0]=="B":
            abc+=1
        elif s[i][-1]=="A":
            ac+=1
        elif s[i][0]=="B":
            bc+=1
        
#############
mn=min(ac,bc)
cnt += mn
if ac or bc:
    cnt += abc
else:
    cnt+=max(abc-1,0)
print(cnt)


Measured memory_bytes: 10436
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using std::cerr;
using std::cin;
using std::cout;
using std::endl;

using namespace std;
typedef long long int64;

int64_t EuclidMod(int64_t v, int64_t m){
  if(0 <= v && v < m){
    return v;
  }else if(-m <= v && v < 0){
    return v + m;
  }else{
    int64_t result = v % m;
    if(result < 0){
      result += m;
    }
    return result;
  }
}

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  int n,k;
  cin>>n>>k;
  vector<int64> a(n);
  for(int i=0;i<n;i++){
    int tmp;
    cin>>tmp;
    a[i]=tmp;
  }

  vector<int64> cum(n);
  cum[0]=a[0];
  for(int i=1;i<n;i++){
    cum[i]=cum[i-1]+a[i];
    cum[i]%=k;
  }

  int64 result=0;

  for(int i=0;i<min(n,k);i++){
    if(cum[i]%k==i+1){
      result++;
    }
  }

  unordered_map<int64,int64> num;
  for(int64 j=0;j<n;j++){

    int64 next=cum[j]-j;
    next=EuclidMod(next,k);
    if(num.find(next)==num.end()){
      num[next]=1;
    }else{
      num[next]++;
    }
    if(j>=k){
      assert(num[EuclidMod(cum[j-k]-(j-k),k)]>=0);
      num[EuclidMod(cum[j-k]-(j-k),k)]--;
    }
      {
        if(num[next]-1>0)
        result+=(num[next]-1);
      }


  }



  cout<<result<<endl;






  return 0;
}

Measured memory_bytes: 11592
a,b,c=map(int,input().split())
if a==b==c and a%2==0:
  print(-1)
else:
  res=0
  while a%2==b%2==c%2==0:
    a,b,c=(b+c)/2,(c+a)/2,(a+b)/2
    res+=1
  print(res)

Measured memory_bytes: 9168
#include<bits/stdc++.h>
using namespace std;
const int N=400010;
int a[N],k,n,b[N],c[N];
struct Q{
	int id,q[N],l=1,r;
	void ins(int ps){
		if(id){
			while(l<=r&&a[ps]>a[q[r]])r--;
		}
		else{
			while(l<=r&&a[ps]<a[q[r]])r--;
		}
		q[++r]=ps;
		while(l<=r&&q[l]<ps-k)l++;
	}
	int f(){
		return a[q[l]];
	}
}mx,mi;
int main(){
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		a[i]++;
	}
	for(int i=2;i<=n;i++){
		if(a[i]<a[i-1])b[i]=1;
		c[i]=c[i-1]+b[i];
	}
	int tot=0,ans=n-k+1;
	for(int i=k;i<=n;i++){
		if(c[i]==c[i-k+1])tot++;
	}
	if(tot)ans-=tot-1;
	mx.id=1;
	for(int i=1;i<=n;i++){
		mx.ins(i),mi.ins(i);
		if(i>k&&mx.f()==a[i]&&mi.f()==a[i-k]){
			if(c[i]==c[i-k+1]&&c[i-1]==c[i-k])continue;
			ans--;
		}
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 5888
# util functions

# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag

def pd(str)
  p str if $debugFlag
end

# input
inputs = []
lc = 0

as = []
bs = []
cs = []
mm = 0
while l = $stdin.gets do
  if lc == 0
    tmp = l.chomp.split(" ").map(&:to_i)
    nn = tmp[0]
    mm = tmp[1]
  else
    tmp = l.chomp.split(" ").map(&:to_i)
    as << tmp[0]
    bs << tmp[1]
    cs << tmp[2]
  end
  lc += 1
end

# input check
if $debugFlag
  p "--- INPUT (begin) ---"
  inputs.each do |l_i|
    p l_i
  end
  p "--- INPUT (end) ---"
  print "\n"
end

# body
if $debugFlag
  p as
  p bs
  p cs
end

scores = []
8.times do |i|
  coef1 = i[0] == 1 ? 1 : -1
  coef2 = i[1] == 1 ? 1 : -1
  coef3 = i[2] == 1 ? 1 : -1
  tmp = []
  pd "#{coef1}, #{coef2}, #{coef3}"
  nn.times do |j|
    tmp << (coef1*as[j] + coef2*bs[j] + coef3*cs[j])
  end
  scores << tmp
end

cand = []
scores.length.times do |i|
  tmp = scores[i].sort[-mm..-1].inject(:+)
  pd tmp
  cand << tmp
end

if mm == 0
  puts 0
else
  puts cand.max
end

Measured memory_bytes: 2040
n = int(input())
while True:
    s = input()
    if s == "-":
        n -= int(input())
    elif s == "+":
        n += int(input())
    elif s =="*":
        n *= int(input())
    elif s == "/":
        n = int(n/int(input()))
    else:
        print(n)
        break


Measured memory_bytes: 5588
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    ll N;
    cin >> N;

    ll ans = 0;
    ll ct = 10;
    while (ct <= N) {
        ans += N / ct;
        ct *= 5;
    }

    if (N % 2) ans = 0;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
const lint mod=1e9+7;

vector<string> split(const string s, char delim) {
    vector<string> elems;
    stringstream ss(s);
    string item;
    while (getline(ss, item, delim)) {
    if (!item.empty()) {
            elems.push_back(item);
        }
    }
    return elems;
}

int main()
{
  string s;
  cin >> s;
  lint q;
  cin >> q;
  string line;
  getline(cin,line,'\n');  // なんかこれ入れないとおかしくなる
  std::vector<std::vector<string>> query;
  REP(i,q){
    getline(cin,line,'\n');
    query.push_back(split(line, ' '));
  }

  lint cnt = 0;
  auto itr = query.begin();
  while(itr != query.end()){
    if((*itr)[0] == "1"){
      cnt++;
      itr++;
    }else{
      if((cnt%2 == 0) == ((*itr)[1] == "1")){
        s.insert(0, (*itr)[2]);
      }else{
        s.insert(s.size(), (*itr)[2]);
      }
      itr++;
    }
  }

  if(cnt%2) reverse(s.begin(), s.end());

  cout << s << "\n";
  return 0;
}


Measured memory_bytes: 45244
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll ;
#define rep(i, a, b) for (int i = a; i <= b; ++ i) 
const int N = 805, inf = 1e9 + 7 ;
const int flg[4][2] = {{1, 0}, {- 1, 0}, {0, 1}, {0, - 1}} ;
using namespace std ;

int n, m, k, f[N][N] ;
char a[N][N] ;
struct poi {
	int x, y ;
} opt[N * N] ;

bool check(int x, int y) {
	return (a[x][y] != '#' && x >= 1 && y >= 1 && x <= n && y <= m && f[x][y] == inf) ;
}

int main() {
	scanf("%d%d%d", &n, &m, &k) ;
	rep(i, 1, n) scanf("%s", a[i] + 1) ;
	int x, y ;
	rep(i, 1, n) rep(j, 1, m) if (a[i][j] == 'S') x = i, y = j ;
	int he = 0, ta = 1 ;
	rep(i, 1, n) rep(j, 1, m) f[i][j] = inf ;
	opt[1].x = x, opt[1].y = y, f[x][y] = 0 ;
	for ( ; he != ta; ) {
		++ he ;
		int x = opt[he].x, y = opt[he].y ;
		rep(i, 0, 3) {
			int xx = x + flg[i][0], yy = y + flg[i][1] ;
			if (check(xx, yy)) f[xx][yy] = f[x][y] + 1, ++ ta, opt[ta].x = xx, opt[ta].y = yy ; 
		}
	}
	int ans = inf ;
	rep(i, 1, n) rep(j, 1, m) if (f[i][j] <= k) ans = min(ans, (min(i - 1, min(n - i, min(j - 1, m - j))) + k - 1) / k + 1) ;
	printf("%d\n", ans) ;
	return 0 ;
}

Measured memory_bytes: 8448
mod=10**9+7
import math
import sys
from collections import deque
import heapq
import copy
import itertools
from itertools import permutations
from itertools import combinations
import bisect
def mi() : return map(int,sys.stdin.readline().split())
def ii() : return int(sys.stdin.readline().rstrip())
def i() : return sys.stdin.readline().rstrip()
a=ii()
print(a*(a-1)//2)

Measured memory_bytes: 67888
#include <iostream>

using namespace std;

int main()
{
  int N, num = 0, aux = 0; 

  cin >> N;
  
  int C[N], V[N];
  for(int i=0;i<N;i++){
    cin >> V[i];
  }
  for(int w=0;w<N;w++){
    cin >> C[w];
  }
  for(int z=0;z<N;z++){
    if(V[z] > C[z]){
      num += V[z];
      aux += C[z];
    }
  }

  cout << num-aux << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	string s;
	cin >> s;
	
	s[5] = ' ';
	s[13] = ' ';
	cout << s << endl;
	return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
typedef pair<pii, pii> piipii;

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define eb emplace_back

int h[100005];
ll h2[100005];
int main(){
    int n, a, b;
    scanf("%d%d%d", &n, &a, &b);
    int c = a-b;
    priority_queue<int> pq;
    for(int i=1;i<=n;i++) scanf("%d", &h[i]);
    int lo = 1, hi = 1e9, ans;
    while(lo <= hi){
        int mid = (lo+hi)/2;

        ll cnt = 0;
        for(int i=1;i<=n;i++){
            if(h[i] <= mid*1ll*b) continue;
            cnt += (h[i]-mid*1ll*b+(a-b)-1)/(a-b);
        }
        if(cnt <= mid) ans = mid, hi = mid-1;
        else lo = mid+1;
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 640
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = input()[:-1].decode()
    last = int(n[-1])
    if last == 2 or last == 4 or last == 5 or last == 7 or last == 9:
        print('hon')
    elif last == 0 or last == 1 or last == 6 or last == 8:
        print('pon')
    elif last == 3:
        print('bon')


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

void solve(int test_case) {
	int n;
	cin>>n;
	bool arr[n+1];
	fill(arr,arr+n+1,true);
	ll ans  = 1;
	for(int i=2;i<=n;i++) {
		if(!arr[i])continue;
		int m = n;
		int loc = 0;
		while(m>0) {
				m/=i;
				loc+=m;
		}
		ans*=(loc+1);
		ans%=1000000007;
		for(int j=i+i;j<=n;j+=i)arr[j]=false;
	}
	cout<<ans;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("in", "r", stdin);
	//freopen("out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
}	


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

long long MOD = 1000000000 + 7;

int main() {
    long long n, k; cin >> n >> k;
    long long res = 0;
    for (int i = k; i <= n + 1; i++) {
        res += (n - (i - 1)) * i + 1;
        res %= MOD;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3636
#include <cstdio>
#include <cmath>

int main (){
    int N;
    scanf("%d",&N);
    int w[N];
    int sum=0;
    for (int i = 0; i < N; i++){
        scanf("%d",&w[i]);
        sum+=w[i];
    }
    int halfweight=0;
    int idx=0;
    while(halfweight<sum/2){
        halfweight+=w[idx];
        idx++;
    }
    if(halfweight-sum/2>sum/2-halfweight+w[idx-1]) halfweight-=w[idx-1];
    halfweight=std::abs(sum-2*halfweight);
    printf("%d",halfweight);
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include<string>
#include <set>
#include <map>
#include <queue>
#include <limits.h>
#include <bitset>

using namespace std;

#define rip(i, n, s) for (int i = (s);i < ( int )( n ); i++)
#define all(a) (a).begin(), (a).end()
typedef long long ll;

int main() {
	int n, k;
	cin >> n >> k;
	vector<ll> da(n);
	rip(i, n, 0) {
		cin >> da[i];
	}
	vector<ll> li(n*(n + 1) / 2);
	int co = 0;
	rip(i, n, 0) {
		li[co] = da[i];
		co++;
		rip(j, n, i + 1) {
			li[co] = li[co - 1] + da[j];
			co++;
		}
	}
	vector<bitset<40>> arr(n*(n + 1) / 2);
	rip(i, n*(n + 1) / 2, 0) {
		arr[i] = bitset<40>(li[i]);
	}
	int m = n * (n + 1) / 2;
	bitset<40> ans, now;
	now.set(39);
	rip(i, 40, 0) {
		ans = ans | now;
		int gg = 0;
		rip(j, m, 0) {
			bitset<40> hoge = arr[j] & ans;
			if (hoge==ans) {
				gg++;
			}
		}
		if (gg < k) {
			ans = ans ^ now;
		}
		now >>= 1;
	}
	ll answer = ans.to_ullong();
	cout << answer << endl;
}

Measured memory_bytes: 8064
#include<bits/stdc++.h>
using namespace std;
int n,k,mx,i;
string b[200005];
string s[200005];
map<string,int>m,f;
int main(){
           cin>>n;
           for(k=1;k<=n;k++){
                      cin>>s[k];
                      m[s[k]]++;
                      mx=max(m[s[k]],mx);
           }
           
           for(k=1;k<=n;k++){
                      if(m[s[k]]==mx && f[s[k]]==0){
                                 i++;
                                 f[s[k]]=1;
                                 b[i]=s[k];
                      }
           }
           sort(b+1,b+i+1);
           for(k=1;k<=i;k++){
           if(k!=i)cout<<b[k]<<endl;
           else cout<<b[k];}
}

Measured memory_bytes: 40832
#include <bits/stdc++.h>
using namespace std;
int main() {
  
  int n,m;
  cin >> n >> m;
  int64_t mod = 1000000007;
  vector<bool> cont(n , false);
  
  vector<int64_t> dp(n+2);
  dp.at(n) = 1;
  
  for(int i = 0 ; i < m ; i++){
    int a;
    cin >> a;
    cont.at(a) = true;
  }
  
  for(int i = n - 1 ; i >= 0 ; i--){
    
    if(cont.at(i)){
      continue;
    }
      dp.at(i) = ( dp.at(i+1) + dp.at(i+2) ) % mod;
  }
  
  cout << dp.at(0) << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rfor(i, a, b) for(int i = a; i < (int)b; i++)
#define all(ary) (ary).begin(), (ary).end()
#define debug(x) cerr << #x << ": " << x << '\n'
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
using namespace std;
using v = vector<int>;
using ll = long long;
template <class T = int> T in(){ T x; cin >> x; return (x);}

int main(int argc, char *argv[]){
    int a, b; cin >> a >> b;
    cout << (a+b)%24 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long int ll;
typedef long double ld;
const ll INF=(1LL<<62);
const ld pi=acosl((ld)-1);
const ll mod = 1000000007;
// const ll mod = 1234567;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
#define endn "\n"
#define TO_STRING(VariableName) # VariableName

template <typename T>ostream &operator<<(ostream &out,const vector<T> &v) {rep(i,(int)v.size()-1)cout<<v[i]<<" ";cout<<v[(int)v.size()-1];return out;}
template <typename T1, typename T2>ostream &operator<<(ostream &out, const map<T1, T2> &p) {out << "(" << p.first << ", " << p.second << ")";return out;}
template <typename T1, typename T2>ostream &operator<<(ostream &out, const pair<T1, T2> &p){out << "(" << p.first << ", " << p.second << ")";return out;}
template<class T>void debag(const T &obj){cout<<obj<<endl;}

bool solve(){
  ll n;cin>>n;
  vector<ll>h(n);
  rep(i,n)cin>>h[i];
  vector<ll>dp(n,INF);
  dp[0]=0;

  rep(i,n){
    if(i+2<n)chmin(dp[i+2],dp[i]+abs(h[i+2]-h[i]));
    if(i+1<n)chmin(dp[i+1],dp[i]+abs(h[i+1]-h[i]));
  }

  cout<<dp[n-1]<<endl;

  return false;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout<<fixed<<setprecision(30);
    solve();
}


Measured memory_bytes: 1792
require 'pp'

n, m = gets.split.map(&:to_i)
h_n = gets.split.map(&:to_i)

path = {}
m.times do |i|
    a, b = gets.split.map(&:to_i)
    path[a] ||= {}
    path[a][b] = 1
    path[b] ||= {}
    path[b][a] = 1
end

count = 0
1.upto(n) do |i|
    if path[i] == nil
        count += 1
        next
    end
    
    if path[i].all? {|k, _| h_n[i-1] > h_n[k-1] }
        count += 1
    end
end

puts count


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

int N;
int S[400010], ans[200010], cnt = 1;
vector<vector<int> > Doors;
vector<int> Cycle;

void prec() {
    Cycle = Doors[0];

    for(int i = 1; i < Doors.size(); i++) {
        ans[ Cycle.back() ] = cnt;
        ans[ Doors[i][0] ] = cnt;
        cnt++;

        Cycle.pop_back();
        for(int j = 1; j < Doors[i].size(); j++) {
            Cycle.push_back(Doors[i][j]);
        }
    }

    ans[ Cycle[0] ] = cnt;
    ans[ Cycle.back() ] = cnt;
    cnt++;

    Cycle.erase(Cycle.begin());
    Cycle.pop_back();
}

void solve() {
    for(int i = 0; i < (int)Cycle.size() - 3; i += 4) {
        ans[ Cycle[i] ] = cnt;
        ans[ Cycle[i + 2] ] = cnt;
        cnt++;

        ans[ Cycle[i + 1] ] = cnt;
        ans[ Cycle[i + 3] ] = cnt;
        cnt++;
    }

    int p = 0;
    for(int i = 0; i < 2 * N; i++) if(!ans[i]) {
        ans[i] = cnt;
        cnt += p;
        p ^= 1;
    }

    printf("Yes\n");
    for(int i = 0; i < 2 * N; i++) {
        printf("%d ", ans[i]);
    }
}

int main() {
    scanf("%d", &N);

    scanf("\n");
    for(int i = 1; i < 2 * N; i++) {
        char t; scanf("%c", &t);
        S[i] = t - '0';
    }

    S[0] = 1;
    for(int i = 0; i < 2 * N; i++) S[2 * N + i] = S[i];

    int p = -1;
    for(int i = 0; i < 2 * N; i++) if(!S[i]) {
        p = i;
        break;
    }
    if(p == -1) {
        if(N % 2) printf("No");
        else {
            for(int i = 0; i < 2 * N; i++) Cycle.push_back(i);
            solve();
        }
        return 0;
    }

    for(int i = p + 1; i <= 2 * N + p; i++) {
        if(!S[i - 1] && S[i]) {
            Doors.push_back(vector<int>());
            Doors.back().push_back((i + 2 * N - 1) % (2 * N));
        }
        if(S[i]) Doors.back().push_back(i % (2 * N));
    }

    int sum = 0;
    for(int i = 0; i < Doors.size(); i++) {
        sum += (int)Doors[i].size() - 2;
    }

    /*
    for(int i = 0; i < Doors.size(); i++) {
        for(int j = 0; j < Doors[i].size(); j++) {
            cout << Doors[i][j] << ' ';
        }
        cout << endl;
    }
    //*/

    if(sum % 2) {
        printf("No");
        return 0;
    }
    if(sum % 4 == 0) {
        prec();
        solve();
        return 0;
    }

    vector<int> tmp;
    for(int i = 0; i < Doors.size(); i++) if(Doors[i].size() > 2) {
        tmp.push_back(i);
    }

    if(tmp.size() < 2) {
        printf("No");
        return 0;
    }

    ans[ Doors[ tmp[0] ][ (int)Doors[ tmp[0] ].size() - 2 ] ] = cnt;
    ans[ Doors[ tmp[1] ][ (int)Doors[ tmp[1] ].size() - 2 ] ] = cnt;
    cnt++;

    Doors[ tmp[0] ].erase(Doors[ tmp[0] ].end() - 2);
    Doors[ tmp[1] ].erase(Doors[ tmp[1] ].end() - 2);
    swap(Doors[ tmp[0] ].back(), Doors[ tmp[1] ].back());

    prec();
    solve();
}


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

int main() {
  int64_t n;
  cin >> n;
  int a = n, sum = 0;
  for (int i = 0; 0 < a; i++) {
    sum += a % 10;
    a /= 10;
  }
  if (n % sum == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define pb push_back
const int maxn = 10000;
const int INF32 = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7 = 1'000'000'007;
const int MOD9 = 1'000'000'009;
const int mod = MOD7;

void ERROR(int num) { cout << "ERROR" << num << endl; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};


int main(){
  //std::ios::sync_with_stdio(false);
  //std::cin.tie(0);
  double a, b, x;
  cin >> a >> b >> x;
  double s = x / a;
  double rad;
  if(s > a*b/2){
    double h = (a*b-s)*2/a;
    rad = atan(a/h);
  }else{
    double h = 2*s/b;
    rad = atan(h/b);
  }
  double PI = acos(-1);
  double ans = 90-rad*180/PI;
  //ans = max(90-ans,ans);
  printf("%.10lf", ans);
}

Measured memory_bytes: 384
#include <stdio.h>
#include <math.h>
#define true 1
#define false -1
int isprime(int);
int main(){
  int i, j,count = 0,p_count = 0;
  int flag;
  int n;

  /*n?????\???*/
  scanf("%d",&n);
  int num[n];
  for(i = 0; i < n; i++){
    scanf("%d",&num[i]);
  }
  i = 0;
  while(count < n){
     if((isprime(num[count])) == true){
       p_count++;
     }
     count++;
  }
  printf("%d\n",p_count);
  return 0;
}
int isprime(int x){
  int i;
  if(x == 2){
    return true;
  }
  if(x< 2 || x % 2 == 0){
    return false;
  }
  i = 3;
  while(i <= sqrt(x)){
    if(x % i == 0){
      return false;
    }
    i = i + 2;
  }
return true;
}

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

int iC[ 20 ];

int main()
{
int i;
int N;
int a;
int iColor;

	ios::sync_with_stdio( false );
	cin.tie( 0 );

	cin >> N;
	for( i = 0; i < N; i++ )
	{
		cin >> a;
		if( a < 400 )
			iC[ 0 ]++;
		else if( a < 400 )
			iC[ 1 ]++;
		else if( a < 800 )
			iC[ 2 ]++;
		else if( a < 1200 )
			iC[ 3 ]++;
		else if( a < 1600 )
			iC[ 4 ]++;
		else if( a < 2000 )
			iC[ 5 ]++;
		else if( a < 2400 )
			iC[ 6 ]++;
		else if( a < 2800 )
			iC[ 7 ]++;
		else if( a < 3200 )
			iC[ 8 ]++;
		else
			iC[ 9 ]++;
	}

	iColor = 0;
	for( i = 0; i <= 8; i++ )
	{
		if( iC[ i ] > 0 ) iColor++;
	}

	if( iColor <= 0 )
	{
		cout << 1 << " ";
		cout << iC[ 9 ] << endl;
	}
	else
	{
		cout << iColor << " ";
		cout << iColor + iC[ 9 ] << endl;
	}

	return 0;
}



Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
#define pb push_back
#define __V vector
#define all(x) x.begin(), x.end()
#define oit ostream_iterator
#define mod 1000000007ll
using namespace std;
void doin() {
	cin.tie();
	cout.tie();
	ios::sync_with_stdio(0);
#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif
}
template<typename X, typename Y>
istream& operator>>(istream& in, pair<X, Y> &a) {
	in >> a.first >> a.second;
	return in;
}
template<typename T>
void getv(T& i) {
	cin >> i;
}
template<typename T, typename ... Ns>
void getv(vector<T>& v, int n, Ns ... ns) {
	v.resize(n);
	for (auto& i : v)
		getv(i, ns...);
}
template<typename T>
void getv1(T& i) {
	cin >> i;
}
template<typename T, typename ... Ns>
void getv1(vector<T>& v, int n, Ns ... ns) {
	v.resize(n + 1);
	for (int i = 1; i <= n; i++)
		getv(v[i], ns...);
}
#ifdef _WIN32
#define getchar_unlocked() _getchar_nolock()
#define _CRT_DISABLE_PERFCRIT_LOCKS
#endif
inline void getch(char &x) {
	while (x = getchar_unlocked(), x < 33) {
		;
	}
}
inline void getstr(string &str) {
	str.clear();
	char cur;
	while (cur = getchar_unlocked(), cur < 33) {
		;
	}
	while (cur > 32) {
		str += cur;
		cur = getchar_unlocked();
	}
}
template<typename T> inline bool sc(T &num) {
	bool neg = 0;
	int c;
	num = 0;
	while (c = getchar_unlocked(), c < 33) {
		if (c == EOF)
			return false;
	}
	if (c == '-') {
		neg = 1;
		c = getchar_unlocked();
	}
	for (; c > 47; c = getchar_unlocked())
		num = num * 10 + c - 48;
	if (neg)
		num *= -1;
	return true;
}
typedef unsigned long long ull;
typedef long long ll;
typedef float ld;
typedef ll _I;
typedef pair<_I, _I> pi;
typedef pair<ld, ld> pd;
typedef map<_I, _I> mii;
typedef __V <_I> vi;
typedef __V <char> vc;
typedef __V <ld> vd;
typedef __V <vd> vvd;
typedef __V <pi> vpi;
typedef __V <__V<_I>> vvi;
typedef __V <__V<char>> vvc;
typedef __V <__V<pi>> vvpi;
using AntonTsypko = void;
using arsijo = AntonTsypko;
using god = arsijo;
uniform_real_distribution<double> double_dist(0, 1);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
	doin();
	int ans = 0, t, c = 0;
	for(int i = 0; i < 5; i++) {
		cin >> t;
		if(t%10 != 0 && (c == 0 || c%10 > t%10)) c = t;
		t = (t+9)/10;
		ans += 10*t;
	}
	ans -= ((c+9)/10)*10;
	ans += c;
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
#include<functional>
#include<stack>
#include<tuple>
#include<cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using ll = long long;
using P = pair<int, int>;
using MATRIX = vector< vector<ll> >;

int N, M, Q;
int a[50], b[50], c[50], d[50];
int ar[20];
int ans = 0;

void dfs(int p, int q) {
  if(p == N && q == M-1) {
    int key = 1;
    int temp = 0;
    vector<int> v;
    rep(i, N + M - 1) {
      if(ar[i] == 1) key++;
      else {
        v.push_back(key);
      }
    }
    // rep(i, v.size()) {
    //   cout << v[i] << " ";
    // }
    // cout << endl;
    rep(i, Q) {
      if(v[b[i]] - v[a[i]] == c[i]) {
        temp += d[i];
      }
    }
    // cout << temp << endl;
    ans = max(ans, temp);
  } else if(p == N) {
    ar[p+q] = 1;
    dfs(N, q + 1);
  } else if(q == M-1) {
    ar[p+q] = 0;
    dfs(p+1, M-1);
  } else {
    ar[p+q] = 0;
    dfs(p+1, q);
    ar[p+q] = 1;
    dfs(p, q+1);
  }
}

int main() {
  cin >> N >> M >> Q;
  rep(i, Q) {
    cin >> a[i] >> b[i]>> c[i] >> d[i];
    a[i]--;b[i]--;
  }

  dfs(0, 0);

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3624
#include<iostream>
using namespace std;
int main(){
    int N;
    int max = -1,min = 1000000000;
    cin >> N;
    for(int i=0;i<N;i++){
        int baf;
        cin >> baf;
        if(max < baf){
            max = baf;
        }
        if(min > baf){
            min = baf;
        }
    }
    cout << max-min << endl;
    return 0;
}

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

using ll = long long;
using ull = unsigned long long;

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

int f(int n, int i, vector<vector<int> > &dp, vector<vector<int> > &v) {
	if(n == 0) {
		return v[n][i];
	}
	if(dp[n][i] != -1) return dp[n][i];
	int x = 0;
	for(int j = 0; j < 3; j++) {
		if(i != j) {
			x = max(x, f(n - 1, j, dp, v) + v[n][i]);
		}
	}
	dp[n][i] = x;
	return x;
}

void solve() {
	int n;
	cin >> n;
	vector<vector<int> > v(n, vector<int>(3));
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < 3; j++){
			cin >> v[i][j];
		}
	}
	vector<vector<int> > dp(n, vector<int>(3, -1));
	int ans = INT_MIN;
	for(int i = 0; i < 3; i++) {
		ans = max(ans, f(n - 1, i, dp, v));
	}
	cout << ans << "\n";
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	solve();
	
	return 0;
}


Measured memory_bytes: 23520
import java.util.Scanner;

class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int Y = sc.nextInt() / 1000;
    for (int i = 0; i <= Y / 10; i++) {
      for (int j = 0; j <= Y / 5; j++) {
        if (i * 10 + j * 5 > Y || i + j > N) {
          break;
        }
        for (int k = 0; k <= Y; k++) {
          if (i * 10 + j * 5 + k > Y || i + j + k > N) {
            break;
          }
          if (i * 10 + j * 5 + k == Y && i + j + k == N) {
            System.out.println(String.format("%d %d %d", i, j, k));
            return;
          }
        }
      }
    }
    System.out.println("-1 -1 -1");
  }

}


Measured memory_bytes: 23124
#include<stdio.h>

int main(){
        int i = 0,t[26]={0},c;
        while((c=getchar()) != EOF){
                c=(c<=90?c-65:c-97);
                t[c]++;
        }
        for(i=0;i<26;i++) printf("%c : %d\n",(97+i),t[i]);
        return 0;
}

Measured memory_bytes: 524
#
# File    : B.rb
# Author  : Kazune Takahashi
# Created : 2/3/2019, 9:02:53 PM
# Powered by Visual Studio Code
#

n = gets.to_i
l = gets.chomp.split(" ").map{|i| i.to_i}
sum = l.inject(:+)
maxi = l.max
if sum - maxi > maxi
  puts "Yes"
else
  puts "No"
end

Measured memory_bytes: 1788