akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>

constexpr int INF = 1 << 30;

void solve() {
    int n;
    std::cin >> n;

    std::vector<int> ls(n + 1);
    ls[0] = 0;
    for (int i = 1; i <= n; ++i) {
        int l;
        std::cin >> l;
        ls[i] = ls[i - 1] + l;
    }
    int lsum = ls.back();

    int ans = INF;
    for (int min = 0; min < lsum; ++min) {
        std::vector<int> lodp(n + 1, INF), tidp(n + 1, INF);
        lodp[0] = 0;
        for (int r = 1; r <= n; ++r) {
            for (int l = 0; l < r; ++l) {
                int len = ls[r] - ls[l];
                if (len < min) continue;
                lodp[r] = std::min(lodp[r], std::max(lodp[l], len));
                tidp[r] = std::min(tidp[r], std::max(tidp[l], len));
                if (len > min) continue;
                tidp[r] = std::min(tidp[r], std::max(lodp[l], len));
            }
        }
        ans = std::min(ans, tidp[n] - min);
    }

    std::cout << ans << std::endl;
}

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

    solve();

    return 0;
}



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

const long long INF = 1LL << 50;
long Lmax(long x, long y) {
	if (x > y)return x;
	return y;
}

int max(int x, int y) {
	if (x > y)return x;
	return y;
}

long Lmim(long x, long y) {
	if (x < y)return x;
	return y;
}

int mim(int x, int y) {
	if (x < y)return x;
	return y;
}

int abs(int x) {
	if (x < 0) {
		return -x;
	}
	return x;
}



int N, M,K,x[100],ans;

