akhauriyash/Code-Regression huggingface dataset:
def main():
    N, K = map(int,input().split())
    MOD = 10**9+7

    low = []
    lowtotal = 0
    high = []
    hightotal = 0
    for i in range(N+1):
        lowtotal += i
        low.append(lowtotal)
        hightotal += N-i
        high.append(hightotal)

    ans = 0
    for l, h in zip(low[K-1:], high[K-1:]):
        cnt = h-l+1
        ans += cnt
        ans %= MOD
    print(ans)
main()

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

int main(void){
    int  A,B,C,K;
    cin >>A>>B>>C>>K;
    while(A>=B){
        B*=2;
        K--;
    }
    while(B>=C){
       C*=2;
       K--; 
    }
    if(K>=0){cout << "Yes"<<endl;}else{cout <<"No"<<endl;}
}

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


int main() {
  string S;
  cin >> S;
  string A = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  
  if(S[0] != 'A') {
    cout << "WA" << endl;
    return 0;
  }
  
  int c=0;
  for(int i=2; i<S.size()-1; i++) {
    if(S[i] == 'C') c++;
    else {
      for(char a : A) {
        if(S[i] == a) {
          cout << "WA" << endl;
          return 0;
        }
      }
    }
  }
  if(c != 1) {
    cout << "WA" << endl;
    return 0;
  }
  for(char a : A) {
    if(S[1] == a) {
      cout << "WA" << endl;
      return 0;
    }
    if(S[S.size()-1] == a) {
      cout << "WA" << endl;
      return 0;
    }
  }
  cout << "AC" << endl;
  
}


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

int main() {
    int a, b, c, t;
    scanf("%d%d%d%d", &a, &b, &c, &t);
    int n = 0;
    while(b <= a) b *= 2, n ++;
    while(c <= b) c *= 2, n ++;
    if(n <= t) puts("Yes");
    else puts("No");
}


Measured memory_bytes: 3760
import sys
n = int(input())
a_ls = [int(i) for i in sys.stdin.readline().split()]
a_ls.sort()
flg = True
if a_ls[-1] < 0:
    score = - sum(a_ls) + a_ls[-1] * 2
    flg = False
elif a_ls[1] < 0:
    score = sum([abs(a) for a in a_ls])
else:
    score = sum(a_ls) - a_ls[0] * 2
cur = a_ls[0]
last = a_ls[-1]
print(score)
if flg:
    for i in range(1,n):
        a = a_ls[i]
        if a < 0:
            print(last, a)
            last -= a
            continue
        if i < n - 1:
            print(cur, a_ls[i])
            cur -= a_ls[i]
        else:
            print(last, cur)
else:
    for i in range(n-1):
        print(last, a_ls[i])
        last -= a_ls[i]

Measured memory_bytes: 13896
# 1st:0407,2nd-:0408

#ABC041-C
if False:
    N=int(input())
    A=[int(i) for i in input().split()]
    ans=[(i,a) for i,a in enumerate(A)]
    ans.sort(key=lambda x: x[1],reverse=True)
    for i in range(N): print(ans[i][0]+1)

#AGC017-A
if False:
    N,P=map(int,input().split())
    A=[int(i) for i in input().split()]
    flag=True # 偶数のみか
    for a in A:
        if a%2==1:
            flag=False
            break
    if flag:
        if P==0:
            print(2**N)
        else:
            print(0)
    else:
        print(2**(N-1))

#3rd: ABC155-A
if False:
    print('Yes' if len(set(input().split()))==2 else 'No')
#4th: ABC155-B
if True:
    N=int(input())
    A=[int(i) for i in input().split()]
    ans='APPROVED'
    for a in A:
        if a%2==0:
            if not(a%3==0 or a%5==0):
                ans='DENIED'
    print(ans)
#5th

Measured memory_bytes: 3064
t = gets.chomp.to_s
p = gets.chomp.to_s

output = []
t_length = t.length
restart_position = (t_length-1)
while true
  number_position = t.rindex(p, restart_position)
  if number_position == nil
    break
  elsif number_position == 0
    output.push(0)
    break
  else
    output.push(number_position)
    restart_position = number_position-1
  end
end
puts output.reverse

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

int main() {
	ll N;
	cin >> N;
	vector<ll> a(N);
	for(int i=0;i<N;i++)
		cin >> a[i];
	
	vector<ll> left(N+1), right(N+1);
	left[0] = 0;
	right[0] = 0;
	for(int i=0;i<N;i++)
	{
		left[i+1] = max(left[i], a[i]);
		right[i+1] = max(right[i] ,a[N-1-i]);
	}
	for(int i=0;i<N;i++)
	{
		cout << max(left[i], right[N-i-1]) << endl;
	}
}

Measured memory_bytes: 6272
x,*s=open(0)
h,w,k,*m=map(int,x.split())
b=512
while b:
 b-=1;r=t=j=0;d=[0]*h
 while j<w:
  i=c=0
  while h-i:
   d[c]+=s[i][j]>'0';y=t<j
   if d[c]>k:d=[0]*h;r+=1-~-y*h*w;t=j;j-=y;break
   c+=b>>i&1;i+=1
  j+=1
 m+=r+c,
print(min(m))

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

using namespace std;

const int N = 1e5+2;
int n;
long long dp[N],tab[N];


int main(){
    ios_base::sync_with_stdio(0);


    cin >> n;

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

    dp[0] = 0;
    dp[1] = abs(tab[0]-tab[1]);

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

        dp[i] += min(dp[i-1]+abs(tab[i-1]-tab[i]), dp[i-2] + abs(tab[i-2]-tab[i]));
    }

    cout << dp[n-1];


}

