akhauriyash/Code-Regression huggingface dataset:
t1,t2=map(int,input().split())
a1,a2=map(int,input().split())
b1,b2=map(int,input().split())
c1=a1*t1+a2*t2
c2=b1*t1+b2*t2
if c1==c2:
    print("infinity")
    exit()
if c1>c2:
    flag=1
else:
    flag=2
if flag==1:
    if a1>b1:
        print(0)
    else:
        m=(b1-a1)*t1
        ans=((m-1)//(c1-c2))*2+1
        if m%(c1-c2)==0:
            ans+=1
        print(ans)
else:
    if a1<b1:
        print(0)
    else:
        m=(a1-b1)*t1
        ans=((m-1)//(c2-c1))*2+1
        if m%(c2-c1)==0:
            ans+=1
        print(ans)

Measured memory_bytes: 3188
nums = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
]
K = int(input())
print(nums[K-1])

Measured memory_bytes: 2940
class Array
  def cumgcd;
    res = self[0];
    map{|t| res = t.gcd(res) }
  end
end

n = gets.to_i
a = gets.split.map(&:to_i)

cg  = a.cumgcd
cgr = a.reverse.cumgcd.reverse

ans = cg[-2]
ans = cgr[1] if ans < cgr[1]
# p cg
# p cgr

(n-2).times do |i|
  t = cg[i].gcd(cgr[i+2])
  ans = t if ans < t
  # p t
end

# require "prime"
# a.each do |k|
#   p k.prime_division
# end

p ans
# p ans.prime_division

Measured memory_bytes: 11780
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 1000000+5;
const int dx[] = {0,0,-1,1,-1,-1,1,1};
const int dy[] = {-1,1,0,0,-1,1,-1,1};
using namespace std;
struct Edge {
    int to,next,w;
    bool operator < (const Edge& rhs)const{
        return w>rhs.w;
    }
} e[N*2];
int cnt, head[N];
void addEdge(int u, int v, int w) {
    e[cnt] = Edge{v, head[u], w};
    head[u] = cnt++;
}
bool vis[N];
int dis[N];
void SPFA(int st, int ed) {
    priority_queue<Edge> q;
    memset(dis,INF,sizeof(dis));
    memset(vis,false,sizeof(vis));
    dis[st] = 0;
    q.push(Edge{st, 0, 0});
    while (!q.empty()) {
        Edge u = q.top();
        q.pop();
        if(vis[u.to]) continue;
        vis[u.to] = 1;

        for (int i = head[u.to]; ~i; i = e[i].next) {
            int to = e[i].to;
            if (dis[to] > dis[u.to] + e[i].w) {
                dis[to] = dis[u.to] + e[i].w;
                q.push(Edge{to, 0, dis[to]});
            }
        }
    }
    printf("%d\n", dis[ed] == INF?-1:dis[ed]/2);
}
map<int, int>mp[N];
int allPoint;
int getPoint(int x,int y) {
    if (!mp[x][y])
        mp[x][y]=++allPoint;
    return mp[x][y];
}
int main() {
    int n,m;
    scanf("%d%d",&n,&m);
    memset(head,-1,sizeof(head));
    allPoint=n;
    for (int i=1; i<=m; i++) {
        int x,y,w;
        scanf("%d%d%d",&x,&y,&w);
        int newX=getPoint(x,w);
        int newY=getPoint(y,w);

        addEdge(newX,newY,0);
        addEdge(newY,newX,0);
        addEdge(x,newX,1);
        addEdge(newX,x,1);
        addEdge(y,newY,1);
        addEdge(newY,y,1);
    }
    SPFA(1,n);

    return 0;
}


Measured memory_bytes: 94196
#!/usr/bin/env python3
#ABC111 C

from operator import itemgetter
import collections

n = int(input())
v = list(map(int,input().split()))

s = [v[i] for i in range(n) if i % 2 == 0]
t = [v[i] for i in range(n) if i % 2 == 1]

sc = collections.Counter(s)
tc = collections.Counter(t)
sc = list(sc.items())
tc = list(tc.items())
ls = len(sc)
lt = len(tc)
sc.sort(key = itemgetter(1))
tc.sort(key = itemgetter(1))
if sc[-1][0] == tc[-1][0]:
    if ls == 1 and lt == 1:
        print(n - sc[-1][1])
    elif ls == 1 and lt != 1:
        print(n - sc[-1][1] - tc[-2][1])
    elif ls != 1 and lt == 1:
        print(n - sc[-2][1] - tc[-1][1])
    else:
        ma = max(sc[-2][1],tc[-2][1])
        print(n - sc[-1][1] - ma)
else:
    print(n - sc[-1][1] - tc[-1][1])


Measured memory_bytes: 65900
import java.util.*;
import java.awt.*;

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

        int n = sc.nextInt();
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextLong();
        }

        Arrays.sort(a);

        long ans = 0;
        if (n % 2 == 0) {
           for (int i = 0; i < n/2 - 1; i++) {
               ans = ans + a[n/2 + i] + a[n/2 + i + 1] - 2*a[i];
           }
           ans = ans + a[n-1] - a[n/2 -1];
        } else {
            for (int i = 0; i < n/2 - 1; i++) {
                ans = ans + a[n/2 + i + 1] + a[n/2 + i + 2] - 2*a[i];
            }
            ans = ans + a[n-1] - a[n/2 -1];
            ans += Math.max(a[n/2 + 1] - a[n/2], a[n/2] - a[n/2 - 1]);
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 64960
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = (int)1e5+10;
int a[MAXN];
ll b[MAXN];
void add(int l,int r,int x){
    if(l>r)return ;
    b[l]+=x;
    b[r+1]-=x;
}
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    ll ans=0;
    for(int i=1;i<n;i++){
        if(a[i]<a[i+1]){
            ans+=a[i+1]-a[i];
            add(a[i]+2,a[i+1],-1);
            add(a[i+1]+1,a[i+1]+1,a[i+1]-a[i]-1);
        }
        else{
            ans+=a[i+1];
            add(2,a[i+1],-1);
            add(a[i+1]+1,a[i+1]+1,a[i+1]+m-a[i]-1);
            add(a[i]+2,m,-1);
        }
    }
    ll step=ans;
    for(int i=2;i<=m;i++){
        b[i]+=b[i-1];
        step+=b[i];
        ans=min(ans,step);
    }
    printf("%lld\n",ans);
    return 0;
}



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

