akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <set>
using namespace std;
int main(void){
    // Your code here!
    int n;
    cin >> n;
    
    int last = -1;
    int count=0;
    for(int i=0; i<n; i++) {
        int tmp;
        cin >> tmp;
        if(tmp == last) {
            count++;
            last = -1;
        }else {
            last = tmp;
        }
    }
    cout << count << endl;
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long n,m,cd=1,c=1;
int lcm(int a,int b)
{
	return a/__gcd(a,b)*b;
}
int main()
{
  	cin>>n>>m;
    int x;
    for(int i=1;i<=n;i++)
    {
        long long a; 
      	cin>>a;
        cd=lcm(cd,a);
        c=lcm(c,a/2);
        int tmp=0;
        while(a%2==0)
		{
            tmp++;
            a/=2;
        }
        if(i==1)
          	x=tmp;
        else 
			if(x!=tmp||c>m)
	        {
	            cout<<0<<endl;
	            exit(0);
	        }
    }
    if(m<c)
      	cout<<0;
    else 
      	cout<<((m-c)/cd)+1;
}

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

int main(){
  int n;
  cin >> n;
  vector<string> s(n);
  for(int i=0; i<n; i++) {
    cin >> s.at(i);
  }
  sort(s.begin(), s.end());
  string now = s.at(0);
  int ans = 1;
  for(int i=0; i<n; i++) {
    if(now != s.at(i)) {
      ans++;
      now = s.at(i);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 9600
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;
typedef long long ll;
int main(){
    ll N; cin >> N;
    string S = "";
    if(N % 2 == 0) S += "0";
    if(N % 2 != 0) {S += "1"; N -= 1;}
    ll cnt = 2;
        
    for(ll i = 0; i < 50; i++){
    //while(1){
        if(N == 0) break;
        ll powed = pow(-2, cnt);
        if(N % powed == 0) S += "0";
        else {
            N -= pow(-2, cnt-1);
            S += "1";
            //cout << N << " " << pow(-2, cnt-1) << endl;
        }
        cnt++;
    }
    reverse(S.begin(), S.end());
    cout << S << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
const ll MOD=1000000007;
const long double PI=3.14159265358979;
const ll MAX=0;

int main() {
  string s;
  cin>>s;
  ll ans=0,d=s.size();
  rep(i,d){
    if(s[i]=='1'){
      ans+=1;
    }
    if(s[i]=='2'){
      ans+=2;
    }
    if(s[i]=='3'){
      ans+=3;
    }
    if(s[i]=='4'){
      ans+=4;
    }
    if(s[i]=='5'){
      ans+=5;
    }
    if(s[i]=='6'){
      ans+=6;
    }
    if(s[i]=='7'){
      ans+=7;
    }
    if(s[i]=='8'){
      ans+=8;
    }
    if(s[i]=='9'){
      ans+=9;
    }
    if(s[i]=='0'){
      ans+=0;
    }
  }
  if(ans%9){
    cout<<"No";
   // cout<<ans;
  }
  else{
    cout<<"Yes";
  }
}


Measured memory_bytes: 3752
#include<stdio.h>

void swap(int *x, int *y) {
        int z;
        z = *x;
        *x = *y;
        *y = z;
}

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

        while(!(x == 0 && y == 0)) {
                if( x > y) {
                                swap(&x, &y);
                }

                printf("%d %d\n", x, y);
                scanf("%d %d", &x, &y);
        }

        return 0;
}

Measured memory_bytes: 596
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		 s =  s.replaceAll("0","");
		 System.out.println(s.length());
		

	}

}


Measured memory_bytes: 19796
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
using namespace std;

int n, m, k;
char s[100005], t[100005];

int gcd(int x, int y)
{
	return y==0?x:gcd(y, x%y);	
}

int main()
{
	scanf("%d%d", &n, &m);
	scanf("%s%s", s, t);
	k=gcd(n, m);
	for(int i=0; i<k; i++)
		if(s[1LL*i*n/k]!=t[1LL*i*m/k])
		{
			printf("-1\n");
			return 0;
		}
	printf("%lld\n", 1LL*n*m/k);
	return 0;
}

Measured memory_bytes: 384
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<vector>
using namespace std;

#define ll long long

#define debug_message 0
#define debug if (debug_message)

#define sz(x) (int)x.size()

ll i,t,j;
ll n,m,nt,a,b;
string s,s1,s2;
char c;

int main(){
	scanf("%lld %c %lld",&a,&c,&b);
	
	if (c=='+') printf("%lld\n",a+b);
	else if (c=='-') printf("%lld\n",a-b);
	
	return 0;
}
/*

*/

Measured memory_bytes: 3776
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
using namespace std;

void solve(){
  int n, a, b; cin >> n >> a >> b;
  int ans = 0;
  for(int i = 1; i <= n; i++){
    string s = to_string(i);
    int sum = 0;
    for(int j = 0; j < s.length(); j++) sum += (int)s[j] - '0';
    if(sum >= a && sum <= b) ans += i;
  }
  cout << ans << endl;
  return;
}

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


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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    bool flag = true;
    for (int i = 0; i < n; i++) {
        if (a[i]%2 == 1) continue;
        if (a[i]%3 != 0 && a[i]%5 != 0) {
            flag = false;
        }
    }
    if (flag) {
        cout << "APPROVED" << endl;
    } else {
        cout << "DENIED" << endl;
    }
    return 0;
}

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

int main(){

    string s;
    cin >> s ;

    ll i=0,j=s.size()-1;

    ll ans=0;

    while(i<j){
        if(s[i]==s[j]){
            i++;
            j--;
        }else if(s[i]=='x'){
            i++;
            ans++;
        }else if(s[j]=='x'){
            j--;
            ans++;
        }else{
            cout << -1 << endl;
            return 0;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
H, W = map(int, input().split())
edges = [[ None for i in range(W) ] for j in range(H)]

for h in range(H):
  v = input()
  for w in range(W):
    edges[h][w] = v[w]

for h in range(H):
  for w in range(W):
    if edges[h][w] == ".": continue

    flag = False
    flag = flag or (w + 1 != W and edges[h][w+1] == "#") # 右
    flag = flag or (w != 0 and edges[h][w-1] == "#") # 左
    flag = flag or (h + 1 != H and edges[h+1][w] == "#") # 下
    flag = flag or (h != 0 and edges[h-1][w] == "#") # 上

    if not flag:
      print("No")
      exit()

print("Yes")


Measured memory_bytes: 3064
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
#include <queue>
#include <tuple>
#include <functional>
#include <cstring>

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int  i = 0; i < n; i++)
#define irep2(i,a,n) for(int i = a; i <= n; i++)
#define lrep(i,n) for(long long  i = 0; i < n; i++)
#define lrep2(i,a,n) for(long long i = a; i <= n; i++)

typedef long long ll;
typedef std::vector<int> v_int;
typedef std::vector<std::vector<int> > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll> > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<std::vector<std::string> > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<std::vector<bool> > v2_bool;
typedef std::pair<ll, ll> pll;

using namespace std;

int main(void){
    int n;
    cin >> n;
    int h[n+5][3];

    irep(i, n) {
        irep(j, 3) {
            cin >> h[i][j];
        }
    }

    int dp[n+5][3];

    irep(i, n) { 
        irep(j, 3) { 
            dp[i][j] = 0; 
        }
    }
    dp[0][0] = h[0][0]; 
    dp[0][1] = h[0][1]; 
    dp[0][2] = h[0][2]; 
    irep(i, n) {
        irep(j, 3) {
            irep(k, 3) {
                if(j == k) { continue; }
                dp[i+1][j] = max(dp[i+1][j], dp[i][k]+h[i+1][j]);
            }
        }
    }   
    int ans = -1;
    irep(j, 3) ans = max(ans, dp[n-1][j]); 
    cout << ans << endl;
	return 0;
}
/** atcodr **/


Measured memory_bytes: 2560
s = input()
n = len(s)

front = s[0:int((n-1)/2)]
back = s[int((n+3)/2)-1:n]

if s != s[::-1]:
    print("No")
else:
    if front == front[::-1] and back == back[::-1]:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
double heron(double a,double b,double c){
  double s=(a+b+c)/2;
  return sqrt(s*(s-a)*(s-b)*(s-c));
}
int main(){
  double a,l,x;
  while(cin>>a>>l>>x){
    double a1=heron(a,l,l);
    double a2=heron(l,(l+x)/2,(l+x)/2);
    printf("%.10f\n",a1+a2*2);
  }
}

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

int gcd(int a,int b)
{
   	if(a<b)swap(a,b);
   	if(a%b)return(gcd(b,a%b));
	else return(b);
}

int main()	
{
	int n,x,a;
	cin>>n>>x;
	vector<int>v(n),w;
	for(int i=0;i<n;i++)
	{
		cin>>v[i];
	}
	v.push_back(x);
	sort(v.begin(),v.end());
	for(int i=1;i<v.size();i++)
	{
		a=v[i]-v[i-1];
		w.push_back(a);
	}
	int k=w[0];
	for(int i=1;i<w.size();i++)
	{
		k=gcd(k,w[i]);
	}
	cout<<k<<endl;
	return 0;
}

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

void move_E(int dice[7]){
    int new_dice[7];
    new_dice[2]=dice[2];
    new_dice[5]=dice[5];
    new_dice[3]=dice[1];
    new_dice[1]=dice[4];
    new_dice[4]=dice[6];
    new_dice[6]=dice[3];

    for(int i=0; i<7; i++){
        dice[i]=new_dice[i];
    } 
}

void move_W(int dice[7]){
    int new_dice[7];
    new_dice[2]=dice[2];
    new_dice[5]=dice[5];
    new_dice[1]=dice[3];
    new_dice[4]=dice[1];
    new_dice[6]=dice[4];
    new_dice[3]=dice[6];

    for(int i=0; i<7; i++){
        dice[i]=new_dice[i];
    } 
}

void move_N(int dice[7]){
    int new_dice[7];
    new_dice[3]=dice[3];
    new_dice[4]=dice[4];
    new_dice[1]=dice[2];
    new_dice[2]=dice[6];
    new_dice[6]=dice[5];
    new_dice[5]=dice[1];

    for(int i=0; i<7; i++){
        dice[i]=new_dice[i];
    } 
}

void move_S(int dice[7]){
    int new_dice[7];
    new_dice[3]=dice[3];
    new_dice[4]=dice[4];
    new_dice[2]=dice[1];
    new_dice[6]=dice[2];
    new_dice[5]=dice[6];
    new_dice[1]=dice[5];

    for(int i=0; i<7; i++){
        dice[i]=new_dice[i];
    } 
}

void rot(int dice[7]){
    int new_dice[7];
    new_dice[1]=dice[1];
    new_dice[6]=dice[6];
    new_dice[2]=dice[3];
    new_dice[3]=dice[5];
    new_dice[5]=dice[4];
    new_dice[4]=dice[2];

    for(int i=0; i<7; i++){
        dice[i]=new_dice[i];
    } 
}

void ad_1(int dice[7], int new_dice[7]){
    if(dice[1] == new_dice[1]){
        ;
    }
    else if(dice[2] == new_dice[1]){
        move_N(dice);
    }
    else if(dice[3] == new_dice[1]){
        move_W(dice);
    }
    else if(dice[4] == new_dice[1]){
        move_E(dice);
    }
    else if(dice[5] == new_dice[1]){
        move_S(dice);
    }
    else if(dice[6] == new_dice[1]){
        move_N(dice);
        move_N(dice);
    }
}


void ad_2(int dice[7], int new_dice[7]){
    if(dice[2] == new_dice[2]){
        ;
    }
    else if(dice[3] == new_dice[2]){
        rot(dice);
    }
    else if(dice[5] == new_dice[2]){
        for(int i=0; i<2; i++){
            rot(dice);
        }
    }
    else if(dice[4] == new_dice[2]){
        for(int i=0; i<3; i++){
            rot(dice);
        }
    }
}


int main()
{
    int dice[7];
    int new_dice[7];
    for(int i=1; i<7; i++){
        scanf("%d", &dice[i]);
        //printf("%d ", dice[i]);
    }
    //printf("\n");

    int q;
    scanf("%d", &q);
    //printf("q:%d\n", q);

    for(int j=0; j<q; j++){
        scanf("%d %d", &new_dice[1], &new_dice[2]);
        
        ad_1(dice, new_dice);
        // for(int i=1; i<7; i++){
        //    printf("%d ", dice[i]);
        // }
        // printf("\n");

        ad_2(dice, new_dice);
        // for(int i=1; i<7; i++){
        //    printf("%d ", dice[i]);
        // }
        // printf("\n");

        printf("%d\n", dice[3]);
    }

    return 0;
}


Measured memory_bytes: 2028
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7;

pair<int, ll> p[N];
ll a[N], cum[N];

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n, dis, dam;
    cin >> n >> dis >> dam;
    for(int i = 0; i < n; i++){
        cin >> p[i].first >> p[i].second;
        a[i] = p[i].first;
    }
    sort(p, p + n);
    sort(a, a + n);
    ll ans = 0, sum = 0;
    for(int i = 0; i < n; i++){
        sum += cum[i];
        ll tmp = p[i].second - sum;
        if(tmp <= 0) continue;
        ll cost = tmp - tmp % dam;
        if(tmp % dam) cost += dam;
        sum += cost;
        ans += cost / dam;
        int idx = upper_bound(a, a + n, a[i] + 2 * dis) - a;
        cum[idx] -= cost;
        // update(1, 0, n - 1, 0, idx, cost);
    }
    cout << ans;

    return 0;
}


Measured memory_bytes: 9808
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))

