akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int MAXN = 1e5 + 5;

struct edge {
	int a, b, c;
	bool operator <(const edge &rhs) const {
		return c > rhs.c;
	}
};

int N;
vector <edge> E;
ll sol[MAXN];
vector <int> comp[MAXN];
int dad[MAXN];
ll add[MAXN];

void load() {
	scanf("%d", &N);
	for (int i = 1; i < N; i++) {
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		E.push_back({a, b, c});
	}
}

void join(edge e) {
	int da = dad[e.a];
	int db = dad[e.b];
	int sza = comp[da].size();
	int szb = comp[db].size();
	if (sza > szb) {
		swap(da, db);
		swap(sza, szb);
	}
	for (auto it : comp[da]) {
		sol[it] += add[da] - add[db] + (ll)(szb - sza) * e.c;
		comp[db].push_back(it);
		dad[it] = db;
	}
	add[db] += (ll)sza * e.c;
}

void solve() {
	for (int i = 1; i <= N; i++) {
		dad[i] = i;
		comp[i].push_back(i);
	}
	
	sort(E.begin(), E.end());
	for (auto it : E)
		join(it);
	
	for (int i = 1; i <= N; i++)
		printf("%lld\n", sol[i] + add[dad[i]]);
}

int main() {
	load();
	solve();
	return 0;
}

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

int main(void) {
    int a[100][100] = {};
    int b[100][100] = {};
    long c[100][100] = {};
    int n, m, l;
    
    cin >> n >> m >> l;
    
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < m; ++j) {
            cin >> a[i][j];
        }
    }
    for(int i = 0; i < m; ++i) {
        for(int j = 0; j < l; ++j) {
            cin >> b[i][j];
        }
    }
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < l; ++j) {
            for(int k = 0; k < m; ++k) {
                c[i][j] += a[i][k] * b[k][j];
            }
        }
    }
    for(int i = 0; i < n; ++i) {
        cout << c[i][0];
        for(int j = 1; j < l; ++j) {
            cout << ' ' << c[i][j];
        }
        cout << endl;
    }
    return 0;
}



Measured memory_bytes: 3268
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=1e9+7;

auto power=[](int a,int b){
  int cnt=1;
  for (int i = 0; i < b; ++i)
  {
    cnt*=a;
  }
  return cnt;
};
vector<int> tmp={2,3,5,7,11,13,17,19,23,29,31};
auto isPrime=[](int a) ->bool {
  for(auto&& e: tmp) {
    if(a%e==0) return false;    
  }
  return true;
};

int main()
{
  int n;
  cin>>n;
  std::vector<int> prime={2,3,5,7,11,13,17,19,23,29,31};
  for (int i = 2; i <= n; ++i)
  {
    if(isPrime(i)) prime.emplace_back(i);
  }

  vector<int> vec;
  for(auto&& e: prime) {
    int cnt=0;
    for (int i = 1; i <= 9; ++i)
    {
      cnt+=n/power(e,i);
    }
    if(cnt==0) continue;
    vec.emplace_back(cnt);
  }
  int64_t ans=1;
  for(auto&& e: vec) {
    ans*=(e+1);
    ans%=mod;
  }

  cout<<ans;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int L, A, B, C, D;
    cin >> L >> A >> B >> C >> D;
    const int a = (A / C) + ((A % C) != 0);
    const int b = (B / D) + ((B % D) != 0);
    cout << L - max(a, b) << endl;
    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define mod 1000000007
#define MAX 1000000
#define vector<ll> vi
#define pair<ll> pi
#define ll long long
#define ld long double
#define pb push_back
#define mk make_pair
#define lb lower_bound
#define ub upper_bound
#define binary_search bs
#define endl "\n"
using namespace std;

int main(){
    fast
    ll k, a, b, f = 0;
    cin >> k;
    cin >> a >> b;
    for(ll i = a;i<=b;i++){
        if(i % k== 0){
            f = 1;
            cout << "OK";
            break;
        }
    }
    if(f == 0){
        cout << "NG";
    }

}


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

#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384


int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;} 
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}    //最大公約数
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}     //最小公倍数
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;} //コンビネーション
int nHr(int a,int b){return nCr(a+b-1,b);}       // 重複組み合わせ
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}  //階乗
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;} // a~bまでの階乗
int dsum(int x){int r=0;while(x){r+=(x%10);x/=10;}return r;}   //数字の各位の和
int dsumb(int x,int b){int r=0;while(x){r+=(x%b);x/=b;}return r;}  // b進数の各位の和？
int sankaku(int x){return ((1+x)*x)/2;} //三角数 xまでの和

//以下long long ver
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llnHr(long long a,long long b){return llnCr(a+b-1,b);}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long lldsum(long long x){long long r=0;while(x){r+=(x%10);x/=10;}return r;}
long long lldsumb(long long x,long long b){long long r=0;while(x){r+=(x%b);x/=b;}return r;}
long long llsankaku(long long x){return ((1+x)*x)/2;}

//double
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
double dbzt(double a,double b){return dbmax(a,b)-dbmin(a,b);}


