akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
long long n,s[51][51],a[51][51],t[51][51],tmp[51][51];
void equal(long long d[][51],long long b[][51])
{
	long long i,j;
	for(i=1;i<=n;i++)
		for(j=1;j<=n;j++)
			d[i][j]=b[i][j];
}
void floyd(long long d[][51],long long b[][51],long long c[][51])
{
	long long i,j,k;
	for(k=1;k<=n;k++)
		for(i=1;i<=n;i++)
			for(j=1;j<=n;j++)
				if(b[i][k]&&c[k][j])
					d[i][j]=(d[i][j]+b[i][k]*c[k][j]%1000000007)%1000000007;
}
int main()
{
	long long ans=0,i,j,k,m,flag=0;
	scanf("%lld%lld",&n,&k);
	for(i=1;i<=n;i++)
		for(j=1;j<=n;j++)
			scanf("%lld",&a[i][j]);
	m=k;
	i=0;
	while(m)
	{
		if(m%2==1)
		{
			if(flag==0)
			{
				equal(s,a);
				flag=1;
			}
			else
			{
				memset(tmp,0,sizeof(tmp));
				floyd(tmp,s,a);
				equal(s,tmp);
			}
		}
		memset(t,0,sizeof(t));
		floyd(t,a,a);
		equal(a,t);
		m/=2;
	}
	for(i=1;i<=n;i++)
		for(j=1;j<=n;j++)
			if(s[i][j])
				ans=(ans+s[i][j])%1000000007;
	printf("%lld",ans%1000000007);
	return 0;
}

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


using namespace std;
long long l,m,n,tmp;
float f,g,h;
vector<int> vi;
vector<int> primes;



int main(int argc, char const *argv[])
{

  cin >> n;


  // float f_sup;
  primes.push_back(2);
  for(int i = 3; i < 55556;i+=2){
    // f_sup = sqrt(i)   ;
    for(auto factor = primes.begin(); factor !=primes.end();++factor){
      if((i % *factor) == 0){
        break;
      }else if(/* *factor > f_sup */  *factor * *factor > i|| factor == primes.end() ){
        primes.push_back(i);
        break;
      }
    }
  }
  int jj = 0;
  for(auto itr = primes.begin(); itr != primes.end();itr++){
    if((*itr%55)%5 == 1){
      // printf("%d",*itr);
      cout << *itr << " ";
      jj++;
    }
    if(jj == n)break;
  }
  printf("\n");
    // printf("%d\n",jj);



  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
#include<unordered_map>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define sort(s) sort(s.begin(),s.end())
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind
#define rt (a); return (a); 
#define Pint pair<int,int>
#define Pll pair<ll,ll>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 1000000000;
constexpr auto mod = 1000000007;
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0)return a;
	return gcd(b, a % b);
}

