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

int main(){
  int N;
  cin>>N;
  string ans;
  if(N%1111==0){
    ans="Yes";
  }
  else if((N/10)%111==0){
    ans="Yes";
  }
  else if((N%1000)%111==0){
    ans="Yes";
  }
  else{
  	ans="No";  
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3592
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();
        boolean flg = true;
        for (char c = 'a' ; c <= 'z' ; c++) {
            int count = 0;
            for (int j = 0 ; j < s.length ; j++) {
                if (s[j] == c) count++;
            }
            if (count % 2 == 1) {
                flg = false;
            }
        }
        System.out.println(flg ? "Yes" : "No");
    }

}


Measured memory_bytes: 25044
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(...) out(__VA_ARGS__);cout<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void out(){} template<class T,class... U> void out(T t,U ...u){cout<<t<<" ";out(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(string, s);
  int ans = INF;
  rep(i, 'a', 'z' + 1) {
    int cnt = 0;
    string t = s;
    char c = i;
    while (1) {
      bool ok = true;
      each(x, t) {
        if (x != c) {
          ok = false;
          break;
        }
      }
      if (ok) {
        break;
      }
      int l = t.length() - 1;
      string tmp = string(l, '_');
      rep(i, 0, l) {
        if (t[i] == c || t[i + 1] == c) {
          tmp[i] = c;
        } else {
          tmp[i] = '_';
        }
      }
      t = tmp;
      cnt++;
    }
    ans = min(ans, cnt);
  }
  print(ans);
}


Measured memory_bytes: 256
integer N
integer,allocatable,dimension(:)::A
integer oddcnt,evencnt
read*,N
allocate(A(N))
read*,A

oddcnt=0
do i=1,N
  if(and(A(i),1)==1)oddcnt=oddcnt+1
end do
evencnt=N-oddcnt
print"(A)",merge("YES","NO ",mod(oddcnt,2)==0)
end

Measured memory_bytes: 1152
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>
#include<cctype>

using namespace std;

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

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = INF+7;

struct edge{int to,cost;};

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

	int n;
	cin >> n;
	
	ll a[n];
	for(int i=0;i<n;i++) {
		cin >> a[i];
	}
	for(int i=1;i<n;i++){
		a[i]+=a[i-1];
	}

	//i+j==2m -> 正
	ll sum=0;
	ll ans[2]={};
	ll tmp;
	for(int i=0;i<=1;i++){
		sum=0;
		for(int j=0;j<n;j++){
//			cout << "\t" << a[j]+sum << " " << ans[i] << "\n";
			tmp = abs(a[j]+sum);
			if((i+j)%2==0 && a[j]+sum<=0){
				ans[i]+=tmp+1;
				sum+=tmp+1;
//				cout << "hit " << i << " " << j << "\n";
			}
			if((i+j)%2==1 && a[j]+sum>=0){
				ans[i]+=tmp+1;
				sum-=tmp+1;
//				cout << "hit " << i << " " << j << "\n";
			}
		}
//		cout << "ans[" << i << "] = " << ans[i] << "\n";
	}
	cout << min(ans[0],ans[1]) << "\n";

	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<math.h>
#include<stdlib.h>

int main(void)
{
    long long int N, K, t, k;
    int flag=0;

    scanf("%lld", &N);
    scanf("%lld", &K);

    N %= K;

    while(flag == 0) {
        N = llabs(N - K);
        t = N;
        N = llabs(N - K);
        k = N;
        N = llabs(N - K);
        if(N == t || N == k) {
            if(t < k) {
                printf("%lld\n", t);
            } else {
                printf("%lld\n", k);
            }
            break;
        }
    }

    return 0;
}


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

using lint = long long int;

struct Pos { int x, y, c; };

int R, C, ax, ay, bx, by, cost[555][555];
lint card[555][555], MOD = (lint)1e9 + 7;

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

void update(int x, int y, int nx, int ny, int nc, queue< Pos >& que) {
	if (nx < 0 || nx >= C || ny < 0 || ny >= R) return;
	if (cost[ny][nx] == -1) {
		cost[ny][nx] = nc;
		que.push(Pos{nx, ny, nc});
	}
	if (cost[ny][nx] == nc) card[ny][nx] = (card[ny][nx] + card[y][x]) % MOD;
}

int main() {
	cin >> R >> C >> ay >> ax >> by >> bx;
	
	memset(cost, -1, sizeof(cost));
	memset(card, 0, sizeof(card));
	
	cost[ay][ax] = 0;
	card[ay][ax] = 1;
	
	queue< Pos > que;
	que.push(Pos{ax, ay, 0});
	
	while (!que.empty()) {
		Pos p = que.front(); que.pop();
		int nc = p.c + 1;
		
		for (int d=0; d<4; ++d) {
			int nx = p.x + dx[d], ny = p.y + dy[d];
			update(p.x, p.y, nx, ny, nc, que);
		}
		
		update(p.x, p.y, p.x, 0, nc, que);
		update(p.x, p.y, p.x, R-1, nc, que);
		update(p.x, p.y, 0, p.y, nc, que);
		update(p.x, p.y, C-1, p.y, nc, que);
	}
	
	cout << cost[by][bx] << " " << card[by][bx] << endl;
}


Measured memory_bytes: 6740
def secMax(a):
    mx = 0
    smx = 0
    for i in range(0,len(a)):
        if a[i] > mx:
            smx = mx
            mx = a[i]
        elif a[i] > smx:
            smx = a[i]
    else:
        return smx

while True:
    n = int(input())
    if n == 0:
        break
    c = list(map(str,input().split()))
    ##alphabet = char('a')##char型ねぇよって言われた(´・ω・`)
    alph = ["A","B","C","D","E","F","G","H",
            "I","J","K","L","M","N","O","P","Q",
            "R","S","T","U","V","W","X","Y","Z"]
    abcCount = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
    for i in range(0, n):
        for j in range(0, 26):
            if c[i] == alph[j]:
                abcCount[j] = abcCount[j] + 1
                break
        #print(abcCount)
        if max(abcCount) > n-1-i+secMax(abcCount):
            print(alph[abcCount.index(max(abcCount))], sum(abcCount))
            break
    else:
        print("TIE")



Measured memory_bytes: 5628
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main(){
    string S;
    cin >> S;
    for(char a = 'a'; a <= 'z'; a++){
        if(S.find(a) == string::npos){
            cout << a << endl;
            return 0;
        }
    }
    puts("None");
}


Measured memory_bytes: 3724
#include <algorithm>
#include <iostream>
#include <vector>
#include <numeric>
#include <string>
#include <stdio.h>
using namespace std;


int main(){
  int K, A, B, C, D;
  cin >> K >> A >> B;
  C = A / K;

  if(((C+1) * K <= B)or(C * K == A)){
    cout << "OK";
  }else{
    cout << "NG";
  }
  return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define ll          long long int
#define ld          long double
#define pb          push_back
#define mp          make_pair
#define ff          first
#define se          second
#define endl        '\n'
#define fd(n)       fixed<<setprecision(n)
#define MAX         1000000000000000000
#define MAXN        200000005
#define mod         1000000007
using namespace std;
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,i,count=0,ans,j;
    cin>>n;
    ll a[n];
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    for(i=0;i<n;i++){
        for(j=i+1;j<n;j++){
            count+=a[i]*a[j];
        }
    }
    cout<<count;
}

Measured memory_bytes: 256
#include <cmath>

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

using ll = long long;
using ld = long double;
using vi = vector<int>;

string s;

void input() {
  cin >> s;
}

void solve() {
  string ans = "No";

  if (s.find('7') != string::npos)
    ans = "Yes";

  cout << ans << '\n';
}

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

  cout.precision(16);
  cout << fixed;

  int _times = 1;

#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);

  _times = 2;
#endif

  // cin >> _times;

  while (_times--) {
    input();
    solve();
  }
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

long long comb(long long a, long long b)
{
  if(b > a)
    return 0;

  b = min(b, a - b);
  long long rst = 1;
  for (int i = a; i > a - b; --i) 
    rst *= i;

  for (int i = 1 ; i < b + 1; ++i) 
    rst /= i;

    return rst;
}

int main()
{
  long long N, P;
  cin >> N >> P;
  long long count_odd = 0, count_even = 0;
  rep(i, N)
  {
    long long A;
    cin >> A;
    if(A % 2 == 0)
      count_even++;
    else
      count_odd++;
  }
  long long ans = 0;
  for(long long i = 0; i * 2 <= count_odd; i++)
  {
    long long count = comb(count_odd, 2 * i + P);
    ans += pow(2, count_even) * count;
  }
  cout << ans << endl;
  return 0;
}

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

int main(void) {
    long i, o, t, j, l, s, z;
    cin >> i >> o >> t >> j >> l >> s >> z;

    long r = 0;
    r += o; o -= o;

    if(((i&1) + (j&1) + (l&1) >= 2) && (i&&j&&l))
        r+=3, i--, j--, l--;
    r += i/2 * 2; i -= i/2*2;
    r += j/2 * 2; j -= j/2*2;
    r += l/2 * 2; l -= l/2*2;
    cout << r << endl;
}


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

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

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

	map<int, int> mp;

	for(int i = 0; i < n; i++){
		mp[a[i]]++;
	}

	int ans = 0;
	for(auto itr = mp.begin(); itr != mp.end(); itr++){
		int f = itr->first;
		int s = itr->second;
		if(f > s) ans += s;
		else if(f < s) ans += s-f;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 5120
#include <stdio.h>
int Binarysearch(int*,int,int);
#define N 100005

int main()
{
  int i,s,array[N],t,m,sum=0;

  scanf("%d",&s);
  for(i=0;i<s;i++)
    {
      scanf("%d",&array[i]);
    }
  scanf("%d",&t);
  for(i=0;i<t;i++)
    {
      scanf("%d",&m);
      if(Binarysearch(array,s,m)) sum++;
    }
  printf("%d\n",sum);
  return 0;
}

int Binarysearch(int A[],int x, int key)
{
  int left=0,right,mid=0;
  right=x;
  while(left<right)
    {
      mid=(left+right)/2;
      if(key==A[mid]) return 1;
      else if(key<A[mid]) right=mid;
      else if(key>A[mid]) left=mid+1;
    }
  return 0;
}

Measured memory_bytes: 2968
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    
    vector <int> a(26,0);
    
    for(string s;cin>>s;){
        
        for(char e:s) a[tolower(e)-'a']++;
        
    }
    
    for(int i=0;i<(int)a.size();i++) cout<<char(i+'a')<<" : "<<a[i]<<endl;
    
    return 0;
    
}



Measured memory_bytes: 3212
#include<stdio.h>

int main(void) {
    int n_num_std, m_num_btn;
    scanf("%d", &n_num_std);
    scanf("%d", &m_num_btn);

    int j, a_id_bibs[n_num_std];
    for(j = 0; j < n_num_std; j++) scanf("%d", &a_id_bibs[j]);

    int k_id_btn, i_id_std, buf;
    for(k_id_btn = 1; k_id_btn <= m_num_btn; k_id_btn++) {
        i_id_std = 1;
        while(i_id_std != n_num_std) {
            if((a_id_bibs[i_id_std - 1] % k_id_btn) > (a_id_bibs[i_id_std] % k_id_btn)) {
                buf = a_id_bibs[i_id_std - 1]; 
                a_id_bibs[i_id_std - 1] = a_id_bibs[i_id_std];
                a_id_bibs[i_id_std]     = buf;
            } else {
                i_id_std++;                                                                                        
            }   
        }   
    }   

    for(j = 0; j < n_num_std; j++) printf("%d\n", a_id_bibs[j]);

    return 0;
}

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

int main() {
  int N;
  string x;
  cin >> N;
  for(int i=0; i<N; i++){
    string S;
    cin >> S;
    if(S == "Y"){
      x = "Four";
      break;
    }
    else{
      x = "Three";
    }
  }
  cout << x << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstdio>
#include<bits/stdc++.h>
using namespace std;
long long l[10005],n;
int main()
{
	l[0]=2;
	l[1]=1;
	cin>>n;
	long long i=2;
	for(i=2;i<=n;i++)
	{
		l[i]=l[i-1]+l[i-2];
	}
	cout<<l[n]<<endl;
}

Measured memory_bytes: 256
pub fn read_parameters<T>() -> Result<Vec<T>, String>
where
    T: std::str::FromStr,
{
    let mut line = String::new();

    std::io::stdin()
        .read_line(&mut line)
        .map_err(|err| format!("{:?}", err))?;

    line.trim()
        .split_whitespace()
        .map(|x| x.parse::<T>())
        .collect::<Result<Vec<T>, _>>()
        .map_err(|_| format!("{}", "parse error"))
}

fn main() {
    let s = read_parameters::<String>().unwrap().join(" ");

    let ans = s
        .chars()
        .map(|c| {
            if c.is_uppercase() {
                c.to_string().to_lowercase()
            } else {
                c.to_string().to_uppercase()
            }
        })
        .collect::<String>();
    println!("{}", ans);
}



Measured memory_bytes: 5056
#include<iostream>
#include<algorithm>
using namespace std;
int n,a[2<<18],B[1<<18],ans,cnt,m,A,i,j,L;
main()
{
	for(cin>>n;cin>>a[A++];);
	for(;i<29;ans|=cnt<<i++)
	{
		m=1<<i+1;
		for(cnt=j=0;j<n;j++)B[j]=a[j+n]%m;
		sort(B,B+n);
		for(j=0;j<n;j++)
		{
			A=a[j]%(m/2);
			L=lower_bound(B,B+n,m-A)-lower_bound(B,B+n,m/2-A);
			(cnt+=a[j]&m/2?n-L:L)&=1;
		}
	}
	cout<<ans<<endl;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

// void Main() {
//     ll N; cin >> N;
//     string S; cin >> S;
//     // NC3だと間に合わない
//     // setにひたすら放り込む？

//     set<string> cands;
//     set<string> fixed;

//     cands.insert("");
//     rep(i, N){
//         set<string> new_cands = cands; // 入れないパターンは変わらないのでコピー
//         for (auto a: cands){
//             // 入れるパターン
//             string tmp = a + S[i];
//             if (a.size() == 2 && fixed.find(tmp) == fixed.end()){fixed.insert(a + S[i]);}
//             if (a.size() <= 1 && new_cands.find(tmp) == new_cands.end()){
//                 new_cands.insert(a + S[i]);
//             }
//         }
//         x = new_x;
//     }
//     ll cnt = 0;
//     cout << fixed.size() << endl;
// }

void Main() {
    ll N; cin >> N;
    string S; cin >> S;
    ll cnt = 0;
    rep(i, 10){rep(j, 10){rep(k, 10){
        vector<ll> inds = {i, j, k};
        ll cur_ind = 0;
        rep(n, N){
            if ((S[n] - '0') == inds[cur_ind]){cur_ind++;}
            if (cur_ind == 3){cnt++; break;}
        }
    }}}
    cout << cnt << endl;
}

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


Measured memory_bytes: 3720
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}
macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let a: i64 = sc.cin();
    let b: i64 = sc.cin();
    let c: i64 = sc.cin();
    let x: i64 = sc.cin();
    let y: i64 = sc.cin();

    let mut ans = a * x + b * y;
    for d in 0..200000 {
        ans = min!(ans,
            c * 2 * d + max!(0, x - d) * a + max!(0, y - d) * b
        );
    }

    put!(ans);
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> { self.cin::<String>().chars().collect() }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> { (0..n).map(|_| self.cin()).collect() }
}


Measured memory_bytes: 4352
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

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

    struct Work {
        ll A, B;
    };
    vector<Work> works(N);
    for (ll i = 0; i < N; i++) {
        cin >> works[i].A >> works[i].B;
    }
    sort(works.begin(), works.end(), [](Work& lhs, Work& rhs) {
        return lhs.A < rhs.A;
    });
    works.push_back({ M + 1, -1 });

    ll ans = 0;
    ll index = 0;
    priority_queue<ll> pq;
    for (ll i = 1; i <= M; i++) {
        //報酬の遅延がi日以内であるものをpqに追加
        while (works[index].A <= i) {
            pq.push(works[index++].B);
        }

        if (!pq.empty()) {
            ans += pq.top();
            pq.pop();
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 4708
X, N = map(int, input().split())
if not N:
    print(X)
    exit()
p = list(map(int, input().split()))
if X not in p:
    print(X)
    exit()
    
p_low = sorted([X - i for i in p if i < X])
p_high = sorted([i - X for i in p if i > X])

if len(p_low) > len(p_high):
    lng = len(p_low)
else:
    lng = len(p_high)

for i in range(1, lng + 2):
    if i not in p_low:
        print(X - i)
        exit()
    elif i not in p_high:
        print(X + i)
        exit()

Measured memory_bytes: 9228
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int n,m,_time,_end,f[maxn];
long long ans;
struct Node{
    int a,b;
    bool operator<(const Node & p){
        if(b==p.b) return a<p.a;
        return b>p.b;
    }
}e[maxn];
int find(int x) { return (f[x]==x?x:f[x]=find(f[x])); }
int main()
{
        cin>>n>>m; m++;
        for(int i=1;i<=n;i++)
            cin>>e[i].a>>e[i].b;
        sort(e+1,e+n+1);
        for(int i=1;i<=m;i++)
            f[i]=i;
        for(int i=1;i<=n;i++)
        {
            if(m-e[i].a<0)continue;
            int fa=find(m-e[i].a);
            if(fa!=0)
            {
                ans+=e[i].b;
                f[fa]=find(fa-1);
            }
        }
        cout<<ans<<endl;
        return 0;
}


Measured memory_bytes: 1408
import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) {
 
        Scanner scan = new Scanner(System.in);
 
        while (true) {
 
            int x = scan.nextInt();
            int y = scan.nextInt();
            if ((x == 0) && (y == 0)) {
                break;
            } else {
                if (x < y) {
                    System.out.println(x + " " + y);
                } else if (x > y) {
                    System.out.println(y + " " + x);
                } else {
                    System.out.println(x + " " + y);
                }
            }
        }
    }
}

Measured memory_bytes: 35396
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<iomanip>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
  int main(){
  int a, b;
  cin >> a >> b;
  int c[3];
    c[0] = a + b;
    c[1] = a - b;
    c[2] = a * b;
    sort(c, c + 3);
    cout << c[2];
  }
    
  


Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <typeinfo>

using namespace std;

int main(){
  string S;
  cin >> S;

  int count=0;
  bool flag;
  if(S.at(0)=='W')  flag=true;
  else if(S.at(0)=='B') flag=false;
  
  for(int i=0;i<S.size();i++){
    if(flag){
      if(S.at(i)=='W')  continue;
      count++;
      flag=false;
    }
    else if(!flag){
      if(S.at(i)=='B')  continue;
      count++;
      flag=true;
    }
  }
  cout << count << endl;

  return 0;
}


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

int main() {
    int A, B;
    cin >> A >> B;
    if (abs(A - B) % 2 == 0)
    {
        cout << min(A, B) + abs(A - B) / 2 << endl;
    } else
    {
        cout << "IMPOSSIBLE" << endl;
    }
    
    

  return 0;
}


Measured memory_bytes: 256
nm =gets.split.map { |e|e.to_i  }
array=[]
nm[1].times do
  road=  gets.split.map { |e|e.to_i  }
  array.push(road[0])
  array.push(road[1])
end
x =1
while x <= nm[0] do
puts array.count(x)
x = x +1
end


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

int linear_search(int ar[], int n, int key)
{
    int i=0;
    ar[n] = key;
    while (ar[i] != key) i++;
    return i != n;
}

int main()
{
    int n, q, sum=0, A[10000+1], key;

    scanf("%d", &n);
    for (int i=0; i<n; ++i) scanf("%d", &A[i]);

    scanf("%d", &q);
    for (int i=0; i<q; ++i) {
        scanf("%d", &key);
        if ( linear_search(A, n, key) ) sum++;
    }
    printf("%d\n", sum);

    return 0;
}



Measured memory_bytes: 3224
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

using ll = long long;

constexpr int MAX_N = 200000;

ll N, K;
ll a[MAX_N], S[MAX_N+10], b[MAX_N];
std::vector<ll> ids;
std::map<ll, ll> m;

ll bit[MAX_N+10];

void add( ll k, ll x )
{
  while( k <= N )
  {
    bit[k] += x;
    k += k & -k;
  }

  return;
}

ll sum( ll k )
{
  ll ret = 0;

  while( k > 0 )
  {
    ret += bit[k];
    k -= k & -k;
  }

  return ret;
}

int main()
{
  scanf( "%lld%lld", &N, &K );
  rep( i, N )
    scanf( "%lld", a+i ), a[i] -= K;

  S[0] = a[0];

  rep( i, N-1 )
    S[i+1] = S[i]+a[i+1];

  rep( i, N )  
    ids.push_back( S[i] );

  std::sort( all(ids) );

  rep( i, N ) if( !i || ids[i-1] != ids[i] )
    m[ids[i]] = i+1;
  rep( i, N )
    b[i] = m[S[i]];

  ll ans = 0;
  rep( i, N )
  {
    ans += sum( b[i] )+(S[i]>=0);
    add( b[i], 1 );
  }

  printf( "%lld\n", ans );

  return 0;
}

Measured memory_bytes: 20592
#include <iostream>
using namespace std;
 
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
 
	int n, d;
	cin >> n >> d;
	
	int num = 1 + 2 * d;
	int ans = n / num;
	if (n % num != 0)ans++;
 
	cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define faster cin.tie(0);ios_base::sync_with_stdio(0)
#define ll long long

int n,k;
ll arr[3004];


// fun(i,j)=arr[i]+fun(i+1,j),arr[j]+fun(i,j-1);

ll dp[3004][3004];

ll find(int i,int j)
{
	if(i>j) return 0;

	
	
	if(dp[i][j]!=-1) return dp[i][j];
	
	// player 1 picks left
	ll cost1=arr[i]+min(find(i+1,j-1),find(i+2,j));

	// player 2 picks right
	ll cost2=arr[j]+min(find(i+1,j-1),find(i,j-2));

	return dp[i][j]=max(cost1,cost2);
	
}

int main()
{
	memset(dp,-1,sizeof(dp));
	int n;cin>>n;
	ll sum=0;
	for(int i=0;i<n;i++) 
	{
		cin>>arr[i];
		sum+=arr[i];
	}
	// cout<<sum<<endl;
	ll x=find(0,n-1);
	ll y=sum-x;
	cout<<(x-y)<<endl;
	
}
	


Measured memory_bytes: 70912
def num_to_str(n):
    return chr(97 + n)

def str_to_num(s):
    return ord(s) - 97

def dfs(s,m,n,N,ans):
    if n == N:
        ans.append(s)
        return
    for i in range(m+2):
        dfs(s+num_to_str(i),max(m,i),n+1,N,ans)

def main():
    N = int(input())
    ans = []
    dfs('a',0,1,N,ans)
    ans.sort()
    for a in ans:
        print(a)


if __name__ == "__main__":
    main()


Measured memory_bytes: 59228
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define PI 3.14159265359
typedef long long LL;

template<class T> inline void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> void print_vector(vector<T> vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	cout << "]" << endl;
}
template<class T> void print_pair_vector(vector<pair<T, T> > vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << "(" << vec[i].first << "," << vec[i].second << ") ";
	}
	cout << "]" << endl;
}

