akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define REPD(i,a,b) for (int i=(a);i<(b);i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef set<int> si;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pi;
typedef queue<pi> qpi;
typedef pair<ll, ll> pll;
typedef queue<pll> qpll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const int mod = 1000000007;
const int INF = 1001001001;
// 小数点　<< fixed << setprecision(0) <<
// sort降順　sort(ALL(),greater<int>());
// 円周率　M_PI
// 文字判定　isupper islower
// 順列　do {} while(next_permutation(ALL(X)));
// 最大値　LLONG_MAX
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};
typedef struct edge se;
typedef vector<edge> ve;
unsigned euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
int main() {
  int n,k;
  cin >> n >> k;
  vi h(n);
  REP(i,n) cin >> h[i];
  ll ans=LLONG_MAX;
    REP(i,1<<n-1) {
      int c=0;
      ll temp=0;
      vi x;
      REP(j,n-1) {
        if((1&i>>j)==1) {
          c++;
          x.push_back(j+1);
        }
      }
      if(c<k-1) continue;
      int start=h[0];
      int l=0;
      REP1(j,n-1) {
        if(start>=h[j]&&x[l]==j) {
          start++;
          temp+=start-h[j];
          l++;
        } else if(start<h[j]) {
          if(x[l]==j) l++;
          start=h[j];
        }
      }
      ans=min(temp,ans);
    }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
int main(){
    int a,b,c,x,ans=0;
    scanf("%d%d%d%d",&a,&b,&c,&x);
    for(int i=0;i<=a&&500*i<=x;i++){
        for(int j=0;j<=b&&500*i+100*j<=x;j++){
            if(x-500*i-100*j<=50*c)ans++;
        }
    }
    printf("%d",ans);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 
#define dump(x)  cout << #x << " = " << (x) << endl;
typedef long long lint;
using namespace std;
int main(){
	int ans=0;
	string s;
	cin>>s;
	rep(i,4){
		if(s.at(i)=='+')ans++;
		else ans--;
	}
	cout<<ans<<endl;
}

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

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


int main()
{
    ll n;
    cin>>n;
    vector<ll> a(n);
    for (int i = 0; i < n; i++)
    {
        cin>>a[i];
    }
    ll sum = 0;
    for (int i = 0; i < n; i++)
    {
        sum += a[i];
    }
    sum/=2;
    ll no1 = sum;
    for (int i = 1; i < n; i+=2)
    {
        no1 -= a[i];
    }
    vector<ll> ans(n);
    ans[0]=no1*2;
    for (int i = 1; i < n; i++)
    {
        no1 = a[i-1]-no1;
        ans[i]=no1*2;
    }
    for (int i = 0; i < n; i++)
    {
        if(i>0) cout<<" ";
        cout<<ans[i];
    }
    cout<<endl;

    return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;

int main() {
  vector<int> x(5);
  rep(i, 5) cin >> x[i];
  int k;
  cin >> k;
  if (x[4]-x[0] <= k) cout << "Yay!" << endl;
  else cout << ":(" << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
using ll = long long;
using ull = unsigned long long;

int main(){
	int N;
	scanf("%d", &N);
	ll A[N+1], deeper_than = 0;
	for (int i = 0; i <= N; ++i){
		scanf("%lld", A + i);
		deeper_than += A[i];
	}
	if(A[0] > 1){
		printf("-1\n");
		return 0;
	}
	if(A[0]){
		if(N){
			printf("-1\n");
			return 0;
		}
		printf("1\n");
		return 0;
	}
	//A[0] = 0
	ll nodes_depth[N+1], answer = 1;
	nodes_depth[0] = 1;
	for (int i = 1; i < N; ++i){
		nodes_depth[i] = min(2*(nodes_depth[i-1] - A[i-1]), deeper_than);
		if(nodes_depth[i] < 0){
			printf("-1\n");
			return 0;
		}
		deeper_than -= A[i];
		answer += nodes_depth[i];
	}
	if(A[N] > 2*(nodes_depth[N-1] - A[N-1])){
		printf("-1\n");
		return 0;
	}
	answer += A[N];
	printf("%lld\n", answer);
	return 0;
}

Measured memory_bytes: 3288
/* ALDS1_9_C: PriorityQueue */
/* 20181129 AOJ */

#define _CRT_SECURE_NO_WARNINGS
#define N 2000001
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void insert(int *priorityQueue, int key);
int extract(int *priorityQueue);
void maxHeapify(int *priorityQueue, int i);
void swap(int *x, int * y);

int id;

int main( )
{
	int  i, key;
	char cmd[8];
	int *priorityQueue = (int *)malloc(sizeof(int) * N);

	id = 0;
	while(1)
	{
		scanf("%s", cmd);
		if(strcmp(cmd, "insert") == 0)
		{
			scanf("%d", &key);
			insert(priorityQueue, key);
		}
		else if (strcmp(cmd, "extract") == 0)
		{
			printf("%d\n", extract(priorityQueue));
		}else
		{
			break;
		}
	}

	return 0;
}

void insert(int *priorityQueue, int key)
{
	int i, parent;

	priorityQueue[++id] = key;
	
	i = id;
	while(i > 1)
	{
		parent = i / 2;
		if (priorityQueue[i] > priorityQueue[parent])
		{
			swap(priorityQueue + i, priorityQueue + parent);
			i = parent;
		} 
		else
		{
			break;
		}	
	}
}

int extract(int *priorityQueue) {
	int ret, i;

	ret =  priorityQueue[1];
	priorityQueue[1] = priorityQueue[id--];
	maxHeapify(priorityQueue, 1);

	return ret;
}

void maxHeapify(int *heap, int i) {
	int left, right, maxId;
	
	left = 2 * i;
	right = left + 1;
	if(left <= id && heap[left] > heap[i])
	{
		maxId = left;
	}
	else
	{
		maxId = i;
	}

	if(right <= id && heap[right] > heap[maxId])
	{
		maxId = right;
	}

	if(maxId != i)
	{
		swap(heap + i, heap + maxId);
		maxHeapify(heap, maxId);
	}
}

void swap(int *x, int * y)
{
	int temp = *x;
	*x = *y;
	*y = temp;
}


Measured memory_bytes: 5636
require 'pp'
# IS_DEBUG = true
IS_DEBUG = false
def dputs str
	if(IS_DEBUG)
		puts str
	end
end
def dpp str
	if(IS_DEBUG)
		pp str
	end
end

require 'pp'

N,d=gets.chomp.split(' ').map{|n| n.to_i}
A = Array.new(N)
A=gets.chomp.split(' ').map{|n| n.to_i}.sort

#(N-1).downto(0){|d|
d = N-1
	s = A[d]
	#0 1 2 3 -> 1, 2
	#0 1 2 3 4 -> 2, 2
	t_best_l = s/2
	t_best_h = s/2+(s%2)
	t = nil
	t_diff = nil
	(N-2).downto(0){|e|
		t2 = A[e]
		diff = (t2 >= t_best_h ? t2 - t_best_h : t_best_l - t2)
		if(t.nil? || t_diff > diff)
			t = t2
			t_diff = diff
		end
	}
#}

puts "#{s} #{t}"


Measured memory_bytes: 12124
import bisect
cost = 0
t = raw_input()
W, H = map(int, t.split(' '))
p, q = [], []
sum_p = []
for i in xrange(W):
    tmp = int(raw_input())
    p.append((i, tmp))
p.sort(key=lambda a: a[1])
pp = [each[1] for each in p]
for i in xrange(W):
    if not sum_p:
        sum_p.append(pp[i])
    else:
        sum_p.append(sum_p[-1]+pp[i])
cost += sum(pp)
for j in xrange(H):
    new = int(raw_input())
    cost += new
    minus = bisect.bisect_right(pp, new)
    cost += (W-minus) * new
    cost += sum_p[minus-1] if minus > 0 else 0

print cost

Measured memory_bytes: 19524
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define re(i,n) for(ll i=0;i<n;++i)
#define ocut cout
#define ouct cout
#define itn int
struct Union{
  vector<int> par;
  Union(int a){
  par=vector<int>(a,-1);
  }
  int find(int a){
    if(par[a]<0){
      return a;
    }
    else{
      return par[a]=find(par[a]);
    }
  }
  bool same(int a,int b){
    return (find(a)==find(b));
  }
  int size(int a){
    return -par[find(a)];
  }
  void unite(int a,int b){
    int c=find(a),d=find(b);
    if(c==d)
      return;
    if(size(c)<size(d)){
      swap(c,d);
    }
    par[c]+=par[d];
    par[d]=c;
  }
};
int main(void){
    int a[3][3];
    bool b[3][3];
    int n;
    re(i,3){
        re(j,3){
            cin >> a[i][j];
            b[i][j]=false;
        }
    }
    cin >> n;
    int bb[n];
    re(k,n){
        cin >> bb[k];
        re(i,3){
            re(j,3){
                if(a[i][j]==bb[k]){
                    b[i][j]=true;
                }
            }
        }
    }
    if((b[0][0]&&b[0][1]&&b[0][2])||(b[1][0]&&b[1][1]&&b[1][2])||(b[2][0]&&b[2][1]&&b[2][2])||(b[1][1]&&b[0][0]&&b[2][2])||(b[0][2]&&b[1][1]&&b[2][0])||(b[0][1]&&b[1][1]&&b[2][1])||(b[0][0]&&b[1][0]&&b[2][0])||(b[0][2]&&b[1][2]&&b[2][2]))cout << "Yes";
    else cout << "No";
}


Measured memory_bytes: 256
use std::io::Read;
use std::collections::HashMap;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

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

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();

    let mut map: HashMap<String, i64> = HashMap::new();
    for _i in 0..n {
        let s = iterator.next().unwrap();
        let sorted = sort(s);
        *map.entry(sorted).or_insert(0) += 1;
    }

    let ans: i64 = map.values()
        .map(|&x| {
            if x <= 1 {
                return 0;
            }
            x * (x - 1) / 2
        })
        .sum::<i64>();

    return format!("{}", ans);
}

fn sort(s: &str) -> String {
    let mut v = Vec::with_capacity(s.len());
    for c in s.chars() {
        v.push(c.to_string());
    }
    v.sort();
    v.join("")
}


Measured memory_bytes: 17680
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
vi dh = {0, 1, 0, -1};
vi dw = {1, 0, -1, 0};
int h = -1, w = -1;
ll l = -1;
vector<vector<bool>> maze;
vector<vector<vector<int>>> sel;
pair<P, ll> move(P now, int dir, ll res) {
  int nowh = now.first, noww = now.second;
  do {
    nowh += dh[dir];
    noww += dw[dir];
    res--;
  } while(0 <= nowh && nowh < h &&
        0 <= noww && noww < w &&
        res >= 0 && !maze[nowh][noww]);
  nowh -= dh[dir];
  noww -= dw[dir];
  res++;
  return {{nowh, noww}, res};
}
pair<P, int> solve(P now, int dir, ll res) {
  pair<P, ll> ans = {now, res};
  ll su = 0;
  while(sel[now.first][now.second][dir] == -1) {
    sel[now.first][now.second][dir] = su;
    ans = move(now, dir, res);
    su += res - ans.second;
    now = ans.first;
    res = ans.second;
    if(res == 0) return {now, dir};
    dir++; dir %= 4;
  }
  res %= (su - sel[now.first][now.second][dir]);
  sel[now.first][now.second][dir] = su;
  if(res == 0) {
    while(1) {
      int nowdir = (dir + 3) % 4;
      if(sel[now.first][now.second][dir] != sel[now.first][now.second][nowdir]) break;
      else dir = nowdir;
    }
    return {now, (dir + 3) % 4};
  }
  while(1) {
    ans = move(now, dir, res);
    now = ans.first;
    res = ans.second;
    if(res == 0) return {now, dir};
    dir++; dir %= 4;
  }
}
int main() {
  cin.tie(0);
  cout << fixed << setprecision(10);
  while(1) {
    cin >> h >> w >> l;
    if(h == 0 && w == 0 && l == 0) break;
    maze.clear();
    maze.resize(h, vector<bool>(w, 0));
    sel.clear();
    sel.resize(h, vector<vector<int>>(w, vector<int>(4, -1)));
    int sh = -1, sw = -1;
    int sdir = -1;
    for(int i=0;i<h;++i) {
      for(int j=0;j<w;++j) {
        char tmp; cin >> tmp;
        if(tmp == '#') maze[i][j] = true;
        else if(tmp != '.') {
          sh = i;
          sw = j;
          if(tmp == 'E') sdir = 0;
          else if(tmp == 'S') sdir = 1;
          else if(tmp == 'W') sdir = 2;
          else if(tmp == 'N') sdir = 3;
        }
      }
    }
    assert(0 <= sh && sh < h);
    assert(0 <= sw && sw < w);
    assert(0 <= sdir && sdir < 4);
    pair<P, int> ans = solve({sh, sw}, sdir, l);
    char ansdir;
    if(ans.second == 0) ansdir = 'E';
    else if(ans.second == 1) ansdir = 'S';
    else if(ans.second == 2) ansdir = 'W';
    else ansdir = 'N';
    cout << ans.first.first + 1 << " " << ans.first.second + 1 << " " << ansdir << endl;
  }
}



Measured memory_bytes: 3680
import java.util.*;

public class Main {
	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		while(true){
			int n = in.nextInt(), m = in.nextInt(), p = in.nextInt();
			if(n==0 && m==0 && p == 0) return ;
			int total = 0, num=1;
			for(int i=0; i<n; i++){
				int x = in.nextInt();
				if(i==m-1) num = x;
				total += x;
			}
			if(num==0)  System.out.println(0);
			else{
				System.out.println((int) ((double)100*total/num*(100-p)/100));
			}
		}
	}
}

Measured memory_bytes: 12000
#include <cstdio>
using namespace std;

inline int gcd(int a, int b) {while(b ^= a ^= b ^= a %= b); return a;}

int main(int argc, char** argv)
{
	int k, s = 0;
	scanf("%d", &k);
	k ++;
	for(int a=1; a<k; a++)
		for(int b=1; b<k; b++)
			for(int c=1; c<k; c++)
				s += gcd(gcd(a, b), c);
	printf("%d\n", s);
	return 0;
}

Measured memory_bytes: 1732
s = int(input())
cnt = 0
li = [s]
if s%2==0:
    s = s//2
else:
    s = 3*s+1
while True:
    if s not in li:
        if s%2==0:
            li.append(s)
            s = s//2
        else:
            li.append(s)
            s = 3*s+1
    else:
        break
print(len(li)+1)


Measured memory_bytes: 38384
#include <iostream>

#include <vector>

#include <cassert>

#include <algorithm>

#include <functional>

#include <cmath>

#include <iomanip>

#include <limits>
#include <bits/stdc++.h>
#include<queue>
#include<type_traits>
#include<cstdint>
using namespace std;
using ll=long long;
int main(){
    int n;
    cin >> n;
    vector<pair<ll,ll>> vec;
   for(int i=0;i<n;i++){
       int a,b;
       cin >> b >> a;
       vec.push_back(make_pair(a,b));
   }
   sort(vec.begin(),vec.end());
   bool hantei=1;
   ll time=0;
   for(int i=0;i<n;i++){
     //  cout <<vec[i].first<<vec[i].second<<endl;
     time += vec[i].second;
     
     if(time>vec[i].first){
         hantei=0;
         break;
     }
   }
   if(hantei){
       cout <<"Yes"<<endl;
   }else{
       cout <<"No"<<endl;
   }
   
}


Measured memory_bytes: 6384
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define max3(x, y, z) max(x, max(y, z))

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif
using namespace std;

int main() {
  int a=0;
  int b=0;
  int c=0;
  cin >> a >> b >> c;
  for (int i = b; i <= c; i++) {
    if (i % a == 0) {
      cout << "OK";
      return 0;
    }
  }
  cout << "NG";
  return 0;
}
/*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
for (int i = 0; i < N; i++) {
cin >> list[i];
}
// for文
for (int i = 0; i < N; i++) {
}
//配列
vector<int> list;
list.at(i)
vector<vector<int>> list(10, vector<int>(10));
sort(all(list));
sort(all(list), greater<int>());
//配列の内容表示
dout << "====listの内容====\n";
for (int i = 0; i < N; i++) dout << list[i] << endl;
dout << "====ここまで====\n";
*/


Measured memory_bytes: 3636
using System;

class quiz
{
    public double solve(int T, int X)
    {
        return (double)T / X;
    }

    public int[] ParseIntBySpace(string str)
    {
        int[] array = new int[str.Length];
        int lastloc = 0, spaceloc = -1;

        for (int i = 0; i < str.Length; i++)
        {
            if (str[i] == ' ')
            {
                array[lastloc++] = int.Parse(str.Substring(spaceloc + 1, i - spaceloc - 1));
                spaceloc = i;
            }
            else if (i == str.Length - 1)
            {
                array[lastloc++] = int.Parse(str.Substring(spaceloc + 1, i - spaceloc));
            }
        }

        Array.Resize(ref array, lastloc);

        return array;
    }
}

class Example
{
    static void Main()
    {
        quiz ex = new quiz();
        int[] XT;

        XT = ex.ParseIntBySpace(Console.ReadLine());

        Console.WriteLine(ex.solve(XT[0],XT[1]));
    }
}

Measured memory_bytes: 13140
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

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

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

int main() {
    ll a, b, c, d; cin >> a >> b >> c >> d;
    ll res_b = b - ((b/c) + (b/d) - (b/lcm(c, d)));
    ll res_a = a - 1 - (((a-1)/c) + ((a-1)/d) - ((a-1)/lcm(c, d)));
    cout << res_b - res_a << endl;
    return 0;
}

Measured memory_bytes: 3612
#include<iostream>
#include<string>
#include<vector>
#include<unordered_map>
#include<algorithm>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<cstdlib>
#include<queue>
#include<utility> //pair
using namespace std;

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

typedef long long ll;


int main() {
	//入力;
	ll n;
	cin >> n;
	vector<ll> a(n);
	REP(i, n) { cin >> a[i]; }

	ll counter = 1;
	ll kudaku = 0;

	REP(i, n) {
		if (a[i] == counter) {
			++counter;
		}
		else {
			++kudaku;			
		}
	}
	if (kudaku > 0 && counter == 1) cout << -1 << endl;
	else cout << kudaku << endl;
	//小数点以下の桁数表示;
	//cout << fixed << setprecision(15);

	return 0;
}

Measured memory_bytes: 1792
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using u64 = uint_fast64_t;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true;} return false; }
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true;} return false; }
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
void print() { cout << "\n"; }
template<class T, class... Args>
void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

