akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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

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

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

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


template <typename T>
T amarinasi(T a,T b){
    if(a%b==0)
{
    return a/b;
}
else if(a%b>0)
{
    return a/b+1;
}
else
{
    return a/b-1;
}
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

//----------------------------------------------------------------

int main(){
ll a,b,c,d;
cin>>a>>b>>c>>d;
if(fabs(c-a)<=d){
    cout<<"Yes"<<endl;
}
else if(fabs(a-b)<=d&&fabs(c-b)<=d){
    cout<<"Yes"<<endl;
}
else{
    cout<<"No"<<endl;
}
}










Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n, x int
	fmt.Scanf("%d", &n)
	fmt.Scanf("%d", &x)

	ls := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &ls[i])
	}

	d := 0
	ans := 1
	for _, l := range ls {
		d += l
		if d > x {
			break
		}
		ans++
	}
	fmt.Println(ans)
}


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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a;
  a.resize(n);
  rep(i, n) { cin >> a.at(i); }
  // sort(a.begin(), a.end(), greater<int>());
  sort(a.begin(), a.end());
  ll ans = 0;
  rep(i, n - k) { ans += a.at(i); }
  cout << ans << endl;
}


Measured memory_bytes: 1152
#include<iostream>
#include<vector>
using namespace std;
#define int long long
#define V vector
#define vel V<int>
#define rep(i,n) for(int i=0;i<n;i++)
#define mkp make_pair
#define pin pair<int,int>
pin solve(V<pin>& ab, int ex) {
	if (!ex) { return mkp(0, 0); }
	V<V<pin>> qab(2);
	int sz = ab.size();
	qab[0].reserve(sz);
	qab[1].reserve(sz);
	for (pin& x : ab) {
		qab[x.second & 1].push_back(mkp(x.first>>1, x.second>>1));
		if (x.first & 1) { qab[(x.second + 1) & 1].push_back(mkp(x.first>>1, (x.second + 1)>>1)); }
	}
	int c = 0;
	for (pin& x : qab[0]) {
		c ^= ((2 * x.first + x.second)%3+1);
	}
	if (!c) {
		pin ans = solve(qab[1], ex - 1);
		ans.first *= 2; ans.second *= 2; ans.second++;
		return ans;
	}
	pin ans = solve(qab[0], ex - 1);
	c = 0;
	int d = 0;
	for (pin& x : qab[1]) {
		int w = ans.second - x.second - 1;
		if ((w & x.first) == w) { c ^= 1; }
		w++;
		if ((w & x.first) == w) { d ^= 1; }
	}
	ans.first *= 2; ans.second *= 2;
	ans.first += (c | d); ans.second -= c;
	return ans;
}
signed main() {
	cin.tie(0); ios::sync_with_stdio(false);
	long long inf = 1e17;
	int n; cin >> n;
	V<pin> ab(n);
	rep(i, n) {
		long long a, b; cin >> a >> b;
		ab[i] = { a + inf,b + inf };
	}
	pin ret = solve(ab, 59);
	cout << ret.first - inf << " " << ret.second - inf << "\n";
}

Measured memory_bytes: 7552
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
 


public class Main {
	private static Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	static long mod =1000000007;
	//static 	ArrayList<Integer> cc = new ArrayList<>(100);
	public static void main(String[] args) {
		int N=sc.nextInt();
		
		ArrayList<Integer> cc = new ArrayList<>(N);

		int sum=0;
		for(int i=0;i<N;i++) {
			cc.add(sc.nextInt());
			sum+=cc.get(i);
		}
		
		
		Collections.sort(cc);
		
		
		if(sum%10==0) {
			int a=0;
			int i=cc.get(a);
			while(i%10==0) {
				a++;
				if(a==cc.size()) {
					i=sum;
					break;
				}
				i=cc.get(a);
			}
			sum-=i;
			
		}
		p(sum);
		
		
		
		
	}
	
	
	
	
	/*static boolean v(int i,long sum1,long sum2) {
		if(i==N) {
			long b=Math.abs(sum1-sum2);
			if(b==0) {
				if(sum1<=K) {
					return true;
				}else return false;
			}else if(b%D==0) {
				if(Math.max(sum1, sum2)<=K)return true;
				else return false;
			}
			else return false;
		}
		
		if(v(i+1,sum1,sum2+v[i]%D))return true;
		
		if(v(i+1,sum1+D-v[i]%D,sum2))return true;
		return false;
		
	}*/
	
	
	
	
	

	


	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	public static int gcd(int a, int b) {
        return b == 0 ? a: gcd(b, a % b);
	}
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
}
	


