akhauriyash/Code-Regression huggingface dataset:
// by adiforluls
#pragma GCC optimize ("-O2")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define FAST         ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll           long long
#define ld           long double
#define pb           push_back
#define mp           make_pair
#define pii          pair<int,int>
#define mii          map<int,int>
#define vi           vector<int>
#define vll          vector<long long>
#define all(a)       (a).begin(),(a).end()
#define clz(a)       __builtin_clz(a) // count leading zeroes
#define ctz(a)       __builtin_ctz(a) // count trailing zeroes
#define popc(a)      __builtin_popcount(a) // count set bits (for ints only diff for ll)
#define lul          1000000007
#define rep(i,a,b)   for(int i=a;i<b;i++)
#define rfor(i,a,b)  for(int i=a; i>=b; i--)
#define SIZE         1000005
#define F            first
#define S            second
#define mod          998244353

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " = " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " = " << arg1<<" |";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define endl         '\n'
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
const ld PI = acos(-1.0);
const int INF = 0x3f3f3f3f;

map<pii,int> ma;
void solve()
{ 
   int n; cin>>n;
   pii p[n];
   rep(i,0,n) cin>>p[i].F>>p[i].S;
   rep(i,0,n)
   {
      rep(j,0,n)
      {
        if(i==j) continue;
        int x = p[i].F-p[j].F,y = p[i].S-p[j].S;
        ma[{x,y}]++;
      }
   }
   int ans=0;
   for(auto i:ma) ans = max(ans,i.S);
   cout<<n-ans;
} 
int main()
{   
    FAST;
   //  #ifndef ONLINE_JUDGE
     // freopen("input.txt", "r", stdin);
     // freopen("output.txt", "w", stdout);
   //  #endif
    int t; t=1;
    while(t--){
       solve();
    }
    return 0;
}

Measured memory_bytes: 384
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 1000000007;
//const int MOD = 998244353;

long long int N, M, K, H, W, L, R;
//int N, M, K, H, W, L, R;




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

	cin >> N >> M >> K >> H;
	vector<long long int>v(N);
	vector<long long int>w(M);
	vector<long long int>u(K);
	for (auto &i : v)cin >> i;
	for (auto &i : w)cin >> i;
	for (auto &i : u)cin >> i;
	vector<long long int>box;
	for (auto i : v) {
		for (auto j : w)box.push_back(i + j);
	}
	sort(u.begin(), u.end());
	reverse(u.begin(), u.end());
	vector<int>index(N*M);
	priority_queue<pair<long long int, int>>PQ;
	for (int i = 0; i < N*M; i++) {
		PQ.push({ box[i] + u[0],i });
	}
	for (int i = 0; i < H; i++) {
		auto bag = PQ.top();
		PQ.pop();
		index[bag.second]++;
		if (index[bag.second] < K) {
			PQ.push({ box[bag.second] + u[index[bag.second]],bag.second });
		}
		cout << bag.first << endl;
	}
	return 0;
}

Measured memory_bytes: 30828
#include <bits/stdc++.h>
using namespace std;
int a, b, c, f[1000];
void get(int x) {
    for (int i = 1; i * i <= x; i++) {
        if (x % i == 0) {
            f[i]++;
            if (i * i != x) f[x / i]++;
        }
    }
}
int main() {
    memset(f, 0, sizeof(f));
    cin >> a >> b >> c;
    get(a);
    get(b);
    for (int i = 100; i >= 1; i--) {
        if (f[i] == 2) c--;
        if (c == 0) return cout << i, 0;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)
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, h;
    cin >> n >> h;
    vector<ll> a(n), b(n);
    rep1(i, n) cin >> a[i] >> b[i];
    ll ans = 0;
    sort(a.begin(), a.end(), greater<ll>());
    sort(b.begin(), b.end(), greater<ll>());
    ll cnt = a[0];
    rep1(i, n){
        if (b[i]<=a[0] || h<1) break;
        h -= b[i];
        ans++;
    }
    if (h>0) ans += (h / cnt) + (h%cnt!=0);

    cout << ans << endl;
    //printf("%.12f", ans);
}

Measured memory_bytes: 4832
#include<iostream>
#include<cstring> 
#include<sstream>
using namespace std;
int main()
{
    long long x, y, a;
    
    while(cin>>x>>y) {
        a=x+y;
        ostringstream os;
        os << a;
        string b = os.str();
        
        cout<< b.size() << endl;
    }
    return 0;
    
}

Measured memory_bytes: 3040
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>

using namespace std;
class State
{
public:
  int x1,y1,x2,y2,cost;

  State(int tx1,int ty1,int tx2,int ty2,int tcost)
  {
    x1 = tx1;
    y1 = ty1;
    x2 = tx2;
    y2 = ty2;
    cost = tcost;
  }
};

int w,h;
bool t[52][52];
bool used[52][52][52][52];

int dx1[] = {-1,1,0,0};
int dx2[] = {1,-1,0,0};
int dy1[] = {0,0,1,-1};
int dy2[] = {0,0,-1,1};


