akhauriyash/Code-Regression huggingface dataset:
A     = [list(map(int, input().split())) for i in range(3)]
N     = int(input())
lst_b = [int(input()) for i in range(N)]


def main(A, N, lst_b):
    
    matrix_result = [[False]*3 for i in range(3)]
    flag_bingo = False

    for b in lst_b:
        for i in range(3):
            for j in range(3):
                if A[i][j] == b:
                    matrix_result[i][j] = True
        
    for i in range(3):
        # check tate
        if (matrix_result[0][i] and matrix_result[1][i] and matrix_result[2][i]):
            flag_bingo = True
        # check yoko
        if (matrix_result[i][0] and matrix_result[i][1] and matrix_result[i][2]):
            flag_bingo = True
    
    # check naname
    if (matrix_result[0][0] and matrix_result[1][1] and matrix_result[2][2]):
        flag_bingo = True
    elif (matrix_result[0][2] and matrix_result[1][1] and matrix_result[2][0]):
        flag_bingo = True
    
    if flag_bingo: return "Yes"
    else         : return "No"
    

if __name__ == "__main__":

    answer = main(A, N, lst_b)
    print(answer)
    

Measured memory_bytes: 3064
/*
  標準偏差(n人の学生を含むクラスでプログラミングの試験を行った。
          それぞれの得点をs1, s2 ... snとしたときの、
	  標準偏差を求めるプログラム)
  2018/03/09
*/

#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int main(void){
  int *s;
  int n;
  double sum,a,d,std;/*sum:合計値、a:平均値、d:分散、std:標準偏差*/
  int i;

  while(1){
    scanf("%d",&n);
    if(n == 0)
      break;
    
    s = (int *)calloc(n,sizeof(int));
    sum=0;
    a=0;
    for(i=0;i<n;i++){
      scanf("%d",(s+i));
      sum += (double)*(s+i);
    }
    a = sum/(double)n;
    
    sum=0;
    for(i=0;i<n;i++)
      sum += pow((double)*(s+i)-a,2);
    d=sum/(double)n;
    std = sqrt(d);
    printf("%f\n",std);
  }
  return 0;
}


Measured memory_bytes: 2108
while true

a, op, b = gets.split.map(&:to_s)

    case op
    when "+" then
        puts a.to_i + b.to_i
    when "-" then
        puts a.to_i - b.to_i
    when "*" then
        puts a.to_i * b.to_i
    when "/" then
        puts a.to_i / b.to_i
    when "?" then
        break
    else
        break
    end
end

Measured memory_bytes: 8668
#include <stdio.h>

