akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;  
using namespace std;

typedef long long ll;

typedef tree<
pair <int, int>,
null_type,
less<pair <int, int>>,
rb_tree_tag,
tree_order_statistics_node_update>
os;

double getTime() {
  return clock() / (double) CLOCKS_PER_SEC;
}

void read() {};

template<typename T, typename... Args>
void read(T& a, Args&... args) {
  cin >> a;
  read(args...);
}

void print() {};

template <typename T, typename... Args>
void print(T a, Args... args) {
  cout << a << " \n"[sizeof...(args) == 0];
  print(args...);
}

const int N = 2e5 + 5;
const ll MOD = 1e9 + 7;

ll f[N];
ll inv[N];

ll get(ll a, ll b) {
  ll res = 1ll;
  while(b) {
    if(b & 1) res = (res * a) % MOD;
    b >>= 1;
    a = (a * a) % MOD;
  }
  return res;
}

ll ncr(ll n, ll r) {
  if(n < r or n < 0 and r < 0) return 0;
  ll cur = f[n];
  cur = (cur * inv[r]) % MOD;
  cur = (cur * inv[n - r]) % MOD;
  return cur;
}

int main() {
  int n; cin >> n;
  string s = "";
  if(n == 0) {
    print(0);
    return 0;
  }
  while(n != 0) {
    int rem = n % (-2);
    n = n / (-2);
    if(rem < 0) {
      rem += 2;
      n++;
    }
    s += rem + '0';
  }
  reverse(s.begin(), s.end());
  print(s);
}


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

