akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main()
{
    int a,b;cin>>a>>b;
    int mul,add,sub;
    mul=a*b;
    add=a+b;
    sub=a-b;
    if(mul>add&&mul>sub){
        cout<<mul;
    }
    else if(add>mul&&add>sub){
        cout<<add;
    }
    else cout<<sub;

   return 0;
}


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

int main(){

    ll A, B, C, X, Y;
    cin>>A>>B>>C>>X>>Y;
    ll ans = 1145141919810;
    for(ll i = max(X, Y)*2;i>=0;i--){
        ll tmp = i*C + max(X-i/2, (ll)0)*A + max(Y-i/2, (ll)0)*B;
        ans=min(ans,tmp);
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;
 
#define Pr(f,...) fprintf(stderr,f,##__VA_ARGS__),fflush(stderr)

const int N=5005; 

string s;
int n,k;
vector<string> a;

bool cmp(string a,string b){
	int n=a.length(),m=b.length(); 
	int p=0; 
	while(p<m&&p<n){
		if(a[p]<b[p])return true;
		if(a[p]>b[p])return false;
		++p;	
	}
	return n<m;
}

int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
	//freopen("dat.in","r",stdin); 
	//freopen("my.out","w",stdout); 
#endif
	cin>>s>>k;
	n=s.length();
	rep(len,1,5){
		for(int i=0;i+len<=n;++i){
			a.pb(s.substr(i,len)); 
		}
	}
	sort(a.begin(),a.end(),cmp); 
	a.erase(unique(a.begin(),a.end()),a.end());
	//for(auto s:a)cout<<s<<endl;
	cout<<a[k-1]<<endl;
}

Measured memory_bytes: 1660
#include<iostream>

using namespace std;
int main()
{
   string s;
   cin>>s;
   if(s=="Sunny"){
      cout<<"Cloudy"<<"\n";
      return 0;
   }
   else if(s=="Cloudy"){
      cout<<"Rainy"<<"\n";
      return 0;
   }
   else
   cout<<"Sunny"<<"\n";
   return 0;

}


Measured memory_bytes: 256
#include<iostream>
#define mod 1000000007
using namespace std;
int n, k, i, j, sol;
long long c[2005][2005];
int main(){
    cin>> n >> k;
    c[0][0] = 1;
    for(i = 1; i <= n; i++){
        c[i][0] = 1;
        for(j = 1; j <= i; j++){
            c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
            if(c[i][j] >= mod){
                c[i][j] -= mod;
            }
        }
    }
    if(k == n){
        cout<<"1\n";
        for(i = 2; i <= n; i++){
            cout<<"0\n";
        }
        return 0;
    }
    for(i = 1; i <= k; i++){
        if(i != 1){
            sol = (c[n - k - 1][i - 2] + c[n - k - 1][i - 1] * 2 + c[n - k - 1][i]) % mod * c[k - 1][i - 1] % mod;
        }
        else{
            sol = (c[n - k - 1][i - 1] * 2 + c[n - k - 1][i]) % mod * c[k - 1][i - 1] % mod;
        }
        cout<< sol <<"\n";
    }
}


Measured memory_bytes: 30208
#include<iostream>
#include<utility>
#include<set>
using namespace std;

int main() {
  int dn, gx, gy, p, x, y;
  pair< pair<int,int> , pair<int, int> > tmp;
  for(cin >> dn; dn > 0; dn--)
    {
      cin >> gx >> gy;
      int map[gy+1][gx+1];
      set< pair<pair<int, int> , pair<int, int> > >  matco;
      cin >> p;
      
      for(int i=0; i<p; i++)
	{
	  cin >> tmp.first.first >> tmp.first.second >> tmp.second.first >> tmp.second.second;
	  if (tmp.first.first > tmp.second.first || tmp.first.second > tmp.second.second) {
	    matco.insert( make_pair(tmp.second, tmp.first) );
	  }
	  else matco.insert(tmp);
	}
      map[0][0] = 1;
      for(y = 0; y <= gy; y++)
	for(x = 0; x <= gx; x++)
	  {
	    if (x != 0 || y != 0) map[y][x] = 0;
	    if (x > 0 && !matco.count(make_pair( make_pair(x-1, y), make_pair(x, y) )))
	      map[y][x] += map[y][x-1];
	    if (y > 0 && !matco.count(make_pair( make_pair(x, y-1), make_pair(x, y) )))
	      map[y][x] += map[y-1][x];
	  }
      if (map[gy][gx]) cout << map[gy][gx] << endl;
      else cout << "Miserable Hokusai!" << endl;
    }
  return 0;
}

Measured memory_bytes: 1200
import Data.List
import qualified Data.ByteString.Char8 as B
import Control.Monad

main :: IO ()
main = breads >>= main'
    where
        main' [h, w] = replicateM h getLine >>= putStrLn . solve h w . concat

solve :: Int -> Int -> String -> String
solve h w = check . foldl' ff (0, 0, 0) . group . sort
    where
        ff (acc3, acc2, acc1) g
            | n `mod` 4 == 1 = (acc3, acc2, acc1 + 1)
            | n `mod` 4 == 2 = (acc3, acc2 + 1, acc1)
            | n `mod` 4 == 3 = (acc3 + 1, acc2, acc1)
            | otherwise = (acc3, acc2, acc1)
            where
                n = length g

        check (acc3, acc2, acc1)
            | (h == 1 || w == 1) && acc3 + acc1 == 1 = "Yes"
            | (even h && even w && acc3 == 0 && acc2 == 0 && acc1 == 0) || (even h && odd w && acc3 == 0 && acc1 == 0 && acc2 <= h `div` 2) || (odd h && even w && acc3 == 0 && acc1 == 0 && acc2 <= w `div` 2) = "Yes"
            | odd h && odd w && acc3 + acc1 == 1 && acc2 <= (w + h - 2) `div` 2 = "Yes"
            | otherwise = "No"

breads :: IO [Int]
breads = unfoldr uff <$> B.getLine
    where
        uff b = check <$> B.readInt b
        check (a, b)
            | B.null b = (a, b)
            | otherwise = (a, B.tail b)


Measured memory_bytes: 2300
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <functional>
#include <cmath>
#include <cstdint>
#include <mutex>
#include <thread>
#include <bitset>

using namespace std;


int main(void)
{
	string s;
	cin >> s;

	if (s[1] == 'B')
		cout << "ARC";
	else
		cout << "ABC";
	return 0;
}

Measured memory_bytes: 3584
use v6;

my $n = get().chomp;
my @arr = get().chomp.split(' ');
@arr = @arr.sort({$^a <=> $^b});
my $ans = 0;
loop (my $i = 0; $i < $n; $i++) {
	$ans += @arr[$i * 2];
}
say $ans;

exit;

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

using ll = long long;
#define ff first
#define ss second

const int N = 1e5 + 10;
int a[N];

int n, m;
int memo[N];

set<int> brk;

int mod = 1000000007;

int dp(int p)
{
	if (p == n)
		return 1;
	if (memo[p] != 0) return memo[p];
	if (brk.count(p + 1))
	{
		return memo[p] = dp(p + 2);
	}
	else if (brk.count(p + 2))
	{
		return memo[p] = dp(p + 1);
	}
	else
	{
		return memo[p] = (dp(p + 1) + (p + 2 > n ? 0 : dp(p + 2))) % mod;
	}
}

void solve()
{
	cin>>n>>m;
	for (int i = 0 ; i < m; i++)
		cin>>a[i];	
	sort(a, a + m);
	bool impossible = false;
	for (int i = 0; i < m - 1; i++)
		if (a[i] + 1 == a[i + 1])
			impossible = true;
	if (impossible)
	{
		cout<<0<<endl;
	}
	else
	{
		for (int i = 0; i < m; i++)
			brk.insert(a[i]);
		cout<<dp(0)<<endl;
	}
}

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


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

int main(void){
    string number;
    int sum;
    while(true){
        sum = 0;
        cin >> number;
        if (number[0] == '0'){
            break;
        }
        for ( int i = 0; i < number.size(); i++ ){
            sum += number[i] - '0'; //ASCIIコードの0を引くことで数値間の引き算を可能にする
        }
        cout << sum << endl;
    }
    return 0;
}


Measured memory_bytes: 3100
n, k = map(int, input().split())
a = sorted([(list(map(int, input().split()))) for i in range(n)])
i = 0

while True:
  if (k - a[i][1]) > 0:
    k -= a[i][1]
    i += 1
  else:
    print(a[i][0])
    break

Measured memory_bytes: 28288
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))
import math
N = ii()

