akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <queue>
#include <utility>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mp make_pair

int N, p[200000], vis[200000];

int visit(int at) {
    if (vis[at]) return -1;
    vis[at] = 1;
    if (p[at] == 0) return at;
    return visit(at+p[at]);
}

int solve() {
    queue<pair<int, int> > q;
    q.push(mp(0, 0));
    while (!q.empty()) {
        pair<int, int> vv = q.front();
        q.pop();
        if (vv.second == N-1) return vv.first;
        rep (i, 6) {
            int t = visit(vv.second+1+i);
            if (t != -1) q.push(mp(vv.first+1, t));
        }
    }
    return -1;
}

int main() {
    scanf("%d", &N);
    rep (i, N) scanf("%d", p+i);
    printf("%d\n", solve());
    return 0;
}

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

ll n, ans;

int main() {
	cin>>n;
	for (int i=1; i<=n; i++) {
		ll akhir=n/i;
		ll tambah=(akhir+1)*akhir/2;
		tambah*=i;
		ans+=tambah;
	}
	cout<<ans<<endl;
}



Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);

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


int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  vector<int> s, t;   //正の配列， tの配列
  REP(i,n){
    cin >> a[i];
    if(a[i] < 0 ) t.push_back(a[i]);
    else s.push_back(a[i]);
  }

  int S = s.size();
  int T = t.size();

  bool ok = false;  //積が正にできるか？

  if(S > 0){
    if(n == k) ok = (T%2 == 0);
    else ok = true;
  }
  else{ //正の数が０個のとき
  ok = (k%2 == 0);
  }

  mint ans = 1;


  //答えが負になるとき
  if(!ok){
    sort(a.begin(), a.end(), [](int x, int y) {
      return abs(x) < abs(y);
    });
    REP(i,k) ans *= a[i];
  }
  //答えが正
  else{
    sort(ALL(s));
    sort(RALL(t));
    if(k % 2 == 1){
      ans *= s.back();  //最後の値を参照
      s.pop_back(); //最後の値を除去
    }


    //二個セットの配列を作製

    vector <ll> p;
    while(s.size() >= 2){
      ll x = s.back();
      s.pop_back();
      x *= s.back(); s.pop_back();
      p.push_back(x);
    }

    while(t.size() >= 2){
      ll x = t.back();
      t.pop_back();
      x *= t.back(); t.pop_back();
      p.push_back(x);
    }

    sort(RALL(p));
    REP(i,k/2) ans *= p[i];
  }

  cout << ans << endl;


  return 0;


}

