akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

typedef long long ll;

///*-*-*-*-*-*-*-*-*-*-*-*-*-*-Macro Start-*-*-*-*-*-*-*--*-*-*-*-*/

#define Faster_IO              ios_base::sync_with_stdio(false); cin.tie(NULL);
#define F                      first
#define S                      second
#define pb                     push_back
#define MP                     make_pair
#define sf                     scanf
#define pf                     printf
#define gcin(a)                getline(cin,a);
#define pi                     (2*acos(0))
#define MAX(a,b)               (a>b? a:b)
#define MIN(a,b)               (a<b? a:b)
#define circle_area(r)         (pi*r*r)
#define triangle_area(b,h)     (0.5*b*h)
#define trapezium_area(a,b,h)  (0.5(a+b)*h)
#define ellipse_area(a,b)      (pi*a*b)
#define sector_area(r,angle)   (0.5*r*r*angle)
#define to_radian(degree)      ((pi/180)*degree)
#define to_degree(radian)      ((180/pi)*radian)
#define SQ(a)                  (a)*(a)
#define SORT(x)                sort(x.begin(),x.end())
#define SetPrint(a,x)          cout<<fixed<<setprecision(x)<<a<<endl
#define READ(x)                freopen(x,"r",stdin)
#define show(vec)              for (auto it = vec.begin(); it != vec.end(); it++)cout << *it << " ";

///*-*-*-*-*-*-*-*-*-*-*-*-*-*-Macro END-*-*-*-*-*-*-*--*-*-*-*-*/

///*-*-*-*-*-*-*-*-*-*-*-*-*-*-Template Start-*-*-*-*-*-*--*-*-*-*-*/

//template <class T> T isPrime(T n){if(n<=1)return 0;for(long long i=2;i*i<=n; i++)if(n%i==0)return 0;return 1;}
//template <class T> T bigmod(T X, T n, T M) {if (n==0) return 1;if (n%2) return ((X%M) * bigmod(X,n-1,M)) %M;else {long long int d = bigmod(X,n/2, M);return ((d%M) * (d%M))%M;}}

///*-*-*-*-*-*-*-*-*-*-*-*-*-*-Template END-*-*-*-*-*-*-*--*-*-*-*-*/



using namespace std;
int main()
{
    ll x, fivehun, five;
    cin >> x;
    fivehun = x/500;
    ll temp = x%500;
    five = temp/5;
    cout << fivehun*1000 + five*5 << endl;



    return 0;
}



Measured memory_bytes: 256
import java.util.*;

class Main {
    
    static Map<String, Integer> map = new HashMap() {
        {
            put("A",10);
            put("B",11);
            put("C",12);
            put("D",13);
            put("E",14);
            put("F",15);
        }
    };
    
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		String line = scanner.nextLine();
		
        String arr[] = line.split(" ", 0);
        
        int X = map.get(arr[0]);
        int Y = map.get(arr[1]);
        
        if (X<Y) {
            System.out.println("<");
        } else if(X>Y) {
            System.out.println(">");
        } else {
            System.out.println("=");
        }
	}
}


Measured memory_bytes: 21844
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=1000010;
const ll mod=1e9+7;

vector<int> ip(mx,0);
bool isprime(int x){
  if(x==2 || x==3){ return true; }
  if(x<2 || x%2==0){ return false; }  
  int sqrtx = ceil(sqrt(x));
  for(int i=3; i<=sqrtx; i+=2){ if(x%i==0){ return false; } }
  return true;
}
void ipset(int x){ for(int i=2; i<x; i++){ ip[i]=(int)isprime(i);} }

ll powll(ll n,ll k){ ll ret=1; while(k){ if(k&1)ret=ret*n; n=n*n; k>>=1; } return ret; }