int main(){
    int i, j, h, w;
    char c[110][110];
    scanf("%d %d", &h, &w);
    for(i = 0; i < h; i++){
        scanf("%s", c[i]);
        // getchar();
        // for(j = 0; j < w; j++){
        //     scanf("%c", &c[i][j]);
        // }
    }
    for(i = -1; i <= h; i++){
        for(j = -1; j <= w; j++){
            if(i == -1 || i == h || j == -1 || j == w){
                printf("#");
            }else{
                printf("%c", c[i][j]);
            }
        }
        printf("\n");
        getchar();
    }
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>          
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
#define mk_p(a,b)	make_pair((a),(b))
#define fixed(n) fixed<<setprecision((n))
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr long long MOD = 1000000007;

int gcd(int a,int b){return b ? gcd(b,a%b) : a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	int sum = 0;
	int x = n;
	while(n){
		sum += n % 10;
		n /= 10;
	}
	if(x % sum == 0) cout << "Yes\n";
	else cout << "No\n";
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;

#define rep(i,N) for(int i=0;i<(int)(N);++i)
#define rrep(i,N) for(int i=(int)(N)-1;i>=0;--i)
#define debug(x) cout<<#x<<"="<<x<<endl;
constexpr ll MOD=1000000007;
constexpr ll INF=1LL<<60;
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;}
template<typename T> void fail(T v){cout << v << endl;exit(0);}
//template end

void solve(){
    int N;
    cin>>N;
    while(N-->0){
        string s;
        cin>>s;
        map<string,int> mp;
        mp[s]++;
        for(int i=0;i<s.size();i++){
            string a=s.substr(0,i),b=s.substr(i);
            mp[a+b]++;
            mp[b+a]++;
            reverse(a.begin(),a.end());
            mp[a+b]++;
            mp[b+a]++;
            reverse(b.begin(),b.end());
            mp[a+b]++;
            mp[b+a]++;
            reverse(a.begin(),a.end());
            mp[a+b]++;
            mp[b+a]++;
        }
        cout<<mp.size()<<endl;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    solve();
    return 0;
}


Measured memory_bytes: 3296
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;
int main()
{
    string s; cin>>s;
    int ans=0;
    int tmp=0;
    for(int i=0;i<s.size();++i){
        char c=s[i];
        if(c=='A'||c=='T'||c=='G'||c=='C'){
            ++tmp;
        }
        else{
            tmp=0;
        }
        ans=max(ans,tmp);
    }
    
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, K: int, S: str):

    seq = []
    ans = 1
    for i in range(N-1):
        if S[i] == S[i+1]:
            ans += 1
        else:
            seq.append(ans)
            ans = 1
    # 最後
    if S[N-2] == S[N-1]:
        seq.append(ans)
    else:
        seq.append(1)
    # print(seq)

    if len(seq) - 2*K <= 1:
        print(N-1)
    else:
        ans = 0
        for c in seq:
            ans += c-1
        print(ans+2*K)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, K, S)


if __name__ == '__main__':
    main()


Measured memory_bytes: 4212
n = int(input())
mod = 10**9+7

dp = [[[[0 for i in range(4)] for i in range(4)] for i in range(4)] for i in range(n+1)]

for i in range(4):
  for j in range(4):
    for k in range(4):
      dp[0][i][j][k] = 1

for i in range(4):
  for j in range(4):
    for m in range(4):
      if i==2 and j==0 and m==1:
        dp[0][m][i][j] = 0
      elif i==0 and j==2 and m==1:
        dp[0][m][i][j] = 0
      elif i==1 and j==0 and m==2:
        dp[0][m][i][j] = 0
      elif i==2 and k==0 and m==1:
        dp[0][m][i][j] = 0
      elif j==2 and k==0 and m==1:
        dp[0][m][i][j] = 0

# A=0, C=1, G=2, T=3
for l in range(1, n+1):
  for m in range(4):
    for i in range(4):
      for j in range(4):
        for k in range(4):
          if i==2 and j==0 and m==1:
            dp[l][m][i][j] = 0
          elif i==0 and j==2 and m==1:
            dp[l][m][i][j] = 0
          elif i==1 and j==0 and m==2:
            dp[l][m][i][j] = 0
          elif i==2 and k==0 and m==1:
            dp[l][m][i][j] = 0
          elif j==2 and k==0 and m==1:
            dp[l][m][i][j] = 0
          else:
            dp[l][m][i][j] += dp[l-1][i][j][k]%mod

print(dp[n][3][3][3]%mod)

Measured memory_bytes: 3444
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e6;
const ll MAX_N = 1e9;

int main() {
    ll n, m;
    cin >> n >> m;

    vl a(n);
    rep(i, n) {
        cin >> a[i];
    }
    sort(rall(a));
    
    ll left = 0;
    ll right = INF;
    while(right - left > 1) {
        ll mid = (left + right)/2;
        ll x = mid;
        ll u = 0;
        ll j = n-1;
        rep(i, n) {
            while(j >= 0 && a[i] + a[j] < x) {
                j--;
            }
            u += j+1;
        }
        if(u >= m) {
            left = mid;
        }
        else {
            right = mid;
        }
    }

    vl rui(n+1);
    rep(i, n) {
        rui[i+1] = rui[i] + a[i];
    }

    ll c = 0;
    ll ans = 0;
    ll j = n-1;
    rep(i, n) {
        while(j >= 0 && a[i] + a[j] < left) {
            j--;
        }
        ans += (j+1)*a[i] + rui[j+1];
        c += j+1;
    }

    ans -= (c - m)*left;

    out(ans);
    re0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
//using lint = long long;

struct P
{
    int x,y;

    bool operator<(const P &a)const{
        if(x!=a.x)
              return x>a.x;
        return y>a.y;
    }

};

vector<int> v[111111],v1;

//bitset<4001000> b;
int i,n,d,m,k,a,b,c,h;

int o[111];
long long l[111][111115];
int j[111];
int e[111111];


//int dx[10]={2,2,-2,-2,1,1,-1,-1},dy[10]={1,-1,1,-1,2,-2,2,-2};

int dx[10]={0,1,0,-1,1,1,-1,-1},dy[10]={1,0,-1,0,1,-1,1,-1},dz[10]={0,0,0,0,1,-1};
long long mod=1000000007,mod2=1000000009,mod3=2017;
long long x,z,y;
double pi=3.14159265;
P u[311111];
stack<int> s;
//set<int> s[222][22];
//priority_queue<P> q;
queue<int> q;
//2147483647
//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
//map<int,int> p;
/*
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
unordered_map<long long, int, custom_hash> safe_map;
*/
//list<int> l;

string r;
//char r[2];
//deque<int> de;
//srand((int)time(NULL));
/*bool as(P a,P b)
{
    if(a.x!=b.x)
    return a.x<b.x;
    return a.y<b.y;
}*/



bool as(P a,P b)
{
    if(a.x!=b.x)
        return a.x<b.x;
    return a.y<b.y;

}

long long f(int n,int m)
{
    if(m<=0) return 0;
    if(n>a) return 987654321987654321;
    if(l[n][m]>=0) return l[n][m];
    return l[n][m]=min(f(n+1,m),f(n+1,m-j[n])+o[n]);
}

int main()
{
    memset(l,-1,sizeof(l));
    scanf("%d %d",&a,&b);
    for(int t=1;t<=a;t++)
        scanf("%d %d",&o[t],&j[t]);
    for(int t=a*1000;;t--)
        if(f(1,t)<=b)
    {
        printf("%d",t);
        return 0;
    }
    //printf("%lld",f(1,0));
}





Measured memory_bytes: 100096
n = gets.to_i
a = Array.new(n)
for i in 0..(n-1)
  a[i] = gets.to_i
end

maxn = a[0]
nextn = 0

for i in 1..(n-1)
  nextn = a[i] if nextn < a[i]
  if nextn > maxn
    tmp = maxn
    maxn = nextn
    nextn = tmp
  end
end

for i in 0..(n-1)
  if a[i] == maxn
    puts nextn
  else
    puts maxn
  end
end   

Measured memory_bytes: 4988
#include <iostream>
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#include <algorithm>
#include <bits/stdc++.h>
#define MOD 1000000000000000000
#define ll long long
#define mm(arr) memset(arr, 1, sizeof(arr))
#define scanArray(a,n) for(ll i = 0; i < n; i++){cin >> a[i];}
using namespace std;
int main(){
    FAST
     int n,h; cin >> n >> h;
     int a[n];
     int cnt;
     scanArray(a,n);
     for(int i=0; i<n; i++){
        if(a[i]>=h){
            cnt++;
        }
     }
     cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3916
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
#define INF 1ll<<59
 
bool ok(vector<ll> &v,ll x){
  ll s=v.size();
  ll i,j;
  for(i=0;i<s;i++) x+=v[i];
  if(x<0) return 0;
  if(x%2!=0) return 0;
  x=x/2;
  vector<bool> b(10101,0);
  b[0]=1;
  for(i=0;i<s;i++){
    for(j=10100;j>=v[i];j--){
      b[j]=b[j]||b[j-v[i]];
    }
  }
  return b[x];
}


int main(){
  ll i,j;
  string s;
  cin>>s;
  s+='T';
  ll x,y;
  cin>>x>>y;
  vector<ll> v1,v2;
  ll c=0;
  ll stage=0;
  ll hajime=-1;
  for(i=0;i<s.size();i++){
    if(s[i]=='F') c++;
    else {
      if(hajime<0) hajime=c;
      else {
        if(stage==0) v1.pb(c);
        else v2.pb(c);
      }
      c=0;
      stage=1-stage;
    }
  }
  
  if(ok(v1,x-hajime)&&ok(v2,y)) cout<<"Yes"<<endl;
  else cout<<"No"<<endl; 
  
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#include <functional>
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;
ll dp[MAX_N];

int main(){
    int n,m;
    cin>>n>>m;
    vector<int> a(m);
    int num[]={0,2,5,5,4,5,6,3,7,6};
    for(int i=0;i<m;i++) cin>>a[i];
    sort(a.begin(),a.end(),greater<int>());
    //cout<<a[0]<<a[1]<<a[2]<<a[3]<<endl;
    for(int i=0;i<=n;i++){
        dp[i]=-INF;
    }
    dp[0]=0;
    for(int i=1;i<=n;i++){
        for(int j=0;j<m;j++){
            if(i-num[a[j]]>=0) dp[i]=max(dp[i],dp[i-num[a[j]]]+1);
        }
    }
    //cout<<dp[n]<<endl;
    string s;
    while(n>0){
        for(int j=0;j<m;j++){
            if(n-num[a[j]]>=0){
                if(dp[n]==dp[n-num[a[j]]]+1){
                    s+=to_string(a[j]);
                    n-=num[a[j]];
                    break;
                }    
            }
        }
    }
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 384
//B
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	int k;
	string s;
	cin >> k >> s;
	if(s.size() <= k)cout << s;
	else{
		for(int i = 0;i < k;i++)cout << s[i];
		cout << "...";
	} 
	return 0;
}


Measured memory_bytes: 3624
import java.util.Scanner;

/**
 * Balanced Path
 */
public class Main {

    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            int H = sc.nextInt();
            int W = sc.nextInt();
            int[][] A = new int[H][W];
            int[][] B = new int[H][W];
            for (int i = 0; i < H; i++) {
                for (int j = 0; j < W; j++) {
                    A[i][j] = sc.nextInt();
                }
            }
            for (int i = 0; i < H; i++) {
                for (int j = 0; j < W; j++) {
                    B[i][j] = sc.nextInt();
                }
            }

            int K = (H + W) * 80;
            boolean[][][] x = new boolean[H][W][K];

            x[0][0][Math.abs(A[0][0] - B[0][0])] = true;

            for (int d = 0; d <= H + W - 2; d++) {
                for (int i = 0; i <= d; i++) {
                    int j = d - i;

                    if (i > H - 1 || j > W - 1) {
                        continue;
                    }

                    for (int k = 0; k < K; k++) {
                        if (!x[i][j][k]) {
                            continue;
                        }

                        if (i < H - 1) {
                            x[i + 1][j][Math.abs(k + A[i + 1][j] - B[i + 1][j])] = true;
                            x[i + 1][j][Math.abs(k - A[i + 1][j] + B[i + 1][j])] = true;
                        }
                        if (j < W - 1) {
                            x[i][j + 1][Math.abs(k + A[i][j + 1] - B[i][j + 1])] = true;
                            x[i][j + 1][Math.abs(k - A[i][j + 1] + B[i][j + 1])] = true;
                        }
                    }
                }
            }

            int ans = -1;
            for (int k = 0; k < K; k++) {
                if (x[H - 1][W - 1][k]) {
                    ans = k;
                    break;
                }
            }

            System.out.println(ans);
        }
    }

}


Measured memory_bytes: 119180
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

from collections import Counter

S = list(input())
T = list(input())

SC = Counter(S)
TC = Counter(T)

lstS = []
for s in SC:
    lstS.append(SC[s])

lstT = []
for t in TC:
    lstT.append(TC[t])

lstS.sort()
lstT.sort()

if lstS == lstT:
    print ('Yes')
else:
    print ('No')

Measured memory_bytes: 6832
#include <vector>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <algorithm>

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

#define pb push_back

const int INF = 100100100;
const int MOD = (int)1e9 + 7;

using ll = long long;

using namespace std;

int main(){
  string s,t,ans;
  int f;

  cin >> s >> t;


  reverse( s.begin(), s.end());
  reverse( t.begin(), t.end());
  REP( i, s.size()){
    ans = s;
    f = 0;
    REP( j, t.size()){
      if( s[i+j] == t[j] || s[i+j] == '?'){
        ans[i+j] = t[j];
        if( j == t.size()-1){
          f = 1;
        }
      }else{
        break;
      }
    }
    if( f == 1){
      break;
    }
  }

  reverse( ans.begin(), ans.end());
  if( f == 0){
    cout << "UNRESTORABLE" << endl;
    return 0;
  }

  REP( i, ans.size()){
   if( ans[i] == '?'){
     ans[i] = 'a';
   }
  }

  cout << ans << endl;
}

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

using namespace std;

int main() {
  int e;
  while(cin >> e, e != 0) {
    int min = 4000000;
    for(int z = 0; z <= 100 ;z++)
      for(int y = 0; y <= 1000;y++) {
	int x = e - y*y - z*z*z;
	if(x >= 0 && x + y + z < min)
	  min = x + y + z;
      }
    cout << min << endl;
  }
    
}

Measured memory_bytes: 1160
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
using lll = long long;
using ull = unsigned long long;
using namespace std;



int main(){
  lll ii,jj,kk;
  lll a,b,c;
  cin >> a >> b;
  c = a+b;
  if(c%2==0){
    cout << c/2 << endl;
  }
  else{
    cout << "IMPOSSIBLE" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
//B - Echo
#include <stdio.h>

int main(void){
    int n, i;
    char s[100], t[100];
    scanf("%d", &n);
    if(n%2==1){
        puts("No");
        return 0;    
    }
    scanf("%s", s);
    for(i=0; i<n/2; i++){
        if(s[i] != s[(n/2)+i]){
            puts("No");
            return 0;
        }
    }
    puts("Yes");
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define xrep(i, a, b) for (int i = int(a); i < int(b); ++i)
int main() {
    int N, M, a;
    int A = 0;
    cin >> N >> M;
    rep(i, M) {
        cin >> a;
        A += a;
    }
    int delta = N - A;
    if(delta < 0) {
        cout << -1 << endl;
    } else {
        cout << delta << endl;
    }



    return 0;
}

Measured memory_bytes: 3560
import math
import collections

def prime_factor(n):
    ass = []
    for i in range(2,int(n**0.5)+1):
        while n % i==0:
            ass.append(i)
            n = n//i
    if n != 1:
        ass.append(n)
    return ass
    
N, P = map(int, input().split())

factors = prime_factor(P)
c = collections.Counter(factors)

count = 1

for i in c.keys():
    sho = c[i]//N
    count *= pow(i, sho)
    
print(count)

Measured memory_bytes: 3444
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int H = sc.nextInt();
            int W = sc.nextInt();
            if(H==0 || W==0){
                break;
            }
            for(int i=0;i<H;i++){
                for(int j=0;j<W;j++){
                    if((i+j)%2==0){
                        System.out.printf("#");
                    }else{
                        System.out.printf(".");
                    }
                    }
                System.out.printf("\n");
            }
            System.out.printf("\n");
        }
    }
}



Measured memory_bytes: 62808
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
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; }
const long long MOD = 1000000007;
const long long INF = 0x3f3f3f3f;
using namespace std;
typedef long long ll;
map<int, int> mp;
using Graph = vector<vector<int>>; 
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s; cin >> s;
	int size = s.size();
	int ans = 0;
	int tmp = 0;
	for (int i = 0; i < (1 << size); i++) {
		tmp = 0;
		for (int j = 1; j <= size; j++) {
			if ((i >> j) & 1) {
				ans += (ll)stoll(s.substr(tmp, j - tmp));
				tmp = j;
			}
		}
		if (tmp != size)ans += (ll)stoll(s.substr(tmp, size - tmp));
	}
	cout << ans / 2 << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split(" ")))
