akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
#define deb(x) cerr << "\n" \
                    << #x << "=" << x << "\n";
#define deb2(x, y) cerr << "\n"                   \
                        << #x << "=" << x << "\n" \
                        << #y << "=" << y << "\n";
#define w(x) \
  int x;     \
  cin >> x;  \
  while (x--)

int32_t main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin>>n;
  vector<int> v(n);
  for(int &i:v)
    cin>>i;
  int buy = 1000,stocks = 0;
  for(int i=0;i<n-1;i++) {
    if(v[i]<v[i+1] && buy >= v[i]) {
      stocks += (buy/v[i]);
      buy -= (buy/v[i]) * v[i];
    }else if(v[i]>v[i+1]) {
      buy += stocks * v[i];
      stocks = 0;
    }
  }
  if(stocks>0)
    buy += v[n-1] * stocks;
  cout<<buy;
  return 0;
}

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


int main(){
  string s; 
  cin >>s;
  int check=0;
  for (int i = 0; i < s.length(); i+=2)
  {
    if(s[i]=='L') check++;
  }
  for (int i = 1; i < s.length(); i+=2)
  {
    if(s[i]=='R') check++;
  }
    if(check>0) cout<< "No";
  else cout << "Yes";
  

}




Measured memory_bytes: 256
#include <stdio.h>

int gcd_euclid(int u, int v) {
  int r;
  while (0 != v) {
    r = u % v;
    u = v;
    v = r;
    //printf("%d %d %d\n", r, u, v);
  }
  return u;
}

int main(void) {
	// your code goes here
	int a, b, x;
	scanf("%d %d %d", &a, &b, &x);
	int maxA = gcd_euclid(a, b);
	int i, j = 1, k;
	for(i = 1, k = 1; i <= x; i++, k++)
	{
	    if(maxA % k == 0)
	    {
	        j = maxA / k;
	    }
	    else
	    {
	        i--;
	    }
	    //printf("%d\n", i);
	}
	printf("%d\n", j);
	return 0;
}

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

void printv(vector<ll> v) {
  for (ll i : v)
    cout << i << endl;
}

int main() {
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
	ll ans;
	if(a>=k)ans=k;
	else if (a+b>=k) ans=a;
	else ans=a-(k-a-b);
	cout<<ans<<endl;
}


Measured memory_bytes: 3592
#include <iostream>
#include <queue>
#include <algorithm>
#include <set>
 
using namespace std;
 
const int H = 5, W = 4;
/*
inline int countZero(const string &str) {
  int ret = 0;
  for(int i=0; i<H*W; i++) {
    ret += str[i] == '0';
  }
   
  return ret;
}
 
void rearrange(string &str) {
  int pos = 0;
  for(int i=0; i<H*W; i++) {
    if(str[i] == '0') continue;
    char ch = str[i];
    str[i] = '0';
    str[pos++] = ch;
  }
}
*/
int main() {
   
  int Tc;
  cin >> Tc;
   
  while(Tc--) {
     
    string initial;
    for(int i=0; i<H; i++) {
      for(int j=0; j<W; j++) {
        char ch; cin >> ch;
        initial += ch;
      }
    }
     
    int ans = 0;
     
    set<string> used;
    queue<string> Q;
    Q.push(initial);
    while(!Q.empty()) {
      const string now = Q.front(); Q.pop();
      int zerocnt = 0;
      for(int i=H*W-1; i>=0; i--) {
        if(now[i] != '0') break;
        zerocnt ++;
      }
      //ans = max(ans, countZero(now));
      ans = max(ans, zerocnt);
      for(int pos=0; pos<H*W; pos++) {
        if(now[pos] == '0') continue;
        int x = pos%W, y = pos/W;
        for(int k=0; k<=1; k++) {
          for(int l=-1; l<=1; l++) {
            if(k == 0 && l == 0) continue;
            const int ny = y+k, nx = x+l;
            if(nx<0 || W<=nx || ny<0 || H<=ny) continue;
            const int npos = ny*W+nx;
            if(now[pos] != now[npos]) continue;
            string next;
            for(int i=0; i<H*W; i++) {
              if(i == pos || i == npos) continue;
              next += now[i];
            }
            next += "00";
            //string next = now;
            //next[pos] = next[npos] = '0';
            //rearrange(next);
            if(used.count(next)) continue;
            used.insert(next);
            Q.push(next);
          }
        }
      }
    }
    cout << 20-ans << endl;
  }
   
  return 0;
}

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

#define vec              vector<int>
#define vecll            vector<ll>
#define vecd             vector<double>
#define vecst            vector<string>
#define vecb             vector<bool>
#define v2(v,n,m,init)   vector<vector<int>>  v(n, vector<int>(m, init))
#define vb2(v,n,m,init)  vector<vector<bool>> v(n, vector<bool>(m, init))
#define vll2(v,n,m,init) vector<vector<ll>>   v(n, vector<ll>(m, init))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << (var) << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << (var);
#define prt2(v1, v2)     cout << (v1) << " " << (v2) << "\n"
#define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
template <typename T>
bool chmax(T &a, const T& b){if(a<b){a=b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a>b){a=b; return true;} return false;}
//----------------------------------------------------------------
ll gcd(ll a, ll b){ return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){ return a/gcd(a,b)*b;}