Measured memory_bytes: 23508
/**
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

#include <bits/stdc++.h>
using namespace std;

#define DEBUG
#ifndef DEBUG
#define endl "\n"
#endif

const double PI = 3.1415926535897932384626433;
typedef long long ll;
#define fori(n) for(ll i=0; i<(n); i++)

#define cins(s) string s; cin>>s;
#define cini(i) int i; cin>>i;
#define cinll(l) ll l; cin>>l;
#define cind(d) double d; cin>>d;
#define cinai(a, n) vi a(n); fori(n) { cin>>a[i]; }
#define cinall(a, n) vll a(n); fori(n) { cin>>a[i]; }
#define cinas(s, n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a, n) vd a(n); fori(n) { cin>>a[i]; }

typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<string> vs;
typedef vector<ll> vll;

void solve() {
	cini(n);
	cins(s);
	cins(t);
	string ans;
	for (int i = 0; i < n; i++) {
		ans += s[i];
		ans += t[i];
	}
	cout << ans << endl;

}

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



Measured memory_bytes: 256
use std::io::prelude::*;

fn input<T: std::str::FromStr>() -> T {
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let s: String = input();
    let t: String = input();

    let slen = s.len();
    let tlen = t.len();
    let mut u = t.clone();
    while u.len() < slen + 2 * tlen {
        u.push_str(&s);
    }

    let rh = RollingHash::new(&u);
    let mut succ = vec![slen; slen];
    let mut pred = vec![0; slen];
    for i in 0..slen {
        if rh.is_same(0, tlen, tlen + i, 2 * tlen + i) {
            let j = (i + tlen) % slen;
            succ[i] = j;
            pred[j] += 1;
        }
    }

    let mut dist = vec![-1; slen];
    let mut q = std::collections::VecDeque::new();
    for i in 0..slen {
        if pred[i] == 0 {
            dist[i] = 0;
            q.push_back(i);
        }
    }
    while let Some(i) = q.pop_front() {
        if succ[i] == slen {
            continue;
        }
        let j = succ[i];
        pred[j] -= 1;
        dist[j] = dist[i] + 1;
        if pred[j] == 0 {
            q.push_back(j);
        }
    }

    let mut ok = true;
    let mut ans = 0;
    for i in 0..slen {
        if dist[i] < 0 {
            ok = false;
            break;
        }
        ans = std::cmp::max(ans, dist[i]);
    }

    println!("{}", if ok { ans } else { -1 });
}

struct RollingHash {
    hash: Vec<Vec<i64>>,
    power: Vec<Vec<i64>>,
}

impl RollingHash {
    fn modulus() -> [i64; 3] {
        [1000000007, 1000000009, 1234567891]
    }

    fn radix() -> [i64; 3] {
        [1007, 1009, 1013]
    }

    fn new<S: AsRef<str>>(s: S) -> RollingHash {
        let s = s.as_ref().as_bytes();
        let m = RollingHash::modulus();
        let r = RollingHash::radix();
        let n = s.len();
        let mut h = vec![vec![0; n + 1]; m.len()];
        let mut p = vec![vec![0; n + 1]; m.len()];
        for i in 0..m.len() {
            h[i][0] = 0;
            p[i][0] = 1;
            for j in 0..n {
                h[i][j + 1] = (h[i][j] * r[i] + s[j] as i64) % m[i];
                p[i][j + 1] = p[i][j] * r[i] % m[i];
            }
        }
        RollingHash { hash: h, power: p }
    }

    fn hash(&self, i: usize, start: usize, end: usize) -> i64 {
        let m = RollingHash::modulus();
        let mut r = self.hash[i][end] - self.hash[i][start] * self.power[i][end - start] % m[i];
        if r < 0 {
            r += m[i];
        }
        r
    }

    fn is_same(&self, start1: usize, end1: usize, start2: usize, end2: usize) -> bool {
        if end1 - start1 != end2 - start2 {
            false
        } else {
            let mlen = RollingHash::modulus().len();
            let mut ok = true;
            for i in 0..mlen {
                if self.hash(i, start1, end1) != self.hash(i, start2, end2) {
                    ok = false;
                }
            }
            ok
        }
    }
}


Measured memory_bytes: 123132
s=input()
K=int(input())
slist=[]
c=len(s)
if c < 5:
    d = c
else:
    d = 5
for i in range(len(s)):
    for j in range (i,i+d+1):
        slist.append(s[i:j+1])
sset=set(slist)
slist=list(sset)
slist.sort()
print(slist[K-1])

Measured memory_bytes: 5428
#include<bits/stdc++.h>
using namespace std;
double min(double x, double y) 
{ 
	return (x < y)? x: y; 
	
} 
const double pi = std::acos(-1);
double calcAngle(int h, int m) 
{ 

	if (h == 12) h = 0; 
	if (m == 60) m = 0;  
	double hour_angle = 0.5 * double(h * 60 + m); 
	double minute_angle =double (6 * m); 

	double angle = abs(hour_angle - minute_angle); 

	angle = min(360 - angle, angle); 

	return angle; 
} 
main()
{
    int a,b,h,m;
    cin>>a>>b>>h>>m;
    double x=calcAngle(h,m);
    double side3;
    double ang=(pi/180)*x;
    int y=a*a+b*b;
    double z=double(y)-double(cos(ang)*2*a*b);
    double m1=sqrt(z);
    std::cout << std::fixed;
    std::cout << std::setprecision(20);
    std::cout << m1<<endl;


    
    
    
    
}

Measured memory_bytes: 4164
package main

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

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

type intSlice []int

func (s intSlice) max() int {
	result := s[0]
	for i := 1; i < len(s); i++ {
		result = max(result, s[i])
	}
	return result
}

func (s intSlice) fill(x int) {
	for i := 0; i < len(s); i++ {
		s[i] = x
	}
}

func main() {
	N := readInt()
	W := readInt()

	dp := make(intSlice, W+1)
	dp.fill(-1)
	dp[0] = 0

	for i := 0; i < N; i++ {
		w := readInt()
		v := readInt()
		for j := W - w; j >= 0; j-- {
			if dp[j] == -1 {
				continue
			}
			dp[j+w] = max(dp[j+w], dp[j]+v)
		}
	}
	fmt.Println(dp.max())
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}


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

int main(){
  char S[4];
  char A[] = "ABC";
  
  scanf("%s",S);
  
  if(strcmp(S,A) == 0) printf("ARC\n");
  else printf("ABC\n");
  
  return 0;
}

Measured memory_bytes: 1664
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<sstream>
#include<cmath>
using namespace std;
#define REP(i, j) for(double i = 0; i < j; i++)
#define FOR(i, j, k) for(double i = j; i < k; i++)

class die{
  public:
    int t, b, n, s, w, e;
    die(int _t, int _b, int _n, int _s, int _w, int _e){
      t = _t; b = _b; n = _n; s = _s; w = _w; e = _e;
    }
    void north(){
      int nt, nb, nn, ns, nw, ne;
      nt = s;
      nb = n;
      nn = t;
      ns = b;
      nw = w;
      ne = e;
      t = nt; b = nb; n = nn; s = ns; w = nw; e = ne;
    }
    void south(){
      int nt, nb, nn, ns, nw, ne;
      nt = n;
      nb = s;
      nn = b;
      ns = t;
      nw = w;
      ne = e;
      t = nt; b = nb; n = nn; s = ns; w = nw; e = ne;
    }
    void west(){
      int nt, nb, nn, ns, nw, ne;
      nt = e;
      nb = w;
      nn = n;
      ns = s;
      nw = t;
      ne = b;
      t = nt; b = nb; n = nn; s = ns; w = nw; e = ne;
    }
    void east(){
      int nt, nb, nn, ns, nw, ne;
      nt = w;
      nb = e;
      nn = n;
      ns = s;
      nw = b;
      ne = t;
      t = nt; b = nb; n = nn; s = ns; w = nw; e = ne;
    }
};

int main(){
  int n;
  while(cin >>n && n){
    die d(1, 6, 2, 5, 3, 4);
    REP(i, n){
      string str;
      cin >>str;
      if(str == "north") d.north();
      else if(str == "south") d.south();
      else if(str == "west") d.west();
      else if(str == "east") d.east();
    }
    cout <<d.t <<endl;
  }
  return 0;
}

Measured memory_bytes: 1212
#include<bits/stdc++.h>
using namespace std;
bitset<4001000> dp;
int n,ma,tot;
int main(){
	scanf("%d",&n);
	dp|=1;
	for(int i=0,a;i<n;i++){
		scanf("%d",&a);
		ma=max(a,ma);
		tot+=a;
		dp=(dp<<a)|dp;
	}
	if(ma>=tot-ma) printf("%d\n",ma);
	else{
		for(int i=(tot+1)/2;;i++){
			if(dp.test(i)){
				printf("%d\n",i);
				break;
			}
		}
	}
	return 0;
}

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

int main(){
  int i, n;
  cin >> n;
  int a[n];
  int b = 0, c = 0;
  for(i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n, greater<int>());
  for(i = 0; i < n; i++){
    if(i % 2 == 0){
      b += a[i];
    }else{
      c += a[i];
    }
  }
  cout << b - c << endl;
}


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

int n;
long ans;

int main() {
    cin >> n;
    vector<P> v(n); // sum, aoki
    rep(i, n) {
        cin >> v[i].first >> v[i].second;
        v[i].first += v[i].second;
    }
    sort(v.begin(), v.end(), greater<P>());
    bool first = true;
    rep(i, n) {
        if (first) {
            ans += v[i].first - v[i].second;
            first = false;
        } else {
            ans -= v[i].second;
            first = true;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1152
import java.util.*;

public class Main {
    public static void main(String[] args) {
        boolean[] dp = genTable();
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int ans = (dp[x]) ? 1 : 0;
        System.out.println(ans);
    }

    static boolean[] genTable() {
        boolean[] dp = new boolean[100005];
        for(int i = 0, f = dp.length; i < f; ++i) {
            if(i == 0) dp[i] = true;
            else if(i < 100) dp[i] = false;
            else if(dp[i - 100] || dp[i - 101] || dp[i - 102] || dp[i - 103] || dp[i - 104] || dp[i - 105]) dp[i] = true;
            else dp[i] = false;
        }
        return dp;
    }
}

Measured memory_bytes: 23508
#include <stdio.h>
#include <stdlib.h>
long long int min(long long int a, long long int b) { return a < b ? a : b; }
long long int max(long long int a, long long int b) { return a > b ? a : b; }
void swap(long long int *a, long long int *b) {
	long long int tmp = *a;
	*a = *b;
	*b = tmp;
}

int main(void) {
	long long int H, W, i, tmp, ans;
	scanf("%lld%lld", &H, &W);

	ans = H * W;
	if (H % 3 == 0 || W % 3 == 0) {
		printf("0\n");
		return 0;
	}
	if (H == 1 || W == 1) {
		printf("0\n");
		return 0;
	}

	for (i = 1; i < W / 2 + 1; i++) {
		if (H % 2 == 0)
			tmp = llabs(i * H - H / 2 * (W - i));
		else 
			tmp = max(llabs(i * H - H / 2 * (W - i)), llabs(i * H - (H / 2 + 1) * (W - i)));
		ans = min(tmp, ans);
	}
	ans = min(H, ans);
	
	swap(&H, &W);
	for (i = 1; i < W / 2 + 1; i++) {
		if (H % 2 == 0)
			tmp = llabs(i * H - H / 2 * (W - i));
		else 
			tmp = max(llabs(i * H - H / 2 * (W - i)), llabs(i * H - (H / 2 + 1) * (W - i)));
		ans = min(tmp, ans);
	}
	ans = min(H, ans);

	printf("%lld\n", ans);
	return 0;
}

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

using namespace std;
typedef pair<int, int> pii;

vector<pii> v;

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

    for (int i = 0; i < n; i++) {
        int a, b;
        scanf("%d %d", &a, &b);
        v.push_back(pii(-b, a));
    }

    sort(v.begin(), v.end());
    
    cout << v[0].second << " " << -v[0].first << endl;

    return 0;
}


Measured memory_bytes: 3208
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
bool sosu[1299710];
void SOSU(){
  memset(sosu,false,sizeof(sosu));
  for(int i=2;i<1299710;i++){
    if(sosu[i]==false){
      for(int j=2;i*j<1299710;j++){
	sosu[i*j]=true;
      }
    }
  }
}
int main(){
  int n,sum,lI,lII;
  SOSU();
  while(1){
    sum=0;
    cin >> n;
    if(n == 0) break;
    for(lI=n;sosu[lI]==true && lI>=2;lI--);
    for(lII=n;sosu[lII]==true;lII++);
    cout << lII-lI << endl;
  }
}

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

#define ONLINE_JUDGE
#define pb(a) push_back(a)
#define all(a) (a.begin(), a.end())

using ll = long long;

const int E5 = 1e5;

//////////// Solution /////////////////////////////////

int n,m;

void solve() {
	scanf("%d %d", &n, &m);
	map<int,char*> id;
	map<int,vector<pair<int,int>>> mp;
	for (int i = 0; i < m; ++i) {
		int p,y;
		scanf("%d %d", &p, &y);
		if (!mp.count(p)) {
			vector<pair<int,int>> vec;
			mp.insert(make_pair(p,vec));
		}
		mp[p].pb(make_pair(y,i+1));
	}

	for (auto &par : mp) {
		sort(par.second.begin(),par.second.end());
	}

	for (auto par : mp) {
		vector<pair<int,int>> vec = par.second;
		for (size_t i = 0; i < vec.size(); ++i) {
			char ch_id[13],buf[7];
			sprintf(buf,"%06d",par.first);
			for (int i = 0; i < 6; ++i)
				ch_id[i] = buf[i];
			sprintf(buf,"%06d",(int)i+1);
			for (int i = 0; i < 6; ++i) {
				ch_id[i+6] = buf[i];
			}
			ch_id[12] = '\0';
			char* ch = new char[13];
			strcpy(ch,ch_id);
			id.insert(make_pair(vec[i].second,ch));
		}
	}

	for (auto par : id) {
		printf("%s\n", par.second);
	}
}	

/////////// End Solution ///////////////////////////////////////

//////// Initialization ////////////////////////////////////

int main() {

	#ifndef ONLINE_JUDGE
	FILE *FIN = freopen("/home/danil/prog/input.txt", "r", stdin);
	clock_t time_start = clock();
	#endif

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

	solve();

	#ifndef ONLINE_JUDGE
	fclose(FIN);
	cerr << "\x1b[031m\n-----------------\nTime=" << (ll)((double)(clock()-time_start) / CLOCKS_PER_SEC * 1000) << "ms\n\x1b[0m";
	#endif

	return 0;
}

//////// End Initialization ///////////////////////////////////////

Measured memory_bytes: 21760
a,b=map(int,input().split())

while b!=0:
  a,b=b,a%b

n=a
s=set()
s.add(1)

while n%2==0:
  n //= 2
  s.add(2)

f=3
while f*f<=n:
  if n%f==0:
    n //= f
    s.add(f)
  else:
    f += 2

if n!=1:
  s.add(n)

print(len(s))


Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
  
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
  
int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};

class State {
public:
  vector<char> nums;
  int cost;
  bool operator <(const State& s) const {
    return cost < s.cost;
  }
  bool operator >(const State& s) const {
    return cost > s.cost;
  }
  State(const vector<char>& n,int c) {
    nums = n;
    cost = c;
  }
};

int bfs(const vector<char>& init,
        map<vector<char>,int>& dp,int limit = 4){
  priority_queue<State,vector<State>,greater<State> > que;
  que.push(State(init,0));
  dp[init] = 0;

  while(!que.empty()){
    State s = que.top();
    que.pop();
    if(s.cost >= limit) continue;
    for(int lhs = 0; lhs < s.nums.size(); lhs++){
      for(int rhs = lhs + 1; rhs <= s.nums.size(); rhs++){
        reverse(s.nums.begin() + lhs,s.nums.begin() + rhs);
        
        if(dp.find(s.nums) != dp.end()){
          reverse(s.nums.begin() + lhs,s.nums.begin() + rhs);
          continue;
        }

        dp[s.nums] = s.cost + 1;
        que.push(State(s.nums,s.cost+ 1));
        reverse(s.nums.begin() + lhs,s.nums.begin() + rhs);
      }
    }
  }
}

int main(){
  int N;
  while(~scanf("%d",&N)){
    vector<char> nums;
    for(int i=0; i < N; i++){
      int num;
      scanf("%d",&num);
      nums.push_back(num);
    }
    map<vector<char>,int> start;
    bfs(nums,start);

    map<vector<char>,int> goal;
    sort(nums.begin(),nums.end());
    bfs(nums,goal,4);
    
    int res = 9;
    for(map<vector<char>,int>::iterator it = start.begin();
        it != start.end();
        it++){
      if(goal.find(it->first) != goal.end()){
        res = min(it->second + goal[it->first],res);
      }
    }
    printf("%d\n",res);
  }
}

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

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  vector<int> ans(N);
  for (int i = 1; i <= N; i++)
  {
    for (int j = i + 1; j <= N; j++)
    {
      ans[min(abs(X - i) + 1 + abs(j - Y), j - i)]++;
    }  
  }
  
  for (int i = 1; i < N; i++)
  {
    cout << ans[i] << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3596
#include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
using namespace std;

int main() {

    long n;
    int k;
    cin >> n >> k;

    long a, b;

    while(cin >> a >> b) {
        int res = 9;
        if ( a > n / 2 )    a = n - a + 1;
        if ( b > n / 2 )    b = n - b + 1;

        if ( a >= b )   res = b % 3;    
        else            res = a % 3;


        if ( res == 0 ) res = 3;
        cout << res << endl;

    }
   
     
    return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define fr(i,x,n) for(int i=x;i<=n;i++)
#define rf(i,n,x) for(int i=n;i>=x;i--)
#define mst(x,i) memset(x,i,sizeof(x))
#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define PB push_back
#define X first
#define Y second
#ifdef DBG
#define dbg(x...) do { cout << "\033[32;1m" << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long LL;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int maxn=1E5+5;
const int maxm=1E5+5;
const int inf=0x3f3f3f3f;
const LL INF=0x3f3f3f3f3f3f3f3f;
const LL mod=1E9+7;
const double eps=1E-6;
const double PI=acos(-1.0);
template<class T>
bool scan(T &ret){
    char c;int sgn;
    if(c=getchar(),c==EOF) return 0;
    while(c!='-'&&(c<'0'||c>'9')) c=getchar();
    sgn=(c=='-')?-1:1;
    ret=(c=='-')?0:(c-'0');
    while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0');
    ret*=sgn;
    return 1;
}
template<class T>
T gcd(T a,T b){
    return b==0?a:gcd(b,a%b);
}
template<class T>
T qpow(T a,T b,T mod){
    T ret=1;
    a%=mod;
    while(b){
        if(b&1) ret=(a*ret)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return ret%mod;
}
LL inv[maxn],sum[maxn],fac[maxn];
void init(int n){
    fac[0]=inv[0]=inv[1]=1;
    fr(i,2,n) inv[i]=((mod-mod/i)*inv[mod%i])%mod;
    rep1(i,n) sum[i]=(sum[i-1]+inv[i])%mod,fac[i]=1LL*fac[i-1]*i%mod;
}
void solve(){
    LL n,t;
    cin>>n;
    init(n);
    LL ans=0;
    rep1(i,n){
        cin>>t;
        ans=(ans+t*(sum[i]+sum[n-i+1]-1+mod)%mod)%mod;
    }
    ans=(ans%mod*fac[n]%mod)%mod;
    cout<<ans<<"\n";
}
int main(){
    IOS;
#ifdef LOCAL
    freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    clock_t START_TIME=clock();
#endif
    int T=1;
    //cin>>T;
    while(T--){
        solve();
    }
#ifdef LOCAL
    clock_t END_TIME=clock();
    double time=double(END_TIME-START_TIME)/CLOCKS_PER_SEC;
    cout<<"\nprocess ends in "<<setprecision(4)<<time<<" seconds"<<endl;
#endif
    return 0;
}

Measured memory_bytes: 6012
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
string s="FESTIVAL";
string ans=s;
const ll b=200;
void solve(ll k, int i){
  for(int j=0; j<(k-1)%b; j++){
    ans+=s[i];
  }
  if((k-1)/b>0){
    solve((k-1)/b, i-1);
    for(int j=0; j<b; j++) ans+=s[i];
  }
}
int main()
{
  ll k;
  cin>>k;
  solve(k, 7);
  cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
#define INF ( 1 << 25 )
int N,mas[16][17],dp[1<<16];
int rec(int bit){
  if(dp[bit]) return dp[bit];
  if(bit + 1 == 1 << N) return 0;
  int ret = INF;
  for(int i = 0 ; i < N ; i++ ){
    if(bit & (1 << i)) continue;
    int min_cost = mas[i][0];
    for(int j = 0 ; j < N ; j++ ){
      if(bit & (1 << j)) min_cost = min( min_cost, mas[i][j+1]);
    }
    ret = min( ret, min_cost + rec(bit|(1 << i)));
  }
  return dp[bit] = ret;
}
int main(){
  bool ok = false;
  while(scanf("%d",&N), N ){
    if(ok) for(int i = 0 ; i < 1 << N ; i++ ) dp[i] = 0;
    else ok++;
    for(int i = 0 ; i < N ; i++ ){
      for(int j = 0 ; j <= N ; j++ ){
        scanf("%d",&mas[i][j]);
      }
    }
    printf("%d\n",rec(0));
  }
}

Measured memory_bytes: 1284
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)

bool match(char c, string s)
{
	rep(i, 0, s.length()) if (s[i] == c) return true;
	return false;
}

string op[2] = { "+-", "*/" };

