akhauriyash/Code-Regression huggingface dataset:
require 'prime'
require 'set'
require 'tsort'
include Math
ALP = ('a'..'z').to_a
INF = 0xffffffffffffffff
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def pr?(num);              Prime.prime?(num)                          end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end

s = []
n = gif
num = gi
rep n do |i|
  if i % 2 == 0
    s.push num[i]
  else
    s.unshift num[i]
  end
end
s.reverse! if n % 2 == 1
puts s.join(' ')

Measured memory_bytes: 25964
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
	int n, d, i, c = 0;

	cin >> n >> d;
	vector<int> x(n), y(n);

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

	for (i = 0; i < n; i++){
		if (sqrt(pow(x[i], 2.0)+pow(y[i], 2.0)) <= d){
			c++;
		}
	}

	cout << c << endl;

	return 0;
}

Measured memory_bytes: 4900
#include <bits/stdc++.h>
#define y0    lol
#define y1    lool
#define yn    loool
#define prev  looool
#define next  loooool
#define read  looooool
#define tm    loooooool
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#ifdef LOCAL
#define rall(x,a) for(x : a)
#define LL "%lld"
#else
#define rall(x,a) for(auto x : a)
#define LL "%I64d"
#endif
#define rng(a) a.begin(), a.end()
#define PI 3.14159265358979323846
#define MOD 1000000007
#define endl "\n"
#define int long long
typedef long long ll;
using namespace std;

const int N = 111111;
int a[N], pref[N], suf[N];
int n;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    rep(i, 1, n) {
        cin >> a[i];
    }
    pref[1] = a[1];
    rep(i, 2, n) {
        pref[i] = __gcd(pref[i - 1], a[i]);
    }
    suf[n] = a[n];
    rrep(i, 1, n - 1) {
        suf[i] = __gcd(suf[i + 1], a[i]);
    }
    int ans = max(pref[n - 1], suf[2]);
    rep(i, 2, n - 1) {
        int cur = __gcd(pref[i - 1], suf[i + 1]);
        ans = max(ans, cur);
    }
    cout << ans << endl;
    return 0;
}


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

int main(void){
    
   int N,X,sum=0;
   cin >> N >> X;
   int L[N];
   
   for(int i=0;i<N;i++) cin >> L[i];
   
   int D = 0;
   for(int i=0;i<N+1;i++){
       if(D <= X) sum++;
       D = D + L[i];
   }
   cout << sum <<endl;
}

