akhauriyash/Code-Regression huggingface dataset:
use std::collections::*;
use std::io::BufRead;
use std::io::*;
struct StdinReader<R: BufRead> {
    pub reader: R,
    pub buf: String,
}
impl<R: BufRead> StdinReader<R> {
    pub fn new(reader: R) -> Self {
        Self {
            reader,
            buf: String::new(),
        }
    }
}
macro_rules! get {
    ($r:expr, $t:ty) => {
        {
            let mut line = &mut $r.buf;
            line.clear();
            $r.reader.read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($r:expr, $($t:ty),*) => {
        {
            let mut line = &mut $r.buf;
            line.clear();
            $r.reader.read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($r:expr, $t:ty; $n:expr) => {
        // items in n lines
        (0..$n).map(|_|
                    get!($r, $t)
                   ).collect::<Vec<_>>()
    };
    ($r:expr, $($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    get!($r, $($t),*)
                   ).collect::<Vec<_>>()
    };
    ($r:expr, $t:ty ;;) => {
        // items in a line
        {
            let mut line = &mut $r.buf;
            line.clear();
            $r.reader.read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($r:expr, $t:ty ;; $n:expr) => {
        (0..$n).map(|_| get!($r, $t ;;)).collect::<Vec<_>>()
    };
}

fn main() {
    let reader = stdin();
    let mut reader = StdinReader::new(reader.lock());
    let out = stdout();
    let mut out = BufWriter::new(out.lock());
    let (n, m, k) = get!(reader, i64, i64, i64);
    let a = get!(reader, i64;;);
    let b = get!(reader, i64;;);
    let a = std::iter::once(0)
        .chain(a)
        .scan(0, |sum, x| {
            *sum += x;
            Some(*sum)
        })
        .collect::<Vec<_>>();
    let b = std::iter::once(0)
        .chain(b)
        .scan(0, |sum, x| {
            *sum += x;
            Some(*sum)
        })
        .collect::<Vec<_>>();
    let mut ans = 0;
    for i in 0..=n {
        let i = i as usize;
        let atime = a[i];
        if atime > k {
            continue;
        }
        let br = &b.binary_search(&(k - atime));
        let b = match br {
            Ok(x) => *x as i64,
            Err(x) => *x as i64 - 1,
        };
        if i as i64 + b > ans {
            ans = i as i64 + b;
        }
    }
    writeln!(out, "{}", ans);
}


Measured memory_bytes: 9004
import java.io.File;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner sc = new Scanner(file);
		
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int X = sc.nextInt();
		int[] xp = new int[N+1];
		for(int i = 0; i < N; i++) xp[i] = sc.nextInt();
		xp[N] = X;
		
		Arrays.sort(xp);
		//for(int i : xp) System.out.println(i);
		int[] dist = new int[N];
		for(int i = 0; i < N; i++) dist[i] = xp[i+1] - xp[i];
		int distMax = dist[N-1];
		
		int ans = 1;
		/*
		for(int i = 2; i <= distMax; i++){
			boolean tf = true;
			for(int j = 0; j < N; j++){
				if(dist[j] % i != 0){
					tf = false;
					break;
				}
			}
			if(tf) ans = i;
		}
		*/
		
		for(int i = distMax;i >= 2; i--){
			boolean tf = true;
			for(int j = 0; j < N; j++){
				if(dist[j] % i != 0){
					tf = false;
					break;
				}
			}
			if(tf){
				ans = i;
				break;
			}
		}
		
		System.out.println(ans);
	}
}

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

typedef long long ll;

#define pb push_back
#define mkp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define clr(a, b) memset(a, b, sizeof(a))
#define forn(i, n) for(int i=0; i<(int)(n); ++i)
#define forab(i, a, b) for(int i=(int)(a); i<=(int)(b); ++i)
#define FOR(it,c) for ( __typeof((c).begin()) it=(c).begin(); it!=(c).end(); it++ )

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifdef LOCAL
    clock_t tStart = clock();
#endif
    int n, k, s;
    cin >> n >> k >> s;
    //corner cases like k = 0, s = 
    forn(i, n) {
        if(k == 0) {
            if(s <= n)
                s = n+1;
            else
                s = 1;
        }
        cout << s << " ";
        --k;
    } 
    cout << "\n";
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * (clock() - tStart)/ CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 1280
n=input()
x=[]
y=[]
for _ in range(n):
    x1,y1=[int(i) for i in raw_input().split()]
    x.append(x1);y.append(y1)
res=0
for p, q in [[1, 1], [1, -1], [-1, 1], [-1, -1]]:
        smallest = p * x[0] + q * y[0]
        for i in range(n):
                cur = p * x[i] + q * y[i]
                res = max(res, cur - smallest)
                smallest = min(smallest, cur)
print res


Measured memory_bytes: 94548
#include<iostream>
using namespace std;
int main()
{
	int m, f, r;
	while (1)
	{
		cin >> m >> f>>r;
		if (m == -1 && f == -1 && r == -1){ break; }
		if (m == -1 || f == -1){ cout << "F" << endl; }
		else if (m + f >= 80)
		{
			cout << "A" << endl;
		}
		else if (65 <= m + f&&m + f < 80)cout << "B" << endl;
		else if (50 <= m + f&&m + f < 65)cout << "C" << endl;
		else if (30 <= m + f&&m + f < 50 && r >= 50)cout << "C" << endl;
		else if (30 <= m + f&&m + f < 50)cout << "D" << endl;
		else cout << "F" << endl;

	}
	return 0;

}


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

int main() {
  //1が書かれたマスにビー玉を置く時、ビー玉がビー玉が置かれるマスの数を出力する。
	int s1s2s3;
	cin >> s1s2s3;
    
    //s1s2s3 = 101;

	int s1, s2,s3;
  	cin >> s1 >> s2 >> s3;
  
	s1 = s1s2s3 / 100;
 	s2 = s1s2s3 /10 - s1 * 10;
    s3 = s1s2s3 - (s1 * 100 + s2 * 10) ;
  
  	cout << (s1 + s2 + s3) << endl;
}
  

Measured memory_bytes: 3620
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main(){
    int n; cin >> n;
    if(n>=30) cout << "Yes" << endl;
    else cout << "No" << endl;
    return;
}

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

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,p,q,r;

  cin>>a>>b>>p>>q>>r;

  int A=p*b;
  
  double d;
  d=(double)(a*q+b*r+p*b)/(q+r);

  cout<<fixed<<setprecision(12)<<d<<endl;
  return 0;
}



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

ll N;
vector<string> ans;

void dfs(string s){
    ll n = s.size();
    if(n == N){
        ans.push_back(s);
        return;
    }
    char mx = 'a';
    for(auto ss : s) mx = max(mx, ss);
    for(char c = 'a'; c <= mx + 1; c++){
        dfs(s+c);
    }
}

int main(){
    cin >> N;
    dfs("a");
    sort(ans.begin(),ans.end());
    for(auto q : ans) cout << q << endl;
    return 0;
}


Measured memory_bytes: 9588
#include<iostream>
#include<stdlib.h>
using namespace std;

int main()
{
    int n,ans=0;
    cin>>n;
    int a[10000];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        if(a[i]%2==0){
            ans++;
            a[i]/=2;
            i--;
        }
    }
    cout<<ans;
    return 0;
}


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

void trace(int A[], int N) {
	for (int i = 0; i < N; i++) {
		if(i>0){
			cout << " ";
		}
		cout << A[i];
	}
	cout << endl;
}

void insertionSort(int A[], int N){
	int v;
	for (int i=1; i < N; i++) {
		v = A[i];
		int j = i - 1;
		while (j >= 0 && A[j] > v) {
			A[j + 1] = A[j];
			j--;
		}
		A[j + 1] = v;
		trace(A, N);
	}
}

int main()
{
	int i,N,A[100];
	cin >> N;
	for (i = 0; i < N; i++) {
		cin >> A[i];
	}
	trace(A, N);
	insertionSort(A, N);
	return 0;
}

Measured memory_bytes: 3104
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

H, W = getNM()
maze = []
for i in range(H):
    a = getList()
    maze.append(a)

ans = []

# 部屋の掃除の要領で奇数の1を右端に運ぶ
for i in range(H):
    for j in range(W - 1):
        if maze[i][j] % 2 == 1:
            maze[i][j] -= 1
            maze[i][j + 1] += 1
            ans.append([i + 1, j + 1, i + 1, j + 2])

# 右端の1を右下に運ぶ
for i in range(H - 1):
    if maze[i][-1] % 2 == 1:
        maze[i][-1] -= 1
        maze[i + 1][-1] += 1
        ans.append([i + 1, W, i + 2, W])

print(len(ans))
for i in ans:
    print(*i)

Measured memory_bytes: 69724
#include <iostream>
#include <string>
#include <cmath>

int main()
{
	int n;
	std::string s;
	std::cin >> n >> s;
	int max = 0;
	for (int i = 0; i < n - 1; i++)
	{
		int cnt = 0;
		std::string buff = "";
		for (int j = 0; j <= i; j++)
		{
			for (int k = i + 1; k < n; k++)
			{
				if (buff.find(s[k]) != std::string::npos)
					continue;
				if (s[j] == s[k])
				{
					buff += s[k];
					cnt++;
				}
			}
		}
		if (cnt > max)
			max = cnt;
	}
	std::cout << max << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define itrep(it, a) for(it = (a).begin(); it != (a).end; it++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
#define INF (1 << 30)
using namespace std;

int main(){
    string a, b;
    while(cin >> a >> b, a[0] - '0'|| b[0] - '0'){
        int result[2] = {0};
        map<char, int> blow;
        rep(i,4){
            blow[a[i]]++;
        }
        rep(i,4){
            result[0]+=blow[b[i]];
            if(a[i] == b[i]) result[1]++;
        }
        cout << result[1] << ' ' << result[0] - result[1] << endl;
    }
}

Measured memory_bytes: 1188
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(){
    int N, R, G, B;
    int r, g, b;
    int count = 0;
    scanf("%d %d %d %d", &R, &G, &B, &N);
    for(r=0; r<=N/R; r++){
        for(g=0; g<=(N-r*R)/G; g++){
            if( (N-r*R-g*G) % B == 0 ){
                count++;
            }
        }
    }
    printf("%d", count);
}

Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>
#define max(a,b) ((a)>(b) ? (a):(b))
int dp[1001][1001];
int lcs(char *s,char *t){
    int i,j,ls,lt;

    ls=strlen(s);
    lt=strlen(t);
    for(i=0;i<ls;i++){
	for(j=0;j<lt;j++){
	    if(s[i]==t[j]) dp[i+1][j+1]=dp[i][j]+1;
	    else dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1]);
	}
    }
    return dp[ls][lt];
}
int main(void){
    char s[1001],t[1001];
    int k;

    scanf("%d",&k);
    while(k--){
	scanf("%s%s",s,t);
	printf("%d\n",lcs(s,t));
    }

    return 0;
}



Measured memory_bytes: 5636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll mod = 1e9+7;
#define rep(i,n) for(int i = 0;i<n;i++)

int main(){
	int n;
	cin >> n;
	vector<ll> a(n);
	ll xorsum = 0;
	rep(i,n){
		cin >> a[i];
		xorsum ^= a[i]; 
	}
	rep(i,n){
		cout << (a[i] ^ xorsum) << endl;
	}

	return 0;
}

Measured memory_bytes: 4752
H, N = map(int, input().split())
AB = [0] * N
for i in range(N):
    AB[i] = list(map(int, input().split()))

m = 10**4 + 100

dp = [float("INF")] * m

dp[0] = 0

for i in range(H):
    for x in AB:
        if i + x[0] <= H:
            dp[i + x[0]] = min(dp[i + x[0]], dp[i] + x[1])
        else:
            dp[H] = min(dp[H], dp[i] + x[1])

print(dp[H])

Measured memory_bytes: 74328
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#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>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};

struct UF{
    const int node_num;
    vector<int> parent;
    vector<int> size;

    UF(int N) : node_num(N), parent(N), size(N, 1) {
        for(int i = 0; i < N; ++i) parent[i] = i;
    }

    //xの根を得る
    int root(int x){
        if(parent[x] == x) return x;
        return parent[x] = root(parent[x]);
    }

    //xが属する木とyが属する木を一つに合わせる
    void unite(int x, int y){
        int root_x = root(x);
        int root_y = root(y);
        if(root_x == root_y) return;
        parent[root_y] = root_x;
        size[root_x] += size[root_y];
    }

    //xとyが属する木が同じならtrueを返す
    bool same(int x, int y){
        int root_x = root(x);
        int root_y = root(y);
        return root_x == root_y;
    }

    //xと同じ木に属する要素の数を返す
    int same_size(int x){
        int root_x = root(x);
        return size[root_x];
    }
};

int main(){
    Stream io;
    
    int N;
    io.read(N);
    cout << 800 * N - (N / 15) * 200;
    return 0;
}

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

bool cmp(const pair<int, int> &a, const pair<int, int> &b) {
  return a.first < b.first;
}

int main(int argc, char *argv[]) {
  int N, T;
  cin >> N >> T;

  vector<pair<int, int>> v(N);
  for (int i = 0; i < N; ++i) {
    cin >> v[i].first >> v[i].second;
  }

  sort(v.begin(), v.end(), cmp);

  for (int i = 0; i < N; ++i) {
    if (v[i].second <= T) {
      cout << v[i].first << endl;
      return 0;
    }
  }

  cout << "TLE" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main () {
	int w,h,n,x,y,a;
  	int finalX1, finalX2, finalY1, finalY2;
	int finalX, finalY;
  
  std::cin >> w >> h >> n;
 	finalX1 = finalX2 = finalY1 = finalY2 = 0;
 
  for(int i=0; i < n; i++) {
  	std::cin >> x >> y >> a;
    
    if(a == 1) {
      if(x > finalX1) {
	      finalX1 = x;
      }
    } else if (a == 2 ) {
      if(w-x > finalX2) {
	      finalX2 = w-x;
      }
    } else if (a == 3) {
      if(y > finalY1) {
      finalY1 = y;
      }
    } else {
      if(h-y > finalY2) {
	      finalY2 = h-y;
      }
    }
  }
  
  finalX = w - (finalX1 + finalX2);
  finalY = h - (finalY1 + finalY2);

 
  if (finalX <=0 || finalY <= 0) {
  	std::cout << 0 << std::endl;
  } else {
  	std::cout << finalX * finalY << std::endl;
  }
}

Measured memory_bytes: 3648
n = gets.to_i
array = gets.split(" ").map(&:to_i)

def buble(array, n)
    i = 0
    x = 0
    while i < n
        k = array.count-1

        while i < k
            if array[k-1] > array[k] 
                w = array[k]
                array[k] = array[k-1]
                array[k-1] = w
                x += 1
            end
            k -= 1
        
        end
        i += 1
        
    end
    return x
end

ct = buble(array,n)
puts array.join(" ")
puts ct


Measured memory_bytes: 6872
a = list(map(int, input().split()))
a += list(map(int, input().split()))
a += list(map(int, input().split()))

n = int(input())

ans = []
for i in range(n):
    b = int(input())
    if b in a:
        ans.append(a.index(b))

f = -1
if (0 in ans) and (1 in ans) and (2 in ans):
     f = 1

elif (3 in ans) and (4 in ans) and (5 in ans):
     f = 1

elif (6 in ans) and (7 in ans) and (8 in ans):
     f = 1

elif (0 in ans) and (3 in ans) and (6 in ans):
     f = 1

elif (1 in ans) and (4 in ans) and (7 in ans):
     f = 1

elif (2 in ans) and (5 in ans) and (8 in ans):
     f = 1

elif (0 in ans) and (4 in ans) and (8 in ans):
     f = 1

elif (2 in ans) and (4 in ans) and (6 in ans):
     f = 1

print("Yes" if f == 1 else "No")

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include<set>
#include<algorithm>
#include <queue>

using ll =  long long;
#define rep(i,n) for(int i= 0; i< (n); i++)
using namespace std;
using Graph = vector<vector<int>>;

int main(){

    int n;
    cin >> n;
    string ans="No";
    rep(i,10)rep(j,10){
        if(i*j==n){
            ans="Yes";
            cout << ans << endl;
            exit(0);
        }else{
            ans="No";
        }
    }    
    cout << ans << endl;

    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>

int main () {
  int n=1,m=1;
  int j[10000],jc=0;
  int max,tmp;
  while(n>0 and m>0){
    std::cin>>n>>m;
    if(n==0 and m==0) break;
    int s[n];
    max=0;
    for(int i=0;i<n;i++){
      std::cin>>s[i];
    }
    for(int k1=0;k1<n;k1++){
      for(int k2=k1+1;k2<n;k2++){
	tmp=s[k1]+s[k2];
	if(max<tmp and tmp<=m){
	  max=tmp;
	}
      }
    }
    j[jc]=max;
    jc++;
  }
  for(int i=0;i<jc;i++){
    if(j[i]==0){
      std::cout<<"NONE\n";
    }else{
      std::cout<<j[i]<<'\n';
    }
  }

  return 0;
}


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

int main()
{
   int q;
   cin >> q;
   vector<int> l(q), r(q);
   int m = 0;
   rep(i,q)
   {
      cin >> l[i] >> r[i];
      m = max(m, r[i]);
   }
   //mまでの素数をエラトステネスの篩で解く
   vector<bool> isprime(m+1, true);
   vector<ll> sum(m+1,0);
   isprime[0] = isprime[1] = false;
   int cnt = 0;
   for(int i = 2; i <= m; i++)
   {
      if(isprime[i])
      {
         for(int j =2*i; j <= m ;j+=i) isprime[j] = false;
      }
      if(isprime[i] && isprime[(i+1)/2]) sum[i] = sum[i-1] +1;
      else sum[i] = sum[i-1];
   }
  // rep(i,sum.size()) cout << sum[i] << endl;
   rep(k,q)
   {
      cout << sum[r[k]] - sum[l[k]-1] << endl;
   }
}

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

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

	int n, k;
	cin >> n >> k;
	vector<int> pref(n + 1);
	pref[0] = 0;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		pref[i+1] = pref[i] + (x+1);
	}

	int best = 0;
	for (int i = 0; i+k <= n; i++) {
		best = max(best, pref[i+k] - pref[i]);
	}
	cout << fixed << setprecision(20) << double(best) / 2 << '\n';

	return 0;
}


Measured memory_bytes: 1024
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n, k= map(int, input().split())
for i in range(1,k+1):
	if n-k+1>=i:
		t = combinations_count(n-k+1, i) *  combinations_count(k-1, k-i)
		s = t%1000000007
		print(s)
	else:
		print(0)

Measured memory_bytes: 3316
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
INF =  float("inf")
import bisect

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

if K % 2 == 1:
    print((N // K)**3)
else:
    print(((N // (K //2)) - (N // K))** 3 + (N // K)**3)



Measured memory_bytes: 68964
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define RSORT(x) sort((x).rbegin(), (x).rend())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
#define SP << " " <<
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) { a = b; return 1;} return 0;}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) { a = b; return 1;} return 0;}
#define dame {cout<< "-1" <<"\n"; return;}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------
vector<ll> divisors(ll n) {
    vector<ll> res;
    for(ll i = 1; i*i <= n; ++i) {
        if(n % i != 0) continue;
        res.push_back(i);
        if(n/i == i) continue; // 上の行で追加済み。
        res.push_back(n/i);
    }
    SORT(res);
    return res;
}

//--MAIN-----------------------------------
void Main() {
    ll N;
    cin>>N;
    auto divn1=divisors(N-1);
    ll sum=divn1.size()-1;
    auto divn=divisors(N);
    for(auto x: divn){
        if(x==1) continue;
        ll now=N;
        while(now%x==0) now/=x;
        if(now%x==1) ++sum;
    }
    cout<< sum<<"\n";
}

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


Measured memory_bytes: 384
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <iostream> 
#include <iomanip>  
#include <string>
#include <sstream>  
#include <algorithm>
#include <numeric>
#include <complex>
#include <functional>
#include <cstring>
#include <cmath>
#include <cassert>


#define INF              (int)1000000007
#define EPS              1e-9
#define pb               push_back
#define mp               make_pair
#define all(c)           c.begin(), c.end()
#define forall(i,a,b)    for(int i=a;i<(b);++i)
#define trav(a,x)        for(auto & a: x)
#define in(a,b)          ((b).find(a) != (b).end())
#define sz(c)            (int)(c).size()
#define input(a)         for(auto & x : a) cin >> x;

using namespace std;

typedef vector<int>      vi;
typedef pair<int,int>    ii;
typedef vector<vi>       vvi;
typedef vector<ii>       vii;
typedef long long        ll;

#ifdef DEBUG
#define trace(...)       __f(#__VA_ARGS__, __VA_ARGS__)
#define debug(args...)   {dbg,args; clog<<endl;}
#define print_( a )      for( auto & x : a ) clog << x << ' '; clog << '\n';
#define printPair_( a )  for( auto & x : a ) clog << '(' << x.first << ',' << x.second << ')' << ' '; clog << '\n';
#else
#define trace(...)       
#define debug(args...)            
#define print_( a )               
#define printPair_( a )           
#endif

struct debugger {
  template<typename T> debugger& operator , (const T& x) {    
    clog << x << " ";    return *this;    
  }
}dbg;

template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << ": " << arg1 << endl;
}

template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << ": " << arg1 << " | ";
    __f(comma + 1, args...);
}

auto ____ =[]() { std::ios::sync_with_stdio(0); cin.tie(0); return nullptr; }();

int main( int argc, char * argv[] ){
  string str; cin >> str;
  int n = sz(str);
  int cnt = 0;
  forall(i,0,n/2){
    if(str[i] != str[n-i-1]) cnt ++;
  }
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF 100000000
#define EPS 1e-10
#define MOD 1000000007
using namespace std;
typedef pair<int,int> P;

int n;
int f[4][4];
bool dp[400][3][3][7][7][7][7];

void solve(){
	rep(i,400) rep(j1,3) rep(j2,3) rep(k1,7) rep(k2,7) rep(k3,7) rep(k4,7) dp[i][j1][j2][k1][k2][k3][k4] = false;
	bool ok = true;
	rep(i,n){
		rep(j,4) rep(k,4) cin >> f[j][k];
		if(!ok) continue;
		if(i == 0){
			if(f[1][1]+f[1][2]+f[2][1]+f[2][2] > 0){
				ok = false;
				continue;
			}
			dp[0][1][1][1][1][1][1] = true;
			continue;
		}
		rep(j,3) rep(k,3){
			if(f[j][k]+f[j+1][k]+f[j][k+1]+f[j+1][k+1] > 0) continue;
			rep(j1,3) rep(k1,3){
				if(abs(j1-j)>0 && abs(k1-k)>0) continue;
				rep(l1,7) rep(l2,7) rep(l3,7) rep(l4,7){
					if(j==0&&k==0){
						if(l2 == 0 || l3 == 0 || l4 == 0) continue;
						rep(x,7) dp[i][j][k][0][l2][l3][l4] |= dp[i-1][j1][k1][x][l2-1][l3-1][l4-1];
					} else if(j==0&&k==2){
						if(l1 == 0 || l3 == 0 || l4 == 0) continue;
						rep(x,7) dp[i][j][k][l1][0][l3][l4] |= dp[i-1][j1][k1][l1-1][x][l3-1][l4-1];
					} else if(j==2&&k==0){
						if(l1 == 0 || l2 == 0 || l4 == 0) continue;
						rep(x,7) dp[i][j][k][l1][l2][0][l4] |= dp[i-1][j1][k1][l1-1][l2-1][x][l4-1];
					} else if(j==2&&k==2){
						if(l1 == 0 || l2 == 0 || l3 == 0) continue;
						rep(x,7) dp[i][j][k][l1][l2][l3][0] |= dp[i-1][j1][k1][l1-1][l2-1][l3-1][x];
					}else {
						if(l1 == 0 || l2 == 0 || l3 == 0 || l4 == 0) continue;
						dp[i][j][k][l1][l2][l3][l4] |= dp[i-1][j1][k1][l1-1][l2-1][l3-1][l4-1];
					}
				}
			}
		}
		bool yes = false;
		rep(j,3) rep(k,3) rep(l1,7) rep(l2,7) rep(l3,7) rep(l4,7) if(dp[i][j][k][l1][l2][l3][l4]) yes = true;
		if(!yes){
			ok = false;
			continue;
		}
	}
	if(!ok) puts("0");
	else puts("1");
}

int main(){
	while(cin >> n){
		if(n == 0) break;
		solve();
	}
}

Measured memory_bytes: 9560
#include <stdio.h>

int main()
{
    int i, n, F[50];
    F[0] = 1, F[1] = 1;
    scanf("%d", &n);
    for(i=2; i<=n; ++i)
        F[i] = F[i-1]+F[i-2];
    printf("%d\n", F[n]);
    return 0;
}


Measured memory_bytes: 2764
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,m = LI()
a = LI()
if sum(a) <= n:
    print(n-sum(a))
else:
    print(-1)

Measured memory_bytes: 68216
/*
 * src.cpp
 *
 *  Created on: 2016/07/31
 *      Author: joi
 */

#include <bits/stdc++.h>

using namespace std;

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

const int MAX_N=1e5;

int N,M;

int cnt[MAX_N];
bool flg[MAX_N];

int main(){
	scanf("%d %d",&N,&M);
	fill(cnt,cnt+N,1);
	fill(flg,flg+N,false);
	flg[0]=true;
	REP(i,M){
		int x,y;
		scanf("%d %d",&x,&y);
		x--;
		y--;
		if (flg[x]){
			flg[y]=true;
		}
		if (--cnt[x]==0){
			flg[x]=false;
		}
		cnt[y]++;
	}
	int ans=0;
	REP(i,N){
		if (flg[i]){
			ans++;
		}
	}
	printf("%d\n",ans);
	return 0;
}




Measured memory_bytes: 768
#include <bits/stdc++.h> // Tomasz Nowak
using namespace std;     // XIII LO Szczecin
using LL = long long;
#define REP(i, n) for(int i = 0; i < (n); ++i)

constexpr int mod = int(1e9) + 7;

int add(int a, int b, int m) {
	a += b;
	return a >= m ? a - m : a;
}
int& add_to(int &a, int b, int m) {
	a += b;
	if(a >= m)
		a -= m;
	return a;
}

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

	string k;
	int d;
	cin >> k >> d;

	vector<int> dp(d), prev_dp(d);
	int curr_sum = 0;
	REP(i, int(k.size())) {
		fill(dp.begin(), dp.end(), 0);
		REP(sum, d)
			REP(last, 10)
				add_to(dp[add(sum, last % d, d)], prev_dp[sum], mod);
		int digit = int(k[i] - '0');
		REP(c, digit)
			add_to(dp[add(curr_sum, c % d, d)], 1, mod);
		add_to(curr_sum, digit % d, d);
		prev_dp = dp;
	}
	cout << add(dp[0], mod - 1 + (curr_sum % d == 0), mod) << '\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back     
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN
using namespace std;
const ll mod=1e9+7;         
const int N=1e5+4;
int main()                  
{
    int k,x;
    scn(k);scn(x);
    for(int i=x-k+1;i<=x+k-1;i++)
    printf("%d ",i);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fi first
#define se second
int main(){
    int arr[3][3];
    for (int i=0; i<3; i++){
        for (int j=0; j<3; j++){
            cin>>arr[i][j];
        }
    }
    int a;
    cin>>a;
    int tar;
    for (int i=0; i<a; i++){
        cin>>tar;
        for (int i=0; i<3; i++){
            for (int j=0; j<3; j++){
                if (arr[i][j]==tar) arr[i][j]=-1;
            }
        }
    }
    int key;
    for (int i=0; i<3; i++){
        key=1;
        for (int j=0; j<3; j++){
            if (arr[i][j]!=-1) key=0;
        }
        if (key==1){
            cout<<"Yes\n";
            return 0;
        }
    }
    for (int i=0; i<3; i++){
        key=1;
        for (int j=0; j<3; j++){
            if (arr[j][i]!=-1) key=0;
        }
        if (key==1){
            cout<<"Yes\n";
            return 0;
        }
    }
    if (arr[0][0]==-1 && arr[1][1]==-1 && arr[2][2]==-1){
        cout<<"Yes\n";
            return 0;
    }
    if (arr[0][2]==-1 && arr[1][1]==-1 && arr[2][0]==-1){
        cout<<"Yes\n";
            return 0;
    }
    cout<<"No\n";
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};

typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left != NIL){
    x = x->left;
  }
  return x;
}

Node treeMaximum(Node x){
  while(x->right != NIL){
    x = x->right;
  }
  return x;
}

Node treeSearch(Node u, int k){
  
  if(u == NIL || k == u->key) return u;
  if(k < u->key) return treeSearch(u->left, k);
  else return treeSearch(u->right, k);
}

Node treeSuccessor(Node x){
  Node y;
  
  if(x->right != NIL) return treeMinimum(x->right);

  y = x->parent;
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if(z->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z);

  if(y->left != NIL) x = y->left;
  else x = y->right;

  if(x != NIL) x->parent = y->parent;

  if(y->parent == NIL) root = x;
  else if(y == y->parent->left) y->parent->left = x;
  else y->parent->right = x;

  if(y != z) z->key = y->key;

}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;

  if(y == NIL) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;
}