Measured memory_bytes: 1792
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String A=sc.next(),B=sc.next(),C=sc.next();
    System.out.println(A.charAt(A.length()-1)==B.charAt(0)&&B.charAt(B.length()-1)==C.charAt(0)?"YES":"NO");
    sc.close();
  }
}



Measured memory_bytes: 21844
N = int(input())
A = list(map(int, input().split()))
total = 0
p = 0
for a in A:
    total += abs(p-a)
    p = a
total += abs(p)

print(total - abs(A[0]) - abs(A[0]-A[1]) + abs(A[1]))
for n in range(1,N-1):
    print(total - abs(A[n-1]-A[n]) - abs(A[n]-A[n+1]) + abs(A[n-1]-A[n+1]))
print(total - abs(A[N-2]-A[N-1]) - abs(A[N-1]) + abs(A[N-2]))

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

int main(void)
{
    using namespace std;

    int n, m;
    scanf("%d %d", &n, &m);
    int A[n][m];
    int B[m];

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            scanf("%d", &A[i][j]);
        }
    }

    for (int i = 0; i < m; i++) {
        scanf("%d", &B[i]);
    }

    int res = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            res += A[i][j] * B[j];
        }
        printf("%d\n", res);
        res = 0;
    }

}


Measured memory_bytes: 3224
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1000000007
using ll = long long;
using namespace std;
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;
}

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

    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    for (auto &i : S) {
        cin >> i;
    }

    auto sum  = vector<vector<int>>(H, vector<int>(W, -1));
    auto tate = vector<vector<int>>(H, vector<int>(W));
    auto yoko = tate;

    // 横の計算
    REP(i, H) {
        int cnt = 0;
        REP(j, W) {
            if (S[i][j] == '#') {
                cnt = 0;
                continue;
            }
            cnt++;
            yoko[i][j] = cnt;
        }
    }
    RREP(i, H - 1) {
        int mx = 0;
        RREP(j, W - 1) {
            if (S[i][j] == '#') {
                mx = 0;
                continue;
            }
            if (mx == 0) {
                mx = yoko[i][j];
            }
            yoko[i][j] = mx;
        }
    }

    // 縦の計算
    REP(j, W) {
        int cnt = 0;
        REP(i, H) {
            if (S[i][j] == '#') {
                cnt = 0;
                continue;
            }
            cnt++;
            tate[i][j] = cnt;
        }
    }
    RREP(j, W - 1) {
        int mx = 0;
        RREP(i, H - 1) {
            if (S[i][j] == '#') {
                mx = 0;
                continue;
            }
            if (mx == 0) {
                mx = tate[i][j];
            }
            tate[i][j] = mx;
        }
    }

    int ans = 0;
    REP(i, H) {
        REP(j, W) {
            sum[i][j] += yoko[i][j] + tate[i][j];
            chmax(ans, sum[i][j]);
        }
    }

    std::cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 51584
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
 
    public static void main(String[] args) throws NumberFormatException, IOException {
        // TODO Auto-generated method stub
        int n;
        String[] token;
        int rank;
        boolean[] S = new boolean[13]; 
        boolean[] H = new boolean[13]; 
        boolean[] C = new boolean[13]; 
        boolean[] D = new boolean[13];
         
        for (int i = 0; i < 13; i++) {
            S[i] = H[i] = C[i] = D[i] = false;
        }
         
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        n = Integer.parseInt(br.readLine());
         
        for (int i = 0; i < n; i++) {
            token = br.readLine().split(" ");
            rank = Integer.parseInt(token[1]);
            if (token[0].equals("S")) {
                S[rank - 1] = true;
            } else if (token[0].equals("H")) {
                H[rank - 1] = true;
            } else if (token[0].equals("C")) {
                C[rank - 1] = true;
            } else if (token[0].equals("D")) {
                D[rank - 1] = true;
            }
        }
         
        for (int i = 0; i < 13; i++) {
            if (!S[i]) System.out.println("S " + (i + 1));
        }
        for (int i = 0; i < 13; i++) {
            if (!H[i]) System.out.println("H " + (i + 1));
        }
        for (int i = 0; i < 13; i++) {
            if (!C[i]) System.out.println("C " + (i + 1));
        }
        for (int i = 0; i < 13; i++) {
            if (!D[i]) System.out.println("D " + (i + 1));
        }
    }
}

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

bool comp(pair<string, pair<int, int>> a, pair<string, pair<int, int>> b) {
    if (a.first != b.first)
        return a.first < b.first;
    else
        return a.second.first > b.second.first;
}

int main(void){
    int N;
    cin >> N;
    vector<pair<string, pair<int, int>>> pairs(N);
    for (int i = 0; i < N; i++) {
        string s;
        int p;
        cin >> s >> p;
        pairs[i] = make_pair(s, make_pair(p, i+1));
    }
    sort(pairs.begin(), pairs.end(), comp);
    
    for (int i = 0; i < N; i++)
        cout << pairs[i].second.second << endl;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;  //ひなあられの数
  cin >> N;  //入力
  bool flag = false;  //ひなあられの種類は4種類かどうか（false:3種類、true:4種類）
  
  //N個のあられを入力
  for (int i = 0; i < N; i++){
  	string arare;  //あられの文字
    cin >> arare;  //入力
    
    if (arare == "Y"){
      flag = true;
    }
  }
  
  //flagの値によって、3種類か4種類か判別する
  if (flag){
  	cout << "Four" << endl;
  } else {
  	cout << "Three" << endl;
  }
  
  
}

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

