akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define p (int)(1e9 + 7)
#define inf (int)(1e9 + 1)

int MOD(int a){
	return (a %= p) >= 0 ? a : a + p;
}

signed main(){
	int N, i;
	scanf("%lld", &N);
	vector<int> T(N), A(N);
	for(i = 0; i < N; i++){
		scanf("%lld", &T[i]);
	}
	for(i = 0; i < N; i++){
		scanf("%lld", &A[i]);
	}
	vector<int> m(N, 1), M(N, inf);
	m[0] = max(m[0], T[0]);
	M[0] = min(M[0], T[0]);
	for(i = 1; i < N; i++){
		if(T[i] > T[i - 1]){
			m[i] = max(m[i], T[i]);
			M[i] = min(M[i], T[i]);
		}
		else{
			M[i] = min(M[i], T[i]);
		}
	}
	m[N - 1] = max(m[N - 1], A[N - 1]);
	M[N - 1] = min(M[N - 1], A[N - 1]);
	for(i = N - 2; i >= 0; i--){
		if(A[i] > A[i + 1]){
			m[i] = max(m[i], A[i]);
			M[i] = min(M[i], A[i]);
		}
		else{
			M[i] = min(M[i], A[i]);
		}
	}
	int ans = 1;
	for(i = 0; i < N; i++){
		ans = MOD(ans * max(0ll, M[i] - m[i] + 1));
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 3328
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////


int main(){

    ll n,m;
    cin >> n >> m;
    ll d[n+5] = {};

    rep(i,0,m){
	ll l,r;
	cin >> l >> r;
	d[l]++;
	d[r+1]--;
    }
    ll ans = 0,num = 0;
    rep(i,1,n+1){
	num += d[i];
	if(num >= m)ans++;
    }
    P(ans);
    return  0;
}


Measured memory_bytes: 1024
s = int(input())
ls = []
ls.append(s)
if s % 2 == 0:
    x = s//2
else:
    x = 3*s + 1
for i in range(10**6+1):
    if x in ls:
        ans = i+2
        break
    else:
        ls.append(x) 
        if x % 2 == 0:
            x = x//2
        else:
            x = 3*x + 1       
print(ans)

Measured memory_bytes: 9176
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        int Y = sc.nextInt();

        for (int bird = 0; bird < X + 1; bird++) {
            for (int turtle = 0; turtle < X + 1; turtle++) {
                if (X == bird + turtle && Y == 2 * bird + 4 * turtle) {
                    System.out.println("Yes");
                    return;
                }
            }
        }
        System.out.println("No");
    }
}

Measured memory_bytes: 35796
n = int(input())
s = list(list(input()) for i in range(n))

for i in range(n):
    s[i].sort()

s.sort()

a = 0
answer = 0
for i in range(n-1):
    for j in range(10):
        if s[i][j] != s[i+1][j]:
            a = 0
            break
        elif j == 9:
            a += 1
    answer += a

print(answer)


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

int n, a, b, hosei, temp;
vector<int> forbidden;

bool is_listed (int num) {
  if (find(forbidden.begin(), forbidden.end(), num) == forbidden.end()) {
    return false;
  }
  return true;
}

int main() {
  cin >> n;
  vector<int> factorio{1, 2, 6, 24, 120, 720, 5040, 40320};
  vector<int> p(n);
  vector<int> q(n);
  rep (i, n) {
    cin >> p.at(i);
  }rep (i, n) {
    cin >> q.at(i);
  }
  a=0;b=0;
  rep (i, n-1) {
    hosei = -1;
    rep (j, forbidden.size()) {
      if (p.at(i) > forbidden.at(j)) hosei--;
    }
    a += (p.at(i) + hosei) * factorio.at(n-i-2);
    forbidden.push_back(p.at(i));
  }
  forbidden = {};
  rep (i, n-1) {
    hosei = -1;
    rep (j, forbidden.size()) {
      if (q.at(i) > forbidden.at(j)) hosei--;
    }
    b += (q.at(i) + hosei) * factorio.at(n-i-2);
    forbidden.push_back(q.at(i));
  }
  cout << abs(a-b) << endl;
  return 0;
}


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

using LL = long long;
LL n;
map<LL, LL> p;