void inorder(Node u){
  if(u != NIL){
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
  }
}
void preorder(Node u){
  printf(" %d", u->key);
  if(u->left!=NIL) preorder(u->left);
  if(u->right!=NIL) preorder(u->right);
}

int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}

Measured memory_bytes: 19364
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>
#include <bitset>
#include<atcoder/all>
 
using namespace std;
 
/* template */
 
using ll = long long;
 
void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif
 
#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
struct Edge{
    int to;
    ll weight;
    Edge(int t, ll w) : to(t), weight(w){ }
};
 
struct edge{
    int from;
    int to;
    ll weight;
    edge(int f,int t,ll w) : from(f), to(t), weight(w){ }
};
 
 
using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;
 
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 <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}
 
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
 
constexpr ll LNF = 1LL<<50;
 
constexpr int INF = 1e9+7;
 
const long double PI=3.14159265358979323846;
 
 
vector<int> dx = {1,0,-1,0};
vector<int> dy = {0,1,0,-1};
 
/* template */

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,q; cin >> n >> q;
    atcoder::dsu uf(n);
    rep(i,0,q){
        int t,u,v; cin >> t >> u >>v;
        if(t==0){
            uf.merge(u,v);
        }
        else{
            cout << uf.same(u,v) << endl;
        }
    }
}

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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  
  vector<int> vec;
  vec = {A, B, C};
  
  int c5 = 0;
  int c7 = 0;
  
  for(int i = 0; i < 3; i++){
   if(vec.at(i) == 5){
     c5++;
   }
  }
  
  for(int i = 0; i < 3; i++){
    if(vec.at(i) == 7){
     c7++;
   }
  }
  if(c5 == 2 && c7 ==1){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
  
  
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath> 
using namespace std;
long long mod=1e9+7;
long long s,ans,res,c[2110][2110];
int main()
{
    cin>>s;
    c[1][1]=c[1][0]=1;
    for(int i=2;i<=2100;i++){
        c[i][0]=1;
        //cout<<1<<endl; 
        for(int j=1;j<=2100;j++){
            c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod;
        }
    } 
    //cout<<1<<endl; 
    if(s==3)ans=1; 
    while(s>=3){
         s-=3;res++; 
         ans=(ans+c[s+res-1][res-1])%mod; //cout<<ans<<endl;
    } 
    cout<<ans<<endl; 
    //system("pause");
    return 0;
}


Measured memory_bytes: 38168
#include <cassert>
#include <climits>
#include <iostream>
#include <vector>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = int(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = int(n) - 1; (i) >= (int)(m); -- (i))
#define ALL(x) begin(x), end(x)
#define dump(x) cerr << #x " = " << x << endl
#define unittest_name_helper(counter) unittest_ ## counter
#define unittest_name(counter) unittest_name_helper(counter)
#define unittest __attribute__((constructor)) void unittest_name(__COUNTER__) ()
using ll = long long;
using namespace std;
template <class T> inline void chmax(T & a, T const & b) { a = max(a, b); }
template <class T> inline void chmin(T & a, T const & b) { a = min(a, b); }
template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }
template <typename T> ostream & operator << (ostream & out, vector<T> const & xs) { REP (i, int(xs.size()) - 1) out << xs[i] << ' '; if (not xs.empty()) out << xs.back(); return out; }

