akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

const int N = 100;
int dat[N+5];

int main() {
    int n; scanf("%d", &n);
    for (int i=1; i<=n; i++) scanf("%d", dat+i);

    dat[0] = 0;
    for (int i=1; i<=n; i++) dat[i] += dat[i-1];

    int res = dat[n];
    for (int i=0; i<=n; i++) {
        res = min(res, abs(dat[i] - (dat[n]-dat[i])));
    }

    printf("%d\n", res);
    return 0;
}


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

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define int ll
#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;++i)
#define ROF(i,a,b) for(int i=(a)-1,i##_cond=(b);i>=i##_cond;--i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define sz(x) ((int)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair
using ll  = long long;
using vi  = vector<int>;
using vvi = vector<vi>;
using vs  = vector<string>;
using pii = pair<int,int>;
constexpr ll inf = 1ll<<61;
constexpr ll mod = 1e9+7;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>void add(T &a, const T &b){a += b; a %= mod;}

signed main(){
  int n; cin >> n;
  vs s(n); rep(i,n) cin >> s[i];
  int c = 0;
  rep(i,n){
    rep(j,sz(s[i])-1){
      if(s[i].substr(j,2) == "AB") c++;
    }
  }

  int x,y,z; x = y = z = 0;
  rep(i,n){
    dump(s[i][0],s[i][sz(s[i])-1]);
    if(s[i][0] == 'B' and s[i][sz(s[i])-1ll] == 'A') x++;
    else if(s[i][sz(s[i])-1ll] == 'A') y++;
    else if(s[i][0] == 'B') z++;
  }
  dump(c,x,y,z);
  c += max(0ll,x-1ll);
  if(y > 0 and x > 0){
    c++;
    y--;
  }
  if(z > 0 and x > 0){
    c++;
    z--;
  }
  c += min(y,z);
  cout << c << endl;
}

Measured memory_bytes: 768
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
using namespace std;
using ll = long long;
#define max(a,b) ((a)>(b) ? (a):(b))
#define min(a,b) ((a)<=(b) ? (a):(b))
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
 
int main(){
  vector<vector<int>> A(3,vector<int>(3));
  for(int i=0; i<=2; i++){
    for(int j=0; j<=2; j++){
      cin >> A[i][j];
    }
  }
    
  int N;
  cin >> N;
  vector<int> b(N);
  
  for(int k=0; k<N; k++){
    cin >> b[k];
    for(int i=0; i<=2; i++){
      for(int j=0; j<=2; j++){
        if(A[i][j] == b[k]) A[i][j] = 0;
      }
    }
  }
  
  if(A[0][0] + A[1][1] + A[2][2] == 0){
    cout << "Yes";
    return 0;
  }
  if(A[2][0] + A[1][1] + A[0][2] == 0){
    cout << "Yes";
    return 0;
  }
  
  bool flg = false;
  for(int i=0; i<=2; i++){
    int tate = 0;
    int yoko = 0;
    for(int j=0; j<=2; j++){
      if(A[i][j] == 0) yoko +=1;
      if(A[j][i] == 0) tate +=1;
    }
    if(yoko==3 || tate==3){
      flg = true;
      break;
    }
  }
  if(flg == true){
    cout << "Yes";
    return 0;
  }
  cout << "No";
  return 0;
}

Measured memory_bytes: 256
from itertools import product

H,W,K=map(int,input().split())
C=[input() for _ in range(H)]
#print(C)

ans=0
for i in product([0,1],repeat=H):
    for j in product([0,1],repeat=W):
        cnt=0
        for row in range(H):
            for col in range(W):
                if (C[row][col]=="#" and i[row]==0 and j[col]==0):
                    cnt+=1
        if cnt==K:
            ans+=1
                    
print(ans)

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

int main() {
    int m1,d1,m2,d2;
    cin >> m1 >> d1;
    cin >> m2 >> d2;
    if (m1+1 == m2)
        cout << '1';
    else if ( m1==12 && m2==1)
        cout << '1';
    else
        cout << '0';

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 5e5+1;


int n,fa[N],tot[N],fr[N],a[N],b[N],c[N],cnt,head[N];

struct nd{int ne,to;}e[N];

void in(int x,int y){e[++cnt].to=y;e[cnt].ne=head[x];head[x]=cnt;}
int w1[5001],q[N];
void dfs(int x)
{
	for(int i=head[x];i;i=e[i].ne)dfs(e[i].to);
	if(!fr[x])return;
	q[0]=0;
	int ret=tot[x],tot1=0;
	for(int i=head[x];i;i=e[i].ne)
	{
		ret-=min(a[e[i].to],b[e[i].to]);
		q[++q[0]]=abs(a[e[i].to]-b[e[i].to]);
		tot1+=a[e[i].to]+b[e[i].to];
	}
	if(ret<0){cout<<"IMPOSSIBLE";exit(0);}
	w1[0]=x;
	for(int i=1;i<=q[0];++i)
	for(int t=5000;t>=q[i];--t)
	if(w1[t-q[i]]==x)w1[t]=x;
	for(int i=ret;i>=0;--i)
	if(w1[i]==x){ret-=i;break;}
	a[x]=tot[x];b[x]=tot1+ret-a[x];
	return;
}

int main()
{
	scanf("%d",&n);
	for(int i=2;i<=n;++i)
	scanf("%d",&fa[i]),in(fa[i],i),fr[fa[i]]++;
	for(int i=1;i<=n;++i)
	{
		scanf("%d",&tot[i]);
		if(!fr[i])a[i]=tot[i],b[i]=0;
	}
	dfs(1);
	cout<<"POSSIBLE";


}

Measured memory_bytes: 14592
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto abt = readln.split.to!(int[]);
    auto A = abt[0];
    auto B = abt[1];
    auto T = abt[2];
    writeln(B * (T / A));
}

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

using namespace std;