using Tu = tuple<ll, ll, ll>;
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<ll> A(N),B(N);
    rep(i,N) cin >> A[i] >> B[i];

    vector<Tu> C(2*N);
    rep(i,N) {
        C[i*2] = Tu(A[i],i,0);
        C[i*2+1] = Tu(B[i],i,1);
    }
    sort(all(C));
    bool ok = false;
    vector<int> check(N,-1);
    int cnt = 0;
    ll val = 0;
    rep(i,N) {
        auto [x,y,z] = C[i];
        if (check[y] != -1) ok = true;
        val += x;
        check[y] = z;
        cnt += z;
    }
    if (cnt == 0 or cnt == N) ok = true;
    if (ok) {
        cout << val << ln;
        return 0;
    }
    ll ans = 1e18;
    chmin(ans,accumulate(all(A),0LL));
    chmin(ans,accumulate(all(B),0LL));
    multiset<ll> dic;
    rep(i,N) {
        if (check[i]) dic.emplace(A[i]);
        else dic.emplace(B[i]); 
    }
    rep(i,N) {
        if (check[i]) {
            ll b = A[i];
            auto it = dic.find(b);
            dic.erase(it);
            chmin(ans,val-B[i]+*dic.begin());
            dic.emplace(b);
        } else {
            ll b = B[i];
            auto it = dic.find(b);
            dic.erase(it);
            chmin(ans,val-A[i]+*dic.begin());
            dic.emplace(b);
        }
    }

    cout << ans << ln;
}



