akhauriyash/Code-Regression huggingface dataset:
#import<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long LL;
LL i,j,k,m,n,t,a[200040];
string s;
main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cout<<fixed<<setprecision(12);
	cin>>s;
	for(;s[i];i++)t+=s[i]-48;
	if(t%9)cout<<"No";
	else cout<<"Yes";
}

Measured memory_bytes: 3780
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ll long long
#define ld long double
#define zeros(x) x^(x-1)&x
#define pii pair<ll,ll>
#define cd complex<double>
#define dbg(x) cerr<<#x<<": "<<x<<endl;ll
#define Nmax 400005
#define OFF 100001
using namespace std;

ll n,m,c;
char mat[55][55];

int main()
{
    cin >> n >> m;
    for (int i=1;i<=n;i++) cin >> mat[i]+1;

    int ok = 1;
    c = 1;
    for (int i=1;i<=n;i++){
        if (mat[i][c]!='#') ok = 0;
        mat[i][c] = '.';
        while (c < m && mat[i][c+1] == '#'){
            c++;
            mat[i][c] = '.';
        }
    }
    for (int i=1;i<=n;i++){
        for (int j=1;j<=m;j++){
            if (mat[i][j] == '#') ok = 0;
        }
    }
    if (ok) cout << "Possible\n";
    else cout << "Impossible\n";

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define Max 500000

int l[Max / 2 + 1], r[Max / 2 + 1];
int count;

void merge(int a[], int right, int mid, int left, int n) {
  int n1 = mid - left;
  int n2 = right - mid;
  int i, j, k;
  for (i = 0; i < n1; i++) {
    l[i] = a[left + i];
  }
  for (i = 0; i < n2; i++) {
    r[i] = a[mid + i];
  }
  l[n1] = r[n2] = 1000000000;
  i = 0, j = 0;
  for (k = 0; k <  n1 + n2; k++) {
    ++count;
    if (l[i] <= r[j]) {
      a[left + k] = l[i++];
    } else {
      a[left + k] = r[j++];
    }
  }
}

void sort(int a[], int right, int left, int n) {
  if (left < right - 1) {
    int mid = (right + left) / 2;
    sort(a, mid, left, n);
    sort(a, right, mid, n);
    merge(a, right, mid, left, n);
  }
}

int main() {
  int a[Max + 1];
  int n;
  int i;
  count = 0;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  sort(a, n, 0, n);
  for (i = 0; i < n; i++) {
    if (i != n - 1) {
      printf("%d ", a[i]);
    } else {
      printf("%d\n", a[i]);
    }
  }
  printf("%d\n", count);

  return 0;
}



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

int a,b,j=0;
int main(){
	cin >> a >>b;
  	for(int i=a;i<=b;i++){
    	if((i-i%10000)/10000==i%10) if((i%10000-i%1000)/1000==(i%100-i%10)/10)j++;
    }
  	cout << j;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main(){
	int n;
	cin >> n;
	long long T=1,A=1;
	for(int i=0;i<n;i++){
		int t,a;
		cin >> t >> a;
		long long n=max(T/t+(T%t?1:0),A/a+(A%a?1:0));
		T=n*t;
		A=n*a;
	}
	cout << T+A << endl;
}


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

max_a = max(a_list)
half_max = max_a / 2

near = max_a
near_ori = max_a
for a in a_list:
    if a == max_a:
        continue
    tmp = abs(a - half_max)
    if tmp < near:
        near = tmp
        near_ori = a
        
print(max_a, near_ori)

Measured memory_bytes: 14432
#include "bits/stdc++.h"
using namespace std;
int main(){
    int n,i,b,c,d,ans = 0;
    cin >> n;
    vector<int> a(n);
    for(i=0;i<n;i++) cin >> a.at(i);
    b = a.at(0); d=1;
    for(i=1;i<n;i++){
        c=a.at(i);
        if(c==b){
            d++;
        }else{
            ans += d/2;
            b = c;
            d = 1;
        }
    }
    ans += d/2;
    cout << ans << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef unordered_set<int> si;
typedef pair<int, int> pp;
typedef vector<pp> vpp;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#define all(e) (e).begin(), (e).end()
#define pb push_back


template <typename T>
void printV(vector<T> A) {
    if (A.empty()) cerr << "EMTPY\n";
    else { 
        cerr << "[";
        for (int i = 0; i < A.size() -1 ; ++i) {
            cerr << A[i] << ", ";
        }
        if (A.size()) cerr << A.back() << "]\n";
    }
}


template <typename T>
void printVV(vector<vector<T>> A) {
    cerr << "[";
    for (auto v : A) {
        printV<T>(v);
    }
    cerr << "]";
}

template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cerr << name << ": " << arg1 << endl;
}

template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&& ...args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << ": " << arg1 << " |";
    __f(comma + 1, args...);
}

int main(int argc, char **argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    si s;
    int n, k; cin >> n >> k;
    for (int i =0 ; i<k; ++i) {
        int d; cin >> d;
        for (int j = 0; j < d; ++j) {
            int id; cin >> id;
            s.insert(id);
        }
    }
    cout << n - s.size() << endl;
    return 0;
}



Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
int ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
ll nod(ll F) { return log10(F) + 1; }
//**定義場所**//
//gcd, isPrime, eratos, modinv, bitSearch, dfs, bfs, dijkstra, UnionFind//
ll i, j, k, l, m, n; ll N, M, K, H, W, L; string S;
ll MOD = 1000000007; ll ans = 0; ll INF = 9999999999999;
vl flag, color; vll path;
//***********//

int main() {
	cin >> N >> K;
	vl H(N);
	for (i = 0; i < N; i++) {
		cin >> H[i];
	}
	sort(H.begin(), H.end());
	reverse(H.begin(), H.end());
	ll P = min(N, K);
	for (i = P; i < N; i++) {
		ans += H[i];
	}
	cout << ans;
}


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

int main() {
  int H, W;
  cin >> H >> W;
  long long retsu1 = W % 2 == 1 ? W / 2 + 1 : W / 2;
  long long retsu2 = W % 2 == 1 ? retsu1 - 1 : retsu1;
  long long result = (H / 2 * retsu1) + (H / 2 * retsu2);
  if (W == 1 || H == 1) {
    result = 1;
  } else if (H % 2 == 1) {
    result += retsu1;
  }

  cout << result << endl;
}



Measured memory_bytes: 256
#AtCoder
from collections import defaultdict
N, M = map(int, input().split())

d = defaultdict(list)
for i in range(M):
    p, S = input().split()
    d[int(p)].append(S)

a = 0
p = 0
for i in d.items():
    if 'AC' not in i[1]:
        continue

    ac_index = i[1].index('AC')
    a += 1

    if 'WA' in i[1]:
        wanum = i[1][:ac_index]
        p += len(wanum)

print(a, p)

Measured memory_bytes: 29808
n = int(input())
L = list(map(int, input().split()))
ans = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            a, b, c = L[i], L[j], L[k]
            if a==b or b==c or c==a:
                continue
            if a+b>c and b+c>a and c+a>b:
                ans += 1
print(ans)

Measured memory_bytes: 68092
#include <bits/stdc++.h>
using namespace std;
struct edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int>>;
using dou =long double;
string Yes="Yes";
string YES="YES";
string NO="NO";
string No="No";
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; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define res resize
#define as assign
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout << "Case #" <<qqq+1<<": "
 
typedef long long ll;
//typedef long long T;
const int INF = 2000000000;
const ll INF64 = 922337203685477580ll;
//const int mod = 1000000007ll;
const ll  MOD = 1000000007LL;
int main(){
    int x,y,z;
    std::cin >> x>>y>>z;
    swap(x,y);
    swap(x,z);
    std::cout << x<<' '<<y<<' '<<z << std::endl;
}

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

vector<long long int>v;
long long int dp[100005];
long long int inf=10000000000;
int main()
{
    long long int j,n,i,a,k;
    cin >> n >> k;
    for(i=0; i<n; i++)
    {
        cin >> a;
        v.push_back(a);
        dp[i]=inf;
        dp[i+1]=inf;
    }
    dp[0]=0;
    for(i=0; i<n; i++)
    {
        for(j=1; j<=k; j++)
        {
            if(i+j<n)
            {
               dp[i+j]=min((abs(v[i]-v[i+j])+dp[i]),dp[i+j]);
               //fo=min(fo,dp[i+j]);
            }
        }
    }
    cout << dp[n-1] << endl;
}


Measured memory_bytes: 4996
#include <iostream>
#include <algorithm>
#include <cstdio>
#include<string>
#include<cstring>
using namespace std;
int m,n,l,a[1100000],b[1100000],d[50],q[10];
void print(int &xx,int &yy)
{
    for(int x=1;x<=l;x++)
    {
      if(abs(xx)>abs(yy))
      {
          if(xx>0)
          {
              cout<<"R";
              xx-=d[x];
          }
          else
          {
              cout<<"L";
              xx+=d[x];
          }
      }
    else
    {
        if(yy>0)
        {
            cout<<"U";
            yy-=d[x];
        }
        else
        {
            cout<<"D";
            yy+=d[x];
        }
    }
    }
}int main()
{
    cin>>m;
    for(int x=1;x<=m;x++)
    {
        cin>>a[x]>>b[x];
        q[(a[x]+b[x])%2]=1;
    }
    if(q[0]==1&&q[1]==1)
    {
        cout<<-1<<endl;
        return 0;
    }
    for(int x=30;x>=0;x--)
    {
        d[++l]=(1<<x);
    }
    if(q[0]==1)
    {
        d[++l]=1;
    }
    cout<<l<<endl;
    for(int x=1;x<l;x++)
    {
        cout<<d[x]<<" ";
    }
    cout<<d[l]<<endl;
    for(int x=1;x<=m;x++)
    {
      print(a[x],b[x]);
  //    cout<<a[x]<<" "<<b[x]<<endl;
      cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 2304
S = input()

def isMonth(S):
    if 1<=int(S)<=12:
        return True
    else:
        return False

s1, s2 = S[:2], S[2:]
if isMonth(s1) & isMonth(s2):
    print('AMBIGUOUS')
elif isMonth(s1):
    print('MMYY')
elif isMonth(s2):
    print('YYMM')
else:
    print('NA')

Measured memory_bytes: 3060
import java.util.*;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int a = Integer.parseInt(sc.next());

		int[] f = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1,
				5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };

		System.out.println(f[a - 1]);

	}
}