int main(){
	cin >> N;
	cin >> K;
	for (int i = 0; i < N; i++) {
		cin >> x[i];
		ans += 2*mim(K - x[i], x[i]);
	}

	cout <<ans<< endl;

	return 0;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main(int argc, char *argv[]) {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    int r; cin >> r;
    cout << 3 * r * r << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
int ans = 1000000;
string s;
int main()
{
	cin >> s;
	int len = s.size();
	for (int i = 0; i <= len - 3; i++)
	{
		if (abs(100 * (s[i] -'0')+ 10 * (s[i + 1]-'0') + (s[i + 2]-'0') - 753)<ans)
			ans = abs(100 * (s[i] - '0') + 10 * (s[i + 1] - '0') + (s[i + 2]-'0') - 753);
	}
	printf("%d", ans);

}

Measured memory_bytes: 256
//Author : Vipul Sharma
 
// LIBRARIES

#include<iostream>
#include<set>
#include<algorithm>
#include<map>
#include <bits/stdc++.h>
 
// MACROS
#define ll long long int
#define ld long double
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define rev(i,b,a) for(ll i=b-1;i>=a;i--)
#define eqrep(i,b) for(ll i=1;i<=b;i++)
#define itrep(at) for (auto it = at.begin(); it != at.end(); it++)
#define ld long double
#define pb push_back
#define eb emplace_back
#define w(t) while (t--)
#define booster                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
#define mod 1000000007
#define endl "\n"
#define deb1(x) cout << #x << " : " << x << endl;
#define deb2(x, y) cout << #x << " : " << x << "\t" << #y << " : " << y << endl;
#define deb3(x, y, z) cout << #x << " : " << x << "\t" << #y << " : " << y << "\t" << #z << " : " << z << endl;
#define deb4(x, y, z, w) cout << #x << " : " << x << "\t" << #y << " : " << y << "\t" << #z << " : " << z << "\t" << #w << " : " << w << endl;
#define deb5(a, b, c, d, e) cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define deb6(a, b, c, d, e, f) cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
 
using namespace std;
long long cost = 1e18;
 
 
 
int main()
{
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif
	booster;
	ll n;
	cin>>n;
	string s;
	cin>>s;
	//map<char,ll>umap;
	ll cnt=0;
	rep(i,0,n)
	{
		if(s[i]!=s[i+1])
		{
			cnt++;
		}
	}
	cout<<cnt<<endl;

	//cout<<umap.size()<<endl;
	return 0;
}

Measured memory_bytes: 3740
package main

import "fmt"

func main() {
	var a int
	var b int

	fmt.Scan(&a, &b)

	if ( 1 <= a && a <= 9 ) && ( 1 <= b && b <=9 ) {
		fmt.Println(a*b)
	}else{
		fmt.Println(-1)
	}
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
using namespace std;

int masu[10][10];
void small(int x, int y) {
    for (int i = x-1; i <= x+1; i++) {
        if (0 <= i && i < 10) {
            masu[y][i]++;
        }
    }
    for (int i = y-1; i <= y+1; i++) {
        if (0 <= i && i < 10) {
            masu[i][x]++;
        }
    }
    masu[y][x]--;
}

void middle(int x, int y) {
    for (int i = y-1; i <= y+1; i++) {
        for (int j = x-1; j <= x+1; j++) {
            if (0 <= i && i < 10 && 0 <= j && j < 10) {
                masu[i][j]++;
            }
        }
    }
}

void big(int x, int y) {
    middle(x, y);
    if (0 <= x-2 && x-2 < 10) masu[y][x-2]++;
    if (0 <= x+2 && x+2 < 10) masu[y][x+2]++;
    if (0 <= y-2 && y-2 < 10) masu[y-2][x]++;
    if (0 <= y+2 && y+2 < 10) masu[y+2][x]++;
}

int main(void) {
    string s;

    while (cin >> s) {
        replace(s.begin(), s.end(), ',', ' ');
        stringstream ss(s);
        int x, y, size;
        ss >> x >> y >> size;

        switch (size) {
        case 1:
            small(x, y);
            break;
        case 2:
            middle(x, y);
            break;
        case 3:
            big(x, y);
        }
    }

    int max_num = -1;
    int no_color = 0;
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            if (masu[i][j] == 0) {
                no_color++;
            } else {
                max_num = max(max_num, masu[i][j]);
            }
        }
    }

    cout << no_color << endl;
    cout << max_num << endl;

    return 0;
}

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

typedef double du ;
typedef string st ;
typedef long long ll ;

int main ()
{
    st t ;
    int numN , numC ;

    cin >> numN >> numC ;
    cin >> t ;

    for (int i = 0 ; i < numN ; i ++)
    {
        if (i == (numC - 1))
        {
            t[i] += 32 ;
        }
    }
    cout << t << endl ;


    return 0 ;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	int N;
	cin >> N;

	int dp[100100][3] = {};

	rep1(i, N) {
		int a, b, c;
		cin >> a >> b >> c;

		dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a;
		dp[i][1] = max(dp[i - 1][2], dp[i - 1][0]) + b;
		dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c;
	}

	co(max(max(dp[N][0], dp[N][1]), dp[N][2]));

	Would you please return 0;
}

Measured memory_bytes: 1408
N = int(input())
d = {}
for i in range(N):
    s = input()
    if s in d:
        d[s] += 1
    else:
        d[s] = 1


max_val = max(d.values())
keys_of_max_val = [key for key in d if d[key] == max_val]

keys_of_max_val.sort()
for s in keys_of_max_val:
    print(s)

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

int N;
int factor[101];

int f(int x)
{
  x--;
  int res = 0;
  rep(i, N + 1) if (factor[i] >= x) res++;
  return res;
}

int main()
{
  cin >> N;
  for (int i = 2; i <= N; i++)
  {
    int cur = i;
    for (int j = 2; j <= cur; j++)
    {
      while (cur % j == 0)
      {
        cur /= j;
        factor[j]++;
      }
    }
  }
  int ans = f(75);
  ans += f(25) * (f(3) - 1);
  ans += f(15) * (f(5) - 1);
  ans += f(5) * (f(5) - 1) * (f(3) - 2) / 2;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ll N,M;
  cin >> N >> M;
  ll ans=abs((N-2)*(M-2));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
l = input()

dp = [[0, 0]] * len(l)

dp[0][0] = 1
dp[0][1] = 2

MOD = 1000000007

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

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


Measured memory_bytes: 41456
def Base_10_to_n(num, n):
    if (int(num/n)):
        return Base_10_to_n(int(num/n), n)+str(num%n)
    return str(num%n)

if __name__ == "__main__":
    N, K = map(int, input().split())
    print(len(Base_10_to_n(N, K)))


Measured memory_bytes: 2940
N = int(input())
A = list(map(int,input().split()))
B = []
count = 0
for a in A:
    if a % 2 == 0:
        B.append(a)

for i in B:
    while i % 2 == 0:
        i = i / 2
        count += 1

print(count)

Measured memory_bytes: 4148
import itertools

N,Q = map(int,input().split())
S = input()
info = [[int(e)-1 for e in input().split()] for _ in range(Q)]
note = [0]*(N)
for i in range(1,N):
    if S[i-1] == "A" and S[i] == "C":
        note[i] = 1
note = list(itertools.accumulate(note))
for l,r in info:
    if l == 0:
        ans = note[r]
    else:
        ans = note[r] - note[l-1]
        if S[l-1] == "A" and S[l] == "C":
            ans -= 1
    print(ans)


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

int main()
{
  int ww,hh,x,y,r;
  cin >> ww >> hh >> x >> y >> r;
  if((x-r < 0)||(x+r > ww)||(y-r < 0)||(y+r > hh)){
      cout << "No" << endl;
  }else if((x-r >= 0)||(x+r <= ww)||(y-r >= 0)||(y+r <= hh)){
      cout << "Yes" << endl;
  }
}


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

int main(){
  int n;
  cin >> n;
  vector<string> s(2);
  rep(snip_i, 2) cin >> s.at(snip_i);
  vector<int> v;
  rep(i, n){
    if(s.at(0).at(i) == s.at(1).at(i)) v.push_back(1);
    else{
      v.push_back(2);
      i++;
    }
  }
  mint ans;
  rep(i, v.size()){
    if(i == 0){
      if(v.at(i) == 1) ans = 3;
      else ans = 6;
      continue;
    }
    if(v.at(i) == 1){
      if(v.at(i-1) == 1) ans *= 2;
    }else{
      if(v.at(i-1) == 1) ans *= 2;
      else ans *= 3;
    }
  }
  cout << ans.x << endl;
  return 0;
}

Measured memory_bytes: 256
# frozen_string_literal: true

n = gets.to_i
ab = n.times.map { gets.split.map(&:to_i) }
MOD = 1_000_000_007

h = Hash.new { 0 }
done = Hash.new { false }

ab.each do |e|
  a = e[0]
  b = e[1]
  c = []
  if b.zero?
    c = if a.zero?
          [0, 0]
        else
          [-1, 0]
        end
  else
    t = Rational(a, b)
    c = [t.numerator, t.denominator]
  end
  h[c] += 1
end
mul = 1
mul2 = 0
count = 0
h.each do |k, v|
  if k == [0, 0]
    mul2 = v % MOD
  else
    kk = if k[0].negative?
           [k[1], -k[0]]
         else
           [-k[1], k[0]]
         end
    if h[kk].positive? && !done[k] && !done[kk]
      mul *= (2**v + 2**h[kk] - 1)
      mul %= MOD
      done[k] = true
      done[kk] = true
    else
      count += v unless done[k]
    end
  end
end
puts((mul2 + (mul * 2**count) - 1) % MOD)


Measured memory_bytes: 48004
#include <stdio.h>

int main(){
    int n, i;
    long long int num;
    
    while(scanf("%d", &n) != EOF){
        num = 2;
        if(n == 1){
            printf("%lld\n", num);
            continue;
        }
        else{
            for (i = 2; i <= n; i++){
                num += i;
            }
            printf("%lld\n", num);
        }
    }
    return 0;
}

Measured memory_bytes: 596
import java.util.Scanner;

public class Main {
	void run(){
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int tPoint = 0;
		int hPoint = 0;
		for(int i = 0;i < n; i++){
			String taro = s.next();
			String hana = s.next();
			if(taro.compareTo(hana) < 0){
				hPoint += 3;
			}else if(taro.compareTo(hana) > 0){
				tPoint += 3;
			}else{
				tPoint++;
				hPoint++;
			}
		}
		System.out.println(tPoint + " " + hPoint);
	}
	public static void main(String args[]){
		new Main().run();
	}
}

Measured memory_bytes: 29840
#include<bits/stdc++.h>//本当は必要なヘッダファイルだけインクルードするべきです
using namespace std;//本当は個別にusingするか変数や関数ごとにstd::をつけるべきです
//本当は関数内に宣言し明示的に初期化するべきです
double a,b,c,d;
int main(void){
  cin>>a>>b>>c>>d;
  printf("%f\n",sqrt(pow(a-c,2)+pow(b-d,2)));//答えが浮動小数点数の場合はprintfを使う！
  return 0;
}



Measured memory_bytes: 3200
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

line = input().split(' ')
N = int(line[0])
M = int(line[1])

count_list = [0 for i in range(N)]

for i in range(M):
    line = input().split(' ')
    for j in line:
        count_list[int(j)-1] += 1


if __name__ == '__main__':
    for count in count_list:
        print(count)


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


def main():
    from math import gcd
    import sys
    input = sys.stdin.readline

    n = int(input())
    a = list(map(int, input().split()))
    max_a = 10 ** 6
    numbers = [0 for _ in range(max_a + 1)]

    # KeyInsight:
    # 調和級数: 計算量 O(AlogA)
    # ◯: 素因数分解をすればよいことには気がつけた。
    # △: 4ケースWA・TLEが取れず
    for ai in a:
        numbers[ai] += 1

    is_pairwise = True

    # 素因数の判定
    # 素因数の倍数の要素を数えている
    for i in range(2, max_a + 1):
        count = 0

        for j in range(i, max_a + 1, i):
            count += numbers[j]

            # 2つ以上ある数の倍数があった場合は、少なくともpairwiseではない
            if count > 1:
                is_pairwise = False

    if is_pairwise:
        print("pairwise coprime")
        exit()

    value_gcd = 0

    # 全ての要素のGCDが1かどうかを判定
    for i in range(n):
        value_gcd = gcd(value_gcd, a[i])

        if value_gcd == 1:
            print("setwise coprime")
            exit()

    print("not coprime")


if __name__ == '__main__':
    main()


Measured memory_bytes: 127132
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    String ans = "";
    
    for(int i = 0 ; i < 3 ; ++i){
      String s = sc.next();
      ans += s.charAt(0);
    }
    
    ans = ans.toUpperCase();
    System.out.print(ans);

  }
}

