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

#define mp make_pair

using namespace std;

typedef int32_t i32;
typedef uint32_t u32;
typedef int64_t i64;
typedef uint64_t u64;
typedef pair<int,int> pii;
typedef pair<i64,int> pli;
typedef pair<int,i64> pil;
typedef pair<i64,i64> pll;
typedef vector<int> vi;
typedef vector<i64> vl;

template <typename T>
T id(T b) {return b;};
template <class It>
bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It>
bool any(It f,It l){return std::any_of(f,l,id<bool>);}

const int MAX_N = 200000;
int n;
int a[MAX_N];
multiset<int> s;

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

  sort(a,a+n);

  int res = 0;
  for (int i = n-1; i >= 0; i--) {
    if (s.find(a[i]) == s.end()) continue;
    s.erase(s.find(a[i]));
    int v = 1;
    while (v <= a[i]) v <<= 1;
    if (s.find(v-a[i]) != s.end()) {
      s.erase(s.find(v-a[i]));
      res++;
    }
  }

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 10368
#include<bits/stdc++.h>
#define pb push_back
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define lb lower_bound
#define ld long double
using namespace std;
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n,m;
	cin>>n>>m;
	int ans = n*(n-1)/2;
	ans+=(m*(m-1)/2);
	cout<<ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
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; }
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
#define fs first
#define sc second

const int INF = 1e9;
const ll LLINF = 1e16;
const ll MOD = 1e9+7;
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}


// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
  return (a + b - 1) / b;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 回文判定
bool kai (string s) {
    string t{s};
    reverse(begin(t), end(t));
    return s == t;
}

using pint = pair<int, int>;
using pll = pair<ll, ll>;


int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll n;
    cin >> n;
    vector<ll> a(n);
    map<pll, ll> mp;
    rep(i, n){
        cin >> a[i];
        mp[pll(a[i], i + 1)]++;
    }
    ll ans = 0;
    rep(i, n){
        ans += mp[pll(i + 1, a[i])];
    }
    print(ans / 2);


}


Measured memory_bytes: 13568
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll ;
typedef double db;
const double pi = 3.141592654;
#define pb         push_back
#define forab(i,a,b)       for(int i=(a);i<=(b);i++)
#define CIN	ios_base::sync_with_stdio(0); cin.tie(0)
#define pcase(z,x)     printf("Case %ld: %lld\n",z,x)
#define nw	 "\n"
#define mod 1000000007

int main(void)
{
	CIN;
	ll tc,l,k,sum=0,x=0,y,z=0,m=1,n=0,ans=0,cnt=0;
	string s;
	cin>>s;
	l=s.size();
	for(ll i=0;i<l;i++){
		sum+=s[i]-'0';
	}
	cout<<(sum%9==0?"Yes":"No");
	

}

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

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> II;
typedef vector<II> VII;

#define REP(x, n) for (int x = 0; x < (n); ++x)
#define INF (1e9 + 1)
#define EPS 1e-9
#define PB push_back
#define F first
#define S second

int main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int r;
    cin >> r;
    cout << 3 * r * r << '\n';
    return 0;
}

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

using namespace std;


void solve() {
    int N, K; cin >> N >> K;
    int ans = 0;

    while (N > 0) {
        N /= K;
        ans++;
    }

    cout << ans << endl;
}


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

Measured memory_bytes: 256
from operator import itemgetter

inf = 10 ** 4

n, m = map(int, input().split())
a = tuple(map(int, input().split()))

use = [None, 2, 5, 5, 4, 5, 6, 3, 7, 6]
# use[i] : 数字iを作るのに必要なマッチの本数

use_num = {use[i]: i for i in range(1, 10) if i in a}
use_num = tuple(sorted(use_num.items()))
# 本数昇順
# print(use_num)

dp = [-inf] * (n + 1)
dp[0] = 0
# dp[j] : j本から構成できる桁数の最大値

for j in range(2, n + 1):
    for use, number in use_num:
        k = j - use
        if k >= 0:
            dp[j] = max(dp[j], dp[k] + 1)
# print(dp)

use_num = tuple(sorted(use_num, key=itemgetter(1), reverse=True))
# 数字降順

rest = n
ans = ''
while rest > 0:
    for use, number in use_num:
        k = rest - use
        if (k >= 0) and (dp[k] == dp[rest] - 1):
            ans += str(number)
            rest -= use
            break
print(ans)

Measured memory_bytes: 3436
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<cctype>
#include<stack>
#define ld long double
#define ll long long int
#define ull unsigned long long int
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long INF=1LL<<60;
//set<int>::iterator it;

int main(void){
   int n,k;
   cin>>n>>k;
   string s;
   cin>>s;
   transform(s.begin() + k - 1,s.begin() + k,s.begin() + k - 1,::tolower);
   cout<<s<<endl;
   return 0;
}



Measured memory_bytes: 256
word = list(input())

if ((word[0]==word[1]) & (word[2]==word[3])) | ((word[0]==word[2]) & (word[1]==word[3])) | ((word[0]==word[3]) & (word[1]==word[2])):
    if word[0] == word[1] == word[2] == word[3]:
        print("No")
    else:
        print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a, b, c, d, e;
    cin >> a >> b >> c >> d >> e;
    
    if(a == 0){
        cout << "1" << endl;
    }else if(b == 0){
        cout << "2" << endl;
    }else if(c == 0){
        cout << "3" << endl;
    }else if(d == 0){
        cout << "4" << endl;
    }else if(e == 0){
        cout << "5" << endl;
    }

}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<(int)(n); i++)
int main(){
  string x;
  cin >> x;
  int a=x.size();
  if(x.at(a-1)=='s'){
    cout << x << "es" << endl;
  }
  else cout << x << 's' << endl;
}