void solve()
{
	while(cin>>w>>h && (w||h))
	{
    int x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;
    x1--; y1--; x2--; y2--;

    for(int i=0;i<h;i++)
	{
      for(int j=0;j<w;j++)
	  {
        cin>>t[i][j];
      }
    }

    int ans = -1;
    queue<State> open;

    memset(used,0,sizeof(used));
    used[x1][y1][x2][y2] = true;
    open.push(State(x1,y1,x2,y2,0));

    while(!open.empty())
	{
      State st = open.front(); open.pop();
      if(st.cost >= 100) break;

      if(st.x1 == st.x2 && st.y1 == st.y2)
	  {
        ans = st.cost;
        break;
      }

      for(int i=0;i<4;i++)
	  {
        int nx1 = st.x1 + dx1[i];
        int ny1 = st.y1 + dy1[i];
        int nx2 = st.x2 + dx2[i];
        int ny2 = st.y2 + dy2[i];
        State nst = st;
        nst.cost++;

        if(nx1>=0 && nx1<w && ny1>=0 && ny1<h && !t[ny1][nx1])
		{
          nst.x1 = nx1;
          nst.y1 = ny1;
        }
        if(nx2>=0 && nx2<w && ny2>=0 && ny2<h && !t[ny2][nx2])
		{
          nst.x2 = nx2;
          nst.y2 = ny2;
        }

        if(!used[nst.x1][nst.y1][nst.x2][nst.y2])
		{
          used[nst.x1][nst.y1][nst.x2][nst.y2] = true;
          open.push(nst);
        }
      }
    }

    if(ans == -1)
      cout<<"NA\n";
    else
      cout<<ans<<endl;
  }

}

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

Measured memory_bytes: 8280
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

def main():
  import collections
  N = int(input())
  if N == 1:
    print(0)
  else:
    K = factorization(N)
    Count = 0
    for i in range(len(K)):
      A = K[i][0]
      B = K[i][1]
      C = 1
      D = 2
      while B >= C:
        C += D
        D += 1
        Count += 1
    print(Count)
main()
  

Measured memory_bytes: 66396
a = int(input())
b = list(map(int, input().split()))
count = 0
while(1):
  flag = 0
  for i in range(0, a, 1):
    if (b[i] % 2 == 1) :
      flag = 1
  if (flag == 1) :
    break
  for i in range(0, a, 1):
    b[i] /= 2
  count += 1
print(count)

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

using namespace std;