int main(void) {
	string O, E;
	cin >> O >> E;

	if ((O.size()+E.size())%2 == 0) {
		for (int i = 0; i < O.size(); i++) {
			cout << O[i] << E[i];
		}
	}
	else {
		for (int i = 0; i < E.size(); i++) {
			cout << O[i] << E[i];
		}
		cout << O[E.size()];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <queue>
#include<iomanip>
#include <cmath>

#define ABS(x) ((x)>0?(x):-(x))
#define MIN(x,y) ((x)>(y)?(y):(x))

using namespace std;
unsigned long long int newton(long long int a, long long int  b)
{
	if(a==b)
		return a;
	while(a != 0 && b != 0)
	{
		if(a > b)
		{
			b += a;
			a = b-a;
			b -= a;
		}
		b %= a;
	}
	return a;
}

struct UnionFind {
	vector<int> p;
	UnionFind(int N):p(N)
	{
		for(int i=0; i< N; i++)
		{
			p[i] = i;
		}
	}
	int root(int x)
	{
		if(p[x] == x)
			return x;
		return p[x] = root(p[x]);
	}
	void unite(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		if(rx == ry) return;
		p[rx] = ry;
	}
	bool issame(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

int main()
{
	int N;
	int u,v,w;
	int mp[100010] = {0};
	queue<pair<int, int> > q;
	cin >> N;
	vector<int> p0[100010];
	vector<int> p1[100010];
	for(int i =0; i < N-1; ++i)
	{
		cin >> u >> v >> w;
		w &= 1;
		if(w)
		{
			p1[u].push_back(v);
			p1[v].push_back(u);
		}
		else
		{
			p0[u].push_back(v);
			p0[v].push_back(u);
		}
	}
	int i,j,f;
	j = 1;
	for(i=0;i<p0[j].size();++i)
	{
		q.push(make_pair(j, p0[j][i]));
		mp[p0[j][i]] = mp[j];
	}
	for(i=0;i<p1[j].size();++i)
	{
		q.push(make_pair(j, p1[j][i]));
		mp[p1[j][i]] = (mp[j]+1)&1;
	}
	while(!q.empty())
	{
		f = q.front().first;
		j = q.front().second;
		q.pop();
		for(i=0;i<p0[j].size();++i)
		{
			if(p0[j][i] == f)
				continue;
			q.push(make_pair(j, p0[j][i]));
			mp[p0[j][i]] = mp[j];
		}
		for(i=0;i<p1[j].size();++i)
		{
			if(p1[j][i] == f)
				continue;
			q.push(make_pair(j, p1[j][i]));
			mp[p1[j][i]] = (mp[j]+1)&1;
		}
	}
	for(i=1;i<=N;++i)
	{
		cout << mp[i] << endl;
	}
	return 0;
}









Measured memory_bytes: 9856
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define uniq(x) (x).erase(unique(ALL(x)),(x).end())
#define SORT(x) sort(ALL(x))
#define REV(x) reverse(ALL(x))
#define foreach(it,x) for(__typeof((x).begin()) it=(x).begin();it!=(x).end();it++)
#define debug(x) cerr<<#x<<"="<<(x)<<endl
#define gett() cerr<<"Time:"<<clock()<<"ms."<<endl
int n,m;
vector<int> heng[2200],zong[2200];
string s[2200];
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>m;
	for(int i=0;i<n;i++)
		cin>>s[i];
	for(int i=0;i<n;i++)
		heng[i].push_back(-1);
	for(int i=0;i<m;i++)
		zong[i].push_back(-1);
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(s[i][j]=='#'){
				heng[i].push_back(j);
				zong[j].push_back(i);
			}
		}
	}
	for(int i=0;i<n;i++)
		heng[i].push_back(m);
	for(int i=0;i<m;i++)
		zong[i].push_back(n);
	int res=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(s[i][j]=='#')
				continue;
			int ri=upper_bound(heng[i].begin(),heng[i].end(),j)-heng[i].begin();
			int dn=upper_bound(zong[j].begin(),zong[j].end(),i)-zong[j].begin();
			res=max(res,heng[i][ri]-heng[i][ri-1]+zong[j][dn]-zong[j][dn-1]-3);
		}
	}
	cout<<res<<endl; 
	return 0;
}


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