template <typename UnaryPredicate>
int64_t binsearch(int64_t l, int64_t r, UnaryPredicate p) {
    assert (l <= r);
    -- l;
    while (r - l > 1) {
        int64_t m = l + (r - l) / 2;
        (p(m) ? r : l) = m;
    }
    return r;
}

ll solve(int n, ll y, vector<ll> const & x) {
    auto cost1 = [&](int k, ll x_i) {
        if (k == 0) {
            return 5 * x_i + 2 * y;
        } else {
            return (2 * k + 3) * x_i + y;
        }
    };
    auto cost = [&](int z) {
        if (z == 0) return LLONG_MAX;
        ll acc = 0;
        int k = 0;
        int z1 = z;
        REP_R (i, n) {
            if (acc >= 1e18) return LLONG_MAX;
            acc += cost1(k, x[i]);
            -- z1;
            if (z1 == 0) {
                z1 = z;
                ++ k;
            }
        }
        return acc;
    };
    int l = 1, r = n;  // [l, r]
    while (r - l >= 10) {
        int m1 = l + (r - l)     / 3;
        int m2 = l + (r - l) * 2 / 3;
// cerr << l << " " << m1 << " " << m2 << " " << r << endl;
        if (cost(m1) < cost(m2)) {
            r = m2;
        } else {
            l = m1;
        }
    }
    ll ans = LLONG_MAX;
    REP3 (z, l, r + 1) {
        chmin(ans, cost(z));
    }
    return ans;
}