int main() {
	ios_base::sync_with_stdio(0); cin.tie(nullptr);
	int m, n;
	cin >> m >> n;
	vector<int> p(m), c(n), e(n);
	for (auto& i : p) cin >> i;
	for (int i = 0; i < n; i++)
		cin >> c[i] >> e[i];
	sort(p.rbegin(), p.rend());
	vector<int> ps(m+1, 0);
	partial_sum(begin(p), end(p), begin(ps)+1);
	vector<vector<int>> dp(n+1, vector<int>(m+1, 0));
	for (auto i = 0; i < n; i++) {
		for (auto j = 0; j <= m; j++) {
			int tail = min(j+c[i], m),
			    sum = ps[tail]-ps[j];
			dp[i+1][tail] = max(dp[i+1][tail], dp[i][j]+sum-e[i]);
			dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
		}
	}
	cout << *max_element(begin(dp[n]), end(dp[n])) << endl;
	return 0;
}

Measured memory_bytes: 20800
// Aizu Vol0 0066: Tic Tac Toe
// 2017.7.29

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

char *gets(char *);
char buf[100], *p;

int main()
{
	int r, c, d;
	int tab[3][3];

	while (gets(p = buf) != NULL) {
		while (isspace(*p)) p++;
		for (r = 0; r < 3; r++) for (c = 0; c < 3; c++) {
			if (*p == 'o') d = 1;
			else if (*p == 'x') d = -1;
			else d = 0;
			tab[r][c] = d;
			p++;
		}
		for (r = 0; r < 3; r++) {
			d = 0;
			for (c = 0; c < 3; c++) d += tab[r][c];
			if (d == 3 || d == -3) goto END;
		}
		for (c = 0; c < 3; c++) {
			d = 0;
			for (r = 0; r < 3; r++) d += tab[r][c];
			if (d == 3 || d == -3) goto END;
		}
		d = tab[0][0] + tab[1][1] + tab[2][2];
		if (d == 3 || d == -3) goto END;
		d = tab[0][2] + tab[1][1] + tab[2][0];

END: 	if (d == 3) putchar('o');
		else if (d == -3) putchar('x');
		else putchar('d');
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 524
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
#define ll long long
using namespace std;

int main()
{
  ll a, b, c;
  cin >> a >> b >> c;
  if (c - a - b >= 0 && (a + b - c) * (a + b - c) - 4 * a * b > 0)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
signed main() {
	int a, b;
	cin >> a >> b;
	cout << a / b << " " << a % b << " ";
	printf("%.12lf\n", (double)a / b);
	getchar();
	getchar();
	return 0;
}


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

using ll = long long;
using ld = long double;

const ll llinf = (ll)1e18;
const int intinf = 1e9;
const int MOD =  (int)(1e9 + 7);
const ld EPS =  1e-7;


void solve() {
	int n, k;
	cin >> n >> k;
	vector <int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

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

	int ans = 0;

	for (int i = 0; i < k; i++) {
		ans += a[i];
	}

	cout << ans << endl;
}

int main(){
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int t = 1;
	// cin >> t;
	while (t--){
		solve();
	}

	return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ul;
typedef signed long long ll;
ul over = 1000000007;

mt19937 mt(time(nullptr));
// uniform_int_distribution< int > rand_int(0, 10) // rand[0, 10] inclusive

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  int n, m;
  cin >> n >> m;
  int l=1, r=n;
  for (int i=0; i<m; ++i) {
    int li, ri;
    cin >> li >> ri;
    l = max(l, li);
    r = min(r, ri);
  }
  cout << max(0, r-l+1) << endl;
  return 0;
}


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

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()

using namespace std;

using ll = long long;

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

    constexpr int M = 44; // floor(log2(10^(4 + 9))) + 1

    int N;
    cin >> N;

    // cnt[a][b] = # { i | A[i] = 2^(-9 + a) * 5^(-9 + b) * q, q: 2-free and 5-free rational }
    vector<vector<int>> cnt(M, vector<int>(M));

    REP(_, N) {
        string s;
        cin >> s;
        auto it = find(all(s), '.');
        long long x;
        int e;
        if (it == s.end()) {
            e = 0;
            x = stoll(s);
        } else {
            e = (s.end() - it) - 1;
            x = stoll(string(s.begin(), it) + string(next(it), s.end()));
        }
        int a = -e;
        while (x % 2 == 0) {
            x /= 2;
            ++a;
        }
        int b = -e;
        while (x % 5 == 0) {
            x /= 5;
            ++b;
        }
        ++cnt[9 + a][9 + b];
    }

    ll result = 0;

    REP(i1, M) FOR(i2, 18 - i1, M) REP(j1, M) FOR(j2, 18 - j1, M) {
        if (make_pair(i1, j1) <= make_pair(i2, j2)) {
            if (i1 == i2 && j1 == j2) {
                ll c = cnt[i1][j1];
                result += c * (c - 1) / 2;
            } else {
                result += (ll)cnt[i1][j1] * cnt[i2][j2];
            }
        }
    }

    cout << result << endl;

    return 0;
}


Measured memory_bytes: 3648
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define divup(a,b) ( ( (a) + ( (b) - 1u) ) / (b) ) // a/b の余り切り上げ
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int mod = 1000000007;

int main(){
    int s;
    cin>>s;
    int sa=s/100 ,sb=s%100;
    if(sa>=1 && sa<=12){
        if(sb>=1 && sb<=12){
            cout<<"AMBIGUOUS"<<endl;
        }else cout<<"MMYY" <<endl;
    }else{
        if(sb>=1 && sb<=12){
            cout<<"YYMM"<<endl;
        }else cout<<"NA" <<endl;
    }
}


Measured memory_bytes: 256
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;
typedef long long ll;
const ll M=998244353;
int a,b,c;
int main(){
	scanf("%d %d %d",&a,&b,&c);
	printf("%d",max(0,c-(a-b)));
}


Measured memory_bytes: 256
N=int(input())
L=[]
W = list(map(int, input().split())) 
 
Total=sum(W)
#print(N,Total,W)
 
 
for t in range(1,N):
    A=0
    B=0
    for i in range(0,t):
        A+=W[i]
    B=Total-A
    L.append(abs(A-B))
 
print(min(L))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ld long double
#define ll long long
#define st first
#define nd second
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define pb push_back
using namespace std;

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n;
	cin>>n;
	int AC=0, WA=0, TLE=0, RE=0;
	for(int i=1; i<=n; ++i) {
		string s;
		cin>>s;
		if(s=="AC") AC ++;
		if(s == "WA") WA++;
		if(s=="TLE") TLE++;
		if(s=="RE") RE++;
	}
	cout<<"AC x "<<AC<<'\n';
	cout<<"WA x "<<WA<<'\n';
	cout<<"TLE x "<<TLE<<'\n';
	cout<<"RE x "<<RE<<'\n';
}


Measured memory_bytes: 3640
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<vector>
#include<cctype>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define qread(x) x=read()
#define mes(x,y) memset(x,y,sizeof(x))
#define mpy(x,y) memcpy(x,y,sizeof(x))
#define Maxn 10
#define INF 2147483647
inline int read(){
	int f=1,x=0;char ch;
	while(!(ch>='0'&&ch<='9')){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return f*x;
}
int x;
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	qread(x);
	if(x<1200)printf("ABC\n");
	else if(x<2800)printf("ARC\n");
	else printf("AGC\n");
}

Measured memory_bytes: 256
"""
300 10 8 5
50 5 2 1
70 5 2 0
75 1 1 0
100 3 1 0
150 3 2 0
"""
while True:
  M,T,P,R = map(int,input().split())
  if M+T+P+R == 0:
    break
  #### [TeamNumber, Solved, Time, WA]
  Tm = [[i+1,0,0,[0 for j in range(P)]]for i in range(T)]
  ####
  for i in range(R):
    m,t,p,j = map(int,input().split())
    if j==0:
      Tm[t-1][1] += 1
      Tm[t-1][2] += m+Tm[t-1][3][p-1]*20
      Tm[t-1][3][p-1] = 0
    else:
      Tm[t-1][3][p-1] += 1
  Tm.sort(key=lambda x:(x[1],-x[2],x[0]), reverse=True)
  ans = []
  for i in range(T):
    ans.append(str(Tm[i][0]))
    if i<T-1:
      if Tm[i][1]==Tm[i+1][1] and Tm[i][2]==Tm[i+1][2]:
        ans.append("=")
      else:
        ans.append(",")
  print("".join(ans))


Measured memory_bytes: 5668
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main{
  public static void main(String args[]) throws IOException{
   BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
   String[] surface =  br.readLine().split(" ");
   String ordern = br.readLine();
   int n = Integer.parseInt( ordern );


   Dise dice1 = new Dise();
   dice1.setSurface(surface);
   dice1.SetDice(1, 2 , 3);


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

	   String[] order = br.readLine().split(" ");
	   dice1.RegulateDice( Integer.parseInt( order[0] ) ,Integer.parseInt( order[1] ));
	   System.out.println(dice1.surface[dice1.Right] );
	   dice1.SetDice(1, 2 , 3);

   }

  }
}