#define all(x) (x).begin(),(x).end()
#define MOD 1000000007

using namespace std;

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

	if( 400 <= x && x <= 599 )		cout << 8 << endl;
	if( 600 <= x && x <= 799 )		cout << 7 << endl;
	if( 800 <= x && x <= 999 )		cout << 6 << endl;
	if( 1000 <= x && x <= 1199 )	cout << 5 << endl;
	if( 1200 <= x && x <= 1399 )	cout << 4 << endl;
	if( 1400 <= x && x <= 1599 )	cout << 3 << endl;
	if( 1600 <= x && x <= 1799 )	cout << 2 << endl;
	if( 1800 <= x && x <= 1999 )	cout << 1 << endl;

	return 0;
}


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

long long pow(long long a, long long b){
	if(b == 0) return a;
	return 2*pow(a, b-1);
}

int main(){
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int max;
	max  = (a > b) ? a : b;
	max = (max > c) ? max : c;
	int sum = a + b + c - max;
	cout << pow(max, d) + sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    string s;cin>>s;
    int flag=0;
      if(s[2]==s[3] && s[4]==s[5])
      flag=1;
    if(flag==1)
    cout<<"Yes";
    else
    cout<<"No";}

Measured memory_bytes: 256
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
ans = 0
for i in range(N):
    a = 0
    Ai = list(map(int, input().split()))
    for j in range(M):
        a += Ai[j]*B[j]
    if a + C > 0:
        ans += 1
print(ans)

Measured memory_bytes: 3060
import copy

N = int(input())

ary = []
for _ in range(N):
    ary.append(int(input()))

ary_copy = copy.copy(ary)
ary_copy.sort()

max_1 = ary_copy[-1]
max_2 = ary_copy[-2]

for i in ary:
    if i == max_1:
        print(max_2)
    elif i != max_1:
        print(max_1)

Measured memory_bytes: 19156
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Optional;
import java.util.OptionalDouble;
import java.util.stream.DoubleStream;
import java.util.stream.Stream;

public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      String line;
      String[] lines;
      double[] s;
      while( !(line = br.readLine()).equals("0") ){

        int n = Integer.parseInt(line);
        lines = br.readLine().split(" ");

        s =
          Stream.of(lines)
            .mapToDouble(Double::parseDouble)
            .toArray();
        
        double dm =
          Arrays.stream(s)
            .average()
          .getAsDouble();

        double result =
        Arrays.stream(s)
          .map(d -> Math.pow((d-dm),2))
          .sum();
        result = Math.sqrt((result)/n);

        System.out.printf("%.8f\n" ,result);
      }
    }
  }
}


Measured memory_bytes: 32160
#include <iostream>

using namespace std;

int main(){
  int num;
  cin >> num;
  int count = 0;
  int max = 0;
  int ans = 1;
  for(int i=1; i<=num; i++){
    int temp_num = i;
    count = 0;
    while(true){
      if(temp_num%2 == 0){
         temp_num /= 2;
         count += 1;
         if(temp_num == 0) break;
      }else{
        break;
      }
    }

    if(max < count){
      max = count;
      ans = i;
    }
  }

  cout << ans;

}


Measured memory_bytes: 256
n, k = map(int, input().split())

if 2 * k - 1 > n:
  print(-1)
else:
  half_n = n // 2
  if n % 2 == 0:
    for i in range(half_n):
      a = k + i
      b = k + n + i + half_n
      c = k + 2 * n + 2 * i
      print(a, b, c)
      a += half_n
      b -= half_n
      c += 1
      print(a, b, c)
  else:
    for i in range(half_n):
      a = k + i
      b = k + n + i + half_n
      c = k + 2 * n + 2 * i
      print(a, b, c)
      a += half_n + 1
      b -= half_n
      c += 1
      print(a, b, c)
    a = k + half_n
    b = k + n + 2 * half_n
    c = k + 2 * n + 2 * half_n
    print(a, b, c)

Measured memory_bytes: 5176
module IntPairMap = Map.Make (struct
  type t = int * int
  let compare = compare
end)

