akhauriyash/Code-Regression huggingface dataset:
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 2e5+5;

int n;
int k;
int h[N];
long long sm = 0;

int main(){
    cin >> n >> k;
    for(int i = 1; i <= n; i++){
        cin >> h[i];
    }
    if(k >= n){
        puts("0");
        return 0;
    }
    sort(h + 1 , h + n + 1);
    for(int i = n - min(k , n); i >= 1; i--){
        sm += h[i];
    }
    cout << sm << endl;
}


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

signed main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    
    //int t=1 ; cin>>t ; while(t--)
    {
    	int n;
    	string s;
    	cin >> n >> s;

    	int f = n%2==0;
    	if(n%2==0)
    	{
    		for(int i=0;i<n/2;i++)
    		{
    			if(s[i] != s[n/2+i])
    				f = 0;
    		}
    	}

    	if(f == 1)
    		cout << "Yes\n";
    	else
    		cout << "No\n";
    }
    
    cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
long long int n,arr[100005],i,t[100005];
scanf("%lld",&n);
for(i=0;i<n;i++){
scanf("%lld",&arr[i]);}
for(i=0;i<=n;i++){
t[arr[i]-1]=i+1;}
for(i=0;i<n;i++){
    printf("%lld",t[i]);
    if(i==n-1){
        break;
    }
    else{
        printf(" ");
    }
}
}


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

int main() {
  int H, W;
  cin >> H >> W;
  
  for (int i = 0; i < W + 2; i++) {
    cout << "#";
  }
  cout << endl;

  for (int j = 0; j < H; j++) {
    vector<char> vec(W);
    cout << "#";
    
    for (int i = 0; i < W; i++) {
      cin >> vec.at(i);
      cout << vec.at(i);
    }
    cout << "#" << endl;
  }
  for (int i = 0; i < W + 2; i++) {
    cout << "#";
  }
}

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
class point{
public:
    double x,y;
    point(double x=0,double y=0):x(x),y(y){};               //1.记得设初值
    point operator +(point a){
        return point(x+a.x,y+a.y);
    }
    point operator -(point a){
        return point(x-a.x,y-a.y);
    }
    double operator *(point a){
        return x*a.x+y*a.y;
    }
    point operator *(double a){
        return point(x*a,y*a);
    }
    void print(){
        printf("%.10lf %.10lf\n",x,y);
    }
};
struct segment{
    point p1,p2,base;
    segment(point a,point b){                                          //1.不然无法构造形参
        p1=a,p2=b,base=b-a;
    }
};
void project(segment s,point p){
    double r=(p-s.p1)*s.base/(s.base*s.base);
    (s.p1+s.base*r).print();
    return;
}
int main(){
    int n;
    double x1,y1,x2,y2;
    scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
    segment s(point(x1,y1),point(x2,y2));
    scanf("%d",&n);
    for(int i=1;i<=n;++i){
        scanf("%lf%lf",&x1,&y1);
        project(s,point(x1,y1));
    }
    return 0;
}


Measured memory_bytes: 2756
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
// #include <iostream>
// #include <array>
// #include <cmath>
// #include <array>
// #include <vector>
// #include <set>
// #include <algorithm>
// #include <functional>
// #include <numeric>
// #include <map>
// #include <unordered_map>
// #include <queue>
using namespace std;
// #define MOD  998244353
// #define MOD ll(1e9) + 7
#define ll long long
const double PI = atan(1.0) * 4;
// const int N = 1e5 + 5 ;
// const ll INF = (int)1e9 ;
const int dx[4] = { -1, 0, 1, 0} ;
const int dy[4] = {0, -1, 0, 1} ;
// const ll INF = (ll)2e18 + 50;
const ll INF = 1e9 ;
const ll MOD = 1e9 + 7 ;
const int M = 1e6 + 50 ;


ll power(ll a , ll e) {
	ll res = 1LL ;
	while (e > 0) {
		if (e % 2 == 1) res = res * a % MOD ;
		a =  a * a % MOD ;
		e /= 2 ;
	}
	return res ;
}
vector<int> complement(const vector<int> &vec) {
	int n = vec.size() ;
	vector<bool> occur(n + 1 , true) ;
	vector<int> ans ;
	for (int i = 0 ; i < (int)vec.size() ; i++) {
		occur[vec[i]] = false ;
	}
	for (int i = 1 ; i <= n ; i++) {
		if (occur[i]) ans.push_back(i) ;
	}
	return ans ;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	// int t ;
	// cin >> t;
	// while (t--) {
	int n ;
	cin >> n;
	vector<int> a(n);
	for (int i = 0 ; i < n ; i++) {
		cin >> a[i] ;
	}
	sort(a.begin(),a.end()) ;
	vector<int> cnt(M) ;
	for (int x : a) {
		if (cnt[x]) {
			cnt[x] = 2 ;
			continue ;
		}
		for (int i = x ; i < M ; i += x) {
			cnt[i]++ ;
		}
	}
	int ans = 0 ;
	for (int x : a) {
		if (cnt[x] == 1) ans++ ;
	}
	cout << ans << "\n";



	// }
	return 0;
}


