akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;


public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        
        int N = scanner.nextInt();
        
        int[] a = new int[N];
        long y = 0;
        
        a[0] = scanner.nextInt();
        for(int i = 1; i < N; i++) {
            a[i] = scanner.nextInt();
            y += a[i];
        }
        
        long x = a[0];
        long min = Math.abs(x - y);
        for(int i = 1; i < N - 1; i++) {
            x += a[i];
            y -= a[i];
            long calc = Math.abs(x - y);
            if(min > calc) {
                min = calc;
            }
        }
        System.out.println(min);
        
    }
}

Measured memory_bytes: 65352
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>

using namespace std;

const int MOD = 1000000007;

struct Edge {
    int to;
    int weight;

    Edge(int t, int w) : to(t), weight(w) {}
};

int main() {
    int N;
    cin >> N;
    vector<int> A(N+2, 0);

    for (int i = 1; i < N+1; ++i) {
        cin >> A[i];
    }
    int sum = 0;
    for (int i = 0; i < N + 1; ++i) {
        sum += abs(A[i] - A[i+1]);
    }
    for (int i = 1; i < N + 1; ++i) {
        cout << sum + abs(A[i-1] - A[i+1]) - (abs(A[i-1] - A[i]) + abs(A[i] - A[i+1])) << endl;
    }
    return 0;
}

Measured memory_bytes: 1664
a = input()

if a == "SUN":
    print(7)
if a == "MON":
    print(6)
if a == "TUE":
    print(5)
if a == "WED":
    print(4)
if a == "THU":
    print(3)
if a == "FRI":
    print(2)
if a == "SAT":
    print(1)

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<sstream>
#include<cmath>
#include<iterator>
#include<bitset>
using namespace std;
#define _for(i,a,b) for(int i=(a);i<(b);++i)
#define _rep(i,a,b) for(int i=(a);i<=(b);++i)
typedef long long ll;
int readint() { int x; cin >> x; return x; }
const int INF = 1 << 30;
const int maxn =200005;
struct Num {
	int val, id;
	Num(int val,int id):val(val),id(id){}
	bool operator<(const Num& rhs)const {
		return val < rhs.val;
	}
	Num(){}
}a[maxn];
int ans[maxn];
int main() {

	int n;
	while (cin >> n) {
		int x;
		for (int i = 0; i < n; ++i) {
			cin >> x; a[i] = Num(x, i);
		}
		sort(a, a + n);
	
		for (int i = 0; i < n; ++i) {
			ans[a[i].id] = ((n-1) / 2 >= i ? a[(n-1)/2+1].val : a[(n-1)/2].val);
		}
		_for(i, 0, n)cout << ans[i] << endl;
		cout << endl;
	}

	
	return 0;
}

Measured memory_bytes: 4480
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
const ll INF=1e9+7;
const ll N = 20001;
ll n,m,k;

int main(){
	cin>>n>>m>>k;
	FOR(i,0,m+1){
		FOR(j,0,n+1){
			if((m-i)*j+(n-j)*i==k){
				cout<<"Yes"<<endl;
				return 0;
			}
		}
	}
	cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int s;
int gcd(int a,int b)
{
    if(b==0)
        return a;
    else{
            int s=gcd(b,a%b);
        return s;
    }
}
int main()
{ int k,sum=0;
    cin>>k;
    int s;
 for(int i=1;i<=k;i++)
    for(int j=1;j<=k;j++)
        for(int l=1;l<=k;l++)
        {
            sum+=gcd(i,gcd(j,l));

        }
        cout<<sum<<endl;
}




Measured memory_bytes: 3648
#include"bits/stdc++.h"

#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)

using namespace std;
using ll = long long;
using pos = pair<ll, ll>;

ll x,a,b;

void solve();

int main() {

   solve();
   return 0;

}

void solve() {

   	cin >> x>> a >> b;
	cout << (abs(x-a)<abs(x-b)?"A":"B") << endl;

}

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

int main()
{
  int n, to;
  cin >> n >> to;
  vector<int> t(n);
  int i;
  for(i = 0; i < n; i++)
  {
    cin >> t.at(i);
  }
  int tuntil = to;
  int tfrom = 0;
  int from = 0;
  int ans = 0;
  for(i = 1; i < n; i++)
  {
    if(t.at(i) <= tuntil)
    {
      tuntil = t.at(i) + to;
    }
    else
    {
      ans += tuntil-tfrom;
      tfrom = t.at(i);
      tuntil = t.at(i) + to;
    }
  }
  ans += tuntil-tfrom;
  cout << ans << endl;
}

Measured memory_bytes: 1024
s = str(input())
if s[0] == "0" and s[1] == "0" and int(s[2]+s[3]) > 12:
    print("NA")
elif s[2] == "0" and s[3] == "0" and int(s[0]+s[1]) > 12:
    print("NA")
elif s == "0000":
    print("NA")
elif int(s[0]+s[1]) > 12 and int(s[2]+s[3]) > 12:
    print("NA")
elif s[0] == "0" and s[1] == "0":
    print("YYMM")
elif s[2] == "0" and s[3] == "0":
    print("MMYY")
elif int(s[0]+s[1]) > 12 and int(s[2]+s[3]) <= 12:
    print("YYMM")
elif int(s[2]+s[3]) > 12 and int(s[0]+s[1]) <= 12:
    print("MMYY")
else:
    print("AMBIGUOUS")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h, n, s = 0;
  scanf("%d %d", &h, &n);
  for(int i = 0; i < n; i++){
	int x;
    scanf("%d", &x);
    s += x;
  }
  if(s >= h){
    printf("Yes");
  }
  else{
    printf("No");
  }
}

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