signed main() {
  // freopen("in", "r", stdin);
  while(~scanf("%lld", &n)) {
    LL ret = 0;
    p.clear();
    for(int i = 1; i <= n; i++) {
      int k = i;
      for(int j = 2; k && j <= k; j++) {
        int tot = 0;
        while(k % j == 0) {
          k /= j;
          tot++;
        }
        if(tot) p[j] += tot;
      }
      if(k > 1) p[k] += 1;
    }
    vector<LL> cnt;
    LL c1=0, c3 = 0, c5 = 0, c15 = 0, c25 = 0, c75 = 0;
    for(auto x : p) {
      if(x.second+1>=1)c1++;
      if(x.second+1>=3)c3++;
      if(x.second+1>=5)c5++;
      if(x.second+1>=15)c15++;
      if(x.second+1>=25)c25++;
      if(x.second+1>=75)c75++;
    }
    printf("%lld\n", c75+c25*(c3-1)+c15*(c5-1)+c5*(c5-1)/2*(c3-2));
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(void) {
  int A[4];
  int B[4];
  int blow;
  int hit;
  int tmp;

  while(cin >> tmp) {
    blow = 0;
    hit = 0;
    
    A[0] = tmp;
    for(int i = 1; i < 4; i++) {
      cin >> A[i];
    }
    for(int i = 0; i < 4; i++) {
      cin >> B[i];
    }

    for(int i = 0; i < 4; i++) {
      if(A[i] == B[i]) {
        hit++;
      }
      else {
        for(int j = 0; j < 4; j++) {
          if(A[i] == B[j]) {
            blow++;
          }
        }
      }
    }
    cout << hit << " " << blow << endl;
  }

  return 0;
}

Measured memory_bytes: 1156
def solve():
    a, b, c, d = read()
    result = think(a, b, c, d)
    write(result)


def read():
    return read_int(4)


def read_int(n):
    return list(map(lambda x: int(x), read_line().split(' ')))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(a, b, c, d):
    if b <= c or d <= a:
        return 0
    elif a <= c and d <= b:
        return d - c
    elif c <= a and b <= d:
        return b - a
    else:
        if a == c:
            return min(b, d) - a
        elif a < c:
            return abs(c - b)
        else:  # a > c
            return abs(d - a)


def write(result):
    print(result)


if __name__ == '__main__':
    solve()

Measured memory_bytes: 3064
/*
 
dunjen_master
 
*/
 

#include<bits/stdc++.h>

 
using namespace std;
 
const int MAX_N = int(1e6) + 10;
const long long int MOD=1e9+7;
const long long int INF=1e18;

typedef long long int ll;

ll mul(ll a,ll b){

    a=(a+MOD)%MOD;
    b=(b+MOD)%MOD;
    ll c=a*b;
    c=(c+MOD)%MOD;
    return c;
}
ll add(ll a,ll b){
    a=(a+MOD)%MOD;
    b=(b+MOD)%MOD;
    ll ans=(a+b);
    ans=(ans+MOD)%MOD;
    return ans;
}
ll power(ll a,ll b,ll c=0){
    ll ans=1;
    while(b){
        if(b&1){
            ans=mul(ans,a);
        }
        a=mul(a,a);
        b=b/2;
    }
    return ans;
}




int main(){
 
    
      int k;
    cin>>k;
 
    ll sum=0;
 
    for(int i=1;i<=k;i++){
        for(int j=1;j<=k;j++){
            for(int m=1;m<=k;m++){
                sum+=__gcd(i,__gcd(j,m));
            }
        }
    }
 
    cout<<sum<<endl;
 
 
    
    
 
    
}

    

    
 
    



Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1e9+7;
const int INF=1e9;
const ll LINF=(ll)1e18;

int main(){
    int n;
    cin>>n;
    bool flag=true;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        if(a%2==0&&(a%3!=0&&a%5!=0)){
            flag=false;
        }
    }
    cout<<(flag?"APPROVED":"DENIED")<<endl;
}


Measured memory_bytes: 256
N=int(input())
A,B= list(map(int,input().split())),list(map(int,input().split()))

ans = 0
for i,b in enumerate(B):
    temp = min(b,A[i]+A[i+1])
    ans += temp
    A[i+1] -= max(0, temp-A[i]) #有り余った力を次の街で倒す
print(ans)


Measured memory_bytes: 18476
def main():
    h, w, m = map(int, input().split())
    bombs_h = [0] * h
    bombs_w = [0] * w
    B = []
    for n in range(m):
        h1, w1 = map(lambda x: int(x)-1, input().split())
        B.append((h1, w1))
        bombs_w[w1] += 1
        bombs_h[h1] += 1
    max_h = max(bombs_h)
    max_w = max(bombs_w)
    h_maxindex = [i for i, x in enumerate(bombs_h) if x == max_h]
    w_maxindex = [i for i, x in enumerate(bombs_w) if x == max_w]
    cnt = 0
    k = len(h_maxindex) * len(w_maxindex)
    for i, j in B:
        if bombs_h[i] == max_h and bombs_w[j] == max_w:
            cnt += 1
    ans = max_h + max_w - (cnt == k)
    print(ans)
    
    
if __name__ == "__main__":
    main()

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

#define int ll
#define FOR(i,n,k) for(int i=n;i<k;i++)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const int N = 1e6 + 5;
int dp[N];

int32_t main()
{
    IOS;
    string s;
    cin>>s;
    dp[0] = 1;
    FOR(i,0,s.size())
    {
        if(dp[i])
        {
            if(i+5 <= s.size() && s.substr(i,5) == "dream") dp[i+5] = 1;
            if(i+5 <= s.size() && s.substr(i,5) == "erase") dp[i+5] = 1;
            if(i+6 <= s.size() && s.substr(i,6) == "eraser") dp[i+6] = 1;
            if(i+7 <= s.size() && s.substr(i,7) == "dreamer") dp[i+7] = 1;
        }
    }
    if(dp[s.size()]) cout<<"YES\n";
    else cout<<"NO\n";
    return 0;
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
#define lp(n) for(int i = 0; i < n; i++)
#define lpp(i, n) for(int i = 0; i < n; i++)

int A[2000001];
int B[2000001];
int C[10001];
using namespace std;
int main() {
    int n;
    cin >> n;
    lp(10001) C[i] = 0;
    lp(n) {
      cin >> A[i];
      C[A[i]]++;
    }
    for(int i = 1; i < 10001; i++) C[i] = C[i] + C[i-1];
    for(int i = n-1; i >= 0; i--) {
        B[C[A[i]]] = A[i];
        C[A[i]]--;
    }
    for(int i = 1; i <= n; i++) cout << B[i] << ((i == n)?"\n":" ");
    return 0;
}






Measured memory_bytes: 18672
n = int(input())
h = list(map(int, input().split()))

count = 0
count_list = [0]

for i in range(n-1):
	if(h[i+1] <= h[i]):
		count += 1
		count_list.append(count)
	else:
		count = 0

print(max(count_list))

Measured memory_bytes: 14224
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

void OutputError(std::string s) {
  cerr << "\033[93m" << s << "\033[m" << endl;
  return;
}

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  int n;
  int64_t result = 0;
  std::vector<int> l;
  cin >> n;
  for (int i = 0; i < 2 * n; i++) {
    int m1;
    cin >> m1;
    l.push_back(m1);
  }
  std::sort(l.begin(), l.end());
  for (int i = 0; i < 2 * n; i += 2) {
    result += l[i];
  }
  cout << result << endl;

  return 0;
}


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

int main() {
  int N;
  cin >> N;
  int cnt = 0;
  for(int i=1;i<=N;i++){
    if(to_string(i).length() % 2 == 1){
      cnt++;
    }
  }
  
  cout << cnt << endl;
  return(0);
}

Measured memory_bytes: 256
#include <iostream>

using llint = long long int;

int main()
{
    std::ios_base::sync_with_stdio(false);
    int N;
    std::cin >> N;
    llint ans = 0;
    while (N--) {
        int a;
        std::cin >> a;
        while (true) {
            if (a % 2 == 0) {
                a /= 2;
                ++ans;
            } else {
                break;
            }
        }
    }
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 256
s=str(input())
t=str(input())
ls=len(s)
lt=len(t)

dp=[[0 for i in range(lt+1)]for j in range(ls+1)]
for i in range(ls):
  for j in range(lt):
    if s[i]==t[j]:
      dp[i+1][j+1]=dp[i][j]+1
    else:
      dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j])