Measured memory_bytes: 39032
#ifdef  DEBUG
#define MAXN 1007
#else
#define MAXN 1007
#endif
 
#include <bits/stdc++.h>
 
using namespace std;
#define rep(i, l, r) for (int i = l; i<r;i++)
#define vi vector<int>
#define vii vector<pair<int,int>>
#define vvi vector<vector<int>>
#define ii pair<int,int>
#define mp(i, j) make_pair(i,j)
#define ull unsigned long long int
#define ll  long long int
#define endl '\n'
#define PI 3.141592653589793238
#define MOD (1000000007)
#define INF (2000000000)
#define EPS (0.00000001)
vi adj[MAXN];
int X[MAXN];
ull dp[MAXN];
ull temp[MAXN+10][5010+1];
 
 
void dfs(int curr) {
 
    for(int nxt:  adj[curr])
        dfs(nxt);
 
    int sum = X[curr];
    int childs = adj[curr].size();
    rep (i,0,childs+1)
        rep (j,0,sum+1)
            temp[i][j] = INF;
 
    rep (i,0,sum+1)
        temp[childs][i] = 0;
    for (int i=childs-1;i>=0;i--) {
 
        int child = adj[curr][i];
        for (int remain = sum;remain>=0;remain--) {
            int ch1 = dp[child];
            int ch2 = X[child];
            ull &ans = temp[i][remain];
            if (remain-ch1>=0) {
                ans = min(ans,temp[i+1][remain-ch1] + ch2);
            }
            if (remain-ch2>=0){
                ans = min(ans,temp[i+1][remain-ch2] + ch1);
            }
        }
    }
 
    dp[curr] = temp[0][sum];
 
}
 
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
#ifdef DEBUG
    freopen("input", "r", stdin);
#endif
    int n;
    cin>>n;
    rep (i,1,n) {
        int p;
        cin>>p;
        p--;
        adj[p].push_back(i);
    }
 
    rep (i,0,n) {
        cin>>X[i];
    }
    dfs(0);
    if (dp[0]!=INF)cout<<"POSSIBLE";
    else cout<<"IMPOSSIBLE";
    return 0;
}

Measured memory_bytes: 37376
#include <bits/stdc++.h>
using namespace std;
int foo(vector<vector<char>>&arr, vector<vector<int>>&dp, int i, int j, int w, int h) {
    if (i > h || j > w) {
        return 0;
    }
    if (arr[i][j] == '#') {
        return dp[i][j] = 0;
    }
    if (dp[i][j] != -1)
        return dp[i][j];
    return dp[i][j] = (foo(arr, dp, i+1, j, w, h) + foo(arr, dp, i, j+1, w, h)) % 1000000007;
}

int main()
{
    int h, w;
    cin >> h >> w;
    vector<vector<char>> arr(h+1, vector<char>(w+1, '0'));
    vector<vector<int>> dp(h+1, vector<int>(w+1, -1));

    for (int i = 1; i <= h; i++) {
      for (int j = 1; j <= w; j++) {
          cin >> arr[i][j];
      }
    }
    dp[h][w] = 1;
    for (int j = w-1; j >= 1; j--) {
        if (arr[h][j] == '.') {
            dp[h][j] = dp[h][j+1];
        } else {
            dp[h][j] = 0;
        }
    }
    for (int j = h-1; j >= 1; j--) {
        if (arr[j][w] == '.') {
            dp[j][w] = dp[j+1][w];
        } else {
            dp[j][w] = 0;
        }
    }
    cout << foo(arr, dp, 1, 1, w, h);
  return 0;
}