Measured memory_bytes: 35548
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define Check system("pause")
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)



int main()
{
	ios::sync_with_stdio(false);
	ll a,b,v,w,t,k;
	cin>>a>>v;
	cin>>b>>w;
	cin>>t;
	if(a>b)
	{
		a=a-v*t;
		b=b-w*t;
		if(a<=b) cout<<"YES";
		else cout<<"NO";
	}
	else
	{
		b=b+w*t;
		a=a+v*t;
		if(a>=b) cout<<"YES";
		else cout<<"NO";
	}
	return 0;
}




Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i )
typedef std::pair<int,int> pint;

using namespace std;
typedef long long ll;

int main(){
    int N,K; cin >> N >> K;
    vector<int> list(N+5);
    rep (i,N){
        int tmp;
        cin >> tmp;
        list[i] = tmp;
    }
    rep (i,N-K){
        if (list[i] < list[i+K]){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 4048
# -*- coding: utf-8 -*-
import sys
N=int(sys.stdin.readline().strip())
A=map(int, sys.stdin.readline().split())

AA=[]
for i,val in enumerate(A):
    AA.append((val,i+1))

AA.append((float("inf"),None))  #1-indexedにする
AA.sort(reverse=True)

dp=[ [ 0 for r in range(N+1) ] for l in range(N+1) ]
dp[0][0]=0

l=0
for l in range(N):
    for r in range(N-l):
        val,idx=AA[l+r+1][0],AA[l+r+1][1]
        dp[l+1][r]=max( dp[l+1][r], dp[l][r]+abs(val*(idx-l-1)) )
        dp[l][r+1]=max( dp[l][r+1], dp[l][r]+abs(val*(N-r-idx)) )

ans=float("-inf")
for l in dp:
    ans=max(ans,max(l))

print ans

Measured memory_bytes: 104916
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;

struct Card { char suit; int value; };

void bubbleSort(struct Card A[], int N) {
  int flag = 1, j;
  while ( flag ) {
    flag = 0;
    for ( j = N - 1; j > 0; j-- ) {
      if ( A[j].value < A[j - 1].value ) {
        swap(A[j], A[j - 1]);
        flag = 1;
      }
    }
  }
}

void selectionSort(struct Card A[], int N) {
  int i, j, minj;
  for (i=0;i<N;i++) {
    minj = i;
    for (j=i;j<N;j++) {
      if (A[j].value < A[minj].value) {
        minj=j;
      }
    }
    if (minj > i) {
      swap(A[i],A[minj]);
    }
  }
}

void trace(struct Card A[], int N) {
  int i;
  for ( i = 0; i < N; i++ ) {
    if ( i > 0 ) printf(" ");
    printf("%c", A[i].suit);
    printf("%d", A[i].value);
  }
  printf("\n");
}

int main() {
	int N, i, count;
  Card A[100], B[100];

  scanf("%d", &N);
  for ( i = 0; i < N; i++ ) {
    cin >> A[i].suit >> A[i].value;
  }
  for ( i = 0; i < N; i++ ) B[i] = A[i];
  bubbleSort(A, N);
  selectionSort(B, N);

  trace(A, N);
  printf("Stable\n");
  trace(B, N);
  bool b = true;
  for ( i = 0; i < N; i++ ) {
    if (A[i].suit != B[i].suit) b = false;
  }
  if (b) {
    printf("Stable\n");
  } else {
    printf("Not stable\n");
  }


  return 0;
}



Measured memory_bytes: 3208
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

int main()
{
    std::vector<int> num(3);
    for (int i = 0; i < 3; i++) {
        std::cin >> num[i];
    }

    int k;
    std::cin >> k;

    std::sort(num.begin(), num.end(), std::greater<int>());

    std::cout << (num[0] << k) + num[1] + num[2] << std::endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
int main() {
  int n, k, t = 0;
  cin >> n >> k;
  vector<int> p(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  sort(p.begin(), p.end());
  for (int i = 0; i < k; i++) {
    t += p[i];
  }
  cout << t << endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,x,cnt;
  cin>>n>>x;
  cnt=n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
    x-=a[i];
  }
  sort(a.begin(),a.end());
  while(x>=0){
    x-=a[0];
    cnt++;
  }
  cout<<cnt-1<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<stdio.h>

using namespace std;
#define INF 1e15
#define MAX_V 100000

typedef struct{
    int to;
    int cost;
} edge;

typedef struct{
    long dist;
    int v;
} rte;

bool operator< (const rte a, const rte b){
    return a.dist > b.dist;  // ascend
}

vector<edge> G[MAX_V];

long d[MAX_V];

void dijkstra(int s, int t);

int main(){

    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N, M;
    cin >> N >> M;

    int L[M], R[M], C[M];
    for(int i = 0; i < M; i++){
        cin >> L[i] >> R[i] >> C[i] ;
        L[i]--; R[i]--; 
    }

    int cnt = 0;

    bool bonded[N]; fill(bonded, bonded + N, false);
    for(int i = 0; i<M; i++){
        G[L[i]].emplace_back(edge{R[i], C[i]});
    }

    for(int i = 0; i<N-1; i++){
        G[i+1].emplace_back(edge{i, 0});
    }
    
    dijkstra(0, N);

    if(d[N-1] == INF) cout << -1 << endl;
    else cout << d[N-1] << endl;

    return 0;
    
}

void dijkstra(int s, int V){

    fill(d, d + V, INF);

    priority_queue< rte > que;
    d[s] = 0;
    que.push(rte{d[s], s});
    
    while(!que.empty()){
        rte now = que.top(); que.pop();
        if(now.dist > d[now.v]) continue;
        for(edge e : G[now.v]){
            if(d[e.to] > d[now.v] + e.cost){
                d[e.to] = d[now.v] + e.cost;
                que.push(rte{d[e.to], e.to});
            }
            
        }
    }
}

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

using namespace std;
int n,a[100001],dp[100001];
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++)
    cin>>a[i];
    dp[0]=10001;
    dp[1]=0;
    for(int i=2;i<=n;i++){
    if((dp[i-1]+abs(a[i]-a[i-1]))<(dp[i-2]+abs(a[i]-a[i-2])))
    dp[i]=dp[i-1]+abs(a[i]-a[i-1]);
    else dp[i]=dp[i-2]+abs(a[i]-a[i-2]);
    }
    cout<<dp[n];
    return 0;
}



Measured memory_bytes: 1024
#!/usr/bin/env python3

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

total = a[0]
xor = a[0]
ans = 0
l = 0
r = 0

while 1:
    if xor == total:
        ans += r-l+1
        r += 1
        if r == n:
            break
        total += a[r]
        xor ^= a[r]
    else:
        total -= a[l]
        xor ^= a[l]
        l += 1
print(ans)


Measured memory_bytes: 32056
A =list(str(input()))
B =list(str(input()))
C =list(str(input()))
P=A
for i in range(len(A)+len(B)+len(C)+3):
    if P[0] == 'a':
        
        P.pop(0)
        P=A
        if len(A) ==0:
            print('A')
            exit()
    elif P[0] =='b':

        P.pop(0)
        P=B
        if len(B) ==0:
            print('B')
            exit()
    elif P[0] =='c':

        P.pop(0)
        P=C
        if len(C) ==0:
            print('C')
            exit()

Measured memory_bytes: 9144
#include<iostream>
using namespace std;
long long answer,n;
int a[110]={0};
int main()
{
	answer=0;
	cin>>n;
	int i,j;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		if(a[i]!=0&&i!=0)
		{
			for(j=0;j<i;j++)
			{
				answer+=a[i]*a[j];	
			}	
		}
	}
	cout<<answer;
}

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

map<int64_t, int> prime_factor(int64_t n) {
	map<int64_t, int> ret;
	for (int64_t i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1)
		ret[n] = 1;
	return ret;
}

int main() {
	int N, mina = INT_MAX;
	cin >> N;
	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		mina = min(mina, prime_factor(a)[2]);
	}
	cout << mina << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
int d[401];

int x[31];
int cnt[21][401];
vector<vector<int> > vec;
set<vector<int> > se;

void dfs(int dep,int l,int r){
	//printf("q %d %d\n",l,r);
	vector<int> xv;
	for(int i=0;i<n;i++){
		xv.push_back(x[i]);
		//printf("%d ",x[i]);
	}
	//printf("\n");
	if(se.find(xv)==se.end()){
		se.insert(xv);
	}else{
		return;
	}
	if(l==r){
		vector<int> vv;
		for(int i=0;i+1<n;i++){
			if(x[i]<x[i+1]){
				vv.push_back(x[i+1]-x[i]);
			}else{
				return;
			}
		}
		vec.push_back(vv);
		return;
	}
	int maxv=0;
	for(int i=400;i>=0;i--){
		if(cnt[dep][i]>0){
			maxv=i;
			break;
		}
	}
	x[l]=d[0]-maxv;
	//printf("%d %d\n",l,d[0]-maxv);
	if(x[l]>x[l-1] && x[l]<x[r]){
		for(int i=0;i<=400;i++){
			cnt[dep+1][i]=cnt[dep][i];
		}
		bool flag=true;
		for(int i=0;i<l;i++){
			cnt[dep+1][x[l]-x[i]]--;
			if(cnt[dep+1][x[l]-x[i]]<0)flag=false;
		}
		for(int i=r;i<n;i++){
			cnt[dep+1][x[i]-x[l]]--;
			if(cnt[dep+1][x[i]-x[l]]<0)flag=false;
		}
		if(flag){
			dfs(dep+1,l+1,r);
		}
	}
	x[l]=0;
	x[r-1]=maxv;
	if(x[r-1]<x[r] && x[r-1]>x[l-1]){
		for(int i=0;i<=400;i++){
			cnt[dep+1][i]=cnt[dep][i];
		}
		bool flag=true;
		for(int i=0;i<l;i++){
			cnt[dep+1][x[r-1]-x[i]]--;
			if(cnt[dep+1][x[r-1]-x[i]]<0){
				flag=false;
				//printf("error %d\n",i);
			}
		}
		for(int i=r;i<n;i++){
			cnt[dep+1][x[i]-x[r-1]]--;
			if(cnt[dep+1][x[i]-x[r-1]]<0){
				flag=false;
				//printf("error %d\n",i);
			}
		}
		if(flag){
			dfs(dep+1,l,r-1);
		}
	}
	x[r-1]=0;
}

void solve(){
	vec.clear();
	se.clear();
	memset(x,0,sizeof(x));
	memset(cnt,0,sizeof(cnt));
	for(int i=1;i<n*(n-1)/2;i++){
		cnt[0][d[i]]++;
	}
	x[0]=0;
	x[n-1]=d[0];
	dfs(0,1,n-1);
	sort(vec.begin(),vec.end());
	for(int i=0;i<vec.size();i++){
		for(int j=0;j<vec[i].size();j++){
			printf("%d%c",vec[i][j],j+1==vec[i].size()?'\n':' ');
		}
	}
	printf("-----\n");
}

int main(void){
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		for(int i=0;i<n*(n-1)/2;i++){
			scanf("%d",&d[i]);
		}
		solve();
	}
	
	return 0;
}


Measured memory_bytes: 3416
import sys
n=int(input())
a=list(map(int,input().split()))


if n==2:
    print(max(a))
    sys.exit()

a0=[a[0],a[0]]
a1=[0,a[1]]
a2=[0,0,a[2]]
for i in range(2,n):
    if i%2==0:
        a0.append(a0[i-2]+a[i])
        a1.append(a1[i-1])
        if i>=4: a2.append(max(a2[i-2],a1[i-3],a0[i-4])+a[i])
    else:
        a0.append(a0[i-1])
        a1.append(max(a1[i-2],a0[i-3])+a[i])
        a2.append(a2[i-1])

if n%2==1: print(max(a0[n-1],a1[n-1],a2[n-1]))
else: print(max(a0[n-1],a1[n-1]))

Measured memory_bytes: 135128
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
#include <map>
#include <cmath>
#include <iomanip>
#include <numeric>
using namespace std;

#define INF 1e18
#define int long long

template<typename T>
void printVec(vector<T> &v) {
    for(int i = 0; i < v.size(); i++) {
        cout << v[i] << " ";
    }
    cout << endl;
}

signed main() {
    vector<vector<int>> v(4, vector<int> (4, 0));
    for(int i = 0; i < 3; i++) {
        int a, b; cin >> a >> b;
        a--; b--;
        v[a][b] = 1;
        v[b][a] = 1;
    }

    int odd = 0;
    for(int i = 0; i < 4; i++) {
        int d = 0;
        for(int j = 0; j < 4; j++) {
            if(v[i][j]) d++;
        }
        if(d % 2 != 0) odd++;
    }

    if(odd == 0) {
        cout << "YES" << endl;
        return 0;
    }

    cout << (odd == 2 ? "YES" : "NO") << endl;
    return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, math.MaxInt64)
}