int main(void) {
  int n, k;
  cin >> n >> k;
  arrll(a,n);
  sortall(a);
  ll g=a[0];
  rep(i,n){
    g=gcd(g,a[i]);
  }
  if(a[n-1]<k || k%g!=0){
    prt("IMPOSSIBLE");
  } else {
    prt("POSSIBLE");
  }
}


Measured memory_bytes: 3940
#include <algorithm>
#include <cstdio>
#include <cstring>

const int N = 200050;
const int NN = N * 20;

int n, pre[N], nxt[N * 2], to[N * 2], cnt;

inline void addEdge(int x, int y) {
  nxt[cnt] = pre[x];
  to[pre[x] = cnt++] = y;
  nxt[cnt] = pre[y];
  to[pre[y] = cnt++] = x;
}

int lc[NN], rc[NN], siz[NN], cnt2;

void merge(int &x, int y) {
  if (!x || !y) return void(x |= y);
  siz[x] += siz[y];
  merge(lc[x], lc[y]);
  merge(rc[x], rc[y]);
}

int query(int o, int l, int r, int B) {
  if (r <= B) return siz[o];
  if (!o || l > B) return 0;
  int mid = (l + r) / 2;
  return query(lc[o], l, mid, B) + query(rc[o], mid + 1, r, B);
}

void remove(int &o, int l, int r, int B) {
  if (r <= B) return void(o = 0);
  if (!o || l > B) return;
  int mid = (l + r) / 2;
  remove(lc[o], l, mid, B);
  remove(rc[o], mid + 1, r, B);
  siz[o] = siz[lc[o]] + siz[rc[o]];
}

void add(int &o, int l, int r, int x, int v) {
  if (r < x || l > x) return;
  if (!o) o = ++cnt2;
  siz[o] += v;
  if (l == r) return;
  int mid = (l + r) / 2;
  add(lc[o], l, mid, x, v);
  add(rc[o], mid + 1, r, x, v);
}

int k[N], sum[N];

int dfs1(int x, int fa) {
  int rt = 0;
  k[x] = std::max(k[fa], fa);
  for (int i = pre[x]; ~i; i = nxt[i])
    if (to[i] != fa) merge(rt, dfs1(to[i], x));
  if (x > 1) {
    if (k[fa] < x) sum[x] = 1 + query(rt, 1, n, k[x]);
    else if (k[fa] < fa) sum[x] = query(rt, 1, n, fa) - query(rt, 1, n, k[fa]);
    else sum[x] = 0;
  }
  int t = query(rt, 1, n, x - 1);
  remove(rt, 1, n, x - 1);
  add(rt, 1, n, x, t + 1);
  return rt;
}

void dfs2(int x, int fa) {
  sum[x] += sum[fa];
  for (int i = pre[x]; ~i; i = nxt[i])
    if (to[i] != fa) dfs2(to[i], x);
}

int main() {
  scanf("%d", &n);
  memset(pre, -1, sizeof pre);
  for (int i = 1, x, y; i < n; ++i) {
    scanf("%d%d", &x, &y);
    addEdge(x, y);
  }
  dfs1(1, 0);
  dfs2(1, 0);
  for (int i = 2; i <= n; ++i)
    printf("%d ", sum[i]);
  return 0;
}

Measured memory_bytes: 56320
#include<bits/stdc++.h>
using namespace std;
int main(){
  int D,i,j,sum;scanf("%d",&D);
  pair<int,vector<int>> ans;
  pair<int,int> k;
  int c[26],l[26],up[26],down[26],output[D];
  fill(l,l+26,-1);
  for(i=0;i<26;i++) scanf("%d",&c[i]);
  for(i=0;i<D;i++){
    for(j=0;j<26;j++){
      scanf("%d",&up[j]);
      down[j] = (i-l[j])*c[j];
    }
    sum = accumulate(down,down+26,0);
    ans = make_pair(-1000000000,vector<int>());
    for(j=0;j<26;j++){
      if(up[j]-sum+down[j] > ans.first){
        ans.first = up[j]-sum+down[j];
        ans.second = vector<int>({j});
      }
      else if(up[j]-sum+down[j] == ans.first){
        ans.second.push_back(j);
      }
    }
    k = make_pair(-1,-1);
    for(j=0;j<ans.second.size();j++){
      if(down[ans.second[j]] > k.first){
        k.first = c[ans.second[j]];
        k.second = ans.second[j];
      }
    }
    l[k.second] = i;
    output[i] = k.second+1;
  }
  for(i=0;i<D;i++) printf("%d\n",output[i]);
}