ans=""
x=ls
y=lt
while x>0 and y>0:
  if dp[x][y]==dp[x-1][y]:
    x-=1
  elif dp[x][y]==dp[x][y-1]:
    y-=1
  else:
    ans=s[x-1]+ans
    x-=1
    y-=1
print(ans)

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

using namespace std;

#define optimize() 		ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll				long long
#define vll				vector<long long>
#define pb				push_back
#define w(x)			int x; cin>>x; while(x--)
#define mp      		make_pair
#define F 				first
#define S 				second
#define mod     		1000000007
#define inf     		1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define endl	  		"\n"
#define sp 				" "
#define ca(x) 			"Case "<<x<<": "
#define all(x) 			x.begin(), x.end()
#define loop(i,a,n)		for (int i = a; i < (n); ++i)
#define rloop(i,a,n)	for (int i = n; i >= (a); --i)
#define in(n)			long long n ; cin >> n;
#define ins(s)			string s; cin >> s;
#define yes				cout << "Yes"<<"\n"
#define no				cout << "No"<<"\n"


int main()
{
	optimize();
	//............. S I D A T I V E  H I P N O T I X .............//

	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	ll x, y, z, zz;
	x = a * c, y = a * d, z = b * c, zz = b * d;
	cout << max(x, max(y, max(z, zz)));

	return 0;
}



Measured memory_bytes: 3656
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N,K;
	ll a[100001];
	ll asum[100001]={},psum[100001]={};
	scan(N>>K);
	rep(i,N){
		scan(a[i]);
		asum[i+1]=asum[i]+a[i];
		psum[i+1]=psum[i]+max(0LL,a[i]);
	}
	ll ans=0;
	rep(i,N-K+1){
		ll nini=psum[N]-(psum[i+K]-psum[i]);
		ans=max(ans,nini+max(0LL,asum[i+K]-asum[i]));
	}
	prin(ans);
	return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                   \
  ifstream in("atcoder-problems/arc063_a.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v) \
rep(l, v.size()) { cout << v[l] << " "; } \
cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18+100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  string S;
  cin >> S;
  int N = S.size();

  ll ans = 0;
  rep(i, N - 1) {
    if (S[i] != S[i + 1]) ans++;
  }

  cout << ans << endl;
}

Measured memory_bytes: 3732
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args)
	{
		Scanner s=new Scanner(System.in);
		
		int a=s.nextInt();
		int b=s.nextInt();
		int c=s.nextInt();
		
		int k=s.nextInt();
		
		int sum=0;
		
		if(k>=a)
		{
			sum=a;
			k=k-a;
			
			if(k>=b)
			{
				k=k-b;
				
				sum=sum-k;
				
				System.out.println(sum);
			}
			else
			{
				System.out.println(sum);
			}
		}
		else
		{
			System.out.println(k);
		}
		
	}
	
}

