akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;
//import java.util.Map.Entry;
//import java.util.stream.*;
//import java.math.*;

public class Main {

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        Scanner sc = new Scanner(System.in);
        long MOD = (long) (Math.pow(10, 9) + 7);
        String str = br.readLine();
        StringBuilder s = new StringBuilder(str);
        while (true && str.length() >= 2) {
            s = s.deleteCharAt(s.length() - 1);
            if (s.substring(0, s.length() / 2).equals(s.substring(s.length() / 2, s.length()))) {
                System.out.println(s.length());
                return;
            }
        }
        System.out.println(0);
        bw.flush();
    }
//==============================================//
//==============================================//
//==============================================//
//==============================================//
//==============================================//
//==============================================//
//==============================================//
//==============================================//

    static class Pair implements Comparable<Pair> {

        int a, b;

        public Pair(int x, int y) {
            a = x;
            b = y;
        }

        @Override
        public int compareTo(Pair p) {
            return a - p.a;
        }
    }

    static void forl_0(int n, int[] array, Scanner sc) {
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }
    }

    static void forl_1(int n, int[] array, Scanner sc) {
        for (int i = 1; i <= n; i++) {
            array[i] = sc.nextInt();
        }
    }

    static void two_d(int n, int m, int[][] array, Scanner sc) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                array[i][j] = sc.nextInt();
            }
        }
    }

    static boolean isPrime(long n) {
        if (n < 2) {
            return false;
        } else if (n == 2 || n == 3) {
            return true;
        } else if (n % 2 == 0 || n % 3 == 0) {
            return false;
        }
        long sqrtN = (long) Math.sqrt(n) + 1;
        for (long i = 6L; i <= sqrtN; i += 6) {
            if (n % (i - 1) == 0 || n % (i + 1) == 0) {
                return false;
            }
        }
        return true;
    }

    public static long gcd(long a, long b) {
        return (b == 0) ? a : gcd(b, a % b);
    }

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


Measured memory_bytes: 26952
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll a,b,c;
  cin>>a>>b>>c;
  ll sum=0;
  REP(i,1,b){
    if((a*i)%b==c){
      cout<<"YES"<<'\n';
      return(0);
    }
  }
  cout<<"NO"<<'\n';
  return(0);
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <string>
#include <utility>
#include <cassert>
#include <functional>
#include <numeric>
#include <chrono>
#include <random>
#include <optional>

using namespace std;
typedef long long ll;

const int MAXN = 2e5+10;
int n;
ll preSum[MAXN], a[MAXN];

// [i, j]
inline ll sumRange(int i, int j) {
  assert(i <= j);
  return i == 0 ? preSum[j] : preSum[j] - preSum[i-1];
}

ll getBest(ll k) {
  ll sum = sumRange(0, k);
  int lo = 0;
  int hi = k;
  while (hi - lo > 1) {
    int mid = (hi + lo) / 2;
    if (sumRange(0, mid) >= sum/2) {
      hi = mid;
    } else {
      lo = mid;
    }
  }
  int i = hi;

  sum = sumRange(k+1, n-1);
  lo = k+1;
  hi = n-1;
  while (hi - lo > 1) {
    int mid = (hi + lo) / 2;
    if (sumRange(k+1, mid) >= sum/2) {
      hi = mid;
    } else {
      lo = mid;
    }
  }
  int j = hi;

  ll res = 1e18;
  // cerr << "i: " << i << " k: " << k << " j: " << j << endl;
  for (int izq = i-2; izq <= i+1; izq++) {
    for (int der = j-2; der <= j+1; der++) {
      if (izq > 0 && der > k+1 && izq <= k && der <= n-1) {
        ll P = sumRange(0, izq-1);
        ll Q = sumRange(izq, k);
        ll R = sumRange(k+1, der-1);
        ll S = sumRange(der, n-1);
        ll mx = max({P, Q, R, S});
        ll mn = min({P, Q, R, S});
        res = min(res, mx - mn);
        // cerr << izq << "  " << der << endl;
        // cerr << P << " " << Q << " " << R << " " << S << endl;
        // cerr << mx - mn << endl;
      }
    }
  }
  return res;
}


int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  preSum[0] = a[0];
  for (int i = 1; i < n; i++) preSum[i] = preSum[i-1] + a[i];

  ll ans = 1e18;
  for (int k = 1; k < n-2; k++) {
    ll op = getBest(k);
    ans = min(ans, op);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6756
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())

    neg = sum(1 for a in A if a < 0)
    ans = sum(abs(a) for a in A)

    if neg % 2 == 1:
        ans -= 2 * min(abs(a) for a in A)

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 20068
MOD=10**9+7

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

B=A+A
C=[0]*N
D=[0]*N

for i in range(N):
    for j in range(i,2*N):
        if(B[i]>B[j]):
            C[i]+=1
for i in range(N):
    for j in range(i,N):
        if(B[i]>B[j]):
            D[i]+=1