Measured memory_bytes: 7948
#include <bits/stdc++.h>
#define rep(i,n,m) for(int i=n;i<(int)(m);i++)
#define rrep(i,n,m) for(int i=((int)(n)-1);i>=m;i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> a(n),b(n),c(n);
    rep(i,0,n) cin>>a[i];
    rep(i,0,n) cin>>b[i];
    rep(i,0,n) cin>>c[i];
    sort(all(a));
    sort(all(b));
    sort(all(c));
    
    vector<ll> v(n);
    int jou=0;
    rep(i,0,n){
        while(jou<n && a[jou]<b[i]) jou++;
        v[i]=jou;
    }
    
    vector<ll> w(n);
    int ge=n-1;
    rrep(i,n,0){
        while(ge>=0 && b[i]<c[ge]) ge--;
        w[i]=n-1-ge;
    }
    
    ll ans=0;
    rep(i,0,n) ans+=v[i]*w[i];
    cout<<ans<<endl;
    
}



Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
#define mx 100005
#define ll long long
#define mod 1000000007

int ar[mx];
char ch[mx];

ll a,b,n;

ll func(ll x)
{
    ll val1=(a*x)/b;
    ll val2=(x/b)*a;
    return val1-val2;
}

void solve()
{

  cin>>a>>b>>n;
  ll l=1,r=n;
  ll re=max(func(1),func(r));
  while(l<=r)
  {
      ll mid1=l+(r-l)/3;
      ll mid2=r-(r-l)/3;
      ll val1=func(mid1);
      ll val2=func(mid2);
      re=max({re,val1,val2});

      if(val1>val2)
      {
          r=mid2-1;
      }
      else if(val1<val2) l=mid1+1;
      else
      {
          l=mid1+1;
          r=mid2-1;
      }
  }
  cout<<re<<endl;
}

int main()
{
    int t=1;
    //scanf("%d",&t);
    while(t--)solve();
    return 0;
}



Measured memory_bytes: 3640
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
#include<utility>
#include<deque>

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int main(){
  int n, ans = 0;
  cin >> n;
  vector<deque<int>> q(n);
  deque<int> q1;
  for(int i = 0; i < n; i++){
    q1.push_back(i);
    for(int j = 0; j < n - 1; j++){
      int x;
      cin >> x;
      x--;
      q[i].push_back(x);
    }
  }
  int g = n * (n - 1) / 2;
  while(g > 0){
    deque<int> q2;
    while(!q1.empty()){
      int x = q1.front();
      q1.pop_front();
      if(q[x].empty()) continue;
      int a = q[x].front();
      if(a == -1) continue;
      if(q[a].empty()) continue;
      int b = q[a].front();
      if(b == -1) continue;
      if(x == b){
        q2.push_back(a);
        q2.push_back(b);
        q[a][0] = -1;
        q[b][0] = -1;
        g--;
      }
    }
    ans++;
    if(q2.empty()) break;
    q1 = q2;
    while(!q2.empty()){
      int p = q2.front();
      q2.pop_front();
      q[p].pop_front();
    }
  }
  cout << (g == 0? ans : -1) << endl;
  return 0;
}


Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

typedef long long int ll;
#define int long long int
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define FRE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define debug cout << "debug" << endl;
#define f(i,n) for(ll i=0;i<n;i++)
#define fa(i,a,n) for(ll i=a;a<n?i<n:i>=n;a<n?i+=1:i-=1)
#define loop(i,a, n) for(ll i = a; i <= n; i++)
#define loopb(i,a, n) for(ll i = a; i >= n; i--)
#define pb push_back
#define pf push_front
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define setmem(x, k) memset(x, k, sizeof(x))
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define PI 3.1415926535897932384626
#define MOD 1000000007
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int>	vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef long double ld;
typedef vector<vector<ll>> matrix;
ll dx[] = {0, 1, 0, -1};
ll dy[] = {-1, 0, 1, 0};
const ll N = 1e7+5;
// ll a[N], b[N], dp[N], level[N], vis[N], in[N], out[N];
// vl g[N];
ll n, m;



void solve() {
	ll t, x, y, l, r;
	ll x1, x2, x3, x4, x5;
	cin >> x1 >> x2 >> x3 >> x4 >> x5;
	map<ll, ll>mp;
	mp[x1]++;
	mp[x2]++;
	mp[x3]++;
	mp[x4]++;
	mp[x5]++;
	fa(i, 1, 6){
		if(mp[i] == 0){
			cout << i << endl;
			return;
		}
	}
}

int32_t main() {
	IOS
	ll T;
	// cin >> T;
	// while(T--)
	solve();
	cerr<<"Time elapsed : "<<clock()*1000.0/CLOCKS_PER_SEC<<"ms"<<'\n'; 
	return 0;
}

Measured memory_bytes: 3776
import java.util.*;
import java.io.*;

public class Main {

  private static void solve() {
    int h = nextInt();
    int w = nextInt();

    char[][] g = new char[h][w];

    for (int i = 0; i < h; i++) {
      g[i] = next().toCharArray();
    }

    boolean[][] visit = new boolean[h][w];

    long ans = 0;
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        if (g[i][j] == '#' && !visit[i][j]) {
          ans += bfs(i, j, visit, g, h, w);
        }
      }
    }

    System.out.println(ans);
  }

  private static long bfs(int i, int j, boolean[][] visit, char[][] g, int h, int w) {
    int[] dx = {1, -1, 0, 0};
    int[] dy = {0, 0, 1, -1};
    Queue<int[]> queue = new LinkedList<>();
    queue.offer(new int[] {i, j, 0});
    visit[i][j] = true;

    long black = 1;
    long white = 0;
    while (!queue.isEmpty()) {
      int[] first = queue.poll();

      for (int k = 0; k < dx.length; k++) {
        int nx = first[0] + dx[k];
        int ny = first[1] + dy[k];

        int expected = (first[2] == 0 ? 1 : 0);
        char expectedChar = '#';
        if (expected == 1) {
          expectedChar = '.';
        }

        if (nx >= 0 && nx < h && ny >= 0 && ny < w && expectedChar == g[nx][ny] && !visit[nx][ny]) {
          visit[nx][ny] = true;
          if (g[nx][ny] == '#') {
            black++;
          } else {
            white++;
          }
          queue.offer(new int[] {nx, ny, expected});
        }
      }
    }
    return black * white;
  }

  private static void run() {
    br = new BufferedReader(new InputStreamReader(System.in));
    out = new PrintWriter(System.out);

    solve();

    out.close();
  }

  private static StringTokenizer st;
  private static BufferedReader br;
  private static PrintWriter out;

  private static String next() {
    while (st == null || !st.hasMoreElements()) {
      String s;
      try {
        s = br.readLine();
      } catch (IOException e) {
        return null;
      }
      st = new StringTokenizer(s);
    }
    return st.nextToken();
  }

  private static int nextInt() {
    return Integer.parseInt(next());
  }

  private static long nextLong() {
    return Long.parseLong(next());
  }

  public static void main(String[] args) {
    run();
  }
}

