akhauriyash/Code-Regression huggingface dataset:
N = int(input())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))

def factorial(n):
    if n == 1:
        return n
    else:
        return n*factorial(n-1)

def order(n, list):
    total = 0
    for i in range(1, n):
        for j in range(i, n):
            if list[i-1] <= list[j]:
                list[j] -= 1
            else:
                pass

        total += (list[i-1]-1)*factorial(n-i)
    return total

def main():
    a = order(N, P)
    b = order(N, Q)
    if 0 <= a-b:
        print(a-b)
    else:
        print(-(a-b))

if __name__ == "__main__":
    main()


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

struct BIT
{
  i64 n;
  vector<i64> bit;

  BIT(i64 _n)
  {
    n = _n;
    bit.resize(n);
    fill(bit.begin(), bit.end(), 0);
  }

  void add(i64 idx, i64 x)
  {
    for (i64 i = idx; i <= n; i += i & -i)
      bit[i] += x;
  }

  i64 sum(i64 end)
  {
    i64 ret = 0;
    for (i64 i = end; i >= 1; i -= i & -i)
      ret += bit[i];
    return ret;
  }
};

int main()
{
  i64 n, k;
  cin >> n >> k;
  vector<i64> a(n + 1);
  for (i64 i = 1; i <= n; i++)
  {
    cin >> a[i];
    a[i] += (i ? a[i - 1] : 0LL) - k;
  }
  vector<i64> sorted_a = a;
  sort(sorted_a.begin(), sorted_a.end());
  i64 ans = 0;
  BIT bit(n + 2);
  for (i64 i = n; i >= 0; --i)
  {
    i64 idx = lower_bound(sorted_a.begin(), sorted_a.end(), a[i]) - sorted_a.begin() + 1;
    if (i != n)
      ans += n - i - bit.sum(idx - 1);
    bit.add(idx, 1);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4992
def binarySearch(alist, item):
    first = 0
    last = len(alist) - 1

    while first <= last:
        midpoint = (first + last)//2
        if item < alist[midpoint] and alist[midpoint - 1] < item or midpoint == 0 and item < alist[midpoint]:
            return midpoint
        else:
            if item < alist[midpoint]:
                last = midpoint - 1
            else:
                first = midpoint + 1
    return -1


def load_input():
    n, k = list(map(int, input().split()))
    s = list(input())
    return n, k, s


def main():
    n, k, s = load_input()

    starts = [0]
    ends = []
    for i in range(n):
        if 0 < i and s[i - 1] == '1' and s[i] == '0':
            ends.append(i)

        if 0 < i and s[i - 1] == '0' and s[i] == '1':
            starts.append(i)
    ends.append(n)

    ml = 0
    for start in starts:
        order = k
        if start == 0 and s[0] == '0':
            order -= 1
        i = binarySearch(ends, start)
        if i + order < len(ends):
            end = ends[i + order]
        else:
            end = ends[-1]
        if ml < end - start:
            ml = end - start
    print(ml)


if __name__ == '__main__':
    main()

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n, m;
  cin >> n >> m;
  
  vector<int> a(m), b(m);
  vector<int> c(m);
  for(int i = 0; i < m; i++){
    cin >> a.at(i) >> b.at(i);
    for(int j = 0; j < b.at(i); j++){
      int x;
      cin >> x;
      c.at(i) += (1 << (x - 1));
    }
  }
  
  vector<vector<int>> dp(m + 1, vector<int>((1 << n), 1e9));
  dp[0][0] = 0;
  for(int i = 0; i < m; i++){
    for(int bit = 0; bit < (1 << n); bit++){
      dp[i + 1][bit] = min(dp[i + 1][bit], dp[i][bit]);
      dp[i + 1][bit | c.at(i)] = min(dp[i + 1][bit | c.at(i)], dp[i][bit] + a.at(i));
    }
  }
  
  if(dp[m][(1 << n) - 1] == 1e9) cout << "-1\n";
  else cout << dp[m][(1 << n) - 1] << '\n';
}

Measured memory_bytes: 16384
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int l,i,j,n,k,c;
	long long int x=0,cost;
	long long int a[402];
	long long int pre[402];
	cin>>n;
	long long int dp[402][402];
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		x+=a[i];
		pre[i]=x;
	}

	for(l=1;l<=n;l++)
	{
		for(i=0;i<n-l+1;i++)
		{
		//for(j=i;j<n;j++)
		//{
		//l=j-i+1;
			j=i+l-1;
			if(i==0)
				cost=pre[j];
			else
				cost=pre[j]-pre[i-1];
			
			if(j==i)
				dp[i][j]=0;
			else
			{
				long long int mini=LLONG_MAX;
				for(c=i+1;c<=j;c++)
				{
					if(dp[c][j]+dp[i][c-1]+cost < mini)
						mini=dp[c][j]+dp[i][c-1]+cost;
				}
				dp[i][j]=mini;
			}
		}
	}
	cout<<dp[0][n-1];
return 0;
}




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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;