c=sum(C)%MOD
d=sum(D)%MOD
c=(c-d)%MOD
t=((K*(2*d+((K-1)*c)))//2)%MOD

print(t)

Measured memory_bytes: 3188
main :: IO ()
main = do
  n <- readLn :: IO Int
  map read . words <$> getLine >>= print . solve

solve :: [Integer] -> Integer
solve as = if even negatives then sum abss else sum abss - 2 * mn
  where
    negatives = length . filter (<0) $ as
    abss = map abs as
    mn = minimum abss

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

using namespace std;

int main() {
  int N, ans = 0;
  vector<int> l;
  
  cin >> N;
  
  for (int i = 0; i < N; i++) {
    int _in;
    
    cin >> _in;
    
    l.push_back(_in);
  }
  
  for (int i = 0; i < N; i += 2) {
    if (l[i] % 2 == 1) {
      ans++;
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3572
n,y=map(int,input().split())
for i in range(n+1):
     for j in range(n+1-i):
        z_m=y-(10000*i+5000*j)
        z_n=n-(i+j)
        if z_m>=0 and z_m//1000==z_n:
          print(i,j,z_n)
          exit()
print(-1,-1,-1)

Measured memory_bytes: 3188
/*
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/

#ifdef LOCAL
#include "debug.h"
#else
#include<bits/stdc++.h>
using namespace std;
#define debug(x...)
#endif
 
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> 
using ordered_set= tree<T, null_type, 
		less<T>, 
		rb_tree_tag, tree_order_statistics_node_update> ;
template<class T> 		
using ordered_mset= tree<T, null_type, 
		less_equal<T>, 
		rb_tree_tag, tree_order_statistics_node_update> ;
		
*/
 
/*
 
PBDS
-------------------------------------------------
			0 based indexing
-------------------------------------------------			 
1) insert(value)
2) erase(value)
3) order_of_key(value) // Number of items strictly smaller than value
4) *find_by_order(k) : K-th element in a set (counting from zero)
 
*/
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());	

const int mx=2e5+5;

int color[mx];
set<int>g[mx];
vector<int>vec;

void dfs(int u)
{
	color[u]=1;
	vec.push_back(u);
	
	for(int v: g[u]) if(!color[v]) dfs(v);
	
}

void solve()
{
	int n,m;
	cin>>n>>m;
	
	for(int i=0;i<m;i++)
	{
		int u,v;
		cin>>u>>v;
		
		g[u].insert(v);
		g[v].insert(u);
	}
	
	int ans=0;
	
	for(int i=1;i<=n;i++)
	{
		if(!color[i])
		{
			dfs(i);
			ans=max(ans,(int)vec.size());
			vec.clear();
		}
	}
	
	cout<<ans;
}		

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	int testcase=1;
	//cin>>testcase;
	
	for(int i=1;i<=testcase;i++)
	{
		//cout<<"Case "<<i<<": ";
		solve();
	}
	
	#ifdef LOCAL
	cerr<<"\nTime elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms\n";
	#endif
	
	
	return 0;
}


Measured memory_bytes: 42384
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1e9+10)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))


int main(void){
	int a,b,c;
	cin>>a>>b>>c;
	if(a==b && b==c){
		cout<<"Yes"<<endl;
	}else{
			cout<<"No"<<endl;
		}
		return 0;
	
}


Measured memory_bytes: 636
/*input
101
*/

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

int main() {
    int n;
    cin >> n;
    int m = (n+1)/2;
    cout << (double)m/n << endl;
}

Measured memory_bytes: 256
x, n = map(int, input().split())
minn = 10000000
if n == 0:
    print(x)
    exit()
p = list(map(int, input().split()))
for i in range(1000):
    if i not in p:
        tmp = abs(x-i)  
        if minn > tmp:
            ans = i
            minn = tmp
        elif minn == tmp:
            ans = min(i, ans)
print(ans)

Measured memory_bytes: 9200
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<endl;
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;
const int inf=-1e9;

struct edge{int to,cost;};

int n,m;
vector<vector<edge>> g(100010);
vector<int> d(100010,inf);

bool dfs(int v,int now){
  if(d[v]!=inf){
    if(d[v]!=now) return false;
    else return true;
  }
  d[v]=now;
  bool ret=true;
  for(auto itr:g[v]){
    ret=dfs(itr.to,now+itr.cost);
    if(!ret) break;
  }
  return ret;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n>>m;
  rep(i,m){
    int l,r,d;
    cin>>l>>r>>d;
    l--,r--;
    g[l].push_back({r,d});
    g[r].push_back({l,-d});
  }
  bool flag=true;
  rep(i,n){
    if(d[i]==inf){
      flag=dfs(i,1e5);
    }
    if(!flag) break;
  }
  if(flag) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 11008
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations
import sys
import bisect
import string
import math
sys.setrecursionlimit(10**6)
def SI():
    return input().split()
def MI():
    return map(int,input().split())
def I():
    return int(input())
def LI():
    return [int(i) for i in input().split()]
YN=['Yes','No']
mo=10**9+7

n=I()
e=[]
for i in range(n):
    x,y=MI()
    if (x,y)==(0,0):
        continue
    else:
        t=math.atan2(y,x)# if x!=0 else (y/abs(y))*math.pi/2
        e.append((x,y,t))
e.sort(key=lambda x:x[2])
n=len(e)

e+=e
a=[(0,0)]
ans=0
for x,y,t in e:
    a+=[(a[-1][0]+x,a[-1][1]+y)]
#print(e,a)
for l in range(n*2):
    for r in range(l,n*2):
        if r-l>n:
            continue
        else:
            x,y=a[r]
            w,z=a[l]
            ans=max((x-w)**2+(y-z)**2,ans)
print(ans**0.5 if n>0 else 0)
    

Measured memory_bytes: 40176
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))

#bit全部作ってる
#bit = [i>>j&1 for j in range(N)]

n,m=MI()
lights=[LI() for _ in range(m)]
p_list=LI()

bit_list=[]
count=0
for i in range(2**n):
    bit = [i>>j&1 for j in range(n)]
    flag=0
    for j in range(m):
        ki=lights[j][0]
        onswitch=0
        for k in range(1,ki+1):
            si=lights[j][k]
            onswitch+=bit[si-1]
        if onswitch%2!=p_list[j]:
            flag+=1
    if flag==0:
        count+=1
print(count)

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