Measured memory_bytes: 3640
#include <cstdio>
#include <vector>

int m;
int k;

typedef int Zp;


const int mod = 924844033;
const int root = 5;

std::vector<int> G[200000];

int s[200000];

int fact[200001];
int ifact[200001];

Zp A[(1<<19)+1];
Zp B[(1<<19)+1];
Zp w[(1<<18)+1];
Zp y[(1<<18)+1];

Zp add(Zp lhs, Zp rhs){
  Zp r = lhs + rhs;
  if(r >= mod) return r - mod;
  else return r;
}

Zp sub(Zp lhs, Zp rhs){
  if(lhs >= rhs) return lhs - rhs;
  else return mod + lhs - rhs;
}

Zp mul(Zp lhs, Zp rhs){
  return ((long long) lhs * rhs) % mod;
}

Zp powr(Zp x, int n){
  Zp r = 1;
  for(; n; n>>=1){
    if(n&0x1) r = mul(r, x);
    x = mul(x, x);
  }
  return r;
}

Zp inv(Zp x){
  return powr(x, mod-2);
}

unsigned clp2(unsigned x) {
   x = x - 1;
   x = x | (x >> 1);
   x = x | (x >> 2);
   x = x | (x >> 4);
   x = x | (x >> 8);
   x = x | (x >>16);
   return x + 1;
}

void fft(Zp *A){
  int u = 1;
  int v = m/2;
  for(int i=k;i>0;i--){
    for(int jh=0;jh<u;jh++){
      Zp wj = w[jh];
      for(int j = jh << i, je = j|v;j<je; j++){
        Zp Ajv = mul(wj, A[j|v]);
        A[j|v]  = sub(A[j], Ajv);
        A[j]   = add(A[j], Ajv);
      }
    }
    u <<= 1;
    v >>= 1;
  }
}

void ifft(Zp *A){
  int u = m/2;
  int v = 1;
  for(int i=1;i<=k;i++){
    for(int jh=0;jh<u;jh++){
      Zp wj = y[jh];
      for(int j = jh << i, je = j|v;j<je; j++){
        Zp Ajv = sub(A[j], A[j|v]);
        A[j] = add(A[j], A[j|v]);
        A[j|v] = mul(wj, Ajv);
      }
    }
    u >>= 1;
    v <<= 1;
  }
}


void genwy(int i, int b, Zp z, Zp x){
  if(b == 0) {
    w[i] = z;
    y[i] = x;
  }
  else {
    genwy(i, b>>1, z, x);
    genwy(i|b, b>>1, mul(z, w[b]), mul(x, y[b]));
  }
}

void init_fact(int n){
  fact[0] = 1;
  for(int i = 1; i <= n; i++){
    fact[i] = mul(fact[i-1], i);
  }
  ifact[n] = inv(fact[n]);
  for(int i = n-1; i >= 0; i--){
    ifact[i] = mul(ifact[i+1], i+1);
  }
}

int comb(int n, int k){
  return mul(mul(fact[n], ifact[n-k]), ifact[k]);
}

int makes(int i, int p){
  int sum = 0;
  for(int j = 0; j < G[i].size(); j++){
    int k = G[i][j];
    if(k == p) continue;
    sum += makes(k, i);
  }
  return s[i] = sum+1;
}

int main(){
  int n;
  std::scanf("%d", &n);
  for(int i=1;i<n;i++){
    int a, b;
    std::scanf(" %d %d", &a, &b);
    G[a-1].push_back(b-1);
    G[b-1].push_back(a-1);
  }
  m = clp2(n+1) << 1;
  k = __builtin_ctz(m);
  init_fact(n);
  makes(0, -1);
  for(int i=1;i<n;i++){
      A[s[i]]++;
      A[n-s[i]]++;
  }
  B[0]=1;
  for(int i=1;i<=n;i++){
    A[i] = mul(A[i], fact[i]);
    B[m-i] = ifact[i];
  }
  Zp z=powr(root, mod>>k);
  Zp x=inv(z);
  for(int j=m/4; j; j>>=1){
    w[j] = z;
    z = mul(z, z);
    y[j] = x;
    x = mul(x, x);
  }
  genwy(0, m/4, 1, 1);
  fft(A);
  fft(B);
  for(int i=0;i<m;i++){
    A[i] = mul(A[i], B[i]);
  }
  ifft(A);
  Zp im = inv(m);
  for(int i=1;i<=n;i++){
    std::printf("%d\n", sub(mul(n, comb(n, i)), mul(mul(A[i], im), ifact[i])));
  }
}

Measured memory_bytes: 34816
#include <bits/stdc++.h> 
using namespace std; 
#define int int64_t
const int M = 1e5 + 5;
int n, ans, a[M];

int32_t main() 
{ 
    	ios_base::sync_with_stdio(0);   cin.tie(0);     cout.tie(0);
    	cin >> n >> a[1];
    	ans = a[1];
    	for(int i = 2; i <= n; i++)	
    	{
    		cin >> a[i];
    		ans = __gcd(ans, a[i]);
    	}
    	cout << ans;
	return 0; 
} 