int parse(string s, int &i, int x)
{
	if (x == 2)
	{
		if (s[i] == '(')
		{
			i++;
			int ans = parse(s, i, 0);
			i++;
			return ans;
		}
		else
		{
			int ret = 0;
			while ('0' <= s[i] && s[i] <= '9')
			{
				ret = ret * 10 + s[i] - '0';
				i++;
			}
			return ret;
		}
	}
	else
	{
		int ans = parse(s, i, x + 1);

		while (op[x].find(s[i]) != string::npos)
		{
			switch (s[i])
			{
			case '+': i++; ans += parse(s, i, x + 1); break;
			case '-': i++; ans -= parse(s, i, x + 1); break;
			case '*': i++; ans *= parse(s, i, x + 1); break;
			case '/': i++; ans /= parse(s, i, x + 1); break;
			}
		}

		return ans;
	}
}

int main()
{
	int n; cin >> n;
	rep(_n, 0, n)
	{
		string s; cin >> s;
		int i = 0;
		cout << parse(s, i, 0) << endl;
	}
}

Measured memory_bytes: 3164
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
signed main()
{
    int n;
    cin >> n;
    vector<ld> x(n);
    vector<string> u(n);
    rep(i, n) cin >> x[i] >> u[i];

    long double sum = 0;
    rep(i, n) {
        if (u[i] == "JPY") {
            sum += x[i];
        }
        else {
            sum += x[i] * 380000.0;
        }
    }

    put(sum)
    
    return 0;
}