class Dise{

	int[] surface = new int [6];
    int Top,Bottom,Right,Left,Front,Back;


	void setSurface(String[] SurfaceString){

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

			surface[i] = Integer.parseInt( SurfaceString[i] );

		}

	}

    void SetDice(int top, int front, int right){
	   Top  = top - 1;
       Front = front - 1;
       Right = right - 1;
       Bottom = 5- (top - 1);
       Back = 5- (front - 1);
       Left = 5- (right - 1);
    }//SetDice


    void RegulateDice( int setTop, int setFront  ){


    	if( surface[Left] == setTop )   {


    	    RollDice("E");

    	}else if( surface[Right] == setTop ){

    		RollDice("W");

    	}else if( surface[Front] == setTop ){

    		RollDice("N");

    	}else if( surface[Back] == setTop ){

    		RollDice("S");

    	}else if( surface[Bottom] == setTop ) {

    		RollDice("NN");

    	}else {



    	}

    	if( surface[Left] == setFront )   {

      	  RollDice("NES");

      	}else if( surface[Right] == setFront ){

      		RollDice("NWS");

      	}else if(surface[Back]== setFront){

      		RollDice("NEES");

      	}

    	
    }

    void RollDice(String RollString){

    	String[] SurfaceString =  RollString.split("");
    	for(int i = 0; i < SurfaceString.length ; i++){

    		if( SurfaceString[i].equals("W") ){

    			Bottom = Left;
    			Left = Top;
    			Top = 5 - Bottom;
    			Right = 5 - Left;

    		}else if( SurfaceString[i].equals("S")){

    			Bottom = Front;
    			Front = Top;
    			Top = 5 - Bottom;
    			Back = 5 - Front;

    		}else if( SurfaceString[i].equals("E")){

    			Bottom = Right;
    			Right = Top;
    			Top = 5 - Bottom;
    			Left = 5 - Right;

    		}else{

    			Bottom = Back;
    			Back = Top;
    			Top = 5 - Bottom;
    			Front = 5 - Back;

    		}
    	}


    }//RollDice

}

Measured memory_bytes: 24556
from itertools import product
N,M = map(int,input().split(" "))
x,y,z = [0]*N,[0]*N,[0]*N
for i in range(N):
	x[i],y[i],z[i] = map(int,input().split(" "))
ans = 0
for a,b,c in product(range(2),repeat=3):
	xyz = [0]*N
	for i in range(N):
		xyz[i] = (xyz[i] + x[i]) if a % 2 == 1 else (xyz[i] - x[i])
		xyz[i] = (xyz[i] + y[i]) if b % 2 == 1 else (xyz[i] - y[i])
		xyz[i] = (xyz[i] + z[i]) if c % 2 == 1 else (xyz[i] - z[i])
	xyz.sort(reverse=True)
	ans = max(sum(xyz[:M]),ans)
print(ans)

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

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

Measured memory_bytes: 256
#include <iostream>
#include <map>

using namespace std;

int main(void) {
	int s, i = 1;
	map<int, int> mp;
	scanf("%d", &s);
	while (mp[s] == 0) {
		mp[s] = 1;
		if ((s & 1) == 0)
			s >>= 1;
		else
			s = 3 * s + 1;
		i++;
	}
	cout << i << "\n";
	return 0;
}

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