int main()
{
  i64 h1, h2, k1, k2, a, b, c, d;
  cin >> h1 >> h2 >> k1 >> k2 >> a >> b >> c >> d;
  i64 hi = h1 * a + (h1 / 10) * c + h2 * b + (h2 / 20) * d, ke = k1 * a + (k1 / 10) * c + k2 * b + (k2 / 20) * d;
  if (ke < hi)
    cout << "hiroshi" << endl;
  else if (hi < ke)
    cout << "kenjiro" << endl;
  else
    cout << "even" << endl;
  return 0;
}



Measured memory_bytes: 3068
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=200000;

int n;
int a[MAXN];
int b[MAXN];

queue<int> q;
bool inq[MAXN];
int c[MAXN];

int prv(int at) { return at==0?n-1:at-1; }
int nxt(int at) { return at==n-1?0:at+1; }
bool can(int at) { return c[at]-c[prv(at)]-c[nxt(at)]>=a[at]; }
void upd(int at) { if(!inq[at]&&can(at)) inq[at]=true,q.push(at); }

ll solve() {
	q=queue<int>(); REP(i,n) inq[i]=false;
	REP(i,n) c[i]=b[i],upd(i);
	ll ret=0;
	while(!q.empty()) {
		int at=q.front(); q.pop(); inq[at]=false;
		//printf("processing %d: c=%d cprv=%d cnxt=%d\n",at,c[at],c[prv(at)],c[nxt(at)]);
		int sub=c[prv(at)]+c[nxt(at)]; if(sub<=0) continue;
		int times=(c[at]-a[at])/sub; if(times<=0) continue;
		ret+=times; c[at]-=times*sub; upd(prv(at)); upd(nxt(at));
		//printf("->%d\n",c[at]);
	}
	REP(i,n) if(c[i]!=a[i]) return -1;
	return ret;
}

void run() {
	scanf("%d",&n);
	REP(i,n) scanf("%d",&a[i]);
	REP(i,n) scanf("%d",&b[i]);
	printf("%lld\n",solve());
}

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


Measured memory_bytes: 3328
#include <stdio.h>
#include <string.h>
 
int main(void){
  char a[101], b[101], c[101];
  scanf("%s %s %s", a, b, c);
  int ai = 1;
  int bi = 0;
  int ci = 0;
  char ans;
  
  char ch = a[0];
  
  while(1){
    if(ch == 'a'){
      if(ai == strlen(a)){
        ans = 'A';
        break;
      }
      ch = a[ai++];
    }else if(ch == 'b'){
      if(bi == strlen(b)){
        ans = 'B';
        break;
      }
      ch = b[bi++];
    }else{
      if(ci == strlen(c)){
        ans = 'C';
        break;
      }
      ch = c[ci++];
    }
  }
  
  printf("%c\n", ans);
  
  return 0;
}

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

#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define eb emplace_back
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(), x.end()

using namespace std;
using ll = long long;
using ull = unsigned long long;
using Vi = vector<int>;

void run() {
 	string s;
 	cin >> s;
 	for (int i= 0; i< s.size(); ++i) {
 		cout  << 'x';
 	} 
 	cout << endl;
}

int main() 
{
    IO;
    double st = clock();
    run();
    cerr << "\n" << "time = " << (clock() - st) / CLOCKS_PER_SEC << "\n";
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
from itertools import accumulate
sys.setrecursionlimit(10**8)
INF = float("inf")

import math


def array(*args, initial=0):
    pre = "["*len(args)
    post = ""
    for a in args[::-1]:
        post += " for _ in range("+str(a)+")]"
    S = pre + str(initial) + post
    return eval(S)


def solve(N: int, A: "List[int]"):

    if N % 2 == 0:
        K = 2
    else:
        K = 3

    DP = array(N, K, initial=-10**9)
    DP[0][0] = A[0]
    DP[1][1] = A[1]
    if K == 3:
        DP[2][2] = A[2]
    for i in range(1, N):
        for k in range(K):
            if i == k and i < K:
                continue
            DP[i][k] = DP[i-2][k]
            if k-1 >= 0:
                DP[i][k] = max(DP[i][k], DP[i-3][k-1])
            if k-2 >= 0:
                DP[i][k] = max(DP[i][k], DP[i-4][k-2])
            DP[i][k] += A[i]
    if N % 2 == 0:
        print(max(DP[-1][1], DP[-2][0]))
    else:
        print(max(DP[-1][2], DP[-2][1], DP[-3][0]))
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)