Measured memory_bytes: 6256
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
int main(){
  int K;
  cin >> K;
  int sum = 0;
  for (int i = 1; i <= K; i++){
    for (int j = 1; j <= K;j++){
      for (int l = 1; l <= K;l++){
        vector<int> data(3);
        data.at(0) = i;
        data.at(1) = j;
        data.at(2) = l;
        sort(data.begin(), data.end());
        int a = __gcd(data[2], data[1]);
        sum += __gcd(data[0], a);
        //cout << __gcd(data[0], a) << endl;
      }
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 3624
#![allow(non_snake_case)]
#![allow(unused_imports)]
use ascii::AsciiChar;
use ascii::AsciiStr;
use itertools::Itertools as _;
use permutohedron::LexicalPermutation as _;
use petgraph::algo::dijkstra;
use petgraph::algo::min_spanning_tree;
use petgraph::data::FromElements;
use petgraph::graph::NodeIndex;
use petgraph::graph::UnGraph;
use petgraph::unionfind::UnionFind;
use proconio::fastout;
use proconio::input;
use proconio::marker::Chars;
use proconio::marker::Usize1;
use std::cmp::max;
use std::cmp::min;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use superslice::Ext as _;

// ナイーブ解法でいくつかの値を見てみたが、mに比例していることしか掴めなかった
// 数学ゲーだったかあ

#[fastout]
fn main() {
    input! {
        N: i64,
        M: usize,
        D: i64,
    }

    // let mut sum_of_beauty: i64 = 0;

    // // まずは全探索でやってみて傾向を掴む
    // let mut stack: Vec<Vec<i64>> = Vec::new();
    // for i in 1..=N {
    //     let state = vec![i as i64];
    //     stack.push(state);
    // }

    // while !stack.is_empty() {
    //     let state = stack.pop().unwrap();

    //     if state.len() == M {
    //         let mut beauty: i64 = 0;
    //         for i in 0..M - 1 {
    //             if (state[i] - state[i + 1]).abs() == D {
    //                 beauty += 1;
    //             }
    //         }
    //         sum_of_beauty += beauty;
    //     } else {
    //         for i in 1..=N {
    //             let mut new_state = state.clone();
    //             new_state.push(i);

    //             stack.push(new_state);
    //         }
    //     }
    // }

    // let ans = sum_of_beauty as f64 / N.pow(M as u32) as f64;
    if D == 0 {
        let nume: i64 = M as i64 - 1;
        let demo: i64 = N;
        let ans = nume as f64 / demo as f64;
        println!("{}", ans);
    } else {
        let nume: i64 = 2 * (N - D) * (M as i64 - 1);
        let demo: i64 = N * N;
        let ans = nume as f64 / demo as f64;
        println!("{}", ans);
    }
}


Measured memory_bytes: 2228
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
n=int(input())
edges=[[] for i in range(n)]
for i in range(n-1):
  a,b,c=map(int,input().split())
  edges[a-1].append((b-1,c))
  edges[b-1].append((a-1,c))
q,k=map(int,input().split())
depth=[0]*n
def dfs(child,parent,d):
  if edges[child]==parent:
    return
  depth[child]=d
  for newchild,distance in edges[child]:
    if newchild==parent:
      continue
    dfs(newchild,child,d+distance)
  return
dfs(k-1,-1,0)
for i in range(q):
  x,y=map(int,input().split())
  x-=1
  y-=1
  ans=depth[x]+depth[y]
  print(ans)

Measured memory_bytes: 131760
n,k = map(int,input().split())
p = list(map(int,input().split()))

a = i = j = count = ans = 0

new_p = [0] * n

for i in range(n):
    new_p[i] = float((p[i]+1)/2)

i = j = 0
total = 0
for i in range(k):
    total += new_p[i]
ans = total
for i in range(k,n):
    total = total + new_p[i] - new_p[i-k]
    ans = max(ans,total)

print('{:.10f}'.format(ans))

Measured memory_bytes: 24808
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <map>
#include <vector>
#include <unordered_map>

#define div 1000000000+7

using ll = long long;
using namespace std;

void solve() {
    int n, m;
    cin >> n >> m;
    cout << (1900*m+100*(n-m))*pow(2,m) << endl;
}

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

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

using namespace std;

int main(){
	int n;
	cin>>n;
	string s;
	cin>>s;
	int i=0;
	int j=n-1;
	int count=0;
	while(i<j){
		if(s[i]=='W'&&s[j]=='R'){
			swap(s[i],s[j]);
				count++;
			i++;
			j--;
		}
	else if(s[i]=='W'&&s[j]!='R'){
		j--;
	}
	else{
		i++;
	}
	}
	cout<<count<<endl;
}

Measured memory_bytes: 3728
#include<iostream>
#include<set>
using namespace std;int Q,N,a,p,M,t;main(){for(cin>>Q;Q--;cout<<a<<endl){set<int>u;for(cin>>N,a=0;N/10&&~a;N=M)for(u.count(N)&&(a=-2),u.insert(N),a++,p=M=1;p<N;p*=10,M=t>M?t:M)t=(N/p)*(N%p);}}

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

using namespace std;
//-----pre_def----
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
#define pi 3.1415926
#define eps 0.000001
#define fir(i, a, b) for (int i = a; i <= b; i++)
#define rif(i, a, b) for (int i = a; i >= b; i--)
#define init_h memset(h, -1, sizeof h), idx = 0;
//---------------
double rx, ry, r, x, y;

double get_dis(double x1, double y1, double x2, double y2)
{
    double c = (x1 - x2) * (x1 - x2);
    double d = (y1 - y2) * (y1 - y2);
    return sqrt(c + d);
}

double get_rad2()
{
    double t1 = (x - rx) / (y - ry);
    double t2 = atan(t1);
    return 180 * t2 / pi;
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    int StartTime = clock();
#endif

    LL n, m;
    cin >> n >> m;
    LL t = __gcd(n, m);
    LL u = n / t;
    LL v = 3 * (u - 1);
    cout << t * v << endl;

#ifndef ONLINE_JUDGE
    printf("Run_Time = %d ms\n", clock() - StartTime);
#endif
    return 0;
}


Measured memory_bytes: 3652
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::*;
use std::str::FromStr;

#[allow(unused_macros)]
macro_rules! debug {($($a:expr),*) => {println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
#[allow(unused_macros)]
macro_rules! input {(source=$s:expr,$($r:tt)*) => {let mut iter=$s.split_whitespace(); let mut next=||{iter.next().unwrap()}; input_inner! {next,$($r)*}};($($r:tt)*) => {let stdin=std::io::stdin();let mut bytes=std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next=move||->String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()}; input_inner! {next,$($r)*}};}
#[allow(unused_macros)]
macro_rules! input_inner {($next:expr) => {}; ($next:expr,) => {}; ($next:expr,$var:ident:$t:tt$($r:tt)*) => {let $var=read_value!($next,$t); input_inner! {$next$($r)*}};}
#[allow(unused_macros)]
macro_rules! read_value {($next:expr,($($t:tt),*)) => {($(read_value! ($next,$t)),*)}; ($next:expr, [$t:tt; $len:expr]) => {(0..$len).map(|_|read_value! ($next,$t)).collect::<Vec<_>>()}; ($next:expr,chars) => {read_value! ($next,String).chars().collect::<Vec<char>>()}; ($next:expr,usize1) => {read_value! ($next,usize)-1}; ($next:expr,$t:ty) => {$next().parse::<$t>().expect("Parse error")};}

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

#[allow(dead_code)]
const MAX: usize = 100006;
#[allow(dead_code)]
const INF_U32: u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32: i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64: u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64: i64 = 1 << 62;
#[allow(dead_code)]
const MOD: i64 = 1e9 as i64 + 7;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[allow(dead_code)]
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()
}

#[allow(unused_imports)]
use std::f64;


fn main() {
    input!{s:chars, t:chars};
    let mut s = s;
    let mut t = t;
    s.sort();
    t.sort();
    t.reverse();
    let s:String = s.into_iter().collect();
    let t:String = t.into_iter().collect();

    println!("{}", if s < t {"Yes"} else {"No"});

}


Measured memory_bytes: 4352
import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

immutable inf = 10^^6;

void main() {
    int k;
    scan(k);

    auto d = new int[](k);
    d[] = inf;
    d[1] = 1;

    auto deq = Deque!(int)(3*k);
    deq.pushBack(1);

    while (!deq.empty) {
        auto u = deq.front;
        deq.popFront();

        if (d[(u + 1) % k] > d[u] + 1) {
            d[(u + 1) % k] = d[u] + 1;
            deq.pushBack((u + 1) % k);
        }

        if (d[(u * 10) % k] > d[u]) {
            d[(u * 10) % k] = d[u];
            deq.pushFront((u * 10) % k);
        }
    }

    writeln(d[0]);
}

struct Deque(T) {
    private {
        int N, head, tail;
        T[] deq;
    }

    this(int n) {
        N = n + 1;
        deq = new T[](N + 1);
    }

    bool empty() {
        return head == tail;
    }

    bool full() {
        return head == ((tail + 1) % N);
    }

    int length() {
        return (tail - head + N) % N;
    }

    T front() {
        assert(!empty);
        return deq[head];
    }

    T back() {
        assert(!empty);
        return deq[(tail - 1 + N) % N];
    }

    void pushFront(T x) {
        assert(!full);
        head = (head - 1 + N) % N;
        deq[head] = x;
    }

    void pushBack(T x) {
        assert(!full);
        deq[tail++] = x;
        tail %= N;
    }

    void popFront() {
        assert(!empty);
        head = (head + 1) % N;
    }

    void popBack() {
        assert(!empty);
        tail = (tail - 1 + N) % N;
    }
}

unittest {
    int n = 5;
    auto deq = Deque!(int)(n);

    deq.pushFront(3);
    deq.pushBack(1);
    deq.pushBack(4);
    deq.pushFront(5);

    assert(deq.front == 5);
    assert(deq.back == 4);
    assert(deq.length == 4);

    deq.pushFront(0);

    assert(deq.full);
    assert(deq.front == 0);
    assert(deq.length == 5);

    deq.popFront();
    deq.popFront();
    deq.popBack();

    assert(deq.front == 3);
    assert(deq.back == 1);
    assert(deq.length == 2);

    deq.popBack();
    deq.popFront();

    assert(deq.empty);
    assert(deq.length == 0);

    writeln("ok");
}

void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 3708
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n;
    cin>>n;
    vector<char> ans;
    for(;n>0;){
        lldiv_t calc = div(n, (ll)26);
        if (calc.rem) {
            ans.push_back('a' + calc.rem - 1);
            n = calc.quot;
        } else {
            ans.push_back('z');
            n = calc.quot - 1;
        }
    }
    reverse(ans.begin(), ans.end());
    for(auto&c : ans){
        cout<<c;
    }
    cout<<endl;
    return 0;
}

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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define what_is(x) cerr << #x << " is " << x << endl;

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

char s[100005];

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	int n, q;
	scanf("%d%d%s", &n, &q, s);

	vi v;
	for (int i = 0; i < n-1; i++) {
		if (s[i] == 'A' && s[i+1] == 'C') v.push_back(i);
	}
	//for (int x : v) printf("%d ", x); puts("");

	while (q-- > 0) {
		int l, r;
		scanf("%d%d", &l, &r);
		--l, --r;
		auto it1 = lower_bound(all(v), l);
		auto it2 = lower_bound(all(v), r);
		int answer = it2 - it1;
		printf("%d\n", answer);
	}
}


Measured memory_bytes: 1276
#include <cstdio>
#include <algorithm>
typedef long long int64;
static const int MAXN = 1004;

int n, t_i, a_i;
int64 T, A;

int main()
{
    scanf("%d", &n);
    scanf("%lld%lld", &T, &A);

    for (int i = 1; i < n; ++i) {
        scanf("%d%d", &t_i, &a_i);
        int64 k = std::max((T + t_i - 1) / t_i, (A + a_i - 1) / a_i);
        T = k * t_i;
        A = k * a_i;
    }

    printf("%lld\n", T + A);
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
int n;
int C[10000];
void swap(int* x,int* y){
    int temp;
    temp=*x;
    *x=*y;
    *y=temp;
}
int partition(int A[],int p,int r){
    int x,i,j;
    x=A[r];
    i=p-1;
    for(j=p;j<r;j++){
        if(A[j]<=x){
            i=i+1;
            swap(&A[i],&A[j]);
        }
    }
    swap(&A[i+1],&A[r]);
    return i+1;
}
int main(){
    int i,r;
    int A[100000];
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&A[i]);
    }
    r=partition(A,0,i-1);
    for(i=0;i<n-1;i++){
        if(i==r){
            printf("[");
        }
        printf("%d",A[i]);
        if(i==r){
            printf("] ");
        }
        else{
            printf(" ");
        }
    }
    printf("%d\n",A[i]);
    return 0;
}