int main()
{
	string S, T;
	cin >> S >> T;

	int textLength = S.size();

	for (int i = 0; i < textLength; i++) {
		bool isMatch = true;
		for (int j = 0; j < textLength; j++) {
			if (S[j % textLength] != T[(i + j) % textLength]) {
				isMatch = false;
			}
		}
		if (isMatch) {
			cout << "Yes" << endl;
			return 0;
		}
	}

	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
N = int(input())
childs = [[] for _ in range(N)]
parent = [-1 for _ in range(N)]
sibling = [-1 for _ in range(N)]
isleaf = [True for _ in range(N)]
for _ in range(N):
    i, l, r = map(int, input().split())
    if l != -1 or r != -1:
        isleaf[i] = False
    for child in [l, r]:
        if child != -1:
            childs[i].append(child)
            parent[child] = i
    if l != -1:
        sibling[l] = r
    if r != -1:
        sibling[r] = l

depth = [0 for _ in range(N)]
height = [0 for _ in range(N)]


def dfs(cur):
    for child in childs[cur]:
        depth[child] = depth[cur] + 1
        dfs(child)
        height[cur] = max(height[child] + 1, height[cur])


root = 0
while root < N:
    if parent[root] == -1:
        break
    else:
        root += 1
dfs(root)

for i in range(N):
    print(
        'node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, {}'
        .format(
            i, parent[i], sibling[i], len(childs[i]), depth[i], height[i],
            'root' if i == root else 'leaf' if isleaf[i] else 'internal node'))



Measured memory_bytes: 5620
#include <bits/stdc++.h>
#define ll long long
#define cal(a,b) ((a+=b)%=mo)
using namespace std;
const int N=3e5+50,mo=998244353;
int fap(int a,int b){
    int s=1;
    for (; b; b>>=1,a=1ll*a*a%mo)
	if (b&1) s=1ll*s*a%mo;
    return s;
}
int n,a,b,ans,pl[N],nl[N];
long long k;
int c(int x,int y){
    if (x<y) return 0;
    return 1ll*pl[x]*nl[y]%mo*nl[x-y]%mo;
}
int main(){
    cin>>n>>a>>b>>k;
    pl[0]=nl[0]=1;
    for (int i=1; i<=n; ++i)
	pl[i]=1ll*pl[i-1]*i%mo;
    nl[n]=fap(pl[n],mo-2);
    for (int i=n-1; i; --i)
	nl[i]=1ll*nl[i+1]*(i+1)%mo;
    for (int i=0; i<=n; ++i){
	if (1ll*i*a>k) break;
	ll s=k-1ll*i*a;
	if (s%b) continue;
	int j=s/b;
	cal(ans,1ll*c(n,j)*c(n,i)%mo);
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 2560
N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

capacity = min(A,B,C,D,E)

if N % capacity == 0:
    answer = N // capacity + 4
else:
    answer = N // capacity + 5

print(answer)

Measured memory_bytes: 3064
/**
 *    author:  math2do
 *    created: 12.04.2020 23:00:04
**/

#include <bits/stdc++.h>

using namespace std;

template <typename T>
class graph {
 public:
  struct edge {
    int from;
    int to;
    T cost;
  };
 
  vector<edge> edges;
  vector<vector<int>> g;
  int n;
 
  graph(int _n) : n(_n) {
    g.resize(n);
  }
 
  virtual int add(int from, int to, T cost) = 0;
};

template <typename T>
class digraph : public graph<T> {
 public:
  using graph<T>::edges;
  using graph<T>::g;
  using graph<T>::n;
 
  digraph(int _n) : graph<T>(_n) {
  }
 
  int add(int from, int to, T cost = 1) {
    assert(0 <= from && from < n && 0 <= to && to < n);
    int id = (int) edges.size();
    g[from].push_back(id);
    edges.push_back({from, to, cost});
    return id;
  }
 
  digraph<T> reverse() const {
    digraph<T> rev(n);
    for (auto &e : edges) {
      rev.add(e.to, e.from, e.cost);
    }
    return rev;
  }
};

template <typename T>
bool cyclic(const digraph <T> &g) {
  const int white = 1;
  const int gray = 2;
  const int black = 3;  
  vector <int> col(g.n, white);

  function <bool(int)> dfs = [&](int u) -> bool {
    col[u] = gray;
    bool found = false;
    for (int id : g.g[u]) {
      int v = g.edges[id].from ^ g.edges[id].to ^ u;
      if (col[v] == gray) {
        found = true;
        goto end;
      }
      if (col[v] == white && dfs(v)) {
        found = true;
        goto end;
      }
    } 
    col[u] = black;
    end : {
      return found;
    } 
  };
  
  bool found = false;
  for (int u = 0; u < g.n; u++) {
    if (col[u] == white) {
      if (dfs(u)) {
        found = true;
        goto end;
      }
    }
  }
  end : {
    return found;
  } 
  //return true if digraph is cyclic
} 

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  digraph <int> g(n);
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    g.add(x, y);
  }
  if (cyclic(g)) {
    cout << 1 << '\n';
  } else {
    cout << 0 << '\n';
  } 
  return 0;
}



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

int main() {
  string S;
  cin>>S;
  int N=S.size();
  vector<vector<int64_t>>p(N,vector<int64_t>(13));
  int64_t Q=1000000007;
  if(S.at(0)=='?'){
    for(int i=0;i<10;i++){
      p.at(0).at(i)=1;
    }
  }
  else{
    int a=S.at(0)-'0';
    p.at(0).at(a)=1;
  }
  for(int i=1;i<N;i++){
    if(S.at(i)=='?'){
      for(int j=0;j<10;j++){
        for(int k=0;k<13;k++){
          int b=(k*10+j)%13;
          p.at(i).at(b)=(p.at(i).at(b)+p.at(i-1).at(k))%Q;
        }
      }
    }
    else{
      int a=S.at(i)-'0';
      for(int k=0;k<13;k++){
        int b=(k*10+a)%13;
        p.at(i).at(b)=p.at(i-1).at(k);
      }
    }
  }
  cout<<p.at(N-1).at(5)<<endl;
        
}




Measured memory_bytes: 13696
(N, M) = map(int, input().split())

P = []
Y = []
pyd = {}
for i in range(M):
    (p, y) = map(int, input().split())
    if p in pyd:
        pyd[p].append([y, i])
    else:
        pyd[p] = [[y, i]]

ans = []
for k in pyd:
    pyd[k].sort(key=lambda x:x[0])
    for i in range(len(pyd[k])):
        htag = str(k)
        while len(htag) < 6:
            htag = '0' + htag
        ltag = str(i+1)
        while len(ltag) < 6:
            ltag = '0' + ltag
        tag = htag + ltag
        ans.append([pyd[k][i][1], tag])

ans.sort(key=lambda x:x[0])
for a in ans:
    print(a[1])



Measured memory_bytes: 57452
// Problem : D - Knight
// Contest : AtCoder - AtCoder Beginner Contest 145
// URL : https://atcoder.jp/contests/abc145/tasks/abc145_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

//Macros

#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define inf 1e10
#define PI acos(-1.0)
#define int long long
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 2000005

//Solution

int binpow(int x,int y){
    x %= mod;
    int res = 1;
    while(y){
        if(y&1) res = (res*x)%mod;
        x = (x*x)%mod;
        y = y/2;
    }
    return res;
}
 
int inv(int a){
    return binpow(a,mod-2);
}
 
int fact[N], invfact[N];
 
void precompute(){
    fact[0] = 1;
    for(int i=1;i<N;i++) fact[i] = (fact[i-1]*i)%mod;
    invfact[N-1] = inv(fact[N-1])%mod;
    for(int i=N-2;i>=0;i--) invfact[i] = (invfact[i+1]*(i+1))%mod;
}
 
int ncr(int n, int r){
    if(n<r) return 0;
    return (((fact[n]*invfact[r])%mod)*invfact[n-r])%mod;
}

void solve(){
    precompute();
    int x,y;
    cin>>x>>y;
    if((x+y)%3){
        cout<<0<<endl;
        return;
    }
    int n = (2*y-x)/3;
    int m = (2*x-y)/3;
    if(n < 0 || m < 0){
        cout<<0<<endl;
        return;
    }
    cout<<ncr(m+n,n)<<endl;
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int tests;
    //cin>>tests;
    tests = 1;
    while(tests--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 34884
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    String S = sc.nextLine();
    String T = sc.nextLine();
    int n = S.length();
    
    String ans = "No";
    for(int i = 0; i <= n; i++){
      if(S.equals(T)){
        ans = "Yes";
        break;
      }
      
      String s1 = new String(S.substring(0,1));
      String s2 = new String(S.substring(1,n));
      S = s2+s1;
    }
    System.out.println(ans);
  }
}

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

double dp[3010];

int main(){
	int n;
	scanf("%d", &n);
	double p;
	dp[0] = 1;
	for(int i=0; i < n; i++) {
		scanf("%lf", &p);
		for(int j=i+1; j >= 0; j--)
			dp[j] = (j == 0 ? 0 : dp[j-1]*p) + dp[j]*(1-p);
	}
	double ans = 0;
	for(int i=0; i <= n; i++)
		if(i > n-i) ans += dp[i];
	printf("%.12lf\n", ans);
}


Measured memory_bytes: 256
# encoding: utf-8
N = int(input())
F = [list(map(int, input().split())) for i in range(N)]
P = [list(map(int, input().split())) for i in range(N)]

def bc10(num):
    num_tmp = num
    ret = 0
    for i in range(10):
        if num_tmp % 2: ret += 1
        num_tmp = num_tmp >> 1
    return ret

# re-arrange enemy infomation
F_mask = [0] * N
for i, F_row in enumerate(F): F_mask[i] += sum([(2 ** j) * item for j, item in enumerate(F_row)])

ans = - (10 ** 7) * N
for case in range(1, 2 ** 10):
    # decide joisino-onechan's status
    joisino = 0
    case_tmp = case
    for i in range(10):
        joisino += (case_tmp % 2) << i
        case_tmp = case_tmp >> 1
    # calc profit
    profit = 0
    for i, enemy in enumerate(F_mask): profit += P[i][bc10(joisino & enemy)]
    # update
    # print("#", joisino, profit)
    if ans < profit: ans = profit

print(ans)

Measured memory_bytes: 3064
#include <stdio.h>

void timePrint(int time);

int main(void){
  int t, h, s;
  int time;

  scanf("%d%d%d", &t, &h, &s);
  while(!(t == -1 && h == -1 && s == -1)){
    time = 7200 - (t*3600 + h*60 + s);
    timePrint(time);
    timePrint(time*3);
    scanf("%d%d%d", &t, &h, &s);
  }
  return 0;
}

void timePrint(int time){
  printf("%02d:", time/3600);
  time %= 3600;
  printf("%02d:", time/60);
  time %= 60;
  printf("%02d\n", time);
  return;
}

Measured memory_bytes: 612
import itertools
N, M,Q = map(int, input().split())
S = [list(map(int, input().split())) for _ in range(Q)]

ans=-1
#全探索
seq = tuple(range(M))

com=list(itertools.combinations_with_replacement(seq, N))

for li in com:
    re=0
    for i in range(Q):
        a=S[i][0]-1
        b=S[i][1]-1
        c=S[i][2]
        d=S[i][3]
        if li[b]-li[a] == c:
            re += d
    if re > ans:
        ans=re

print(ans)

Measured memory_bytes: 21412
word=[]
max_score=0

n=int(input())
for i in range(n):
    s=input()
    word.append([s,1])
m=int(input())
for i in range(m):
    s=input()
    word.append([s,-1])
word2=sorted(word)

now=word2[0][0]
score=0
for i in range(n+m):
    if now==word2[i][0]:
        score+=word2[i][1]
    else:
        if score>max_score:
            max_score=score
        score=0
        score+=word2[i][1]
        now=word2[i][0]
print(max(score,max_score))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int N;
long long x,sum,mmin=2e9,cnt;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> N;
	for(int i = 1; i <= N; ++i){
		cin >> x;
		sum += abs(x);
		mmin = min(mmin,abs(x));
		if(x < 0) cnt++;
	}
	if(cnt % 2 == 1) sum -= mmin*2;
	cout << sum << endl;
	return 0;
}

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