#define INF 1e9
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};

int solve(const vector<string>& board, int h, int w, int sy, int sx, int gy, int gx) {
	vector<vector<int>> cost(h + 2, vector<int>(w + 2, INF));
	queue<pair<int, int>> que;
	que.push(make_pair(sy, sx));
	cost[sy][sx] = 0;

	while(not que.empty()) {
		int y = que.front().first, x = que.front().second;
		que.pop();
		rep(k, 4) {
			int ny = y + dy[k], nx = x + dx[k];
			if (board[ny][nx] == '#') continue;
			if (cost[ny][nx] != INF) continue;
			que.push(make_pair(ny, nx));
			cost[ny][nx] = min(cost[ny][nx], cost[y][x] + 1);
		}
	}
	return cost[gy][gx] == INF ? 0 : cost[gy][gx];
}

int main(int argc, char const *argv[]) {
	int h, w; cin >> h >> w;
	vector<string> s(h + 2);

	string b;
	rep(i, w + 2) b += '#';

	s[0] = b;
	rep(i, h) {
		string t; cin >> t;
		t = '#' + t + '#';
		s[i + 1] = t;
	}
	s[h + 1] = b;

	// rep(i, h + 2) cout << s[i] << endl;

	int ans = 0;
	rep(sy, h)rep(sx, w)rep(gy, h)rep(gx, w) {
		if (s[sy + 1][sx + 1] == '#' or s[gy + 1][gx + 1] == '#') continue;
		int cost = solve(s, h, w, sy + 1, sx + 1, gy + 1, gx + 1);
		ans = max(ans, cost);
	}
	cout << ans << endl;
	return 0;
}


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


int main() {
  int N,M;
  cin >> N >> M;
  vector<int> p(M);
  vector<string> S(M);
  for(int i=0;i<M;i++){
    cin >> p.at(i) >> S.at(i);
  }
  set<int> AC;
  int WA = 0;
  for(int i=0; i<M; i++){
    if(S.at(i)=="AC"){
      AC.insert(p.at(i));
    }else{
      if( !(AC.count(p.at(i))) ) WA++;
    }
  }
  for(int i=0; i<M; i++){
    if( !(AC.count(p.at(i))) ) WA--;
  }
  cout << AC.size() <<' ' << WA << endl;
}

Measured memory_bytes: 10752
# -*- coding: utf-8 -*-
"""
Created on Sat Nov 16 19:44:49 2019
ABC145D
@author: maezawa
"""

#MAX = 5*10**5+1
MAX = 10**6+1
MOD = 10**9+7

fac = [0] * MAX
finv = [0]*MAX
inv = [0]*MAX