Measured memory_bytes: 38252
#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;

int main() {
	long long int N, M;
	long long int result = 0;
	unordered_map<string, long long int> mymap_blue;
	unordered_map<string, long long int> mymap_red;
	cin>>N;
	for (int i = 0; i < N; i++) {
		string tmp;
		cin>>tmp;
		++mymap_blue[tmp];
	}
	cin>>M;
	for (int i = 0; i < M; i++) {
		string tmp;
		cin>>tmp;
		++mymap_red[tmp];
	}
	for (auto m : mymap_blue) {
		string s = m.first;
		long long int count = m.second;
		if (mymap_red.find(s) == mymap_red.end()) {
			result = max(result, count);
		}
		else if (mymap_red[s] < count){
			result = max(result, count - mymap_red[s]);
		}
	}
	cout<<result<<endl;
	return 0;
}

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

SP = [list(input().split()) for _ in range(N)]

iSP = [(i, (Si, int(Pi))) for i, (Si, Pi) in enumerate(SP)]

iSP.sort(key=lambda x: -x[1][1])
iSP.sort(key=lambda x: x[1][0])

for i, (Si, Pi) in iSP:
    print(i + 1)


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

int main() {
  int a,b,c;
  cin>>a>>b>>c;
  if(a==b&&a==c){
    cout<<"No"<<endl;
  }
  else if(a!=b&&a!=c&&b!=c){
    cout<<"No"<<endl;
  }
  else {
    cout<<"Yes"<<endl;
  }



 
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <fstream>
#define debug(x) cout << #x << " = " << x << endl
#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); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;


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

  int n,k;
  cin>>n>>k;
  int d[k];
  rep(i,k) cin>>d[i];
  
  for(int i = n; i <= 10 * n; i++) {
    int t = i;
    bool flag = true;
    while(t > 0) {
      int r = t % 10;
      rep(i,k) {
        if(r == d[i]) flag = false;
      }
      t /= 10;
    }
    if(flag) {
      cout << i << endl;
      return 0;
    }
  }
  

  return 0;

}


Measured memory_bytes: 256
s = input()
res = 0
for i in range(0,10):
    for j in range(i+1,11):
        for x in s[i:j]:
            if x not in ['A','C','G','T']:
                break
        else:
            if res < len(s[i:j]):
                res = len(s[i:j])
print(res)

Measured memory_bytes: 3060
import sys, re
import math
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul	# 
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd	# 最大公約数
from heapq import heappush, heappop

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

# -*- coding: utf-8 -*-

a,b,h,m = MAP()

angleH = (h/12 + m/720) * 2 * pi
angleM = m/60 * 2 * pi

ax = sin(angleH) * a
ay = cos(angleH) * a
bx = sin(angleM) * b
by = cos(angleM) * b
width = max(ax, bx) - min(ax, bx)
height = max(ay, by) - min(ay, by)

print(math.sqrt(width * width + height * height))

Measured memory_bytes: 10968
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int n,a,m=1;
    cin>>n;
    for(int i=0;i<n;i++){
    	cin>>a;
    	m*=((a&1)?1:2);
    }
    cout << pow(3,n)-m <<endl;
    return 0;
}



Measured memory_bytes: 256
o = input()
e = input()
flag = False
if len(o) == len(e):
    length = len(o)
else:
    flag = True
    length = len(e)

ans = ''

for a in range(length):
    ans += o[a]
    ans += e[a]

if flag:
    print(ans + o[-1])
else:
    print(ans)


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


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

struct edge {int to; ll cost; };

int dx[] = {-1, 1, 0,  0};
int dy[] = { 0, 0, 1, -1};

 
int main(){
  string s, t, u;
  int a, b;
  cin >> s >> t >> a >> b >> u;
  if(s==u) a--;
  else b--;
  cout << a << " "<< b;
  return 0;
}


Measured memory_bytes: 3612
maxl = 8

offsetV = ('A', 'B', 'C', 'D', 'E', 'F', 'G')
offset = (((0, 1), (1, 0), (1, 1)),
          ((0, 1), (0, 2), (0, 3)),
          ((1, 0), (2, 0), (3, 0)),
          ((0, 1), (-1, 1), (-1, 2)),
          ((1, 0), (1, 1), (2, 1)),
          ((0, 1), (1, 1), (1, 2)),
          ((1, 0), (-1, 1), (0, 1)),
          )


def match(l, x, y, oi):
    for offX, offY in [a for a in offset[oi]]:
        if 0 <= x + offX < maxl and 0 <= y + offY < maxl:
            pass
        else:
            return False

        if l[y + offY][x + offX] == '0':
            return False
    return True