Measured memory_bytes: 14476
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    a, b, c = read_ints()
    if b-a == c-b:
        return 'YES'
    return 'NO'


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 61912
from itertools import product
import pprint

h, w, k = map(int, input().split())
c = [list(input()) for _ in range(h)]

ans = 0

for row_bit in product(range(2), repeat=h):
  for col_bit in product(range(2), repeat=w):
    cnt = 0
    for row in range(h):
      for col in range(w):
        if c[row][col] == "#" and (row_bit[row] and col_bit[col]):
          cnt += 1
    if cnt == k:
      ans+=1

print(ans)

Measured memory_bytes: 9884
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()

using namespace std;

void solve(int tc) {
    int n;
	cin>>n;
	vector<pair<ll, ll>> a(n);
	for(int i=0; i<n; ++i) {
		cin>>a[i].first;
		a[i].second = i;
	}
	sort(all(a));
    vector<vector<ll>> dp(n, vector<ll>(n, 0));
    for(int i=0; i<n; ++i)
        dp[i][i] = a[0].first * abs(a[0].second - i);
    for(int k=1; k<n; ++k) {
    	for(int i=0; i+k<n; ++i) {
            int j = i+k;
            dp[i][j] = max(dp[i+1][j] + abs(i - a[k].second) * a[k].first, 
                           dp[i][j-1] + abs(j - a[k].second) * a[k].first);
            // cout<<dp[i][j]<<" ";
        }
        // cout<<endl;
    }
    cout<<dp[0][n-1]<<endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    // cin>>t;
    for(int tc=1; tc<=t; ++tc) {
        solve(tc);
    }    
    return 0;
}