Measured memory_bytes: 8704
#include <bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define ld long double
#define pb push_back
#define sz size

/*
author: Basel
*/

using namespace std;

const int N=2e5+5;

int n,m,ans[N];

vector<int>adj[N];

void dfs(int x,int par)
{
    for (auto X:adj[x])
    {
        if (X==par)continue;
        ans[X]+=ans[x];
        dfs(X,x);
    }
}

int main()
{
    cin >> n >> m;
    for (int i=0;i<n-1;i++)
    {
        int u,v;cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    while(m--)
    {
        int p,x;
        cin >> p >> x;
        ans[p]+=x;
    }
    dfs(1,1);
    cout << ans[1];
    for (int i=2;i<=n;i++)
    {
        cout << " " << ans[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 23424
#include <iostream>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
using namespace std; 
typedef long long ll; 
int p[200005], tot; 
bool np[2205]; 
map<ll, ll> app, to; 
int main()
{
	// freopen("AGC003-D.in", "r", stdin); 
	for (int i = 2; i < 2205; i++)
	{
		if (!np[i])
			p[tot++] = i; 
		for (int j = 0; j < tot && i * p[j] < 2205; i++)
		{
			np[i * p[j]] = true; 
			if (!(i % p[j]))
				break; 
		}
	}
	bool f = false; 
	int n; 
	scanf("%d", &n); 
	for (int i = 0; i < n; i++)
	{
		ll x, y = 1, z = 1; 
		scanf("%lld", &x);
		for (int j = 0; j < tot; j++)
		{
			int cnt = 0; 
			while (!(x % p[j]))
			{
				x /= p[j]; 
				cnt = (cnt + 1) % 3; 
			}
			int t = (3 - cnt) % 3; 
			while (cnt--)
				y *= p[j]; 
			while (t--)
				z *= p[j]; 
		}
		if (x != 1)
		{
			ll k = sqrt(x); 
			if (k * k == x)
			{
				y *= k * k; 
				z *= k; 
			}
			else
			{
				y *= x; 
				z *= x * x; 
			}
		}
		// cout << y << " " << z << endl; 
		if (y == 1)
		{
			f = true; 
			continue; 
		}
		app[y]++; 
		to[y] = z; 
	}
	// cout << endl; 
	ll ans = 0; 
	for (map<ll, ll>::iterator it = to.begin(); it != to.end(); it++)
	{
		if (it->second >= it->first || !to.count(it->second))
		{
			// cout << it->first << " " << it->second << " " << app[it->first] << " " << app[it->second] << endl; 
			ans += max(app[it->first], app[it->second]); 
		}
	}
	printf("%lld\n", ans + f);
	return 0; 
}


Measured memory_bytes: 18944
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//#include <math.h>
#include <algorithm>
#include <vector>
#pragma warning(disable:4996)

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define MOD 1000000007
using namespace std;


int main(int argc, char* argv[])
{
    long a,b;
    scanf("%ld %ld", &a, &b);

    long n=b-a;
    long ans=n*(n+1)/2-b;
    printf("%ld\n", ans);

    return 0;
}


Measured memory_bytes: 128
import sys
from bisect import bisect_right as br
from bisect import bisect_left as bl
input = sys.stdin.readline
N = int(input())
S = list(input())[: -1]
rs = []
gs = []
bs = []
res = 0
for i in range(N):
  if S[i] == "R": rs.append(i)
  if S[i] == "G": gs.append(i)
  if S[i] == "B": bs.append(i)
#print(rs, gs, bs)
for i in range(N):
  for j in range(i + 1, N):
    if S[i] == S[j]: continue
    d = j - i
    k = 0
    x = 0
    t = 0
    if S[i] == "R":
      if S[j] == "G":
        k = br(bs, j)
        x = bl(bs, j + d)
        t = len(bs) - k
        if len(bs) > x:
          t -= (j + d) == bs[x]
      elif S[j] == "B": 
        k = br(gs, j)
        x = bl(gs, j + d)
        t = len(gs) - k
        if len(gs) > x:
          t -= (j + d) == gs[x]
    elif S[i] == "G":
      if S[j] == "R":
        k = br(bs, j)
        x = bl(bs, j + d)
        t = len(bs) - k
        if len(bs) > x:
          t -= (j + d) == bs[x]
      elif S[j] == "B":
        k = br(rs, j)
        x = bl(rs, j + d)
        t = len(rs) - k
        if len(rs) > x:
          t -= (j + d) == rs[x]
    elif S[i] == "B":
      if S[j] == "R":
        k = br(gs, j)
        x = bl(gs, j + d)
        t = len(gs) - k
        if len(gs) > x:
          t -= (j + d) == gs[x]
      elif S[j] == "G":
        k = br(rs, j)
        x = bl(rs, j + d)
        t = len(rs) - k
        if len(rs) > x:
          t -= (j + d) == rs[x]
    res += t
    #print(i, j, t, k, x)
print(res)

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

#define LL long long
#define COIN const int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>

#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define REPD(i,n) for((i)=(n)-1;(i)>=0;(i)--)

#define ALL(c) (c).begin(), (c).end()
#define LEN(s) (s).size()
#define CLEAR(x) memset(x,0,sizeof x);

#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define VI vector<int>
#define VS vector<string>
#define VII vector<PII>
#define VVI vector<VI>

#define PIII 3.1415926
#define PI 3.14
/*****************************************************************************/

using namespace std;

bool yes[18]={1,0,0,0,1,0,0,1,1,0,0,1,1,0,1,1,1,0};
int n;

int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin >>n;
	if (n<18)
	{
		if (yes[n]==0)
		{
			cout <<"No"<<endl;
			return 0;
		}
	}
	cout <<"Yes"<<endl;
	return 0;
}
/******************************************************************************
******************************************************************************/


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <cmath>

#define	MOD 1000000007;
#define PI 3.14159265358979323846;
#define rep(i,n) for(ll i = 0;i<(ll)n;i++)
using namespace std;
typedef long long ll;
static const int MAX = 50;
static const long long INFTYL = 9223372036854775807;
ll mod = 1000000007;

int main()
{
	ll N, A, B;
	cin >> N >> A >> B;
	ll X[100000];
	rep(i, N) {
		cin >> X[i];
	}

	ll tired = 0;
	rep(i, N - 1) {
		tired += min((X[i + 1] - X[i])* A, B);
	}

	cout << tired << endl;
	return 0;
}

Measured memory_bytes: 1024
n = int(input())
num = list(map(str,input().split()))
a,b = [],[]
result = ''
for i in range(n):
  if i%2 == 0:
    a.append(num[i])
  else:
    b.append(num[i])
if n%2 ==1:
  result = ' '.join(a[::-1])
  result += ' ' + ' '.join(b)
else:
  result = ' '.join(b[::-1])
  result += ' ' + ' '.join(a)
print(result)

Measured memory_bytes: 26436
#include<iostream>
#include<cmath>
using namespace std;
#define N_MAX 50
int main(void)
{
  int n, m;
  int a[N_MAX], b[N_MAX], c[N_MAX], d[N_MAX];
  cin>>n>>m;
  for(int i=0; i<n; i++)
    cin>>a[i]>>b[i];
  for(int i=0; i<m; i++)
    cin>>c[i]>>d[i];

  for(int i=0; i<n; i++)
    {
      long long min=1000000000;
      int min_i;
      for(int j=0; j<m; j++)
	{
	  int x1=a[i];
	  int x2=c[j];
	  int y1=b[i];
	  int y2=d[j];
	  long long d=abs(x1-x2)+abs(y1-y2);
	  if(min>d)
	    {
	      min=d;
	      min_i=j;
	    }
	}
      cout<<min_i+1<<endl;
    }
  return 0;
  
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>

using namespace std;

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

typedef long long ll;

#define INF 1000000000000000000

int h[100010];
ll dp[100010];

void Main()
{
	int N; cin >> N;
	rep(i,N) cin >> h[i];

	rep(i,N) dp[i] = INF;
	dp[0] = 0;
	rep(i,N) {
		dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
		dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
	}
	cout << dp[N - 1] << endl;
}

int main()
{
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	Main();
}


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

int main()
{
	int x,y;
	cin>>x>>y;
	
	if(((2*x<=y) && (4*x>=y)) && (y%2==0 || y%4==0))
	  cout<<"Yes"<<endl;
	else
	  cout<<"No"<<endl;
	
	return 0;   
}

Measured memory_bytes: 3628
# 長さN
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))

import itertools

p = 0
q = 0
n = list(itertools.permutations(range(1,N+1)))
#print(n)
for i in range(len(n)):
    if list(n[i]) == P:
        p = i+1
    if list(n[i]) == Q:
        q = i+1

print(abs(p-q))

Measured memory_bytes: 46448
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const int INF=1000000001;
const double PI=3.141592653589;


int main(){
  int r,g; cin>>r>>g;
  cout<<2*g-r<<endl;

  return 0;
}


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

using namespace std;

int main()
{
  string s,ans="";
  cin >> s;
  int len = s.size();
  for(int i = 0 ; i < len ; i++)
  {
   	 if(s[i] == '0')ans += '0';
     else if(s[i] == '1')ans += '1';
     else
     {
      	if(ans.size() > 0)
          ans.erase(ans.size()-1,1);
     }
  }
  for(auto i : ans)
    if(i != '.')cout << i;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n,v) rep(i,n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
int x_pos[4] = {1,0,-1,0}, y_pos[4] = {0,1,0,-1};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

char upper(char c){
	return c-0x20;
}

char lower(char c){
	return c+0x20;
}

void unique_vector(vector<int>& v){
	sort(all(v));
	v.erase(unique(all(v)), v.end());
}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

//ユークリッドの互除法
//最大公約数
ll gcd(ll x, ll y) {
  if (y == 0) return x;
  return gcd(y, x%y);
}

//最小公倍数
ll lcm(ll x, ll y){
	ll g = gcd(x,y);
	return x/g*y;
}

ll myPow(ll x, ll n, ll m){
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}

int main() {
	ll n;
	cin >> n;
	cout << n * (n - 1) / 2 << endl;
}



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

void solve(const string S, const int K)
{
    int N = S.length(); /* digit of original "N" */
    // cout << "length of " << s << " is " << dig << endl;
    int dp[N + 1][K + 1][2];
    for (size_t i = 0; i < N + 1; i++)
    {
        for (size_t j = 0; j < K + 1; j++)
        {
            for (size_t k = 0; k < 2; k++)
            {
                dp[i][j][k] = 0;
            }
        }
    }

    dp[0][0][0] = 1; /* empty set */

    // cout << dp[1][1][0] << endl;

    for (size_t i = 0; i < N; i++)
    {
        for (size_t j = 0; j < K + 1; j++)
        {
            for (size_t k = 0; k < 2; k++)
            {
                int nd = S[i] - '0';
                for (size_t d = 0; d < 10; d++)
                {
                    int ni = i + 1, nj = j, nk = k;
                    if (d != 0)
                    {
                        nj++;
                    }
                    if (nj > K)
                    {
                        continue; /* out of bound */
                    }
                    if (k == 0)
                    {
                        if (d > nd)
                        {
                            continue; /* out of bound */
                        }
                        if (d < nd)
                        {
                            nk = 1;
                        }
                    }
                    dp[ni][nj][nk] += dp[i][j][k];
                }
            }
        }
    }
    cout << (dp[N][K][0] + dp[N][K][1]) << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    string S = "";
    int K = 0;
    cin >> S >> K;

    solve(S, K);
    return 0;
}


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

int main(){
  int N;
  int hundN;
  int tenN;
  int oneN;
  int flag = 0;
  cin >> N;
  hundN = N / 100;
  tenN = (N % 100 ) / 10;
  oneN = N % 10;
  if(hundN == 7 || tenN == 7 || oneN == 7){
    flag = 1;
  }
  if(flag == 1) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

namespace ConsoleApplication1
{
    static class Program
    {
        static void Main()
        {
            long n = long.Parse(Console.ReadLine());
            Console.WriteLine(ToAlphabet(n).ToLower());
        }

        static string ToAlphabet(this long self)
        {
            if (self <= 0) return "";
            long n = self % 26;
            n = (n == 0) ? 26 : n;
            string s = ((char)(n + 64)).ToString();
            if (self == n) return s;
            return ((self - n) / 26).ToAlphabet() + s;
        }

        static void ForEach<T>(this IEnumerable<T> src, Action<T> action)
        {
            foreach (T item in src) { action(item); }
        }
    }
}

Measured memory_bytes: 27824
#include<bits/stdc++.h>
using namespace std;
const double eps=1e-9;
struct dot{
	double x,y;
	double len(){return sqrt(x*x+y*y);}
	dot(double a=0.0,double b=0.0){x=a,y=b;}
	dot operator +(const dot&b)const {return dot(x+b.x,y+b.y);}
	dot operator -(const dot&b)const {return dot(x-b.x,y-b.y);}
	dot operator *(const double&z)const {return dot(x*z,y*z);}
	bool operator <(const dot&b)const {return (x<b.x)||(x==b.x&&y<b.y);}
	void read(){scanf("%lf%lf",&x,&y);} 
};
struct line{
	dot x1,x2;
	void read(){x1.read();x2.read();};
	dot getdot(){return x2-x1;}
};
double chaji(dot x,dot y){
	return x.x*y.y-x.y*y.x;
}
double neiji(dot x,dot y){
	return x.x*y.x+x.y*y.y;
}
double cos(dot x,dot y){
	if (!x.len()||!y.len())return 0;
	return neiji(x,y)/x.len()/y.len();
}
dot Projection(dot x,line y){//求x关于直线y的投影点（垂足） 
	y.x2=y.x2-y.x1;
	x=x-y.x1;
	double len=cos(x,y.x2)*x.len()/y.x2.len();
	y.x2=y.x2*len;
	return y.x2+y.x1;
}
dot Reflection(dot x,line y){//求x关于直线y的对称点 
	dot z=Projection(x,y);
	return z*2-x;
}
int Counter_Clockwise(dot x,line y){//求两个向量的五种关系 
	x=x-y.x1;y.x2=y.x2-y.x1;
	if (chaji(y.x2,x)!=0){
		if (chaji(y.x2,x)>0)return 1;
		return 2;
	} 
	if (fabs(cos(x,y.x2)+1)<eps)return 3;
	if (x.len()>y.x2.len())return 4;
	return 5;
} 
int Parallel_Orthogonal(line x,line y){//求两个直线是垂直还是平行还是其他 
	dot a=x.getdot(),b=y.getdot();
	if (chaji(a,b)==0)return 2;
	if (neiji(a,b)==0)return 1;
	return 0;
}
int Intersection(line x,line y){//求两条直线是否相交 
	int Minx1=min(x.x1.x,x.x2.x),Maxx1=max(x.x1.x,x.x2.x);
	int Minx2=min(y.x1.x,y.x2.x),Maxx2=max(y.x1.x,y.x2.x);
	int Miny1=min(x.x1.y,x.x2.y),Maxy1=max(x.x1.y,x.x2.y);
	int Miny2=min(y.x1.y,y.x2.y),Maxy2=max(y.x1.y,y.x2.y);
	if (Minx1>Maxx2||Minx2>Maxx1)return 0;
	if (Miny1>Maxy2||Miny2>Maxy1)return 0;
	if (chaji(x.getdot(),y.x1-x.x1)*chaji(x.getdot(),y.x2-x.x1)>0)return 0;
	if (chaji(y.getdot(),x.x1-y.x1)*chaji(y.getdot(),x.x2-y.x1)>0)return 0;
	return 1;
}
dot CrossPoint(line x,line y){//求两条线段的交点 
	if (fabs(cos(x.getdot(),y.getdot())-1)<eps){
		if (x.x2<y.x2)return y.x2;
		else return x.x2;
	}
	else {
		if (x.x2.x-x.x1.x==0){
			double k2=(y.x2.y-y.x1.y)/(y.x2.x-y.x1.x),b2=y.x2.y-y.x2.x*k2;
			return dot(x.x2.x,x.x2.x*k2+b2);
		}
		if (y.x2.x-y.x1.x==0){
			double k1=(x.x2.y-x.x1.y)/(x.x2.x-x.x1.x),b1=x.x2.y-x.x2.x*k1;
			return dot(y.x2.x,y.x2.x*k1+b1);			
		}
		double k1=(x.x2.y-x.x1.y)/(x.x2.x-x.x1.x),b1=x.x2.y-x.x2.x*k1;
		double k2=(y.x2.y-y.x1.y)/(y.x2.x-y.x1.x),b2=y.x2.y-y.x2.x*k2;
		dot ans;
		ans.x=(b2-b1)/(k1-k2);ans.y=ans.x*k1+b1;
		return ans;
	}
} 
int main(){
	int T;
	scanf("%d",&T);
	while (T--){
		line x,y;
		x.read();y.read();
		dot ans=CrossPoint(x,y);
		printf("%.10lf %.10lf\n",ans.x,ans.y);
	}
	return 0;
}



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

using namespace std;

typedef long long ll;
string s;
deque<ll> dq[27];
ll A[200050];
ll fw[200050];
ll n;
bool odd = false;
void update(ll p, ll v, ll *a){
	p++;
	for(;p<=n;p+=p&(-p)) a[p]+=v;
}
ll query(ll p, ll *a){
	p++;
	ll ans = 0;
	for(;p;p-=p&(-p)) ans+=a[p];
	return ans;
}
ll query(ll x, ll y, ll *a){
	return query(y,a )-query(x-1, a);
}
int main(){
	cin >> s;
	n = s.length();
	int oddguy = n/2;
	for(ll i=0; i<n; i++) dq[s[i]-'a'].push_back(i);
	for(ll i=0; i<26; i++){
//		printf("%c : ", i+'a'); for(auto i : dq[i]) printf("%d ", i); printf("\n");
		while(!dq[i].empty()){
			if(dq[i].size() == 1){
				oddguy = dq[i].front();
				if(odd){ cout << -1; return 0; }
				odd = true;
				break;
			}
			ll f = dq[i].front(), b = dq[i].back();
			dq[i].pop_front(); dq[i].pop_back();
			A[f] = b, A[b] = f;
		}
	}
//	for(ll i = 0; i<n; i++) printf("%d ", A[i]); printf("\n");
	ll ans = 0;
	ll complete = 0;
	for(ll i = 0; i<n; i++){
		if(odd and i == oddguy) continue;
		if(A[i] < i){ // closing
			update(A[i],-1,fw);
			ans += query(A[i],i,fw);
			complete++;
		}else{ // opening
			update(i,1,fw);
			ans += 2*complete;
		}
	}
	if(odd) for(int i = 0; i<n; i++){
		if(i == oddguy) continue;
		if(A[i] < i) if(A[i] > oddguy or i < oddguy) ans++;
	}
	cout << ans;
}


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

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

		if( a >= b )
		{
		cout << "No" << endl;
		}else{
			if( b >= c )
			{
			cout << "No" << endl;
			}else{
			cout << "Yes" << endl;
			}
		}

}


Measured memory_bytes: 3080
#include "bits/stdc++.h"
using namespace std;


int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	int64_t sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> a.at(i);
		sum += a.at(i);
	}

	int64_t temp = 0;
	for (int i = 1; i < n - 1; i += 2) {
		temp += a.at(i) * 2;
	}

	vector<int> x(n);
	x.at(0) = sum - temp;
	cout << x.at(0) << " ";
	for (int i = 0; i < n - 1; i++) {
		x.at(i + 1) = a.at(i) * 2 - x.at(i);
		cout << x.at(i + 1) << " ";
	}
	cout << endl;




	//vector<int> x(n);
	//int min = 0;
	//int max = a.at(0) * 2;

	//while (true) {
	//	bool flag = true;
	//	x.at(0) = (min + max) / 2;
	//	if (x.at(0) % 2 == 1) {
	//		x.at(0) -= 1;
	//	}
	//	for (int i = 0; i < n - 1; i++) {
	//		x.at(i + 1) = a.at(i) * 2 - x.at(i);
	//	}
	//	if (x.at(0) + x.at(n - 1) != a.at(n - 1) * 2) {
	//		flag = false;
	//	}
	//	if (flag == true) {
	//		break;
	//	} else {
	//		if (x.at(0) + x.at(n - 1) > a.at(n - 1) * 2) {
	//			max = x.at(0) - 2;
	//		} else {
	//			min = x.at(0) + 2;
	//		}
	//	}
	//}

	//for (int i = 0; i < n; i++) {
	//	cout << x.at(i) << " ";
	//}
	//cout << endl;
}


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

int main() {
  string s;
  cin >> s;
  map<char, int> mp;
  rep(i, s.size()) mp[s[i]]++;
  int a = mp['a'], b = mp['b'], c = mp['c'];
  // cerr << a << " " << b << " " << c << endl;
  if (abs(a - b) <= 1 && abs(b - c) <= 1 && abs(c - a) <= 1) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 512
import itertools

n=input()
p=[]
for i in range(3,len(n)+1):
    p+=list(itertools.product("357",repeat=i))
ans=0
for i in range(len(p)):
    s="".join(p[i])
    if int(s)>int(n):
        continue
    if all(s.count(c) for c in "753"):
        ans+=1
print(ans)

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

int main(){

	int H,W;

	while(cin >> H >> W, H && W){
		for(int i=0; i<H; i++){
			for(int j=0; j<W; j++){
				if(j==0 || j==(W-1) || i==0 || i==(H-1))
					cout << "#";
				else cout << ".";
			}
			cout << endl;
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 3068
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    StringBuilder output = new StringBuilder();
    String crlf = System.getProperty("line.separator");
    
    String cards;
    int count, shuffle;
    
    while (in.hasNext()) {
      cards = in.next();
      if (cards.equals("-")) break;
      count = in.nextInt();
      
      for (int i = 0; i < count; i++) {
        shuffle = in.nextInt();
        cards = shuffle(cards, shuffle);
      }
      System.out.println(cards);
    }
  }
  public static String shuffle(String cards, int shuffle) {
    StringBuilder output = new StringBuilder();
    String first = cards.substring(0, shuffle);
    String last = cards.substring(shuffle, cards.length());
    cards = output.append(last).append(first).toString();
    return cards;
  }
}

Measured memory_bytes: 18312
// https://atcoder.jp/contests/abc076/tasks/abc076_c
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define EPS (1e-9)
#define INF (1e9)
#define INFL (1e18)
#define MOD (1000000007)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define BIT(n) (1LL << (n))
// ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
// ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s, t;
    cin >> s >> t;
    vector<string> v;
    int slen = s.length(), tlen = t.length();
    for (int i = 0; i <= slen - tlen; i++) {
        bool find = true;
        for (int j = 0; j < tlen && i + j < slen; j++) {
            if (s[i + j] != '?' && s[i + j] != t[j]) {
                find = false;
                break;
            }
        }
        if (find) {
            string ss = s;
            for (int j = 0; j < tlen && i + j < slen; j++) {
                ss[i + j] = t[j];
            }
            for (auto &x : ss) {
                if (x == '?')
                    x = 'a';
            }
            v.push_back(ss);
        }
    }
    sort(ALL(v));
    if (v.size() == 0) {
        cout << "UNRESTORABLE\n";
    } else {
        cout << v[0] << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int main()
{
__asm("nop \n\t");
	for(int i = 1; i <= 9; i ++)
	{
		for(int j = 1; j <= 9; j ++)
		{
			::printf("%dx%d=%d\n", i, j, i * j);
		}
	}
}

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

using namespace std;

using ll = long long;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    ll ans = 0;
    for (int i = 1; i < n + 1; ++i) {
        if (i % 15 == 0 || i % 3 == 0 || i % 5 == 0) continue;
        ans += i;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3652
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    H, N = map(int, input().split())
    AB = [tuple(map(int, input().split())) for _ in range(N)]

    dp = [10**9+1] * (H+1)
    dp[0] = 0
    for a, b in AB:
        for i in range(1, H+1):
            if i - a >= 0:
                v = dp[i-a] + b
            else:
                v = b
            if dp[i] > v:
                dp[i] = v

    print(dp[H])

if __name__ == '__main__':
    main()


Measured memory_bytes: 40048
using System;

class Pratice
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        bool[,] cards = new bool[4, 13];
        for (int i = 0; i < n; ++i)
        {
            string[] str = Console.ReadLine().Split(' ');
            cards[str[0] == "S" ? 0 : str[0] == "H" ? 1 : str[0] == "C" ? 2 : 3, int.Parse(str[1]) - 1] = true;
        }
        for (int i = 0; i < 4; ++i)
        {
            for (int j = 0; j < 13; ++j)
            {
                if (!cards[i, j])
                {
                    Console.WriteLine("{0} {1}", i == 0 ? 'S' : i == 1 ? 'H' : i == 2 ? 'C' : 'D', j + 1);
                }
            }
        }
    }
}


Measured memory_bytes: 15936
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	int n, k;
	cin >> n >> k;

	out(k * (int)pow(k - 1, n - 1));

	return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;


int main(){
  ll n; cin >> n; vl high(n);
  rep(i,n){ ll x; cin >> x; high[i] = x; }
  
  ll sum = high[0]; 
  for(ll i=0; i < n-1; i++){
    if(high[i] < high[i+1]) sum += high[i+1] - high[i];
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 256
//Radhe Radhe
#include<bits/stdc++.h>
#define godspeed  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define rep1(i,a,b)    for(ll i=a; i<=b; i++)
#define repVect(i,n)    for(ll i=0; i<sum.size(); i++)
#define fixed cout.setf(ios::fixed);
#define Precise cout.precision(7);
#define yes cout<<"Yes"<<'\n';
#define no cout<<"No"<<'\n';
using namespace std;

int main()
{
    godspeed
    ll  t,i,j,k,l,r,g,b;
    cin>>r>>g>>b;
    ll num=r*100+g*10+b;

    if(num%4==0)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;

    return 0;
}





Measured memory_bytes: 3620
#include "bits/stdc++.h"
#define readInt(x) scanf("%d", &x)
#define readStr(x) scanf("%s", x)
#define rep(i, n) for(int i=0; i<(n); ++i)
#define write(x) cout << (x) << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1 << 28;
const int MAX = 1e5 + 10;

int N;
int a[MAX];

int main()
{
    cin >> N;
    rep(i, N) cin >> a[i];
    int cnt = 0;
    for (int i = 0, cnt = 0; cnt < N; cnt++) {
        if (i == 2 - 1) {
            write(cnt);
            return 0;
        }
        i = a[i] - 1;
    }
    write(-1);
}

Measured memory_bytes: 640
// D - Sum of Divisors
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rp(i,s,e) for(int i=(s);i<(int)(e);++i)

int main(){
	int N; cin>>N;
	vector<int> f(N+1);
	rp(d, 1, N+1)
		for(int k=d; k<=N; k+=d) f[k]++;
	ll  s = 0;
	rp(k, 1, N+1) s += (ll)k * f[k];
	cout<< s <<endl;
}


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

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

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}

const char newl = '\n';

int main() {
    ll n,x,y,m,ans = 0,sum = 0,cnt = 0;
    cin >> n >> x >> m;
    y = x;
    vector<bool> f(1e5,false);
    while (!f[x]) {
        f[x] = true;
        (x *= x) %= m;
    }
    for (;n && x != y;n--) {
        ans += y;
        (y *= y) %= m;
    }
    f = vector<bool>(1e5,false);
    while (!f[x]) {
        sum += x;
        cnt++;
        f[x] = true;
        (x *= x) %= m;
    }
    ans += n/cnt*sum;
    n %= cnt;
    for (int i = 0;i < n;++i) {
        ans += x;
        (x *= x) %= m;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
vector<LL> edges[110000];
vector<LL> wgt[110000];
LL sz[110000];
LL ok[110000];

LL ans = 0;
LL medge = 1e9;
LL n;
LL t = -1;
void dfs(int a, int p){
	sz[a] = 1;
	ok[a] = 1;	
	for(int j = 0; j < edges[a].size(); j++){
		if(edges[a][j] == p) continue;
		dfs(edges[a][j],a);
		LL k = sz[edges[a][j]];
		ans += 2LL*min(k,n-k) * wgt[a][j];
		sz[a] += k;
		if(k > (n/2)){
			ok[a] = 0;
		}
		if(k*2 == n){
			medge = wgt[a][j];
		}
	}
	if(n-sz[a] > (n/2)) ok[a] = 0;
	if(ok[a]){
		t = a;
	}
}

int main(){
	cin >> n;
	for(int i = 1; i < n; i++){
		LL a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		edges[a].push_back(b);
		edges[b].push_back(a);
		wgt[a].push_back(c);
		wgt[b].push_back(c);
	}
	ans = 0;
	dfs(0,-1);
	if(medge == 1e9 && t != -1){
		for(int j = 0; j < edges[t].size(); j++){
			medge = min(medge, wgt[t][j]);
		}
	}
	ans -= medge;
	cout << ans << endl;
}


Measured memory_bytes: 19968