int32_t main()
{
	int n;
	cin>>n;
	
	int arr[n];
	for (int i=0;i<n;i++) cin>>arr[i];
	
	int ans=0;
	int elem = arr[0];
	for (int i=0;i<n;i++){
		elem=min(elem,arr[i]);
		if (elem>=arr[i]) ans++;
	}
	
	cout<<ans<<'\n';
}



Measured memory_bytes: 1792
use std::io::*;
use std::str::FromStr;
use std::collections::HashMap;
use std::collections::BTreeSet;
use std::collections::HashSet;
use std::cmp;
use std::f64::consts;

fn main() {
    let n: String = read();
    let k: i64 = read();
    let char_vec: Vec<char> = n.chars().collect();

    let mut ans= '1';

    let length = cmp::min(k, char_vec.len() as i64) as usize;

    for i in 0..length {
        if char_vec[i] != '1' {
            ans = char_vec[i];
            break;
        }
    }

    println!("{}", ans);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// 最大公約数
fn gcd(a: i32, b: i32) -> i32 {
    match b {
        0 => a,
        _ => gcd(b, a % b)
    }
}

// 最小公倍数
fn lcm(a: i32, b: i32) -> i32 {
    a * b / gcd(a, b)
}

// 階乗
fn kaijou(n: i32)->i32 {
    if n == 1 {
        return n;
    }
    return n * kaijou(n-1);
}

Measured memory_bytes: 4352
# 0〜9
l=list(range(10))

# 入力
N,K=map(int,input().split())
l2=list(map(int,input().split()))

# 使用可能な数字を求める
for x in l2:
  l.remove(x)

# 集合型に変換
l=set(l)

# 1<=N<=10000 なので、答えは最大でも100000まで
for x in range(1,100001):
  # 集合型に変換
  y=set(map(int,list(str(x))))

  # Nを上回る数字かつ、使える数字のみを使用している場合
  if N<=x and l.issuperset(y):
    print(x)
    break

Measured memory_bytes: 3060
N = int(raw_input())
A = map(int, raw_input().split())

def solve(N, A):
    problems = []
    for i, x in enumerate(A):
        if x != i+1:
            problems.append(i)
    if len(problems) < 2: return True
    if len(problems) > 2: return False
    i0, j0 = problems
    A[i0], A[j0] = A[j0], A[i0]
    return all(A[k] < A[k+1] for k in xrange(N-1))

print "YES" if solve(N, A) else "NO"


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

bool solve() {
    ll N, M;
    cin >> N >> M;
    string S;
    cin >> S;
    vector<int> s(N);
    for ( int i = 0; i < N; i++ ) {
        s[i] = (S[i] == 'B' ? 1 : 0);
    }
    int a, b;
    vector<vector<int>> G(N);
    vector<vector<int>> nc(N, vector<int>(2));
    for ( int i = 0; i < M; i++ ) {
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        if ( a != b ) G[b].push_back(a);
        nc[a][s[b]]++;
        if ( a != b ) nc[b][s[a]]++;
    }
    priority_queue<pii> q;
    auto q_push = [&](int i) {
        q.push(pii(-min(nc[i][0],nc[i][1]), i));
    };
    for ( int i = 0; i < N; i++ ) {
        q_push(i);
    }
    vector<int> ng(N);

    while ( !q.empty() ) {
        int i, m;
        auto p = q.top();
        i = p.second;
        m = -p.first;
        if ( ng[i] > 0 ) {
            q.pop();
            continue;
        }
        int mn = min(nc[i][0],nc[i][1]);
        if ( mn < m ) {
            q.pop();
            continue;
        }
        if ( m == 0 ) {
            q.pop();
            for ( int u : G[i] ) {
                if ( ng[u] > 0 ) continue;
                if ( u != i ) {
                    nc[u][s[i]]--;
                    q_push(u);
                }
            }
            ng[i] = 1;
        } else {
            break;
        }
    }
    bool ans = !q.empty();
    return ans;
}

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

Measured memory_bytes: 23672
N, M = [int(i) for i in input().split()]

#通れない箇所を示す配列の作成
a = [0 for i in range(N+1)] #0で初期化

#通れない箇所にフラグを立てる
for mi in range(M):
    a[int(input())] = 1
#print(a)

cnt = 0

#通れるパターンを示す配列の作成
s = [0 for i in range(N+1)] #0で初期化
s[0] = 1  #フィボナッチlikeに　n-1, n-2を参照して計算するので，はじめは1とする
#print(s)

if a[1] == 0:  #配列aで通れるのなら1
    s[1] = 1
else:
    s[1] = 0   #配列aで通れないのなら0
#print(s)
for ni in range(2,N+1):  #フィボナッチlikeなので[2]から計算開始
    if a[ni] == 0:  #通れる場合
        s[ni] = (s[ni-1] + s[ni-2]) % 1000000007
    else: #通れない場合
        s[ni] = 0
#print(s)

print(s[N]) #配列の最後が答え

Measured memory_bytes: 7832
#include<iostream>
#include<vector>
#include<cmath>
#include<map>
#include<queue>
#include<stack>
#include<algorithm>
#include<functional>

typedef unsigned long long LL;

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int>a;
	a.push_back(0);
	for (int i = 0; i < N; i++) {
		int tmp;
		cin >> tmp;
		a.push_back(tmp);
	}
	int number = 0;
	bool flag = false;
	int current = 1;
	do{
		number++;
		current = a[current];
		if (current == 2) {
			flag = true;
			break;
		}
	} while (number < N + 10);
	if (!flag) {
		cout << -1 << endl;
	}
	else {
		cout << number << endl;
	}
}