func readString() string {
	sc.Scan()
	return sc.Text()
}

func readInt() int {
	sc.Scan()
	r, _ := strconv.Atoi(sc.Text())
	return r
}

func main() {
	n := readInt()
	s := readString()
	cnt, max := 0, 0
	for i := 0; i < n; i++ {
		switch string(s[i]) {
		case "I":
			cnt++
			if max < cnt {
				max = cnt
			}
		case "D":
			cnt--
		}
	}
	fmt.Println(max)
}


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

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int a, b, h, S;
	cin >> a;
	cin >> b;
	cin >> h;

	S = (a + b) * h / 2;
	printf("%d\n", S);
	return 0;
}

Measured memory_bytes: 3700
program hi;
var 
    si: array[2..100010] of boolean;
    x, i, j: longint;

begin
    for i := 2 to 100010 do 
        si[i] := true;
    for i := 2 to 317 do begin
        j := i * i;
        while j <= 100010 do begin
            si[j] := false;
            j := j + i;
        end;
    end;
    readln(x);
    if si[x] then 
        writeln(x)
    else begin
        i := x;
        while not si[i] do 
            inc(i);
        writeln(i);
    end;
end.

Measured memory_bytes: 1392
#include<iostream>
#define ll long long
using namespace std;
int a[200000], l[100005], r[100005];
ll cnt;
void merge(int left, int mid, int right) {
  int x = mid - left, y = right - mid;
  for (int i = 0; i<x; ++i) l[i] = a[left + i];
  for (int i = 0; i<y; ++i) r[i] = a[mid + i];
  l[x] = r[y] = 1000000001;
  x = y = 0;
  for (int i = left; i<right; ++i) {
    if (l[x] <= r[y]) a[i] = l[x++];
    else {
      a[i] = r[y++];
      cnt += mid - left - x;
    }
  }
}