if __name__ == '__main__':
    main()


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

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

    int N;
    cin >> N;
    vector<ll> H(N);
    for (auto &x : H) cin >> x;

    for (int i = N - 2; i >= 0; --i) {
        if (H.at(i) - H.at(i + 1) == 1) {
            H.at(i)--;
        } else if (H.at(i) - H.at(i + 1) > 1) {
            cout << "No" << endl;
            exit(0);
        }
    }
    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        
        String s = sc.next();
        
        boolean[][][] exist = new boolean[10][10][10];
        
        for(int i=0;i<10;i++){
            for(int j=0;j<10;j++){
                for(int k=0;k<10;k++){
                    exist[i][j][k]=false;
                }
            }
        }
        
        boolean[][] exist10 = new boolean[10][10];
        for(int i=0;i<10;i++){
            for(int j=0;j<10;j++){
                exist10[i][j]=false;
            }
        }
        boolean[] exist_hundred = new boolean[10];
        for(int i=0;i<10;i++){
            exist_hundred[i]=false;
        }
        
        boolean all_c=true;
        int i_data=0, j_data=0,k_data=0;
        for(int i=0;i<n;i++){
            i_data=s.charAt(i)-48;
            
            if(!exist_hundred[i_data]){
                for(int j=i+1;j<n;j++){
                    j_data=s.charAt(j)-48;
                    
                    if(!exist10[i_data][j_data]){
                        for(int k=j+1;k<n;k++){
                            k_data=s.charAt(k)-48;
                            if(!exist[i_data][j_data][k_data]){
                                exist[i_data][j_data][k_data]=true;
                                
                                all_c=true;
                                for(int l=0;l<10;l++){
                                    if(!exist[i_data][j_data][k_data]) all_c=false;
                                }
                                if(all_c) exist10[i_data][j_data]=true;
                            }
                        }
                        
                        all_c=true;
                        for(int l=0;l<10;l++){
                            if(!exist10[i_data][j_data]) all_c=false;
                        }
                        if(all_c) exist_hundred[i_data]=true;
                    }
                }
            }
        }
        
        int count=0;
        for(int i=0;i<10;i++){
            for(int j=0;j<10;j++){
                for(int k=0;k<10;k++){
                    if(exist[i][j][k]) count++;
                }
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 24276
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define FOR1(i, n) FOR(i, 1, n+1)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define int long long
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));

#define dl(line) cerr << "RUN: until " << (line) << "th line." << endl
#define dv(name, value) cerr << (name) << " is " << (value) << endl
#define da(v)  cerr << "["; REPI(itr, v){cerr << *itr << (itr != --v.end() ? ", " : "");} cerr << "]" << endl

const string YES = "YES";
const string NO = "NO";

void solve(long long N, std::vector<long long> A){
  sort(A.begin(), A.end());
  A.erase(unique(A.begin(), A.end()), A.end());
  cout << ((ll)A.size() == N ? YES : NO) << endl;
}

signed main(){
  long long N;
  scanf("%lld",&N);
  std::vector<long long> A(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&A[i]);
  }
  solve(N, std::move(A));
}


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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

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

const int INF = 1e9;

int main(void){

	int X; cin >> X;


	int ans = 0;
	ans += (X/500)*1000;
	X -= 500*(X/500);
	ans += (X/5)*5;

	cout << ans << endl;


	return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n, k; scanf("%d%d", &n, &k); std::vector<int> p(n);
	for(auto& v: p) scanf("%d", &v);

	long double now = 0;
	for(int i = 0; i < k; i++) now += p[i] * (p[i] + 1) / 2. / p[i];

	long double ans = now;
	for(int i = 0; i < n - k; i++) {
		now -= p[i] * (p[i] + 1) / 2. / p[i];
		now += p[i + k] * (p[i + k] + 1) / 2. / p[i + k];

		ans = std::max(ans, now);
	}

	printf("%.12Lf\n", ans);
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,i,j,k,l,a,b,c,x,y;
    cin>>n;
    stack<long long>st;
    stack<long long>st1;
    x=10000000000;
    for(i=0; i<n; i++)
    {
        cin>>k;
        st.push(k);
        if(k<x)
        {
            x=k;
        }
    }
    i=1;
    c=x;
    while(st.size()>1||st1.size()>1)
    {
        if(i==1)
        {
            x=c;
            c=100000000000;
            while(!st.empty())
            {
                a=st.top();
                st.pop();
                if(a%x!=0)
                {
                    b=a%x;
                    st1.push(b);
                    if(b<c)
                    {
                        c=b;
                    }

                }
            }
            if(x<c)
            {
                c=x;
            }
            st1.push(x);
            i--;

//            while(!st1.empty())
//            {
//                cout<<st1.top()<<" ";
//                st1.pop();
//            }

        }
        else if(i==0)
        {
            x=c;
            c=100000000000;
            while(!st1.empty())
            {
                a=st1.top();
                st1.pop();
                if(a%x!=0)
                {
                    b=a%x;
                    st.push(b);
                    if(b<c)
                    {
                        c=b;
                    }

                }
            }
            if(x<c)
            {
                c=x;
            }
            st.push(x);
            i++;

        }
    }
    cout<<x<<endl;
    return 0;
}


Measured memory_bytes: 1152
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)


int main(){
    ll N;
    cin >> N;

    ll A[N];
    ll num[100001];
    ll sum = 0;
    rep(i, 100001){
        num[i] = 0;
    }
    rep(i, N){
        cin >> A[i];
        num[A[i]]++;
        sum += A[i];
    }

    ll Q;
    cin >> Q;

    ll B, C;
    ll diff;
    rep(i, Q){
        cin >> B >> C;
        diff = C - B;
        sum += diff * num[B];
        num[C] += num[B];
        num[B] = 0;
        cout << sum << endl;
    }

    return 0;
}