let () = Scanf.scanf "%d %d %d\n" @@ fun n ma mb ->
  let abc = Array.init n @@ fun _ ->
    Scanf.scanf "%d %d %d\n" @@ fun a b c -> a, b, c in
  Array.fold_left (fun m (a, b, c) ->
    IntPairMap.fold (fun (a', b') c' m ->
      IntPairMap.add (a + a', b + b')
        (min (c + c') (try IntPairMap.find (a + a', b + b') m with Not_found -> max_int)) m) m m) (IntPairMap.singleton (0, 0) 0) abc
  |> IntPairMap.bindings
  |> List.filter (fun ((a, b), _) -> 0 < a && 0 < b && b * ma = a * mb)
  |> List.map snd
  |> List.fold_left min max_int
  |> (fun c -> if c = max_int then print_endline "-1" else Printf.printf "%d\n" c)


Measured memory_bytes: 7168
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define pb push_back
#define pll pair<ll,ll> 
#define mll map<ll,ll>
#define pii pair<int,int>
#define rep(i,n) for(int i=0; i<n; i++)
#define All(x,v) for(auto x:v)
#define arrin(a,n) ll a[n]; rep(i,n) cin>>a[i]
#define vi vector<int>
#define nl "\n"
#define print(arr) All(x,arr) cout<<x<<" "; cout<<nl
#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define ing(m,ad) rep(i,m){ int u,v; cin>>u>>v; u--;v--; ad[u].pb(v); ad[v].pb(u);}
#define vdsort(v) sort(v.begin(),v.end(),greater<int>())
#define F first
#define S second
#define mod (ll)1000000007
const int MAXN=1000005;
int spf[MAXN];
ll fac1[MAXN],fac2[MAXN],inv[MAXN];
ll gcd(ll x, ll y){ return y?gcd(y,x%y):x; }

void sieve(){  
    spf[1] = 1; 
    for (int i=2; i<MAXN; i++)  spf[i] = i; 
    for (int i=4; i<MAXN; i+=2) spf[i] = 2; 
    for (int i=3; i*i<MAXN; i++) { 
        if (spf[i] == i) 
            for (int j=i*i; j<MAXN; j+=i) 
                if (spf[j]==j)  spf[j] = i; 
    } 
} 
vector<int> getFactorization(int x){
    vector<int> ret; 
    while (x != 1) { 
        ret.push_back(spf[x]); 
        x = x / spf[x]; 
    } 
    return ret; 
}

ll exp(ll n, ll m){
    ll a = 1;
    while (m){
        if (m & 1) a = (a * n % mod) % mod;
        m /= 2;
        n = (n*n) % mod;
    }
    return a;
}

void pre(){
    fac1[0]=fac2[0]=inv[1]=1;
    for(ll i=1;i<MAXN;i++){
        fac1[i]=(fac1[i-1]*i)%mod;
        if(i>1) inv[i]=( mod - ((ll)(mod/i)*inv[mod%i])%mod ) %mod;
    }
    for(int i=1;i<MAXN;i++) fac2[i]=(fac2[i-1]*inv[i])%mod;
}
ll C(int n,int k){
    if(n<k) return 0;
    return ((fac1[n]*fac2[n-k]%mod)*fac2[k]%mod);
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    // freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    int n,t=1;
    // cin>>t;
    while(t--){
        cin>>n;
        vi v,w;
        rep(i,n){
            int x,y;
            cin>>x>>y;
            v.pb(x+y); w.pb(x-y);
        }
        sort(all(v));
        sort(all(w));
        cout<<max(v[n-1]-v[0],w[n-1]-w[0])<<nl;
    }
    return 0;
}

Measured memory_bytes: 4740
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
#define tpl(...) make_tuple(__VA_ARGS__)
const int INF = 0x3f3f3f3f;
const double EPS = 1e-8;
const double PI = acos(-1);
typedef long long ll;
typedef pair<int,int> pii;
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 (a>b) { a=b; return 1; } return 0; }
template<class T>ostream&operator<<(ostream &o,const vector<T>&t){o<<'[';FOR(i,t){if(i!=t.begin())o<<',';o<<*i;}return o<<']';}
template<class S,class T>ostream&operator<<(ostream &o,const pair<S,T>&t){return o<<'('<<t.first<<','<<t.second<<')';}
template<int N,class Tp>void output(ostream&,const Tp&){}
template<int N,class Tp,class,class ...Ts>void output(ostream &o,const Tp&t){if(N)o<<',';o<<get<N>(t);output<N+1,Tp,Ts...>(o,t);}
template<class ...Ts>ostream&operator<<(ostream&o,const tuple<Ts...>&t){o<<'(';output<0,tuple<Ts...>,Ts...>(o,t);return o<<')';}
template<class T>void output(T t,char z=10){if(t<0)t=-t,putchar(45);int c[20];
int k=0;while(t)c[k++]=t%10,t/=10;for(k||(c[k++]=0);k;)putchar(c[--k]^48);putchar(z);}
template<class T>void outputs(T t){output(t);}
template<class S,class ...T>void outputs(S a,T...t){output(a,32);outputs(t...);}
template<class T>void output(T *a,int n){REP(i,n)output(a[i],i!=n-1?',':10);}
template<class T>void output(T *a,int n,int m){REP(i,n)output(a[i],m);}
template<class T>bool input(T &t){int n=1,c;for(t=0;!isdigit(c=getchar())&&~c&&c-45;);
if(!~c)return 0;for(c-45&&(n=0,t=c^48);isdigit(c=getchar());)t=10*t+c-48;t=n?-t:t;return 1;}
template<class S,class ...T>bool input(S&a,T&...t){input(a);return input(t...);}

ll cost(ll x, ll y) {
  int c = 0;
  ll res = 0;
  while(x||y) {
    int a = x%10;
    int b = y%10;
    res += a*b+c;
    if (a+b+c>=10) {
      c = 1;
    } else {
      c = 0;
    }
    x/=10;
    y/=10;
  }
  if (c) res++;
  return res;
}
ll sum[301];
ll a[300];
ll dp[301][301];

int main() {
  int n;
  while(cin >> n) {
    REP(i,n) {
      input(a[i]);
      sum[i+1] = sum[i] + a[i];
    }
    REP(i,n+1)REP(j,n+1) dp[i][j] = 1LL<<60;
    for (int w=1; w<=n; ++w) {
      for (int i=0; i<=n-w; ++i) {
        int j = i+w;
        if (w == 1) {
          dp[i][j] = 0;
          continue;
        }
        for (int k=i+1; k<j; ++k) {
          // [i,k), [k,j)
          ll x = sum[k]-sum[i];
          ll y = sum[j]-sum[k];
          chmin(dp[i][j], dp[i][k] + dp[k][j] + cost(x,y));
        }
      }
    }
    cout << dp[0][n] << endl;
  }
}

Measured memory_bytes: 1868
H,W = map(int,input().split())
maze = []
for _ in range(H):
    l = list(input())
    maze.append(l)
import collections as col
q = col.deque()
q.append((0,0))
maze[0][0] = 0
def bfs(maze):
    while True:
        try: nowx,nowy = q.popleft()
        except IndexError:
            print("-1")
            quit()
        if nowx == (H - 1) and nowy == (W - 1): return
        for x in [1,-1]: 
            if nowx + x == H or nowy == W: continue
            if maze[nowx + x][nowy] != '.' : continue
            if 0 <= nowx + x and nowx + x <= H - 1:
                q.append((nowx+x,nowy))
                maze[nowx + x][nowy] = maze[nowx][nowy] + 1
        for y in [1,-1]: 
            if nowx == H or nowy + y== W: continue
            if maze[nowx][nowy + y] != '.' : continue
            if 0 <= nowy + y and nowy + y <= W - 1:
                q.append((nowx,nowy+y))
                maze[nowx][nowy + y] = maze[nowx][nowy] + 1
bfs(maze)
cnt = 0
for x in maze:
    for y in x:
        if y == '#':
            cnt += 1
print(H*W - maze[H-1][W-1] - cnt - 1)



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

typedef int i32;
typedef long long i64;
typedef unsigned int u32;
typedef unsigned long long u64;


template<typename First, typename Second, typename Third>
struct triple {
   First first;
   Second second;
   Third third;
};


#define debug(x)  cerr<<x<<"\n";
#define loop(i,n) for(i32 i = 0; i < n; ++i)
#define pi  pair<int,int>
#define ti  tuple<int,int,int>
#define mt  make_tuple
#define mk  make_pair
#define vi  vector<int>
#define vll vector<i64>
#define fastInOut ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pr(a) for(auto x:a) cout<<x<<" ";
#define prmap(m) for(auto x:m) cout<<x.first<<" "<<x.second<<"\n";
using namespace std;

int main() 
{ 
	int a,b,c;
	cin>>a>>b>>c;
	if(c>=a&&c<=a+b)
		 cout<<"YES";
	else 
		cout<<"NO";
    return 0; 
} 



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
using ll = long long;

using namespace std;

int main() {
    ll N;
    cin >> N;
    ll result = -1;
    for(int i = 0; i < 500 * 108 + 1000; i++){
        if(floor(i * 1.08) == N){
            result = i;
            break;
        }
    }
    if(result == -1){
        cout << ":(" << endl;
    }else{
        cout << result << endl;
    }
}


Measured memory_bytes: 256
import std.stdio;
import std.string;

char[10][10] map;
int x, y;

void main(){
	string s, ans;
	for (int i = 0; i < 5; i++) {
		for (int j = 0; j < 5; j++) {
			map[i][j] = cast(char)('a' + j + i*5);
		}
	}
	map[5][0..5] = ['z', '.', '?', '!', ' '];
	while ((s = chomp(readln())), s) {
		if (s.length%2 != 0) {
			writeln("NA");
			continue;
		}

		ans = "";
		for (int i = 0; i < s.length; i+=2) {
			x = s[i] - '1';
			y = s[i+1] - '1';
			if (x < 0 || x > 5 || y < 0 || y > 4) {
				ans = "NA";
				break;
			}else {
				ans ~= map[x][y];
			}
		}
		writeln(ans);
	}
}

Measured memory_bytes: 972
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const int INF=1000000001;
const double PI=3.141592653589;


int main(){
  int n,a; cin>>n>>a;
  cout<<n*n-a<<endl;

  return 0;
}


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

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    string s;
    cin >>s;

    int mn=10000000;
    int n=s.length();
    int cnt=0;
    char ch;
    for(int i=0;i<n;i++){
        if(i&1)ch='0';
        else ch='1';
        if(s[i]!=ch)cnt++;
    }
    mn=min(mn,cnt);
    cnt=0;
    for(int i=0;i<n;i++){
        if(i&1)ch='1';
        else ch='0';
        if(s[i]!=ch)cnt++;
    }
    mn=min(mn,cnt);
    cout<<mn<<endl;
}



Measured memory_bytes: 3792
N, P = map(int, input().split())
if N == 1:
  print(P)
  exit()
if N > 40:
  print(1)
  exit()
res = []
for i in range(1,P+1):
  x = i**N
  if i**N > P:
    break
  if P%x == 0:
    res.append(i)
print(max(res))

Measured memory_bytes: 3060
n = int(input())
s = input()
ans = []
for i in s:
    ask = ord(i)
    if (ask+n) > ord('Z'):
        a = n+ask-ord('Z')
        ans.append(chr(ord('A')+a-1))
    else:
        ans.append(chr(ask+n))
print("".join(ans))


Measured memory_bytes: 3060
N,K=map(int,input().split())
A=list(map(lambda x:int(x)-1,input().split()))
seen=[-1]*N
i=0
cnt=0
iri=-1

while True:
    if(cnt==K):
        print(i+1)
        exit()
    if seen[i]!=-1:
        roop=cnt-seen[i]
        iri=i
        K-=seen[i]
        K=K%roop
        break
    seen[i]=cnt
    cnt+=1
    i=A[i]
now=iri
for i in range(K):
    now=A[now]


print(now+1)

Measured memory_bytes: 32380
import numpy as np
N = int(input())
W = list(map(int, input().split()))
sum_W = np.sum(W)
diff = 100000

for t in range(N):
  i = np.sum(W[0:t])
  j = sum_W - i
  if abs(i-j) < diff:
    diff = abs(i-j)
print(diff)

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

int H,W;
string S[2020];
int dr[4]={-1,-1,0,0};
int dc[4]={-1,0,-1,0};
int kousi[2020][2020];
int h[2020][2020];

ll LargestRectangle(int t){
  int L[W],R[W];
  stack<int> st;
  rep(i,W){
    while(st.size()&&h[t][st.top()]>=h[t][i]) st.pop();
    L[i]=st.size()?st.top():0;
    st.push(i);
  }
  while(st.size()) st.pop();
  for(int i=W-1;i>=0;i--){
    while(st.size()>0&&h[t][st.top()]>=h[t][i]) st.pop();
    R[i]=st.size()?st.top():W;
    st.push(i);
  }
  ll res=0;
  rep(i,W){
    res=max(res,1LL*h[t][i]*(R[i]-L[i]));
  }
  return res;
}

int main(){
  cin>>H>>W;
  rep(i,H) cin>>S[i];
  for(int i=1;i<H;i++) for(int j=1;j<W;j++){
    int cnt=0;
    rep(k,4) if(S[i+dr[k]][j+dc[k]]=='#') cnt++;
    if(cnt%2) kousi[i][j]=1;
  }
  for(int i=1;i<=H;i++) rep(j,W){
    if(kousi[i-1][j]) h[i][j]=1;
    else h[i][j]=h[i-1][j]+1;
  }
  ll ans=0;
  for(int i=1;i<=H;i++){
    ans=max(ans,LargestRectangle(i));
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 36096
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c = 0;
  cin >> a;
  c = a;
  if(1 <= a / 100){
    b++;
    c = c - 100;
  }
  if(1 <= c / 10){
    b++;
    c = c - 10;
  }
  if(1 <= c / 1){
    b++;
  }
  cout << b << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,m,K;
char s[20][20];
bool vis[20];
int ans=0;
void check(){
	int sum=0;
	for(int i=1;i<=n;i++){
		if(vis[i]) continue;
		for(int j=1;j<=m;j++){
			if(vis[n+j]) continue;
			if(s[i][j]=='#') sum++;
		}
	}
	ans+=(sum==K);
}
void dfs(int x){
	if(x==n+m+1){
		check(); return;
	}
	vis[x]=1;
	dfs(x+1);
	vis[x]=0;
	dfs(x+1);
}
int main(){
	//freopen("data.in","r",stdin);
	scanf("%d %d %d\n",&n,&m,&K);
	for(int i=1;i<=n;i++){
		scanf("%s",s[i]+1);
	}
	dfs(1);
	cout<<ans<<endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <math.h>
#include <map>
#include <numeric>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	while(1){
		string s; cin >> s;
		if(s=="#")break;
		int y,m,d; cin >> y >> m >> d;
		if(y<=30){
			cout << s << " " << y << " " << m << " " << d << endl;
		}else if(y==31){
			if(m<=4){
				cout << s << " " << y << " " << m << " " << d << endl;
			}else{
				cout << "? " << y-30 << " " << m << " " << d << endl;
			}
		}else{
			cout << "? " << y-30 << " " << m << " " << d << endl;
		}
	}
}


Measured memory_bytes: 3036
#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x,long long int y) 
{ 
    long long int res = 1;     // Initialize result 
  // x=x;
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x); 
   
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x);  // Change x to x^2 
    } 
    return res; 
}
long long int power(long long int x,long long int y,long long int m) 
{ 
    long long int res = 1;     // Initialize result 
   x=x%m;
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x)%m; 
   
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x)%m;  // Change x to x^2 
    } 
    return res; 
}
void primeFactors(int n)  
{  
    // Print the number of 2s that divide n  
    while (n % 2 == 0)  
    {  
        cout << 2 << " ";  
        n = n/2;  
    }  
  
    // n must be odd at this point. So we can skip  
    // one element (Note i = i +2)  
    for (int i = 3; i <= sqrt(n); i = i + 2)  
    {  
        // While i divides n, print i and divide n  
        while (n % i == 0)  
        {  
            cout << i << " ";  
            n = n/i;  
        }  
    }  
  
    // This condition is to handle the case when n  
    // is a prime number greater than 2  
    if (n > 2)  
        cout << n << " ";  
}

