akhauriyash/Code-Regression huggingface dataset:
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd(a, b)


A, B, C, D = map(int, input().strip().split())

a_c = A // C
a_c_mod = A % C
b_c = B // C
a_d = A // D
a_d_mod = A % D
b_d = B // D

l = lcm(C, D)

a_cd = A // l
a_cd_mod = A % l
b_cd = B // l

if a_c_mod == 0:
    a_c -= 1

if a_d_mod == 0:
    a_d -= 1

if a_cd_mod == 0:
    a_cd -= 1

print((B - A + 1) - (b_c - a_c) - (b_d - a_d) + (b_cd - a_cd))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long 
#define MAXN 1000010

using namespace std;

int n, m, d, x;
int f;
int a[MAXN];
int t;
string s;

int main() {
	scanf("%d", &n);
	
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
	}
	t = 0;
	int be = a[1];
	int maxn = 0;
	for (int i = 2; i <= n; i++) {
		if (be >= a[i]) {
			t++;
			be = a[i];
		}
		else {
			maxn = max(maxn, t);
			t = 0;
			be = a[i];
		}
//		cout << t << endl;
	}
	maxn = max(maxn, t);
	cout << maxn << endl;
	return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int ans=0;
		Scanner sc = new Scanner(System.in);

		String s = sc.nextLine();
		char[] a = s.toCharArray();
		String t = sc.nextLine();
		char[] b = t.toCharArray();

		for(int i=0;i<a.length;i++) {
			if (a[i] != b[i]) {
				ans++;
			}
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 43568
//01 Matrix
#include<bits/stdc++.h>
using namespace std;
int main() {
	int H, W, A, B;
	cin >> H >> W >> A >> B;

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cout << ((i < B)^(j < A));
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1280
n = int(input())
itv = []
for i in range(n):
    x,l = map(int, input().split())
    start = x - l if x - l > 0 else 0
    end = x + l
    itv.append([end, start])

itv.sort()

ans, t = 0, 0
for [x, l] in itv:
    if t <= l:
        ans += 1
        t = x

print(ans)


Measured memory_bytes: 59352
n = gets.to_i
s = gets.chomp.chars
max = 0
i = 0
while i < n
  if max < (s[0..i] & s[(i+1)..(n-1)]).size
   max = (s[0..i] & s[(i+1)..(n-1)]).size
  end
  i += 1
end
puts max

Measured memory_bytes: 14328
NK = input().split()
N = int(NK[0])
K = int(NK[1])
Moratta = []
 
for i in range(0, K):
    D = int(input())
    A = input().split()
    for j in A:
      if j in Moratta:
        continue
      else:
        Moratta.append(j)

sunuke_count = len(Moratta)
result = N-sunuke_count
print(result)

Measured memory_bytes: 9192
C = []
for _ in range(3):
    C.append(list(map(int, input().split())))

A = []
B = []
for i in range(3):
    A.append(sum(C[i]))
    B.append(C[0][i] + C[1][i] + C[2][i])

# print('A, B', A, B)

if (A[0] - A[1]) % 3 == 0 and (A[1] - A[2]) % 3 == 0 and (A[2] -
                                                          A[0]) % 3 == 0:
    if (B[0] - B[1]) % 3 == 0 and (B[1] - B[2]) % 3 == 0 and (B[2] -
                                                              B[0]) % 3 == 0:
        print('Yes')
        exit()
print('No')


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

#define FOR(i,a,b) for (int i = a; i < b; ++i)
#define FORR(i,a,b) for (int i = b - 1; i >= a; --i)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) FORR(i,0,n)

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

	ll nine = 0;
	for (char c : N) {
		nine += (c - '0');
	}

	if (nine % 9 == 0) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 3724
#include<bits/stdc++.h>
using namespace std;
    int main(){
        int A, B, a, b, c;
            cin >> A >> B;
                a = A + B;
                    b = A - B;
                        c = A * B;
                            if(a >= b && a >= c){
                                cout << a << endl;
                                    return 0;
                            }else if(b >= a && b >= c){
                                cout << b << endl;
                                    return 0;
                            }else if(c >= a && c >= b){
                                cout << c << endl;
                                    return 0;
                            }
    return 0;}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { os << p.first << ' ' << p.second; return os; }

void solve() {
  while (true) {
    int n; cin >> n;
    if (n == 0) return;
    bool up = false;
    bool lup = false, rup = false;
    int ans = 0;
    rep(i, n) {
      string s; cin >> s;
      if (s == "lu") lup = true;
      if (s == "ld") lup = false;
      if (s == "ru") rup = true;
      if (s == "rd") rup = false;
      if (!up && lup && rup) up = true, ans++;
      else if (up && !lup && !rup) up = false, ans++;
    }
    cout << ans << '\n';
  }
}



Measured memory_bytes: 3216
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br =
				new BufferedReader(new InputStreamReader(System.in));
		/*
		 * 1 <= i, j < = 5
		 * horiEdge[i][0] = horiEdge[i][5] = '\u0000'
		 * vertEdge[0][j] = vertEdge[5][j] = '\u0000'
		 */
		char[][] horiEdge = new char[6][6];
		char[][] vertEdge = new char[6][6];
		for (int i=1; /* i <= 5 */; i++) {
			char[] data;

			data = br.readLine().toCharArray();
			for (int j=1; j <= 4; j++) {
				horiEdge[i][j] = data[j-1];
			}

			if (i==5) break;

			data = br.readLine().toCharArray();
			for (int j=1; j <= 5; j++) {
				vertEdge[i][j] = data[j-1];
			}
		}

		Wanderer man = new Wanderer();
		StringBuilder ans = new StringBuilder();
		do {
			String temp = man.go(horiEdge, vertEdge);
			ans.append(temp);
		} while ( ! (man.x == 1 && man.y == 1) );

		System.out.println(ans);
	}

	public static final int right = 0;
	public static final int down = 1;
	public static final int left= 2;
	public static final int up = 3;

	public static class Wanderer {
		int x; // coordinate
		int y; // coordinate
		int dir; // direction

		public Wanderer() {
			this.x = 1;
			this.y = 1;
			this.dir = right;
		}

		public String go(char[][] horiEdge, char[][] vertEdge) {
			if (dir == right) {
				x = x+1;
				if (vertEdge[y-1][x] == '1') {
					dir = up;
				} else if (horiEdge[y][x] == '1') {
					dir = right;
				} else if (vertEdge[y][x] == '1') {
					dir = down;
				} else {
					dir = left;
				}
				return "R";
			}

			if (dir == down) {
				y = y+1;
				if (horiEdge[y][x] == '1') {
					dir = right;
				} else if (vertEdge[y][x] == '1') {
					dir = down;
				} else if (horiEdge[y][x-1] == '1') {
					dir = left;
				} else {
					dir = up;
				}
				return "D";
			}

			if (dir == left) {
				x = x-1;
				if (vertEdge[y][x] == '1') {
					dir = down;
				} else if (horiEdge[y][x-1] == '1') {
					dir = left;
				} else if (vertEdge[y-1][x] == '1') {
					dir = up;
				} else {
					dir = right;
				}
				return "L";
			}

			if (dir == up) {
				y = y-1;
				if (horiEdge[y][x-1] == '1') {
					dir = left;
				} else if (vertEdge[y-1][x] == '1') {
					dir = up;
				} else if (horiEdge[y][x] == '1') {
					dir = right;
				} else {
					dir = down;
				}
				return "U";
			}

			return "hoge";
		}
	}
}