l = len(a)
f = False
c = 0
while True:
    for i in range(0, l):
        if a[i] % 2 == 0:
            a[i] /= 2
        else:
            f = True
    if f is not True:
        c += 1
    else:
        break
print(str(c))


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

#define REP(i, n) for (int i = 0; i < (int)(n); ++i)

struct Edge {
    int dst;
};

void dfs(const vector<vector<Edge>>& edges, vector<bool>& visited, int v) {
    for (auto e : edges[v]) {
        if (!visited[e.dst]) {
            visited[e.dst] = true;
            dfs(edges, visited, e.dst);
        }
    }
}

int main() {
    int N, M;
    while (cin >> N >> M) {
        vector<vector<Edge>> edges(N);
        REP(i, M) {
            int X, Y, Z; cin >> X >> Y >> Z; --X; --Y;
            edges[X].push_back({ Y });
            edges[Y].push_back({ X });
        }

        int answer = 0;
        vector<bool> visited(N);
        REP(v, N) {
            if (!visited[v]) {
                visited[v] = true;
                dfs(edges, visited, v);
                ++answer;
            }
        }

        cout << answer << endl;
    }
}

Measured memory_bytes: 10368
import Data.List
import Data.Maybe

main :: IO ()
main = do
  [n,m] <- map read.words <$> getLine
  let divisors = [ i | i <- [1..(floor $ sqrt $ fromIntegral m)], m`mod`i == 0 ]
  if Nothing /= find (n<=) divisors then print $ (m`div`) $ fromJust $ find (n<=) divisors
    else print $ (m`div`) $ fromJust $ find (n<=) (reverse $ map (m`div`) divisors)