print(math.pi*2*N)

Measured memory_bytes: 9204
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,u) for(int i=start[u];i;i=e[i].next)
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
#define SZ(A) ((int)A.size())
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
inline void myassert(bool a,string s){ if(!a)cerr<<s<<endl,exit(0);}
inline int read()
{
	int s=0,f=1;char ch=getchar();
	while(!isdigit(ch) && ch!='-')ch=getchar();
	if(ch=='-')ch=getchar(),f=-1;
	while(isdigit(ch))s=s*10+ch-'0',ch=getchar();
	return ~f?s:-s;
}

const int maxn=120;

int n,m,col[maxn][maxn];

vector<int>rest[maxn][maxn];

inline void init()
{
	n=read();m=read();
	REP(i,1,n)REP(j,1,m)
	{
		int x=read();
		col[i][j]=(x+m-1)/m;
		rest[i][col[i][j]].push_back(x);
	}
}

int f[maxn][maxn];
int mch[maxn],vis[maxn];

inline bool dfs(int u)
{
	REP(v,1,n)if(f[u][v] && !vis[v])
	{
		vis[v]=1;
		if(!mch[v] || dfs(mch[v]))
		{
			mch[v]=u;
			return 1;
		}
	}
	return 0;
}

int B[maxn][maxn];
int C[maxn][maxn];

inline void doing()
{
	REP(k,1,m)
	{
		REP(i,1,n)REP(j,1,n)f[i][j]=!rest[i][j].empty();
		memset(mch,0,sizeof(int)*(n+1));
		REP(i,1,n)
		{
			memset(vis,0,sizeof(int)*(n+1));
			dfs(i);
		}
		REP(i,1,n)
		{
			int x=mch[i],y=i;
			B[x][k]=rest[x][y].back(); rest[x][y].pop_back();
			C[y][k]=B[x][k];
		}
	}
	REP(i,1,n)REP(j,1,m)printf("%d%c",B[i][j],j==m?'\n':' ');
	REP(i,1,n)REP(j,1,m)printf("%d%c",C[i][j],j==m?'\n':' ');
}

int main()
{
	init();
	doing();
	return 0;
}


Measured memory_bytes: 1152
#include <stdio.h>
//#include <math.h>
int main(){
	int n,a,b,c,d,ans;
	while(scanf("%d",&n)!=EOF){
		ans=0;
		for(a=0; a<=9; a++){
			for(b=0; b<=9; b++){
				for(c=0; c<=9; c++){
					for(d=0; d<=9; d++){
						if(a+b+c+d==n)ans+=1;
					}
				}
			}
		}
		printf("%d\n",ans);
	}

	return 0;
}

Measured memory_bytes: 596
# -*- coding: utf-8 -*-
# B - AcCepted
import re

s = str(input())

if s[0] == "A":
    s = s[1:len(s)]

    s2 = s[1:len(s) - 1]
    arr = re.findall("C", s2)
    if len(arr) == 1:
        s2 = re.sub("C", "", s2)
        s = s[0] + s2 + s[len(s) - 1]

        if s.islower():
            print("AC")
            exit()

print("WA")