Measured memory_bytes: 34624
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	int a, b, c, d; cin >> a >> b >> c >> d;
	bool yes = false;
	rep(p, 0, N) {
		if (p*c + (N - 1 - p)*(-d) <= b - a&&b - a <= p*d + (N - 1 - p)*(-c))
			yes = true;
	}
	cout << (yes ? "YES" : "NO") << endl;
	return 0;
}

Measured memory_bytes: 256
# abc130_b.py
# https://atcoder.jp/contests/abc132/tasks/abc132_b

# B - Ordinary Number /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 200点

# 問題文
# {1, 2, ..., n} の順列 p = {p1, p2, ..., pn} があります。
# 以下の条件を満たすような pi(1<i<n) がいくつあるかを出力してください。
#     pi−1, pi, pi+1の 3 つの数の中で、pi が 2番目に小さい。

# 制約
#     入力は全て整数である。
#     3≤n≤20
#     pは {1, 2, ..., n} の順列である。

# 入力
# 入力は以下の形式で標準入力から与えられる。
# n
# p1 p2 ... pn

# 出力
# 条件を満たす piの個数を出力せよ。

# 入力例 1
# 5
# 1 3 5 4 2

# 出力例 1
# 2

# p1=1, p2=3, p3=5の中で、p2=3 は 2 番目に小さい数です。
# また、p3=5, p4=4, p5=2 の中で、p4=4 は 2 番目に小さい数です。条件を満たす要素はこの 2つです。