Measured memory_bytes: 1020
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;


namespace SolutionCS
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            int[] v = new int[N];
            int max0 = int.MinValue;
            int max1 = int.MinValue;

            for (int i = 0; i < N; i++)
            {
                v[i] = int.Parse(Console.ReadLine());

                if ( v[i] >= max0)
                {
                    max1 = max0;
                    max0 = v[i];
                }
                else if ( v[i] >= max1)
                {
                    max1 = v[i];
                }
            }

            for (int i = 0; i < N; i++)
            {
                if ( v[i] == max0)
                {
                    Console.WriteLine(max1);
                }
                else
                {
                    Console.WriteLine(max0);
                }
            }
        }
    }
}


Measured memory_bytes: 18608
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mod 1000000007
#define all(v)  v.begin(),v.end()
#define pb push_back
#define size(v)  (int) v.size()
#define fast ios_base:: sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
ll power_mod(ll a,ll x){if(x==0) return 1;ll y=power_mod(a,x/2);ll ans=(y*y)%mod; if(x%2) ans=(ans*a)%mod;return ans;}
ll inv(ll a){return power_mod(a,mod-2);}    
ll power(ll a, ll x){ if(x==0) return 1; ll y= power(a,x/2); ll ans=(y*y); if(x%2) ans*=a; return ans;}

const int N = 500005;

int bit[N];
vector<pair<pair<int,int>,int>> queries;
int ans[N];
int vis[N] = {};

void update(int idx, int val) {
    for(;idx < N; idx += (idx&(-idx))) {
        bit[idx] += val;
    }
}
int get(int idx) {
    int res = 0;

    for(;idx > 0; idx -= (idx&(-idx))) {
        res += bit[idx];
    }
    return res;
}