int main() {
    ll n, d;
    cin >> n >> d;
    d = d * d;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        ll a, b;
        cin >> a >> b;
        if (a * a + b * b <= d) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
bool rec(int n, int sum, int m, int max_n, array<int, 25> &a) {
    if(n == max_n) return sum == m;
    if(sum > m) return false;
    return rec(n + 1, sum, m, max_n, a) || rec(n + 1, sum + a[n], m, max_n, a);
}

int main(){
    int n, m_n, m;
    cin >> n;
    array<int, 25> a;
    for(int i = 0; i < n; i++) cin >> a[i];
    cin >> m_n;
    for (int p = 0; p < m_n; p++) {
        cin >> m;
        cout << (rec(0, 0, m, n, a) ? "yes" : "no") << endl;
    }
}


Measured memory_bytes: 3092
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

int main(){
   int n;
   cin >> n;
   for (int i = 1;i <= 9;i++){
      for (int j = 1; j <= 9;j++){
         if (i*j == n){
            cout << "Yes" << endl;
            return 0;
         }  
      }
   }
   cout << "No" << endl;


  
  return 0;
}


Measured memory_bytes: 3596
from collections import deque
H, W = map(int, input().split())
grid = [list(input()) for i in range(H)]
flag = [[-1 for i in range(W)] for j in range(H)]
whites = sum(grid[i].count('.') for i in range(H))
#BFS
q = deque()
q.append([0,0])
flag[0][0] = 0
dx = [1, -1, 0, 0]
dy = [0, 0, 1, -1]
while q:
    v = q.popleft()
    for j in range(4):
        if 0 <= v[0] + dx[j] < H and 0 <= v[1] + dy[j] < W and grid[v[0]+dx[j]][v[1]+dy[j]] == '.' and flag[v[0]+dx[j]][v[1]+dy[j]] == -1:
            flag[v[0]+dx[j]][v[1]+dy[j]] = flag[v[0]][v[1]] + 1
            q.append([v[0]+dx[j], v[1]+dy[j]])
if flag[H-1][W-1] == -1:
    print(-1)
else:
    print(whites - flag[H-1][W-1] - 1)


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

using namespace std;
#define ll long long
#define ld long double
#define rep(i,h) for(int i = 0; i < h; ++i)
#define rep1(i,h) for(int i = 0; i <= h; ++i)
#define rep2(i,k,h) for(int i = k; i < h; ++i)
#define rep3(i,k,h) for(int i = k; i <= h; ++i)
#define INF LLong_MAX // long long INF
#define inf INT_MAX // int inf

typedef pair<int,int> int_pair;
typedef pair<string,string> string_pair;

int main(){
    string s;
    cin >> s;
    string k;
    int n =s.length();
    rep(i,n) {
        k += "x";
    }
    cout << k ;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
	string s[3];
	while(cin >> s[0] , s[0] != "0"){
		cin >> s[1] >> s[2];
		rep(j,3){
			int a[2] ={0};
			rep(i,s[j].size()-1){
				a[s[j][i+1]!='A']++;
			}
			cout << a[0] + (a[0]>a[1]) << " " << a[1] + (a[1]>a[0]) << endl;
		}
	}
}

Measured memory_bytes: 0
#!/usr/bin/env python3
n = int(input())
x_l = [0]*n
x_plus_l = [0]*n
# 左端から貪欲に埋めることができる
# 証明：f(x)をx以降に最大で残せる数とすると、現時点の可動域の右端をXとして　Xi<Xj の時、f(xi) >= f(xj)がそれまでの選び方によらず成り立つから
# つまり、X< xi-liとなるiの中でxi+liがminを選べば良い
# xi+Liでソートして毎回2分探索するとO(nlogn)で終わる => xi-liはソートされてないので2分探索できない
# xi-liでソートして、X以上の要素に対して、順番に X = max(X,xi+li)として更新し、
# X > Xi-Li になったらcnt += 1 し、その時点でXは確定する、と言うように尺取的なことをすると、
# ロボットを通過するのは各ロボットに対し、一度しかないのでO(n)でいける
# 変数：X,cnt
for i in range(n):
    x,l = map(int,input().split())
    x_l[i] = x-l
    x_plus_l[i] = x+l
x_l,x_plus_l = zip(*sorted(zip(x_l,x_plus_l)))
cnt = 1# 初期点は左端
i = 1#0から順番に見て行く
X = min(x_plus_l)#初期化 はx+l のmin
#print(X,x_l,x_plus_l)
#最初だけ 右端がminになる点をとるので x_l[i] >= Xになるように初期の調整をする
while i < n:# nになったら全点を探索しているので終了
    if x_l[i] >= X:
        cnt += 1
        X = x_plus_l[i]
        #print(i,cnt)
    else:
        if cnt != 1:
            X = min(X,x_plus_l[i])
    i += 1
print(cnt)

Measured memory_bytes: 64600
#include<stdio.h>
#define INF (1<<25)
#define minn(x,y) ((x)<(y)?(x):(y))

int main(){
  while(1){
    int n, k, i, j, l;
    scanf("%d %d", &n, &k);
    if(n == 0 && k == 0){
      return 0;
    }
    int dist[n][n];
    for(i = 0;i < n;i++){
      for(j = 0;j < n;j++){
	if(i == j){
	  dist[i][j] = 0;
	}
	else{
	  dist[i][j] = INF;
	}
      }
    }
    
    for(i = 0;i < k;i++){
      int mode;
      scanf("%d", &mode);
      if(mode == 0){
	int a, b;
	scanf("%d%d", &a, &b);
	a--;b--;
	if(dist[a][b] == INF){
	  printf("-1\n");
	}
	else{
	  printf("%d\n", dist[a][b]);
	}
      }
      else{
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);
	a--;b--;
	dist[a][b] = minn(dist[a][b], c);
	dist[b][a] = dist[a][b];
	for(j = 0;j < n;j++){
	  for(l = 0;l < n;l++){
	    dist[j][l] = minn(dist[j][l], dist[j][a] + dist[b][l] + c);
	    dist[l][j] = dist[j][l];
	  }
	}
      }
    }
  }
}