Measured memory_bytes: 35776
/**
*	created: 19.09.2020 22:04:08
**/
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
// #define endl '\n'
#define int long long
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define rrep(i,n) for (int i = (int)(n - 1); i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
using ll = long long;
using P = pair<int,int>;
const long double pi = acos(-1.0);
const int MAX = 1000010;
const int INF = 1ll << 60;
const int MOD = 1000000007;
// const int MOD = 998244353;
template<typename T> inline bool chmax(T &a, T b) {if (a < b) {a = b; return 1;} return 0;}
template<typename T> inline bool chmin(T &a, T b) {if (b < a) {a = b; return 1;} return 0;}
inline void print(P a) {cout << a.first << " " << a.second << endl;}
template<typename T> T pow(T a, ll n) {T r(1); while(n) {if (n & 1) r *= a; a *= a; n >>= 1;} return r;}
struct faster_io {faster_io() {cin.tie(0); ios_base::sync_with_stdio(false);}} faster_io_;

signed main() {
    int n, x, m; cin >> n >> x >> m;
    map<int,int> mp;
    vector<int> v;
    int a = x;
    int t;
    rep(i,m+1) {
        mp[a]++;
        if (mp[a] > 1) {
            t = a;
            break;
        }
        v.push_back(a);
        a = (a * a) % m;
    }
    int st;
    rep(i,v.size()) if (v[i] == t) st = i;
    int rsum = 0;
    rep2(i,st,v.size()) rsum += v[i];
    int fsum = 0;
    rep(i,st) fsum += v[i];
    if (n <= v.size()) {
        int ans = 0;
        rep(i,n) ans += v[i];
        cout << ans << endl;
    }
    else {
        int res = n - st;
        int tim = res / (v.size()-st);
        int lsum = 0;
        rep2(i,st,st + (res % (v.size()-st))) lsum += v[i];
        cout << fsum + rsum * tim + lsum << endl;
    }
    return 0;
}

Measured memory_bytes: 6708
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <string>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <map>
using namespace std;
#define ms(a, x) memset(a, x, sizeof(a))
#define fore(i, a, n) for (long long i = a; i < n; i++)
#define ford(i, a, n) for (long long i = n - 1; i >= a; i--)
#define si(a) scanf("%d", &a)
#define sl(a) scanf("%lld", &a)
#define sii(a, b) scanf("%d%d", &a, &b)
#define siii(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define sll(a, b) scanf("%lld%lld", &a, &b)
#define slll(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define debug(a) cout << a << endl
#define pr(a) printf("%d ", a)
#define endl '\n'
#define pi acos(-1.0)
#define tr t[root]
#define lson t[root << 1]
#define rson t[root << 1 | 1]
#define IO ios::sync_with_stdio(false), cin.tie(0)
#define ull unsigned long long
#define py puts("Yes")
#define pn puts("No")
#define pY puts("YES")
#define pN puts("NO")
#define re(i, a, b) for (int i = a; i <= b; ++i)
#define de(i, a, b) for (int i = a; i >= b; --i)
const double eps = 1e-8;
inline int sgn(const double &x) { return x < -eps ? -1 : x > eps; }
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int MAXN = 1e5 + 5;
template <class T>
inline void cmin(T &a, T b) { ((a > b) && (a = b)); }
template <class T>
inline void cmax(T &a, T b) { ((a < b) && (a = b)); }
string s;
int main()
{
  cin>>s;
  cout<<(s=="ABC"?"ARC":"ABC")<<endl;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  sort(a.rbegin(), a.rend());
  int k = (sum + 4 * m - 1) / (4 * m);
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] >= k) cnt++;
  }
  if (cnt >= m) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}

Measured memory_bytes: 3660
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int r, c;
    int[][] a;
    int i, j;

    r = sc.nextInt();
    c = sc.nextInt();
    a = new int[r + 1][c + 1];

    for(i = 0;i < r;i++){
      for(j = 0;j < c;j++){
        a[i][j] = sc.nextInt();
      }
    }

    for(i = 0;i < r;i++){
      for(j = 0;j < c;j++){
        a[i][c] += a[i][j];
        a[r][j] += a[i][j];
      }
      a[r][c] += a[i][c];
    }

    for(i = 0;i < r + 1;i++){
      for(j = 0;j < c;j++){
        System.out.print(a[i][j] + " ");
      }
      System.out.println(a[i][j]);
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

Measured memory_bytes: 39468
#include<bits/stdc++.h>
#define ll long long int
#define pragi(a,b) for(ll i = a;i<b;i++)
#define pragj(a,b) for(ll j = a;j<b;j++)
#define pragk(a,b) for(ll k = a;k>=b;k--)
#define all(v) (v.begin(),v.end())
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define MP make_pair
#define MT make_tuple
#define F first
#define S second
#define KAKA ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int mod = 1e9 + 7;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef long double ld;
typedef pair<int, int> pii;
//typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef pair<ll, ll> pll;

void Compute(ll a,ll b,ll k)
{
    KAKA
    ll na,nb;
    if(k <= a){ na = a - k ; nb = b;}
    else { na = 0;nb = b-k+a;if(nb < 0) nb = 0;}
    cout<<na<<" "<<nb<<"\n";
}
int main()
{
    KAKA
    ll a,b,k;
    cin>>a>>b>>k;
    Compute(a,b,k);
}

Measured memory_bytes: 256
//#include<iostream>
#include<vector>
#include<stack>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
  stack<int> S1;
  stack<pair<int, int>> S2;
  char ch;
  int sum = 0;
  for(int i=0; scanf("%c", &ch)!=EOF; i++)
  {
    if(ch == '\\') S1.push(i);
    else if(ch == '/' && S1.size() > 0)
    {
      int j =  S1.top();
      S1.pop();
      sum += i-j;
      int a = i - j;
      while(S2.size() > 0 && S2.top().first > j)//why while....
      {
        a += S2.top().second;
        S2.pop();
      }
      S2.push(make_pair(j, a));
    }
  }

  vector<int> ans;
  while(S2.size() > 0)
  {
    ans.push_back(S2.top().second);
    S2.pop();
  }
  reverse(ans.begin(), ans.end());
  printf("%d\n", sum);
  printf("%d", ans.size());
  for(int i=0; i<ans.size(); i++)
  {
    printf(" %d", ans[i]);
  }
  printf("\n");

  return 0;
}