int main() {
    int n,q;
    cin >> n >> q;
    int a[n+1];
    for(int i = 1; i <= n; i++) cin >> a[i];
    for(int i = 1; i <= q; i++) {
        int l,r;
        cin >> l >> r;
        queries.pb({{l,r},i});
    }
    int query = 1;
    sort(all(queries),[&](pair<pair<int,int>,int> a,pair<pair<int,int>,int> b){
        return(a.first.second < b.first.second);
    });

    for(int i = 1; i <= n; i++) {
        if(vis[a[i]] != 0) {
            update(vis[a[i]],-1);
        }
        vis[a[i]] = i;
        update(i,1);

        while(query <= q and queries[query-1].first.second == i) {
            int l = queries[query-1].first.first;
            int r = queries[query-1].first.second;
            int idx = queries[query-1].second;
            ans[idx] = get(r) - get(l-1);
            query++;
        }
    
    }
    for(int i = 1; i <= q; i++)  cout << ans[i] << endl;
    
}

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

ans = 0
for i in range(n):
    if a[i] - b[i] >= 0:
        ans += b[i]
    else:
        if a[i+1] > b[i] - a[i]:
            ans += b[i]
            a[i+1] -= b[i] - a[i]
        else:
            ans += a[i+1] + a[i]
            a[i+1] = 0
print(ans)

Measured memory_bytes: 18476
import java.io.*;
import java.util.*;
import java.math.*;
class Main
{ 
	public static int M = 1000000007;
    public static void main(String[] args)throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        String s = br.readLine();	
        int n=0;
        for(int i=0;i<s.length();i++)
        {
            if(s.charAt(i)=='+')
                n++;
            else
                n--;
        }
        out.println(n);
        out.flush();
    }
    /** Loops
    *	i: for(int i=0;i<n;i++)
    *	j: for(int j=0;j<n;j++)
    *	k: for(int k=0;k<n;k++)

    *	ArrayList<Integer> arr1 = new ArrayList<>();
    
    * 	HashMap
    *	HashMap<Integer, Integer> hm = new HashMap<>();
    * 	for (Map.Entry<String,String> entry : hm.entrySet()) 
    		out.println(entry.getValue());
    
    *	Count frequencies
    	for(int i=0;i<n;i++)
        {
            Integer c = hm.get(Integer.parseInt(s[i]));
            if(c==null)
                hm.put(Integer.parseInt(s[i]),1);
            else
                hm.put(Integer.parseInt(s[i]),++c);
        }
	**/		
    public static long modularExpo(long x,long n,int M)
	{
		long result=1;
		while(n>0)
		{
		    if(n%2==1)
		        result=(result*x)%M;
		    x=(x*x)%M;
		    n=n/2;
		}	
		return result;												
	}
	//FLT, only when a and M are co-prime
	public static long modInverse(int a,int M)
	{
		long g = gcd(a,M);
		if(g!=1)
			return -1;
	    return modularExpo(a,M-2,M);
	}
	public static long gcd(int a, int b) 
	{
	    if(b==0)
	        return a;
	    else
	        return gcd(b, a % b);
	}
}

Measured memory_bytes: 22612
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef vector<int> vec;
int main(){
  long a,b,c,d; cin>>a>>b>>c>>d;
  if(b>0&&d>0)cout<<max(a*c,b*d);
  else if(a<0&&c<0)cout<<a*c;
  else cout<<max(a*d,b*c);

}

Measured memory_bytes: 3568
#include <bits/stdc++.h> // Tomasz Nowak
using namespace std;     // XIII LO Szczecin
using LL = long long;    // Poland
#define FOR(i, l, r) for(int i = (l); i <= (r); ++i)
#define REP(i, n) FOR(i, 0, (n) - 1)
template<class T> int size(T &&x) {
	return int(x.size());
}
template<class A, class B> ostream& operator<<(ostream &out, const pair<A, B> &p) {
	return out << '(' << p.first << ", " << p.second << ')';
}
template<class T> auto operator<<(ostream &out, T &&x) -> decltype(x.begin(), out) {
	out << '{';
	for(auto it = x.begin(); it != x.end(); ++it)
		out << *it << (it == prev(x.end()) ? "" : ", ");
	return out << '}';
}
void dump() {}
template<class T, class... Args> void dump(T &&x, Args... args) {
	cerr << x << ";  ";
	dump(args...);
}
#ifdef DEBUG
  struct Nl{~Nl(){cerr << '\n';}};
# define debug(x...) cerr << (strcmp(#x, "") ? #x ":  " : ""), dump(x), Nl(), cerr << ""
#else
# define debug(...) 0 && cerr
#endif
mt19937_64 rng(0);
int rd(int l, int r) {
	return uniform_int_distribution<int>(l, r)(rng);
}
// end of templates

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

	int n;
	LL k;
	cin >> n >> k;
	vector<int> a(n);
	REP(i, n)
		cin >> a[i];
	REP(i, n)
		a.emplace_back(a[i]);
	debug(a);
	vector<int> nxt(2 * n, 2 * n);
	vector<int> last(int(2e5) + 1, -1);
	for(int i = 2 * n - 1; i >= 0; --i) {
		if(last[a[i]] != -1)
			nxt[i] = last[a[i]];
		last[a[i]] = i;
	}
	debug(nxt);

	int lg = 0;
	LL pot2 = 1;
	while(pot2 <= k * n) {
		pot2 *= 2;
		++lg;
	}
	lg += 2;

	vector<vector<pair<int, LL>>> ptr(n, vector<pair<int, LL>>(lg + 1));
	REP(i, n) {
		int layerdelta = (nxt[i] + 1) >= n;
		if(nxt[i] + 1 == 2 * n)
			++layerdelta;
		ptr[i][0] = {(nxt[i] + 1) % n, layerdelta};
	}

	for(int l = 1; l <= lg; ++l)
		REP(i, n) {
			int half = ptr[i][l - 1].first;
			ptr[i][l] = {ptr[half][l - 1].first, ptr[i][l - 1].second + ptr[half][l - 1].second};
		}
	debug(ptr);

	int i = 0;
	LL layer = 1;
	for(int l = lg; l >= 0; --l) {
		LL nxtlayer = layer + ptr[i][l].second;
		if(nxtlayer > k)
			continue;
		i = ptr[i][l].first;
		layer = nxtlayer;
		debug(i, layer);
	}
	debug(i, layer) << "ended jumping";

	vector<bool> inside(int(2e5) + 1, false);
	vector<int> que;
	auto simulate_until_end = [&] {
		while(i < n) {
			if(inside[a[i]]) {
				while(inside[a[i]]) {
					int x = que.back();
					que.pop_back();
					inside[x] = false;
				}
			} else {
				que.emplace_back(a[i]);
				inside[a[i]] = true;
			}
			++i;
		}
	};
	if(layer < k) {
		simulate_until_end();
		i = 0;
		++layer;
	}
	if(layer == k) {
		simulate_until_end();
		i = 0;
		++layer;
	}
	debug(i, layer);

	debug(que);

	for(int x : que)
		cout << x << ' ';
	cout << '\n';
}


