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

string s;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int ans=0;
    cin>>s;
    for(char &c:s)ans+=c-'9';
    cout<<(ans%9==0?"Yes":"No")<<endl;

    return 0;
}

Measured memory_bytes: 3708
import java.util.*;

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

    int n = sc.nextInt();

    List<Restaurant> restaurants = new ArrayList<>();
    for (int i = 0; i < n ; i++) {
      Restaurant restaurant = new Restaurant(i+1, sc.next(),sc.nextInt());
      restaurants.add(restaurant);
    }

    restaurants.sort(Comparator.comparing(Restaurant::getScore).reversed());
    restaurants.sort(Comparator.comparing(Restaurant::getCity));

    restaurants.forEach(r -> System.out.println(r.id));

  }


  static class Restaurant {
    int id;
    String city;
    int score;

    public Restaurant (int id, String city, int score) {
      this.id = id;
      this.city = city;
      this.score = score;
    }

    public String getCity() {
      return city;
    }

    public int getScore() {
      return score;
    }

  }
}


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

typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)

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

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


int main() {
  int N,A,B;
  cin >> N >> A >> B;
  cout << min(B,N*A) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;
void getValue(string& line, int* D, int& v1, int& v2){
	string::size_type p1 = 0;
	string::size_type p2 = line.find(',');
	int k, i = 0;
	while (p1 != string::npos){
		if (p1 == 0) k = atoi(line.substr(0, p2).c_str());
		else if( p2 != string::npos)	k = atoi(line.substr(p1 + 1, p2 - p1 - 1).c_str());
		else k = atoi(line.substr(p1 + 1).c_str());
		if (i < 10) D[i] = k;
		else if (i == 10) v1 = k;
		else if (i == 11) v2 = k;
		p1 = p2;
		++i;
		if(p1 != string::npos)
			p2 = line.find(',', p1 + 1);
	}
}
int main()
{
	int D[10] = {}, S[10] = {};
	int v1, v2, d, v;
	string line;
	while (cin >> line){
		getValue(line, D, v1, v2);
		d = 0;
		for (int i = 0; i < 10; ++i){
			d += D[i];
			if (0 == i) S[0] = D[i];
			else		S[i] = S[i - 1] + D[i];
		}
		v = v1 + v2;
		double t = (double)d / (double)v;
		double a = t * v1;
		int b = 0;
		for (int i = 0; i < 10; ++i){
			if (0 == i){
				if (a <= S[0]){
					b = 1;
					break;
				}
			}
			else{
				if (S[i - 1] < a && a <= S[i]){
					b = i + 1;
					break;
				}
			}
		}
		cout << b << "\n";
	}
	return 0;
}

Measured memory_bytes: 1200
//Author ::  ABHINAV3010 ::

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define fast ios_base::sync_with_stdio(false)
typedef long long ll;
typedef pair<ll,ll> p;
ll mod=1000000007;
ll gcd(ll a,ll b)
{
    return (b==0)?a:gcd(b,a%b);
}
int main()
{
fast;
ll m,d;
cin>>m>>d;
ll cnt=0;
for(ll i=1;i<=m;i++)
{
    for(ll j=1;j<=d;j++)
    {
        if(j>=22)
        {
            ll a=j;
            ll x=j%10;
            a=a/10;
            ll y=a;
            if(x>=2&&y>=2)
            {
                if(x*y==i)
                {
                    cnt++;
                }
            }
        }
    }
}
cout<<cnt<<endl;
return 0;
}


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


using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cout(n) cout<<fixed<<setprecision(n)

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

    ll a,b,c;
    cin>>a>>b>>c;

    cout<<max((ll)0,c-(a-b))<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>

using namespace std;

int main(int argc, const char *argv[]) {
  int ans = 999;
  int tmp;
  char S[12];
  char a[2], b[2], c[2];
  scanf("%s", S);
  for (int i = 0; i < strlen(S) - 2; i++) {
    a[0] = S[i];
    b[0] = S[i+1];
    c[0] = S[i+2];
    tmp = abs(753 - (atoi(a) * 100 + atoi(b) * 10 + atoi(c)));
    ans = min(ans, tmp);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 888
#include<iostream>
#include<vector>
#include<functional>
#include<algorithm>
#include<string>
#include<map>
#include<queue>

using namespace std;

int main(void){

    string s, t;
    cin >> s >> t;
    int a, b;
    cin >> a >> b;
    string str;
    cin >> str;

    if(str == s) a--;
    else b--;

    cout << a << " " << b << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#include <unistd.h>
#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
#define vecin(a) rep(i,a.size())cin >> a[i]
#define vecout(a) rep(i,a.size()){cout << a[i];cout << (i == a.size() - 1 ? "\n":" ");}
#define mp make_pair
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll inf = 2147483647;
const ll INF = 1LL << 60;
const dou pi = 3.14159265358;
const ll mod = 1000000007LL;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
template<class T> inline bool change(T a,T b){if(a > b){swap(a,b);return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    return a / gcd(a,b) * b;
}

//素数判定O(sqrt(N))
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
const ll cmax = 1000000;
ll fac[cmax], finv[cmax], inv[cmax];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < cmax; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
ll nCk(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
//nのm乗をMODで割ったあまりO(logm)
ll modpow(ll n,ll m,ll MOD){
    if(m == 0)return 1;
    if(m < 0)return -1;
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}

//printf("%.10f\n", N);
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/

//    cout << fixed << setprecision(15);

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N;
    cin >> N;
    vector<ll> vec(N);
    vecin(vec);
    ll ans = 0,cnt = 0;
    rep(i,N){
        if(vec[i] == 0 && cnt){
            ans += cnt / 2;
            cnt = 0;
        }
        else if(vec[i]){
            cnt += vec[i];
        }
    }
    if(cnt != 0)ans += cnt / 2;
    cout << ans << endl;
}

Measured memory_bytes: 3888
M = 10**9 + 7
a = [1] + [0] * 12
p = 1
for c in reversed(input()):
    r = range(10) if c == '?' else (int(c),)
    a = [sum(a[(i - p * j) % 13] for j in r) % M for i in range(13)]
    p = p * 10 % 13
print(a[5])

Measured memory_bytes: 47624
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "random"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 0.00000001;


long long int N, M, K, L, R, H, W;

class Add_Segment_Tree {
	vector<long long int>v;
	vector<int>l;
	vector<int>r;
	long long int ret;
	int num;
	long long int Update(int place) {
		if (place >= v.size() / 2) {
			return v[place];
		}
		v[place] = Update(place * 2) + Update(place * 2 + 1);
		return v[place];
	}
	void Sum(int a, int b, int place) {
		if (l[place] >= a&&r[place] <= b) {
			ret += v[place];
			return;
		}
		if (l[place] > b || r[place] < a) return;
		Sum(a, b, place * 2);
		Sum(a, b, place * 2 + 1);
		return;
	}
public:
	void Left(int place) {
		if (place >= v.size() / 2) {
			l[place] = place - v.size() / 2;
			return;
		}
		Left(place * 2);
		Left(place * 2 + 1);
		l[place] = l[place * 2];
		return;
	}
	void Right(int place) {
		if (place >= v.size() / 2) {
			r[place] = place - v.size() / 2;
			return;
		}
		Right(place * 2);
		Right(place * 2 + 1);
		r[place] = r[place * 2 + 1];
		return;
	}
	Add_Segment_Tree(int N) {
		num = 1;
		while (num < N * 2)num *= 2;
		l.resize(num);
		r.resize(num);
		v.resize(num, 0);
		Left(1);
		Right(1);
	}
	void Add(int place, long long int num, bool update) {
		place += v.size() / 2;
		v[place] += num;
		if (!update)return;
		place /= 2;
		while (place) {
			v[place] = v[place * 2] + v[place * 2 + 1];
			place /= 2;
		}
	}
	void TopDown() {
		Update(1);
	}
	long long int Sum(int a, int b) {
		ret = 0;
		Sum(a, b, 1);
		return ret;
	}
};

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

	cin >> N >> K;

	vector<long long int>num(N);
	for (int i = 0; i < N; i++) {
		cin >> num[i];
		num[i] -= K;
		
		if (i) {
			num[i] += num[i - 1];
		}
		if (num[i] >= 0) {
			M++;
		}
	}
	set<long long int>s;
	for (auto i : num) {
		s.insert(i);
	}
	vector<long long int>v;
	for (auto i : s) {
		v.push_back(i);
	}
	map<long long int,long long int>m;
	for (int i = 0; i < v.size(); i++) {
		m[v[i]] = i;
	}
	for (int i = 0; i < N; i++) {
		num[i] = m[num[i]];
	}
	Add_Segment_Tree sg(N);
	for (int i = 0; i < N; i++) {
		M += sg.Sum(0, num[i]);
		sg.Add(num[i], 1, true);
	}
	cout << M << endl;
	return 0;
}

Measured memory_bytes: 33520
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <cassert>
using namespace std;

const double PI = 3.14159265359;

int main() {
    double R; cin >> R;
    printf("%.10f\n", 2*PI*R);
    return 0;
}


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

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        int ans = main.solve();
        System.out.println(ans);
    }

    int solve() {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        if(x<100) return 0;
        if(x%100==0) return 1;
        int n = x/100;
        return x%100 <= 5*n?1:0;
    }
}

Measured memory_bytes: 21844
#include <stdio.h>

long gojo(long a, long b){
  if(a % b)
    gojo(b, a%b);
  else
    return b;
}

int main(){
  long a, b;  scanf("%ld %ld", &a, &b);
  if(b > a){
    long t = a; a = b; b = t;
  }
  long gcd = gojo(a, b);

  printf("%ld\n", a*b/gcd);
  return 0;
}
  


Measured memory_bytes: 1728
import std.conv, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken().to!int; }
long readLong() { return readToken().to!long; }
real readReal() { return readToken().to!real; }

void chmin(T)(ref T t, in T f) { if (t > f) t = f; }
void chmax(T)(ref T t, in T f) { if (t < f) t = f; }

int binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = cast(int)(as.length); for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }
int lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a < val)); }
int upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a <= val)); }