hei(ll) seg;
void update(int k,ll x) {
	seg[k] = x;
	while (k > 1) {
		k -= 1;
		k /= 2;
		seg[k] = gcd(seg[k * 2 + 1], seg[k * 2 + 2]);
   }
}
ll query(int a, int b, int k, int l, int r) {
	if (b <= l || r <= a)return 0;
	if (a <= l && b >= r)return seg[k];
	ll v1 = query(a, b, k * 2 + 1, l, (l + r) / 2);
	ll v2 = query(a, b, k * 2 + 2, (l + r) / 2, r);
	return gcd(v1, v2);
}
int main() {
	int n;
	cin >> n;
	int x = 1;
	while (x < n)x *= 2;
	seg.resize(x*2-1);
	rep(i, 0, n) {
		ll a;
		cin >> a;
		update(x - 1 + i, a);
	}
	ll ans = 0;
	rep(i, 0, n) {
		if (i == 0) {
			ans = max(ans, query(1, n, 0, 0, x));
		}
		else if (i == n - 1) {
			ans = max(ans, query(0, n - 1, 0, 0, x));
		}
		else {
			ll a = query(0, i, 0, 0, x);
			ll b = query(i + 1, n, 0, 0, x);
			ans = max(ans, gcd(a, b));
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 2304
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

int main() {
	string S; cin >> S;
	if (S == "ABC") cout << "ARC" << endl;
	else cout << "ABC" << endl;
	return 0;
}

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


ll num[sz];

int main()
{

    ll n,k,i,j,a,b,x,c,d;

    cin>>n>>k;

    for(i=1;i<=n;i++)
    {
        cin>>num[i];
    }

    sort(num+1,num+n+1);

    c=0;

    for(i=n;i>=1;i--)
    {
       if(k>0)k--;
       else
       {
           c+=num[i];
       }
    }

    cout<<c<<endl;

    return 0;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define test long long int t; cin>>t; while(t-->0)
#define fIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define loop(n) for(long long int i=0;i<n;i++)
using namespace std;
int main()
{
    fIO
    int r;
    cin>>r;
    float pi=3.1415926;
    cout<<fixed<<setprecision(7)<<2*pi*r;
    return 0;
}
    

Measured memory_bytes: 3804
n, m = map(int, input().split())
H = list(map(int, input().split()))
_H = H.copy()
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    if H[a]==H[b]:
        _H[a] = -1
        _H[b] = -1
    elif H[a] < H[b]:
        _H[a] = -1
    else:
        _H[b] = -1

print(len(_H)-_H.count(-1))

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

int N,M,K;
int a[300];
int b[300][300];
int cnt[300];

int s[200000],t[200000];

int A[300];
int B[300][300];
bool check(int x){
  for(int i=0;i<M;i++){
    A[i]=a[i];
  }
  for(int i=0;i<N;i++){
    cnt[i]=0;
    for(int j=0;j<M;j++){
      B[i][j]=b[i][j];
      cnt[i]+=b[i][j];
    }
  }
  
  for(int i=0;i<x;i++){
    int p=s[i],q=t[i];
    A[q]--;
    if(A[q]<0)return false;
    
    B[p][q]--;
    cnt[p]--;
    if(cnt[p]==0){
      for(int j=0;j<M;j++)
        A[j]+=b[p][j];
    }
  }
  
  bool update=true;
  while(update){
    update=false;
    for(int i=0;i<N;i++){
      if(cnt[i]==0)continue;
      bool flg=true;
      for(int j=0;j<M;j++)
        if(A[j]<B[i][j])flg=false;
      if(!flg)continue;
      
      cnt[i]=0;
      for(int j=0;j<M;j++)
        A[j]+=(b[i][j]-B[i][j]);
      update=true;

    }
  }
  
  for(int i=0;i<N;i++){
    if(cnt[i]>0)return false;
    assert(cnt[i]==0);
  }
  return true;
}

int main(){
  scanf("%d %d %d",&N,&M,&K);
  for(int i=0;i<M;i++)scanf("%d",&a[i]);
  for(int i=0;i<N;i++)
    for(int j=0;j<M;j++)
      scanf("%d",&b[i][j]);

  for(int i=0;i<K;i++){
    scanf("%d %d",&s[i],&t[i]);
    s[i]--;
    t[i]--;
  }
  
  int left=0,right=K,mid;
  while(left<right){
    mid=(left+right)/2;
    if(check(mid))left=mid+1;
    else right=mid;
  }
  
  if(check(K))left=-1;
  printf("%d\n",left);
  return 0;
}

Measured memory_bytes: 5400
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		String c = sc.next();
		
		char d = a.charAt(a.length() -1 );
		char e = b.charAt(0);
		char f = b.charAt(b.length() -1);
		char g = c.charAt(0);
		if (d == e && f == g) {
			System.out.println("YES");		
		} else {
			System.out.println("NO");
		}
		}
	}

Measured memory_bytes: 23764
#include <iostream>

using namespace std;

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

    int sum = 0, max = 0;
    for (int i = 0; i < n; i++) {
        int p;
        cin >> p;

        if (max < p) {
            sum += max;
            max = p;
        } else {
            sum += p;
        }
    }

    sum += max / 2;
    cout << sum << endl;
}


Measured memory_bytes: 256
#include <string>
#include <cctype>
#include <iostream>
typedef std::string::iterator State;
using namespace std;

 
int number(State &begin);
int factor(State &begin);
int expression(State &begin);

int main(void){
  int N;
  std::cin >> N;

  while(N--){
    std::string s;
    std::cin>>s;
    State begin = s.begin();
    int ans = expression(begin);
    std::cout << ans << std::endl;
  }
  return 0;
}
 
int number(State &begin){
  int ret = 0;
 
  while(isdigit(*begin)){
    ret *= 10;
    ret += *begin - '0';
    begin++;
  }
 
  return ret;
}
 
int factor(State &begin){
  if(*begin == '('){
    begin++;
    int ret = expression(begin);
    begin++;
    return ret;
  }else{
    return number(begin);
  }
}
 

 
int expression(State &begin){
  int num = factor(begin);
  int sum = 0;
  
  for(;;){
    char ch = *begin;
    begin++;
    if(ch == '+'){
      sum += num;
      num = factor(begin);
    } else if(ch == '-'){
      sum += num;
      num = -factor(begin);
    }else if(ch == '*'){
      num *= factor(begin);
    }else if(ch == '/'){
      num /= factor(begin);
    }else{
      begin--;
      break;
    }
  }
  return sum+num;
}

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

int main() {
  LL n, k;
  cin >> n >> k;

  LL ans, x, y;
  if (k % 2 == 1) {
    x = n / k;
    ans = x * x * x;
  } else {
    x = n / k;
    y = (n + k / 2) / k;
    ans = x * x * x + y * y * y;
  }

  cout << ans << endl;
}


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


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;

int main()
{ios_base::sync_with_stdio(false);
string s,t,ans;
cin>>s>>t;

int n=s.length(),m=t.length();

if(m>n)
{
	ol("UNRESTORABLE");
	return 0;
}

rep(i,0,n-1)
{
	string kk="";
	int j=i+m-1;
	if(j>n-1)break;
	kk=s;
	rep(ii,0,i-1)
	{
		if(kk[ii]=='?')kk[ii]='a';
	}
	rep(ii,j+1,n-1)
	{
		if(kk[ii]=='?')kk[ii]='a';
	}
	int f=1;
	rep(ii,i,j)
	{
		if(kk[ii]=='?')kk[ii]=t[ii-i];
		else if(kk[ii]!=t[ii-i])f=0;
	}
	if(f)
	{
		if(ans=="")ans=kk;
		else ans=min(ans,kk);
	}
}

if(ans=="")
{
	ol("UNRESTORABLE");
	return 0;
}
else
{
	ol(ans);
}

return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdlib>
#define N 200005
#define lowbit(o) o&(-o)
using namespace std;
int i,j,l,s,n,m,R[N],L[N],st[N],ans,mx[N],top;
int a[N],b[N];
char c[N];
inline bool cmp(int x,int y) {
	return R[x]<R[y];
}
int main() {
	scanf("%s",c+1);
	n=strlen(c+1);
	for (i=1;i<=n;i++) a[i]=c[i]-48,L[i]=R[i]=100000000;
	scanf("%s",c+1);
	for (i=1;i<=n;i++) b[i]=c[i]-48;
	for (i=1;i<=n;i++) for (j=1;j<=n;j++) if (b[j]) L[i]=min(L[i],(i-j+n)%n),R[i]=min(R[i],(j-i+n)%n);
	ans=100000000;
	for (i=1;i<=n;i++) {
		top=0; int now=i;
		for (j=1;j<=n;j++) {
			if (a[now]!=b[j]) st[++top]=now;
			now%=n; now++;
		}//printf("%d\n\n",j);
		sort(st+1,st+1+top,cmp);
		mx[top+1]=0;
		for (j=top;j>=0;j--) mx[j]=max(mx[j+1],L[st[j]]);
		
		for (j=0;j<=top;j++) {
			//workL:
			ans=min(ans,(R[st[j]]+max((i-(n+1)+n)%n,mx[j+1]))*2-(i-(n+1)+n)%n+top);
			//workR:
			ans=min(ans,(mx[j+1]+max(((n+1)-i+n)%n,R[st[j]]))*2-((n+1)-i+n)%n+top);
		}
	}
	if (ans>=100000000) ans=-1;
	printf("%d\n",ans);
}

Measured memory_bytes: 2304
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

int main(){
    int A, B, N = 1000;
    cin >> A >> B;
    for(int i = 1; i <= N; i ++) {
        if ((int)(i * 0.08) == A && (int)(i * 0.1) == B){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 764
#include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void) {
  int i,j,k;
  int N,K,d;
  int a;
  int ii[101]={0};
  long cnt = 0;
  scanf("%d %d", &N, &K);
  for (j = 0; j < K;j++) {
    scanf("%d", &d);
    for (i = 0; i < d; i++) {
      scanf("%d", &a);
      ii[a] = 1;
    }
  }
  for (i = 0; i <= 100;i++){
    if(ii[i]==1){
      cnt++;
    }
  }
      printf("%ld\n",N-cnt);
  return 0;
}


Measured memory_bytes: 2152
import heapq

X,Y,Z,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))

AB=[]
for i in A:
  for j in B:
    heapq.heappush(AB,-i-j)
#print(AB)

ABC=[]
for i in range(min(K,X*Y)):
  temp=heapq.heappop(AB)
  for j in C:
    heapq.heappush(ABC,temp-j)

for i in range(min(K,X*Y*Z)):
  print(-heapq.heappop(ABC))
    

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

typedef long long ll;

#define int ll
#define all(v) v.begin(), v.end()
#define reps(__i, a, b) for (int __i = a; i < b; i++)
#define rep(__i, n) reps(__i, 0, n)

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

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

    int l = 0, r = 0;
    for (int i = 0; i < s.length(); i++)
    {
        if (s[i] == '(')
            r++;
        else if (s[i] == ')')
        {
            if (r > 0)
            {
                // OK.
                r--;
            }
            else
            {
                s = "(" + s;
                i++;
            }
        }
    }
    for (int i = s.length() - 1; i >= 0; i--)
    {
        if (s[i] == ')')
            l++;
        else
        {
            if (l > 0)
            {
                // OK.
                l--;
            }
            else
            {
                s = s + ")";
            }
        }
    }
    cout << s << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int a[n];
    for(int i = 0;i < n;i++)
    {
        cin >> a[i];
    }
    sort(a,a + n);
    cout << a[n - 1] - a[0];
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,-1,0,1},dy={1,0,-1,0};



int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int k,t;cin >> k >> t;
	vector<pii> a(t);
	rep(i,t){
		cin >> a.at(i).first;
		a.at(i).second=i;
	}
	if(t==1){
		cout << k-1 << endl;
		return 0;
	}
	int ans=0,pre=-1;
	rep(i,k){
		sort(a.rbegin(),a.rend());
		if(a.at(0).second==pre){
			if(a.at(1).first>0){
				a.at(1).first--;
				pre=a.at(1).second;
			}
			else{
				ans++;
				a.at(0).first--;
				pre=a.at(0).second;
			}
		}
		else{
			a.at(0).first--;
			pre=a.at(0).second;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
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; }
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b / gcd(a,b);}

int main() {
    int a,b;
    cin >> a >> b;
    cout << a*b - (a+b-1)<< "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
int main()
{
	SPEED
	string s;
	cin >> s;
	if (s=="Sunny")
	{
		cout << "Cloudy";
	}
	else if (s=="Cloudy")
	{
		cout << "Rainy";
	}
	else if (s=="Rainy")
	{
		cout << "Sunny";
	}
	return 0;
}

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

int main(){
  int X = 0;
  int A = 0;
  int B = 0;
  int C = 0;
  int count = 0;
  cin >> A >> B >> C >> X;
  for(int a = 0; a <= A; a++){
  	for(int b = 0; b <= B; b++){
      for(int c = 0; c <= C; c++){
        if(500 * a + 100 * b + 50 * c == X) count++;
      }
    }
  }
  cout << count;
  return 0;
}

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

#define Online 1
// #define multitest 1
// #define Debug
typedef long long ll;
typedef long double ld;
#define f first
#define s second
#define pb push_back
#define mp make_pair
const long long mod = 1000000007;
const long long High = 1e16;
void ControlIO();
void TimerStart();
void TimerStop();
#ifdef Debug
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void ZZ(const char *name, Arg1 &&arg1)
{
	std::cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char *names, Arg1 &&arg1, Args &&... args)
{
	const char *comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}
#else
#define db(...)
#endif

typedef pair<int, int> pii;

void solve()
{
	vector<vector<bool>> G_Comp;
	int n;
	cin >> n;
	G_Comp.resize(n + 1, vector<bool>(n + 1));
	if (n & 1)
	{
		for (int i = 1; i <= n; ++i)
		{
			G_Comp[i][n - i] = true;
			G_Comp[n - i][i] = true;
		}
	}
	else
	{
		for (int i = 1; i <= n; ++i)
		{
			G_Comp[i][n - i + 1] = true;
			G_Comp[n - i + 1][i] = true;
		}
	}
	vector<pii> Ans;
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j)
		{
			if (i == j)
				continue;
			if (G_Comp[i][j]==false)
			{
				G_Comp[i][j] = G_Comp[j][i] = true;
				Ans.pb(mp(i, j));
			}
		}
	cout << Ans.size() << '\n';
	for (auto x : Ans)
		cout << x.f << ' ' << x.s << '\n';
}

main()
{
	ControlIO();
	int t = 1;
#ifdef multitest
	cin >> t;
	// cout << t << '\n';
#endif
	TimerStart();
	while (t--)
		solve();
	TimerStop();
	return 0;
}

void ControlIO()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#ifndef Online
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

auto TimeStart = chrono::steady_clock::now();
auto TimeEnd = chrono::steady_clock::now();

void TimerStart()
{
#ifndef Online
	TimeStart = chrono::steady_clock::now();
#endif
}

void TimerStop()
{
#ifndef Online
	TimeEnd = chrono::steady_clock::now();
	auto ElapsedTime = TimeEnd - TimeStart;
	cout << "\n\nTime elapsed: " << chrono::duration<double>(ElapsedTime).count() << " seconds.\n";
#endif
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<pair<long long, long long>> work(N);
    long long a, b, sum = 0;
    for(int i=0; i<N; i++){
        cin >> a >> b;
        work[i] = make_pair(b, a);
    }

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

    for(int i=0; i<N; i++){
        sum += work[i].second;
        if(sum > work[i].first){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3328
#include<stdio.h>

int main()
{
  char str[100];
  int K;
  int n=0;
  int i, flag=0;

  
  scanf("%d",&K);
  scanf("%s",str);

  while(str[n] != '\0'){
    n++;
  }
  
  if(n>K)
  {
    flag = 1;
    n=K;
  }
  
  for(i=0; i<n; i++)
  {
    printf("%c",str[i]);
  }
  if(flag==1)
  {
    puts("...");
  }
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int gcd(int a, int b) {  
  return b != 0 ? gcd(b, a % b) : a;
}//MAX
int lcm(int a, int b) { 
   return a * b / gcd(a, b);
   }
//MIN
 main() {
int n;
cin >> n;
vector<int>a(n);
for(int i=0;i<n;i++){
  cin >> a.at(i);
}
sort(a.begin(),a.end());
int ans = 0;
int che = 1;
for(int i=1;i<n;i++){
  if(a.at(i-1)!=a.at(i)){
    if(che%2==1){
      ans++;
    }
    che = 1;
  }
  else che++;
}
if(che%2==1)ans++;
cout << ans << endl;
 }
 


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define mp	    make_pair
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define MOD        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define rep(i,a,b)  for(int i=a;i<b;i++)
ll mult(ll a,ll b, ll p=MOD){return ((a%p)*(b%p))%p;}
ll multbig(ll a,ll b,ll mod){
    if(a==0 or b==0) return 0;
    if(a==1 or b==1) return (a*b)%mod;
    ll cur=multbig(a,b/2,mod);
    cur=(2*cur)%mod;
    if(b%2) cur=(cur+a)%mod;
    return cur;
}
ll add(ll a, ll b, ll p=MOD){return (a%p + b%p)%p;}
ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1LL) {if (k & 1LL) r = mult(r,n,p); n = mult(n,n,p);} return r;}
ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}
ll inv_euclid(ll a, ll m = MOD){ll m0 = m;ll y = 0, x = 1;if (m == 1)return 0;while (a > 1){ll q = a / m;ll t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}


void solve(){
	int n;
	cin>>n;
	if(n%2)cout<<(n/2+1)*(n/2)<<endl;
	else cout<<n/2 * n/2<<endl;
	
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    t =1;
//     cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
import sys
import copy
from io import StringIO
import unittest
from collections import deque

# 参考：https://atcoder.jp/contests/abc168/submissions/13401646

def resolve():
    n, m = map(int, input().split())
    ms = [list(map(int, input().split())) for i in range(m)]

    # 各部屋のつながりを整理整頓する(添え字0は使わないので、+1して一つ多い配列を作成)
    roots = [[] for i in range(n + 1)]
    for i in ms:
        roots[i[0]].append(i[1])
        roots[i[1]].append(i[0])

    # 各部屋の深さを保持する配列を作成(配列は0始まりだが、番号は1始まりなので+1(添え字0は使用しない想定))
    deeps = [99999 for i in range(n + 1)]
    aaa = [False for i in range(n + 1)]

    best_signs = [0 for i in range(n+1)]

    # 調べ終えた道を格納するタプル
    # searched = []

    # 初期値を代入
    que = deque()
    que.append(1)  # スタート地点
    deeps[1] = 0  # スタート地点の深さは0

    # BFS開始
    while not len(que) is 0:

        now = que.popleft()

        # 無限ループ防止のため調査済みフラグを立てる
        # searched.append(now)

        # 最適解を代入し続けて、適切な深さを求める
        for target in roots[now]:
            # 調査済みの道には何もしない。
            if aaa[target] is True:
                continue

            # 新しい道の場合。最適解を取得+キュー追加
            deeps[target] = deeps[now] + 1
            que.append(target)
            aaa[target] = True
            # 最適な道しるべを設定
            best_signs[target] = now

    # 不要な添え字を削除(0番目=未使用なので不要 1番目=出力しないので不要)
    # del best_signs[0:2]

    # ans = "Yes"
    print("Yes")
    for i in range(2, len(best_signs)):
        # ans = ans + "\n" + str(best_signs[i])
        print(best_signs[i])

    # print(ans)


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """4 4
1 2
2 3
3 4
4 2"""
        output = """Yes
1
2
2"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """6 9
3 4
6 1
2 4
5 3
4 6
1 5
6 2
4 5
5 6"""
        output = """Yes
6
5
5
1
1"""
        self.assertIO(input, output)


if __name__ == "__main__":
    # unittest.main()
    resolve()


Measured memory_bytes: 144740
#B問題
import bisect

N = int(input())
S = list(str(input()))
mod = 998244353
N_factorial = 1
for i in range(N):
    N_factorial*=(i+1)
    N_factorial%=mod

r,g,b = [],[],[]
for i,s in enumerate(S):
    if s == "R":
        r.append(i)
    if s == "G":
        g.append(i)
    if s == "B":
        b.append(i)
        
A,B,C = [],[],[]
for i in range(N):
    rgb = [r[i],g[i],b[i]]
    rgb.sort()
    A.append(rgb[0])
    B.append(rgb[1])
    C.append(rgb[2])

ans = N_factorial
for i,B_ind in enumerate(B):
    x = bisect.bisect_left(A,B_ind)-i
    y = i+1-bisect.bisect_right(C,B_ind)
    ans*=(x*y)
    ans%=mod

print(ans)


Measured memory_bytes: 20784
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	string s;cin>>s;
	bool flag1 = false;
	for(int i = 0; i < s.size(); i++) {
		if(s[i] == 'C'){
			for(int j = i + 1; j < s.size(); j++) {
				if (s[j] == 'F'){
					flag1 = true;
					break;
				}
			}
		}
	}
	if (flag1){
		cout << "Yes" << endl;		
	}
	else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int a,b;
  cin >> a >> b;
  int ans = 0;
  for(int x=a;x<=b;++x){
    if(x/10000==x%10 && (x/1000)%10==(x/10)%10) ++ans;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
alphabetlist=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
alpha={moji:alphabetlist.index(moji) for moji in alphabetlist}

s=input()
N=len(s)
data=[0]
for i in range(N):
    data.append(2**alpha[s[i]])

for i in range(1,N+1):
    data[i]^=data[i-1]

que={val:2*N for val in data}

dp=[2*N]*(N+1)
dp[0]=0
que[0]=0
S=set([2**i for i in range(26)])
S.add(0)
for i in range(1,N+1):
    for j in S:
        k=data[i]^j
        if k in que:
            dp[i]=min(dp[i],que[k]+1)
    que[data[i]]=min(que[data[i]],dp[i])

print(dp[-1])


Measured memory_bytes: 69108
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
using ll = long long;
int main(){
  string a,b;
  cin >> a>>b;
  int cnt=0;
  rep(i,3)if(a[i] == b[i])cnt++;
  cout << cnt <<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()

#define pb push_back
#define mp make_pair

#define F first
#define S second

using ll = long long;
using namespace std;

void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }

const int mod = 1000000007;
const int INF = 1e+9;

int main() {
    int n; cin >> n;
    vector<int> v(n);
    vector<int> odd(100010, 0), even(100010, 0);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    for (int i = 0; i < n; i++) {
        if (i % 2 != 0) odd[v[i]]++;
        else even[v[i]]++;
    }

    int odd_mode = 0, even_mode = 0, odd_mode2 = 0, even_mode2 = 0;
    int o;
    int e;
    for (int i = 0; i < n; i++) {
        cerr << odd[v[i]] << endl;
        if (odd[v[i]] > odd_mode && i % 2 != 0) {
            o = v[i];
            odd_mode = odd[v[i]];
        } else if (even[v[i]] > even_mode && i % 2 == 0) {
            e = v[i];
            even_mode = even[v[i]];
        }
    }
    sort(odd.begin(), odd.end());
    sort(even.begin(), even.end());
    odd_mode2 = odd[100008];
    even_mode2 = even[100008];

    if (o != e) cout << n - odd_mode - even_mode << endl;
    else {
        cout << min(n - odd_mode - even_mode2, n - odd_mode2 - even_mode);
    }
}


Measured memory_bytes: 1536
import java.util.*;

 
class Main {
 
    private static Scanner sc = new Scanner(System.in);

        public static void main(String[] args) {
            String s = sc.next();
            char s1='1';
            char s0='0';
            char[] si  = s.toCharArray();
            int ans1 =0;
            int ans2 = 0;
            if(si.length==0){
                System.out.println(0);
                return;
            }
                char now=s0;
                for(char curr:si){
                    if(curr==now){
                        if(now==s0){
                            now = s1;
                        }else{
                            now = s0;
                        }
                    }else{
                        ans1++;
                        if(now==s0){
                            now = s1;
                        }else{
                            now = s0;
                        }
                    }
                }
                now=s1;
                for(char curr:si){
                    if(curr==now){
                        if(now==s0){
                            now = s1;
                        }else{
                            now = s0;
                        }
                    }else{
                        ans2++;
                        if(now==s0){
                            now = s1;
                        }else{
                            now = s0;
                        }
                    }
                }
            if(ans1>ans2){
                System.out.println(ans2);
            }else{
                System.out.println(ans1);
            }
    }
}

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

typedef long long ll;
typedef long double ld;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vstr;

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define asd cout << "ok" << endl;

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define trav(it, m) for(auto it = m.begin(); it it!= m.end(); it++)

const char nl = '\n';
const int MOD = 1e9 +7;
const ll INF = 1e19;
const ld PI = acos((ld)-1);
const int MX = 2e5 + 5;

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0);
  int n; cin >> n;
  int ans = 0;
  vi v(n), c(n);
  for(int i = 0; i < n; i++)
    cin >> v[i];
  for(int i = 0; i < n; i++)
    cin >> c[i];
  for(int i =0; i <n; i++){
    if(v[i] > c[i])
      ans += v[i] - c[i];
  }
  cout << ans << nl;


}


Measured memory_bytes: 3520
#include <iostream>
#include <string.h>
#include <cstdint>
using namespace std;
 
#define N 16

int main() {
	int a, b;

	cin >> a >> b;

	if( a <= N/2 && b <= N/2 ) {
		cout << "Yay!" << "\n";
	}
	else {
		cout << ":(" << "\n";
	}
 
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(asd, fgh) for(int asd = 0; asd < fgh; asd++)
#define MAX_N 200000

int main(void){
  int n;
  int a[MAX_N];
  int m = INT_MAX;
  int ans = INT_MIN;
  cin >> n;
  REP(i, n){
    cin >> a[i];
  }

  for(int i = 1; i < n; i++){
    m = min(m, a[i-1]);
    ans = max(ans, a[i] - m);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1940
N = gets.to_i
T = gets.split(" ").map(&:to_i)
sum = 0
T.each{|i| sum += i}
M = gets.to_i
P = []
for i in 1..M do
    P.push(gets.split(" "))
end
for j in P do
    puts sum - T[j[0].to_i - 1] + j[1].to_i
end

Measured memory_bytes: 3836
#include<bits/stdc++.h>
using namespace std;
int main(){


    int m1,d1,m2,d2;
    cin>>m1>>d1>>m2>>d2;
    if(m1==m2-1){
        cout<<"1"<<endl;
    }
    else{
        cout<<"0"<<endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define repu(i,m,n) for(int i=m;i<n;i++)
#define repd(i,m,n) for(int i=m,i>n;i--)
#define pb push_back

int main() {
    ll n,k;
    cin>>n>>k;
    ll arr[n];
    vector<ll> dp(n+1,LLONG_MAX);
    dp[1]=0;
    repu(i,0,n)
    cin>>arr[i];
    for(ll i=2;i<=n;i++) {
        for(ll j=1;j<=k;j++) {
            if(i-j-1<0) {break;}
            else {
                dp[i]=min(dp[i],dp[i-j]+abs(arr[i-1]-arr[i-j-1]));
            }
        }
    }
    cout<<dp[n]<<endl;
    
	return 0;
}


Measured memory_bytes: 1792
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, AB):
    g = defaultdict(list)
    for a, b in AB:
        g[a].append(b)
        g[b].append(a)
        
    s = [(1, -1)]
    done = set([1])
    K = 1
    ans = {}
    while s:
        u, c = s.pop()
        used = set([c])
        c = 1
        for v in g[u]:
            if v in done:
                continue
            while c in used:
                c += 1 
                K = max(K, c)
            used.add(c)
            s.append((v, c))
            i, j = min(u, v), max(u, v)
            ans[(i, j)] = c
            done.add(v)
    print(K)
    for a, b in AB:
        print(ans[(a, b)])
    # return ans


def main():
    N = read_int()
    AB = [read_int_n() for _ in range(N-1)]
    (slv(N, AB))


if __name__ == '__main__':
    main()


Measured memory_bytes: 67416
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.nextLine();
        int ac = 0, wa = 0, tle = 0, re = 0;
        for (int i = 0; i < n; i++) {
            String str = sc.nextLine();
            if (str.equals("AC")) {
                ac++;
            } else if (str.equals("WA")) {
                wa++;
            } else if (str.equals("TLE")) {
                tle++;
            } else if (str.equals("RE")) {
                re++;
            }
        }
        System.out.println("AC x " + ac);
        System.out.println("WA x " + wa);
        System.out.println("TLE x " + tle);
        System.out.println("RE x " + re);
    }
}

Measured memory_bytes: 60508
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int N;
i64 W, wi[110], vi[110];

int main()
{
	scanf("%d%lld", &N, &W);
	for (int i = 0; i < N; ++i) {
		scanf("%lld%lld", wi + i, vi + i);
	}

	map<i64, i64> mp;
	mp[0LL] = 0LL;
	for (int i = 0; i < N; ++i) {
		map<i64, i64> mp2;
		for (auto a : mp) {
			mp2[a.first] = max(mp2[a.first], a.second);
			if (a.first + wi[i] <= W) mp2[a.first + wi[i]] = max(mp2[a.first + wi[i]], a.second + vi[i]);
		}
		swap(mp, mp2);
	}

	i64 ret = 0;
	for (auto a : mp) ret = max(ret, a.second);
	printf("%lld\n", ret);

	return 0;
}


Measured memory_bytes: 512
import sys

def solve():
    n = int(sys.stdin.readline())

    ans = sum(is_prime(int(sys.stdin.readline())) for i in range(n))

    print(ans)

def is_prime(n):
    if n < 2 or (n > 2 and n & 1 == 0):
        return False

    p = 3

    while p*p <= n:
        if n % p == 0:
            return False

        p += 2

    return True

if __name__ == '__main__':
    solve()

Measured memory_bytes: 7700
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    string s;
    cin >> s;
    int n = s.length();
    bool win = (s[0] != s.back()) ^ (n % 2 == 0);
    if(win) cout << "First\n";
    else    cout << "Second\n";
}

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

#define int long long
#define pb emplace_back
#define f(i,n) for(int i=1 ; i<=n ; i++)
#define F first
#define S second
#define fast ios:: sync_with_stdio(false),cin.tie(0);
const int N =1e5 + 5;
int n,a[N] , dp[N];
int32_t main(){
	fast;
	cin >> n;
	f(i,n)  cin >> a[i];
	
	dp[1] = 0;
	dp[2] = abs(a[2]-a[1]);
	for(int i=3 ; i<=n ; i++)
		dp[i] = min(dp[i-1] + abs(a[i] - a[i-1]) , dp[i-2] + abs(a[i] - a[i-2]));
		
	cout << dp[n];
}







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

int main() {
    int n, l;
    cin >> n >> l;
    vector<int> taste(n);
    int mi = 500;
    rep(i, n) {
        taste[i] = l + i;
        mi = min(abs(taste[i]), mi);
    }

    int ans = 0;
    rep(i, n) {
        if (abs(taste[i]) == mi) continue;
        else ans += taste[i];
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;

vector<vector<ll>> dist(1010,vector<ll>(1010,1e18));

void Warshall_floyd(int& V){
    for(int mid=0;mid<V;++mid){
        for(int s=0;s<V;++s){
            for(int e=0;e<V;++e){
                if(dist[s][mid] == 1e18 || dist[mid][e] == 1e18) continue;
                dist[s][e] = min(dist[s][e],dist[s][mid] + dist[mid][e]);
            }
        }
    } 
}

int main(){
    int V,E;
    cin >> V >> E;
    for(int i=0;i<E;++i){
        int s,t,d;
        cin >> s >> t >> d;
        dist[s][t] = d;
    }
    for(int i=0;i<V;++i) dist[i][i] = 0;
    Warshall_floyd(V);

    for(int i=0;i<V;++i){
        if(dist[i][i] < 0){
            cout << "NEGATIVE CYCLE\n";
            return 0;
        }
    }

    for(int i=0;i<V;++i){
        for(int j=0;j<V;++j){
            if(dist[i][j] >= 1e18) cout << "INF";
            else cout << dist[i][j];
            if(j != V-1) cout << " ";
        }
        cout << endl;
    }
}


Measured memory_bytes: 10648
#include <bits/stdc++.h>
#define rep(i,n) for ( int (i) = 0; (i) < (n); (i)++ )
using namespace std;
using ll = long long int;
const long long int INF = 1001001001001001LL;
const int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

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

    ll n, d, a;
    cin >> n >> d >> a;
    vector<pair<ll, ll>> p(n);
    rep(i, n) cin >> p[i].first >> p[i].second;
    sort( p.begin(), p.end() );

    vector<ll> imos(n+1, 0);
    ll cnt = 0;
    rep(i, n) {
        if ( i > 0 ) imos[i] += imos[i-1];
        ll h = p[i].second - imos[i];

        if ( h > 0 )
        {
            ll c = (h+a-1) / a;
            ll damage = c*a;

            ll out = upper_bound( p.begin(), p.end(), make_pair( p[i].first+2*d, INF ) ) - p.begin();
            
            imos[i] += damage;
            imos[out] -= damage;
            cnt += c;
        }
    }

    cout << cnt << endl;
    
    return 0;
}

Measured memory_bytes: 4992
#!/usr/bin/env python3
from bisect import bisect_right

n, *L = map(int, open(0).read().split())
L.sort()
ans = 0
c = [0] * (2 * 10**3 + 1)
for i in range(2 * 10**3 + 1):
    c[i] = bisect_right(L, i)
for i in range(n):
    for j in range(i + 1, n):
        ans += c[L[i] + L[j] - 1] - c[L[j] - L[i]] - 1 - (L[j] - L[i]*2 < 0)
print(ans//3)


Measured memory_bytes: 9228
N = int(input())
L1 = []
L2 = []
ans = -10**10
for _ in range(N):
    l = list(map(int,input().split()))
    L1.append(l)
for _ in range(N):
    l = list(map(int,input().split()))
    L2.append(l)

for j in range(1,1024):
    b = format(j,'b').zfill(10)
    price = 0
    for k in range(N):
        cnt = 0
        for i in range(10):
            if L1[k][i] == int(b[i]) == 1:
                cnt += 1
        price += L2[k][cnt]
    ans = max(ans,price)
print(ans)


Measured memory_bytes: 42020
#include <iostream>
using namespace std;
int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if (a<b)  swap(a,b);
	if (a<c)  swap(a,c);
	for (int i=1;i<=d;i++)  a*=2;
	cout<<a+b+c;
	return 0; 
}

Measured memory_bytes: 256
MOD = 998244353
list_size = 10000010

f_list = [1] * list_size
f_r_list = [1] * list_size

for i in range(list_size - 1):
	f_list[i + 1] = int((f_list[i] * (i + 2)) % MOD)

f_r_list[-1] = pow(f_list[-1], MOD - 2, MOD)

for i in range(2, list_size + 1):
	f_r_list[-i] = int((f_r_list[-i + 1] * (list_size + 2 - i)) % MOD)

def comb(n, r):
	if n < r:
		return 0
	elif n == 0 or r == 0 or n == r:
		return 1
	else:
		return (((f_list[n - 1] * f_r_list[n - r - 1]) % MOD) * f_r_list[r - 1]) % MOD 

n = int(input())
sub = 0
for i in range(n//2+1, n+1):
	sub += comb(n, i) * pow(2, n-i, MOD)
	sub %= MOD
print((pow(3, n, MOD) - 2 * sub) % MOD)

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

int main(){
   long int n;
   long int sam=0;
    cin >> n;
    long int x[n];

    for(long int i=0; i<n; i++){
        cin >> x[i];
    }
    long int max=x[0];
    for(long int i=0; i<n; i++){
        if(x[i]>max){
            max=x[i];
        }
    }
    long int min=x[0];
    for(long int i=0; i<n; i++){
        if(x[i]<min){
            min=x[i];
        }
    }
    for (long int i=0; i<n; i++){
        sam=sam+x[i];

    }
    cout << min << ' ' << max << ' ' << sam << '\n';

    return 0;
}   


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


int main() {
	const int INF = 1e8;
	int r, c, n; cin >> r >> c >> n;
	vector<pair<int, int>> v;
	for(int i = 0; i < n; ++i) {
		int x1, y1; cin >> x1 >> y1;
		int e1 = -1;
		if(x1 == 0) {
			e1 = INF - y1;
		} else if(y1 == 0) {
			e1 = INF + x1;
		} else if(x1 == r) {
			e1 = 2 * INF + y1;
		} else if(y1 == c) {
			e1 = 4 * INF - x1;
		}
		int x2, y2; cin >> x2 >> y2;
		int e2 = -1;
		if(x2 == 0) {
			e2 = INF - y2;
		} else if(y2 == 0) {
			e2 = INF + x2;
		} else if(x2 == r) {
			e2 = 2 * INF + y2;
		} else if(y2 == c) {
			e2 = 4 * INF - x2;
		}
		if(e1 != -1 and e2 != -1) {
			v.emplace_back(e1, i);
			v.emplace_back(e2, i);
		}
	}
	sort(v.begin(), v.end());
	stack<int> st;
	for(auto i : v) {
		int idx = i.second;
		if(not st.empty() and st.top() == idx) {
			st.pop();
		} else {
			st.push(idx);
		}
	}
	if(st.empty()) cout << "YES" << '\n';
	else cout << "NO" << '\n';
	return 0;
}

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

struct S {
	ll zeros, ones, ans;
};

using F = bool;

S op(S x, S y) { return S{x.zeros+y.zeros, x.ones+y.ones, x.ans+y.ans+x.ones*y.zeros}; }

S e() { return S{0, 0, 0}; }

S mapping(F f, S x) { return f ? S{x.ones, x.zeros, x.zeros*x.ones-x.ans} : x; }

F composition(F f, F g) { return (f!=g); }

F id() { return 0; }

int main()
{
	int n, q, t, l, r;
	scanf("%d%d", &n, &q);
	vector<S> a(n);
	for (int i = 0; i < n; ++i) {
		scanf("%d", &t);
		a[i] = S{1-t, t, 0};
	}
	lazy_segtree<S, op, e, F, mapping, composition, id> st(a);
	while (q--) {
		scanf("%d%d%d", &t, &l, &r);
		--l;
		if (t == 1) {
			st.apply(l, r, 1);
		}
		else {
			printf("%lld\n", st.prod(l, r).ans);
		}
	}
}

Measured memory_bytes: 20476
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<algorithm>
#include<vector>
#include<set>
using namespace std;
typedef long long ll;
const int MAXM = 4e2 + 5;
const int MAXN = 26 + 5;
const ll linf = 0x3f3f3f3f3f3f3f3f;

int n=26, m;
int c[MAXN];
int a[MAXM][MAXN];

int p[MAXM];
set<int> idx[MAXN];
ll ans;

void init(void)
{
	for(int i=1; i<=n; ++i)
	{
		idx[i].clear();
		idx[i].insert(0);
		idx[i].insert(m+1);
	}
	
	for(int k=1; k<=m; ++k)
		idx[ p[k] ].insert(k);
}

ll recalc(int pos, int x)
{
	int old = p[pos];
	if(old == x) return ans;
	
	ll res = ans;
	
	idx[old].erase(pos);
	
	set<int>::iterator it = idx[old].upper_bound(pos);
	int nxt = *it;
	int lst = *(--it);
	
	res -= (pos - lst) * c[old] * (nxt - pos);
	res -= a[pos][old];
	
	it = idx[x].upper_bound(pos);
	nxt = *it;
	lst = *(--it);
	
	res += (pos - lst) * c[x] * (nxt - pos);
	res += a[pos][x];
	
	idx[x].insert(pos);
	
	p[pos] = x;
	return res;
}

int main(void)
{
	srand(time(0));
	
	scanf("%d",&m);
	for(int i=1; i<=n; ++i) scanf("%d",&c[i]);
	for(int i=1; i<=m; ++i)
		for(int j=1; j<=n; ++j)
			scanf("%d",&a[i][j]);
	
	static int lst[MAXN];
	
	ans = 0;
	for(int k=1; k<=m; ++k)
	{
		ll mx = -linf;
		int mxi = -1;
		for(int i=1; i<=n; ++i)
		{
			ll res = a[k][i];
			for(int j=1; j<=n; ++j) if(j!=i)
				res -= c[j] * (k-lst[j]);
			
			if(mxi==-1 || mx < res)
				mxi = i, mx = res;
		}
		lst[mxi] = k;
		
		ans += mx;
		p[k] = mxi;
	}
	
	init();
	
	int T = 2e6;
	while(T--)
	{
		int pos = rand()%m + 1;
		int x = rand()%n + 1;
		
		int old = p[pos];
		ll res = recalc(pos, x);
		if(res < ans) recalc(pos, old);
		else ans = res;
	}
	
	for(int i=1; i<=m; ++i) printf("%d\n",p[i]);
	return 0;
}

Measured memory_bytes: 3336
#include <bits/stdc++.h>
#define int long long

using namespace std;

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    int a;
    int am4 = 0, am2 = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> a;
        if (a % 4 == 0) am4++;
        else if (a % 2 == 0) am2++;
    }
    if (am2 == n)
    {
        cout << "Yes";
        return 0;
    }
    am2 = max((int)0, am2 - 1);
    if (am2 + am4 * 2 + 1>= n)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
    return 0;
}



Measured memory_bytes: 256
from collections import deque
H, W= map(int, input().split())
Ch, Cw = map(int, input().split())
Dh, Dw = map(int, input().split())
Ch -= 1
Cw -= 1
Dh -= 1
Dw -= 1
A = []
for i in range(H):
  A.append([])
  s = input()
  for j in range(W):
    if s[j] == '.':
      A[-1].append(0)
    else:
      A[-1].append(1)
P = [[1e6 for i in range(W)] for j in range(H)]
P[Ch][Cw] = 0
D = deque([[Ch, Cw]])
while len(D):
  d = D.pop()
  for i in range(-2, 3):
    for j in range(-2, 3):
      if 0 <= d[0]+i < H and 0 <= d[1]+j < W and A[d[0]+i][d[1]+j] == 0:
        if (i + j == 1 or i + j == -1) and i*j == 0 and P[d[0]][d[1]] < P[d[0]+i][d[1]+j]:
          D.append([d[0]+i, d[1]+j])
          P[d[0]+i][d[1]+j] = P[d[0]][d[1]]
        elif P[d[0]][d[1]]+1 < P[d[0]+i][d[1]+j]:
          D.appendleft([d[0]+i, d[1]+j])
          P[d[0]+i][d[1]+j] = P[d[0]][d[1]] + 1
if P[Dh][Dw] == 1e6:
  print(-1)
else:
  print(P[Dh][Dw])

Measured memory_bytes: 117512