Measured memory_bytes: 1024
import java.util.Scanner;

class Main{
      	public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
    	
    	int n = scan.nextInt();
    	int a;
    	int min = 0;
    	int max = 0;
    	long sum = 0;
    	
    	for(int i = 0; i < n; i++){
    	    a = scan.nextInt();
    	    if(i == 0) {
    	    	min = a;
    	    	max = a;
    	    }
    	    min = Math.min(min, a);
    	    max = Math.max(max, a);
    	    sum += a;
    	}
    	
    	System.out.println(min + " " + max + " " + sum);
    	
     }
}

Measured memory_bytes: 41540
#include <iostream>
//#include <stdio.h>
using namespace std;

int main(){
	int n,m,l;
	long sum;
	int a[102][102],b[102][102],c[102][102];

	cin >> n >> m >> l;
	for (int i=1;i<=n;i++){
		for (int j=1;j<=m;j++){
			cin >> a[i][j];
		}
	}
	for (int i=1;i<=m;i++){
		for (int j=1;j<=l;j++){
			cin >> b[i][j];
		}
	}
	
	for (int i=1;i<=n;i++){
		for (int j=1;j<=l;j++){
			sum = 0;
			for (int k=1;k<=m;k++){
				sum += a[i][k] * b[k][j];
			}
			if (j != 1) cout << " ";
			cout << sum;
		}
		cout << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1240
n, k=map(int, input().split())
m=(n-1)*(n-2)//2
c=0
if k>m:
    print(-1)
else:
    e=n-1+m-k
    print(e)
    i=0
    while c<e:
        for j in range(i+1,n):
            c+=1
            print(i+1,j+1)
            if c==e:
                break
        i+=1

Measured memory_bytes: 44528
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <numeric>
#include <type_traits>
#include <limits>
#include <random>
#include <iomanip>

using namespace std;

using ll = long long;

typedef pair<int, int> P;

#define rep(i,N) for(long long i = 0;i < (long long)N; ++i)

static int mod = 1000000007;
static int large = 1000000000;

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

int N;

int a[100001];
int b[100001];
int c[100001];

int dp[100001][3];

inline int change(int x, int i) {
	if (x == 0) return a[i - 1];
	else if (x == 1) return b[i - 1];
	else if (x == 2) return c[i - 1];
	return -1;
}

//i日目,jで遊ぶ
int f(int i, int j) {
	if (dp[i][j] != -1) return dp[i][j];
	if (i == 0) return dp[0][j] = 0;
	int sec = 0;
	rep(k, 3) {
		if (k != j) {
			sec = max(sec, f(i - 1, k) + change(j, i));
		}
	}
	return dp[i][j] = sec;
}

int main() {
	cin >> N;
	rep(i, N) {
		cin >> a[i] >> b[i] >> c[i];
	}
	rep(i, 100001) {
		rep(j, 3) {
			dp[i][j] = -1;
		}
	}
	cout << max(f(N, 0), max(f(N, 1), f(N, 2))) << endl;
	return 0;
}



Measured memory_bytes: 10368
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	ll k,n,i,j,l;
  	cin >> k >> n;
    ll a[n+1];l=0;
  	for(i=0;i<n;i++)
    {
    	cin >> a[i];
    }
  	for(i=0;i<n-1;i++)
    {
    	j=a[i+1]-a[i];
      	if(j>l)
        {
          l=j;
        }
    }
  	j = a[0]+k-a[n-1];
  if(j>l)
        {
          l=j;
        }
  cout << (k-l) << endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
#include<map>
#include<cstring>
using namespace std;

int main() {
	string a; cin >> a;
	int b = a.length();
	if (*a.begin() == *--a.end())b--;
	if (b & 1)puts("First");
	else puts("Second");
}

Measured memory_bytes: 512
#!/usr/bin/env python3
#AGC19 B

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

a = input()
n = len(a)
c = list(Counter(a).items())
ans = n*(n-1)//2 + 1
for i,j in c:
    ans -= j*(j-1)//2
print(ans)


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

int main(){

    int n; cin>>n;

    int val[n],cos[n];

    for(int i=0; i<n; i++)cin>>val[i];

    for(int i=0; i<n; i++) cin>>cos[i];

    int ans=0,sum=0;

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

        if(val[i] - cos[i] < 0 ) continue;

        sum += val[i] - cos[i];
    }

    cout<<sum<<endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int acount = sc.nextInt();
		int bcount = sc.nextInt();
		int mcount = sc.nextInt();
		int []a = new int[acount];
		int []b = new int[bcount];
		int mina,minb;
		mina = 999999;
		minb = 999999;
		for (int i=0;i<acount;i++) {
			a[i]=sc.nextInt();
			if (a[i]<mina) {
				mina = a[i];
			}
		}
		for (int i=0;i<bcount;i++) {
			b[i]=sc.nextInt();
			if (b[i]<minb) {
				minb = b[i];
			}
		}

		int min =mina + minb;
		for (int i=0;i<mcount;i++) {
			int x=sc.nextInt();
			int y=sc.nextInt();
			int cut = sc.nextInt();
			if (a[x-1]+b[y-1]-cut<min) {
				min =a[x-1]+b[y-1]-cut;
			}
		}
		System.out.println(min);
	}
}

Measured memory_bytes: 133692
N, K = map(int, input().split())