Measured memory_bytes: 23952
package main

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

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func max(a, b int) int {
	return int(math.Max(float64(a), float64(b)))
}

func min(a, b int) int {
	return int(math.Min(float64(a), float64(b)))
}

func abs(a, b int) int {
	return int(math.Abs(float64(a) - float64(b)))
}

func main() {
	sc.Split(bufio.ScanWords)
	a, b := nextInt(), nextInt()
	if a == b {
		fmt.Print("Yes")
	} else {
		fmt.Print("No")
	}
}


Measured memory_bytes: 640
#!/usr/bin/env python
from bisect import bisect_right
INF = 10**18
A, B, Q = map(int, input().split())
S = [-INF] + [int(input()) for i in range(A)] + [INF]
T = [-INF] + [int(input()) for i in range(B)] + [INF]

for q in range(Q):
    x = int(input())
    se, te = bisect_right(S, x), bisect_right(T, x)
    ans = INF
    for s in [S[se-1], S[se]]:
        for t in [T[te-1], T[te]]:
            ds, dt = abs(s-x)+abs(s-t), abs(t-x)+abs(t-s)
            ans = min(ans, ds, dt)
    print(ans)

Measured memory_bytes: 14092
n = int(input())
s = list(int(input()) for _ in range(n))

s = sorted(s)
ans = sum(s)
if(ans % 10 != 0):
    print(ans)
else:
    flag = False
    for i in s:
        if ((ans - i) % 10 != 0):
            flag = True
            ans = ans - i
            break

    if(flag):
        print(ans)
    else:
        print(0)


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <sstream>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
using namespace std;
long long i,j,k,n,m;
string s;
long long mod=1000000007;

int main() {
  cin >> n>>m;
  long long out =0;
  if (m>=2) {
    out += min(n,m/2);
    m -= 2 * min(n,m/2);
    out += m/4;
  }
  cout << out << endl;
  return 0;
}


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

int cou_l(int i, string s){
    int cou = 0;
    int len = s.length();

    for(int j = i; j < len; j++){
        if(s[j] == 'R'){
            break;
        }else{
            cou++;
        }
    }

    return cou;
}

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

    int len = s.length();

    int cou[len];
    int flag[len];
    int cou_0[len]; 
    for(int i = 0; i < len; i++){
        cou[i] = 0;
        flag[i] = 0;
        cou_0[i] = 0; 
    }

    for(int i = 0; i < len; i++){
        if(s[i] == 'L'){
            if(s[i - 1] == 'L'){
                flag[i] = 0;
            }else{
                flag[i] = 2;
            }
        }else{
            if(s[i + 1] == 'R'){
                flag[i] = 0;
            }else{
                flag[i] = 1;
            }
        }
    }

    int k = 0;

    for(int i = 0; i < len; i++){
        if(flag[i] == 0){
            k++;
        }else if(flag[i] == 1){
            cou_0[i] = k;
            k = 0;
        }else{
            cou_0[i] = cou_l(i + 1, s);
            i += cou_0[i];
        }
    }

    for(int i = 0; i < len; i++){
        if(flag[i] == 0){
            cou[i] = 0;
        }else{
            if(cou_0[i] == 0){
                cou[i] += 1;
            }else{
                if(s[i] == 'R'){
                    cou[i] += 1 + (cou_0[i] / 2);
                    cou[i + 1] += cou_0[i] - (cou_0[i] / 2);
                }else{
                    cou[i] += 1 + (cou_0[i] / 2);
                    cou[i - 1] += cou_0[i] - (cou_0[i] / 2);
                }
            }
        }
    }

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

}