int main()
{
	int nishin[] = {1,2,4,8,16,32,64,128,256,512};
	int n;
	vector<int> result;

	while(cin >> n) {
		result.clear();
		while(true) {
			if(n<=0) break;
			if(n%2 == 1) result.push_back(1);
			else		 result.push_back(0);
			n /= 2;
		}

		for(int i=0;i<result.size();i++) {
			if(result[i] == 1 && i<result.size()-1) 
				cout << pow(2,i) << ' ';
			else if(result[i] == 1)
				cout << pow(2,i);
		}
		cout << '\n';
	}

	return 0;
}

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

using ll = long long;
#define REP(i, n) for(int (i)=0; (i)< (n); ++i)
#define REPR(i, n) for(int (i)=(n); (i)>=0; --i)
#define FOR(i, n, m) for(int (i)=(n); (i)<(m); ++i)
constexpr int INF = 1e9;
//constexpr ll INF = 1LL << 61;
//constexpr int mod = 1e9+7;
constexpr ll mod = 998244353;

int main(){
  ll X, M;
  ll N;
  cin >> N >> X >> M;
  vector<ll> A;
  vector<ll> sum(1, 0);
  map<ll, ll> mp;
  ll x = X;
  ll ans = 0;
  int roop = 1;
  while(N){
    if(mp[x]){
      ll add = sum[roop-1] - sum[mp[x]-1];
      int kukan = roop-1 - (mp[x]-1);
      ans += add * (N / kukan);
      N %= kukan;
      break;
    }
    ans += x;
    mp[x] = roop;
    A.push_back(x);
    sum.push_back(sum[roop-1] + x);
    N--;
    roop++;
    x = (x*x) % M;
  }
  REP(i, N){
    ans += x;
    x = (x*x) % M;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 7228
#include <bits/stdc++.h>
#define lp(n) for(int i = 0; i < n; i++)
#define lpp(i, n) for(int i = 0; i < n; i++)
int partition(int A[], int p, int r) {
  int t;
  int x = A[r];
  int i = p - 1;
  for(int j = p; j < r; j++) {
    if(A[j] <= x) {
      i++;
      t = A[i];
      A[i] =  A[j];
      A[j] = t;
    }
  }
  t = A[i+1];
  A[i+1] =  A[r];
  A[r] = t;
  return i+1;
}
using namespace std;
int main() {
  int n;
  int c;
  int *A;
  cin >> n;
  A = (int *)malloc(n *sizeof(int));
  lp(n) cin >> A[i];
  c = partition(A, 0, n-1);
  lp(c) cout << A[i] << " ";
  cout<< '[' << A[c] << "] ";
  for(int i = c+1; i < n-1; i++) cout << A[i] << " ";
  cout << A[n-1] << endl;
  return 0;
}




Measured memory_bytes: 3400
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (int i = 0; i < n; i++)
#define IREP(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(a, b) for (int i = a; i < b + 1; i++)
#define all(a) a.begin(),a.end()
#define MOD 1000000007
#define int long long
using namespace std;
typedef long long ll;

signed main() {
	int n;
	cin >> n;
	vector<ll> h(n);
	REP(i,n){
		cin >> h[i];
	}
	if(n==1){
		cout << "Yes" << endl;
		return 0;
	}
	for(int i=n-1;i>=1;i--){
		if(h[i]<h[i-1]){
			if(h[i]==h[i-1]-1){
				h[i-1]--;
			}
			else{
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 1024
N = int(input())
h = list(map(int,input().split()))

l = list(set(h))
l.sort()
a = []
for i in range(len(l)):
    a.append(h.count(l[i]))
ans = 0
for i in range(len(l)):
    for j in range(i+1, len(l)):
        for k in range(j +1, len(l)):
            if l[i] + l[j] > l[k]:
                ans += a[i] * a[j] * a[k]
print(ans)

Measured memory_bytes: 9136
//#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

int daishou[200002];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int N = getint();
	int A[200001];
	rep1(i, N) A[getint()] = i;

	ll kotae = 0;
	for (int i = N; i > 0; i--) {
		int a = A[i];
		int l = daishou[a - 1];
		if (!l) l = a;
		int r = daishou[a + 1];
		if (!r) r = a;
		kotae += (ll)(a - l + 1) * (r - a + 1) * i;
		daishou[l] = r;
		daishou[r] = l;
	}

	printf("%lld", kotae);

	Would you please return 0;
}

Measured memory_bytes: 1792
fun main(args:Array<String>) {
    val input = readLine()!!
    assert(input.length == 4)
    val (A,B,C,D) = input.map{it.toInt()-'0'.toInt()}
    0.until(8).map { n->
       0.until(3).map { i->
         if((n and (1 shl i)) > 0) {1} else {-1}
       }
    }.filter { A + it[0] * B + it[1] * C + it[2] * D == 7}.let {
        assert(it.size !=0)
        val opr = it[0].map {pm -> if(pm==1) {"+"} else {"-"}}
        println("${A}${opr[0]}${B}${opr[1]}${C}${opr[2]}${D}=7")
    }
}

Measured memory_bytes: 33444
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 解説通りに実装したソースコード
 */
public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int[] a = new int[n + 1];
			a[0] = 0;
			IntStream.rangeClosed(1, n).forEach(i -> a[i] = scanner.nextInt());
			Arrays.sort(a);
			System.out.println(IntStream.range(1, n).mapToLong(k -> a[n - k / 2]).sum());
		}
	}
}


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

class par
{
 public:
 int value;
 int pos;
};
bool comp(par a, par b)
{
if(a.value<b.value)return true;
return false;
};
int main()
{
    int n;
    cin>>n;
    vector<par>v (n);
    for(int i=0 ; i<n;i++)
        {
            int temp;
            cin>>temp;
            v[i].pos=i;
            v[i].value=temp;
        }
    sort(v.begin(), v.end(), comp);
     int times=0;

     for(int i=0 ; i<n;i+=2)
     {
      {
          if(i%2!=v[i].pos%2)
            times++;
      }

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



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

#define ll long long int
#define int long long int
#define pb push_back
#define p1da(a,n) for(int i=0;i<(n);i++) cout << *( (a) + (i))<<" "; cout<<endl;
#define g1da(a,n) for(int i=0;i<(n);i++) cin >> *( (a) + (i)) ;
#define fi first
#define se second
#define f(i,n) for(int (i)=0;(i)<(n) ; (i)++ )
#define fr(i,s,e) for(int (i)=s;(i)<=(e) ; (i)++ )
#define pii pair <int,int>
#define p2da(a,row,col) f(i,row){f(j,col) cout << a[(i)][(j)]  <<" "; cout<<endl; }
#define g2da(a,row,col) f(i,row) f(j,col) cin >> a[(i)][(j)] ;
#define p1dv(v) f(i,v.size())cout<<v[(i)]<<" "; cout << endl ;
#define g1dv(v) f(i,v.size()) cin>>v[i] ;
#define debug(...)       dbg (#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void dbg(const char* n, Arg1&& arg1){cerr<<n<< " : "<<arg1<<endl;}
template <typename Arg1,typename... Args>
void dbg(const char* n,Arg1&& arg1, Args&&... args){const char*c=strchr(n+1,',');cerr.write(n,c-n)<<" : "<<arg1<<" || ";dbg(c+1,args...);}
clock_t startTime ;void mainstart(); void mainEnd();



signed main()
{
  //  mainstart() ;
    
    int n , a,b;
    cin >> n >> a >> b ;
    int d = abs(a-b);

    if(d%2==0)
    {
        cout << d/2 ;
    }  
    else
    {
        cout <<  min( a + d/2 , n - b + 1 + d/2 ) ;
    }


  




    
 //   mainEnd() ;
    return 0 ;
}
 


void mainstart()
{
    #ifndef ONLINE_JUDGE 
    freopen("Input.txt","r",stdin) ;
    freopen("Output.txt","w",stdout) ;
    #endif
    startTime = clock() ;
}
void mainEnd()
{
    clock_t endTime = clock() ;
    cerr << "Run Time is : " << (float)( endTime - startTime ) / CLOCKS_PER_SEC << endl ;    
}







Measured memory_bytes: 256
import bisect,itertools
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort()
b.sort()
c.sort()
ba = []
for i in b:
    ba.append(bisect.bisect_left(a, i))
accba = list(itertools.accumulate(ba))#累積和
ans = 0
for i in c:
    tmp = bisect.bisect_left(b,i)
    if tmp==0: continue
    ans += accba[tmp-1]

print(ans)

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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
ll MOD = 1e9+7;
ll INF = 1e18;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }

int main(){
  ll i, j;
  
  ll n;
  cin >> n;
  vector<ll> a(n), b(n);
  for(i = 0; i < n; i++)
    cin >> a[i];
  
  ll count = 0;
  bool judge = false;
  for(i = 0; i < n; i++){
    if(a[i] < 0)
      count++;
    if(a[i] == 0)
      judge = true;
    b[i] = abs(a[i]);
  }
  sort(ALL(b));
  ll result = 0; 
  //cout << count spa judge << endl;
  
  if(count % 2 == 1 && !judge){
    i = 1;
    result -= b[0];
  }
  else
    i = 0;
  
  for(; i < n; i++)
    result += b[i];
    
  cout << result << endl;

  return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <unordered_map>
using namespace std;

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

const int maxn = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int Mod = 1000000007;
#define dbg(x1) cout<<#x1<<" = "<<(x1)<<endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<(x1)<<" "<<#x2<<" = "<<(x2)<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<(x1)<<" "<<#x2<<" = "<<(x2)<<" "<<#x3<<" = "<<(x3)<<endl
int x[maxn],y[maxn];
int main() {
    //freopen(".in", "r", stdin);
    int n,m;scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) scanf("%d",&x[i]);
    for(int i=1;i<=m;i++) scanf("%d",&y[i]);
    ll s1=0,s2=0;
    for(int i=1;i<=n-1;i++) s1=(s1+1LL*i*(n-i)%Mod*(x[i+1]-x[i])%Mod)%Mod;
    for(int i=1;i<=m-1;i++) s2=(s2+1LL*i*(m-i)%Mod*(y[i+1]-y[i])%Mod)%Mod;
    printf("%lld\n",(s1*s2)%Mod);
    return 0;
}



Measured memory_bytes: 1024
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <regex>
#include <string>
#include <stack>
#include <utility>
#include <vector>

#include <random>

using namespace std;
using ll = long long;


int main()
{
	string s;
	cin >> s;
	s[5] = ' ';
	s[13] = ' ';

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


Measured memory_bytes: 384
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int n = sc.nextInt();
			if(n == 0) break;
			int sum = 0 ;
			for(int i = 0 ; i < n/4 ;i++){
				sum += sc.nextInt();
			}
			System.out.println(sum);
		}
		sc.close();
	}

}

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

const int N = 2e5 + 5;
int n, m, a[N];

bool check(int x) {
    int y = m;
    for (int i = 1; i <= n; i++){
        y -= (a[i] - 1) / x;
    }
    return y >= 0;
}

int main() {
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    sort(a + 1, a + n + 1);
    int l = 1, r = 1e9, ans = 0;
    while(l <= r) {
        int mid = (l + r) >> 1;
        if(check(mid)) {
            ans = mid; r = mid - 1;
        } else l = mid + 1;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 4440
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int n,i,a,ans = 0;cin >> n;vector<int> safe{0};
    for(i=1;i<=n;i++){
        cin >> a;
        if(a == 0) safe.push_back(i);
    }
    safe.push_back(n+1);
    for(i=1;i<safe.size();i++){
        ans = max(ans,safe[i]-safe[i-1]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3148
#include<cstdio>
int main(){
    int w,h,x,y,r;
    scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);
    if(0<=x-r && 0<=y-r && x+r<=w && y+r<=h){
            printf("Yes\n");
    }else {
        printf("No\n");
    }
}

Measured memory_bytes: 2584
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 s = sc.next();
		String s = "Christmas";
		int[] p = new int[n];
		int sum = 0;
		for(int i = 0 ; i < n ; i++) {
			p[i] = sc.nextInt();
			sum += p[i];
		}
		Arrays.sort(p);
		sum -= p[n - 1] / 2;

		System.out.println(sum);

	}
}



Measured memory_bytes: 35832
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
signed main(){
  int n,k;cin>>n>>k;
  vector<int> h(n);
  rep(i,n)cin>>h[i];
  sort(h.begin(),h.end());
  int sum=0;
  rep(i,n-k){
    sum+=h[i];
  }
  cout<<sum<<endl;
  return 0;
}

Measured memory_bytes: 1792
def getsum(x, n):
    ans = 0
    acu = 0
    for i in range(n // 2):
        acu += (x[n - i - 1] - x[i])
        ans = (ans + acu) % 1000000007
    if n % 2 == 0:
        ans = ans * 2 - acu
    else:
        ans = ans * 2
    return ans % 1000000007

n, m = (int(i) for i in input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

print(getsum(x, n) * getsum(y, m) % 1000000007)


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

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
const int inf = 1000000001;
const ll INF = 1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<<fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a == b) {
		cout << c << endl;
	}
	else if (a == c) {
		cout << b << endl;
	}
	else {
		cout << a << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import sys

input = sys.stdin.readline

n, m = map(int, input().split())
s_list = [list(map(int, input().split())) for _ in range(m)]
p_list = list(map(int, input().split()))
patterns = []
for i in range(2**n):
    patterns.append(bin(i)[2:].zfill(n))
cnt = 0
for pattern in patterns:
    flag = 1
    for s, p in zip(s_list, p_list):
        if sum([int(pattern[i-1]) for i in s[1:]]) % 2 != p:
            flag = 0
            break
    if flag == 1:
        cnt += 1
print(cnt)


Measured memory_bytes: 3316
import sys
import numpy as np
import math  # gcdもあるよ
from collections import deque
from collections import defaultdict
from copy import deepcopy
from itertools import accumulate #リストを与えると累積和を返す
def input(): return sys.stdin.readline().rstrip()
from functools import lru_cache #メモ化
INF = 10**9 + 7
mod = 10**9 + 7

def main():
    S = list(input())
    #print(S)
    if S[-1] != 's':
        S.append('s')
    else: S.append('es')
    #print(S)
    print(''.join(S))
    return 0

if __name__ == "__main__":
    main()

Measured memory_bytes: 27160
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, start, n) for (int i = (int)(start); i < (int)(n); ++i)
static const int INFTY = (1 << 30);
int X;
void func()
{
    cin >> X;
    int ans;
    while (1)
    {
        bool check = true;
        rep(i, 2, sqrt(X) + 1)
        {
            if (X % i == 0)
            {
                check = false;
                break;
            }
        }
        if (check)
        {
            cout << X << endl;
            return;
        }
        ++X;
    }
}
int main()
{
    func();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define N 1000005
using namespace std;

typedef long long ll;

int n, x, y;
char s[N];

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	scanf("%d %s",&n,s + 1);
	for(int i = 1; i <= n; i++)
		if(s[i] == 'R')
			x++;
		else
			y++;
	if(x > y)
		puts("Yes");
	else
		puts("No");
	
	return 0;
}

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}

struct Solver {
    int N, M, Q;
    vector<vector<int>> v;

    Solver() {
        cin >> N >> M >> Q;
        v = vector<vector<int>>(Q, vector<int>(4));
        REP(i, Q){
            REP(j, 4){
                cin >> v[i][j];
            }
        }
    }

    int calc(const vector<int>& val) {
        int res = 0;
        REP(i, Q){
            int a = v[i][0], b = v[i][1], c = v[i][2], d = v[i][3];
            if(val[b-1] - val[a-1] == c){
                res += d;
            }
        }
        return res;
    }

    int recursive(int n, int k, vector<int>& val) {
        if(n == 0){
            return calc(val);
        }
        int res = 0;
        FOR(i, 1, k+1){
            val[n-1] = i;
            chmax(res, recursive(n-1, i, val));
        }
        return res;
    }

    void solve(){
        vector<int> val(N);
        cout << recursive(N, M, val) << endl;
    }
};

signed main(){
    Solver S;
    S.solve();
    return 0;
}


Measured memory_bytes: 3628
function Main(input) {
  input = input.trim()
  input = input.split(" ").map(Number);
if(input[0]>=input[2]){

console.log("delicious")
}else if(input[0]+input[1]>=input[2]){
console.log("safe")
}else{
console.log("dangerous")
}
}Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
N = int(input())
S = input()

roop = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]

out = 0

for i in roop:
    keta1 = S.find(i)
    if keta1 > N - 3 or keta1 == -1:
        continue
    else:
        S2 = S[keta1 + 1 :]
    for j in roop:
        keta2 = S2.find(j)
        if keta2 > len(S2) - 2 or keta2 == -1:
            continue
        else:
            S3 = S2[keta2 + 1 :]
        for k in roop:
            keta3 = S3.find(k)
            if keta3 != -1:
                out = out + 1
print(out)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
using namespace std;
typedef pair<ll, ll> pll;


ll a,b;
int main()
{
        cin >> a >> b;
        cout << max(a+b, max(a-b, (a*b))) << endl;
        return 0;
}


Measured memory_bytes: 256
N, Q = map(int, input().split())
S = input()

cum, now, bef = [], 0, False

for c in S:
    if bef and c == 'C':
        now += 1
    cum.append(now)
    if c == 'A':
        bef = True
    else:
        bef = False

for _ in range(Q):
    l, r = map(int, input().split())
    print(cum[r-1] - cum[l-1])


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

#define MOD 1000000007
#define MAX 200105
#define ll long long
#define slld(t) scanf("%lld",&t)
#define sd(t) scanf("%d",&t)
#define ss(x) scanf("%s",x)
#define pd(t) printf("%d\n",t)
#define plld(t) printf("%lld\n",t)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define mp(a,b) make_pair(a,b)
#define FF first
#define SS second
#define pb(x) push_back(x)
#define vi vector<int>
#define vpii vector<pii >
#define vll vector<ll>
#define clr(x) memset(x,0,sizeof(x))

#define FILEIO(name) \
    freopen(name".in", "r", stdin); \
    freopen(name".out", "w", stdout);

using namespace std;

ll solve(ll a,ll b,ll n){
	if(a==1 && b==1){
		return 0;
	}
	if(a==n && b==n){
		return 0;
	}
	ll d = b-a;
	ll odd = d%2;
	if(a==1){
		if(odd) return 1 + solve(a,b-1,n);
		return d/2;
	}
	if(b==n){
		if(odd) return 1 + solve(a+1,b,n);
		return d/2;
	}
	ll ans = MOD*1LL*MOD;
	ll ans2 = min(a-1+solve(1,b-a+1,n),n-b+solve(a+n-b,n,n));
	if(!odd){
		ans = d/2;
	}
	return min(ans, ans2);
}

int main(){
	ll n,a,b;
	cin>>n>>a>>b;
	plld(solve(a,b,n));
}

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

using namespace std;

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

	vector<pair<int, int> > a(n);
	for(int i=0; i<n; ++i) {
		cin >> a[i].first;
		a[i].second=i+1;
	}

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

	for(auto i:a){
		cout << i.second << " ";
	}
	cout << endl;

	return 0;

}