int main(){
  ipset(100002);
  ll n,p;
  cin >> n >> p;
  if(n==1){ cout << p << endl; return 0; }
  ll ans = 1;
  for(ll i=2; i<mx; i++)if(isprime(i)){
    ll tmp = p;
    ll cnt = 0;
    while(tmp%i==0){
      tmp/=i;
      cnt++;
    }
    if(cnt>=n){
      ans *= powll(i,(cnt/n));
      for(int j=0; j<cnt/n; j++){
        p /= powll(i,n);
      }
    }
//    if(powll(i,n)>p) break;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4096
str = gets.chomp
c = str.length
len = str.length/2
(len-1).downto(0) do |i|
  str1 = str[0..i]
  str2 = str[i+1..i*2+1]
  if str1 == str2 && c != str.length
    puts c
    exit
  end
  c -= 2
end


Measured memory_bytes: 3836
#include<iostream>
#include<queue>
#include<vector>
#include<set>
using namespace std;

typedef long long ll;

int main(){
    int n;
    cin >> n;
    ll sum = 0;
    priority_queue<pair<int,int>> pq;
    for(int i = 0; i < n; i++){
        int x;  cin >> x;
        pq.push({x, -i});
        sum += x;
    }
    vector<ll> ans(n, 0);
    set<int> inds;
    int bef;
    while(!pq.empty()){
        int now = pq.top().first;
        if(!inds.empty()){
            ans[*inds.begin()] += (ll)(bef-now)*(int)(inds.size());
        }
        while(!pq.empty() && pq.top().first == now){
            inds.insert(-pq.top().second);
            pq.pop();
        }
        bef = now;
    }
    ans[0] += (ll)bef*n;
    for(int i = 0; i < n; i++)  cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 7412
import java.util.*;

public class Main{
    public static void main(String[] args){

	Scanner sc = new Scanner(System.in);

	int n = sc.nextInt();
	int temp = 0;
	int x = 0;
	
	
	int[] table = new int[n];

	for(int i=0;i<n;i++){
	    table[i] = sc.nextInt();
	}
	for(int i=0;i<n-1;i++){
	    
	    for(int j=i+1;j<n;j++){
		
		if(table[i]>table[j]){
		    temp = table[i];
		    table[i] = table[j];
		    table[j] = temp;
		}
	    }
	}

	for(int i=0;i<n-1;i++){
	    if(table[i] == table[i+1]) x++;
	}
	System.out.println(n-x);
    }
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using P = pair<int,int>;
using vl = vector<ll>; using vvl = vector<vl>;
#define mp make_pair
#define pb push_back
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,n) for (int i=(n-1);i >= 0;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)((v).size())
#define MAX(v) *max_element(all(v))
#define MIN(v) *min_element(all(v))
#define Sort(v) sort(all(v))
#define Rev(v) reverse(all(v))
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);in(name)
#define vv(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define VV(type,name,h,w) vector<vector<type>>name(h,vector<type>(w));in(name)
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cout << H << " ";
    debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
    for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
    return os;
}
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
template<class T>bool chmax(T &a, const T &b) {if(a<b){a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if(b<a){a=b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const int dx[8] = {1,0,-1,0,1,1,-1,-1}; const int dy[8] = {0,1,0,-1,1,1,-1,-1};

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    char c;
    cin >> c;
    if(isupper(c)){
        cout << "A" << endl;
    }else{
        cout << 'a' << endl;
    }
}

Measured memory_bytes: 3608
N = int(input())
ashiba = list(map(int, input().split()))

# dp配列の準備
dp = ["inf"] * N

dp[0] = 0
dp[1] = abs(ashiba[1] - ashiba[0])
for i in range(2, N):
    dp[i] = min(dp[i-2] + abs(ashiba[i] - ashiba[i-2]), dp[i-1] + abs(ashiba[i] - ashiba[i-1]))

print(dp[N-1])

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

int main(){
  int n;
  cin >>n;
  vector<int> p(n);
  for(int i=0;i<n;i++){
    cin>>p.at(i);
  }
  int a = 0;
  for(int i=0;i<n;i++){
    a = max(a,p.at(i));
  }
  int sum = 0;
  for(int i=0;i<n;i++){
    sum += p.at(i);
  }
  cout<<sum-a/2<<endl;
}

Measured memory_bytes: 256
from collections import deque

s = deque(input())
q = int(input())

qq = [list(input().split()) for i in range(q)]


rl = 1
rlrl = 1
fleft = deque()
fright = deque()

for i in qq:
  if i[0] == '1':
    rl *= -1
  else:
    if i[1] == '1':
      if rl == 1:
        fleft.appendleft(i[2])
      else:
        fright.append(i[2])
    else:
      if rl == 1:
        fright.append(i[2])
      else:
        fleft.appendleft(i[2])

fleft.reverse()        
        
s.extendleft(fleft)
s.extend(fright)        

if rl == -1:
  s.reverse()

print(''.join(s))

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

int main() {
	string cards, stock_cards1, stock_cards2;
	int h, m;
	while (1) {
		cin >> cards;
		if (cards == "-") break;
		cin >> m;
		for (int i = 0; i < m; i++) {
			cin >> h;
			stock_cards1 = cards.substr(0, h);
			stock_cards2 = cards.substr(h);
			cards = stock_cards2 + stock_cards1;
		}
		cout << cards << "\n";
	}
	return 0;
}

Measured memory_bytes: 1204
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#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++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int c[5];
int main() {
	rep(i, 3) {
		int a, b; cin >> a >> b;
		c[a]++; c[b]++;
	}
	int cnt = 0;
	rep1(i, 4) {
		if (c[i] % 2)cnt++;
	}
	if (cnt == 0 || cnt == 2) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	//stop
	return 0;
}

Measured memory_bytes: 256
require 'prime'

A, B = gets.split.map { |e| e.to_i }

# 最大公約数
def gcd(a, b)
  t = 0
  while b != 0 do
    t = a % b
    a = b
    b = t
  end
  return a
end

p Prime.prime_division(gcd(A, B)).length + 1


Measured memory_bytes: 2172
#include <bits/stdc++.h>
using namespace std;
int n,p,q,a[55];
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;++i){
		scanf("%d",&a[i]);
		if (!p||a[i]<a[p]) p=i;
		if (!q||a[i]>a[q]) q=i;
	}
	printf("%d\n",2*n-2);
	if (p&&abs(a[p])>abs(a[q])){
		for (int i=1;i<=n;++i) if (i!=p) printf("%d %d\n",p,i);
		for (int i=n;i>1;--i) printf("%d %d\n",i,i-1);
	}else{
		for (int i=1;i<=n;++i) if (i!=q) printf("%d %d\n",q,i);
		for (int i=1;i<n;++i) printf("%d %d\n",i,i+1);
	}
	return 0;
}

Measured memory_bytes: 256
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List

main :: IO ()
main = do
  solve <$> getLine >>= print

solve :: String -> Int
solve cs = f 0 0 cs
  where
    f t s [] = t + s
    f t s (x:xs)
      | x == 'T' = if s > 0 then f t (s - 1) xs else f (t + 1) s xs
      | otherwise = f t (s + 1) xs

getl :: (String -> a) -> IO a
getl f = f <$> getLine


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

const int MAX = 510000;
unsigned ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
   for (int i = 2; i < MAX; 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;
    }
}
// 二項係数計算関数
long long comb(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;
}
ll ans=0;
int main(){
   int n,l; cin >> n >>l;
   int taste[n+1];
   ll minimam = INF;
   for(int i=1;i<=n;i++){
       taste[i] = l+i-1;
      // cout << taste[i] << " " ;
       ans+=taste[i];

       if(minimam > abs(taste[i])){
           minimam = abs(taste[i]);
       }
   }
  if(l+n-1 < 0) cout << ans + minimam << endl;
  else cout << ans - minimam << endl;
  }