int main() {
    int n;
    cin >> n;
    vector<pair<int, int>> work(n);
    
    for (int i = 0; i < n; i++){
        int a, b;
        cin >> a >> b;
        work.at(i) = make_pair(b, a);
    }

    sort(work.begin(), work.end());
    
    int time = 0;
    bool ret = false;
    for (int i = 0; i < n; i++){
        time += work.at(i).second;
        if (time > work.at(i).first){
            ret = true;
        }
    }

    cout << (ret ? "No" : "Yes") << endl;
}

Measured memory_bytes: 1920
S = input()
S = [1 if s == 'W' else -1 for s in S]

# BBBWW
# WBWBWBWBWBBWWW 1個以上のつながりはぐるーぷとしてかんがえてOK
# １試行ごとにグループを一つ消せる
# 最後のグループは消さなくていいので何グループあるか考えて - 1したものが答え

num_groups = 0
for i in range(1, len(S)):
    if S[i - 1] * S[i] == -1:
        num_groups += 1
print(num_groups)


Measured memory_bytes: 3956
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <iomanip> 

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

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;(i) < ((int)(n));++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

// const int dx[4] = { 1, 0, -1, 0 };
// const int dy[4] = { 0, 1, 0, -1 };

const int dx[8] = {1, 1, 0,-1,-1,-1, 0, 1};
const int dy[8] = {0, 1, 1, 1, 0,-1,-1,-1};

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline void print(T&& x){cout<<x<<endl;}// 改行付き出力
template<typename T>inline T SUM(vector<T> vec){return accumulate(all(vec),(T)0);} // vectorの中身を全部足す
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
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; }
int ctoi(char c){return c-'0';}


// TODO: write
int main() {
  int n;cin>>n;
  for(int i = 1;i <= n;++i){
    int ans = 0;
    for(int x = 1;x*x <= i;++x){
      for(int y = 1;x*x+y*y+x*y <= i;++y){
        for(int z = 1;x*x+y*y+z*z+x*y+y*z+z*x <= i;++z){
          if(x*x+y*y+z*z+x*y+y*z+z*x == i)ans++;
        }
      }
    }
    print(ans);
  }
  return 0;
}

Measured memory_bytes: 3592
from collections import defaultdict

n, m = list(map(int, input().split()))

def func(x):
    res = 0
    res += -1/6 * x * (x + 1)* (2*x + 1)+ (n + 1) * 1/2 * x * (x + 1) + x
    return int(res)

print(int((func(n + 1) - func(m - 1)) % (10 ** 9 + 7)))


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

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

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

	int h,w; cin >> h >> w;

	int field[33][33];
	for (int i = 0;i < h;i++){
		for (int j = 0;j < w;j++){
			cin >> field[i][j];
		}
	}

	int dp[33][33][1000];
	for (int i = 0;i < h;i++){
		for (int j = 0;j < w;j++){
			for (int k = 0;k <= h*w;k++){
				dp[i][j][k] = INT_MAX;
			}
		}
	}

	int dx[] = {1,0,-1,0};
	int dy[] = {0,1,0,-1};

	dp[0][0][0] = 0;

	for (int k = 0;k < h*w;k++){
		for (int i = 0;i < h;i++){
			for (int j = 0;j < w;j++){
				if(dp[i][j][k] == INT_MAX) continue;
				for (int l = 0;l < 4;l++){
					int ni = i + dy[l];
					int nj = j + dx[l];
					if(ni<0 || nj<0 || ni>=h || nj>=w) continue;
					dp[ni][nj][k+1] = min(dp[ni][nj][k+1], dp[i][j][k] + field[ni][nj]*(2*k+1));
				}
			}
		}
	}

	int ans = INT_MAX;
	
	for (int i = 0;i < h*w;i++){
		ans = min(dp[h-1][w-1][i],ans);
	}

	cout << ans << endl;

	return 0;

}