def solve():
    l = [input() for i in range(8)]
    for y in range(8):
        for x in range(8):
            if l[y][x] == '1':
                for o in range(7):
                    if match(l, x, y, o):
                        return offsetV[o]



try:
    while 1:
        print(solve())
        l = input()
except:
    pass

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second

#define DUMP(x) cout<<#x<<":"<<(x)<<endl
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  LL N, H;
  cin >> N >> H;
  vector<LL> xs(N);
  LL mx = 0;
  REP(i,N){
	LL a;
	cin >> a >> xs[i];
	maxi(mx, a);
  }
  RSORT(xs);

  LL ans = H;
  REP(i,N){
	H -= xs[i];
	mini(ans, i+1 + (H>0? (H+mx-1)/mx: 0ll));
	if(H <= 0) break;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
#include <numeric>
#include <list>
#include <bitset>
using namespace std;

int main()
{
    int A, B, C, X;
    cin >> A >> B >> C >> X;
    int ans = 0;
    for (int i = 0; i <= A; i++)
    {
        for (int j = 0; j <= B; j++)
        {
            for (int k = 0; k <= C; k++)
            {
                if ((500 * i + 100 * j + 50 * k) == X)
                {
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<limits>
#include<iomanip>
#include<cmath>
#include<climits>

using namespace std;

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

const int mod=1e9+7;

int main(){
    string b;
    cin >> b;
    if(b=="A")  cout << 'T';
    else if(b=="T") cout << "A";
    else if(b=="C") cout << "G";
    else if(b=="G") cout << "C";
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll const mod = 1e9+7;

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

Measured memory_bytes: 3628
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
void YN(bool ans){
    if(ans)cout<<"Yes"<<endl;
    else cout <<"No"<<endl;
    return;
}

int main(){
    string S;
    cin>>S;
    ll sum=0;
    rep(i,0,S.size()){
        sum += ll(S[i]-'0');
    }
    YN(sum%9 == 0);
    return 0;
}

Measured memory_bytes: 3736
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define ll long long

using namespace std;

const int N=1e5+10;
int n,m,x,y,cnt,head[N],col[N],sz,flag; ll t[3],ans;
struct edge{int to,nxt,w;}e[N<<1];

void adde(int x,int y,int w){
	e[++cnt].to=y; e[cnt].nxt=head[x]; head[x]=cnt; e[cnt].w=w;
}

void dfs(int u,int c){
	t[col[u]=c]++;
	for (int i=head[u],v;i;i=e[i].nxt){
		v=e[i].to,sz+=e[i].w==1;
		if (col[v]!=-1) flag|=col[v]!=(c+e[i].w)%3;
		else dfs(v,(c+e[i].w)%3);
	}
}

int main(){
	scanf("%d%d",&n,&m);
	rep (i,1,m) scanf("%d%d",&x,&y),adde(x,y,1),adde(y,x,2);
	memset(col,-1,sizeof(col));
	rep (i,1,n) if (col[i]==-1){
		flag=sz=t[0]=t[1]=t[2]=0,dfs(i,0);
		if (flag) ans+=(t[0]+t[1]+t[2])*(t[0]+t[1]+t[2]);
		else if (!t[0]||!t[1]||!t[2]) ans+=sz;
		else ans+=t[0]*t[1]+t[1]*t[2]+t[2]*t[0];
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 6528
#include <chrono>

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <time.h>
#include <random>
#include <string>
#include <cassert>
#include <vector>
#include <ostream>
#include <istream>
#include <stack>
#include <deque>
#include <queue>
#include <functional>

using namespace std;

#define int long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define ld long double

ostream& operator << (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << " ";
    return a;
}

#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << (x) << "\n";
    const int INF = 1e18;
//    const int mod = 2600000069;
//    const int p = 10;
//    const ld PI = 3.1415926535;
#else
    #define dbg(x)
    const int INF = 1e18;
//    const int mod = 2600000069;
//    const int p = 179;
//    const ld PI = 3.1415926535;
#endif

//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,sse3,sse4")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("fast-math")
//#pragma GCC target("avx2")
//#pragma GCC optimize("section-anchors")
//#pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
//#pragma GCC optimize("vpt")
//#pragma GCC optimize("rename-registers")
//#pragma GCC optimize("move-loop-invariants")
//#pragma GCC optimize("unswitch-loops")
//#pragma GCC optimize("function-sections")
//#pragma GCC optimize("data-sections")

const int mod = 1e9 + 7;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifdef LOCAL
    #else
//        freopen("capitals.in", "r", stdin);
//        freopen("capitals.out", "w", stdout);
    #endif
    string s, t;
    cin >> s >> t;
    int n = s.size();
    vector<set<int>> pos(30);
    for (int i = 0; i < n; i++) {
        pos[s[i] - 'a'].insert(i);
    }
    int m = t.size();
    int ans = 0, lst = -1;
    for (int i = 0; i < m; i++) {
        if (pos[t[i] - 'a'].empty()) {
            cout << -1;
            return 0;
        }
        auto ptr = pos[t[i] - 'a'].upper_bound(lst);
        if (ptr == pos[t[i] - 'a'].end()) {
            ans += n - lst - 1;
            lst = *pos[t[i] - 'a'].begin();
            ans += lst + 1;
        } else {
            ans += *ptr - lst;
            lst = *ptr;
        }
    }
    cout << ans;
}
/*

*/


Measured memory_bytes: 5200
import java.util.Scanner;
 
/**
 *
 * @author kke2
 */
public class Main {
 
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int weight  =sc.nextInt();
    int time    =sc.nextInt();
    int i = weight-time;
    if(weight<time){
    i =0;
    }
    System.out.println(i);
    }
}

Measured memory_bytes: 25684
import sys
N = int(sys.stdin.readline().rstrip())
A = list(map(int, sys.stdin.readline().rstrip().split()))
A.sort()
size = 0
r = 0
ans = 0
for l in range(N):
    if l == r:
        r += 1
        size += A[l]
    while r < N and size * 2 >= A[r]:
        size += A[r]
        r += 1
    if r == N:
        ans += 1
print(ans)

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

int main(){
    ll x,y;
    cin >> x >> y;
    ll cnt = 0;
    while(x <= y){
        cnt++;
        x*=2;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
  static public void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    
    String s = sc.nextLine();
    String t = sc.nextLine();
    
    int sLength = s.length();
    int tLength = t.length();
    
    if((sLength+1) != tLength){
      System.out.println("No");
      return;
    }else if(sLength == 0){
      System.out.println("No");
      return;
    }
    
    int errFlag = 0;
    for(int i=0; i<sLength; i++){
      if(s.charAt(i) != t.charAt(i)){
        errFlag = 1;
      }
    }
    
    if(errFlag == 0){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
    
  }
}

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

int main()
{
	int n,l,i;
	cin>>n>>l;
	string a[n+1];
	for(i=1; i<=n; i++)
		cin>>a[i];
	sort(a+1,a+n+1);
	for(i=1; i<=n; i++)
		cout<<a[i];
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")  
#pragma GCC optimize ("-fno-defer-pop")
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
int main(){
	
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll x,a;
	cin>>x>>a;
	if(x<a){
		cout<<"0";
	}
	else {
		cout<<"10";
	}

	return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#include<bitset>
#include<stdio.h>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const int INF = 100000000;

bool isOK(int a[],int index,int key){
    if(a[index] >= key){
        return true;
    }else{
        return false;
    }
}

int binary_search(int a[],int n,int key){
    int left = -1;
    int right = n;

    while(right-left>1){
        int mid = left + (right - left)/2;
        if(isOK(a,mid,key)){
            right = mid;
        }else{
            left = mid;
        }
    }
    return right;
}

int factrial(int n){
    if(n==0){
        return 1;
    }else{
        return n*factrial(n-1);
    }
}

int main(void){
    int n,m;
    int count = 0;
    cin >> n >> m;

    vector<vector<int> > dist(n,vector<int>(m));
    vector<int> distnum(n);
    vector<int> order(n);
    rep(i,n){
        order[i] = i;
    }
    rep(i,n){
        distnum[i] = 0;
    }
    rep(i,n){
        rep(j,m){
            dist[i][j] = -1;
        }
    }
    rep(i,m){
        int a,b;
        cin >> a >> b;
        dist[a-1][distnum[a-1]++] = b-1;
        dist[b-1][distnum[b-1]++] = a-1;
    }
    do{
        rep(i,n-1){
            bool flag2 = false;
            rep(j,distnum[order[i]]){
                if((dist[order[i]][j]==order[i+1]) && order[0]==0){
                    flag2 = true;
                }
            }
            if(!flag2){
                break;
            }
            if(flag2 && i==n-2){
                count++;
            }
        }
    }while(next_permutation(order.begin(),order.end()));

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


Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;

public class Main{
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        if(s.length() == 1){
            System.out.println("0");
            return;
        }

        int s_0 = s.replaceAll("1","").length();
        int s_1 = s.length() - s_0;

        int min = min(s_0, s_1);
        System.out.println(min*2);
    }
}

Measured memory_bytes: 31040
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,n;
  int sum = 0;
  
  cin >> N;
  n = N;
  
  for (int i = 0; i < N; i++) {
    sum += N % 10;
    N /= 10;
    
    if (N % 10 == N) {
      sum += N;
      break;
    }
  }

  if (n % sum == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3636
#include <iostream>
# include <cstdio>

using namespace std;

char s[5];
int main(void){
    // Your code here!
    scanf("%s", &s);
    if(s[0] == s[1] && s[1] == s[2]) puts("Yes");
    else if (s[1] == s[2] && s[2] == s[3]) puts("Yes");
    else puts("No");
    
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#include <vector>
#include <numeric>
#include <map>
#include <cmath>
#include <iomanip>
#include <queue>
using ll =long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vs = vector<string>;

int main(){
    int K, A, B;
    cin >> K >> A >> B;

    for(int i= A; i<=B; i++){
        if(i%K == 0){
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
}

Measured memory_bytes: 3132
#include<cstdio>
#include<algorithm>
#include<deque>

using namespace std;

const int INF = 1 << 29;

int main(){
	int k; scanf("%d", &k);
	int d[100000];
	fill(d, d + k, INF); d[1] = 1;
	deque<int> q;
	q.push_back(1);
	while(!q.empty()){
		int t = q.front(); q.pop_front();
		if(d[(t * 10) % k] > d[t]){ q.push_front((t * 10) % k); d[(t * 10) % k] = d[t]; }
		if(d[(t + 1) % k] > d[t] + 1){ q.push_back((t + 1) % k); d[(t + 1) % k] = d[t] + 1; }
	}
	printf("%d\n", d[0]);
	return 0;
}

Measured memory_bytes: 820
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b , a % b);
}

const ll MOD = 998244353;
const ll MAX = 2000001;

ll mod(ll a){
  if(a % MOD < 0) return MOD + (a % MOD);
  return a % MOD;
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}


int main(){
  ll a,b,c,d; cin >> a >> b >> c >> d;
  
  if(a+b == c+d) cout << "Balanced" << endl;
  else if(a+b > c+d) cout << "Left" << endl;
  else cout << "Right" << endl;
  
  
}

Measured memory_bytes: 3584
import java.util.*;
import java.math.BigInteger;

public class Main {

	public static void main(String [] args) {
		Scanner in =new Scanner(System.in);
		String N=in.next();
		String K=in.next();
		BigInteger b =new BigInteger(N);
		BigInteger jian =new BigInteger(K);
		b=b.mod(jian);
		  b=b.min(b.subtract(jian).abs());
		System.out.print(b.toString());

		
	}
}

Measured memory_bytes: 22732
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int MOD=1000000007;


int main() {
  int n;
  cin >> n;
  int ans=0;
  if(n<105){
    cout << ans << endl;
    return 0;
  }
  else{
    for(int i=105;i<=n;i=i+2){
      int t=0;
      for(int j=1;j<=pow(i,0.5);j++){
        if(i%j==0)
        t++;
      }
      if(t==4)
      ans++;
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 3892
//*******Abhijit Burman***********//
//Jalpaiguri Government Engineering College//

// Taken From Striver_79
// Never open a ranklist untill and unless you are done with solving problems, wastes 3/4 minuts 
// Donot treat CP as a placement thing, love it and enjoy it, you will succeed for sure. 


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define ff first
#define ss second
#define mk make_pair
#define MAXX (1000000000000000000+7)
#define mod 1000000007
#define endl "\n"
#define fio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define sortv(v) sort(v.begin(),v.end())
void printv(vector<ll> v) { ll sz = v.size(); for(ll i=0;i<sz;i++) {if (i == sz - 1) cout << v[i] << "\n"; else cout << v[i] << " ";}}
void input(ll a[], ll sz) {for(ll i=0;i<sz;i++) cin >> a[i];}
void print(ll a[], ll sz) {for(ll i=0;i<sz;i++) {if (i == sz - 1) cout << a[i] << "\n"; else cout << a[i] << " ";}}
ll dx1[] = {1, 1, 0, -1, -1, -1, 0, 1};
ll dy1[] = {0, 1, 1, 1, 0, -1, -1, -1};

ll dx2[] = {1, 0, -1, 0};
ll dy2[] = {0, 1, 0, -1};

ll mul(ll a, ll b, ll p = mod) {return ((a % p) * (b % p)) % p;}
ll add(ll a, ll b, ll p = mod) {return (a % p + b % p) % p;}
ll power(ll x,ll y,ll p = mod) 
{ 
    ll res = 1;
    x = x % p;
    while (y > 0) 
    {
        if (y & 1) 
            res = (res*x) % p;
        y = y>>1; // y = y/2 
        x = (x*x) % p; 
    } 
    return res; 
} 
ll modInverse(ll n, ll p = mod)
{
    return power(n, p - 2, p);
}
ll ncrMod(ll n, ll r, ll p = mod)
{
    if (r == 0)
        return 1;
    ll fac[n + 1];
    fac[0] = 1;
    for (ll i = 1 ; i <= n; i++)
        fac[i] = fac[i - 1] * i % p;
    return (fac[n] * modInverse(fac[r], p) % p *
            modInverse(fac[n - r], p) % p) % p;
}
// a+b=xor(a,b)+2*(a&b)//

bool isPrime(ll n){
    for(int i=2;i*i<=n;i++){
        if(n%i==0){
            return false;
        }
    }
    return true;
}
bool cmp(pair<ll,ll>&a, pair<ll,ll>&b){
    if(a.ff==b.ff){
        return (a.ss<b.ss);
    }
    else{
        return (a.ff>b.ff);
    }
}
 
void solve()
{
    string s;
    cin>>s;
    
    if(s[s.size()-1]=='s'){
        cout<<s<<"es"<<endl;
    }
    else{
        cout<<s<<"s"<<endl;
    }
}


int main()
{
	fio;
// 	#ifndef ONLINE_JUDGE
//     // for getting input from input.txt
//     freopen("input.txt", "r", stdin);
//     // for writing output to output.txt
//     freopen("output.txt", "w", stdout);
// 	#endif
 
    
	ll t=1;
// 	cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 3620
N= input()
S= input()


N = int(N)
Len = len(S)#文字数の長さ
LIST = list(S)#文字列を1文字ごとに分割する。

ANSWER = ""
#リストの中身をループ
for SS in LIST:
    NUNBER = ord(SS)#アスキーコードを出す組み込み関数:1文字しか対応していない
    NUNBER = NUNBER -65#アスキーコードからアルファベット順に変更
    AFFTER = NUNBER + N
    LAST  = AFFTER % 26
    LAST  = chr(LAST+65)#アスキーコードからアルファベットに戻す
    ANSWER = ANSWER + LAST
    
print(ANSWER)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(void){
    int n, b, f, r, v;
    int data[4][3][10];
    for (int a =0; a < 4; a++)
        for (int b=0; b < 3; b++)
            for (int c=0; c < 10; c++)
                data[a][b][c] = 0;
    cin >> n;
    for (int i=0; i<n; i++) {
        cin >> b >> f >> r >> v;
        data[b-1][f-1][r-1] += v;
    }
    for (int a =0; a < 4; a++) {
        for (int b=0; b < 3; b++) {
            for (int c=0; c < 10; c++) {
                cout << ' ' << data[a][b][c];
            }
            cout << endl;
        }
        if (a != 3) cout << "####################" << endl;
    }
}

Measured memory_bytes: 3076
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int W = sc.nextInt();
        int H = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        int r = sc.nextInt();
        if (x >= r && x <= (W - r) &&
            y >= r && y <= (H - r)) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 26332
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

typedef long long ll;

ll gcd(ll a,ll b){
    ll x = min(a,b);
    ll y = max(a,b);
    while(y % x != 0){
        ll z = y % x;
        y = x;
        x = z;
    }
    return x;
}

ll A,B;
vector<ll> v;

int main(){
    cin >> A >> B;
    ll C = gcd(A,B);
    ll count = 0;
    ll D = C;
    for(ll i = 2;i*i <= D;i++){
        if(C % i == 0){
            count++;
            while(C % i == 0) C /= i;
        }
    }
    if(C != 1) count++;
    cout << count + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define f first
#define s second
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mem(arr,v) memset(arr,v,sizeof(arr))
/*bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
} */
int main()
{
     ll t,cnt=0;
     string s1,s2;
     cin>>s1>>s2;
     for(int i=0;i<s1.size();i++)
         {
             if(s1[i]==s2[i])
                cnt++;
         }
         //cout<<cnt<<endl;
     if(cnt==s1.size() && s1.size()+1==(s2.size()))
        cout<<"Yes"<<endl;
     else
        cout<<"No"<<endl;
}


Measured memory_bytes: 3600
import numpy as np
from scipy.sparse.csgraph import connected_components
from collections import deque
n,m=map(int,input().split())
matrix=[[0]*n]*n
matrix=np.array(matrix)
l=deque()
for _ in range(m):
    a,b=map(int,input().split())
    l.append([a,b])
    matrix[a-1][b-1]=1
count=0
for i in range(m):
    [a,b]=l.popleft()
    matrix[a-1][b-1]=0
    k,kk=connected_components(matrix)
    if kk[a-1]!=kk[b-1]:
        count+=1
    l.append([a,b])
    matrix[a-1][b-1]=1
print(count)


Measured memory_bytes: 13848
import java.io.*;

public class Main {

    public static void main(String[] args) throws IOException  {
        
        BufferedReader reader =
            new BufferedReader(new InputStreamReader(System.in));
 
        String[] line = reader.readLine().split(" ");
        int w = Integer.parseInt(line[0]);
        int h = Integer.parseInt(line[1]);
        int x = Integer.parseInt(line[2]);
        int y = Integer.parseInt(line[3]);
        int r = Integer.parseInt(line[4]);
        
        if(r <= x && x <= w - r) {
            if(r <= y && y <= h - r){
                System.out.println("Yes");
            }
            else {
                System.out.println("No");
            }
        }
        
        else System.out.println("No");
        
    }
    
}

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

int main()
{
    int N;
    int a[100] = {0};
    int mmax = 0, mmin = 1000;
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        int x;
        cin >> x;
        mmax = max(mmax, x);
        mmin = min(mmin, x);
    }
    cout << abs(mmax - mmin) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ull uint64_t
#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mx5 100005
#define mx6 1000005
#define mod 1000000007
#define nfs ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

ll dp[401][401] = {}, part[401] = {};

int main() {
    nfs
    int i, j, k, n, a, d;
    cin >> n;
    for (i = 1; i <= n; i++) {
        cin >> a;
        part[i] = part[i-1] + a;
        dp[i][i] = 0;
    }

    for (d = 1; d < n ; d++) {
        for (i = 1, j = i + d; j <= n; i++, j++) {
            dp[i][j] = 1e18;
            for (k = i; k < j; k++) {
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j]);
            }
            dp[i][j] += part[j] - part[i-1];
        }
    }
    cout << dp[1][n];
}

Measured memory_bytes: 4852
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<utility>

using namespace std;

int panel_loc[8][8];
int visit[8][8];
int color[5];
int maxcolor[5];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int getarea(const vector<vector<int>> panel,int h, int w){
  int c,c_before,sum=0,tmp;
  queue<pair<int,int>> que;
  for(int y=0;y<h;y++){
    for(int x=0;x<w;x++){
      panel_loc[y][x] = panel[y][x];
    }
  }
  for(int i=0;i<5;i++){
    for(int y=0;y<h;y++){
      for(int x=0;x<w;x++){
        visit[y][x]=0;
      }
    }
    c = color[i];
    c_before = panel_loc[0][0];
    panel_loc[0][0] = c;
    visit[0][0] = 1;
    que.push(make_pair(0,0));
    while (not que.empty()){
      //cin >> tmp;
      pair<int,int> pan = que.front();
      que.pop();
      for(int j=0;j<4;j++){
        if (pan.first+dy[j]>=0 && pan.first+dy[j]<h && pan.second+dx[j]>=0 && pan.second+dx[j]<w && panel_loc[pan.first+dy[j]][pan.second+dx[j]]==c_before && !visit[pan.first+dy[j]][pan.second+dx[j]]){
          panel_loc[pan.first+dy[j]][pan.second+dx[j]] = c;
          visit[pan.first+dy[j]][pan.second+dx[j]] = 1;
          que.push(make_pair(pan.first+dy[j],pan.second+dx[j]));
        }
      }
    }
  }
  //count
  for(int y=0;y<h;y++){
    for(int x=0;x<w;x++){
      visit[y][x] = 0;
    }
  }
  que.push(make_pair(0,0));
  visit[0][0] = 1;
  while(not que.empty()){
    pair<int,int> pan = que.front();
    ++sum;
    que.pop();
    for(int i=0;i<4;i++){
      if (pan.first+dy[i]>=0 && pan.first+dy[i]<h && pan.second+dx[i]>=0 && pan.second+dx[i]<w && panel_loc[pan.first+dy[i]][pan.second+dx[i]]==color[4] && !visit[pan.first+dy[i]][pan.second+dx[i]]){
        que.push(make_pair(pan.first+dy[i],pan.second+dx[i]));
        visit[pan.first+dy[i]][pan.second+dx[i]]=1;
      }
    }
  }
  return sum;
}

int main(){
  int h,w;
  while (1){
    cin >> h >> w >> color[4];
    --color[4];
    if (h == 0){
      break;
    }
    vector<vector<int>> panel(h,vector<int>(w));
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        cin >> panel[i][j];
        --panel[i][j];
      }
    }
    int maxarea = 0;
    int tmp;
    for(int i=0;i<1296;i++){
      color[0] = i-(i/6)*6;
      color[1] = ((i-(i/36)*36)-color[0])/6;
      color[2] = ((i-(i/216)*216)-color[0]-color[1]*6)/36;
      color[3] = ((i-(i/1296)*1296)-color[0]-color[1]*6-color[2]*36)/216;
      tmp = getarea(panel,h,w);
      if (tmp>maxarea){
        maxarea=tmp;
        maxcolor[0] = color[0];
        maxcolor[1] = color[1];
        maxcolor[2] = color[2];
        maxcolor[3] = color[3];
        maxcolor[4] = color[4];
      }
    }
    cout << maxarea << endl;
  }
  return 0;
}

Measured memory_bytes: 3112
use std::io::*;
use std::str::FromStr;
 
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}
 
fn main() {
    let n: usize = read();
    let mut m: u64 = read();
    let mut zaiko: Vec<(u64,u64)> = (0..n).map(|_| (read(), read())).collect();
    let mut ans = 0;
 
    zaiko.sort();
    for mise in zaiko.iter() {
        if mise.1 > m {
            //必要分購入
            ans += mise.0 * m;
            m -= m;
        }else{
            //買い占め
            ans += mise.0 * mise.1;
            m -= mise.1;
        }
        if m == 0 {
            break;
        }
    }
 
    println!("{:?}", ans);
 
}

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

int main() {
    int N, A;
    cin >> N >> A;

    if ((N % 500) <= A) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
using namespace std;
#define REP(i,n); for(int i = 0;i < (int)(n);i++)

int main() {
	int n,a,count=0;
	vector<int> h;
	cin >> n;
	h.resize(n);
	REP(i,n){
		cin >> h[i];
		a = 0
		REP(j,i + 1){
			a = max(a,h[j]);
		}
		if(a==h[i])count++;
	}
	cout << count;
	return(0);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int m,n,x,y,lose[21]={};
  vector<int> vec[21];
  cin >> m >> n;
  for(int i=0;i<n;i++){
    cin >> x >> y;
    lose[y]++;
    vec[x].push_back(y);
  }
  queue<int> que;
  for(int i=1;i<=m;i++){
    if(lose[i] == 0) que.push(i);
  }
  while(!que.empty()){
    int z = que.front();
    que.pop();
    cout << z << endl;
    for(int i=0;i<vec[z].size();i++){
      lose[vec[z][i]]--;
      if(lose[vec[z][i]] == 0) que.push(vec[z][i]);
    }
  }
  return (0);
}



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

using namespace std;

int main()
{
    string s;
    cin >> s;
    bool ch = 1;
    for (int i = 1; i < 4; i++)
        if (s[i] == s[i - 1])
            ch = 0;
    if (ch)
        cout << "Good" << endl;
    else
        cout << "Bad" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    int count=0;
    cin >> n;
    for(int i=1;i<n;i++){
        for(int j=1;j<n;j++){
            if(i*j < n) count ++;
            if(i*j >= n) break;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
unsigned euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
int main(){
  int n;
  cin >> n;
  int a;
  cin >> a;
  rep(i,n-1){
    int q;
    cin >> q;
    a=euclidean_gcd(a,q);
  }
  cout << a << endl;
}


Measured memory_bytes: 256
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=str(input())
T=[z for z in T]
c=0
for i in range(K):
  M=[]
  t=0
  j=i
  while j <= N-1:
    M.append(T[j])
    j=j+K
  k=0
  while k <= len(M)-1:
    if M[k]=='r':
      t=t+P
    elif M[k]=='p':
      t=t+S
    else:
      t=t+R
    if k<len(M)-1 and M[k]==M[k+1]:
      k=k+2
    else:
      k=k+1
  c=c+t
print(c)

Measured memory_bytes: 4700
import java.util.Scanner

case class Proc(name: String, time: Int)

object Main extends App {
  val sc = new Scanner(Console.in)

  def next() = sc.next
  def nextInt() = next.toInt

  val n = nextInt
  val q = nextInt

  val procs = List.fill(n)(Proc(next, nextInt))

  def schedule(in: List[Proc], out: List[Proc], totalTime: Int, log: List[Proc]): List[Proc] = {
    if (in.isEmpty) {
      if (out.isEmpty)
        log.reverse
      else
        schedule(out.reverse, List(), totalTime, log)
    } else {
      val Proc(name, t) = in.head
      if (t <= q)
        schedule(in.tail, out, totalTime + t, Proc(name, totalTime + t)::log)
      else
        schedule(in.tail, Proc(name, t - q)::out, totalTime + q, log)
    }
  }

  val log = schedule(procs, List(), 0, List())
  for (Proc(name, time) <- log)
    println(s"$name $time")
}



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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 30)
#define MOD 1000000007
//int dy[4] = {-1,0,0,1};
//int dx[4] = {0,1,-1,0};



int main(){
  
  int n;
  cin >> n;
  ll res = 0;
  REP(i,n){
    int l,r;cin >> l >> r;
    res += r - l + 1;
  }
  cout << res << endl;

  


  

  return 0;
}

Measured memory_bytes: 256