Measured memory_bytes: 3796
#include<iostream>
using namespace std;
bool suger[3005];
int su[3005];
bool water[35];
int main(){
	int a,b,c,d,e,f;
	int i,j,k;
	double t=0,w=0;
	int s[2];
	cin>>a>>b>>c>>d>>e>>f;
	water[0]=true;
	suger[0]=true;
	for(i=0;i<31;i++){
		if(i>=a && water[i-a])water[i]=true;
		if(i>=b && water[i-b])water[i]=true;
	}
	su[0]=0;
	for(i=0;i<3005;i++){
		if(i>=c && suger[i-c])suger[i]=true;
		if(i>=d && suger[i-d])suger[i]=true;
		if(suger[i])su[i]=i;
		else su[i]=su[i-1];
	}
	for(i=1;i<31;i++){
		if(i*100>f)break;
		if(!water[i])continue;
		a=min(f-100*i,i*e);
		w=(double)su[a]/(double)(i*100+su[a]);
		if(i*100+su[a]>f)continue;
		if(t<=w)t=w,s[0]=i*100+su[a],s[1]=su[a];
	}
	cout<<s[0]<<" "<<s[1]<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < 4; i++){
            list.add(in.nextInt());
        }
        boolean one = list.contains(1), seven = list.contains(7),nine = list.contains(9), four = list.contains(4);
        if(one && seven && nine && four){
            System.out.println("YES");
            return;
        }
        System.out.println("NO");
    }
    
}

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

int main(){
  int N, A, B;
  cin >> N >> A >> B;
  
  int all_sum = 0;
  
  for(int num=1; num<=N; num++){
    int sum = 0;
    int n = num;
    for(int j=0; j<5; j++){
      sum += n%10;
      n /= 10;
    }
    if(sum>=A && sum<=B) all_sum += num;
  }
  cout << all_sum << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
MOD = 10**6+3
q = int(input())

fact = [1]*MOD
for i in range(1, MOD):
    fact[i] = fact[i-1]*i%MOD
finv = [1]*(MOD-1) + [pow(fact[-1], MOD-2, MOD)]
for i in range(MOD-1, 0, -1):
    finv[i-1] = finv[i]*i%MOD

for _ in range(q):
    x, d, n = map(int, input().split())
    if d == 0:
        ans = pow(x, n, MOD)
    else:
        x_div = x*pow(d, MOD-2, MOD)%MOD
        if x_div+n-1 > MOD:
            ans = 0
        else:
            if x_div+n-1 >= MOD:
                ans = 0
            else:
                ans = fact[x_div+n-1]*finv[x_div-1]%MOD*pow(d, n, MOD)%MOD
    print(ans)


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

int main() {
    ios_base::sync_with_stdio(false), cin.tie(nullptr);
    string s, t;
    cin >> s >> t;
    
    int n = s.size();
    int m = t.size();
    int ans = 1001;
    for (int i = 0; i <= n - m; i++) {
     
        int equal = 0;
        for (int j = 0; j < m; j++) {
            if (s[i + j] == t[j]) equal++;
        }
        ans = min(ans, m - equal);
    }
    cout << ans << "\n";
    return 0;
}


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

const int mn = -120;
const int mx = 120;

int main() {
  long long x;
  cin >> x;

  long long a, b;
  for ( a = mn; a <= mx; a++ ) {
    bool find = false;
    for ( b = mn; b <= mx; b++ ) {
      if ( pow(a, 5) - pow(b, 5) == x ) { find = true; break; }
    }
    if ( find ) { break; }
  }

  cout << a << ' ' << b << endl;
  return 0;
}


Measured memory_bytes: 4028
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in Actual solution is at the top
 *
 * @author Silviase
 */
public class Main {

  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    Scanner in = new Scanner(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    CGrandGarden solver = new CGrandGarden();
    solver.solve(1, in, out);
    out.close();
  }

  static class CGrandGarden {

    public void solve(int testNumber, Scanner in, PrintWriter out) {
      int n = in.nextInt();
      ArrayList<Integer> a = new ArrayList<>();
      for (int i = 0; i < n; i++) {
        a.add(in.nextInt());
      }

      out.println(func(a));

    }

    int func(ArrayList<Integer> a) {
      // a.forEach(x -> System.out.print(x + " "));

      if (a.size() == 0) {
        return 0;
      }

      int res = 0;

      while (!a.contains(0)) {
        res++;
        for (int i = 0; i < a.size(); i++) {
          a.set(i, a.get(i) - 1);
        }
      }

      ArrayList<Integer> b = new ArrayList<>();
      for (int i = 0; i < a.size(); i++) {
        if (a.get(i) != 0) {
          b.add(a.get(i));
        } else {
          res += func(b);
          b.clear();
        }
      }
      res += func(b);
      return res;
    }

  }
}



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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)


int main()
{
  ll k, x;
  ll a, b;
  cin >> k >> a >> b;
  forll(i, 0, b-a+1){
	if ((a + i) % k == 0){
	  cout << "OK" << endl;
	  return 0;
	}
  }
	
  cout << "NG" << endl;
}


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

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

	int l[100000]={0};
	int r[100000]={0};

	for(int i=0;i<m;++i) cin >> l[i] >> r[i];


	int max_l=0;
	int min_r=100000;
	for(int i=0;i<m;++i){
		if(max_l<l[i]) max_l = l[i];
		if(min_r>r[i]) min_r = r[i];
	}

	int output;
	output = min_r - max_l + 1;
	if(output > 0){
		cout << output << endl;
	}	else{
		output = 0;
		cout << output << endl;
	}

}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int k = Integer.parseInt(sc.next());
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		String ans = solve(k, a, b) ? "OK" : "NG";
		System.out.println(ans);

	}

	public static boolean solve(int k, int a, int b) {
		for (int i = a; i <= b; i++) {
			if (i % k == 0)
				return true;
		}
		return false;
	}

}