ans=0
for i in range(n):
    eat=a[i]-1
    ans+=b[eat]
    if i!=0 and eat==a[i-1]:
        ans+=c[eat-1]


print(ans)


Measured memory_bytes: 3060
while s = gets
  s = s.chomp
  cnt_j = 0
  cnt_i = 0
  for i in 0..(s.length-2)
    t = s[i,3]
    if t == 'JOI'
       cnt_j += 1 
   end
   if t == 'IOI'
    cnt_i += 1 
  end
  end
  puts cnt_j
  puts cnt_i    
end



Measured memory_bytes: 6840
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repf(i,a,b) for (int i = (a); i < (b); i++)
#define repi(i,a,b) for (int i = (a); i <= (b); i++)
#define repr(i,a,b) for (int i = (a); i >= (b); i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(all(x));
#define RSORT(x) sort(rall(x));
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vd = vector<double>;
using vb = vector<bool>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;
const int inf = 1<<29;
const ll mod = 1000000007;
const double eps = 1e-9;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

int main () {
  int N; cin >> N;
  vi p(N); rep(i,N) cin >> p.at(i);

  bool flag = true;
  rep(i,N-1) {
    if(p.at(i)>p.at(i+1)) flag = false;
  }
  if(flag) {
    cout << "YES" << endl;
    return 0;
  }

  for (int i = 0; i <= N-2; i++) {
    for(int j = i+1; j <= N-1; j++) {
      swap(p.at(i),p.at(j));

      bool flag = true;
      rep(i,N-1) {
        if(p.at(i)>p.at(i+1)) flag = false;
      }
      if(flag) {
        cout << "YES" << endl;
        return 0;
      }

      swap(p.at(i),p.at(j));
    }
  }

  cout << "NO" << endl;
}

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