Measured memory_bytes: 1536
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// ?¨??????\???????????????????????????????????????
Scanner sc= new Scanner(System.in);
int w = sc.nextInt();
int n = sc.nextInt();
int[] values = new int[w];
for(int i= 0; i< values.length; i++) {
values[i] = i+ 1;
}
for(int i= 0; i< n; i++) {
String str= sc.next();
String[] ab = str.split(",");
int a = Integer.parseInt(ab[0]) -1;
int b = Integer.parseInt(ab[1]) -1;
// a??¨b????????£???values??????????????????
int x = values[a];
values[a]=values[b];
values[b]= x;
}

// values??????????????????
for(int z =0;z<w;z++){System.out.println(values[z]);}
}
}

Measured memory_bytes: 17200
#include <bits/stdc++.h>
#define sanyes ios_base::sync_with_stdio(0), cout.tie(0); cin.tie(0);
#define llong long long
#define pb push_back
#define bpc __builtin_popcount

const llong mxn = 1e5 + 7;
const llong mod = 1e9 + 7;
const llong inf = 1e18 + 9;

using namespace std;

char c[1001][1001];

llong n, m, dp[1001][1001], used[mxn];
vector <llong> v, g[mxn];

int main (){
    cin >> n >> m;
    for (int i = 1; i <= n; i ++){
        for (int j = 1; j <= m; j ++){
            cin >> c[i][j];
        }
    }if(c[1][1] != '#'){
        dp[1][1] = 1;
    }for (int i = 1; i <= n; i ++){
        for (int j = 1; j <= m; j ++){
            if(i == 1 && j == 1) continue;
            if(c[i][j] != '#'){
                dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod;
            }
        }
    }cout << dp[n][m] % mod;
    return 0;
}


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