Measured memory_bytes: 652
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int N;
int A[100010][4];
int dp[100010][4];
int call(int x, int y)
{
    if(x>N) return 0;
    if(dp[x][y]!=-1) return dp[x][y];
    
    if(y==1)
    {
        if(x<N)
        return dp[x][y]=A[x][y]+max(call(x+1,2), (call(x+1,3)));
        else
        return dp[x][y]=A[x][y];
    }
    else if(y==2)
    {
        if(x<N)
        return dp[x][y]=A[x][y]+max(call(x+1,1), (call(x+1,3)));
        else
        return dp[x][y]=A[x][y];
    }
    else
    {
        if(x<N)
        return dp[x][y]=A[x][y]+max(call(x+1,2), (call(x+1,1)));
        else
        return dp[x][y]=A[x][y];
    }
}
int main()
{
    cin>>N;
    for(int i=1;i<=N;i++)
    {
        cin>>A[i][1]>>A[i][2]>>A[i][3];
    }
    memset(dp,-1,sizeof(dp));
    cout<<max(call(1,1),max(call(1,2),call(1,3)));
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n), b;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(n % 2 == 0){
            if(i % 2 == 0){
                b.push_back(a[i]);
            }
            else{
                b.insert(b.begin(), a[i]);
            }
        }
        else{
            if(i % 2 == 0){
                b.insert(b.begin(), a[i]);
            }
            else{
                b.push_back(a[i]);
            }
        }
    }

    for(int i = 0; i < n; i++){
        cout << b[i] << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 3828
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
#include <numeric>
#include <math.h>
#include <set>

#define inf 1e15
#define sz 1e5
using ll = long long int;
using namespace std;

int main() {
int n;
cin>>n;
if (n==0)cout<<1<<endl;
else cout<<0<<endl;




    return 0;
}

Measured memory_bytes: 3568
import math
import queue
import bisect
import heapq
import time
import itertools

mod = int(1e9+7)

def swap(a,b):
    return (b,a)

def gcd(a,b): #最大公約数
    if (a<b):
        a,b = swap(a,b)
    if (b==0):
        return a
    else:
        return gcd(b,a%b)

def lcm(a,b): #最小公倍数
    return a/gcd(a,b)*b

def divisors(a): # 約数列挙
    divisors = []
    for i in range(1,int(a**0.5)+1):
        if a%i==0:
            divisors.append(i)
            if i!=a//i:
                divisors.append(a//i)
    return divisors

def is_prime(a): #素数判定
    if a<2:
        return False
    elif a==2:
        return True
    elif a%2==0:
        return False
    sqrt_num = int(a**0.5)
    for i in range(3,sqrt_num+1,2):
        if a%i==0:
            return False
    return True

def prime_num(a): #素数列挙
    pn = [2]
    for i in range(3,int(a**0.5),2):
        prime = True
        for j in pn:
            if i%j==0:
                prime = False
                break
        if prime:
            pn.append(i)
    return pn

def prime_fact(a): #素因数分解
    sqrt = math.sqrt(a)
    res = []
    i = 2
    if is_prime(a):
        res.append(a)
    else:
        while a!=1:
            while a%i==0:
                res.append(i)
                a //= i
            i += 1
    return res

def main():
    a,b = input().split()
    if a=='H' and b=='H':
        print('H')
    elif a=='H' and b=='D':
        print('D')
    elif a=='D' and b=='H':
        print('D')
    else:
        print('H')
    return

if __name__=='__main__':
    main()


Measured memory_bytes: 38636
# include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
template<typename T>vector<T> make_v(size_t a){ return vector<T>(a); }
template<typename T,typename... Ts>auto make_v(size_t a, Ts... ts){ return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template<typename T,typename V>typename enable_if<is_class<T>::value==0>::type fill_v(T &t, const V &v){ t = v; }
template<typename T,typename V>typename enable_if<is_class<T>::value!=0>::type fill_v(T &t, const V &v){ for(auto &e : t) fill_v(e, v); }
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

LL n;
LL ans;
set<LL>st;
int main(){
    cin >> n;
    for(LL i = 1;i*i <= n;i++){
        if((n - i)%i == 0 && i < (n - i)/i)st.insert((n - i)/i);
    }
    for(auto it = st.begin(); it != st.end();++it){
        ans += *it;
        //cout << *it << endl;
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
import sys
sys.setrecursionlimit(10000000)

nCr = {}
def cmb(n, r):
    if n == 1: return 0
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]


N=int(input())
a=list(map(int,input().split()))

L=[0]
s=0
for i in range(N):
    s+=a[i]
    L.append(s)

L=sorted(L)

s=0
t=L[0]
c=1
for i in range(1,len(L)):
    if(t==L[i]):
        c+=1
    else:
        s+=cmb(c,2)
        t=L[i]
        c=1
else:
    s+=cmb(c,2)
print(s)


Measured memory_bytes: 199756
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    x1, y1, x2, y2 = LI()
    d = max(abs(x1-x2), abs(y1-y2))
    dx = abs(x1-x2)
    dy = abs(y1-y2)
    if x1 < x2 and y1 <= y2:
        x3 = x2 - dy
        x4 = x1 - dy
        y3 = y2 + dx
        y4 = y1 + dx
    elif x1 < x2 and y1 > y2:
        x3 = x2 + dy
        x4 = x1 + dy
        y3 = y2 + dx
        y4 = y1 + dx
    elif x1 >= x2 and y1 < y2:
        x3 = x2 - dy
        x4 = x1 - dy
        y3 = y2 - dx
        y4 = y1 - dx
    else:
        x3 = x2 + dy
        x4 = x1 + dy
        y3 = y2 - dx
        y4 = y1 - dx
    print(x3, y3, x4, y4)



main()



Measured memory_bytes: 83528
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int T = sc.nextInt();
		int A = sc.nextInt();
		int H[]= new int[N];
		double Max = Integer.MAX_VALUE;
		int answer = 0;
		for(int i=0; i<N; i++) {
			H[i] = sc.nextInt(); //N個の標高の入力
			double ave = T - H[i] * 0.006; //平均気温
			if(Max>Math.abs(A-ave)) {
				Max = Math.abs(A-ave);
				answer = i+1;
			}
		}
		System.out.println(answer);
		
	}
}


Measured memory_bytes: 23380
def main() :
    N = int(input())
    H_list = [int(i) for i in input().split()]    

    max_step = 0
    current_step = 0

    prev_H = H_list[0]
    for i in range(1,N) :
        H = H_list[i]
        # print(prev_H,H)
        if (prev_H  >= H) :
            # print(True)
            current_step += 1
        else :
            if (max_step <= current_step) :
                max_step = current_step

            current_step = 0
        prev_H = H
        # print(H,current_step,max_step)

    if (max_step <= current_step) :
        max_step = current_step
    
    print(max_step)





main()


def gomi() :
    N = int(input())
    H_list = [int(i) for i in input().split()]

    # 単調減少区間の最大長を求めればよい -> どうやって？
    # 愚直に書いたら間に合わないはず
    max_downs = 0
    current_downs = 0
    prev_H = 999999999999999 
    for H in H_list :
        if (prev_H >= H ) :
            current_downs += 1
            prev_H = H
        else :
            if (current_downs > max_downs ) :
                max_downs = current_downs

            current_downs = 0
            prev_H = 999999999999999
        
        print(current_downs, max_downs)

    if (current_downs > max_downs ) :
        max_downs = current_downs

    # 着地を1で数えちゃったので引く
    print(max_downs-1)


Measured memory_bytes: 14480
#include <cstdio>
#include <cmath>

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define inc( i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec( i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

typedef long long   signed int LL;
typedef long long unsigned int LU;

template<typename T> void swap(T &x, T &y) { T t = x; x = y; y = t; return; }
template<typename T> T abs(T x) { return (0 <= x ? x : -x); }
template<typename T> T max(T a, T b) { return (b <= a ? a : b); }
template<typename T> T min(T a, T b) { return (a <= b ? a : b); }
template<typename T> bool setmin(T &a, T b) { if(a <= b) { return false; } else { a = b; return true; } }
template<typename T> bool setmax(T &a, T b) { if(b <= a) { return false; } else { a = b; return true; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n;
int p[20000];
int a[20000];
int b[20000];

int main() {
	scanf("%d", &n);
	inc(i, n) { scanf("%d", &p[i]); }
	
	inc(i, n) { a[i] = b[n - 1 - i] = (i + 1) * 30000; }
	incID(i, 1, n) { a[ p[i] - 1 ] += i; }
	
	inc(i, n) { printf("%s%d", i == 0 ? "" : " ", a[i]); } puts("\n");
	inc(i, n) { printf("%s%d", i == 0 ? "" : " ", b[i]); } puts("\n");
	
	return 0;
}


Measured memory_bytes: 768
# ALDS1_3_C: Doubly Linked List

class DoublyLinkedList
  include Enumerable

  def initialize
    @head = Node.new
    @head.next = @head.prev = @head
  end

  def insert(key)
    node = Node.new key
    @head.append node
    node
  end

  def delete(key)
    node = search_node key
    delete_node node
  end

  def deleteFirst
    delete_node @head.next
  end

  def deleteLast
    delete_node @head.prev
  end

  def each
    node = @head.next
    while node != @head
      yield node
      node = node.next
    end
  end

  def to_s
    inject('') do |s, node|
      s << ' ' << node.key.to_s
    end.strip
  end

  private
    def delete_node(node)
      node.disappear unless node.nil?
    end

    def search_node(key)
      find do |node|
        node.key == key && node != @head
      end
    end

    class Node
      attr_accessor :key, :next, :prev

      def initialize(key = nil)
        @key  = key
        @next = @prev = nil
      end

      def append(another)
        another.next   = self.next
        self.next.prev = another
        self.next      = another
        another.prev   = self
      end

      def disappear
        self.prev.next = self.next
        self.next.prev = self.prev
        self
      end
    end
end

list = DoublyLinkedList.new
n_commands = gets.to_i

n_commands.times do
  input   = gets.chomp.split
  command = input.first
  args    = input.drop(1).map &:to_i
  list.send command, *args
end

puts list

Measured memory_bytes: 80824
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	int n,t=0,maxx=0;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(int i=0;i<n;i++)
	{
		if(a[i]>=maxx)
		t++;
		maxx=max(maxx,a[i]);
	}
	cout<<t<<endl;
	
 } 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pf printf
#define sc(x) scanf("%d",&x);
#define scs(x) scanf("%s",x);
#define scl(x) scanf("%lld",&x);
#define rep(i,s,e) for(int i=s; i<=e; ++i)
#define dep(i,s,e) for(int i=s; i>=e; --i)
typedef long long ll;
using namespace std;
const ll mod=998244353;
ll a[10005];
int main()
{
	ll n,s,count=0;
	scl(n);scl(s);
	rep(i,1,n){
		ll u;scl(u);a[0]=i;
		if(u<=s)dep(j,s-u,0)(a[j+u]+=a[j])%=mod;
		(count+=a[s]%mod*(n-i+1)%mod)%=mod;a[s]=0;
	}pf("%lld\n",count%mod);
}


Measured memory_bytes: 256