akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int (i)=0; (i)<(n); ++(i))
#define rrep(i,n) for(int (i)=(1); (i)<=(n); ++(i))
#define all(x) ((x).begin(), (x).end())
#define maxa(a,b) ((a)=max((a),(b)))
#define mina(a,b) ((a)=min((a),(b)))
#define pb push_back
#define sz(x) ((int)x.size())
#define vT(T) vector<T>
#define vvT(T) v(v(T))

using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;

// helpers
template<typename T>inline istream& operator>>(istream&i,vT(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const vT(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const vT(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const vT(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}

int a,b,c;

void read() {
    cin>>a>>b>>c;
}

void solve() {
//    if (a == b and b == c) {
//        cout << "-1\n";
//        return;
//    }

    ll cnt = 0, same = 0;
    int x, y, z;
    while (!(a&1) and !(b&1) and !(c&1)) {
        x = a/2;
        y = b/2;
        z = c/2;

        a = y + z;
        b = x + z;
        c = x + y;

        if (same > 1) {
            cnt = -1;
            break;
        }
        if (a == b and b== c){
            ++same;
        } else {
            same = 0;
        }

        ++cnt;
    }
    cout << cnt << endl;
}

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

    read();
    solve();

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) ((int)(x).size())
#define whole(x) (x).begin(), (x).end()
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
 
const int N = int(2e5) + 2;
const int LG = 20;
const ll mod = (int)1e9 + 7;
const int INF = (int)1e9 + 7;
const ll linf = 1e18; 
const ld pi = acos(-1);
const int base = 10;
const ld EPS = 1e-9;


int n, a[1005][1005], enemy[2005], Next[2005], res[2005];
int main (){
    scanf ("%d", &n);
    for (int i = 1; i <= n; ++i){
        for (int j = 1; j <= n - 1; ++j){
            scanf ("%d", &a[i][j]);
        }
        enemy[i] = a[i][1];
        Next[i] = 1;
    } 
    queue < int > q;
    for (int i = 1; i <= n; ++i){
        if (enemy[enemy[i]] == i) q.push(i);
    }
    int cnt = 0, ans = 0;
    while (!q.empty()){
        int v = q.front();
        q.pop();
        if (enemy[enemy[v]] != v) continue;
        ++cnt;
        int p = enemy[v];
        int r = max(res[v], res[p]) + 1;
        ans = max(ans, r);
        res[v] = res[p] = r;
        Next[v]++, Next[p]++;
        if (Next[v] != n){
            enemy[v] = a[v][Next[v]];
            if (enemy[enemy[v]] == v) q.push(v);
        }
        if (Next[p] != n){
            enemy[p] = a[p][Next[p]];
            if (enemy[enemy[p]] == p) q.push(p);
        }
    }
    if (cnt != (n * (n - 1)) / 2) return !printf ("-1\n");
    printf ("%d\n", ans);
}

Measured memory_bytes: 4224
MAX = 1e6.to_i

tetra = (1..1/0.0).lazy.map{ |n| n * (n + 1) * (n + 2) / 6 }.take_while{ |n| n < MAX }.to_a.reverse

def tabulate(tetra, dp)
  tetra.each do |t|
    (0...MAX - t).each do |i|
      dp[t + i] = dp[i] + 1 if dp[i] + 1 < dp[t + i]
    end
  end
end

dp = [MAX] * MAX
dp_odd = [MAX] * MAX
dp[0] = 0
dp_odd[0] = 0
tabulate(tetra, dp)
tabulate(tetra.select{ |n| n.odd? }, dp_odd)
while (n = gets.to_i) != 0
  puts [dp[n], dp_odd[n]].join(' ')
end

Measured memory_bytes: 24288
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int N = scanner.nextInt();
			int K = scanner.nextInt();

			// input
			List<Integer> integers = new ArrayList<Integer>();
			for (int i = 0; i < N; i++) {
				integers.add(scanner.nextInt());
			}

			// 長さの最大値
			System.out.println(bouMaxLength(integers, K));
		}
	}

	private static int bouMaxLength(List<Integer> integers, int bouNum) {
		int sum = 0;
		Collections.sort(integers, Comparator.reverseOrder());

		for (int i = 0; i < bouNum; i++) {
			sum += integers.get(i);
		}
		return sum;
	}
}

Measured memory_bytes: 23380
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残さない
//数値計算 基本はdouble
//map<キー,値> p は辞書。p[キー] = 値
#include <bits/stdc++.h>
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// Nの桁数
ll dig(ll N) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= 10;
	}
	return dig;
}
// x,yの最大公約数
ll gcd(ll x, ll y) {
	ll r;
	while (x%y) {
		r = x % y;
		x = y;
		y = r;
	}
	return y;
}   // 


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

	for (int i = 0; i < N; i++) {
		if (A[i] % 2 == 0) {
			if (A[i] % 3 != 0 && A[i] % 5 != 0) {
				cout << "DENIED" << endl;
				return 0;
			}
		}
	}

	cout << "APPROVED" << endl;
}

Measured memory_bytes: 256
def sinsuuton(X, n): #10進数の Xをn進数に
    if (int(X/n)):
        return sinsuuton(int(X/n), n)+str(X%n)
    return str(X%n)
def sinsuutoo10(X,n): #n進数のX(str)を10進数に
    return sum([ X[-i-1]*n**i for i in range(len(X)) ])
n=int(input())
ans=float("inf")
for i in range(n+1):
    t=i
    now=0
    t6= sinsuuton(t, 6)
    now+= sum([int(i) for i in t6])
    t=n-i
    t9= sinsuuton(t, 9)
    now+= sum([int(i) for i in t9])
    ans=min(ans,now)

print(ans)


Measured memory_bytes: 9212
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll,ll> P;