Measured memory_bytes: 256
#include <stdio.h>
 
int main()
{
 
   int n,k;
   scanf("%d%d",&n,&k);
  char s[n+1];
  scanf("%s",&s);
  int i;
  for(i=0;i<n;++i)
  {
     if(i+1==k)
     {
       if(s[i]>='A' && s[i]<='Z')
           printf("%c",s[i]+32);
       
       else
          printf("%c",s[i]);
     }
    
    else
       printf("%c",s[i]);
  }
  
  
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<map>
using namespace std;
int main()
{
	string s;
	int n;
	cin >> n >> s;
	string o = "";
	for (int i = 0; i < (int)(s.length()); i++)
	{
		if (char(s[i] + n) >= '[')
		{
			o += int(s[i] + n) - 26;
		}
		else
		{
		    o += char(s[i] + n);
		}
	}
	cout << o << endl;
	return 0;
}

Measured memory_bytes: 256
#結果の格納リストの準備
result = list()

#インプットdataの読み込みと計算
while True:
    input_data = list(input())
    input_data_int = [int(d) for d in input_data]
    if input_data_int[0] == 0:
        break
    result.append(sum(input_data_int))

#結果の表示
[print(i) for i in result]



Measured memory_bytes: 5620
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> mp;
typedef pair<int,mp> mmp;
int main(){
        while(1){
                int n,m,a;
                cin>>n>>m>>a;
                if(n==0)break;
                priority_queue<mmp> Q;
                int s = -1;
                for(int i=0;i<m;i++){
                        int h,p,q;
                        cin>>h>>p>>q;
                        Q.push(mmp(h,mp(p,q) ) );
                        Q.push(mmp(h,mp(q,p) ) );
                }
                while(!Q.empty() ){
                        mmp tmp = Q.top();
                        Q.pop();
                        mp now = tmp.second;
                        if(a == now.first&&s != tmp.first)a = now.second,s = tmp.first;
                }
                cout<<a<<endl;
        }

        return 0;
}



Measured memory_bytes: 3132
function Main(input) {
    const s = input.trim();
    if(s.includes("RRR")) {
        console.log(3);
    } else if(s.includes("RR")) {
        console.log(2);
    } else if(s.includes("R")) {
        console.log(1);
    } else {
        console.log(0);
    }
    
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29640
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <typename T> bool chmax(T &a, const T &b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> bool chmin(T &a, const T &b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
const long long INFLL = 1LL << 60;
const long long MOD = 1e9 + 7;

bool graph[8][8];

int dfs(int v, int N, bool visited[8]) {
    bool all = 1;
    rep(i, N) if(!visited[i]) all = 0;
    if(all) return 1;
    int ret = 0;
    rep(i, N) {
        if(!graph[v][i]) continue;
        if(visited[i]) continue;
        visited[i] = true;
        ret += dfs(i, N, visited);
        visited[i] = false;
    }
    return ret;
}

int main() {
    int N, M;
    cin >> N >> M;
    rep(i, 8) rep(j, 8) graph[i][j] = 0;
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        graph[a - 1][b - 1] = graph[b - 1][a - 1] = 1;
    }
    bool visited[8] = {0};
    visited[0] = 1;
    cout << dfs(0, N, visited) << endl;
}

Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <functional>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, n) for (int i = 1; i < (int)(n); ++i)
using namespace std;
using lint = int64_t;

int N;
lint C;
vector<lint> x, v;

lint solve() {
    vector<lint> S(N + 1, 0);
    rep(i, N) S[i + 1] = S[i] + v[i];
    rep(i, N) S[i + 1] -= x[i];
    reverse(x.begin(), x.end());
    reverse(v.begin(), v.end());
    vector<lint> T(N + 1, 0);
    rep(i, N) T[i + 1] = T[i] + v[i];
    rep(i, N) T[i + 1] -= (C - x[i]);
    rep(i, N) T[i + 1] = max(T[i], T[i + 1]);
    reverse(x.begin(), x.end());
    reverse(v.begin(), v.end());
    lint res = 0;
    REP(i, N + 1) {
        res = max(res, S[i]);
        res = max(res, S[i] - x[i - 1] + T[N - i]);
    }
    return res;
}

int main() {
    cin >> N >> C;
    x = v = vector<lint>(N);
    rep(i, N) cin >> x[i] >> v[i];
    
    lint ans = solve();
    reverse(x.begin(), x.end());
    reverse(v.begin(), v.end());
    rep(i, N) x[i] = C - x[i];
    ans = max(ans, solve());
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3424
//#typedef int ll
// include
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <tuple>
// namespace
using namespace std;
// typedef
typedef long long ll;
typedef long double ld;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pint;
// const
const int inf = 1e9;
const ll mod = ((ll)1e9 + 7);
// loop
#define rep(i, n) for(int i = 0, i##_mx = n; i < i##_mx; i++)
#define brep(i, b, e) for(int i = b; i < e; i++)
#define erep(i, b, e) for(int i = b; i <= e; i++)
#define rrep(i, b, e) for(int i = b; i >= e; i--)
// STL
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(v) (v).begin(), (v).end()
// sort
#define vsort(v, b) sort(all(v), [](auto l, auto r){return (b);})
// access
#define gt(i, n) get<n>(i)
// function
ll gcd(ll a, ll b){return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
void prime(vint& v, int n){brep(i, 2, n){bool fg = false; for(auto e : v){if(i % e == 0){fg = true;}} if(fg){continue;} v.pb(i);}}
void in(vint& v){for(auto& i : v){cin >> i;}}
void in(vll& v){for(auto& i : v){cin >> i;}}
ll egcd(ll a, ll b, ll& x, ll& y){if(b == 0){x = 1; y = 0; return a;} ll d = egcd(b, a % b, y, x); y -= a / b * x; return d;}

signed main(){
    int n, k;
    cin >> n >> k;
    
    vint h;
    h.resize(n);
    in(h);
    
    int ans = 0;
    for(auto i : h){
        if(i >= k){
            ans++;
        }
    }
    
    cout << ans << endl;
	
	return 0;
}

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


//@@@@@@
//@ snippet WeightedUnionFind
//@ alias   PotentialedUnionFind
//@ options head
template<class Abel>
struct WeightedUnionFind {
    vector<int> p;      // 親もしくは連結成分の数
    vector<Abel> dw;    // 親ノードとの差分

    explicit WeightedUnionFind(int n, Abel SUM_UNITY = 0)
        : p(n+5, -1), dw(n+5, SUM_UNITY) {}

    inline int root(int x) {
        if (p[x] < 0) {
            return x;
        } else {
            const int r = root(p[x]);
            return (dw[x] += dw[p[x]]), (p[x] = r);
        }
    }

    // diff(x, y) == w となるようにする
    inline bool unite(int x, int y, Abel w) {
        w += weight(x); w -= weight(y);
        if ((x=root(x)) == (y=root(y))) return false;
        p[x] += p[y]; p[y] = x;
        dw[y] = w;
        return true;
    }

    inline bool same(int x, int y) { return root(x) == root(y); }
    inline int  size(int x)        { return -p[root(x)]; }
    inline Abel diff(int x, int y) { return weight(y) - weight(x); }
    inline Abel weight(int x)      { root(x); return dw[x]; }
};
//@@@@@@@


struct FastIO {
    FastIO() { cin.tie(nullptr); ios::sync_with_stdio(false); }
} fastIO_ydk ;

void ABC087_D()
{
    using i64 = int_fast64_t;

    int N, M;
    cin >> N >> M;

    WeightedUnionFind<i64> uf(N);

    while(M--) {
        int l, r, d;
        cin >> l >> r >> d;

        uf.unite(l, r, d);
        if (uf.diff(l, r) != d) {
            cout << "No" << endl;
            return;
        }
    }

    cout << "Yes" << endl;

    return;
}

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


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

using ll=long long;

int main() {
  int N,i;
  ll c=0;
  cin >> N;
  vector<int> A(N+1), B(N);
  for(i=0; i<N+1; i++)
    cin >> A.at(i);
  for(i=0; i<N; i++)
    cin >> B.at(i);
  
  for(i=0; i<N; i++) {
    if(B.at(i) < A.at(i))
      c += B.at(i);
    else {
      c += A.at(i);
      B.at(i) -= A.at(i);
      if(B.at(i) < A.at(i+1)) {
        c += B.at(i);
        A.at(i+1) -= B.at(i);
      } else {
        c += A.at(i+1);
        A.at(i+1) = 0;
      }
    }
  }
  
  cout << c << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstring>
using namespace std;
long long arr[100100];
int flag[100100];
void run() {
	int N;
	while(cin >> N) {
		memset(flag, 0, sizeof(flag));
		for(int i = 0; i < N; i++) {
			cin >> arr[i];
		}
		
		int ans = 0;
		for(int i = 1; i < N; ++i) {
			if(flag[i - 1] == 0) {
				if(arr[i] - arr[i - 1] > 0)
					flag[i] = flag[i - 1] + 1;
					
				if(arr[i] - arr[i - 1] < 0)
					flag[i] = flag[i - 1] - 1;
					
				if(arr[i] - arr[i - 1] == 0)
					flag[i] = flag[i - 1];
			}
			else if(flag[i - 1] > 0) {
				if(arr[i] - arr[i - 1] > 0)
					flag[i] = flag[i - 1] + 1;
				if(arr[i] - arr[i - 1] == 0)
					flag[i] = flag[i - 1];
					
				if(arr[i] - arr[i - 1] < 0) {
					ans++;
					flag[i] = 0;
				}
			}else {
				if(arr[i] - arr[i - 1] < 0)
					flag[i] = flag[i - 1] - 1;
				if(arr[i] - arr[i - 1] == 0)
					flag[i] = flag[i - 1];
					
				if(arr[i] - arr[i - 1] > 0) {
					ans++;
					flag[i] = 0;
				}
			}
		}
		
		cout << ans + 1 << endl;
		
	}
}
int main(int argc, char *argv[]) {
	//freopen("data.txt", "r", stdin);
	run();
}

Measured memory_bytes: 1408
# Problem E - This Message Will Self-Destruct in 5s

# input
N = int(input())
a_nums = list(map(int, input().split()))

# initialization
tmp_1 = {}
ans = 0

# count
for i in range(1, N+1):
    if i+a_nums[i-1] in tmp_1:
        tmp_1[i + a_nums[i-1]] += 1
    else:
        tmp_1[i + a_nums[i-1]] = 1

# count 2
for j in range(1, N+1):
    if j-a_nums[j-1] in tmp_1:
        ans += tmp_1[j-a_nums[j-1]]

# output
print(ans)


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



int main(){
	string s;
	cin>>s;
	int K;
	cin>>K;
	vector<string> V;
	
	for(int i=1;i<=K;i++){
		for(int j=0;j<s.size()+1-i;j++){
			V.push_back(s.substr(j,i));
		}
	}
	sort(V.begin(),V.end());
	
	int x = 0;
	
	for(int i=0;i<V.size();i++){
		if(i==0)x++;
		else{
			if(V[i]!=V[i-1])x++;
		}
		if(x==K){
			cout<<V[i]<<endl;
			return 0;
		}
	}
	
	return 0;
}


Measured memory_bytes: 1660
#include <iostream>

using namespace std;

int N, Y;
int x, y, z;

int main(void)
{
	cin >> N >> Y;
	
	for(x = 0; x <= N; x++){
		for(y = 0; y <= N; y++){
			z = N - x - y;
			if(z < 0) continue;
			if(10000*x+5000*y+1000*z == Y){
				cout << x << " " << y << " " << z << endl;
				return 0;
			}
		}
	}
	cout << -1 << " " << -1 << " " << -1 << endl;
	return 0;
}

Measured memory_bytes: 256
import kotlin.math.max
import kotlin.math.min

fun main() {
    val (h, n) = readLine()!!.split(" ").map { it.toInt() }

    val magics = MutableList(n) {
        val (a, b) = readLine()!!.split(" ").map { it.toInt() }
        a to b
    }
    magics.sortByDescending { it.first.toFloat() / it.second }

    val dp = Array(h + 1) { Long.MAX_VALUE / 2 }
    dp[h] = 0
    for (i in 0 until n) {
        for (j in (0..h).reversed()) {
            val nextHp = max(j - magics[i].first, 0)
            dp[nextHp] = min(dp[nextHp], dp[j] + magics[i].second)
        }
    }

    println(dp[0])
}

Measured memory_bytes: 55392
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

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

const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    int M, D, M2, D2; cin >> M >> D >> M2 >> D2;
    Ans(M != M2, 1, 0);

    return 0;
}


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

int main() {
int N,K,Q;
cin>>N>>K>>Q;
map<int,int> mp;
for(int i=0; i<N; i++){
	mp[i]=K-Q;
}
int ansp;
for(int i=0; i<Q; i++){
	cin>>ansp;
	ansp=ansp-1;
mp[ansp]+=1;
}
for(int i=0; i<N; i++){
	if(mp[i]>0) cout<<"Yes"<<endl;
	else              cout<<"No"<<endl;
}
}

Measured memory_bytes: 5376
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <set>
#include <map>
#include <deque>
#include <cmath>
#include <queue>
#include <random>
#include <bitset>
#include <time.h>
#include <string>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
//#define endl '\n'
#define mp make_pair
#define pbc push_back
#define pob pop_back()
#define empb emplace_back
#define sp system("pause")
#define queuel queue<long long>
#define all(x) (x).begin(),(x).end()
#define matrix vector<vector<ll>>
#define pin(p) cin >> p.first >> p.second;
#define rev(v) reverse(v.begin(),v.end());
#define mx(v) max_element(v.begin(), v.end());
#define mn(v) min_element(v.begin(), v.end());
#define sout(s, c) for(auto i : s) cout << i << c;
#define pout(p) cout << p.first << " " << p.second;
#define er(v, l, r) erase(v.begin() + l, v.begin() + r);
#define vin(v) for(ll i = 0; i < v.size(); ++i) cin >> v[i];
#define vout(v, c) for(int i = 0; i < v.size(); ++i) cout << v[i] << c;
#define pushi(v, a) for(int i = 0; i < a.size(); ++i) v.push_back(a[i]);
#define sin(s, n) for(int i = 0; i < n; ++i){int a; cin >> a; s.insert(a);}
#define fastio() ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);srand(time(NULL));
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
using namespace std;
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
const ll INF = 1000LL * 1000 * 1000 * 1000 * 1000 * 1000;
const int inf = 1000 * 1000 * 1000;
const ld PI = acos(-1.0);
const ll mod1 = inf + 7;
const ll mod2 = inf + 9;
const int MAXN = 500001;
const ld EPS = 1e-9;
int hp = 179;

signed main()
{
	fastio();
	int ans = 0;
	int n;
	cin >> n;
	vector<int> a(n);
	vin(a);
	for (int i = 0; i < n; ++i)
	{
		int pw = 2;
		int cnt = 0;
		while (a[i] % pw == 0)
		{
			cnt++;
			pw *= 2;
		}
		ans += cnt;
	}
	cout << ans;
	sp;
}

Measured memory_bytes: 504
S = input()
X, Y = map(int, input().split())

# 横方向と縦方向に分解
X_Commands = [len(s) for s in S.split('T')[::2]]
Y_Commands = [len(s) for s in S.split('T')[1::2]]

# x方向で到達可能な場所
x_set = set((X_Commands[0], ))
for xc in X_Commands[1:]:
    tmp = set()
    for xs in x_set:
        tmp.add(xs + xc)
        tmp.add(xs - xc)
    x_set = tmp

# y方向で到達可能な場所
y_set = set((0, ))
for yc in Y_Commands:
    tmp = set()
    for ys in y_set:
        tmp.add(ys + yc)
        tmp.add(ys - yc)
    y_set = tmp

if (X in x_set) and (Y in y_set):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 49116
M, K = map(int, input().split())

if K >= 2 ** M:
    print(-1)
elif K == 0:
    ans = []
    x = range(0, 2 ** M)
    y = range(0, 2 ** M)
    for xx, yy in zip(x, y):
        ans.append(xx)
        ans.append(yy)
    print(*ans)
else:
    if M == 1 and K == 1:
        print(-1)
        exit()
    x = [i for i in range(0, 2 ** M) if i != K]
    ans = [K] + x + [K] + list(reversed(x))
    print(*ans)


Measured memory_bytes: 66928
#include<iostream>
using namespace std;
int a[1000];
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	long long ans=0;
	long long minn=99999998;
	for(int i=-100;i<=100;i++)
	{
		ans=0;
		for(int j=1;j<=n;j++)
		{
			ans+=(a[j]-i)*(a[j]-i);
		}
		minn=min(minn,ans);
	}
	cout<<minn<<endl;
}

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

int main(){
  int a,b;
  cin>>a>>b;
  int ma = a+b;
  int sub = a-b;
  int ans = max(ma,sub);
  ans=max(ans,a*b);
  cout<<ans<<endl;
}

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

int main() {
  int n; cin >> n;
  vector<int> x(n);
  rep(i, n) cin >> x[i];
  int ans = 1e9;
  for (int p = 1; p <= 100; ++p) {
    int now = 0;
    rep(i, n) now += (x[i] - p) * (x[i] - p);
    ans = min(ans, now);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3612
#include<iostream>
#include<cstdio>
using namespace std;
#define int long long
const int N=1e5+10;
int n,m,x,y,tot,ans,fi[N],a[N<<1],ne[N<<1],col[N],cn[3];
bool flag;
inline void add(int x,int y){
	a[++tot]=y;ne[tot]=fi[x];fi[x]=tot;
}
inline void dfs(int x,int no){
	if (col[x]) {flag|=col[x]!=no;return;}
	++cn[col[x]=no];
	for (int i=fi[x];i;i=ne[i]) dfs(a[i],3-no);	
}
main(){
	scanf("%lld%lld",&n,&m);
	for (int i=1;i<=m;++i) scanf("%lld%lld",&x,&y),add(x,y),add(y,x);
	for (int i=1;i<=n;++i) if (!col[i]){
		cn[1]=cn[2]=0;
		flag=0;
		dfs(i,1);
		if (flag) ans+=(cn[1]+cn[2])*(cn[1]+cn[2]-1)/2;
			else ans+=cn[1]*cn[2];
	}
	printf("%lld",ans-m);
	return 0;
}

Measured memory_bytes: 5120
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#include <complex>
#include <random>
#include <bitset>
#include <list>
// #include <prettyprint.hpp>
using namespace std;
#define repi(i,n) for(int i=0;i<n;++i)
#define rep(i,n) for(ll i=0;i<n;++i)
#define repinvi(i,n) for(int i=n-1;i>=0;--i)
#define sll(n) scanf("%lld", &n);
#define sii(n) scanf("%d", &n);
#define slf(n) scanf("%lf", &n);
#define pll pair<ll,ll>
#define pii pair<int,int>
#define psi pair<si,si>
typedef long long ll;
typedef double lf;
typedef short int si;


void Main(){
    ll N, a;
    sll(N);
    // vector<ll> as(N, 0);
    ll ans = 0;
    ll prev_max = 0;
    rep(i, N){
        sll(a);
        prev_max = max(a, prev_max);
        ans += prev_max - a;
    }

    cout << ans <<endl;
    
}

int main(){
    Main();
}

Measured memory_bytes: 3232
using System;

namespace AtCoder
{
    class Program
    {
        static IO io = new IO();

        static void Main(string[] args)
        {
            io.ReadSplit();
            int N = io.Int();
            long T = io.Long();
            io.ReadSplit();
            long[] t = io.Long(N);

            io.WriteLine(Calc(N, T, t).ToString());
        }

        private static long Calc(int N, long T, long[] t)
        {
            long total = 0;
            int start = 0;
            int i = 0;
            while (i < N - 1)
            {
                if (t[i] + T < t[i + 1])
                {
                    total += t[i] + T - t[start];
                    start = i + 1;
                }
                i += 1;
            }
            total += t[N - 1] + T - t[start];
            return total;
        }
    }
    class IO
    {
        private string[] _Inputs;
        private int _Index;
        public void Read()
        {
            _Inputs = new string[1];
            _Inputs[0] = Console.ReadLine();
            _Index = 0;
        }
        public void ReadSplit()
        {
            _Inputs = Console.ReadLine().Split(' ');
            _Index = 0;
        }
        public string String()
        {
            return _Inputs[_Index++];
        }
        public string[] String(int xCount)
        {
            string[] rv = new string[xCount];
            Array.Copy(_Inputs, _Index, rv, 0, xCount);
            _Index += xCount;
            return rv;
        }
        public int Int()
        {
            return int.Parse(_Inputs[_Index++]);
        }
        public int[] Int(int xCount)
        {
            int[] rv = new int[xCount];
            for (int i = 0; i < xCount; ++i)
            {
                rv[i] = int.Parse(_Inputs[_Index++]);
            }
            return rv;
        }
        public long Long()
        {
            return long.Parse(_Inputs[_Index++]);
        }
        public long[] Long(int xCount)
        {
            long[] rv = new long[xCount];
            for (int i = 0; i < xCount; ++i)
            {
                rv[i] = long.Parse(_Inputs[_Index++]);
            }
            return rv;
        }
        public void Write(string xStr)
        {
            Console.Write(xStr);
        }
        public void WriteLine(string xStr)
        {
            Console.WriteLine(xStr);
        }
    }
}

Measured memory_bytes: 30368
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

N = read_a_int()
n = int(str(N)[-1])
if n == 3:
    print('bon')
elif n in [0, 1, 6, 8]:
    print('pon')
else:
    print('hon')


Measured memory_bytes: 65416
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int

def powmod(a, n, m):
    L = [1 for _ in range(n+1)]
    for i in range(n):
        L[i+1] = L[i] * a % m
    return L

def solve(L: str):
    p = len(L)
    pm = powmod(3, p, MOD)
    
    res = 1
    for i, c in enumerate(L[::-1]):
        if c == '0':
            res = res
        else:
            res = (pm[i] + res * 2) % MOD
    print(res)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    L = next(tokens)  # type: int
    solve(L)

if __name__ == '__main__':
    main()


Measured memory_bytes: 46064
import sys
def main():
    input = sys.stdin.readline
    N,K=map(int, input().split())
    H=[int(input()) for _ in range(N)]

    H.sort()
    ans=10**12
    for i in range(N):
        if i+K-1 >= N: break
        ans = min(ans, H[i+K-1]-H[i])
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 43996
n,m=map(int,input().split())
one_to=[0]*(n+1)
to_n=[0]*(n+1)
for i in range(m):
    a,b=map(int,input().split())
    if a==1:
        one_to[b]=1
    elif b==n:
        to_n[a]=1
flag=False
for i in range(2,n):
    if one_to[i]==1 and to_n[i]==1:
        flag=True
        break
print("POSSIBLE" if flag else "IMPOSSIBLE")

Measured memory_bytes: 48388
/* BISMILLAHIR RAHMANIR RAHIM */
#include<bits/stdc++.h>
using namespace std;
#define ll        long long
#define ull       unsigned long long
#define si(x)     scanf("%d", &x)
#define sll(x)    scanf("%lld", &x)
#define ssll(x,y)    scanf("%lld %lld", &x ,&y)
#define sd(x)     scanf("%lf", &x)
#define l0(i,n)   for(ll i=0; i<n; i++)
#define MAX       100000
#define maxn 	  200002
#define pb 		  push_back
#define mk 		  make_pair
#define endl	  "\n"
#define INF 	  1000000000
#define MOD		  1000000007
#define vll(a)	  vector<ll>a
#define imie(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

ll n,m,k,a[maxn],b[maxn];


int main ()
{
		ios::sync_with_stdio(0);
		cin.tie(0);
		//CODE TONOY
		    scanf("%lld %lld %lld",&n,&m,&k);
    a[0]=b[0]=0;
    for( int i=1 ; i<=n ; i++ ){
        scanf("%lld",&a[i]);
        a[i]=a[i]+a[i-1];
    }
    a[n+1]=a[n]+1;
    int ans=upper_bound(a+1,a+2+n,k)-a-1;
    for( int i=1 ; i<=m ; i++ ){
        scanf("%lld",&b[i]);
        b[i]=b[i]+b[i-1];
        ll rem=k-b[i];
        if( rem>0 ){
            int num=upper_bound(a+1,a+2+n,rem)-a;
            num--;
            ans=max(ans,i+num);
        }
    }
    b[m+1]=b[m]+1;
    int ans1=upper_bound(b+1,b+2+m,k)-b-1;
    ans=max(ans,ans1);
    printf("%d\n",ans);
		return 0;
}







Measured memory_bytes: 6968
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
    ios::sync_with_stdio(false);

    string S, T; cin >> S >> T;
    vector< vector<int> > dp(S.size() + 1, vector<int>(T.size() + 1, 0));

    for (int i = 1; i <= int(S.size()); ++i)
        for (int j = 1; j <= int(T.size()); ++j)
            dp[i][j] = max({dp[i - 1][j - 1] + int(S[i - 1] == T[j - 1]), dp[i - 1][j], dp[i][j - 1]});

    string answer;
    for (int x = S.size(), y = T.size(); x > 0 && y > 0;) {
        if (dp[x][y] == dp[x - 1][y])
            --x;
        else if (dp[x][y] == dp[x][y - 1])
            --y;
        else if (S[x - 1] == T[y - 1]) {
            answer += S[x - 1];
            --x;
            --y;
        }
    }

    reverse(answer.begin(), answer.end());
    cout << answer << "\n";
}


Measured memory_bytes: 35584
#include<iostream>
#include<algorithm>
#include<set>
using namespace std;
string str;
set<string> S;

int main(){
  int Tc;
  cin>>Tc;
  while(Tc>0){
    Tc--;
    S.clear();
    cin>>str;
    for(int i=1;i<(int)str.size();i++){
      string a=str.substr(0,i);
      string b=str.substr(i);
      string c=a;
      string d=b;
      reverse(c.begin(),c.end());
      reverse(d.begin(),d.end());
      string t[4]={a,c,b,d};
      
      for(int j=0;j<2;j++){
        for(int k=2;k<4;k++){
          S.insert(t[j]+t[k]);
          S.insert(t[k]+t[j]);
        }
      }
    }
    cout<<S.size()<<endl;
  }
  return 0;
}

Measured memory_bytes: 1292
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;
#define MAX_N 100
#define MAX_W 100000

ll dp[MAX_N + 1][MAX_W + 1] = {};

int main(){
	int N,W;
	cin >> N >> W;
	int w[N],v[N];
	REP(i,N) cin >> w[i] >> v[i];
	REP(i,N){
		for(int j = 0; j <= W; j++){
			if(j < w[i]) dp[i + 1][j] = dp[i][j];
			else dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
		}
	}
	cout << dp[N][W] << endl;
}

Measured memory_bytes: 78336
from fractions import gcd
N = int(input())
A = set()
for i in range(N):
    A.add(int(input()))
A = sorted(list(A), reverse=True)
while len(A) != 1:
    a = A.pop()
    b = A.pop()
    A.append(a//gcd(a,b)*b)

print(A[0])

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

#define mp       make_pair
#define mt	  make_tuple
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

const int INF=1<<29;
const double EPS=1e-9;
const ll MOD = 1000000007;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
double R1,R2;
int main(){
  cin >> R1 >> R2;
  double res = (R1 * R2) / (R1 + R2);
  printf("%.20lf\n", res);
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long  fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; 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;
	}
}

// 二項係数計算
long long COM(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;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y){
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
/*逆元計算*/
long long int  modinv(long long a, long long m) {
	long long int b = m, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
// index が条件を満たすかどうか
long long int dp[100040] = {};
int main() {
	string s;
	cin >> s;
	string abc = "abcdefghijklmnopqrstuvwxyz";
	int ds[26] = {};
	for (int i = 0; i < s.size(); i++) {
		for (int j = 0; j < abc.size(); j++) {
			if (abc[j] == s[i]) {
				ds[j]++;
			}
		}
	}
	for (int i = 0; i < 26; i++) {
		if (ds[i] == 0) {
			cout << abc[i];
			return 0;
		}
	}
	cout << "None";
}


Measured memory_bytes: 512
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use nalgebra::max;

#[fastout]
fn main() {
    input! {
    n: usize,
    m: usize
    }
    let mut ans = 0;
    let d = divisor(m);
    for i in d {
        if m / i >= n {
            ans = i;
        }
    }
    println!("{}", ans);
}

fn divisor(m: usize) -> Vec<usize> {
    let mut l = Vec::new();
    for i in 1.. {
        if i * i > m {break}
        if m % i == 0 {
            l.push(i);
            l.push(m / i);
        }
    }
    l.sort();
    l.dedup();
    l
}


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

using namespace std;

int main() {
	int N;
	while(cin >> N && N) {
		vector<int> tmp(N);
		int score_max = 0;
		int score_min = 1001;
		int res = 0;
		for(int i = 0; i < N; i++) {
			cin >> tmp[i];
			score_max = max(score_max, tmp[i]);
			score_min = min(score_min, tmp[i]);
			res += tmp[i];
		}
		cout << (res - (score_max+score_min))/(N-2) << endl;
	}

	return 0;
}

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

using namespace std;

const double PI = 3.141592653589;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define int long long
#define all(c) (c).begin(),(c).end()
#define M 1000000007
#define INF LLONG_MAX
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ", "; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}
// Use pr(a,b,c,d,e) or cerr<<anything or prc(v.begin(),v.end()) or prc(v,v+n)
//  


int32_t main()
{
    fastio;
    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);
    int n;
    cin >> n;
    string a, b;
    cin >> a >> b;
    for(int i=0;i<2*n;i++)
    {
        if(i%2 == 0) cout << a[i/2];
        else cout << b[i/2];
    }
    return 0;
}



Measured memory_bytes: 256
n,m,c=map(int,input().split())
b=list(map(int,input().split()))
a=[list(map(int,input().split())) for i in range(n)]
s=[[a[i][j]*b[j] for j in range(m)] for i in range(n)]
count=0
for i in range(n):
    if sum(s[i])+c>0:
        count=count+1     
print(count)

Measured memory_bytes: 3064