Measured memory_bytes: 3188
#include <stdio.h>

int main(){
  int A, B;

  scanf("%d %d", &A, &B);

  A = (A - 2)%13;
  if(A < 0){
    A += 13;
  }
  B = (B - 2)%13;
  if(B < 0){
    B += 13;
  }

  if(A > B){
    printf("Alice\n");
  }else if(A == B){
    printf("Draw\n");
  }else if(A < B){
    printf("Bob\n");
  }

  return 0;
}


Measured memory_bytes: 128
#define f(I,H)(p[I]+h[I]*(h[I]-2*H))
long C,h[2<<17],p[2<<17],X,a;
P[2<<17];
s,t=-1,i,x,y;
c(x,y,z){
	return (h[y]-h[x])*(f(y,0)-f(z,0))>=(h[z]-h[y])*(f(x,0)-f(y,0));
}
main(){
	for(scanf("%*d%ld",&C);~scanf("%ld",&a);){
		for(;X=f(P[s],a),s<t&&X>=f(P[s+1],a);s++);
		h[i]=a;
		X=p[i]=i?a*a+C+X:0;
		for(;s<t&&
			//c(P[t-1],P[t],i)
			(h[y=P[t]]-h[x=P[t-1]])*(f(y,0)-f(i,0))>=(h[i]-h[y])*(f(x,0)-f(y,0))
			;t--);
		P[++t]=i++;
	}
	printf("%ld",X);
}

Measured memory_bytes: 4608
#include<bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)
#define ROP(i, n)       for(int i = 1 ; i <= n ; i++)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define VECOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define SORT(obj) sort(ALL(obj))
#define GSORT(obj) sort(ALL(obj) , greater<int>())
#define VLL vector<long long>
#define M map<int, int>
#define S set<int>
#define V vector<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

class UnionFind{
  private:
   vector<int> par;
   vector<int> rank;

  public:
   UnionFind(int n) : par(n), rank(n){
	 for(int i = 0 ; i < n ; i++)
	  par[i] = i, rank[i] = 0;
   }

   int find(int x){
	 if(par[x] == x)  return x;
	 else             return par[x] = find(par[x]);
   }

   void unite(int x, int y){
	 x = find(x);
	 y = find(y);
	 if(x == y)  return;

	 if(rank[x] < rank[y])
	  par[x] = y;
	 else{
	  par[y] = x;
	  if(rank[x] == rank[y]) rank[x]++;
	 }
   }

   bool is_same(int x, int y){
	 return find(x) == find(y);
   }
};