Measured memory_bytes: 1792
// Problem : D - Knapsack 1
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <stdio.h>
#include <math.h>
#include <cstdlib>
#include <iostream>
#include <cstdlib>
#include <algorithm>
using namespace std;
#define ll long long 
#define ull unsigned long long
const int INF = 1e9 + 5;
#define pb push_back
#define eb emplace_back
#define vll vector<long long int>
#define vi vector<int>
#define loop(i, a, b) for(long long int i = a; i < b; i++)
#define FastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pii pair<ll, ll>
#define vpair vector<pii>
#define vbool vector<bool>
#define mkp make_pair
#define scan(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) {cout<<a[i]<<' ';}cout<<'\n'
#define sec second
#define fir first
#define br '\n'
#define permute next_permutation
#define pqua priority_queue<ll>
#define pqud priority_queue<ll, vector<ll>, greater<ll> >
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define maxi *max_element
#define pi acos(-1)
#define PRECISION std::cout.unsetf ( std::ios::fixed );std::cout.precision(10)

vector<long long int> sieve(long long int n){
 	vector<long long int> primes;
 	bool isPrime[n+1] = {false};
 	isPrime[1] = isPrime[0] = false;
 	for(long long int i = 2;i<=n;i++)
 	{
 		isPrime[i] = true;
 	}
 	for(long long int i = 2;i*i<=n;i++)
 	{
 		if(isPrime[i])
 		{
 			for(long long int j = i*i;j<=n;j+=i)
 			{
 				isPrime[j] = false;
 			}
 		}
 	}
 	for(long long int i = 2;i<=n;i++)
 	{
 		if(isPrime[i])
 		{
 			primes.push_back(i);
 		}
 	}
 	return primes;
}

void print_vector2(vector<vector<ll> >v) {
    for(ll i=0;i<v.size();i++){
        for(ll j=0;j< v[i].size();j++){
            cout<<v[i][j]<<" ";
        }cout<<"\n";
    }
}

void print_vector1(vector<ll> v) {
    for(ll i=0; i<v.size();i++){
        cout<<v[i]<<" ";
    }cout<<"\n";
}

ll gcd(ll a, ll b) {
    return __gcd(a, b);
}

// v.back()
// v.erase(v.begin(), v.brgin + k)
// v.insert(at which place v.bigin() + 1 implines at i = 1, no. of times, value)
// v.insert(position, copy.begin(), copy.end())
// v1.swap(v2)
// v.clear() to clear v.empty() to check empty
// map assending order and set descending order 
// stringstream ss(str) Used for breaking words

int main(){
    FastIO;
    PRECISION;
	ll n, w;
	cin>>n>>w;
	vll val(n);
	vll weight(n);
	for(ll i = 0; i < n; i++){
		cin>>weight[i]>>val[i];
	}
	ll dp[n + 1][w + 1];
	for(int i = 0; i <= n; i++){
		for(int j = 0; j <= w; j++){
			if(i == 0 || j == 0){
				dp[i][j] = 0;
			}
			else if(weight[i - 1] > j){
				dp[i][j] = dp[i - 1][j];
			}
			else{
				dp[i][j] = max(dp[i - 1][j - weight[i - 1]] + val[i - 1], dp[i - 1][j]);
			}
		}
	}
	cout<<dp[n][w];
    
    return 0;
}

Measured memory_bytes: 82508
#include <bits/stdc++.h>
using namespace std;
bool dp[21];
vector<int> a;

bool solve(int i,int m){
    if(m==0){

        return true;
    }
    else if(m<0)return false;
    else if(i>=a.size())return false;
    else return (solve(i+1,m-a[i]))||(solve(i+1,m));
}

int main(){
    int ans=0,sum=0;
    int n;
    cin >>n;
    
    for (int i = 0; i < n; i++){
        int ai;
        cin >> ai;
        a.push_back(ai);
    }

    int q;
    cin >> q;

    for (int i = 0; i < q; i++){
        int m;
        cin >>m;

        if(solve(0,m))cout << "yes" <<endl;
        else cout << "no" <<endl;
    }

    //cout <<fixed<<setprecision(16)<< << endl;
    //cout << ans << endl;

    //if(flag==1)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}



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

#pragma region template

using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vl2 = vector<vl>;
using vs = vector<string>;

#define pb push_back
#define mp make_pair
#define F first
#define S second

#define reps(i, k, n) for (int i = (k), i##_len = (n); i < i##_len; ++i)
#define rep(i, n) reps(i, 0, n)
#define all(o) (o).begin(), (o).end()
#define sz(a) ((int)(a).size())
#define debug(x) cerr << x << " (L:" << __LINE__ << ")" << '\n';
#define bit(n) (1LL << (n))

const ll MOD = 1000000007;

const ll MAX = (ll)0x3f0000003f000000;
const double EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1},
          dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