int L;
string S;

void main() {
  try {
    for (; ; ) {
      S = readToken();
      L = cast(int)(S.length);
      bool ans;
      foreach (i; 0 .. L + 1) foreach (j; i .. L + 1) {
        if (S[0 .. i] ~ S[j .. L] == "keyence") {
          ans = true;
        }
      }
      writeln(ans ? "YES" : "NO");
    }
  } catch (EOFException e) {
  }
}


Measured memory_bytes: 636
n = gets.chomp.to_i
s = gets.chomp.split("")
chars = Hash.new(0)
s.each do |c|
  chars[c] += 1
end
sum = 1
chars.each do |k, v|
  sum *= v + 1
end
sum -= 1
sum = sum % (10**9 + 7)
puts sum
  

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> a(N, -1);
    rep(_, M) {
        int s, c;
        cin >> s >> c;
        s--;
        if (a[s] == -1) {
            a[s] = c;
        } else if (a[s] != c) {
            cout << -1 << endl;
            return 0;
        }
    }

    if (N > 1 && a[0] == 0) {
        cout << -1 << endl;
        return 0;
    }

    rep(i, N) if (a[i] == -1) a[i] = 0;
    if (N > 1 && a[0] == 0) a[0] = 1;

    rep(i, N) cout << a[i];
    cout << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void){
    int n = 0, count = 0;
    double d = 0;
    int *p;
    int **pp;
    int i,j;
    
    if (scanf("%d %lf", &n,&d) == 2){
    p = (int *)calloc(2,sizeof(int));
    if (p != NULL){
        for(i=0; i<n; i++){
        scanf("%d %d",&p[0], &p[1]);
        if (hypot(p[0],p[1]) <= d){
                    count++;
                }    
            }
        printf("%d\n",count);
        }
    }
    return 0;
}