D = []
As = []
for _ in range(K):
    D.append(int(input()))
    As.append(map(int, input().split()))

d = {i: 0 for i in range(1, N + 1)}
for i in range(K):
    A = As[i]
    for j in A:
        d[j] += 1

ans = 0
for key, val in d.items():
    if val == 0:
        ans += 1

print(ans)


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int

using namespace __gnu_pbds;

typedef tree<pair<ll,pair<ll,ll> >, null_type, less<pair<ll,pair<ll,ll> > >, rb_tree_tag, tree_order_statistics_node_update>ordered_set;


#define me BOSS
#define bug() cout<<"AIkahne aise"<<endl
#define PI acos(-1)
#define mod 1000000007
/* Precode Start Here *\


power of 2 less than or equal to N

ll largest_power(ll N)
{
    //changing all right side bits to 1.
    N = N (N>>1);
    N = N| (N>>2);
    N = N| (N>>4);
    N = N| (N>>8);


//as now the number is 2 * x-1, where x is required answer, so adding 1 and dividing it by
 2.
            return (N+1)>>1;

}


     Sieve
void sieve()
{
    for(ll i=3; i<=2000; i+=2)
    {
        for(ll j=i*i; j<=4000000; j+=i)
            A[j]=1;
    }
    v.push_back(2);
    for(ll i=3; i<=4000000; i+=2)
        if(A[i]==0)
            v.push_back(i);
}

     Power Function Modulo P

ll modPow(ll a, ll x, ll p) {
    //calculates a^x mod p in logarithmic time.
    long res = 1;
    while(x > 0) {
        if( x % 2 != 0) {
            res = (res * a) % p;
        }
        a = (a * a) % p;
        x /= 2;
    }
    return res;
}


   factorial

ll fact(ll n)
{
    ll ans=1;
    for(ll i=1;i<=n;i++)
    {
        ans=(ans*i)%mod;
    }
    return ans;
}
     Calculating nCr using Fermats law Theorem

ll modInverse(ll a, ll p) {
    //calculates the modular multiplicative of a mod m.
    //(assuming p is prime).
    return modPow(a, p-2, p);
}


ll modBinomial(ll n, ll k, ll p) {
// calculates C(n,k) mod p (assuming p is prime).

    ll numerator = 1; // n * (n-1) * ... * (n-k+1)
    for (ll i=0; i<k; i++) {
        numerator = (numerator * (n-i) ) % p;
    }

    ll denominator = 1; // k!
    for (ll i=1; i<=k; i++) {
        denominator = (denominator * i) % p;
    }

    // numerator / denominator mod p.
    return ( numerator* modInverse(denominator,p) ) % p;
}
     num of divisor and euler totient

ll phi[1000001],mark[1000001],divi[1000001];;
void divisorPhi(ll n)
{
    for(int i=1;i<=n;i++)
        phi[i]=i;
    for(int i=2;i<=n;i++)
    {
        if(!mark[i])
        {
            for(int j=i;j<=n;j+=i)
            {
                mark[j]=1;
                phi[j]*=(1-1/(double)i);
            }
        }
    }
    for(ll i=1;i<=n;i++)
    {
        for(ll j=i;j<=n;j+=i)
            divi[j]++;
    }
}




/* Precode Ends */
ll A[5000001],B[5000001];
vector<ll>v;
map<ll,ll>myMap;
set<ll>mySet;
vector<pair<ll,ll> >vp;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);

 ll a,b,x,y,n;
 cin>>a>>b>>n;
 if(a>=b)
 {
     x=a;
     y=b;
 }
 else
 {
     y=a;
     x=b;
 }
 cout<<(n+x-1)/x<<endl;
return 0;
}



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

typedef vector<int> vi;
typedef pair<int, int> pi;

const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

#define pb push_back
#define mp make_pair

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, b, e) for (int i = (b); i <= (int)(e); i++)
#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUGA(a) cout << #a << ": "; for (const auto& v: (a)) cout << v << endl

ll prod(ll a, ll b) {
    return a * b % MOD;
}

ll add(ll a, ll b) {
    return (a + b) % MOD;
}

signed main() {
    int N, K;
    cin >> N >> K;

    vi A(N);
    REP(i, N) cin >> A[i];

    ll f = 0, b = 0;
    REP2(i, 0, N-1) {
        REP2(j, i+1, N-1) {
            if (A[i] > A[j]) f++;
            if (A[i] < A[j]) b++;
        }
    }

    ll S = K % 2 == 0 ? prod(K / 2, K-1) : prod(K, (K-1)/2);
    ll ans = add(prod(f, K), prod(add(f, b), S));

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main (void)
{
   int n,i,j;
   scanf("%d",&n);

   for(i=1;i<=9;i++)
           for(j=1;j<=9;j++){
      if(i*j==n){
            printf("Yes\n");
            return 0;
      }
           }

             puts("No");
}


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

int n,k,x[100000];

int main(){
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++)scanf("%d",&x[i]);
    int ans=INT_MAX;
    for(int i=0;i<=n-k;i++){
        int l=x[i],r=x[i+k-1];
        if(l<=0&&r>=0)ans=min(ans,r-l+min(abs(l),abs(r)));
        else ans=min(ans,max(abs(l),abs(r)));
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,k;
	cin>>n>>k;
	vl v(n);
	rep(i,n)cin>>v[i];
	ll ans=0;
	rep(i,n)if(v[i]>=k)ans++;
	cout<<ans<<endl;
}


Measured memory_bytes: 1024
#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 ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;

#define int ll
#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "\n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)

const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e16;
const ld eps = 1e-12;
const ll N = (int)1e5 + 5;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
inline ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
inline ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
inline ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}