long long int gcd(long long int a, long long int b){ 
    if (a == 0) 
        return b;  
    return gcd(b % a, a);  
 } 
 long long int lcm(long long int a, long long int b)  
 { 
     long long int temp;
    
    return (a*b)/gcd(a, b);  
 }
 
int main() {
   
    long long int n1,m1,t;
 //  cin>>t;
   t=1;
    while(t--)
    {
   long long int i,j;
 //long long int b[1000000];
 //set<long long int >s;
       long long int f=1,p=0,z,o=0;
       double pie=3.141592653589793238;
    long long int c=0,n,m,l=0,r=0,k,min1=10000000000000,max2=-100;
 cin>>n;
 long long int a[n];
 for(i=0;i<n;i++)
 cin>>a[i];
 for(i=0;i<n;i++)
 {
   //cout<<(i+1)<<" "<<a[i];
   if((i+1)%2!=0&&a[i]%2!=0)
 c++;}
 cout<<c;
 
 
 }
 return 0;
}


Measured memory_bytes: 3624
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;

int main()
{
	int x;
	cin>>x;
	int ans = 1;
	for(int i = 2; i*i <= x; i++){
		for(int p = 2; pow((double)(i),p) <= x; p++){
			ans = max(ans,(int)pow((double)(i),p));
		}
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 3536
#include"bits/stdc++.h"
using namespace std;

typedef long long ll;
#define FOR(i, a, n) for (ll i=(ll)a;i<(ll)n;i++)
#define REP(i, n) FOR(i, 0, n)

#define INF 1000000

int dfs(int N, int A, int B, int C, int n, int a, int b, int c, vector<int> l){
    if (N==n){
        int ans = abs(A-a)+abs(B-b)+abs(C-c)-30;
        return (min(a, min(b,c))>0) ? ans:INF;
    }
    else{
        int ret0 = dfs(N,A,B,C,n+1,a,b,c,l);
        int ret1 = dfs(N,A,B,C,n+1,a+l[n],b,c,l)+10;
        int ret2 = dfs(N,A,B,C,n+1,a,b+l[n],c,l)+10;
        int ret3 = dfs(N,A,B,C,n+1,a,b,c+l[n],l)+10;

        return min(ret0,min(ret1,min(ret2,ret3)));
    }
}

int main(){
    int n, a, b, c;
    cin >> n >> a >> b >> c;

    vector<int> l(n, 0);
    REP(i, n){
        cin >> l[i];
    }
    
    cout << dfs(n,a,b,c,0,0,0,0,l) << endl;
}

Measured memory_bytes: 256
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string { sc.Scan(); return sc.Text() }
func scanInt() int { a,_ := strconv.Atoi(scanString()); return a }
func scanInt64() int64 { a,_ := strconv.ParseInt(scanString(),10,64); return a }
func scanFloat64() float64 { a,_ := strconv.ParseFloat(scanString(),64); return a }

func scanInts(n int) []int {
	res := make([]int, n); for i := 0; i < n; i++ { res[i] = scanInt() }; return res
}

func abs(a int) int { if a<0 { return -a }; return a }
func min(a,b int) int { if a<b { return a }; return b }
func max(a,b int) int { if a>b { return a }; return b }

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()

	a := make([]int, n)
	b := make([]int, n)
	c := make([]int, n)
	d := make([]int, n)

	for i := 0; i < n; i++ {
		a[i] = scanInt()
		b[i] = scanInt()
	}

	for i := 0; i < n; i++ {
		c[i] = scanInt()
		d[i] = scanInt()
	}

	pair := make([][]int, n*2)
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if a[i] < c[j] && b[i] < d[j] {
				pair[i] = append(pair[i], n+j)
				pair[n+j] = append(pair[n+j], i)
			}
		}
	}

	ans,_ := bipartiteMatching(pair)

	fmt.Fprintln(wr, ans)
}