Measured memory_bytes: 26848
N, = map(int, raw_input().split())
a = [0]*200
a[0] = 1
for i in range(0,100):
  a[i+4] = max(a[i+4], a[i])
  a[i+7] = max(a[i+7], a[i])
print "Yes" if a[N]==1 else "No"

Measured memory_bytes: 2568
def gcd(x, y)
  if x == y
    return x
  elsif y > x
    gcd(y, x)
  elsif x % y == 0
    return y
  else
    gcd(y, x % y)
  end
end

x, y = STDIN.gets.chomp.split(' ').map(&:to_i)
puts gcd(x, y)

Measured memory_bytes: 8608
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(10);

}

signed main() {
	vector<ll> v(5, 0);
	ll ans = 0;
	ll mi = 10;

	REP(i, 5) {
		cin >> v[i];
		if (v[i] % 10 != 0) {
			mi = min(mi, v[i] % 10);
			ans += v[i] + 10 - (v[i] % 10);
		}
		else {
			ans += v[i];
		}
	}

	cout << ans - (10 - mi) << endl;
}

Measured memory_bytes: 256
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<string>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>
#define MAXN 300000
#define MAXM 100000
#define lowbit(x) (x&(-x))

using namespace std;

int n,m;
vector<int>gg[MAXM+80];
struct node{
	int a[MAXM+80];
	void add(int x,int A)
	{
		while(x<=m)
		{
			a[x]+=A;
			x+=lowbit(x);
		}
		return ;
	}
	int S(int x)
	{
		int sum=0;
		while(x)
		{
			sum+=a[x];
			x-=lowbit(x);
		}
		return sum;
	}
}tree;
int main()//You'll know it's a copy.
{
	int i,j,l,r,tmp=0,S;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++)
	{
		scanf("%d%d",&l,&r);
		gg[r-l+1].push_back(l);
	}
	for(i=1;i<=m;i++)
	{
		S=0;
		for(j=i;j<=m;j+=i)
			S+=tree.S(j);
		for(j=0;j<gg[i].size();j++)
			tree.add(gg[i][j],-1),tree.add(i+gg[i][j],1);
		printf("%d\n",n-tmp-S);
		tmp+=gg[i].size();
	}
	return 0;
}

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

typedef long lint;
typedef long long llint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }


int main(void) {
    double r;
    cin >> r;

    cout << 2*3.1415926535*r << endl;
    return 0;
}


Measured memory_bytes: 3776
#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
long long int __lcm(long long int a,long long int b){
  long long int n;
  n=a*b/__gcd(a,b);
  return n;
}
 //__gcd 最大公約数
 //__lcm 最小公倍数
 //double 少数（変数）
//sqrt 平方根
//ceil 天井関数
//floor 床関数
//abs 絶対値
//pow 累乗
//cbrt  立方根
//hypot 平方和の平方根
 
int main() {
  int a,b;
  cin>>a>>b;
  b=b*2+1;
  if(a%b==0)
    cout<<a/b;
  else
    cout<<a/b+1;
}

Measured memory_bytes: 256
def bubble_sort(data, test_proc = proc { |a, b| (a <=> b) > 0 } )
  n = data.size
  loop {
    orderd = true
    0.upto(n - 2) { |i|
      if test_proc.call(data[i], data[i + 1])
        tmp = data[i]
        data[i] = data[i + 1]
        data[i + 1] = tmp
        orderd = false
      end
    }
    break if orderd
  }
  data
end

def selection_sort(data, test_proc = proc { |a, b| (a <=> b) > 0 } )
  n = data.size
  0.upto(n - 2) { |i|
    swap_idx = i
    i.upto(n - 1) { |j|
      swap_idx = j if test_proc.call(data[swap_idx], data[j])
    }
    tmp = data[i]
    data[i] = data[swap_idx]
    data[swap_idx] = tmp
  }
  data
end

def stable_sort?(original, sorted)
  0.upto(sorted.size - 2) { |i|
    if sorted[i][1] == sorted[i + 1][1]
      is_not_stable = false
      original.each { |a|
        if a == sorted[i]
          break
        elsif a == sorted[i + 1]
          is_not_stable = true
          break
        end
      }
      if is_not_stable
        return false
      end
    end
  }
  true
end

data = $stdin.read.lines[1].split(' ').each { |n| n.instance_eval { def <=>(other); self[1].to_i <=> other[1].to_i; end } }
[bubble_sort(data.clone), selection_sort(data.clone)].each { |sorted|
  puts sorted.join(' ')
  puts stable_sort?(data, sorted) ? 'Stable' : 'Not stable'
}

Measured memory_bytes: 8892
#include<bits/stdc++.h>
const long long LINF = 1001002003004005006ll;
using namespace std;
long long min(long long a,long long b){ if(a>b) return b;
else return a;}
int main(){
  long long n,w;
  cin>>n>>w;
  long long a[n][2];
  vector<long long > dp(100002);
  for(int i=0;i<100002;i++) dp[i]=LINF;
  dp[0]=0;
  for(int i=0;i<n;i++){
      long long a,b;
      cin>>a>>b;
      for(int j=100002-b;j>=0;j--){
          dp[j+b]=min(dp[j+b],dp[j]+a);
      }
  }
  long long ans;
  for(int i=0;i<100002;i++){
      if(dp[i]<=w) ans=i;
  }
    cout<<ans;}