dp = [0 for _ in range(N)]
dp[1] = abs(H[1]-H[0])
for i in range(2,N):
  dp[i] = min(dp[i-1] + abs(H[i]-H[i-1]),dp[i-2] + abs(H[i]-H[i-2]))
print(dp[N-1])

Measured memory_bytes: 54264
#include <bits/stdc++.h>
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 fst first
#define pb push_back
#define mp make_pair
#define ALL(obj) (obj).begin(), (obj).end()
using ul = unsigned long;
using ll = long long;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;

ll a[5], n;

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

  cin >> n >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];

  ll neck = min( min( min(a[0], a[1]), min(a[2], a[3]) ), a[4] );

  if(neck >= n){
    cout << 5 << endl;
    return 0;
  }

  bool f=true;
  if(n%neck==0) f=false;

  ll ans=0;
  if(f) ans = 4+ (n/neck)+1;
  else  ans = 4+ (n/neck);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 50
int main()
{
    int N,i,j,temp,sum=0;
    int arr[MAX];
    while(scanf("%d",&N)!=EOF)
    {
        for(i=0;i<N;i++)
        {
            scanf("%d",&temp);
            arr[i]=temp;
        }
        for(i=0;i<N;i++)
        {
            for(j=i+1;j<N;j++)
            {
                sum+=arr[i]*arr[j];
            }
        }
        printf("%d\n",sum);
    }
    return 0;
}


Measured memory_bytes: 128
n,m=map(int,input().split())
h=list(map(int,input().split()))
a=[]
b=[]
l=[0]*n
for i in range(m):
    A,B=map(int,input().split())
    a.append(A)
    b.append(B)
for i in range(m):
    if h[a[i]-1] > h[b[i]-1]:
        l[b[i]-1] += 1
    elif h[a[i]-1] < h[b[i]-1]:
        l[a[i]-1] += 1
    else:
        l[a[i]-1] += 1
        l[b[i]-1] += 1
