akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define int long long

#define iin(x) scanf("%d", &x)
#define lin(x) scanf("%lld", &x)
#define fin(x) scanf("%lf", &x)

#define iout(x) printf("%d", x)
#define lout(x) printf("%lld", x)
#define fout(x) printf("%.10f", x)
#define _ putchar(' ')
#define endl puts("")

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

int L[500001], R[500001];

int merge(int A[], int left, int mid, int right) {
  int res = 0;
  int n1 = mid - left;
  int n2 = right - mid;
  int i, j, k;
  rep(i, n1) L[i] = A[left+i];
  rep(i, n2) R[i] = A[mid+i];
  L[n1] = 2000000000;
  R[n2] = 2000000000;
  i = 0, j = 0;
  reps(k, left, right) {
    if(L[i] <= R[j]) {
      A[k] = L[i];
      i++;
    } else {
      A[k] = R[j];
      j++;
      res += n1 - i;
    }
  }
  return res;
}

int mergeSort(int A[], int left, int right) {
  int a = 0, b = 0, c = 0;
  if(left + 1 < right) {
    int mid = (left + right) / 2;
    a = mergeSort(A, left, mid);
    b = mergeSort(A, mid, right);
    c = merge(A, left, mid, right);
  }
  return a+b+c;
}

int A[500001];

signed main() {
  int n; lin(n);
  int i;
  rep(i, n) lin(A[i]);
  lout(mergeSort(A, 0, n)),endl;

  return 0;
}

Measured memory_bytes: 9580
//Let's join Kaede Takagaki Fan Club !!
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define all(x) x.begin(),x.end()
template<class T>
void dmp(T a){
	rep(i,a.size()) cout << a[i] << " ";
	cout << endl;
}
template<class T>
bool chmax(T&a, T b){
	if(a < b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
bool chmin(T&a, T b){
	if(a > b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
void g(T &a){
	cin >> a;
}
template<class T>
void o(const T &a,bool space=false){
	cout << a << (space?' ':'\n');
}
//ios::sync_with_stdio(false);
const ll mod = 1000000007;//998244353
template<class T>
void add(T&a,T b){
	a+=b;
	if(a >= mod) a-=mod;
}

int main(){
	int s, w; cin >> s >> w;
	if(w >= s) printf("un");
	puts("safe");
}


Measured memory_bytes: 3724
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    
    cin>>a>>b>>c;

    if(a==b&&b!=c&&c!=a)
    {
        cout<<"Yes"<<endl;
    }

    else if(b==c&&c!=a&&a!=b)
    {
        cout<<"Yes"<<endl;
    }

    else if(c==a&&a!=b&&b!=c)
    {
        cout<<"Yes"<<endl;
    }

    else cout<<"No";
}   

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int K = in.nextInt();
            int odd = 0;
            int even = 0;
            for (int i = 1; i <= K; i++) {
                if (i % 2 == 0) {
                    even++;
                } else {
                    odd++;
                }
            }
            System.out.println(odd * even);
        }
    }
}


Measured memory_bytes: 26984
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1001001001;

int main() {
  ll n, tmpa;
  bool tmpflag = true;
  cin >> n;
  n++;
  unordered_map<ll, ll> a;
  a[INF] = 10;
  for(int i = 1; i < n; i++){
    cin >> tmpa;
    if(a[tmpa] != 0){
      cout << "NO" << endl;
      tmpflag = false;
      break;
    }
    a[tmpa] = i;
  }
  if(tmpflag){
      cout << "YES" << endl;
  }
  return 0;
}