Measured memory_bytes: 4048
import java.util.Scanner;
import java.math.*;

class Main {
    public static void main(String[] args){
    	 Scanner sc = new Scanner(System.in);
         int aPrice = sc.nextInt();
         int bPrice = sc.nextInt();
         int abPrice = sc.nextInt();
         int aNeed = sc.nextInt();
         int bNeed = sc.nextInt();
         int most,res;
         if(aNeed>bNeed){
            most = aPrice;
         }else{
            most = bPrice;
         }
         if(aPrice+bPrice<=2*abPrice){
            res = (aPrice*aNeed)+(bPrice*bNeed);
         }else{
            res = (abPrice*Math.min(aNeed,bNeed)*2)+(Math.min(most,2*abPrice)*Math.abs(aNeed-bNeed));
         }
         System.out.println(res);
    }    
}

Measured memory_bytes: 22100
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

ll binomialCoeff(ll n, ll k) 
{ 
    ll C[k+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1;  // nC0 is 1 
  
    for (ll i = 1; i <= n; i++) 
    { 
        // Compute next row of pascal triangle using 
        // the previous row 
        for (ll j = min(i, k); j > 0; j--) 
            C[j] = C[j] + C[j-1]; 
    } 
    return C[k]; 
} 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int x=nxt(),t=nxt();
    cout<<max(0,x-t)<<endl;
    
    
    return 0;   
}




 
 


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int X;

signed main(){
	cin>>X;
	int Q=X/500;
	int R=X%500;
	cout<<Q*1000+(R/5)*5<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
#include  <cstdlib>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <vector>
#include <string>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)n;i++)
typedef long long lint;
#define SZ(x) ((int)(x).size())

int main()
{
	int a, b;
	cin >> a >> b;
	int cnt = 0;
	int n= b - a;
	int tower2 = (n + pow(n, 2)) / 2;
	cout << tower2-b << endl;
	return 0;
}


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

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

#define INF 1000000000

using namespace std;

int scoring(const vector<int> &c,
            const vector<vector<int>> &s,
            int day,
            int type,
            const vector<int> &previous) {
    int score = s[day][type];

    REP(i, 26) {
        score -= c[i] * (day + 1 - previous[i]);
    }

    return score;
}

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

    vector<int> c(26);
    REP(i, 26)
        cin >> c[i];

    vector<vector<int>> s(D, vector<int>(26, 0));
    REP(i, D)
        REP(j, 26)
            cin >> s[i][j];

    vector<int> result(D);
    REP(i, D) {
        cin >> result[i];
        result[i]--;
    }

    vector<int> previous(26, 0);

    long long score = 0;
    REP(i, D) {
        previous[result[i]] = i + 1;
        score += scoring(c, s, i, result[i], previous);
        cout << score << endl;
    }

    return 0;
}


Measured memory_bytes: 3676
import itertools
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))

perms = list(itertools.permutations(range(1, N+1)))

a = 0
b = 0
for i in range(len(perms)):
  if P == list(perms[i]):
    a = i+1
  if Q == list(perms[i]):
    b = i+1
  if a != 0 and b != 0:
    break


print(abs(a-b))

Measured memory_bytes: 47344
#include <stdio.h>

int main(void) {

	int x, y, temp;
	
	while (scanf("%d %d", &x, &y), x || y){

		if (x < y) printf("%d %d\n", x, y);

		else printf("%d %d\n", y, x);
		
	}

	return 0;
}

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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

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

int main(void)
{
  ll a, b, c;
  ll x, y;
  cin >> a >> b >> c >> x >> y;
  ll p, pmin = -1;
  ll imax = max(x, y) * 2;
  for(ll i = 0; i <= imax; i += 2) {
    p = max(0ll,(x - i / 2)) * a + max(0ll,(y - i / 2)) * b + c * i;
    if(pmin > 0) {
      pmin = min(pmin, p);
    } else {
      pmin = p;
    }
  }
  cout << pmin << endl;
}


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

public class Main {

    private void solve(InputReader in, PrintWriter out) {
        int n = in.nextInt();
        if (n % 4 == 0) {
            out.println("Yes");
            return;
        }
        if (n % 7 == 0) {
            out.println("Yes");
            return;
        }
        int a = n;
        while (n > 0) {
            n -= 7;
            if (n > 0 && n % 4 == 0) {
                out.println("Yes");
                return;
            }
        }
        while (a > 0) {
            a -= 4;
            if (a > 0 && a % 7 == 0) {
                out.println("Yes");
                return;
            }
        }
        out.println("No");
    }


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

    private void run() {
        try (
                InputReader in = new InputReader(System.in);
                PrintWriter out = new PrintWriter(System.out)) {
            solve(in, out);
        }
    }


    static class InputReader implements AutoCloseable {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }


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

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

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