int main(){
    string s;
    cin >> s;
    int b,e;
    for(int i=0; i<(int)s.length(); i++){
        if(s[i]=='A'){
            b=i;
            break;
        }
    }
    for(int i=s.length()-1; i>=0; i--){
        if(s[i]=='Z'){
            e=i;
            break;
        }
    }
    cout << e-b+1 << endl;
    return 0;
}

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

int main() {
    int n;
    std::cin >> n;
    std::cin.ignore();

    std::string s;
    for (int i = 0; i < n; i++) {
        int out = 0;
        int runner = 0;
        int score = 0;
        while (out < 3) {
            std::getline(std::cin, s);
            if (s == "HIT") {
                runner++;
                if (runner > 3) {
                    score++;
                    runner = 3;
                }
            } else if (s == "HOMERUN") {
                score += runner + 1;
                runner = 0;
            } else if (s == "OUT") {
                out++;
            }
        }
        std::cout << score << std::endl;
    }
}

Measured memory_bytes: 2952
#include <bits/stdc++.h>
//登録しよう！→ https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define gre greater //sortを降順にする
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示

void solve(long long K, long long X){
  for (int i = 0; i < 1+((K-1)*2); i++) {
    cout << X-(K-1) + i;
    if(i != ((K-1)*2))cout << " ";
  }
  cout << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long K;
    scanf("%lld",&K);
    long long X;
    scanf("%lld",&X);
    solve(K, X);
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
using namespace std;
typedef long long int ll;
set <int> s;
int main(){
	int n; cin >> n;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	for(int i=0;i<n;i++){
		s.insert(a[i]);
		if(a[i]!=0){
			if(i<n-1){
				s.insert(a[i]*10+a[i+1]);
			}
			if(i<n-2){
				s.insert(a[i]*100+a[i+1]*10+a[i+2]);
			}
		}
	}
	for(int i=0;i<=999;i++){
		if(s.find(i)==s.end()){
			cout << i << endl;
			return 0;
		}
	}
}



Measured memory_bytes: 3140
nyuryoku=int(input())
lunlun=[["1","2","3","4","5","6","7","8","9"],[],[],[],[],[],[],[],[],[]]
numbers=[["0","1"],["0","1","2"],["1","2","3"],["2","3","4"],["3","4","5"],["4","5","6"],["5","6","7"],["6","7","8"],["7","8","9"],["8","9"]]

for i in range(9):
    for j in lunlun[i]:
        if j[-1]=="0":
            for k in numbers[0]:
                lunlun[i+1].append(j+k)
        elif j[-1]=="1":
            for k in numbers[1]:
                lunlun[i+1].append(j+k)
        elif j[-1]=="2":
            for k in numbers[2]:
                lunlun[i+1].append(j+k)
        elif j[-1]=="3":
            for k in numbers[3]:
                lunlun[i+1].append(j+k)
        elif j[-1]=="4":
            for k in numbers[4]:
                lunlun[i+1].append(j+k)
        elif j[-1]=="5":
            for k in numbers[5]:
                lunlun[i+1].append(j+k)
        elif j[-1]=="6":
            for k in numbers[6]:
                lunlun[i+1].append(j+k)
        elif j[-1]=="7":
            for k in numbers[7]:
                lunlun[i+1].append(j+k)
        elif j[-1]=="8":
            for k in numbers[8]:
                lunlun[i+1].append(j+k)
        elif j[-1]=="9":
            for k in numbers[9]:
                lunlun[i+1].append(j+k)

newrunrun=[]
for i in range(len(lunlun)):
    newrunrun+=lunlun[i]
newlunlun=list(map(int,newrunrun))
newlunlun.sort()
print(newlunlun[nyuryoku-1])

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

using lint = long long;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<vector<T>>;
template <typename T> using VVV = vector<vector<vector<T>>>;
#define rep(i, n) for(int i = 0; i < int(n); i++)
#define repu(i, a, b, s) for(int i = int(a); i < int(b); i += int(s))
#define repd(i, a, b, s) for(int i = int(a); i > int(b); i += int(s))
#define endl "\n"
constexpr lint INF = 2e18;
constexpr lint MOD = 1e9 + 7;

void solve() {
    lint D, N;
    cin >> D >> N;
    lint ans;
    lint cnt = 0;
    repu(i, 1, 1e7, 1) {
        if(D == 0) {
            if(i % 100 != 0) {
                cnt++;
            }
        } else if(D == 1) {
            if(i % 100 == 0 and i % 10000 != 0) {
                cnt++;
            }
        } else if(D == 2) {
            if(i % 100 == 0 and i % 10000 == 0 and i % 1000000 != 0) {
                cnt++;
            }
        }

        if(cnt == N) {
            ans = i;
            break;
        }
    }

    cout << ans << endl;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    solve();
}

Measured memory_bytes: 3636
n=int(input())
a=[]
syougen=[]
for i in range(n):
  a+=[int(input())]
  syougen+=[[list(map(int,input().split()))for j in range(a[-1])]]
for i in range(n):
  for j in range(a[i]):
    syougen[i][j][0]-=1
honest=0
for i in range(2**n):
  t=[0]*(n-len(str(bin(i)))+2)+list(map(int,str(bin(i))[2:]))
  flag=1
  for j in range(n):
    if t[j]:
      for k in range(a[j]):
        if t[syougen[j][k][0]]!=syougen[j][k][1]:flag=0
  if flag:
    if honest<t.count(1):honest=t.count(1)
print(honest)

Measured memory_bytes: 3064
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <map>
using namespace std;
typedef long long int64;
typedef pair<int64, int64> pll;


int main(){
	int A,B,C,K;
	scanf("%d%d%d%d",&A,&B,&C,&K);
	int ret = 0;
	int a = 0, b = 0, c = 0;
	if(K > 0){
		a = min(A,K);
		K -= a;
	}

	if(K > 0){
		b = min(B,K);
		K -= b;
	}

	if(K > 0){
		c = min(C,K);
		K -= c;
	}
	int ans = a-c;
	printf("%d\n",ans);
}



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

int main() {
  string n;
  cin >> n;
  int ans=0;
  rep(i,4){
    if(n.at(i)=='2'){
      ans++;
    }
  }
 
  cout<<ans<<endl;  
}



Measured memory_bytes: 256
N = int(input())
tmp = input()
H = [int(x.strip()) for x in tmp.split(' ')]
n = 0
lists = list()
lists.append(0)
count = 0
while n <= N-2:
    if H[n] >= H[n+1]:
        while H[n] >= H[n+1]:
            count += 1
            n += 1
            if n == N-1:
                lists.append(count)
                break
        lists.append(count)
        count = 0
    else:
        n += 1
print(max(lists))

Measured memory_bytes: 15192
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const double PI = acos(-1);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////
 
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N,K; cin >> N >> K;

    cout << ((N%K) ? 1 : 0) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define scan1(a) scanf("%d",&a);
#define scan2(a,b) scanf("%d %d",&a,&b);
#define loop(i,j) for(int i=0;i<j;i++)
using namespace std;

int main()
{
  int N,K;
  scan2(N,K);
  int v[N];
  loop(i,N) scan1(v[i]);
  sort(v,v+N);
  int mi=INT_MAX;
  loop(i,N-K+1){
    if(mi>v[i+K-1]-v[i]) mi=v[i+K-1]-v[i];
  }
  printf("%d\n",mi);
  return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
typedef long long ll;
using namespace std;

int main(void) {
  ll i, j, k, a = 0, b = 0, c, n, m;
  char s[100010];
  scanf("%s", s);
  n = strlen(s);
  for(i = 0; i < n; ++i) {
    if(s[i] == '0') ++a;
    else ++b;
  }
  printf("%lld", a < b ? a * 2 : b * 2);
  return 0;
}

Measured memory_bytes: 256
from math import atan, degrees

a, b, x = map(int, input().split())
if x <= (a**2 * b) / 2:
    print(90.0 - degrees(atan(2*x / (a*(b**2)))))
else:
    print(degrees(atan((2*(a**2 * b - x) / a**3))))

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

#define mp make_pair
#define X first
#define Y second
#define FOE(x, a) for(auto x : a)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define FOD(i, a, b) for(int i = a; i >= b; i--)

using namespace std;

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

const int N = 5010;
const ll INF = 1e18;

int n, a[N];
vector <int> adj[N];

int sz[N];
ll f[N][N], g[N][N]; /// f : sum; g : min
ll tmpF[N], tmpG[N];

void dfs(int u, int p){
    f[u][0] = g[u][0] = a[u];
    sz[u] = 1;

    for(int v : adj[u])
        if (v != p){
            dfs(v, u);
            FOR(i, 0, sz[u] + sz[v] - 1){
                tmpF[i] = INF;
                tmpG[i] = -INF;
            }
            FOR(x, 0, sz[u] - 1)
                FOR(y, 0, sz[v] - 1){
                    tmpF[x + y] = min(tmpF[x + y], f[u][x] + f[v][y]);
                    tmpG[x + y] = max(tmpG[x + y], min(g[u][x], g[v][y]));
                    if (f[v][y] < 0 || g[v][y] > 0){
                        tmpF[x + y + 1] = min(tmpF[x + y + 1], f[u][x]);
                        tmpG[x + y + 1] = max(tmpG[x + y + 1], g[u][x]);
                    }
                }

            sz[u] += sz[v];
            FOR(i, 0, sz[u] - 1){
                f[u][i] = tmpF[i];
                g[u][i] = tmpG[i];
            }
        }
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    FOR(i, 1, n)
        cin >> a[i];
    FOR(i, 1, n - 1){
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    dfs(1, -1);
    int ans = n - 1;
    FOR(i, 0, n - 1)
        if (f[1][i] < 0 || g[1][i] > 0)
            ans = min(ans, i);

    cout << ans;

    return 0;
}



Measured memory_bytes: 206944
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

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

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

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

    int q;
    cin >> q;

    map<string, int> mp;
    while(q--){
        int m, x;
        string k;
        cin >> m;

        if(m == 0){
            cin >> k >> x;
            mp[k] = x;
        }else if(m == 1){
            cin >> k;
            cout << mp[k] << endl;
        }else if(m == 2){
            cin >> k;
            auto it = mp.find(k);
            if(it != mp.end()){
                mp.erase(it);
            }
        }
    }

    return 0;
}


Measured memory_bytes: 25908
#include<bits/stdc++.h>
using namespace std;
vector <int > sam({0,2,5,5,4,5,6,3,7,6});
vector <pair<int , int > > allowed;

string find_max(string &curr,string  &temp){
	int sz =(int) curr.size();
	int tsz= (int) temp.size();
	bool flg = false;
	if(tsz > sz){
		flg = true ;
	}
	else if(tsz == sz ){
		
		for(int i = 0 ; i < sz ; i++){
			int a = curr[i]-'0';
			int b = temp[i]-'0';
			
			if(a > b)
				break ;
			if( a < b){
				flg = true ;
				break ;
			}
		}
	}
	
	if(flg )
		return temp;
	return curr ;
}

int main(){
	
	/* 5
	 * 117
	 * 711
	 * */
	 
	 int n, m;
	 scanf("%d%d",&n,&m);
	 
	 for(int i = 0 ; i< m ; i++){
		int temp ;
		scanf("%d",&temp);
		allowed.emplace_back(temp,sam[temp]);
	}

	const int nax = 1e4+5;
	vector < string > dp(nax,"");
	for(auto x : allowed){
		char value = x.first + '0';
		int cost = x.second;
		for(int i = 1; i <= n ; i++){
			
			if(i-cost >=0 ){
				if(dp[i-cost]!="" || i-cost==0){
					string temp = dp[i-cost];
					temp += value ;
					if(temp.size()<dp[i].size())
						continue ;
					sort(temp.begin(),temp.end(),greater<int>());
					
					dp[i] = find_max(dp[i],temp);
				}
			}
			
			
		}
		
		
	}
	
	cout << dp[n] << endl;
	
	return 0;
}


Measured memory_bytes: 25344