akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace std;
#define ll long long

vector <ll> vec;

void findDuplicate(string s, ll n){
	ll counter = 0;
  	ll left = 0, right = 0; 

	while(left < s.size()){
		while(right < s.size() && s[right] == s[right+1])
			right++; 
		vec.push_back(right - left + 1);
		left = right + 1; 
		right = left; 
  	}
}

void solve(string s, ll n){
	ll answer = 0; 
	for(ll i = 0; i < vec.size(); i++){ 
	    answer += vec[i] / 2; 
	}

  if(vec[0] == s.size()){
	   cout << (s.size()*n) / 2 << endl; 
	   exit(0);
	 }

	if(vec[0] % 2 == 1 && vec.back() % 2 == 1 && s[0] == s[s.size() - 1]){
		cout << n * answer + n - 1 << endl; 
		exit(0);
	}
	cout << n * answer << endl; 
}

int main(){
	string s;
	ll n;

	cin >> s >> n; 

  	findDuplicate(s , n);
	solve(s , n);
}

// First, last letter are same, if odd occurence increase answer by n-1


Measured memory_bytes: 3168
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int n;
  int a[100000];
  int b[100000];
  int c[100000];
  int dpa[100000];
  int dpb[100000];
  int dpc[100000];
  cin >> n;
  for(int i = 0;i < n;i++){
    cin >> a[i] >> b[i] >> c[i];
  }
  dpa[0] = a[0];
  dpb[0] = b[0];
  dpc[0] = c[0];
  for(int i = 1;i < n;i++){
    dpa[i] = max(dpb[i - 1], dpc[i - 1]) + a[i];
    dpb[i] = max(dpa[i - 1], dpc[i - 1]) + b[i];
    dpc[i] = max(dpa[i - 1], dpb[i - 1]) + c[i];
  }
  cout << max(max(dpa[n - 1], dpb[n - 1]), dpc[n - 1]) << endl;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;

    long long int counter = 0;

    for (int i = 0; i < n - 2; i++)
    {
        if(s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C')   counter++;
    }
    
    cout << counter << endl;
  
    return 0;
}

Measured memory_bytes: 256
from collections import deque
N = int(input())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))

AB_list = sorted([A-B for A,B in zip(A_list, B_list)])
AB_q = deque(AB_list)

if sum(AB_list) < 0:
    print(-1)
    exit()
if AB_list[0] >= 0:
    print(0)
    exit()

cnt = 0
stock = 0
while len(AB_q) > 0:
    if stock <= 0:
        stock += AB_q.pop()
    else:
        lv = AB_q.popleft()
        if lv >= 0:
            break
        stock += lv
    cnt += 1
print(cnt)


Measured memory_bytes: 24484
N = input()
n = int(N)
X = input().split()

wa = 0
wa2 = 0
for i in range(n):
    X[i] = int(X[i])
    wa = wa + X[i]
    wa2 = wa2 + X[i]*X[i]
    
y = round(wa/n)

print( wa2 - 2*y*wa + n*y*y )



Measured memory_bytes: 3060
from collections import Counter

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


o = Counter(l[::2]).most_common()
e = Counter(l[1::2]).most_common()

if o[0][0] == e[0][0]:
    if len(o) == 1:
        print(N//2)
    else:
        e1, e2 = o[0][1], o[1][1]
        o1, o2 = e[0][1], e[1][1]

        res = min(N-e1-o2, N-e2-o1)
        print(res)
else:
    print(N - o[0][1] - e[0][1])


Measured memory_bytes: 25460
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int L = scanner.nextInt();
        int R = scanner.nextInt();
        int d = scanner.nextInt();
 
        int ans = 0;
        for (int i = L; i <= R; i++) {
            if(i%d==0) ans++;
        }
 
        System.out.println(ans);
 
    }
 
 
 
}

Measured memory_bytes: 35628
#include <bits/stdc++.h>
using namespace std;
//関数
const long INF=1000000000000;