func bipartiteMatching(g [][]int) (int, []int) {
	used := make([]int, len(g))
	match := make([]int, len(g))
	for i := 0; i < len(g); i++ { match[i] = -1 }
	cnt := 0

	var fn func(v int) bool
	fn = func(v int) bool {
		used[v] = cnt
		for _, to := range g[v] {
			if match[to] == -1 || (cnt!=used[match[to]] && fn(match[to])) {
				match[v], match[to] = to, v
				// used[v] = false
				return true
			}
		}
		// used[v] = false
		return false
	}

	res := 0

	for i := 0; i < len(g); i++ {
		cnt++
		if match[i] == -1 && fn(i) { res++ }
	}

	return res, match
}


Measured memory_bytes: 768
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
def main(X, K, D):
    X = abs(X)
    k = X // D
    X -= D * min(K, k)
    K -= min(K, k)

    ans = X - D if K & 1 else X
    print(abs(ans))


if __name__ == '__main__':
    input = sys.stdin.readline
    X, K, D = map(int, input().split())
    main(X, K, D)


Measured memory_bytes: 61780
#include <iostream>
#include <vector>
#include <map>
#include<algorithm>
#include <climits>
typedef long long ll;
#define INF (LLONG_MAX/10)
using namespace std;

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	ll N, W; cin >> N >> W;
	vector<ll> w(N + 1), v(N + 1);
	vector<pair<ll, ll>> ps(1 << ((N+1)/ 2));
	for (int i = 0; i < N;i++) {
		cin >> v[i] >> w[i];
	}

	int N2 = N / 2;
	for (int i = 0; i < 1 << N2;i++) {
		ll sw = 0, sv = 0;
		for (int j = 0; j < N2;j++) {
			if (i >> j & 1) {
				sw += w[j];
				sv += v[j];
			}
		}
		ps[i] = make_pair(sw, sv);
	}

	sort(ps.begin(), ps.begin() + (1 << N2));

	int m = 1;
	for (int i = 1; i < 1 << N2; i++) {
		if (ps[m - 1].second < ps[i].second) {
			ps[m++] = ps[i];
		}
	}

	ll res = 0;
	for (int i = 0; i < 1 << (N - N2); i++) {
		ll sw = 0, sv = 0;
		for (int j = 0; j < N - N2;j++) {
			if (i >> j & 1) {
				sw += w[N2 + j];
				sv += v[N2 + j];
			}
		}
		if (sw <= W) {
			ll tv = (lower_bound(ps.begin(), ps.begin() + m, make_pair(W - sw, INF)) - 1)->second;
			res = max(res, sv + tv);
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 19064
def main():
    from sys import stdin
    input = stdin.readline

    n = int(input())
    ab = [list(input().split()) for _ in [0]*(2*n)]
    ab = [(a == "B", int(b)-1) for a, b in ab]
    dct_b = [0]*n
    dct_w = [0]*n
    for i, (a, b) in enumerate(ab):
        if a:
            dct_b[b] = i
        else:
            dct_w[b] = i

    dp = [[10**9]*(n+1) for _ in [0]*(n+1)]  # dp[i][j] = Bをi個、Wをj個置くための最小手数
    dp[0][0] = 0

    # 左i個にあるj以上のボールの数
    lb = [[0]*(n+1) for _ in [0]*(2*n)]
    lw = [[0]*(n+1) for _ in [0]*(2*n)]

    for j in range(n):
        cnt1, cnt2 = 0, 0
        for i, (a, b) in enumerate(ab):
            lb[i][j] = cnt1
            lw[i][j] = cnt2
            if a:
                if b >= j:
                    cnt1 += 1
            else:
                if b >= j:
                    cnt2 += 1

    dp = [[10**9]*(n+1) for _ in [0]*(n+1)]  # dp[i][j] = Bをi個、Wをj個置くための最小手数
    dp[0][0] = 0

    for i in range(n+1):
        dp1 = dp[i]
        if i < n:
            dp2 = dp[i+1]
            t = dct_b[i]
        for j in range(n+1):
            d = dp1[j]
            if i < n:
                dp2[j] = min(dp2[j], d+lb[t][i]+lw[t][j])
            if j < n:
                t2 = dct_w[j]
                dp1[j+1] = min(dp1[j+1], d+lb[t2][i]+lw[t2][j])
    print(dp[n][n])


main()

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

const int maxn = 1e5 + 10;
int a[maxn];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n; cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        int t = 0;
        while (a[i] % 2 == 0) a[i] >>= 1, ++t;
        a[i] = t;
    }
    int z = 0, o = 0, t = 0;
    for (int i = 0; i < n; ++i) {
        if (a[i] == 0) ++z;
        else if (a[i] == 1) ++o;
        else ++t;
    }
    // if (z > t) return cout <<
    --z;
    if (z > t) return cout << "No" << endl, 0;
    if (z == t) {
        if (o) return cout << "No" << endl, 0;
        else return cout << "Yes" << endl, 0;
    }
    cout << "Yes" << endl;
    return 0;
}

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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define sz(v) (int)v.size()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
const char EOL = '\n';

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