void mergesort(int left, int right) {
  if (left + 1<right) {
    int mid = (right + left) / 2;
    mergesort(left, mid);
    mergesort(mid, right);
    merge(left, mid, right);
  }
}

int main() {
  int n; cin >> n;
  for (int i = 0; i<n; ++i) cin >> a[i];
  mergesort(0, n);
  cout << cnt << endl;
  return 0;
}



Measured memory_bytes: 4660
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353

def ddprint(x):
  if DBG:
    print(x)

s = ins()
t = ins()
sacc = [0]
for c in s:
    sacc.append(((1 if c=='A' else 2)+sacc[-1])%3)
tacc = [0]
for c in t:
    tacc.append(((1 if c=='A' else 2)+tacc[-1])%3)
#ddprint(sacc)
#ddprint(tacc)
q = inn()
for i in range(q):
    a,b,c,d = inm()
    #ddprint('{} {} {} {}'.format(sacc[b],sacc[a-1],tacc[d],tacc[c-1]))
    print('YES' if (sacc[b]-sacc[a-1])%3==(tacc[d]-tacc[c-1])%3 else 'NO')


Measured memory_bytes: 82788
#include <cmath>
#include <queue>
#include <bitset>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 100005;
const int M = 500005;

const long long inf = 0x3f3f3f3f3f3f3f3f;