print(l.count(0))

Measured memory_bytes: 89916
#include<bits/stdc++.h>
using namespace std;
int main(void){
  pair<string,int> s,t;
  cin>>s.first>>t.first>>s.second>>t.second;
  string u; cin>>u;
  if(s.first==u) --s.second; else --t.second;
  printf("%d %d",s.second,t.second);
  return 0;
}


Measured memory_bytes: 3688
import java.util.Scanner;

public class Main {
	private static final String YES = "Yes";
	private static final String NO = "No";
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();
		
		boolean valid = (2*x <= y && y <= 4*x) && y%2 == 0;
		System.out.println(valid ? YES : NO);
	}

}


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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for(auto &x: v) cin >> x;
    long long sum=0;
    for(int x: v) sum += 2 * min(x, abs(k-x));
    cout << sum << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(void){
    long long  a,b,c,A,B;
    while(cin >> a >> b){
        A=a;
        B=b;
        while(b!=0){
            c=a%b;
            a=b;
            b=c;
        }
    cout<<a<<' '<<A/a*B<<endl;
    }
}


Measured memory_bytes: 2984
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;

int N;

void make_graph(vector<PL>& c, vector<vector<ll>>& g, map<P, ll>& m) {
  repi(i, 1, N) {
    ll cost = c[i].first - c[i - 1].first;
    int j = c[i - 1].second;
    int k = c[i].second;

    g[j].push_back(k);
    g[k].push_back(j);
    PL key = make_pair(j, k);
    if (m.count(key)) {
      ll current_cost = m.at(key);
      if (current_cost > cost) {
        m.erase(key);
        m.erase(make_pair(k, j));
      }
    }
    m.emplace(make_pair(j, k), cost);
    m.emplace(make_pair(k, j), cost);
  }
}

ll solve_prim(vector<vector<ll>>& g, map<P, ll>& m) {
  // cost, next
  priority_queue<PL, vector<PL>, greater<PL>> que;
  ll cost = 0;
  ll cnt = 0;
  vector<bool> reached(N, false);

  que.push(make_pair(0, 0));
  while (cnt < N || !que.empty()) {
    PL top = que.top();
    que.pop();

    ll current = top.second;
    if (reached[current]) continue;

    cost += top.first;
    reached[current] = true;
    cnt++;

    for (auto i : g[top.second]) {
      if (reached[i]) continue;
      ll _cost = m.at(make_pair(current, i));
      que.push(make_pair(_cost, i));
    }
  }
  return cost;
}

/**
 * 最小全域木 / プリム法
 * http://www.deqnotes.net/acmicpc/prim/
 */
int main() {

  cin >> N;

  vector<PL> x(N);
  vector<PL> y(N);
  rep(i, N) {
    ll _x, _y;
    cin >> _x >> _y;
    x[i] = make_pair(_x, i);
    y[i] = make_pair(_y, i);
  }

  vector<vector<ll>> g(N, vector<ll>(0));
  map<P, ll> m;
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());

  make_graph(x, g, m);
  make_graph(y, g, m);

  ll cnt = solve_prim(g, m);
  cout << cnt << endl;
}

Measured memory_bytes: 41716
N,X,Y=map(int,input().split())
#i<X<Y<j
#このときはX->を通るほうが良い
#X<=i<j<=Y
#このときはループのどちらかを通れば良い
#X<=i<=Y<j
#このときはiとYの最短距離+Yとjの最短距離
#i<X<=j<=Y
#同上
#i<j<X
#パスは1通りしか無い
def dist(i,j):
    if i>j:
        return dist(j,i)
    if i==j:
        return 0
    if i<X:
        if j<X:
            return j-i
        if X<=j and j<=Y:
            return min(j-i,(X-i)+1+(Y-j))
        if Y<j:
            return (X-i)+1+(j-Y)
    if X<=i and i<=Y:
        if j<=Y:
            return min(j-i,(i-X)+1+(Y-j))
        if Y<j:
            return min((i-X)+1+(j-Y),j-i)
    if Y<i:
        return (j-i)
ans=[0 for i in range(N)]
for i in range(1,N+1):
    for j in range(i+1,N+1):
        ans[dist(i,j)]+=1
for k in range(1,N):
    print(ans[k])

Measured memory_bytes: 75084
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;
using P = pair<int, int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef vector<ll> vi;
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
  ll n;
  cin >> n;
  print(n / 3);
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int i;
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String T = sc.next();
		String[] s = S.split("");
		String[] t = T.split("");
		int[] start = new int[26];
		int[] goal = new int[26];
		for (i = 0; i < 26; i++) {
			start[i] = -1;
			goal[i] = -1;
		}
		for (i = 0; i < s.length; i++) {
			 char[] x = s[i].toCharArray();
			 char[] y = t[i].toCharArray();
			 int a = x[0] - 'a';
			 int b = y[0] - 'a';

			 if (start[a] != -1 || goal[b] != -1) {
				 if (start[a] != b || goal[b] != a) {
					 System.out.println("No");
					 return;
				 }
			 }

			 start[a] = b;
			 goal[b] = a;
		}
		System.out.println("Yes");
	}
}

Measured memory_bytes: 68140
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
 int n;
 cin>>n;
 vector<int> a(n),b(n),c(n);
 for(int i=0;i<n;i++){
  cin>>a[i]>>b[i]>>c[i];
 }
 vector<vector<int>> dp(n,vector<int>(3));
 dp[n-1][0]=a[n-1];
 dp[n-1][1]=b[n-1];
 dp[n-1][2]=c[n-1];
 for(int i=n-2;i>=0;i--){
  dp[i][0]=max(dp[i+1][1]+a[i],dp[i+1][2]+a[i]);
  dp[i][1]=max(dp[i+1][0]+b[i],dp[i+1][2]+b[i]);
  dp[i][2]=max(dp[i+1][0]+c[i],dp[i+1][1]+c[i]);
 }
 cout<<max({dp[0][0],dp[0][1],dp[0][2]})<<endl;
 return 0;
}