Measured memory_bytes: 2216
x='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
from collections import Counter
c=Counter([])
for i in range(len(x)):
    c[x[i]]=i
n=int(input())
s=input()
ans=''
for i in range(len(s)):
    m=c[s[i]]
    ans+=x[(m+n)%26]
print (ans)

Measured memory_bytes: 9388
#include <iostream>

using namespace std;

int main(){
	int e;
	while (1){
		cin >> e;
		int m = 1000000;
		if (e == 0) break;
		for (int z = 0; z * z * z <= e; z++){
			for (int y = 0; y * y + z * z * z <= e; y++){
				int x = e - z * z * z - y * y;
				if (m > x + y + z) { m = x + y + z; }
			}
		}
		cout << m << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
            using namespace std;
             
            int main() {
              int N, res, sum;
              
              cin >> N;
              res = N;
              while(N > 0){
                sum += N % 10;
                N = N / 10;
              }
              
              if(res % sum == 0){
                cout << "Yes" << endl;
              } else {
                cout << "No" << endl;
              }
            }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) v.erase(unique(ALL(v)), v.end())
#define bit(i) (1LL<<i)
#define sz(v) ((LLI)(v).size())

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){is >> p.first >> p.second; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

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

  int p,q,r;
  while(cin >> p >> q >> r){

    int ans = min({p+q, p+r, q+r});
    cout << ans << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
/*input
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
*/
#include <bits/stdc++.h>
using namespace std;
const long long md=1e9+7;
long long a[1000005],n;

int main(){
	#ifdef ONLINE_JUDGE
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	#endif
	map<char,long long> mp;
	long long q,m,k,h,ans=0,sum=0,p,x,y;
	cin>>n;
	string s;
	for(int i=0;i<n;++i){
		cin>>s;
		if(s[0]=='M'  || s[0]=='A' || s[0]=='R' || s[0]=='C' || s[0]=='H')
			++mp[s[0]];
	}
	s = "MARCH";
	for(int i=0;i<5;++i) for(int j=i+1;j<5;++j) for(int k =j+1;k<5;++k){
		ans += mp[s[i]]*mp[s[j]]*mp[s[k]];
	}
	cout<<ans;
}

Measured memory_bytes: 256
h, w = gets.split.map(&:to_i)
a = readlines.map {|line| line.strip.split.map(&:to_i) }

results = []
routes = []
carrying = false
h.times do |y|
  w.times do |xx|
    x=xx
    x = w-1-x if y.odd?
    if carrying
      routes << [y,x]
    end

    if a[y][x].odd?
      carrying=!carrying
      if carrying
        routes << [y,x]
      else
        results.push(routes)
        routes=[]
      end
    end
  end
end

p results.map {|arr| arr.length-1 }.inject(0, :+)

results.each do |r|
  r.each_cons(2) do |arr|
    puts arr.flatten.map {|e| e+1 }.join(' ')
  end
end


Measured memory_bytes: 40976
using System;
using System.Linq;

public class Problem_B
{
  public static void Main()
  {
    var inputs = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
    var N = inputs[0];
    var X = inputs[1];
    var M = new int[N];
    var total = 0;
    for (var i = 0; i < N; i++)
    {
      M[i] = int.Parse(Console.ReadLine());
      X -= M[i];
      total += 1;
    }
    var min = M.Min();
    while (X >= min)
    {
      X -= min;
      total += 1;
    }
    Console.WriteLine($"{total}");
  }
}


Measured memory_bytes: 13268
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define maxn 1000119
int num[maxn],tree[maxn],booll[maxn],nnn[maxn],N,ww;;
//num数组保存原数列，tree树状数组，nnn保存结果
struct tt
{
    int l,r;//左右边界
    int pos;//原位置（因为我们要离线排序后处理）
};
tt ask[maxn];
bool cmp(tt x,tt y)
{ 
    return x.r<y.r;
    //快排大法好，没有什么是快排解决不来哦
    //实在不行就加上一个cmp
}
int lowbit(int n) 
{
    return n&(-n);
    //树状数组核心操作×1
}
void add(int n,int now)
{
    while(n<=N)
    {
        tree[n]+=now;
        n+=lowbit(n);
    }
    //树状数组核心操作×2-->更新操作
}
int sum(int n)
{
    int ans=0;
    while(n!=0)
    {
        ans+=tree[n];
        n-=lowbit(n);
    }
    return ans;
    //树状数组核心操作×3———>查询操作
}
int main()
{
        scanf("%d",&N);
        scanf("%d",&ww);
        for(int i=1;i<=N;i++)
            scanf("%d",&num[i]);
        for(int i=1;i<=ww;i++)
        {
            scanf("%d%d",&ask[i].l,&ask[i].r);
            ask[i].pos=i; //存储初始位置
        }
        sort(ask+1,ask+1+ww,cmp);//按r排序
        int next=1;
        for(int i=1;i<=ww;i++)
        {
            for(int j=next;j<=ask[i].r;j++)
            {
                if(booll[num[j]]) 
                    add(booll[num[j]],-1);
                 //之前打过标记，在之前的位置加上-1，保证无重复
                add(j,1);
                booll[num[j]]=j;
            }
            next=ask[i].r+1;
            //更新下一次查询的位置
            nnn[ask[i].pos]=sum(ask[i].r)-sum(ask[i].l-1);
            //按询问编号存储每组询问的结果
        }
    for(int i=1;i<=ww;i++)
      cout<<nnn[i]<<endl;
    return  0;
}

Measured memory_bytes: 17432
from fractions import gcd

n, m = map(int, input().split())

s = input()
t = input()

div = gcd(n, m)
div_n = n // div
div_m = m // div

if s[::div_n] == t[::div_m]:
    print(n * m // div)
else:
    print(-1)


Measured memory_bytes: 5472
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
//const long long MOD = 1000000007;
const long long MOD = 998244353;
using namespace std;

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

int main(int argc, char* argv[])
{
    int n,k;
    scanf("%d%d", &n, &k);

    int max=0;
    int i, g;
    for(i=0; i<n; i++) {
        int tmp;
        scanf("%d", &tmp);
        max=MAX(max,tmp);
        if(i==0) g=tmp;
        else g=gcd(g,tmp);
    }
    if(k>=0 && k<=max && k%g==0) {
        printf("POSSIBLE\n");
    }
    else {
        printf("IMPOSSIBLE\n");
    }

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <climits>
#include <memory>
#include <sstream>
#include <iomanip>
#include <cstdio>

using namespace std;


int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	char s;
	cin >> s;

	char ans;
	if (s == 'A') {
		ans = 'T';
	}
	if (s == 'T') {
		ans = 'A';
	}
	if (s == 'C') {
		ans = 'G';
	}
	if (s == 'G') {
		ans = 'C';
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
// Problem: E - Bomber
// Contest: AtCoder - AtCoder Beginner Contest 176
// URL: https://atcoder.jp/contests/abc176/tasks/abc176_e
// Memory Limit: 1024 MB
// Time Limit: 3000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
 
using namespace std;
#define int long long
#define ll long long
const int N = 2e5+5;
const int mod = 1e9;
#define ld long double
#define PI 3.14159265358979323846
const int INF = 10000000;
 
void flash()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(9);
}
 
//3. Structure or classes
//3. Ends here
 
//1. Data structures declaration here
//1. Ends here
 
//2. Extra Functions here
//2. Ends here
 
 
void solve();
int32_t main()
{
    flash();
    int t;
    t = 1;
    //cin>>t;
    while(t--){
        solve();
        //cout<<"\n";
    }
    return 0;
}
 
 
 
void solve()
{
	int n,m,k;
	cin>>n>>m>>k;
	
	map<int,map<int,int> >mp;
	map<int,int>r,c;
	
	for(int i=0;i<k;i++){
		int x,y;
		cin>>x>>y;
		mp[x][y]=1;
		r[x]++;
		c[y]++;
	}
	
	int ans=0;
	int maxr=0;
	vector<int>vr;
	for(auto rr:r){
		if(rr.second>maxr){
			maxr=rr.second;
			vr.clear();
			vr.push_back(rr.first);
		}
		else if(rr.second==maxr){
			vr.push_back(rr.first);
		}
	}
	
	int maxc=0;
	vector<int>vc;
	for(auto cc:c){
		if(cc.second>maxc){
			maxc=cc.second;
			vc.clear();
			vc.push_back(cc.first);
		}
		else if(cc.second==maxc){
			vc.push_back(cc.first);
		}
	}
	
	ans=0;
	
	for(auto i:vr){
		for(auto j:vc){
			ans=max(ans,r[i]+c[j]-mp[i][j]);
			if(ans==maxr+maxc)break;
		}
		if(ans==maxr+maxc)break;
	}
	
	cout<<ans<<"\n";
	
    return;
}
// how r u bro

Measured memory_bytes: 95856
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n,m;
  cin >> n;
  bool f=true;
  map<long long, int> mp;
  long long a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
    mp[a[i]]++;
  }
  cin >> m;
  long long b[m];
  for(int i=0;i<m;i++){
    cin >> b[i];
    if(mp[b[i]]==0){
      f=false;
    }
    mp[b[i]]--;
  }
  cout << ((f)?"YES":"NO") << endl;
  return 0;
}


Measured memory_bytes: 15872
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll powm(ll a, ll b, ll c) {
	if (b == 0)
		return 1;
	else if (b % 2 == 0) {
		ll d = powm(a, b / 2, c);
		return (d * d) % c;
	} else
		return (a * powm(a, b - 1, c)) % c;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

//ll dx[4] = {1, 0, -1, 0};
//ll dy[4] = {0, 1, 0, -1};

int main() {
	IOS();
	ll n;
	cin >> n;
	vector<ll> w(n);
	ll sum = 0;
	ll tmp = 0;
	ll ans = INF;
	for (int i = 0; i < n; i++) {
		cin >> w[i];
		sum += w[i];
	}
	for (int i = 0; i < n; i++) {
		tmp += w[i];
		ans = min(abs(sum - 2 * tmp), ans);
	}
	dump(ans);
	return 0;
}

Measured memory_bytes: 256
N = int(input())
S = []
for _ in range(N):
    s = input()
    S.append(s)
    
class RollingHash:
    def __init__(self, s, base=1007, mod=10**9+7):
        self.s = s
        self.length = length = len(s)
        self.base = base
        self.mod = mod
        self.h = h = [0] * (length + 1)
        for i in range(length):
            h[i + 1] = (h[i] * base + ord(s[i])) % mod
        self.p = p = [1] * (length + 1)
        for i in range(length):
            p[i + 1] = pow(base, i + 1, mod)

    def get(self, l, r):
        mod = self.mod
        return ((self.h[r] - self.h[l] * self.p[r - l]) + mod) % mod
    
    
H = [RollingHash(s) for s in S]

abcd = [chr(97+i) for i in range(26)]
sub_strs = ['']
#print(abcd)
l = 1
while 1:
    sub_set = set()
    for h in H:
        for i in range(len(h.s)-(l-1)):
            sub_set.add(h.get(i,i+l))
    
    tmp = []
    for s1 in sub_strs:
        for s2 in abcd:
            tmp.append(s1+s2)
    sub_strs = tmp[:]
    
    flag = False
    for s in sub_strs:
        h = RollingHash(s).get(0,len(s))
        if h in sub_set:
            continue
        else:
            flag = s
            break
    if flag:
        print(s)
        break
    l += 1
    
    



Measured memory_bytes: 116304
n, m = map(int, input().split())

hole_count = 0
pattern = [0,1]

if m != 0:
    a = int(input())
    hole_count += 1
else:
    a = n+1
    
for i in range(n):
    index = i + 1
    if index == a:
        pattern.append(0)
        if hole_count < m:
            a = int(input())
            hole_count += 1
    else:
        pattern.append(pattern[-1] + pattern[-2])

print(pattern[-1] % 1000000007)

Measured memory_bytes: 460020
def solve(n, m, aaa, bbb):
    nm = n * m
    i, j = 0, 0
    freedom = 0
    ans = 1
    MOD = 10 ** 9 + 7
    for k in range(nm, 0, -1):
        if aaa[-1] == bbb[-1] == k:
            freedom += i + j
            i += 1
            j += 1
            aaa.pop()
            bbb.pop()
        elif aaa[-1] == k:
            freedom += j - 1
            i += 1
            aaa.pop()
            ans = ans * j % MOD
        elif bbb[-1] == k:
            freedom += i - 1
            j += 1
            bbb.pop()
            ans = ans * i % MOD
        else:
            ans = ans * freedom % MOD
            freedom -= 1
            if freedom < 0:
                return 0

        if i > n or j > m:
            return 0

    return ans


n, m = map(int, input().split())
aaa = [0] + sorted(map(int, input().split()))
bbb = [0] + sorted(map(int, input().split()))
print(solve(n, m, aaa, bbb))


Measured memory_bytes: 3188
a,b,i,t;long long k=1;L(x,y){!y?t=x:L(y,x%y);}main(n){for(;scanf("%d%d",&a,&b)*a;L(n,k),k*=n/t,n=++i%3<1?printf("%lld\n",k),k=1:1)for(t=a;t-1;t=t*a%b)++n;}

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

int n,h[100005],cnt,ans;

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&h[i]);
	h[n+1]=0x3f3f3f3f;
	for(int i=n;i>=1;i--)
	{
		if(h[i+1]>h[i]) cnt=0; else cnt++;
//		cout<<i<<' '<<cnt<<endl;
		ans=max(ans,cnt);
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 640
def hantei(n,m,s,k,p):
  b = 0
  for l in range(m):
    a = 0
    for x in range(k[l][0]):
      a += s[k[l][x+1]-1]
    if a%2 != p[l]:
      b = 1
  if b == 0:
    return True
  else:
    return False

n,m = map(int,input().split())
k = []
for _ in range(m):
  k.append(list(map(int,input().split())))
p = list(map(int,input().split()))
c = 0
for _ in range(2**n):
  s = [0] * n
  ll = len(bin(_))
  for i in range(ll):
    if i >= 2:
      s[n-ll+i] = int(bin(_)[i])
  if hantei(n,m,s,k,p):
    c += 1
print(c)


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

using namespace std;

int size, max_jump;
int stones[100005];
int memo[100005];

int ans_iterative(int n){
	if(memo[n] != -1){
		return memo[n];
	}
	else{
		for(int i = 2; i < n; ++i){
			memo[i] = 1e9;

			for(int j = 1; j <= min(max_jump, i); ++j){
				memo[i] = min(
					memo[i],
					memo[i - j] + abs(stones[i] - stones[i - j])
				);
			}
		}
		return memo[n - 1];
	}
}

int main() {
	int temp;

	cin >> size >> max_jump;

	memset(memo, -1, sizeof(memo));

	for (int i = 0; i < size; ++i){
		cin >> temp;
		stones[i] = temp;
	}

	if(size == 1){
		cout << 0 << endl;
	}
	else{
		memo[0] = 0;
		memo[1] = abs(stones[0] - stones[1]);
		cout << ans_iterative(size) << endl;
	}

	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin >> n >> k;
    int h[n];
    for(int i=0;i<n;i++)cin >> h[i];
    vector<int>dp(n,1<<30);
    dp[0] = 0;
    for(int i=0;i<n;i++){
        for(int j=1;j<=k;j++){
            if(i+j<n)dp[i+j] = min(dp[i+j],dp[i] + abs(h[i+j]-h[i]));
        }
    }
    cout << dp[n-1] << endl;
}


Measured memory_bytes: 1024
#include<cstdio>

using namespace std;

long long a[100100];
int N;
int req[100100];
bool must[100100];

int calc(int x){
    long long tmp = 1;
    for(int i = 0; i < x; ++i){
        if(tmp >= x) return i;
        tmp *= 2;
    }
    return -1;
}

int solve(){
    for(int i = 0; i < N; ++i){
        req[i] = calc(a[i]);
        int tmp = a[i] & (a[i] - 1);
        if(tmp == 0) must[i] = false;
        else must[i] = true;
    }
    int cur = 0;
    int ans = 0;
    for(int i = 0; i < N; ++i){
        if(cur < req[i]){
            ans += (req[i] - cur);
            cur = req[i];
        }else if(cur == req[i]){
            if(must[i]){
                cur = req[i] - 1;
            }
        }else{
            if(must[i]){
                cur = req[i] - 1;
            }else{
                cur = req[i];
            }
        }
    }
    return ans;
}

int main(){
    scanf("%d", &N);
    for(int i = 0; i < N; ++i)
        scanf("%lld", a + i);
    int ans = solve();
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 1408
const main = (input) => {
  const args = input.split(' ')
  let a = parseInt(args[0], 10)
  let b = parseInt(args[1], 10)
  let c = parseInt(args[2], 10)
  let d = parseInt(args[3], 10)

  while (1) {
    c = c - b
    if (c <= 0) {
      console.log('Yes')
      return
    }
    a = a - d
    if (a <= 0) {
      console.log('No')
      return
    }
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
	for(auto &e:u) fill_v<T>(e,v...);
}

int64 N, K;
int64 ptoi(int64 y, int64 x) {
  return y * N + x;
}

PLL itop(int64 p) {
  return PLL(p / N, p % N);
}

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

  int64 N, M;
  cin >> N >> M;
  scc_graph scc(N);
  REP(i, M) {
    int64 a, b;
    cin >> a >> b;
    scc.add_edge(a, b);
  }
  auto res = scc.scc();

  cout << res.size() << endl;
  for (auto &&vec : res) {
    cout << vec.size() << " ";
    for (auto &&v : vec) {
      cout << v << " ";
    }
    cout << endl;
  }
}



Measured memory_bytes: 40596
#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 INF = 1001001001;

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

template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int n;
ll dp[100005][3];
int main() {
    int n;
    cin >> n;
    ll a[n][3];
    rep(i,n) rep(j,3) cin >> a[i][j];

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (j == k) continue;
                chmax(dp[i+1][k], dp[i][j] + a[i][k]);
            }
        }
    }

    ll res = 0;
    for (int i = 0; i < 3; i++) chmax(res, dp[n][i]);
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 8268
n, m, x = map(int, input().split(' '))
input_lists = [list(map(int, input().split(' '))) for _ in range(n)]
 
comb = []
for i in range(2 ** n):
    tmp = []
    for j in range(n):
        if ((i >> j) & 1):
            tmp.append(input_lists[j])
    comb.append(tmp)

result = -1
for i in range(len(comb)):
    understand = [0]*m
    total_fee = 0
    for j in range(len(comb[i])):
        total_fee += comb[i][j][0]
        for k in range(m):
            understand[k] += comb[i][j][k+1]
    if all(t >= x for t in understand) and (result == -1 or result > total_fee):
        result = total_fee
 
print(result)

Measured memory_bytes: 9236
#include<bits/stdc++.h>
#define mx 105
using namespace std;

int k, s, ans;

int main(){
  scanf("%d%d", &k, &s);
  for(int i = 0; i <= k; i++){
    for(int j = 0; j <= k; j++) {
      if(i + j <= s && s - k <= i + j) ans++;
    }
  }
  printf("%d\n", ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1111, mod = 1'000'000'007;
int mul(long long a, long long b){
	return a * b % mod;
}
int xp(long long a, long long b){
	a %= mod;
	int r = 1;
	for(; b; b >>= 1, a = mul(a, a)) if(b&1) r = mul(r, a);
	return r;
}
int fat[maxn], ifat[maxn];
void init(){
	fat[0] = 1;
	for(int i = 1; i < maxn; i++) fat[i] = mul(i, fat[i - 1]);
	ifat[maxn - 1] = xp(fat[maxn - 1], mod - 2);
	for(int i = maxn - 2; i >= 0; i--) ifat[i] = mul(ifat[i + 1], i + 1);
}	
int md[maxn][maxn];
int ncr(int n, int r){
	if(n < r) return 0;
	return mul(fat[n], mul(ifat[r], ifat[n - r]));
}
int dp[maxn][maxn];
int solve(int p, int k){
	if(p < 0) return 0;
	if(p == 0) return 1;
	if(dp[p][k] != -1) return dp[p][k];
	return dp[p][k] = mul(ncr(p - 1, k - 1), solve(p - k, k));
}
int main(){
	memset(dp, -1, sizeof(dp));
	init();
	int n, a, b, c, d;
	cin >> n >> a >> b >> c >> d;
	vector<int> f(n + 1, 0), nf;
	for(int j = a; j <= b; j++){
		md[j][0] = 1;
		for(int k = 1; k <= d; k++){
			md[j][k] = mul(md[j][k - 1], ifat[j]);
		}
	}
	f[0] = 1;
	for(int i = a; i <= b; i++){
		nf = f;
		for(int j = c; j * i <= n && j <= d; j++){
			for(int k = 0; k + j * i <= n; k++){
				int ways = solve(j * i, i);
				nf[k + j * i] += mul(ways, mul(ncr(k + j*i, j * i), f[k]));
				if(nf[k + j * i] >= mod) nf[k + j*i] -= mod;
			}
		}
		f = nf;
	}
	cout << f[n] << endl;
	return 0;
}


Measured memory_bytes: 9472
#include <iostream>
#include <cstdlib>
#include <time.h>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <array>
#include <string>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mp make_pair
#define eb emplace_back
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ost;

const ll maxN = 1e7;
const ll INF = 1e17;
const ll MOD = 1e9 + 7;

ll xs[] = {-1, 1, 0, 0, -1, 1, 1, -1};
ll ys[] = {0, 0, -1, 1, -1, 1, -1, 1};

ll segtree[maxN << 2];
ll lazy[maxN << 2];
ll A[maxN];

inline ll left(ll x){
	return x << 1;
}

inline ll right(ll x){
	return (x<<1) + 1;
}

void build(ll node, ll start, ll end){
	if(start == end)
		segtree[node] = A[start];
	else{
		ll mid = (start + end)/2;
		build(left(node), start, mid);
		build(right(node), mid+1, end);
		segtree[node] = segtree[left(node)] + segtree[right(node)];
	}
}

void update(ll node, ll start, ll end, ll l, ll r, ll val){
	if(lazy[node] != 0){
		segtree[node] += (end-start+1)*lazy[node];
		if(start != end){
			lazy[left(node)] += lazy[node];
			lazy[right(node)] += lazy[node];
		}
		lazy[node] = 0;
	}
	if(start > end or l > start or r < end)
		return ;
	else if(start >= l and r >= end){
		segtree[node] += val;
		if(start != end){
			lazy[left(node)] += val;
			lazy[right(node)] += val;
		}
	}
	else{
		ll mid=(start + end)/2;
		update(left(node), start, mid, l, r, val);
		update(right(node), mid+1, end, l, r, val);
		segtree[node] = segtree[left(node)] + segtree[right(node)];
	}
}

ll sums(ll node, ll start, ll end, ll l, ll r){
	if(lazy[node] != 0){
		segtree[node] += (end-start+1)*lazy[node];
		if(start != end){
			lazy[left(node)] += lazy[node];
			lazy[right(node)] += lazy[node];
		}
		lazy[node] = 0;
	}
	if(l > end or r < start or start > end)
		return 0;
	if(l <= start and r >= end)
		return segtree[node];
	ll mid = (start+end)/2;
	return sums(left(node), start, mid, l , r) + sums(right(node), mid + 1, end, l , r);
}

int main(){
	cin.sync_with_stdio(false);
	cin.tie(0);
	ll a, b;
	cin >> a >> b;
	if(a==b)
		cout << "Draw";
	else if(a == 1 or (a>b and b!=1))
		cout << "Alice";
	else
		cout << "Bob";
	return 0;
}

Measured memory_bytes: 3632
n, m = map(int,input().split())

l_M = 0
r_m = 10**5 +3


for i in range(m):
    l,r = map(int,input().split())
    l_M = max(l_M,l)
    r_m = min(r_m ,r)
   
ans = r_m - l_M + 1
if ans >= 0:
    print(ans)
else:
    print(0)
    
    
    


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

string divide[4] = {"dream", "dreamer", "erase", "eraser"};

int main() {
  string S;
  cin >> S;

  // 後ろから解くかわりにすべての文字列を「左右反転」する
  reverse(S.begin(), S.end());
  for (int i = 0; i < 4; ++i) reverse(divide[i].begin(), divide[i].end());

  // 端から切っていく
  bool can = true;
  for (int i = 0; i < S.size();) {
    bool can2 = false;  // 4 個の文字列たちどれかで divide できるか
    for (int j = 0; j < 4; ++j) {
      string d = divide[j];
      if (S.substr(i, d.size()) == d) {  // d で divide できるか
        can2 = true;
        i += d.size();  // divide できたら i を進める
      }
    }
    if (!can2) {  // divide できなかったら
      can = false;
      break;
    }
  }

  if (can)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}


Measured memory_bytes: 764
//Atcoder
import java.io.*;
import java.util.*;

public class Main {

	static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            try {
                br = new BufferedReader(new InputStreamReader(System.in));
                st = new StringTokenizer(br.readLine());
            } catch (Exception e){e.printStackTrace();}
        }

        public String next() {
            if (st.hasMoreTokens()) return st.nextToken();
            try {st = new StringTokenizer(br.readLine());}
            catch (Exception e) {e.printStackTrace();}
            return st.nextToken();
        }

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

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

        public double nextDouble() {return Double.parseDouble(next());}

        public String nextLine() {
            String line = "";
            if(st.hasMoreTokens()) line = st.nextToken();
            else try {return br.readLine();}catch(IOException e){e.printStackTrace();}
            while(st.hasMoreTokens()) line += " "+st.nextToken();
            return line;
        }
    }

    static class Drink implements Comparable<Drink> {
        long cost;
        long num;
        public Drink(long cost, long num) {
            this.cost = cost;
            this.num = num;
        }
        @Override
        public int compareTo(Drink other) {
            return (int)(this.cost - other.cost);
        }
    }

	public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter pw = new PrintWriter(System.out);

        int n = sc.nextInt();
        int m = sc.nextInt();

        Drink[] a = new Drink[n];
        for(int i=0;i<n;i++) a[i] = new Drink(sc.nextLong(), sc.nextLong());
        Arrays.sort(a);

        int cnt = 0;
        long ans = 0;

        for(int i=0;;i++) {
            if(i >= a.length) break;
            cnt += a[i].num;
            ans += a[i].cost * a[i].num;
            if(cnt > m) {
                ans -= a[i].cost * (cnt - m);
                break;
            }
        }

        pw.println(ans);
        pw.close();
    }
}


Measured memory_bytes: 44968
def find_par(x,p):
    
    try :
        if x == p[x] :
            return x

        p[x] = find_par(p[x],p)
        return p[x]
    except:
        return x


def union(x,y,p,size):
    try:
        xp = find_par(x,p)
        yp= find_par(y,p)

        if xp != yp:
            p[yp] = xp
            size[xp] += size[yp]
    except:
        pass
    
n,m=[int(c) for c in input().split()]
p=[i for i in range(n+1)]
size =[1 for i in range(n+1)]
for i in range(m):
    a,b =[int(c) for c in input().split()]
    union(a,b,p,size)

roots= set()

for i in range(1,n+1):
    par = find_par(i,p)
    roots.add(par)

ans = float("-inf")
for pp in roots:
    try:
        ans = max(ans,size[pp])
    except:
        pass

print(ans)

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

int main()
{
    int n, x;
    cin >> n >> x;
    vector<int> m(n);
    int count = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> m.at(i);
        count += m.at(i);
    }
    sort(m.begin(), m.end());
    int ans = 0;
    int l = m.at(0);
    x = x - count;
    ans = n;
    ans += x / l;

    cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        var io = new StandardIO();
        new Process(io).Run();
    }

}