Measured memory_bytes: 5156
#include<iostream>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<cmath>
#include<cstdio>
#include<cassert>
using namespace std;

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aut(r,v) __typeof(v) r = (v)
#define each(it,o) for(aut(it,(o).begin()); it!=(o).end(); ++it)
#define reach(it,o) for(aut(it,(o).rbegin()); it!=(o).rend(); ++it)
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T1, typename T2> ostream& operator<<(ostream& o, const pair<T1, T2>& p)
{return o<<"("<<p.first<<", "<<p.second<<")";}
template<typename T>string join(const vector<T>&v, string del=", ")
{stringstream s;rep(i,v.size())s<<del<<v[i];return s.str().substr(del.size());}
template<typename T>ostream& operator<<(ostream& o, const vector<T>&v)
{if(v.size())o<<"["<<join(v)<<"]";return o;}
template<typename T>ostream& operator<<(ostream& o, const vector<vector<T> >&vv)
{int l=vv.size();if(l){o<<endl;rep(i,l){o<<(i==0?"[ ":",\n  ")<<vv[i]<<(i==l-1?" ]":"");}}return o;}
template<typename T>ostream& operator<<(ostream& o, const set<T>& st)
{vector<T> v(st.begin(),st.end());o<<"{ "<<join(v)<<" }";return o;}
template<typename T1, typename T2>ostream& operator<<(ostream& o, const map<T1, T2>& m)
{each(p,m){o<<(p==m.begin()?"{ ":",\n  ")<<*p<<(p==--m.end()?" }":"");}return o;}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0)); 
const double INF = 0x3f3f3f3f;
const double INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
const double mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

vi a;

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");
    int n;
    cin >> n;
    a = vi(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(), a.end());

    ll ans=n,sum=0;
    rep(i,n-1){
        sum += a[i];
        if(a[i+1] > sum*2){ ans = n-i-1; }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    if(a < b && b < c) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}



Measured memory_bytes: 26272
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;
#define all(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)
const int inf = 1<<29;

const int MAX = 1000005;
const ll MOD = 1000000007;

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

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll gcd(ll x, ll y) {
    if(x%y==0) return y;
    return gcd(y,x%y);
}

ll lcm(ll x, ll y) {
    return x/gcd(x,y)*y;
}

ll mul(ll x, ll y) {return (x*y)%MOD;}
ll add(ll x, ll y) {return (x+y)%MOD;} 

map<ll,ll> mp;
void prime_factorization(ll N) {
    map<ll,ll> tmp;
    ll n = N;
    for(ll i=2;i*i<=N;++i) {
        while(n%i==0) {
            n /= i;
            tmp[i]++;
        }
    }
    if(n!=1) tmp[n]++;
    for(auto& p:tmp) {
      ll prime = p.first;
      ll num = p.second;
        if(mp.find(prime)==mp.end()) mp[prime] = num;
        else {
            mp[prime] = max(mp[prime],num);
        } 
    }
}