typedef pair<int, int> pr;

signed main(void)
{
	int n, m, s; cin >> n >> m >> s;

	vector< vector<pr> > to(n);

	for (int i = 0, u, v, w; i < m; ++i)
	{
		cin >> u >> v >> w;
		to[u].push_back(make_pair(v, w));
	}

	vector<long long> dis(n); queue<int> que; bitset<N> vis;
	for (auto &i : dis)i = inf; dis[s] = 0; que.push(s); vis.set(s);

	while (!que.empty())
	{
		int top = que.front(); que.pop(); vis.reset(top);

		for (auto t : to[top])
			if (dis[t.first] > dis[top] + t.second)
			{
				dis[t.first] = dis[top] + t.second;
				if (!vis[t.first])vis.set(t.first), que.push(t.first);
			}
	}

	for (auto i : dis)
	{
		if (i < inf)cout << i << endl;
		else cout << "INF" << endl;
	}

//	system("pause");
}

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

int main() {
  int a, b;
  cin >> a >> b;
  if (b==a) cout << "Draw";
  else {
  	if (a==1) cout << "Alice";
    else if (b==1) cout << "Bob";
    else {
    	if (a > b) cout << "Alice";
      	else cout << "Bob";
    }
  }
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    int K[N];
    int A[N][M];

    int sum[M+1] = {0};

    int tot = 0;

    for (int i = 0; i < N; i++){
        cin >> K[i];
        for (int j = 0; j < K[i]; j++){
            cin >> A[i][j];
            for (int l = 1; l <= M; l++){               
                if (A[i][j] == l)
                sum[l] += 1;
            }
        }
    }
    for (int l = 1; l <= M; l++){
        if (sum[l] == N)
        tot += 1;
    }


    cout << tot;
}

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

//-----------------------------------------------

//------------------------------------------------

int main(){
  ll n,k,q,a;
  cin>>n>>k>>q;
  vector<ll> b;
  b.assign(n,k-q);
  rep(i,0,q) {
    cin>>a;
    b[a-1]+=1;
  }
  rep(i,0,n){
    if(b[i]>0) cout<<"Yes"<<endl;
    if(b[i]<=0) cout<<"No"<<endl;
  }
}


Measured memory_bytes: 1408
n = gets.to_i
ary = []
ns = ['7','5','3']
(3..9).each do |i|
  nums = ns.repeated_permutation(i).select{ |set| (ns - set).empty? }.map(&:join)
  ary += nums
end
 
 
cnt = ary.select{|num| num.to_i <= n}
puts cnt.length

Measured memory_bytes: 11680
#include <bits/stdc++.h>
using namespace std;
#define INFTY (1<<21)
#define MAX 100
void floyd(int m, int C[MAX][MAX], int T[MAX][MAX]) {
	for (int k = 0; k < m; k++)
		for (int i = 0; i < m; i++)
			for (int j = 0; j < m; j++) {
				C[i][j] = min(C[i][j], C[i][k] + C[k][j]);
				T[i][j] = min(T[i][j], T[i][k] + T[k][j]);
			}
}
main() {
	int n, m, a, b, c, t, k, q, C[MAX][MAX], T[MAX][MAX];
	while( cin >> n >> m && !(n == 0 && m == 0) ) {
		for(int i = 0;i<m;i++)
		for(int j = 0;j<m;j++) {C[i][j] = T[i][j] = INFTY;}
		for(int i = 0;i<n;i++) {
			cin >> a >> b >> c >> t; C[a-1][b-1] = C[b-1][a-1] = c; T[a-1][b-1] = T[b-1][a-1] = t;
		}
		floyd(m, C, T);
		cin >> k;
		for(int i = 0;i<k;i++) {
			cin >> a >> b >> q;
			if ( q ) cout << T[a-1][b-1] << endl;
			else cout << C[a-1][b-1] << endl;}
	}
}