typedef pair<int, int> ii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
#define forr(i,a,b) ; for(int i=(a); i<(b); i++)
#define clean(arr,val) memset(arr,val,sizeof(arr))
#define forn(i,n) forr(i,0,n)
#define PB push_back
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vpll;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
bool is_prime (int x){
  if (x<=1) return false ;
  for (int i=2 ; i*i<=x ; i++){
    if (x%i==0) return false ;
  }
   return true;
}

 
/*CODE START HERE*/
int main() {
  int n,m;
  cin >> n >> m;
  
  vector <int> a(m);
  vector <int> b(m);
  forn(i,m){
    cin >> a.at(i) >> b.at(i);
  }
  int per_max = *min_element(b.begin(),b.end() ) ;
  int per_min = *max_element(a.begin(),a.end() ) ;
  int c = per_max-per_min+1 ;
  cout << (c>0 ? c : 0) << endl;
}


Measured memory_bytes: 4068
import numpy as np
import sys
input = sys.stdin.readline
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,K = IL()
l = np.array(IL())

dp = np.zeros(N,dtype=int)
dp[0] = 0

for i in range(1,N):
    if i-K < 0:
        dp[i] = np.min(dp[:i]+np.abs(l[i]-l[:i]))
    elif i-K >= 0:
        dp[i] = np.min(dp[i-K:i]+np.abs(l[i]-l[i-K:i]))

print(dp[-1])

Measured memory_bytes: 22840
import sys
def recurcive(n,length,result):
    tmp=[]
    for _ in range(length):
        if n[_]%2==0:
            tmp.append(int(n[_]/2))
            #c+=1
        else:
            print(result)
            sys.exit()
            #return result
    #print(tmp)
    result+=1
    #print("result=",result)
    recurcive(tmp,length,result)

    

length=int(input())
n=list(map(int,input().split(" ")))
recurcive(n,length,0)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define REP(i,x,n) for(int i = (x); i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);

int main(void)
{
    ll a, b, n;
    cin >> a >> b >> n;
    n = min(n, b-1);
    cout << a*n/b - a*(n/b) << endl;
    return 0;
}

Measured memory_bytes: 3604
n, m = map(int, input().split())
k = 0
ki = []
si = []
smi = []

for i in range(m):
    si = list(map(int, input().split()))
    k = si.pop(0)
    ki.append(k)
    smi.append(si)

p = list(map(int, input().split()))
ans = 0

for i in range(2**n):
    h = [0]*n
    flag = True
    for j in range(n):
        if (i >> j) & 1:
            h[j] = 1
    for j in range(m):
        num = 0
        si = smi[j]
        k = ki[j]
        for l in range(k):
            if h[si[l]-1] == 1:
                num += 1
        if num % 2 != p[j]:
            flag = False
    if flag:
        ans += 1

print(ans)

Measured memory_bytes: 3064
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
		        int W = sc.nextInt();
		        int H = sc.nextInt();
		        int x = sc.nextInt();
		        int y = sc.nextInt();
		        int r = sc.nextInt();
		        if(x + r <= W && x - r >= 0 && y + r <= H && y - r >= 0){
		            System.out.println("Yes");
		        }else{
		            System.out.println("No");
		        }
    }
}


Measured memory_bytes: 26328
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <string>

using namespace std;

int main(void)
{
    map<string, int> s;

    s["SUN"] = 7;
    s["MON"] = 6;
    s["TUE"] = 5;
    s["WED"] = 4;
    s["THU"] = 3;
    s["FRI"] = 2;
    s["SAT"] = 1;

    string t;
    cin >>t;

    printf("%d\n", s[t]);

    return 0;
}

Measured memory_bytes: 256
n = 0
i = 0
while (n == 0): 
 
    i = i + 1
 
    data = map(int, raw_input().split())
    x = data[0]
    y = data[1]
 
    if(x == 0 and y == 0):
        break
    else:
        if x > y:
            print "%s %s" % (y, x)
        else:
            print "%s %s" % (x, y)

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

#define all(x) (x).begin(), (x).end()
typedef long long ll;