Measured memory_bytes: 3580
#include <iostream>
using namespace std;
long long 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;
int main()
{
	cin>>k>>s;
	for(i=0;i<=k;i++)
	{
		for(j=0;j<=k;j++)
		{
			if((s-i-j<=k)&&(s-i-j>=0))
			{
				z++;
			}
		}
	}
	cout<<z<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#include <functional>
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;
ll a[400];
ll b[400];

int main(){
    ll x; 
    cin>>x;
    for(ll i=-200;i<200;i++){
        a[i+200]=b[i+200]=i*i*i*i*i;
    }
    for(ll i=0;i<400;i++){
        for(ll j=0;j<400;j++){
            if(a[i]-b[j]==x){
                cout<<i-200<<" "<<j-200<<endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3572
object Main extends App {
  import scala.io.StdIn._
  import scala.math._
  var n = readLine.trim.toInt
  while(n != 0){
    println(maxFloor(n * 2))
    n = readLine.trim.toInt
  }
  def maxFloor(n: Long): String = {
    var max = sqrt(n).floor.toInt
    while (n % max != 0 || (n / max - max) % 2 != 1){
      max -= 1
    }
    val diff = ((n / max - max) - 1) / 2
    s"${diff + 1} $max"
  }
}


Measured memory_bytes: 44996
#include <bits/stdc++.h>
using namespace std;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define ll long long
#define pb emplace_back
#define mp make_pair
#define nt _int128
#define ld long double
long double PI =3.14159265358979323846;


const ll modo=1e9+7;
const ll inf=1e7;
const ll ms=(2e5)+5;

int ar[ms];
map<int,int> mm;

int main()
{
    idfc;

    ll n,k;
    cin>>n>>k;
    int i;
    for(i=1;i<=n;i++)cin>>ar[i];

    mm[0]=0;
    i=1;
    int cur=ar[1]; int nx;
    if(cur==1)
    {
        cout<<1;return 0;
    }
    int len;
    while(true)
    {
       // cout<<cur<<" "<<i<<"\n";
        mm[cur]=i;
        if(i==k)
        {
            cout<<cur;
            return 0;
        }
        i++;
        nx=cur;
        cur=ar[cur];
        if(mm.count(cur))
        {
            len=i-mm[cur];
           // cout<<len<<"\n";
            k-=(i-1);
            k%=len;

            while(k--)
            {
                nx=ar[nx];
            }
            cout<<nx;return 0;
        }

    }

    return 0;
}

Measured memory_bytes: 11912
import sys
import heapq

input = sys.stdin.readline
N= int(input())
A = []
[heapq.heappush(A,[a,i+1]) for i, a in enumerate(map(int,input().split()))]
ans = []
while len(A) !=0:
  a, idx = heapq.heappop(A)
  ans.append(idx)
print(*ans)

Measured memory_bytes: 78224
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<numeric>
#include<algorithm>

using namespace std;

int par[123];

int find(int x){
  return (par[x]==x)?x:par[x]=find(par[x]);
}

void unite(int a,int b){
  par[find(a)]=find(b);
}

int ex[123][1234],ey[123][1234];
int evx[123][1234],evy[123][1234];

double sqr(double x){return x*x;}

int main(){
  for(int N,T,R;cin>>N>>T>>R,N|T|R;){
    char nicknames[123][12];
    vector<int> t[123],x[123],y[123],vx[123],vy[123];
    vector<double> ev;
    for(int i=0;i<N;i++){
      cin>>nicknames[i];
      for(int j=0;;j++){
	int ti,xi,yi;
	cin>>ti>>xi>>yi;
	ev.push_back(ti);
	t[i].push_back(ti);
	int cx,cy;
	if(j){
	  vx[i].push_back(xi);
	  vy[i].push_back(yi);
	  for(int k=t[i][j-1]+1;k<=ti;k++){
	    ey[i][k]=ey[i][k-1]+yi;
	    ex[i][k]=ex[i][k-1]+xi;
	    evy[i][k-1]=yi;
	    evx[i][k-1]=xi;
	  }
	  cy=ey[i][ti];
	  cx=ex[i][ti];
	}else{
	  cx=xi;
	  cy=yi;
	  ex[i][0]=cx;
	  ey[i][0]=cy;
	}
	x[i].push_back(cx);
	y[i].push_back(cy);
	if(ti==T)break;
      }
    }
    for(int i=0;i<N;i++){
      for(int j=0;j<vx[i].size();j++){
	int y1=y[i][j]-t[i][j]*vy[i][j];
	int x1=x[i][j]-t[i][j]*vx[i][j];
	for(int k=0;k<i;k++){
	  for(int l=0;l<vx[k].size();l++){
	    int y2=y[k][l]-t[k][l]*vy[k][l];
	    int x2=x[k][l]-t[k][l]*vx[k][l];
	    long long X=x1-x2;
	    long long Y=y1-y2;
	    long long VX=vx[i][j]-vx[k][l];
	    long long VY=vy[i][j]-vy[k][l];
	    long long a=VX*VX+VY*VY;
	    long long b=X*VX+Y*VY;
	    long long c=X*X+Y*Y-R*R;
	    long long inr=b*b-a*c;
	    if(inr>=0&&a){
	      ev.push_back((-b-sqrt(inr))/a);
	      ev.push_back((-b+sqrt(inr))/a);
	    }
	  }
	}
      }
    }
    sort(begin(ev),end(ev));
    bool has[123]={true};
    for(int k=0;k<ev.size()-1;k++){
      double e=(ev[k]+ev[k+1])/2;
      //      cerr<<e<<endl;
      if(e<0||T<e)continue;
      iota(begin(par),end(par),0);
      int g=e;
      double f=e-g;
      for(int i=0;i<N;i++){
	for(int j=0;j<i;j++){
	  if(sqr(ey[i][g]+evy[i][g]*f-(ey[j][g]+evy[j][g]*f))+
	     sqr(ex[i][g]+evx[i][g]*f-(ex[j][g]+evx[j][g]*f))<=R*R){
	    unite(i,j);
	  }
	}
      }
      for(int i=0;i<N;i++){
	has[find(i)]|=has[i];
      }
      for(int i=0;i<N;i++){
	has[i]|=has[find(i)];
      }
    }
    vector<string> ans;
    for(int i=0;i<N;i++){
      if(has[i]){
	ans.push_back(nicknames[i]);
      }
    }
    sort(begin(ans),end(ans));
    for(auto e:ans){
      cout<<e<<endl;
    }
  }
}

  

Measured memory_bytes: 5532
#include<stdio.h>
#include<string.h>
#define MAX 180
#define LIMIT 180
int main()
{
	int n = 0;
	int i = 0;
	int j = 0;
	int k = 0;
	int a = 0;
	char num1[MAX];
	char num2[MAX];
	int num1_int[MAX];
	int num2_int[MAX];
	int count1 = 0;
	int count2 = 0;
	int sum[MAX];
	int ans[MAX];
	
	scanf("%d",&n);
	scanf("\n");
	for(a=0;a < n;a++)
	{
		for(i=0;i < MAX;i++)
		{
			num1[i] = '\0';
			num2[i] = '\0';
			num1_int[i] = 0;
			num2_int[i] = 0;
			sum[i] = 0;
			ans[i] = 0;
		}
		scanf("\n");
		scanf("%s",num1);
		scanf("\n");
		scanf("%s",num2);
		
		if(num1[0] == '0' && num2[0] == '0')
		{
			printf("0\n");
			continue;
		}
		
		//入力が79桁を超える場合
		if(strlen(num1) > 80 || strlen(num2) > 80)
		{
			printf("overflow\n");
			continue;
		}
		
		//要素数の個数
		while(1)
		{
			if(num1[count1] == '\0')
			{
				break;
			}
			count1++;
		}
		while(1)
		{
			if(num2[count2] == '\0')
			{
				break;
			}
			count2++;
		}
		
		//16進数の整数を10進数の整数に変換
		for(i=0;i < count1;i++)
		{
			num1_int[i] = num1[i] - 0x30;
			/*printf("%d",num1_int[i]);*/
		}
		for(i=0;i < count2;i++)
		{
			num2_int[i] = num2[i] - 0x30;
			//printf("%d",num2_int[i]);
		}
		//配列の右側に移動させ桁数を合わせる
		for(i=0;i < count1;i++)
		{
			num1_int[LIMIT - count1 + i] = num1_int[i];
			num1_int[i]  = 0;
		}
		for(i=0;i < count2;i++)
		{
			num2_int[LIMIT - count2 + i] = num2_int[i];
			num2_int[i]  = 0;
		}
		/*
		for(i =  0;i < count1;i++)
		{
			printf("%d",num1_int[i]);
		}*/
		for(i = LIMIT-1;i >= 0;i--)
		{
			sum[i] = num1_int[i] + num2_int[i];
			//繰り上げ処理
			if(sum[i] >= 10)
			{
				num1_int[i-1]++;
				sum[i] -= 10;
			}
		}
		
		for(i = 0; i < LIMIT;i++)
		{
			if(sum[i] != 0)
			{
				for(k = i;k < LIMIT;k++)
				{
					ans[j] = sum[k];
					//printf("%d",ans[j]);
					j++;
				}
				break;
			}
			//printf("%d",sum[i]);
		}
		count1 = 0;
		count2 = 0;
		
		/*printf("j=%d\n",j);*/
		if(j <= 80)
		{
			
			for(i=0;i < j;i++)
			{
				printf("%d",ans[i]);
			}
			printf("\n");
		}
		else if(j > 80)
		{
			printf("overflow\n");
		}
		j = 0;

	}
	return 0;
}

Measured memory_bytes: 616
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
int main()
{
    ll N; cin >> N;
    vector<ll> A(N);
    rep(i,N){
        cin >> A.at(i);
    }
    ll count=1;
    int judge=0;
    rep(i,N-1){
        if(i!=0){
            if(judge==2){
                if(A.at(i)>A.at(i+1)){
                    count++;
                    judge=1;
                    continue;
                }
                if(A.at(i)==A.at(i+1)){
                    continue;
                }
            }
            if(judge==0){
                if(A.at(i)<A.at(i+1)){
                    count++;
                    judge=1;
                    continue;
                }
                if(A.at(i)==A.at(i+1)){
                    continue;
                }
            }
        }
        if(A.at(i)<A.at(i+1)){
            judge=2;
        }
        else if(A.at(i)>A.at(i+1)){
            judge=0;
        }
        else if(A.at(i)==A.at(i+1)){
            judge=1;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 1024
n, k = map(int, input().split())
a = list(map(int, input().split()))
p = 0 #tumble count in a: finally *k
q = 0 #tumble count between a: finally *kC2
for i in range(n-1):
  for j in range(i+1,n):
    if a[i] > a[j]:
      p += 1
for i in range(n):
  for j in range(n):
    if a[i] > a[j]:
      q += 1
p *= k
q *= k*(k-1)//2
print((p+q)%(10**9+7))

Measured memory_bytes: 70132
#include <algorithm>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using Graph = std::vector<std::vector<int>>;
using WGraph = std::vector<std::vector<std::pair<int, long long>>>;
using ll = long long;
using namespace std;

int main() {
    int n = 0;
    cin >> n;
    vector<ll> a(n);
    for (int i=0; i<n; i++) {
        cin >> a.at(i);
    }
    for (int i=0; i<n; i++) {
        if (a.at(i)%2 == 1) {
            cout << "first" << endl;
            return 0;
        }
    }
    cout << "second" << endl;
    return 0;
}
 

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

int main(){
  string str;
  int h,i,hm;

  while(1){
    cin >> str;
    if(str == "-") break;
    cin >> h;
    for(i = 0; i < h; i++){
      cin >> hm;
      str = str.substr(hm) + str.substr(0,hm);
    }
    cout << str << endl;
  }
  return 0;
}

Measured memory_bytes: 1216
import java.util.*;

public class Main {
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);

    int n = scan.nextInt();

    int[] array = new int [n];
    for(int i = 0; i < n; i++){
      array[i] = scan.nextInt();
    }

    int max = MaxRate(array);
    System.out.println(max);
  }

  static int MaxRate(int array[]){
    int minv = array[0];
    int maxv = array[1] - array[0];

    for(int j = 1; j < array.length; j++){
      if(maxv < array[j] - minv){
        maxv = array[j] - minv;
      }
      if (minv > array[j]){
        minv = array[j];
      }
    }
    return maxv;
  }
}



Measured memory_bytes: 101016
#include<bits/stdc++.h>
using namespace std;
#define bitCount(num)  __builtin_popcount(num)
#define pb push_back
#define ll long long
#define bye return 0;
#define f(i,a,b) for( long long i=a;i<b;i++)
#define testCases long long t;cin>>t; while(t--)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define newLine <<"\n"
#define all(x) (x).begin(), (x).end()
#define vll vector<long long>

int main()
{
    fast
   
    	ll n;
    	cin>>n;
    	vector<ll> a(n,0);
    	f(i,0,n)cin>>a[i];
    	ll ans=0;

    	vector<ll> pSum(n,0);
    	pSum[n-1]=a[n-1];
    	
    	for(ll j=n-2;j>=0;j--)
    	{
         pSum[j]=pSum[j+1]+a[j];
         pSum[j]%=1000000007;
    	}

    	for(ll j=1;j<n;j++)
    	{
    	  ll tempAns= a[j-1]*pSum[j];
    	  ans+=tempAns;
    	  ans%=1000000007;
    	}

    	cout<<ans<<endl;


    
    bye
}

Measured memory_bytes: 6340
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int d,g;
    cin >> d >> g;
    vector<int> p(d),c(d);
    rep(i,d) cin >> p[i] >> c[i];
    int ans = inf;
    rep(bit,1<<d) {
        int now = 0,cnt = 0;
        rep(i,d) {
            if(bit>>i&1) {
                cnt += p[i];
                now += 100*(i+1)*p[i];
                now += c[i];
            }
        }
        if(now >= g) {
            chmin(ans,cnt);
            continue;
        }
        rrep(i,d) {
            if(bit>>i&1) continue;
            if(now+100*(i+1)*p[i] < g) {
                cnt += p[i];
                now += 100*(i+1)*p[i];
            } else {
                cnt += (g-now+(100*(i+1))-1)/(100*(i+1));
                break;
            }
        }
        chmin(ans,cnt);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 1e18;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main(){
	ll n; cin >> n;
	int ans=log10(n)+1;
	for(int i=1;i<=sqrt(n);i++){
		if(n%i==0){
			ans=max(log10(i)+1,log10(n/i)+1);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3892
//To compile : type "$     g++ test.cpp -std=c++14 -I .    "
#include <atcoder/lazysegtree>
#include <bits/stdc++.h>
//#include <chrono>
//#pragma GCC optimize("Ofast")
using namespace std;
using namespace atcoder;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
//string S;
typedef pair<ll, ll> P;
const ll INF = (1LL<<60);
template <long long mod > class modint{
public:
    ll x;
    const static unsigned long long mod_plus = (LLONG_MAX / mod) * mod;
    constexpr modint(){x = 0;}
    constexpr modint(ll _x) : 
	x((_x < 0 ? ((_x += mod_plus) < 0 ? _x + mod_plus : _x) : _x) >= mod ? _x % mod : _x){}
    constexpr modint operator-(){
        return x == 0 ? 0 : mod - x;
    }
    constexpr modint& operator+=(const modint& a){
        if((x += a.x) >= mod) x -= mod;
        return *this;
    }
    constexpr modint operator+(const modint& a) const{
        return modint(*this) += a;
    }
    constexpr modint& operator-=(const modint& a){
        if((x -= a.x) < 0) x += mod;
        return *this;
    }
    constexpr modint operator-(const modint& a) const{
        return modint(*this) -= a;
    }
    constexpr modint& operator*=(const modint& a){
        (x *= a.x)%=mod;
        return *this;
    }
    constexpr modint operator*(const modint& a) const{
        return modint(*this) *= a;
    }
    constexpr modint pow(unsigned long long pw) const{
        modint res(1), comp(*this);
        while(pw){
            if(pw&1) res *= comp;
            comp *= comp;
            pw >>= 1;
        }
        return res;
    }
    //以下、modが素数のときのみ
    constexpr modint inv() const{
        return modint(*this).pow(mod - 2);
    }
    constexpr modint& operator/=(const modint &a){
        (x *= a.inv().x)%=mod;
        return *this;
    }
    constexpr modint operator/(const modint &a) const{
        return modint(*this) /= a;
    }
};
#define mod1 998244353
using mint = modint<mod1>;

ostream& operator<<(ostream& os, const mint& a){
    os << a.x;
    return os;
}
using vm = vector<mint>;

struct S {
	mint x;
	int n;
	S(mint _x = 0, int _n = 0) : x(_x), n(_n){}
};

struct F {
	mint a, b;
	F(mint _a = 1, mint _b = 0) : a(_a), b(_b){}
};

S op(S s, S t){
	return S(s.x + t.x, s.n + t.n);
}

S e(){ return S(); }

S mapping(F f, S s){
	return S(f.a * s.x + f.b * s.n, s.n);
}

F composition(F f, F g){
	return F(f.a * g.a, f.a * g.b + f.b);
}

F id(){ return F(); }

int main() {
	cin>>N>>Q;
	vector<S> a(N);
	rep(i, N){
		scanf("%lld", &A);
		a[i] = S(A, 1);
	}
	lazy_segtree<S, op, e, F, mapping, composition, id> seg(a);
	rep(_, Q){
		int t, l, r, b, c;
		scanf("%d%d%d", &t, &l, &r);
		if(t == 0){
			scanf("%d%d", &b, &c);
			seg.apply(l, r, F(b, c));
		}else{
			printf("%lld\n", seg.prod(l, r).x.x);
		}
	}
}

Measured memory_bytes: 35696
#include <bits/stdc++.h>
#define ll long long
#define MAX_N 51
#define mod 1000000007
using namespace std;
 

ll power2(ll x, ll n, ll m){
    ll res = 1;
    if( n > 0){
        res = power2(x, n/2,m);
        if(n%2 == 0) res = (res*res) %m;
        else res = (((res*res)%m)*x) %m;
    }
    return res;
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll x,y;
    cin>>x>>y;
    ll ans = 0;
    if(x > y) swap(x,y);
    for(ll i = x%2; i<=x; i+=2){
        ll j = (x-i)/2;
        if(2*i + j == y){
            ll a = 1, b = 1, c = 1;
            for(ll k = i+j; k > i; k--) a = (a*k)%mod;
            for(ll k = j; k >0; k--) b = (b*k)%mod;
            ans = (a*power2(b,mod-2,mod))%mod;
            cout<< ans <<endl;
            return 0;
        }
    }

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


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
signed main(){
  string s,st[]={"Sunny","Cloudy","Rainy"};
  cin >> s;
  if(s==st[0])cout << st[1]<<endl;
  else if(s==st[1])cout << st[2]<<endl;
  else cout <<st[0]<<endl;
}


Measured memory_bytes: 256
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> void get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'; t=getchar());
	if(t=='-')neg=true,t=getchar();
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) get1(a),get1(b)
#define get3(a,b,c) get1(a),get2(b,c)
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

char s[200111];
int stk[200111],top,n;
int main()
{
	scanf("%s",s+1);n=strlen(s+1);
	for(int i=1;i<=n;i++)
	{
		stk[++top]=i;
		while(top>=2&&s[stk[top]]=='T'&&s[stk[top-1]]=='S')top-=2;
	}
	printendl(top);
	return 0;
}

Measured memory_bytes: 1280
#include <stdio.h>
#include <math.h>

int main(void)
{
	double r;
	double men;
	double shu;

	scanf("%lf", &r);

	if( r<0 || r>10000 )
	{
		return 1;
	}

	men = r * r * M_PI;
	shu = ( r + r ) * M_PI;


	printf("%lf %lf \n", men, shu);

	return 0;
}

Measured memory_bytes: 648
#include<bits//stdc++.h>
using namespace std;
int h,w,b[6]={0,1,0,-1,-1,-1},c[6]={-1,0,1,1,0,-1},d[6]={1,1,1,0,-1,0},e[6]={-1,0,1,1,0,-1},a[102][102];
struct Q {int x,y;};
int main() {
	while (cin >> w >> h) {
		for (int i = 0; i <= h + 1; i++) {
			for (int j = 0; j <= w + 1; j++)
				a[i][j] = 0;
		}
		for (int i = 1; i <= h; i++) {
			for (int j = 1; j <= w; j++)
				cin >> a[i][j];
		}
		queue<Q>q;
		q.push(Q{ 0,0 });
		//y????????????????¨?
		int ans = 0;
		while (!q.empty()) {
			Q t = q.front(); q.pop();
			for (int i = 0; i < 6; i++) {
				int x2, y2;
				if (t.y % 2 == 0) {
					y2 = t.y + c[i];
					x2 = t.x + b[i];
				}
				else {
					y2 = t.y + e[i];
					x2 = t.x + d[i];
				}
				if (y2<0 || y2>h + 1 || x2<0 || x2>w + 1) continue;
				if (a[y2][x2] == 0) {
					q.push(Q{ x2,y2 });
					a[y2][x2] = 2;
				}
				else if (a[y2][x2] == 1) ans++;
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3204
import java.util.Arrays;
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String a[] = new String[n];
		String b[] = new String[n];

		for (int i = 0; i < n; i++) {
			a[i] = sc.next();
		}

		System.arraycopy(a, 0, b, 0, a.length);

		bubbleSort(a, n);
		System.out.println(Arrays.toString(a).replace("[", "").replace("]", "").replace(",", ""));
		System.out.println("Stable");

		selectionSort(b, n);
		System.out.println(Arrays.toString(b).replace("[", "").replace("]", "").replace(",", ""));
		if (Arrays.equals(a, b)) {
			System.out.println("Stable");
		} else {
			System.out.println("Not stable");
		}

		sc.close();
	}

	private static void bubbleSort(String[] a, int n) {
		boolean flg = true;
		while (flg) {
			flg = false;
			for (int i = n - 1; 0 < i; i--) {
				if (a[i].charAt(1) < a[i - 1].charAt(1)) {
					String tmp = a[i - 1];
					a[i - 1] = a[i];
					a[i] = tmp;
					flg = true;
				}
			}
		}
	}

	private static void selectionSort(String[] a, int n) {
		for (int i = 0; i < n; i++) {
			int minj = i;
			for (int j = i; j < n; j++) {
				if (a[j].charAt(1) < a[minj].charAt(1)) {
					minj = j;
				}
			}
			String tmp = a[minj];
			a[minj] = a[i];
			a[i] = tmp;
		}
	}

}




Measured memory_bytes: 26280
#include<bits/stdc++.h>
#define mo 1000000007
#define plus(a,b) (a+b<mo)?(a+=b):(a+=b-mo) 
using namespace std;
int n;
long long d[1000100];
struct bit
{
	int sum[1000100];
	vector <int> vec;
	void clear()
	{
		for (int i=0;i<vec.size();i++) sum[vec[i]]=0;
		vec.clear();
	}
	void add(int s,int w)
	{s++;if (!w) return;
		while (s<=n+1)
		{
			plus(sum[s],w);vec.push_back(s);
			s+=s&(-s);
		}
	}
	int getsum(int s)
	{s++;
		int ans=0;
		while (s)
		{
			plus(ans,sum[s]);
			s-=s&(-s);
		}
		return ans;
	}
	int getsum(int l,int r)
	{
		int p=getsum(l-1),q=getsum(r);
		if (p<=q) return q-p;else return q-p+mo;
	}
}f,g;
int main()
{
	long long a,b;scanf("%d%lld%lld",&n,&a,&b);
	for (int i=1;i<=n;i++) scanf("%lld",&d[i]);
	f.add(0,1);g.add(0,1);
	int tf=0,tg=0;
	for (int i=2;i<=n;i++)
	{
		while ((tf+1<i)&&(d[i]-d[tf+1]>=a)) tf++;
		while ((tg+1<i)&&(d[i]-d[tg+1]>=b)) tg++;
		int ff=g.getsum(tf),gg=f.getsum(tg);
		if (d[i]-d[i-1]>=a) f.add(i-1,ff);
		else {f.clear();f.add(i-1,ff);}
	 	if (d[i]-d[i-1]>=b) g.add(i-1,gg);
	 	else {g.clear();g.add(i-1,gg);}
	}
	printf("%d\n",(f.getsum(n-1)+g.getsum(n-1))%mo);
}
	 	

Measured memory_bytes: 17760
n = gets
vr = gets
cr = gets
if n != nil  && vr != nil && cr != nil then
  n = n.to_i
  vr = vr.split(" ").map(&:to_i)
  cr = cr.split(" ").map(&:to_i)

  ans = 0

  for i in 0..(n-1) do
    if (vr[i] - cr[i]) > 0 then
      ans = ans + vr[i] - cr[i]
    end
  end


puts ans
end


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

int main(void){
	int K, N;
	cin >> K >> N;
	int A[N];
	rep(i,N) cin >> A[i];

	int dmax = A[0] + K - A[N-1];
	rep(i,N-1){
		dmax = max(dmax, A[i+1]-A[i]);
	}
	cout << K - dmax << endl;
	return 0;
}


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

#define fi first
#define sd second
#define lson (nd<<1)
#define rson (nd+nd+1)
#define PB push_back
#define mid (l+r>>1)
#define MP make_pair
#define SZ(x) (int)x.size()

using namespace std;

typedef long long LL;

typedef vector<int> VI;

typedef pair<int,int> PII;

inline int read(){
    int res=0, f=1;char ch=getchar();
    while(ch<'0'|ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){res=res*10+ch-'0';ch=getchar();}
    return res*f;
}

const int MAXN = 2'005;

const int MOD = 1000000007;

void addmod(int& a, int b){a+=b;if(a>=MOD)a-=MOD;}
int mulmod(int a, int b){return 1ll*a*b%MOD;}

int ans[MAXN];

int main(){
    int n, x, y;
    n=read();x=read();y=read();

    for(int i=1;i<=n;++i){
        for(int j=i+1;j<=n;++j){
            int t=min(j-i,1+abs(i-x)+abs(j-y));
            ++ans[t];
        }
    }

    for(int i=1;i<=n-1;++i){
        cout<<ans[i]<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {

	int A[200000] = { 0 };
	int n = 0;
	int max = 0;
	int max2 = 0;

	cin >> n;

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

		cin >> A[i];

		if (A[i] > max) {

			max = A[i];

		}
		else if (A[i] > max2) {

			max2 = A[i];

		}

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

		if (A[i] == max) {

			cout << max2 << endl;

		}
		else {

			cout << max << endl;

		}

	}

	return 0;

}

Measured memory_bytes: 2432
#ABC162B B - FizzBuzz Sum
# iが3でも5でも割り切れる ai=FizzBuz
# iが3で割り切れる ai=Fizz
# iが5で割り切れる ai=Buzz
# 割り切れない ai=i

# 1<=N<=10**6
N=int(input())
A=[]
for i in range(N+2):
    A.append(i)
for i in range(N//3+1):
    A[i*3]=0
for i in range(N//5+1):
    A[i*5]=0
ans=0
for i in range(N+1):
    ans+=A[i]
print(ans)

Measured memory_bytes: 140312
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  ll x = x2 - x1;
  ll y = y2 - y1;
  cout << x2 - y << " " << y2 + x << " " << x1 - y << " " << y1 + x << endl;
  return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define P pair<ll, ll>
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define pp pair<ll, pair<ll, ll>> 
#define fi first
#define se second

void print(Vl vec){
    rep(i, 0, sz(vec)){
        if(i) cout << " ";
        cout << vec[i];
    }
    coel;
}

////////////////////////////////////////////////////////
Vl a, p;
ll n, x; 

ll f(ll n, ll x){
    if(n == 0){
        if(x <= 0) return 0;
        else return 1;
    }else if(x <= 1 + a[n-1]){
        return f(n-1, x-1);
    }else{
        return p[n-1] + 1 + f(n-1, x-2-a[n-1]);
    }
}

int main() {
    cin >> n >> x;
    a.resize(n);
    p.resize(n);
    a[0] = 1; p[0] = 1;
    rep(i, 1, n){
        a[i] = a[i-1]*2 + 3; //thickness
        p[i] = p[i-1]*2 + 1; //patty
    }

    co(f(n, x));

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rem(i, m, n) for (int i = m; i < (n); i++)
#define eps (1e-7)
#define inf (1e9)
#define pi (acos(-1))
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    int ab = a + b;
    int c2 = c * 2;
    int ans = 0;
    if (c2 > ab)
        ans = a * x + b * y;
    else
    {
        if (x > y)
        {
            ans = c2 * y;
            ans += min(a, c2) * (x - y);
        }
        else
        {
            ans = c2 * x;
            ans += min(b, c2) * (y - x);
        }
    }

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 256
def solve(K, ABs):
    if not ABs: return 0
    ansK = sum(b for a, b in ABs if (K | a) == K)
    pool = []
    for i in range(30, -1, -1):
        if (K & (1<<i)):
            pool.append(i)
    for p in pool:
        v = 1 << p
        KK = (K >> p) << p
        KKK = (K >> p)
        t = sum(b for a, b in ABs if (not(a & v) and ((a | KK) >> p) == KKK))
        if t > ansK:
            ansK = t
    return ansK
   

N, K = map(int, input().split())
ABs = []
for i in range(N):
    a, b = map(int, input().split())
    if a > K: continue
    ABs.append([a, b])

print(solve(K, ABs))

Measured memory_bytes: 81136
#include<iostream>
#include<cstdio>
#include<string>
#include<cmath>

using namespace std;

const double INF=10000;

double color[8][3]=
{0,0,0,
0,0,255,
0,255,0,
0,255,255,
255,0,0,
255,0,255,
255,255,0,
255,255,255
};
string colors[8]=
{"black",
"blue",
"lime",
"aqua",
"red",
"fuchsia",
"yellow",
"white"
};

int main(void){
	while(1){
		string str;
		cin >> str;
		if(str=="0")break;
		double c[3]={0,0,0};
		for(int i=0;i<3;i++){
			if(str[i*2+1]>='a' && str[i*2+1]<='f'){
				c[i]+=(str[i*2+1]-'a'+10)*16;
			}else c[i]+=(str[i*2+1]-'0')*16;
			if(str[i*2+2]>='a' && str[i*2+2]<='f'){
				c[i]+=str[i*2+2]-'a'+10;
			}else c[i]+=str[i*2+2]-'0';
		}
		double adk=INF;
		int ans=0;
		for(int i=0;i<8;i++){
			double dk=sqrt(pow(abs(c[0]-color[i][0]),2)+pow(abs(c[1]-color[i][1]),2)+pow(abs(c[2]-color[i][2]),2));
			if(adk>dk){
				ans=i;
				adk=dk;
			}
		}
		cout << colors[ans] << endl;
	}
    return 0;
}

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

using namespace std;

void solve() {
    string s, ans = "";
    cin >> s;
    for (int i = 0; i < s.size(); i += 3) {
        if (ans.find(s[i]) != string::npos) continue;
        if (!i) ans = ans + s[i];
        else if (s[i - 1] == '>') ans = ans + s[i];
        else if (s[i - 2] == '<') ans = s[i] + ans;
    }
    cout << ans << endl;
}

int main(void) {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
        solve();

    return 0;
}


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

int main(){
    int h, w;
    cin >> h >> w;

    vector<string> a(h);
    for(int i=0; i<h; i++){
        cin >> a[i];
    }

    for(int bit=0; bit<(1<<(h+w-2)); bit++){
        if(__builtin_popcount(bit) != h-1) continue;
        //bitset<16> b(bit);
        //cout << b << endl;

        vector<string> test(h, "");
        for(int i=0; i<h; i++){
            for(int j=0; j<w; j++){
                test[i] += '.';
            }
        }

        int x = 0;
        int y = 0;
        test[0][0] = '#';

        for(int i=0; i<(h+w); i++){
            if(bit >> i & 1) x += 1;
            else y += 1;

            //cout << x << " " << y << endl;
            test[x][y] = '#';
        }

        bool flag = true;
        for(int i=0; i<h; i++){
            if(a[i] != test[i]) flag = false;
        }
        if(flag == true){
            cout << "Possible" << endl;
            return 0;
        }
    }
    cout << "Impossible" << endl;
    return 0;
}

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

int main() {
    int n, m, a, h, p, q;
    while (cin >> n >> m >> a, n) {
        int ans = a;
        vector<pair<int,pair<int,int>>> v;
        for (int i=0; i<m; ++i) {
            cin >> h >> p >> q;
            v.push_back(make_pair(h, make_pair(p, q)));
        }
        sort(v.begin(), v.end());
        reverse(v.begin(), v.end());
        for (int i=0; i<(int)v.size(); ++i) {
            if (v[i].second.first == ans) {
                ans = v[i].second.second;
            } else if (v[i].second.second == ans) {
                ans = v[i].second.first;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1224
import java.util.*;

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

		long a = sc.nextLong();
		long b = sc.nextLong();

		long n = gcd(a, b);

		int size = factorize(n);
		System.out.println(size + 1);

	}

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

  private static int factorize(long n) {
    Set<Long> set = new HashSet<>();
     for(long i = 2; i * i <=n; i++) {
        while (n % i == 0) {
          set.add(i);
          n /= i;
          }
     }
     if(n > 1) set.add(n);
     return set.size();
    }
}


Measured memory_bytes: 23252
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;

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

	for (int i = 0; i < 3; i++) {
		string s; cin >> s;
		cout << s[i]  ;
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	while(a>=b) b*=2,k--; 
	while(b>=c) c*=2,k--;
	k>=0?cout<<"Yes":cout<<"No";
	return 0;
}

Measured memory_bytes: 3608
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;

public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		long ans = 0;
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				for (int k = 1; k <= n; k++) {
					ans += gcd(gcd(i, j), k);
				}
			}
		}

		System.out.println(ans);
	}

	static long gcd(long a, long b) {
		return b > 0 ? gcd(b, a % b) : a;
	}
}

Measured memory_bytes: 32772
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int ans;
int main()
{
	ll l,r,d;
	cin>>l>>r>>d;
	for(int i=l;i<=r;i++){
		if(i%d==0)ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define P 1000000007
#define M 400010

using namespace std;

typedef long long ll;

int B, W;

ll powmod(ll x, ll y = P - 2, ll p = P) {
	ll ans = 1;
	while(y) {
		if(y & 1) ans = ans * x % p;
		x = x * x % p;
		y >>= 1;
	}
return ans;
}

ll Fac[M], Rev[M], SB[M], SW[M];


ll getC(ll x, ll y) {
	if(x < 0 || y < 0 || x < y) return 0;
	return Fac[x] * Rev[y] % P * Rev[x - y] % P;
}

int main() {
	scanf("%d%d", &B, &W);
	for(int i = 0; i < M; i++) Fac[i] = !i ? 1 : Fac[i - 1] * i % P;
	for(int i = M - 1; i >= 0; i--) Rev[i] = powmod(Fac[i]);
	for(int i = B; i < B + W; i++)
		SB[i] = (SB[i - 1] + (getC(i, B) - getC(i - 1, B)) * powmod(powmod(2), i)) % P;
	for(int i = W; i < B + W; i++)
		SW[i] = (SW[i - 1] + (getC(i, W) - getC(i - 1, W)) * powmod(powmod(2), i)) % P;
	//printf("%lld\n", SW[1]);
	for(int i = 0; i < B + W; i++) {
		ll ans = (1 - SB[i] + SW[i]) % P;
		printf("%lld\n", (ans * powmod(2) % P + P) % P);
	}
return 0;
}

Measured memory_bytes: 13440
#include <cstdio>

//using namespace std;

int T[11][11];

int main() {

    int R, C;

    scanf("%d %d", &R, &C);

    for(int i = 0 ; i <= 9; ++i) {
        for(int j = 0 ; j <= 9; ++j) {
            scanf("%d", &T[i][j]);
        }
    }
    for(int k = 0 ; k <= 9; ++k) {
        for(int i = 0 ; i <= 9; ++i) {
            for(int j = 0 ; j <= 9; ++j) {

                if(T[i][j] > T[i][k] + T[k][j]) {
                    T[i][j] = T[i][k] + T[k][j];
                }
            }
        }
    }

    unsigned long long res = 0;

    for(int i = 0 ; i < R; ++i) {
        for(int j = 0 ; j < C; ++j) {
            int d;
            scanf("%d", &d);
            if(d != -1) {
                res += T[d][1];
            }
        }
    }

    printf("%llu\n", res);

    return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
ll A, B, C, K;

int main() {
  INCANT;
  cin >> A >> B >> C >> K;
  
  if (A>=K) cout << K;
  else if (K>A && K<=A+B) cout << A;
  else cout << A-(K-A-B);
  cout << "\n";
  return 0;
}

Measured memory_bytes: 3608
def main():
    n, k = map(int,input().split())
    inlis = list(map(int, input().split()))

    for i in range(k, n):
        if inlis[i-k]< inlis[i]:
            print('Yes')
        else:
            print('No')
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 31540
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        var nk = Console.ReadLine().Split().Select(int.Parse).ToArray();
        long k = nk[1];
        var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        long res = 0;
        for (int i = 0; i < a.Length; i++)
        {
            var cur =
                a.Skip(i).Count(x => x < a[i]) * k +
                a.Count(x => x < a[i]) * ((k * (k - 1) / 2) % 1000000007);
            res += cur % 1000000007;
            res %= 1000000007;
        }
        Console.WriteLine(res);
    }
}


Measured memory_bytes: 13444
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
/* テンプレートここまで */

int main() {
  int r; cin >> r;
  if(r < 1200) cout << "ABC" << endl;
  else if (r < 2800) cout << "ARC" << endl;
  else cout << "AGC" << endl;
}


Measured memory_bytes: 764
//筋肉解法O(K^2)
#include <iostream>
#define int long long
using namespace std;

int mod = 1000000007;
int n, m, k;
int fact[300001], factInv[300001];
int f[2][10001];

int power(int a, int n) { if (n == 0) return 1; if (n & 1) return (a * power(a, n - 1)) % mod; return power((a * a) % mod, n / 2); }
void init() { fact[0] = 1; factInv[0] = 1; for (int i = 1; i <= 300000; i++) { fact[i] = (fact[i - 1] * i) % mod; factInv[i] = power(fact[i], mod - 2); } }
int C(int n, int k) { if (k > n) return 0; return fact[n] * factInv[k] % mod * factInv[n - k] % mod; }

void solve() {
	int dp[20001];	//dp([i])[j] = i回移動して, そのうちj回左に移動した
	int i, j;
	
	dp[0] = 1;
	for (i = 0; i <= 2 * k; i++) {
		if (i % 2 == 0) {
			//位置0->nと移動するときにi / 2回左移動をするが, 位置が負になってはダメ. 移動方法はf[0][i]通り.
			for (j = 0; j <= (i >> 1); j++) f[0][i >> 1] = (f[0][i >> 1] + dp[j] * C(n, (i >> 1) - j)) % mod;
			for (j = 0; j <= (i >> 1); j++) f[1][i >> 1] = (f[1][i >> 1] + dp[j] * C(m, (i >> 1) - j)) % mod;
		}
		for (j = (i == 0 ? -1 : (i - 1) / 2); j >= 0; j--) {
			dp[j + 1] = (dp[j + 1] + dp[j]) % mod;
		}
	}
}

signed main() {
	init();
	cin >> n >> m >> k;
	solve();
	int ans = 0;
	for (int i = 0; i <= k; i++) {
		ans += f[0][i] * f[1][k - i] % mod * C(n + m + 2 * k, n + 2 * i) % mod;
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 7996
#include <iostream>

const int MAX = 100 + 5;
long long a[MAX][MAX], b[MAX][MAX], c[MAX][MAX];

int main()
{
	int n, m, l;
	std::cin >> n >> m >> l;
	for (int i = 0; i != n; ++i) {
		for (int j = 0; j != m; ++j) {
			std::cin >> a[i][j];
		}
	}

	for (int i = 0; i != m; ++i) {
		for (int j = 0; j != l; ++j) {
			std::cin >> b[i][j];
		}
	}

	for (int i = 0; i != n; ++i) {
		for (int j = 0; j != l; ++j) {
			for (int k = 0; k != m; ++k) {
				c[i][j] += a[i][k] * b[k][j];
			}
		}
	}

	for (int i = 0; i != n; ++i) {
		for (int j = 0; j != l; ++j) {
			if (j) std::cout << ' ';
			std::cout << c[i][j];
		}
		std::cout << std::endl;
	}

	return 0;
}


Measured memory_bytes: 3320
n, m = map(int, input().split())
ss = [list(map(int, input().split()[1:])) for _ in range(m)]
p = list(map(int, input().split()))

def is_light(sw, p, state):
    acc = 0
    for s in sw:
        if ((state >> (s-1))& 1) == 1:
            acc += 1
    return acc % 2 == p


ans = 0
for i in range(1<<n):
    for j in range(m):
        if not is_light(ss[j], p[j], i):
            break
    else:
        ans += 1
print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int c=0;
string s,s1;
cin>>s>>s1;
int p=s.size();
for(int i=0;i<p;i++)
{
if(s[i]!=s1[i])
c++;
}
cout<<c<<endl;
	return 0;
}

Measured memory_bytes: 3916
#include <bits/stdc++.h>
using namespace std;
/*int64_t Lucas(int N){
    if(N==0){
        return 2;
    }
    if(N==1){
        return 1;
    }
    
    return Lucas(N-1)+Lucas(N-2);

}*/

int main(){
    int N;
    int64_t L[100];
    cin >>N;
    L[0]=2L;
    L[1]=1L;
    for(int i=2;i<=N;i++){
        L[i]=L[i-1]+L[i-2];
    }
    cout << L[N]<<endl;
    //cout<<Lucas(N)<<endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    template<typename T>
    vector<T> read_vec(size_t n){
        vector<T> tmp(n);
        for(size_t i = 0; i < n; i++){
            cin >> tmp[i];
        }
        return tmp;
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};

int main(){
    Stream io;

    string S;
    io.read(S);
    int ans = -1;
    S.pop_back();
    while(!S.empty()){
        if(S.size() % 2 == 0){
            bool f = true;
            for(int i = 0; i < S.size() / 2; i++){
                if(S[i] != S[i + S.size() / 2]) f = false;
            }
            if(f){
                ans = S.size();
                break;
            }
        }
        S.pop_back();
    }
    cout << ans;
    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()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	vector<double> v(N);
	rep(i, N) cin >> v[i];



	double ans = 0.0;
	for(int _ = 0; _ < N-1; _++){
		sort(v.begin(), v.end());
		double x = v[0], y = v[1];
		v.erase(v.begin());
		v.erase(v.begin());
		v.push_back((x+y) / 2.0);
	}

	cout << v[0] << endl;
}


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

int main() {
    int N;
    cin>>N;
    vector<int> a(N);
    int sum=0;


    int W[N];
    for(int i=0;i<N;i++){
        cin>>a[i];
        sum += a[i];
    }

    int mini = sum;
    int prefix_sum = 0;
    for(int i=0;i<N;i++){
        prefix_sum += a[i];
        mini = min(mini, abs(prefix_sum-(sum-prefix_sum)));
    }
    cout << mini << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
count = 0
scores = {}

for i in range(1, N + 1):
    I = i
    while(i % 2 == 0):
        i /= 2
        count += 1
    i = I
    scores[i] = count
    count = 0

print(max(scores, key = scores.get))

Measured memory_bytes: 9000
#include<stdio.h>

#define N 100000
#define Q 50000

int main(){
  int S[N],T[Q],C=0;
  int l,r,mid,key;
  int n,q,i;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&T[i]);
  }
  for(i=0;i<q;i++){
    key=T[i];
    l=0;
    r=n;
    while(l<r){
      mid=(l+r)/2;
      if(S[mid]==key){
        C++;
        break;
      }
      else if(key<S[mid]){
        r=mid;
      }
      else l=mid+1;
    }
  }
  printf("%d\n",C);
  return 0;
}



Measured memory_bytes: 2324