        @Override
        public void close() {

        }
    }


}


Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define mrep(i,from,n) for(int i = from; i < n; i++)
#define mreps(i,from,n) for(int i = from; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(all(x), val), x.end())
typedef long long ll;
typedef pair<int, int> P;
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; }
ll MOD = 1000000007;
int INF = 1001001001;

void solve()
{
    ll n, k; cin >> n >> k;
    ll ans = 0;
    mrep(i, k, n+2)
    {
        ans += i*(n+1-i)+1;
        ans %= MOD;
    }
    cout << ans << endl;
    return;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


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

using namespace std;

typedef long long ll;

string s;
ll ans;
ll a[500005];
ll b[500005];

int main()
{
    cin>>s;
    for(ll i = 0; i < s.size(); i++)
    {
        if(s[i] == '<') a[i + 1] = a[i] + 1;
    }
    for(ll i = s.size() - 1; i >= 0; i--)
    {
        if(s[i] == '>') b[i] = b[i + 1] + 1;
    }
    for(ll i = 0; i <= s.size(); i++)
    {
        ans += max(a[i], b[i]);
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 8708
a = [list(map(int,input().split())) for _ in range(3)]
n = int(input())
b = [int(input()) for _ in range(n)]
ati=[[a[0][i],a[1][i],a[2][i]] for i in range(3)]
an1 = [a[0][0],a[1][1],a[2][2]]
an2 = [a[2][0],a[1][1],a[0][2]]
for i in a:
  if all(j in b for j in i):
    print('Yes')
    exit()
for i in ati:
  if all(j in b for j in i):
    print('Yes')
    exit()
for i in [an1,an2]:
  if all(j in b for j in i):
    print('Yes')
    exit()
print('No')

Measured memory_bytes: 3064
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

int Digit_Count(ll N){
  int ans = 0;
  while (N > 0){
    ans++; N /= 10;
  }
  return ans;
}

int main(){
  ll N; cin >> N;
  vector <ll> L, R;
  for (ll i = 1; i * i <= N; i++){
    if (N % i == 0){
      L.push_back(i);
      R.push_back(N / i);
    }
  }
  
  int ans = 1e9;
  for (int i = 0; i < L.size(); i++){
    ans = min(ans, max(Digit_Count(L[i]), Digit_Count(R[i])));
  }
  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Iterator;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String[] input = scan.nextLine().split(" ");
		int n = Integer.parseInt(input[0]);
		int m = Integer.parseInt(input[1]);

		HashMap map = new HashMap<Integer, Integer>();
		for (int i=0; i<n; i++) {
			int foods = scan.nextInt();
			for (int j=0; j<foods; j++) {
				int food = scan.nextInt();
				if (map.containsKey(food)) {
						int suki = (int) map.get(food);
					map.put(food, ++suki);
				} else {
					map.put(food, 1);
				}
			}
		}

		int count = 0;
		for(Iterator it = map.keySet().iterator(); it.hasNext(); ) {
		    int key = (int) it.next();
		    int value = (int) map.get(key);

		    if (n == value) count++;
		}

		System.out.println(count);
	}
}

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

int main() {

    ll N, P;
    string S;
    cin >> N >> P >> S;

    if (P == 2 or P == 5) {
        ll ans = 0;
        map<ll, ll> cnt;
        ll sum = 0;
        //cnt[0]++;
        for (int i=0; i<N; ++i) {
            ll tmp = S[i] - '0';
            if (tmp % P == 0) {
                ans += (i + 1);
            }
        }
        cout << ans << endl;
        return 0;
    }

    map<ll, ll> cnt;
    ll ans = 0;
    ll sum = 0;
    ll base = 1;
    cnt[0] = 1;
    for (int i=S.size()-1; i>=0; --i) {
        ll tmp = S[i] - '0';
        sum = (sum + tmp * base) % P;
        ans += cnt[sum];
        base = (base * 10) % P;
        cnt[sum]++;
        //cerr << sum << endl;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1028
#![allow(non_snake_case)]
use proconio::input;
// use std::collections::HashMap;

fn main() {
    input! {
        mut A: i32,
        B: i32,
        mut C: i32,
        D: i32,
    }

    loop {
        C -= B;
        if C <= 0 {
            println!("Yes");
            return;
        }

        A -= D;
        if A <= 0 {
            println!("No");
            return;
        }
    }
}


Measured memory_bytes: 2092
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,M=MI()
    s=[]
    for i in range(M):
        L=LI()
        s.append(L[1:])
    p=LI()
    
    import itertools
    
    ans=0
    for ite in itertools.product([0,1], repeat=N):
        flag=1
        for i in range(M):
            temp=0
            for ss in s[i]:
                if ite[ss-1]:
                    temp+=1
            if temp%2==p[i]:
                pass
            else:
                flag=0
        if flag:
            ans+=1
            
    print(ans)
                
                
            
        

main()


Measured memory_bytes: 73704
#include <bits/stdc++.h>
using namespace std;
typedef tuple<int64_t, int64_t, int64_t> T;
const int64_t INF = (1LL << 62);
const int64_t MAXN = 55, MAXS = 2500;
int64_t N, M, S;
vector<T> to[MAXN];
vector<int64_t> C(MAXN), D(MAXN);

void dijkstra()
{
  priority_queue<T, vector<T>, greater<T>> PQ;
  vector<vector<int64_t>> dp(N, vector<int64_t>(MAXS + 1, INF));
  dp[0][S] = 0;
  PQ.emplace(0, 0, S);
  while (!PQ.empty())
  {
    int64_t time, v, s;
    tie(time, v, s) = PQ.top();
    PQ.pop();
    if (time > dp[v][s])
    {
      continue;
    }
    if (s + C.at(v) <= MAXS)
    {
      int64_t ns = s + C.at(v);
      int64_t ntime = time + D.at(v);
      if (ntime < dp[v][ns])
      {
        dp[v][ns] = ntime;
        PQ.emplace(ntime, v, ns);
      }
    }
    for (auto u : to[v])
    {
      int64_t nv, a, b;
      tie(nv, a, b) = u;
      if (s < a)
        continue;
      int64_t ns = s - a, ntime = time + b;
      if (ntime < dp[nv][ns])
      {
        dp[nv][ns] = ntime;
        PQ.emplace(ntime, nv, ns);
      }
    }
  }
  for (int v = 1; v < N; v++)
  {
    int64_t res = INF;
    for (int s = 0; s <= MAXS; s++)
    {
      res = min(res, dp[v][s]);
    }
    cout << res << endl;
  }
}

int main()
{
  cin >> N >> M >> S;
  if (S >= MAXS)
    S = MAXS;
  int64_t u, v, a, b;
  for (int i = 0; i < M; i++)
  {
    cin >> u >> v >> a >> b;
    u--, v--;
    to[u].emplace_back(v, a, b);
    to[v].emplace_back(u, a, b);
  }
  for (int i = 0; i < N; i++)
  {
    cin >> C.at(i) >> D.at(i);
  }
  dijkstra();
}

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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return 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 V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a) {
    out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
    out<<'[';
    for(const T &i: a) out<<i<<',';
    out<<']';
    return out;
}
template<class T>
ostream &operator <<(ostream& out, const set<T>& a) {
    out<<'{';
    for(const T &i: a) out<<i<<',';
    out<<'}';
    return out;
}
template<class T, class S>
ostream &operator <<(ostream& out, const map<T,S>& a) {
    out<<'{';
    for(auto &i: a) out<<i<<',';
    out<<'}';
    return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

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

    ll n, q;
    string s;
    cin >> n >> q >> s;

    vector<ll> x(n);
    REP(i, n) {
        if(i && s[i]=='C' && s[i-1]=='A') {
            x[i] = 1;
        }
    }
    FOR(i, 1, n) x[i] += x[i-1];

    while(q--) {
        ll l, r;
        cin >> l >> r;
        l--, r--;
        cout << x[r] - (l==0?0:x[l-1]) - (l&&s[l-1]=='A'&&s[l]=='C') << endl;
    }

    return 0;
}


Measured memory_bytes: 1872
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<cmath>
#include<string>
using namespace std;

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

    if(s.size()<=k){
        cout << s << endl;
    }
    else{
        for(int i=0;i<k;i++){
            cout << s[i];
        }
        cout << "..." << endl;
    }
    return 0;
}




Measured memory_bytes: 3616
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

set<int> ss[210000];

set<pair<int, int>> gg;

int h, w, n;

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	cin >> h >> w >> n;
	for (int i = 0; i < n; ++i) {
		int x, y;
		cin >> x >> y;
		--x, --y;
		ss[y].insert(x);
		gg.emplace(x, y);
	}
	for (int i = 0; i < w; ++i)
		ss[i].insert(h);
	int x = 0, y = 0;
	int ans = h;
	while (y < w) {
		ans = min(ans, *ss[y].lower_bound(x));
		int fl = 0;
		while (x + 1 < ans) {
			x += 1;
			if (gg.find({x, y + 1}) == gg.end()) {
				y += 1, fl = 1;
				break;
			}
		}
		if (!fl)
			break;
	}
	cout << ans << "\n";
	return 0;
}




Measured memory_bytes: 38272
#include<iostream>
using namespace std;
const long mod=1e9+7;
int main() {
    int N; cin>>N;
    long S=0,T=0;
	for (int i=0; i<N; i++) {
		long A; cin>>A;
		S = (S+A*T) % mod;
		T = (T+A) % mod;
	}
	cout<<S<<endl;
    return 0;
}

Measured memory_bytes: 3608
l = input()
mod = 10**9+7

just = 1
lower = 0
for x in l:
    if x == '1':
        lower = (lower * 3 + just) % mod
        just = (just * 2) %mod
    else:
        lower = (lower * 3) %mod
        just = just %mod

print((just + lower) %mod)

Measured memory_bytes: 39536
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {

	public static final int BIG_NUM = 2000000000;
	public static final int MOD = 1000000007;
	public static final long HUGE_NUM = 99999999999999999L;
	public static final double EPS = 0.000000001;


	@SuppressWarnings("unchecked")
	public static void main(String[] args) {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		try {

			String input_str;
			int num_hit,num_blow;

			while((input_str = br.readLine()) != null){

				String A[] = input_str.split("\\s+");
				String B[] = br.readLine().split("\\s+");

				num_hit = 0;
				num_blow = 0;

				for(int i = 0; i < A.length; i++){
					for(int k = 0; k < B.length; k++){
						if(A[i].equals(B[k])){
							if(i == k){

								num_hit += 1;
							}else{

								num_blow += 1;
							}
							break;
						}
					}
				}

				System.out.printf("%d %d\n",num_hit,num_blow);
			}


		} catch (IOException e) {
			// TODO 自動生成された catch ブロック
			e.printStackTrace();
		}
    }
}


class UTIL{

    //String→intへ変換
    public static int getNUM(String tmp_str){

        return Integer.parseInt(tmp_str);
    }

    //文字が半角数字か判定する関数
    public static boolean isNumber(String tmp_str){

        if(tmp_str == null || tmp_str.length() == 0){

            return false;
        }

        Pattern pattern = Pattern.compile("\\A[0-9]+\\z");
        Matcher matcher = pattern.matcher(tmp_str);
        return matcher.matches();
    }
}


Measured memory_bytes: 24704
#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;


int main(void)
{
    long long N, x;
    cin >> N >> x;

    vector<long long> A;

    for (int i = 0; i < N; i++) {
        long long tmp;
        cin >> tmp;
        A.push_back(tmp);
    }

    long long ans = 0;
    if (A[0] > x) {
        ans += A[0] - x;
        A[0] = x;
    }

    for (int i = 0; i < N; i++) {
        long long tmp;
        tmp = A[i] + A[i + 1];
        if (tmp <= x)
            continue;
        ans += tmp - x;
        A[i + 1] -= (tmp - x);
    }

    cout << ans;
    cout << endl;

    return 0;
}


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

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

    float x = (float)n/(float)1.08;
    int y = ceil(x)*1.08;
    if(y==n)
        cout << ceil(x);
    else
        cout << ":(";
    return 0;
}

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