ll mpow(ll a, ll b, ll m) {
    ll ans = 1;
    do {
        if (b & 1) ans = ans * a % m;
        a = a * a % m;
    } while (b >>= 1);  //  b/=2; }while (b!= 0);
    return ans;
}

inline ll mpow(ll a, ll b) {
    mpow(a, b, MOD);
}

template <class T>
void print(T& x) {
    cout << x << '\n';
}

struct setup_main {
    setup_main() {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(15);
    }
} setup_main_;

#pragma endregion
ll ans = MAX;

void solve(long long N, long long T, std::vector<long long> c,
           std::vector<long long> t) {
    rep(i, N) {
        if (t[i] <= T) {
            ans = min(ans, c[i]);
        }
    }
    if (ans != MAX) cout << ans << "\n";
    else
        cout << "TLE" << endl;
}


signed main() {
    long long N;
    scanf("%lld", &N);
    long long T;
    scanf("%lld", &T);
    std::vector<long long> c(N);
    std::vector<long long> t(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &c[i]);
        scanf("%lld", &t[i]);
    }
    solve(N, T, std::move(c), std::move(t));

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
long long l,r,luxiangnan,red,j;
long long minnest=999999999999999999;
int main(){
	cin>>l>>r;
	luxiangnan=l%2019;
	red=r%2019;
	if(r-l>=2019){
		cout<<"0";
		return 0;
	}
	for(long long i=luxiangnan;i<red;i++){
		for(j=red;j>i;j--){
				minnest=min((i*j)%2019,minnest);
			}
		}
		cout<<minnest;
		return 0;
	cout<<"0";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define fi first
#define se second
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
const long long MOD = 1e9 + 7, INF = 1e18;

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

signed main()
{
    int N, K, Q;
    cin >> N >> K >> Q;
    vector<int> a(N + 1);
    for (int i = 0; i < N; i++)
    {
        cin >> a[i];
    }
    a[N] = 0;
    int ans = INF;
    for (int i = 0; i < N + 1; i++)
    {
        int ng = a[i];
        vector<int> v;
        vector<int> tmp;
        for (int j = 0; j < N; j++)
        {
            if (a[j] <= ng)
            {
                if (tmp.size() >= K)
                {
                    sort(tmp.begin(), tmp.end());
                    for (int k = 0; k < min(Q, (int)tmp.size() - K + 1); k++)
                    {
                        v.push_back(tmp[k]);
                    }
                }
                tmp.clear();
            }
            else
            {
                tmp.push_back(a[j]);
            }
            if (j == N - 1)
            {
                if (tmp.size() < K)
                    continue;
                sort(tmp.begin(), tmp.end());
                for (int k = 0; k < min(Q, (int)tmp.size() - K + 1); k++)
                {
                    v.push_back(tmp[k]);
                }
                tmp.clear();
            }
        }
        sort(v.begin(), v.end());
        if ((int)v.size() >= Q)
        {
            chmin(ans, v[Q - 1] - v[0]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const ll mod = 1e9 + 7;
const ll inf = 1e18;

// retun n の約数の集合
vector<ll> divisors(ll n){
      vector<ll> y;
    for(ll i = 1; i * i <= n; i++){
        if(n % i == 0) y.push_back(i);
    }
      ll len = y.size();
      REP(i, len){
        if(y[i] == n / y[i]) continue;
        y.push_back(n / y[i]);
    }
    return y;
}

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

    ll n;
    cin >> n;

    ll res = 1, sq = sqrt(n);

    // N % K == 1
    for (auto y : divisors(n - 1)) {
        if (y > sq) res++;
    }

    REP(x, sq + 1) {
        if (x < 2) continue;
        ll mem = n;
        while (mem % x == 0) mem /= x;
        if (mem % x == 1) res++;
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	string s;
	cin >> s;
	int count = 0;
	int ans = 0;

	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T') {
			count++;
			if (ans <= count) {
				ans = count;
			}
		}
		else {
			count = 0;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define prtd(var, i) cout << fixed << setprecision(i) << var << endl;
#define ll long long
using namespace std;

int main(){
    string s;
    cin >> s;
    rep(i, s.size()){
        if(s[i] == '?'){
            s[i] = 'D';
        }
        cout << s[i];
    }
    cout << endl;
}


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

int main(void){
    int a,b;
    cin >> a >> b;
    
    if(a>b){
        rep(i,a){
            cout << b;
        }
        cout << endl;
    }
    else{
        rep(i,b){
            cout << a;
        }
        cout <<endl;
    }
    
    return 0;
    
}






















































Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int n; cin >> n;
    string s; cin >> s;
    
    vector<int> m(200, 0);

    for(int i = 0; i < n; ++i) {
        m[s[i]] += 1;
    }
    
    vector<int> f(200, 0);
    int ans = 1e9;

    for(int i = 0; i < n; ++i) {
        int temp = i - f['E'] // left of me facing west
                   + (m['E'] - f['E'] - (s[i] == 'E')); // right of me facing east
        ans = min(ans, temp);   
        f[s[i]] += 1;
    }

    cout << ans << "\n";
}

Measured memory_bytes: 900
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/





typedef long long ll;
int N, A[101010], B[101010], C[101010];
//---------------------------------------------------------------------------------------------------
map<pair<int, int>, int> dic;
vector<int> E[101010];
int S[101010];
int cnt[101010], dep[101010];
void dfs(int cu, int pa = -1) {
    cnt[cu] = 1;
    fore(to, E[cu]) if (to != pa) {
        dep[to] = dep[cu] + 1;
        dfs(to, cu);
        cnt[cu] += cnt[to];
    }
}
int count(int from, int to) { // from -> toと遷移するとき、to以降の頂点数
    if (dep[from] < dep[to]) return cnt[to];
    else return N - cnt[from];
}
//---------------------------------------------------------------------------------------------------
ll case1(int edgeid) { // Si = N/2 となる辺がある場合
    ll ans = 0;
    rep(i, 0, N - 1) {
        if (i != edgeid) ans += 1LL * C[i] * 2 * S[i];
        else ans += 1LL * C[i] * (N - 1);
    }
    return ans;
}
//---------------------------------------------------------------------------------------------------
ll case2() { // Si = N/2 となる辺がない場合
    int centroid;
    rep(cu, 0, N - 1) {
        int ok = 1;
        fore(to, E[cu]) {
            int c = count(cu, to);
            if (N / 2 < c) ok = 0;
        }
        if (ok) {
            centroid = cu;
            break;
        }
    }

    ll ans = 0;
    rep(i, 0, N - 1) ans += 1LL * C[i] * 2 * S[i];
    ll mi = 1LL<<60;
    fore(to, E[centroid]) {
        int i = dic[{centroid, to}];
        mi = min(mi, (ll)C[i]);
    }
    return ans - mi;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    rep(i, 0, N - 1) {
        cin >> A[i] >> B[i] >> C[i];
        A[i]--; B[i]--;
        E[A[i]].push_back(B[i]);
        E[B[i]].push_back(A[i]);
        dic[{A[i], B[i]}] = dic[{B[i], A[i]}] = i;
    }

    dfs(0);

    int ok = -1;
    rep(i, 0, N - 1) {
        int c = count(A[i], B[i]);
        S[i] = min(c, N - c);
        if (S[i] * 2 == N) ok = i;
    }

    ll ans;
    if (0 <= ok) ans = case1(ok);
    else ans = case2();
    cout << ans << endl;
}

Measured memory_bytes: 23296
import java.util.*;
class Main{
public static void main(String[] args){
    int a,b,d,r;
    Scanner scan=new Scanner(System.in);
    a=scan.nextInt();
    b=scan.nextInt();
    d=a/b;
    r=a%b;
    double f = (double) a / (double) b; 
    System.out.printf("%d %d %.5f\n",d,r,f);
    }
}


Measured memory_bytes: 26616
set = gets
arr = Array.new(3)

while line = gets do
	num = line.split
	arr[0] = num[0].to_i
	arr[1] = num[1].to_i
	arr[2] = num[2].to_i
	arr_s = arr.sort

	a = arr_s[0]**2 + arr_s[1]**2
	if a == arr_s[2]**2
		puts "YES"
	else
		puts "NO"
	end

end

Measured memory_bytes: 6108
#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;
#define INF 999999999
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define LL long long

int main(void)
{
    int a, b;
    scanf("%d %d", &a, &b);
    string s;
    cin >> s;
    int l = a + b + 1;

    REP(i, l)
    {
        char c = s[i];
        if (i == a)
        {
            if (c == '-')
                continue;
        }
        else
        {
            if ('0' <= c and c <= '9')
                continue;
        }

        printf("No");
        return 0;
    }

    printf("Yes");
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int i; //for loop
  int sx,sy,tx,ty; //for input
  int dx,dy; //different
  int err;
  
  err=scanf("%d",&sx);
  if(err==EOF){return 0;}
  err=scanf("%d",&sy);
  if(err==EOF){return 0;}
  err=scanf("%d",&tx);
  if(err==EOF){return 0;}
  err=scanf("%d",&ty);
  if(err==EOF){return 0;}

  dx=tx-sx;
  dy=ty-sy;
  
  for(i=0;i<dy;i++){printf("U");}
  for(i=0;i<dx;i++){printf("R");}
  for(i=0;i<dy;i++){printf("D");}
  for(i=0;i<dx;i++){printf("L");}
  printf("L");
  for(i=0;i<dy+1;i++){printf("U");}
  for(i=0;i<dx+1;i++){printf("R");}
  printf("D");
  printf("R");
  for(i=0;i<dy+1;i++){printf("D");}
  for(i=0;i<dx+1;i++){printf("L");}
  printf("U\n");

  return 0;  
}


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

using namespace std;
typedef long long ll;

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

int main() {
    ll n, k, s; cin >> n >> k >> s;
    if (s < 1e9) {
        if (k == 0) {
            REP(i, n) {
                if (i == 0) {
                    cout << s+1;
                } else {
                    cout << " " << s+1;
                }
            }
        } else {
            REP(i, k) {
                if (i == 0) {
                    cout << s;
                } else {
                    cout << " " << s;
                }
            }
            REP(i, n-k) {
                cout << " " << s+1;
            }
        }
    } else {
        if (k == 0) {
            REP(i, n) {
                if (i == 0) {
                    cout << 1;
                } else {
                    cout << " " << 1;
                }
            }
        } else {
            REP(i, k) {
                if (i == 0) {
                    cout << s;
                } else {
                    cout << " " << s;
                }
            }
            REP(i, n-k) {
                cout << " " << 1;
            }
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3636
n = int(input())
T, A = list(map(int, input().split(" ")))
H = list(map(int, input().split(" ")))

def TEMP(H):
    return T - H*0.006

def AAA(H):
    return abs(A - H)

H = list(map(TEMP, H))

H = list(map(AAA, H))

print(H.index(min(H))+1)


Measured memory_bytes: 9200
#include <iostream>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;
typedef long long ll;

const ll M = 1e9+7;


// a^n mod を計算する
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;
}

// a^{-1} mod を計算する
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

long long modcomb(long long n, long long k){
    long long ans = 1;
    rep(i,k){
        ans = (ans * (n-i) % M ) * modpow(i+1,M-2,M) % M;
    }
    return ans;
}

vector<ll> fac(3000001); //n!(mod M)
vector<ll> ifac(3000001); //k!^{M-2} (mod M)
//a,bの範囲的にこれだけ配列を用意していけば十分

ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll a, ll b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % M;
    return tmp * fac[a] % M;
}

int main()
{
    ll n,a,b;
    cin >> n >> a >> b;

    ll al = modpow(2,n,1e9+7);
    ll nca = modcomb(n,a);
    ll ncb = modcomb(n,b);

    cout<< (al%M + (M-nca)%M + (M-ncb)%M - 1)%M << endl;

    return 0;


    ll fct = 1;
    rep(i,n){
        fct = fct * (i+1) % M;
    }
    cout<<fct<<endl;

    ll f = 1;
    rep(i,a){
        f *= modinv((i+1)*(n-i),1e9+7);
    }
    cout<<f<<endl;

    return 0;
}

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

using namespace std;
typedef long long ll;
ll p[20];
int main()
{
    ll a,b,c,d,e,f,g;
    cin>>a>>b;
    if(b%2==1)
        cout<<"No"<<endl;
    else
    {
        if(b/2-a>=0&&2*a-b/2>=0)
          cout<<"Yes"<<endl;
        else
          cout<<"No"<<endl;

    }
    return 0;
}


Measured memory_bytes: 3600
#include <cstdio>
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#include <queue>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
using namespace std;
#define sL(i) i << 1
#define sR(i) i << 1 | 1
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<int, pair<int,int>> ppi;
const int MOD = 1e9 + 7;
const int INF = 2e9 + 5;

int n;
int a[200010];
int main() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    ll ans = 0;
    for (int i = 1; i < n; i++) {
        ans += max(a[i - 1] - a[i], 0);
        a[i] = max(a[i], a[i - 1]);
    }
    cout << ans;
}

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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define DISP1(as)		for(auto it : as) cout<<it.f<<" "<<it.s<<") ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	2e+5 + 99;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9 + 7;

// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, k, l, q, x;
string s;
ll prime[200];
// < ----------- func eh ---------------- ? //

void PRIME() {
	for (ll i = 0; i <= 100; i++) {
		prime[i] = i;
	}

	for (ll i = 4; i <= 100; i += 2) {
		prime[i] = 2;
	}

	for (ll i = 3; i <= 100; i += 2) {
		if (prime[i] == i) {
			for (ll j = i * i; j <= 100; j += i) {
				if (prime[j] == j) prime[j] = i;
			}
		}
	}
}

map<ll , ll> factorize(ll x) {
	map<ll, ll> ans;

	while (x > 1) {
		ll m = prime[x];
		while (x % m == 0) {
			ans[m] = (ans[m] + 1) % MOD;
			x /= m;
		}
	}
	return ans;
}

// <------------- Start of main() -------------------> //

void MAIN() {
	cin >> n;
	map<ll, ll> ans, ans1;
	for (ll i = 2; i <= n; i++) {
		ans1 = factorize(i);
		for (auto it : ans1) {
			ans[it.f] += it.s;
		}
	}
	
	vll cnt(100, 0);
	for (auto it : ans) {
		//cout<<it.f<<" "<<it.s;newl;
		cnt[it.s + 1] += 1	;
	}

	for(ll i=99;i>=0;i--) cnt[i]+=cnt[i+1];
	//DISP(cnt);
	//dline;
	ll Ans = 0;
	Ans = cnt[75] + (cnt[25] * (cnt[3] - 1)) + (cnt[15] * (cnt[5] - 1))  +  (cnt[5] * (cnt[5]-1) * (cnt[3]-2))/2;
	cout << Ans;
}

int main() {
	fastio; randomINT;
	//cin >> T;
	PRIME();
	while (T--) {
		MAIN();
	}
	return 0;
}


Measured memory_bytes: 3588
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <string>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define endl '\n'
const int INF = (1 << 30);
using namespace std;
typedef long long int ll;

bool solve(){
    string s;
    cin >> s;
    cout << (count(s.begin(), s.end(), 'g') - count(s.begin(), s.end(), 'p')) / 2 << endl;;
    return false;
}

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

    while(solve());
}

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

using namespace std;

int gcd(int a, int b) {
	for (; b; swap(a, b))
		a %= b;
	return a;
}
int a[111111], b[111111];
int main() {
	int n, m = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		scanf("%d", a + i);
		b[i + 1] = gcd(b[i], a[i]);
	}
	for (int i = n; i--;)
		a[i] = gcd(a[i], a[i + 1]);
	for (int i = 0; i < n; i++)
		m = max(m, gcd(a[i + 1], b[i]));
	cout << m << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<stdio.h>
#include<set>
#include<cstdio>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;

int main(){
    int n,m;
    cin>>n>>m;
    
    int P[100000],Y[100000];
    vector<int> v[100001];
    
    rep(i,m){
        cin>>P[i]>>Y[i];
        v[P[i]].push_back(Y[i]);
    }
    rep(i,n) sort(v[i+1].begin(),v[i+1].end());
    
    rep(i,m){
        printf("%06d",P[i]);
       // int r=0;
        /*for(int j=0;j<v[P[i]].size();j++){
            r++;
            if(v[P[i]][j]>=Y[i]){
                break;
            }
        }*/
        int r=lower_bound(v[P[i]].begin(),v[P[i]].end(),Y[i])-v[P[i]].begin()+1;
        printf("%06d",r);
        cout<<endl;
        }
    

return 0;
}

Measured memory_bytes: 7808
#include <bits/stdc++.h>
#define MAXN 100005
#define LL long long 
using namespace std;

LL n, ans, l[MAXN], r[MAXN];

bool CMP1(LL x, LL y) {return x>y;}
bool CMP2(LL x, LL y) {return x<y;}

int main()
{
	scanf("%lld", &n);
	for(int i=1; i<=n; i++) scanf("%lld%lld", &l[i], &r[i]);
	sort(l, l+n+1, CMP1);
	sort(r, r+n+1, CMP2);
	for(int i=0; i<=n; i++) if(l[i]>r[i]) ans+=l[i]-r[i];
	printf("%lld\n", ans*2);
} 

Measured memory_bytes: 1792
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();

		if(x==1) {
			System.out.println("0");
		}else {
			System.out.println("1");
		}

	}

}


Measured memory_bytes: 35712
while True:
    H,W = map(int,input().split())
    if (H==0 and W==0):
        break
    for i in range(H):
        for j in range(W):
            if ((i+j)%2==0):
                print("#",end = "")
            else:
                print(".",end = "")
        print()

    print()


Measured memory_bytes: 7004
#include <bits/stdc++.h>
#define clr cin.ignore(numeric_limits<streamsize>::max(), '\n')
#define _val(x) cerr << #x << " is " << x << "\n";
#define all(container) container.begin(), container.end()
#define rall(container) container.rbegin(), container.rend()
#define rep(i, a, b, c) for(ll i = a; i <= b; i += c)
#define rrep(i, a, b, c) for(ll i = a; i >= b; i -= c)
#define pb push_back
#define mp make_pair

using namespace std;

const double eps = 1e-10;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int, int> pii;
typedef vector<pair<int, int> > vpii;
typedef pair<long long, long long> pll;
typedef vector<pair<long long, long long> > vpll;
const int INF = 0x3f3f3f3f;

int main(void){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.precision(10);
	cout << fixed;
	ll n; cin >> n;
	ll heights[n], dp[n];
	rep(i, 0, n-1, 1) cin >> heights[i];
	dp[0] = 0;
	dp[1] = abs(heights[0]-heights[1]);
	rep(i, 2, n-1, 1) 
		dp[i] = min(dp[i-2]+abs(heights[i-2]-heights[i]), dp[i-1]+abs(heights[i]-heights[i-1]));
	cout << dp[n-1] << "\n";
	return 0;
}

Measured memory_bytes: 1792
while 1:
    n=int(input())
    if n==0:break
    a=list(map(int,input().split()))
    s=list(input())
    for i in range(len(s)):
        for j in range(a[i%n]):
            if s[i]=='A':s[i]='z'
            elif s[i]=='a':s[i]='Z'
            else:s[i]=s[i]=chr(ord(s[i])-1)
    print(*s,sep='')

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

using namespace std;

int main(){
 int n;
  cin >> n;
 vector<int> a(n);
  int ave=0;
  for(int i=0;i<n;i++){
   cin >> a[i];
    ave+=a[i];
  }
  
  int res;
  int dis=1000000;
  for(int i=n-1;i>=0;i--){
  
   if(dis>=abs(n*a[i]-ave)){
    dis=abs(n*a[i]-ave);
    res=i;
   }
  
  
  }
  
   cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int const inf = numeric_limits<int>::max();

template<class T>
struct SegmentTree {
    int n;
    vector<T> dat;
    SegmentTree(int n_ = 0) : n(n_){
        n = 1;
        while(n < n_) n <<= 1;
        dat.resize(n*2, inf);
    }
    T query(int v, int w, int l, int r){
        if(r <= l || w == 0) return inf;
        if(l + w == r) return dat[v];
        return min(query(v*2, w/2, l, min(r, w/2)),
                   query(v*2+1, w/2, max(0, l-w/2), r-w/2));
    }
    void update(int i, T x){
        i += n;
        dat[i] = x;
        for(; i!=1; i/=2) dat[i/2] = min(dat[i], dat[i^1]);
    }
    T query(int l, int r){
        return query(1,n,l,r);
    }
    size_t size() const {
        return n;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n, q;
    cin >> n >> q;
    SegmentTree<int> st(n);
    for(int i = 0; i < q; i++){
        char c;
        int x, y;
        cin >> c >> x >> y;
        if(c == '0'){
            st.update(x,y);
        } else {
            cout << st.query(x,y+1) << '\n';
        }
    }
}

Measured memory_bytes: 2052
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;

int a[maxn], b[maxn];
typedef long long ll;

int main()
{
    int n;
    while(cin>>n){
        for(int i=0;i<=n;i++){
            cin>>a[i];
        }
        for(int i=0;i<n;i++){
            cin>>b[i];
        }
        ll ans=0;
        for(int i=0;i<n;i++){
            int temp = min(b[i], a[i] + a[i+1]);
            ans += temp;
            if(temp < a[i]){
                a[i] = a[i] - temp;
            }
            else if(temp<a[i]+a[i+1]){
                a[i+1] = a[i+1] + a[i] - temp;
            }
            else{
                a[i+1] = 0;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 1024
package main

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

func main() {
	var wtr = bufio.NewWriter(os.Stdout)
	var N, A, B int
	fmt.Scan(&N, &A, &B)
	set := (N / (A + B)) * A
	if N%(A+B) > A {
		set += A
	} else {
		set += N % (A + B)
	}
	fmt.Fprintln(wtr, set)
	_ = wtr.Flush()
}


Measured memory_bytes: 1840
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

using Pair = System.Collections.Generic.KeyValuePair<int, int>;

class Program
{
	public Program() { }

	static void Main(string[] args)
	{
		new Program().prog();
	}
	Scanner cin;
	const int MOD = 1000000007;
	const int INF = int.MaxValue;
	const double EPS = 1e-7;
	
	void prog()
	{
		cin = new Scanner();

		int a = cin.nextInt();
		int b = cin.nextInt();
		int c = cin.nextInt();
		if (a < b && b < c) Console.WriteLine("Yes");
		else Console.WriteLine("No");
	}
}

class Scanner
{
	string[] s;
	int i;

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

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

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

	public int nextInt()
	{
		return int.Parse(next());
	}

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

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

Measured memory_bytes: 8944
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
void Direction(void);  //方角の入力 
void North(void);      //北へ回す
void East(void);       //東へ回す 
void West(void);       //西へ回す
void South(void);      //南へ回す
void Right(void);      //右回転
void Left(void);       //左回転

int sum,n;
int ove,cen,rig,lef,bac,und;   //さいころの場所ごとの状態を示す。
char way[10]={'\0'};

using namespace std;

int main(){

  while(1){


  /*さいころの初期状態*/
  ove=1;  //上
  cen=2;  //前
  rig=3;  //右
  lef=4;  //左
  bac=5;  //後
  und=6;  //下
  sum=1;  //合計値

    scanf("%d",&n);

    if(n==0)break;

    Direction();

    printf("%d\n",sum);
  }

  return 0;
}

void Direction(){

  int i;

  for(i=0;i<n;i++){

    scanf("%s",way);

    if(strcmp(way,"North")==0){

      North();

    }

    else if(strcmp(way,"East")==0){

      East();

    }

    else if(strcmp(way,"West")==0){

      West();

    }

    else if(strcmp(way,"South")==0){

      South();
   
    }

    else if(strcmp(way,"Right")==0){

      Right();

    }

    else if(strcmp(way,"Left")==0){

      Left();

    }

  }

}

void North(){

  int temp;

  temp=cen;
  cen=und;
  und=bac;
  bac=ove;
  ove=temp;

  sum+=ove;


}
void East(){

  int temp;

  temp=lef;
  lef=und;
  und=rig;
  rig=ove;
  ove=temp;

  sum+=ove;

}

void West(){

  int temp;

  temp=rig;
  rig=und;
  und=lef;
  lef=ove;
  ove=temp;

  sum+=ove;

}

void South(){

  int temp;

  temp=bac;
  bac=und;
  und=cen;
  cen=ove;
  ove=temp;

  sum+=ove;

}

void Right(){

  int temp;

  temp=cen;
  cen=rig;
  rig=bac;
  bac=lef;
  lef=temp;

  sum+=ove;

}

void Left(){

  int temp;

  temp=cen;
  cen=lef;
  lef=bac;
  bac=rig;
  rig=temp;

  sum+=ove;
  
}

Measured memory_bytes: 1192
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <map>

using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}

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

ll solve(ll h, ll w) {
  ll ans = h*w;
  for(int i=2; i<h; i++) {
    ll ma = max(max((h-i)*w, (i/2)*w), (i-(i/2))*w);
    ll mi = min(min((h-i)*w, (i/2)*w), (i-(i/2))*w);
    ans = min(ans, ma-mi);
  }
  for(int i=1; i<h; i++) {
    ll ma = max(max((h-i)*w, i*(w/2)), i*(w-(w/2)));
    ll mi = min(min((h-i)*w, i*(w/2)), i*(w-(w/2)));
    ans = min(ans, ma-mi);
  }
  return ans;
}

int main(void) {
  ll h, w;
  cin>>h>>w;
  std::cout << min(solve(h, w), solve(w, h)) << std::endl;
  return 0;
}



Measured memory_bytes: 256