int main(){
    int N; cin >> N;
    vector<ll> A(N);
    REP(i,N) cin >> A[i];
    REP(i,N) prime_factorization(A[i]);
    ll lcmmod = 1;
    for(auto& p:mp) {
      ll prime = p.first;
      ll num = p.second;
      //cout << prime << " " << num << endl;
        REP(cnt,((int)num)) {
            lcmmod = mul(lcmmod,prime);
        }
    }
    COMinit();
    ll ans = 0;
    REP(i,N) {
        ans = add(ans,mul(lcmmod,inv[(int)A[i]]));
    }
   //for(auto p:mp) cout << p.first << " " << p.second << endl;
  // cout << lcmmod << endl;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 24448
//https://atcoder.jp/contests/arc073/tasks/arc073_d

#include<bits/stdc++.h>
const int N = 2e5 + 5;
const long long inf = 1e18;
using namespace std;

int n, q, a, b;
long long it[N << 2][3], lz[N << 2];

void dolazy(int i, int l, int r){
    if (l != r){
        lz[i << 1] += lz[i];
        lz[i << 1 | 1] += lz[i];
    }
    for (int x = 0; x < 3; x++) it[i][x] += lz[i];
    lz[i] = 0;
}

void update(int i, int l, int r, int pos, long long val){
    dolazy(i, l, r);
    if (l > pos || pos > r) return;
    if (l == r){
        if (it[i][0] > val){
            it[i][0] = val;
            it[i][1] = val-l;
            it[i][2] = val+l;
        }
        return;
    }
    int mid = (l + r) >> 1;
    update(i << 1, l, mid, pos, val); update(i << 1 | 1, mid+1, r, pos, val);
    for (int x = 0; x < 3; x++) it[i][x] = min(it[i << 1][x], it[i << 1 | 1][x]);
}

long long get(int i, int l, int r, int L, int R, int type){
    dolazy(i, l, r);
    if (L > r || l > R) return inf;
    if (L <= l && r <= R) return it[i][type];
    int mid = (l + r) >> 1;
    return min(get(i << 1, l, mid, L, R, type), get(i << 1 | 1, mid+1, r, L, R, type));
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> q >> a >> b;
    for (int i = 0; i < (N << 2); i++) it[i][0] = it[i][1] = it[i][2] = inf;
    int last = 0;
    for (int i = 1; i <= q; i++){
        int x; cin >> x;
        if (i == 1){
            update(1, 1, n, a, abs(x - b));
            update(1, 1, n, b, abs(x - a));
        }
        else{
            long long Min = min(get(1, 1, n, 1, x, 1) + x, get(1, 1, n, x, n, 2) - x);
            lz[1] = abs(last - x);
            dolazy(1, 1, n);
            update(1, 1, n, last, Min);
        }
        last = x;
    }
    cout << it[1][0];
}


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

int main() {
  int n, m;
  cin >> n >> m;
  
  vector<int> v(n);
  for(int i=0; i<n; i++) v[i] = i+1;
  vector<int> h(n);
  for(int i=0; i<n; i++) cin >> h[i];
  
  int a, b;
  for(int i=0; i<m; i++) {
    cin >> a >> b;
    if(h[a-1]==h[b-1]) v[a-1]=0, v[b-1]=0;
    else if(h[a-1]>h[b-1]) v[b-1]=0;
    else v[a-1]=0;
  }
  
  int ans = 0;
  for(int i=0; i<n; i++) if(v[i]!=0) ans++;
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4020
#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"
	#define ll long long int
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define inf 1000000000000000001;
	#define all(c) c.begin(),c.end()
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define f first
	#define s second
	
	using namespace std;
	int main()
	{
		std::ios::sync_with_stdio(false);
		int x1, x2, x3, x4, x5;
		cin>>x1>>x2>>x3>>x4>>x5;
		if (x1 == 0)
			cout<<"1"<<endl;
		if (x2 == 0)
			cout<<"2"<<endl;
		if (x3 == 0)
			cout<<"3"<<endl;
		if (x4 == 0)
			cout<<"4"<<endl;
		if (x5 == 0)
			cout<<"5"<<endl;
		return 0;
	}


Measured memory_bytes: 3552
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < n; ++i)
#define FOR(i, b, n) for (ll i = b; i < n; ++i)

using namespace std;
using ll = long long;
using P = pair<int, int>;
const string YES = "YES";
const string NO = "NO";

void solve(string S) {
  unordered_map<char, long> cnt;
  REP(i, S.length())
    cnt[S[i]]++;
  ll A = cnt['a'];
  ll B = cnt['b'];
  ll C = cnt['c'];
  cout << (max(max(A, B), C) - min(min(A, B), C) <= 1 ? YES : NO) << endl;
}

int main(){
  // int 3E4  long 2E9  ll 9E18
  cin.tie(0);
  ios::sync_with_stdio(false);

  string S;
  cin >> S;

  solve(S);

  return 0;
}


Measured memory_bytes: 3880
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) (signed)((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int MOD = 1000000007;

#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"  << " " << __FILE__ << endl;

signed main(void) {
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed, ios::floatfield);
    cout.precision(10);
    cin.tie(0);

    int n;
    cin >> n;
    VI a(n);
    REP(i,n){
        cin >> a[i];
    }

    if(accumulate(ALL(a),0LL)%(n*(n+1)/2)!=0){
        cout << "NO" << endl;
        return 0;
    }

    int t = accumulate(ALL(a),0LL)/(n*(n+1)/2);

    VI sa(n,0);
    sa[0] = a[0]-a[n-1];
    FOR(i,1,n){
        sa[i] = a[i]-a[i-1];
    }

    REP(i,n){
        sa[i] -= t;
        sa[i] = -sa[i];
        if(sa[i]<0){
            cout << "NO" << endl;
            return 0;
        }
    }

    int c=0;
    REP(i,n){
        if(sa[i]%n!=0){
            cout << "NO" << endl;
            return 0;
        }
        c+=sa[i]/n;
    }


    if(c==t){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 2424
#include <bits/stdc++.h>
using namespace std;
 
/*てんぷれぞーん！*/
struct edge {int to,cost;};
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
typedef vector<edge> VE;
//static const int INF = 2147483647;
static const int INF = 1000000000;
static const long long llINF = 9223372000000000000;
static const int NIL = -1;
static const int MOD = 1000000007;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define np next_permutation
#define pq priority_queue
/* t y p o っ て 知 っ て る ゥ ！ ？ */
#define itn int
#define scnaf scanf
#define reutnr return
#define scamf scanf
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
//#define int ll
//#define INF llINF

const int NMAX = 120;
 
int n,m;    //nが頂点の数、mが辺の数
bool rinsetsu[NMAX][NMAX];    //最後に使うよ
int d[NMAX][NMAX];      //WF用テーブル
int previous[NMAX][NMAX];   //previous[i][j]はiからjへの最短路におけるjの手前の頂点

void WF(){
    for(int k=0;k<n;k++){
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                if(d[i][j]>d[i][k]+d[k][j]){
                    d[i][j] = d[i][k] + d[k][j];
                    previous[i][j] = previous[k][j];
                }
            }
        }
    }
}

void delete_path(int start,int goal){
    VI path;
    int via=0,current;
    for(current=goal;current!=start;current=previous[start][current]){
        path.pb(current);
    }
    path.pb(start);

    for(int i=0;i<path.size()-1;i++){
        rinsetsu[path[i]][path[i+1]] = rinsetsu[path[i+1]][path[i]] = false;
    }
}

void debug(){
    printf("\n");
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++) printf("%d ",d[i][j]);
        printf("\n");
    }
    printf("\n");
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++) printf("%d ",previous[i][j]);
        printf("\n");
    }
    printf("\n");
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++) printf("%d ",rinsetsu[i][j]);
        printf("\n");
    }
    printf("\n");
}