Measured memory_bytes: 2156
N=input()
a=list(map(int,input().split()))
a.sort(reverse = True)
Alice,Bob=0,0
while len(a) != 0:
  if len(a) != 0:
     Alice+=a.pop(0)
  if len(a) != 0:
     Bob += a.pop(0)
print(Alice-Bob)

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

int a[25], b[25], c[25];

int main(){

    int n; cin >> n;
    for(int i = 0; i < n; i++)
        cin >> a[i];
    for(int i = 0; i < n; i++)
        cin >> b[i];
    int sum = 0;
    for(int i = 0; i < n; i++)
        sum += b[i];
    for(int i = 0; i < n-1; i++)
        cin >> c[i];
    for(int i = 0; i < n; i++){
        if(i-1 >= 0 and a[i] == a[i-1]+1)
            sum += c[a[i-1]-1];
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#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=1e5;


int main(){
	int N;
	cin>>N;
	int A[MAX],B[MAX],C[MAX];
	rep(i,N) cin>>A[i];
  	rep(i,N) cin>>B[i];
  	rep(i,N) cin>>C[i];

	sort(A,A+N);
	sort(C,C+N);
	
	lli ans=0;
	rep(i,N) {
		lli ause=lower_bound(A,A+N,B[i])-lower_bound(A,A+N,0);
		lli cunuse=upper_bound(C,C+N,B[i])-upper_bound(C,C+N,0);
		ans+=ause*(N-cunuse);
	}
	cout<<ans;
}

Measured memory_bytes: 1408
#include<cstdio>
#include<iostream>

#define INF 2100000000

using namespace std;

int minix(int a,int b,int c){
	if(b>=a && c>=a){
		return a;
	}
	if(a>=b && c>=b){
		return b;
	}
	if(b>=c && a>=c){
		return c;
	}
}

int main(){
	int n;
	int masu[1002][1002];
	int ura[1002][1002];
	char str[1002];
	while(1){
		for(int i=0;i<=1001;i++){
			for(int j=0;j<=1001;j++){
				masu[i][j]=0;
			}
		}
		scanf("%d",&n);
		if(n==0){
			break;
		}
		for(int i=1;i<=n;i++){
			scanf("%s",str);
			for(int j=1;j<=n;j++){
				if(str[j-1]=='.'){
					ura[i][j]=0;
				}else{
					ura[i][j]=1;
				}
			}
		}
		
		int maxi=0;
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				if(ura[i][j]==0){
					masu[i][j]=minix(masu[i-1][j],masu[i][j-1],masu[i-1][j-1])+1;
					maxi=max(masu[i][j],maxi);
				}
			}
		}
		
		printf("%d\n",maxi);
	}
}

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