Measured memory_bytes: 892
def main():
  
  n,m = map(int, input().split())
  A = sorted([int(x) for x in input().split()],reverse=True)
  
  asum = 0
  for a in A:
    asum += a
   
  if(A[m-1]>=asum/(4*m)):
    print("Yes")
  else:
    print("No")
  return 0
 
if __name__ == "__main__":
  main()

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstring>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  vector<int> ans(s.size());
  rep(i, s.size()-1) {
    if (s[i] == 'R' && s[i+1] == 'L') {
      ans[i]++, ans[i+1]++;
      for (int j = i-2; j >= 0; j-=2) {
        if (s[j+1] == 'L' || s[j] == 'L')
          break;
        ans[i]++;
      }
      for (int j = i+2; j < s.size(); j+=2) {
        if (s[j-1] == 'R' || s[j] == 'R')
          break;
        ans[i]++;
      }
      for (int j = i-1; j >= 0; j-=2) {
        if (s[j+1] == 'L' || s[j] == 'L')
          break;
        ans[i+1]++;
      }
      for (int j = i+3; j < s.size(); j+=2) {
        if (s[j-1] == 'R' || s[j] == 'R')
          break;
        ans[i+1]++;
      }
    }
  }
  rep(i, s.size())
    printf("%d%c", ans[i], i<s.size()-1?' ':'\n');
  return 0;
}

Measured memory_bytes: 1104
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cout<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}


typedef long long int64;


int main() {
    int n,k,x,y;
    cin >> n >> k >> x >> y;
    cout << x*min(n,k) + y*max(0,n-k) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <tuple>

using namespace std;

class Solver {
};

signed main() {
	while (true) {
		int n;
		cin >> n;
		if (n == 0)break;

		vector<int> hs(n + 1, 0);
		for (int i = 0; i < n + 1; i++) {
			cin >> hs[i];
		}

		for (int i = 0; i < n + 1; i++) {
			vector<int> remain;
			for (int j = 0; j < n + 1; j++) {
				if (i == j)continue;

				remain.emplace_back(hs[j]);
			}
			vector<int> deltas;
			for (int j = 1; j < n; j++) {
				deltas.emplace_back(remain[j] - remain[j - 1]);
			}
			sort(deltas.begin(), deltas.end());

			if (deltas[0] == deltas[deltas.size() - 1]) {
				cout << hs[i] << endl;
				break;
			}
		}
	}
}


Measured memory_bytes: 3140
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}

vector<ll> pw2(51,1);vector<ll> pw10(19,1);
ll high_order_bit(ll n){
    ll tmp=1,i=-1;
    while(tmp<=n){
        tmp*=2;
        i++;
    }
    if(n==0) return 0;
    else return i;
}
vector<ll> binary_expansion(ll n){
    vector<ll> B(high_order_bit(n)+1);
    ll tmp=n;
    for(ll i=high_order_bit(n);i>=0;i--){
        B[i]=tmp/pw2[i];
        tmp%=pw2[i];
    }
    return B;
}
vector<ll> divisor(ll x){
    vector<ll> div;
    for(int i=1;i*i<=x;i++){
        if(i*i!=x && x%i==0){
            div.pb(i);
            div.pb(x/i);
        }
        else if(x%i==0) div.pb(i);
    }
    return div;
}
vector<ll> vectorprime(ll x){
    vector<bool> is_prime(x+1);
    vector<ll> prime;
    rep(i,x+1) is_prime[i]=true;
    is_prime[0]=is_prime[1]=false;
    for(int i=2;i<=x;i++){
        if(is_prime[i]){
            prime.pb(i);
        }
        for(int j=i*2;j<=x;j+=i) is_prime[j]=false;
    }
    return prime;
}