inline vector<int> get_d(int n) {return vector<int>(n, INF);}
inline vector<ll> get_d(ll n) {return vector<ll>(n, LINF);}
template<typename T> vector<T> dijkstra(int s, vector<vector<pair<int, T>>>& g) {
    T n = sz(g);
    priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> q;
    vector<T> d = get_d(n);
    d[s] = 0;
    q.emplace(0, s);

    while (!q.empty()) {
        pair<T, int> p = q.top();
        q.pop();
        int v = p.second;
        if (d[v] < p.first) continue;

        for (auto x : g[v]) {
            if (d[x.first] > d[v] + x.second) {
                d[x.first] = d[v] + x.second;
                q.emplace(d[x.first], x.first);
            }
        }
    }
    return d;
}

void solve() {
    int n, m, s, t;
    cin >> n >> m >> s >> t;
    s--; t--;
    vector<vector<pair<int, ll>>> yen(n, vector<pair<int, ll>>());
    vector<vector<pair<int, ll>>> snk(n, vector<pair<int, ll>>());

    int u, v;
    ll a, b;
    REP(i, m) {
        cin >> u >> v >> a >> b;
        u--; v--;
        yen[u].emplace_back(v, a);
        yen[v].emplace_back(u, a);
        snk[u].emplace_back(v, b);
        snk[v].emplace_back(u, b);
    }

    auto miny = dijkstra(s, yen);
    // for (auto x : miny) cout << x << " "; cout << EOL;
    auto mins = dijkstra(t, snk);
    // for (auto x : mins) cout << x << " "; cout << EOL;
    vector<ll> ans(n + 1);
    REPR(i, n) {
        ans[i] = max(ans[i + 1], 1000000000000000 - (miny[i] + mins[i]));
    }
    REP(i, n) {
        cout << ans[i] << EOL;
    }
}



Measured memory_bytes: 19016
import sys