Measured memory_bytes: 3760
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

int main() {
	int n;
	std::string s;
	std::cin >> n >> s;

	std::vector<bool> v3(1000);
	std::vector<bool> v2(100);
	std::vector<bool> v1(10);
	for (int i = 0; i < n; ++i) {
		const int d = s[i] - '0';

		for (int j = 0; j <= 99; ++j)
			if (v2[j])
				v3[j * 10 + d] = true;

		if (i <= n - 2)
			for (int j = 0; j <= 9; ++j)
				if (v1[j])
					v2[j * 10 + d] = true;

		if (i <= n - 3)
			v1[d] = true;
	}

	std::cout << std::count(v3.begin(), v3.end(), true) << std::endl;
}

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

int main()
{
  int n;
  float ans=0;
  cin >> n;
  
  float x[n];
  string u[n];
  
  for(int i=0;i<n;i++)
  {
    cin >> x[i] >> u[i];
    
    if(u[i]=="JPY")
      ans+=x[i];
    if(u[i]=="BTC")
      ans+=380000.0*x[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll n ,a[102] ,b[102] , c[102] , ans;
int main()
{
   cin >>n;
   a[n-1] = 1e9;
   for (int  i = 0 ; i < n  ;i++)
   {
       if ( i == 1)continue ;
       cin >> a[i] ;
   }
    a[1] = a[0];
    if (n == 2)
    {
        cout << a[0] * 2 ;
        return 0 ;
    }
  //for (int i = 0; i < n ; i++)cout <<a[i] <<" ";
  for (int  i = 0 ; i < n  ;i++)
    {
        ans += min(a[i] ,a[i + 1]);
        //cout << ans <<endl;
    }
    //cout <<ans <<endl;
    cout <<ans +a[n - 1] ;
    return 0;
}


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

using namespace std;
long long int a[1005];
bool fun(int j)
{
    int i;
    for(i=2;i*i<=j;i++)
    {
        if(j%i==0)
            return 0;
    }
    return 1;
}
int main()
{
    int i,j,k,m,n;
    long long int ans=1;
    cin >> n;
    for(i=2;i<=n;i++)
    {
        j=i;
        if(fun(j))
        {
            a[j]++;
        }
        else
        {
            m=j;
            for(k=2;k<m;k++)
            {
                if(fun(j))
                {
                    a[j]++;
                    break;
                }
                else if(j%k==0)
                {
                    a[k]++;
                    j=j/k;
                    k--;
                }
            }
        }
    }
    for(i=2;i<=1000;i++)
    {
        if(a[i]!=0)
        {
            ans=ans*(a[i]+1)%1000000007;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
/************************************
/ AUTHOR : YATHARTH GOSWAMI         /  
/ ALIAS : hacker_yg                 /
/ INSTITUTE : IIT Kanpur            /
************************************/
//          TEMPLATE                //

#include <bits/stdc++.h>

#define ll long long
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second

using namespace std;

int main(){
    int n, r;
    cin >> n >> r;
    if (n < 10){
        cout << r + 100*(10-n);
    }
    else cout << r;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<string>
#include<stack>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
const ll m = (1e+9) + 7;
int main() {
	int n, m;
	static ll ans;
	vector<pair<int, int>> p;
	cin >> n >> m;
	priority_queue<int> que;
	for (int i = 0; i < n; ++i) {
		int a, b;
		cin >> a >> b;
		p.push_back(make_pair(a, b));
	}
	sort(p.begin(), p.end(),greater<pair<int,int>>());
	for (int day = 1; day <= m; ++day) {
		while (!p.empty() && p.back().first == day) {
			que.push(p.back().second);
			p.pop_back();
		}
		if (!que.empty()) {
			ans += que.top();
			que.pop();
		}
	}
	cout<<endl;
	cout << ans << endl;
}


Measured memory_bytes: 1908
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
typedef long long int ll;

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

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

ll d = 1e9 + 7;

ll modpow(ll x, ll y){
    return x*y % d;
}

ll gyaku(ll x){
    ll bai = x;
    ll e = d-2;
    ll ret = 1;
    while (e > 0){
        if (e % 2 == 1){
            ret = modpow(bai, ret);
        }
        bai = modpow(bai, bai);
        e /= 2;
    }
    return ret;
}

ll cmb(ll x, ll y){
    ll ans = 1;
    REP(i, y){
        ans = modpow(ans, x-i);
    }
    dump(ans)
    REP(i, y){
        ans = modpow(ans, gyaku(i+1));
    }
    return ans;
}


int main(void){
    ll n; cin >> n;
    ll nn = n;
    ll bai = 2;
    ll ans = 1;
    while(nn > 0){
        if (nn % 2 == 1){
            ans = modpow(bai, ans);
        }
        bai = modpow(bai, bai);
        nn /= 2;
    }
    ans = (ans+d-1) % d;
    ll a; cin >> a;
    ll minusa = cmb(n, a);
    ll b; cin >> b;
    ll minusb = cmb(n, b);
    ans += d - minusa;
    ans += d - minusb;
    cout << ans % d << endl;
    return 0;
}

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

using namespace std;

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

	int ans = 0;
	for (int i = 0; i < n - 2; i++) {
		if ((p[i] < p[i + 1] && p[i + 1] < p[i + 2])
		    || (p[i] > p[i + 1] && p[i + 1] > p[i + 2])) {
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
use std::io;

fn main() {
    let (a, b) = input();

    let area = a * b;
    let perimeter = a * 2 + b * 2;

    println!("{} {}", area, perimeter);
}

fn input() -> (i32, i32) {
    let mut s = String::new();
    io::stdin().read_line(&mut s).expect("");

    let mut iter = s.trim().split_whitespace();

    let a: i32 = iter.next().unwrap().parse().unwrap();
    let b: i32 = iter.next().unwrap().parse().unwrap();

    (a, b)
}



Measured memory_bytes: 5028
#include <iostream>
#include <vector>
using namespace std;
const long long INF = 1LL<<60; // 無限大を表す値

int main() {
    int H, N;
    cin >> H >> N;
    vector<int> A(N), B(N);
    for (int i = 0; i < N; ++i) cin >> A[i] >> B[i];

    vector<vector<long long>> dp(N+1, vector<long long>(H+1, INF));
    dp[0][0] = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j <= H; ++j) {
            dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
            dp[i+1][j] = min(dp[i+1][j], dp[i+1][max(j-A[i], 0)] + B[i]);
        }
    }
    cout << dp[N][H] << endl;
}

Measured memory_bytes: 81656
#include <bits/stdc++.h>
#include <algorithm>
#include <math.h>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define INF 999999999
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using llong = long long;
using namespace std;

// long long gcd(long long a, long long b){
//     if (a < b){
//         a ^= b;
//         b ^= a;
//         a ^= b;
//     }
//     return b ? gcd(b, a % b) : a;
// }

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

int main(){
    int a[3],sum;
    cin >> a[0] >> a[1] >> a[2];
    sum = a[0] + a[1] + a[2];
    if(sum >= 22) cout << "bust" << endl;
    else cout << "win" << endl;
}


Measured memory_bytes: 256
a = int(input())
b = [3]
b = list(map(int, input().split()))
all_count = 0
k = 0
while(1):
    count = 0
    for x in range(a):
        if(b[x] % 2 == 0):
            count = count + 1
        else:
            k = 1
    if(a == count):
        for x in range(a):
            b[x] = b[x] / 2
    if(k == 1):
        break
    all_count += 1
print(all_count)


Measured memory_bytes: 3060
use strict;
use warnings;
use 5.010;

use Data::Dumper;

my $n = <STDIN>;
my $a = read_split();
my $b = read_split();
my $c = read_split();

#warn Dumper $a, $b, $c;

my $score   = 0;

my $pre_ate = -1;
for my $ate (@$a) {
    $score  += $b->[$ate-1];

    if ($ate - $pre_ate == 1) {
        $score  += $c->[$pre_ate-1];
    }
    $pre_ate    = $ate;
}

say $score;


sub read_split {
    my $line    = <STDIN>;
    chomp($line);
    return [split(/ /, $line)];
}


Measured memory_bytes: 1920
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <stack>
#include <string.h>
using namespace std;
long long ax[200005];

int main()
{
    int n;
    long long i,a=0,b=0,res = 0x7fffffffffffffff,mid;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%lld",&ax[i]);
        a += ax[i];
    }
    for(i=0;i<n-1;i++){
        b += ax[i];
        mid = a - 2*b;
        if(mid<0) mid *= -1;
        res = min(res,mid);
    }
    printf("%lld",res);
}


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

#define rep(i, n) REP(i, 0, n)
#define REP(i, x, n) for (int i = x; i < n; i++)
#define REP2(i, x, n) for (int i = x; i <= n; i++)
#define OP(x) cout << x << endl;

int main() {
    int n, l; cin >> n >> l;

    int sum = 0;
    REP2(i, 1, n) sum += (i + l - 1);

    int tmp = abs(l);
    int target = 1;
    REP2(i, 2, n){
        if(abs(i + l - 1) < tmp){
            tmp = abs(i + l - 1);
            target = i;
        };
    }
    OP(sum - (target + l - 1));
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    String s = sc.next();
    
    StringBuffer buf = new StringBuffer();
    
    for(int i=0; i<n; i++){
      char si = s.charAt(i);
      
      if(i == k-1){
        if(si == 'A'){
        buf.append("a");
        }
        
        if(si == 'B'){
        buf.append("b");
        }
        
        if(si == 'C'){
        buf.append("c");
        }
      }else{
        buf.append(s.charAt(i));
      }
    }
    
    String new_s = buf.toString();
    
    System.out.println(new_s);
  }
}

Measured memory_bytes: 21844
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <set>
#include <cmath>
#include <algorithm>
using namespace std;

int day_of_week(int y,int m,int d){
	static int t[]={0,3,2,5,0,3,5,1,4,6,2,4};
	y-=m < 3;
	return ( y + y/4 - y/100 + y/400 + t[m-1] + d) % 7 ;
}

int main(){
	int m , d , w=4 , fw;
	while (cin >> m >> d, m){
		switch(day_of_week(2004,m,d)){
			case 0:
			cout << "Sunday" << endl;
			break;
			case 1:
			cout << "Monday" << endl;
			break;
			case 2:
			cout << "Tuesday" << endl;
			break;
			case 3:
			cout << "Wednesday" << endl;
			break;
			case 4:
			cout << "Thursday" << endl;
			break;
			case 5:
			cout << "Friday" << endl;
			break;
			case 6:
			cout << "Saturday" << endl;
		}
	}
	return 0; 
}

Measured memory_bytes: 1152
#![allow(non_snake_case)]
#![allow(unused_imports)]
#![allow(dead_code)]
 
use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;
use num_traits::*;
use superslice::*;
use std::ops::*;
 
use itertools::Itertools;
use itertools_num::ItertoolsNum;

pub fn enum_divisors<T: PrimInt + NumAssign>(n: T) -> Vec<T> {
    let mut res: Vec<T> = Vec::new();
    let mut i: T = one();
    while i * i <= n {
        if n % i == zero() {
            res.push(i);
            if n / i != i {
                res.push(n / i)
            }
        }
        i += one();
    }
    res.sort();
    res
}

#[fastout]
fn solve() {
    const MOD: usize = 1_000_000_007;
    const INF: usize = std::usize::MAX;

    input!{
        a: usize, b: usize, k: usize,
    }

    let a_div = enum_divisors(a).into_iter().collect::<HashSet<usize>>();
    let b_div = enum_divisors(b).into_iter().collect::<HashSet<usize>>();

    let mut intersect_vec: Vec<&usize> = a_div.intersection(&b_div).collect();
    intersect_vec.sort();
    intersect_vec.reverse();

    for (i, d) in intersect_vec.iter().enumerate() {
        if i+1 == k {
            println!("{}", d);
            break;
        }
    }
}

fn main() {
    solve();
}


Measured memory_bytes: 2196
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include<stack>
#include<sstream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<list>
#include<numeric>
typedef long long ll;

#define pi 3.14159265358979323846
#define VI vector<int>
#define VLL vector<long long>
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
const ll MOD = 1e9 + 7;
using namespace std;
template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}

template<typename T>
T binarysearch(vector<T> A, T key) {
	ll left = 0;ll right = 4;ll mid;
	while (left < right) {
		mid = (left + right) / 2;
		if (key == A[mid]) return 1;
		if (key > A[mid]) left = mid + 1;
		else if (key < A[mid]) right = mid;
	}
	return 0;
}

template<typename T>
T finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}
ll frac(ll n)//階乗
{
	if (n == 0) {
		return 1;
	}
	return (n * frac(n - 1)) % MOD;
}

template<typename T>
T keta(T a) {
	ll kazu = 1;
	while (1) {
		if (a / 10 != 0) { a /= 10;kazu++; }
		else break;
	}
	return kazu;
}//桁数


template<typename T>
T nCr(ll n, T r) {
	ll ans = 1;
	for (int i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (int i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
/*char r[4];
int yaju[4];
char op[3];
int sum = 0;
scanf("%s", r);
for (int i = 0;i < 4;i++) {
	yaju[i] = r[i] - '0';
}
*/
int main() {
	ll X;cin >> X;
	bool ok = true;
	while (ok) {
		for (int i = 2;i <= X;i++) {
			if (i == X) ok = false;
			if (X % i == 0)break;
		}
		X++;
	}
	cout << X-1 << endl;
}

Measured memory_bytes: 256
#include <iostream>

#define REP(i, a, b) for ( int i = (a); i < (b); i++ )
#define REVREP(i, a, b) for ( int i = (a); i > (b); i--)
#define DEBUG_INT(var) printf("the value of "#var" is %d\n", var)

typedef long long ll;

using namespace std;

int main(void) {

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

    ll min = 1e15 + 5;
    REP(i, 0, 5) {
    	ll x;
    	scanf("%lld", &x);
    	if ( x < min ) min = x;
    }
    
    printf("%lld\n", (N + min - 1) / min + 4);

	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
 
string s;
int sum=0;
vector<int> arr;
vector<char> v;
bool flag=false;
// vector<vector<char>> ans;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
 	
 	cin>>s;
 	for(int i=0;i<4;i++){
 		int n=s[i]-'0';
 		arr.push_back(n);
 	}
 	sum+=arr[0];
 	for(int i=0;i<2;i++){
 		for(int j=0;j<2;j++){
 			if(i==0){
 				v.push_back('+');
 				sum+=arr[1];
 			}
 			else{
 				v.push_back('-');
 				sum-=arr[1];
 			}
 			if(j==0){
 				v.push_back('+');
 				sum+=arr[2];
 			}
 			else{
 				v.push_back('-');
 				sum-=arr[2];
 			}
 			if(sum+arr[3]==7){
 				flag=true;
 				v.push_back('+');
 				break;
 			}
 			else if(sum-arr[3]==7){
 				flag=true;
 				v.push_back('-');
 				break;
 			}
 			sum=arr[0];
 			v.clear();
 		}
 		if(flag==true)
 			break;
 	}
 	for(int i=0;i<3;i++){
 		cout<<arr[i]<<v[i];
 	}
 	cout<<arr[3]<<'='<<7;
	return 0;
}

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

#include <algorithm>

using namespace std;

#define sqr(x) ((x) * (x))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

typedef long long ll;

const int MOD = 1000000007;
const int INF = 1000000007;
const ll INFLL = 1000000000000000007LL;

void solve() {
  int K, N;
  cin >> K >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  vector<int> d;
  for (int i = 0; i < N - 1; i++) {
    d.push_back(A[i + 1] - A[i]);
  }
  d.push_back(K - A.back() + A[0]);
  ll ans = 0;
  for (int i = 0; i < d.size(); i++) {
    ans += d[i];
  }
  sort(all(d));
  cout << ans - d.back() << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // cout << fixed << setprecision(12);

  solve();

  return 0;
}


Measured memory_bytes: 2168
#include<stdio.h>
#include<math.h>
int main(void){
  int n,d,i,j,k,cnt=0;
  scanf("%d %d",&n,&d);
  int num[n][d];
  double sum=0;
  for(i=0;i<n;i++){
    for(j=0;j<d;j++){
      scanf("%d",&num[i][j]);
    }
  }
  for(i=0;i<n-1;i++){
    for(j=i+1;j<n;j++){
      sum=0;
      for(k=0;k<d;k++){
        sum+=(num[i][k]-num[j][k])*(num[i][k]-num[j][k]);
      }
      if((int)sqrt(sum)*(int)sqrt(sum)==sum){
        cnt++;
      }
    }
  }
  printf("%d",cnt);
  return 0;
}

Measured memory_bytes: 128