Measured memory_bytes: 6852
#include<bits/stdc++.h>
using namespace std;
int N, a[109];
int main() {
	cin >> N;
	for (int i = 0; i < N; i++) cin >> a[i];
	sort(a, a + N, greater<int>());
	int ret = 0;
	for (int i = 0; i < N; i++) ret += a[i] * (i & 1 ? -1 : 1);
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
int main(){
	char c[2][3];
	for(int i=0;i<2;i++){
		for(int j=0;j<3;j++){
			cin>>c[i][j];
		}
	}
	if(c[0][0]==c[1][2]&&c[0][1]==c[1][1]&&c[0][2]==c[1][0]){
		cout<<"YES";
	}
	else{
		cout<<"NO";
	}
}

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

int main() {
  long N;
  long H;
  int times=0;
  long aMax=0;
  cin >> N >> H;
  long a[100000], b[100000];
  for(int i=0;i<N;i++){
    cin >> a[i] >> b[i];
  }
  for(int j=0;j<N;j++){
    if(aMax<a[j]){
      aMax=a[j];
    }
  }
  sort(b, b+N);
  for(int k=N;k>=0;k--){
    if(aMax<b[k]){
      if(H>0){
        H-=b[k];
        times++;
      }
    }
  }
  while(H>0){
    H-=aMax;
    times++;
  }
  cout << times;
  return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<math.h>
using namespace std;
#define ll long long
int main(){
	string S;
    cin >> S;
    if(S=="AAA" || S=="BBB" )cout << "No";else cout << "Yes";
    return 0;
}


Measured memory_bytes: 256
import math
from functools import reduce

k = int(input())

def find_gcd(*numbers):
    return reduce(math.gcd, numbers)

ans = 0
for a in range(1, k+1, 1):
    for b in range(1, k+1, 1):
        for c in range(1, k+1, 1):
            gcd = find_gcd(a, b, c)
            ans += gcd

print(ans)

Measured memory_bytes: 74960
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include<atcoder/convolution>
#include<atcoder/modint>
#include<iostream>
#include<cstdint>
using namespace std;
using namespace atcoder;

using i32 = int_fast32_t;
using i64 = int_fast64_t;
using usize = uint_fast64_t;
#define rep(i, n) for (usize i = 0; i < (usize)(n); i++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using P = pair<i64,i64>;

int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
i32 n,m;
cin >> n >> m;
vector<i64> a(n),b(m);
rep(i,n)cin >> a[i];
rep(i,m)cin >> b[i];
vector<i64> c = convolution(a,b);
rep(i,n + m - 1)cout << c[i] << " \n"[i == n + m - 2];
}

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

int main()
{int N; cin >> N;
 vector<long long> X(N);
 for(int i = 0; i < N ; i ++ )
 { cin >> X.at(i);}
 int cnt = 0;
 for ( int j = 0; j < N ; j++)
 {if( X.at(j) < 0 ) {cnt++;}}
 
 for(int i = 0; i < N; i++)
 {X.at(i) = abs( X.at(i));}
 
 //この時点でmainのカッコしかない
 if(cnt % 2 == 0 )
 {long long sum1 = 0;
  for(int i=0;i < N; i++)
  {sum1 += X.at(i);}
  cout << sum1<<endl;}
 //mainのみ
 else if(cnt % 2 != 0)
 {long long sum2 = 0; long long min_number = X.at(0);
  for(int i = 0; i < N ; i++)
  {min_number = min(min_number,X.at(i));}
  //min_number入力完了。この時点でelseとmainのみ。
  for (int i = 0; i < N; i++)
  {sum2 += X.at(i);}
  cout << sum2 - min_number*2 <<endl;}
 return 0;
}


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

ll N,M,ans;

int main(){

cin>>N>>M;

if(2*N-M>0){
    ans=M/2;
}
else if(2*N-M==0){
    ans=M/2;
}
else if(2*N-M<0){
    ans=N+(M-2*N)/4;
}

cout<<ans<<endl;

return 0;
 
}

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


int N;
vector<int> a, b;


vector<int> make_next(const vector<int> &P)
{
    int m = P.size();
    vector<int> next(m);
    int q, k;
    next[0] = 0;
    for (q = 1, k = 0; q < m; ++q) {
        while (k > 0 && P[q] != P[k])
            k = next[k - 1];
        if (P[q] == P[k])
            k++;
        next[q] = k;
    }
    return next;
}


vector<int> kmp(const vector<int> &T, const vector<int> &P)
{
    vector<int> res;
    int n = T.size();
    int m = P.size();
    vector<int> next = make_next(P);
    int i, q;
    for (i = 0, q = 0; i < n; ++i) {
        while (q > 0 && P[q] != T[i])
            q = next[q - 1];
        if (P[q] == T[i])
            q++;
        if (q == m) {
            res.push_back(i - m + 1);
            q = next[q - 1];
        }
    }
    return res;
}


void solve()
{
    vector<int> vt(2*N-1);
    vector<int> vp(N);
    vector<int> pos;
    vector<int> m1(N), m2(N);

    reverse(a.begin(), a.end());
    reverse(b.begin(), b.end());
    for (int e = 0; e < 30; e++) {
        for (int i = 0; i < N; i++)
            m2[i] = -1;
        for (int i = 0; i < 2*N; i++) {
            if (i < N) {
                vt[i] = b[i] & 1;
                b[i] >>= 1;
            } else {
                vt[i] = vt[i - N];
            }
        }
        for (int i = 0; i < N; i++) {
            vp[i] = a[i] & 1;
            a[i] >>= 1;
        }
        pos = kmp(vt, vp);
        for (int k : pos) {
            if (m1[k] >= 0)
                m2[k] = m1[k];
        }
        for (int i = 0; i < N; i++)
            vp[i] = 1 - vp[i];
        pos = kmp(vt, vp);
        for (int k : pos) {
            if (m1[k] >= 0)
                m2[k] = m1[k] + (1 << e);
        }
        swap(m1, m2);
    }

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


int main()
{
    cin >> N;
    a.resize(N);
    b.resize(N);
    for (int i = 0; i < N; i++)
        cin >> a[i];
    for (int i = 0; i < N; i++)
        cin >> b[i];
    solve();
    return 0;
}


Measured memory_bytes: 11476
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	ull n, m;
	cin >> n >> m;
	if(n==1 && m==1) cout << 1 << endl;
	else if(n==1) cout << m-2 << endl;
	else if(m==1) cout << n-2 << endl;
	else cout << (n-2)*(m-2) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<iomanip>
#include <string>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<math.h>
#include<stack>
#include<set>
#include<map>
#define INF long long int(1e18+1)
#define rep(i,n,m) for(int i=n;i<m;i++)

using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int>Prime(100101, 0);
	Prime[1] = true;
	rep(i, 2, 1000101) {
		long int x = i;
		while (x < 100101) {
			Prime[x]++;
			x += i;
		}
	}
	rep(i, n, 100101) {
		if (Prime[i]==1) {
			cout << i << endl;
			break;
		}
	}
}

Measured memory_bytes: 3224
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define REP(i,a,b) for(int i=int(a);i<(int)b;++i)


using namespace std;
using ll = long long;

int main(void)
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int a,b,c,d,p,q;
    cin >> a >> b>>c >>d;
    a--;
    c--;
    p=a/d;
    q=c/b;
    if(p>=q)cout << "Yes" << endl;
    else cout << "No" << endl;
    

    return 0;
}


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

#define pout(n)  printf ("%d\n", n)

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
#define all(c)     begin(c), end(c)