int main(){
    {rep1(i,50) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    
    string N; cin>>N;
    bool ans=false;
    rep(i,3){
        if(N[i]=='7') ans=true;
    }
    if(ans) cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 3616
#include<cstdio>
using namespace std;
int main(){
	int m,k;
	scanf("%d%d",&m,&k);
	if (k>=1<<m){
		printf("-1\n");
	}else
	if (m==0) {
		if (k==0) printf("0 0\n");else printf("-1\n");
	}else
	if (m==1){
		if (k==0) printf("0 0 1 1\n");else printf("-1\n");
	}else{
		for (int i=0;i<1<<m;i++)
		if (i!=k)printf("%d ",i);
		printf("%d ",k);
		for (int i=(1<<m)-1;i>=0;i--)
		if (i!=k)printf("%d ",i);
		printf("%d\n",k);
	}
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;
const int MOD = 1e9+7;


#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((int)(x).size())
//vvintを作る　マクロで　 #define vvint(N,M) vector<vector<int>>

using namespace std;

struct node{
    int key;
    int pk,lk,rk;
};


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

    int n;
    cin >> n;
    vector<node> nodes(n+1);
    for(int i = 1; i < n+1;i++){
        cin >> nodes[i].key;
    }

    for(int i = 1; i < n+1;i++){
        cout << "node " << i << ": key = " << nodes[i].key << ", ";
        if(i != 1) cout << "parent key = " << nodes[i/2].key << ", ";
        if(i*2 <= n) cout << "left key = " << nodes[i*2].key << ", ";
        if(i*2+1 <= n) cout << "right key = " << nodes[i*2+1].key << ", ";
        cout << endl; 
    }

    

    return 0;
}


Measured memory_bytes: 3132
n = int(input())
a = [int(x) for x in input().split()]

p = min(a)
q = max(a)

res = 4000000
for x in range(p, q+1):
    tmp = 0
    for y in a:
        tmp += (x - y) ** 2
    res = min(res, tmp)

print(res)

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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int n;
ll m;
int a[125252];
ll sum[125252];

int main(){
    scanf("%d%lld",&n,&m);
    REP(i,n)scanf("%d",a+i);
    sort(a,a+n);
    int ok = 0, ng = 1<<30;
    while(abs(ok-ng)>1){
        int x = (ok+ng)/2;
        ll cnt = 0;
        REP(i,n){
            cnt += (a+n)-lower_bound(a,a+n,x-a[i]);
        }
        (cnt>=m ? ok : ng) = x;
    }
    REP(i,n)sum[i+1] = sum[i]+a[i];
    ll rest = m;
    int th = ok;
    ll ans = 0;
    // cout<<th<<endl;
    REP(i,n){
        int it = upper_bound(a,a+n,th-a[i])-a;
        ans += sum[n] - sum[it];
        ans += 1ll * (n-it) * a[i];
        rest -= n-it;
        // cout<<a[i]<<endl;
        // cout<<ans<<endl;
        // cout<<rest<<endl;
    }
    // DEBUG(ans);
    // DEBUG(th);
    // DEBUG(rest);
    ans += rest * th;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1408
/*
 * =template=.cpp
 * Copyright (C) 2017 hzw <hzw@huzhenweideMacBook.local>
 *
 * Distributed under terms of the MIT license.
 */

#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<string>
#include<cstring>
#include<sstream>
#define FR first
#define SC second
#define MP make_pair
#define rep(i,a,b) for (int i=a;i<=b;i++)
#define pb push_back
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N=100010;
const int p=1000000007;
int pow(int a,int b,int c)
{
    if (a==0)return 0;
    int d=a,e=1;
    while (b)
    {
        if (b&1) e=(1LL*e*d)%c;
        d=1LL*d*d%c;
        b>>=1;
    }
    return e;
}
int random(int n) { return 1LL*rand()*rand()%n+1;}
int n,m,d,q;
LL f[N];
int a[N],b[N];
int main()
{
	scanf("%d",&n);
	cout<<n/3<<endl;
	return 0;
}


Measured memory_bytes: 256
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")

#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
const int NINF = -1*INF;
const long long LLINF = 1ll << 60;
const long long LLNINF = -1*LLINF;

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}

template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
	return os << "[ " << p.first << ", " << p.second << "]" ;
}

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef vector<vector<int>> vvi;
typedef vector<vll> vvll;
typedef vector<vd> vvd;
typedef vector<vld> vvld;
 
#define mp make_pair
#define pb push_back
#define pf push_front
#define all(x) x.begin(), x.end()
#define revAll(x) x.rbegin(), x.rend()
#define gcd(a, b) __gcd(a, b)
#define popcount(x) __builtin_popcount(x)
#define isize(x) (int)(x.size())
#define rep(i,n) for(int i = 0; i < n; i++)
#define umap unordered_map
#define uset unordered_set
#define pq priority_queue

const ll MOD = 1e9 + 7;

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);
	int rows, cols;
	cin >> rows >> cols;
	int r0, c0, r1, c1;
	cin >> r0 >> c0 >> r1 >> c1;
	r0--, c0--, r1--, c1--;
	vvi G = vvi(rows, vi(cols, 0));
	rep(i, rows) {
		rep(j, cols) {
			char c; cin >> c;
			G[i][j] = (c == '#' ? 1 : 0);
		}
	}
	auto inside = [rows, cols] (int r, int c) {
		return r >= 0 and c >= 0 and r < rows and c < cols;
	};
	deque<tuple<int, int, int>> Q = deque<tuple<int,int,int>>();
	vi seen = vi(rows*cols+10, 0);
	Q.pb({0, r0, c0});
	int ans = -1;
	while (!Q.empty()) {
		auto [magics, r, c] = Q.back();
		Q.pop_back();
		int val = r*cols + c;
		if (seen[val]) continue;
		seen[val] = 1;
		if (r == r1 and c == c1) {
			ans = magics;
			break;
		}
		for (int dr = -2; dr <= 2; dr++){
			for (int dc = -2; dc <= 2; dc++){
				int nr = r + dr, nc = c + dc;
				if (!inside(nr, nc) or G[nr][nc] == 1 or seen[nr*cols+nc]) continue;
				if (abs(dr) + abs(dc) > 1) {
					Q.pf({magics+1, nr, nc});
				}else{
					Q.pb({magics, nr, nc});
				}			
			}
		}
	}
	cout << ans;
}