//main関数
int main() {
    //入力
    long N;
    cin>>N;
    vector<long> A(N);
    for(int i=0;i<N;i++){
        cin>>A.at(i);
    }
    
    //計算
    sort(A.begin(),A.end());
    long ave=A.at((N-1)/2);
   // cout<<"ave"<<ave<<endl;
    long ans=0;
    for(int i=0;i<N;i++){
        ans+=2*abs(A.at(i)-ave);
//cout<<A.at(i)<<"を加え"<<ans<<"に"<<endl;
    }
    
    
    if(N%2==1){
        ans-=min(A.at(N/2+1)-A.at(N/2),A.at(N/2)-A.at(N/2-1));
    }else{
        ans-=A.at(N/2)-A.at(N/2-1);
    }
    
    //出力
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
using System;
class Program{
	static long[] s;
	static void Main(){
		s=Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
		double a=(s[0]-s[2])*2;
		long b=s[0]*s[0];
		double ans=(a/b)*(s[1]-1);
		if(s[2]==0){ans/=2;}
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 11220
/**
 *    author:  tourist
 *    created: 25.01.2020 20:41:36       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, x;
  cin >> n >> x;
  cout << 3 * (n - __gcd(n, x)) << '\n';
  return 0;
}


Measured memory_bytes: 256
n, m =map(int, input().split())
ab = []
cd = []
for i in range(n):
    a, b =map(int, input().split())
    ab.append((a,b))
for i in range(m):
    c, d =map(int, input().split())
    cd.append((c,d))

for i in range(n):
    nearest = 100000000000
    ans = 0
    for j in range(m):
        dis = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
        if dis < nearest:
            ans = j+1
            nearest = dis
    print(ans)


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

int main() {
  string n;
  cin >> n;
  if ((n[0] == n[1] && n[1] == n[2]) || (n[1] == n[2] && n[2] == n[3])) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

#define null                ""
#define all(dat)            dat.begin(), dat.end()
#define over(msg)           puts(msg), exit(0);
#define loop(i, to)         for (int i = 0; i < to; ++i)
#define cont(i, to)         for (int i = 1; i <= to; ++i)
#define forever             for (;;)
#define foreach(i, dat)     for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long           num;

using namespace std;

int n, l, q, to = 20, pos[100005], dis[25][100005], ans;

int main() {
	
	ios_base::sync_with_stdio(0);
	
	cin >> n;
	
	cont (i, n) {
		
		cin >> pos[i];
		
	}
	
	cin >> l >> q;
	
	cont (i, n) {
		
		dis[0][i] = (int) (upper_bound(pos + 1, pos + n + 1, pos[i] + l) - (pos + 1));
		
	}
	
	cont (i, to) {
		
		cont (j, n) {
			
			dis[i][j] = dis[i - 1][dis[i - 1][j]];
			
		}
		
	}
	
	cont (i, q) {
		
		int a, b, ans = 0;
		
		cin >> a >> b;
		
		if (a > b) {
			
			swap(a, b);
			
		}
		
		for (int i = to; i >= 0; --i) {
			
			if (dis[i][a] < b) {
				
				ans += 1 << i;
				
				a = dis[i][a];
				
			}
			
		}
		
		if (a != b) {
			
			++ans;
			
		}
		
		cout << ans << endl;
		
	}
	
}


Measured memory_bytes: 9472
// 基本テンプレート

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

bool solve(vector<int> segs, int goal, int mode) {
    map<int, int> rec;
    rec[0] = true;
    int N = segs.size();

    rep(i,0,N) {
        int val = segs[i];
        map<int, int> swp;
        for(auto x : rec) {
            swp[x.first + val]++;
            if(mode == 1 && i == 0) continue;
            swp[x.first - val]++;
        }
        swap(swp, rec);
    }
    return rec.count(goal);
}

signed main() {
    string s; cin >> s;
    int x, y; cin >> x >> y;

    s += "T";

    vector<int> move_x, move_y;
    int mode = 0, len = 0; // 0: move_x, 1: move_y
    rep(i,0,s.length()) {
        if(s[i] == 'F') len++;
        else {
            (mode ? move_y : move_x).push_back(len);
            len = 0;
            mode ^= 1;
        }
    }

    bool ok = true;
    ok &= solve(move_x, x, 1);
    ok &= solve(move_y, y, 0);
    cout << (ok ? "Yes" : "No") << endl;
    return 0;
}

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

int main() {
    string num;
    int cnt = 0;
    cin >> num;

    for (int i = 0; i < 3; i++) {
        if (num[i] == '1') {
            cnt++;
        }
    }

    cout << cnt << endl;

    return 0;


}

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

#define all(a) (a).begin(), (a).end()

int be[100001],en[100001];

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

int main(){
	int n;
	cin>>n;
	int a[100000];

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

	be[0]=a[0];
	en[n-1]=a[n-1];
	for (int i = 1; i < n; ++i){
		be[i]=gcd(be[i-1],a[i]);
	}

	for (int i = 1; i < n ; ++i){
		en[n-1-i]=gcd(a[n-1-i],en[n-i]);
	}

	int mx=max(be[n-2],en[1]);
	for (int i = 1; i < n-1; ++i){
		mx=max(mx,gcd(be[i-1],en[i+1]));
	}

	cout<<mx<<endl;

}


Measured memory_bytes: 1408
N, M = map(int, input().split())
edges = [list(map(int, input().split())) for _ in range(M)]

graph = [[None] * N for _ in range(N)]
for x, y in edges:
    graph[x - 1][y - 1] = True
    graph[y - 1][x - 1] = True
    
def dfs(v):    
    if all(visited):
        return 1
    
    ret = 0
    for i in range(N):
        if not graph[v][i]:
            continue
        if visited[i]:
            continue
            
        visited[i] = True
        ret += dfs(i)
        visited[i] = False
        
    return ret

visited = [True] + [False] * (N - 1)
print(dfs(0))

Measured memory_bytes: 3064
import sys

alf = list(str(input()))
for index1 in range(0,len(alf),2):
	if alf[index1]=="L":
		print("No")
		sys.exit()
for index1 in range(1,len(alf),2):
	if alf[index1]=="R":
		print("No")
		sys.exit()
print("Yes")

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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;

int check_div(int x){

    int ret=0;
    for(int i=1;i<=x;i++){
    if(x%i==0)ret++;
    }

return ret;
}
//status unsolved
int main(){
    int n;
    cin>>n;
    int ans=0;
    for(int i=1;i<=n;i+=2){
    if(check_div(i)==8)ans++;
    }
    cout<<ans<<"\n";
    return 0;

}
/*


*/


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

int main()
{
	int n, k;
	char s[51];

	scanf("%d", &n);
	scanf("%d", &k);
	scanf("%s",s);

	s[k - 1] = tolower(s[k - 1]);

	printf("%s", s);

	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=(1<<18)+10;
ll a[maxn],ans[maxn];
int main(){
	int n=read(),N=(1<<n)-1;
	REP(i,0,N) a[i]=read();
	REP(j,0,n-1) REP(i,0,N) if(i&(1<<j)){
		chkmax(ans[i],a[i]+a[i^(1<<j)]);
		chkmax(a[i],a[i^(1<<j)]);
	}
	REP(i,1,N) chkmax(ans[i],ans[i-1]);
	REP(i,1,N) printf("%lld\n",ans[i]);
	return 0;
}


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;


int a, b, k, cnt;
int main() {
    cin >> a >> b >> k;
    for (int i = min(a, b); i >= 1; --i) {
        if (a % i == 0 && b % i == 0) {
            ++cnt;
            if (cnt == k) {
                cout << i << endl;
                exit(0);
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3648
h, n = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
max_a = max(a for a, _ in ab)
dp = [10 ** 18 for _ in range(h + max_a)]
dp[0] = 0

for i in range(1, h + max_a):
    dp[i] = min(dp[i-a] + b for a, b in ab)
print(min(dp[h:]))


Measured memory_bytes: 3832
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll x;cin>>x;
    cout<<x/500*1000+x%500/5*5<<endl;

    return 0;
}

Measured memory_bytes: 256
fn main() {
    proconio::input! {
        n: usize,
        s: proconio::marker::Chars,
    }
    let (num_r, num_g, num_b) = {
        let (mut r, mut g, mut b) = (0, 0, 0);
        for c in s.iter() {
            match c {
                'R' => r += 1,
                'G' => g += 1,
                'B' => b += 1,
                _ => unreachable!(),
            }
        }
        (r, g, b)
    };
    let (remain_r, remain_g, remain_b) = {
        let (mut r, mut g, mut b) = (vec![], vec![], vec![]);
        let (mut num_r, mut num_g, mut num_b) = (num_r, num_g, num_b);
        for c in s.iter() {
            r.push(num_r);
            g.push(num_g);
            b.push(num_b);
            match c {
                'R' => {
                    num_r -= 1;
                }
                'G' => {
                    num_g -= 1;
                }
                'B' => {
                    num_b -= 1;
                }
                _ => unreachable!(),
            }
        }
        (r, g, b)
    };
    let mut sum = 0;
    for i in 0..n - 2 {
        for j in i + 1..n - 1 {
            if s[i] == s[j] {
                continue;
            }
            let diff_ji = j - i;
            let same_distance_k = j + diff_ji;
            let color_k = if s[i] != 'R' && s[j] != 'R' {
                'R'
            } else if s[i] != 'G' && s[j] != 'G' {
                'G'
            } else {
                'B'
            };
            let mut remain: i64 = match color_k {
                'R' => remain_r[j + 1],
                'G' => remain_g[j + 1],
                'B' => remain_b[j + 1],
                _ => unreachable!(),
            };
            if n <= same_distance_k {
                // can not take same distance
            } else if s[same_distance_k] == color_k {
                remain -= 1;
            }
            sum += remain;
        }
    }
    println!("{}", sum);
}


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

int N,K;
bool D[10];
int tmp;

bool check(int n)
{
	while(n)
	{
		if(D[n%10]==false)return false;
		n/=10;
	}
	return true;
}

int main()
{
	for(int i=0;i<10;i++)D[i]=true;
	
	cin >> N >> K;
	for(int i=0;i<K;i++)
	{
		cin >> tmp;
		D[tmp]=false;
	}
	
	for(int i=N;;i++)
	{
		if(check(i))
		{
			cout << i << endl;
			return 0;
		}
		
	}
	return 0;
}

Measured memory_bytes: 256
function Scanner(input) {
	var self = this;
	self.itemNo = 0;
	self.orgStr = input;
	self.splitedStrs = (function(target) {
		var result = [];
		var target = target.replace(/[\n \t]+/g, " ");
		var strs = target.split(" ");
		for (var i = 0, len = strs.length; i < len; i++) {
			result.push(strs[i]);
		}
		return result;
	}(input));

	self.next = function() {
		var result = self.splitedStrs[self.itemNo];
		self.itemNo++;
		return (result != null) ? result : null;
	}

	self.nextInt = function() {
		var result = self.splitedStrs[self.itemNo];
		self.itemNo++;
		return (result != null) ? parseInt(result) : null;
	}

	self.nextBigDecimal = function() {
		var result = self.splitedStrs[self.itemNo];
		self.itemNo++;
		return (result != null) ? parseFloat(result) : null;
	}
	
	self.nextByte = function() {
		var result = self.splitedStrs[self.itemNo];
		self.itemNo++;
		return (result != null) ? new Int8Array(result) : null;
	}

}

// inputに入力データ全体が入る
function Main(sc) {

	var N = sc.nextInt();
	var A = sc.nextInt();
	var B = sc.nextInt();
	var C = sc.nextInt();
	var ABC = { A : A, B : B, C : C, };
	var ans = "Yes";
	var ans2 = [];
	
	var sL = [];
	for (var i = 0; i < N; i++) {
		sL.push(sc.next());
	}
	
	for (var i = 0; i < N; i++) {
		
		var c0 = sL[i].charAt(0);
		var c1 = sL[i].charAt(1);
		var nextS = sL[i + 1];
		
		if (ABC[c0] == 0 && ABC[c1] == 0) {
			ans = "No";
			break;
		}
		
		// 次との共通ターゲット
		var nextShareTs = [];
		var crntNotShareT = "";
		var nextNotShareT = "";
		if (nextS) { 
			if (nextS.indexOf(c0) > -1) {
				nextShareTs.push(c0);
			}
			if (nextS.indexOf(c1) > -1) {
				nextShareTs.push(c1);
			}
			
		}
		
		var plusT = (ABC[c0] < ABC[c1]) ? c0 : c1;
		if (nextShareTs.length == 1 && ABC[c0] == 1 && ABC[c1] == 1) {
			plusT = nextShareTs[0];
		}
		var minusT = (c0 == plusT) ? c1 : c0;
		
		ABC[plusT]++;
		ABC[minusT]--;
		ans2.push(plusT);
	}
	
	// 出力
	console.log((ans == "No") ? ans : ans + "\n" + ans2.join("\n"));
}
Main(new Scanner(require("fs").readFileSync("/dev/stdin", "utf8")));
// Main(new Scanner("33"));

// var str1 = sc.next(); // Stringで取得
// var int1 = sc.nextInt(); // intで取得
// var bd1 = sc.nextBigDecimal(); // BigDecimalで取得
// var byte1 = sc.nextByte(); // byteで取得


Measured memory_bytes: 62416
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1145141919
#define LLINF 1145148101919
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
int ny, nx;
typedef long long ll;
using namespace std;

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

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

int ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}

class UnionFind
{
public:
    vector<ll> par; // 各元の親を表す配列
    vector<ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL)
    {
        for (ll i = 0; i < sz_; ++i)
            par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_)
    {
        siz.assign(sz_, 1LL); // assign: 再代入
        par.resize(sz_);      // resize: 再確保
        for (ll i = 0; i < sz_; ++i)
            par[i] = i; // 初期では親は自分自身
    }

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

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

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

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

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

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

template <typename Container>
bool exist_in(const Container &c, const typename Container::value_type &v)
{
    return (c.end() != std::find(c.begin(), c.end(), v));
}

vector<ll> decom;

void decompositPrime(ll n)
{
    ll a = 2;
    while (n >= a * a)
    {
        if (n % a == 0)
        {
            decom.push_back(a);
            n /= a;
        }
        else
        {
            a++;
        }
    }
    decom.push_back(n);
}

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

const ll mod = 1e9 + 7;
ll N;

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

int main()
{
    cin >> N;
    ll ans=LLINF;
    FOR(i,1,sqrt(N)+1){
        ll res=N/i;
        if(i*res==N and i+res<ans){
            ans=i+res;
            //cout << i << " " << res << endl;
        }
    }

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


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<tuple>
#include<utility>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<iomanip>
#include<map>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const int INF = 1e9 + 7;
int dx[8] = { 1,0,-1,0,1,1,-1,-1 };
int dy[8] = { 0,1,0,-1,1,-1,1,-1 };

int n;
vector<int> a;
int solve(int k, int m) {

	if (k == 0) {
		if (m == 0) {
			return 1;
		}
		else {
			return 0;
		}
	}
	int cnt = 0;
	for (int i = 0; i < 2; i++) {
		cnt += solve(k - 1, m - a[k - 1] * i);
	}
	return cnt;

}

int main() {
	int q;
	vector<int> m;
	while (cin >> n) {
		a.resize(n);
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		cin >> q;

		m.resize(q);
		for (int i = 0; i < q; i++) {
			cin >> m[i];
		}

		for (int i = 0; i < q; i++) {
			if (solve(n, m[i])) {
				cout << "yes" << endl;
			}
			else {
				cout << "no" << endl;
			}
		}

	}
	return 0;
}



Measured memory_bytes: 3080
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int A = scan.nextInt();
        int B = scan.nextInt();
        int C = scan.nextInt();
        String answer = "No";
        if (A == B && B == C) {
            answer = "Yes";
        }
        System.out.println(answer);
    }
}


Measured memory_bytes: 23892
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{

    ll pera,n,i,diff=0;
    cin>>pera>>n;
    ll ara[n+5];
    for(i=0;i<n;i++)
    {
        cin>>ara[i];
    }
    diff=ara[n-1]-ara[0];
    for(i=1;i<n;i++)
    {
        diff=min(diff,pera-(ara[i]-ara[i-1]));
    }
    cout<<diff<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <utility>
#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;

int main() {
    int n; cin >> n;
    bool flag = false;
    while(n > 0){
    	int x = n % 10; 
    	if(x == 7){
    		flag = true;
    		break;
    	}
    	n = n / 10;
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
	return 0;
} 

Measured memory_bytes: 3132
#include <iostream>
using namespace std;
int main(){
	int n ; cin >> n ; int a[200];
	for(int i=0;i<2*n;i++) a[i]=i+1 ;
	int m ; cin >> m ;
	for(int i=0;i<m;i++){
		int num; cin >> num ;
		if(!num) {
			int temp[200];
			for(int j=0;j<n;j++)
				temp[2*j]=a[j],temp[2*j+1]=a[n+j];
			for(int j=0;j<2*n;j++)
				a[j]=temp[j];
		}
		else {
			int temp[200];
			for(int j=0;j<2*n-num;j++)
				temp[j]=a[num+j];
			for(int j=0;j<num;j++)
				temp[2*n-num+j]=a[j];
			for(int j=0;j<2*n;j++)
				a[j]=temp[j];
		}
	}
	for(int i=0;i<2*n;i++)
	cout << a[i] << '\n' ;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
int main() {
	int D,G;
	cin>>D>>G;
	//入力
	vector<int> veca(D);
	vector<int> vecb(D);
	vector<int> vecc(D);
	vector<int> vecd(D);
	for(int i=0; i<D; i++){
		cin>>veca[i]>>vecb[i];
	}
	//入力
	for(int i=0; i<D; i++){
		vecc[i]=(i+1)*100*veca[i]+vecb[i];
	}
	//veccの定義
	int sum=0,sub=10000,ssbbb=0;//sumは合計金額、subは合計数、ssbbbは現時点での個数
	//最終的な答えはsubで出力
	/////////////////////////////////////////////
	for(int bit=0;bit<pow(2,D);bit++){
		for(int i=0; i<D; i++){
		if(bit&(1<<i)){
			vecd[i]=1;
			sum+=vecc[i];
			ssbbb+=veca[i];
		}
		}
		//ボーナス分のbit終了
		for(int j=0; j<D; j++){
			for(int k=0; k<veca[D-j-1]; k++){
				if(((vecd[D-j-1])==0)&&(sum<G)){
					sum+=(D-j)*100;
					ssbbb++;
				}
			}
		};
		
	if(ssbbb<sub){
		sub=ssbbb;
	}
	//ここから初期化
	for(int q=0; q<D; q++){
	    vecd[q]=0;
	}
	sum=0;
	ssbbb=0;
	//初期化終わり
	}//ここまでで２＾D通り
	////////////////////////////////////////////
	cout<<sub<<endl;
}

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

int main(void){
    long long N;cin>>N;
    std::vector<long long>A(N);
    for(long long i=0;i<N;i++){
        cin>>A[i];
    }
    sort(A.begin(),A.end());
    long long ans=0;
    long long tmp=0;
    for(long long i=1;i<N;i++){
        if(A[i]==A[i-1]){
            tmp++;
            if(i==N-1){
                if(tmp%2==0){
                    ans++;
                }    
            }
        }
        else{
            if(tmp%2==0){
                ans++;
            }
            tmp=0;
        }
    }
    if(A[N-1]!=A[N-2]){
        ans++;            
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3960
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
bool f[314514];
int main(){
	ll n,m;
	cin>>n>>m;
	vector<vector<ll>>v(314514);
	vector<ll>dis(314514,1e9);
	ll p=100000;
	for(int i=0;i<m;i++){
		ll a,b;
		cin>>a>>b;
		v[a].push_back(b+p);
		v[a+p].push_back(b+2*p);
		v[a+2*p].push_back(b);
	}
	ll s,t;
	cin>>s>>t;
	dis[s]=0;
	f[s]=1;
	queue<P>que;
	que.push({s,0});
	while(!que.empty()){
		P x=que.front();
		que.pop();
		for(ll num:v[x.first]){
			if(f[num])continue;
			f[num]=1;
			que.push({num,x.second+1});
			dis[num]=x.second+1;
		}
	}
	if(dis[t]==1e9)cout<<-1;
	else cout<<dis[t]/3;
	return 0;
}


Measured memory_bytes: 22696
import sys
from fractions import gcd
from functools import reduce

def solve(N, T):
    def lcm(x, y):
        return x*y // gcd(x,y)

    print(reduce(lambda x,y: lcm(x,y), T, 1))

def main():
    N = int(input())
    T = [ int(input()) for _ in range(N) ]
    solve(N, T)

if __name__ == "__main__":
    main()

Measured memory_bytes: 5076
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 998244353;
const ll INF = 1001001001;
const ll LINF = 1001001001001001001;

void prvec(vector<ll> vec){
    ll n = vec.size();
    rep(i,n) cout << i << " " << vec.at(i) << "\n";
}

void pr2d(vector<vector<ll>> vvec){
    ll h = vvec.size();
    ll w = vvec.at(0).size();
    rep(i,h){
        rep(j,w){
            cout << vvec.at(i).at(j) << " ";
        }
        cout << "\n";
    }
}

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

Measured memory_bytes: 3632
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int64_t A,B,C,K;

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> A>>B>>C>>K;
	if (K & 1) {
		out << B - A << endl;
	}
	else {
		out << A - B << endl;
	}

	return 0;
}
#endif


Measured memory_bytes: 888
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int num = (s.length() / 2) + s.length() % 2;
        String s1 = repeat("10", num).substring(0, s.length());
        String s2 = repeat("01", num).substring(0, s.length());

        int diff1 = 0;
        int diff2 = 0;
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) != s1.charAt(i)) diff1++;
            if (s.charAt(i) != s2.charAt(i)) diff2++;
        }

        System.out.println(diff1 > diff2 ? diff2 : diff1);
    }

    private static String repeat(String s, int i) {
        StringBuilder sb = new StringBuilder();
        for (int j = 0; j < i; j++) {
            sb.append(s);
        }
        return sb.toString();
    }
}


Measured memory_bytes: 26376
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    template<typename T>
    vector<T> read_vec(size_t n){
        vector<T> tmp(n);
        for(size_t i = 0; i < n; i++){
            cin >> tmp[i];
        }
        return tmp;
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};

int main(){
    Stream io;

    int N;
    io.read(N);
    auto T = io.read_vec<int>(N);
    int M;
    io.read(M);
    vector<int> P(M);
    vector<int> X(M);
    for(int i = 0; i < M; i++){
        io.read(P[i], X[i]);
    }
    int sum = 0;
    for(int i = 0; i < N; i++){
        sum += T[i];
    }
    for(int i = 0; i < M; i++){
        cout << sum - (T[P[i] - 1] - X[i]) << '\n';
    }
    return 0;
}

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

int main() {
  long long a,b,c;
  cin >> a >> b >> c;
  if (a == 0) {
    cout << b/c +1 << endl;
  }
  else {
    cout << b/c - (a-1)/c << endl;
  }
}


Measured memory_bytes: 256
/* Read input from STDIN. Print your output to STDOUT*/
#include <bits/stdc++.h>
#define ll long long

using namespace std;

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



ll calc(string s){
    if(s.size() == 1){
        ll c = s[0]-'0';
        return c/2;
    }
    ll val = 0;
    ll ans = 4LL;
    if(s.size() > 2){
      ll prod = 10LL*(pow(10LL, s.size()-2)-1LL)/9LL;
      ans *= prod;
    }
    for(int i = 0; i < s.size()-1; i++){
        ll c = s[i] - '0';
        c = 9LL-c;
        c /= 2LL;
        ll prod = 10LL*(pow(10LL, i)-1LL)/9LL;
        val -= c*prod;
    }
    ll c = s[s.size()-1] - '0';
    c /= 2LL;
    ll prod = 10LL*(pow(10LL, s.size()-1)-1LL)/9LL;
    val += c*prod;
    cout << ans << " " << val << endl;
    if(c > 1) ans += val;
    return ans;
}

int main()
{
    ll a, b;
    cin >> a >> b;
    ll g = gcd(a,b);
    a /= g;
    a *= b;
    cout << a;

}


Measured memory_bytes: 256
n=int(input())
l=[]
for i in range(n):
    l.append(int(input()))
l.sort()
sl=sum(l)
if sl%10==0:
    for i in l:
        if i%10==0:continue
        print(sl-i)
        break
    else:print(0)
else:print(sl)

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    ll ans = 0;
    ll a[300000];
    for (int i = 0; i < 3 * n; i++) {
        cin >> a[i];
    }
    sort(a, a + 3 * n);
    for (int i = 3 * n - 2; i >= n; i -= 2) {
        ans += a[i];
    }
    cout  << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
/**
 *    author:  tourist
 *    created: 13.10.2018 16:23:29       
**/
#include <bits/stdc++.h>

using namespace std;

const int N = 505;

short L[N][N][N];
short R[N][N][N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<string> board(n);
  for (int i = 0; i < n; i++) {
    cin >> board[i];
  }
  vector<vector<int>> a(n, vector<int>(n, 0));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      a[i][j] = (board[i][j] == '#' ? 0 : (int) (board[i][j] - '0'));
    }
  }
  vector<vector<int>> row(n, vector<int>(n + 1));
  for (int i = 0; i < n; i++) {
    row[i][0] = 0;
    for (int j = 0; j < n; j++) {
      row[i][j + 1] = row[i][j] + a[i][j];
    }
  }
  long long ans = 0;
  function<void(int,int)> put = [&](int i, int j) {
    if (0 <= i && i < n && 0 <= j && j < n && a[i][j] > 0) {
      if (i == 0 || a[i - 1][j] == 0) {
        if (j == 0 || a[i][j - 1] == 0) {
          for (int k = j; k < n; k++) {
            row[i][k + 1] -= a[i][j];
          }
          a[i][j] = 0;
          put(i + 1, j);
          put(i, j + 1);
        }
      }
    }
  };
  for (int i = n - 1; i >= 0; i--) {
    for (int j = n - 1; j >= 0; j--) {
      if (a[i][j] == 0) {
        continue;
      }
      for (int k = i; k < n; k++) {
        L[i][j][k] = n;
        R[i][j][k] = 0;
      }
      L[i][j][i] = j;
      R[i][j][i] = j;
      if (i < n - 1 && a[i + 1][j] != 0) {
        for (int k = i + 1; k < n; k++) {
          L[i][j][k] = min(L[i][j][k], L[i + 1][j][k]);
          R[i][j][k] = max(R[i][j][k], R[i + 1][j][k]);
        }
      }
      if (j < n - 1 && a[i][j + 1] != 0) {
        for (int k = i; k < n; k++) {
          L[i][j][k] = min(L[i][j][k], L[i][j + 1][k]);
          R[i][j][k] = max(R[i][j][k], R[i][j + 1][k]);
        }
      }
      int sum = 0;
      for (int k = i; k < n; k++) {
        if (L[i][j][k] <= R[i][j][k]) {
          sum += row[k][R[i][j][k] + 1] - row[k][L[i][j][k]];
        }
      }
      ans += a[i][j] * (sum - a[i][j]);
      put(i, j);
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 504320
#include <bits/stdc++.h>
       
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
  int N, M;
  cin >> N;
  vector<int> S(N, -1);
  cin >> M;
  for (int i = 0; i < (int)(M); ++i) {
    int s, c;
    cin >> s >> c;
    --s;
    if (S[s] != -1 && S[s] != c) {
      cout << -1 << endl;
      return 0;
    }
    S[s] = c;
  }

  bool ok = false;
  for (int i = 0; i < (int)(N); ++i) {
    if (!ok && S[i] == 0 && N != 1) {
      cout << -1 << endl;
      return 0;
    }
    if (S[i] == -1) {
      cout << (ok || (N == 1) ? 0 : 1);
    } else {
      cout << S[i];
    }
    ok = true;
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <unordered_map>

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

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

int N, M;
std::string S, T;

int main(int argc, char **argv) {
    std::cin >> N >> M;
    std::cin >> S;
    std::cin >> T;

    long long cand = lcm(N, M);
    long long stepS = cand / N;
    long long stepT = cand / M;

    for (int i = 0; i < N; i++) {
        if ((i * stepS) % stepT == 0) {
            int j = (i * stepS) / stepT;
            //std::cout << i << " " << j << " " << S[i] << " " << T[j] << std::endl;
            if (S[i] != T[j]) {
                std::cout << -1 << std::endl;
                return 0;
            }
        }
    }

    for (int i = 0; i < M; i++) {
        if ((i * stepT) % stepS == 0) {
            int j = (i * stepT) / stepS;
            if (T[i] != S[j]) {
                std::cout << -1 << std::endl;
                return 0;
            }
        }
    }

    std::cout << cand << std::endl;
    
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cout << setiosflags(ios::fixed) << setprecision(10);
	int n;
	cin >> n;
	vector<double> r(n);
	for(int i = 0; i < n; ++i){ cin >> r[i]; }
	vector<double> p(n);
	for(int i = 1; i < n; ++i){
		double x = 0;
		for(int j = 0; j < i; ++j){
			const double y = abs(r[i] - r[j]);
			const double z = r[i] + r[j];
			x = max(x, p[j] + sqrt(z * z - y * y));
		}
		p[i] = x;
	}
	double left = -r[0], right = r[0];
	for(int i = 0; i < n; ++i){
		left  = min(left,  p[i] - r[i]);
		right = max(right, p[i] + r[i]);
	}
	cout << right - left << endl;
	return 0;
}

Measured memory_bytes: 3316
a = {x:0 for x in range(ord('a'), ord('z') + 1)}

while True:
    try:
        text = input()
        for x in text:
            if ord('a') <= ord(x) <= ord('z') or ord('A') <= ord(x) <= ord('Z'):
                a[ord(x.lower())] += 1
    except EOFError:
        break

for x in range(ord('a'), ord('z') + 1):
    print(chr(x), ':', a[x])

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

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); ++i) {
        int a = (s[i] - 'A' + n) % 26;
        char c = 'A' + a;
        cout << c;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 764
import collections

def fanctionA(n):
    AList = []
    tmp = 2
    
    while n % tmp == 0:
        AList.append(tmp)
        n //= tmp
    tmp = 3
    while tmp * tmp <= n:
        if n % tmp == 0:
            AList.append(tmp)
            n //= tmp
        else:
            tmp += 2
    if n != 1:
        AList.append(n)
    return AList
  
    
N = int(input())

arr = collections.Counter(fanctionA(N))

arr = list(arr.values())

tmp = 1
count = 0
for a in arr:
    while 'true':
        if a >= tmp:
            a -= tmp
            count += 1
            tmp += 1
        else:
            tmp = 1
            break

print(count)

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

int main(){
    long long n;
    cin >> n;

    vector<long long> L(n);

    for(long long i = 0; i < n; i++){
        cin >> L[i];
    }

    sort(L.begin(), L.end());

    long long count = 0;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            int k = lower_bound(L.begin(), L.end(), L[i]+L[j]) - L.begin();
            //printf("k %d\n", k);
            count += k - (j+1);
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<bitset>
using namespace std;

int main() {

	string T;
	cin >> T;

	for (int i = 0; i < T.length(); i++) {
		if (T[i] == '?') {
			T[i] = 'D';
		}
	}
	
	cout << T << endl;

	return 0;
}



Measured memory_bytes: 3756
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <utility>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <istream>
#include <ostream>

#include <cstdlib>
#include <cmath>
#include <cstdio>

using namespace std;

#define fi first
#define se second
#define mkp make_pair
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define rep(i,n) for(ll i=0; i < (n); ++i)
#define rrep(i,n) for(ll i=((n)-1); i >= 0; --i)

#define OPLT(T) bool operator<(const T & lop_, const T & rop_)
#define OPEQ(T) bool operator==(const T & lop_, const T & rop_)

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

istream& operator>>(istream& istr, __float128& obj) { double d; istr >> d; obj = d; return istr; };
ostream& operator<<(ostream& ostr, __float128& obj) { ostr << static_cast<double>(obj); return ostr; };

int c[110][110];

int main() {
	int H, W;
	int N;
	cin >> H >> W;
	cin >> N;
	vector<int> a(N);
	rep(i,N) cin >> a[i];
	rep(i,H) {
		rep(j,W) {
			int jj = j;
			if(i % 2) jj = W-1 -j;

			c[i][jj] = a.size();
			a.back()--;
			if(a.back() == 0) a.pop_back();
		}
	}

	rep(i,H) {
		rep(j,W) {
			if(j) cout << " ";
			cout << c[i][j];
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<int, pair<int, int>> PP;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int INF = 1001001001;
const int mod = 1e+9 + 7;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

int n;
vector<int> graph[100005];

vector<int> calc_dist(int st){
    vector<int> dist(n, INF);
    queue<int> que;
    dist[st] = 0;
    que.push(st);
    while(!que.empty()){
        int u = que.front();
        que.pop();
        for(int v : graph[u]){
            if(dist[v] != INF)  continue;
            dist[v] = dist[u] + 1;
            que.push(v);
        }
    }
    return dist;
}

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

    int s, t;
    cin >> n >> s >> t;
    --s, --t;
    for(int i = 0; i < n - 1; ++i){
        int a, b;
        cin >> a >> b;
        --a, --b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    vector<int> dists = calc_dist(s);
    vector<int> distt = calc_dist(t);
    
    int res = 0;
    for(int v = 0; v < n; ++v){
        if(dists[v] < distt[v]){
            chmax(res, distt[v]);
        }
    }
    --res;
    cout << res << endl;
}

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

struct Benri { Benri() { std::cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12);}} benri;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using ull = unsigned long long;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

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

constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
//constexpr int INF = 1001001001;
constexpr ll INF = 1001001001001001001LL;
constexpr double EPS = 1e-10;
using number = long long;

int main() {
    int n; cin >> n;
    vi l(n);
    rep(i, n) cin >> l[i];
    sort(all(l));
    ll ans = 0;

    for (ll i = 0; i < n - 2; i++) {
        for (ll j = i + 1; j < n - 1; j++) {
            auto itr = lower_bound(all(l), l[i] + l[j]);
            ll k = itr - l.begin() - 1;
            //cout << i << " "<< j  << " "<< k << endl;
            ans += max(k - j, 0LL);
        }
    }

    cout << ans << endl;
}


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

bool B[200001];

int main(){
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++) B[i]=true;
    vector<int> E(m);
    for(int i=0;i<m;i++){
        cin>>E[i];
    }
    reverse(E.begin(),E.end());
    for(auto e:E){
        if(B[e]){
            cout<<e<<endl;
            B[e]=false;
        }
    }
    for(int i=1;i<=n;i++){
        if(B[i]){
            cout<<i<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3284
using System;
// using System.Collections.Generic;
// using System.Globalization;
// using System.IO;
// using System.Linq;
// using System.Text;
// using System.Text.RegularExpressions

class Program
{
    static void Main()
    {
        string[] arr = Console.ReadLine().Split();
        int N, D;
        N = int.Parse(arr[0]);
        D = int.Parse(arr[1]);
        Console.WriteLine(Math.Ceiling(N / (2M * D + 1)));
        return;
    }
}

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

class Program
{
    static void Main()
    {
        Scanner cin = new Scanner();
        int N = cin.Int();
        int M = cin.Int();
        string S = Console.ReadLine();
        string T = Console.ReadLine();

        int n = N / GCD(N, M);
        int m = M / GCD(N, M);
        bool flag = true;
        for (int a = 0; a < GCD(N, M); a++)
        {
            if (S[a * n] != T[a * m]) flag = false;
        }

        Console.WriteLine(flag ? LCM(N, M) : -1);
        Console.ReadLine();
    }

    static int GCD(int a, int b) //a,bの最大公約数
    {
        if (a < b)
            // 引数を入替えて自分を呼び出す
            return GCD(b, a);
        while (b != 0)
        {
            var remainder = a % b;
            a = b;
            b = remainder;
        }
        return a;
    }

    static long LCM(int a, int b) //a,bの最小公倍数
    {
        return (long)a / GCD(a, b) * b;
    }
}

class Scanner //標準入力
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int Int()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = Int() + add;
        }
        return Array;
    }

    public long Long()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = Long() + add;
        }
        return Array;
    }

    public double Double()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = Double() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 11616
#include <bits/stdc++.h>
#define ll long long 
#define vi vector<int>
#define vl vector<ll>
#define vll vector<pair<ll,ll> >
#define pb push_back
#define f(i,a,b) for(i=a;i<b;i++)
using namespace std;

int main()
{
	int a;
	cin>>a;
	if(a>=30)cout<<"Yes";
	else cout<<"No";

	
}

Measured memory_bytes: 3632
import math

input()
a = *map(int, input().split()),
         
N = max(a) + 1
 
spf = [*range(N)]
i = 2
while i * i < N:
  if spf[i] == i:
    for j in range(i * i, N, i):
      if spf[j] == j:
        spf[j] = i
  i += 1
  
r = 'pairwise'
 
d = None
u = set()
for x in a:
  d = math.gcd(d or x, x)
  s = set()
  while x > 1:
    p = spf[x]
    if p in u:
      r = 'setwise'
    s.add(p)
    x //= p
  u |= s
print((r, 'not')[d > 1], 'coprime')


Measured memory_bytes: 211732