const int d4x[4] = {1, 0, -1, 0};
const int d4y[4] = {0, 1, 0, -1};
const int d8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const int d8y[8] = { 0,1,1,1,0,-1,-1,-1 };

#define MAX_N (int)2e5+20
#define INF 1e12+20

typedef long long ll;
using namespace std;

ll n,k;
ll m = 0,j = 0, ans = 0;
int main() {
    scanf("%lld%lld",&n,&k);
    vector<ll>a(n);
    rep(i,0,n) cin >> a[i];

    vector<ll>num(n+1,0);
    
    rep(i,0,n) num[a[i]]++;
    sort(all(num));

    rep(i,0,n+1){
        if(num[i] != 0) m++;
    }
    
    while(m>k){
        if(num[j]>0){
            ans += num[j];
            m--;
        }
        j++;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 3328
x=int(input())
if(360%x==0):
    print(int(360/x))
elif(360%(180-x)==0):
    print(int(360/(180-x)))
else:
    m=2
    while(1):
        if((360*m)%x==0):
            print(int(360*m/x))
            break
        elif((360*m)%(180-x)==0):
            print(int(360*m/(180-x)))
            break
        m+=1

Measured memory_bytes: 9076
num_input=list(map(int,input().split()))

h=num_input[0]
w=num_input[1]

while h!=0 or w!=0:
    for i in range(h):
        for j in range(w-1):
            print("#",end="")
        print("#")

    print()
    num_input=list(map(int,input().split()))

    h=num_input[0]
    w=num_input[1]



Measured memory_bytes: 7040
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int n;
    cin >> n;
    vl a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vl b;
    for (int i = 1; i < n; ++i) {
        if (a[i] <= a[i - 1]) {
            b.push_back(a[i]);
        }
    }
    if (b.size() == 0) {
        cout << 1 << "\n";
        return 0;
    }
    ll ng      = 1;
    ll ok      = n;
    auto check = [&](ll mid) {
        vector<pii> v;
        v.emplace_back(-1, -1);
        bool ret = true;
        for (int i = 0; i < b.size(); ++i) {
            int m = b[i];
            while (v.back().first > m)
                v.pop_back();
            while (v.back().first == m && v.back().second == mid - 1)
                v.pop_back(), --m;
            if (m == v.back().first)
                ++v.back().second;
            else if (m)
                v.emplace_back(m, 1);
            else {
                ret = false;
                break;
            }
        }
        return ret;
    };
    while (ok - ng > 1) {
        ll mid = (ok + ng) / 2;
        if (check(mid))
            ok = mid;
        else
            ng = mid;
    }
    cout << ok << endl;
    return 0;
}

Measured memory_bytes: 4084
import sys
input = sys.stdin.readline
import math
def bit_check(n,m,x,c,a):
    mx = 2**n
    bit = n
    acc_m = 10**9 + 1


    for i in range(1,mx):
        acc_u = [0] * m
        can = 0
        for b in range(bit):
            r = i & (1 << b)
            #print(x,type(x))
            if r != 0:
                v = int(math.log2(r))
                #print(i,(1 <<b ),v,c[v])
                for j in range(m):
                    acc_u[j] += a[v][j]
                can += c[v]
        #print(can,acc_u)
        #print(all([s >= 10 for s in acc_u]))
        if can < acc_m and all([s >= x for s in acc_u]):
            acc_m = can
    if acc_m > 10**9:
        return -1
    else:
        return acc_m
    
if __name__ == "__main__":
    n,m,x = map(int,input().split())
    c = []
    a = []
    for i in range(n):
        ca = list(map(int,input().split()))
        c.append(ca[0])
        a.append(ca[1:])

    print(bit_check(n,m,x,c,a))


Measured memory_bytes: 9112
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;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 REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define int long long

using namespace std;


int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };
int dxx[8] = { 0,0,1,1,1,-1,-1,-1 };
int dyy[8] = { 1,-1,0,1,-1,0,1,-1 };


const int MOD = 1000000007;

ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}

ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}

long long nCr(int n, int r) {
	if (r > n / 2) r = n - r; // because C(n, r) == C(n, n - r)
	long long ans = 1;
	int i;

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

	return ans;
}



map<int, int> mp1, mp2, mp3;
signed main() {
	int n; cin >> n;
	REP(i, n) {
		int v; cin >> v;
		mp1[v]++;
		if (i % 2 == 0)mp2[v]++;
		else mp3[v]++;
	}
	if (mp1.size() == 0) {
		cout << n / 2 << endl;
		return 0;
	}
	int max1 = 0, max2 = 0;
	int e1=0, e2=0;
	for (auto x : mp2) {
		if (x.second >= max2) {
			if (x.second > max1) {
				max2 = max1;
				e2 = e1;
				max1 = x.second;
				e1 = x.first;
			}
			else {
				max2 = x.second;
				e2 = x.first;
			}
		}
	}

	int MAX1 = 0, MAX2 = 0;
	int E1 = 0, E2 = 0;
	for (auto x : mp3) {
		if (x.second >= MAX2) {
			if (x.second > MAX1) {
				MAX2 = MAX1;
				E2 = E1;
				MAX1 = x.second;
				E1 = x.first;
			}
			else {
				MAX2 = x.second;
				E2 = x.first;
			}
		}
	}
	int ans = 9999999;
	if (e1 == E1) {
		int ans1 = (n + 1) / 2 - max2;
		ans1 += n / 2 - MAX1;

		int ans2 = (n + 1) / 2 - max1;
		ans2 += n / 2 - MAX2;

		ans = min(ans1, ans2);
		cout << ans << endl;
		return 0;
	}
	ans = n - max1 - MAX1;
	cout << ans << endl;
}