Measured memory_bytes: 3052
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<bitset>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int N=100000;
const db pi=acos(-1.0);
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u];i;i=sq[i].nxt)
#define fir first
#define sec second
#define mp make_pair
#define pb push_back
#define maxd 998244353
#define eps 1e-8
#define int long long
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

namespace My_Math{
	#define N 100000

	int fac[N+100],invfac[N+100];

	int add(int x,int y) {return x+y>=maxd?x+y-maxd:x+y;}
	int dec(int x,int y) {return x<y?x-y+maxd:x-y;}
	int mul(int x,int y) {return 1ll*x*y%maxd;}
	ll qpow(ll x,int y)
	{
		ll ans=1;
		while (y)
		{
			if (y&1) ans=mul(ans,x);
			x=mul(x,x);y>>=1;
		}
		return ans;
	}
	int Inv(int x) {return qpow(x,maxd-2);}

	int C(int n,int m)
	{
		if ((n<m) || (n<0) || (m<0)) return 0;
		return mul(mul(fac[n],invfac[m]),invfac[n-m]);
	}

	void math_init()
	{
		fac[0]=invfac[0]=1;
		rep(i,1,N) fac[i]=mul(fac[i-1],i);
		invfac[N]=Inv(fac[N]);
		per(i,N-1,1) invfac[i]=mul(invfac[i+1],i+1);
	}
	#undef N
}
using namespace My_Math;

int n;
map<int,int> vis; 

bool chk(int k)
{
	int now=n;vis[k]=1;
	while (now%k==0) now/=k;
	if ((now-1)%k==0) return 1;else return 0;
}

int solve(int x)
{
	int ans=0;
	for (int i=1;i*i<=x;i++)
	{
		if (x%i) continue;
		if (!vis.count(i)) ans++;
		if ((i*i!=x) && (!vis.count(x/i))) ans++;
	}
	return ans;
}

signed main()
{
	n=read();
	int ans=1;vis[1]=vis[n]=1;
	for (int i=2;i*i<=n;i++)
	{
		if (n%i) continue;
		ans+=chk(i);
		if (i*i!=n) ans+=chk(n/i);
	}
	ans+=solve(n-1);
	cout << ans;
	return 0;
}



Measured memory_bytes: 640
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

int main(void) {

	int n, l, k;
	string s[100];

	cin >> n >> l;

	for (k = 0; k < n; k++) {
		cin >> s[k];
	}

	sort(s, s + n,greater<string>());

	for (k = 1; k < n; k++) {
		s[k] += s[k - 1];
	}

	cout << s[n - 1] << "\n";

	return 0;
}

Measured memory_bytes: 896
import math

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

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

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

    return arr

N,P = map(int,input().split())
arr = factorization(P)
candi = 1
for fact,num in arr:
    candi *= fact**(math.floor(num/N))
print(candi)


Measured memory_bytes: 9380
def compute_score(sub):
    max_i = max(sub)
    min_i = min(sub)
    score = max_i * (max_i + 1) * (1 /2) + min_i * (min_i - 1) * (1/2)
    return score

S = input()
sub = [0, 0]
ans = 0
flag = False
for s in S:
    if s == '<' and flag:
        ans += compute_score(sub)
        sub = [0, 0]
        flag = False
    if s == '>':
        flag = True
    if s == '<':
        sub[0] += 1
    else:
        sub[1] += 1
ans += compute_score(sub)
print(int(ans))

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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int N, M;
  cin >> N >> M;
  vector<int> A(N), B(N);
  REP(i, N) { cin >> A.at(i) >> B.at(i); }
  vector<int> C(M), D(M);
  REP(i, M) { cin >> C.at(i) >> D.at(i); }

  REP(i, N) {
    ll c = 100;
    ll dist = 1 << 29;

    for (ll j = 0; j < M; ++j) {
      ll d = abs(C.at(j) - A.at(i)) + abs(D.at(j) - B.at(i));
      // cout << i << ":" << j + 1 << ":" << d << endl;
      if (dist > d) {
        dist = d;
        c = j + 1;
      } else if (dist == d) {
        c = min(c, j + 1);
      }
    }

    cout << c << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>
#include<set>
#include <bits/stdc++.h>

using namespace std;
using ll = long long int;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++) //REP(i, 5) cout<<i;
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define MOD 1000000007 //10^9+7

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


int main(void){
  
  ll n, k;
  cin>>n>>k;

  vector<ll> sum(n+2);
  vector<ll> v(n+2);

  REP(i, n+2){
    if(i==0 || i == 1) sum[0] = 0;
    else sum[i] = sum[i-1] + (i-1);
    //sum[i] = sum[i]%MOD;
    //cout<<sum[i]<<" ";
  }
  //cout<<endl;
  
  REP(i, n+2){
    if(i==0) v[0] = 0;
    else v[i] = (i*n-sum[i])-sum[i] +1;
    //v[i] = v[i]%MOD;
    //cout<<v[i]<<" ";
  }
  
  ll ans = 0;
  FOR(i, k, n+1){
    ans += v[i]%MOD;
    ans = ans%MOD;
  }

  cout<<ans%MOD<<endl;
  return 0;

}

Measured memory_bytes: 6348
#include <math.h>

#include <algorithm>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
using ll = long long;

ll gcd(ll m, ll n) {
  if (n == 0)
    return m;
  else
    return gcd(n, m % n);
}

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll num = b - a + 1;

  num -= b / c - (a - 1) / c;
  num -= b / d - (a - 1) / d;
  num += b / lcm(c, d) - (a - 1) / lcm(c, d);

  cout << num;
  return 0;
}