n, a, b, c = map(int, input().split())
S = [input() for _ in range(n)]


abc = {"A": a, "B": b, "C": c}
ans = []
for i, s in enumerate(S):
    u, v = s[0], s[1]
    if abc[u] == abc[v] == 0:
        print("No")
        sys.exit()
    elif abc[u] > abc[v]:
        abc[u] -= 1
        abc[v] += 1
        ans.append(v)
    elif abc[u] < abc[v]:
        abc[u] += 1
        abc[v] -= 1
        ans.append(u)
    elif i == n-1:
        ans.append(u)
    else:
        if u in S[i+1]:
            abc[u] += 1
            abc[v] -= 1
            ans.append(u)
        elif v in S[i+1]:
            abc[v] += 1
            abc[u] -= 1
            ans.append(v)
print("Yes")
for ans_ in ans: print(ans_)

Measured memory_bytes: 16936
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

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

		// 入力
		int n = sc.nextInt();
		
		// 計算
		long result = 0L;
		int[][][][] dp = new int[n+1][4][4][4];
		// A->0 C->1 G->2 T->3
		dp[0][3][3][3] = 1;
		for(int len = 0; len < n; len++){
		    for(int i = 0; i < 4; i++){
		        for(int j = 0; j < 4; j++){
		            for(int k = 0; k < 4; k++){
		                if(dp[len][i][j][k] == 0) continue;
		                for(int a = 0; a < 4; a++){
		                    if(a == 1 && i == 2 && j == 0) continue;
		                    if(a == 1 && i == 0 && j == 2) continue;
		                    if(a == 1 && i == 2 && k == 0) continue;
		                    if(a == 1 && j == 2 && k == 0) continue;
		                    if(a == 2 && i == 1 && j == 0) continue;
		                    dp[len + 1][a][i][j] += dp[len][i][j][k];
		                    dp[len + 1][a][i][j] %= MOD;
		                }
		            }
		        }
		    }
		}

		// 出力
		for(int i = 0; i < 4; i++){
		    for(int j = 0; j < 4; j++){
		        for(int k = 0; k < 4; k++){
		            result += dp[n][i][j][k];
		            result %= MOD;
		        }
		    }
		}
		System.out.println(result);
        
	}
}


Measured memory_bytes: 21972
import re
import doctest


class IO_for_Contest(object):
    @staticmethod
    def my_input():
        # return raw_input()
        return input()

    @staticmethod
    def read_from_input():
        return IO_for_Contest.read_n_int(3)

    @staticmethod
    def read_line():
        return IO_for_Contest.my_input().strip()

    @staticmethod
    def read_int():
        return int(IO_for_Contest.my_input().strip())

    @staticmethod
    def read_n_int(n):
        return list(map(
                    int,
                    re.split('\s+', IO_for_Contest.my_input().strip())))[: n]


def solve():
    buf = IO_for_Contest.read_from_input()
    a = buf[0]
    b = buf[1]
    c = buf[2]

    if a == b and b == c:
        print(1)
        return
    if a == b or b == c or c == a:
        print(2)
        return
    print(3)

if __name__ == '__main__':
    # doctest.testmod()
    solve()


Measured memory_bytes: 8148
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int n;
long long ans;
int par[100010];
vector<pair<int ,int> >vx,vy;
vector<pair<int ,pair<int ,int> > >edges;
int root(int x)
{
	if(par[x]==x)return x;
	return par[x]=root(par[x]);
}
void un(pair<int ,pair<int ,int> >t)
{
	int x=t.second.first,y=t.second.second;
	int w=t.first;
	x=root(x);y=root(y);
	if(x!=y)
	{
		par[x]=y;
		ans+=w;
	}
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		par[i]=i;
		int x,y;
		scanf("%d%d",&x,&y);
		vx.push_back(make_pair(x,i));
		vy.push_back(make_pair(y,i));
	}
	sort(vx.begin(),vx.end());
	sort(vy.begin(),vy.end());
	for(int i=0;i+1<vx.size();i++)
	{
		edges.push_back(make_pair(vx[i+1].first-vx[i].first,make_pair(vx[i].second,vx[i+1].second)));
	}
	for(int i=0;i+1<vy.size();i++)
	{
		edges.push_back(make_pair(vy[i+1].first-vy[i].first,make_pair(vy[i].second,vy[i+1].second)));
	}
	sort(edges.begin(),edges.end());
	for(int i=0;i<edges.size();i++)
	{
		un(edges[i]);
	}
	printf("%d",ans);
	return 0;
}

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

