akhauriyash/Code-Regression huggingface dataset:
use std::io::*;
// use std::collections::HashMap;

fn read_int(s: &mut StdinLock) -> usize {
    s.by_ref().bytes().map(|c| c.unwrap() as char)
        .take_while(|c| !c.is_whitespace())
        .skip_while(|c| c.is_whitespace())
        .fold(0, |a, x| (x as u8 - b'0') as usize + a * 10)
}

fn main() {
    let s = stdin();
    let mut s = s.lock();
    let k = read_int(&mut s);
    let mut ll: usize = 0;
    let mut ll_old: usize = 0;
    for _ in 0..k {
        let mut ll_old_vec: Vec<usize> = ll_old.to_string().chars().map(|x| (x as u8 - b'0') as usize).collect();
        let keta = ll_old_vec.len();
        for j in 1..keta {
            if ll_old_vec[keta-j] < ll_old_vec[keta-j-1] || (ll_old_vec[keta-j] == ll_old_vec[keta-j-1] && ll_old_vec[keta-j] != 9) {
                ll_old_vec[keta-j] += 1;
                for k in keta - j + 1..keta {
                    if ll_old_vec[k-1] > 0 {
                        ll_old_vec[k] = ll_old_vec[k-1] - 1;
                    } else {
                        ll_old_vec[k] = 0;
                    }
                }
                ll = ll_old_vec.iter().fold(0, |a, x| *x as usize + a * 10);
                break;
            }
        }
        if ll != ll_old {
            ll_old = ll;
        } else if ll_old_vec[0] == 9 {
            ll = 10_usize.pow(ll_old_vec.len() as u32);
            ll_old = ll;
        } else {
            ll_old_vec[0] = ll_old_vec[0] + 1;
            for j in 1..keta {
                if ll_old_vec[j-1] > 0 {
                    ll_old_vec[j] = ll_old_vec[j-1] - 1;
                } else {
                    ll_old_vec[j] = 0;
                }
            }
            ll = ll_old_vec.iter().fold(0, |a, x| *x as usize + a * 10);
            ll_old = ll;
        }
    }
    println!("{}", ll);
}

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

  cin >> s >> t;

   sort (s.begin(), s.end());
   sort (t.rbegin(), t.rend());


  if (s < t) cout << "Yes" << endl;    
   else cout << "No" << endl;

 return 0;
}

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

using namespace std;
using ll = long long;

int main(){
    cout<<std::setprecision(20);
    int n;cin >> n;
    long double sum = 0;
    for(int i = 0;i < n;i++){
        long double a;cin >> a;
        sum += 1 / a;
    }
    cout<<1/sum<<endl;
}


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