# 入力例 2
# 9
# 9 6 3 2 5 8 7 4 1

# 出力例 2
# 5


global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    # FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    # S = lines[0]
    N = int(lines[0])
    # X, A = list(map(int, lines[0].split()))
    values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[2].split()))
    # values = list()
    # for i in range(6):
    #     values.append(int(lines[i]))
    # valueses = list()
    # for i in range(M):
    #     valueses.append(list(map(int, lines[i+1].split())))

    result = 0

    for i in range(N-2):
        tmp = values[i:i+3]
        tmp.sort()
        log(f'i=[{i}]')
        if tmp[1] == values[i+1]:
            result += 1

    return [result]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['5', '1 3 5 4 2']
        lines_export = [2]
    if pattern == 2:
        lines_input = ['9', '9 6 3 2 5 8 7 4 1']
        lines_export = [5]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(2)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()


Measured memory_bytes: 9116
#include <bits/stdc++.h>
using namespace std;
// (setq-default c-basic-offset 2)

int main() {
  int n;
  cin >> n;
  vector<long long> h(n);
  for (long long& hi : h) {
    cin >> hi;
  }

  vector<long long> dp(n, INT_MAX);
  dp[0] = 0;

  for (int i = 0; i < n; ++i) {
    for (int j : {i + 1, i + 2}) {
      if (j < n) {
        long long cost = abs(h[i] - h[j]);
        dp[j] = min(dp[j], dp[i] + cost);
      }
    }
  }
  cout << dp.back() << endl;
  return 0;
}


Measured memory_bytes: 4764
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)
#define rrep(i, j, n) for (int i = (int)n - 1; j <= i; --i)

int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> s(h + 2, vector<char>(w + 2, '#'));
  rep(i, 1, h + 1) rep(j, 1, w + 1) cin >> s[i][j];
  rep(i, 0, h + 2) {
    rep(j, 0, w + 2) { cout << s[i][j]; }
    cout << '\n';
  }
  return 0;
}

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

constexpr int64_t MOD = (int64_t)1e9 + 7;
int64_t N;
vector<int64_t> memo;

int64_t MODpow(int64_t n, int64_t m) {
    int64_t result = 1;
    while (m) {
        if (m % 2 == 1) {
            result *= n;
            result %= MOD;
        }

        m /= 2;
        n *= n;
        n %= MOD;
    }

    return result;
}