Measured memory_bytes: 12800
#include <stdio.h>
int parent(int );
int left(int );
int right(int );
int main() {
	int heap_size,i;
	int A[260];
	scanf("%d",&heap_size);
	for(i=1;i<=heap_size;i++) {
		scanf("%d",&A[i]);
	}

	for(i=1;i<=heap_size;i++) {
		printf("node %d: key = %d, ",i,A[i]);
		if(parent(i) != 0) printf("parent key = %d, ",A[parent(i)]);
		if(left(i) <= heap_size)   printf("left key = %d, ",A[left(i)]);
		if(right(i) <= heap_size)   printf("right key = %d, ",A[right(i)]);
		printf("\n");
	}
	return 0;
}

int parent(int i) { return i/2; }
int left(int i) { return 2*i; }
int right(int i) { return 2*i+1; }

Measured memory_bytes: 600
//106 B - 105 2018/08/18
#include <bits/stdc++.h>
#define rep(i ,n) for(int i=0;i<(int)(n);++i)
using namespace std;
typedef long long int int64;
typedef unsigned long long uint64;

int main(){
    int n; cin >> n;
    int counter=0;int ans=0;
    for(int i=1;i<=n;i+=2){
        for(int j=1;j<=i;++j){
            if(i%j==0) ++counter;
        }
        if (counter==8) ++ans;
        counter = 0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use text_io::*;
use itertools::Itertools;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

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

    let s = s.chars().collect_vec();
    let t = t.chars().collect_vec();

    let mut a = 0;
    for i in 0..s.len() {
        if s[i] != t[i] {
            a += 1;
        }
    }

    println!("{}", a)
}


Measured memory_bytes: 4120
[n] = [int(i) for i in input().split()]
s = str(input())

char = {}

for c in s:
    if c not in char.keys():
        char[c] = 1
    else:
        char[c] = char[c] + 1

cnt = 1
for c in char.keys():
    cnt = (char[c] + 1) * cnt

print((cnt - 1) % (10 ** 9 + 7))


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

int main(void){
    int n, m, c, cnt=0;
    cin >> n >> m >> c;
    int b[100];
    for(int i=0;i<m;++i) cin >> b[i];
    for(int i=0;i<n;++i){
        int a = 0, sum=0;
        for(int j=0;j<m;++j){
            cin >> a;
            sum += a*b[j];
        }
        if((sum+c) > 0) ++cnt;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(v) v.begin(), v.end()

using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const double PI = 2 * acos(0);

int main() {
	int K;
	scanf("%d", &K);
	LL sum = 0;
	for (int i = 1; i <= K; i++) {
		for (int j = 1; j <= K; j++) {
			for (int k = 1; k <= K; k++) {
				sum += __gcd(i, __gcd(j, k));
			}
		}
	}
	printf("%lld\n", sum);
}

Measured memory_bytes: 3764
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
am = 0
bm = 0
for i in range(n):
    if a[i] == b[i]:
        continue
    elif a[i] > b[i]:
        bm += a[i] - b[i]
    else:
        am += (b[i] - a[i] + 1) // 2
        if (b[i] - a[i]) % 2:
            bm += 1
if am - bm >= 0:
    print('Yes')
else:
    print('No')


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

int main()
{
    char yamaha[5];
//    cin.ignore();
    cin.getline(yamaha,5);
    char d01[3];
    char d23[3];
    d01[0]=yamaha[0];
    d01[1]=yamaha[1];
    d01[2]='\n';
    d23[0]=yamaha[2];
    d23[1]=yamaha[3];
    d23[2]='\n';
    int dd01=atoi(d01), dd23=atoi(d23);
    //AMBIGUOUS
    if(
            dd01>=1&&dd01<=12 &&
            dd23>=1&&dd23<=12
            )
        cout<<"AMBIGUOUS\n";
    else if(dd01>=1&&dd01<=12)
        cout<<"MMYY\n";
    else if(dd23>=1&&dd23<=12)
        cout<<"YYMM\n";
    else {
        cout<<"NA\n";
    }
    return 0;
}


Measured memory_bytes: 256
// ABEY SAALE
// QUESTION KHUD KR SOLUTION KYU DEKH RHA H
 
 
 
 
 
 
 
 
//MAAF KIJIYEGA ME GUSSE ME IDHAR UDHAR NIKAL JATA HU
#include<bits/stdc++.h>
#define mod 1000000007
#define fr first
#define se second
#define ll long long
#define PI 3.1415926535 
#define pb push_back
#define mpr make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define senky_bansal ios_base::sync_with_stdio(false);
#define IIIT_ALLAHABAD    cin.tie(NULL);cout.tie(NULL);
using namespace std;

ll fac[2000005];
void pre(){ fac[0]=1; fac[1]=1; for(int i=2;i<200005;i++) fac[i]=(i*fac[i-1])%mod;}
ll power(ll a,ll b){ll res=1;while(b){if(b&1) res=(res*a)%mod;a=(a*a)%mod;b=b/2;}return res%mod;}
ll ncr(ll n,ll r){return ((fac[n]*power(fac[r],mod-2))%mod*power(fac[n-r],mod-2))%mod;}
// DEKHIYE JI  WALID JO THE ABBA HAMARE WO YEH function CHHOD KR GYE THE

signed main()
{   


      
      senky_bansal
      IIIT_ALLAHABAD
      
      // pre();
      ll t;
      // cin>>t;
      t=1;
      while(t--)
      { 
         ll a,b;
        cin>>a>>b;
        ll p1 = min(a,b);
        ll p2 = max(a,b);
        for(int i=0;i<p2;i++)
          cout<<p1;
         
         

      }
      






}





Measured memory_bytes: 256
n, m, q = list(map(int, input().split()))
a, b, c, d = [], [], [], []
for i in range(q):
    ai, bi, ci, di = list(map(int, input().split()))
    a.append(ai)
    b.append(bi)
    c.append(ci)
    d.append(di)

def max_point(ary):
    if len(ary) == n:
        pt = 0
        for i in range(q):
            if ary[b[i] - 1] - ary[a[i] - 1] == c[i]:
                pt += d[i]
        return pt
    if len(ary) == 0:
        s = 1
    else:
        s = ary[-1]
    return max([max_point(ary + [i]) for i in range(s, m + 1)])

print(max_point([]))


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

int main(){
  int a,b,c,d;
  int timeMin,timeMax;
  
  cin >> a >> b >> c >> d;
  /*scanf("%d %d %d %d",&a,&b,&c,&d);*/
  
  
  if(a<c)
    timeMin = c;
  else
    timeMin = a;
  if(b<d)
    timeMax = b;
  else
    timeMax = d;
  /*if(a<c){
    timeMin = c;
  }
  else{
    timeMin = a;
  }
  if(b<d){
    timeMax = b;
  }
  else{
    timeMax = d;
  }*/
  
  
  if(timeMax-timeMin > 0)  
    cout << timeMax - timeMin;
    /*printf("%d",timeMax-timeMin);*/
  else
    cout << "0";
    /*printf("0");*/
  
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

//Code Short
#define REP(i,n) for(int i = 0;i < n;++i)
#define PB(s) push_back(s)
#define DSORT(n) sort(n.begin(),n.end())
#define QECHO(n) cout << n
#define QECHOS(n) cout << n << " "

//Define Math
const double EPS = 1e-10;
const double PI  = acos(-1.0);

using namespace std;
typedef long long ll;
/* prototype */
int EDSum(ll);//各桁の和
vector<int> SOE(int,int);//素数 (Min,Max)
int MinCM(int,int);//最小公倍数(num1,num2)
int MaxCD(int,int);//最大公約数(num1,num2)
vector<int> igets(int);//cin * N
ll nPr(ll,ll); //(n,r)
ll nE(ll); //(n)
ll nCr(ll,ll); //(n,r)

void solve(){
    int a;
    cin >> a;
    cout << 48 - a << endl;
}

int main(void){cin.tie(0);ios::sync_with_stdio(false);solve();}
int EDSum(ll number) {
  int ans = 0;
  while (1) {
    ans += number % 10;
    number /= 10;
    if (number == 0) break;
  }
  return ans;
}

vector < int > SOE(int min, int max) {
  if (min < 2) min = 2;
  vector < int > int_array;
  for (int i = min; i <= max; i++) int_array.push_back(i);
  vector < int > sosu;
  double stop = sqrt(max);
  while (true) {
    sosu.push_back(int_array.front());
    int_array.erase(int_array.begin());
    if (stop < (double)(sosu.back())) break;
    for (int i = 0; i < (int) int_array.size(); i++) {
      if (int_array[i] % sosu.back() == 0)
        int_array.erase(int_array.begin() + i);
    }
  }
  sosu.insert(sosu.end(), int_array.begin(), int_array.end());
  return sosu;
}

int MinCM(int a, int b) {
  int c = a * b;
  if (a < b)
    swap(a, b);
  int r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return c / b;
}

int MaxCD(int a, int b) {
  if (a < b)
    swap(a, b);
  int r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}
vector < int > igets(int N) {
  vector < int > A;
  int temp;
  for (int i = 0; i < N; ++i) {
    cin >> temp;
    A.push_back(temp);
  }
  return A;
}

ll nPr(ll n, ll r) {
  ll ans = 1;
  r = n - r;
  while (n != r) {
    ans *= n;
    --n;
  }
  return ans;
}

ll nE(ll n) {
  return nPr(n, n);
}

ll nCr(ll n, ll r) {
  if (r == 0) return -1;
  else {
    if (0 != n - r && n - r < r) r = n - r;
    return nPr(n, r) / nE(r);
  }
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
  int n,i,A,B,C,D;
  int X,Y,Z,W;
  int a[1001];
  int min=100000001;
  double ans;
  scanf("%d",&n);
  for(i=0;i<n;++i) scanf("%d",&a[i]);
  sort(a,a+n);
  A = a[n-1];
  B = a[n-2];
  for(i=0;i<n-2;++i){
    if(a[i+1]-a[i]<min){
      min=a[i+1]-a[i];
      C = a[i+1];
      D = a[i];
    }
  }
  
  ans = (double)(A+B)/(C-D);

  if(a[n-1]-a[n-2]<min){
    X = a[n-3];
    Y = a[n-4];
    Z = a[n-1];
    W = a[n-2];
    ans = (ans>(double)(X+Y)/(Z-W)) ? ans : (double)(X+Y)/(Z-W);
  }
  
  
  printf("%f\n",ans);
}

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

#define INF (1 << 30) - 1 + (1 << 30)

int a[262144], n2;

void update(int i, int x) {
  i += n2 - 1;
  a[i] = x;
  while (i > 0) {
    i = (i - 1) / 2;
    a[i] = min(a[i * 2 + 1], a[i * 2 + 2]);
  }
}

int find(int s, int t, int i, int l, int r) {
  if (s <= l && r <= t) return a[i];
  if (t <= l || r <= s) return INF;
  int cl, cr;
  cl = find(s, t, i * 2 + 1, l, (l + r) / 2);
  cr = find(s, t, i * 2 + 2, (l + r) / 2, r);
  return min(cl, cr);
}

int main() {
  int n, q, com, x, y;

  cin >> n >> q;
  n2 = 1;
  while (n > n2) n2 *= 2;
  for (int i = 0; i < n2*2; i++) a[i] = INF;

  for (int i = 0; i < q; i++) {
    cin >> com >> x >> y;
    if (com == 0)
      update(x, y);
    else
      cout << find(x, y + 1, 0, 0, n2) << endl;
  }
  return 0;
}


Measured memory_bytes: 4124
fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim_right().to_owned()
}

fn comb2(n: usize) -> Vec<(usize, usize)> {
    let mut v = Vec::new();
    for i in 0..(n - 1) {
        for j in (i + 1)..n {
            v.push((i, j));
        }
    }
    v
}

fn main() {
    let v: Vec<u64> = read_line().split_whitespace().map(|x| x.parse().unwrap()).collect();
    let (l, r) = (v[0], v[1]);
    let len = r - l + 1;
    
    // 2019 = 3 * 673
    if len <= 673 {
        let l_mod = l % 673;
        let r_mod = r % 673;
        
        if l_mod == 0 || r_mod == 0 {
            println!("0");
            return;
        }
        
        if 673 < l_mod + len {
            println!("0");
            return;
        }
        
        let min = comb2(len as usize)
            .into_iter()
            .map(|(i, j)| ((l + i as u64) * (l + j as u64)) % 2019)
            .min()
            .unwrap();
        println!("{}", min);
    } else {
        println!("0");
    }
}


Measured memory_bytes: 6396
# import numpy as np

h, w, m = map(int, input().split())
hw_array = [list(map(int, input().split())) for _ in range(m)]

h_array = [0]*h
w_array = [0]*w

for hw in hw_array:
    h, w = hw
    h_array[h - 1] += 1
    w_array[w - 1] += 1

h_max = max(h_array)
h_argmax_array = [True if i == h_max else False for i in h_array]
w_max = max(w_array)
w_argmax_array = [True if j == w_max else False for j in w_array]

comb = sum(h_argmax_array) * sum(w_argmax_array)
for hw in hw_array:
    h, w = hw
    if h_argmax_array[h - 1] and w_argmax_array[w - 1]:
        comb -= 1
ans = h_max + w_max
if comb == 0:
    ans -= 1

print(ans)

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

int dp1[3030][3030];
int dp2[3030][3030];

int main(){
  int n, t;
  cin >> n >> t;
  vector<P> p;
  rep(i,n) {
    int a, b;
    cin >> a >> b;
    p.push_back({a,b});
  }
  
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < t; j++) {
      if (j + p[i].first < t) dp1[i+1][j + p[i].first] = max(dp1[i+1][j + p[i].first], dp1[i][j] + p[i].second);
      dp1[i+1][j] = max(dp1[i+1][j], dp1[i][j]);
    }
  }

  for (int i = n-1; i >= 0; i--) {
    for (int j = 0; j < t; j++) {
      if (j + p[i].first < t) dp2[i][j + p[i].first] = max(dp2[i][j + p[i].first], dp2[i+1][j] + p[i].second);
      dp2[i][j] = max(dp2[i][j], dp2[i+1][j]); 
    }
  }

  int res = 0;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < t; j++) res = max(res, dp1[i][j] + dp2[i+1][t - 1- j] + p[i].second);
  }
  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 71936
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>
#include <stack>
 