Measured memory_bytes: 256
/*
 * cpp_filepath
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
void solve();
int main() { solve(); return 0; }


void solve() {
  int n;
  string s, t;
  cin >> n >> s>>t;
  loop(i,0,n) {
    cout << s[i] << t[i];
  }
  cout << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<vector>
#include<cmath>
#include<cstdio>
#include<cstring>
using namespace std;
int n,a[15],ans,i;
int main()
{
	cin>>n;
	for(i=1;i<=n;++i) cin>>a[i];
	sort(a+1,a+n+1);
	for(i=1;i<=n-1;++i)
	{
		ans+=a[i];
	}
	ans+=a[n]/2;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
using namespace std;

int main(void) {
    string str;
    char order[16];
    int n;
    int a, b;
    char word[1000];
    
    cin >> str;
    cin >> n;
    
    for(int i = 0; i < n; ++i) {
        cin >> order;
        
        if(strstr(order, "print")) {
            cin >> a >> b;
            for(int j = a; j < b + 1; ++j) {
                cout << str[j];
            }
            cout << endl;
        } else if(strstr(order, "reverse")) {
            cin >> a >> b;
            for(int j = 0; j < (double)(b - a + 1) / 2; ++j) {
                char cpy = str[a + j];
               str[a + j] = str[b - j];
                str[b - j] = cpy;
            }
        } else if(strstr(order, "replace")) {
            cin >> a >> b >> word;
            str.replace(a, b - a + 1, word);
        }
    }
    return 0;
}



Measured memory_bytes: 3216
#include <bits/stdc++.h>
#define rep(i , n) for (int i = 0; i < (int)(n); i++)
const int INF = 1<<29;
using namespace std;
using ll = long long;
#include <bits/stdc++.h>
int main() {
    int N, A, B, C, D;
    string S;
    cin >> N >> A >> B >> C >> D >> S;
    S = "#" + S + "#";
    auto t = [&](int start , int end) {
        for (int i = start; i + 1 <= end; i++) {
            if (S[i] == '#' && S[i + 1] == '#'){
                return false;
            }
        }
        return true;
    };

    if (!t(A, C) || !t(B, D)) {
        cout << "No" << endl;
        return 0;
    }

    if (C > D) {
        bool h = false;
        for (int i = B; i <= D; i++) {
            if (S[i - 1] == '.' && S[i] == '.' && S[i + 1] == '.') {
                h = true;
            }
        }
        if (!h) {
            cout << "No" << endl;
            return 0;
        }
    }

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


Measured memory_bytes: 3904
D = int(input())
C = input().split()
C = [int(c) for c in C]
#print(C)
S = []
for i in range(D):
  s = input().split()
  s = [int(j) for j in s]
  S.append(s)
M = 0
last = [0] * 26
#print(last)
for d in range(1,D+1):
  N = 0
  t = int(input())
  last[t-1] = d
  #print(last)
  for j in range(26):
    N = N + C[j]*(d-last[j])
  M = M + S[d-1][t-1] - N
  print(M)

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

int main() {
	long long n, a, b;
	cin >> n >> a >> b;
	
	long long ans, rem;
	ans = n/(a+b);
	ans *= a;
	rem = n%(a+b);
	
	if (rem < a) ans += rem;
	else ans += a;
	cout << ans << endl;
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <ll,ll> pii;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rept(i,x,y) for(int i=x;i<=y;i++)
#define per(i,x,y) for(int i=x;i>=y;i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define fi first
#define se second
#define mes(a,b) memset(a,b,sizeof a)
#define mp make_pair
#define dd(x) cout<<#x<<"="<<x<<" "
#define de(x) cout<<#x<<"="<<x<<"\n"
#define debug() cout<<"I love Miyamizu Mitsuha forever.\n"
const int inf=0x3f3f3f3f;
const int maxn=2e5+5;

ll prefix[maxn];
ll a[maxn],b[maxn];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,m;
	ll k;
	cin>>n>>m>>k;
	a[0]=0;
	rept(i,1,n) cin>>a[i];
	rept(i,1,m) cin>>b[i];
	rept(i,1,m) prefix[i]=prefix[i-1]+b[i];
	int ans=0;
	ll cost=0;
	rept(i,0,n)
	{
		cost+=a[i];
		if(cost>k) break;
		int l=0,r=m;
		while(l<r)
		{
			int mid=(l+r)/2+1;
			if(prefix[mid]>k-cost) r=mid-1;
			else l=mid;
		}
		ans=max(ans,i+l);
	}
	cout<<ans<<"\n";
	return 0;
}

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

int main()
{
    int N, M;
    cin >> N >> M;
    int H[N];
    for (int i = 0; i < N; i++) cin >> H[i];
    int A, B;
    bool judge[N];
    for (int i = 0; i < N; i++) judge[i] = true;
    for (int i = 0; i < M; i++) {
        cin >> A >> B;
        A--; B--;
        if (H[A] > H[B]) judge[B] = false;
        else if (H[A] < H[B]) judge[A] = false;
        else {
            judge[A] = false;
            judge[B] = false;
        }
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (judge[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		int d = scan.nextInt();
		
		while (a > 0 && c > 0) {
			c -= b;
			if (c <= 0) {
				System.out.println("Yes");
				break;
			}
			a -= d;
			if (a <= 0) {
				System.out.println("No");
				break;
			}
		}
	}
}

Measured memory_bytes: 35800
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;
#define all(x) (x).begin(),(x).end()

ll gcd(ll a,ll 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;
}

ll fac(ll n){
    ll t = 1;
    rep1(i, n + 1)t *= i;
    return t;
}

int main()
{
    double k,n,a;
    cin >> n >> k;
    rep0(i, n)cin >> a;
    cout << ceil((n - 1) / (k - 1)) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ROOP(i, N) for(int i=0; i++; i<N)
#define RVROOP(i, N) for(int i=N; i--; i>=0)
#define ALL(v) v.begin(), v.end()
const int INF = 1e9;
const int MAX = 510000;
const int MOD = 1000000007;
const double PI = acos(-1);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

/*C++になってるか確認したほうがよくない？WOWWOW*/
/*DP使ったほうがよくない？？WOWWOW*/