int64_t num_of_gcd_equal_1(int64_t k) {
    if (memo[k] != -1) {
        return memo[k];
    }

    int64_t result = MODpow(k, N);

    for (int64_t i = 2; i <= k; i++) {
        (result += MOD - num_of_gcd_equal_1(k / i)) %= MOD;
    }

    return memo[k] = result;
}

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

    memo.resize(K + 1, -1);

    int64_t ans = 0;
    for (int64_t k = 1; k <= K; k++) {
        (ans += k * num_of_gcd_equal_1(K / k)) %= MOD;
    }

    cout << ans << endl;
}

Measured memory_bytes: 4028
#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#include <cmath>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <utility>
#include <set>
#include <bitset>
typedef long long ll;
typedef long double ld;

#define REP(i,s,n)for(ll i=s;i<(n);++i)
#define rep(i,n) REP(i,0,n)
using namespace std;

int main() {
    ll N;
    ll a[100010];
    int zero = 0;
    ll prod = 1;
    ll max =1000000000000000000;
    cin >> N;
    rep(i,N) {
        cin >> a[i];
    }
    rep(i,N) if (a[i] == 0)zero++;
    if (0<zero) {
        cout << 0 << endl;
        return 0;
    }
    rep(i, N) {
        if (a[i] <= max / prod) {
            prod *= a[i];
        }
        else {
            cout << -1 << endl;
            return 0;
        }
    }

    cout << prod << endl;
    return 0;
}

Measured memory_bytes: 4356
package main

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

func newScanner() *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	return scanner
}

var sc = newScanner()

func scanInt() int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

func scanInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = scanInt()
	}
	return a
}

func scanString() string {
	if sc.Scan() {
		return sc.Text()
	}
	panic(sc.Err())
}

func main() {
	x := scanInt()
	rotation := 0
	count := 0
	for {
		rotation += x
		count++
		if rotation == 360 {
			break
		}
		if rotation > 360 {
			rotation -= 360
		}
	}
	fmt.Println(count)
}

func debug(a ...interface{}) {
	fmt.Println(a...)
}


Measured memory_bytes: 1768
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        for (int i = 0 ; i <= 1000000 ; i++) {
            if (i * 8 / 100 == a && i * 10 / 100 == b) {
                System.out.println(i);
                return;
            }
        }
        System.out.println(-1);
    }


}

Measured memory_bytes: 23764
#include<iostream>
#include<algorithm>

using namespace std;
#define int long long

signed main(){

   int N, C, K;
   cin>> N>> C>> K;
   int t[N];
   for(int i=0; i<N; i++) cin>> t[i];

   sort(t, t+N);
   int a=0, b=0, c=0;
   for(int i=0; i<N; i++){
      if(i==0){
         a=t[i];
         b++;
         c++;
      }else{
         if(t[i]<=a+K&&b+1<=C){
            b++;
         }else{
            a=t[i];
            b=1;
            c++;
         }
      }
   }

   cout<< c<< endl;

   return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main(){
  int n,d[100010][2],f,i;
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d %d",&d[i][0],&d[i][1]);
  f=0;
  for(i=2;i<n;i++){
    if(d[i-2][0]==d[i-2][1]&&d[i-1][0]==d[i-1][1]&&d[i][0]==d[i][1])f=1;
  }
  printf("%s\n",f?"Yes":"No");
  return 0;
}


Measured memory_bytes: 1652
import sys
input = sys.stdin.readline


def main():
    s = input()[:-1]
    t = input()[:-1]

    S = len(s)
    T = len(t)
    dp = [[0]*(T+1) for _ in range(S+1)]
    for i in range(S):
        for j in range(T):
            if s[i:i+1] == t[j:j+1]:
                dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + 1)
            dp[i+1][j+1] = max(dp[i+1][j+1], dp[i+1][j])
            dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j+1])
    
    ans = ""
    i = S
    j = T
    while i>0 and j>0:
        if dp[i][j] == dp[i-1][j]:
            i -= 1
        elif dp[i][j] == dp[i][j-1]:
            j -= 1
        else:
            ans = s[i-1:i] + ans
            i -= 1
            j -= 1
    
    # for i in range(S+1):
    #     print(dp[i])
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 114524
n = gets.chomp.to_i

if n % 2 == 0
  groups = (1..(n / 2)).map { |i| [i, n + 1 - i] }
else
  groups = (1..(n / 2)).map { |i| [i, n - i] }
  groups.push([n])
end

graphs = []
groups.combination(2) do |groupa, groupb|
  groupa.each { |i|  groupb.each { |j| graphs.push([i, j]) } }
end

n = graphs.length
puts n

graphs.each { |graph| puts(graph.join(' ')) }