Measured memory_bytes: 11800
ls = list(input())
n = len(ls)
rvls = ls[::-1]

fh = int((n-1) /2)
fhls = ls[:fh]
rvfhls = fhls[::-1]

sh = int((n+3)/2-1)
shls = ls[sh:]
rvshls = shls[::-1]


if ls == rvls and fhls==rvfhls and shls == rvshls:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
use proconio::{input, fastout};

macro_rules! echo {
  ($val:expr) => {
    println!("{}", $val);
  }
}

#[fastout]
fn main() {
  input!{
    n: usize,
    mut aa: [i64; n]
  };
  
  let max = *aa.iter().max().unwrap();
  let mut ans_a = *aa.iter().min().unwrap();
  for a in &aa {
    if *a == max {
      continue;
    }
    if (max - ans_a*2).abs() > (max - *a*2).abs() {
      ans_a = *a;
    }
  }
  println!("{} {}", max, ans_a);
}


Measured memory_bytes: 3620
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<utility>
#include<cstdio>
using namespace std;
#define rep(i,x,n) for(int i=x;i<n;i++)
using ll=long long;

string ans;

void ps(int n,char a){
    for(int i=0;i<n;i++) ans+=a;
    return;
}

int main(){
    string s;cin>>s;
    int i=0;
    int n=s.size();
    bool flag=true;
    while(i<n){
        if(s.substr(i,min(n-i,5))=="dream"){
            if(i+5==n) break;
            else if(s[i+5]=='d'){
                i+=5;continue;
            }else if(i+6<n&&s[i+5]=='e'&&s[i+6]=='r'){
                if(i+7==n) break;
                if(s[i+7]=='a'){
                    i+=5;continue;
                }else if(s[i+7]=='d'||s[i+7]=='e'){
                    i+=7;continue;
                }else{
                    flag=false;break;
                }
            }else{
                flag=false;break;
            }
        }else if(s.substr(i,min(n-i,5))=="erase"){
            if(i+5==n) break;
            else if(s[i+5]=='e'||s[i+5]=='d'){
                i+=5;continue;
            }else if(s[i+5]=='r'){
                if(i+6==n) break;
                if(s[i+6]=='e'||s[i+6]=='d'){
                    i+=6;continue;
                }else{
                    flag=false;break;
                }
            }
        }else{
            flag=false;break;
        }
    }
    if(flag) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}    

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int a, b, c;
    cin >> a >> b >> c;
    int nokori = a-b;
    cout << max(0, c-nokori) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  string s;
  cin >> s;
  int ans = 700;
  rep(i, 0, s.size()) {
    if (s[i] == 'o')
      ans += 100;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        
        int result = a - (b*2);
        System.out.println(result > 0 ? result : 0);
        
    }
}


Measured memory_bytes: 35616
using System;
using System.Linq;

namespace abc138_b
{
    static class Program
    {
        static void Main(string[] args)
        {
            var n = Console.ReadLine().ToInteger();
            var a = Console.ReadLine().ToDoubleArray();

            var answer = 0D;
            for (int i = 0; i < a.Length; i++)
            {
                answer += 1 / a[i];
            }

            Console.WriteLine($"{1 / answer}");
        }

        static int ToInteger(this string s)
        {
            return int.Parse(s);
        }

        static double ToDouble(this string s)
        {
            return double.Parse(s);
        }


        static double[] ToDoubleArray(this string s, char separator = ' ')
        {
            return s.Split(separator).Select(m => m.ToDouble()).ToArray();
        }
    }
}


Measured memory_bytes: 13396
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include <string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<bits/stdc++.h>
#include <set>
#define ll   long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f
#define pi 3.1415926535898
using namespace std;
const int mod=1e9+7;