int main(int argc, char const* argv[])
{
   int r, d, x;
   cin >> r >> d >> x;
   for (int i = 0; i < 10; i++) {
      cout << r*x - d << endl;
      x = r*x - d;
   }
   return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

string s[100];

signed main()
{
    int H,W; cin>>H>>W;
    REP(i,H) cin>>s[i];

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

    REP(i,H) REP(j,W){
        if(s[i][j]=='.') continue;

        bool flag=false;
        REP(k,4){
            int y=i+dy[k],x=j+dx[k]; 
            if(y<0 or H<=y or x<0 or W<=x) continue;
            if(s[y][x]=='#') flag=true;
        }
        if(!flag){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >>N;
    vector<int>hei(N);
    for(int i=0;i<N;i++){
        cin >>hei[i];
    }
    vector<int>tf(N-1);
    for(int i=0;i<N-1;i++){
        if(hei[i]<hei[i+1]){
            tf[i]=0;
        }
        else{
            tf[i]=1;
        }
    }
    vector<int>ans(N-1);
    for(int i=0;i<N-1;i++){
        if(tf[i]==0){
            ans[i]=0;
        }
        else{
            ans[i]=ans[i-1]+1;
        }
    }
    int a=0;
    for(int i=0;i<N-1;i++){
        if(a<ans[i]){
            a=ans[i];
        }
    }
    cout<<a<<endl;
}


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

using namespace std;

typedef long double ld;
typedef long long ll;

#define sz(x) (int)(x).size()
#define pb push_back
#define mp make_pair
#define f first
#define s second

template<typename T, typename U> bool ckmin(T &a, U b){ return b < a ? a = b, true : false; }
template<typename T, typename U> bool ckmax(T &a, U b){ return b > a ? a = b, true : false; }

ll n, k;
vector<ll> p;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> k;
    p.assign(n, 0);
    for(int i = 0; i < n; ++i){
        cin >> p[i];
    }
    sort(p.begin(), p.end());
    ll res = 0;
    for(int i = 0; i < k; ++i){
        res += p[i];
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 3596
// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = int64_t;
using ull = uint64_t;
using PLL = pair<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace init__ {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
// #include "../debug/debug.cpp"
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}
        
const size_t size = 1e6 + 10;
const ll mod = 998244353;
ll sum_per_div[size] = {};
ll mul_sum_per_div[size] = {};
ll calc_just[size] = {};
ll cnt_num[size] = {};

ll mod_pow(ll n, ll k) { return k ? (k & 1 ? n : 1) * mod_pow(n * n % mod, k / 2) % mod : 1; }

ll inv(ll n) { return mod_pow(n, mod - 2); }

int main() {
    ll N;
    cin >> N;
    ll div2 = inv(2);
    ll ans = 0;
    while(N--) {
        ll a;
        cin >> a;
        cnt_num[a]++;
    }
    for(ll i = 1; i < size; i++) {
        for(ll j = 1; i * j < size; j++) {
            ll num = i * j;
            ll cnt = cnt_num[num];
            (sum_per_div[i] += cnt * num % mod) %= mod;
            (mul_sum_per_div[i] += mod - mod_pow(num, 2) * cnt % mod) %= mod;
        }
    }
    for(ll i = 1; i < size; i++) {
        auto &num = mul_sum_per_div[i];
        num += mod_pow(sum_per_div[i], 2);
        num *= div2;
        num %= mod;
    }
    DEBUG(sum_per_div[2], mul_sum_per_div[2]);
    for(ll gcd = size - 1; 1 <= gcd; gcd--) {
        ll &num = calc_just[gcd];
        num = mul_sum_per_div[gcd];
        for(ll i = 2; i * gcd < size; i++) (num += mod - calc_just[gcd * i]) %= mod;
        (ans += num * inv(gcd)) %= mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 31488
#include <bits/stdc++.h>
#define MAX_N 200001
#define mod 1000000007
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define FOR(i, a, b) for(ll i=a; i<b; i++)
#define REP(i, n) for(ll i=0; i<n; i++)
#define REV(i, n) for(ll i=n-1; i>=0; i--)
#define ALL(v) v.begin(), v.end()
#define pb push_back
const ll INF = 9e18;
ll a, b, n;

signed main(){
    cin >> a >> b >> n;
    if(n >= b){
        double u = (double)(b-1) / b;
        cout << floor(a * u) << endl;
    }else{
        double u = (double)n / b;
        cout << floor(a * u) << endl;
    }
    return 0;
}

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

int main(){
    int n, m;
    cin >> n >> m;
    vector<P> p;
    rep(i,n){
        int a, b;
        cin >> a >> b;
        p.push_back(P(a,b));
    }
    sort(p.begin(),p.end());
    priority_queue<int> que;
    int k = 0;
    int ans = 0;
    for(int i = 1; i <= m; i++){
        while(k < n && p[k].first <= i){
            que.push(p[k].second);
            k++;
        }
        if(!que.empty()) {
            ans += que.top();
            que.pop();
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main() {
   int n,a,b;
   cin >> n >> a >> b;

  if(a+b < n){
     cout << (a>b ? b : a) << " 0" << endl;
  }else if(a+b == n){
     cout << (a>b ? b : a) << " 0" << endl;
  }else if(a+b > n){
     cout << (a>b ? b : a) << ' ' << a+b - n << endl;
  }
   return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
//#define mod 998244353
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline void out(T a){ cout << a << '\n'; }
void YN(bool ok){if(ok) cout << "Yes" << endl; else cout << "No" << endl;}
//void YN(bool ok){if(ok) cout << "YES" << endl; else cout << "NO" << endl;}


const ll INF=1e18;
const int mx=200005;
//abc177
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll d,t,s;
    cin>>d>>t>>s;
    YN(d<=s*t);
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
//どうしてもわからないときはサンプルで実験　何か見えてくるかも
//頭で考えてダメなら紙におこせ！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
{
    ・全探索できるなら全探索しろ
    ・異常な制約ならそこに注目
}
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'¥n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え('='でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
doubleを扱うときには(abs)ではなく'fabs'!!!
*/

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    string s, t;
    cin >> s >> t;
    if(s[0] == t[2] && s[1] == t[1] && s[2] == t[0]) cout << "YES" << endl;
    else cout << "NO" << endl;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
  string s;
  int start, end;
  int ret = 0;
  cin >> s;
  for(int i = 0; s.size() > i; i++){
    if(s.at(i) == 'A'){
      start = i;
      break;
      cout << start << endl;
    }
  }
  for(int i = (s.size() - 1); start < i; i--){
    if(s.at(i) == 'Z'){
      end = i;
      break;
    }
  }
  cout << (end - start + 1) << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using pll = pair<ll,ll>;
using vll = vector<pll>;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rng(i,a,b) for(int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
const ll mod = 1e9+7;

ll pow_mod(ll x, ll n) {
    ll res = 1, b = x;
    while (n > 0) {
        if (n & 1) {
            res *= b;
            res %= mod;
        }
        b *= b;
        b %= mod;
        n >>= 1;
    }
    return res;
}

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

    vl dp(K+1, 1);
    ll ans = 0;
    for (int x = K; x > 0; x--) {
        ll cnt = pow_mod(K/x, N);
        for (int X = 2*x; X <= K; X += x) {
            cnt = (cnt - dp[X] + mod) % mod;
        }
        dp[x] = cnt;
        ans += (dp[x] * x) % mod;
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4040
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    // 互いに相手からの距離が最短の頂点を塗っていくのが最適？
    int N; cin >> N;
    vector<vector<int>> adList(N);
    for (int i = 0; i < N - 1; ++i)
    {
        int ai, bi; cin >> ai >> bi; --ai; --bi;
        adList[ai].push_back(bi);
        adList[bi].push_back(ai);
    }
    // 互いに相手のスタート地点に向かうパス上を塗っていく:O(N)
    vector<int> parents(N, -1);
    vector<int> dists(N, 1e9);
    dists[0] = 0;
    deque<int> Q{ 0 };
    while (!Q.empty())
    {
        int v = Q.front(); Q.pop_front();
        for (const int n : adList[v])
        {
            if (dists[n] > dists[v] + 1)
            {
                dists[n] = dists[v] + 1;
                parents[n] = v;
                Q.push_back(n);
            }
        }
    }
    deque<int> path{ N - 1 };
    int parent = parents[N - 1];
    for (;;)
    {
        path.push_front(parent);
        if (parent == 0) break;
        parent = parents[parent];
    }
    // パス上を交互に塗っていく:O(N)
    vector<int> colors(N, 0);
    while (!path.empty())
    {
        colors[path.front()] = 1; path.pop_front();
        if (path.empty()) break;
        colors[path.back()] = -1; path.pop_back();
    }
    // パス以外のマスを塗っていく:O(N)
    vector<bool> notVisited(N, true);
    Q.push_back(0);
    notVisited[0] = false;
    notVisited[N - 1] = false;
    while (!Q.empty())
    {
        int v = Q.front(); Q.pop_front();
        for (const int n : adList[v])
        {
            if (colors[n] != -1 && notVisited[n])
            {
                colors[n] = 1;
                notVisited[n] = false;
                Q.push_back(n);
            }
        }
    }
    Q.push_back(N - 1);
    while (!Q.empty())
    {
        int v = Q.front(); Q.pop_front();
        for (const int n : adList[v])
        {
            if (colors[n] != 1 && notVisited[n])
            {
                colors[n] = -1;
                notVisited[n] = false;
                Q.push_back(n);
            }
        }
    }
    // より多くのマスを塗れる方が勝者
    cout << (count(colors.begin(), colors.end(), 1) >
        count(colors.begin(), colors.end(), -1) ? "Fennec" : "Snuke") << endl;
}

Measured memory_bytes: 7296
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define P pair<int,int>
#define ll __int64
//#define __int64 long long

int n,c,k;
int t[111111];
int main(){	
	cin>>n>>c>>k;
	rep(i,n)cin>>t[i];
	sort(t,t+n);
	int ans=1;
	int time=t[0],cnt=0;

	rep(i,n){
		cnt++;
		if(t[i]-time>k){
			ans++;
			time=t[i];
			cnt=1;
		}
		else if(cnt>c){
			ans++;
			time=t[i];
			cnt=1;
		}

	}
	cout<<ans<<endl;
	
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
using namespace std;
int N;
bool b[8];
int C;
int ans;
int main(){
  cin >> N;
  int a;
  for(int i=0;i<N;i++){
    cin >> a;
    if(1<=a && a<=399)b[0]=true;
    else if(400<=a && a<=799)b[1]=true;
    else if(800<=a && a<=1199)b[2]=true;
    else if(1200<=a && a<=1599)b[3]=true;
    else if(1600<=a && a<=1999)b[4]=true;
    else if(2000<=a && a<=2399)b[5]=true;
    else if(2400<=a && a<=2799)b[6]=true;
    else if(2800<=a && a<=3199)b[7]=true;
    else C++;
  }
  for(int i=0;i<8;i++)if(b[i]==true)ans++;
  if(ans==0){
    cout << "1" << " " << ans+C << endl;
  }
  else{
    cout << ans << " " << ans+C << endl;
  }
  return 0;
}


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

int main()
{
	int H, W;
	while(1)
	{
		cin >> H >> W;
		if( H == 0 && W == 0)
		break;
		for(int j = 0; j < H; j++)
		{
		for(int i = 0; i < W; i++)
		{
			switch((i+j)%2)
			{
			case 0:
				cout << '#';
				break;
			case 1:
				cout << '.';
				break;
			}
		}
		cout << endl;
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3064
#include<bits/stdc++.h>   
#include<tr1/unordered_map>
#define ll long long int  
#define mkp make_pair 
#define mod 1000000007
using namespace std;   
  

int main(){    
  ios_base::sync_with_stdio(false); 
  cin.tie(NULL);   
  int n; 
  cin>>n;  
  string str; 
  int ac=0,tle=0,re=0,wa=0;
  while(n--){  
     cin>>str; 
     if(str=="AC") ac++; 
     else if(str=="TLE")tle++; 
     else if(str=="RE")re++; 
     else wa++;
    }  
  cout<<"AC x "<<ac<<"\n"; 
  cout<<"WA x "<<wa<<"\n"; 
  cout<<"TLE x "<<tle<<"\n"; 
  cout<<"RE x "<<re<<"\n";
 
   
    
  return 0;
}

Measured memory_bytes: 3632
//include
//-------------------------
#include<vector>
#include<list>
#include<map>
#include<set>
#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>

using namespace std;

//conversion
//-----------------------
inline int toInt(string s) { int v;istringstream sin(s);sin >> v;return v; }
template<class T>inline string toString(T x) { ostringstream sout;sout << x;return sout.str(); }

//math
//-----------------------
template<class T>inline T sqr(T x) { return x * x; }

//using
//-----------------------
using VI = vector<int>;
using VVI = vector<VI>;
using VS = vector<string>;
using PII = pair<int, int>;
using LL = long long;

//container util
//-----------------------
#define WHOLE(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define RWHOLE(f,x,...) ([&](decltype((x)) whole) { return (f)(rbegin(whole), rend(whole), ##__VA_ARGS__); })(x)
#define CWHOLE(f,x,...) ([&](decltype((x)) whole) { return (f)(cbegin(whole), cend(whole), ##__VA_ARGS__); })(x)
#define CRWHOLE(f,x,...) ([&](decltype((x)) whole) { return (f)(crbegin(whole, crend(whole), ##__VA_ARGS__); })(x)
#define PB push_back
#define MP make_pair
#define SZ(a) int((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())


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

//constant
//----------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

//clear memory
#define CLR(a) memset((a).0,sizeof(a))

//#define DEBUG
#ifdef DEBUG
//debug
#define dump(x) cerr<<#x<<"="<<(x)<<endl;
#define debug(x) cerr<<#x<<"="<<(x)<<"(L"<<__LINE__<<")"<<""<<__FILE__<<endl;
#define stay cout<<"Push any key and Enter..."; scanf_s("%*s");
#else
#define dump(x)
#define debug(x)
#define stay
#endif

int main() {
	string s, t;
	cin >> s >> t;
	for (int i = 0;i != s.size();++i) {
		if (s == t) { cout << "Yes" << endl;return 0; }
		s.insert(s.begin(), s.back());s.pop_back();
	}
	cout << "No" << endl;
	stay;
	return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	int ans = 0;
	rep(i,n){
		int a;
		cin >> a;
		if(i%2 == 0 && a%2 == 1) ++ans;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3648
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<deque>
#include<queue>
using namespace std;

using ll = long long;
const int INF = 1001001001;
const ll LLINF = 1001001001001001001;
const int MOD = 1000000007;

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

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

  vector<ll> cost(n);
  vector<vector<ll>> a(n);

  rep (i,n) {
    cin >> cost[i];
    rep (j,m) {
      int tmp;
      cin >> tmp;
      a[i].push_back(tmp);
    }
  }

  vector<ll> tot(m);
  rep (i,n) {
    rep (j,m) {
      tot[j] += a[i][j];
    }
  }
  rep (i,m) {
    if (tot[i] < x) {
      cout << -1 << endl;
      return 0;
    }
  }

  ll result = LLINF;

  for (int bit = 0; bit < pow(2, n); bit++) {
    // 今回選択する参考書リスト
    vector<int> book;
    int tbit = bit;

    // 参考書リストの作成
    int count = 0;
    while (tbit > 0) {
      if (tbit & 1) {
        book.push_back(count);
      }
      count++;
      tbit >>= 1;
    }

    // 選び方の時に、理解度の累計を計算
    ll tcost = 0;
    vector<int> score(m);
    for (int b : book) {
      rep (i,m) {
        score[i] += a[b][i];
      }
      tcost += cost[b];
    }

    // x以上かを判定
    bool isOk = true;
    rep (i,m) {
      if (score[i] < x) isOk = false;
    }

    // 更新
    if (isOk)  result = min(result, tcost);
  }

  cout << result << endl;
}




Measured memory_bytes: 4116
// Charan Sriramula
 
#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long int ll;
 
const ll lg=22;
const ll N=1e6+5;
const ll M=5e8;
const ll INF=1e18;
const ll mod=1e9+7;
const double PI = 3.14159265358979323846;
 
#define is(n) scanf("%d",&n)
#define io(n) printf("%d\n",n)
#define ls(n) scanf("%lld",&n)
#define lo(n) printf("%lld\n",n)
 
#define f first
#define s second
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define mp(x,y) make_pair(x,y)
#define GCD(a,b) __gcd((a),(b))
#define all(v) v.begin(),v.end()
#define bits(x) __builtin_popcount(x)
#define LCM(a,b) ((a)*(b))/GCD((a),(b))
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
template<typename T> T power(T x,T y,ll m){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}
 
inline ll mul(ll a, ll b, ll p){ return (a * 1ll * b) % p; }
inline ll sub(ll a, ll b, ll p){ ll c = a - b; if(c < 0) c += p; return c; }
inline ll add(ll a, ll b, ll p){ ll c = a + b; if(c > p) c -= p; return c; }
 
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

ll a[N],b[N];

int main()
{
    ll n;
    cin>>n;
    ll sum=0;
    for(ll i=0;i<=n;i++){cin>>a[i];}
    for(ll i=0;i<n;i++){cin>>b[i];}
    for(ll i=0;i<n;i++)
    {
        ll cur=a[i],nex=a[i+1];
        ll mini=min(cur,b[i]);
        sum+=mini;
        a[i]-=mini;
        ll left=b[i]-mini;
        ll minx=min(nex,left);
        sum+=minx;
        a[i+1]-=minx;
    }
    cout<<sum<<endl;
}

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

int main() {
    int N;
    cin >> N;
    vector<vector<pair<int, int>>> edge(N);
    vector<pair<pair<int, int>, int>> point_f(N);
    vector<pair<pair<int, int>, int>> point_s(N);
    for (int i = 0; i < N; i++) {
        int x, y;
        cin >> x >> y;
        point_f[i] = {{x, y}, i};
        point_s[i] = {{y, x}, i};
    }
    sort(point_f.begin(), point_f.end());
    sort(point_s.begin(), point_s.end());
    for(int i = 1; i < N; i++) {
        int a = point_f[i-1].second;
        int b = point_f[i].second;
        edge[a].push_back({point_f[i].first.first - point_f[i-1].first.first, b});
        edge[b].push_back({point_f[i].first.first - point_f[i-1].first.first, a});
        
        int c = point_s[i-1].second;
        int d = point_s[i].second;
        edge[c].push_back({point_s[i].first.first - point_s[i-1].first.first, d});
        edge[d].push_back({point_s[i].first.first - point_s[i-1].first.first, c});
    }
    
    ll ans = 0;
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
    for (pair<int, int> p : edge[0]) {
        q.push(p);
    }
    vector<bool> check(N, false);
    check[0] = true;
    while(!q.empty()){
        pair<int, int> p = q.top();
        q.pop();
        if (check[p.second] == true) continue;
        ans += p.first;
        check[p.second] = true;
        for (pair<int, int> nxt : edge[p.second]) {
            q.push(nxt);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 12404
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <iomanip>
using namespace std;
#define all(x) x.begin(), x.end()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }
int sub(int a, int b) { return (a -= b) < 0 ? a + mod : a; }
int ctz(int x) { return __builtin_ctz(x); }
int clz(int x) { return __builtin_clz(x); }

string g[21];
int done[21][21];

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  #ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif

  int n, m;
  cin >> n >> m;
  for(int i = 0; i < n; i++){
    cin >> g[i];
  }

  const int dx[] = {-1, 0, 0, 1};
  const int dy[] = {0, -1, 1, 0};

  int res = 0;

  for(int si = 0; si < n; si++){
    for(int sj = 0; sj < m; sj++){
      for(int ti = 0; ti < n; ti++){
        for(int tj = 0; tj < m; tj++){
          if(si == ti && sj == tj) continue;
          if(g[si][sj] == '#' || g[ti][tj] == '#') continue;
          queue <tuple<int, int, int>> q;
          q.emplace(0, si, sj);
          memset(done, 0, sizeof done);
          done[si][sj] = 1;
          while(!q.empty()){
            int d, x, y;
            tie(d, x, y) = q.front();
            //auto [d, x, y] = q.front();
            q.pop();
            if(x == ti && y == tj){
              res = max(res, d);
              break;
            }
            for(int dir = 0; dir < 4; dir++){
              int nx = x + dx[dir];
              int ny = y + dy[dir];
              if(nx < 0 || ny < 0 || nx >= n || ny >= m || done[nx][ny] || g[nx][ny] == '#') continue;
              done[nx][ny] = 1;
              q.emplace(d + 1, nx, ny);
            }
          }
        }
      }
    }
  }
  cout << res;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int k;
	scanf("%d",&k);
	if(k&1)
		printf("%d\n",(k/2)*(k/2+1));
	else 
		printf("%d\n",(k/2)*(k/2));
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fin         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ii          pair<int,int>
#define F           first
#define S           second
#define pb          push_back
#define all(x)      (x).begin(),(x).end()
#define rall(x)     (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a)   for(int i = a; i >= 0; i--)
#define fori(i,m)   for(auto i = m.begin(); i != m.end(); i++) 
#define w(t)        while(t--)
#define sz(s)       int(s.size())
#define cls(a,car)  memset(a,car,sizeof (a))
#define db(x)       cerr << #x << " is " << x << '\n'
#define FL          freopen("in", "r", stdin),freopen("out", "w", stdout);
#define EjecuteTime cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
#define angle(x)    double(x * acos(-1) / 180.0)
using namespace std;
typedef long long   ll;
typedef vector<int> vi;
typedef vector<ii>  vii;
const int N = 1 * 1e6 + 5;
const ll mod = 1e9 + 7;
const double E = 1e-9;
//int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//int dx[] = {2, 1, -1, -2, -2, -1, 1, 2}, dy[] = {1, 2, 2, 1, -1, -2, -2, -1};
// fflush(stdout)
// cout << flush
// a + b = a ^ b + 2 * (a & b)
int v[N];
int pre[N];
int divi[N];
int main(){
    //FL;
    fin;
    int n;
    cin >> n;
    fore(i, 0, n){
        int x;
        cin >> x;
        v[x]++;
    }
    int ans = 0;
    for(int i = N - 1; i >= 1; i--){
        if(v[i] == 1){
            for(ll j = 1; j * j <= i; j++){
                if(i % j == 0){
                    if(v[j] && i != j){
                        pre[i] = 1;
                    }
                    if(v[i / j] && (i / j) != i){
                        pre[i] = 1;
                    }

                }
            }
        }else{
            pre[i] = 1;
        }
    }
    fore(i, 1, N){
        if(v[i]){
            if(!pre[i])
                ans++;
        }
    }
    cout << ans << '\n';
    EjecuteTime;
    return 0;
}       



Measured memory_bytes: 11616
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>

long long gcd(long long n1, long long n2)
{
    if (n1 < n2) std::swap(n1, n2);
    if (n2 == 0) return n1;

    long long m;
    do {
        m = n1 % n2;
        n1 = n2;
        n2 = m;
    } while(m != 0);

    return n1;
}

int main()
{
    long long N;
    std::cin >> N;

    std::vector<long long> A(N);
    for (long long i = 0; i < N; i++) {
        std::cin >> A[i];
    }

    std::vector<long long> L(N);
    L[0] = 0;
    L[1] = A[0];
    for (long long i = 2; i < N; i++) {
        L[i] = gcd(L[i-1], A[i-1]);
    }

    std::vector<long long> R(N);
    R[N-1] = 0;
    R[N-2] = A[N-1];
    for (long long i = N-3; i >= 0; i--) {
        R[i] = gcd(R[i+1], A[i+1]);
    }

    long long max_g = 0;
    for (long long i = 0; i < N; i++) {
        max_g = std::max(max_g, gcd(L[i], R[i]));
    }

    std::cout << max_g << std::endl;

    return 0;
}

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

int main(){
  int N;
  long K;
  vector<pair<int, int> > v;
  cin >> N >> K;
  for(int i=0; i<N; i++){
    int a, b;
    cin >> a >> b;
    v.push_back(make_pair(a,b));
  }
  sort(v.begin(), v.end());
  for(int i=0; i<v.size(); i++){
    if(v[i].second>=K){
      cout << v[i].first << endl;
      return 0;
    }
    K-=v[i].second;
  }
  return 0;
}

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

int main(){
    int n, ai[100];
    cin >> n;
    for (int i = 0; i < n; i++) cin >> ai[i];
    for (int i = n-1; i >= 0; i--){
        if (i != n-1) cout << " ";
        cout << ai[i];
    }
    cout << endl;
    
    return 0;
}


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

int main(void){
    int H,W;
    cin>>H>>W;
    vector<string> a(H);
    rep(y,H) cin>>a[y];
    int cnt[26]={};
    rep(y,H)rep(x,W) cnt[a[y][x]-'a']++;
    int set4=0,set2=0;
    rep(c,26){
        set4 += cnt[c]/4;
        if((cnt[c]%4)>=2) set2++;
    }
    set4 -= (H/2)*(W/2);
    if(set4>=0 && set2+set4*2 == (W%2)*(H/2)+(H%2)*(W/2)){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
H, W = map(int, input().split())
A1 = ["#"*W]
A2 = ["."*W]
input()
for i in range(H-2):
    A = input()
    s = ""
    for j, c in enumerate(A):
        if j%2 or c=="#":
            s += "#"
        else:
            s += "."
    A1.append(s)
    s = ""
    for j, c in enumerate(A):
        if j%2==0 or c=="#":
            s += "#"
        else:
            s += "."
    A2.append(s)
A1.append("."*W)
A2.append("#"*W)
print("\n".join(A1))
print()
print("\n".join(A2))


Measured memory_bytes: 4868
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

func main() {
	var xx []int

	s := bufio.NewScanner(os.Stdin)
	for i := 0; s.Scan(); i++ {
		if i == 0 {
			continue
		}
		for _, element := range strings.Split(s.Text(), " ") {
			x, _ := strconv.Atoi(element)
			xx = append(xx, x)
		}
	}

	sort.Sort(sort.Reverse(sort.IntSlice(xx)))
	cand := make([]int, xx[0]+1)
	for i := 1; i <= xx[0]; i++ {
		for _, x := range xx {
			cand[i] += (x - i) * (x - i)
		}
	}

	sort.Ints(cand)
	fmt.Println(cand[1])
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
const int maxn=1000001;
int a[maxn];
int k,n;

inline int read()
{
	 char ch=getchar();
    while(ch<'0' || ch>'9')
     ch=getchar();
    int x=0;
    while(ch>='0' && ch<='9')
    {
        x=(x<<3)+(x<<1)+(ch^'0');
        ch=getchar();
    }
    return x;
}

int main()
{
	a[0]=1;
	n=read(),k=read();
	for(int i=1;i<=n;i++)
	a[i]=min(a[i-1]+k,a[i-1]*2);
	cout<<a[n];
	return 0;
}

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

int main() {
  string money, price, dislike_number[10];
  int num;
  bool pay_flag = false;
  cin >> price >> num;
  for (int i = 0; i < num; i++) {
    cin >> dislike_number[i];
  }
  price = to_string(stoi(price) - 1);
  while (!pay_flag) {
    pay_flag = true;
    price = to_string(stoi(price) + 1);
    for (int i = 0; i < num; i++) {
      if (price.find(dislike_number[i]) != string::npos) pay_flag = false;
    }
  }

  cout << price;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
 public static void main(String args[]){
	 Scanner s=new Scanner(System.in);
	 int x=s.nextInt();
	 if(x>=1 && x<=100){
          int result=x*x*x;
		 System.out.println(result);
	 }
}
}

Measured memory_bytes: 26104
using System;
using System.Collections.Generic;
using System.Linq;

struct E {
  public long A;
  public long B;
}

class M{static void Main(string[] _) {
  var I0 = Console.ReadLine().Split(' ');
  var N = long.Parse(I0[0]);
  var M = long.Parse(I0[1]);
  
  var L = new List<E>();
  for( int I=0 ; I<N ; ++I ) {
    var I1 = Console.ReadLine().Split(' ');
    var e = new E();
    e.A = long.Parse(I1[0]);
    e.B = long.Parse(I1[1]);
    L.Add(e);
  }
  L.Sort( (a,b) => a.A.CompareTo(b.A) );
  
  long total = 0;
  foreach( var l in L) {
    if ( l.B <= M ) {
      total += l.A * l.B;
      M -= l.B;
    } else {
      total += l.A * M;
      break;
    }
  }
  
  Console.Write(total);  
}}
        

Measured memory_bytes: 20932
N,K = map(int, input().split())
P = list(map(int, input().split()))

S = [0]
before = 0
for i in range(N):
    S.append(P[i]+before)
    before += P[i]

max_num = 0
l = 0
m = 0
for i in range(N):
    if K+i > N:
        break
    tmp = S[K+i]-S[i]
    if tmp > max_num :
        l = K+i
        m = i
        max_num = tmp

S = P[m:l]
ans = 0
for i in range(len(S)):
    gausu = (S[i])*(S[i]+1)/2
    ans += (gausu/S[i])

print(ans)

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

int main() {
	int n, sum = 0;
	cin >> n;
	int a[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum += a[i];
	}
	int m = sum / 2;
	bitset<2000001> bs(1);
	for (int i = 0; i < n; i++) {
		bs |= bs << a[i];
	}
	while (!bs[m]) m--;
	cout << sum - m << endl;
	return 0;
}

Measured memory_bytes: 1024
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus >= 201703L
#        pragma GCC target("avx2")
#    else
#        pragma GCC target("avx")
#    endif

#endif
// 実数の場合
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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

    int a, b;
    cin >> a >> b;

    int ans = max({a + b, a - b, a * b});

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <stack>
#define rep(i, s, g) for (i = s; i < g; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;


int main(void)
{
    int n;
    string s;
    map<string, int> m;
    int i;
    int maxv = 0;

    cin >> n;

    rep(i, 0, n)
    {
        cin >> s;

        m[s] += 1;
    }

    for (auto &x : m)
    {
        maxv = max(maxv, x.second);
    }

    for (auto &x : m)
    {
        if (maxv == x.second)
        {
            cout << x.first << endl;
        }
    }
}

Measured memory_bytes: 25216
import java.util.*;
import java.math.*;

class Main {
    public static void main(String[] args) {
        new Solver().run();
    }
}

class Solver {

    public void run() {
        Scanner sc = new Scanner(System.in);
        BigInteger A = new BigInteger(sc.next());
        BigInteger B = new BigInteger(sc.next());

        int ret = A.compareTo(B);
        if (ret == 0) {
            System.out.println("EQUAL");
        } else if (ret > 0) {
            System.out.println("GREATER");
        } else {
            System.out.println("LESS");
        }

        return;
    }

}

Measured memory_bytes: 23252
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main(){
	string s;
	int i;
	getline(cin, s);
	for(i=0;i<s.size();i++)
	if(s[i]==','||s[i]=='.')s[i]=' ';
	stringstream ss;
	ss<<s;
	int f=0,n;
	while(ss>>s){
		n=s.size();
		if(n>=3&&n<=6){
			cout<<((f==1)?" ":"")<<s;
			f=1;
		}
	}
	cout<<endl;
}

Measured memory_bytes: 1196
import java.util.*;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int max = 0;
    int c = 0;
    for (int i = 0; i < N; i++) {
      int n = sc.nextInt();
      if (n >= max) {
        max = n;
      } else {
        c++;
      }
    }
    System.out.println(N - c);
  }
}

Measured memory_bytes: 21844
#include <iostream>
using namespace std;
int main(){
 int a[5];
  
  for(int i=0;i<5;i++){
  cin >> a[i];
  }
  
 for(int i=0;i<5;i++){
 if(a[i] == 0){
    cout<<i+1<<endl;   
   break;
  }
   }
}

Measured memory_bytes: 3592
import java.util.Scanner;

public class Main {

	static Scanner scanner;
	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    int A=gi();
	    int B=gi();
	    int C=gi();
	    int D=gi();
	    int E=gi();
	    int F=gi();

	    double maxn=0;
	    int ma=0;
	    int ms=0;
	    
	    for (int i=0; 100*A*i<=F; i++) {
	    	for (int j=0; 100*A*i+100*B*j<=F; j++) {
                if(i==0 && j==0) continue;
	    		for (int k=0; 100*A*i+100*B*j+C*k<=F; k++) {
	    			for (int l=0; 100*A*i+100*B*j+C*k+D*l<=F; l++) {
                        double n=(double)(k*C+l*D)/(double)(100*(i*A+j*B));
                        if(n>=maxn && (i*A+j*B)*E>=(k*C+l*D)) {
                        	maxn=n;
                        	ma=100*A*i+100*B*j+C*k+D*l;
                        	ms=C*k+D*l;
                        }
	    		    }
	    	    }
		    }
	    }
	    
	    System.out.print(ma + " "+ ms);
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

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

using namespace std;

int n;

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

	cin >> n;
	
	vector<int> x(n+1), y(n+1);

	for (int i = 1; i <= n; i++) {
		cin >> x[i] >> y[i];
	}

	sort(x.rbegin(), x.rend());
	sort(y.begin(), y.end());
	
	long long ans = 0;
	for (int i = 0; i <= n; i++) {
		if (x[i] > y[i]) {
			ans += 2 * (x[i] - y[i]);
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024