# テーブルを作る前処理
fac[0] = 1
fac[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
for i in range(2,MAX):
    fac[i] = fac[i - 1] * i % MOD
    inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
    finv[i] = finv[i - 1] * inv[i] % MOD

# 二項係数計算
def COM(n, k):
    if (n < k):
        return 0
    if (n < 0 or k < 0):
        return 0
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD


#n, r = list(map(int, input().split()))
#ans = COM(n, r)
#print(ans)

x, y = list(map(int, input().split()))

if (x+y)%3 != 0:
    print(0)
else:
    n = (x+y)//3
    if n>x or 2*n<x or n>y or 2*n<y:
        print(0)
    else:
        m = 2*n - x
        ans = COM(n, m)
        print(ans)
        
    
        
    

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

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

    int a,b,c;
    cin >> a >> b >> c;
    
    int d = a - b;
    
    cout << max(c-d, 0) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>

const int N=101000;

int f[N];

int main()
{
	for(int i=1;i<N;i++)
		f[i]=f[i/10]+i%10;

	int n,ans=233333;

	scanf("%d",&n);
	
	for(int i=1;i<n;i++)
		ans=std::min(ans,f[i]+f[n-i]);

	printf("%d\n",ans);

	return 0;
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N;
  cin >> N;
  ll mn = pow(10, 17);
  REP(i, 5) {
    ll tmp;
    cin >> tmp;
    mn = min(mn, tmp);
  }

  ll ans;
  if(N % mn != 0) {
    ans = N / mn + 5;
  } else {
    ans = N / mn + 4;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int a, b;
	scanf("%d %d", &a, &b);

	if (a < b) {
		printf("a < b\n");
	} else if (a > b) {
		printf("a > b\n");
	} else {
		printf("a == b\n");
	}
	return 0;
}

Measured memory_bytes: 580
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define speedX ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
// #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
template<typename T>
void __p(T a) { cout << a << " "; }
template<typename T, typename F>
void __p(pair<T, F> a) { cout << "{ "; __p(a.first); __p(a.second); cout << "}"; }
template<typename T>
void __f(const char* s, T t) { cout << s << " : "; __p(t); }
template<typename T>
void __t(const char* s, const T &x) { cout << s << " : { "; for (auto it : x) __p(it); cout << "} ";}
template<typename T, typename ... F>
void __f(const char* s, T t, F ... f) {
	int i = 0; for (;; ++i) if (s[i] == ',') break;
	cout.write(s, i) << " : "; __p(t); cout << " | "; __f(s + i + 1, f...);
}
#define trace(...) { cout<<"LINE: "<<__LINE__<<" || "; __f(#__VA_ARGS__,__VA_ARGS__); cout<<"\n\n"; }
#define debug(...) { cout<<"LINE: "<<__LINE__<<" || "; __t(#__VA_ARGS__,__VA_ARGS__); cout<<"\n\n"; }
int begtime = clock();
#define end_time() cout << "\n\nTime of execution: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define trace(...)
#define debug(...) 
#define end_time()
#endif
 
 
#define int long long 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef vector<int> vi;
typedef vector<pii> vii;

inline bool equals(ld a, ld b) {return fabs(a - b) < 1e-9;}
inline int gcd(int a, int b) { a=abs(a); b=abs(b); while(a>0 && b>0) (a>b?a%=b:b%=a); return (a==0?b:a); } 
inline int power(int x, int n, int m = LLONG_MAX)
    {  int res=1; x = (x%m + m)%m;
       while(n) { if(n&1) res=(res*x)%m;  x=(x*x)%m;  n >>= 1; }  return res;
    }
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define uset unordered_set
#define umap unordered_map
#define all(x) x.begin(), x.end()
#define mod 1000000007

void solve(){
	int n,d;
	cin>>n>>d;
	int ans = 0;
	for(int i = 0; i<n; i++){
		int x,y;
		cin>>x>>y;
		if(pow(x,2)+pow(y,2)-pow(d,2) <= 0) ans++;
	}
	cout<<ans<<"\n";
}
signed main(){
	speedX;
	#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
	int t=1;
	//cin>>t;
	for(int i=1;i<=t;++i) {
		//cout<<"Case #"<<i<<": ";
		solve();
	}
	end_time();
	return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,i,j,k,l=0;
    char c[100009];
    scanf("%d %s",&n,&c);
    for(i=1;i<n;i++){
        if(c[i]!=c[i-1])
            l++;
    }
    printf("%d\n",l+1);


}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
	long long a;
	int b_1,b_2;
	char c;
	cin>>a>>b_1>>c>>b_2;
	
	long long ans=b_1*100+b_2;
	ans*=a;
	cout<<ans/100ll<<endl;
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
    using namespace std;
    typedef long long int ll;
    const int N=1e6+6;
    const int mod=1e9+7;
    ll fact[N],inv[N];
     
    ll fp(ll b,ll p){
    	if(p==0) return 1;
    	if(p&1) return (b*fp(b,p-1))%mod;
    	return fp((b*b)%mod,p/2);
    }
     
    ll nCk(ll n,ll k){
       return ((fact[n]*inv[k])%mod*inv[n-k])%mod;
    }
     
    int main()
    {
     
      /* #ifndef ONLINE_JUDGE
       freopen("test.txt", "r", stdin);
       #endif*/
       ios_base::sync_with_stdio(0);
       cin.tie(0);
        fact[0]=1;
       inv[0]=fp(fact[0],mod-2);
       for(int i=1;i<=1000000;i++){
           fact[i]=fact[i-1]*i%mod;
           inv[i]=fp(fact[i],mod-2);
       }
       ll x,y,ans=0;
       cin>>x>>y;
       if((x+y)%3!=0)return cout<<0,0;
       ll n=2*y-x;
       n=n/3;
       ll m=y-2*n;
       if(m<0||n<0)return cout<<0,0;
       cout<<nCk(n+m,n)<<'\n';
     
     
     
        return 0;
    }

Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
 
int sumnumbers(int x){
    int y = 0;
    while (x > 0){
        y += x % 10;
        x /= 10;
    }
    return y;
}

int main() {
    int N;
    cin >> N;
    int sum = sumnumbers(N);
    if(N % sum == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]

def main():
    n = i_input()
    dic = {}
    for i in range(n):
        a = i_input()
        dic[a] = dic.get(a,0) + 1

    ans = 0

    for i,k in dic.items():
        if k % 2 == 1:
            ans += 1
    print(ans)








if __name__=="__main__":
    main()


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


int main(){

    string str,tmp;
    cin >> str;
    tmp = str;

    
    reverse(str.begin(), str.end());
    if(tmp == str){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    //cout << tmp << " " << str << endl;
    
    


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define MOD 1000000007
using namespace std;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
   	int m1,d1,m2,d2;
   	cin >> m1 >> d1 >> m2 >> d2;
   	map<int,int> m;
   	m[1]=31;m[2]=28;m[3]=31;m[4]=30;m[5]=31;
   	m[6]=30;m[7]=31;m[8]=31;m[9]=30;m[10]=31;m[11]=30;m[12]=31;
   	if(d1==m[m1]) cout << 1;
   	else cout << 0;
   	cout << "\n";
    return 0;
}



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

long long int* we=new long long int[100005];
long long int* val=new long long int[100005];

long long int maxim(long long int a, long long int b)
{
    if(a>b)
        return a;
    return b;
}

long long int compute(long long int n, long long int w)
{
    long long int a[n+1][w+1];
    long long int i, x, y, j;
    for(i=0;i<=n;i++)
    {
        for(j=0;j<=w;j++)
        {
            if(i==0||j==0)
                a[i][j]=0;
            else if(j>=we[i-1])
            {
                x=a[i-1][j-we[i-1]]+val[i-1];
                y=a[i-1][j];
                a[i][j]=maxim(x, y);
            }
            else
            {
                a[i][j]=a[i-1][j];
            }

        }

    }
    return a[n][w];
}

int main()
{
    long long int n, w, i;
    cin>>n>>w;
    for(i=0;i<n;i++)
    {
        cin>>we[i]>>val[i];
    }
    cout<<compute(n, w);
}


Measured memory_bytes: 79104
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	list := make([]Nodes, n)

	for i := 0; i < n; i++ {
		heap.Init(&list[i])
	}

	for i := 0; i < n; i++ {
		u := getNextInt(scanner)
		k := getNextInt(scanner)
		for ii := 0; ii < k; ii++ {
			v := getNextInt(scanner)
			c := getNextInt(scanner)
			heap.Push(&list[u], &Node{
				id:   v,
				cost: c,
			})
		}
	}

	ans := make([]int, n)
	for i := 0; i < n; i++ {
		ans[i] = 1 << 30
	}
	h := make(Nodes, 0)
	heap.Init(&h)
	heap.Push(&h, &Node{
		id:   0,
		cost: 0,
	})

	im := make(IntMap, 1)

	for len(h) > 0 {
		node := heap.Pop(&h).(*Node)
		u := node.id
		if ans[u] < node.cost {
			continue
		}
		ans[node.id] = node.cost
		im.increment(u)
		for l := list[u].Len(); l > 0; l-- {
			p := heap.Pop(&list[u]).(*Node)
			v := p.id
			c := p.cost
			if im.get(v) != 0 {
				continue
			}
			if ans[v] > ans[u]+c {
				ans[v] = ans[u] + c
				heap.Push(&h, &Node{
					id:   v,
					cost: ans[v],
				})
			}
		}
	}

	for i := 0; i < n; i++ {
		fmt.Fprintln(writer, fmt.Sprintf("%d %d", i, ans[i]))
	}
	writer.Flush()
}

// Node ...
type Node struct {
	id   int
	cost int
}

// Nodes ...
type Nodes []*Node

func (a Nodes) Len() int           { return len(a) }
func (a Nodes) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a Nodes) Less(i, j int) bool { return a[i].cost < a[j].cost }

// Push ...
func (a *Nodes) Push(x interface{}) {
	*a = append(*a, x.(*Node))
}

// Pop ...
func (a *Nodes) Pop() interface{} {
	old := *a
	n := len(old)
	x := old[n-1]
	*a = old[0 : n-1]
	return x
}

// IntMap ...
type IntMap map[int]int

func (m IntMap) get(key int) int {
	if _, ok := m[key]; ok {
		return m[key]
	}
	return 0
}
func (m IntMap) increment(key int) {
	if _, ok := m[key]; ok == false {
		m[key] = 0
	}
	m[key]++
}



Measured memory_bytes: 18024
#include<bits/stdc++.h>
using namespace std;
static const int INF=(1<<21);
int n,M[101][101];
int d[101];

void bfs(int s){
  
  queue<int>q;
  
  q.push(s);
  
  for(int i=0;i<n;i++) d[i]=INF;
  d[s]=0;
  
  while(!q.empty()){
    
    int u=q.front();
    q.pop();
    for(int v=0;v<n;v++){
      
      if(M[u][v]==0)continue;
      if(d[v]!=INF) continue;
      d[v]=d[u]+1;
      q.push(v);
   
    }
 
  }
 
  for(int i=0;i<n;i++){
    cout<<i+1<<" "<<( (d[i]==INF)?(-1):d[i] )<<endl;
  }

}

int main(){
  int u,k,v;
  cin>>n;
  
  for(int i=0;i<n;i++){   
    cin>>u>>k;
    u--;
    
    for(int j=0;j<k;j++){     
      cin>>v;
      v--;
      M[u][v]=1;
      
    }
    
  }
  
  bfs(0);
  return(0);
}

      



Measured memory_bytes: 3120
n = int(input())

y =list(map(int,input().split()))
x = list()

for i in range(n-1,-1,-1):
    arry = y[i]
    x.append(arry)

for i in range(n):
    if(i == n-1):
        print('{}'.format(x[i]))
    else:
        print(x[i],end=' ')
    


Measured memory_bytes: 5604
n, k = map(int, input().split())
ls = list(map(int, input().split()))
ls2 = list(map(lambda x: bin(x)[2:], ls))
m = max(map(len, ls2))
m = max(m, len(bin(k)[2:]))
ls2 = [s.rjust(m, '0') for s in ls2]
res = []
for i in range(m):
    if 2**(m - i - 1) > k:
        continue
    count = 0
    for s in ls2:
        if i < len(s) and s[i] == '0':
            count += 1
    if count < (n + 1) // 2:
        res.append('0')
    else:
        res.append('1')

x = 0
mm = len(res)
for i, c in enumerate(res):
    if c == '1':
        c = 2**(mm - i - 1)
        if x + c <= k:
            x += c

y = 0
for a in ls:
    y += x ^ a
print(y)

Measured memory_bytes: 25588
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024*1024), bufio.MaxScanTokenSize)
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func nextFloat() float64 {
	sc.Scan()
	f, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func scanInts(n int) []int {
	is := make([]int, n)
	for i := 0; i < n; i++ {
		is[i] = nextInt()
	}
	return is
}

func main() {
	D, T, S := nextFloat(), nextFloat(), nextFloat()
	if T >= D/S {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


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


int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, m;
	char grid[1005][1005];
	string inp;
	cin >> n >> m;
	vector<vector<int>> dp (n+1, vector<int> (m+1));
	for (int i = 0; i < n; i++)
		cin >> grid[i];
	for (int i = 0; i < n; i++)
		if (grid[i][0] != '#')
			dp[i][0] = 1;
		else
			break;
		
	for (int i = 0; i < m; i++)
    	if (grid[0][i] != '#')
			dp[0][i] = 1;
		else
			break;

	for (int i = 1; i < n; i++) {
		for (int j = 1; j < m; j++) {
			if (grid[i][j] == '#') {
				dp[i][j] = 0;
			} else {
				dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % 1000000007;
			}
		}
	}
	cout << dp[n-1][m-1] % 1000000007;
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
#define rep(i,n) for(int i=1;i<=n;++i)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
using namespace std;

int main(){
  int n;
  cin >> n;
  cout << 48-n << endl;
  return 0;
}


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

using namespace std;
#define rep(i, n) for(int i = 0 ; i < (int)(n) ; i++)
typedef long long ll;
typedef long double Double;

#ifndef INPUTS_DIR
#define INPUTS_DIR "./"
#endif


void solve(ll N, vector<ll> L) {
    sort(L.rbegin(), L.rend());
    long long ans = 0;
    for (int i = 0; i + 1 < N * 2; i += 2) {
        ans += L[i + 1];
    }
    cout << ans << endl;
}


void main_(istream &cin) {
    ll N;
    cin >> N;
    vector<ll> L(2 * N - 1 + 1);
    for (int i = 0; i <= 2 * N - 1; i++) {
        cin >> L[i];
    }
    solve(N, L);
}

int main() {
#ifdef INTELLIJ
    ifstream ifs(string(INPUTS_DIR) + "in_1.txt");
    if (ifs.is_open()) {
        main_(ifs);
        ifs.close();
    } else {
        cerr << "Error: no input." << endl;
    }
#else
    ios::sync_with_stdio(false);
    cin.tie(0);
    main_(cin);
#endif
}





Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#define SIZE 200005

using namespace std;
typedef long long int ll;

int A[SIZE];
int imos1[SIZE];
ll imos2[SIZE];

int main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	int now;
	scanf("%d",&now);now--;
	ll all=0;
	for(int i=1;i<n;i++)
	{
		int to;
		scanf("%d",&to);to--;
		now%=m;
		if(now>to) to+=m;
		all+=to-now;
		imos1[now+1]++;
		imos1[to+1]--;
		imos2[now+1]+=now;
		imos2[to+1]-=now;
		now=to;
	}
	for(int i=1;i<2*m;i++)
	{
		imos1[i]+=imos1[i-1];
		imos2[i]+=imos2[i-1];
	}
	ll ret=all;
	for(int i=0;i<m;i++)
	{
		int a=imos1[i];
		ll b=imos2[i];
		ll nxt=all;
		nxt-=(ll) a*(ll) i-b-a;
		a=imos1[i+m],b=imos2[i+m];
		nxt-=(ll) a*(ll) (i+m)-b-a;
		ret=min(ret,nxt);
	}
	printf("%lld\n",ret);
	return 0;
}


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

int main() {
    int64_t k, a, b;
    cin >> k >> a >> b;
    int64_t ans = 0;
    if (b < a + 3) ans = k + 1;
    else {
        ans = (k - a + 1) / 2 * (b - a) + a;
        if ((k - a + 1) % 2 == 1) ans += 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n=int(input())

score=0

for i in range((n+1)//2):
    i=i*2+1
    yakusuu1 = []
    yakusuu2 = []
    d=1
    while d*d <= i:
        if i%d==0:
            yakusuu1.append(d)
            
            if d!= i//d: #べき乗ではなかったら　ex:2*2=4
                yakusuu2.append(i//d)
        
        d=d+1
    yakusuu = yakusuu1+yakusuu2[::-1]
    # print(i,yakusuu)
    
    if len(yakusuu) == 8:
        score = score+1
print(score)

Measured memory_bytes: 61896
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif
// 実数の場合
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

int N, A, B, C;
vector<int> L;
int dfs(int cur, int a, int b, int c) {
    if (cur == N) {
        if (min({a, b, c}) > 0) {
            return abs(A - a) + abs(B - b) + abs(C - c) - 30;
        } else {
            return 1000000000;
        }
    }

    vector<int> ret;
    ret.push_back(dfs(cur + 1, a, b, c));
    ret.push_back(dfs(cur + 1, a + L[cur], b, c) + 10);
    ret.push_back(dfs(cur + 1, a, b + L[cur], c) + 10);
    ret.push_back(dfs(cur + 1, a, b, c + L[cur]) + 10);

    int m = *min_element(ret.begin(), ret.end());
    return m;
}

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

    cin >> N >> A >> B >> C;
    L.assign(N, 0);
    for (int i = 0; i < N; i++) {
        cin >> L[i];
    }

    int ans = dfs(0, 0, 0, 0);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int h[200002];
int main(){
    int n,k,temp;
    long long int sum=0;
    cin>>n>>k;
    for(int i=0;i<n;++i){
    	cin>>temp;
    	h[i]=temp;
	}
	sort(h,h+200002);
	for(int i=0+k;i<n;++i){
		sum+=h[200001-i];
	}
	printf("%lld",sum);
	return 0;
} 

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

using namespace std;
#define sz(x) (int)((x).size())
#define forn(i,n) for (int i=0; i < n; i++)
#define forse(i,s,e) for (int i=s; i < e; i++)
#define pb push_back
#define fi first
#define se second
#define all(vec) vec.begin(), vec.end()
#define time() ((double)clock() / CLOCKS_PER_SEC)

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

double PI=3.141592653589793;


void solve(){
	int h[2],m[2],k;
	forn(i,2) cin >> h[i] >> m[i];
	cin >> k;
	int t[]={h[0]*60+m[0],h[1]*60+m[1]};
	t[1]-=k;
	cout << max(0,t[1]-t[0]);	
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); 
	int T=1;
//	cin >> T;
	forse(c,1,T+1){
	//	cout << "Case #" << cid << ": ";
		solve();
	}
}


Measured memory_bytes: 3652
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n, sum, ans, a[5001];
  while(1){
    cin >> n;
    if(n == 0) 
      break;
    ans = -100000;
    for(int i = 0; i < n; i++)
      cin >> a[i];
    for(int i = 0; i < n; i++){
      sum = 0;
      for(int j = i; j < n; j++){
        sum += a[j];
        ans = max(ans,sum);
      }
    }
    cout << ans << endl;
  }
}

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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...)
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int h, w, k, x1, y1, x2, y2;
    cin >> h >> w >> k >> x1 >> y1 >> x2 >> y2;
    x1--, y1--, x2--, y2--;

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

    auto ok = [&] (int r, int c) {
        return 0 <= r && r < h && 0 <= c && c < w;
    };

    vector<vector<vector<pair<int, int>>>> dist(h, vector<vector<pair<int, int>>>(w, vector<pair<int, int>>(4, {INT_MAX, INT_MAX})));
    priority_queue<array<int, 5>, vector<array<int, 5>>, greater<array<int, 5>>> pq;
    dist[x1][y1][0] = {0, 0};
    pq.push({0, 0, x1, y1, 0});
    while (!pq.empty()) {
        int d = pq.top()[0], pd = pq.top()[1], r = pq.top()[2], c = pq.top()[3], dir = pq.top()[4];
        pq.pop();
        if (make_pair(d, pd) > dist[r][c][dir])
            continue;
        if (r == x2 && c == y2) {
            cout << d + (pd + k - 1) / k << "\n";
            return 0;
        }

        for (int i=0; i<4; i++) {
            int nr = r, nc = c, nd = d, npd = pd;
            if (i == dir) {
                nr += dr[i], nc += dc[i];
                if (++npd == k) {
                    nd++;
                    npd = 0;
                }
            } else if (npd > 0) {
                nd++;
                npd = 0;
            }
            if (ok(nr, nc) && grid[nr][nc] == '.' && make_pair(nd, npd) < dist[nr][nc][i]) {
                dist[nr][nc][i] = {nd, npd};
                pq.push({nd, npd, nr, nc, i});
            }
        }
    }
    cout << "-1\n";

    return 0;
}


Measured memory_bytes: 144976
#include<cstdio>

typedef long long int lli;

using namespace std;

int main(){
  lli N, ans = 1;

  scanf("%lld", &N);

  for(lli l = 2; l <= N; l++){
    ans *= l;
    ans %= 1000000007;
  }

  printf("%lld", ans);

  return 0;

}


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

using _i64 = int64_t;
using _u64 = uint64_t;
using _f64 = double;

#define _for(i, start, end) for(_i64 i = (_i64)start; i < (_i64)end; ++i)
#define _rep(i, number) _for(i, 0, number)
#define _foreach(e, data) for(auto& e : data)
#define _all(data) data.begin(), data.end()

template<typename type>
_i64 _size(const type& data) { return static_cast<_i64>(data.size()); }
template<typename type, size_t size>
_i64 _size(const type (&)[size]) { return static_cast<_i64>(size); }

enum _flag : bool { able = true, disable = false };

struct _time {
    _time(_flag flag) { check = flag; if(!check) { return; } gettime(start); }
    ~_time() {
        if(!check) { return; }; gettime(end);
        _i64 elapse = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cout << endl << "Time: " << elapse << " ms" << endl;
    }
    private:
    using _timer = chrono::time_point<chrono::system_clock>;
    _timer start, end; bool check;
    void gettime(_timer& time) { time = chrono::system_clock::now(); }
};

struct _ini { _ini() { ios::sync_with_stdio(false); cin.tie(nullptr); } } _ini;

int main() {
    {
        _time time(disable);
        _i64 N; vector<_i64> l(3); cin >> N; 
        _rep(i, N) {
            _foreach(e, l) { cin >> e; } sort(_all(l));
            cout << (pow(l[0], 2) + pow(l[1], 2) == pow(l[2], 2) ? "YES" : "NO") << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3024
import java.io.*;
import java.util.*;
import java.math.*;
     
public class Main{
	public static void main(String[] args) throws Exception {
	IO io = new IO();
	PrintWriter out = new PrintWriter(System.out);
	Solver sr = new Solver();
	sr.solve(io,out);
	out.flush();
	out.close();
    	}

	static class Solver
	{
      	long[][] dp;
      	long[] val;
      	int[] wt;
      	long dfs(int i, int w, int n)
        {
          if(i==n || w==0)
            return 0;
          
          if(dp[i][w]!=-1)
            return dp[i][w];
          
          long max=0;
          if(wt[i]<=w)
            max =  Math.max(val[i]+dfs(i+1,w-wt[i],n), dfs(i+1,w,n));
          else
            max = dfs(i+1,w,n);
          
          return dp[i][w] = max;
        }
        void solve(IO io, PrintWriter out)
        {
            int t = 1;
            while(t-->0)
            {
                int n = io.nextInt();
              	int w = io.nextInt();
              	
              	dp = new long[n+1][w+1];
              	val = new long[n];
              	wt = new int[n];
              	for(int i=0 ; i<n ; i++)
                {
                  Arrays.fill(dp[i],-1);
                  wt[i] = io.nextInt();
                  val[i] = io.nextInt();
                }
              	Arrays.fill(dp[n],-1);
                out.print(dfs(0,w,n));
            }
	    }
	}
	//Special thanks to Petr (on codeforces) who inspired me to implement IO class!
	static class IO
	{
    	private static final int BUF_SIZE = 2048;
        BufferedReader br;
        private IO() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        private boolean isSpace(char c) {
            return c == '\n' || c == '\r' || c == ' ';
        }
        String next() {
            try {
                StringBuilder sb = new StringBuilder();
                int r;
                while ((r = br.read()) != -1 && isSpace((char) r));
                if (r == -1) {
                    return null;
                }
                sb.append((char) r);
                while ((r = br.read()) != -1 && !isSpace((char) r)) {
                    sb.append((char) r);
                }
                return sb.toString();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
	}
}

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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

int main(){

    int a, b, k;
    cin >> a >> b >> k;

    vector<int> ans;
    for(int i = 1; i <= 100; i++){
        if((a%i == 0) && (b%i == 0)) ans.push_back(i);
    }
    sort(ans.rbegin(), ans.rend());
    cout << ans[k-1] << endl;
    return 0;
}

Measured memory_bytes: 256
import heapq

N,K = map(int, input().split())
h = []
max_t = 0
for _ in range(N):
    t, d = map(int, input().split())
    heapq.heappush(h, (-d, t))
    max_t = max(max_t, t)

L = [0]*max_t
num = 0
h2 = []
for _ in range(K):
    temp = heapq.heappop(h)
    L[temp[1]-1] += 1
    num -= temp[0]
    heapq.heappush(h2, (-temp[0], temp[1]))
    
cnt = 0
for i in range(max_t):
    if L[i] > 0:
        cnt += 1

ans = num + cnt**2
while len(h) > 0 and len(h2) > 0:
    temp = heapq.heappop(h)
    if L[temp[1]-1] > 0:
        continue
    while L[h2[0][1]-1] <= 1:
        heapq.heappop(h2)
        if not h2:
            break
    if not h2:
        break
    temp2 = heapq.heappop(h2)    
    num -= temp2[0] + temp[0]
    L[temp2[1]-1] -= 1
    L[temp[1]-1] += 1
    cnt += 1
    ans = max(ans, num+cnt**2)

print(ans)

Measured memory_bytes: 79704
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

#define _CRT_SECURE_NO_WARNINGS

int main(int argc, char const *argv[])
{
	int n,a,b;
	scanf("%d%d%d",&n,&a,&b);
	if(n * a < b)	printf("%d\n", n * a);
	else printf("%d\n", b);
	return 0;
}


Measured memory_bytes: 128
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> //tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <numeric>
using namespace std;

int main() {
    int N, M, ret = -1, tmp = 0;
    cin >> N >> M;
    vector<int> A(M);
    for (int i = 0; i < M; i++) {
        cin >> A.at(i);
        tmp += A.at(i);
    }

    cout << (tmp <= N ? N - tmp : -1) << endl;
}

Measured memory_bytes: 3672