int main(void) {

	ios::sync_with_stdio(false);	cin.tie(0);
    //Zが偶数 -> Axi Ayi ともに偶数もしくはともに奇数
    //Zが奇数 -> Axi Ayi の片方のみ偶数
    int n, m;  cin >> n >> m;
    UnionFind uf(n+2);
    while(m--){
      int x, y, z;  cin >> x >> y >> z;
      uf.unite(x-1,y-1);
    }

    int ans = 0;
    REP(i, n)
      if(uf.find(i) == i)  ans++;

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


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

long long times100(string B)
{
	long long ans = 0;
	for(int i = 0; i < (int)(B.length()); i++)
	{
		if(B[i] == '.')
			continue;
			
		ans = ans * 10 + (B[i] - '0');
	}
	
	return ans;
}

int main()
{
	long long A;
	scanf("%lld", &A);
	
	string B;
	cin >> B;
	
	printf("%lld", A * times100(B) / 100);
}

Measured memory_bytes: 3788
#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>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;



int main() {
    int a, b, c;
    cin >> a >> b >> c;
    int mx = max({a, b, c});
    int mn = min({a, b, c});
    int ans = mx - mn;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3592
#include <stdio.h>
#define mod 998244353
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define ll long long
ll C[4005][4005];
int n,k;
int main()
{
	for (int i=0;i<=4000;i++)
	{
		C[i][0]=1;
		for (int j=1;j<=i;j++) C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
	}
	scanf("%d%d",&k,&n);
	for (int i=2;i<=k<<1;i++)
	{
		ll ans=0,cur=1;
		int cnt=max(min(i>>1,k)-max(i-k,1)+1,0),x=k-(cnt<<1);
		for (int j=0;j<=cnt;j++)
		{
			(ans+=C[cnt][j]*cur%mod*C[n+x-1][x+j-1])%=mod;
			cur=cur*2%mod;
		}
		printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 123648
#![allow(non_snake_case)]
#![allow(unused_imports)]
use ascii::AsciiChar;
use ascii::AsciiStr;
use itertools::Itertools as _;
use permutohedron::LexicalPermutation as _;
use petgraph::algo::dijkstra;
use petgraph::algo::min_spanning_tree;
use petgraph::data::FromElements;
use petgraph::graph::NodeIndex;
use petgraph::graph::UnGraph;
use petgraph::unionfind::UnionFind;
use proconio::fastout;
use proconio::input;
use proconio::marker::Chars;
use proconio::marker::Usize1;
use std::cmp::max;
use std::cmp::min;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use superslice::Ext as _;

#[fastout]
fn main() {
    input! {
        N: usize,
        K: i64,
    }

    let mut ans: i64 = 1;

    for i in 0..N {
        if ans > K {
            ans += K
        } else {
            ans *= 2;
        }
    }

    println!("{}", ans);
}


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

int main() {
	int n;
	string a, b, temp = "";
	cin >> n >> a >> b;

	for(int i = 0; i<n; i++){
		temp += a.substr(i, 1) + b.substr(i, 1);
	}

	cout << temp;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 21474836001234567
#define double long double

int main(){
  int w,h;
  cin>>w>>h;
  vector<string> vec(h);
  rep(i,h) cin>>vec[i];

  int sx,sy,tx,ty;
  vector<int> spx,spy;
  rep(i,h)rep(j,w){
    if(vec[i][j]=='s') sx=i,sy=j;
    if(vec[i][j]=='g') tx=i,ty=j;
    if(vec[i][j]=='*') spx.pb(i), spy.pb(j);
  }

  vector<vector<long>> d(h, vector<long>(w, INF));
  // g?????§??????????????¢
  {
    queue<int> xs,ys;
    d[tx][ty] = 0;
    xs.push(tx); ys.push(ty);
    while(!xs.empty()){
      int x = xs.front(); xs.pop();
      int y = ys.front(); ys.pop();
      const int dx[] = {0,0,-1,1}, dy[] = {-1,1,0,0};
      rep(i,4){
        int nx = x+dx[i];
        int ny = y+dy[i];
        if(vec[nx][ny]!='#' && vec[nx][ny]!='*' && d[nx][ny]>d[x][y]+1){
          d[nx][ny] = d[x][y]+1;
          xs.push(nx);
          ys.push(ny);
        }
      }
    }
  }

  vector<vector<long>> ds(h,vector<long>(w,INF));
  // ????????????spring?????§??????????????¢
  {
    queue<int> xs,ys;
    rep(i,spx.size()){
      xs.push(spx[i]);
      ys.push(spy[i]);
      ds[spx[i]][spy[i]] = 0;
    }
    while(!xs.empty()){
      int x = xs.front(); xs.pop();
      int y = ys.front(); ys.pop();
      const int dx[] = {0,0,-1,1}, dy[] = {-1,1,0,0};
      rep(i,4){
        int nx = x+dx[i];
        int ny = y+dy[i];
        if(vec[nx][ny]!='#' && vec[nx][ny]!='*' && ds[nx][ny]>ds[x][y]+1){
          ds[nx][ny] = ds[x][y]+1;
          xs.push(nx);
          ys.push(ny);
        }
      }
    }
  }

  double p = INF; // ????????§?£???°??????????????¨?????????????§????????????????
  {
    int cnt=1;
    rep(i,h)rep(j,w)if(vec[i][j]=='.') cnt++;

    double l = 0, r = 500.0*500*500*500;
    rep(_,1000){
      double m = (l+r)/2.0;
      double accm = min<double>(d[sx][sy], ds[sx][sy]+m);
      rep(i,h) rep(j,w)if(vec[i][j]=='.'){
        accm += min<double>(d[i][j], ds[i][j]+m);
      }
      p = accm/cnt;
      if(p<m) r = m;
      else l = m;
    }
    p = (r+l)/2.0;
  }

  printf("%.10Lf\n", min<double>(d[sx][sy], ds[sx][sy]+p));

  return 0;
}

Measured memory_bytes: 7292
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

using namespace std;


int main() {
	int k, s;
	cin >> k >> s;
	int ans=0;
	for(int x=0;x<=k;x++)
		for (int y = 0; y <= k; y++) {
			int z = s - x - y;
			if (0 <= z && z <= k)
				ans += 1;
		}
	cout << ans << endl;

}

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

using namespace std;

int main(){

int H, R;
cin>>H>>R;

if(H + R > 0) cout<<"1"<<endl;
if(H + R == 0) cout<<"0"<<endl;
if(H + R < 0) cout<<"-1"<<endl;
return 0;
}


Measured memory_bytes: 3116
N = int(input())

from collections import Counter
def factorize(n):
    d = Counter()
    m = 2
    while m*m <= n:
        while n%m == 0:
            n //= m
            d[m] += 1
        m += 1
    if n > 1:
        d[n] += 1
    return d

fs = Counter()
for i in range(1,N+1):
    fs += factorize(i)

MOD = 10**9+7
ans = 1
for v in fs.values():
    ans *= (v+1)
    ans %= MOD
print(ans)

Measured memory_bytes: 3316
//  RAKSHIT KADAM

 #include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> 3
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree< int ,  null_type ,  less<int> ,  rb_tree_tag ,  tree_order_statistics_node_update>
#warning !!!check the size of arrayss!!!
 
// NUMERIC DEFINITIONS :
    #define INF 100000000000000005
    #define inf 1000000004
    #define MOD  1000000007
    #define mod 998244353
    #define MAX 300006
    #define pi 3.1415926535897932384626433832795
#define ld long double
 #define ll long long
 #define int long long
 
 #define P(gg) for(auto rax:gg){cout<<rax<<" ";}cout<<endl;
 #define Need_for_speed(activated) ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
 #define satisfy ll ter; cin>> ter; while(ter--)
 #define inp(n) int n;cin >> n
 #define mp make_pair
 #define pb push_back
 #define endl "\n"
 #define x first
 #define y second
 #define fore(i,a,b) for(ll i=a;i<b;i++)
 #define forci(i,n) for(ll i=0;i<n;i++)
 #define vi vector<ll>
 #define Endl endl
 #define lb lower_bound
 #define ub upper_bound
#define pii pair<ll,ll>
 
 #define input freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout)
 #define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;
 
ll gcd(ll a, ll b){if (b == 0)return a;return gcd(b, a % b);}
int power(int x, unsigned int y, unsigned int m){ if (y == 0) return 1;int p = power(x, y/2, m) % m;  p = (p * p) % m;return (y%2 == 0)? p : (x * p) % m;}
ll modInverse(int a, int m){{ return power(a, m-2, m);}}
const int maxn = 500003;
 ll fact[1000005];
//ll modIN[1000005];
//void facto()
//{
//    ll lim =1000005;fact[0]=1;
//    for(ll i=1;i<lim;i++)
//    {
//        fact[i]=(fact[i-1]*i)%MOD;
//    }
//    modIN[n]=modInverse(fact[n],MOD);
//    for(ll i=n-1;i>=1;i--)
//    {
//        modIN[i] = (modIN[i+1]*(i+1))%MOD;
//    }
//}
//ll ncr(ll a,ll b)
//{
//    ll ret = 0;
//    ret = fact[a]*(modIN[b]);
//    ret%=MOD;
//    ret*=modIN[a-b];
//    ret%=MOD;
//    return ret;
//}
void solve()
{
    string s;cin>>s;
    ll x=0;
    for(auto it:s)
    {
        x+=it-'0';
        
    }
    if(x%9)
        cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
   
}
signed main()
{
   Need_for_speed(activated);
    
//    satisfy
//    {
// solve();
//    }
//
//
    solve();
    
    return 0;
}


Measured memory_bytes: 3784
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
const int mod = 1000000007;
ll cnt = 0;

int main(){
  string s; cin >> s;
  int n = s.size();

  int a=0,b=0,c=0;

  for(int i=0;i<n;i++){
      if(s.at(i) == 'a')a++;
      if(s.at(i) == 'b')b++;
      if(s.at(i) == 'c')c++;

  }
  if( abs(a-b)>=2 || abs(a-c)>=2 || abs(c-b)>=2 ){
      cout << "NO" << endl;
  }else cout << "YES" << endl;
  
}

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

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

    int h,w;
    cin>>h>>w;
    int cnt[30]={};
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            char c;
            cin>>c;
            cnt[c-'a']++;
        }
    }
    bool f=true;
    if(h%2==0 && w%2==0){
        for(int i=0;i<26;i++){
            cnt[i]%=4;
            if(cnt[i]!=0)f=false;
        }
    }
    else if ((h*w)%2==1){
        int f1=1,f2=(h-1)/2+(w-1)/2;
        for(int i=0;i<26;i++){
            cnt[i]%=4;
            if(cnt[i]>=2 && f2!=0){
                f2--;
                cnt[i]-=2;
            }
            if(cnt[i]==1 && f1!=0){
                f1--;
                cnt[i]--;
            }
            if(cnt[i]!=0)f=false;
        }
    }
    else if(h%2==1){
        int f1=w/2;
        for(int i=0;i<26;i++){
            cnt[i]%=4;
            if(cnt[i]==2 && f1!=0){
                f1--;
                cnt[i]-=2;
            }
            if(cnt[i]!=0)f=false;
        }
    }
    else{
        int f1=h/2;
        for(int i=0;i<26;i++){
            cnt[i]%=4;
            if(cnt[i]==2 && f1!=0){
                f1--;
                cnt[i]-=2;
            }
            if(cnt[i]!=0)f=false;
        }
    }

    if(f)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

}

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

static const int MAX = 100;
int main(){
    int A[MAX], n;
    cin >> n;
    for(int i = 0; i < n; i++){
        scanf("%d",&A[i]);
    }
    for(int i = 1; i < n; i++){
        int v = A[i];
        int j = i-1;
        for(int l = 0; l < n-1; l++){
            printf("%d ", A[l]);
        }
        printf("%d",A[n-1]);
        while(j >= 0 && A[j] > v){
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        printf("\n");
    }
    for(int l = 0; l < n-1; l++){
            printf("%d ", A[l]);
    }
    printf("%d",A[n-1]);
    printf("\n");
    return 0;
}


Measured memory_bytes: 3240
D, G = gets.split.map(&:to_i)
ary = D.times.map{gets.split.map(&:to_i)}
min_cnt = D*100
# 完全に解くか全く解かないかの組み合わせ
[0, 1].repeated_permutation(ary.size) do |a|
    # 完全に解いた結果の回数と得点
    sum, cnt = 0, 0
    a.size.times do |n|
        next if a[n] == 0
        cnt += ary[n][0]
        sum += 100*(n+1)*ary[n][0] + ary[n][1]
        min_cnt = [min_cnt, cnt].min if sum >= G
    end
    # 解いていないもののうち一番大きいiのケースだけ判定
    idx = a.rindex(0)
    next unless idx
    ary[idx][0].times do |n|
        cnt += 1
        sum += 100*(idx+1)
        min_cnt = [min_cnt, cnt].min if sum >= G
    end
end
puts min_cnt

Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define PRINT(x) cout<<(x)<<endl
#define INF 1000000000000 // 10^12
#define MOD 1000000007 // 10^9+7
#define PB push_back
#define MP make_pair

const int MAX_N = 44;

int n;

int dp[MAX_N];

int main() {
    cin >> n;
    dp[0] = 1, dp[1] = 1;
    REP2(i, 2, n+1) dp[i] = dp[i-1] + dp[i-2];
    PRINT(dp[n]);
    return 0;
}


Measured memory_bytes: 3116
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tupiii;
typedef tuple<ll, ll, ll> tuplll;

const int INTMAX = 2147483647;
const ll LLMAX = 9223372036854775807;
const int MOD = 1000000007;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
inline void swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
inline void swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }



int main()
{
	string a, b, c;
	cin >> a >> b >> c;

	char res[4];
	res[0] = a.front() - 'a' + 'A';
	res[1] = b.front() - 'a' + 'A';
	res[2] = c.front() - 'a' + 'A';
	res[3] = 0;

	cout << res << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mod 1000000007 //998244353
#include<string.h>
#define inf 1000000000000000000
#define maxn 200006
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
#define endl '\n'
#define mapint_iterator map<int,int> :: iterator
#define mapll_iterator map<ll,ll> :: iterator
#define setint_iterator set<int> :: iterator
#define setll_iterator set<ll> :: iterator
#define setpint_iterator set<pint> :: iterator
#define setpll_iterator set<pll> :: iterator
#define trace(x) cout<<#x<<": "<<x<<" "<<endl
#define trace2(x,y) cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x,y,z) cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a,b,c,d) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define cout1(a) cout<<a<<endl
#define cout2(a,b) cout<<a<<' '<<b<<endl
#define cout3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl
#define cout4(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl
#define vcout(v,i) cout<<v[i].fi<<" "<<v[i].se<<endl
typedef priority_queue<ll,vector<ll>,greater<ll> > pqset;
typedef priority_queue<pint,vector<pint>,greater<pint> > pqset_ll;
#define pb push_back
#define fi first
#define se second
#include<ext/pb_ds/assoc_container.hpp>
ll dxk[]={0,0,1,-1,1,1,-1,-1};
ll dyk[]={1,-1,0,0,1,-1,1,-1};
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> os;
typedef tree<pll,null_type,less<pll>,rb_tree_tag,tree_order_statistics_node_update> os_pair;
#define acc (ios::sync_with_stdio(false),cin.tie(0))
#define rep(i,n) for(ll i=0;i<n;i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define per1(i,n) for(ll i=n;i>0;i--)
#define repeat(i,start,n) for(ll i=start;i<n;i++)
#define print(a,n) for(ll i=0;i<n;i++){ cout<<a[i]<<" ";}
ll ll_max(ll a,ll b,ll c){return max(a,max(b,c));}
int int_max(int a,int b,int c){return max(a,max(b,c));}
ll ll_min(ll a,ll b,ll c){return min(a,min(b,c));}
int int_min(int a,int b,int c){return min(a,min(b,c));}
ll max(int a,ll b){ return max((ll)a,b);}
ll min(int a,ll b){ return min((ll)a,b);} 
ll min(ll a,int b){ return min(a,(ll)b);}
ll max(ll a,int b){ return max(a,(ll)b);}
ll dx[]={0,0,1,-1};
ll dy[]={1,-1,0,0};
//ifstream cin("b_read_on.txt"); ofstream cout("output3.txt");
//Chronology: Binary Search,Greedy,dp,dfs and similar
//Use (<<) for multiplication
//Use (>>) for division
// In dp, first try top-down,then bottom-up
//ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);cout<<fixed;cerr.tie(NULL);cout.precision(10);
// find_by_order -> value at index
// order_of_key -> index of value
void solve(int countu){
	ll a,b,c;
	cin>>a>>b>>c;
	swap(a,b);
	swap(a,c);
	cout3(a,b,c);
}
int main(){
    //ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);cout<<fixed;cerr.tie(NULL);
    int t=1;
	//cin>>t;
	int countu=1;
    while(t--){
    	solve(countu);
    	countu++;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define LL long long
#define st first
#define nd second
#define endl '\n'
using namespace std;
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	LL a[n],sum=0,cur=0,ans=1e17;
	for(int i=0;i<n;++i)
		cin>>a[i];
	for(int i=0;i<n;++i) {
		sum+=a[i];
		if(i%2==0&&sum>=0) {
			cur+=sum+1;
			sum=-1;
		}
		else if(i%2==1&&sum<=0) {
			cur+=abs(sum)+1;
			sum=1;
		}
	}
	ans=min(ans,cur);
	cur=sum=0;
	for(int i=0;i<n;++i) {
		sum+=a[i];
		if(i%2==0&&sum<=0) {
			cur+=abs(sum)+1;
			sum=1;
		}
		else if(i%2==1&&sum>=0) {
			cur+=sum+1;
			sum=-1;
		}
	}
	ans=min(ans,cur);
	cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#include<utility>
#include <numeric>
 
using namespace std;
typedef long long ll;
 
int main(){
ll n,k;
cin>>n>>k;
if(n%2==0){
if(k<=n/2)
cout<<"YES";
else
cout<<"NO";
}
else{
if(k<=(n/2)+1)
cout<<"YES";
else
cout<<"NO";

}
  return 0;
 
}
 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
  ll A, B;
  cin >> A >> B;
  if(A <= 0 && 0 <= B) {
    cout << "Zero" << endl;
  }
  else if(A > 0) {
    cout << "Positive" << endl;
  }
  else {
    if((B - A) % 2 == 0) {
      cout << "Negative" << endl;
    }
    else {
      cout << "Positive" << endl;
    }
  }
}

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

using namespace std;

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// cout << fixed << setprecision(20);

int N;
int p[1100];
signed main() {
    cin>>N;
    int cnt=0;
    for(int i=1;i<=N;i++){
        cin>>p[i];
        if(p[i]!=i)cnt++;
    }
    if(cnt<=2)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    vi p(n);
    rep(i,n) cin>>p[i];
    {
        bool ok=true;
        rep(i,n-1)if(p[i]>p[i+1]) ok=false;
        if (ok){
            cout<<"YES\n";
            return 0;
        }
    }
    rep(i,n)FOR(j,i+1,n-1){
        vi a = p;
        swap(a[i],a[j]);
        bool ok=true;
        rep(i,n-1)if(a[i]>a[i+1]) ok=false;
        if (ok){
            cout<<"YES\n";
            return 0;
        }
    }
    cout<<"NO\n";
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
    int n;
    scanf("%d",&n);

    int m;
    scanf("%d",&m);

    int ans=0,sum=0,x;
    for(int i = 0;i < n; i++){
        for(int j = 0;j < m; j++){
            scanf("%d",&x);
            sum += x;
        }
        ans = max(ans,sum);
        sum = 0;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 1032
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
#include <array>
#include <numeric>
#include <regex>
#include <bitset>
#include <deque>

using namespace std;
typedef long long ll;
typedef pair<int, int> p_ii;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)

const int INF = 1e9;
const double PI = acos(-1.0);
const ll MOD = 1e9 + 7;



int main() {
	int n;
	cin >> n;
	vector<string>w(n);
	rep(i, n)cin >> w[i];
	set<string> check;

	rep(i, n) {
		if (i>0&& w[i][0] != w[i-1][w[i-1].size()-1]||check.count(w[i]) != 0) {
			cout << "No" << endl;
			return 0;
		}
		check.insert(w[i]);
	}
	cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(unsigned long long i = (a); i < (b); i++)
#define iter(it,c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end();++it)
typedef pair<unsigned long long,unsigned long long> ii;
typedef vector<unsigned long long> vi;
typedef vector<ii> vii;
typedef long long ll;
const unsigned long long INF = ~(1<<31);
const double pi = acos(-1);

int main() {
	cin.sync_with_stdio(false);
	unsigned long long n;
	cin >> n;
	priority_queue<ii,vector<ii>, greater<ii>> pq;
	rep(i,0,n) {
		unsigned long long hold;
		cin >> hold;
		pq.push(ii(hold,1));
	}
	rep(i,0,n-1) {
		ii first = pq.top();	
		pq.pop();
		ii second = pq.top();
		pq.pop();
		unsigned long long colors = 0;
		if(first.first*2 >= second.first && second.first*2 >= first.first) colors = second.second+first.second;
		else colors = second.second;
		unsigned long long third = first.first+second.first;
		pq.push(ii(third,colors));
	}
	ii k = pq.top();
	cout << k.second << endl;
	return 0;
}


Measured memory_bytes: 2548
import "dart:io";

void main(){
  int k = int.parse(stdin.readLineSync());
  List<String> inputStrList = stdin.readLineSync().split(" ");
  int a = int.parse(inputStrList[0]);
  int b = int.parse(inputStrList[1]);

  for(int i=a; i<=b; i++){
    if(i % k == 0){
      print("OK");
      return;
    }
  }

  print("NG");
}


Measured memory_bytes: 13196
#[allow(unused_macros)]
macro_rules! get {
    ([$t:ty] ; $n:expr) => {
        (0..$n)
        .map(|_| get!([$t])).collect::<Vec<_>>()
    };
    ($($t:ty),+ ; $n:expr) => {
        (0..$n).map(|_| get!($($t),+)).collect::<Vec<_>>()
    };
    ([$t:ty]) => {
        rl().split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect::<Vec<$t>>()
    };
    ($t:ty) => {
        rl().parse::<$t>().unwrap()
    };
    ($($t:ty),*) => {
        {
            let line =rl();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap()),*)
        }
    };
}
fn rl() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn main() {
    let (n, m, c) = get!(i32, i32, i32);
    let b = get!([i32]);
    let mut v = Vec::new();
    for _ in 0..n {
        let t = get!([i32]);
        v.push(t);
    }
    //eprintln!("{:?}", v);
    let mut ans = 0;
    for i in 0..v.len() {
        let mut sum = 0;
        for j in 0..v[i].len() {
            sum += v[i][j] * b[j];
        }
        sum += c;
        if sum > 0 {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#!/usr/bin/env php
<?php
fscanf(STDIN, "%d", $N);
$array = array_map(function($v) {return (int)$v;}, explode(' ', rtrim(fgets(STDIN))));

$plus = [];
$first_max = max($array);
$first_min = min($array);

$direct_plus = true;
if ($first_min >= 0) {
    $direct_plus = true;
} elseif ($first_max <= 0) {
    $direct_plus = false;
} elseif ($first_max > abs($first_min)) {
    $direct_plus = true;
    $k = array_search($first_max, $array, true);
    for ($i = 0; $i < $N; $i++) {
        if ($array[$i] < 0) {
            $plus[] = sprintf("%d %d", $k + 1, $i + 1);
            $array[$i] += $array[$k];
        }
    }
} else {
    $direct_plus = false;
    $k = array_search($first_min, $array, true);
    for ($i = 0; $i < $N; $i++) {
        if ($array[$i] > 0) {
            $plus[] = sprintf("%d %d", $k + 1, $i + 1);
            $array[$i] += $array[$k];
        }
    }
}

if ($direct_plus) {
    for ($i = 0; ($i + 1) < $N; $i++) {
        $a = $array[$i];
        $b = $array[$i + 1];
        while ($a > $b) {
            $mx = max($array);
            $k = null;
            if ($a > ($b + $mx)) {
                $k = array_search($mx, $array, true);
            } else {
                $mn = $mx;
                foreach ($array as $j => $v) {
                    if ($a <= ($b + $v) && $mn >= $v) {
                        $k = $j;
                        $mn = $v;
                    }
                }
            }
            $plus[] = sprintf("%d %d", $k + 1, $i + 2);
            $array[$i + 1] += $array[$k];
            $b = $array[$i + 1];
        }
    }
} else {
    for ($i = $N - 1; $i >= 1; $i--) {
        $a = $array[$i - 1];
        $b = $array[$i];
        while ($a > $b) {
            $mn = min($array);
            $k = null;
            if (($a + $mn) > $b) {
                $k = array_search($mx, $array, true);
            } else {
                $mx = $mn;
                foreach ($array as $j => $v) {
                    if (($a + $v) <= $b && $mx <= $v) {
                        $k = $j;
                        $mx = $v;
                    }
                }
            }
            $plus[] = sprintf("%d %d", $k + 1, $i);
            $array[$i - 1] += $array[$k];
            $a = $array[$i - 1];
        }
    }
}

echo count($plus).PHP_EOL;
if (count($plus)) {
    echo implode(PHP_EOL, $plus).PHP_EOL;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;

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

  int sum = 0;
  rep(i, m) {
    int t;
    cin >> t;
    sum += t;
  }

  if (sum > n) {
    cout << "-1";
  } else if (sum == n) {
    cout << "0";
  } else {
    cout << n - sum;
  }
}

Measured memory_bytes: 3624
using System;

class Program
{
 static void Main(string[] args)
 {
  int cnt;
  int bollNum = 0;
  string massNum;
   
  massNum = Console.ReadLine();
   
  for( cnt = 0; cnt < 3; cnt++ )
  {
    if( massNum[cnt] == '1' )
    {
      bollNum++;
    }
  }
  
  Console.WriteLine(bollNum);
 }
}



Measured memory_bytes: 13140
//{{{
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printw) FUNC(printwe) FUNC(printb) FUNC(printbe) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m, c;
    cin >> n >> m >> c;
    vector<int> bs(m); cin >> bs;
    int ans = 0;
    for(int i = 0; i < n; i++){
        vector<int> as(m); cin >> as;
        int sum = c;
        for(int j = 0; j < m; j++){
            sum += as[j] * bs[j];
        }
        ans += sum > 0;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 256
from itertools import permutations 
a = [int(i) for i in input().split()]
p = permutations(a,3)
mn = 10**10
for i in p:
    cost = 0
    cost += abs(i[0]-i[1])
    cost += abs(i[1]-i[2])
    mn = min(mn,cost)
print(mn)

Measured memory_bytes: 39700
import sys
X,Y = map(int,input().split())
y = Y / 2
if Y % 2 != 0:
    print("No")
    sys.exit()

for i in range(0,X + 1):
    for j in range(0,X + 1):
        if i + j == X:
            if Y == 2 * i + 4 * j:
                print("Yes")
                sys.exit()
print("No")

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

using namespace std;

int main() {
	long long int n;
	string kazu = "01235789";
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		string b = "";
		while (n != 0) {
			b += kazu[n%8];
			n /= 8;
		}
		for (int i = b.size()-1; i >= 0; i--) {
			cout << b[i];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1200
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

# 1点を0,0で固定、面積公式よりx1y2-x2y1=S
# x1=10**9,x2=1(0にすると変数が減るので駄目？)
# y2を切り上げ気味に近づける（切り下げ気味だとy1が負になりうる）
# x2y1=x1y2-Sよりy1も求まる

def main():
  s=I()
  x1=0
  y1=0
  x2=10**9
  x3=1
  y3=(s+x2-1)//x2
  y2=x2*y3-s

  print(x1,y1,x2,y2,x3,y3)

main()
# print(main())


Measured memory_bytes: 5172
num_word = int(input())
word_list = []
flag = True

for i in range(num_word):
    word_list.append(input())

for j in range(num_word - 1):
    word1 = word_list[j]
    word2 = word_list[j + 1]
    for k in range(j):
        if word1 == word_list[k]:
            flag = False
            break
    if word1[len(word1) - 1] != word2[0]:
        flag = False
        break
for l in range(num_word  - 1):
    if word_list[num_word - 1] == word_list[l]:
        flag = False

if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#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() {
  string s, t;
  cin >> t;
  ll k;
  cin >> k;
  s=t;
  if(s==string(s.size(),s[0])) {
    cout << s.size()*k/2 << endl;
    return 0;
  }
  ll ans=0;
  for(int i=1; s[i]!='\0'; i++) {
    if(s[i]==s[i-1]) {
      ans++;
      s[i]='*';
    }
  }
  ans*=k;
  int n1=1, n2=1;
  for(int i=1; i<t.size(); i++) {
    if(t[0]==t[i]) n1++;
    else break;
  }
  for(int i=t.size()-2; i>=0; i--) {
    if(t.back()==t[i]) n2++;
    else break;
  }
  if(n1%2==1&&n2%2==1&&t[0]==t.back()) ans += k-1;

  cout << ans << endl;
}


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

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

  int n, m;
  cin >> n >> m;
  vector<tuple<int, int>> ab(n);
  vector<tuple<int, int>> cd(m);
  int x, y;
  for (int i = 0; i < n; i++) {
    cin >> x >> y;
    ab[i] = make_tuple(x, y);
  }
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    cd[i] = make_tuple(x, y);
  }

  for (tuple<int, int> &xy : ab) {
    int a, b;
    a = get<0>(xy);
    b = get<1>(xy);
    int dist = 1001001001;
    int p;
    for (int i = 0; i < m; i++) {
      int c, d;
      c = get<0>(cd[i]);
      d = get<1>(cd[i]);
      int tmp = abs(c - a) + abs(d - b);
      if (tmp < dist) {
        dist = tmp;
        p = i + 1;
      }
    }
    cout << p << '\n';
  }
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
    int main() {   
        int x, k, k_t;
        scanf("%d", &k);
        scanf("%d", &x);
        k_t = k * 500;
        if(k_t >= x){
            printf("Yes");
        }else{
            printf("No");
        }
        return 0;
    }

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(){
	int k, s, cnt = 0;
	cin >> k >> s;
	for (int x = 0; x <= k; x++)
		for (int y = 0; y <= k; y++)
			if (s - x - y >= 0 && s - x - y <= k)cnt++;
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.PrintWriter
import java.util.*

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val s = readLine()!!.toCharArray()
    val q = readLine()!!.toInt()

    val t = mutableMapOf<Char, TreeSet<Int>>()
    for (i in 0 until 26) {
        t['a' + i] = sortedSetOf()
    }

    for (i in s.indices) {
        t[s[i]]!!.add(i)
    }

    val pw = PrintWriter(System.out)

    repeat(q) {
        val query = readLine()!!.split(' ')
        if (query[0] == "1") {
            val (i, c) = query[1].toInt() - 1 to query[2][0]
            t[s[i]]!!.remove(i)
            s[i] = c
            t[c]!!.add(i)
        } else {
            val (l, r) = query[1].toInt() - 1 to query[2].toInt() - 1

            (0 until 26)
                    .filter {
                        val p = t['a' + it]!!.higher(l - 1) ?: n
                        p <= r
                    }
                    .count()
                    .let { pw.println(it) }
        }
    }

    pw.flush()
}


Measured memory_bytes: 99972
n, w = map(int, input().split())
wt, v = [], []
for i in range(n):
    a, b = map(int, input().split())
    wt.append(a)
    v.append(b)
dp = [[0 for i in range(w + 1)] for j in range(n + 1)]
for i in range(1, len(wt)+1):
    for j in range(w + 1):
        if j >= wt[i-1]:
            dp[i][j] = max(dp[i-1][j], v[i - 1] + dp[i - 1][j - wt[i - 1]])
        else:
            dp[i][j] = dp[i-1][j]
print(dp[-1][-1])


Measured memory_bytes: 171912