class Process
{
    public Process(IIO io)
    {
        this.io = io;
    }

    IIO io;

    public void Run()
    {
        var ns = io.GetIntegerArray();
        int n = ns[0];
        int y = ns[1] / 1000;

        int diff = y - n;
        for (int t = 0; t <= diff / 9; t++)
        {
            int rest = diff - t * 9;
            if (rest % 4 != 0)
                continue;

            int f = rest / 4;
            int o = n - f - t;
            if (o < 0)
                continue;

            Write(o, f, t);
            return;
        }

        Write(-1, -1, -1);
    }

    void Write(int one, int five, int ten)
    {
        io.Write(string.Format("{0} {1} {2}", ten, five, one));
    }
}

public interface IIO
{
    string Get();
    void Write(string s);
    void Flush();
}

public class StandardIO : IIO
{
    string IIO.Get()
    {
        return Console.ReadLine();
    }

    void IIO.Write(string s)
    {
        Console.WriteLine(s);
    }

    void IIO.Flush()
    {
        Console.Out.Flush();
    }
}

public static class InputExtension
{
    public static int GetInteger(this IIO input)
    {
        return int.Parse(input.Get());
    }

    public static string[] GetStrings(this IIO input, char separator = ' ')
    {
        return input.Get().Split(separator);
    }