Measured memory_bytes: 2804
#include<bits/stdc++.h>
using namespace std;
const int N=11,mo=998244353;
char s[N][N];
int inv[N],fac[N],f[N][N],g[N][N],w[N],v[N];
//f[i][j] indicate the number of ways that print a i*j rectangle
//g[i][j] indicate the number of ways that print a i*j L 
void init(){
	fac[0]=inv[0]=fac[1]=inv[1]=1;
	for(int i=2;i<=10;i++)fac[i]=fac[i-1]*i,inv[i]=1ll*(mo-mo/i)*inv[mo%i]%mo;
	for(int i=2;i<=10;i++)inv[i]=1ll*inv[i]*inv[i-1]%mo;
}
void add(int &x,int y){(x+=y)%=mo;}
int mul(int x){return x;}
template<class... T> int mul(int x,T... y){return 1ll*x*mul(y...)%mo;}
inline int C(int n,int m){return 1ll*fac[n]*inv[n-m]%mo*inv[m]%mo;}
int main(){
	init();
	int n,m,s1,s2;scanf("%d%d",&n,&m),s1=(1<<n),s2=(1<<m);
	for(int i=0;i<n;i++){
		scanf("%s",s[i]);
		for(int j=0;j<m;j++)if(s[i][j]=='#')w[i]|=(1<<j),v[j]|=(1<<i);
	}
	for(int i=0;i<=n;i++){
		for(int j=0;j<=m;j++){
			if(!i||!j){f[i][j]=1,g[i][j]=1<<(i+j);continue;}
			for(int k=1;k<=i;k++)add(f[i][j],mul(k&1?1:mo-1,C(i,k),1<<k,f[i-k][j])),
			add(g[i][j],mul(k&1?1:mo-1,C(i,k),1<<k,g[i-k][j]));
			for(int k=1;k<=j;k++)add(f[i][j],mul(k&1?1:mo-1,C(j,k),1<<k,f[i][j-k])),
			add(g[i][j],mul(k&1?1:mo-1,C(j,k),1<<k,g[i][j-k]));
			for(int k=1;k<=i;k++)for(int l=1;l<=j;l++){
				add(f[i][j],mul((k+l)&1?1:mo-1,C(i,k),C(j,l),2,f[i-k][j-l]));
				add(g[i][j],mul((k+l)&1?1:mo-1,C(i,k),C(j,l),2,g[i-k][j-l]));
			}
		}
	}
	int ans=0;
	for(int i=1;i<s1;i++){
		for(int j=1;j<s2;j++){
			bool fl=0;int a=0,b=0;
			for(int k=0;k<n;k++)if(i&(1<<k))a++,fl|=(w[k]&j)==j||((~w[k])&j)==j;
			for(int k=0;k<m;k++)if(j&(1<<k))b++,fl|=(v[k]&i)==i||((~v[k])&i)==i;
			if(!fl)add(ans,g[n-a][m-b]);
		}
	}
	printf("%d",(ans+f[n][m])%mo);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <limits.h>

using namespace std;

int main() {
	int n;

	cin >> n;
	int R[n];

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

	int minv = R[0];
	int maxv = R[1] - R[0];

	for (int j = 1; j < n; j++) {
		if (maxv < R[j] - minv)
			maxv = R[j] - minv;

		if (minv > R[j])
			minv = R[j];
	}

	cout << maxv << endl;
}



Measured memory_bytes: 3880
#include<bits/stdc++.h>
using namespace std;
char a[10001];
long long f[10001][101][2];
int main()
{
	int n,i,D,j,k;
	scanf("%s",a);
	scanf("%d",&D);
	f[0][0][1]=1;
	n=strlen(a);
	for(i=0;i<n;i++)
	{
		for(j=0;j<D;j++)
		{
			for(k=0;k<=9;k++)
			{
				f[i+1][(j+k)%D][0]=(f[i+1][(j+k)%D][0]+f[i][j][0])%1000000007;
			}
			for(k=0;k<=a[i]-'0';k++)
			{
				if(k==a[i]-'0')
					f[i+1][(j+k)%D][1]=(f[i+1][(j+k)%D][1]+f[i][j][1])%1000000007;
				else
					f[i+1][(j+k)%D][0]=(f[i+1][(j+k)%D][0]+f[i][j][1])%1000000007;
			}
		}
	}
	printf("%lld",((f[n][0][0]+f[n][0][1]-1)%1000000007+1000000007)%1000000007);
	return 0;
}

Measured memory_bytes: 16000
#include <iostream>

using namespace std;

const int DAYS_NUM[12] =
  {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

const string days[7] = {
  "Monday", "Tuesday", "Wednesday", "Thursday",
  "Friday", "Saturday", "Sunday"
};

int main() {
  int m, d;
  string day;
  while(1) {
    cin >> m >> d;
    if (m == 0) break;
    for (int i = 0; i < m - 1; i++)
      d += DAYS_NUM[i];
    d = (d + 2) % 7;
    cout << days[d] << endl;
  }
  return 0;
}

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

 int main () {
   string a;
   cin >> a;
  
   if (a == "SUN") {
     cout << 7 << endl;
   }
   else if (a == "MON") {
     cout << 6 << endl;
   }
   else if (a == "TUE") {
     cout << 5 << endl;
   }
   else if (a == "WED") {
     cout << 4 << endl;
   }
   else if (a == "THU") {
     cout << 3 << endl;
   }
   else if (a == "FRI") {
     cout << 2 << endl;
   }
   else {
     cout << 1 << endl;
   }
 }


Measured memory_bytes: 3632
#include <bits/stdc++.h>
 
using namespace std;
const int MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
const double PI = 4*atan(1);
typedef long long ll;
typedef pair<int,int> pii;
int n, m, a;
void solve() {
	cin >> n >> m;
	int sum = 0;
	for (int i = 0; i < m; i++) {
		cin >> a;
		sum += a;
	}
	cout << max(-1,n-sum) << endl;
}
int main() {
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	// int t;
	// cin >> t;
	// for (int i = 1; i <= t; i++) { 
		// cout << "Case #" << i << ": ";
		solve();
	// }
}

Measured memory_bytes: 3644
#include<stdio.h>
#include<math.h>
#define PI 3.141592653589793238
int main(){
	double a,b,C;
	scanf("%lf%lf%lf",&a,&b,&C);
	C=C/180*PI;
	printf("%f\n%f\n%f\n",a*b/2*sin(C),a+b+sqrt(a*a+b*b-2*a*b*cos(C)),b*sin(C));
}


Measured memory_bytes: 2132
using System;
using System.Collections.Generic;
using System.Linq;

class Solution
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var fours = a.Count(i => i % 4 == 0);
        var twos = a.Count(i => i % 4 != 0 && i % 2 == 0);
        var others = n - fours - twos;

        if (others > fours + 1)
        {
            Console.WriteLine("No");
            return;
        }

        if (fours + 1 == others && others > 0 && twos > 0)
        {
            Console.WriteLine("No");
            return;
        }

        Console.WriteLine("Yes");
    }
}

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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