void initializer(){
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++) d[i][j] = INF;
    }
    memset(rinsetsu,false,sizeof(rinsetsu));
    for(int i=0;i<NMAX;i++) d[i][i] = 0;
    for(int i=0;i<NMAX;i++){
        for(int j=0;j<NMAX;j++) previous[i][j] = i;
    }
}

signed main(){
    scanf("%d%d",&n,&m);

    initializer();  //初期化

    for(int i=0;i<m;i++){
        int tmp1,tmp2,tmp3;
        scanf("%d%d%d",&tmp1,&tmp2,&tmp3);
        tmp1--; tmp2--;
        rinsetsu[tmp1][tmp2] = rinsetsu[tmp2][tmp1] = true;
        d[tmp1][tmp2] = d[tmp2][tmp1] = tmp3;
    }
    //debug();

    WF();

    //debug();

    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++) delete_path(i,j);
    }

    int ans = 0;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(rinsetsu[i][j]) ans++;
        }
    }
    //debug();

    printf("%d\n",ans/2);
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>
using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    cout << ((n-m)*100 + m *1900) * pow(2,m) << endl;
    return 0;
}


Measured memory_bytes: 256
/*
[ ( ^ _ ^ ) ]
*/
// problem: atc/abc165_c
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1000000000

int n, m, q;
ll rs = 0;
vector<vector<int>> con(60, vector<int>(4));
vector<int> a(15);
int c = 0;

void dfs(int last, int idx) {
    if(idx>n) {
        c++;
        ll s = 0;
        for(int i=0; i<q; i++) {
            if(a[con[i][1]] - a[con[i][0]] == con[i][2]) {
                s += con[i][3];
            }
        }
        rs = max(rs, s);
        return;
    }
    for(int i=last; i<=m; i++) {
        a[idx] = i;
        dfs(i, idx+1);
    }
}

int main() {
    scanf("%d%d%d", &n, &m, &q);
    for(int i=0; i<q; i++) {
        scanf("%d %d %d %d", &con[i][0], &con[i][1], &con[i][2], &con[i][3]);
    }
    rs = 0;
    c = 0;
    for(int i=1; i<=m; i++) {
        a[1] = i;
        dfs(i, 2);
    }
    // cout << "c=" << c << endl;
    printf("%lld\n", rs);
}


Measured memory_bytes: 3768
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

const ll MOD = 1e9+7;

const ll MAX_A = 1000100;

ll fac[MAX_A]; // 最小公倍数の指数表記

ll power(ll a, ll r){
  
  if( r == 0 ){ return 1LL;}
  else if( r == 1 ){ return a;}
  else{
    if( r % 2 == 0 ){ return ( power(a,r/2)*power(a,r/2) )%MOD;}
    else{  return  (( (power(a,(r-1)/2 ) * power(a, (r-1)/2 ) ) % MOD ) * a ) % MOD;}
    
  }
  
  
}

void prime_factors(ll a ){
  
  for(ll j = 2; j < (ll)sqrt(MAX_A); j++){
    
    ll cnt = 0;
    
    while( a % j == 0 ){ a /= j; cnt++;}
    
    fac[j] = max(fac[j],cnt);
    
  }
  
  if( a != 1){ fac[a] = 1;
              
             }
  
  
  return ;
  
}


int main(){ 
  
  ll N; cin >> N;
  vector<ll> A(N);
  
  ll s = 1LL; // 最小公倍数%MODを求める
  
  for(ll i = 0; i < N; i++){ 
    cin >> A[i];
    
    prime_factors(A[i]);
    
    
  }
  
  for(ll i = 2; i < MAX_A; i++){ 
    
    s *= power(i,fac[i]);
    
    s %= MOD; // 最小公倍数%MODを計算
    
  }
  
  ll ans = 0;
  
  for(ll i = 0; i < N; i++){
    
    ans += s*power(A[i],MOD-2);
    ans %= MOD;
  }
  
  cout << ans << endl;
  
  return 0;
} 
  

Measured memory_bytes: 6656
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const long long mod = 1000000007LL;

pair<int,int> f(int r, int l) {
  int sr = 0;
  int sl = 0;
  sr += (r+1)/2;
  sl += r/2;
  sr += l/2;
  sl += (l+1)/2;
  return make_pair(sr,sl);
}

int main() {
  string s;
  cin >> s;
  int n = s.size();
  vi v;
  v.push_back(-1);
  rep(i,n-1) {
    if(s[i]=='R' && s[i+1]=='L') v.push_back(i);
    if(s[i]=='L' && s[i+1]=='R') v.push_back(i);
  }
  v.push_back(n-1);
  vi len;
  rep(i,v.size()-1) len.push_back(v[i+1]-v[i]);
  vi zahyo;
  int sum = -1;
  rep(i,len.size()) {
    sum += len[i];
    zahyo.push_back(sum);
  }
  vi ans(n);
  for(int i = 0; i<len.size()-1; i+=2) {
    pair<int,int> p = f(len[i],len[i+1]);
    int r = p.first;
    int l = p.second;
    ans[zahyo[i]] = r;
    ans[zahyo[i]+1] = l;
  }
  rep(i,n) {
    cout << ans[i];
    if(i!=n-1) cout << " ";
    else cout << endl;
  }
  return 0;
}