Measured memory_bytes: 6912
#include<iostream>
using namespace std;
int main() {
	long long a[50];
	int  l = 1, u = 0;
	while (l <= 1000000000) {
		a[u] = l;
		l *= 2;
		u++;
	}
	int n;
	cin >> n;
	for (int z = 0; z < n; z++) {
		int sum = 0;
		long long  s, d;
		cin >> s >> d;
		while (true) {
			for (int i = u-1; i >= 0; i--) {
				if (s%a[i] == 0&&(d-s)>=a[i]) {
					sum++;
					s += a[i];
					break;
				}
			}
			if (s == d) break;
		}
		cout << sum << endl;
	}
}

Measured memory_bytes: 3064
// Ivan Carvalho
// Problem A - Educational Dynamic Programming Contest - AtCoder
// Link : https://atcoder.jp/contests/dp
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 1e5 + 10;
const int INF = 2 * 1e9;

int dp[MAXN], N, K, h[MAXN];

int main() {


	//scanf("%d", &N);
	cin>>N>>K;
	//K = 2;
	for (int i = 1; i <= N; i++) {
		scanf("%d", &h[i]);
		dp[i] = INF;
	}
	dp[1] = 0;
	for (int i = 1; i <= N; i++) {
		//dp[i] = INF;
		//dp[i] = min(abs(h[i] - h[i + 1]), abs(h[i] - h[i + 2]));
		for (int j = 1; j <= min(K, N - i); j++)
		{
			dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[j + i]));
		}
		// for(int j = i+1;j>=max(i - K,1);j--){
		// 	dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]) );

	}

	printf("%d\n", dp[N]);

	return 0;

}