#define PI (2*acos(0.0))
#define eps 1e-9
#define pb push_back
#define endl "\n"
#define watch(x) cout << (#x) << " is " << (x) << endl;
#define show(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi] << " "; cout << endl;
#define showpair(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi].first << " " << v[fi].second << endl;
#define ff first
#define ss second
#define fu cout << "lol" << endl;
#define precision(n) cout << fixed << setprecision(n);
#define lb lower_bound
#define up upper_bound
#define vscan for(i = 0;i<n;i++){cin>>in; v.pb(in);}
#define all(a) a.begin(), a.end()
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define mem(a,val) memset(a,val,sizeof(a))
#define loop(i,n) for(i = 0; i < n; i++)
#define TC ull T; cin>>T; while(T--)
#define IN(x) {scanf("%d",&x);}
#define LL(x) {scanf("%lld",&x);}
#define CC(x) {scanf("%c",&x);}
#define pfl(x) printf("%d\n",x)
#define pfll(x) printf("%lld\n",x)
#define newl puts("")
#define space printf(" ")
#define MOD 1000000007
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL);


int main()
{
    int i = 0, j = 0, cs = 0, in;
    int n; cin>>n;
    vi v(n);
    for(i = 0; i < n; i++) cin>>v[i];
    int ans = 0;
    for(i = 0; i < n; i++){
        for(j = i+1; j < n; j++){
            for(int k = j + 1; k < n; k++){
                int a = v[i], b = v[j], c = v[k];
                if(a != b && b != c && c != a && (a+b)>c && (b+c)>a && (c+a)>b) ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3624
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    _LI = lambda : [-int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()
    DD = ((1,0),(0,1),(-1,0),(0,-1))

    N = NI()
    X = SI()

    cnt = [0] * (N+1)
    for i in range(1,N+1):
        x = i % bin(i).count('1')
        if x == 0:
            cnt[i] = 1
        else:
            cnt[i] = cnt[x] + 1

    xc = X.count('1')
    xp = 0
    xm = 0
    xpb = 1
    xmb = 1
    for i in range(N-1,-1,-1):
        xp = (xp + int(X[i]) * xpb) % (xc+1)
        if xc > 1:
            xm = (xm + int(X[i]) * xmb) % (xc-1)
            xmb = (xmb * 2) % (xc - 1)
        else:
            xm = 0
            xmb = 0
        xpb = (xpb * 2) % (xc+1)

    for i in range(N):
        if X[i] == '0':
            x = (xp + pow(2,N-i-1,xc+1)) % (xc+1)
        else:
            if xc > 1:
                x = (xm - pow(2,N-i-1,xc-1)) % (xc-1)
            else:
                x = -1
        if x < 0:
            print(0)
        else:
            print(cnt[x]+1)



if __name__ == '__main__':
    main()

Measured memory_bytes: 77988
#include<bits/stdc++.h>
#define ll long long
#define debug(x) cout<<#x<<'='<<x<<endl
#define set0(x) memset(x,0,sizeof(x))
using namespace std;
const int inf=0x3f3f3f3f;
const int maxn=2e6+10;
int main()
{
   ll x;
   cin>>x;
   ll a=x/500;
   ll b=(x-a*500)/5;
   ll ans=a*1000+b*5;
   cout<<ans<<endl;
   //system("pause");
   return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include<random>
#include <bitset>
using namespace std;
#define N (1000000000+7)
//#define N 998244353
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> Q;

const int inf = (int)1e9; 

ll gcd(ll a, ll b) {
	if (b > a) {
		ll tmp = b;
		b = a;
		a = tmp;
	}
	if (a%b == 0)return b;
	else return gcd(b, a%b);
}


int main(void){
	int n,k;
	cin>>n>>k;
	vector<ll>a(n+1);
	for(int i=0;i<n;i++)cin>>a[i+1];
	for(ll i=k+1;i<=n;i++){
		if(a[i-k]<a[i])cout<<"Yes";
		else cout<<"No";
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 4784
/* ex5-3
    kas056 */

#include <stdio.h>

int main(void){
    int row, column;//変数設定
    int i,j;
    
    
    scanf("%d %d", &row, &column);

    char matrix[row][column];//行列を入れる配列作成
    int judge_r[row], judge_c[column];//その行・列に＃が含まれているか判定。

    //入力の読み込み。一文字ずつ読み込み、(i,j)番目に入れる
    for(i = 0; i < row; i++){
        for (j = 0; j < column; j ++){
            scanf(" %c", &matrix[i][j]);
        }
    }

    //判定機の初期値設定。＃があれば１にしたいので、初期値を全て0にする。
    for(i=0; i<row; i++){//行
        judge_r[i] = 0;
    }
    for(j=0; j<column; j++){//列
        judge_c[j] = 0;
    }

    for(i = 0; i < row; i++){//まず行を固定して
        for (j = 0; j < column; j++){//その行の各要素に対して
            if(matrix[i][j] == '#'){//＃と一致するものがあったら
                judge_r[i] = 1;//判定を真にして終了する。
                break;
            }
        }
    }//これを行の数だけ繰り返す。

    for(j = 0; j < column; j++){//列を固定して、行の場合と同様の操作を行う
        for(i = 0; i < row; i++){
            if(matrix[i][j] == '#'){
                judge_c[j] = 1;
                break;
            }
        }
    }

    for(i=0; i<row; i++){//ある行において判定が真だった時、かつ
        if(judge_r[i] == 1){
            for(j = 0; j<column; j++){//その列の判定が真の時、
                if(judge_c[j] == 1){
                    printf("%c", matrix[i][j]);//(i,j)番目の文字を一文字出力
                }
            }//折り返し。これをcolumnの数だけ繰り返す
            printf("\n");//終点で改行
        }
    }//これをrowの数だけ繰り返す

    return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
    int main(){
    string s;
    cin >> s;
    bool d = true;
    for(int i = 0; i < 3; i++){
    if(s.at(i) == s.at(i + 1)){
        d = false;
        break;
    }
    }
    if(d == true)
    cout << "Good" << endl;
    else 
    cout << "Bad" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
using namespace std;

static const long long int M = 1000000007;

long long int mypow(long long int x, long long int n)
{
    long long int t, t2;
    if (n == 1){
        return x % M;
    }
    t = mypow(x, n / 2);
    t2 = (t * t) % M;
    if (n % 2 == 0){
        return t2;
    }else{
        return (t2 * x) % M;
    }
}

int main()
{
    long long int m, n;
    scanf("%lld %lld", &m, &n);
    
    printf("%lld\n", mypow(m, n));
    return 0;
}



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

int main() {
  int n;
  cin>>n;
  string ss[n];
  for (int i=0; i<n; i++) {
    string s;
    cin>>s;
    sort(s.begin(), s.end());
    ss[i] = s;
  }
  sort(ss, ss + n);

  long long idx1 = 0;
  long long idx2 = 1;
  long long ans = 0;
  while (idx1 < n) {
    while (idx2 < n) {
      if (ss[idx1] != ss[idx2]) {
        break;
      }
      ++idx2;
    }
    ans += (idx2 - idx1) * (idx2 - idx1 - 1) / 2;
    idx1 = idx2;
    ++idx2;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 7808
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 9999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(25) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<int,int>
#define paf(L,R) pair<L,R>
#define mod 998244353
#define MAX 10000000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli A,B,C,D,E,F,N,M,K,L,X,Y,Z,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> N;
  Vec(P,bool,N,0);//famale-1,male-0
  Out(0);
  cin >> S;
  if(S[0]=='V')return 0;
  else if(S[0]=='F')P[0]=true;
  else P[0]=false;
  Out(N/2);
  cin >> S;
  if(S[0]=='V')return 0;
  else if(S[0]=='F')P[N/2]=true;
  else P[N/2]=false;
  int ok,ng;
  if((P[0]==P[N/2]&&(N/2-1)&1)||(P[0]!=P[N/2]&&(N/2-1)%2==0)){
    ok=N/2;
    ng=N;
  }
  else{
    ok=0;
    ng=N/2;
  }
  while(1){
    int mid=(ok+ng)/2;
    Out(mid);
    cin >> S;
    if(S[0]=='V')return 0;
    else if(S[0]=='F')P[mid]=true;
    else P[mid]=false;
    if((P[ok]==P[mid]&&(mid-ok-1)&1)||(P[ok]!=P[mid]&&(mid-ok-1)%2==0))ok=mid;
    else ng=mid;
  }
}



Measured memory_bytes: 852
#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
    int n,m;
    long long sum = 0;
    scanf("%d%d",&n,&m);
    if(n>=2){
        sum += (1+n-1)*(n-1)/2;
    }
    if(m>=2){
        sum += (1+m-1)*(m-1)/2;
    }
    printf("%lld\n",sum);
    return 0;
}


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

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n;
  cin >> n;

  if(n <= 10) {
    cout << "2 3 ";
    ll cur = 30;
    rep(i, n-3){
      cout << cur << " ";
      cur += 30;
    }
    cout << 985 << endl;
    return 0;
  }

  cout << "2 3 4 6 8 9 10 ";
  ll cur = 12;
  ll cnt = 7;
  rep(i, (n-7)/8){
    printf("%lld %lld %lld %lld %lld %lld %lld %lld ", cur, cur+2, cur+3, cur+4, cur+6, cur+8, cur+9, cur+10);
    cur += 12;
    cnt += 8;
  }
  
  ll res = n - cnt;
  if(res == 0){
  } else if(res == 1){
    printf("%lld", cur);
    cnt += 1;
  } else if(res == 2){
    printf("%lld %lld", cur+2, cur+4);
    cnt += 2;
  } else if(res == 3){
    printf("%lld %lld %lld", cur, cur+2, cur+4);
    cnt += 3;
  } else if(res == 4){
    printf("%lld %lld %lld %lld", cur, cur+2, cur+4, cur+6);
    cnt += 4;
  } else if(res == 5){
    printf("%lld %lld %lld %lld %lld", cur, cur+2, cur+3, cur+4, cur+9);
    cnt += 5;
  } else if(res == 6){
    printf("%lld %lld %lld %lld %lld %lld", cur, cur+2, cur+3, cur+4, cur+6, cur+9);
    cnt += 6;
  } else if(res == 7){
    printf("%lld %lld %lld %lld %lld %lld %lld", cur, cur+2, cur+3, cur+4, cur+8, cur+9, cur+10);
    cnt += 7;
  } else {
    assert(false);
  }
  cout << endl;

  //cout << cnt << endl; // debug

  return 0;
}


Measured memory_bytes: 3696
import java.util.Scanner;
public class Main {
   public static void main(String[] args) {
     
        //sec--1
        Scanner sc = new Scanner(System.in);
        int[] x = new int[5];
        
        //sec--2
        for(int i=0; i<5; i++) {
          x[i] = sc.nextInt();
          
          //配列子が0を見つける
          if(x[i] == 0) {  
            System.out.println(i+1);
            break;
          }
        }
   }
}

Measured memory_bytes: 35664
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (ll i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
// template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m = 3501; cin >> n;
    rep (x, 1, m) {
        rep (y, 1, m) {
            if (4 * x * y <= n * (x + y)) continue;
            ll a = n * x * y, b = 4 * x * y - n * (x + y);
            if (a % b == 0) {
                cout << x << ' ' << y << ' ' << a / b << '\n';
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
S = list(input())
T = list(input())

# 前計算
S_n = [0] * (len(S) + 1)
# S_n[0] = 1 if S[0] == 'A' else 2
for i in range(1, len(S) + 1):
    if S[i - 1] == 'A':
        S_n[i] = S_n[i - 1] + 1
    else:
        S_n[i] = S_n[i - 1] + 2

T_n = [0] * (len(T) + 1)
# T_n[0] = 1 if T[0] == 'A' else 2
for i in range(1, len(T) + 1):
    if T[i - 1] == 'A':
        T_n[i] = T_n[i - 1] + 1
    else:
        T_n[i] = T_n[i - 1] + 2

q = int(input())
for _ in range(q):
    a, b, c, d = map(int, input().split())
    #output
    S_A = S_n[b] - S_n[a - 1]
    T_A = T_n[d] - T_n[c - 1]
    delta = abs(S_A - T_A)
    if delta % 3 == 0:
        print ('YES')
    else:
        print ('NO')    




Measured memory_bytes: 64276
#include <iostream>
#include <vector>
using namespace std;
using ll = long long; using P = pair<int,int>;
using vl = vector<ll>; using vvl = vector<vl>;
#define mp make_pair
#define pb push_back
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,n) for (int i=(n-1);i >= 0;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)((v).size())
#define MAX(v) *max_element(all(v))
#define MIN(v) *min_element(all(v))
#define Sort(v) sort(all(v))
#define Rev(v) reverse(all(v))
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);in(name)
#define vv(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define VV(type,name,h,w) vector<vector<type>>name(h,vector<type>(w));in(name)
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cout << H << " ";
    debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
    for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
    return os;
}
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
template<class T>bool chmax(T &a, const T &b) {if(a<b){a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if(b<a){a=b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const int dx[8] = {1,0,-1,0,1,1,-1,-1}; const int dy[8] = {0,1,0,-1,1,1,-1,-1};

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    ll n; cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    ll sum = 0;
    rep(i, n) sum = (sum + a[i]) % mod;
    ll ans = 0, tsum = 0;
    rep(i, n) {
        tsum = (tsum + a[i]) % mod;
        ans = (ans + (a[i] * (sum - tsum + mod) % mod) % mod + mod) % mod;
    }
    cout << ans % mod << endl;
}

Measured memory_bytes: 4732
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int n,m,q;
int a[505][505],jx[505][505];
int st[505],l,r,ans=0;
int main()
{
    std::ios::sync_with_stdio(false);
    cin>>n>>m>>q;
    for(register int i=1;i<=m;++i)
    {
        cin>>l>>r;
        a[l][r]++;
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            jx[i][j]=a[i][j]+jx[i-1][j]+jx[i][j-1]-jx[i-1][j-1];
        }
    }
    for(register int i=1;i<=q;++i)
    {
        cin>>l>>r;
        cout<<jx[r][r]+jx[l-1][l-1]-jx[r][l-1]-jx[l-1][r]<<endl;;
    }
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> ab(n);
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    ab.at(i) = make_pair(b, a);
  }
  sort(ab.begin(), ab.end());
  bool flag = true;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    int b, a;
    tie(b, a) = ab.at(i);
    sum += a;
    if (sum > b) {
      flag = false;
      break;
    }
  }
  if (flag == true)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
} 

Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

struct vertex {
  int k;
  int visited;
  int vlist[100][2];
};

int main(int argc, char *argv[])
{
  int n, i, j;
  int e;
  struct vertex *adj;
  int v;
  int op, cost, mine, newv;
  int sum;

  scanf("%d", &n);
  adj = (struct vertex *)malloc(sizeof(struct vertex) * n);
  for (i = 0; i < n; i++) {
    adj[i].k = 0;
    adj[i].visited = 0;
    for (j = 0; j < 100; j++) {
      adj[i].vlist[j][0] = -1;
      adj[i].vlist[j][1] = -1;
    }
  }

  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      scanf("%d", &e);
      if (e != -1) {
	adj[i].vlist[adj[i].k][0] = j;
	adj[i].vlist[adj[i].k][1] = e;
	adj[i].k++;
      }
    }
  }

  adj[0].visited = 1;
  v = 1;
  sum = 0;
  while (v != n) {
    mine = INT_MAX;
    newv = -1;
    for (i = 0; i < n; i++) {
      if (adj[i].visited == 1) {
	for (j = 0; j < adj[i].k; j++) {
	  op = adj[i].vlist[j][0];
	  cost = adj[i].vlist[j][1];
	  if (adj[op].visited == 0 && mine > cost) {
	    mine = cost;
	    newv = op;
	  }
	}
      }
    }
    adj[newv].visited = 1;
    v++;
    sum += mine;
  }

  printf("%d\n", sum);

  return 0;
}

Measured memory_bytes: 676
import std.stdio;
import std.string;
import std.algorithm;
import std.conv;
import std.array;
import std.math;
import std.range;

void main()
{
    foreach(line; stdin.byLine)
    {
        auto nn = line.chomp.split.map!(to!uint).array,
             n = nn[0], x = nn[1];

        if(nn == [0, 0]) return;

        uint cnt;
        foreach(a; 1 .. n+1)
            foreach(b; a+1 .. n+1)
                foreach(c; b+1 .. n+1)
                    if(a+b+c == x) ++cnt;

        writeln(cnt);
    }
}

Measured memory_bytes: 1072
n, y = gets.split.map(&:to_i)

a = b = c = -1

valid = false
imax = y / 10_000 <= 2_000 ? y / 10_000 : 2_000
(imax).downto(0) do |i|
  break if valid

  ((y - 10_000 * i) / 5_000).downto(0) do |j|
    rest = y - 10_000 * i - 5_000 * j
    k = rest / 1_000
    valid = k && (i + j + k == n)

    if valid
      a, b, c = [i, j, k]
      break
    end
  end
end

puts [a, b, c].join(" ")


Measured memory_bytes: 1788
//vvk
#include "bits/stdc++.h"
using namespace std;
 
using ll = long long;
 
const ll inf = 1e18;
const int N = 2 * 1e5 + 1;

ll res , k , n;
ll w[105] , v[105] , dp[105][N];

void solve(){
    cin >> n >> k;
    for(int i = 1; i <= n; i++) {
        cin >> w[i] >> v[i];
        res += v[i];
    }
    for(int i = 1; i <= res; i++) dp[0][i] = inf; 

    for(int i = 1; i <= n; i++) {
        for(int j = 0; j <= res; j++) {
            if(v[i] > j) dp[i][j] = dp[i - 1][j];
            else dp[i][j] = min(w[i] + dp[i - 1][j - v[i]] , dp[i - 1][j]);
        }
    }
    ll ans = 0;
    for(int i = 0; i <= res; i++) {
        if(dp[n][i] <= k) 
            ans = i;
    }
    cout << ans;
}
 
int main(int argc, char const *argv[]){
    ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    ll t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 82816
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

int main(void){
  int h, w;
  cin >> h >> w;

  vector<string> s(h);
  for (int i = 0; i < h; i++)
    cin >> s[i];


  vector<vector<int>> yoko(h, vector<int>(w, 0));
  vector<vector<int>> tate(h, vector<int>(w, 0));

  for (int i = 0; i < h; i++){
    for (int j = 0; j < w; j++){
      if (s[i][j] == '#')
        yoko[i][j] = -1;
      else if (j == 0){
        yoko[i][j] = 0;
      }
      else
        yoko[i][j] = yoko[i][j-1] + 1;
    }
    for (int j = w - 2; j >= 0; j--){
      if (yoko[i][j + 1] > 0 && yoko[i][j] >= 0)
        yoko[i][j] = yoko[i][j + 1];
    }
  }
  for (int j = 0; j < w; j++){
    for (int i = 0; i < h; i++){
      if (s[i][j] == '#')
        tate[i][j] = -1;
      else if (i == 0){
        tate[i][j] = 0;
      }
      else
        tate[i][j] = tate[i - 1][j] + 1;
    }
    for (int i = h - 2; i >= 0; i--){
      if (tate[i + 1][j] > 0 && tate[i][j] >= 0)
        tate[i][j] = tate[i + 1][j];
    }
  }


  int m = 0;
  for (int j = 0; j < w; j++){
    for (int i = 0; i < h; i++){
      m = max(m, yoko[i][j] + tate[i][j] + 1);
    }
  }

  cout << m << endl;




  return 0;
}


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

int main(void){
  int a;
  cin >> a;
  for(int i = 1; i <= 9; i ++){
    for(int j = 1; j <= 9; j ++){
      if(i*j == a){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug { 
    ($($a: expr),*) => { 
        println!(concat!($(stringify!($a)," = {:?}, "),*), $($a),*);
    } 
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

fn solve() {
    let s = get!(String).chars().collect::<Vec<_>>();
    let t = match s[0] {
        'A' => "T",
        'C' => "G",
        'G' => "C",
        'T' => "A",
        _  => "",
    };
    println!("{}", t);
}


Measured memory_bytes: 8572
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string s,t;
  cin>>s>>t;
  int n=0;
  for(int i=0; i<3; i++){
    if(s[i]==t[i])
       n++;
  }
  cout<<n<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,m,i,a;
    int sum=0;
    cin >> n >> m;
    for(i=0; i<m; i++){
        cin >> a;
        sum += a;
    }
    if(sum>n){
        cout << -1 << endl;
    }else{
        cout << n-sum << endl;
    }
    return 0;
}

Measured memory_bytes: 3592
#include<stdio.h>
   #define num 100
   int main(void){
       int n[num],x[num],a,i,j,k,c=0,ans[num]={0};
       for(a=0;1;a++){
          scanf("%d %d",&n[a],&x[a]);
         if(n[a]==0&&x[a]==0)
            break;
          c++;
      }
      for(a=0;a<c;a++){
         for(i=1;i<n[a]-1;i++){
            for(j=i+1;j<n[a];j++){
               for(k=j+1;k<n[a]+1;k++){
                  if(i+j+k==x[a]&&i!=j&&j!=k&&k!=i)
                    ans[a]++;
               }
            }
         }
      }
      for(i=0;i<c;i++){
         printf("%d\n",ans[i]);
      }
      return 0;
  }


Measured memory_bytes: 2068
from math import log 
import numpy as np
from bisect import bisect
x=int(input())
n=x
f=[100]
for i in range(1,4000):
    inte=f[-1]//100 
    f.append(f[-1]+inte) 
#print(f)
#print(bisect(f,x))
for i in range(len(f)):
    if f[i]>=x:
        print(i)
        break
    

Measured memory_bytes: 27332
def f(n, ans):
    for k, c in dic.items():
        a, b = k
        if a == n:
            if not b in cost or c < cost[b]:
                cost[b] = c
        elif b == n:
            if not a in cost or c < cost[a]:
                cost[a] = c
    for k, c in sorted(cost.items(), key=lambda x: x[1]):
        if not k in res:
            res.append(k)
            ans += c
            del cost[k]
            return f(k, ans)
    return ans
            
while True:
    n, m = map(int, raw_input().split())
    if n == m == 0: break
    dic = {}
    s, b, c = map(int, raw_input().split())
    dic[(s, b)] = c
    for i in range(m-1):
        a, b, c = map(int, raw_input().split())
        dic[(a, b)] = c
    cost = {}
    res = [s]
    print f(s, 0)

Measured memory_bytes: 4496
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int n, m;
    cin >> n >> m;
    int a[m], b[m], c[m] = {};
    rep(i,m){
        cin >> a[i];
        cin >> b[i];
        rep(j, b[i]){
            int d; cin >> d;
            d--;
            c[i] += (1 << d);
        }
    }


    int dp[1 << n];
    rep(i,(1 << n)){
        if(i == 0)dp[i] = 0;
        else dp[i] = 1001001001;
    }
    
    rep(i,m){
        rep(j,(1 << n)){
            int jj = j | c[i];
            dp[jj] = min(dp[jj], dp[j] + a[i]);
        }
    }

    if(dp[(1 << n) - 1] == 1001001001) dp[(1 << n) - 1] = -1;
    cout << dp[(1 << n) - 1] << endl;
    return 0;
}
 
 


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

namespace _0011
{
    public class Program

    {
        public static void Main(string[] args)
        {
            int n = ReadInt();
            int[] items = new int[n];
            for (int i = 0 ; i < n ; i++) items[i] = i + 1;

            int m = ReadInt();
            for (int i = 0 ; i < m ; i++)
            {
                int[] line = ReadIntAr(',');
                Swap(items, line[0] - 1, line[1] - 1);
            }

            foreach (var item in items) Console.WriteLine(item);
        }

        private static void Swap(int[] items, int v1, int v2)
        {
            var tmp = items[v1]; items[v1] = items[v2]; items[v2] = tmp;
        }

        static string ReadSt() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Console.ReadLine()); }
        static long ReadLong() { return long.Parse(Console.ReadLine()); }
        static double ReadDouble() { return double.Parse(Console.ReadLine()); }
        static string[] ReadStAr(char sep = ' ') { return Console.ReadLine().Split(sep); }
        static int[] ReadIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); }
        static long[] ReadLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); }
        static double[] ReadDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); }
        static string WriteAr(int[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }
        static string WriteAr(double[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }
        static string WriteAr(long[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }

    }

}



Measured memory_bytes: 15904
import java.awt.geom.Rectangle2D;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		while(true){
			String str = br.readLine();
			
			if(str == null){
				break;
			}
			
			String[] tmpArray = str.split(" ");
			double[] input = new double[8];
			for(int i = 0; i < input.length ; i++){
				input[i] = Double.parseDouble(tmpArray[i]);
			}
			
			if(input[0] > input[6] || input[1] > input[7]
					|| input[2] < input[4] || input[3] < input[5]){
				System.out.println("NO");
			}
			else {
				System.out.println("YES");
			}
//			Rectangle2D.Double rect1 = new Rectangle2D.Double(input[0], input[3], input[2] - input[0], input[3] - input[1]);
//			Rectangle2D.Double rect2 = new Rectangle2D.Double(input[4], input[7], input[6] - input[4], input[7] - input[5]);
//			
//			if(rect1.intersects(rect2)){
//				System.out.println("YES");
//			}
//			else {
//				System.out.println("NO");
//			}
		}
	}

}

Measured memory_bytes: 24320
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <iostream>
#include <string>
#include <set>
using namespace::std;

int main(){
	int N;
	cin >> N;
	int A[2][101];

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

	int max_sum = 0;

	for(int i = 0; i < N; i++){
		int temp = 0;
		for(int j = 0; j < N; j++){
			if(j == i){
				temp += A[0][j] + A[1][j];
			} else if(j > i) {
				temp += A[1][j];
			} else {
				temp += A[0][j];
			}
		}
		if(temp>max_sum) max_sum = temp;
	}
	cout << max_sum <<endl;
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

dx = [-1, 0, 1, 0]
dy = [0, 1, 0, -1]

h, w = map(int, input().split())

grid = []
for i in range(h):
  grid.append(list(input()))

for i in range(h):
  for j in range(w):
    if grid[i][j]=='#':
      isFillable = False
      for k in range(4):
        x = j + dx[k]
        y = i + dy[k]
        if 0 <= x and x <= w-1 and 0 <= y and y <= h-1:
          if grid[y][x] == "#":
            isFillable = True
      if not isFillable:
        print('No')
        exit()

print('Yes')


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

using namespace std;

double x, a;
int i;

int main (void)
{
	scanf("%lf",&x);
	a=100;
	for (i=1; ; i++) {
		a=a+floor(a/100);
		if (a>=x) break;
	}
	printf("%d\n",i);
	
	return 0;
}

Measured memory_bytes: 3824
r1 = list(map(lambda x:int(x),input().split()))
r2 = list(map(lambda x:int(x),input().split()))
r3 = list(map(lambda x:int(x),input().split()))
n = int(input())
for i in range(n):
  called = int(input())
  for j in range(3):
    if called==r1[j]:
      r1[j] = 0      
    elif called==r2[j]:
      r2[j] = 0
    elif called==r3[j]:
      r3[j] = 0
if r1==[0,0,0] or r2==[0,0,0] or r3==[0,0,0]:
  print("Yes")
elif r1[0]==r2[0]==r3[0] or r1[1]==r2[1]==r3[1] or r1[2]==r2[2]==r3[2]:
  print("Yes")
elif r1[0]==r2[1]==r3[2] or r1[2]==r2[1]==r3[0]:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <string.h>
#define ll long long
#define MAX 200000000000
#define MOD 1000000007
ll int bin(ll int);

int main(void){
ll int N,A,B,C,D;
 scanf("%lld%lld%lld%lld%lld",&N,&A,&B,&C,&D);
 ll int b,u,h;
 if(B>A){
 h=B-A;
 }else{
 h=A-B;
 }
 
 int f=0;
 int i;
 if(f==0)
 for(i=N-1;i>=0;i--){
  if(C*i-D*(N-1-i)<=h&&h<=D*i-C*(N-1-i)) f=1;
 }
 
 if(f==1){
  printf("YES\n");
 }else{
  printf("NO\n");
 }
 
 return 0;
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

##### 無限 #####
# inf = float('inf')

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

inf = float('inf')

def main():
	N = inputInt()
	S = {}
	for i in range(N):
		inp = input()
		inp = inp[:-1]
		if inp in S:
			S[inp] += 1
		else:
			S[inp] = 1

	score_sorted = sorted(S.items(), key=lambda x:-x[1])
	ans = []
	mx = 0
	for i in score_sorted:
		str,inin = i
		if mx == 0:
			mx = inin
		if mx != inin:
			break
		ans.append(str)

	ans.sort()
	for i in ans:
		print(i)

	#print(score_sorted)

if __name__ == "__main__":
	main()


Measured memory_bytes: 111576
a=list(input())
b=list(input())
c=list(input())
ans="a"
while True:
  try:
    if ans == "a":
      ans=a[0]
      a=a[1:]
    elif ans == "b":
      ans = b[0]
      b=b[1:]
    elif ans == "c":
      ans = c[0]
      c=c[1:]
  except:
    print(ans.upper())
    break


Measured memory_bytes: 9120
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

template< typename T >
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

template< typename T >
vector< T > dijkstra(WeightedGraph< T > &g, int s) {
  const auto INF = numeric_limits< T >::max();
  vector< T > dist(g.size(), INF);

  using Pi = pair< T, int >;
  priority_queue< Pi, vector< Pi >, greater< Pi > > que;
  dist[s] = 0;
  que.emplace(dist[s], s);
  while(!que.empty()) {
    T cost;
    int idx;
    tie(cost, idx) = que.top();
    que.pop();
    if(dist[idx] < cost) continue;
    for(auto &e : g[idx]) {
      auto next_cost = cost + e.cost;
      if(dist[e.to] <= next_cost) continue;
      dist[e.to] = next_cost;
      que.emplace(dist[e.to], e.to);
    }
  }
  return dist;
}

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m,s,t; cin >> n >> m >> s >> t;
    s--; t--;
    WeightedGraph<LL> yg(n), sg(n);
    REP(i,m){
        int u,v,a,b; cin >> u >> v >> a >> b;
        u--; v--;
        yg[u].eb(v,a);
        yg[v].eb(u,a);
        sg[u].eb(v,b);
        sg[v].eb(u,b);
    }
    VL ycost(n,0), scost(n,0),tcost(n,0);
    ycost = dijkstra(yg,s);
    scost = dijkstra(sg,t);

    REP(i,n){
        tcost[i] = ycost[i]+scost[i];
    }
    VL memo(n,LINF);
    memo[n-1] = tcost[n-1];
    for(int i = n-2; i >= 0; i--){
        memo[i] = min(memo[i+1],tcost[i]);
    }
    REP(i,n){
        cout << LL(1e15) - memo[i] << endl;
    }



}


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

using namespace std;
typedef long long ll;

const int MaxN = 100010;
const int MaxLabel = 20;

int n, ans, f[MaxN]; vector<int> edge[MaxN];

void dfs(int x, int fa) {
  int all = 0;
  for (int y : edge[x]) {
    if (y == fa)
      continue;
    dfs(y, x);
    all |= (f[x] & f[y]);
    f[x] |= f[y];
  }
  
  int t = 0;
  while ((1 << t) <= all || f[x] >> t & 1)
    ++t;
  ans = max(ans, t);
  f[x] >>= t;
  f[x] <<= t;
  f[x] |= (1 << t);
}

int main() {
  scanf("%d", &n);
  for (int i = 1, u, v; i < n; i++) {
    scanf("%d%d", &u, &v);
    edge[u].push_back(v);
    edge[v].push_back(u);
  }
  
  dfs(1, 0);
  cout << ans << "\n";
  return 0;
}



Measured memory_bytes: 11776
import sys
input = sys.stdin.readline

#import collections
#from bisect import *
from heapq import *

def linput(_t=int):
	return list(map(_t, input().split()))

def gcd(n,m):
    while m: n,m = m, n%m
    return n

def lcm(n,m): return n*m//gcd(n,m)

def prime_factorize(n):
	r = []
	rapp = r.append
	while n%2<1: rapp(2); n//=2
	f = 3
	while f*f<=n:
		if n%f<1: rapp(f); n//=f
		else: f+=2
	if n != 1: rapp(n)
	return r

def main():
	N = int(input())
	#N,P,C,M = linput()

	res = 0
	vQ = prime_factorize(N)
	vQ.sort(reverse=True)
	
	sV = set([])
	t = 1
	pp = 1
	for p in vQ:
		if t != 1 and p != pp:
			t = 1
		t *= p
		if t not in sV:
			N //= t
			sV |= {t}
			res += 1
			t = 1
		pp = p
		if N==1: break
	
	print(res)
	#print("{:.5f}".format(res/R))


main()


Measured memory_bytes: 9284
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <set>
#include <vector>
#include <map>
#include <cstdio>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <cassert>
#include <climits>
using namespace std;
typedef long long ll;
#define DEBUG
#ifdef DEBUG
	#define debug printf
#else
	#define debug(...)
#endif
const ll maxn = 2005;
const ll mod = 1e9 + 7;
ll c[maxn][maxn];
ll pre()
{
	for(int i = 0;i < maxn; ++i)
	{
		c[0][i] = 0;
		c[i][0] = 1;
	}
	for(int i = 1;i < maxn; ++i)
	{
		for(int j = 1;j < maxn; ++j)
		{
			c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;
		}
	}
}
int main(int argc, char const *argv[])
{
	pre();
	ll n,k;
	cin>>n>>k;
	ll r = n - k,b = k;
	for(ll i = 1;i <= k; ++i)
	{
		printf("%lld\n",c[r + 1][i] * c[b - 1][i - 1] % mod);
	}
	return 0;
}

Measured memory_bytes: 31616
const val MOD = 1000000007

fun COMinit(m: Int): Pair<List<Long>, List<Long>> {
    val fac = mutableListOf(1L, 1L)
    val finv = mutableListOf(1L, 1L)
    val inv = mutableListOf(1L, 1L)
    for (i in 2 until m + 1) {
        fac.add((fac[i - 1] * i) % MOD)
        inv.add(MOD - ((inv[MOD % i] * (MOD / i)) % MOD))
        finv.add((finv[i - 1] * inv[i]) % MOD)
    }
    return Pair(fac, finv)
}

fun COM(m: Int, r: Int, fac: List<Long>, finv: List<Long>): Long {
    if (m < r) return 0L
    if (m < 0 || r < 0) return 0L
    return (fac[m] * ((finv[r] * finv[m - r]) % MOD)) % MOD
}

fun main(args: Array<String>){
    val (n, k) = readLine()!!.split(" ").map(String::toInt)
    val (fac, finv) = COMinit(Math.max(n - k + 1, k - 1))
    for (i in 1 until k + 1) {
        println((COM(n - k + 1, i, fac, finv) * COM(k - 1, i - 1, fac, finv)) % MOD)
    }
}


Measured memory_bytes: 36036
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();

        int num = 1;
        for (int i = 0; i < n; i++) {
            if (num * 2 < num + k) {
                num *= 2;
                continue;
            }
            num += k;
        }
        System.out.println(num);
    }

}


Measured memory_bytes: 21844
#include <iostream>

using namespace std;

const long long mod = 998244353LL;

int n;

long long pw(long long a, long long b) {
  if (b == 0LL) return 1LL;
  long long r = pw(a, b >> 1);
  r = (r * r) % mod;
  if (b & 1LL) r = (a * r) % mod;
  return r;
}

long long inv(long long x) {
  return pw(x, mod-2LL);
}

int main() {
  cin >> n;

  long long ans = 1LL;
  for (int i = 0; i < n; ++i) ans = (3 * ans) % mod;

  long long val = 1LL, sum = 0LL;
  for (int i = n; i > n/2; --i) {
    sum = (sum + 2 * val) % mod;
    val = (val * i % mod * inv(n-i+1)) % mod;
    val = (val * 2) % mod;
  }

  ans = (ans - sum) % mod;
  ans = (ans % mod + mod) % mod;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int main()
{
	LL N, K;
	in >> N >> K;
	std::vector<LL>A(N + 1);
	rep(i, N) in >> A[i + 1];

	if (K == 1)
	{
		out << 0 << std::endl;
		return 0;
	}

	for (LL i = 1; i <= N; ++i) A[i] = (A[i] - 1 + K) % K;
	rep(i, N) (A[i + 1] += A[i]) %= K;

	std::map<LL, LL>nums;
	LL ans = 0;
	nums[A[0]]++;
	for (LL i = 1; i <= N; ++i)
	{
		ans += nums[A[i]];
		nums[A[i]]++;
		if (i >= K - 1) nums[A[i - K + 1]]--;
	}

	out << ans << std::endl;
}


Measured memory_bytes: 14336