string vow = "aeiou";

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

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

const ld pie = 3.14159265358979 ;
const ll mod = 1e9 + 7 ;

void solve ( int test_case )
{
    int n , q ;
    cin >> n >> q ;

    vi v ( n + 2 ) ;
    int Q = q ;

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

        v[r+1] -- ;
        v[l] ++ ;
    }

    v.pop_back() ;
    for ( int i=1 ; i <= n ; i ++ )
        v[i] += v[i-1] ;

    int ans = 0 ;
    for ( int i : v )
        ans += ( i == Q ) ;

    cout << ans ; line
}

int main()
{fast
    int t = 1;
    // cin >> t;

    for ( int i=0 ; i < t ; i++ ) solve(i);
    return 0;
}


Measured memory_bytes: 640
#include<iostream>

using namespace std;

void move2end(string &a,int pos){
    string s1;
    string s2;
    s1.assign(a, 0, pos);
    s2.assign(a, pos, a.length() - pos);
    a = s2 + s1;
}

string s;
int main(){
    while(true){
        cin >> s;
        if(s == "-") break;
        int n;
        cin >> n;
        for(int i = 1; i <= n; ++i){
            int pos;
            cin >> pos;
            move2end(s,pos);
        }
        cout << s << endl;
    }
    return 0;
}


Measured memory_bytes: 3184
N, Y = map(int, input().split())


def main():
    x, y, z = detect()
    print(x, y, z)


def detect():
    for x in range(N+1):
        for y in range(N+1 - x):
            z = N - x - y

            if x*10000 + y*5000 + z*1000 == Y:
                return x, y, z
    return -1, -1, -1


main()


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

using namespace std;

int main(){
  for(string A;cin>>A,A!="0";){
    string B,C;
    cin>>B>>C;
    int dp[51][2]={1};
    int len=A.size();
    for(int i=0;i<A.size();i++){
      for(int j=0;j<2;j++){
	int last=i==A.size()-1;
	for(int k=last;k<=9;k++){
	  if(A[len-1-i]!='?'&&A[len-1-i]!='0'+k)continue;
	  for(int l=last;l<=9;l++){
	    if(B[len-1-i]!='?'&&B[len-1-i]!='0'+l)continue;
	    for(int m=last;m<=9;m++){
	      if(C[len-1-i]!='?'&&C[len-1-i]!='0'+m)continue;
	      int s=k+l+j;
	      if(s%10!=m)continue;
	      dp[i+1][s/10]=(dp[i+1][s/10]+dp[i][j])%(1000000007);
	      
	    }
	  }
	}
      }
    }
    cout<<dp[A.size()][0]<<endl;
  }
}

Measured memory_bytes: 1188
#include <iostream>
#include <vector>
#include <cmath>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> a(n, 100010);
  rep(i, n-1){
    int b;
    cin >> b;
    a[i] = min(a[i], b);
    a[i+1] = min(a[i+1], b);
  }
  int ans = 0;
  rep(i, n) ans += a[i];
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
#include <math.h>
using namespace std;

typedef long long ll;

/*
const ll M = 1000000007;
vector<ll> fac(3001);
vector<ll> ifac(3001);
ll mpow(ll x, ll n){
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}
 
ll comb(ll a, ll b){
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0 || b < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % M;
    return tmp * fac[a] % M;
}
*/


ll lcm(ll a,ll b){
 
  ll r, x, tmp;
  x = a * b;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return x/b;
}

ll gcd(ll a ,ll b){
    if(a==0){return b;}
    else if(b==0){return a;}
    else{
    ll tmp,r;
    if(a<b){
        tmp = a;
        a = b;
        b = tmp;
    }
    
    r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
    }
}

bool sosu(ll p){
    bool ans = true;
    double psqrtd = pow(p, 0.5);
    ll psqrt = psqrtd;
    for(ll i = 2; i <= psqrt; i++){
        if(p%i==0)ans = false;
    }
    if(p==1)ans = false;
    return ans;
}

vector< bool > prime_table(ll n) {
  vector< bool > prime(n + 1, true);
  if(n >= 0) prime[0] = false;
  if(n >= 1) prime[1] = false;
  for(int i = 2; i * i <= n; i++) {
    if(!prime[i]) continue;
    for(int j = i + i; j <= n; j += i) {
      prime[j] = false;
    }
  }
  return prime;
}