Measured memory_bytes: 1024
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    *A, = map(int,open(0).read().split())
    print(sum(A[:2])*A[-1]//2)    
if __name__ == '__main__':
    main()

Measured memory_bytes: 3444
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_A

num = int(input())

A = list(map(int, input().split()))
print(" ".join(list(map(str,A))))

for i in list(range(1, len(A))):
	v = A[i]
	j = i - 1
	while j >= 0 and A[j] > v:
		A[j+1] = A[j]
		j -= 1
	A[j+1] = v
	print(" ".join(list(map(str,A))))

Measured memory_bytes: 7576
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (int i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": ";
    printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  string s;
  cin >> s;
  ll N = s.size() + 1;

  // Run Length Encoding
  // e.g. issii -> i1s2i2
  vector< pair<char, ll> > cnts;
  rep(i, N-1) {
    ll cnt = 1;
    while (i < N - 2 && s[i] == s[i+1]) {
      ++cnt;
      ++i;
    }
    cnts.emplace_back(s[i], cnt);
  }

  // For Debug
  // for (auto x : cnts) {
  //   cout << x.first << ", " << x.second << endl;
  // }

  vector<ll> a(N);
  ll i = 0;
  for (auto x : cnts) {
    if (x.first == '>') {
      for (ll j = 1; j <= x.second; ++j) {
        a[i+j] = x.second - j;
      }
      a[i] = max(i > 0 ? a[i-1] : 0, i < N-1 ? a[i+1] : 0) + 1;
      i += x.second;
    } else { // <
      a[i] = 0;
      for (ll j = 1; j <= x.second; ++j) {
        a[i+j] = j;
      }
      i += x.second;
    }
  }

  // For Debbug
  // printvec(a);

  ll ans = 0;
  rep(i, N) { ans += a[i]; }
  cout << ans << endl;
}


Measured memory_bytes: 8820
// g++ -I ~/Documents/programming/cppLib -std=gnu++14 -o test ~/Documents/programming/cppLib/test.cpp && ./test && rm test
#include <bits/stdc++.h>
using namespace std;
template <typename T> using vector2 = vector <vector  <T>>;
template <typename T> using vector3 = vector <vector2 <T>>;
template <typename T> using vector4 = vector <vector3 <T>>;
using lint = long long;
#define FOR( i, a, b ) for( lint i=(a) ; i < (b) ; ++i )
#define REP( i, n )    for( lint i= 0  ; i < (n) ; ++i )
#define ALL( v )       (v).begin(), (v).end()

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

    vector<lint> A(N), B(N);
    REP( i, N ) {
        cin >> A[i] >> B[i];
    }

    lint count =0;
    for( int i=N-1; i>=0; i-- ) {
        A[i] += count;
        if( A[i] % B[i] > 0 ) {
            count += B[i] - A[i] % B[i];
        }
    }

    cout << count << endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = int_fast64_t;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

void answer() {
  ll n; cin >> n;
  vector<ll> p(n);
  rep(i, n) cin >> p[i];
  ll INF = 1e18;
  ll minv = INF, ans = 0;
  rep(i, n) if(chmin(minv, p[i])) ans++;
  cout << ans << "\n";
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define endl "\n"

typedef long long ll;
using namespace std;

//ll const N = 32000;

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

    int N, cnt = 0;
    cin >> N;

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

    sort(arr, arr + N);

    for(int i = 0; i < N - 2; i++)
    {
        int a = arr[i], b, c;

        for(int j = i + 1; j < N; j++)
        {
            if(arr[j] != a)
            {
                b = arr[j];

                for(int k = j + 1; k < N; k++)
                {
                    if(arr[k] != b)
                    {
                        c = arr[k];
                        if(a + b > c)cnt++;
                    }
                }
            }
        }
    }

    cout << cnt;

    return 0;
}


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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const ll INF = 1e18;
const int inf = 1e8;


void solve()
{
  std::string S;
  std::cin >> S;
  vector<int> a(26, 0);
  for (auto c: S) {
    a[c-'a']=1;
  }
  string ans="None";
  for (int i=25; i>=0; i--) {
    if (a[i]==0) ans=(i+'a');
  }
  cout << ans << endl;
}

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


Measured memory_bytes: 512
def search_rolling_hash(S, T):
    base = 1234
    mod = 2**64-1
    n, m = len(S), len(T)
    rolling_hash = [0]*(n-m+1)  
    rolling_hash[0] = ord(S[0])
    b_m = pow(base, m, mod)
    T_hash = ord(T[0])
    start_index = []
    for i in range(1, m):
        rolling_hash[0]*=base
        rolling_hash[0]+=ord(S[i])
        rolling_hash[0]%=mod
        T_hash = (T_hash*base+ord(T[i]))%mod
    if rolling_hash[0] == T_hash: start_index.append(0)
    for i in range(1, ls):
        rolling_hash[i] = (rolling_hash[i-1]*base-ord(S[i-1])*b_m+ord(S[i+m-1]))%mod
        if rolling_hash[i] == T_hash: start_index.append(i)
    return start_index
import sys
s = input()
t = input()
ls, lt = len(s), len(t)
S = s*(lt//ls+2)
index = search_rolling_hash(S, t)
flag = [False]*ls
for i in index:
    flag[i] = True
stack = []
inf = float('inf')
cnt = [inf]*ls
for i in range(ls):
    if flag[i] == False:
        stack.append(i)
        cnt[i] = 0
while stack:
    x = stack.pop()
    y = (x-lt)%ls
    if cnt[y] == inf:
        cnt[y] = cnt[x]+1
        stack.append(y)
ans = max(cnt)
if ans == inf:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 177600
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

struct Job { int a, b; };

int main() {
  int n, m; cin >> n >> m;
  vector<vector<int>> jobs(100000);
  for (int i = 0; i < n; ++i) { 
    int a, b; cin >> a >> b;
    jobs[a-1].push_back(b);
  }
  priority_queue<int> pq;
  int ans = 0;
  for (int i = 0; i < m; ++i) {
    for (int b : jobs[i]) {
      pq.push(b);
    }
    if (pq.empty()) continue;
    ans += pq.top(); pq.pop();
  }
  cout << ans << endl;
}



Measured memory_bytes: 5632
#include <iostream>
#include <vector>

using namespace std;
int main(){
    int N, ans=0;
    cin >> N;
    int V[30], C[30], B[30];
    for(int i=0; i<N; ++i){
        cin >> V[i];
    }

    for(int i=0; i<N; ++i){
        cin >> C[i];
        B[i] = V[i] - C[i]; 
        ans += max(0,B[i]);
    }


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

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll N, K;
  cin>>N>>K;
  ll A[N];
  for(int i=0;i<N;++i) {
    cin>>A[i];
    A[i]--;
  }
  int start = -1;
  int cycle;
  map<int, int> amap;
  for(int i=0;i<N;++i) amap[i] = -1;
  int now = 0;
  int get;
  int ans = -1;
  for(int i=0;i<K;++i) {
    if(amap[now]>-1) {
      start = now;
      get = amap[now];
      cycle = i - get;
      break;
    }
    amap[now] = i;
    now = A[now];
    if(i==K-1) ans = now;
  }
  if(ans>-1) {
    cout<<ans+1<<endl;
    return 0;
  }
  K -= get;
  K %= cycle;
  now = start;
  for(int i=0;i<K;++i) {
    now = A[now];
  }
  cout<<now+1<<endl;
}



Measured memory_bytes: 14584
from collections import defaultdict
def gen_bound(x,B):
	if x < 3: lb = 2
	else: lb = x - 1
	if x > B-2: ub = B-1
	else: ub = x + 1
	return lb,ub+1
def solve():
	count = defaultdict(int)
	ans = [0]*10
	H,W,N = map(int,raw_input().split())
	ans[0] = (H-2)*(W-2)
	for i in xrange(N):
		a,b = map(int,raw_input().split())
		xlb,xub = gen_bound(a,H)
		ylb,yub = gen_bound(b,W)
		for x in xrange(xlb,xub):
			for y in xrange(ylb,yub):
				count[x+(y<<34)] += 1
	for v in count.itervalues():ans[v] += 1
	ans[0] -= sum(ans[1:])
	for c in ans: print c
solve()

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

int main(){
	int m, n, ans;
	while(cin>>m>>n, m!=0&&n!=0){
		ans=1;
		for(int i=2; i<=m; i++){
			ans = (ans+n)%i;
			if(ans==0)ans=i;
		}
		cout<<ans<<"\n";
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define INF (int)1e9
#define endl "\n"
#define ll long long
#define ull unsigned long long

using namespace std;
string a;

int main()
{
    cin >> a;
    int k;
    cin >> k;

    string b;
    b = a;
    b.assign(a.size(), '0');
    int ans = 0;
    if (k == 1)
    {
        for (int i = 0; i < a.size(); i++)
        {
            for (char x = '1'; x <= '9'; x++)
            {
                b[i] = x;
                ans += b <= a;
                b[i] = '0';
            }
        }
    }
    else if (k == 2)
    {
        for (int i = 0; i < a.size(); i++)
        {
            for (int x = '1'; x <= '9'; x++)
            {
                b[i] = x;
                for (int j = i + 1; j < a.size(); j++)
                {
                    for (char y = '1'; y <= '9'; y++)
                    {
                        b[j] = y;
                        ans += b <= a;
                        b[j] = '0';
                    }
                }
                b[i] = '0';
            }
        }
    }
    else
    {
        for (int i = 0; i < a.size(); i++)
        {
            for (int x = '1'; x <= '9'; x++)
            {
                b[i] = x;
                for (int j = i + 1; j < a.size(); j++)
                {
                    for (char y = '1'; y <= '9'; y++)
                    {
                        b[j] = y;
                        for (int k = j + 1; k < a.size(); k++)
                        {
                            for (char z = '1'; z <= '9'; z++)
                            {
                                b[k] = z;
                                ans += b <= a;
                                b[k] = '0';
                            }
                        }
                        b[j] = '0';
                    }
                }
                b[i] = '0';
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(void){

    int a, b, c;

    char x;

    while(true){

        cin >> a >> x >> b;

        if(x == '?')break;

        if(x == '+') c = a + b;
        
        if(x == '-') c = a - b;

        if(x == '*') c = a * b;

        if(x == '/') c = a / b;

        cout << c << endl;

    }

return 0;

}

Measured memory_bytes: 1164
import java.util.Scanner;

class Main {
    public static void main(final String[] args) {
        Scanner scan = new Scanner(System.in);
        int[] in = new int[5];
        in[0] = scan.nextInt();
        in[1] = scan.nextInt();
        in[2] = scan.nextInt();
        in[3] = scan.nextInt();
        in[4] = scan.nextInt();

        int sum = 0;
        int max = 0;
        for (int i = 0; i < in.length; i++) {
            sum +=Math.round((int)Math.ceil((double)in[i]/10) * 10);
            if (10-in[i]%10 == 10) {
                continue;
            }
            max = Math.max(max,10-in[i]%10);
        }
        System.out.println(sum - max);
    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T = int> void print(vector<T> v){for(auto a:v)cout<<a<<" ";cout<<endl;}

/*
*/

ll n,a[200010],ans=0;
map<ll,ll> m;

int main(void){
	cin>>n;
	rep(i,n)cin>>a[i];
	rep(i,n)m[i-a[i]]++;
	rep(i,n){
		ans+=m[i+a[i]];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 27692
using System;
using System.Linq;
using System.Text;

class Program
{
    static void Main(string[] args)
    {

        const string ac = "AC";
        // 入力
        int[] nq = Console.ReadLine().Split().Select(int.Parse).ToArray();
        string str = Console.ReadLine();

        int[] l = new int[nq[1]];
        int[] r = new int[nq[1]];
        for (int i = 0; i < nq[1]; i++)
        {
            int[] tmp = Console.ReadLine().Split().Select(int.Parse).ToArray();
            l[i] = tmp[0];
            r[i] = tmp[1];
        }

        // 累積和
        // 0で配列を初期化
        int[] s = Enumerable.Repeat<int>(0, nq[0] + 1).ToArray();
        for (int i = 0; i < nq[0]; ++i)
        {
            if (i + 1 < nq[0] && str[i] == 'A' && str[i + 1] == 'C')
            {
                s[i + 1] = s[i] + 1;
            }
            else
            {
                s[i + 1] = s[i];
            }
        }

        // クエリ
        for (int q = 0; q < nq[1]; ++q)
        {
            Console.WriteLine(s[r[q]-1] - s[l[q]-1]);

        }
    }
}


Measured memory_bytes: 20412
#include <stdio.h>
#include <string.h>
int main(){
 int A,B,C,D;
 scanf("%d %d %d %d",&A,&B,&C,&D);
 while(0<B&&0<D){
  C-=B;
  if(C<=0){
   printf("Yes");
   break;
   }
  A-=D;
  if(A<=0){
   printf("No");
   break;
   }
 }
 return 0;
}

Measured memory_bytes: 1736
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;

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

        long L = 1 ;
        long S = 1 ;
        long C = 1 ;
        long temp = 1;
        if (a >= b) {
        	L = a;
        	S = b;
        }else {
        	L = b;
        	S = a;
        }

        while (true){
        	temp = S;
        	S = L % S;
        	L = temp;
        	if (S == 0 ) {
        		C = L;
        		break;
        	}
        }
        if (C == 1) {
        	System.out.print(1);
        	return;
        };


        List<Long> list = new ArrayList<Long>();
        long num = C;
        long i = 2;

        while (i < Math.sqrt(C) + 1  ){
        	if ( num % i == 0 ) {
        		num = num / i;
        		list.add(i);
        		}
        	 else {
        		i++;
        	}
        }


        List<Long> ans = new ArrayList<Long>(new HashSet<>(list));
        if (num == 1) {
    	  System.out.print(ans.size() + 1);
        }else {
    	  System.out.print(ans.size() + 2);
        }

    }
}

Measured memory_bytes: 25044
#include <vector>
#include <algorithm>
#include <iostream>
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <ctime>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <cassert>
#include <stack> 

#define INFLL 2000000000000000000
#define INF 2000000000
#define MOD 1000000007
#define BASE 15487469
#define PI acos(-1.0)
#define MAXLEN 29

typedef std::pair <int, int> pii;
typedef long long ll;
typedef std::vector <ll> vll;

using namespace std;

int main() {
	string str;
	cin >> str;
	if (str.length() < 26) {
		bool used[26];
		for (int i = 0; i < 26; i++) used[i] = false;
		for (int i = 0; i < str.length(); i++) used[str[i] - 'a'] = true;
		cout << str;
		for (int i = 0; i < 26; i++) if (!used[i]) {
			cout << (char)('a' + i) << endl;
			break;
		}
	} else {
		if (str == "zyxwvutsrqponmlkjihgfedcba") {
			cout << -1 << endl;
		} else {
			for (int j = str.length() - 1; j >= 0; j--) {
				int mini = INF;
				for (int i = j + 1; i < str.length(); i++) {
					if (str[i] > str[j]) {
						mini = min(mini, str[i] - 'a');
					}
				}
				if (mini != INF) {
					cout << str.substr(0, j) << (char)('a' + mini) << endl;
					return 0;
				}
			}
		}
	}
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  string S, T; cin >> S >> T;
  int A, B; cin >> A >> B;
  string U; cin >> U;
  if (S==U) A--;
  else B--;
  cout << A << " " << B << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <utility>
#include <queue>
#include <cmath>

using namespace std;

int main() {
  int n,m,k,t,a,i,j;
  string s;
  cin >> n;
  cin >> t >> a;
  int h[n];
  for(i=0;i<n;i++){
    cin >> h[i];
  }
  int point=0;
  double now=100000000;
  for(i=0;i<n;i++){
    double temp;
    temp = fabs(a-(t-h[i]*0.006));
    if(now>temp){
      point = i+1;
      now = temp;
    }
  }
  cout << point << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using static System.Console;

namespace B
{
  class Program
  {
    static void Main(string[] args)
    {
      int N = int.Parse(ReadLine());
      string[] input = ReadLine().Split();
      int A = int.Parse(input[0]);
      int B = int.Parse(input[1]);
      input = ReadLine().Split();
      int[] P = new int[input.Length];
      for(int i=0; i<input.Length; i++)
        P[i] = int.Parse(input[i]);

      int fst = 0;
      int snd = 0;
      int srd = 0;
      foreach(var p in P)
        if(p <= A) fst++;
        else if(p <= B) snd++;
        else srd++;

      int min = Math.Min(Math.Min(fst, snd), srd);
      WriteLine(min);
    }
  }
}


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


int main()
{
	string s;
	cin >> s;
  	long now = 0,count=0;
  	int n = s.size();
	for(int i = n-1; i >= 0 ; i--) {
    	if(s[i] == 'B') {
          	count += n-1-i-now;
          	now++;
        }
    }
  
  	cout << count << endl;


}


Measured memory_bytes: 640
import itertools
n = int(input())

p = list(map(int, input().split()))
q = list(map(int, input().split()))
nums = []
for i in range(n):
    nums.append(i + 1)
p_index, q_index = 0, 0
data = itertools.permutations(nums)
index = 0
for i in data:
    
    if list(i) == p:
        p_index = index
    if list(i) == q:
        q_index = index
    index += 1
    
print(abs(p_index - q_index))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define len(val) static_cast<long long>(val.size())
#define rep(i, n) for(int i=0; i<(n); i++)
typedef long long ll;
typedef pair<int, int> P;


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

    int N;
    string A, B, C;
    cin >> N >> A >> B >> C;
    int x[N];
    for(int i=0; i<N; i++){
        if((A[i] == B[i]) and (C[i] == B[i]) and (A[i] == C[i])) x[i] = 0;
        else if((A[i] == B[i]) or (C[i] == B[i]) or (A[i] == C[i])) x[i] = 1;
        else x[i] = 2;
    }
    int ans = 0;
    for(int i=0; i<N; i++){
        ans += x[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <sstream>
#include <ostream>
#include <bitset>
#include <list>
#include <deque>
#include <complex>
#include <cassert>
#include <cstring>
#include <cstdio>
#include <cfloat>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <climits>

using namespace std;

#define MAX_N 201
#define MAX_L 10001
#define INF 1e9
#define rep(i,n) for(int i = 0 ; i < n ; i++)
#define FOR(i,a,b) for(int i = a ; i < b ; i++)
#define all(p) (p).begin(),(p).end() 

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;

int N,K,T,U,V,L;
bool road[MAX_L];

double getTime(double v){
  return (double)L / v;
}

double solve(){
  int speed = 0, carr = 0;
  double res = 0;

  rep(i,L){
    if(road[i]){
      carr++;
    }
    if(speed == 0 && carr > 0){
      carr--;
      speed = V*T;
    }
    if(carr > K){
      carr--;
      speed = V*T;
    }
    if(speed > 0){
      speed--;
      res += 1./ V;
    }else{
      res += 1./ U;
    }
  }  
  return res;
}

int main(){
  int D;
  memset(road,false,sizeof(road));
  cin >> N >> K >> T >> U >> V >> L;
  rep(i,N){
    cin >> D;
    road[D] = true;
  }
  printf("%.8f\n",solve());
  return 0;
}

Measured memory_bytes: 1208
// by Balloons
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define mpr make_pair
#define debug() puts("okkkkkkkk")
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)

using namespace std;

typedef long long LL;
#define int LL

const int inf = 1e9,maxn=3e5+5;
int n,c,a[maxn],b[maxn],mx1[maxn],mx2[maxn];
signed main(){
	scanf("%lld%lld",&n,&c);
	for(int i=1;i<=n;i++)scanf("%lld%lld",&a[i],&b[i]);
//	for(int i=n+1;i<=2*n;i++)sum[i]=sum[i-1]+(b[i]-(a[i]-(i==n+1?0:a[i-1])));
//	for(int i=n-1;i>=1;i--)sumr[i]=sumr[i+1]+(b[i]-((i==n-1?c:a[i+1])-a[i]));
	int sum=0;for(int i=1;i<=n;i++)sum+=b[i],mx1[i]=max(mx1[i-1],sum-a[i]);
	sum=0;for(int i=n;i>=1;i--)sum+=b[i],mx2[i]=max(mx2[i+1],sum-(c-a[i]));
	int ans=max(mx1[n],mx2[1]);
	sum=0;
	for(int i=1;i<n;i++){
		sum+=b[i];
		ans=max(ans,sum-2*a[i]+mx2[i+1]); 
	}
//	printf("	%lld\n",mx2[2]);
	sum=0;
	for(int i=n;i>=2;i--){
		sum+=b[i];
		ans=max(ans,sum-2*(c-a[i])+mx1[i-1]);
//		printf("	%lld %lld\n",i,sum-a[i]+mx1[i+1]);
	}
	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 7168