    public static int[] GetIntegerArray(this IIO input, char separator = ' ')
    {
        return input.GetStrings().Select(s => int.Parse(s)).ToArray();
    }
}



Measured memory_bytes: 13396
import sys
def input(): return sys.stdin.readline().strip()

def main():
    N, T = map(int, input().split())
    cv = [tuple(map(int, input().split())) for _ in range(N)]
    cv = sorted(cv, key=lambda x : x[0])
    dp = [[0]*(T+1) for _ in range(N+1)]

    # 貰うdp

    ans = 0
    for i in range(N):
        cost, value = cv[i]
        for now in range(min(T+1, cost)):
            dp[i+1][now] = dp[i][now]

        for now in range(cost, T+1):
            old = now - cost
            dp[i+1][now] = max(dp[i][now], dp[i][old] + value)
        
        ans = max(ans, dp[i][T-1] + value)

    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 112860
#include <iostream>
#include <vector>
using namespace std;
int main(){
	int n,k;
	while(cin>>n>>k,n,k){
		vector<int> amount;
		for(int i=0,s;i<k;++i){
			cin>>s;
			amount.push_back(s);
		}
		bool f = true;
		for(int i=0;i<n;++i){
			for(int j=0,b;j<k;++j){
				cin>>b;
				amount[j]-=b;
				if(amount[j]<0) f=false;
			}
		}
		cout<<((f)?"Yes\n":"No\n");
	}
}

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  	int b,p=1000;
  	cin >> b;
  	while(b>p)
      p+=1000;
  	cout << p-b;
    return 0;
}

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

int solve(ll H, ll W) {
    ll c = H * W;
    ll ssmin = LLONG_MAX;
    ll c1, c2, c3, smax, smin;
    for (int i = 1; i < H; i++) {
        c1 = i * W;
        c2 = (H - i) / 2 * W;
        c3 = c - c1 - c2;
        smax = max(c1, max(c2, c3));
        smin = min(c1, min(c2, c3));
        ssmin = min(smax - smin, ssmin);
        c2 = W / 2 * (H - i);
        c3 = c - c1 - c2;
        smax = max(c1, max(c2, c3));
        smin = min(c1, min(c2, c3));
        ssmin = min(smax - smin, ssmin);
    }
    return ssmin;
}

int main(void)
{
    ll H, W;
    cin >> H >> W;
    cout << min(solve(H, W), solve(W, H)) << endl;
    return 0;
}



Measured memory_bytes: 256