#define ll long long
ll MOD = 1000000007;

using namespace std;

int main() {
    ll n, k;
    cin >> n >> k;
    vector<int> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    ll intra_inv = 0, inter_inv = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++)
            if (v[j] < v[i])
                intra_inv++;
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++)
            if (v[j] < v[i])
                inter_inv++;
    }
    ll ans = (intra_inv * k) % MOD;
    ll ans2 = ((k * (k - 1)) / 2) % MOD;
    ans2 = (ans2 * inter_inv) % MOD;

    cout << (ans + ans2) % MOD;

    return 0;
}

Measured memory_bytes: 256
/*
	*	Created By: 'Present_Sir'
	*	Created On: Thursday 27 August 2020 03:01:29 PM IST
*/

#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define sz(v) ((int)v.size())
#define lgt(s) ((int)s.length())
#define int long long
using namespace std;

class Solver{
    public:
        void test(){
            //int t; cin>>t; for(int i=1; i<=t; ++i)
            {
                //cout<<"Case #"<<i<<": ";
                this->solve();
            }
        }
        void solve(){
            int n;
            cin>>n;
            map < int, int > mp;
            int N = 1e6+5;
            //cout<<N<<endl;
            vector < bool > present(N,0);
            
            for(int i=0; i<n; ++i){
                int x;
                cin>>x;
                mp[x]++;
            }
            int ans = 0;
            for(auto x: mp){
                if(present[x.first]) continue;
                if(x.second == 1)ans++;
                for(int i=x.first; i<N; i+=x.first){
                    //cout<<i<<endl;
                    present[i] = true;
                }
            }
            cout<<ans<<endl;
        }
};