int main(){
  string s,sa,sb,ca,cb;
  cin>>s;
  for(int i=0;i<(s.size()-1)/2;i++){
    sa+=s[i];
    sb+=s[(s.size()+1)/2+i];
  }
  ca=sa;
  cb=sb;
  reverse(ca.begin(),ca.end());
  reverse(cb.begin(),cb.end());

  if(sa==sb&&sa==ca&&sb==cb){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    class QuestionB
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数配列の入力
            var nk = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            int n = nk[0];
            int k = nk[1];

            var p = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();

            Array.Sort(p);


            long result = 0;

            for (int i = 0; i < k; i++)
            {
                result += p[i];
            }



            Console.WriteLine(result);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 28360
if __name__ == "__main__":
    H,W = map(int, input().split())
    board = []
    for x in range(H):
        board.append(input())
    print ('#' * (W + 2))
    for y in range(H):
        print ('#' + board[y] + '#')
    print ('#' * (W + 2))


Measured memory_bytes: 3060
n = int(input())
s = {}
for i in range(n):
    a = input()
    if a in s:
        s[a] += 1
    else:
        s[a] = 1
t = {}
m = int(input())
for i in range(m):
    a = input()
    if a in t:
        t[a] += 1
    else:
        t[a] = 1
ans = 0
for i,j in s.items():
    if i in t:
        if j > t[i]:
            ans = max(ans,j-t[i])
    else:
        ans = max(ans,j)
print(ans)


Measured memory_bytes: 3064
import math
import itertools
import statistics
#import collections

n, m, X, Y =  list(map(int, input().split()))
x =  list(map(int, input().split()))
y =  list(map(int, input().split()))
#s = int(input())

z_min = X+1
z_max = Y

if Y-X > 0:
    if z_min <= max(x) and z_max >= min(y) and min(y)-max(x)>0:
       print("No War")
       exit()
    print("War")

Measured memory_bytes: 5276
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<cmath>
#include<iomanip>
using namespace std;

int INF = 1e9 + 7;

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

vector<vector<int>> d(210, (vector<int>(210, INF)));

void warshall_floyd(int n) {
	for (int k = 1; k <= n; k++) {
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
}

int main() {
	int n, m, r;
	cin >> n >> m >> r;
	vector<int> x(r);
	for (int i = 0; i < r; i++) cin >> x[i];
	sort(begin(x), end(x));
	for (int i = 1; i <= n; i++) d[i][i] = 0;
	int a, b, c;
	for (int i = 1; i <= m; i++) {
		cin >> a >> b >> c;
		d[a][b] = d[b][a] = c;
	}

	warshall_floyd(n);

	int sum = 0, ans = INF;
	do {
		for (int i = 0; i < r - 1; i++) sum += d[x[i]][x[i + 1]];
		ans = min(ans, sum);
		sum = 0;
	} while (next_permutation(begin(x), end(x)));
	cout << ans << endl;
}

Measured memory_bytes: 384
#include <algorithm>
#include <cctype>
#include <iostream>
#include <string>

int main(void){
    int n,k;
    std::cin >> n;
    std::cin >> k;
    std::string s;
    std::cin >> s;
    for(int i = 0;i < n;i++){
        if(i == k - 1){
        std::cout << (unsigned char)tolower(s[i]);
        } else {
            std::cout << s[i];
        }
    }
    std::cout << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main(){
    int N,i;
    scanf("%d", &N);
    long int * A = malloc(sizeof(long int)*N);
    for(i=0;i<N;i++){
        scanf("%ld", &A[i]);
    }

    long int MAX = A[0] ,MIN = A[0]; 
    for(i=0;i<N;i++){
        if(MAX<A[i])    MAX=A[i];
        if(MIN>A[i])    MIN=A[i];        
    }

    printf("%d", MAX-MIN);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define  rep(i,a,b)for(int i=a;i<b;++i)
#define  rrep(i,a,b)for(int i=a;i>=b;--i)
#define  yesno(flag)if(flag)cout<<"Yes"<<endl; else cout<<"No"<<endl;
using namespace std;
typedef long long ll;
const ll INF=10000000000LL;
const ll r197=1000000007;
typedef pair<ll,int>P;
typedef pair<int,P>Pa;
vector<P> v[100001];
ll n,w;
ll dp[100005];
struct edge{ll cost,num; };
int main() {
	rep(i,0,100005)dp[i]=INF;
	cin>>n>>w;
	ll a,b;
	dp[0]=0;
	rep(i,0,n){
		cin>>a>>b;
		for(int j=100000-b;j>=0;--j){
			dp[j+b]=min(dp[j+b],dp[j]+a);
		}
	}
	ll ans=0;
	rep(i,0,100005){
		if(dp[i]<=w)ans=i;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3964
#include <iostream>
#include <bitset>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

Int mod_pow(Int x, Int n){
    Int res = 1;
    for(int i = 0;i < 60; i++){
        if(n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

Int gcd(Int a, Int b) {
    return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
    return a * b / gcd(a, b);
}
// a x + b y = gcd(a, b)
Int extgcd(Int a, Int b, Int &x, Int &y) {
    Int g = a; x = 1; y = 0;
    if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
    return g;
}


int main(){
    cin.tie(0);

    string s;
    string ss;
    cin >> s;
    int ans = 0;
    for (int i = 0; i < s.length(); i++){
        if (s[i] != 'x') ss.push_back(s[i]);
    }
    int i = 0;
    int len = ss.length();
    while (i < len-1-i){
        if (ss[i] != ss[len-1-i]){
            cout << -1 << endl;
            return 0;
        }
        i++;
    }
    int left = 0;
    int right = s.length()-1;
    while (left < right){
        if (s[left] != s[right]){
            ans++;
            if (s[left] == 'x') left++;
            else if (s[right] == 'x') right--;
        }else{
            left++;
            right--;
        }
    }
    cout << ans << endl;
    
    
    return 0;
} 


Measured memory_bytes: 704
#include <algorithm>
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <cmath>
#include <limits>
#include <numeric>
#include <iomanip>
#include <cstdlib>
#include <iterator>
#include <functional>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef unsigned                    ui;
typedef int                         si;
typedef long                        sl;
typedef long long                   ll;
typedef unsigned long long          ull;

#ifdef LOCALHOST
std::ifstream in("input.txt", std::ifstream::in);
#endif // LOCALHOST

#ifdef LOCALHOST
#define is in
#else
#define is cin
#endif // LOCALHOST

int main(int argc, char *argv[])
{
    std::ios_base::sync_with_stdio(false);

    ll a, b;
    cin >> a >> b;

    if (a > b) {
        swap(a, b);
    }

    for (int i = 0; i < b; ++i) {
        cout << a;
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#double underscore makes a class variable or a class method private
mod = 1000000007
ii = lambda :  int(input())
si = lambda :  input()
dgl = lambda : list(map(int, input()))
f = lambda :   map(int, input().split())
il = lambda :  list(map(int, input().split()))
it = lambda :  tuple(map(int, input().split()))
ls = lambda :  list(input())
a, b=f()
c=1
if b==1:
    print(0)
    exit()
while a*c-c+1 < b:
    c += 1
print(c)

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

int main() {
	multiset<int, greater<int>> mul;
	int itr = 0; int temp;
	while (cin >> temp) { mul.insert(temp); }
	for (auto x : mul) { 
		cout << x << endl; itr++;
		if (itr == 3) break;
	}
	return 0;
}


Measured memory_bytes: 3036
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n, d;
	int a[10][10];
	cin >> n >> d;
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < d; ++j) {
			cin >> a[i][j];
		}
	int g = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = i + 1; j < n; ++j) {
			int s = 0;
			for (int k = 0; k < d; ++k) {
				s += (a[i][k] - a[j][k])*(a[i][k] - a[j][k]);
			}
			double r = sqrt((double)s+0.00000001);
			if ((int)r*(int)r == s) ++g;
		}
	}
	cout << g;
	return 0;
}


Measured memory_bytes: 256
def inpl(): return input().split()

n = int(input())
a = list(map(int, inpl()))
sa = sum(a)
b = [a[0]]
for i in range(1, n - 1):
    b.append(a[i] + b[i - 1])

ans = float('inf')
for x in b:
    ans = min(ans, abs(sa - 2 * x))
print(ans)

Measured memory_bytes: 24832
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

#define minimize(a, b) a = min({a, b})

int main() {
    int n, m;
    cin >> n >> m;
    int a[m], c[m];
    for (int i=0, b; i<m; i++) {
        cin >> a[i] >> b;
        c[i] = 0;
        for (int j=0, _c; j<b; j++) {
            cin >> _c;
            c[i] += (1 << (_c - 1));
        }
    }
    int dp[m+1][1 << n];
    fill(dp[0], dp[m+1], 1000000000);
    dp[0][0] = 0;
    for (int i=0; i<m; i++) {
        for (int j=0; j<(1<<n); j++) {
            minimize(dp[i+1][j | c[i]], dp[i][j] + a[i]);
            minimize(dp[i+1][j], dp[i][j]);
        }
    }
    cout << (dp[m][(1<<n) - 1] < 1000000000 ? dp[m][(1<<n) - 1] : -1) << '\n';
    return 0;
}

Measured memory_bytes: 16256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
int powint(int a, int x){
	int res = 1;
	REP(i,x){
		res = res *a; 
	}
	return res;
}

using namespace std;

int main(){
	int N;
	cin>>N;
	vector<int> t(N);
	vector<int> x(N);
	vector<int> y(N);
	REP(i,N){
		cin>>t[i]>>x[i]>>y[i];
	}
	bool dame = false;
	REP(i,N){
		if(i==0){
			int dx = x[i]-0;
			int dy = y[i]-0;
			int d = max(dx,-dx) + max (dy,-dy);
			if(d > t[i]-0){
				dame=true;
				break;
			} else if ((d - (t[i]-0)) %2 != 0){
				dame=true;
				break;
			}
		} else {
			int dx = x[i]-x[i-1];
			int dy = y[i]-y[i-1];
			int d = max(dx,-dx) + max (dy,-dy);
			if(d > t[i]-t[i-1]){
				dame=true;
				break;
			} else if ((d - (t[i]-t[i-1])) %2 != 0){
				dame=true;
				break;
			}
		}
	}
	
	if(dame){
		cout<<"No"<<endl;
	} else {
		cout<<"Yes"<<endl;
	}
	return 0;
}


Measured memory_bytes: 1408
from heapq import heapify, heappush, heappop
class HeapQue(object):
    def __init__(self, iterable, max_heap=False):
        self.sign = -1 if max_heap else 1
        sequence = [self.sign * number for number in iterable]
        heapify(sequence)
        self.heapque = sequence

    def push(self, item):
        heappush(self.heapque, item * self.sign)

    def pop(self):
        return heappop(self.heapque) * self.sign

    def dump(self):
        return [heappop(self.heapque) * self.sign for _ in range(len(self.heapque))]

N, M = map(int, input().split())
q = HeapQue(map(int, input().split()))
pairs = sorted((tuple(map(int, input().split())) for _ in range(M)), key=lambda t: t[1], reverse=True)
for b, c in pairs:
    for _ in range(b):
        x = q.pop()
        if x < c:
            q.push(c)
        else:
            q.push(x)
            print(sum(q.dump()))
            quit()
print(sum(q.dump()))

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

bool exist(int x, vi A){
    bool a = false;
    rep(i, A.size()){
        if(A[i] == x) a = true;
    }
    return a;
}

int main(){
    int N, M, X;
    cin >> N >> M >> X;
    vi A(M);
    rep(i, M) cin >> A[i];

    int cost1 = 0, cost2 = 0;

    for(int i = 0; i < X; i++){
        if(exist(i, A)) cost1++;
    }

    for(int i = X+1; i < N; i++){
        if(exist(i, A)) cost2++;
    }


    int cost = min(cost1, cost2);

    cout << cost << endl;

    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define nyan "(=^･ω･^=)"
typedef long long ll;
typedef long double ld;
using namespace std;

const int maxn = 3e5+10;
int a[maxn];

void add(int idx, int v) {
    while(idx <= maxn) {
        a[idx] += v;
        idx += idx & (-idx);
    }
}
int query(int idx) {
    int ret = 0;
    while(idx) {
        ret += a[idx];
        idx -= idx & (-idx);
    } return ret;
}

bool cmp(pii a, pii b) {
    return a.second - a.first < b.second - b.first; 
}

int main()
{
    int n, m;
    vector<pii> v;

    cin >> n >> m;
    for(int i = 0, l, r; i < n; i++) {
        cin >> l >> r;
        v.pb({l, r});
    }
    sort(v.begin(), v.end(), cmp);
    
    for(int d = 1, j = 0; d <= m; d++) {
        for(; v[j].second - v[j].first + 1 < d && j < n; j++) 
            add(v[j].first, 1), add(v[j].second+1, -1);

        int ans = n-j;
        for(int i = 0; i <= maxn; i += d)
            ans += query(i);

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

Measured memory_bytes: 6512
N,K=map(int,input().split())
B=[[0]*(2*K) for i in range(2*K)]
W=[[0]*(2*K) for i in range(2*K)]
w=0
for i in range(N):
    x,y,c=map(str,input().split())
    x=int(x)
    y=int(y)
    if c=="B":
        B[y%(2*K)][x%(2*K)]+=1
    else:
        w+=1
        W[y%(2*K)][x%(2*K)]+=1
sumb=[[0]*(2*K+1) for i in range(2*K+1)]
sumw=[[0]*(2*K+1) for i in range(2*K+1)]
for i in range(2*K):
    for j in range(2*K):
        sumb[i+1][j+1]=sumb[i][j+1]+sumb[i+1][j]-sumb[i][j]+B[i][j]
        sumw[i+1][j+1]=sumw[i][j+1]+sumw[i+1][j]-sumw[i][j]+W[i][j]


ans=0
for i in range(K):
    for j in range(K):
        for _ in range(2):
            s=0
            s+=sumb[i][j]-sumb[i][0]-sumb[0][j]+sumb[0][0]#
            s+=sumb[i+K][j+K]-sumb[i][j+K]-sumb[i+K][j]+sumb[i][j]
            s+=sumb[i][2*K]-sumb[0][2*K]-sumb[i][j+K]+sumb[0][j+K]#
            s+=sumb[2*K][j]-sumb[i+K][j]-sumb[2*K][0]+sumb[i+K][0]#
            s+=sumb[2*K][2*K]-sumb[i+K][2*K]-sumb[2*K][j+K]+sumb[i+K][j+K]#

            s+=sumw[i][j+K]-sumw[0][j+K]-sumw[i][j]+sumw[0][j]#
            s+=sumw[i+K][j]-sumw[i][j]-sumw[i+K][0]+sumw[i][0]#
            s+=sumw[2*K][j+K]-sumw[i+K][j+K]-sumw[2*K][j]+sumw[i+K][j]#
            s+=sumw[i+K][2*K]-sumw[i+K][j+K]-sumw[i][2*K]+sumw[i][j+K]#

            ans=max(ans,s)
            sumb,sumw=sumw,sumb

print(ans)


Measured memory_bytes: 164616
fn main() {
    let nd = read_vec::<usize>();
    let n = nd[0];
    let d = nd[1];
    let points = read_vec2::<f64>(n);

    let mut ret = 0;
    for i in 0..n-1 {
        for j in i+1..n {
            let p1 = &points[i];
            let p2 = &points[j];
            let mut dis = 0.0;
            for k in 0..d {
                dis += (p1[k] - p2[k]) * (p1[k] - p2[k]);
            }
            dis = dis.sqrt();
            if dis - dis.floor() == 0.0 {
                ret += 1;
            }
        }
    }

    println!("{}", ret);
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    let mut v2 = Vec::new();
    for _ in 0..n {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).ok();
        let v = s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect();
        v2.push(v);
    }
    v2
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define p_b push_back
#define MOD 1
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL) ;

    ll n;
    cin >> n;
    ll arr[n];
    ll i;
    for(i=0;i<n;i++)
    {

        cin >> arr[i];
    }
    ll ans = 0;
    for(i=1;i<n-1;i++)
    {
        vector<ll> v;
        v.p_b(arr[i]);
        v.p_b(arr[i-1]);
        v.p_b(arr[i+1]);
        sort(v.begin(),v.end());

        if(v[1]==arr[i])
        {

            ans++;
        }

    }
    cout << ans << endl;




    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include "atcoder/math.hpp"
using namespace atcoder;
using namespace std;
template<typename T1, typename T2> inline void chkmin(T1 &a, T2 b) {if (a > b) a = b;}
template<typename T1, typename T2> inline void chkmax(T1 &a, T2 b) {if (a < b) a = b;}
#define files(FILENAME) read(FILENAME); write(FILENAME)
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define all(c) (c).begin(), (c).end()
#define sz(c) (int)(c).size()
#define left left228
#define right right228
#define y1 y1228
#define mp make_pair
#define pb push_back
#define y2 y2228
#define rank rank228
using ll = long long;
using ld = long double; 
const string FILENAME = "input";



ll gcd(ll a, ll b) {
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}


int main() {
  	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//read(FILENAME);
    ll n;
    cin >> n;
    n *= 2;
    //k * (k + 1) ;
    vector<ll> kek;
    for (ll s = 1; s <= (ll)sqrt(n); s++) {
        if (n % s == 0) {
            kek.pb(s);
            kek.pb(n / s);
        }
    }
    ll resp = 4e18;
    for (auto x: kek) {
        ll y = n / x;
        if (gcd(x, y) == 1) {
            auto d = atcoder::crt(vector<long long>{0, y - 1}, vector<long long>{x, y});
            chkmin(resp, (d.first == 0 ? d.second: d.first));
        }
    }
    cout << resp << endl;
   	return 0;
}

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

int main(){
	string s;
	int n,len;
	cin >> n >> s;
	len=s.length();
	for(int i=0;i<len;i++)
	{
		if(s[i]+n > 'Z') s[i]-=(26-n);
		else s[i]+=n;
	}
	cout << s;

	return 0;
	
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()
const long long INF = 1e15;
using namespace std;
typedef long long ll;

struct Edge {
  ll to;
  ll cost;
};
vector<vector<Edge>> G(100010);
bool even[100010];

void dfs(ll p, ll v) {
  for (auto x : G[v]) {
    if (x.to == p) continue;

    if (even[v]) {
      if (x.cost % 2 == 0) {
        even[x.to] = true;
      } else {
        even[x.to] = false;
      }
    } else {
      if (x.cost % 2 == 0) {
        even[x.to] = false;
      } else {
        even[x.to] = true;
      }
    }
    dfs(v, x.to);
  }
}

int main() {
  ll n;
  cin >> n;
  REP(i, n - 1) {
    ll u, v, w;
    cin >> u >> v >> w;
    u--, v--;
    G[u].push_back(Edge{v, w});
    G[v].push_back(Edge{u, w});
  }

  even[0] = true;

  dfs(-1, 0);

  REP(i, n) {
    if (even[i]) {
      cout << '1' << endl;
    } else {
      cout << '0' << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define REP(i, n) FOR(i, 0, n)
#define INF 999999999
typedef long long ll;
using namespace std;
int main() {
    int n;
    cin >> n;
    ll a[n];
    bool flag = true;
    int cnt = 0;
    REP(i, n) {
        cin >> a[i];
        if(a[i] % 2 == 1) flag = false;
    }
    while(flag) {
        cnt++;
        REP(i, n) {
            a[i] /= 2;
            if(a[i] % 2 == 1) flag = false;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <complex>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <iomanip>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T,vector<T>,greater<T>>
#define Pqza(T) priority_queue<T>
#define put(x) cout << x;
#define putsp(x) cout << x << ' ';
#define putln(x) cout << x << endl;
#define ENJYU std::ios::sync_with_stdio(false);std::cin.tie(0);

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef complex<double> comp;
typedef vector <int> vec;
typedef vector <ll> vecll;
typedef vector <double> vecd;
typedef vector <vec> mat;
typedef vector <vecll> matll;
typedef vector <vecd> matd;

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

const int MAX_V = 10010;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INFL = 1e18;
const int MOD = 1000000007;

int dx4[4]={1,0,-1,0};
int dy4[4]={0,1,0,-1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

void solve(void){
	int N; ll W;
	cin >> N >> W;

	vec vs(N); vecll ws(N);
	rep(N, i)
	{
		cin >> vs[i] >> ws[i];
	}

	vecll dp(MAX_V, INFL);

	dp[0] = 0;

	rep(N, i) repr(MAX_V, j)
	{
		dp[j+vs[i]] = min(dp[j+vs[i]], dp[j] + ws[i]);
	}

	int ans = 0;

	rep(MAX_V, i)
	{
		if (dp[i] <= W)
		{
			ans = i;
		}
	}

	cout << ans << endl;

}

int main(void){
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}



Measured memory_bytes: 3196
#include <stdio.h>
int d(int a,int b,int c)
{
	if(a>=b && a>=c){
		return ((a-b)+(a-c))/2;
	}else if(b>=a && b>=c){
		return ((b-a)+(b-c))/2;
	}else if(c>=a && c>=b){
		return ((c-a)+(c-b))/2;
	}
}
int main(void)
{
	int a,b,c,x,y,tmp;
	scanf("%d%d%d",&a,&b,&c);
	if(a%2==0 && b%2==0 && c%2==0){
		printf("%d\n",d(a,b,c));
		return 0;
	}
	if(a%2==1 && b%2==1 && c%2==1){
		printf("%d\n",d(a,b,c));
		return 0;
	}
	
	if(b>=a && b>=c){
		tmp=b;
		b=a;
		a=tmp;
	}else if(c>=a && c>=b){
		tmp=c;
		c=a;
		a=tmp;
	}
	
	if(a%2==0){
		if(b%2==1 && c%2==1){
			printf("%d\n",d(a,b,c));
			return 0;
		}else{
			printf("%d\n",d(a+1,b+1,c)+1);
			return 0;
		}
	}
	if(a%2==1){
		if(b%2==0 && c%2==0){
			printf("%d\n",d(a,b,c));
			return 0;
		}else{
			printf("%d\n",d(a+1,b+1,c)+1);
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
typedef long long ll;
int main(){
    int n; string s; cin >> n >> s;

    int ans = 1;
    FOR(i,1,n){
        if(!(s[i] == s[i-1])) ans++; 
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def solve():
    H, W, K = Scanner.map_int()
    S = Scanner.string_list(H)

    ans = [[0 for _ in range(W)] for _ in range(H)]

    vec = []
    for h in range(H):
        if S[h].count('#') > 0:
            vec.append(h)

    for i in range(len(vec)):
        v1, v2 = 0, H - 1
        if i > 0:
            v1 = vec[i - 1] + 1
        if i < len(vec) - 1:
            v2 = vec[i]

        vec2 = []
        for w in range(W):
            cnt = 0
            for h in range(v1, v2 + 1):
                if S[h][w] == '#':
                    cnt += 1
            if cnt > 0:
                vec2.append(w)
        for j in range(len(vec2)):
            w1, w2 = 0, W - 1
            if j > 0:
                w1 = vec2[j - 1] + 1
            if j < len(vec2) - 1:
                w2 = vec2[j]
            for h in range(v1, v2 + 1):
                for w in range(w1, w2 + 1):
                    ans[h][w] = K
            K -= 1
    for a in ans:
        print(*a)


def main():
    # sys.stdin = open("sample.txt")
    solve()


if __name__ == "__main__":
    main()


Measured memory_bytes: 9600
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
//const int MAX=;

int f(int b,lli n){
	if(n<b)return n;
	return f(b,n/b)+n%b;
}
int main(){
	lli n,s;
	cin>>n>>s;
	if(n<s){
		cout<<-1;
		return 0;
	}
	if(n==s){
		cout<<n+1;
		return 0;
	}
	lli sq=sqrt(n);
	for(int i=2;i<=sq;i++){
		int pat=f(i,n);
		if(pat==s){
			cout<<i;
			return 0;
		}
	}
	for(int i=sq;i>=1;i--){
		if(i>s)continue;
		if((n-(s-i))%i==0&&(n-(s-i))/i>s-i&&i<(n-(s-i))/i){
			cout<<(n-(s-i))/i;
			return 0;
		}
	}
	cout<<-1;
}

Measured memory_bytes: 384
n=int(input())
v=list(map(int,input().split()))
temp1=[]
temp2=[]
for i in range(0,n):
  if i%2==0:
    temp1.append(v[i])
  else:
    temp2.append(v[i])
count=0
from collections import Counter
c1=Counter(temp1)
values1,counts1=zip(*c1.most_common())
counts1=list(counts1)
mode1=counts1[0]
if len(counts1)>1:
  mode1s=counts1[1]
c2=Counter(temp2)
values2,counts2=zip(*c2.most_common())
counts2=list(counts2)
mode2=counts2[0]
if len(counts2)>1:
  mode2s=counts2[1]
if len(counts1)==1 and len(counts2)==1 and c1.most_common()[0][0]==c2.most_common()[0][0]:
  count=min(mode1,mode2)
elif c1.most_common()[0][0]==c2.most_common()[0][0]:
  if len(temp1)-mode1s>=len(temp2)-mode2s:
    count=len(temp1)-mode1+len(temp2)-mode2s
  else:
    count=len(temp2)-mode2+len(temp1)-mode1s
else:
  count=len(temp1)-mode1+len(temp2)-mode2
print(count)

Measured memory_bytes: 24272
#include <algorithm>
#include <iostream>
#include <math.h>
#include <queue>
#include <string>
#include <vector>

using namespace std;

#define INF 210000000

static long long gcd(long long a, long long b) {
  int amari = a % b;
  int c = b;
  if (amari == 0) {
    return b;
  } else {
    return gcd(b, amari);
  }
}

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

int main() {
  double n, d;
  cin >> n >> d;
  double tmp = n / (d + d + 1);
  cout << ceil(tmp);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  map<char,string> mp;
  cin >> mp['a'] >> mp['b'] >> mp['c'];
  char turn = 'a';
  while(true){
    if(mp[turn].size()==0){
      string output;
      switch(turn){
        case 'a':
          output = "A";
          break;
        case 'b':
          output = "B";
          break;
        case 'c':
          output = "C";
          break;
      }
      cout << output << endl;
      break;
    }
    char next_turn = mp[turn].at(0);
    if(mp[turn].size()>1){
	    mp[turn] = mp[turn].substr(1);
    } else{
       mp[turn] = "";
    }
    turn = next_turn;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <random>
#include <ctime>
#include <bitset>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define ld long double
#define ull unsigned long long
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fast_io cout.tie(0), cin.tie(0), ios_base::sync_with_stdio(0)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ld eps = (ld)1 / 1e10;
ll inf = 1e18, mod2 = 998244353, mod1 = 1e9 + 7;
ll sqr(ll a) { return a * a; }
ll qb(ll a) { return a * a * a; }
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }
ll binmult(ll a, ll b, ll mod) { return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod : (2 * binmult(a, b / 2, mod)) % mod) : 0; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main()
{
    fast_io;
    ll n, i;
    string a, b, c, d;
    bool bl = 0;
    cin >> a;
    n = a.size();
    b = a, reverse(all(b));
    if (b != a) bl = 1;
    for (i = 0; i < (n - 1) / 2; i++) c += a[i];
    b = c, reverse(all(b));
    if (c != b) bl = 1;
    for (i = (n + 3) / 2 - 1; i < n; i++) d += a[i];
    b = d, reverse(all(b));
    if (b != d) bl = 1;
    cout << (!bl ? "Yes" : "No");
    return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [float("inf") for _ in range(N)]
dp[0] = 0
for i in range(N):
    for j in range(1, K + 1):
        if i + j < N:
            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]))
print(dp[N - 1])


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

using namespace std;
const int maxn = 2e5 + 5, mod = 1e9 + 7;
typedef pair<int, int> ii;
int a[maxn], h[maxn], n;
long long fen[maxn];
void update(int x, long long val)
{
    for(int i=x; i<maxn; i+=i&(-i)) fen[i] = max(fen[i], val);
}
long long get(int x)
{
    long long res = 0;
    for(int i=x; i>=1; i-=i&(-i)) res = max(res, fen[i]);
    return res;
}

int main()
{
    #ifdef NTMA 
        freopen("abc.inp", "r", stdin);
    #endif
    //memset(f, 255, sizeof(f));
    long long ans = 0;
    cin >> n;
    for(int i=1; i<=n; ++i) cin >> h[i];
    for(int i=1; i<=n; ++i) cin >> a[i];
    for(int i=1; i<=n; ++i) {
        long long res = get(h[i]-1) + a[i];
        update(h[i], res);
        ans = max(ans, res);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>
#include <new>
#include <typeinfo>

typedef  long long ll;
#define mop 1000000007
#define mop2 998244353
using namespace std;

int main() {
    

    deque <ll> d;
    ll q;
    cin >> q;
    for(ll i=0;i<q;i++){
        ll a;
        cin >> a;
        if(a == 0){
            ll b,c;
            cin >> b >> c;
            if(b == 0){
                d.push_front(c);
            }else{
                d.push_back(c);
            }
        }else if(a == 1){
            ll b;
            cin >> b;
            cout << d[b] << endl;
        }else{
            ll b;
            cin >> b;
            if(b == 0){
                d.pop_front();
            }else{
                d.pop_back();
            }
        }
    }

}


Measured memory_bytes: 6228
#include <algorithm>
#include<stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stack>
#include <queue>
#include<map>
#include <set>
#include<math.h>
using namespace std;
#define int long long
#define ll long long
#define double long double
#define rep(i,n) for(ll i=0;i<n;++i)
#define Rep(i,n) for(ll i=1;i<=n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define elif else if
#define P pair<ll,ll>
#define prique priority_queue<ll>
#define ALL(a)  (a).begin(),(a).end()
const int mod = 1000000007;
const int mod2 = 998244353;
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2) * pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int nCr(int n, int r) {
	int ans = 1;
	for (ll i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (ll i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
int per(int n, int r) {
	r = n - r;
	int sum = 1;
	int i;
	for (i = n; i >= r + 1; i--)sum *= i;
	return sum;
}
struct union_find {
	int par[200010], size_[200010];
	void init(int x) {
		rep(i, x) { par[i] = i; size_[i] = 1; }
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (size_[x] < size_[y]) {
			par[x] = y;
			size_[y] += size_[x];
		}
		else {
			par[y] = x;
			size_[x] += size_[y];
		}
	}
};

int ctoi(const char c) {
	switch (c) {
	case '0': return 0;
	case '1': return 1;
	case '2': return 2;
	case '3': return 3;
	case '4': return 4;
	case '5': return 5;
	case '6': return 6;
	case '7': return 7;
	case '8': return 8;
	case '9': return 9;
	default: return -1;
	}
}
int keta(int a) {
	return to_string(a).size();
}
char d[15];
bool b[15];
signed main() {
	int n, k;
	cin >> n >> k;
	rep(i, k) {
		cin >> d[i];
		b[d[i]-'0']= true;
	}
	for (int i = n; i < 100000; ++i) {
		string s = to_string(i);
		bool o = false;
		rep(j, s.size()) {
			if (b[s[j]-'0'])goto bed;
		}
		cout<<i<<endl;return 0;
		bed:;
	}
}


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

using namespace std;

using ll = long long;

template<typename T> using V = std::vector<T>;
using Vi = V<int>;
using VVi = V<V<int>>;
using Vl = V<ll>;
using VVl = V<V<ll>>;
using Vs = V<string>;

template<typename T1, typename T2> using P = std::pair<T1, T2>;
using Pii = P<int, int>;
using Pll = P<ll, ll>;
using Pdd = P<double, double>;

template<typename T1, typename T2> using M = std::map<T1, T2>;
using Mii = M<int, int>;
using Mll = M<ll, ll>;
using Msi = M<string, int>;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin(),ie=(c).rend();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

const double PI = acos(-1);
const ll MOD = 1e9+7;

int n, m, r;

int main() {
    cin >> n >> m >> r;
    Vi rl(r);
    REP(i, r) {
        cin >> rl[i];
        rl[i]--;
    }

    VVi d(n, Vi(n, 1e9));
    REP(i, m) {
        int a,b,c; cin >> a >> b >> c; a--; b--;
        d[a][b] = c;
        d[b][a] = c;
    }

    REP(k, n) REP(i, n) REP(j, n) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
    }

    int mini = 1e9;
    Vi p(r);
    REP(i, r) p[i] = i;
    do {
        int sum = 0;
        REP(i, r-1) {
            sum += d[rl[p[i]]][rl[p[i+1]]];
        }
        mini = min(mini, sum);
    } while( next_permutation(ALL(p)) );

    cout << mini << '\n';

    return 0;
}


Measured memory_bytes: 384
import std.stdio;
import std.array;
import std.conv;
import std.string;

void main() {
	int [] c = [10, 50, 100, 500];

	bool flg = false;
	while(1) {
		int P;
		string s;
		string [] arrs;
		int [] a, b;
		int sum;

		P = to!int(chomp(readln()));
		if(P == 0) break;
		s = readln();
		arrs = split(s);
		a.length = b.length = c.length;
		for(int i = 0; i < arrs.length; i++) {
			a[i] = to!int(arrs[i]);
			sum += to!int(arrs[i]) * c[i];
		}
		int rest = sum - P;

		for(int i = to!int(c.length)-1; i >= 0; i--) {
			b[i] = rest / c[i];
			rest = rest % c[i];
		}

		if(flg) writeln("");
		flg = true;

		for(int i = 0; i < b.length; i++) {
			if(b[i] < a[i])
				writef("%d %d\n", c[i], a[i]-b[i]);
		}
	}
}

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

int main() {
  ll N;
  cin >> N;
  ll ans = 0;
  for(int i = 1; i <= N; i++) {
    for(int j = i; j <= N; j += i) {
      if(j % i == 0) ans += j; 
    }
  }

  cout << ans;
  return 0;
}

Measured memory_bytes: 3532
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = std::vector<T>;
using vvi = std::vector<vt<int>>;

int main(){
  int q,h,s,d,n;
  std::cin >> q >> h >> s >> d >> n;

  int q_1 = 4*q, h_1 = 2*h, qh_1 = 2*q + h;

  int two = n/2;
  int one = n%2;

  int min = std::min({q_1, h_1, qh_1, s});
  if(two == 0)
    std::cout << min << '\n';
  else
    std::cout << (ll) std::min(min*2,d)*two + min*one << '\n';
  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 FOR(i, r, n) for (int i=(int)(r); i<=(int)(n); i++)
#define all(v) v.begin(), v.end()
#define INF 2147483647
#define INF64 9223372036854775807
#define MOD 1000000007

int main(){

    int h, w, k;
    cin>>h>>w>>k;
    vector<vector<int>> c(h, vector<int>(w));
    rep(i, h){
        rep(j, w){
            c[i][j]=0;
            char s;
            cin>>s;
            if(s=='#') c[i][j]=1;
        }
    }

    int ans=0;

    for (int tmp = 0; tmp < (1 << h); tmp++) {
        bitset<6> s1(tmp);
        for (int tmpra = 0; tmpra < (1 << w); tmpra++) {
            bitset<6> s2(tmpra);
            
            vector<vector<int>> cs(h, vector<int>(w));
            cs=c;

            rep(i, h){
                if(s1.test(i)){
                    rep(j, w) cs[i][j]=0;
                } 
            }
            rep(i, w){
                if(s2.test(i)){
                    rep(j, h) cs[j][i]=0;
                } 
            }

            int cnt=0;

            rep(i, h){
                rep(j, w){
                    if(cs[i][j]==1) cnt++;
                }
            }

            if(cnt==k) ans++;

        }
    }

    cout<<ans<<endl;

}

Measured memory_bytes: 3648
import java.util.*;
public class Main {
	static int[] f=new int[112345];
	static long[] sz=new long[112345];
	static int[] lose=new int[112345];
	public static class edge implements Comparable<edge> {
		int u,v,w;
		@Override
		public int compareTo(edge o) {
			return w-o.w;
		}
	}
	public static int F(int x) {
		return x==f[x]?x:(f[x]=F(f[x]));
	}
	public static void U(int x,int y,int w) {
		int fx=F(x),fy=F(y);
		if (fx==fy) {
			//System.out.printf("1: %d %d %d\n",x,y,w);
			if (w>sz[fx]) ++lose[fx];
          	else lose[fx]=0;
			return;
		}
		//System.out.printf("2: %d %d %d\n",x,y,w);
		sz[fx]+=sz[fy];
		f[fy]=fx;
		if (w<=sz[fx]) lose[fx]=0;
		else lose[fx]+=lose[fy]+1;
		return;
	}
	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		int m=in.nextInt();
		edge[] e=new edge[m];
		long tot=0;
		for (int i=1;i<=n;++i) {
			sz[i]=in.nextLong();
			f[i]=i;
			tot+=sz[i];
		}
		for (int i=0;i<m;++i) {
			e[i]=new edge();
			e[i].u=in.nextInt();
			e[i].v=in.nextInt();
			e[i].w=in.nextInt();
		}
		Arrays.sort(e,0,m);
		for (int i=0;i<m;++i) U(e[i].u,e[i].v,e[i].w);
		System.out.println(lose[F(1)]);
	}
}

Measured memory_bytes: 111136
#include <bits/stdc++.h>
 
typedef long long ll;

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

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define COUT(a) cout << (a) << endl;
#define ENDL(a) cout << endl;

const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000
const unsigned int BIT_FLAG_8 = (1 << 8); // 0000 0001 0000 0000
const unsigned int BIT_FLAG_9 = (1 << 9); // 0000 0010 0000 0000
const unsigned int BIT_FLAG_10 = (1 << 10); // 0000 0100 0000 0000
const unsigned int BIT_FLAG_11 = (1 << 11); // 0000 1000 0000 0000

const double PI=3.14159265358979323846; // or M_PI


void Main() {
    ll x, y, z;
    cin >> x >> y >> z;

    cout << z << " " << x << " " << y << endl;
}

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



Measured memory_bytes: 3624
#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>;
using Graph = vector<vector<int>>;

// header area

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

    if(A+B==3) cout << 3 << endl;
    else if(A+B==4) cout << 2 << endl;
    else cout << 1 << 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 Rep(i,n) for(int i=1;i<=n;i++)
const ll MOD = 1000000007;

struct edge{
    int to,weight;
    edge(int to,int weight):to(to),weight(weight){}
};
using Graph = vector<vector<int>> ;
using GraphEdge = vector<vector<int>> ;

long long modinv(long long a, long long m=MOD) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}
int main(){

    int N,Q;cin >> N >> Q;
    string s;cin >> s;
    int len = s.length();
    const int MAXN = 100001;
    int tm[MAXN];
    tm[0] = 0;
    Rep(i,len){
        tm[i] = tm[i-1];
        if(s[i-1]=='A' && s[i]=='C')tm[i]++;
    }
    const int MAXQ = 100001;
    int l[MAXQ],r[MAXQ];
    rep(i,Q){
        cin >> l[i]>> r[i];
    }

    rep(i,Q){
        cout << tm[r[i]-1] - tm[l[i]-1] << endl;
    }




    return 0;
}

Measured memory_bytes: 4940
#include <bits/stdc++.h>
#define maxn 205
#define maxk 60
using namespace std;

int T, n;
long long a[maxn];
string s;

int bits[maxk][maxn], choice[maxk], N = 0;

void add(long long target) {
	for (int i = 0; i < maxk; i++) {
		bits[i][N] = (target & (1LL << i)) ? 1 : 0;
	}
	for (int i = 0; i < maxk; i++) if (bits[i][N]) {
		for (int col = 0; col < N; col++) if (bits[i][col]) {
			bool is_valid = true;
			for (int row = 0; row < i; row++) if (bits[row][col]) {
				is_valid = false;
				break;
			}
			if (!is_valid) {
				continue;
			}
			for (int row = 0; row < maxk; row++) {
				bits[row][N] ^= bits[row][col];
			}
			break;
		}
	}
	N++;
}

bool solve(long long target) {
	for (int i = 0; i < maxk; i++) {
		choice[i] = (target & (1LL << i)) ? 1 : 0;
	}

	for (int i = 0; i < maxk; i++) if (choice[i]) {
		for (int col = 0; col < N; col++) if (bits[i][col]) {
			bool ok = true;
			for (int row = 0; row < i; row++) if (bits[row][col]) {
				ok = false;
			}
			if (!ok) {
				continue;
			}
			for (int row = 0; row < maxk; row++) choice[row] ^= bits[row][col];
			break;
		}
		if (choice[i]) {
			return false;
		}
	}
	return true;
}

bool solve_case() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	cin >> s;

	N = 0;
	for (int i = n - 1; i >= 0; i--) if (s[i] == '0') {
		add(a[i]);
	} else if (!solve(a[i])) {
		return true;
	}
	return false;
}

int main() {
	cin >> T;
	while (T--) {
		cout << solve_case() << endl;
	}
	return 0;
}

Measured memory_bytes: 3648
n,m=map(int,input().split())
A=[[0,0] for i in range(n)] #ACしたか、WA数
AC=0
pen=0
for i in range(m):
    a,b=map(str,input().split())
    a=int(a)
    if b=="AC":
        A[a-1][0]=1
    elif b=="WA" and A[a-1][0]==0:
        A[a-1][1]+=1
for i in range(n):
    if A[i][0]==1:
        AC+=1
        pen+=A[i][1]
print(AC,pen)

Measured memory_bytes: 13172