int main() {
    int n; ll y; cin >> n >> y;
    vector<ll> x(n);
    REP (i, n) cin >> x[i];
    cout << solve(n, y, x) << endl;
    return 0;
}


Measured memory_bytes: 1792
n=int(input())

r=list(map(int,input().split()))

if n==2:
  print(abs(r[0]-r[1]))
  exit()
 

#print(r)

temp=sum(r)

goukei=0
for item in r:
  if goukei+item>=temp/2.0:
    
    if abs(temp-goukei-goukei)<=abs((temp-(goukei+item))-(goukei+item)):
      print(abs(temp-goukei-goukei))
    else:
      print(abs((temp-(goukei+item))-(goukei+item)))
    exit()
  goukei=goukei+item
  
goukei=goukei-item
  
print(abs(temp-(goukei-item)))


  





Measured memory_bytes: 87888
#include <complex>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <map>
#include <cmath>
#include <vector>

using namespace std;

typedef long double ldb;
typedef complex<ldb> P;

const ldb eps = 1e-10;
const ldb pi = acos(-1);
int sig(ldb a) {return (a<-eps)?-1:(a>eps)?1:0;}
bool eq(ldb a,ldb b){return abs(a-b)<eps;}
ldb dot(P a, P b) {
  return (a.real() * b.real() + a.imag() * b.imag());
}
ldb cross(P a, P b) {
  return (a.real() * b.imag() - a.imag() * b.real());
}