using namespace std;

#define endl '\n'

int main(){

  ios_base :: sync_with_stdio(false);
  cin.tie(NULL);

  int n;
  cin >> n;

  for(int i=1;i<=n;i++){
    int cnt = 0;
    for(int x=1;x<=100;x++){
      for(int y=1;y<=100;y++){
        int val = i-x*x-y*y-x*y;
        int delta = (x+y)*(x+y) + 4*val;
        if(delta < 0)
          continue;
        int root = sqrt(delta);
        if(root*root != delta)
          continue;
        int z = (-(x+y) + root);
        if(z%2 || z <= 0)
          continue;
        cnt++;
      }
    }
    cout << cnt << endl;
  }

  return 0;
}

Measured memory_bytes: 3540
def find_root(components, n):
    if components[n] == n:
        return n
    elif components[components[n]] == components[n]:
        return components[n]
    else:
        components[n] = find_root(components, components[n])
        return components[n]

N, M = [int(s) for s in input().split(' ')]
bridges = []
for i in range(M):
    bridges.append([int(s)-1 for s in input().split(' ')])
components = [i for i in range(N)]
componentsLen = [1 for i in range(N)]
inconvenience = [int(N * (N-1) / 2)]
for i in range(M-1, -1, -1):
    a, b = bridges[i]
    a_root = find_root(components, a)
    b_root = find_root(components, b)
    if a_root != b_root:
        inconvenience.append(inconvenience[-1] - componentsLen[a_root] * componentsLen[b_root])
        if componentsLen[a_root] < componentsLen[b_root]:
            a_root, b_root = b_root, a_root
        componentsLen[a_root] += componentsLen[b_root]
        components[b_root] = a_root
    else:
        inconvenience.append(inconvenience[-1])
for i in range(M-1, -1, -1):
    print(inconvenience[i])


Measured memory_bytes: 29892
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define fi first
#define se second
using namespace std;

int inf = 2147483647;
int64_t inf64 = 9223372036854775807;
int mod = 1e+7;