int main(void){
    ll n;
    ll ans = 0;
    cin >> n;
    ll d[n];
    for(ll i = 0; i < n; i++)cin >> d[i];
    for(ll i = 0; i < n; i++)for(ll j = i+1; j < n; j++)ans+=d[i]*d[j];
    cout << ans << endl;
    return 0;
}


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

/* macro */
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define int long long
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))
#define isin(a, b, c) (b <= a && a <= c)
#define println cout << "\n";
#define sz(v) (int)v.size()
#define bin(x) static_cast<bitset<16> >(x)


/* alias */
template<class T> using vec = vector<T>;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef tuple<int, int, int> ti;
typedef map<int, int> mi;
typedef set<int> si;


/* constant */
const int inf = 1LL << 62;
const int mod = 1e9 + 7;
const int dx[8]={1,0,-1,0,-1,1,-1,1};
const int dy[8]={0,1,0,-1,-1,-1,1,1};
const string alphabet = "abcdefghijklmnopqrstuvwxyz";

/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T, class U, class V> void printx(tuple<T, U, V> t){cout << "{" << get<0>(t) << "," << get<1>(t) <<"," << get<2>(t) << "}" << endl;}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}
template<class T> void printans(vec<T> v){rep(i,0,sz(v)){cout << v[i] << (i == sz(v) - 1 ? "" : " ");}cout << endl;}


/* general_method */
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; }
template<class T>T cut(T &a, int l, int r){return T(a.begin()+l, a.begin()+r);}


/* math_method */
int ceil(int a, int b){return a / b + (a % b > 0);}


/* main */

int n;
vector<vector<int>> edges(10101);
vi c;
void in(){
    cin >> n;
    rep(i,0,n - 1){
        int f, t; cin >> f >> t;
        f--; t--;
        edges[f].push_back(t);
        edges[t].push_back(f);
    }

    rep(i,0,n) c.push_back(input());
    sort(all(c));
    reverse(all(c));
}

vi ans(10101);


int ind = 0;
vec<bool> visited(10101, false);
void dfs(int v){

    if(visited[v]) return;
    ans[v] = c[ind];
    ind++;
    visited[v] = true;
    rep(i,0,sz(edges[v])){
        int nxt = edges[v][i];
        if(not visited[nxt]) dfs(nxt);  
    }
}


void solve(){

    dfs(0);


    int sum = 0;
    rep(i,0,n){
        rep(j,0,sz(edges[i])){
            int nxt = edges[i][j];
            sum += min(ans[i], ans[nxt]);
        }
    }

    print(sum / 2);
    printans(cut(ans, 0, n));


}

signed main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    in();
    solve();
    
}

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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

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

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    int n;
    cin >> n;
    cout << "ABC";
    cout << n << endl;
}


Measured memory_bytes: 256
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int n, m;
//素因数分解o√n
vector<int> prime_factor(int n)
{
    vector<int> res;
    for (int i = 2; i * i <= n; i++)
    {
        if(n%i==0){
            res.push_back(i);
        }
        while (n % i == 0)
        {
            n /= i;
        }
    }
    if (n != 1)
        res.push_back(n);
    return res;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    vector<int> d=prime_factor(n);
    int m=d.size();
    ll ans=0;
    rep(i,(1<<m)){
        int count=__builtin_popcount(i);
        int l=1;
        rep(j,m){
            if((1<<j)&i){
                l*=d[j];
            }
        }
        if(l!=1){
            if(count%2)ans+=n/l;
            else ans-=n/l;
        }
    }
    cout<<n-ans<<"\n";
}



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

using namespace std;

int main()
{
    char s[10];
    scanf("%s", s);
    for(int i = 0; i <= 2; i ++)
        if(s[i] == s[i + 1]) return puts("Bad"), 0;
    puts("Good");
    return 0;
}


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

int main(){
	int n,m;
	cin >> n >> m;
	vector<int> k(n);
	vector<int> M(m);
	rep(i,n){
		cin >> k[i];
		rep(j,k[i]){
			int a;
			cin >> a;
			M[a-1]++;
		}
	}
	int res=0;
	rep(i,m){
		if(M[i] == n){
			res++;
		}
	}
	cout << res << endl;
	return 0;
}



