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

#define int long long
#define itn int
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
constexpr int MOD = 1e9 + 7;

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
using P = pair<int, int>;
using vec = vector<int>;
template <typename T>
using mat = vector<vector<T>>;

// clang-format off
template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) { return stream << p.first << "," << p.second; }
template <typename T>
void print(const vector<T> vec) { rep (i, vec.size() - 1) cout << vec[i] << ' '; cout << vec[vec.size() - 1] << '\n'; }
template <typename Arg>
void print(const Arg arg) { cout << arg << '\n'; }
template <typename Head, typename... Args>
void print(const Head head, const Args... args) { cout << head << " "; print(args...); }
template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) { rep (i, v.size()) cin >> v[i] >> w[i]; }
template <typename T>
void init(vector<T>& v) { rep (i, v.size()) cin >> v[i]; }
template <typename T>
T sum_(vector<T> vec, T init = 0) { return std::accumulate(all(vec), T(init)); }
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; }
template <typename T>
int index(const T& vec, const typename T::iterator it) { return distance(vec.begin(), it); }
template <typename T = int>
mat<T> mmat(int n, int m=0) { return mat<T>(n, vector<T>(m)); }
template <typename T = int>
vector<T> ivec(int n) { vector<T> v(n); init(v); return v; }
// clang-format on

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    int x, n;
    cin >> x >> n;
    vector<bool> exist(102);
    int tmp;
    rep (i, n) {
        cin >> tmp;
        exist[tmp] = true;
    }

    int prev = -1;
    For(i, 0, 101) {
        if (i <= x and not exist[i])
            prev = i;
        else if (i > x and not exist[i]) {
            if (abs(prev - x) <= abs(i - x)) {
                print(prev);
                return 0;
            }
            print(i);
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
long long a[10000],n,cnt;
int main(){
	cin>>n;for(int i=0;i<n;i++)cin>>a[i];
	sort(a,a+n);
	for(int i=0;i<n;i++){
		if(cnt+1<a[i]){cout<<cnt+1<<endl;return 0;}cnt+=a[i];
	}
	cout<<cnt+1<<endl;
	return 0;
}

Measured memory_bytes: 3224
# coding: utf-8
#Problem Name: Digit Number
#ID: tabris
#Mail: t123037@kaiyodai.ac.jp

while True:
    try:
        a,b = map(int,raw_input().split(' '))
        print len(str(a+b))
    except:
        break

'''
Sample Input
5 7
1 99
1000 999
'''

Measured memory_bytes: 4196
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;cin>>N;
  int64_t L; cin>>L;
  vector<int64_t>a(N);
  for(int i=0;i<N;i++)
    cin>>a.at(i);
  int64_t ans=0;
  for(int i=0;i<N-1;i++)
    if(L<=a.at(i)+a.at(i+1)){ans=i+1; break;}
  if(ans==0)
    cout<<"Impossible"<<endl;
  else{
    cout<<"Possible"<<endl;
    for(int i=1;i<ans;i++)
      cout<<i<<endl;
    for(int i=N-1;ans<i;i--)
      cout<<i<<endl;
    cout<<ans<<endl;
 }
  return 0;
}

Measured memory_bytes: 4024
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001




int main (){
    int N; cin >> N;
    vector<vector<int>> R(N, vector<int>(N, 1));
    
    int A = (N+1)*N/2;
    
    if(N%2==0){
        for(int i=0; i<N; i++){
            R[i][N-1-i] = 0;
        }
    }else{
        for(int i=0; i<N-1; i++){
            R[i][N-2-i] = 0;
        }
    }
    
    int cnt = 0;
    for(int i=0; i<N; i++){
        for(int j=i+1; j<N; j++){
            if(R[i][j]) cnt++;
        }
    }
    cout << cnt << endl;
    for(int i=0; i<N; i++){
        for(int j=i+1; j<N; j++){
            if(R[i][j]) cout << i + 1 << " " << j + 1 << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>

using namespace std;

#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) (EQ((a).real(),(b).real()) && EQ((a).imag(),(b).imag()))

typedef complex<double> P;
typedef long long ll;

const double PI=4*atan(1.0);
const int MAX_SIZE = 10000;

// àÏ
double dot(P a, P b) {
  return (a.real() * b.real() + a.imag() * b.imag());
}
// OÏ
double cross(P a, P b) {
  return (a.real() * b.imag() - a.imag() * b.real());
}
// ½p`ÌÊÏö®
double calcPolygonArea(vector<P> p){
  double sum=0;
  for(int i = 0; i < p.size(); i++)
    sum+=cross(p[i],p[(i+1)%(p.size())]);
  return sum/2;
}

P points[50];
int n,m;
double dp[41][41][41];

const double INF=1000000;

// idxÈ~ÅleftÂIñÅÅÉfirstIdxÌàÌðIð
double calcMaxS(int left,int prvSelIdx,int firstIdx){
  if(!EQ(dp[left][prvSelIdx][firstIdx],0))
    return dp[left][prvSelIdx][firstIdx];
  double maxSum=-INF;
  bool ok=false;
  if(left==0){
    maxSum=(cross(points[prvSelIdx],points[firstIdx]));
    ok=true;
  }
  else{
    for(int i = prvSelIdx+1; i < n; i++){
      double res=calcMaxS(left-1,i,firstIdx);
      if(!EQ(res,INF)){
	maxSum=max(maxSum,res+(cross(points[prvSelIdx],points[i])));
	ok=true;
      }
    }
  }
  if(!ok)maxSum=INF;
  return dp[left][prvSelIdx][firstIdx]=maxSum;
}

int main(){
  while(cin>>n>>m&&!(n==0&&m==0)){
    double maxS=0;
    memset(dp,0,sizeof(dp));
    vector<double>tmp;
    for(int i = 0; i < n; i++){
      double p;
      cin>>p;
      tmp.push_back(p);
    }
    sort(tmp.begin(),tmp.end());
    for(int i = 0; i < n; i++)
      points[i]=P(cos(tmp[i]*2*PI),sin(tmp[i]*2*PI));
    for(int i = 0; i < n-m+1; i++){
      double res=abs(calcMaxS(m-1,i,i));
      if(!EQ(res,INF))
	maxS=max(maxS,res/2);
    }
    printf("%.6f\n",maxS);
  }
  return 0;
}

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

int main(void) {

  int n;
  long long ans = 0;
  cin >> n;

  for(int i = 1; i <= n; i++) {
    for(int j = 1; j <= n; j++) {
        int l = __gcd(i, j);
        //cout << l << endl;
      for (int k = 1; k <= n; k++) {
        int m = __gcd(l, k);
        //cout << m << endl;
        ans += m;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3624
import java.util.*;

class Main {
	public static void main (String[] args) {
		Scanner scan = new Scanner(System.in);
		int uhouho = scan.nextInt();
		int uhauha = scan.nextInt();
		System.out.println(uhouho * uhauha +  " "  + (2 * uhouho + 2 * uhauha));
	}
}

Measured memory_bytes: 17220
#include <vector>
#include <iostream>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;
int n, m, h, p, w1, w2;
int main() {
	while (scanf("%d%d%d%d", &n, &m, &h, &p), n) {
		vector<int> a(n);
		for (int i = 0; i < n; i++) scanf("%d", &a[i]);
		vector<vector<int> > v(h - 1);
		for (int i = 0; i < m; i++) {
			scanf("%d%d", &w1, &w2); w1--, w2--;
			v[w2].push_back(w1);
		}
		vector<int> x(n);
		for (int i = 0; i < n; i++) x[i] = i;
		vector<int> z = x;
		for (int i = 0; i < h - 1; i++) {
			for (int j : v[i]) swap(z[j], z[j + 1]);
		}
		vector<int> zp(n);
		for (int i = 0; i < n; i++) zp[z[i]] = i;
		int s = 0;
		for (int i = 0; i < p; i++) s += a[zp[i]];
		int ret = s;
		for (int i = 0; i < h - 1; i++) {
			for (int j : v[i]) {
				int res = s;
				if (x[j] < p && x[j + 1] >= p) res += a[zp[x[j + 1]]] - a[zp[x[j]]];
				if (x[j + 1] < p && x[j] >= p) res += a[zp[x[j]]] - a[zp[x[j + 1]]];
				ret = min(ret, res);
			}
			for (int j : v[i]) swap(x[j], x[j + 1]);
		}
		printf("%d\n", ret);
	}
	return 0;
}

Measured memory_bytes: 3436
#include<stdio.h>

int main(void){
  int i,j,tmp;
  int sum=0;
  int d[101],A[101];
  int N,K;
  
  for(i=1; i<=100; i++)
    A[i]=0;
  
  scanf("%d %d",&N,&K);
  for(i=1; i<=K; i++){
 	scanf("%d",&d[i]);
    for(j=1; j<=d[i]; j++){
   	  scanf("%d",&tmp);
      A[tmp]++;
    }
  }
  
  for(i=1; i<=N; i++)
    if(A[i]==0)
      sum++;
  printf("%d",sum);
  
  return 0;
}

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

using namespace std;

int main(){
    string s; cin >> s;
    int n; cin >> n;
    for(int i = 0; i < n; ++i){
        if(s[i] != '1'){
            cout << s[i] << endl;
            return 0;
        }
    }
    cout << '1' << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int N;
    cin >>N;
    int a =N%10;
    if(a==3){
        cout<<"bon"<<endl;
    }else if(a==0 ||a==1||a==6||a==8){
        cout<<"pon"<<endl;
    }else{
        cout<<"hon"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3044
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[8] = {-1,0,1,0,-1,1,1,-1};
int dx[8] = {0,1,0,-1,1,1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,w;
    cin>>n>>w;
    vector<pair<int,int>> v(n);
    for(int i=0;i<n;i++){
        cin>>v[i].first>>v[i].second;
    } 
    set<int> st;
    for(auto c:v){
        st.insert(c.first);
    }
    int m1=0,m2=0,m3=0,m4=0;
    for(auto c:st){
        if(m1==0)m1=c;
        else if(m2==0)m2=c;
        else if(m3==0)m3=c;
        else m4=c;
    }
    vector<int> M1,M2,M3,M4;
    for(auto c:v){
        if(c.first==m1)M1.push_back(c.second);
        else if(c.first==m2)M2.push_back(c.second);
        else if(c.first==m3)M3.push_back(c.second);
        else M4.push_back(c.second);
    }
    sort(All(M1),greater<int>());
    sort(All(M2),greater<int>());
    sort(All(M3),greater<int>());
    sort(All(M4),greater<int>());
    int s1=M1.size();
    int s2=M2.size();
    int s3=M3.size();
    int s4=M4.size();
    for(int i=1;i<s1;i++)M1[i]+=M1[i-1];
    for(int i=1;i<s2;i++)M2[i]+=M2[i-1];
    for(int i=1;i<s3;i++)M3[i]+=M3[i-1];
    for(int i=1;i<s4;i++)M4[i]+=M4[i-1];
    M1.insert(M1.begin(),0);
    M2.insert(M2.begin(),0);
    M3.insert(M3.begin(),0);
    M4.insert(M4.begin(),0);
    int res=0;
    for(int i=0;i<=s1;i++){
        for(int j=0;j<=s2;j++){
            for(int k=0;k<=s3;k++){
                for(int h=0;h<=s4;h++){
                    int totalW=m1*i+m2*j+m3*k+m4*h;
                    if(totalW>w)continue;
                    res=max(res,M1[i]+M2[j]+M3[k]+M4[h]);
                }
            }
        }
    }
    cout<<res<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2　//1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) (max(x,y)-min(x,y))
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int,int>;
typedef vector<int> vit;

signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  string s, t;
  cin >> s >> t;
  if(s.size() > t.size()){
    cout << "GREATER\n";
  } else if(s.size() < t.size()){
    cout << "LESS\n";
  } else {
    rep(i, s.size()){
      if(s[i] > t[i]){
	cout << "GREATER\n";
	return 0;
      } else if(s[i] < t[i]){
	cout << "LESS\n";
	return 0;
      }
    }
    cout << "EQUAL\n";
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

int main(){

	int n, ab=0, a=0, b=0, ba=0, ans;
	string s;

	cin>> n;

	for(int i=0;i<n;i++){
		cin>> s;
		for(int j=0;j<s.size()-1;j++){
			if(s.substr(j, 2)=="AB") ab++;
		}

		if(s[0]=='B' && s[s.size()-1]=='A'){
			ba++;
		}else{
			if(s[s.size()-1]=='A') a++;
			if(s[0]=='B') b++;
		}
	}

	//cout<< ab << " " << a << " " << b << " " << ba << endl;

	ans=ab;
	ans+=max(0, ba-1);

	if(1<=ba){
		if(1<=a){
			ans++;
			a--;
		}
		if(1<=b){
			ans++;
			b--;
		}
	}

	ans+=min(a, b);	

	cout<< ans << endl;
/*
	for(int i=0;i<v.size();i++) cout<< v[i] << endl;

	cout<< n << endl;
	cout<< v[0] << " " << v[1] << endl;*/


}

Measured memory_bytes: 384
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,-1,0};
int dy[4]={1,0,0,-1};
long double eps = 1e-9;
long double pi = acos(-1);

ll mod = 1e9+7;
template<typename T> void add(T &a,T b){a=(a+b)%mod;}
template<typename T> void sub(T &a,T b){a=(a+mod-b)%mod;}


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    int n = 5;
    int a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++){
        if(a[i] == 0){
            cout << i+1 << endl;
            return 0;
        }
    }

}

Measured memory_bytes: 3612
#include<iostream>
#include<vector>
#include<math.h>
#include<algorithm>
using namespace std;

int main(){
  int n, k;
  cin >> n >> k;
  vector<long long> a;
  vector<long long> b;
  long long x[50];
  long long y[50];
  for(int i = 0; i < n ; i++){
    cin >> x[i] >> y[i];
    a.push_back(x[i]);
    b.push_back(y[i]);
  }

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

  long long ans = (a[n-1]-a[0])*(b[n-1]-b[0]);

  for(int xi = 0; xi < n ; xi++){
    for(int xj = xi + 1; xj < n; xj++){
      for(int yi = 0 ; yi < n ; yi++){
        for(int yj = yi + 1; yj < n ; yj++){
          int count = 0;
          long long o = a[xi];
          long long p = a[xj];
          long long q = b[yi];
          long long r = b[yj];
          for(int c = 0 ; c < n; c++){
            if(x[c] >= o && x[c] <= p && y[c] >= q && y[c] <= r) count++;
          }
          if(count >= k) ans = min(ans, (p - o) * (r - q));
        }
      }
    }
  }
  cout << ans << endl;
}


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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL<<60;
const ll mod =1000000007;



int main() {

	ll n;
	cin >> n;

	ll ans = 0;


	FOR(i, 1, 1000000) {
		ll m = n - i;
		if (m%i != 0)continue;

		if(m/i>i)ans += m / i;
	}

	cout << ans << endl;


}


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

int main() {
	for (int a = 1; a < 10; a++) {
		for (int b = 1; b < 10; b++) {
			printf("%dx%d=%d\n", a, b, a*b);
		}
	}
}

Measured memory_bytes: 3132
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
template<class D>
vector<D> dijkstra(const vector<vector<pair<int,D>>>& G, int s = 0){	//G:(v,cost)
	using P = pair<D,int>;
	priority_queue<P,vector<P>,greater<P> > que;
	int N = G.size();

	D inf = 1e18;
	vector<D> d(N,inf);
	d[s] = 0;
	que.push(P(0,s));

	while(!que.empty()){
		P p=que.top();
		que.pop();
		int v = p.sc;
		D c = p.fs;
		if(d[v]!=c) continue;
		for(auto p:G[v]){
			int to=p.fs;
			if(d[to]>d[v]+p.sc){
				d[to]=d[v]+p.sc;
				que.push(P(d[to],to));
			}
		}
	}

	return d;
}
using ll = long long;
using P = pair<int,ll>;
int N,M,S,T;
vector<vector<P>> G,G2;
int main(){
	cin>>N>>M>>S>>T;
	S--,T--;
	G.resize(N),G2.resize(N);
	rep(i,M){
		int x,y;
		ll a,b;
		cin>>x>>y>>a>>b;
		x--,y--;
		G[x].pb(P(y,a));
		G[y].pb(P(x,a));
		G2[x].pb(P(y,b));
		G2[y].pb(P(x,b));
	}
	vector<ll> a = dijkstra(G,S);
	vector<ll> b = dijkstra(G2,T);
	vector<ll> ans(N);
	ll X = 1;
	rep(i,15) X*=10;
	rep(i,N){
		ans[N-1-i] = a[i]+b[i];
	}
	rep1(i,N-1){
		chmin(ans[i],ans[i-1]);
	}
	rep(i,N){
		cout<<X-ans[N-1-i]<<endl;
	}
}


Measured memory_bytes: 19012
#include<stdio.h>
#include<string.h>
#include<queue>
#include<utility>
using namespace std;
char m[128][128];
void PutSquare(int x, int y, int c)
{
	m[y][x] = m[y+1][x] = m[y+1][x+1] = m[y][x+1] = static_cast<char>(c);
}
bool CanReach(int sx,int sy,int gx,int gy)
{
	bool f[128][128]={};

	typedef pair<int,int>P;
	queue<P>q;
	q.push(P(sx,sy));

	const char c = m[sy][sx];
	if(!c)
		return false;
	const int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
	while(!q.empty())
	{
		P p = q.front();
		q.pop();
		if(f[p.second][p.first] || c!=m[p.second][p.first])
			continue;
		if(p.first==gx && p.second==gy)
			return true;
		f[p.second][p.first] = true;
		for(int i=0; i<4; ++i)
			q.push(P(p.first+dx[i],p.second+dy[i]));
	}
	return false;
}
int main()
{
	int h, w;
	int sx, sy;
	int gx, gy;
	int n;
	int c, d, x, y;
	while(scanf("%d%d",&w,&h),h)
	{
		memset(m,0,sizeof(m));

		scanf("%d%d",&sx,&sy);
		scanf("%d%d",&gx,&gy);
		scanf("%d",&n);
		while(n--)
		{
			scanf("%d%d%d%d",&c,&d,&x,&y);
			PutSquare(x,y,c);
			if(d==0)
				PutSquare(x+2,y,c);
			else
				PutSquare(x,y+2,c);
		}
		puts(CanReach(sx,sy,gx,gy) ? "OK" :"NG");
	}
	return 0;
}

Measured memory_bytes: 1068
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define INF 0x3f3f3f3
#define LINF 0x3f3f3f3f3f3f3f
#define MAXN int(1e5)+5
#define fim '\n'
#define ll long long
#define f first
#define s second
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << fim
#define debug2(x, y) cout << "DEBUG " << x << " " << y << fim
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< fim
#define debug4(x, y, z, o) cout << "DEBUG " << x << " " << y << " " << z<< " " << o << fim
#define max3(x, y, z) max(x, max(y, z))
#define ull unsigned long long
using namespace std;
using namespace __gnu_pbds;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef pair<unsigned ll, pair<int, int> > piii;
typedef pair<pair<int, int>, int> piii2;
typedef tree<int,null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> indexed_set;
const ll mod = 1e9+7;
ll expo(ll a, ll b){
    if(b == 0) 
		return 1;
    ll x = expo(a, b/2);
    return (b & 1 ? ((x*x)%mod*a)%mod : (x*x) % mod);
}

int main() {
	int n, k;
	cin >> n >> k;
	int ans = 0;
	while(n--) {
		int a;
		cin >> a;
		if(a >= k) ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>
using std::cout;
using std::cin;
using std::endl;
int n;

int partition(int *A, int p, int r){
  int x=A[r];
  int i=p-1;
  for(int j=p;j<r;j++){
    if(A[j]<=x){
      i++;
      std::swap(A[i], A[j]);        
    }
  }
  std::swap(A[i+1], A[r]);
  return i+1;
}  

int main(){
  cin >> n;
  int A[n];
  for(int i=0;i<n;i++)     
    cin >> A[i];  int q=partition(A,0,n-1);
  for(int i=0;i<n;i++){        if(i) cout << " ";         if(i==q)
      cout << "[" << A[i] << "]";
    else
      cout << A[i];
  }
  cout << endl;
  return 0;
}


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

int main() {
  char N,M;
  cin >> N >> M;
  if (string(int(N-'0'), M) <= string(int(M-'0'), N)) cout << string(int(N-'0'), M) << endl;
  else cout << string(int(M-'0'), N) << endl;
}

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

char ss[25000][6];

int compare(const void *arg1, const void *arg2){
	return(strcmp(ss[*(int*)arg1], ss[*(int*)arg2]));
}

int main(){
	char s[5001];
	int k,g=0,i,j,c=0,l;
	scanf("%s%d",s,&k);
	while(s[g]!=0)g++;
	int num[25000];
	for(i=0;i<25000;i++)num[i]=i;
	for(i=0;i<g;i++){
		for(j=0;j<5&&i+j<g;j++){
			for(l=0;l<=j;l++)ss[c][l]=s[i+l];
			ss[c][5]='\0';
			c++;
		}
	}
//	for(i=0;i<c;i++)printf("%s\n",ss[i]);
	qsort(num,c,sizeof(int),compare);
/*	for(i=0;i<c;i++){
		for(j=0;j<i;j++){
			if(strcmp(ss[num[i]],ss[num[j]])<0){
*//*				char tmp[7]={0};
				strcpy(tmp,ss[i]);
				for(l=0;l<5;l++)ss[i][l]='\0';
				strcpy(ss[i],ss[j]);
				for(l=0;l<5;l++)ss[j][l]='\0';
				strcpy(ss[j],tmp);
*//*			
			int tmp=num[i];
			num[i]=num[j];
			num[j]=tmp;
			}
		}
	}*/
//	for(i=0;i<c;i++)printf("%s\n",ss[i]);
	int count=0;
	for(i=0;i<c;i++){
		if(count==k-1){
			printf("%s\n",ss[num[i]]);
			return 0;
		}
		if(strcmp(ss[num[i]],ss[num[i+1]])<0)count++;
	}
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  cout<<fixed;
  int n, a,b;
  cin>>n>>a>>b;
  cout <<min(a*n,b) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

void call(int);

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

  call(n);
  return 0;
}

void call(int n){
  int i;
  int x;

  for(i = 1; i <= n; i++){
    x = i;
    if(x % 3 == 0){
      printf(" %d", i);
    }
    else if(x % 10 == 3){
      printf(" %d", i);
    }
    else {
      while(x != 0){
	if(x % 10 == 3){
	  printf(" %d", i);
	  break;
	}
	x /= 10;
      }
    }
  }

  printf("\n");
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(v) v.begin(), v.end()
#define revall(v) v.rbegin(), v.rend()
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){ if(y<h && y>=0 && x<w && x>=0) 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 chmax(T& a, T b){ if(a < b){ a = b; return true; } return false; }






int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,k,q;cin >> n >> k >> q;
	vector<int> a(n, q);
	rep(i,q){
		int b;cin >> b;
		b--;
		a.at(b)--;
	}
	rep(i,n){
		if(k - a.at(i) > 0) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()
template<class T>
using reverse_priority_queue = priority_queue<T, vector<T>, greater<T>>;


int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    REP(i, n){
        cin >> a.at(i);
    }
    sort(ALL(a));

    const ll maxa = *max_element(ALL(a));

    vector<bool> check(maxa + 1, false);
    ll ans = 0;
    REP(i, n){
        const ll ai = a.at(i);
        if(!check.at(ai) &&
           (i == n - 1 || a.at(i + 1) != ai) &&
           (i == 0 || a.at(i - 1) != ai)){
            ans++;
        }
        if(!check.at(ai)){
            for(ll x = ai; x <= maxa; x += ai){
                check.at(x) = true;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4760
void main() {
    int n = readln.chomp.to!int;
    int[] a = readln.split.to!(int[]);
    writeln(a.reduce!max - a.reduce!min);
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    while(cin >> n, n){
        int cur = 0;
        while(n != 1){
            if(n&1) n = n*3+1;
            else n /= 2;
            cur++;
        }
        cout << cur << "\n";
    }
    return 0;
}


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

using namespace std;

long long n, m;
long long ans;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    long long d = min(n, m / 2);
    m -= 2 * d;
    cout << d + m / 4 << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <stack>
#include <map>
#include <math.h>
#include <vector>
#include <cctype>
using namespace std;

int main() {

	int a;
	bool good = false;
	cin >> a;
	for(int i=0; i<=25; i++){
		for(int k=0; k<=15; k++){
			if(i*4+k*7 == a){
				good = true;
			}
			if(i*4+k*7 > 100){
				break;
			}
		}
	}
	if(good){
		cout << "Yes";
	}else{
		cout << "No";
	}
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lowbit(i) ((i)&(-(i)))
#define lson(i) ((i)<<1)
#define rson(i) ((i)<<1|1)
#define fi first
#define se second
#define m_p(x,y) make_pair((x),(y))
using namespace std;

typedef long long ll;typedef unsigned long long ul;
typedef pair<int,int> pii;typedef pair<ll,ll> pll;
typedef vector<string> vss;
typedef vector<int> vii;typedef vector<pii> vpi;
typedef queue<int> qii;typedef queue<pii> qpi;

const int inf=0x3f3f3f3f;
const int maxn=200007;

ll n,m,a[maxn],pre[maxn],res;
unordered_map<ll,ll> num;

int main()
{
// 	freopen("","r",stdin);
// 	freopen("","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		pre[i]=pre[i-1]+a[i];
		num[pre[i]]++;
	}
	num[0]++;
	for(unordered_map<ll,ll>::iterator it=num.begin();it!=num.end();it++){
		ll p=it->second;
		res+=p*(p-1)>>1;
	}
	cout<<res<<'\n';
	return 0;
}



Measured memory_bytes: 11592
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  ll n,m,k;
  cin >> n >> m >> k;
  bool a=false;
  rep(i,n+1){
    rep(j,m+1){
      if(k==i*j+(n-i)*(m-j)){
        a=true;
      }
    }
  }
  if(a){
    cout << "Yes" << endl;
  }
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maximo = 1e5;
int arr[maximo+10];
int ordenado[maximo+10];
int cant = 0;
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	//freopen(".in","r",stdin);
	//entrada
	int n ; cin >> n;
	for (int i = 0 ; i < n ; i++)
        {cin >> arr[i];ordenado[i]=arr[i];}

    //solution
    sort(ordenado,ordenado+n);
    for (int i = 0 ; i< n ;i++)
    {
        int a = lower_bound(ordenado,ordenado+n,arr[i])-arr;
        if (abs(a-i)%2 != 0) cant++;
    }
    cout << cant/2 << "\n";





    return 0;
}


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

int main(){
    string s, t;
    cin >> s >> t;
    int x = (int)s.size();
    int y = (int)t.size();
    struct data{
        int from_x, from_y, length;
        char z;
    };
    data ini;
    ini.from_x = 0;
    ini.from_y = 1;
    ini.length = 0;
    ini.z = '0';
    vector<vector<data>> ans(x+1, vector<data>(y+1, ini));
    for (int i = 0; i < x; i++){
        for (int j = 0; j < y; j++){
            if (s[i] == t[j]){
                ans[i+1][j+1].from_x = i;
                ans[i+1][j+1].from_y = j;
                ans[i+1][j+1].length = ans[i][j].length + 1;
                ans[i+1][j+1].z = s[i];
            }
            else {
                if (ans[i+1][j].length >= ans[i][j+1].length) ans[i+1][j+1] = ans[i+1][j];
                else ans[i+1][j+1] = ans[i][j+1];
            }
        }
    }

    string out = "";
    int nx = ans[x][y].from_x;
    int ny = ans[x][y].from_y;
    if (ans[x][y].z != '0') out += ans[x][y].z;
    while (nx != 0 && ny != 0){
        out += ans[nx][ny].z;
        int tx = ans[nx][ny].from_x;
        int ty = ans[nx][ny].from_y;
        nx = tx;
        ny = ty;
    }
    if (out.back() == '0') out.pop_back();
    reverse(out.begin(), out.end());
    cout << out << endl;
}

Measured memory_bytes: 141184
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<cmath>
#include<cstring>
using namespace std;
#define maxn 1000010
#define llg long long 
#define yyj(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
llg n,m,a[maxn],qz[maxn];

bool check(llg x)
{
	llg val=qz[x];
	for (llg i=x+1;i<=n;i++)
		if (val*2<a[i])
		{
			return 0;
		}
		else
		{
			val+=a[i];
		}
	return 1;
}

int main()
{
//	yyj("B");
	cin>>n;
	for (llg i=1;i<=n;i++) scanf("%lld",&a[i]);
	sort(a+1,a+n+1);
	for (llg i=1;i<=n;i++) qz[i]=qz[i-1]+a[i];
	llg l=1,r=n,mid,ans;
	while (l<=r)
	{
		mid=(l+r)>>1;
		if (check(mid)) {ans=mid,r=mid-1;}else l=mid+1; 
	}
	cout<<n-ans+1;
	return 0;
}


Measured memory_bytes: 5120
#![allow(non_snake_case, unused_imports)]

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,HashMap,BTreeMap,VecDeque};

// Functions

// Main
fn main(){
    input!{
        A: i64,
        B: i64,
        C: i64,
    }
    println!("{}", if B-A==C-B{"YES"}else{"NO"});
}

Measured memory_bytes: 4352
#include <cstdio>
#include <map>
#include <queue>
#include <vector>
#include <functional>

using std::map;
using std::vector;
using std::greater;
using std::priority_queue;

int k,ans;

map<int,int> mp;

inline int greedy(){
	static priority_queue<int,vector<int>,greater<int> > hp;
	for(map<int,int>::iterator i=mp.begin();i!=mp.end();++i)
		hp.push(i->second);
	int ret=0;
	while(hp.size()>k){
		ret+=hp.top();
		hp.pop();
	}
	return ret;
}

int main(){
	int n;
	scanf("%d%d",&n,&k);
	for(int i=1,a;i<=n;++i){
		scanf("%d",&a);
		++mp[a];
	}
	printf("%d",greedy());
	return 0;
}

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

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

template<class T> using v = std::vector<T>;
template<class T> using vv = v<v<T>>;

const int mod = 1000000007;
//const int mod = 998244353;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


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

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;}

// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

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

    for(char i: n) {
        if (i == '7') {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3644
import scala.collection.mutable
import scala.io.StdIn._
object Main extends App {

  val Array(n, m, k) = readLine.trim.split(' ').map(_.toInt)
  val roads = Array.tabulate(m){_ ⇒
    val Array(a, b, l) = readLine.trim.split(' ').map(_.toInt)
    Road(a - 1, b - 1, l)
  }
  val cities = Array.fill(n){Nil: List[Path]}
  for (Road(a, b, l) ← roads) {
    cities(a) ::= Path(b, l)
    cities(b) ::= Path(a, l)
  }
  val minDistance = Array.fill(n){Int.MaxValue}
  val queue = mutable.PriorityQueue[(Int, Int)]()(Ordering.by[(Int, Int), Int](_._2).reverse)
  for (_ ← 0 until k){
    val s = readInt() - 1
    minDistance(s) = 0
    queue.enqueue(s → 0)
  }
  while (queue.nonEmpty) {
    val (current, cost) = queue.dequeue()
    if (minDistance(current) == cost){
      for (Path(to, length) ← cities(current) if minDistance(to) > cost + length) {
        minDistance(to) = cost + length
        queue.enqueue(to → minDistance(to))
      }
    }
  }
  println(roads.map{
    case Road(a, b, length) ⇒
      val min = Math.min(minDistance(a), minDistance(b))
      val max = Math.max(minDistance(a), minDistance(b))
      val diff = max - min
      (length - diff + 1) / 2 + max
  }.max)
  case class Road(a: Int, b: Int, length: Int)
  case class Path(to: Int, length: Int)
}


Measured memory_bytes: 195188
import java.util.*;

public class Main{
    public static void main(String args[]){ 

	Scanner scn = new Scanner(System.in);
	int H = scn.nextInt();
	int W = scn.nextInt();
    int h = scn.nextInt();
  	int w = scn.nextInt();

      System.out.print((H*W)-((w*H)+(h*W)-(w*h)));

    }
}

Measured memory_bytes: 21844
import math
n = int(input())
ans = 0

for i in range(n):
    num1 = i + 1
    for j in range(n - num1 + 1):
        num2 = j + num1
        gcd1 = math.gcd(num1, num2)
        for k in range(n - num2 + 1):
            num3 = k + num2
            gcd2 = math.gcd(gcd1, num3)
            if num1 == num2 and num2 == num3:
                ans += gcd2
            elif num1 == num2 or num2 == num3:
                ans += gcd2 * 3
            else:
                ans += gcd2 * 6

print(ans)


Measured memory_bytes: 9192
def solve():
    n = int(input())
    a = []
    b = []
    for _ in range(n):
        A, B = map(int, input().split())
        a.append(A)
        b.append(B)

    ans = b[-1] - a[-1]%b[-1]
    if a[-1]%b[-1] == 0: ans = 0

    for i in range(1, n):
        c = a[-(i+1)]+ans
        if c%b[-(i+1)] == 0: continue
        
        if c > b[-(i+1)]:
            dis = b[-(i+1)]-c%b[-(i+1)]
            ans += dis
        else:
            dis = b[-(i+1)] - c
            ans += dis

    return max(0, ans)
    

print(solve())


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

bool check(string s, string t){
	if(s.size() != t.size()) return false;
	for(int i=0;i<s.size();i++){
		if(s[i] != t[i] && s[i] != '?') return false;
	}
	return true;
}

int main(){
	string s,t;
	cin >> s >> t;
	if(s.size() < t.size()) {
		cout << "UNRESTORABLE" << endl;
		return 0;
	}
	for(int i=(int)s.size() - (int)t.size();i>=0;i--){
		if(check(s.substr(i,t.size()),t)){
			for(int j=0;j<(int)s.size();j++){
				if(j < i){
					if(s[j] == '?'){
						cout << "a";
					} else {
						cout << s[j];
					}
				} else if(j < i + (int)t.size()){
					cout << t[j-i];
				} else {
					if(s[j] == '?'){
						cout << "a";
					} else {
						cout << s[j];
					}
				}
			}
			cout << endl;
			return 0;
		}
	}
	cout << "UNRESTORABLE" << endl;
	return 0;
}

Measured memory_bytes: 256
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=1e18;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll a,b,m,aa[100005]={},bb[100005]={},ans=INF,x[100005]={},y[100005]={},c[100005]={},c1=INF,c2=INF;
  cin >> a >> b >> m;
  for(int i=0; i<a; i++) {
    cin >> aa[i];
    c1=min(c1,aa[i]);
  }
  for(int i=0; i<b; i++) {
    cin >> bb[i];
    c2=min(c2,bb[i]);
  }
  ans=c1+c2;
  for(int i=0; i<m; i++) {
    cin >> x[i] >> y[i] >> c[i];
    ans=min(ans,aa[x[i]-1]+bb[y[i]-1]-c[i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 4224
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int h = sc.nextInt();
        int w = sc.nextInt();
        int count = 0;
        for(int i = 0; i < n; i++){
            int a = sc.nextInt();
            int b = sc.nextInt();
            if(h <= a && w <= b) count++;
        }
        
        System.out.println(count);
    }
}


Measured memory_bytes: 26324
x1, y1, x2, y2 = map(int, input().split())
a = y1 - y2
b = x2 - x1
x3 = x2 + a
y3 = y2 + b
x4 = x3 - b
y4 = y3 + a
print(x3, y3, x4, y4)


Measured memory_bytes: 38256
#include<iostream>
#include<cstdio>
#include<algorithm>
#define rep(i,x,y) for(int i=(x);i<=(y);++i)
#define per(i,x,y) for(int i=(x);i>=(y);--i)
typedef long long LL;
using std::sort;
const int N=1e5+10; 
int n,a[N],b[N];
LL c[N];
bool cmp(int x,int y){return a[x]>a[y]||(a[x]==a[y]&&x<y);}
int main(){
	scanf("%d",&n);
	rep(i,1,n)scanf("%d",&a[i]);
	rep(i,1,n)b[i]=i;
	sort(b+1,b+1+n,cmp);
	int p=n+1;
	LL sum=0,cnt=0;
	rep(i,1,n){
		if(b[i]<p){
			c[p]=sum-cnt*a[b[i]];
			sum=cnt*a[b[i]];
			p=b[i];
		}
		++cnt;
		sum+=a[b[i]];
	}
	c[1]=sum;
	rep(i,1,n)printf("%lld\n",c[i]);
	return 0;
}


Measured memory_bytes: 2688
N, M = map(int, input().split())
A = list(map(int, input().split()))

def nax(a, b):
    if a == '-':
        return b
    if len(a) != len(b):
        return a if len(a)>len(b) else b
    return a if a>b else b


match = [2,5,5,4,5,6,3,7,6]
# dp[i]  : iほんのマッチを使ってできる数値の最大値
dp = ['-'] * 11000
dp[0] = ''

for i in range(N+1):
    if dp[i] == '-':
        continue
    for a in A:
        dp[i+match[a-1]] = nax(dp[i+match[a-1]], dp[i] + chr(ord('0') + a))

print(dp[N])

Measured memory_bytes: 98280
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <list>

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

using namespace std;
using ll = long long;
using P = pair<int, int>;
using TP = tuple<ll, ll, ll>;
ll MOD = 1e9+7;
const int INF = 1e6;
const ll LINF = (ll)1e19;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;
    cin >> N;
    list<int> lst;// = {-1, -1};
    stack<int> st;
    REP(i, N){
        int tmp;
        cin >> tmp;
        lst.push_front(tmp);
    }
    list<int>::const_reverse_iterator itr;
//
//    for(itr = lst.begin(); itr != lst.end(); ++itr){
//        cout << *itr << endl;
//    }
//    return 0;
    while(lst.size() > 0){
        int idx = lst.size();
        bool found = false;
        for(itr = lst.rend(); itr != lst.rbegin(); --itr){
            //cout << idx << "," << *itr.base() << endl;
            if(*itr.base() == idx){
                st.push(*itr.base());
                lst.erase(itr.base());
                found = true;
                break;
            }
            idx--;
        }
        if(found == false){
            cout << -1 << endl;
            return 0;
        }
    }
    while(!st.empty()){
        cout << st.top() << endl;
        st.pop();
    }

    
    return 0;    
}


Measured memory_bytes: 256
def main():
    N, Q = map(int, input().split())
    S = input()
    LR = [list(map(int, input().split())) for _ in range(Q)]

    AC_cnt = 0
    ll = [0]
    for i in range(1, len(S)):
        if S[i - 1:i + 1] == "AC":
            AC_cnt += 1
        ll.append(AC_cnt)

    for l, r in LR:
        print(ll[r - 1] - ll[l - 1])


main()


Measured memory_bytes: 30696
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

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

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
int A, B, C;

int main() {
  scanf(" %d%d%d", &A, &B, &C);
  if (A > B) std::swap(A, B);
  puts((A < C) && (C < B) ? "Yes" : "No");
  return 0;
}


Measured memory_bytes: 128
#include<iostream>

using namespace std;

int main()
{
	int n;

	cin >> n;

	int a[100];
	int sum = 0;

	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum += a[i];
	}

	double ave = (double)sum / n;
	int p;

	if (ave - sum / n < 0.5) p = sum / n;
	else p = sum / n + 1;

	int S = 0;

	for (int i = 0; i < n; i++)
		S += (a[i] - p) * (a[i] - p);
	cout << S << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define srt(x) sort((x).begin(), (x).end());
#define rsrt(x) sort((x).rbegin(), (x).rend());
#define deb(x) cout<<#x<<" = "<<(x)<<" (L"<<LINE<<")"<<endl;
#define vdeb(x) {cout<<#x<<" = { "; rep(i, x.size()) cout<<x[i]<<' '; cout <<'}'<<" (L"<<LINE<<")"<<endl;}
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vivi = vector<vi>;
using vll = vector<long long>;
using vllvll = vector<vll>;
using vs = vector<string>;
using um = unordered_map<long long, long long>;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
const long long MAX = 1000;

ll n;
vllvll M(MAX,vll(0));
vll ts1(MAX);
vll ts2(MAX);
vll seen(MAX, 0);

void rec(ll node, ll& ptr)
{
    ts1[node] = ptr++;
    seen[node] = 1;
    for (ll adj : M[node]) {
        if (seen[adj] == 1) continue;
        rec(adj, ptr);
    }
    ts2[node] = ptr++;
}

void dfs()
{
    ll ptr = 1;
    rep(i, 0, n) {
        if (seen[i] == 0) {
            rec(i, ptr);
        }
    }
}

int main()
{
    cin >> n;
    ll u, k, v;
    rep(i, 0, n) {
        cin >> u >> k;
        --u;
        rep(j, 0, k) {
            cin >> v;
            --v;
            M[u].push_back(v);
        }
    }
    ll f = 0, l = 0;
    dfs();
    rep(i, 0, n) {
        cout << i+1 << ' ' << ts1[i] << ' ' << ts2[i]<< endl;
    }
}


Measured memory_bytes: 3116
package main

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

func readLine(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func lineToInts(line string) []int {
	var res []int
	for _, s := range strings.Split(line, " ") {
		i, _ := strconv.Atoi(s)
		res = append(res, i)
	}
	return res
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	line1 := lineToInts(readLine(sc))
	n := line1[0]
	m := line1[1]
	c := line1[2]

	bs := lineToInts(readLine(sc))
	res := 0
	for i := 0; i < n; i++ {
		calc := 0
		as := lineToInts(readLine(sc))
		for j := 0; j < m; j++ {
			calc += as[j] * bs[j]
		}
		calc += c
		if calc > 0 {
			res++
		}
	}
	fmt.Println(res)
}


Measured memory_bytes: 640
#include <iostream>

int main() {
  int week;
  std::cin >> week;

  int debt = 100000;

  for(int cnt = 0; cnt < week; ++cnt) {
    debt *= 1.05;
    if(debt % 1000 != 0) {
      debt += (1000 - (debt % 1000));
    }
  }

  std::cout << debt << std::endl;
}

Measured memory_bytes: 1160
#include <stdio.h>
int main()
{
    int a, b, c;
    scanf(" %d %d %d",&a,&b,&c);
        if((a==b&&a!=c)||(a==c&&a!=b)||(b==c&&b!=a))
            printf("Yes\n");
        else
            printf("No\n");
}

Measured memory_bytes: 128