Measured memory_bytes: 8520
def resolve():
    '''
    code here
    '''
    N = int(input())
    As = [int(item) for item in input().split()]

    As.sort()
    max_num = max(As)

    res = 10**9 + 1
    if max_num % 2 == 0:
        if max_num //2 in As:
            res = max_num //2
        else:
            for item in As:
                if abs(max_num //2 - res) > abs(max_num //2 - item):
                    res = item
    else:
        if max_num //2 in As:
            res = max_num //2
        elif max_num // 2 + 1 in As:
            res = max_num //2 + 1 
        else:
            for item in As:
                if abs(max_num //2 - res) > abs(max_num //2 - item):
                    res = item
                if abs(max_num //2 + 1 - res) > abs(max_num //2 + 1 - item):
                    res = item


    print(max(As), res)

if __name__ == "__main__":
    resolve()


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

int main(){
    string s;
    cin >> s;
    int len = (int)(s.length());
    int cnt[2019] = {};
    reverse(s.begin(), s.end());
    int total = 0, x = 1, ans = 0;
    for(int i = 0; i < len; i++){
        cnt[total]++;
        // -'0'によって文字コードを数値に変換している
        total += (s[i]-'0')*x;
        total %= 2019;
        x = x * 10 % 2019;
        // 1+2+3+4+...
        ans += cnt[total];
    }
    cout << ans;
    return 0;
}

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

using namespace std;


//repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define euc_dis(x, y) sqrt(x*x + y*y)

#define pb push_back
#define mp make_pair
#define INF 999999999
#define MOD 1000000007
#define sp ' '


//typedef
typedef long long ll;
typedef pair<int, int> pint;
typedef pair<long, long> pll;
typedef map<int, int> mint;
typedef set<int> sint;
typedef vector<int> vint;
typedef vector<char> vchr;
typedef vector<long long> vll;
typedef vector<string> vstr;


ll mod(ll a, ll b){return (a%b+b)%b;}
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 Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll a, ll b, ll c){ll ans=1; rep(i, b){ans=ans*a%c;} return ans;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T>
void dpp(T n){cerr << n << endl;}
template<typename T>
void vpp(T a){rep(i,a.size()){cout << a[i] << endl;}}
template<typename T>
void vdp(T a){rep(i,a.size()){cerr << a[i] << endl;}}

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

int main(){

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

    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;

    int dx, dy;
    dx = x2-x1;
    dy = y2-y1;

    int x3,x4,y3,y4;

    x3 = x2-dy;
    y3 = y2+dx;
    x4 = x1-dy;
    y4 = y1+dx;

    cout << x3 << sp << y3 << sp << x4 << sp << y4 << endl;



    return 0;
}


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

typedef long long ll;
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

const int MOD = 1e9 + 7 ;
const double PI = 2 * acos(0.0) ;

map <string, ll> mp ;

int main()
{
    string s, t, x ;
    ll a, b ;
    cin >> s >> t ;
    cin >> a >> b ;
    mp[s] = a, mp[t] = b ;
    cin >> x ;
    mp[x]-- ;

    cout << mp[s] << " " << mp[t] << endl ;

}


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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    int ma=0;
    int ma2=0;
    rep(i,n){
        cin >> a[i];
        //cout << a[i] << endl;
    ma=max(a[i],ma);
    }
    int cunt=0;
    rep(i,n){
        if(a[i]!=ma){
            ma2=max(ma2,a[i]);
        }
        if(ma==a[i]){
                cunt++;
        }
    }
    if(cunt>1){
        ma2=ma;
    }
    rep(i,n){
        if(a[i]==ma){
                cout << ma2 << endl;
        }
        else{
        cout << ma << endl;
        }
    }
  //  cout << ma2 << endl;
    
}

Measured memory_bytes: 4724
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
constexpr auto INF = INT_MAX >> 1;
constexpr auto LINF = 5000000000000000;
constexpr auto MOD = 1000000007;

int main()
{
    int n, k;
    cin >> n >> k;
    vi a(n);
    rep(i, n)cin >> a[i];
    vi sum(n + 1);
    rep(i, n)sum[i + 1] = (sum[i] + a[i]) % k;
    rep(i, n + 1) {
        sum[i] += n - i;
        sum[i] %= k;
    }

    map<int, int> mp;
    ll ans = 0;
    rep(i, n) {
        if (i + 1 >= k)mp[sum[i - k + 1]]--;
        mp[sum[i]]++;
        ans += mp[sum[i + 1]];
    }

    cout << ans << endl;

}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
#include <math.h>
#include <float.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
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; }
// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
const int MOD = 1000000007;


int main(){
    char A; cin >> A;

    if ('a'<=A && A<='z'){
        cout << "a" << endl;
    }
    else{
        cout << "A" << endl;
    }
}

Measured memory_bytes: 3608
import java.util.*

fun main() {
  val sc = Scanner(System.`in`)
  val n = sc.nextInt()
  val k = sc.nextLong()
  
  val telepo = mutableListOf<Int>()
  for (i in 1..n) {
    telepo.add(sc.nextInt())
  }
  
  val dup = mutableMapOf<Int, Long>()
  
  var idx = 1
  var i = 1L
  while (i <= k) {
  	val next = telepo[idx - 1]
    
    if (dup.containsKey(next)) {
      val p = dup[next]!!
      val ni = (k - i) % (i - p)
      val newi = k - ni + 1
      if (i < newi) {
        i = newi
        idx = next
        continue
      }
    }
    
    dup.put(next, i)
    idx = next
    i += 1
  }
  println(idx)
}

Measured memory_bytes: 73892
from collections import Counter
N = int(input())
MOD = 10**9+7
  
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
  
ans = 1
counter = Counter()
for p in range(2,N+1):
  counter.update(Counter(prime_factorize(p)))
for value in counter.values():
    ans *= (value + 1)
print(ans % MOD)



Measured memory_bytes: 3316
H,W=gets.split.map &:to_i
M=H.times.map{gets.split.map &:to_i}
Z=H.times.flat_map{|h|[*0...W].send([:to_a,:reverse][h%2]).map{|e|[h,e]}}
R=[]
Z.each_cons(2){|(y1,x1),(y2,x2)|
	if M[y1][x1]%2>0
		M[y2][x2]+=1
		R<<[y1+1,x1+1,y2+1,x2+1]*' '
	end
}
p R.size
puts R

Measured memory_bytes: 51324
#include<bits/stdc++.h>
#define int long long
#define MAXN 2010
#define p 1000000007
using namespace std;
int n,f[MAXN];
signed main(){
	scanf("%lld",&n);
	f[0]=1;if(n<=2)return printf("0"),0;
	for(int i=3;i<=n;i++)
		for(int j=0;j<=i-3;j++)
			f[i]=(f[i]+f[j])%p;
	printf("%lld",f[n]%p);
	return 0;
}

Measured memory_bytes: 3820
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll l, r; cin >> l >> r;
    ll m = min(l+4038, r);
    ll x = 1000100010;
    ll res = 2019;
    for(ll i=l; i<=m; ++i){
        for(ll j=i+1; j<=m; ++j){
            ll x = i*j%2019;
            res = min(res, x);
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3556
#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll MOD=1000000007;
#define loop(i,n) for(ll i=0;i<(ll)(n);i++)
#define change(a,b) do{ll c=a; a=b; b=c;}while(0)
long long gcd(long long a,long long b){
    ll gcdmax=max(a,b);
    ll gcdmin=min(a,b);
    while(true){
        if(gcdmax%gcdmin==0)break;
        else gcdmax%=gcdmin;
        change(gcdmin,gcdmax);
    }
    return gcdmin;
}
ll powerup(ll N,ll P,ll M){
    if(P==0)return 1;
    else if(P%2==0){
        ll t=powerup(N,P/2,M);
        return t*t%M;
    }
    else return N*powerup(N,P-1,M)%M;
}
int main()
{
  ll A[3][3]={0};
  loop(i,3){
    loop(j,3){
      cin>>A[i][j];
    }
  }
  ll N,M;
  cin>>N;
  loop(i,N){
    cin>>M;
    loop(j,3){
      loop(k,3){
        if(A[j][k]==M)A[j][k]=0;
      }
    }
  }
  ll line=0;
  if(A[0][1]+A[0][2]+A[0][0]==0)line=1;
  if(A[1][1]+A[1][2]+A[1][0]==0)line=1;
  if(A[2][1]+A[2][2]+A[2][0]==0)line=1;
  if(A[0][0]+A[1][0]+A[2][0]==0)line=1;
  if(A[0][1]+A[1][1]+A[2][1]==0)line=1;
  if(A[0][2]+A[1][2]+A[2][2]==0)line=1;
  if(A[0][0]+A[1][1]+A[2][2]==0)line=1;
  if(A[0][2]+A[1][1]+A[2][0]==0)line=1;
  if(line==1)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
int main() {
	ll N;
	cin >> N;
	if (N < 105)
		cout << 0 << endl;
	else if (N < 135)
		cout << 1 << endl;
	else if (N < 165)
		cout << 2 << endl;
  	else if(N<189)
      	cout<<3<<endl;
	else if (N < 195)
		cout << 4 << endl;
	else
		cout << 5 << endl;


}











Measured memory_bytes: 256
N, K = map(int, input().split())
d = [0 for _ in range(K)]
A = [0 for _ in range(K)]
for i in range(K):
    d[i] = int(input())
    A[i] = list(map(int, input().split()))

l = []
for i in range(K):
    l += A[i]
print(N - len(set(l)))

Measured memory_bytes: 9376
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
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 (a>b) { a = b; return 1; } return 0; }
void rcmb(ll *x,ll s,ll r,function<void(ll *)>f){if(r==0){f(x);}else{if(s<0)return;rcmb(x,s-1,r,f);x[r-1]=s;rcmb(x,s-1,r-1,f);}}
void cmb(ll n,ll k,function<void(ll *)>f){ll x[k];rcmb(x,n-1,k,f);}
void prm(ll n,function<void(ll *)>f){ll x[n];for(ll i=0;i<n;i++)x[i]=i;do{f(x);}while(next_permutation(x,x+n));}
void prm(ll n,ll k,function<void(ll *)>f){cmb(n,k,[&](ll *c){prm(k,[&](ll *p){ll x[k];for(ll i=0;i<k;i++){x[i]=c[p[i]];}f(x);});});}
// prm(4, 2, [](ll *x){ cout << x[0] << "," << x[1] << "\n"; });

const string YES = "Yes";
const string NO = "No";

void solve(string N){
	bool can = false;
	if (N[0]=='7') can = true;
	if (N[1]=='7') can = true;
	if (N[2]=='7') can = true;
	if (can) cout << YES << "\n";
	else cout << NO << "\n";
}

int main(){
    string N;
	cin >> N;
    solve(N);
    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n,v) rep(i,n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
int x_pos[4] = {1,0,-1,0}, y_pos[4] = {0,1,0,-1};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

char upper(char c){
	return c-0x20;
}

char lower(char c){
	return c+0x20;
}

void unique_vector(vector<int>& v){
	sort(all(v));
	v.erase(unique(all(v)), v.end());
}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int gcd(int x, int y) {
  if (y == 0) return x;
  return gcd(y, x%y);
}

int main() {
    ll q,h,s,d;cin>>q>>h>>s>>d;
    ll n;cin>>n;
    ll cost = INF;
    cost = min(q*4,cost);
    cost = min(h*2,cost);
    cost = min(s,cost);
    ll cost_2 = min(cost*2,d);
    ll ans = n/2*cost_2;
    if(n%2) ans+=cost;
    cout << ans << endl;
}



Measured memory_bytes: 256
#include<stdio.h>

int main(void) {
	int H, W;
	while (1) {
		scanf("%d %d", &H, &W);
		if (H == 0 && W == 0)break;
		for (int i = 1; i <= H; i++) {
			for (int j = 1; j <= W; j++) {
				if (i == 1 || i == H || j == 1 || j == W) {
					printf("#");
				}
				else {
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
}


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

#define ll          long long
#define ull         unsigned long long
#define pb          push_back
#define pii         pair<int,int>
#define pll         pair<long,long>
#define vi          vector<int>
#define vll         vector<ll>
#define vii         vector<pii>
#define Mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)      (a).rbegin(),(a).rend()
#define ff           first
#define ss           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define mod        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rem(i,a,b)  for(int i=a;i>b;i--)
#define mp(a,b)     make_pair(a,b)
#define INF         numeric_limits<ll>::max();
#define NINF        numeric_limits<ll>::min();
#define vvi(a,b,name)    vector<vector<int>> name(a,vector<int>(b,-1))



void solve(){
    ll n,k;
    cin>>n>>k;
    if(n==0){
        cout<<0;
        return;
    }
    ll i=n/k;
    ll j=(n+k-1)/k;
    cout<<min(abs(n-i*k),abs(n-j*k));




}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    long t=1;
    //cin>>t;

    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
/*
h s, d't skp th si tll i's svedclTabCtrl
 * ABC141 E
 * ABC145 D
 * ABC147 F
 * ABC174 F
*/
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n,k;
cin>>n>>k;
ll p[n];
ll c[n];
for(ll i=0;i<n;i++)
{
cin>>p[i];
}
for(ll i=0;i<n;i++)
{
cin>>c[i];
}
vector< vector<ll> > vc;
vector<set<ll> > st;
map<ll,ll> mp;
bool ok[n+1]={};
for(ll i=0;i<n;i++)
{
if(!ok[p[i]])
{
ll sm=0;
ll j=p[i];
vector<ll> arr;
set<ll> stt;
ll cnt=1;
arr.push_back(0);
ll ps=i;
while(!ok[j])
{
sm+=c[ps];
arr.push_back(sm);
stt.insert(j);
mp[j]=cnt;
cnt++;
ok[j]=1;
ps=j-1;
j=p[j-1];
}
vc.push_back(arr);
st.push_back(stt);
}
}
ll res=-1e19;
ll u=k;
for(ll i=1;i<=n;i++)
{
for(ll o=0;o<st.size();o++)
{
k=u;
if(st[o].count(i))
{
ll pp=mp[i];
ll ans=-1e19;

ll maxi=-1e18;
for(ll w=1;w<vc[o].size();w++)
{
maxi=max(maxi,vc[o][w]);
}

if(k>=vc[o].size()-pp)
{
for(ll j=pp;j<vc[o].size();j++)
{
ans=max(ans,vc[o][j]-vc[o][pp-1]);
}
ll kk=vc[o][vc[o].size()-1]-vc[o][pp-1];
ll ff=k-(vc[o].size()-pp);
for(ll j=1;j<=min((ll)vc[o].size()-1,ff);j++)
{
ans=max(ans,kk+vc[o][j]);
}
ll gg=0;
gg+=vc[o][vc[o].size()-1]-vc[o][pp-1];
k-=(vc[o].size()-pp);
ll f=k/(vc[o].size()-1);
gg+=vc[o][vc[o].size()-1]*f;
k%=(vc[o].size()-1);
ll nn=-1e18;
for(ll w=1;w<=k;w++)
{
nn=max(nn,vc[o][w]);
}
if(nn!=-1e18)
{
gg+=nn;
}
ans=max(ans,gg);




k=u;
gg=0;
gg+=vc[o][vc[o].size()-1]-vc[o][pp-1];
k-=(vc[o].size()-pp);
f=k/(vc[o].size()-1);
f--;
if(f>=0)
{
gg+=vc[o][vc[o].size()-1]*f;
if(nn!=-1e18)
{
gg+=maxi;
}
ans=max(ans,gg);
}


k=u;

}
else
{
for(ll j=pp;j<pp+k;j++)
{
ans=max(ans,vc[o][j]-vc[o][pp-1]);
}
}
res=max(res,ans);
break;
}
}
}

cout<<res<<endl;
}

/*
 *||||

 */


Measured memory_bytes: 4592
#include <iostream>
#include <map>
#include <ctime>
#include <vector>
#include <climits>
#include <algorithm>
#include <random>
#include <cstring>
#include <cstdio>
#include <map>
#include <set>
#include <bitset> 
#include <queue>
#pragma warning(disable:4996);
#define inf 0x3f3f3f3f
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define rep(i, a, n) for(register int i = a; i <= n; ++ i)
#define per(i, a, n) for(register int i = n; i >= a; -- i)
//#define ONLINE_JUDGE
using namespace std;
typedef long long ll;
const int mod=1e9+7;
template<typename T>void write(T x)
{
    if(x<0)
    {
        putchar('-');
        x=-x;
    }
    if(x>9)
    {
        write(x/10);
    }
    putchar(x%10+'0');
}
 
template<typename T> void read(T &x)
{
    x = 0;char ch = getchar();ll f = 1;
    while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
    while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}
int gcd(int a,int b){return b==0?a:gcd(b,a%b);}
int lcm(int a,int b){return a/gcd(a,b)*b;};
ll ksm(ll a,ll n){//看是否要mod 
	ll ans=1;
	while(n){
		if(n&1) ans=((ans%mod)*(a%mod))%mod;
		a=((a%mod)*(a%mod))%mod;
		n>>=1;
	}
	return ans%mod;
}
//==============================================================
int n,l[105];


int main()
{
	#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
	//===========================================================
	read(n);
	rep(i,1,n) read(l[i]);
	sort(l+1,l+1+n);
	int ans=0;
	rep(i,1,n){
		rep(j,i+1,n){
			rep(k,j+1,n){
				if(l[i]+l[j]>l[k]){
					if(l[i]!=l[j]&&l[j]!=l[k]&&l[i]!=l[k]) ans++;
				}
			}
		}
	}
	write(ans);
	//===========================================================
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <iomanip>
#include <math.h>

using namespace std;

int main(){
	
	
	int h1,h2,m1,m2,k,res=0;
	cin >> h1 >> m1 >> h2 >> m2 >>k;
	
	res=(h2-h1)*60+(m2-m1)-k;
	
	
//	if (res=0){
//		cout << "Yes" <<endl;
//	}
//	}
//	else{
//		if (ceil(c/b)<=ceil(a/d)){ //9 11 10 10
//		//cout << ceil(c/b);
//		cout << "Yes"<<endl;}
//		else
//		cout <<"No"<<endl;
//	}
	
	cout << res<<endl;
	
	return 0;
	
	
	
}

Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
#include<cassert>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

int main(){
	int n,m;
	int i,j,k;
	int a,b,c;
	cin>>a>>b;
	if(b%2==0 && a*2<=b && b<=a*4)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int x,y;
	scanf("%d%d",&x,&y);
	for(int i=0;i<=x;i++)
	{
		if(2*i+4*(x-i)==y)
		{
			puts("Yes");
			return 0;
		}
	}
	puts("No");
	return 0;
}

Measured memory_bytes: 3656
x = int(input())

if 400 <= x <= 599:
    print(8)
elif 600 <= x <= 799:
    print(7)
elif 800 <= x <= 999:
    print(6)
elif 1000 <= x <= 1199:
    print(5)
elif 1200 <= x <= 1399:
    print(4)
elif 1400 <= x <= 1599:
    print(3)
elif 1600 <= x <= 1799:
    print(2)
elif 1800 <= x <= 1999:
    print(1)


Measured memory_bytes: 9180
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
int main() {
  string S;
  cin >> S;
  string key = "keyence";
  int ans = 0;
  REP(i, 7) {
    if (S[i] != key[i]) {
      break;
    }
    ans++;
  }
  for (int i = 0; i < 7;i++){
    if(S[S.size()-i]!=key[key.size()-i]){
      break;
    }
    ans++;
  }
    if (7 < ans) {
      puts("YES");
    } else {
      puts("NO");
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
const ll INF = 1e18;
#define print(x) cout << (x) << endl;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    sort(S.begin(), S.end());
    bool flag = true;
    if (S.at(0) != S.at(1)) {
        flag = false;
    }
    if (S.at(1) == S.at(2)) {
        flag = false;
    }
    if (S.at(2) != S.at(3)) {
        flag = false;
    }
    if(flag) cout << "Yes" << endl;
    else {cout << "No" << endl;}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int ans=0,cnt=0;
	while(1)
	{
		cnt+=n;
		ans++;
		if(cnt%360==0)
		{
			cout<<ans;
			return 0;
		} 
	}
	return 0;
}

Measured memory_bytes: 3596
N = int(input())
ansAC = 0
ansWA = 0
ansTLE = 0
ansRE = 0
 
for i in range(N):
  S = input()
  if S == "AC":
    ansAC += 1
  elif S == "TLE":
    ansTLE += 1
  elif S == "WA":
    ansWA += 1
  elif S == "RE":
    ansRE += 1
print("AC x " + str(ansAC))
print("WA x " + str(ansWA))
print("TLE x " + str(ansTLE))
print("RE x " + str(ansRE))

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

int main(){
  int N,M;
  cin>>N>>M;
  int C=0,P=0,w[N],p;
  string S;
  bool a[N];
  
  for(int i=0;i<N;i++){
    a[i]=false; w[i]=0;
  }
  
  for(int i=0;i<M;i++){
    cin>>p>>S;
    if(S=="WA"&&a[p-1]==false){
      w[p-1]++;
    }
    if(S=="AC"&&a[p-1]==false){
      C++; P+=w[p-1]; a[p-1]=true;
    }
  }
  cout<<C<<" "<<P;
}
  
  

Measured memory_bytes: 768
// Vicfred
// https://atcoder.jp/contests/abc046/tasks/abc046_a
// simulation
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.stdio;

void main() {
    int[] cans = readln.split.map!(to!int).array;
    auto rbt = redBlackTree(cans);
    rbt.length.writeln;
}



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

int main() {
  
  int x, y;
  cin >> x >> y;
  
  int m = 0;
  
  if (x == 3)  m += 100000;
  else if (x == 2)  m += 200000;
  else if (x == 1)  m += 300000;
  
  if (y == 3)  m += 100000;
  else if (y == 2)  m += 200000;
  else if (y == 1)  m += 300000;
  
  if (x == 1 && y == 1)  m += 400000;
  
  cout << m << endl;
  
}


Measured memory_bytes: 256
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2005
#include <iostream>
#include <vector>
#include <climits>
using namespace std;

const int INF = 1<<28;

int main(){

  for(int n,m,s,g1,g2;cin>>n>>m>>s>>g1>>g2,n;){
    vector<vector<int>> d(n, vector<int> (n, INF));

    // directed graph
    for(int i=0,b1,b2,c;i<m;++i){
      cin>>b1>>b2>>c;
      d[b1-1][b2-1] = c;
    }

    for(int i=0;i<n;++i) d[i][i] = 0;

    for(int k=0;k<n;++k)
      for(int i=0;i<n;++i)
        for(int j=0;j<n;++j) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);

    int ans = INT_MAX;
    for(int i=0;i<n;++i) ans = min(ans, d[s-1][i] + d[i][g1-1] + d[i][g2-1]);

    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 1260
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
 
a, b = [0], [0]
for i in range(N):
  a.append(a[i] + A[i])
for i in range(M):
  b.append(b[i] + B[i])
  
ans, j = 0, M
for i in range(N + 1):
  if a[i] > K:
    break
  while b[j] > K - a[i]:
    j -= 1
  ans = max(ans, i + j)
print(ans)

Measured memory_bytes: 47300
from collections import Counter
N = int(input())
A = list(map(int, input().split()))

sorted_A = sorted(A)
result = 0
c = Counter(sorted_A)
# 倍数を管理するテーブル
lendp = sorted_A[-1] + 1
dp = [0] * lendp

for a in sorted_A:
    dp[a] += 1
    if dp[a] == 1:
        b = a * 2
        while b < lendp:
            dp[b] += 2
            b += a

print(dp.count(1))


Measured memory_bytes: 40084
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
using namespace std;
typedef pair<int, int> pii;
#define MAX 99999999
int main(){
    int n;
    while(cin>>n,n){
    vvi v(n+1,vi(n+1,INF));
    rep(i,n+1)v[i][i]=0;
    int hoge = 0;
    rep(i,n){
        int c;
        pii temp; cin>>temp.first>>temp.second>>c;
        v[temp.first][temp.second]=c;
        v[temp.second][temp.first]=c;
        hoge=max(hoge,max(temp.first, temp.second));
    }
    n=hoge+1;
    loop(k,0,n)
    loop(i,0,n)
    loop(j,0,n){
        v[i][j]=min(v[i][j],v[i][k]+v[k][j]);
    }
    //loop(i, 0, n){loop(j, 0, n)cout<<v[i][j]<<" "; puts("");}
    ll ans=INF,temp=0; int num=12;
    loop(i,0,n){
        loop(j,0,n)temp+=v[i][j];
        if(ans>temp){num=i; ans=temp;}
        temp=0;
    }
    cout<<num<<" "<<ans<<endl;
    }
}

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

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

    int ans = 1;
    for(int i = 1; i*i <= m; i++){
        if(m % i)   continue;
        if(i >= n)      ans = max(ans, m/i);
        if(m/i >= n)    ans = max(ans, i);
    }

    cout << ans << endl;

    return 0;
}

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

typedef std::pair<int, int> P;

P data[202];
int dp[202];

int main(){

	int n, m;
	while (std::cin >> n, n){

		memset(data, 0, sizeof(data));
		memset(dp, 0, sizeof(dp));

		for (int i = 1; i <= n; i++){
			std::cin >> data[i].first >> data[i].second;
		}

		std::cin >> m;
		for (int i = 1; i <= m; i++){
			std::cin >> data[i + n].first >> data[i + n].second;
		}

		std::sort(data, data + 1 + n + m);

		for (int i = 1; i <= n + m; i++){
			for (int j = 0; j < i; j++){
				if (data[i].first > data[j].first&&data[i].second > data[j].second){
					dp[i] = std::max(dp[i], dp[j] + 1);
				}
			}
		}

		int max = 0;
		for (int i = 0; i <= n + m; i++){
			if (dp[i] > max)max = dp[i];
		}
		std::cout << max << std::endl;
	}
	return 0;
}

Measured memory_bytes: 1164
#include <iostream>
using namespace std;
int main( void )
{
  int x,y,z;
  while( 1 ){
    cin >> x >> y;
    if( cin.eof() ) break;
    x += y;
    z = 0;
    if( x == 0 ) z = 1;
    while( x > 0 ){
      z++;
      x /= 10;
    }
    cout << z << endl;
  }
  return 0;
}

Measured memory_bytes: 0
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
ll tSize[55];
ll pNum[55];
ll n, x;
ll ans = 0;

void solve(ll nowp, ll nows){
    if(tSize[nows] / 2 + 1 <= nowp){
        ans += pNum[nows - 1];
        //cout << pNum[nows - 1] << endl;
        ans++;
        if(tSize[nows] / 2 + 1 == nowp){
            return;
        }
        ll nextp = nowp - (tSize[nows] / 2 + 1);
        if(nows < 1) return;
        solve(nextp, nows - 1);
    } else {
        if(nowp - 1 < 1){
            return;
        }
        if(nows < 1) return;
        solve(nowp - 1, nows - 1);
    }
    


}

int main(void){
    cin >> n >> x;
    tSize[0] = 1;
    pNum[0] = 1;
    for(int i = 1; i <= n; i++){
        tSize[i] = tSize[i - 1] * 2 + 3;
        //cout << tSize[i] << endl;
        pNum[i] = pNum[i - 1] * 2 + 1;
    }

    solve(x, n);

    cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

int main(){
    double a;
    double b;
    double C;
    double S;
    double L;
    double h;

    cin >> a >> b >> C;

    double PI = acos(-1);
    double rad = C * PI / 180;
    S = (a*b*sin(rad))/2;
    L = sqrt(pow(a, 2) + pow(b , 2) - 2*a*b*cos(rad)) + a + b;
    h = b*sin(rad);

    printf("%.5f\n", S);
    printf("%.5f\n", L);
    printf("%.5f\n", h);
     
}


Measured memory_bytes: 3428
import math
import numpy as np
import sys
import os
from operator import mul

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353    

N = I()
S = str(N)
S_sum = 0
for s in S:
    S_sum += int(s)

if S_sum % 9 == 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 27276
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {

	int n; cin >> n;
	string s; cin >> s;

	int cnt = 0;
	int ans = 0;
	for (int i = 0; i < s.length(); i++) {
		if (s[i]=='(')
		{
			cnt++;
		}
		else {
			cnt--;

			ans = min(ans, cnt);
		}
	}

	
	if (ans < 0) {
		ans = -ans;
		for (int i = 0; i < ans; i++) {
			s = "(" + s;
		}
	}


	int m = cnt +ans;

	for (int i = 0; i < m; i++) {
		s = s + ")";
	}

	cout << s << endl;


	return 0;
}

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

typedef long long ll;
#define N (1<<18)

ll ai[N*2];
ll max_num = 1;

void update(int x, int y){
    int k = x + N-1;
    ai[k] = y;
    while(k > 0){
        k = (k-1)/2;
        ai[k] = min(ai[k*2+1], ai[k*2+2]);
    }
}

int find(int x, int y, int k = 0, int l = 0, int r = N){
    if(r <= x || y <= l) return max_num;
    if(x <= l && r <= y) return ai[k];

    int resultl = find(x, y, k*2+1, l, (l+r)/2);
    int resultr = find(x, y, k*2+2, (l+r)/2, r);
    return min(resultl, resultr);
}

int main(){
    for(int i = 0; i < 31; i++) max_num *= 2;
    max_num -= 1;

    for(int i = 0; i < N*2; i++) ai[i] = max_num;

    int n, q;
    cin >> n >> q;

    for(int i = 0; i < q; i++){
        int com, x, y;
        cin >> com >> x >> y;
        if(com == 0){
            update(x, y);

        }else{
            cout << find(x, y+1) << endl;
        }
    }

}




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

#define ll long long
#define ull unsigned long long

const ll MOD = 1000000007;

using namespace std;

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

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

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

	auto dp = make_vec<ll>(N+1, 4, 4, 4);
	dp[0][0][0][0] = 1;

	rep(i,N)rep(z,4)rep(a,4)rep(b,4)rep(c,4) {
		if ((b==1)&&(c==2)&&(z==3)) continue;
		if ((b==2)&&(c==1)&&(z==3)) continue;
		if ((b==1)&&(c==3)&&(z==2)) continue;
		if ((a==1)&&(c==2)&&(z==3)) continue;
		if ((a==1)&&(b==2)&&(z==3)) continue;
		dp[i+1][b][c][z] = (dp[i+1][b][c][z] + dp[i][a][b][c]) % MOD;
	}

	ll ans = 0;
	rep(a,4)rep(b,4)rep(c,4) {
		ans = (ans + dp[N][a][b][c]) % MOD;
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 3692
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, L = lr()
A = np.arange(1, N+1)
A += (L - 1)
answer = A.sum() - A[np.argmin(np.abs(A))]
print(answer)

Measured memory_bytes: 14456
#include<stdio.h>
#include<string.h>
#include<math.h>


int main()
{
	int n,k;
	scanf("%d %d",&n,&k);
	long long int array[n];
	int i;
	for (i=0;i<n;i++)
	{
		scanf("%lld",&array[i]);
	}
	long long int answer=0;
	for (i=0;i<n-1;i++)
	{
		if (array[i+1]-array[i]>k)
			answer += k;
		else answer += array[i+1] - array[i];
	}
	answer += k;
	printf("%lld",answer);
	
	return 0;
}

Measured memory_bytes: 1664
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] l = new int[n];
        int sum = 0;
        for (int i = 0; i < n; i++) {
            l[i] = sc.nextInt();
            sum+=l[i];
        }
        
        for (int i = 0; i < n; i++) {
            if (l[i] >= sum - l[i]) {
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");
    }
}


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

int main(void)
{
	string S;
  	int ans = 0;
  	cin >> S;
  	for (int i = 0; i<3; i++)
    {
      if (ans > 0 && S[i] == 'S')
        break;
      if (S[i] == 'R')
        ans++;
    }
  	cout << ans;
  	return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
  int a, b, d, r;
  double f;
  cin >> a >> b;

  d = a/b;
  r = a%b;
  f = (double)a/(double)b;
  cout << d << " " << r << " " << fixed << setprecision(5) << f << endl;
  return 0;
}

Measured memory_bytes: 1244
#include <stdio.h>

struct Card{
  char suit;
  char value;
};


void bubble(struct Card A[], int num){
  int i,j;
  struct Card tmp;
  for(i=0;i<num-1;i++){
    for(j=num-1;j>=i+1;j--){
      if(A[j].value < A[j-1].value){
	tmp=A[j];
	A[j]=A[j-1];
	A[j-1]=tmp;
      }
    }
  }
}

void Selection(struct Card A[], int num){
  int i,j,min;
  struct Card tmp;
  for(i=0;i<num-1;i++){
    min=i;
    for(j=i;j<num;j++){
      if(A[j].value < A[min].value) {
	min=j;
    }
    }
    if(A[i].value != A[min].value){
    tmp=A[i];
    A[i]=A[min];
    A[min]=tmp;
    }
  }
}

void print(struct Card A[], int num){
  int i;
  for(i=0;i<num;i++){
    if(i) printf(" ");
    printf("%c%c", A[i].suit, A[i].value);
  }
  printf("\n");
}

int isStable(struct Card C1[], struct Card C2[], int num){
  int i;
  for(i=0;i<num;i++){
    if(C1[i].suit != C2[i].suit) return 0;
  }
  return 1;
}

int main ()
{
  struct Card C1[101],C2[101];
  int num,i;
 

  scanf("%d\n",&num);
  for(i=0;i<num;i++){
    scanf(" %c%c",&C1[i].suit, &C1[i].value);
  }
  for(i=0;i<num;i++) C2[i]=C1[i];
  
  bubble(C1,num);
  Selection(C2,num);
  
  print(C1,num);
  printf("Stable\n");
  print(C2,num);
  if(isStable(C1,C2,num)){
    printf("Stable\n");
  }
  else{
    printf("Not stable\n");
  }

  return 0;
}

Measured memory_bytes: 612
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#include<queue>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

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

const ll MOD = 1e9 + 7;
// const long long INF = 1LL<<60;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }
void sub(long long &a, long long b) { a -= b; if (a < 0) a += MOD; }
void mul(long long &a, long long b) { a *= b; a %= MOD; }
ll llmin(ll a, ll b) { if (a < b) return a; else return b; }
ll llmax(ll a, ll b) { if (a < b) return b; else return a; }
ll llabs(ll a) { if (a >= 0) return a; else return - a; }
ll llmodpow(ll a, ll n) {
   if (n == 0) return 1;
   ll tmp = llmodpow(a, n / 2);
   mul(tmp, tmp);
   if (n & 1) mul(tmp, a);
   return tmp;
}

int main() {
   int N;
   cin >> N;
   int s[N];
   int ans = 0;
   int tmp = 101;
   for (int i = 0; i < N; i++) {
      cin >> s[i];
      ans += s[i];
      if (s[i] % 10 != 0) chmin(tmp, s[i]);
   }
   if (ans % 10 != 0) cout << ans << endl;
   else if (tmp != 101) cout << ans - tmp << endl;
   else cout << 0 << endl;
   return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <math.h>
#include <iomanip>
using namespace std;

double gCount = 0.0;
double gSum = 0.0;

void calcSum(double sum, int n, vector<int> isFinish, int s, int e,const vector<double>& x, const vector<double>& y)
{
	sum += sqrt((x[e] - x[s])*(x[e] - x[s]) + (y[e] - y[s])*(y[e] - y[s]));
	for (int i = 0; i < n; ++i) {
		if (isFinish[i] == 0) {
			isFinish[i] = 1;
			calcSum(sum, n, isFinish, e, i, x, y);
			isFinish[i] = 0;
		}
	}

	int i = 0;
	for (; i < n; ++i) {
		if (isFinish[i] == 0) {
			break;
		}
	}
	if (i == n) {
		gSum += sum;
		gCount += 1.0;
	}
}

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

	vector<double> x(n);
	vector<double> y(n);
	for (int i = 0; i < n; ++i) {
		cin >> x[i] >> y[i];
	}

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			if (i == j) {
				continue;
			}
			vector<int> isFinish(n, 0);
			isFinish[i] = 1;
			isFinish[j] = 1;
			double sum = 0.0;
			calcSum(sum, n, isFinish, i, j, x, y);
		}
	}

	cout << fixed << setprecision(10);
	cout << gSum / gCount << endl;

	return 0;
}

Measured memory_bytes: 256
N = int(input())
a = [0] * N
b = [0] * N
c = [0] * N
for i in range(N):
    a[i], b[i], c[i] = map(int, input().split())
    
Dpa = [0]*N
Dpb = [0]*N
Dpc = [0]*N

Dpa[0] = a[0]
Dpb[0] = b[0]
Dpc[0] = c[0]


for i in range(1,N):
  Dpa[i] = max(Dpb[i-1],Dpc[i-1])+a[i]
  Dpb[i] = max(Dpc[i-1],Dpa[i-1])+b[i]
  Dpc[i] = max(Dpa[i-1],Dpb[i-1])+c[i]
  
print(max(Dpa[-1],Dpb[-1],Dpc[-1]))

Measured memory_bytes: 26740
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N = INT()
A = [INT() for _ in range(N)]

ans = 0
for i in range(N-1):
	if A[i]%2 and A[i+1]:
		A[i] -= 1
		A[i+1] -= 1
		ans += 1

for a in A:
	ans += a//2

print(ans)


Measured memory_bytes: 14392
#![allow(unused_imports)]
#![allow(unused_macros)]
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_variables)]
#![allow(unused_mut)]
#![allow(unused_assignments)]
use proconio::input;
use proconio::marker::*;
use std::collections::*;
use std::cmp::*;
use std::f64::consts::*;

const MOD: u64 = 1000000007;
const INF: usize = std::usize::MAX / 4;

fn main() {
    input! {
        N: Chars,
    }

    if N.iter().filter(|&&n| n == '7').count() > 0 {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 2164
#include <iostream>
#include<string>

using namespace std;

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

	for (int i = 0; i < s.size(); i++) {
		s[i] = s[i] + n;
		if (s[i] > 90) {
			s[i] -= 26;
		}
	}
	cout << s << endl;

	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,ssse3")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
using namespace std;
using ll = long long;
using vi = vector<ll>;
using pi = pair<ll, ll>;
const int maxn = 1<<20, mod = 1e9 + 7;
int fact[maxn], inv[maxn];
void calc() {
	for(int i = 0; i < maxn; i++) {
		if(i < 2) fact[i] = inv[i] = 1;
		else fact[i] = i, inv[i] = mod - (mod/i)*1ll*inv[mod%i]%mod;
	}
	for(int i = 1; i < maxn; i++) fact[i] = fact[i]*1ll*fact[i-1]%mod;
	for(int i = 1; i < maxn; i++) inv[i] = inv[i]*1ll*inv[i-1]%mod;
}
int nck(int n, int k) {
	if(k > n || n < 0 || k < 0) return 0;
	int t = fact[n]*1ll*inv[k]%mod;
	return t*1ll*inv[n-k]%mod;
}
int main() {
	cin.tie(0)->sync_with_stdio(0);
	calc();
	int n, m, a, b;
	cin >> n >> m >> b >> a;
	int ans = nck(n+m-2, n-1);
	for(int i = 0; i < a; i++) {
		ans = (ans + mod - nck(n-b-1+i, i)*1ll*nck(m-i-1+b-1, b-1)%mod)%mod;
	}
	cout << ans;
}


Measured memory_bytes: 8576
#include<stdio.h>

int min(int x,int y){
  if(x<y) return x;
  else return y;
}

int main(){
  int a,b,c,d;
  scanf("%d %d %d %d",&a,&b,&c,&d);
  printf("%d\n",min(a,b)+min(c,d));
}

Measured memory_bytes: 128