Measured memory_bytes: 256
(defun solve (n k pos)
  (let ((ret 10000000000000000000000000000000000000000000000000))
    (loop for i below n
          do (let ((vec (make-array 0 :fill-pointer t :adjustable t)))
               (loop for j from i below n
                     for u = 0 for d = (- k 1)
                     do (progn (vector-push-extend (cdr (aref pos j)) vec)
                               (sort vec #'<))
                     do (loop while (< d (length vec))
                              if (>= d (- k 1))
                              do (setf ret (min ret (* (- (aref vec d) (aref vec u)) (- (car (aref pos j)) (car (aref pos i))))))
                              end
                              do (incf u)
                              do (incf d)))))
    ret))

(let* ((n (read))
       (k (read))
       (pos (make-array n :element-type 'cons)))
  (loop for i below n
        do (setf (aref pos i) (cons (read) (read))))
  (princ (solve n k (sort pos #'< :key #'car))))

Measured memory_bytes: 6504
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
//constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcountll(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;
//struct edge{lint to,num;};

vector<lint> G[60]; // MAX_V,隣接リスト
lint root;

lint parent[7][60]; // logMAX_V,MAX_V
lint depth[60];

void LCAdfs(lint v,lint p,lint d){
    parent[0][v]=p;
    depth[v]=d;
    rep(i,G[v].size()) if(G[v][i]!=p) LCAdfs(G[v][i],v,d+1);
}

void LCAinit(lint V){
    LCAdfs(root,-1,0);
    for(int k=0;k+1<7;k++){
        for(int v=0;v<V;v++){
            if(parent[k][v]<0) parent[k+1][v]=-1;
            else parent[k+1][v]=parent[k][parent[k][v]];
        }
    }
}

lint LCA(lint u,lint v){
    if(depth[u]>depth[v]) swap(u,v);
    for(int k=0;k<7;k++){
        if((depth[v]-depth[u])>>k&1) v=parent[k][v];
    }
    if(u==v) return u;
    for(int k=7-1;k>=0;k--){
        if(parent[k][u]!=parent[k][v]){
            u=parent[k][u];
            v=parent[k][v];
        }
    }
    return parent[0][u];
}

vector<int> path(int s,int t){
    int lca=LCA(s,t);
    vector<int> ps,pt;
    int now=s;
    while(true){
        if(now==lca) break;
        ps.push_back(now);
        now=parent[0][now];
    }
    now=t;
    while(true){
        pt.push_back(now);
        if(now==lca) break;
        now=parent[0][now];
    }
    reverse(pt.begin(),pt.end());
    ps.insert(ps.end(),pt.begin(),pt.end());
    return ps;
}

int edge[2500];

int main(void){
    int N;
    cin >> N;
    rep(i,N-1){
        int u,v;
        cin >> u >> v;
        u--,v--;
        G[u].push_back(v);
        G[v].push_back(u);
        edge[u*50+v]=i;
        edge[v*50+u]=i;
    }
    LCAinit(N);
    lint ans=0;
    int M;
    cin >> M;
    int u[M],v[M];
    rep(i,M) cin >> u[i] >> v[i];
    rep(i,M) u[i]--,v[i]--;
    lint edges[M]={};
    rep(i,M){
        vector<int> way=path(u[i],v[i]);
        rep(j,way.size()-1) edges[i]+=1LL<<edge[way[j]*50+way[j+1]];
    }
    rep(i,(1<<M)){
        int pick=Flagcount(i);
        lint sum=0;
        rep(j,M) if(i&(1<<j)) sum|=edges[j];
        int vtx=Flagcount(sum);
        lint cnt=(1LL<<(N-1-vtx));
        if(pick%2) ans-=cnt;
        else ans+=cnt;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3676
S = input()
N = len(S)

S2 = S[:int((N-1)/2)]
S3 = S[int((N+3)/2)-1:N+1]
# print(S2)
# print(S3)
if S == S[::-1] and S2 == S2[::-1] and S3 == S3[::-1]:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include <stdio.h>
#define MAX 100000

struct node{
  //int p, d, c[10], t, k; //????????????,???????????±???,???????????????,type,?¬???°
  int p, l, r;
};
struct node T[MAX];
int n, D[MAX];

void print(int u){
  int i = 0, c;
  printf("node %d: parent = %d, depth = %d, ", u, T[u].p, D[u]);

  if(T[u].p == -1) printf("root, [");
  else if(T[u].l == -1) printf("leaf, [");
  else printf("internal node, [");

  for(i = 0, c = T[u].l; c != -1; i++, c = T[c].r){
    if(i) printf(", ");
    printf("%d", c);
  }
  printf("]\n");
}

int rec(int u, int p){
  D[u] = p;
  if(T[u].r != -1) rec(T[u].r, p);
  if(T[u].l != -1) rec(T[u].l, p + 1);
}

int main()
{
  /*  node T[MAX];
  int i = 0, j, t = 0, l;
  int n, id; //?????°,???????????????
  char type[4][] = {root???internal node???leaf}
  */
  int i, j, k, id, c, l, r;

  scanf("%d", &n);
  for(i = 0; i < n; i++) T[i].p = T[i].l = T[i].r = -1;
  for(i = 0; i < n; i++){
    scanf("%d %d", &id, &k);
    for(j = 0; j < k; j++){
      scanf("%d", &c);
      if(j == 0) T[id].l = c;
      else T[l].r = c;
      l = c;
      T[c].p = id;
    }
  }
  for(i = 0; i < n; i++){
    if(T[i].p == -1) r = i;
  }
  rec(r,0);
  for(i = 0; i < n; i++) print(i);

  return 0;
}

Measured memory_bytes: 5296
import java.io.PrintWriter

val out = PrintWriter(System.out)

fun main(args: Array<String>) {
    val (n, x) = readLine()!!.split(' ').map(String::toInt)
    if (x == 1 || x == 2 * n - 1) {
        println("No")
        return
    }
    if (n == 2) {
        println("Yes")
        println("1 2 3")
        return
    }
    val ans = IntArray(2 * n - 1)
    val range : IntRange
    if (x == 2 * n - 2) {
        ans[n - 2] = x - 1
        ans[n - 1] = x + 1
        ans[n] = x
        ans[n + 1] = x - 2
        range = IntRange(x - 2, x + 1)
    } else {
        ans[n - 2] = x + 1
        ans[n - 1] = x - 1
        ans[n] = x
        ans[n + 1] = x + 2
        range = IntRange(x - 1, x + 2)
    }
    var j = 1
    for (i in ans.indices) {
        if (ans[i] == 0) {
            while (j in range) j++
            ans[i] = j++
        }
    }
    out.println("Yes")
    ans.forEach { out.println(it) }
    out.close()
}


Measured memory_bytes: 28524
import sys
input = sys.stdin.readline
from collections import *

N = int(input())
A = list(map(int, input().split()))
ans = 0
cnt = defaultdict(int)

for i in range(N):
    k = i-A[i]
    ans += cnt[k]
    cnt[A[i]+i] += 1

print(ans)

Measured memory_bytes: 131372