Measured memory_bytes: 2300
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){

	long long int w, h, x, y;
	double ans;

	cin>> w >> h >> x >> y;

	ans=(w/2.0)*h;
	cout<< ans << endl;
	if(w==2*x && h==2*y) cout<< '1' << endl;
	else cout<< '0' << endl;


}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#define ll long long
#define F(i,a,b) for(int i=(a);i<=(b);i++)
#define mst(a,b) memset((a),(b),sizeof(a))
#define PII pair<int,int>
#define rep(i,x,y) for(auto i=(x);i<=(y);++i)
#define dep(i,x,y) for(auto i=(x);i>=(y);--i)
using namespace std;
template<class T>inline void rd(T &x) {
    x=0; int ch=getchar(),f=0;
    while(ch<'0'||ch>'9'){if (ch=='-') f=1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
    if(f)x=-x;
}
const int inf=0x3f3f3f3f;
int n;
queue<ll> q;
int main()
{
    cin>>n;
    rep(i,1,9) q.push(i);
    for(int i=1;i<=n-1;i++)
    {
        ll u=q.front();q.pop();
        if(u%10) q.push((u*10)+(u%10)-1);
        q.push((u*10)+u%10);
        if(u%10<9) q.push((u*10)+(u%10)+1);
    }
    cout<<q.front()<<endl;
    return 0;
}

Measured memory_bytes: 1792
S=input()

temp=0
for i in range(len(S)):
  if i%2==1:
    if S[i]=='0':
      temp+=1
  else:
    if S[i]=='1':
      temp+=1
#print(temp)
ans=len(S)-temp

temp=0
for i in range(len(S)):
  if i%2==0:
    if S[i]=='0':
      temp+=1
  else:
    if S[i]=='1':
      temp+=1
#print(temp)
ans=min(ans,len(S)-temp)

print(ans)

Measured memory_bytes: 3188
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<vector>

using namespace std;

int main() {
	int m, n;
	vector<string> str;
	string s;
	cin >> m >> n;
	for( int i=0; i<m; i++ ) {
		cin >> s;
		str.push_back(s);
	}
	for( int i=0; i<n+2; i++ ) {
		cout << "#";
	}
	cout << endl;
	for( int i=0; i<m; i++ ) {
		cout << "#" << str.at(i) << "#" << endl;
	}
	for( int i=0; i<n+2; i++ ) {
		cout << "#";
	}
	
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
    	int a = 0,b = 0,k;
    	Scanner in = new Scanner(System.in);
    	while(true){
    		int cnt = 0;
    		try{
    			a = in.nextInt();
    			b = in.nextInt();
    			k = a + b;
    		}
    		catch (Exception e){
    			System.exit(0);
    		}
    		k = a + b;
    		while(k > 0){
    			k = k / 10;
    			cnt = cnt + 1;
    		}
    		System.out.println(cnt);
    	}
    }
}

Measured memory_bytes: 20400
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N = INT()
A = LIST()

ans = 1
cnt = [0, 0, 0]
for i in range(N):
	ans = ans * cnt.count(A[i]) % mod
	if A[i] in cnt:
		cnt[cnt.index(A[i])] += 1
	else:
		print(0)
		exit()

print(ans)

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

using namespace std;

// 丁度a個のマッチを使い切るときの最大桁数
int solve(vector<int> &costs, int a, vector<int> &memo) {
  if (a <= 0) {
    return a == 0 ? 0 : -20000;
  }

  if (memo[a] == -1) {
    int ans = solve(costs, a - costs[0], memo) + 1;
    for (int i = 0; i < costs.size(); i++) {
      ans = max(ans, solve(costs, a - costs[i], memo) + 1);
    }

    memo[a] = ans;
  }

  return memo[a];
}

int main(int argc, const char *argv[]) {
  int n, m;
  cin >> n >> m;

  vector<int> all_costs{2, 5, 5, 4, 5, 6, 3, 7, 6};
  vector<int> va(m);
  for (int i = 0; i < m; ++i) {
    cin >> va[i];
  }

  sort(va.begin(), va.end(), greater<int>());

  vector<int> costs;
  for (auto a : va) {
    costs.push_back(all_costs[a - 1]);
  }

  vector<int> memo(n + 1, -1);

  // 最大でmax_d桁の整数が作れる！
  int max_d = solve(costs, n, memo);

  string ans;
  int r = n;
  for (int i = 1; i <= max_d; i++) {
    for (int j = 0; j < costs.size(); ++j) {
      if (r - costs[j] < 0) {
        continue;
      }

      int d = solve(costs, r - costs[j], memo);
      if (d == max_d - i) {
        ans += to_string(va[j]);
        r -= costs[j];
        break;
      }
    }
  }

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

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define maxn 500000
using namespace std;
int n;
int a[maxn];
int c[maxn];
int main() {
    scanf("%d",&n);
    long long tot=0;
    for(int i=0;i<n;i++) {
        scanf("%d",&a[i]);
        tot+=c[a[i]];
        c[a[i]]++;
    }
    for(int i=0;i<n;i++) {
        printf("%lld\n",tot-c[a[i]]+1);
    }
    return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) rep(i, x.size()) cerr << x[i] << (i == x.size() - 1 ? "\n" : " ")
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = ((1LL << 30) + (1LL << 29));
const int MOD = 1000000007;
const int FIVE = 101010;

//=============================
int N, M, K;
string S, T;
vector<int> A;
vector<int> B;
//=============================
void input()
{
    cin >> N;
}
//=============================
void func() {}
    priority_queue<int> que;
//=============================
void solve()
{
    // ぜんぶ
    int jj = (N+1)/2;
    rep(i, jj+1)
    {
        if (i == 0)
            continue;;
        int p = i;
        rep(j, 10)
        {
            p *= i;
            if (p <= N)
            {
                que.push(p);
            }
            else
            {
                break;
            }
        }
    }
    cout << que.top() << endl;
}
//=============================
signed main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 764
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        long a = sc.nextLong();
        long b = sc.nextLong();

        long tmp = 0;
        while ((tmp = a % b) != 0){
            a = b;
            b = tmp;
        }

//        System.out.println(b);

        long ans = 0;

//        boolean flag = false;

//        if (b%2==0) ans++;

        double sqrt = Math.sqrt(b);
//        long c = b;

        for (int i=2; i<=sqrt+1; i++){
            if (b%i==0){
                ans++;
                while (b%i==0){
                    b /= i;
                }
            }
        }

        if (b!=1){
            ans++;
        }



        System.out.println(ans+1);
    }
}




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