void solve() {
    int n, m;
    cin>>n>>m;
    f(i, m) {
        int u;
        cin>>u;
        n -= u;
    }
    if(n >= 0) cout<<n;
    else cout<<-1;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (LOCAL) {
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin);
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout);
    }
    int t = 1;
    //cin>>t;
    for(int test = 1; test <= t; test++) {
        //cout<<"Case #"<<test<<": ";
        solve();
    }
    return 0;
}

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

int main(){
	string s; cin>>s;
	int k=s.size();
	set<char> st;
	rep(i,k) st.insert(s[i]);
  
	if(st.size()==k) cout<<"yes"<<endl;
	else cout<<"no"<<endl;
}

Measured memory_bytes: 3592
w=list(input())
w_dct={}
for i in w:
    if i in w_dct.keys():
        w_dct[i]+=1
    else:
        w_dct[i]=1
        
tag=True
for i, j in w_dct.items():
    if j%2 ==0:
        pass
    else:
        tag=False
        
if tag:
    print('Yes')
else:
    print('No')

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

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

    int t1 = 1900;
    int t2 = 100;
    double p = 0.5;
    double q = 1-pow(p, m);
    int tt = t1*m + t2*(n-m);

    cout << -tt*q/(1-pow(2, m))/(1-q)/(1-q) << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>
#include <queue>
#include <cmath>

using namespace std;

typedef long long ll;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

const ll SQ = 50000, MOD = 1e9 + 7;

ll dp[110][SQ], pref[110][SQ], slf[110][SQ];