struct L {
  P a,b;
  L(){}
  L(P a,P b):a(a),b(b){}
  ldb len(){return abs(a-b);}
  P vec(){return b-a;}
};

P iP2(L a,L b) {
  P c = b.b-b.a;
  ldb d1 = abs(cross(c, a.a-b.a));
  ldb d2 = abs(cross(c, a.b-b.a));
  ldb t = d1 / (d1 + d2);
  return a.a + (a.b-a.a) * t;
}

enum CCW{FRONT = 1, RIGHT = 2, BACK = 4, LEFT = 8, ON = 16};
int ccw(L s, P p) {
  P a = s.vec();
  p -= s.a;
  ldb cr = cross(a, p);
  if (eq(cr, 0)) {
    if (sig(dot(a, p)) < 0) return BACK;
    if (sig(norm(a) - norm(p)) < 0) return FRONT;
    return ON;
  }
  return (cr > 0) ? LEFT : RIGHT;
}

bool iI2_1(L a, L b) {
  return ((ccw(a, b.a) | ccw(a, b.b)) & (ccw(b, a.a) | ccw(b, a.b))) == (LEFT | RIGHT);
}

bool cmp(P a,P b)
{
  return make_pair(a.real(),a.imag()) < make_pair(b.real(),b.imag());
}

