akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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;
}

ll gcd(ll a, ll b)
{
    if (a % b == 0)
    {
        return (b);
    }
    else
    {
        return (gcd(b, a % b));
    }
}

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

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

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

int main(){
ll a,b,c;
cin>>a>>b>>c;
if(b-a==c-b){
    cout<<"YES"<<endl;
}else{
    cout<<"NO"<<endl;
}
}










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

int main(){

  string a, b, c;
  cin >> a >> b >> c;

  if (a.at(a.size() - 1) == b.at(0)){
    if (b.at(b.size() - 1) == c.at(0)){
      cout << "YES" << endl;
    }
    else{
      cout << "NO" << endl;
    }
  }
  else{
    cout << "NO" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>
#include <string>
#include <map>//map<int, int> x;
#include <numeric>
#define rep(i, n) for (int i = 1; i <= (int)(n); i++)
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
 
using ll = long long;
using namespace std;
 int main(){
int s,w; 
   string tmp="unsafe";
 cin>>s>>w;
   if(s>w)tmp="safe";
cout<<tmp<<endl;
}

Measured memory_bytes: 3628
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
#include<cstdlib>
#include<ctime>
#include<vector>
#include<map>
using namespace std;

int main(){
//srandom((unsigned long)time(NULL));

int s;
cin>>s;

int a,b;
a=s/100;
b=s%100;

//00-99  1
//01-12  2

int x=0;
int y=0;

if(a==0 || a>12)x=1;
if(b==0 || b>12)y=1;

if(x==1 && y==1)cout<<"NA"<<endl;
else if(x==1 && y==0)cout<<"YYMM"<<endl;
else if(x==0 && y==1)cout<<"MMYY"<<endl;
else cout<<"AMBIGUOUS"<<endl;



return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
using namespace std;
//cout << fixed << setprecision(0)
int main() { 
  int n,a=0,b=INF;
  cin >> n;
  rep(i,n){
    int c;cin >> c;
    a = max(a,c);
    b = min(b,c);
  }
  cout << a-b << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll ceil(ll num,ll div){
    return (num % div == 0 ? num / div : num / div + 1);
}
signed main(){
    ll K;
    cin >> K;
    vector<ll>A(K);
    for(auto & e : A) cin >> e;
    reverse(A.begin(),A.end());
    if(A.front() != 2)return puts("-1") * 0;
    ll lb = A.front(); ll ub = A.front() * 2 - 1;
    for(ll i = 1; i < A.size(); ++i){
        ll crt = A[i];
        ub = (ub / crt) * crt + crt - 1;
        lb = ceil(lb,crt) * crt;
        if(lb > ub) return puts("-1") * 0;
    }
    cout << lb << " " << ub << endl;
}



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

int main() {
  long long a,b,k;
  cin >> a >> b >> k;
  
  if(a>=k){
    a -= k;
  }
  else{
    if(b>k-a){
      b -= (k-a);
    }
    else{
      b = 0;
    }
    a = 0;
  }
  
  cout << a << ' ' << b << endl;
}

Measured memory_bytes: 256
// To the MOTHER OF DRAGONS	

//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
#include <bits/stdc++.h>
#define ll long long
#define llu unsigned long long
#define ld long double
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define PI 3.14159265358979323846
#define all(x) x.begin(), x.end()
#define deb(x) cerr << ">> " << #x << " : " << x << "\n"
#define RAGE ios::sync_with_stdio(0); cin.tie(0);

using namespace std;

const ll inf = 1e18 + 42;

void solve()
{
	ll n;
	cin >> n;
	ll sum = 0;
	for(ll i = 1; i <=n; i++)
	{
		if(i % 3 != 0 && i % 5 != 0)
		{
			sum += i;
		}
	}
	cout << sum << "\n";
}

int main()
{
	RAGE
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ll t;
	//cin >> t;
	//while(t--)
		solve();
	return 0;
}

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

using namespace std;
typedef int64_t ll;
typedef uint64_t ull;
typedef long double ld;

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

	int n;
	cin >> n;
	int a[n+1], b[n+1], c[n];
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = 1; i <= n; i++) cin >> b[i];
	for(int i = 1; i < n; i++) cin >> c[i];
	
	int res = 0;
	for(int i = 1; i <= n; i++) {
		res += b[a[i]];
		if(i > 1 && a[i] == a[i-1]+1)
			res += c[a[i-1]];
	}
	cout << res;
	
	cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << " ms.\n";
}

// g++ o .cpp -O2 -std=c++11 -D cute -Wall -Wno-unused-result



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// #define cerr if(false)cerr
#define watch(x) cerr << "\n" << (#x) << " is " << (x) << endl;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> ii;
typedef vector<vector<ll>> vvll;
typedef vector<pair<ll, ll>> vii;
typedef long double ld;
typedef vector<ld> vld;
typedef vector<vector<ld>> vvld;
typedef vector<bool> vbl;
typedef vector<vbl> mbl;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(s) (s).begin(), (s).end()
const ll MOD = 1e9 + 7;

inline void solve()
{
    int n;
    cin >> n;
    vll arr(n);
    ll x = 0;
    for (int i = 0; i < n; i++)
        cin >> arr[i], x ^= arr[i];
    for (int i = 0; i < n; i++)
        cout << (arr[i] xor x) << ' ';
}

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

    int t = 1;
    // cin >> t;
    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 4784
#include <iostream>
#include <cstdlib>

using namespace std;

typedef long long int lli;

int main() {
    lli x, y;
    cin >> x >> y;
    lli ans = 0;

    if (x < y) {
        if (x * y >= 0) {
            ans = y - x;
        } else {
            ans = abs(x + y) + 1;
        }
    } else if (x > y) {
        if (x * y >= 0) {
            ans = x - y + 2;
            if (x * y == 0) {
                ans --;
            }
        } else {
            ans = abs(x + y) + 1;
        }
    }

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


Measured memory_bytes: 256
use proconio::input;
use itertools::Itertools;

fn dedup(v: Vec<u64>) -> Vec<(u64, u16)>{
    let mut tmp = vec![];
    for i in v {
        let mut found = false;
        for j in 0..tmp.len() {
            let (t, n) = tmp[j];
            if i == t {
                found = true;
                tmp[j] = (t, n+1)
            }
        }
        if !found { tmp.push((i, 1)) }
    }
    tmp
}

fn count(xs: Vec<(u64, u16)>) -> u64 {
    let mut x_max = 0;
    let mut temp = 1;
    let mut total = 0;
    for (x, n) in xs {
        temp *= n;
        total += x;
        if x > x_max { x_max = x }
    }
    total -= x_max;
    if x_max < total { temp as u64 } else { 0 }
}

fn main() {
    input!(n: i16);
    let mut ls = vec![];
    for _ in 0..n {
        input!(l: u64);
        ls.push(l);
    }
    let ls = dedup(ls);
    let res = ls.into_iter()
                .combinations(3)
                .map(count)
                .sum::<u64>();
    println!("{}", res)
}

Measured memory_bytes: 2164
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
d = {}
sum = 0
for i in c:
    k = c[i]
    sum += k * (k - 1) / 2
for i in range(n):
    print(int(sum - c[a[i]] + 1))

Measured memory_bytes: 26780
#include <bits/stdc++.h>
using namespace std;
int a[2000005];

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

Measured memory_bytes: 1024
N = int(input())
A_list = [int(input()) for i in range(N)]

sorted_A_list = sorted(A_list)
n1 = sorted_A_list[-1]
n2 = sorted_A_list[-2]

for i in range(N):
    if A_list[i] == n1:
        print(n2)
    else:
        print(n1)


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

int main()
{
    ll A, B;
    cin >> A >> B;

    ll big, small;
    if (A > B)
    {
        big = A;
        small = B;
    }
    else
    {
        big = B;
        small = A;
    }

    ll mod = big % small;
    while (mod != 0)
    {
        big = small;
        small = mod;
        mod = big % small;
    }
    ll gcd = small;

    ll cnt = 1;
    for (int i = 2; i <= sqrt(gcd); i++)
    {
        if (gcd % i == 0)
        {
            cnt++;
            while (gcd % i == 0)
                gcd /= i;
        }
    }
    if (gcd != 1)
        cnt++;
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
/*input
8
2 8 8
1 5 1
4 8 2
2 5 4
3 8 6
6 8 9
2 7 12
*/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define sp ' '
#define endl '\n'
#define fi first
#define se second
#define mp make_pair
#define int long long
#define N 100005

int n;
vector<vector<pair<int, int> > > a(N);
int child[N];
int ans = 0;

void dfs(int u, int p, bool cal = 1) {
	child[u] = 1;
	for (int i = 0; i < a[u].size(); i++) {
		int v = a[u][i].fi; if (v == p) continue;
		dfs(v, u, cal);
		child[u] += child[v];
		if (cal)
			ans += a[u][i].se * min(child[v], n - child[v]) * 2;
	}
}

int findcen(int u, int p) {
	for (int i = 0; i < a[u].size(); i++) {
		int v = a[u][i].fi;
		if (v == p) continue;
		if (child[v] > n / 2) return findcen(v, u);
	}
	return u;
}

signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef UncleGrandpa
	freopen("1test.inp", "r", stdin);
#endif
	cin >> n;
	int mn = 1e18;
	for (int i = 1; i <= n - 1; i++) {
		int u, v, w;
		cin >> u >> v >> w;
		a[u].push_back(mp(v, w));
		a[v].push_back(mp(u, w));
	}
	dfs(1, 1);
	int root = findcen(1, 1);
	dfs(root, root, 0);
	for (int i = 0; i < a[root].size(); i++) {
		int v = a[root][i].fi; mn = min(mn, a[root][i].se);
		if (n % 2 == 0 && child[v] == n / 2) {
			cout << ans - a[root][i].se << endl;
			exit(0);
		}
	}
	cout << ans - mn << endl;
}

Measured memory_bytes: 15360
import Control.Monad
import Control.Applicative
import Data.List

-- String, Int, Char, IO

-- e.g.
-- 1
-- [a] <- map read . words <$> getLine => [1] -> a == 1
-- 1
-- a <- readLn
-- 1 2 3
-- lst <- map read . words <$> getLine => [1, 2, 3]
-- 1 2 3
-- [l, m, n] <- map read . words <$. getLine :: IO [Int] => [1, 2, 3]
-- 'a'
-- c <- getChar => c == 'a'


main :: IO()
main = do
  n <- readLn :: IO Int
  lst <- replicateM n readLn :: IO [Int]
  let l = splitBySame $ sort lst
  print $ length $ filter odd l


samelist :: Int -> [Int] ->  Int -> (Int, [Int])
samelist a [] n = (n+1, [])
samelist a (x:xs) n
              | a == x = samelist a xs (n+1)
              | a /= x = (n+1, x:xs)



splitBySame :: [Int] -> [Int]
splitBySame [] = []
splitBySame (x:xs) = let (n, list) = (samelist x xs 0) in n : (splitBySame list)


Measured memory_bytes: 60924
N = gets.to_i
P = gets.strip.gsub(' ', '')
Q = gets.strip.gsub(' ', '')

p = 0
q = 0
(1..N).to_a.permutation(N).each_with_index { |a, i|
    aa = a.join('')
    p = i if aa == P
    q = i if aa == Q
}

puts (p-q).abs


Measured memory_bytes: 1916
import sys
import math
def input():
    return sys.stdin.readline()[:-1]

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def trial_division(n):
    factor = []
    tmp = int(math.sqrt(n)) + 1
    for num in range(2,tmp):
        while n % num == 0:
            n //= num
            factor.append(num)
    if n!=1:
        factor.append(n)
    return factor

n,m=map(int,input().split())
mod=10**9+7
if m==1:
    print(1)
    quit()
li=trial_division(m)
tmp=li[0]
countli=[]
count=1
for i in range(1,len(li)):
    if tmp!=li[i]:
        countli.append(count)
        count=1
    else:
        count+=1
    tmp=li[i]
countli.append(count)
ans=1
for i in range(len(countli)):
    r=countli[i]
    s=n+r-1
    r=min(r,n-1)
    p=1
    for j in range(r):
        p*=s-j
        p//=j+1
    ans*=p
    ans%=mod
    
print(ans%mod)

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


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

	int64_t ans = 0;
	for (int i = 0; i < n; i++) {
		if (a.at(i) > b.at(i)) {
			ans += b.at(i);
		} else if (a.at(i) + a.at(i + 1) > b.at(i)) {
			ans += b.at(i);
			a.at(i + 1) -= b.at(i) - a.at(i);
		} else {
			ans += a.at(i) + a.at(i + 1);
			a.at(i + 1) = 0;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 1792
import java.util.*;

public class Main {

    public static int harshad(int n) {
        int sum = 0;
        while (n != 0) {
            sum += n % 10;
            n /= 10;
        }
        return sum;
    }

    public static String isHarshad(int n) {
        return n % harshad(n) == 0 ? "Yes" : "No";
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println(isHarshad(sc.nextInt()));
    }

}


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

void insertionSort(vector<int>& a, int n) {
    for (int i=1; i<n; i++) {
        int v = a[i];
        int j = i - 1;
        while (j >= 0 && a[j] > v) {
            a[j+1] = a[j];
            j--;
        }
        a[j+1] = v;

        for (int i=0; i<a.size()-1; i++) cout << a[i] << " ";
        cout << a[n-1] <<  endl;
    }
}

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i=0; i<N; i++) cin >> A[i];
    for (int i=0; i<N-1; i++) cout << A[i] << " ";
    cout << A[N-1] << endl;

    insertionSort(A, N);

    return 0;
}



Measured memory_bytes: 3092
S = gets.chomp
T = gets.chomp
N = S.length
def check(s, t)
  cs = {}
  (0...N).all?{|i|
    cs[s[i]] ||= t[i]
    t[i] == cs[s[i]]
  }
end
ans = check(S, T) && check(T, S)
puts ans ? 'Yes' : 'No'

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

using namespace std;
#define ll long long

#define rep(i, a) for (int i = 0; i < (int) (a); i++)
#define reps(i, a, b) for (int i = (int) (a); i < (int) (b); i++)
#define rrep(i, a) for (int i = (int) a-1; i >= 0; i--)
#define rreps(i, a, b) for (int i = (int) (a)-1; i >= (int) (b); i--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__ "YES"
#define FALSE__ "NO"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#ifdef LOCAL
#define lcout(a) cout << a;
#define lcoutln(a) cout << a << endl;
#define lcerr(a) cerr << a;
#define lcerrln(a) cerr << a << endl;
#else
#define lcout(a) 
#define lcoutln(a) 
#define lcerr(a) 
#define lcerrln(a) 
#endif


signed main()
{
	string s, t;
	cin >> s >> t;
	rep(i, s.length()) {
		cout << s[i];
		if (i < (int) t.length()) cout << t[i];
	}
	cout << endl;
}




Measured memory_bytes: 256
import static java.lang.System.*;
import java.util.*;

public class Main {
	public static final int MOD = 1000000007;
	
    public static void main(String[] args) {
        Scanner sc = new Scanner(in);

        int n = sc.nextInt();
		
		long[][][][] dp = new long[4][4][4][n-3+1];
		for(int i=0; i<4; i++) 
			for(int j=0; j<4; j++) 
				for(int k=0; k<4; k++) {
					Arrays.fill(dp[i][j][k], 0L);
					dp[i][j][k][0] = 1L;
				}
		dp[0][1][2][0] = 0L;
		dp[0][2][1][0] = 0L;
		dp[1][0][2][0] = 0L;
		
		for(int m=0; m<n-3; m++) 
			for(int i=0; i<4; i++) 
				for(int j=0; j<4; j++) 
					for(int k=0; k<4; k++)
						for(int l=0; l<4; l++) {
							dp[j][k][l][m+1] += dp[i][j][k][m];
							dp[j][k][l][m+1] %= MOD;
							
							dp[0][1][2][m+1] = 0L;
							dp[0][2][1][m+1] = 0L;
							dp[1][0][2][m+1] = 0L;
							if(i==0) {
								for(int o=0; o<4; o++) {
									dp[o][1][2][m+1] = 0L;
									dp[1][o][2][m+1] = 0L;
								}
							}
						}
		
		long sum = 0L;
		for(int i=0; i<4; i++) 
			for(int j=0; j<4; j++) 
				for(int k=0; k<4; k++) {
					sum += dp[i][j][k][n-3];
					sum %= MOD;
				}
		
		out.println(sum);
	}
}


Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

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

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

void solve(long long N, long long Y)
{
    ll ans = 0;
    for (int i = 0; i <= N; i++)
    {
        for (int j = 0; j <= N; j++)
        {
            ll k = N - i - j;
            if (k < 0 || N < k)
                continue;

            if (10000 * i + 5000 * j + 1000 * k == Y)
            {
                cout << i << " " << j << " " << k << endl;
                return;
            }
        }
    }

    cout << "-1 -1 -1" << endl;
}

int main()
{
    long long N;
    scanf("%lld", &N);
    long long Y;
    scanf("%lld", &Y);
    solve(N, Y);
    return 0;
}


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

struct data{
    int y,m,d;
    void set(int y,int m,int d){
        this->y = y;
        this->m = m;
        this->d = d;
    }
};

bool operator<(const data& d1, const data& d2){
    if(d1.y == d2.y){
        if(d1.m == d2.m){
            return d1.d < d2.d;
        }
        return d1.m < d2.m;
    }
    return d1.y < d2.y;
}

map<data, int> memo;

int main() {

    int count = 0;
    int maxd = 0;

    for(int y=1; y<1000; y++){
        for(int m=1; m<=10; m++){
            int limit = 20;
            if(y%3 != 0 && m%2 == 0){
                limit = 19;
            }
            for(int d=1; d<=limit; d++){
                count++;
                data d1;
                d1.set(y, m, d);
                memo[d1] = count;
                maxd = count;
            }
        }
    }


    int n;
    cin >> n;

    for(int loop = 0; loop < n; loop++){

        int y,m,d;

        cin >> y >> m >> d;

        data input;
        input.set(y, m, d);

        cout << maxd - memo[input] + 1 << endl;

    }


    return 0;
}


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


void solve(long long N, long long A){
    cout << N * N - A <<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long A;
    scanf("%lld",&A);
    solve(N, A);
    return 0;
}


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

signed main() {
  int n,k;
  cin>>n>>k;
  if(k>(n-1)*(n-2)/2){
    cout<<-1;
    return 0;
  }
  cout<<n-1+((n-1)*(n-2)/2 -k)<<endl;
  for(int i=2;i<=n;i++)cout<< 1<<' '<<i<<endl;
  int a=2,b=3;
  for(int i=0;i<(n-1)*(n-2)/2 -k;i++){
    cout<<a<<' '<<b<<endl;
    if(b<n){
      b++;
      continue;
    }
    a++;
    b=a+1;

  }

 


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <assert.h>
#include <numeric>
#include <math.h>
#include <climits>

using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
typedef long long ll;

template <typename T>
T gcd(T a, T b) {
    if(a < b) gcd(b, a);
    if (b == 1) return 1;
    T r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

#define MOD (1000000000+7)

int main() {
    ll W, H, x, y;
    cin >> W >> H >> x >> y;
    cout << W*H*0.5 << " ";
    if (2*x == W && 2*y == H) {
        cout << "1" << endl;
    }else {
        cout << "0" << endl;
    }
}


Measured memory_bytes: 256
import java.util.*;
import java.math.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] list = new int[9];
        start:for(int i=0;i<n;i++){
            int s = Integer.parseInt(sc.next());
            int rate = s/400;
            if(rate<8) list[rate]++;
            else list[8]++;
        }
        int aans = 0;
        int bans = 0;
        for(int i=0;i<8;i++){
            if(list[i]>0) aans++; 
        }
        bans = aans+list[8];
        if(aans == 0) {aans=1;}
        System.out.println(aans + " " + bans);
        
    }
}

Measured memory_bytes: 23764
#include <iostream>
#include <utility>
#include <vector>
#include <tuple>

void Display(std::vector<long int> ary) {
    long int n = ary.size();
    for (long int i = 0; i < n; i++) {
        std::cout << ary[i];
        if (i < n -1) {
            std::cout << " ";
        }else{
            std::cout << std::endl;
        }
    }
}

std::vector<long int> GetInput() {
    long int n = -1;
    std::vector<long int> ary;
    std::cin >> n;
    ary.resize(n);
    for (long int i = 0; i < n; i++) {
        std::cin >> ary[i];
    }
    return ary;
}


std::tuple<std::vector<long int>, long int>
    InsertionSort(std::vector<long int> ary, long int gap = 1) {
    long int cnt = 0;
    if (gap < 1) {
        std::cout << "----------" << std::endl;
        std::cout << "Invalid gap is inputted." << std::endl;
        std::cout << gap << std::endl;
        std::cout << "----------" << std::endl;
    }
    long int n = ary.size();
    for (long int i=gap; i<n; i++) {
        long int temp = ary[i];
        long int j = i - gap;
        while(j>=0 && ary[j] > temp) {
            ary[j+gap] = ary[j];
            cnt++;
            j -= gap;
        }
        ary[j+gap] = temp;
    }
    return std::tuple<std::vector<long int>, long int>(ary, cnt);
}

std::vector<long int> ShellSort(std::vector<long int> ary) {
    long int cnt = 0;
    long int n = ary.size();
    std::vector<long int> g_params;
    for (int i = 1; i <= n;) {
        g_params.push_back(i);
        i = i * 3 + 1;
    }
    std::cout << g_params.size() << std::endl;
    for (int i = g_params.size() - 1; i > 0; i--) {
        std::cout << g_params[i] << " ";
    }
    std::cout << g_params[0] << std::endl;

    for (int i = g_params.size()-1; i >= 0; i--) {
        auto result = InsertionSort(ary, g_params[i]);
        ary = std::get<0>(result);
        cnt += std::get<1>(result);
    }

    std::cout << cnt << std::endl;
    for(auto it: ary) {
        std::cout << it <<std::endl;
    }
    return ary;
}


int main(int argc, char const* argv[])
{
    auto ary = GetInput();
    auto sorted_ary = ShellSort(ary);
//     Display(sorted_ary);
    return 0;
}

Measured memory_bytes: 34192
#include<iostream>
#include<strstream>
#include<utility>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cmath>
#include<climits>
#include<map>
#include<string>
#include<sstream>

using namespace std;

#define mp make_pair
#define rep(i,n) for( int i = 0; i < n; i++ )
typedef vector<int,int> V;
typedef long long int ll;


int StringToInt(string str)
{
    istrstream istr(str.data());
    int i;
    istr>>i;
    return i;
}

string IntToString(int number)
{
	stringstream ss;
	ss << number;
	return ss.str();
}

int main()
{
	string a;
	int L;

	while( cin >> a >> L, L )
	{
		if( a == "0" ) 
		{
			puts("0 0 1");
			continue;
		}
		map< string,int > container;
		for( int i = 1; i <= 20; i++ )
		{
			container.insert( mp( a,0 ) );
			while( a.size() < L )
			a = '0' + a;
			int k;
			stable_sort( a.begin() , a.end() , greater<int>() );
			k = StringToInt(a);
			stable_sort( a.begin() , a.end() );
			k -= StringToInt(a);
			a = IntToString(k); 
			if( !container.insert( mp(a,i) ).second )
			{
				map< string,int >::iterator itr = container.begin();
				itr = container.find(a);
				cout << itr->second << " " << k << " " << i - itr->second << endl; 
				break;
			}
		}

	}
	return 0;
}

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

int main() {
  ios::sync_with_stdio(0);
  int n; cin >> n;
  vector <int> v(n);
  for(int i = 0; i < n; i++) cin >> v[i];

  int mx = 1, now = 1;
  for(int i = n - 2;  i >= 0; i--) {
    if(v[i] >= v[i + 1]) now++, mx = max(mx, now);
    else now = 1;
  }
  cout << mx - 1 << endl;
  return 0;
}
/*
#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(0);

  return 0;
}
 */

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

int main(){
  int m,d,dd,ddd,i,j,h,ans;
  cin >> m >> d;
  ans =0;
  for(i=4;i<=m;i++){
    for(j=22;j<=d;j++){
      dd=j/10;
      ddd=j%10;
      h=dd*ddd;
      if((h==i)&&(ddd!=1)){
        ans=ans+1;
      }
    }
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
//**************************
//*** writer  :  Alan Hu **
//************************

//傅思程你敢抄我程序？？？
//傅思程你敢抄我程序？？？
//傅思程你敢抄我程序？？？

#include<bits/stdc++.h>

using namespace std;

#define CLEAN(a,b) memset(a,b,sizeof(a))
#define mkp make_pair
#define pb push_back
#define rept(i,a,b) for(int i=(int)(a);i<(int)(b);i++)

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
 
string s;
char cnt;
map<string,int> mp;
int n;
 
int main()
{
	int n;
	cin>>n;
	rept(i,0,n)
	{
		cin>>s;
		mp[s]++;
		if (mp[s]>=2)
		{
			cout<<"No"<<endl;
			return 0;
		}
		if (i==0) cnt=s[0];
		if (cnt!=s[0])
		{
			cout<<"No"<<endl;
			return 0;
		}
		cnt=s[s.size()-1];
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <map>
#include <math.h>
#include <vector>
using namespace std;
struct cww { cww() { ios::sync_with_stdio(false); cin.tie(0); } }star;
map<int, int> ct;
map<int, int> ct2;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vll;
#define INF 0x3f3f3f3f
#define MOD 998244353LL
#define EPS 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair

#define FOR(i, a, b) for (int i=(a); i<=(signed)(b); i++)
#define AFOR(i, a) for (int i=0; i<(signed)(a); i++)
#define RFOR(i, a, b) for (int i=(a); i >= b; i--)

#define MN 100005
int n, m, l;
int a, b, c;
string s[MN];
string str;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

/*
int N;
cin >> N;
vi vect(N);
FOR(i,N) cin >> vec.at(i);*/
//sort(vec.begin(),vec.end());
//vvi data(N,vi(4));

std::vector<int> Eratosthenes(const int N)
{
	std::vector<bool> is_prime(N + 1);
	for (int i = 0; i <= N; i++)
	{
		is_prime[i] = true;
	}
	std::vector<int> P;
	for (int i = 2; i <= N; i++)
	{
		if (is_prime[i])
		{
			for (int j = 2 * i; j <= N; j += i)
			{
				is_prime[j] = false;
			}
			P.emplace_back(i);
		}
	}
	return P;
}
/*	int bfs(int x, int y,vvi &A,vvi flag) {
		queue<pii> que;
		que.push(pii(x, y));
		while (que.size()) {
			pii p = que.front(); que.pop();
			AFOR(i, 4) {
				int nx = p.first + dx[i]; int ny = p.second + dy[i];
				if (0 <= nx && nx < N && 0 <= ny && ny < N) {
					if (A.at(p.first).at(p.second) + flag.at(p.first).at(p.second) < A.at(nx).at(ny)) {
						A.at(nx).at(ny) = A.at(p.first).at(p.second) + flag.at(p.first).at(p.second);
						que.push(pii(nx, ny));
					}
				}
			}
		}
		return 0;
	}
	*/
	/*int gcd(int p, int q){
		while(q != 0){
		int r = p % q;
		p = q;
		q = r;
		}
	return p;
	}*/
ll N;
ll K;
ll A[200100];
int  L[200100];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int X,Y;
	cin >> X >> Y;
	if (4 * X - Y < 0) cout << "No" << endl;
	else if(4*X-Y == 0)cout << "Yes" << endl;
	else if ((4 * X - Y) % 2 == 0 && Y -2*X >= 0) { cout << "Yes" << endl; }
	else cout << "No" << endl;
	return 0;

}

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

int main(){
	//??????????¢??????¨?????°
	string s, p;

	//??\???
	cin >> s;
	cin >> p;

	//??????????????¨????????°
	int flag = 0;

	s += s;
	int s_length = s.length();
	int p_length = p.length();
	for (int i = 0; i < s_length - p_length; i++)
	{
		if (s.substr(i, p_length) == p){
			flag = 1;
			break;
		}
	}
	if (flag){
		cout << "Yes" << endl;
	}else
	{
		cout << "No" << endl;
	
	}
	return 0;
}

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

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

  string S[N];
  int flag[4] = {};
  for(int i=0; i<N; i++){
    cin >> S[i];
    if(S[i]=="P"){
      flag[0]++;
    }else if(S[i]=="W"){
      flag[1]++;
    }else if(S[i]=="G"){
      flag[2]++;
    }else if(S[i]=="Y"){
      flag[3]++;
    }
  }

  int kinds = 0;
  for(int i=0; i<4; i++){
    if(flag[i]>0){
      kinds++;
    }
  }

  if(kinds==3){
    cout << "Three" << endl;
  }else if(kinds==4){
    cout << "Four" << endl;
  }else{
    cout << "error" << endl;
  }

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
    #define ll long long int
    using namespace std;
    int main()
    {
        ll n;
        ll we;
        cin>>n>>we;
        ll val[100000];
        ll w[100000];
        ll dp[n+1][we+1];
        for(int i=0;i<n;i++){

            cin>>w[i];
              cin>>val[i];
        }

        for(int i =0;i<=n;i++){
            for(int W=0;W<=we;W++){
                    if(i==0 || W==0 ){
                        dp[i][W]=0;
                    }
                    else if(W>=w[i-1]){
                        dp[i][W]=max(dp[i-1][W-w[i-1]]+val[i-1],dp[i-1][W]);
                    }
                    else{
                        dp[i][W]=dp[i-1][W];
                    }

            }
        }
        cout<<dp[n][we];
    }


Measured memory_bytes: 79104
#include<cstdio>
#include<iostream>
#include<sstream>
#include<cstdlib>
#include<cstring>
#include<string>
#include<climits>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<fstream>
#include<iomanip>
#define pi 3.14159265358
using namespace std;
#define fout cout
#define fin cin
#define maxn 200000+10

#define clr(a) memset(a,0,sizeof(a))
int dist[100][100];
int jl[100][100];
int main()
{
    int n,u,v,d,i,j,k;
    int exist[100];
   while(cin>>n)
   {
       if(n==0) break;
       clr(exist);
       for(i=0;i<=30;i++)
        for(j=0;j<=30;j++)
       {
        jl[i][j]=dist[i][j]=9999999;
        if(i==j) jl[i][j]=dist[i][j]=0;
       }
       for(i=1;i<=n;i++)
       {

        scanf("%d%d%d",&u,&v,&d);
        exist[u]=exist[v]=1;
        dist[u][v]=dist[v][u]=d;
       }
       for(i=0;i<=10;i++)
        for(j=0;j<=10;j++)
        for(k=0;k<=10;k++)
       {

           dist[j][k]=min(dist[j][k],dist[j][i]+dist[i][k]);
       }
       int tot[100];
       clr(tot);
       for(i=0;i<=10;i++)
       {
           if(!exist[i]) continue;
           for(j=0;j<=10;j++)
           {
           if(!exist[j]) continue;

            tot[i]+=dist[i][j];
           }
       }
       int mi=-1;
       for(i=0;i<=10;i++)
       {
           if(tot[i]==0) continue;
           if(mi==-1) mi=i;
           if(tot[mi]>tot[i]) mi=i;
       }

      cout<<mi<<" "<<tot[mi]<<endl;
   }
}



Measured memory_bytes: 3172
use std::collections::{BTreeSet, VecDeque};

const MOD: u64 = 998244353;
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let s = sc.chars();
    let n = s.len();

    if n <= 4 {
        println!("{}", naive(s));
        return;
    }

    if s.iter().all(|&c| c == s[0]) {
        println!("1");
        return;
    }

    let mut dp: Vec<Vec<Vec<u64>>> = vec![vec![vec![0; 2]; 3]; 3];
    dp[0][0][0] = 1;
    for i in 0..n {
        let mut next_dp = vec![vec![vec![0; 2]; 3]; 3];
        for cur in 0..3 {
            for remain in 0..3 {
                for next in 0..3 {
                    let same = if cur == next && i > 0 { 1 } else { 0 };
                    let next_remain = (remain + next) % 3;
                    next_dp[next][next_remain][same] += dp[cur][remain][0];
                    next_dp[next][next_remain][1] += dp[cur][remain][1];
                }
            }
        }

        for i in 0..3 {
            for j in 0..3 {
                for k in 0..2 {
                    next_dp[i][j][k] %= MOD;
                }
            }
        }
        dp = next_dp;
    }

    let remain: usize = s.iter().map(|&c| c as usize - 'a' as usize).sum::<usize>() % 3;
    let mut ans = dp[0][remain][1] + dp[1][remain][1] + dp[2][remain][1];
    if (1..n).all(|i| s[i] != s[i - 1]) {
        ans += 1;
    }
    println!("{}", ans % MOD);
}

fn naive(s: Vec<char>) -> usize {
    let mut set = BTreeSet::new();
    let mut q = VecDeque::new();
    q.push_back(s.clone());
    set.insert(s);
    while let Some(s) = q.pop_front() {
        for i in 1..s.len() {
            if s[i - 1] == s[i] {
                continue;
            }
            let c = match (s[i - 1], s[i]) {
                ('a', 'b') | ('b', 'a') => 'c',
                ('a', 'c') | ('c', 'a') => 'b',
                ('b', 'c') | ('c', 'b') => 'a',
                _ => unreachable!(),
            };
            let mut t = s.clone();
            t[i - 1] = c;
            t[i] = c;
            if !set.contains(&t) {
                set.insert(t.clone());
                q.push_back(t);
            }
        }
    }
    set.len()
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
using System;
using System.Linq;

namespace ABC86
{
    class Program
    {
        static void Main(string[] args)
        {
            var solver = new Solver();
            solver.Solve2();
        }
    }

    public class Solver
    {

        public void Solve1()
        {
            var ab = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Console.WriteLine(ab[0] * ab[1] % 2 == 0 ? "Even" : "Odd");

        }

        public void Solve2()
        {
            var ab = int.Parse(Console.ReadLine().Replace(" ", ""));

            Console.WriteLine(Math.Sqrt(ab) - (int)Math.Sqrt(ab) == 0 ? "Yes" : "No");


        }
    }
}


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

int main(){
  long long N,D,ans=0;
  cin >> N >> D;
  for(int i=0;i<N;i++){
    long long x,y;
    cin >> x >> y;
    if(x*x+y*y<=D*D) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int n;
  R n;
  int a[n][10],b[n][11];
  rep(i,n)rep(j,10) R a[i][j];
  rep(i,n)rep(j,11) R b[i][j];
  int ans=-MAX;
  REP(t,1,1<<10) {
    int sum=0,c[n];
    mem(c);
    rep(i,n) {
      rep(j,10) {
        if(t&(1<<j)) c[i]+=a[i][j];
      }
    }
    rep(i,n) sum+=b[i][c[i]];
    ans=max(ans,sum);
  }
  pr(ans);
}

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


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define MAX_N 500
#define MAX_F 100

i64 C[MAX_N];
i64 S[MAX_N];
i64 F[MAX_N];

i64 rec(i64 si, i64 t, i64 ti) {
    if (si == ti) return t;

    chmax(t, S[si]);
    t = (t / F[si] + (t % F[si] > 0)) * F[si];
    return rec(si + 1, t + C[si], ti);
}

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

    REP(i, N - 1) cin >> C[i] >> S[i] >> F[i];

    REP(i, N) {
        cout << rec(i, 0, N - 1) << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int n, a, mx = -1000000007, mxnm, id[2] = {0, 0};
  long long sm[2] = {0, 0};
  int mns[2][1000];
  mns[0][0] = mns[1][0] = 0;
  scanf("%d", &n);
  for(int i = 0; i < n; i++){
    scanf("%d", &a);
    if(mx < a) mx = a, mxnm = i+1;
    if(a > 0) sm[i&1] += a;
    else mns[i&1][id[i&1]++] = i+1;
  }
  if(mx <= 0){
    printf("%d\n%d\n", mx, n-1);
    for(int i = n; i > mxnm; i--) printf("%d\n", i);
    for(int i = 1; i < mxnm; i++) printf("%d\n", 1);
  }else{
    bool t = (sm[0] < sm[1]);
    int cnt  =  n/2 + (n&1 && t) + (mns[t][0] == 1) + (mns[t][id[t]-1] == n);
    printf("%lld\n%d\n", sm[t], cnt);
    for(int i = id[t]-1; i >= 0; i--) printf("%d\n", mns[t][i]);
    for(int i = 0; i < cnt - id[t]; i++)
      printf("%d\n", (t^(mns[t][0] == 1) ? (i == cnt - id[t] -1) ? 1 : 3 : 2));
  }   
}


Measured memory_bytes: 256
n, m = map(int, input().split())
n_m_matrix = [list(map(int, input().split())) for _ in range(n)]
m_1_matrix = [int(input()) for _ in range(m)]
answer = []
for row in n_m_matrix:
    tmp = 0
    for i in range(m):
        tmp += row[i] * m_1_matrix[i]
    answer.append(tmp)

[print(n) for n in answer]



Measured memory_bytes: 6024
from collections import deque

N, Q = map(int, input().split())
graph_lis = [[] for n in range(N)]

for i in range(N - 1):
    a, b = map(int, input().split())
    graph_lis[a - 1].append(b - 1)
    graph_lis[b - 1].append(a - 1)

ans = [0] * N
for q in range(Q):
    p, x = map(int, input().split())
    ans[p - 1] += x

deq = deque([0])
visited = [False] * N
while deq:
    parent = deq.popleft()
    edge = graph_lis[parent]
    for v in edge:
        if not visited[v]:
            ans[v] += ans[parent]
            deq.append(v)
    visited[parent] = True
print(*ans)

Measured memory_bytes: 56188
#include <bits/stdc++.h>
#define Phuong_ ios_base::sync_with_stdio(0); cin.tie(0);
#define pb push_back
#define mp make_pair

/// easy access -------------
using namespace std;
using ll = long long;
using ld = long double;
typedef pair<ll,ll> pii;
///-------------------------


int main()
{
    Phuong_; /// <3
    ll sum=0;
    int n;
    cin >> n;
    for(int i=1; i<=n; ++i)
        if (i%3!=0 && i%5!=0) sum+=i;
    cout << sum;
    return 0;
}



Measured memory_bytes: 3640
#include "bits/stdc++.h"
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define repf(i, x, n) for (int i = (int)(x); i < (int)(n); i++)
#define repfr(i, x, n) for (int i = (int)(x)-1; i >= (int)(n); i--)
#define INF 1e9
using ll = int64_t;
template <class T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, const T &b)
{
  if (b < a)
  {
    a = b;
    return true;
  }
  return false;
}

//10^9 + 7
#define yojo 1000000007

std::int64_t gcd(std::int64_t a, std::int64_t b)
{
  // a >= b && b != 0
  std::int64_t c;
  do
  {
    c = a % b;
    a = b;
    b = c;
  } while (c);

  return a;
}
std::int64_t gcd_s(std::int64_t aa, std::int64_t bb)
{
  std::int64_t a = max(aa, bb);
  std::int64_t b = min(aa, bb);
  std::int64_t c;
  if (b == 0)
  {
    return -1;
  }
  do
  {
    c = a % b;
    a = b;
    b = c;
  } while (c);

  return a;
}
void rle(std::vector<std::pair<char, std::int64_t>> &data, std::string str)
{
  char now = str[0];
  std::int64_t count = 0;
  for (std::int64_t i = 0; i < str.size() + 1; i++)
  {
    if (i == str.size())
    {
      data.push_back(make_pair(str[i - 1], count));
      break;
    }
    else if (now != str[i])
    {
      data.push_back(make_pair(now, count));
      now = str[i];
      count = 0;
    }
    count++;
  }

  return;
}

#define MAX_NUM 200001

void Main()
{
  int n;
  cin >> n;
  vector<pair<int, int>> a(n);
  for (int i = 0; i < n; i++)
  {
    int tmp;
    cin >> tmp;
    a[i] = make_pair(tmp, i + 1);
  }

  sort(all(a));

  for (auto &&i : a)
  {
    std::cout << i.second << ' ';
  }

  std::cout << std::endl;

  return;
}

int main()
{
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Measured memory_bytes: 1664
/* ex4-2
   Sagzar1993  */

#include <stdio.h>
#include <math.h>

int main(void) {
    int hourLen, minuteLen, hour, minute;  //時針と分針の長さ、現在の時刻

    scanf("%d %d %d %d", &hourLen, &minuteLen, &hour, &minute); //入力を受け取る

    //０時ちょうどの時の針の角度を０として、現在の針の角度をそれぞれ求める
    double minuteAng = (minute / 60.0) * (2 * M_PI);
    double hourAng = (hour / 12.0) * (2 * M_PI) + (minute / 60.0) * (M_PI / 6);
    

    double angleDelta = hourAng - minuteAng;  //時針と分針のなす角(符号は任意)

    //余弦定理から辺の長さを求める
    double sideLen = sqrt(pow(hourLen, 2.0) + pow(minuteLen, 2.0) - 2 * hourLen * minuteLen * cos(angleDelta));

    printf("%.10f\n", sideLen); //相対誤差が10^-9以下になるように出力

    return 0;
}

Measured memory_bytes: 2584