Measured memory_bytes: 205168
// C++ program to print all possible
// substrings of a given string
#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <cstring>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

using namespace std;

char str[100000000][6], ct[27];
int cr[27] = {0};


// Function to print all sub strings
int subString(string s, int n, int d)
{
    // Pick starting point in outer loop
    // and lengths of different strings for
    // a given starting point
    int c=0, k=0;
    string sr;
    char ar[5010];
    for (int i = 0; i < n; i++)
    {
        for (int len = 1; len <= d; len++)
        {


            sr = s.substr(i, len);
            strcpy(ar, sr.c_str());
            if(ar[0] == ct[0] || ar[0] == ct[1] || ar[0] == ct[2] || ar[0] == ct[3])
            {
                strcpy(str[c], ar);
                c++;
            }
         //   printf("%d   ", c);
            if (c == 100000000)
            {
           //     printf("  Here \n");
                break;
            }

        }
    }
    return c;
}

void sorting(int n)
{
    char min[5010];
    int a;

    for (int i = 0; i < n - 1; i++)
    {
        a = i;
        strcpy(min, str[i]);

        for (int j = i + 1; j < n; j++)
        {
            if( (strcmp(str[j], min)) < 0)
            {
                strcpy(min, str[j]);
                a = j;
            }
        }
        strcpy(str[a], str[i]);
        strcpy(str[i], min);
    }
}

// Driver program to test above function
int main()
{
    string s;
    cin >> s;
    int d, i, j, k=0, l, p;
    char sry[5010], ch;
    strcpy(sry, s.c_str());
    l = strlen(sry);
    for ( j=0; j<l; j++)
        cr[sry[j]-'a'+1]++;
    for (j=0; j<26; j++)
    {
        if(cr[j] >= 1)
        {
            ct[j] = j + 'a' - 1;
            k++;
        }
        else
            ct[j] = 'z' ;
    }
    int q, w;
    char temp;
    // statements to scan the number of items (n) and the string a[n].

    for (w = 1; w < 26; w++)
    {
        for (q = 0; q < 26 - w; q++)
        {
            if (ct[q] >= ct[q+1])
            {
                temp = ct[q];
                ct[q] = ct[q+1];
                ct[q+1] = temp;
            }
        }
    }

    scanf("%d", &d);
    i = subString(s,s.length(), d);

    sorting(i);

//   printf("Here1[]\n");
    k=0;

    for(j=0; ; j++)
    {
        if (strcmp(str[j], str[j+1]) != 0)
            k++;
        if(k==d)
            break;

    }
    //  printf("Here1\n");
    printf ("%s", str[j]);

    /*  for(p=0; p<i; p++)
          printf("%s\n", str[p]);
          */
    return 0;
}


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

int main() {
  int a,b,c,k;
  cin >> a >> b >> c >> k;
  vector<int> vec = {a,b,c};
  sort(vec.begin(),vec.end());
  a = vec.at(0);
  b = vec.at(1);
  c = vec.at(2);
  cout << a+b+c*pow(2,k) << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int n, x;
vector<int> data(110);
void solve(){
    cin >> n >> x;
    int memo = 10000;
    int sum = 0;
    for(int i = 0; i < n; i++){
        cin >> data.at(i);
        memo = min(memo, data.at(i));
        sum += data.at(i);
    }
    int ans = (x - sum) / memo + n;
    cout << ans << endl;
}
int main(){
    solve();
    return 0;
}


Measured memory_bytes: 256
n,a = (int(i) for i in input().split())
x = [int(i)-a for i in input().split()]
x = [0]+x
y = max(max(x)+a,a)
dp = [[0 for i in range(2*n*y+1)] for i in range(n+1)]
dp[0][n*y] = 1
for i in range(n+1):
	for j in range(2*n*y+1):
		if i>0 and (j-x[i]<0 or j-x[i]>2*n*y): dp[i][j]=dp[i-1][j]
		elif i>0 and 0<=j-x[i]<=2*n*y: dp[i][j]=dp[i-1][j]+dp[i-1][j-x[i]]
		else: pass
print(dp[n][n*y]-1)

Measured memory_bytes: 5740
#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.precision(20);
    map<char, char> mp;
    mp['A'] = 'T';
    mp['T'] = 'A';
    mp['C'] = 'G';
    mp['G'] = 'C';
    char ch; cin >> ch;
    cout << mp[ch];
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int n,q,i,key,j,k=0;
  scanf("%d",&n);
  int S[n];
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  int T[q];
  for(i=0;i<q;i++){
    scanf("%d",&T[i]);
  }
  for(j=0;j<q;j++){
    i=0;
    while(1){
      if(T[j]==S[i]){
        k++;
        break;
      }
      if(i==n){
        break;
      }
      i++;
    }
  }
  printf("%d\n",k);
  return 0;
}



Measured memory_bytes: 2144
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <bitset>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <functional>
#include <algorithm>
#include <iterator>
using namespace std;