vector<pair<int64_t, int64_t>> toMulti(int64_t n) {
  vector<pair<int64_t, int64_t>> res(0);
  for (int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) res.push_back({i, n/i});
  }
  return res;
}

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

  int64_t n;
  cin >> n;
  vector<pair<int64_t, int64_t>> mult = toMulti(n);
  int64_t res = inf64;
  for(auto p : mult) {
    res = min(res, p.fi+p.se-2);
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 384
//#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cctype>


using namespace std;
#define modd 1000000007


typedef pair<long long, long long> pl;


typedef string::const_iterator State;
class ParseError {};




#define ll long long




/*
class UnionFind {
public:
	vector <ll> par;
	vector <ll> siz;
	vector <ll> gr;

	// Constructor
	UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) ,gr(sz_){
		for (ll i = 0; i < sz_; ++i) par[i] = i;
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
		for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}

	// Member Function
	// Find
	ll root(ll x) { // 根の検索
		while (par[x] != x) {
			x = par[x] = par[par[x]]; // x の親の親を x の親とする
		}
		return x;
	}

	// Union(Unite, Merge)
	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;

		// merge technique（データ構造をマージするテク．小を大にくっつける）
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}



	bool issame(ll x, ll y) { // 連結判定
		return root(x) == root(y);
	}

	ll size(ll x) { // 素集合のサイズ
		return siz[root(x)];
	}


};*/


long long N, M, K, a, b, c, d, e, H, W, L;
ll A[100005] = {};
ll B[300005] = {};
ll C[300005] = {};
bool f, ff;
string S,T;
set <long long>sll;
pl bufpl;
vector <long long>vl;
vector <pl>vpl;
vector <string> vs;
set<ll> llset;
multiset<ll> llmset;

/*struct ST
{
	long long Kati;
	int bangou;

	bool operator<(const ST& another) const
	{
		return Kati < another.Kati;//比較
	};

};



vector <ST> vst;
ST st[200005];
ST bufst;
bitset<5000> bits;*/


long long modinv(long long aa, long long mm) {
	long long bb = mm, uu = 1, vv = 0;
	while (bb) {
		long long tt = aa / bb;
		aa -= tt * bb; swap(aa, bb);
		uu -= tt * vv; swap(uu, vv);
	}
	uu %= mm;
	if (uu < 0) uu += mm;
	return uu;
}



ll minn, maxx;
double ansa;
bool fl[30] = {};


string ss, sss;

int main() {


	cin >> N;

	f = true;

	for (int i = 0; i < 4; i++) {
		A[i] = N % 10;
		N /= 10;
	}

	for (int i = 0; i < 3; i++) {
		if (A[i] == A[i + 1]) {
			f = false;
		}
	}

	if (f) {
		cout << "Good" << endl;
	}
	else {
		cout << "Bad" << endl;
	}

	return 0;

}


Measured memory_bytes: 256
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
//#include <algorithm>
//#include <utility>
#include <set>
//#include <map>
//#include <queue>
//#include <deque>
#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b%mod ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	while(1){
		ll a,x ;
		cin >> a >> x ;
		if(a==0&&x==0) return 0 ;
		ll cnt = 0 ;
		for(int i=1;i<=a-2;i++) for(int j=i+1;j<=a-1;j++) if(j<x-i-j&&x-i-j<=a) cnt++ ;
		cout << cnt << endl ;
	}
}