ll ans = LLINF;
void dfs(ll now, ll cou, ll a, ll b, ll sum){
	if(a <= 0)return;
	if(ans < now)return;
	if(cou == 41){
		ans = min(ans, now);
		return;
	}
	ll A = (a >> cou) & 1;
	ll B = (b >> cou) & 1;
	ll C = (sum >> cou) & 1;
	if((A + B + C) % 2)return;

	ll tmp = (1LL << cou);
	dfs(now, cou+1, a, b, sum);
	dfs(now + tmp, cou+1, a - tmp, b + tmp, sum);
}

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

	ll n;cin >> n;
	vector<ll> v(n);REP(i, n)cin >> v[i];
	ll sum = 0;
	for(ll i = 2;i < n;i++)sum ^= v[i];

	dfs(0, 0, v[0], v[1], sum);
	if(ans < v[0]){
		cout << ans << endl;
	}
	else{
		cout << -1 << endl;
	}

	return 0;
}


Measured memory_bytes: 3612
#include<iostream>
using namespace std;
int main(void)
{
  int N;
  int val;
  int odd=0;
  int inp1[100],inp[100];
  cin>>N;
  
  for(int i=1;i<=N;i++)
  {
   cin>>val;
    inp[i]=i;
    inp1[i]=val;
    if(i%2!=0 && val%2!=0 )
    {
      odd++;
    }
  }
  
  cout<<odd;
}

Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#define INF 1.0e9
using namespace std;
typedef long long ll;

int R, G, B, N;
int ans = 0;