int main() {
	fastInp;

	ll n, k;
	cin >> k >> n;

	ll sq = sqrt(k);

	dp[0][1] = 1;
	ll ans = 0;
	for (int i = 1; i <= n; i++) {
		ll sm = 0, cur = 0, curs = 0;
		for (int j = 1; j <= sq; j++) {
			cur += pref[i][j];
			cur = (cur + MOD) % MOD;
			dp[i][j] += cur;
			dp[i][j] %= MOD;

			curs += slf[i][j];
			ll dl = (k / j);
			curs = (curs + MOD) % MOD;
			dp[i][j] += (dl - sq) * curs;
			dp[i][j] %= MOD;

			sm += dp[i - 1][j];
			sm %= MOD;
		}
		for (int j = 1; j <= sq; j++) {
			dp[i][j] += sm;
			dp[i][j] %= MOD;
		}

		for (int j = 1; j <= sq; j++) {
			ll dl = (k / j);
			dl -= sq;
			pref[i + 1][1] += dp[i - 1][j] * dl;
			pref[i + 1][j + 1] -= dp[i - 1][j] * dl;

			slf[i + 1][j + 1] += dp[i - 1][j];
			slf[i + 1][sq + 1] -= dp[i - 1][j];
		}

		if (i == n) {
			for (int j = 1; j <= sq; j++) {
				ll dl = (k / j);
				dl -= sq;
				ans += dp[i][j] + (dp[i - 1][j] * dl);
				ans %= MOD;
			}
		}
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 79008
N, M = map(int, input().split())
E1 = set()
EN = set()
for n in range(M):
    a, b = map(int, input().split())
    if a == 1:
        E1.add(b)
    if b == 1:
        E1.add(a)
    if a == N:
        EN.add(b)
    if b == N:
        EN.add(a)
for a in E1:
    if a in EN:
        print("POSSIBLE")
        break
else:
    print("IMPOSSIBLE")




Measured memory_bytes: 19024
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>


using namespace std;
using LLint = long long int;

LLint ModPow(LLint j,LLint k,LLint l){
	//(j^k)/mod l を計算
	if(k==0) return 1%l;
	else if(k%2==0){
		LLint t=ModPow(j,k/2,l);//k/2乗したもの
		return t*t%l;
	}
	else return (j%l)*ModPow(j,k-1,l)%l;
}

LLint Combi(LLint a,LLint b,LLint M){
	LLint UP,DOWN;
	UP=DOWN=1;
	for(int i=0;i<b;++i){
		UP = UP*((a-i)%M)%M;
		DOWN = DOWN*((i+1)%M)%M;
	}
	return (UP*ModPow(DOWN,M-2,M))%M;
}



const LLint Mod = 1000000007;

int main() {
	int n,a,b;
	cin>>n>>a>>b;
	LLint ALL = ModPow(2,n,Mod);

	LLint A;
	A=Combi(n,a,Mod);

	LLint B;
	B=Combi(n,b,Mod);

	cout<< (((ALL-1-A-B)%Mod)+Mod)%Mod<<endl;

	return 0;
}

Measured memory_bytes: 256
n,*h=map(int,open(0).read().split())
cnt=0
c=[]
pos=h[0]
for i in range(1,n):
  if pos>=h[i]:
    pos=h[i]
    cnt+=1
  else:
    c.append(cnt)
    cnt=0
    pos=h[i]
c.append(cnt)    
print(max(c)) 

Measured memory_bytes: 14092
import java.util.*;
import java.util.Scanner;
class Main{
    public static void main(String[] args)
    {
        int n;
        int result;
        int cal1;
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();

        if(n % 2 == 0){
            result = n / 2;
        }else{
            cal1 = n % 2;
            result = n / 2 + cal1;
        }
        
        System.out.println(result);
    }
}

Measured memory_bytes: 21844
S = input()
T = input()
flag = False
if len(S) == 2:
    if (S[0] == T[0] and S[1] == T[1]) or (S[0] == T[1] and S[1] == T[0]):
        flag = True

for i in range(1, len(S)-1):
    if S[:i] in T and S[i:] in T:
        flag = True
        break

if flag:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18 + 10;
const int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	ll n;
	cin >> n;
	ll p = n - 1;
	map<ll, ll> mp;
	repl(i, 2, sqrt(n) + 1) {
		while (p % i == 0) {
			p /= i;
			mp[i]++;
		}
	}
	if (p != 1) mp[p]++;
	ll cnt = 1;
	for (auto m : mp) cnt *= (m.second + 1);
	cnt--;
	repl(i, 2, (ll)sqrt(n) + 1) {
		if (n % i == 0) {
			p = n;
			while (p % i == 0) p /= i;
			if (p % i == 1) cnt++;
			if (n == i * i) break;
			p = n;
			ll q = n / i;
			while (p % q == 0) p /= q;
			if (p % q == 1) cnt++;
		}
	}
	cout << cnt + 1 << endl;
	return 0;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void)
{
  int n, f = 1;
  cin >> n;
  for(int i = 0;i<n;i++)
  {
      int a;
      cin >> a;
      if(a % 2 == 0)
      {
          if(a % 3 != 0 && a%5 != 0)
          {
              f = 0;
              break;
          }
      }
  }
  if(f == 1) cout << "APPROVED\n";
  else cout << "DENIED\n";
  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define ggr getchar();getchar();return 0;
#define prique priority_queue
constexpr auto mod = 1000000007;
#define inf 1e15
#define key 1e9
using namespace std;
typedef pair<int, int>P;
template<class T> inline void chmax(T& a, T b) {
	a = std::max(a, b);
}
template<class T> inline void chmin(T& a, T b) {
	a = std::min(a, b);
}
//combination(Nが小さい時はこれを使う
const int MAX = 330000;
int 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;
}
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

//繰り返し二乗法（Nが大きい時の場合のcombination)
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= (i % mod); res %= mod;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
//UnionFind
class UnionFind {
protected:
	int* par, * rank, * size;
public:
	UnionFind(unsigned int size) {
		par = new int[size];
		rank = new int[size];
		this->size = new int[size];
		rep(i, size) {
			par[i] = i;
			rank[i] = 0;
			this->size[i] = 1;
		}
	}
	int find(int n) {
		if (par[n] == n)return n;
		return par[n] = find(par[n]);
	}
	void unite(int n, int m) {
		n = find(n);
		m = find(m);
		if (n == m)return;
		if (rank[n] < rank[m]) {
			par[n] = m;
			size[m] += size[n];
		}
		else {
			par[m] = n;
			size[n] += size[m];
			if (rank[n] == rank[m])rank[n]++;
		}
	}
	bool same(int n, int m) {
		return find(n) == find(m);
	}
	int getsize(int n) {
		return size[find(n)];
	}
};
int dight(int n) {
	int ans = 1;
	while (n >= 10) {
		n /= 10;
		ans++;
	}
	return ans;
}
int dight_sum(int n) {
	int sum = 0;
	rep(i, 20)sum += (n % (int)pow(10, i + 1)) / (pow(10, i));
	return sum;
}
int dight_min(int n) {
	int ans = 9;
	while (n >= 10) {
		ans = min(ans, n % 10);
		n /= 10;
	}
	ans = min(ans, n);
	return ans;
}
int dight_max(int n) {
	int ans = 0;
	while (n >= 10) {
		ans = max(ans, n % 10);
		n /= 10;
	}
	ans = max(ans, n);
	return ans;
}
int a[5];
signed main() {
	rep(i, 5)cin >> a[i];
	rep(i, 5) {
		if (a[i] == 0)cout << i + 1 << endl;
	}
	ggr
}


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

int N, C, K;
char* S;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> N >> K >> C;
	S = new char[N];
	cin >> S;
//	cout << "N = " << N << ", K = " << K << ", C = " << C << ", S = [" << S << "]" <<endl;

	// 後詰め pos をxとしたときに、次のセル以降で稼げる最大数
	vector<int> r2l(N, 0);
	int s = 0;
	int d = 0;
	r2l[N - 1] = 0;
	for (int p = N - 1; p > 0; p--) {
		if (d <= 0 && S[p] != 'x') {
			s++;
			d = C + 1;
		}
		r2l[p - 1] = s;
		d--;
	}
//	cout << "r2l = [";
//	for (int p = 0; p < N; p++) cout << r2l[p];
//	cout << "]" << endl;

	// 前詰めしながらカウント
	int p = 0;
	s = 0;
	while(p < N) {
		if (S[p] != 'x') {
//			cout << "(p,s,r2l[p]) = (" << p << "," << s << "," << r2l[p] << ")" << endl;
			if (s + r2l[p] < K) cout << p + 1 << endl;
			s++;
			p += C + 1;
		}
		else {
			p++;
		}
	}
}


Measured memory_bytes: 2560
#include<stdio.h>
#include<stdlib.h>