int main()
{
    ll a1,a2,t1,t2,b1,b2;
    cin>>t1>>t2>>a1>>a2>>b1>>b2;
    if(a1*t1+a2*t2 == b1*t1+b2*t2)
    {
        cout<<"infinity"<<endl;
        return 0;
    }
    a1=a1*t1;
    a2=a2*t2;
    b1=b1*t1;
    b2=b2*t2;
    if(a1+a2>b1+b2)
    {
        swap(a1,b1);
        swap(a2,b2);
    }
    if(a1>b1)
    {
        ll r = (a1-b1)/(b1+b2-a1-a2);
        ll res = 2*r;
        if((a1-b1)%(b1+b2-a1-a2))
            res++;
        cout<<res<<endl;
    }
    else
    {
        cout<<0<<endl;
    }
    return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
map<char,long long int>q;
int main()
{
    int n;
    scanf("%d",&n);
    char str[16];
    for(int i=0;i<n;i++)
    {
        scanf("%s",str);
        q[str[0]]++;
    }
    long long int sum=0;
    sum+=q['M']*q['A']*(q['R']+q['C']+q['H'])+q['A']*q['R']*(q['C']+q['H'])+q['R']*q['C']*q['H']+q['M']*q['R']*(q['C']+q['H'])+q['M']*q['C']*q['H']+q['A']*q['C']*q['H'];
    printf("%lld",sum);


}


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

int main() {
  int L =0;
  string w;
  cin >> w;
  for(int i = 0;i < 3;i++){
    if(w[i] == 'R')L++;
  }
  if(w[1] == 'S' && w[0] == 'R')L = 1;
  cout << L <<endl;
}

Measured memory_bytes: 3600
def load_input():
    s = [int(c) for c in list(input())]
    return s


def main():
    s = load_input()

    cand = []
    cand.append([0 if i % 2 == 0 else 1 for i in range(len(s))])
    cand.append([0 if i % 2 == 1 else 1 for i in range(len(s))])

    diff = [0, 0]
    for i in range(2):
        for j in range(len(s)):
            if s[j] != cand[i][j]:
                diff[i] += 1
    if diff[0] < diff[1]:
        print(diff[0])
    else:
        print(diff[1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 5400
from collections import deque


def resolve():
  N, M = map(int, input().split(" "))
  connections = []
  for _ in range(N):
    connections.append(deque())
  checked = [False] * N
  prev = [None] * N

  for _ in range(M):
    A, B = map(int, input().split(" "))
    A -= 1
    B -= 1
    connections[A].append(B)
    connections[B].append(A)

  max_count = 0
  for i in range(N):
    if checked[i]:
      continue

    checked[i] = True
    count = 1 # 自身が入ってるので 1 から count 開始
    current = i
    # 根に戻ってくるまでループする
    while current != i or len(connections[current]) != 0:
      checked[current] = True
      # 次のノードを見つける
      next_node = connections[current].pop()
      # チェック済みのノードにぶつかった時は next_node を入れ替える。
      while checked[next_node]:
        if len(connections[current]) != 0:
          next_node = connections[current].pop()
        else:
          # チェック済みじゃ無いノードが見つからなかった場合は Break する。
          next_node = None
          break


      # チェックしながら行けるところまで行く
      while next_node is not None:
        prev[next_node] = current
        current = next_node
        # 移動した瞬間に count をインクリメントする。
        count += 1
        checked[current] = True
        # next_node　が見つからなかった場合は Break. 遡る処理に入る。
        if len(connections[current]) == 0:
          break

        next_node = connections[current].pop()
        # チェック済みのノードにぶつかった時は next_node を入れ替える。
        while checked[next_node]:
          if len(connections[current]) != 0:
            next_node = connections[current].pop()
          else:
            # チェック済みじゃ無いノードが見つからなかった場合は Break する。
            next_node = None
            break
      
      # 行き止まりにまで到達してることが保証されているので一旦 1 つ戻る
      if prev[current] is None:
        continue
      current = prev[current]

      # 次の分岐が来るまで遡る
      while len(connections[current]) == 0:
        if prev[current] is not None:
          current = prev[current]
        else:
          break

    max_count = max(count, max_count)
  # print(prev)
  print(max_count)

if __name__ == "__main__":
  resolve()

Measured memory_bytes: 217404
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>

using namespace std;
using lli = long long int;
// #define DEBUG
#ifdef DEBUG
#define debug(var) cout << (#var) << ": " << (var) << endl;
template<class T> void dump_array_impl(const T& a) {
  bool first = true;
  for (auto&& x : a) {
    if (!first) cout << ", "; else first = false; cout << x;
  }
}
#define debug_array(a) cout<<(#a)<<": ";dump_array_impl(a);cout<<endl
#else
#define debug(var) {}
#define debug_array(a) {}
#endif
template<class T> void read_n(vector<T>& v, size_t n) {
  v = vector<T>(n); for (lli i=0; i<n; ++i) cin >> v[i];
}
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

lli n, m;
vector<lli> p;
vector<pair<lli, lli>> s;

template<class T>
lli root(T& uf, lli x) {
  if (uf[x] == x) return x;
  return uf[x] = root(uf, uf[x]);
}

template<class T>
lli same(T& uf, lli x, lli y) {
  return root(uf, x) == root(uf, y);
}

template<class T>
void unite(T& uf, lli x, lli y) {
  lli rx = root(uf, x), ry = root(uf, y);
  uf[rx] = ry;
}

int main() {
  cin >> n >> m;
  p = decltype(p)(n+1); s = decltype(s)(m);
  for (lli i=1; i<=n; ++i) cin >> p[i];
  for (lli i=0; i<m; ++i) cin >> s[i].first >> s[i].second;
  vector<lli> uf(n+1);
  iota(begin(uf), end(uf), 0);
  for (lli i=0; i<m; ++i) {
    unite(uf, s[i].first, s[i].second);
  }
  lli ans = 0;
  for (lli i=1; i<=n; ++i) {
    if (same(uf, i, p[i])) ++ans;
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  int n, k, sum;
  cin >> n >> k;

  for (int i = 0; i < n+1; i++) {
    // 操作Aをi回操作する。必ず操作Aは最初に集中する
    int f = pow(2,i)+k*(n-i);
      
    for (int j = 0; j < n+1; j++) {
      // i回操作した場合の最終数fがほかの回数（j回）操作した場合の最終数mと比べて大きければアウト
      // 内側のfor文をbreakし、外側のfor文に戻る
      int m = pow(2,j)+k*(n-j);
      if (f > m) 
        break;
      else if (j == n)
        sum = f;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
import Control.Monad
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)

main :: IO ()
main = do
    n <- fst . fromJust . B.readInt <$> B.getLine
    ts <- replicateM n $ fst . fromJust . B.readInt <$> B.getLine
    print $ foldl1 lcm ts


Measured memory_bytes: 764