int main()
{
  int n, x, cnt = 0;
  cin >> n;
  for (int i = 0; i < n; i++)
  {
    cin >> x;
    cnt += x == i + 1;
  }
  cout << (cnt >= n - 2 ? "YES" : "NO") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(var,cnt) for(int (var)=0; (var)<(int)(cnt); ++(var))
#define Rep(var,init,cnt) for(int (var)=(init); (var)<(cnt); ++(var))
#define ran(var,vec) for(auto &(var):(vec))
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(rall(v))
#define SUM(v) accumulate(all(v),0)
#define tget(tp,idx) get<idx>(tp)
#define TF(flag) (flag)?1:0
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using ti = tuple<int,int,int>;
using tl = tuple<ll,ll,ll>;

template<typename T>
using vec = vector<T>;
template<typename T>
using mat = vector<vec<T>>;
template<typename T>
using cub = vector<mat<T>>;
template<typename T>
using val = valarray<T>;

template<typename T>
using pq = priority_queue<T>;
template<typename T>
using rpq = priority_queue<T,vec<T>,greater<T>>;

template<typename T1,typename T2>
ostream &operator<<(ostream &os, const pair<T1,T2> &p){
  os<<"P("<<p.first<<", "<<p.second<<") ";
  return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is, pair<T1,T2> &p){
  is>>p.first>>p.second;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, vector<T> &v){
  for(T &in:v) is>>in;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const valarray<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, valarray<T> &v){
  for(T &in:v) is>>in;
  return is;
}

// Usual Template End ================================================

// Template End ======================================================

constexpr int MOD=1e9+7;

int main(void){
  char c; cin>>c;
  vec<char> v{'a','i','u','e','o'};
  bool ans=false;
  ran(i,v) ans|=(c==i);
  if(ans) cout<<"vowel"<<endl;
  else cout<<"consonant"<<endl;
}













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

int compare_int(const void *a, const void *b)
{
  return *(int*)b - *(int*)a;
}

int main(){
  int n;
  scanf("%d", &n);
  int d[n];
  for (int i=0; i<n; i++)
  {
    scanf("%d", &d[i]);
  }
  qsort(d, n, sizeof(int), compare_int);
  int cnt = 1;
  for (int i=0; i<n-1; i++)
  {
    if (d[i]>d[i+1]) {
      cnt++;
    }
  }
    
  printf("%d\n", cnt);

  return 0;
}

Measured memory_bytes: 128
# coding:utf-8

INF = float('inf')


def inpl(): return list(map(int, input().split()))


N, M = inpl()
# move = [inpl() for _ in range(M)]

ans = [0 for _ in range(N)]
ans[0] = 1
box = [1 for _ in range(N)]
# print(ans, box)
for i in range(M):
    # x, y = move[i]
    x, y = inpl()
    box[x - 1] -= 1
    box[y - 1] += 1
    if ans[x - 1]:
        ans[y - 1] = 1
        if box[x - 1] == 0:
            ans[x - 1] = 0
    # print(ans, box)


print(sum(ans))

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

const int MAX = 510000;
const int MOD = 1000000007;

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

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

    COMinit();

    ll n, k;
    cin >> n >> k;

    const ll mod = 1000000007;

    vector<ll> sm(n+1, 0);
    sm[0] = 0;
    for(ll i = 1; i < n+1; ++i) sm[i] = (sm[i-1]+i)%mod;

    vector<ll> sm_t(n+1, 0);
    sm_t[n] = n;
    for(ll i = 1; i < n+1; ++i) sm_t[n-i] = (sm_t[n-i+1]+(n-i))%mod;

    // rep(i, n+1) cout << sm[i] << " ";
    // cout << endl;

    // rep(i, n+1) cout << sm_t[i] << " ";
    // cout << endl;

    ll res = 0;
    for(ll i = k; i <= n+1; ++i){
        // cout << sm_t[n-i+1] << " " << sm[i-1] << endl;
        res =  (res + (sm_t[n-i+1]+mod - sm[i-1] + 1) % mod) % mod;
        
    }

    cout << res << endl;

    return 0;
}

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

int main()
{
    long long a,b,c,d;
    cin>>a>>b>>c>>d;
    vector<long long> v(4);
    v[0]=a*c;
    v[1]=a*d;
    v[2]=b*c;
    v[3]=b*d;
    sort(v.begin(),v.end());
    cout<<v[3];
    

    return 0;
}


Measured memory_bytes: 3628
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No"); }
void Yes() { cout << "Yes"; }
void No() { cout << "No"; }
//max_element


signed main()
{
	int N;
	string S;
	cin >> N;
	cin >> S;

	int cnt = 0;
	for (int i = 0; i < N - 2; i++)
	{
		if (S[i] == 'A'
			&& S[i + 1] == 'B'
			&& S[i + 2] == 'C'
			)
		{
			cnt++;
		}
	}

	cout << cnt << endl;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
int main(){
    ll N, M;
    cin >> N >> M;
    vl A(M), B(M - 1);
    for(int i = 0; i < M; i++){
        cin >> A.at(i);
    }
    sort(A.begin(), A.end());
    for(int i = 0; i < M - 1; i++){
        B.at(i) = (A.at(i + 1) - A.at(i));
    }
    sort(B.begin(), B.end());
    ll ans = 0;
    for(int i = 0; i < M - N; i++){
        ans += B.at(i);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

main() {
    int64_t n, q;
    cin >> n >> q;

    map<int64_t, int64_t> m;
    m[0] = 0;
    m[n] = -1;
  
    for (auto i : irange(0L, q)) {
        int64_t a, b;
        cin >> a >> b;

        auto it = m.lower_bound(a);
        if (it == m.end() || a < it->first) {
            --it;
            auto v = it->second;
            it = m.emplace(a, v).first;
        }
        --it;
        while (it != m.begin()) {
            auto previt = it;
            --previt;
            int64_t d = (previt->second - it->second) * (a - it->first);
            if (d <= b) {
                b -= d;
                m.erase(it--);
            } else {
                break;
            }
        }
        it->second += b / (a - it->first);
        b %= a - it->first;
        if (b > 0) {
            m.emplace(it->first + b, it->second);
            it->second += 1;
        }
    }
  
    for (auto i : irange(0L, n)) {
        cout << (--m.upper_bound(i))->second << "\n";
    }
}


Measured memory_bytes: 7680
#include <iostream>
#include <cstdio>
using namespace std;
int N=1000000007;
int main()
{
	int n,i;
	long long x;
	char s[2][60];
	cin>>n;
	scanf("%s",&s[0]);
	scanf("%s",&s[1]);
	x=3;
	i=1;	
	if(s[0][0]!=s[1][0])
	{
		i=2;
		x=6; 
	} 		
	//cout<<i<<endl;
	for(;i<n;i++)
	{
	//	cout<<s[0][i]<<" "<<s[1][i]<<endl;
		if(s[0][i]==s[1][i])
		{
			if(s[0][i-1]==s[1][i-1])
			{
				x=x*2;
				x=x%N;
			}			
		}
		else
		{
			if(s[0][i-1]==s[1][i-1])
			{
				x=x*2;
				x=x%N;			
			}
			else
			{
				x=x*3;
				x=x%N;
			}
			i++;
		}
		//cout<<i<<" "<<x<<endl;
	}
	cout<<x<<endl;
	return 0;
}

Measured memory_bytes: 256
s = input()
s += 'R'
kids = [0 for i in range(len(s))]
ri = 0
cursor = -1
for i in range(1, len(s)):
  if s[i-1] == 'R' and s[i] == 'L':
    ri = i-1
  elif s[i-1] == 'L' and s[i] == 'R':
    kids[ri] = int((i-1 - cursor) / 2)
    kids[ri+1] = int((i-1 - cursor) / 2)
    if (i-1 - cursor) % 2 == 1:
      if (ri - cursor) % 2 == 1:
        kids[ri] += 1
      else:
        kids[ri+1] += 1
    cursor = i-1
result = [str(kids[i]) for i in range(len(s)-1)]
print(' '.join(result))

Measured memory_bytes: 10876