int main(void) {

	int N,i,j;
	int count = 0;
	int m[8][2];
	double h[8][8];
	double x, y;
	double sum=0;
	scanf("%d", &N);
	for (i = 0; i < N; i++) {
		scanf("%d", &m[i][0]);
		scanf("%d", &m[i][1]);
	
	}
	
	for (i = 0; i < 8; i++) {
		for (j = 0; j < 8; j++) {
			h[i][j] = -1;
		}
	}

	for (i = 0; i < N; i++) {
		for (j = i + 1; j < N; j++) {
			x = m[i][0] - m[j][0];
			y = m[i][1] - m[j][1];

			//h[i][j] = sqrt((m[i][0] - m[j][0])*(m[i][0] - m[j][0]) + (m[i][1] - m[j][1])*(m[i][1] - m[j][1]));
			h[i][j] = sqrt(x*x + y * y);
			sum += h[i][j];
			count++;
			//printf("m[%d][0] m[%d][1]:%d %d\n", i, i, m[i][0], m[i][1]);
			//printf("m[%d][0] m[%d][1]:%d %d\n", j, j, m[j][0], m[j][1]);
			//printf("%lf %lf \n", x, y);
			//printf("h[%d][%d] : %lf  \n", i, j, h[i][j]);
		}
	}
	//printf("count:%d\n", count);
	printf("%lf \n", sum/count*(N-1));
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;
ll X[105];
ll Y[105];
ll H[105];
int main() {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  for (int i=0; i<N; i++) {
    cin >> X[i] >> Y[i] >> H[i];
  }
  for (ll x=0; x<=100; x++) {
    for (ll y=0; y<=100; y++) {
      ll h = 1LL << 60;
      for (int i=0; i<N; i++) {
        if (H[i] > 0) {
          ll d = abs(X[i] - x) + abs(Y[i] - y);
          h = min(h, d + H[i]);
        }
      }
      bool f = true;
      for (int i=0; i<N; i++) {
        ll d = abs(X[i] - x) + abs(Y[i] - y);
        ll h0 = max(h - d, 0LL);
        if (h0 != H[i]) {
          f = false;
          break;
        }
      }
      if (f) {
        cout << x << ' ' << y << ' ' << h << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(A,x,n) rep(I,0,n){cout<<(I ? " ":"")<<A[I]x;}cout<<endl;
#define pprint(A,y,m,n) rep(J,0,m){print(A[J],y,n);}
const long mod=998244353;
const int size=3e5+1;
const int inf=1e9;
template<typename T> pair<T,T> bezout(T a,T b){// ax + by = 1, gcd(a, b)=1
	if(__gcd(a, b) != 1) return {0, 0};
	else if(b == 1) return {1, - a + 1};
    else if(a % b == 1) return {1, - a / b};
	else{
		pair<T,T> p = bezout(b, a % b);
		swap(p.first, p.second);
		p.second = p.second - (a / b) * p.first;
        return p;
	}
}
long fact[300010] = {};
void calc(long n){
	fact[0] = 1;
	rep(i,1,n+1) fact[i] = (fact[i-1] * i) % mod;
	return;
}
long modcomb(long n, long r){//nCr mod p
	if(n < r) return 0;
	long x = (fact[n-r] * fact[r]) % mod;
	long res = 1; int i = 0;
	while( (mod-2) >= (1<<i) ){
		if( (mod-2) & (1<<i) ) (res *= x) %= mod;
		i++; x = (x * x) % mod;
	}
    return (res * fact[n]) % mod;
}
int main(){
	int N; long A,B,K; cin>>N>>A>>B>>K;
	long g = __gcd(__gcd(A, B), K);
	A /= g; B /= g; K /= g;
	pair<long,long> p = bezout(A, B);
	p.first *= K; p.second *= K;
	if(p.first > 0){
		p.second += p.first / B * A;
		p.first %= B;
	}else if(p.first < 0){
		p.second -= (- p.first + B - 1) / B * A;
		p.first = (p.first % B + B) % B;
	}
	long ans = 0; calc(N);
	while(p.second > N){ p.first += B; p.second -= A; }
	while(p.first <= N && 0 <= p.second){
		ans += (modcomb(N, p.first) * modcomb(N, p.second)) % mod;
		ans %= mod;
		p.first += B;
		p.second -= A;
	}cout<<ans<<endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define MOD (long long)(1e9 + 7)
using namespace std;

long long ssize = 0;
long long dp[200005][2] = {0}, sum[200005][2] = {0};
string s, t;

long long solve();

int main() {
  cin >> s >> t;
  cout << solve() << endl;
  return 0;
}

long long solve() {
  ssize = s.size();
  dp[0][0] = 1;
  for(int i = 0; i < ssize; ++i) {
    int nums = s[i] - '0', numt = t[i] - '0';
    if(t[i] != '?') {
      if(nums == numt) {
        (dp[i + 1][1] += dp[i][1]) %= MOD;
        (dp[i + 1][0] += dp[i][0]) %= MOD;

        sum[i + 1][1] +=
            (sum[i][1] * 10 % MOD + dp[i][1] * numt % MOD) %
            MOD;
        sum[i + 1][1] %= MOD;
        sum[i + 1][0] +=
            (sum[i][0] * 10 % MOD + dp[i][0] * numt % MOD) %
            MOD;
        sum[i + 1][0] %= MOD;
      }
      else if(nums < numt) {
        dp[i + 1][1] += dp[i][1];
        dp[i + 1][1] %= MOD;

        sum[i + 1][1] +=
            (sum[i][1] * 10 % MOD + dp[i][1] * numt % MOD) %
            MOD;
        sum[i + 1][1] %= MOD;
      }
      else {
        dp[i + 1][1] += dp[i][1];
        (dp[i + 1][1] += dp[i][0]) %= MOD;

        sum[i + 1][1] +=
            (sum[i][1] * 10 % MOD + dp[i][1] * numt % MOD) %
            MOD;
        sum[i + 1][1] %= MOD;
        sum[i + 1][1] +=
            (sum[i][0] * 10 % MOD + dp[i][0] * numt % MOD) %
            MOD;
        sum[i + 1][1] %= MOD;
      }
    }
    else {
      for(int k = 0; k < 10; ++k) {
        numt = k;
        if(nums == numt) {
          (dp[i + 1][1] += dp[i][1]) %= MOD;
          (dp[i + 1][0] += dp[i][0]) %= MOD;

          sum[i + 1][1] += (sum[i][1] * 10 % MOD +
                            dp[i][1] * numt % MOD) %
                           MOD;
          sum[i + 1][1] %= MOD;
          sum[i + 1][0] += (sum[i][0] * 10 % MOD +
                            dp[i][0] * numt % MOD) %
                           MOD;
          sum[i + 1][0] %= MOD;
        }
        else if(nums < numt) {
          dp[i + 1][1] += dp[i][1];
          dp[i + 1][1] %= MOD;

          sum[i + 1][1] += (sum[i][1] * 10 % MOD +
                            dp[i][1] * numt % MOD) %
                           MOD;
          sum[i + 1][1] %= MOD;
        }
        else {
          dp[i + 1][1] += dp[i][1];
          (dp[i + 1][1] += dp[i][0]) %= MOD;

          sum[i + 1][1] += (sum[i][1] * 10 % MOD +
                            dp[i][1] * numt % MOD) %
                           MOD;
          sum[i + 1][1] %= MOD;
          sum[i + 1][1] += (sum[i][0] * 10 % MOD +
                            dp[i][0] * numt % MOD) %
                           MOD;
          sum[i + 1][1] %= MOD;
        }
      }
    }
  }

  return (sum[ssize][1] + sum[ssize][0]) % MOD;
}


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

namespace AtCoder.Contest.B
{
	class Program
	{
		public static void Main(string[] args)
		{
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);

			Scanner cin = new Scanner();

			int a = cin.nextInt();
			int b = cin.nextInt();
			int ans = (b - 1) / (a - 1);
			if ((b - 1) % (a - 1) > 0) ans++;
			Console.WriteLine(ans);
			Console.Out.Flush();
		}
	}

	class Scanner
	{
		string[] s;
		int i;

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

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

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

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

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

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

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

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

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

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

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

signed main() {
    ll N;
    cin>>N;
    vector<ll> L(N);
    rep(i,0,N){
        cin>>L[i];
    }
    sort(begin(L),end(L));
    ll s = 0;
    rep(i,0,N-1){
        s+=L[i];
    }

    if(L[N-1] < s){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}


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

#define MAX 1e+18
vector<long long>v;

int main()
{
    int Ob[100005],Arr[100005]={0},ans=0;
    int N,M,x,y;
    cin>>N>>M;
    for(int i=1;i<=N;i++) cin>>Ob[i];
    for(int i=1;i<=M;i++)
    {
        cin>>x>>y;
        Arr[x]=max(Arr[x],Ob[y]);
        Arr[y]=max(Arr[y],Ob[x]);
    }
    for(int i=1;i<=N;i++)
    {
        if(Ob[i]>Arr[i]) ans++;
    }
    cout<<ans<<endl;
}


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

using namespace std ;

int main()
{
    cin.tie(nullptr) ;
    ios_base :: sync_with_stdio(false) ;
    long long x ;
    cin >> x ;
    string s = "";
    while(x > 0)
    {

        s = (char(((x - 1) % 26) + 'a') ) + s;
        x -- ;
        x /= 26 ;
    }
    cout << s ;
    return 0;
}

Measured memory_bytes: 3616
def resolve():
    x = int(input())
    ans = 0
    if 400 <= x <= 599:
        ans = 8
    elif 600 <= x <= 799:
        ans = 7
    elif 800 <= x <= 999:
        ans = 6
    elif 1000 <= x <= 1199:
        ans = 5
    elif 1200 <= x <= 1399:
        ans = 4
    elif 1400 <= x <= 1599:
        ans = 3
    elif 1600 <= x <= 1799:
        ans = 2
    elif 1800 <= x <= 1999:
        ans = 1
    print(ans)
resolve()

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

int main() {
  std::ios::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  while (true) {
    int n;
    cin>>n;
    if (!n) {
      break;
    }
    int a[n];
    double average=0;
    for (int i=0; i<n; i++) {
      cin>>a[i];
      average+=a[i];
    }
    average/=n;
    int ans=0;
    for (int i=0; i<n; i++) {
      if (a[i]<=average) {
	ans++;
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}




Measured memory_bytes: 3212
import java.util.*;

class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int l = sc.nextInt();
    long a[][] = new long[n][m];
    long b[][] = new long[m][l];
    int i, j, k;
    long sum;
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++) {
        a[i][j] = sc.nextInt();
      }
    }
    for (i = 0; i < m; i++) {
      for (j = 0; j < l; j++) {
        b[i][j] = sc.nextInt();
      }
    }
    for (i = 0; i < n; i++) {
      for (j = 0; j < l; j++) {
        sum = 0;
        for (k = 0; k < m; k++) {
          sum += a[i][k] * b[k][j];
        }
        System.out.printf(j == l - 1 ? "%d%n" : "%d ", sum);
      }
    }
  }
}

Measured memory_bytes: 54484
#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
long long modpow(long long a, long long b){
  long long ans = 1;
  while (b > 0){
    if (b % 2 == 1){
      ans *= a;
      ans %= MOD;
    }
    a *= a;
    a %= MOD;
    b /= 2;
  }
  return ans;
}
long long modinv(long long a){
  return modpow(a, MOD - 2);
}
vector<long long> mf;
long long modfact(long long x){
  if (mf.size() > x){
    return mf[x];
  } else {
    if (mf.empty()){
      mf.push_back(1);
    }
    for (int i = mf.size(); i <= x; i++){
      long long tmp = mf.back() * i % MOD;
      mf.push_back(tmp);
    }
    return mf[x];
  }
}
long long modbinom(long long a, long long b){
  return modfact(a) * modinv(modfact(b)) % MOD * modinv(modfact(a - b)) % MOD;
}
int main(){
  int N, M;
  cin >> N >> M;
  vector<int> p;
  for (int i = 2; i * i <= M; i++){
    if (M % i == 0){
      int cnt = 0;
      while (M % i == 0){
        cnt++;
        M /= i;
      }
      p.push_back(cnt);
    }
  }
  if (M != 1){
    p.push_back(1);
  }
  long long ans = 1;
  int C = p.size();
  for (int i = 0; i < C; i++){
    ans *= modbinom(p[i] + N - 1, p[i]);
    ans %= MOD;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1400
/* ex4_2
  key_tree */

#include <stdio.h>
#include <math.h>

int main(void){
    // 入力
    int A, B, time, minute;
    scanf("%d %d %d %d",&A, &B, &time, &minute);

    double time_angle, minute_angle, angle, ans;
    // 時針と分針の角度をラジアンで求める
    time_angle = 2 * M_PI* ((time + minute / 60.0)/12);
    minute_angle = 2 * M_PI * minute / 60.0;
    // 針同士のなす角度
    angle = fabs(minute_angle - time_angle);
    //　余弦定理
    ans = sqrt(pow(A, 2) + pow(B, 2) 
          - 2 * A *B * cos(angle));
    
    // 小数点以下10桁を表示
    printf("%.10lf\n", ans);

    return 0;

}


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

int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;
	k = min(k, 15);
	char c = 'z';
	for(char x : s){
		c = min(c, x);
	}
	string t = s;
	reverse(t.begin(), t.end());
	string s1 = s + t;
	string best = s;
	for(int i = 0; i < n; i++){
		if(s[i] == c){
			int j = i;
			while(j > 0 && s[j-1] == c) j -= 1;
			int res = (i - j + 1) << (k-1);
			int pos = i+1;
			if(i == n-1){
				res = res << 1;
				pos = 2*n-j;
			}
			res = min(res, n);
			string ans(res, c);
			ans += s1.substr(pos, n - res);
			best = min(best, ans);
		}
	}
	cout << best << '\n';
}

Measured memory_bytes: 384
"""
自分のみを選択することで

3　- 1
4  - 2
5 -3 -1
6 -4 -2
みたいな感じにできるので実質カードは1か2
で2のやつどうしを組み合わせると2つずつ減ってくので、
2の数字の数-2*k,していって
1 - 1
3 -1
2 2
4 -2
みたいな感じになる。

2のやつが１つあるときは、巻き添えで他1つが死ぬ
2のやつが２つあるときは、巻き添えで他のが死ぬことはない。

"""

n = input()
arr = list(map(int,input().split()))
odd = 0
even = 0
cards={}

for a in arr:
    if a not in cards:
        cards[a] = 1
    else:
        cards[a]+=1

for key in cards.keys():
    if cards[key]%2 == 0:
        even += 1
    else:
        odd += 1

if even%2 == 1:
    print(even+odd-1)
else:
    print(even+odd)

Measured memory_bytes: 18272
x, y, z, K = map(int, input().split())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))
Z = list(map(int, input().split()))
XY = []
for i in range(x):
    for j in range(y):
        XY.append(X[i]+Y[j])
XY.sort()
Z.sort()
XYZ = []
for x in XY[::-1][:K]:
    for z in Z:
        XYZ.append(x+z)
XYZ.sort()
print(*XYZ[::-1][:K])


Measured memory_bytes: 147768
#include<stdio.h>
int main(void){
  char b;
  scanf("%c",&b);
  if(b=='A'){
    printf("T\n");
  }
  if(b=='T'){
    printf("A\n");
  }
  if(b=='C'){
    printf("G\n");
  }
  if(b=='G'){
    printf("C\n");
  }
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll INF = mod * mod;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)

int main()
{
    int N, K;
    string S;
    cin >> N >> K >> S;

    vector<char> T;
    T.push_back(S[0]);

    bool flag;
    if (S[0] == 'L') flag = true;
    else flag = false;

    rep(i,N)
    {
        if (flag && S[i] == 'R')
        {
            T.push_back('R');
            flag = false;
        }
        if (!flag && S[i] == 'L') 
        {
            T.push_back('L');
            flag = true;
        }
    }

    int M = T.size();
    int ans = N - M;

    if (M/2 <= K) ans = N-1;
    else ans += 2 * K;
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <cmath>
#define INF 100000000000
#define MOD 1000000007
#define ll long long int
using namespace std;



int main(){
  ll N; cin>>N;
  vector <ll> A; A.resize(N+1,0);
  vector <ll> dp; dp.resize(N+1,0); dp[0] = 0;
  vector <ll> rp; rp.resize(N+1,0); rp[0] = -INF;
  for(int i=0;i<N;i++) cin>>A[i+1];
  dp[1] = (A[1]);
  rp[1] = -(A[1]);

  //cout<<1<<endl;
  //cout<<dp[1]<<"   "<<rp[1]<<endl;
  if(N == 2){
    cout<<max(dp[1] + A[2] , rp[1] - A[2]);
    return 0;
  }

  for(int i=2;i<=N-1;i++){ // 漸化式
//  ll a = A[i-1];
 // ll b = A[i];

  ll dp1,dp2,dp3,dp4;
  ll rp1,rp2,rp3,rp4;

//cout<<i<<endl;
  

  dp1 = max(dp[i-2] + A[i-1] + A[i], dp[i-2] - A[i-1] - A[i]); 
  //cout<<dp1<<endl;
  dp2 = dp[i-1] + A[i];
  dp3 = max(rp[i-2] + A[i-1] + A[i] , rp[i-2] - A[i-1] - A[i]);
  //if(i==2) dp3 = 0;
  //cout<<dp2<<endl;
  //cout<<dp3<<endl;
  dp4 = rp[i-1] - A[i];
  //cout<<dp4<<endl;

  rp1 = max(rp[i-2] - A[i-1] - A[i] , rp[i-2] + A[i-1] + A[i]);
  rp2 = rp[i-1] + A[i];
  rp3 = max(dp[i-2] - A[i-1] - A[i] , dp[i-2] - A[i-1] - A[i]);
  //if(i==2) rp3 = 0;
  rp4 = dp[i-1] - A[i];

dp3 = 0;
dp1 = 0;
rp1=0;
rp3 = 0;
  
ll res_dp = max(dp1,dp2);
res_dp = max(res_dp,dp3);
dp[i] = max(res_dp , dp4);

ll res_rp = max(rp1,rp2);
res_rp = max(res_rp,rp3);
rp[i] = max(res_rp , rp4);


//cout<<dp[i]<<"   "<<rp[i]<<endl;


  }


cout<<max(dp[N-1] + A[N] , rp[N-1] - A[N]) <<endl;

  return 0;
}

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


int main(){
    char S[100];
    cin >> S;
    int N;
    N = strlen(S);

    bool answer = true;

    for(int i=0; i<N/2-1; i++){
        if(S[i] != S[N-1-i]){
            answer = false;
        }
    }

    for(int j=0; j<(N-1)/4; j++){
        if(S[j] != S[(N-1)/2-j-1]){
            answer = false;
        }
    }

    for(int k=0; k<(N-3)/2; k++){
        if(S[(N+3)/2-1+k] != S[N-k-1]){
            answer = false;
        }
    }

    if(answer){
        cout << "Yes";
    }
    else{
        cout << "No";
    }

    return 0;
}

Measured memory_bytes: 256
a,b = map(int, input().split())
if a%2:
    if (b-a)%2:
        print((( (b-a-1) // 2) % 2) *1 ^ a ^ b)
    else:
        print((( (b-a) // 2) % 2) *1 ^ a)
else:
    if (b-a+1)%2:
        print((( (b-a) // 2) % 2) *1 ^ b)
    else:
        print((( (b-a+1) // 2) % 2) *1)

Measured memory_bytes: 3060
'use strict'

const main = (input) => {
    input = input.split(' ').map(i => parseInt(i))
    const A = input[0]
    const B = input[1]
    const K = input[2]

    let nums = new Set()
    for(let i = A; i <= Math.min(A + K - 1, B); i++){
        nums.add(i)
    }
    for(let i = Math.max(B - K + 1, A + K); i <= B; i++){
        nums.add(i)
    }
    nums.forEach(v => console.log(v))
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))

Measured memory_bytes: 22956
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
int n;
ll a[111111];

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

  ll ans = 0;
  ll k = 1;
  for(int i = 0; i < n; i++){
    if(a[i] > k){
      ans += (a[i]-1)/k;
      k = max(k,2LL);
    }else if(a[i] == k){
      k++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
N=int(input())
T,A=map(int,input().split())
H=list(map(int,input().split()))
nin=10**6
ans=0

for i in range(N):
    ave=T-H[i]*0.006
    dif=abs(A-ave)
    if dif<nin:
        ans=i
        nin=dif

print(ans+1)

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

using namespace std;

int main(void) {
  int K;
  cin >> K;

  int i, j, k;
  int flag = 0;
  int coef = 0;
  long long ans = 0;
  for (i = 1;i <= K;i++) {
    for (j = i;j <= K;j++) {
      for (k = j;k <= K;k++) {
        flag = 0;
        if (i == j) flag++;
        if (j == k) flag++;
        if (i == k) flag++;
        
        if (flag == 0) {
          // a b c -> 6
          coef = 6;
        } else if (flag == 1){
          // a a b -> 3
          coef = 3;
        } else {
          // a a a -> 1
          coef = 1;
        }
        
        ans += gcd(gcd(i, j), k) * coef;
      }
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3648
odd, even = map(int, input().split(" "))
odd_list = [1] * odd
even_list = [2] * even
nums = odd_list + even_list
counter = 0
for x in range(len(nums)):
    if x == len(nums) - 1:
        break
    else:
        for y in nums[x + 1:]:

            if (nums[x] + y) % 2 == 0:
                counter += 1
print(counter)



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

int main() {
  int N, i, j;
  cin >> N;
  i = N;
  while (i > 0) {
    j += i % 10;
    i /= 10;
  }
  
  if (N % j == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int    
#define mod 1000000007

int main()
{
    ll n;
    cin>>n;
    ll ar[n]={0};
    ll sum=0;

    unordered_map<int,int> mp;

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

    // for(auto i:mp)
    // {
    //     cout<<i.second<<' ';
    // }
    // cout<<sum;
    ll t;
    cin>>t;
    while(t--)
    {
        ll b,c;
        cin>>b>>c;
        sum=sum-(mp[b]*b);
        sum=sum+mp[b]*c;
        mp[c]=(mp[c]+mp[b]);
        mp[b]=0;
        // cout<<mp[c]<<endl;
        cout<<sum<<endl;
    }
}

Measured memory_bytes: 7764
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// lib/prime_sieve.hpp
#ifndef PRIME_SIEVE_HPP
#define PRIME_SIEVE_HPP


/*
// primes are all primes less than or equal to 100
std::vector<std::int_fast64_t> primes = tools::prime_sieve<std::int_fast64_t>(100);
*/

namespace tools {
  template <typename T>
  std::vector<T> prime_sieve(const T n) {
    std::vector<bool> is_prime(n + 1, true);
    is_prime[0] = false;
    is_prime[1] = false;

    const T max = static_cast<T>(std::sqrt(n));
    for (T i = 2; i <= max; ++i) {
      if (is_prime[i]) {
        for (T j = i * 2; j <= n; j += i) {
          is_prime[j] = false;
        }
      }
    }

    std::vector<T> result;
    for (T i = 0; i <= n; ++i) {
      if (is_prime[i]) {
        result.push_back(i);
      }
    }
    return result;
  }
}

#endif

// main.cpp

int main() {
  i64 X;
  std::cin >> X;
  const std::vector<i64> primes = tools::prime_sieve<i64>(100003);
  std::cout << *std::lower_bound(primes.begin(), primes.end(), X) << std::endl;
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
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;}

vector<int> ab[201010];
int P[201010];
bool passed[201010];
int n,q;

void dfs(int now){
    passed[now] = true;
    for(int next : ab[now]){
        if(passed[next]) continue;
        P[next] += P[now];
        dfs(next);
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n>>q;
    rep(i,n-1){
        int a,b;cin>>a>>b;
        ab[a].push_back(b);
        ab[b].push_back(a);
    }
    rep(i, 201010){
        passed[i] = false;
        P[i] = 0;
    }
    rep(i,q) {
        int p,x; cin>>p>>x;
        P[p] += x;
    }

    dfs(1);
    for(int i=1; i<=n; i++){
        cout<<P[i]<<" ";
    }
    cout<<endl;
    return 0;
}

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

using namespace std;

int main()
{
    bool a[3][3]={0};
    map<int,vector< pair<int,int> > >m;
    for (int i=0;i<3;i++)
        for (int j=0;j<3;j++)
    {
        int h;
        cin>>h;
        m[h].push_back({i,j});
    }
    int n;
    cin>>n;
    while(n--)
    {
        int h;
        cin>>h;
        for (int i=0;i<m[h].size();i++)
            a[m[h][i].first][m[h][i].second]=1;
    }
    for (int i=0;i<3;i++)
    {
        bool f=0,f1=0;
        for (int j=0;j<3;j++)
        {
           if (a[i][j]==0)
            f=1;
            if (a[j][i]==0)
                f1=1;
        }
        if (!f || !f1)
        {
            cout<<"Yes";
            return 0;
        }
    }
       if ((a[0][0] && a[1][1] && a[2][2]) || (a[0][2] && a[1][1] && a[2][0]))
       cout<<"Yes";
       else
        cout<<"No";
    return 0;
}


Measured memory_bytes: 256
import collections


def solve():
    s = input()
    if s[0] == s[-1]:
        if len(s)%2 == 0:
            print("First")
        else:
            print("Second")
    else:
        if len(s)%2 == 0:
            print("Second")
        else:
            print("First")

if __name__ == "__main__":
    solve()


Measured memory_bytes: 3572
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
using namespace std;
typedef long long int ll;
typedef vector< int > vi;
typedef pair< int, int > ii;
typedef vector< ii > vii;
typedef vector< ll > vll;
// #define DEBUG_MODE
#ifdef DEBUG_MODE
	#define errp(...) fprintf(stderr, __VA_ARGS__)
	#define dbg(x) fprintf(stderr, "[%s = %d]\n", #x, x)
#else
	#define errp(...)
	#define dbg(x) 
#endif

ll gcd_ext (ll a, ll b, ll &x, ll &y) {
	if (a == 0) {
		x = 0;
		y = 1;
		return b;
	}

	ll xn, yn, g;
	g = gcd_ext(b % a, a, xn, yn);
	x = yn - xn * (b / a);
	y = xn;
	return g;
}

ll mod_inv (ll a, ll b) {
	ll x, y, g;
	g = gcd_ext(a, b, x, y);
	if (g != 1) return -1;
	return (x % b + b) % b; /* x may be negative */
}

ll sub (ll a, ll b, ll p) {
	ll res = a - b;
	if (res < 0) res += p;
	return res;
}

ll add (ll a, ll b, ll p) {
	ll res = a + b;
	if (res >= p) res -= p;
	return res;
}

ll mul (ll a, ll b, ll p) {
	return ((a % p) * (b % p)) % p;
}

ll bin_exp (ll a, ll b, ll p) { /* pow(a, b) % p */
	if (b == 1) return a % p;
	if (b & 1) return mul(a, bin_exp(a, b - 1, p), p);
	else {
		ll x = bin_exp(a, b / 2, p);
		return mul(x, x, p);
	}
}

const ll MOD = (ll)1e9 + 7;
const int N = 200010;
ll fact[N];
ll n, m, k;

ll calc (ll r, ll c) {
	ll a = r * (r - 1) + (n - r) * (n - r + 1);
	ll b = c * (c - 1) + (m - c) * (m - c + 1);
	return add(mul(a, m, MOD), mul(b, n, MOD), MOD);
}

int main () { 
#ifdef DEBUG_MODE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	fact[0] = 1;
	for (int i = 1; i < N; i++)
		fact[i] = mul(fact[i - 1], i, MOD);

	scanf("%lld %lld %lld", &n, &m, &k);
	ll f = mul(fact[n * m - 2], mul(mod_inv(fact[k - 2], MOD),
		mod_inv(fact[n * m - k], MOD), MOD), MOD);

	ll res = 0;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			res = add(res, mul(f, calc(i, j), MOD), MOD);

	res = mul(res, mod_inv(4, MOD), MOD);
	printf("%lld\n", res);
}

Measured memory_bytes: 1664
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<bitset>
#include<vector>
#include<map>
#include<ctime>
#include<cstdlib>
#include<set>
#include<bitset>
#include<stack>
#include<list>
#include<cmath>
using namespace std;
#define RP(t,a,b) for(register int (t)=(a),edd_=(b);t<=edd_;++t)
#define DRP(t,a,b) for(register int (t)=(a),edd_=(b);t>=edd_;--t)
#define ERP(t,a) for(int t=head[a];t;t=e[t].nx)
#define Max(a,b) ((a)<(b)?(b):(a))
#define Min(a,b) ((a)<(b)?(a):(b))
#define TMP template<class ccf>
#define lef L,R,l,mid,pos<<1
#define rgt L,R,mid+1,r,pos<<1|1
#define midd register int mid=(l+r)>>1
#define chek if(R<l||r<L)return
#define all 1,n,1
#define pushup(x) seg[(x)]=seg[(x)<<1]+seg[(x)<<1|1]
typedef long long ll;
TMP inline ccf qr(ccf k){
    char c=getchar();
    ccf x=0;
    int q=1;
    while(c<48||c>57)
	q=c==45?-1:q,c=getchar();
    while(c>=48&&c<=57)
	x=x*10+c-48,c=getchar();
    if(q==-1)
	x=-x;
    return x;
}
const int maxn=505;
bool g1[maxn][maxn];
int m,n;

inline bool qrqr(){
    char c=getchar();
    while(c!='.'&&c!='#')
	c=getchar();
    return c=='#';
}


int main(){
    n=qr(1);
    m=qr(1);
    RP(t,1,n)
	RP(i,1,m)
	g1[t][i]=qrqr();

    RP(t,1,n){
	RP(i,1,m)
	    if(g1[t][i]||((t&1)&&i!=m)||i==1)
		cout<<'#';
	    else
		cout<<'.';
	cout<<endl;
    }putchar('\n');
    RP(t,1,n){
	RP(i,1,m)
	    if(g1[t][i]||((!(t&1))&&i!=1)||i==m)
		cout<<'#';
	    else
		cout<<'.';
	cout<<endl;
    }
    return 0;
}




Measured memory_bytes: 1024
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
using lint = long long;

class Combi {
private:
	vector<lint> fac, inv, finv;

	void init(int N) {
		fac[0] = fac[1] = 1; inv[1] = 1; finv[0] = finv[1] = 1;

		for (int i = 2; i < N; i++) {
			fac[i] = fac[i - 1] * i % MOD;
			inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
			finv[i] = finv[i - 1] * inv[i] % MOD;
		}
	}

public:
	Combi(int N = 100000) : fac(N + 1), inv(N + 1), finv(N + 1) { init(N + 1); }

	lint Cmod(int n, int k) {
		if (n < k) return 0;
		if (n < 0 || k < 0) return 0;
		return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
	}

	lint Pmod(int n, int k) {
		if (n < k) return 0;
		if (n < 0 || k < 0) return 0;
		return fac[n] * finv[n - k] % MOD;
	}
};

Combi C;
vector<vector<int>> edges;

lint dfs(int k, vector<int> edge, int now, int from) {

	lint res = C.Pmod(k - (now != 0), (int)edge.size() - (now != 0));
	for (const auto &e : edge) {
		if (e != from) {
			res *= dfs(k, edges[e], e, now);
			res %= MOD;
		}
	}
	
	return res;

}

int main() {

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

	int N, K;
	cin >> N >> K;
	edges.resize(N);
	int u, v;
	for (int i = 0; i < N - 1; i++) {
		cin >> u >> v;
		edges[u - 1].emplace_back(v - 1);
		edges[v - 1].emplace_back(u - 1);
	}

	lint ans = K * dfs(K - 1, edges[0], 0, 0) % MOD;
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 19840
#include<stdio.h>

void bubbleSort(int *A, int N)
{
    int flag = 1;
    int buff, count = 0;
    while(flag == 1){
        flag = 0;
        for(int j = N-1; j > 0; j--)
        {
            if(A[j] < A[j-1])
            {
                count++;
                buff = A[j];
                A[j] = A[j-1];
                A[j-1] = buff;
                flag = 1;
            }
        }
    }
    for(int k = 0; k < N; k++){
        printf("%d", A[k]);
        if(k != N-1){
            printf(" ");
        }
    }
    printf("\n");
    printf("%d\n",count);
}

int main(void){
    int N, a;
    
    scanf("%d",&N);
    int A[N];
    
    for(int i = 0; i < N;i++)
    {
        scanf("%d",&a);
        A[i] = a;
    }
    bubbleSort(A, N);
    return 0;
}



Measured memory_bytes: 1992
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>
#include <functional>
#include <vector>
#include <stack>
#include <set>
using namespace std;
typedef long long ll;
const int maxn=3e5+50;
const int inf=0x3f3f3f3f;
const int MOD=1e9+7;
const int HASH=131;

int a[maxn];
int n,k;

bool jungle(int mid)
{
    if(mid==0) return false;
    int ti=0;
    for(int i=1;i<=n;i++)
    {
        if(a[i]<mid) continue;
        ti+=a[i]/mid-1;
        if(a[i]%mid>0) ti++;
        if(ti>k) return false;
    }
    return true;
}

int main()
{
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a+1,a+1+n);
    int r=a[n];
    int l=0;
    int mid;
    int ans=0;
    while(l<=r)
    {
        mid=(l+r)>>1;
        if(!jungle(mid))
        {
            l=mid+1;
        }
        else
        {
            r=mid-1;
            ans=mid;
        }
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 4420
n, m, c = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)
count = 0
n.times do
    a = gets.split.map(&:to_i)
    sum = 0
    m.times do |m|
        sum += a[m]*b[m]
    end
    count += 1 if sum+c > 0
end
puts count

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
#define INF 1e9
typedef long long ll;
//約数列挙O(root n)

int divisor(int n){
  int num=0;
  for(int i=1; i<=sqrt(n); i++){
    if(n%i == 0){
      num++;
      if(i!=n/i) num++;
    }
  }
  return num;
}

int main(void){
  int N;cin >> N;
  int i,num=0;
  REP(i,N+1){
    if(i%2==1){
      int n = divisor(i);
      if(n==8) num++;
    }
  }
  cout << num << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int N,M;
  scanf("%d",&N);
  scanf("%d",&M);
  if(N<=100 && N>0 && M>=0 && M<=N)
  {
      if(M==N)
        printf("Yes");
      else
        printf("No");
  }
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string  s;
	cin>>s;
	if(count(all(s),'o')+15-s.size()>=8)puta("YES");
	else puta("NO");
		return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<map>
#include<algorithm>
using namespace std;

#define ran 202202

struct modular_arithmetic{
	int mod;

	modular_arithmetic(){
		mod = 998244353;
	}
	//No specific settings.
	int add(int x,int y){return (x+=y)<mod?x:x-mod;}
	int sub(int x,int y){return (x-=y)>=0?x:x+mod;}
	int mul(int x,int y){return (int)((long long int)x*y%mod);}
};
modular_arithmetic ma;

struct BIT {
    int max_val;
    int a[ran];
    const static int mo = 998244353;

	BIT() {}
    BIT(int maxv) { max_val = maxv; }

    inline int lowbit(int x) { return x & (-x); }
    inline int madd(int a, int b) {
        return (a+=b) >= mo ? a-mo : (a<0 ? a+mo : a);
    }

    void clear() { memset(a, 0, sizeof(a)); }
    void clear(int max_id) {
        for(int i=0;i<=max_id;i++) a[i]=0;
    }

    void add(int pos, int val) {
        for (pos = max(1, pos); pos <= max_val; pos += lowbit(pos))
            a[pos] = madd(a[pos], val);
    }

    int query(int pos) {
        int res = 0;
        for (; pos; pos -= lowbit(pos))
            res = madd(res, a[pos]);
        return res;
    }

    int query(int l, int r) {
		if (l>r || l<0) return 0;
		int res = query(r) - (l ? query(l-1) : 0);
		// printf("%d %d %d\n", l, r, res);
        return res;
    }
} b;


int n;
pair<int, int> a[ran];
int pw[ran];

int cmp_x(const pair<int, int> &a, const pair<int, int> &b) {
	return a.first < b.first;
}
int cmp_y(const pair<int, int> &a, const pair<int, int> &b) {
	return a.second < b.second;
}

int main() {
	scanf("%d", &n);

	for(int i=0;i<n;i++)
		scanf("%d%d", &a[i].first, &a[i].second);
	
	sort(a, a+n, cmp_x);
	for(int i=0;i<n;i++) a[i].first = i+1;
	sort(a, a+n, cmp_y);
	for(int i=0;i<n;i++) a[i].second = i+1;
	
	pw[0] = 0;
	for(int i=1;i<=n;i++)
		pw[i] = ma.add(ma.mul(pw[i-1], 2), 1);
	
	int res = ma.mul(n, pw[n]);
	
	sort(a, a+n, cmp_x);
	b.max_val = n;
	b.clear();
	for(int i=0;i<n;i++) {
		res = ma.sub(res, pw[i]);
		res = ma.sub(res, pw[n-i-1]);
		
		res = ma.add(res, pw[b.query(1, a[i].second - 1)]);
		res = ma.add(res, pw[b.query(a[i].second + 1, n)]);
		b.add(a[i].second, 1);
	}
	b.clear();
	for(int i=n-1;i>=0;i--) {
		res = ma.add(res, pw[b.query(1, a[i].second - 1)]);
		res = ma.add(res, pw[b.query(a[i].second + 1, n)]);
		//printf("add: %d\n", a[i].second);
		b.add(a[i].second, 1);
	}
	
	sort(a, a+n, cmp_y);
	for(int i=0;i<n;i++) {
		res = ma.sub(res, pw[i]);
		res = ma.sub(res, pw[n-i-1]);
	}
	
	printf("%d\n", res);
	
	return 0;
}

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

using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define TRAV(a, x) for(const auto& a : x)
#define ALL(x) x.begin(), x.end()
#define NEXT_PERM(x) while(next_permutation(ALL(x))) // 순열 알고리즘(오름)
#define PREV_PERM(x) while(prev_permutation(ALL(x))) // 순열 알고리즘(내림)
#define PRINT(x) cout << x
#define PRINT_LN(x) cout << x << endl;
#define DUMP(a, n) REP(_i, n) printf("%d%c", a[_i], _i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(_i, n) REP(_j, m) printf("%d%c", a[_i][_j], _j + 1 == m ? '\n' : ' '); puts("")

typedef long long int ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;

int gcd(int a, int b);
int lcm(int a, int b);

void solve() {
  int n;
  cin >> n;
  int result = 0;
  REP(i,n){
    REP(j,n){
      REP(k,n){
        result += gcd(i+1, gcd(j+1, k+1));
      }
    }
  }
  cout << result;
}

int main() {
  solve();
  return 0;
}

int gcd(int a, int b){
	while(b!=0){
		int r = a%b;
		a= b;
		b= r;
	}
	return a;
}

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


Measured memory_bytes: 3636
N = int(input())
a = sorted(list(map(int, input().split())))

def find_p(n, i):
    lo = 0
    hi = i
    mid = (hi-lo)//2
    xl = a[0]
    xh = a[i]
    while hi - lo > 1:
        mid = (hi+lo)//2
        if a[mid] > n//2:
            hi = mid
        else:
            lo = mid
    if abs(a[lo] - n/2) > abs(a[hi] - n/2):
        return a[hi]
    else:
        return a[lo]



print(str(a[-1]) + ' ' + str(find_p(a[-1], N-1)))

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

const int MAXN = 100000;
ll x[MAXN+2], v[MAXN+2], sum[MAXN+2];

int main() {
  int n;
  ll c;
  cin >> n >> c;
  rep(i, n) {
    cin >> x[i+1] >> v[i+1];
  	sum[i+1] = sum[i] + v[i+1];
  }
  ll lmax[n+2], rmax[n+2];
  lmax[0] = rmax[n+1] = 0;
  rep(i, n) {
    lmax[i+1] = max(lmax[i], sum[i+1] - x[i+1]);
    rmax[n-i] = max(rmax[n-i+1], (sum[n]-sum[n-i-1]) - (c-x[n-i]));
  }
  ll ans = 0;
  rep(i, n) {
    ans = max(ans, sum[i+1]-2*x[i+1]+rmax[i+2]);
    ans = max(ans, (sum[n]-sum[n-i-1]) - 2*(c-x[n-i]) + lmax[n-i-1]);
  }
  ans = max(ans, max(lmax[n], rmax[1]));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4096
D, G = map(int, input().split())
P = []
C = []
for i in range(D):
  p, c = map(int, input().split())
  P.append(p)
  C.append(c)
  
out = 1000
for i in range(2**D):
  total = 0
  count = 0
  for j in range(D):
    p, c = P[j], C[j]
    if i & (1 << j):
      count += p
      total += p * 100 * (j + 1) + c
    else:
      k = j
      
  if total >= G:
    out = min(out, count) 
    continue
    
  p = P[k]
  for j in range(p):
    count += 1
    total += 100 * (k + 1)
    if total >= G:
      out = min(out, count)
      break

print(out)

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_1_C&lang=jp

"""
import sys
from sys import stdin
input = stdin.readline


def main(args):
    a, b = map(int, input().split())
    print(a*b, (a*2 + b*2))


if __name__ == '__main__':
    main(sys.argv[1:])

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

int main(){
    int n;
    cin>>n;
    int arr[n];

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

    int flag = 1;

    for(int i=1;i<n;i++){
        if(arr[i] < arr[i-1]){
            flag = 0;
            break;
        }
        else if(arr[i] == arr[i-1]){
            continue;
        }
        else{
            arr[i] = arr[i]-1;
        }
    }

    //for(int i=0;i<n;i++){
        //cout<<arr[i]<<" ";
    //}
    //cout<<endl;

    if(flag){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }


}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;



int main()
{
    ll n,ans;
    cin>>n;
    if(n%1000==0)
        ans=0;
    else{
        ans=1000*(n/1000+1)-n;
    }
    cout<<ans<<endl;
	return 0;
}



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

int main(){
    string s;
    cin>>s;
    int ans = 0;
    int currLen =0;
    for(int i=0;i<3;i++){
        if(s[i] == 'R'){
            ++currLen;
            if(currLen > ans)
                ans = currLen;
        }
        else{
            currLen = 0;
        }
    }
    cout<<ans;
}

Measured memory_bytes: 3196
#include <algorithm>
#include <iostream>
#include <climits>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <set>
#include <map>

using namespace std;

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define ll long long
#define mod 1000000007
#define vi vector<int>
#define vll vector<ll>
#define pb push_back

// D R U L
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

const int mx = 1e6 + 5;
const int INF = mod;

ll power(int x, unsigned int y){
    ll res = 1;
    while(y > 0){
        if(y & 1) res = res * x;
        y >>= 1;
        x *= x;
    }
    return res;
}



// Check for number of Cases!!
void solve() {
    ll arr[4];
    
    for(int i = 0; i < 4; i++) {
        cin >> arr[i];
    }

    ll ans = LLONG_MIN;

    for(int i = 0; i < 2; i++) {
        for(int j = 2; j < 4; j++) {
            ans = max(ans, arr[i] * arr[j]);
        }
    }

    cout << ans;
}

int main(){

    #ifndef ONLINE_JUDGE
    freopen("/ATOMCODES/input.txt", "r", stdin);
    freopen("/ATOMCODES/output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int t = 1;
    // cin >> t;
    while(t--) {
      solve();
    }
}

Measured memory_bytes: 3636
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long MAX = 5100000;
const long long INF = 1LL << 60;
const long long mod = 1000000007LL;
//const long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

struct Train {
	ll t;
	int is_in;
	Train(ll _t, int _is_in) :t(_t), is_in(_is_in) {}
	bool operator< (const Train& tr) {
		if (t == tr.t) {
			return is_in < tr.is_in;
		}
		else {
			return t < tr.t;
		}
	}
};
int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	while (1) {
		ll n; scanf("%lld", &n);
		if (n == 0) break;
		ll a[30][30] = {};
		ll nx = 10;
		ll ny = 10;
		for (ll i = 0; i < n; i++) {
			ll x, y; scanf("%lld %lld", &x, &y);
			a[x][y]++;
		}
		ll m; scanf("%lld", &m);
		for (ll i = 0; i < m; i++) {
			char c;
			ll len;
			cin >> c >> len;
			if (c == 'N') {
				for (ll i = ny + 1; i <= ny + len; i++) {
					if (a[nx][i] > 0) a[nx][i]--;
				}
				ny += len;
			}
			if (c == 'S') {
				for (ll i = ny - 1; i >= ny - len; i--) {
					if (a[nx][i] > 0) a[nx][i]--;
				}
				ny -= len;
			}
			if (c == 'E') {
				for (ll i = nx + 1; i <= nx + len; i++) {
					if (a[i][ny] > 0) a[i][ny]--;
				}
				nx += len;
			}
			if (c == 'W') {
				for (ll i = nx - 1; i >= nx - len; i--) {
					if (a[i][ny] > 0) a[i][ny]--;
				}
				nx -= len;
			}
		}
		bool flag = true;
		for (int i = 0; i < 30; i++)for (int j = 0; j < 30; j++) if (a[i][j] > 0) flag = false;
		if (flag) puts("Yes");
		else puts("No");
	}
	return 0;
}


Measured memory_bytes: 3100