int main(){
    ull N, K; cin>>N>>K;
    int A[N];
    ll already[N];
    already[0]=0;
    for(int i=1; i<N; i++){
        already[i]=-1;
    }
    for(int i=0; i<N; i++){
        cin>>A[i];
        A[i]--;
    }
    ll roop, now=0;
    for(int i=0; i<K; i++){
        now=A[now];
        if(i==K-1){
            cout<<now+1<<endl;
            return 0;
        }
        else if(already[now]>=0){
            roop=i-already[now]+1;
            for(int j=0; j<(K-i-1)%roop; j++){
                now=A[now];
            }
            cout<<now+1<<endl;
            return 0;
        }
        already[now]=i+1;
    }
}

Measured memory_bytes: 5956
#include<bits/stdc++.h>
#define long long long
using namespace std;
const long N=3e5;
long aa[N+2],cnt[N+2],fr[N+2],qm[N+2],mv[N+2];
int main()
{
  ios_base::sync_with_stdio(0);cin.tie(0);
  long n;cin>>n;
  for(long i=1;i<=n;i++)
  {
    cin>>aa[i];cnt[aa[i]]++;
  }
  for(long i=1;i<=N;i++)
    if(cnt[i])fr[cnt[i]]++;
  for(long i=1;i<=N;i++)qm[i]=qm[i-1]+fr[i]*i;
  for(long i=N;i>=1;i--)fr[i]+=fr[i+1];

  for(long i=1;i<=N;i++)
    mv[i]=qm[i-1]+fr[i]*i;

  for(long i=1;i<=n;i++)
  {
    long lo=1,hi=N,md;
    while(hi-lo>2)
    {
      md=(lo+hi)/2;
      if(i*md<=mv[md])lo=md;
      else hi=md;
    }
    for(md=hi;md>=lo;md--)
      if(i*md<=mv[md])break;
    cout<<md<<"\n";
  }
  return 0;
}


Measured memory_bytes: 12544
N = int(input())
S = input()
first = S[:N]
latter = S[N:][::-1]

dic = {}
digit = "0"+str(N)+"b"
for i in range(2**N):
    pattern = list(format(i,digit))
    red = []
    blue = []
    for j in range(N):
        if pattern[j] == "1":
            red.append(first[j])
        else:
            blue.append(first[j])
    key = ",".join(("".join(red),"".join(blue)))
    if key in dic:
        dic[key] += 1
    else:
        dic[key] = 1

ans = 0
for i in range(2**N):
    pattern = list(format(i,digit))
    red = []
    blue = []
    for j in range(N):
        if pattern[j] == "1":
            red.append(latter[j])
        else:
            blue.append(latter[j])
    key = ",".join(("".join(red),"".join(blue)))
    if key in dic:
        ans += dic[key]

print(ans)

Measured memory_bytes: 95196
/*
    ThunderClap and Flash.
    Raunaq Singh
*/
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
#define ThunderClap ios::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
#define debugg(something)   cout<<#something<<" - "<<something<<"\n";
#define vi vector
#define umap unordered_map
#define uset unordered_set
#define mset multiset
#define LB lower_bound
#define UB upper_bound
#define mp make_pair
#define pb push_back
#define in insert
#define s second
#define f first
#define pQueue priority_queue
#define maxElement *max_element
#define minElement *min_element
#define MAX 100000LL
#define mod 1000000007LL
#define inf 1000000000000000000LL
#define mI2 500000004LL
inline ll add(ll a, ll b){ return ((a%mod)+(b%mod))%mod;}
inline ll mul(ll a, ll b){ return ((a%mod)*(b%mod))%mod;}
inline ll sub(ll a, ll b){ return ((a%mod)-(b%mod)+mod)%mod;}

bool chk(string s, ll i, ll j){
    while(i<j){
        if(s[i]!=s[j]){
            return false;
        }
        ++i,--j;
    }
    return true;
}

void Flash(){
    string s;
    cin>>s;
    ll n=s.size();
    if(!chk(s,0,n-1)){
        cout<<"No\n";
        return;
    }
    if(!chk(s,0,(n-1)/2 - 1)){
        cout<<"No\n";
        return;
    }
    if(!chk(s,(n-1)/2 + 1,n-1)){
        cout<<"No\n";
        return;
    }
    cout<<"Yes\n";
}

int main(int argc, char const *argv[]){
    ThunderClap;
    ll t=1;
    //cin>>t;
    for(ll i=1;i<=t;i++){
        //cout<<"Case #"<<i<<": ";
        Flash();
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0; i<n; i++)
typedef long long int ll;
typedef pair<int, int> P;
#define INF 1e9 + 7

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

    int p[3];
    cin >> p[0] >> p[1] >> p[2];
    
    sort(p, p+3);
    
    cout << p[0]+p[1] << endl;

    return 0;
}

Measured memory_bytes: 256
import numpy as np

H, W = map(int, input().split())

ans = []
for i in range(H):
  ans.append(input())
  
ind = []
k = len(ans)
for i, ss in enumerate(reversed(ans)):
  if ss == "." * W:
    ind.append(k-i-1)
  
index = []
for i in range(H):
  for j in range(W):
    if ans[i][j] == "#":
      index.append(j)

for i in range(H):
  if i in ind:
    continue
  aaa = ""
  for j in range(W):
    if j in index:
      aaa += ans[i][j]
      
  print(aaa)
      

Measured memory_bytes: 12484
import java.util.Scanner;
public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int S = sc.nextInt();
        int h,m,s;
        h=(S-S%3600)/3600;
        m=((S-h*3600)-(S-h*3600)%60)/60;
        s=S-h*3600-m*60;
        System.out.println(h+":"+m+":"+s);
    }
}


Measured memory_bytes: 26416