int main(void)
{
  int n;
  for(;;) {
    scanf("%d",&n); if( n == 0 ) break;
    vector<L> ls;
    int x1,y1,x2,y2;
    int res = 1;
    for( int i = 0; i < n; i++ ) {
      scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
      P a(x1,y1),b(x2,y2);
      L l(a,b);
      int inc = 0;
      vector<P> v;
      for( int j = 0; j < int(ls.size()); j++ ) {
        if( !iI2_1(l,ls[j]) ) continue;
        P c = iP2(l,ls[j]);
        bool ex = false;
        for( int k = 0; k < int(v.size()); k++ ) {
          if( abs(v[k]-c) < eps ) ex = true;
        }
        if( !ex ) {
          v.push_back(c);
          inc += 1;
        }
      }
      res += inc+1;
      ls.push_back(l);
    }
    printf("%d\n",res);
  }
  return 0;
}

Measured memory_bytes: 1068
n,*h=map(int,open(0).read().split())

INF=float("inf")
dp=[INF]*(n)
dp[0]=0

for i in range(1,n):
    if not i-1<0:
        dp[i]=min(dp[i],dp[i-1]+abs(h[i]-h[i-1]))
    if not i-2<0:
        dp[i]=min(dp[i],dp[i-2]+abs(h[i]-h[i-2]))