Measured memory_bytes: 2424
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int, W: "List[str]"):
    if N != len(set(W)):
        print(NO)
        exit()

    for i in range(1, len(W)):
        if W[i-1][-1] != W[i][0]:
            print(NO)
            exit()
    print(YES)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    W = [next(tokens) for _ in range(N)]  # type: "List[str]"
    solve(N, W)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

def main():
    N = int(input())
    A = list(map(int, input().split()))
    A = sorted(A, reverse=True)
    ans = 0
    h = [-A.pop(0)]
    for a in A:
        t = heappop(h)
        ans += -t
        heappush(h,-a)
        heappush(h,-a)
    #ans += -heappop(h)
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 32888
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        for(int i=1; ;i++){
            int x = sc.nextInt();
        if(x == 0){
            break;
        }else{
            System.out.printf("Case %d: %d\n",i,x);
        }
        }  
        sc.close();
    }    
}


Measured memory_bytes: 65084
#include <stdio.h>
int main(int argc, char const *argv[]){
	int i=-1,x=0,f=0;
	char s[8];
	scanf("%s",s);
	while(s[++i]!='\0'){
		if(i!=0)x*=10;
		x+=s[i]-'0';
		f+=s[i]-'0';
	}
	printf("%s",(x%f==0)? "Yes":"No");
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long int
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define rep(i,a,n)   for(int i=a;i<n;i++)
#define pb           push_back
#define ff           first
#define ss           second
#define lcm(a, b)    ((a)*((b)/gcd(a,b)))
#define all(v)       v.begin(),v.end()
#define rall(v)      v.rbegin(),v.rend()
#define Pi           2*acos(0.0)
#define pii          pair<int,int>
#define pll          pair<ll,ll>
#define mem(a,b)     memset(a, b, sizeof(a))
#define fill_(a,b)   fill(a,a+n,b);
using namespace std;

ll expo(ll a,ll b,ll m = mod){
	a%=mod;
	ll res = 1;
	while(b){
		if(b&1)
			res = (res*a)%m;
		a = (a*a)%m;
		b>>=1;
	}
	return res;
}
ll gcd(ll a,ll b){
	while(b>0){
		ll r = a%b;
		a = b; b = r;
	}
	return a;
}
int main()
{
	 
   boost
   #ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	int t=1;
// 	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		ll A[n];
		ll sum = 0;
		for(int i=0;i<n;i++){
    		cin>>A[i];
    		sum+=A[i];
		}
		if(n==1){
		    cout<<A[0]<<"\n";
		    return 0;
		}
		ll dp1[n][n] , dp2[n][n];
		mem(dp1,0);
		mem(dp2,0);
		for(int i=0;i<n-1;i++){
		    dp1[i][i] = dp2[i][i] = A[i];
		    dp1[i][i+1] = max(A[i],A[i+1]);
		    dp2[i][i+1] = min(A[i],A[i+1]);
		}
		for(int l=3;l<=n;l++){
		    for(int i=0;i<=n-l;i++){
		        int j = i+l-1;
		        dp1[i][j] = max(A[i]+dp2[i+1][j],A[j]+dp2[i][j-1]);
		        dp2[i][j] = min(dp1[i+1][j],dp1[i][j-1]);
		    }
		}
		
		cout<<2*dp1[0][n-1]-sum<<"\n";
	}
    return 0;
}


Measured memory_bytes: 144136
n,W=map(int,input().split())
w=[]
v=[]
for i in range(n):
  w_,v_=map(int,input().split())
  w.append(w_)
  v.append(v_)
dp=[[0]*(W+1) for i in range(n)]
for i in range(n):
  for j in range(W+1):
    if j-w[i]>=0:
      dp[i][j]=max(dp[i-1][j-w[i]]+v[i],dp[i-1][j])
    else:
      dp[i][j]=dp[i-1][j]
print(dp[n-1][W])

Measured memory_bytes: 149628
#include <bits/stdc++.h>
using namespace std;
typedef pair<char, int> P;
vector<P> c(26);
vector<char> in(100);
int n;

int main() {
  while(cin >> n && n != 0) {
    for(int i = 0; i < 26; i++) c[i].first = 'A' + i;
    for(int i = 0; i < n; i++) cin >> in[i];
    for(int i = 0; i < 26; i++) c[i].second = 0;

    for(int i = 0; i < n; i++) {
      c[(int)(in[i] - 'A')].second++;
      vector<P> check = c;
      sort(check.begin(), check.end(), [](const P &l,const P &r){
	  return l.second > r.second;});
      // for(int i = 0; i < 26; i++) {
	// cout << check[i].first << " " << check[i].second << " ";
      // }
      // cout << endl;
	
      if(check[0].second - check[1].second > n - (i + 1)) {
	cout << check[0].first << " " << i + 1 << endl;
	goto END;
      }
    }
  sort(c.begin(), c.end(), [](const P &l,const P &r){ return l.second > r.second;});
    if(c[0].second == c[1].second) cout << "TIE" << endl;      
    else cout << c[0].first << " " << n << endl;
  END:;
  }
}

Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }

int n;
vector<vector<int>> g;
map<pair<int,int>,int> mp;
void dfs(int x,int pre,int col){

    int cnt=0;
    for(auto nxt:g[x])if(nxt!=pre){
        if(cnt==col) cnt++;
        mp[make_pair(min(x,nxt),max(x,nxt))]=cnt;
        //cout<<x<<' '<<nxt<<' '<<cnt<<endl;
        dfs(nxt,x,cnt);
        cnt++;
    }
}


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

    cin>>n;
    // とりあえず一番生えてるでやる
    g.resize(n);
    vector<pair<int,int>> vec(n-1);
    rep(i,n-1){
        int u,v;cin>>u>>v;u--,v--;
        g[u].push_back(v);
        g[v].push_back(u);
        vec[i]=make_pair(u,v);
    }

    int ed=0;
    rep(i,n){
        chmax(ed,(int)(g[i].size()) );
    }

    dfs(0,-1,-1);
    cout<<ed<<endl;
    rep(i,n-1){
        cout<<1+mp[vec[i]]<<endl;
    }
    return 0;
}


Measured memory_bytes: 13184
sd = input()
T = input()
answer = []
if len(sd) < len(T):
    print('UNRESTORABLE')
    exit(0)
for i in range(len(sd)-len(T)+1):
    s = sd
    for j in range(len(T)):
        if sd[i+j] == T[j] or sd[i+j] == '?':
           s = s[:i+j] + T[j] + s[i+j+1:]
        else:
            break 
    else:
        answer.append(s.replace('?', 'a'))
if len(answer) == 0:
    print('UNRESTORABLE')
else:
    print(sorted(answer)[0])

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const int INF=1e7;
const LL LINF=1e18;

int main(){
    int N;
    string s,t;
    cin >> N >> s >> t;
    for(int i=0;i<s.length();i++){
        for(int j=0;j<s.length()-i;j++){
            if(s[i+j]!=t[j]) break;
            if(j==s.length()-i-1){
                cout << N+i << endl;
                return 0;
            }
        }
    }
    cout << 2*N << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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 <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    ll sum = 0;
    ll N;
    cin >> N;
    for (long long i = 0; i <= N; i++)
    {
        if (i % 15 == 0)
        {
        }
        else if (i % 3 == 0)
        {
        }
        else if (i % 5 == 0)
        {
        }
        else
        {
            sum += i;
        }
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 3652
using System;

namespace ITP1_5_A
{
    class Program
    {
        static void Main(string[] args)
        {
            while(true)
            {
                string[] str = Console.ReadLine().Trim().Split(' ');
                int H = int.Parse(str[0]);
                int W = int.Parse(str[1]);

                if(H==0 && W==0) break;
                    
                for(int i=0; i<H; i++)
                {
                    for(int j=0; j<W; j++)
                    {
                        Console.Write("#");
                    }
                    Console.WriteLine();
                }
                Console.WriteLine();
            }
        }
    }
}



Measured memory_bytes: 13936
import java.util.*;

public class Main {
	static ArrayList[] graph;
	public static void main(String[] args) {
		Scanner s=new Scanner(System.in);
		int size=Integer.parseInt(s.next());
		int edges=Integer.parseInt(s.next());
		graph=new ArrayList[size];
		for(int i=0;i<size;i++)
			graph[i]=new ArrayList<Integer>();
		int[] indegree=new int[size];
		for(int i=0;i<edges;i++)
		{
			int source=s.nextInt();
			int dest=s.nextInt();
			graph[source-1].add(dest-1);
			indegree[dest-1]++;
			
		}
		Queue<Integer> Q=new LinkedList<>();
		for(int i=0;i<indegree.length;i++)
			if(indegree[i]==0)
				Q.add(i);
		int[] dist=new int[size];
		while(!Q.isEmpty())
			DFS(Q.poll(),dist,indegree);
		int ans=0;
		for(int d:dist)
			ans=Math.max(ans, d);
		System.out.println(ans);
		s.close();
	}
	static void DFS(int v,int[] dist,int[] indegree)
	{
		for (Integer e : (ArrayList<Integer>) graph[v]) {
			dist[e]=Math.max(dist[e], dist[v]+1);
			indegree[e]--;
			if (indegree[e] == 0)
				DFS(e,dist,indegree);
		}
	}
}


Measured memory_bytes: 112980
L   = list(input())
dp  = [[0 for _ in range(2)] for _ in range(100005)]
MOD = 10**9+7

dp[0][0] = 1

for i,l in enumerate(L,1):
  if l=='1':
    dp[i][0] = dp[i-1][0]*2 % MOD
    dp[i][1] = (dp[i-1][0] + dp[i-1][1]*3) % MOD
  else:
    dp[i][0] = dp[i-1][0]
    dp[i][1] = dp[i-1][1]*3 % MOD

print((dp[i][0] + dp[i][1]) % MOD)

Measured memory_bytes: 21928
import java.util.Scanner;

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

        while(true){
            int num = sc.nextInt();
            if(num==0){
                break;
            }

            System.out.println("Case " + i + ": " + num);
            i++;
        }
    }
}


Measured memory_bytes: 42908