Measured memory_bytes: 3068
# include <bits/stdc++.h>
# define int long long
using namespace std;
const int N = 2e5 + 10, mod = 1e9 + 7;
int x[N];
main(){
    int n, ans = 1e9 + 100;
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> x[i];
    }
    for(int i = 1; i <= 100; i++){
        int cur = 0;
        for(int j = 1; j <= n; j++){
            cur += (i - x[j]) * (i - x[j]);
        }
        ans = min(ans, cur);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define Fast_IO ios::sync_with_stdio(false);
#define DEBUG fprintf(stderr,"Running on Line %d in Function %s\n",__LINE__,__FUNCTION__)
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define fir first
#define sec second
#define mod 998244353
#define ll long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
inline int read()
{
	char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
	int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
	if(nega==-1) return -ans;
	return ans;
}
typedef pair<int,int> pii;
inline int min(int x,int y,int z){return min(x,min(y,z));}
inline int max(int x,int y,int z){return max(x,max(y,z));}
inline int add(int x,int y){return x+y>=mod?x+y-mod:x+y;}
inline int add(int x,int y,int z){return add(add(x,y),z);}
inline int sub(int x,int y){return x-y<0?x-y+mod:x-y;}
inline int mul(int x,int y){return 1LL*x*y%mod;}
inline int mul(int x,int y,int z){return mul(mul(x,y),z);}
#define N 100005
vector<int> G[N];
int dgr[N],vis[N],x,y;
void dfs(int u)
{
	vis[u]=1;
	for(int v:G[u])
	{
		if(vis[v]==1) continue;
		if(vis[v]==2)
		{
			if(x) y=v;
			else x=v;
		}
		if(!vis[v]) dfs(v);
	}
}
signed main()
{
	int n=read(),m=read();
	for(int i=1;i<=m;i++)
	{
		int u=read(),v=read();
		G[u].pb(v),G[v].pb(u);
		dgr[u]++,dgr[v]++;
	}
	int maxn=0,cnt=0;
	for(int i=1;i<=n;i++)
	{
		if(dgr[i]&1) {cout<<"No\n"; return 0;}
		if(dgr[i]>maxn) maxn=dgr[i],cnt=0;
		if(maxn==dgr[i])  cnt++;
	}
	if(maxn>=6) {cout<<"Yes\n"; return 0;}
	if(maxn==2) {cout<<"No\n"; return 0;}
	if(cnt>2) {cout<<"Yes\n"; return 0;}
	if(cnt==1) {cout<<"No\n"; return 0;}
	for(int i=1;i<=n;i++) if(dgr[i]==4) vis[i]=2;
	for(int i=1;i<=n;i++) if(!vis[i])
	{
		x=0,y=0; dfs(i);
		if(x==y) {cout<<"Yes\n"; return 0;}
	}
	cout<<"No\n";
	return 0;
}




Measured memory_bytes: 7296
#define _USE_MATH_DEFINES

#include <array>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <utility>
#include <tuple>
#include <algorithm>
#include <limits>
#include <fstream>
#include <numeric>
#include <stack>
#include <queue>
#include <list>
#include <cstring>
#include <unordered_set>
#include <cmath>
#include <iomanip>

namespace
{
	template<int N>
	std::array<int, N> GetValue(std::istream& stream)
	{
		std::string buf;
		std::getline(stream, buf);

		std::stringstream sstr(buf);
		std::array<int, N> retval;

		for (int i = 0; i < N; ++i)
		{
			std::getline(sstr, buf, ' ');
			retval[i] = std::stoi(buf);
		}

		return retval;
	}

	std::vector<int> GetValue(std::istream& stream, int num, char delim)
	{
		std::string buf;
		std::getline(stream, buf);
		std::stringstream sstr(buf);

		std::vector<int> retval;
		retval.reserve(num);

		std::string input;;
		for (int i = 0; i < num && std::getline(sstr, input, delim); ++i)
		{
			retval.push_back(std::stoi(input));
		}

		return retval;
	}

	int GetValue(std::istream& stream)
	{
		int in;
		stream >> in;

		return in;
	}

	std::vector<std::string> GetValueString(std::istream& stream, int num, char delim)
	{
		std::string buf;
		std::vector<std::string> retval;
		retval.reserve(num);

		std::getline(stream, buf);
		std::stringstream sstr(buf);

		for (int i = 0; i < num && std::getline(sstr, buf, delim); ++i)
		{
			retval.push_back(std::move(buf));
		}

		return retval;
	}

	template<typename Itr>
	void PrintLine(Itr begin, Itr end)
	{
		bool first = true;

		for (int i = 0; begin != end; ++begin, ++i)
		{
			if (!first)
			{
				std::cout << ' ';
			}

			std::cout << (*begin);

			first = false;
		}
		std::cout << std::endl;
	}

	template<typename T>
	void Print(const std::vector<T>& sequence)
	{
		for (const auto& e : sequence)
		{
			std::cout << e << '\n';
		}

		std::cout << std::flush;
	}

	uint64_t fibonacchi[50] = {};

	uint64_t Fibonacci(uint64_t n)
	{
		if (n == 0 || n == 1)
		{
			if (fibonacchi[n] == 0)
			{
				fibonacchi[n] = 1;
			}
			return fibonacchi[n];
		}

		if (fibonacchi[n] == 0)
		{
			fibonacchi[n] = Fibonacci(n - 1) + Fibonacci(n - 2);
		}

		return fibonacchi[n];
	}
}

int main(int argc, char* argv[])
{
	auto file = (argc == 1) ? std::ifstream() : std::ifstream(argv[1]);
	std::istream& stream = (argc == 1) ? std::cin : file;
	if (argc == 1)
	{
		std::cin.tie(0);
		std::ios::sync_with_stdio(false);
	}

	int num;
	stream >> num;

	std::cout << Fibonacci(num) << std::endl;
}



Measured memory_bytes: 3132
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n;
  cin >> n;
  vi a(n);
  vector<double> x(n),y(n);
  rep(i,n)cin >> x[i] >> y[i];
  iota(a.begin(), a.end(), 1);
  rep(i,n)a[i]--;
  double ans = 0;
  double cnt = 0;
  do {
      double px = x[a[0]],py = y[a[0]];
       srep(i,1,n){
         double xx = (px-x[a[i]])*(px-x[a[i]]);
         double yy = (py-y[a[i]])*(py-y[a[i]]);
         ans+= sqrt(xx+yy);
         px = x[a[i]]; py = y[a[i]];
       }  
       cnt++;
  } while( next_permutation(a.begin(), a.end()) );
  printf("%.10f\n",ans/cnt);
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,m,ans=1e18;
    cin>>n>>m;
    n%=m;
    for(int i=1;i<=10;i++)
    {
        ans=min(ans,n);
        n=abs(n-m);
    }
    cout<<ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <deque>
#include <numeric>
#include <sstream>
#include <iomanip>
using lint = long long;

int main()
{
    lint n;
    scanf("%lld", &n);

    std::vector<lint> x_l(n);
    std::vector<lint> y_l(n);
    std::vector<lint> h_l(n);

    for (int i = 0; i < n; ++i)
    {
        lint x, y, h;
        scanf("%lld", &x);
        scanf("%lld", &y);
        scanf("%lld", &h);
        x_l[i] = x;
        y_l[i] = y;
        h_l[i] = h;
    }

    for (lint cy = 0; cy <= 100; ++cy)
    {
        for (lint cx = 0; cx <= 100; ++cx)
        {
            lint cand_h = -1;
            lint lim = 1e10 + 1;
            lint ok = 1;
            for (int i = 0; i < n; ++i)
            {
                lint dist = abs(x_l[i] - cx) + abs(y_l[i] - cy);
                if (h_l[i] == 0)
                {
                    lim = std::min(dist, lim);
                }
                else
                {
                    lint cur_h = h_l[i] + dist;
                    if (cand_h < 0)
                    {
                        cand_h = cur_h;
                    }
                    else if (cand_h != cur_h)
                    {
                        ok = 0;
                        break;
                    }
                }
            }
            if (ok && cand_h <= lim && cand_h > 0)
            {
                printf("%lld %lld %lld", cx, cy, cand_h);
                return 0;
            }
        }
    }

    return 0;
}


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

#define io ios::sync_with_stdio(false)
#define pb push_back
#define pqueue priority_queue
#define fi first
#define se second
#define ls rt<<1
#define rs rt<<1|1
#define sz(x) (int)(x).size()
#define dbg(x) cout<<#x<<" --- "<<x<<endl
#define mst(x,a) memset(x,a,sizeof(x))
#define fin(a) freopen(a,"r",stdin)
#define fout(a) freopen(a,"w",stdout)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll gcd(ll a,ll b){ return b==0?a:gcd(b,a%b); }
ll qpow(ll a,ll b,ll m){ ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r; }
const int inf=0x7fffffff;

int main(){
	ll x=0;
	int k;cin>>k;
	for(int i=1;i<=k;i++){
		x=(x*10LL+7LL)%(ll)k;
		if(x==0){
			cout<<i<<endl;
			return 0;
		}
	}
	cout<<-1<<endl;
}

Measured memory_bytes: 3664
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define ll long long
#define INF 1000000000000000000
#define INT_MAX 2147483647

#include <iostream>

using namespace std;
 
template<class T> inline bool chmax(T& a, T b) {
	 if (a < b) {
	 	a = b; 
	 	return true;
	 } 
	 return false;
}
 
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

ll N, W, w[110], v[110];
ll DP[110][110000] = {};
 
int main() {
	cin >> N >> W;
	
	for(int i = 0; i < N; i++){
		cin >> w[i] >> v[i];
	}
	

	for(int i = 0; i < 110; i++){
		for(int j = 0; j < 110000; j++){
            DP[i][j] = INF;
        }
    }

    DP[0][0]=0;


	for(int i = 0; i < N; i++){
		for(int j = 0; j < 110000; j++){
			chmin(DP[i+1][j], DP[i][j]);
			if(j - v[i] >= 0) {
				chmin(DP[i+1][j], DP[i][j - v[i]] + w[i]);
			}
		}
	}

    ll ans = 0;
	for(ll i = 0; i < 110000; i++) {
		if(W >= DP[N][i] && ans < i) {
			ans = i;
		}
	}
	cout << ans << endl;
}


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

int main(){
    int N;
    cin >> N;
    int A;
    map<int, int> ans;
    for (int i = 0; i < N-1; ++i){
        cin >> A;
        ans[A]++;
    }
    for (int i = 1; i <= N; ++i){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 12976
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// Edge :
type Edge struct {
	from, to, cost int
}

// Route :
type Route struct {
	path []int
}

const inf = math.MaxInt64 >> 10

// ベルマンフォード法
func bellmanFord2(N, S int, edges []Edge) ([]int, []Route, bool) {
	d := make([]int, N+1)
	for i := 0; i <= N; i++ {
		d[i] = inf
	}
	d[S] = 0
	r := make([]Route, N+1)
	r[S].path = []int{S}

	negativeLoop := false
	for i := 0; i <= N*2; i++ {
		for _, e := range edges {
			if d[e.to] > d[e.from]+e.cost {
				d[e.to] = d[e.from] + e.cost
				r[e.to].path = append(r[e.from].path, e.to)
				if i > N && (e.to == N || e.from == N) {
					negativeLoop = true
				}
			}
		}
	}

	return d, r, negativeLoop
}

// ベルマンフォード法
func bellmanFord(N, S int, edges []Edge) ([]int, bool) {
	d := make([]int, N+1)
	for i := 0; i <= N; i++ {
		d[i] = inf
	}
	d[S] = 0

	for i := 0; i <= N; i++ {
		for _, e := range edges {
			if d[e.from] == inf {
				continue
			}
			if d[e.to] > d[e.from]+e.cost {
				d[e.to] = d[e.from] + e.cost
			}
		}
	}

	negativeLoop := false
	for i := 0; i <= N; i++ {
		for _, e := range edges {
			if d[e.from] == inf {
				continue
			}
			if d[e.to] > d[e.from]+e.cost {
				d[e.to] = d[e.from] + e.cost
				if e.to == N || e.from == N {
					negativeLoop = true
				}
			}
		}
	}

	return d, negativeLoop
}

func main() {
	sc.Split(bufio.ScanWords)

	N, M := getInt(), getInt()
	edges := make([]Edge, M)
	for i := 0; i < M; i++ {
		f, t, c := getInt(), getInt(), getInt()
		edges[i] = Edge{f, t, -c}
	}
	S, D := 1, N

	// ここから
	d, _, negativeLoop := bellmanFord2(N, S, edges)

	if negativeLoop == true {
		out("inf")
	} else {
		out(-d[D])
	}

}


Measured memory_bytes: 57216
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
 
int main(){
    int N;
    cin >> N;
    int sum = 0;
    int num = N;
    while(num>0){
      int dig = num % 10;
      sum += dig;
      num /= 10;
    }
  if(N % sum == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,k;
  cin>>n>>k;
  cout<<n+1-k<<endl;

  return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define per(i,n) for(int i=(n)-1; i>=0; i--)
#define chmin(a,b) a = min(a,b)
#define chmax(a,b) a = max(a,b)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vv = vector<vi>;
const int MOD = 1000000007;

int main(){
    ll n,m,k;
    cin>>n>>m>>k;
    
    vector<ll> a(n+1,0), b(m+1,0);
    
    rep(i,n){
        cin>>a[i+1];
        a[i+1] += a[i];
    }
    
    
    rep(i,m){
        cin>>b[i+1];
        b[i+1] += b[i];
    }
    
    ll ans = 0;
    
    for(ll i=0; i<n+1; i++){
        ll target = k - a[i];
        if(target<0)continue;
        
        ll itr = upper_bound(b.begin(), b.end(), target) - b.begin();
        //cout << i << " " << itr << endl;
        if(itr==0)ans = max(ans, i);
        else ans = max(ans, itr-1 + i);
        //cout << ans << endl;
    }
    
    
    cout << ans <<endl;
    return 0;
}

Measured memory_bytes: 6420
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, f, n) for (int i = (f); i < (n); i++)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
ll const INF = 1LL << 60;

int main() {
    ll X;
    cin >> X;

    if (X == 3 || X == 5 || X == 7)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<bitset>
#include<functional>
#include<iterator>
#include<complex>
#include<fstream>
#include<random>
#include<ctype.h>
#include<stdio.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(i, n) for(int i=0;i<n;++i)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using PII = pair<ll, ll>;
using piii = pair<pii, pii>;
using Pi = pair<int, pii>;
using Graph = vector<vector<int>>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
bool check(int x, int y) {
	if (0 <= x && x<55 && 0 <= y && y<55)return true;
	else return false;
}
const int INF = 1001000100;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
using Graph = vector<vector<int>>;
ll mypow(ll x, ll n, ll m) {
	if (n == 0) {
		return 1;
	}
	if (n % 2 == 0) {
		return mypow(x*x%m, n / 2, m);
	}
	else {
		return x * mypow(x, n - 1, m) % m;
	}
}
long long modinv(long long a, long long m) {
	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;
}
const double PI=3.14159265358979323846;
const int MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];
//テーブルをつくる前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;//mod pにおける1,2,,,nの逆元
	for (int i = 2; i < MAX; ++i) {
		fac[i] = fac[i - 1] * i%INF;
		inv[i] = INF - inv[INF%i] * (INF / i) % INF;
		finv[i] = finv[i - 1] * inv[i] % INF;
	}
}

ll COM(int n, int k) {
	if (n < k)return 0;
	if (n < 0 || k < 0)return 0;
	return fac[n] * (finv[k] * finv[n - k] % INF) % INF;
}
double Euclidean_distance(double x1, double y1, double x2, double y2){
    return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

///////////////////////////////////////

int c[10][1005];
int main() {
	int h, w, k; cin >> h >> w >> k;
	vector<string>s(h);
	REP(i, h)cin >> s[i];
	int ans = INF;
	REP(div, 1 << (h - 1)) {
		int g = 0;
		vector<int>id(h);
		REP(i, h) {
			id[i] = g;
			if (div >> i & 1)++g;
		}
		g++;
		REP(i, g)REP(j, w)c[i][j] = 0;
		REP(i, h)REP(j, w)c[id[i]][j] += (s[i][j] - '0');
		int num = g - 1;
		vector<int>now(g, 0);
		bool ok = true;
		REP(j, w) {
			REP(i, g) {
				now[i] += c[i][j];
			}
			REP(i, g) {
				if (now[i] > k) {
					num++;
					now = vector<int>(g, 0);
					REP(l, g) {
						now[l] += c[l][j];
					}
					REP(l, g) {
						if (now[l] > k) {
							ok = false;
						}
					}
				}
			}
		}
		if (ok) {
			ans = min(ans, num);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>/*{{{*/
#include <bits/stdc++.h>
#define rep(i, x) for(int i = 0; i < (int)(x); i++)
#define reps(i,x) for(int i = 1; i <= (int)(x); i++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define RFOR(i, m, n) for(int i = m;i >= n;i--)
#define foreach(x,a) for(auto& (x) : (a) )
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fill(x,y) memset(x,y,sizeof(x))
#define pb(a) push_back(a)
#define debug(x)                 cerr << __LINE__ << ": " << #x << " -> " << x << '\n'
#define debug2(x, y)             cerr << __LINE__ << #x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define debug3(x, y, z)          cerr << __LINE__ << #x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define debug4(a, b, c, d)       cerr << __LINE__ << #a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define debug5(a, b, c, d, e)    cerr << __LINE__ << #a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define debug6(a, b, c, d, e, f) cerr << __LINE__ << #a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define INF 999999999
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<vii> vvii;
typedef tuple<int,int,int> iii;
typedef set<int> si;
typedef complex<double> pnt;
typedef vector<pnt> vpnt;
typedef priority_queue<pii,vii,greater<pii> > spq;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};/*}}}*/

ll n;
ll m;
ll x[1001];
ll y[1001];
ll z[1001];

ll f(int n, int m, int p,int q, int r){
  ll tmp[n];
  rep(i, n){
    tmp[i] = p*x[i] + q*y[i] + r*z[i];
  }
  sort(tmp, tmp+n, greater<ll>());

  ll res=0;
  rep(i, m){
    res += tmp[i];
  }
  debug(res);
  return res;
}

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

  cin >>n;
  cin >>m;
  rep(i,n){
    cin >> x[i];
    cin >> y[i];
    cin >> z[i];
  }

  ll res = 0;
  res = max(f(n,m,1,1,1), res);
  res = max(f(n,m,1,1,-1), res);
  res = max(f(n,m,1,-1,1), res);
  res = max(f(n,m,1,-1,-1), res);
  res = max(f(n,m,-1,1,1), res);
  res = max(f(n,m,-1,1,-1), res);
  res = max(f(n,m,-1,-1,1), res);
  res = max(f(n,m,-1,-1,-1), res);

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main implements Runnable {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        // Run with 32MB stack
        Thread thread = new Thread(null, new Main(), "", 32 * 1024 * 1024);
        thread.start();
    }

    @Override
    public void run() {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static void solve(Scanner scanner) {
        String s = scanner.next();
        int a = 0, b = 0;
        for (char c: s.toCharArray()) {
            if (c == '0') {
                a++;
            } else {
                b++;
            }
        }
        System.out.println(Math.min(a, b) * 2);
    }

}



Measured memory_bytes: 27092