print(dp[-1])

Measured memory_bytes: 57872
N = int(input())
A = list(map(int,input().split()))
MOD = 10**9 + 7
base = sum(A) % MOD

b = 1
b2 = 1
ans = (base * N) % MOD
for i in range(60):
	s = 0
	k = 0
	for a in A:
		if (a // b) % 2 == 1:
			k -= 1
			s += 1
		else:
			k += 1
	ans = (ans + ((b2 * s * k) % MOD)) % MOD
	b2 = b2 * 2 % MOD
	b = b * 2
# divide 2
ans = (ans * ((MOD + 1) // 2)) % MOD
print(ans)

Measured memory_bytes: 125624
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

class User
{
public:
    int belong_group = -1;
    vector<int> friends;
    vector<int> blocks;
};

int main(void)
{
    vector<int> groups_size;
    vector<User> users;
    int users_count;
    int friends_count;
    int blocks_count;

    cin >> users_count >> friends_count >> blocks_count;

    users.resize(users_count);

    for(int i = 0; i < friends_count; i++){
        int user, fri;
        cin >> user >> fri;

        users[user - 1].friends.push_back(fri - 1);
        users[fri - 1].friends.push_back(user - 1);
    }

    for(int j = 0; j < blocks_count; j++){
        int user, blo;
        cin >> user >> blo;

        users[user - 1].blocks.push_back(blo - 1);
        users[blo - 1].blocks.push_back(user - 1);
    }

    bool *searched_users = new bool[users_count];
    bool *found_users = new bool[users_count];
    for(int i = 0; i < users_count; i++){
        searched_users[i] = false;
        found_users[i] = false;
    }

    queue<int> search_que;
    int group_count = 0;
    for(int i = 0; i < users_count; i++){
        int group_size = 0;
        if(users[i].belong_group == -1){
            found_users[i] = true;
            search_que.push(i);
        }

        while(!search_que.empty()){
            int searching = search_que.front();
            search_que.pop();

            searched_users[searching] = true;
            users[searching].belong_group = group_count;

            group_size += 1;
            for(int i = 0; i < users[searching].friends.size(); i++){
                int friend_num = users[searching].friends[i];

                if(!found_users[friend_num]){
                    search_que.push(friend_num);
                    found_users[friend_num] = true;
                }
            }
        }
        if(group_size > 0){
            groups_size.push_back(group_size);
            group_count += 1;
        }
    }

    for(int i = 0; i < users_count; i++){
        int belong_num = users[i].belong_group;
        int group_blocked = 0;
        for(int j = 0; j < users[i].blocks.size(); j++){
            if(users[users[i].blocks[j]].belong_group == belong_num){
                group_blocked += 1;
            }
        }

        cout << groups_size[belong_num] - users[i].friends.size() - group_blocked - 1 << endl;
    }
}

Measured memory_bytes: 13176
import java.io.*;

public class Main {

	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		String[] strargs = new String[3];
		long[][] A = null;
		long[][] B = null;
		long[][] C = null;
		
		strargs = br.readLine().split("\\s+");
		
		int n = Integer.parseInt(strargs[0]);
		int m = Integer.parseInt(strargs[1]);
		int l = Integer.parseInt(strargs[2]);
		
		if ((1 <= n && n <= 100) && (1 <= m && m <= 100) && (1 <= l && l <= 100)) {
			A = new long[n][m];
			B = new long[m][l];
			C = new long[n][l];
			
			for (int i = 0; i < n; i++) {
				strargs = br.readLine().split("\\s+");
				for (int j = 0; j < m; j++) A[i][j] = Long.parseLong(strargs[j]);
			}
			
			for (int i = 0; i < m; i++) {
				strargs = br.readLine().split("\\s+");
				for (int j = 0; j < l; j++) B[i][j] = Long.parseLong(strargs[j]);
			}
			
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < l; j++) {
					for (int k = 0; k < m; k++) {
						C[i][j] += A[i][k] * B[k][j];
					}
				}
			}
			
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < l; j++) {
					sb.append(C[i][j]);
					if (j != (l - 1)) sb.append(" ");
				}
				if(i != (n - 1)) sb.append("\n");
			}
			
			System.out.println(sb);
		}
	}
}