int32_t main(){
    IOS;
    Solver S;
    S.test();
    return 0;
}



Measured memory_bytes: 16220
//https://ferin-tech.hatenablog.com/entry/2017/10/28/225850
//嘘解法が今でも通るのか確認するため
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#ifdef int
const ll INF = (1LL<<60);
#else
const int INF = (1LL<<30);
#endif
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

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

signed main(void)
{
  string s,t;
  cin >> s >> t;
  bool ret = false;
  int idx = -1;
  REP(i, s.size()-t.size()+1) {
    bool flag = true;
    REP(j, t.size()) {
      if(s[i+j] == '?' || s[i+j] == t[j]) continue;
      flag = false;
      break;
    }
    if(flag) ret = true, idx = i;
  }
  if(!ret) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  REP(i, t.size()) {
    if(s[i+idx] == '?') s[i+idx] = t[i];
  }
  REP(i, s.size()) {
    if(s[i] == '?') s[i] = 'a';
  }
  cout << s << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
typedef long long ll;
#include <cmath>
#include<cstdio>
#include<iomanip>
 
int main(int argc, char *argv[])
{
	int n;
	cin>>n;
	set<string> a;
 
 
	for (int i=0;i<n;i++)
	{
		string s;
		cin>>s;
		a.insert(s);
 
	}
	cout<<a.size()<<endl;
	return 0;
}

Measured memory_bytes: 19260
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
    
using namespace std;    
typedef long long ll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

int digitSum(ll n, ll a, ll b){

    ll sum = 0;
    while(n > 0){
        sum += n % 10;
        n = n / 10;
    }
    if(sum >= a && sum <= b) return 1;
    return 0;
}

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

    ll ans = 0;
    for(ll i = 1; i <= n; i++){
        if(digitSum(i, a, b)) ans += i;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256