int main(void){
    int num;
    double a[100000];
    unsigned int minus_cnt=0;
    double sum=0;
    double min;
    
    scanf("%d",&num);
    if(num<2) return -1;
    for(int i=0; i<num; i++){
        scanf("%lf",&a[i]);
    }
    min = abs(a[0]);
    
    for(int i=0; i<num; i++){
        if(a[i]<0){
            minus_cnt++;
        }
        sum += abs(a[i]);
        
        if(min > abs(a[i])) min=abs(a[i]);
    }
    
    if(minus_cnt%2==0){
        printf("%.0lf\n",sum);
    }else{
        printf("%.0lf\n",sum-(2*min));
    }
  
    return 0;
}

Measured memory_bytes: 896
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; }
    void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; }

    void solve()
    {
        var X = cin.nextlong;
        var A = cin.nextlong;
        var B = cin.nextlong;

        if (A - B >= 0)
        {
            WriteLine("delicious");
        }
        else if (B - A <= X)
        {
            WriteLine("safe");
        }
        else
        {
            WriteLine("dangerous");
        }

    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 11092
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <map>
#include <functional>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
#define MIN(a, b) (((a) < (b)) ? (a) : (b))



using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;
const ll inf = (1LL << 60);



vector<pint> query;


ll N, C;
vector<pll> val, cval;
ll Clock[100005], Cclock[100005];
int main() {
	cin >> N >> C;
	ll v, x;

	rep(i, N) {
		cin >> x >> v;
		val.push_back({x, v});
	}
	
	rep(i, N) {
		cval.push_back({ C - val[N - 1 - i].first, val[N-1-i].second });
	}
	ll sum = 0, sumc = 0;
	rep(i, N) {

		sum += val[i].second;
		sumc += cval[i].second;

		if (i != 0) {
			Clock[i] = MAX(Clock[i - 1], sum - val[i].first);
			Cclock[i] = MAX(Cclock[i - 1], sumc - cval[i].first);
		}
		else {
			Clock[0] = MAX(0, sum - val[i].first);
			Cclock[0] = MAX(0, sumc - cval[i].first);
		}
		
	}

	ll rpos = 0;
	ll ans = MAX(Clock[N-1], Cclock[N-1]);

	for(rpos = 0; rpos < N - 1; rpos++){
		
		ans = MAX(ans, Clock[rpos] - val[rpos].first + Cclock[N - rpos - 2]);
		ans = MAX(ans, Cclock[rpos] - cval[rpos].first + Clock[N - rpos - 2]);

	}
	


	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5104
import java.util.Scanner

import scala.collection.mutable.ArrayBuffer


object Main {

  // u: from
  // v: to
  case class Edge(u: Int, v: Int, w: Long)

  def read() = {
    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    // ここ、0オリジン化した方がいい
    val edges = IndexedSeq.fill(n - 1)(Edge(sc.nextInt(), sc.nextInt(), sc.nextInt()))
    (n, edges)
  }

  def read2() = {
    val input = io.Source.stdin.getLines()
    val n = input.next().toInt
    val edges = IndexedSeq.fill(n - 1) {
      val strs = input.next().split(" ")
      Edge(strs(0).toInt, strs(1).toInt, strs(2).toInt)
    }
    (n, edges)
  }

  def solve(n: Int, edges: IndexedSeq[Edge]): IndexedSeq[Int] = {
    val nextList = IndexedSeq.fill(n + 1)(ArrayBuffer.empty[Edge])
    for (edge <- edges) {
      val from = edge.u
      val to = edge.v
      nextList(from).append(edge)
      nextList(to).append(Edge(to, from, edge.w))
    }
    val visited = Array.fill(n + 1)(false)
    // 1から
    visited(1) = true
    val open: java.util.Queue[Int] = new java.util.ArrayDeque[Int]()
    //add, remove
    open.add(1)
    //白:false ,黒:true
    val colors = Array.fill(n + 1)(true)
    colors(1) = false


    while (!open.isEmpty) {
      val current = open.remove()
      for (edge <- nextList(current)) {
        val next = edge.v
        if (!visited(next)) {
          val w = edge.w
          if (w % 2 == 0) {
            colors(next) = colors(current)
          } else {
            colors(next) = !colors(current)
          }
          visited(next) = true
          open.add(next)
        }
      }
    }
    colors.takeRight(n).map(p => if (p) 1 else 0)
  }

  def output1(result: IndexedSeq[Int]) = {
    result.foreach(println)
  }

  def output2(result: IndexedSeq[Int]) = {
    result.foreach(System.out.println)
  }

  def output3(result: IndexedSeq[Int]) = {
    val out = new java.io.PrintWriter(System.out)
    result.foreach(out.println)
    out.flush()
  }

  def main(args: Array[String]): Unit = {
    val (n, edges) = read2()
    output3(solve(n, edges))
  }
}

Measured memory_bytes: 69640
#include <stdio.h>
#include <ctype.h>

int main() {

  char ch[1200];
  int i,n;
  n=0;
  char a[1200];

  while(1) {
    scanf("%c",&a[n]);
    if(a[n] == '\n') {
      break;
    }
    ch[n] = a[n];
    if('A' <= a[n] && a[n] <= 'Z') {
      ch[n] = a[n] + 32;
    } else if(a[n] >= 'a' && a[n] <= 'z') {
      ch[n] = a[n] - 32;

    }
    
    
    n = n +1;
    
  }
  
  for(i=0; i<n ; i++) {
    printf("%c" ,ch[i]);
  }
  printf("\n"); 
  return 0;
  
}



Measured memory_bytes: 2048
#include <stdio.h>

int main()
{
	int	h, w;
	char	a[100][100+1] = {0};
	int	x[100] = {0}, y[100] = {0};
	int	i, j;

	scanf("%d %d", &h, &w);
	for (i = 0; i < h; ++i) {
		scanf("%s", a[i]);
	}

	for (i = 0; i < h; ++i) {
		for (j = 0; j < w; ++j) {
			if (a[i][j] != '.') {
				x[j] = 1;	// 残す
				y[i] = 1;	// 残す
			}
		}
	}

	for (i = 0; i < h; ++i) {
		if (y[i] == 0) {
			continue;
		}
		for (j = 0; j < w; ++j) {
			if (x[j] == 1) {
				printf("%c", a[i][j]);
			}
		}
		printf("\n");
	}

	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)

int main( void ){
	int n, m, x;
	if (!scanf( "%d%d%d", &n, &m, &x ))
		return -1;
	int a=0, b=0;
	rep( i, 0, m ){
		int c;
		if (!scanf( "%d", &c ))
			return -1;
		if (c < x)
			a++;
		else
			b++;
	}
	printf( "%d\n", std::min(a, b) );
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
#define repi(i,n) for(int i=0;i<(int)(n);i++)
#define repd(i,n) for(int i=(int)(n);i>=0;i--)

int main()
{
    int A,B,X;
    cin >> X >> A >> B;
    cout << (X-A)%B << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <climits>
using namespace std;

long int jou(long int x, long int y){
    long int f = 1;
    for(int i = 0; i < y; ++i){
        f = f * x % int(powl(10,9) + 7);
    }

    return f;
}

int main(){

      vector<long int> v;

    long int n;
    cin >> n;
    if(n == 0){
        cout << 0 << endl;
        return 0;
    }
    for(long int i = 0; i < n; ++i){
        long int a;
        cin >> a;
        v.push_back(a);
    }

    sort(v.begin(),v.end());

    if(n % 2 == 1){
        if(v[0] != 0){
            cout << 0 << endl;
            return 0;
        }
        for(long int i = 1;i < n; i += 2){
            if(v[i] != i + 1 || v[i] != v[i + 1]){
                cout << 0 << endl;
                return 0;
            }
        }
        cout << jou(2,n/2)%((long int)powl(10,9) + 7) << endl;
    }else{
        for(long int i = 0;i < n; i += 2){
            if(v[i] != i + 1 || v[i] != v[i + 1]){
                cout << 0 << endl;
                return 0;
            }
        }
        cout << jou(2,n/2)%((long int)powl(10,9) + 7) << endl;
    }

  return 0;
}

Measured memory_bytes: 1400
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define double long double
#define EPS 1e-9
//#define PI 3.14159265358979

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < A[i].size(); j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

typedef pair< int, int > pii;
typedef long long ll;

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	cin >> N;
	vector< int > A(N);
	rep(i, N) cin >> A[i];
	int ans = 1000;
	K = 0;
	rep(i, N) {
		if (i == N - 1) {
			ans += K * A[i];
			K = 0;
		} else {
			if (A[i + 1] > A[i]) {
				int tmp = ans / A[i];
				ans -= A[i] * tmp;
				K += tmp;
			} else if (A[i + 1] < A[i]) {
				ans += A[i] * K;
				K = 0;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>

int main(void) {
  int n,t,c[200000],i,ans = 0;
  scanf("%d %d",&n,&t);
  for (i = 0;i < n;i++) {
    scanf("%d",&c[i]);
  }
  for (i = 1;i < n;i++) {
    if (c[i] < c[i - 1] + t) {
      ans += c[i] - c[i - 1];
    } else {
      ans += t;
    }
  }
  ans += t;
  printf("%ld\n",ans);
  return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <b; i++)
typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int,int> pi;
#define trace(x) cout<<#x<<"="<<x<<"\n";
#define sz(x) (int)(x.size())
#define mod 1000000007

template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "{";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "[";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
    os << "[";
    typename map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " = " << it -> second ;
    }
    return os << "]";
}

#define deb(x) cerr << #x << " = " << x << endl;



int32_t main(){
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vi b(n-1);
    REP(i,0,n-1){
        cin>>b[i];
    }
    vi a(n,1e18);
    for(int i=0;i<(n-1);i++){
        a[i]=min(a[i],b[i]);
        a[i+1]=min(a[i+1],b[i]);
    }
    int sum=0;
    REP(i,0,n){
        sum+=a[i];
    }
    cout<<sum<<"\n";



    return 0;
}

Measured memory_bytes: 256
n,a,b,c = gets.split.map(&:to_i)
xs=n.times.map{gets.to_i}
$ans = 100000000000
def f(ps, xs, a, b, c)
  if ps.size == xs.size

    lens = [0] * 4
    num = 0
    ps.zip(xs).each{|p, x|
      lens[p] += x
      num += 1 if p < 3
    }
    3.times{|k|
      return if lens[k] == 0
    }
    cost = (lens[0] - a).abs + (lens[1] - b).abs + (lens[2] - c).abs + (num - 3) * 10
    $ans = [$ans, cost].min
  else
    4.times{|k|
      f(ps+[k], xs, a, b, c)
    }
  end
end
f([], xs, a, b, c)
p $ans


Measured memory_bytes: 1788