Measured memory_bytes: 33652
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

// #define endl            "\n"
#define forn(i,x1,n)     for(int i=x1; i<n; i++)
#define forit(it, m)    for(decltype(m)::iterator it = m.begin(); it!=m.end(); ++it)
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x1)      __builtin_popcountll(x1)
#define zrobits(x1)      __builtin_ctzll(x1)
#define mod             1000000007
#define inf             1e18
#define ps(x1,y)         fixed<<setprecision(y)<<x1
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x1)            int x1; cin>>x1; while(x1--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());


void zeus()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

int n;
vector<int> h;
int memo[100005];
int solve(int i) {
    if (i == n) {
        return 0;
    }
    if (i == n - 1) {
        return abs(h[n] - h[n - 1]);
    }
    if (memo[i] != -1) {
        return memo[i];
    }
    memo[i] = INT_MAX;

    memo[i] = min(abs(h[i + 1] - h[i]) + solve(i + 1), abs(h[i + 2] - h[i]) + solve(i + 2));

    return memo[i];
}

int32_t main() {

    zeus();
    cin >> n;

    vector<int> x(n + 1);
    memset(memo, -1, sizeof memo);
    forn(i, 1, n + 1) {
        cin >> x[i];
    }
    h = x;

    cout << solve(1) << endl;






}








Measured memory_bytes: 7916
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
    
using namespace std;    
typedef long long ll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

int main(){

    ll x, y, z;
    cin >> x >> y >> z;

    ll cnt = 0;
    while(true){
        if( (cnt + 1) * z + cnt * y <= x){
            cnt ++;
        }
        else{
            break;
        }
    }
    cout << cnt - 1 << endl;
}

Measured memory_bytes: 256