using namespace std;
 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define ktya(x) sort(all(x))
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 1e18
#define INFLL 1000000000000000007LL
#define SIZE 200105
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)

typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
ll MOD = 1000000007;
//ll MOD=998244353;
typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
int N;
ll A,B;
vector<ll> S;
ll dp[114514]={0};
ll sum[114514]={0};
int main(){
	cin>>N>>A>>B;
	if(A>B)swap(A,B);
	S.pb(-INF);
	//cout<<S[0]<<endl;
	rep(i,N){
		ll x;
		cin>>x;
		S.pb(x);
	}
	S.pb(4*INF);
	dp[0]=1;
	sum[0]=1;
	int l=0, r=0;
	for(int i=1;i<N+2;i++){
		//dp計算 iまで処理した場合　lとrがポインタ　sumにメモ
		if(l>r)dp[i]=0;
		else{
			if(l==0){
				dp[i]=sum[r];
			}else{
				dp[i]=sum[r]-sum[l-1];
				dp[i]+=MOD;
				dp[i]%=MOD;
			}
		}
		if(i<N+1){
			while(S[i+1]-S[r+1]>=B)r++;
			if(S[i]-S[i-1]<A){
				if(S[i]-S[i-2]>=A){
					l=i-1;
				}else{
					l=i;
				}
			}
		}
		sum[i]=(sum[i-1]+dp[i])%MOD;
	}
	//rep(i,N+2)cout<<dp[i]<<" ";
	cout<<dp[N+1]<<endl;
}


Measured memory_bytes: 2676
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define int ll

int n;

struct ver{
  int a,b,c;
};


bool cmp(const ver &a,const ver &b){
  return a.c > b.c;
}

signed main(){
  cin>>n;
  ver v[110000];
  int sumc=0;
  rep(i,n){
    cin>>v[i].a;
  }
  rep(i,n){
    cin>>v[i].b;
    v[i].c=v[i].a-v[i].b;
    sumc+=v[i].c;
  }
  sort(v,v+n,cmp);

  int i=0,j=n-1;
  int sum=0,ans=0;
  while(v[j].c<0||sum<0){
    if(sum<=0){
      sum+=v[i].c;
      i++;
      ans++;
    }
    else{
      sum+=v[j].c;
      j--;
      ans++;
    }
  }

  if(sumc<0){
    cout<<-1<<endl;
  }
  else{
    cout<<ans<<endl;
  }

}

Measured memory_bytes: 2816