int main() {
    cin >> R >> G >> B >> N;
    for (int r = 0; r < N/R + 1; r++) {
        for (int g = 0; g < N/G + 1; g++) {
            int b = (N - R*r - G*g) / B;
            if (b >= 0 && b*B == N - R*r - G*g) {
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 888
//060A
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string a, b, c= " "; //stringの末尾はヌルが格納されている
    cin >> a >> b >> c;  //.length要素数 .back:末尾
    if (a.back() == b[0] and b.back() == c[0]){
        cout << "YES";
    }else{
        cout << "NO";
    }
    
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF =1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define trep(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
int main(){
    string s;
    cin >> s;
    cout<<count(s.begin(),s.end(),'1')<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <string.h>
main(){char x[105];int h=0,i,j,w=0;while(scanf("%s",x)!=-1){int c=strlen(x);for(i=0;i<c/2;i++){if(x[i]!=x[c-1-i])w=1;
}if(w==0){h++;}w=0;}printf("%d\n",h);return 0;} 

Measured memory_bytes: 540
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{

  ll n;
  cin>>n;
  ll arr[n+5]={0};
  for(int i=0;i<n;i++)
  {
      cin>>arr[i];
  }
  ll cnt=0;
  ll ans=INT_MIN;
  for(int i=0;i<n-1;i++)
  {
      if(arr[i]>=arr[i+1])
      {
          cnt++;
          ans=max(ans,cnt);
      }
      else
      {
          ans=max(ans,cnt);
          cnt=0;
      }
  }
  ans=max(ans,cnt);

  cout<<ans<<endl;

}










Measured memory_bytes: 4360
#include<bits/stdc++.h>
using namespace std;
void solve(){
    string str;
    cin>>str;
    for(int i=0;i<str.length();i++){
        if(str[i]=='?')
        cout<<'D';
        else
        cout<<str[i];
    }
}
int main(){
    int T=1;
    //cin>>T;
    while(T--){
        solve();
    }
    return 0;
}

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

int main() {
  int N;
  int K;
  cin>>N>>K;
  int ans = 0; 
  for(int i=0; i<N; i++){
    int h;
    cin>>h;
    if(h>=K){
      ans+=1;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using lli = long long;
#define rep(i,n) for(int i=0;i<n;i++)
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; }

lli n, q, k;
vector<vector<pair<lli, lli>>> g;
vector<lli> dist;
vector<lli> x, y;

void dfs(lli x, lli d){
    dist[x] = d;
    for(auto i : g[x]){
        if(dist[i.second] >= 0) continue;
        dfs(i.second, lli(dist[x]+i.first));
    }
}

int main(void){
    cin >> n;
    g.resize(n);
    dist.assign(n, -1);
    rep(i, n-1){
        lli a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        g[a].push_back({c, b});
        g[b].push_back({c, a});
    }
    cin >> q >> k;
    k--;
    x.resize(q);
    y.resize(q);
    rep(i, q){
        cin >> x[i] >> y[i];
        x[i]--;
        y[i]--;
    }
    dist[k] = 0;
    dfs(k, 0);
    rep(i, q){
        cout << dist[x[i]]+dist[y[i]] << endl;
    }
    return 0;
}


Measured memory_bytes: 15564
#include <stdio.h>

int main() {
	int A;
	int B = 2; 
	scanf("%d", &A);
	
	if(A % B == 0) {
	printf("%d\n", A/B);
	}
	
	else
	printf("%d\n", (A/B)+1);
	
	return 0;
}

Measured memory_bytes: 1720
/**
 * @file a.cpp
 * @brief A - Regular Triangle
 * @version 0.1
 * 
 * @copyright Copyright (c) 2019
 * 
 */

#include <iostream>
using namespace std;

/**
 * @brief Entry point
 * 
 * @return int 
 */
int main()
{
    // 三辺の長さが A, B, C
    // であるような正三角形が存在するなら Yes を
    // そうでなければ No を出力せよ。
    int A, B, C;
    cin >> A >> B >> C;

    if (A == B && A == C)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}


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

typedef long long ll;

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

  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ans += min(a[i], b[i]);
    b[i] -= min(a[i], b[i]);
    ans += min(a[i + 1], b[i]);
    a[i + 1] -= min(a[i + 1], b[i]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
s=input()
ls=[c for c in s]
ct=0
j=0
for i in range(len(ls)):
    if ls[i]==ls[j]:
        if (i-j)%2!=0 and i-j!=0 and i-j!=1 and i!=len(ls)-1:
            ct+=int((i-j-1)/2)+1
            ls[i]=ls[j+1]
            j=i
        elif (i-j)%2!=0 and i-j!=0 and i-j!=1 and i==len(ls)-1:
            #print(i,j)
            ct+=int((i-j-1)/2-1)
        elif (i-j)%2==0 and i-j!=0 and i-j!=2:
            ct+=int((i-j)/2-1)
            j=i
            #print(i,j)
        elif i-j==1:
            ct+=1
            if ls[i]=='0':
                ls[i]='1'
            else:
                ls[i]='0'
            j=i
        elif i-j==2:
            j=i
            
        else:pass
if j<len(ls)-2:
    if (len(ls)-1-j)%2==0:
        ct+=int((len(ls)-1-j)/2)
    else:
        ct+=int((len(ls)-2-j)/2)
print(ct)

Measured memory_bytes: 4092
from math import factorial
n, m = map(int, input().split())
c_n = factorial(n) / (factorial(2) * factorial(n - 2)) if n > 1 else 0
c_m = factorial(m) / (factorial(2) * factorial(m - 2)) if m > 1 else 0
ans = int(c_n) + int(c_m)
print(ans)

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
#include <string>
#include <algorithm>
#define ll long long
int a[10001];
bool com(int a,int b)
{
	return a>b;
}
int main()
{
	ll n;
	cin>>n;
	if(n<=6)
	{
		cout<<"1";
		return 0;
	}
	if(n%11==0)
	{
		n=n/11*2;
	}
	else
	{
		int m=n%11;
		if(m<=6)
		{
			n=n/11*2+1;
		}
		else
		{
			n=n/11*2+2;
		}
	}
	cout<<n;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long int a,b,c,d;
    cin>>a>>b>>c>>d;
    long long int a1,a2,a3,a4;
    a1 = a*c;
    a2 = a*d;
    a3 = b*c;
    a4 = b*d;
    long long int ans = max(a1,max(a2,max(a3,a4)));
    cout<<ans;
}


Measured memory_bytes: 3612
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;

int main ()
{
	int n,i,ans=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		int t;
		scanf("%d",&t);
		ans+=t-1;
	}
	printf("%d\n",ans);
	return 0;
}

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

using namespace std;


#define mod(cans) cans%10**9+7
#define cin_pl(x,y) for(int i=0;i<x;i++){cin>>y[i];}
#define pl_twin(x,y,z) for(int i=0;i<x;i++){cin>>y[i]>>z[i];}
#define debug(x) cout << "Debug" << x << "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define st(s) size_t size = s.length()
#define prians(Answer) cout<<Answer<<"\n"
#define make_pair mp;
#define com_div(x,Co) for(int i=1;i<x+1;i++){if(x%i==0){Co++;}}
#define TF(X) X==1?cout<<"Yes\n":cout<<"No\n"
#define elcon else{continue;}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<vector<int>> matrix;
typedef pair<int,int> pr;
typedef vector<pr> vpt;
typedef greater<int> gi;

int main()
{
    string s;
    cin>>s;
    int count=0;
    size_t size = s.length();
    rep(i,size)
    {
        if(s[i]=='x')
        count++;
    }
    count>=8?cout<<"NO":cout<<"YES";


}

Measured memory_bytes: 256
#include <iostream>
#include <cstdint>
#include <string>
#include <cmath>

using namespace std;

int main() {
  int64_t N;
  cin >> N;
  if (N % 2) {
    cout << 0 << endl;
  } else {
    int64_t res = 0;
    int64_t i = 1;
    while (0 < N) {
      N = N / 5;
      res += N / 2;
    }
    cout << res << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python

import sys

MOD=10**9 + 7

def Add(n,m):
    return (n+m)%MOD

def Sub(n,m):
    return (n-m)%MOD

def Mul(n,m):
    return (n*m)%MOD

def Pow(n,p):
    if p<0: return Pow(n,  ( p % ( MOD-1 ) ) )
    elif p==0: return 1
    elif p==1: return n
    elif p%2==0:
        tmp= Pow( n,(p//2) ) % MOD
        return tmp**2 % MOD
    else:
        tmp= Pow( n,(p//2) ) % MOD
        return ( n * tmp**2 ) % MOD
    #
    raise ValueError

def Div(n,m):
    return ( n * Pow(m,MOD-2) ) % MOD
#
#::::::::::::::::::::::::::::::::::::::::::::::::::
n,a,b,c = [ int(x) for x in sys.stdin.readline().split() ]
#
h= Div(1,100)
pa= Mul(a,h)
pb= Mul(b,h)
cc= Div( 1,Mul(100-c,h) )
# power of n
cn= Pow(cc,n+1)
t = Mul(cn,n)
an= Mul(Pow(pa,n),t)
bn= Mul(Pow(pb,n),t)
# for A
pam= bn
pac= Mul(pa,cc)
# for B
pbm= an
pbc= Mul(pb,cc)
# permutation
mbar = n
perm= [1]*n
for m in range(1,n):
    mbar-=1
    perm[m]= Mul(perm[m-1],mbar)
perm.reverse()
nfact= perm[0]
#
ret= 0
ncm= 1
for m in range(n):
    if m>0:
        ncm= Mul(ncm,n+m)
        pam= Mul(pam,pac)
        pbm= Mul(pbm,pbc)
    #
    ret= ( ret + Mul(Mul(ncm,pbm+pam),perm[m]) ) % MOD
#
print( Div(ret,nfact) )


Measured memory_bytes: 7028
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;

namespace ConsoleApp23
{
    class Program
    {
        private static string[,] _board;
        private static int _h;
        private static int _w;

        static void Main(string[] args)
        {
            var line = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            _h = line[0];
            _w = line[1];
            _board = new string[_h, _w];

            for (int i = 0; i < _h; i++)
            {
                var line2 = Console.ReadLine();
                for (int j = 0; j < _w; j++)
                {
                    var drawString = line2[j].ToString();
                    if (drawString == ".")
                    {
                        _board[i, j] = _board[i, j] ?? "0";
                    }
                    else if (drawString == "#")
                    {
                        _board[i, j] = "#";
                        DrawPoint(i, j);
                    }
                }
            }

            for (int i = 0; i < _h; i++)
            {
                for (int j = 0; j < _w; j++)
                {
                    Console.Write(_board[i, j]);

                    if(j == _w - 1)
                    {
                        Console.WriteLine("");
                    }
                }
            }

        }

        static void DrawPoint(int rowPoint, int colPoint)
        {
            for (int i = rowPoint - 1; i <= rowPoint + 1; i++)
            {
                if(i < 0 || i >= _h)
                {
                    continue;
                }

                for (int j = colPoint - 1; j <= colPoint + 1; j++)
                {
                    if (j < 0 || j >= _w)
                    {
                        continue;
                    }

                    int p;
                    if (int.TryParse(_board[i, j], out p))
                    {
                        _board[i, j] = (p + 1).ToString();
                    }
                    else
                    {
                        _board[i, j] = _board[i, j] ?? "1";
                    }
                }
            }
        }

    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
const int N=2010,MD=1e9+7;
int v[N],f[N];
int Pow(int x,int y)
{
    int ans=1;
    for(;y;x=x*1LL*x%MD,y>>=1)if(y&1)ans=1LL*ans*x%MD;
    return ans;
}
int main()
{
    int n,k,tot=0,ans=0,i;
    cin>>n>>k;
    for(i=1; i*i<n; i++)
        if(n%i==0)v[tot++]=i,v[tot++]=n/i;
    if(i*i==n)v[tot++]=i;
    sort(v,v+tot);
    for(int i=0; i<tot; i++)
    {
        f[i]=Pow(k,(v[i]+1)/2);
        for(int j=0; j<i; j++)if(v[i]%v[j]==0) f[i]=(f[i]-f[j])%MD;
        if(v[i]&1) ans=(ans+1LL*v[i]*f[i])%MD;
        else ans=(ans+v[i]*1LL*Pow(2,MD-2)%MD*f[i])%MD;
    }
    cout<<(ans+MD)%MD;
}


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

int N, K;
vector<ll> A;
int neg_l, neg_r, pos_l, pos_r;
ll zero_cnt;

void add(ll& cnt, int idx, int l, int r, ll mid) {
    if (l > r or l < 0 or r < 0) return;
    bool fl = A[idx] * A[l] < mid;
    bool fr = A[idx] * A[r] < mid;
    /* */if (fl and fr) cnt += r - l + 1;
    else if (fl or fr) {
        int ok = fl ? l : r, ng = fl ? r : l;
        while (abs(ok - ng) > 1) {
            int m = (ok + ng) >> 1;
            ((A[idx] * A[m] < mid) ? ok : ng) = m;
        }
        cnt += fl ? ok - l + 1 : r - ok + 1;
    }
}

bool check(ll mid) {
    ll cnt = 0;
    if (neg_l != -1) FOR(i, neg_l, neg_r + 1) {
        add(cnt, i, i + 1, neg_r, mid);
        add(cnt, i, pos_l, pos_r, mid);
    }
    if (pos_l != -1) FOR(i, pos_l, pos_r + 1) {
        add(cnt, i, i + 1, pos_r, mid);
    }
    if (mid > 0) cnt += (zero_cnt * (zero_cnt - 1) >> 1) + zero_cnt * (N - zero_cnt);
    return cnt < K;
}

signed main() {

    cin >> N >> K;

    A.resize(N);
    REP(i, N) cin >> A[i];
    sort(A.begin(), A.end());

    // [l, r]
    neg_l = neg_r = pos_l = pos_r = -1;
    REP(i, N) {
        /* */if (A[i] < 0) { neg_r = i; if (neg_l == -1) neg_l = i; }
        else if (A[i] > 0) { pos_r = i; if (pos_l == -1) pos_l = i; }
        else ++zero_cnt;
    }

    ll ok = -(ll)1e18 - 1, ng = (ll)1e18 + 1;
    while (abs(ok - ng) > 1) {
        ll mid = (ok + ng) >> 1;
        (check(mid) ? ok : ng) = mid;
    }
    cout << ok << endl;

}

Measured memory_bytes: 1792
#include  <bits/stdc++.h>
using namespace std;
int main(){
    long long H, W, K;
    cin >> H >> W >> K;
    vector<vector<char>> s(H, vector<char> (W));
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++) cin >> s[i][j];
    }
    long long ans = 1e18;
    for(int bit = 0; bit < (1 << (H - 1)); bit++){
        vector<int> slit(H - 1, 0);
        long long count = 0;
        for(int i = 0; i < (H - 1); i++){
            if(bit & (1 << i)) {
                slit[i] = 1;
                count++;
            }
        }
        int t = count + 1;
        vector<vector<int>> ko(t, vector<int> (W, 0));
        for(int i = 0; i < W; i++){
            int u = 0;
            for(int j = 0; j < H; j++){
                if(s[j][i] == '1') ko[u][i]++;
                if(j < H - 1 && slit[j] == 1) u++;
            }
        }
        vector<int> ko2(t, 0);
        int flag = 0;
        for(int i = 0; i < W; i++){
            if(flag) break;
            for(int j = 0; j < t; j++){
                if(ko[j][i] > K) {
                    flag = 1;
                    break;
                }
                ko2[j] += ko[j][i];
                if(ko2[j] + ko[j][i + 1] > K && i < W - 1){
                    count++;
                    for(int k = 0; k < t; k++) ko2[k] = 0;
                    break;
                }
            }
        }
        if(flag) continue;
        ans = min(ans, count);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007;
struct edge {int to,costa,costb;};

signed main() {
int n,m,s,t;
cin>>n>>m>>s>>t;s--;t--;
vector<edge> hen[n];
int u,v,a,b;
for(int i=0;i<m;i++){
    cin>>u>>v>>a>>b;
    u--;v--;
    hen[u].push_back((edge){v,a,b});
    hen[v].push_back((edge){u,a,b});
}
int d1[n]={},d2[n]={};
fill(d1,d1+n,MOD*MOD);fill(d2,d2+n,MOD*MOD);
d1[s]=0;
pair<int,int> q;
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> que;
que.push(make_pair(0,s));
while(!que.empty()){
    q=que.top();
    que.pop();
    if(q.first>d1[q.second])continue;
    for(int i=0;i<hen[q.second].size();i++){
        if(d1[hen[q.second][i].to]>d1[q.second]+hen[q.second][i].costa){
            d1[hen[q.second][i].to]=d1[q.second]+hen[q.second][i].costa;
            que.push(make_pair(d1[hen[q.second][i].to],hen[q.second][i].to));
        }
    }
}
d2[t]=0;
que.push(make_pair(0,t));
while(!que.empty()){
    q=que.top();
    que.pop();
    if(q.first>d2[q.second])continue;
    for(int i=0;i<hen[q.second].size();i++){
        if(d2[hen[q.second][i].to]>d2[q.second]+hen[q.second][i].costb){
            d2[hen[q.second][i].to]=d2[q.second]+hen[q.second][i].costb;
            que.push(make_pair(d2[hen[q.second][i].to],hen[q.second][i].to));
        }
    }
}
for(int i=0;i<n;i++)que.push(make_pair(d1[i]+d2[i],i));
int ans=1;for(int i=0;i<15;i++)ans*=10;
for(int i=0;i<n;i++){
    while((!que.empty())&&i>que.top().second)que.pop();
    cout<<ans-que.top().first<<endl;
}
return 0;


}


Measured memory_bytes: 13936
#include <bits/stdc++.h>
using namespace std;
#define rep(i,b) for(int i=0; i<int(b);i++)
#define eb emplace_back

typedef int Weight;
struct Edge {
    int src, dst;
    Weight weight;
    Edge(int src_, int dst_, Weight weight_) :
        src(src_), dst(dst_), weight(weight_) { }
};
bool operator < (const Edge &e, const Edge &f) {
    return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
        e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

int const MAX_V = 100000;
void stronglyConnectedComponents(Graph const & g, int cmp[MAX_V]){
    int n = g.size();
    Graph rg(n);
    rep(i,n) for(auto & e : g[i]) rg[e.dst].eb(e.dst, e.src, e.weight);
    int cnt = 0;
    static int lavel[MAX_V], used[MAX_V], ord[MAX_V], inS[MAX_V], S[MAX_V];
    rep(i,n) lavel[i] = used[i] = inS[i] = cmp[i] = 0;
    int sz = 0;
    rep(i,n){
        if(used[i]) continue;
        int s = 0;
        S[s++] = i;
        while(s){
            int v = S[s-1];
            used[v] = true;
            bool flg = true;
            for(auto & e : g[v]){
                int dst = e.dst;
                if(!used[dst] && !inS[e.dst]){
                    S[s++] = dst;
                    flg = false;
                }
            }
            if(flg){
                int t = S[s-1];
                if(!lavel[t]){
                    lavel[t] = cnt++;
                    ord[sz++] = t;
                }
                s--;
            }
        }
    }
    rep(i,n) used[i] = 0;
    int k = 0;
    rep(i,n){
        int u = ord[n-i-1];
        if(used[u]) continue;
        int s = 0;
        S[s++] = u;
        while(s){
            int v = S[--s];
            used[v] = true;
            cmp[v] = k;
            for(auto & e : rg[v]){
                int d = e.dst;
                if(!used[d]) S[s++] = d;
            }
        }
        k++;
    }
}

int main(){
    int n,m;
    scanf("%d%d", &n,&m);
    Graph g(n);
    rep(i,m){
        int a,b;
        scanf("%d%d", &a,&b);
        g[a].eb(a,b,0);
    }
    int c[MAX_V];
    stronglyConnectedComponents(g,c);
    int q; cin >> q;
    rep(i,q){
        int a,b;
        scanf("%d%d", &a,&b);
        printf("%d\n", c[a]==c[b]);
    }
}

Measured memory_bytes: 2416
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	int n;
	cin >> n;
	string str1;
	string str2;
	string ans;
	cin >> str1;
	cin >> str2;
	for (int i = 0; i < n; ++i) {
		ans.push_back(str1[i]);
		ans.push_back(str2[i]);
	}
	cout << ans << endl;
	system("pause");
	return 0;
}

Measured memory_bytes: 504
/*
	Created by : imay_10
	" It won't be EASY, but I'll make it "
*/

#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
const int mod = 1e9+7;
const ll inf = 1e18;
const double pi = 3.1415926535897932384626;

// Utility for fast exponentiation
ll mpow(ll a,ll b,ll m){
    ll res=1;
    //a%=m;
    while(b){
    	if(b%2) res=res*a%m;
		a=a*a%m;
		b/=2;
	}
	return res;
}

// Utility for modular inverse
ll inv(ll a,ll m){
	return mpow(a,m-2,m);
}

// Utility for GCD Calculation
ll gcd(ll a,ll b){
	if(b==0) return a;
	return gcd(b,a%b);
}

void solve(){
	//code
	double x,t;
	cin>>t>>x;
	cout<<double(t/x);
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	solve();
 	return 0;
}


Measured memory_bytes: 3804
#include <bits/stdc++.h>
#define sanyes ios_base::sync_with_stdio(0), cout.tie(0); cin.tie(0);
#define llong long long
#define pb push_back
#define bpc __builtin_popcount

const llong mxn = 1e5 + 7;
const llong mod = 1e9 + 2;
const llong inf = 1e18 + 9;

using namespace std;

llong n, k, dp[mxn], sum = 0, w, c;
vector <llong> v1, v2;

int main(){
    sanyes
    cin >> n >> k;
    for (int i = 1; i <= n; i ++){
        cin >> w >> c;
        sum += c;
        v1.pb(w);
        v2.pb(c);
    }for (int i = 1; i <= sum; i ++){
        dp[i] = inf;
    }for (int i = 0; i < n; i ++){
        for (int j = sum; j >= v2[i]; j --){
            dp[j] = min(dp[j], dp[j - v2[i]] + v1[i]);
        }
    }for (int i = sum; i >= 0; i --){
        if(dp[i] <= k){
            cout << i;
            return 0;
        }
    }return 0;
}


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

int main()
{
  int n;
  cin >> n;
  int num;
  char x;

  int a[4][13]={};

  for(int i=0;i<n;i++)
    {
      cin >> x >> num;
      for(int j=1;j<=13;j++)
	{
	  if(num==j)
	    {
	      if(x=='S')a[0][num-1]=1;
	      if(x=='H')a[1][num-1]=1;
	      if(x=='C')a[2][num-1]=1;
	      if(x=='D')a[3][num-1]=1;
	    }
	}
    }

  for(int i=0;i<4;i++)
    {
      for(int j=0;j<13;j++)
	{
	  if(a[i][j]==0)
	    {
	      if(i==0)cout << 'S' << " " << j+1 << endl;
	      if(i==1)cout << 'H' << " " << j+1 << endl;
	      if(i==2)cout << 'C' << " " << j+1 << endl;
	      if(i==3)cout << 'D' << " " << j+1 << endl;
	    }
	}
    }

  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define MAX_V 100000
#define INF 1000000000000000
#define int long long
typedef pair<int, int> P; //firstは最短距離,secondは頂点の番号
struct edge
{
    long long to, cost;
};
struct graph
{
    int V;                  //頂点数
    vector<vector<edge>> G; //頂点sからの最短距離
    vector<long long> d;
    graph(int n)
    {
        init(n);
    }
    void init(int n)
    {
        V = n;
        G.resize(V);
        d.resize(V);
        for (int i = 0; i < V; i++)
        {
            d[i] = INF;
        }
    }
    void add_edge(int s, int t, long long cost)
    {
        edge e;
        e.to = t;      //行き先
        e.cost = cost; //cost
        G[s].push_back(e);
    }
    void dijkstra(int s)
    {
        for (int i = 0; i < V; i++)
        {
            d[i] = INF;
        }
        d[s] = 0;
        priority_queue<P, vector<P>, greater<P>> que;
        que.push(P(0, s));
        while (!que.empty())
        {
            P p = que.top();
            que.pop();
            long long v = p.second;
            if (d[v] < p.first)
                continue;
            for (auto e : G[v])
            {
                if (d[e.to] > d[v] + e.cost)
                {
                    d[e.to] = d[v] + e.cost;
                    que.push(P(d[e.to], e.to));
                }
            }
        }
    }
};
main()
{
    long long n, m, s, t;
    cin >> n >> m >> s >> t;
    s--, t--;
    graph G1(n);
    graph G2(n);
    for (int i = 0; i < m; i++)
    {
        long long u, v, a, b;
        cin >> u >> v >> a >> b;
        u--, v--;
        G1.add_edge(u, v, a);
        G1.add_edge(v, u, a);
        G2.add_edge(u, v, b);
        G2.add_edge(v, u, b);
    }
    G1.dijkstra(s);
    G2.dijkstra(t);
    long long res[n];
    for (int i = 0; i < n; i++)
    {
        res[i] = G1.d[i] + G2.d[i];
    }
    for (int i = n - 2; i >= 0; i--)
    {
        res[i] = min(res[i], res[i + 1]);
    }
    for (int i = 0; i < n; i++)
    {
        cout << INF - res[i] << endl;
    }
}


Measured memory_bytes: 19068
void main() {
  problem();
}

void problem() {
  auto X = scan!long;
  const DELTA = 0.000001L;

  long solve() {
    long theta;
    real x = sin(PI*theta/180L);
    real y = cos(PI*theta/180L);
    
    while(true) {
      theta += X;
      x += sin(PI*theta/180L);
      y += cos(PI*theta/180L);
      [x, y, PI].deb;

      if (-DELTA <= x && x <= +DELTA && -DELTA <= y && y <= +DELTA) break;
    }

    return theta / X + 1;
  }

  solve().writeln;
}

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

import std.stdio, std.numeric, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric;
T[][] combinations(T)(T[] s, in int m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");

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


Measured memory_bytes: 2716
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef pair<string, int> guide;

int main() {
  int N;
  cin >> N;
  vector<guide> G;
  vector<guide> C;
  for (int i = 0; i < N; i++) {
    string s;
    int p;
    cin >> s >> p;
    G.push_back(guide(s, p));
    C.push_back(guide(s, p));
  }

  sort(C.begin(), C.end());

  for (int i = 0; i < N - 1; i++) {
    for (int j = N - 1; j >= i + 1; j--) {
      if (C[j].first == C[j - 1].first) {
        if (C[j].second > C[j - 1].second) {
          guide tmp = C[j];
          C[j] = C[j - 1];
          C[j - 1] = tmp;
        }
      }
    }
  }

  for (int i = 0; i < N; i++) {
    guide c = C[i];
    for (int j = 0; j < N; j++) {
      if (c == G[j]) cout << j + 1 << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    int N, K;
    cin >> N >> K;
    vector<int> h(N);
    rep(i, 0, N) cin >> h[i];

    vector<int> dp(N + 1, inf);
    dp[0] = 0;
    rep(i, 0, N)
    {
        rep(j, 1, K + 1)
        {
            if (i + j >= N) continue;
            chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
        }
    }
    cout << dp[N - 1] << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; (i) < (n); ++ (i))
#define loop(i,a,n) for (int i = (a); (i) < (n); ++ (i))
#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF (int)1e9
#define MOD 0
//#define int ll
using namespace std;
typedef vector<long long> vl;

signed main() {
  int a,b,t;
  cin >> a >> b >> t;
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << t/a*b << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n;
int a[100100];
int ma,mi=0x3f3f3f3f;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%d",&a[i]),ma=max(ma,a[i]),mi=min(mi,a[i]);
	if(ma-mi>=2)
	{
		puts("No");
		return 0;
	}
	int c=0;
	if(ma==mi)
	{
		if(mi==n-1||mi*2<=n)
			puts("Yes");
		else puts("No");
	}
	else
	{
		for(int i=1;i<=n;++i)
			if(a[i]==mi)c++;
		if(2*(mi+1-c)>n-c||ma-c<=0)
			puts("No");
		else puts("Yes");
	}
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll unsigned long long 
#define MOD 1000000007
using namespace std;
ll a[2000005];
ll S[2000005];
ll add(ll a,ll b){
	return (a%MOD+b%MOD)%MOD;
}
ll mul(ll a,ll b){
	return (a%MOD*b%MOD)%MOD;
}
int main(){
	int n ;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	S[1] = a[1];
	for(int i=2;i<=n;i++){
		S[i] = add(S[i-1],a[i]);
	}
	ll ans = 0;
	for(int i=1;i<=n-1;i++){
		ans = add(ans,mul(a[i],(S[n]-S[i]+MOD)%MOD))%MOD;
	}
	cout<<ans;
//	
//	ull n,sum = 0;
//    cin >> n;
//    for(int i = 1;i <= n;i++) cin >> arr[i];
//    for(int i = 1;i <= n;i++) ans[i] = (arr[i]+ans[i-1]);
//    for(int i = 1;i <= n;i++) sum = ((sum + arr[i]*((ans[n]-ans[i])%mod))%mod)%mod;
//    cout << sum << endl;
} 

Measured memory_bytes: 6708
n = int(input())
count = [[0]*10 for _ in range(10)]

for num in range(1, n+1):
    first = int(str(num)[0])
    last = int(str(num)[-1])

    if first == 0 or last == 0:
        continue
    else:
        count[first][last] += 1

ans = 0
for first in range(1, 10):
    for last in range(1, 10):
        pattern = count[first][last] * count[last][first]
        ans += pattern

print(ans)


Measured memory_bytes: 3060
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstring>
using namespace std;

bool A[110][110],flag[110];
int in[110],out[110];
int n,now=1;
stack<int> S;

void dfs_visit(int u){
	flag[u]=true;
	for(int i=1;i<=n;i++){
		if(A[u][i]==true && flag[i]==false) {
			S.push(i);
			in[i]=now++;
			dfs_visit(i);
		}
	}
	int x=S.top();
	S.pop();
	out[x]=now++;
	return ;
}

void dfs(){
	S.push(1);in[1]=now++;
L1:	while(S.empty()==0){
		int x=S.top();
		dfs_visit(x);
	}
	for(int i=1;i<=n;i++){
		if(flag[i]==false){
			S.push(i);in[i]=now++;goto L1;
		}
	}
	for(int i=1;i<=n;i++) cout<<i<<" "<<in[i]<<" "<<out[i]<<endl;
	return ;
}

int main (){
	int a,b,c;
	cin>>n;
	for(int i=1;i<=n;i++){
		flag[i]=false;
			for(int j=1;j<=n;j++){
				A[i][j]=false;
		}
	}
	for(int i=1;i<=n;i++){
		cin>>a>>b;
		for(int j=1;j<=b;j++){
			cin>>c;
			A[a][c]=true;
		}
	}
	dfs();
	return 0;

}


Measured memory_bytes: 3136
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

int main() {
	int S, h, m, m2, s;
	cin >> S;
	s = S % 60;
	m2 = S / 60;
	m = m2 % 60;
	h = m2 / 60;
	cout << h << ":" << m << ":" << s << endl;
}


Measured memory_bytes: 3132
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
using ll = long long;
int main(){
	int L;
	string s,t;
	cin>>L>>s>>t;
	if(s+t > t+s) swap(s,t);
	ll x = s.size(), y = t.size();
	for(int i=L;i>=0;i--){
		if(x*i<=L && (L-x*i)%y==0){
			int j = (L-x*i)/y;
			string ans;
			rep(k,i) ans += s;
			rep(k,j) ans += t;
			cout<<ans<<endl;
			return 0;
		}
	}
}


Measured memory_bytes: 1544
#include<bits/stdc++.h>
using namespace std;
 
int d[51]={0}, t[51]={0};
 
int main(){
    int n;
    cin >> n;
    for(int i=0;i<n;++i){
        cin >> d[i];
    }
 
    sort(d, d+n);
 
    for(int i=0;i<n;++i){
        t[i] = abs(24*(i%2) - d[i]);
    }
 
    int mini = d[0];
    for(int i=1;i<n;++i){
        for(int j=0;j<i;++j)
            mini = min(mini, min(abs(t[i]-t[j]), 24-abs(t[i]-t[j])));
    }
 
    cout << mini << endl;
 
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {

    for(int i = 0; i < 3; ++i) {
        for(int j = 0; j < 3; ++j) {
            char c; cin>>c;
            if(i == j) {
                cout << c << flush;
            }
        }
    }
    cout << endl;

    return 0;
}


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

int masu[404][404];

int main(){
	int n;
	while(cin>>n){
		if(n==0) break;
		if(n==1){
			cout<<"1 1"<<endl;
			continue;
		}
		for(int i=0; i<404; i++){
			for(int j=0; j<404; j++){
				masu[i][j] = -1;
			}
		}
		masu[201+0][201+0] = 0;
		for(int k=1; k<n; k++){
			int m, d;
			cin>>m>>d;
			int x, y;
			for(int i=0; i<404; i++){
				for(int j=0; j<404; j++){
					if(masu[i][j] == m){
						x = i;
						y = j;
					}
				}
			}
			if(d==0) masu[x-1][y] = k;
			else if(d==1) masu[x][y+1] = k;
			else if(d==2) masu[x+1][y] = k;
			else if(d==3) masu[x][y-1] = k;
		}
		int mue, msita, mhidari, mmigi;
		mue = 500;
		msita = -1;
		mhidari = 500;
		mmigi = -1;
		for(int i=0; i<404; i++){
			for(int j=0; j<404; j++){
				if(masu[i][j] != -1){
					mue = min(mue, j);
					msita = max(msita, j);
					mhidari = min(mhidari, i);
					mmigi = max(mmigi, i);
				}
			}
		}
		cout<<mmigi-mhidari+1<<" "<<msita-mue+1<<endl;
	}
}

Measured memory_bytes: 1500
N = int(input())
A = list(map(int,input().split()))
ASUM = sum(A)
B = list(map(int,input().split()))
for i,b in enumerate(B):
    if A[i] > b:
        A[i] -= b
        continue
    else:
        b -= A[i]
        A[i] = 0
        b -= A[i]
    if A[i+1] > b:
        A[i+1] -= b
    else:
        A[i+1] = 0
print(ASUM-sum(A))

Measured memory_bytes: 18624
#include <iostream>
#include <algorithm>
using namespace std;
int n, arr[100009];
int dp[100009];
int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> arr[i];
	dp[1] = 0;
	dp[2] = abs(arr[1] - arr[2]);
	for (int i = 3; i <= n; i++) {
		dp[i] = min(abs(arr[i] - arr[i - 1])+dp[i-1], abs(arr[i] - arr[i - 2])+dp[i-2]);
	}
	cout << dp[n] << endl;
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        PrintWriter pw = new PrintWriter(System.out);

        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        char[] s = sc.next().toCharArray();

        int total = a + b;
        int cnt = 0;
        int bCnt = 0;
        for (char c : s) {
            if (c == 'c')
                pw.println("No");
            else if (total > cnt) {
                if (c == 'a') {
                    pw.println("Yes");
                    cnt++;
                } else if (b > bCnt){
                    pw.println("Yes");
                    cnt++;
                    bCnt++;
                } else {
                    pw.println("No");
                }
            } else {
                pw.println("No");
            }
        }

        pw.flush();
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}

Measured memory_bytes: 22908
using System;

namespace AtCoderConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            // 標準入力から1行取得
            string input = Console.ReadLine();
            int a = int.Parse(input.Split(' ')[0]);
            int b = int.Parse(input.Split(' ')[1]);

            // b-aで高さの差を求める
            double dif = b - a;

            // 東側の塔の高さは 1+...+dif
            int heightEast = (int)((1 + dif) * (dif / 2.0));

            // 雪の積もった高さ
            int output = heightEast - b;

            // 標準出力に出力
            Console.WriteLine(output);
        }
    }
}


Measured memory_bytes: 13140
n = int(input())
w = list(map(int,input().split()))
l, r = w[0], sum(w)-w[0]
m = abs(l-r)
for i in range(1,n-1):
    l += w[i]
    r -= w[i]
    if abs(l-r) < m:
        m = abs(l-r)
print(m)

Measured memory_bytes: 3060
#include <set>
#include <cstdio>
#include <cstring>
using namespace std;
int sq[10000],v[9999];
int main(){
	int i,n;
	for(i=1;i<10000;i++)sq[i]=i*i;
	for(;scanf("%d",&n),n;){
		set<int>s;
		memset(v,0,sizeof(v));
		for(i=1;i<n;i++)s.insert(sq[i]%n);
		set<int>::iterator is,iS;
		for(is=s.begin();is!=s.end();is++)
			for(iS=is,iS++;iS!=s.end();iS++){
				i=*iS-*is;
				if(i>(n-1)/2)i=n-i;
				v[i]++;
			}
		for(i=1;i<=(n-1)/2;i++)printf("%d\n",v[i]*2);
	}
}

Measured memory_bytes: 1344
#include<bits/stdc++.h>
using namespace std;using L=long long;using V=pair<L,L>;
#define F first
#define S second
#define I X[i]
#define R for(L i=0;i<N;i++)
L N,D,A,n=0,r=0,t;V X[200005];queue<V>P;main(){cin>>N>>D>>A;R cin>>I.F>>I.S;sort(X,X+N);R{while(!P.empty()&P.front().F<I.F){n-=P.front().S;P.pop();}I.S-=n;if(I.S>0){t=(I.S+A-1)/A;r+=t;P.push({I.F+2*D,t*A});n+=t*A;}}cout<<r;} 

Measured memory_bytes: 4992
N, L = map(int,input().split())

p = []
pi = []
pi_s = []


for i in range(L,L+N):
    p.append(i)

all_t = sum(p)

for i in range(N):
    pi.append(all_t - p[i])
    pi_s.append(abs(all_t - pi[i]))

# print(p, pi,pi_s)
min_abs = pi_s[0]
ans = 0

for i in range(1,N):
    if min_abs > pi_s[i]:
        min_abs = pi_s[i]
        ans = i

# print(ans,pi[ans],pi_s[ans])

print(pi[ans])

Measured memory_bytes: 3188
#include<stdio.h>
#include<iostream>
using namespace std;
int main(){
    long long int a, b, c, mi, ma,sum ;
    cin >> a;
    sum = 0;
    mi = 10000000;
    ma = -10000000;
    for(int i=1;i<=a;i++){
       cin >>b;
       ma = max(b,ma);
       mi = min(b,mi);
       sum += b;
    }
    cout << mi << " " << ma << " " << sum <<endl;
    
 return 0;
}


Measured memory_bytes: 3124