#define dfor(i,a,b) for(int i=(a);i<(b);++i)
#define drfor(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define drep(i,n) dfor(i,0,n)
#define drrep(i,n) drfor (i,n,0)
#define dump(x)  cout << #x << " = " << (x) << endl;
const double EPS = 1e-10;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) { }
	bool unite(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool same(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

struct edge { int to, cost; };
typedef pair<unsigned long long, unsigned long long> P;
int n;
unsigned long long dyen[100005],dsnuuk[100005];
vector<edge> yen[100005],snuuk[100005];

void dijk(int s, vector<edge> G[], unsigned long long d[]) {
	priority_queue< P, vector<P>, greater<P> > que;
	fill(d, d + n+2, 1000000000000000);
	d[s] = 0;
	que.push(P(0, s));

	while (!que.empty()) {
		P p = que.top();que.pop();
		int v = p.second;
		if (d[v] < p.first) continue;
		for (int i = 0;i < G[v].size();i++) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

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

	int m, s, t,u,v,a,b;
	cin >> n >> m >> s >> t;
	for (int i = 0;i < m;i++) {
		cin >> u >> v >> a >> b;
		yen[u].push_back(edge{ v,a });
		yen[v].push_back(edge{ u,a });
		snuuk[u].push_back(edge{ v,b });
		snuuk[v].push_back(edge{ u,b });
	}
	dijk(s, yen,dyen);
	dijk(t, snuuk,dsnuuk);
	unsigned long long result[100005];
	result[n] = dyen[n] + dsnuuk[n];
	for (int i = n - 1;i >=1;i--) {
		if (dyen[i] + dsnuuk[i] < result[i + 1]) result[i] = dyen[i] + dsnuuk[i];
		else result[i] = result[i + 1];
	}
	for (int i = 1;i <= n;i++) cout << 1000000000000000 - result[i] << "\n";
	return 0;
}


Measured memory_bytes: 16252
use std::io::stdin;

fn main() {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    let k: usize = s.trim().parse().unwrap();
    s.clear();
    stdin().read_line(&mut s).ok();
    s.pop();
    println!(
        "{}",
        if s.len() <= k {
            s
        } else {
            format!("{}...", &s[..k])
        }
    );
}


Measured memory_bytes: 2092
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr int MAX = 1000000;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    
    sort(a.begin(), a.end());
    map<int, int> ok;
    for (int i = 0; i < n - 1; i++) {
        if (a[i] == a[i+1])
            ok[a[i]] = 1;
    }
    
    map<int, int> mp;
    for (int i = 0; i < n; i++) {
        int num = a[i];
        if(mp[num] == 0) {
            if (ok[num] == 1)
                mp[num] = 1;
            while(1) {
                num += a[i];
                if (num > MAX)
                    break;
                mp[num] = 1;
            }
        }
    }
    
    int count = 0;
    for (int i = 0; i < n; i++)
        if (ok[a[i]] == 0 && mp[a[i]] == 0)
            count++;
    
    cout << count << endl;
    
    return 0;
}


Measured memory_bytes: 60104
object Main {
  def main(args: Array[String]): Unit = {
    val lines = io.Source.stdin.getLines().toArray
    println(C.solve(lines))
  }
}


object C {
  def solve(input: Array[String]) = {
    val N = input(0).toDouble
    val weights = input.drop(0).toList.map(_.toLong)
    val bottleNeck = weights.min
    val bottleNeckWeight = (N / bottleNeck).ceil.toLong
    4 + bottleNeckWeight
  }
}

Measured memory_bytes: 27308
n = int(input())
a = list(map(int, input().split()))
cash = 1000
bill = 0
table = []

for i in range(n-1):
    if a[i] > a[i+1]:
        table.append(False)
    elif a[i] == a[i+1]:
        table.append("-")
    else:
        table.append(True)
# print(table)
if table[0] == True:
    bill, cash = divmod(cash, a[0])
# print(cash, bill)
i = 0
while i < n-1:
    if table[i] == True:
        while not table[i] == False:
            i += 1
            if i == n-1:
                break
        cash += bill * a[i]
        bill = 0
        # print(cash, bill)
    else:
        while not table[i] == True:
            i += 1
            if i == n-1:
                break
        bill, cash = divmod(cash, a[i])
        # print(cash, bill)
cash += bill * a[-1]
print(cash)


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;

void solve()
{
	int n, u, v;
	cin >> n >> u >> v;
	u--; v--;

	vector< vector<int> > node(n, vector<int>() );
	vector<int> dist_u(n, -1);
	vector<int> dist_v(n, -1);

	int a, b;
	for(int i = 0; i < n - 1; ++i)
	{
		cin >> a >> b;
		a--; b--;
		node[a].emplace_back(b);
		node[b].emplace_back(a);
	}

	queue<int> que;
	que.push(u);

	dist_u[u] = 0;

	// ゲームか必ず終了することが証明できる
	// つまり閉路はない
	// BFSで経路長探索
	while(!que.empty())
	{
		int now = que.front();
		que.pop();
		for(const auto& next : node[now])
		{
			if (dist_u[next] == -1)
			{
				dist_u[next] = dist_u[now] + 1;
				que.push(next);
			}
		}
	}

	// queはemptyだから使いまわせる...けれどこれは関数化したい
	que.push(v);
	dist_v[v] = 0;

	while(!que.empty())
	{
		int now = que.front();
		que.pop();
		for(const auto& next : node[now])
		{
			if (dist_v[next] == -1)
			{
				dist_v[next] = dist_v[now] + 1;
				que.push(next);
			}
		}
	}

	int ans = -1;
	for(int i = 0; i < n; ++i)
	{
        if(dist_u[i] < dist_v[i])
		{
	        ans = max(ans, dist_v[i]);
		}
	}

	cout << ans - 1;
}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 6656
#include <stdio.h>

int main() {
    int a,b;
    scanf("%d %d",&a,&b);
    if(a<b){
    printf("a < b\n");
    }else if(a>b){
        printf("a > b\n");
    }else{
        printf("a == b\n");
    }
    return 0;
}

Measured memory_bytes: 1756
N = int(input())
xy_list = []
ans = []
 
for i in range(N):
    x,y = map(int,input().split())
    xy_list.append([x,y])

if N==1:
    print(1)
    exit(0)
xy_list.sort(key=lambda x:x[1]) #yの値でソート
xy_list.sort(key=lambda x:x[0]) #xの値でソート
#print(xy_list)
#差をすべて調べる
for i in range(N):
  for j in range(N):
    if( i==j ):     #xとyの重複はなし
      continue
    t = (xy_list[i][0]-xy_list[j][0],xy_list[i][1]-xy_list[j][1])
    ans.append(t)
    #print(ans)  
#差の種類ごとの個数を調べる
res = [ans.count(e) for e in set(ans)]
#Nから一番多かった差の個数を引いたものが答え
print(N-max(res))

Measured memory_bytes: 3444
S = input()
ans = 0
if S[1] != "R" and "R" in S:
    ans = 1
elif S[1] == "R":
    if S[0] == "R" and S[2] == "R":
        ans = 3
    elif S[0] == "R" or S[2] == "R":
        ans = 2
    else:
        ans = 1    
elif "R" in S:
    ans = 1
print(ans)


Measured memory_bytes: 9104
using System;using System.Linq;namespace AOJ_console{class _1_2{static void Main(){Console.WriteLine(Enumerable.Range(1, 1).Select(x=>Console.ReadLine().Split(' ')).Select(x=>x[0]==x[1]?"a == b":(int.Parse(x[0])>int.Parse(x[1])?"a > b":"a < b")).First().ToString());}}}

Measured memory_bytes: 9260
S = input()
N = len(S)
mod = 10**9+7
numofA = 0
numofAB = 0
numofABC = 0
numofquestion = 1
for i in range(N):
    if S[i] == "?":
        numofABC = (numofABC*3+numofAB) % mod
        numofAB = (numofAB*3+numofA) % mod
        numofA = (numofquestion + numofA*3) % mod
        numofquestion = (numofquestion * 3) % mod
    elif S[i] == "C":
        numofABC = (numofAB+numofABC) % mod
    elif S[i] == "B":
        numofAB = (numofAB + numofA) % mod
    else:
        numofA = (numofquestion + numofA) % mod
print(numofABC)


Measured memory_bytes: 3188
import java.util.Scanner;


public class Main
{
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		
		double x=0, y=0;
		int angle = 90;
		for(;;)
		{
			String s = scanner.next();
			String[] str = s.split(",");
			
			int d = Integer.parseInt(str[0]);
			int a = Integer.parseInt(str[1]);
			if(d==0 && a==0)
			{
				break;
			}
			
			double rad = Math.toRadians(angle);
			x -= d * Math.cos(rad);
			y += d * Math.sin(rad);
			
			angle += a;
		}
		
		System.out.println((int)x);
		System.out.println((int)y);
	}
}

Measured memory_bytes: 26144
/**
     **author : _KMS_
     **created : 07-03-2020
**/
#include<bits/stdc++.h>
using namespace std;
const long long M =1e5+100,MOD=2e9;
typedef long long ll;
bool prime[M+100];
int dp[50][M];
int arr[100];
set<int>st;
void precal()
{
      arr[0]=1;
      arr[1]=6;
      arr[2]=9;
      st.insert(1);
      int j=3;
     for(int i=1;i<=2;i++) 
     {
           int p=2;
           st.insert(arr[i]);
           while(1)
           {
                 int c=arr[i];
                 int d=(int)(pow(c,p)+0.5);
                // cout<<arr[i]<<" "<<p<<" "<<d<<endl;
                 if(d<=100000)st.insert(d);
                 else break;
                 p++;
                 j++;
                
           }
     }
    // sort(arr,arr+j);
    //for(auto x : st)cout<<x<<" ";
    
}
int main() {
      
   ios::sync_with_stdio(false);
   cin.tie(0);
   precal();
   int i=1;
   arr[0]=0;
   for(auto x : st)
   {
         arr[i]=x;
         i++;
         
   }
   int n;
   cin>>n;
   for(int j=0;j<=n;j++)dp[0][j]=10000000;
   for(int j=1;j<i;j++)
   {
        // cout<<arr[j]<<endl;
         for(int k=1;k<=n;k++)
         {
               if(arr[j]<=k)
               {
                     dp[j][k]=min((1+dp[j][k-arr[j]]),dp[j-1][k]);
               }
               else
               {
                     dp[j][k]=dp[j-1][k];
               }
         }
   }
   cout<<dp[i-1][n]<<"\n";
   
   return 0;
}


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

// @author: pashka

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

    int k, n;
    cin >> k >> n;
    vector<int> a(n + 1);
    for (int i = 0; i < n; i++) cin >> a[i];
    a[n] = a[0] + k;
    int res = INT_MAX;
    for (int i = 0; i < n; i++) {
        int x = a[i + 1] - a[i];
        res = min(res, k - x);
    }
    cout << res;

    return 0;
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        int[] arr1 = Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray();
        int x = arr1[0];
        int y = arr1[1];
        int min = x * 2;
        int max = x * 4;
        if(y >= min && y <= max && y % 2 == 0)
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }
        



    }
}

Measured memory_bytes: 19012
import itertools

N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))

S = []
for i in range(N):
    S.append(i+1)

a = 0
b = 0
i = 1

for v in itertools.permutations(S, N):
    if list(v) == P:
        a = i
    if  list(v) == Q:
        b = i
    i += 1

print(abs(a-b))

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

#define AS(arr)  (sizeof(arr)/sizeof(arr[0]))
#define ALL(c) (c).begin(),(c).end() 
#define SIZE(a) int((a).size())
#define EACH(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

#define pb push_back
#define mp make_pair

typedef vector<int> VI;
typedef vector<string> VS;
typedef long long LL;

const double EPS = 1e-11;
#define EQ(a,b) (abs(a-b)<EPS)
#define EQ0(x) (abs(x)<EPS)


int main(void){
    string s;
    cin >> s;
    cout << s[0] << s[1] << s[2] << s[3] << " " << s[4] << s[5] << s[6] << s[7] << s[8] << s[9] << s[10] << s[11] << endl;
}


Measured memory_bytes: 256