using namespace std;

using ll = long long;
using ld = long double;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()
#define sortAl(v) sort(all(v))
#define sortAlr(v)          \
  sort(v.begin(), v.end()); \
  reverse(v.begin(), v.end())

#define cout(n) cout << fixed << setprecision(n)

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T &a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T &a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
#define INF LLONG_MAX

ll dist2(vector<ll> &y, vector<ll> &z) {
  ll sum = 0;
  rep(i, y.size()) {
    sum += (y[i] - z[i]) * (y[i] - z[i]);
  }
  return sum;
}

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

  ll n, d;
  cin >> n >> d;

  vector<vector<ll>> x(n, vector<ll>(d));
  rep(i, n) {
    rep(j, d) {
      cin >> x[i][j];
    }
  }
  ll ans = 0;
  rep(y, n - 1) {
    FOR(z, y + 1, n) {
      double d = sqrt(dist2(x[y], x[z]));
      if (d == (ll)d) {
        ans++;
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
N,A,B,C,D = map(int,input().split())
S = list(input())

#C<Dのとき　AはBを抜かなくて良い
if C < D:
    if ''.join(S[A:C]).find('##') == -1 and ''.join(S[B:D]).find('##') == -1:
        print('Yes')
    else:
        print('No')
        
#C>Dのとき　AはBを抜かなければならない
else:
    if ''.join(S[A:C]).find('##') == -1 and ''.join(S[B:D]).find('##') == -1 and ''.join(S[B-2:D+1]).find('...') > -1:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 6388
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define mkp(a,b) make_pair(a,b)
const long long mod = 1000000007;
const long long inf = 1ll<<61;
typedef pair<int, int> P;
typedef pair<int ,P> PP;
struct edge { int to; int to2; int cost; };
int v[25], c[25];
signed main() {
	int a, b, t; cin >> a >> b >> t;
	cout << (t / a)*b << endl;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
g = [[] for _ in range(n)]
inv = [0] * n
for _ in range(n - 1 + m):
    a, b = map(int, input().split())
    g[a - 1].append(b - 1)
    inv[b - 1] += 1
for i in range(n):
    if inv[i] == 0:
        root = i
        break
d = [0] * n
s = [root]
while s:
    p = s.pop()
    for node in g[p]:
        inv[node] -= 1
        if inv[node] == 0:
            d[node] = max(d[node], d[p] + 1)
            s.append(node)
ans = [0] * n
for i in range(n):
    for node in g[i]:
        if d[node] == d[i] + 1:
            ans[node] = i + 1
for x in ans:
    print(x)


Measured memory_bytes: 70176
#!/usr/bin/python3

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def main():
    N = int(input())
    A = [0] + list(map(int, input().split())) + [0]

    total = 0
    for i in range(1, len(A)):
        total += abs(A[i - 1] - A[i])

    for i in range(1, len(A) - 1):
        a = abs(A[i - 1] - A[i]) + abs(A[i] - A[i + 1])
        b = abs(A[i - 1] - A[i + 1])
        print(total - a + b)


if __name__ == '__main__':
    main()


Measured memory_bytes: 14948
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <stack>
#include <map>
#include <queue>
#include <algorithm>

using namespace std;

typedef long long ll;

ll t[128];

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

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

int main()
{
//  for(int i=0;i<10;i++)
//    cout<<rand()%2048<<endl;
//  freopen("/Users/qianjay/Documents/cc/in", "r", stdin);
  int n;
  scanf("%d",&n);
  ll res=1;
  for(int i=0;i<n;i++)
  {
    scanf("%lld",&t[i]);
    res=gcm(res,t[i]);
  }
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>

#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

const ll MOD = 1000000007;
const long double EPS = 1e-10;
const int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

const ll BTC_TO_YEN = 380000;

int main() {
    string s;
    cin >> s;
    if(s <= "2019/04/30") {
        cout << "Heisei\n";
    } else {
        cout << "TBD\n";
    }
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main (){

    int n, data[200], cnt = 0, ans = 0;
    cin >> n;

    for(int i=0; i<n; i++)cin >> data[i];

    bool flag = 1;
    while(flag){
        cnt = 0;
        for(int i=0; i<n; i++)
            if(data[i]%2 == 0) cnt++;

        if(cnt == n){
            for(int i=0; i<n; i++) data[i] = data[i]/2;
            ans++;
        }
        else flag = 0;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 2147483647;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
const double pi = acos(-1);//3.1415926535897932384626433832795028...
const ll SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

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

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

double add(double a, double b) {
	if (abs(a + b) < EPS * (abs(a) + abs(b))) { return 0; }
	return a + b;
}

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

Measured memory_bytes: 256