akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define ROF(i, a, b) for (int i = a; i >= b; i--)
using namespace std;

using pii = pair<int, int>; using vpii = vector<pii>;
using vi = vector<int>; using vvi = vector<vi>;
using ll = long long;
using pll = pair<ll, ll>; using vpll = vector<pll>;
using vll = vector<ll>; using vvll = vector<vll>;

int main() {
    int n; cin >> n;
    int ans = 0;
    FOR(i, 1, n) {
        int tt; cin >> tt;
        if (tt & 1 && i & 1) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  int X,Y;
  X=(A+D-1)/D;
  Y=(B+C-1)/B;
  if(Y>X)
    cout<<"No"<<endl;
  else
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 3632
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,K = map(int, readline().split())
A = np.int32(read().split())

A -= 1

def mult(A, B):
  return B[A]

def power(A, n):
  if not n:
    return np.arange(N)
  B = power(A, n//2)
  B = mult(B,B)
  return mult(A,B) if n & 1 else B

print(power(A, K)[0] + 1)

Measured memory_bytes: 39352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ldb = long double;
using pa = pair < ll, ll >;
using vec = vector < ll >;
#define pb push_back
#define F  first
#define S  second
#define int ll
#define f(i,x,n) for(ll i=x;i<n;i++) 
#define all(c) c.begin(),c.end()
#define edl "\n"
#define ceils(s,n) (s+n-1)/n
#define str string
#define add insert
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
const int MOD = 1e9 + 7, N = 5e5 + 10;
const ll LINF = LLONG_MAX;
int a,b,c,d,ans;
str s1,s2,s;
int32_t main() {
    fast();
    cin >> a >> b;
    if(a==1 and b==2){
        cout<<3;
    }
    if(a==3 and b==2){
        cout<<1;

    }
    if(a==3 and b==1){
        cout<<2;
    }
    if(a==1 and b==3){
        cout<<2;
    }
    if(a==2 and b==3){
        cout<<1;
    }
    if(a==2 and b==1){
        cout<<3;
    }
    return 0;
}
 

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

using namespace std;

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

long long int INF = 3e18;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←


#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(15)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl


long long int mod = 4294967296;
ll rui(ll number1,ll number2){
    //abcのbed乗を計算する
    if(number2 == 0){return 1;}
    else{
        ll number3 = rui(number1,number2/2);
        number3 *= number3;
        number3 %= mod;
        if(number2 % 2 == 1){number3 *= number1; number3 %= mod;}
        return number3;
    }
}
ll gcd(ll number1,ll number2){
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}

ll n,m,num,sum,ans,a,b,c,d,e,f,g,h,i,j,k,w,ok,ng,res,q;
ll x[500005],y[500005],z[500005];
char s[500005];

int main(){
    cin >> s;
	if(s[0] == 'A')p("T");
	if(s[0] == 'T')p("A");
	if(s[0] == 'C')p("G");
	if(s[0] == 'G')p("C");
	return 0;
}

Measured memory_bytes: 25600
#include<bits/stdc++.h>
using namespace std;
int main(){
  int t,max=0;
    cin>>t;
  string ss;
  map<string,int>vote;
  set<string> words;
  for(int i=0;i<t;i++)
  {cin>>ss;
  	++vote[ss];
  	words.insert(ss);
  	if(max<vote[ss])
  	max=vote[ss];} 
  for(set<string>::iterator it=words.begin();it!=words.end();++it)
  {if(vote[*it]==max)
  	cout<<*it<<"\n";}
  return 0;
} 

Measured memory_bytes: 34560
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		boolean f = true;
		int[] c = new int['z' - 'a' + 1];
		while (s.hasNext()) {
			char[] chars = s.next().toLowerCase().toCharArray();
			for (char ch : chars) {
				if (Character.isLetter(ch)) {
					c[ch - 'a']++;
				}
			}
		}
		for (int i = 0; i < c.length; ++i) {
			System.out.printf("%c : %d\n", (char)('a' + i), c[i]);
		}
	}
}

Measured memory_bytes: 20132
program name
    implicit none
    integer(4):: n,i,cnt
    integer(4),allocatable:: a(:)
    logical,allocatable:: pulled(:)

    read*, n
    allocate(a(n),pulled(n))

    do i=1,n
        read*, a(i)
    end do

    pulled(:) = .false.
    i=1
    cnt = 0
    do while(.not.(pulled(2)))
        i = a(i)
        if (pulled(i)) then
            print*, -1
            stop
        end if
        pulled(i) = .true.
        cnt=cnt+1
    end do

    print*, cnt

end program name

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define yoi cout<<"yo"<<endl;
#define debug(x) cerr << #x << " is " << x << endl;
#define all(x) x.begin(),x.end()
const lli inf=1e18;
const int mod=1e9+7;
int main(){
IOS;
lli n,k;
cin>>n>>k;
lli i,a[n],b[n];
for(i=0;i<n;i++)
    cin>>a[i];
for(i=0;i<n;i++)
    cin>>b[i];
sort(a,a+n,greater<lli>());
sort(b,b+n);
lli start=0,last=1e15,middle,index=-1;
while(start<=last){
    middle=(start+last)/2;
    lli x=k;
    //cout<<middle<<endl;
    for(i=0;i<n;i++){
        if(a[i]*b[i]>middle){
            lli w=middle/b[i];
            x-=a[i]-w;
            //cout<<a[i]<<" "<<w<<endl;
        }
        if(x<0)
            break;
    }
    if(i==n){
        last=middle-1;
        index=middle;
    }
    else{
        start=middle+1;
    }
}
cout<<index<<endl;
}


Measured memory_bytes: 3328
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
int n,res;
int main(){
	scanf("%d",&n);
	res=(n-1)>>1;
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 256
st = gets.chomp.split("")
st2 = gets.chomp.split("")

st3 = st.length
i = 0

st3.times do
  if st[i] != st2[i]
    puts "No"
    exit
  end
  i += 1
end

if (st3 + 1) != st2.length
  puts "No"
  exit
end

puts "Yes"


Measured memory_bytes: 14380
n=int(input())
h=list(map(int,input().split()))
ans=0
for i in range(n):
  l=len(h)
  if(l==1):
    ans+=h[0]
  else:
    m=max(h)
    a=h.index(m)
    if(a==0):
      ans+=h[0]-h[1]
      h=h[1:]
    elif(a==l-1):
      ans+=h[l-1]-h[l-2]
      h=h[:l-1]
    else:
      ans+=h[a]-(max(h[a-1],h[a+1]))
      h=h[:a]+h[a+1:]
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long                                    // long long省略
#define pb push_back                                    // push_back省略
#define mp make_pair                                    // make_pair省略
#define fi first                                        // first省略
#define se second                                       // second省略
#define itn int                                         // int誤字保険
#define count cout                                      // cout誤字保険
#define vecotr vector                                   // vector誤字保険
#define ednl endl                                       // endl誤字保険
#define opt() cin.tie(0); ios::sync_with_stdio(false)   // 入出力速度改善

#define rep(i,l,r) for(ll i=(l);i<(r);i++)               // 範囲[l, r)で刻み1のfor文(順方向)
#define repp(i,l,r,k) for(ll i=(l);i<(r);i+=(k))         // 範囲[l, r)で刻みkのfor文(順方向)
#define rrep(i,l,r) for(ll i=(r-1);i>=(l);i--)           // 範囲[l, r)で刻み1のfor文(逆方向)
#define rrepp(i,l,r,k) for(ll i=(r-1);i>=(l);i-=(k))     // 範囲[l, r)で刻みkのfor文(逆方向)
#define all(x) (x).begin(), (x).end()                   // vectorのポインタ位置指定用
#define max(p,q)((p)>(q)?(p):(q))                       // max拡張
#define min(p,q)((p)<(q)?(p):(q))                       // min拡張
#define bit(n,m)(((n)>>(m))&1)                          // 変数nのm番目のbitを取り出す

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

int dy[]={0, 1, 0, -1};                                 // 4方向近傍
int dx[]={1, 0, -1, 0};                                 // 4方向近傍

int main(){
    ll a,b,c,d;cin>>a>>b>>c>>d;
    cout << 24 + (24-a) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>


int main(void)
{
    int k=0;
    char c,pre='0';
    while(1)
    {
        c=getchar();
        if(c=='\n'||c==EOF||c=='\0') break;
        if(c!=pre)
        {
            k++;
            pre=c;
        }
        else
        {
            pre='0';
            c=getchar();
            if(c=='\n'||c==EOF||c=='\0') break;
            k++;
        }
    }
    printf("%d",k);
    return 0;
}




Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
    string s, t;
    cin >> s >> t;
    string res;
    for (int i = 0; i < s.size(); i++) {
        res.push_back(s[i]);
        if (i < t.size()) {
            res.push_back(t[i]);
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 3628
#include<iostream>

using namespace std;

int main(){

    int h, w;
    int i, j;

    while(1){

        cin >> h >> w;

        if(h == 0 && w == 0){
            break;
        }else{
            for(i=1;i<=h;i++){
                for(j=1;j<=w;j++){
                    if((i + j) % 2 == 0){
                        cout << "#";
                    }else{
                        cout << ".";
                    }
                }
                cout << endl;
            }
            cout << endl;
        }
    }
    
    return 0;

}


Measured memory_bytes: 3084
import collections
polls = collections.Counter()

N = int(input())
for n in range(N):
    polls[input()] += 1

flag = True
top = polls.most_common()[0][1]
ans = [polls.most_common()[0][0]]
for p in polls.most_common()[1:]:
    if(p[1] != top):
        break
    ans.append(p[0])
ans.sort()
for a in ans:
    print(a)

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

int main()
{
    string s,t;
    int a=97;
    bool chk=false;
    cin >> s >> t;
    vector<int> cks(26),ckt(26);
    for(int i=0;i<s.size();i++){
        cks.at(s.at(i)-97)++;
        ckt.at(t.at(i)-97)++;
    }
    sort(cks.begin(),cks.end());
    sort(ckt.begin(),ckt.end());
    for(int i=0;i<26;i++) if(cks.at(i)!=ckt.at(i)) chk=true;
    if(chk){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 776
n = int(input())
S = ["".join(sorted(input())) for _ in range(n)]
counters = {}

for s in S:
    if s in counters:
        counters[s] += 1
    else:
        counters[s] = 1

ans = 0
for v in counters.values():
    if v == 1: continue
    ans += int(v * (v - 1) / 2)
print(ans)

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

int main()
{
    int n, k;
    cin >> n >> k;
    int a[n];
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    sort(a, a + n);
    int sum = 0;
    for (int i = 0; i < k; i++)
    {
        sum += a[i];
    }
    cout << sum;
}

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

int main()
{
    int n;
    cin>>n;
    int a[n],x=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]!=i+1)
        {
            x++;
        }
    }
    if(x==0 || x==2)
        cout<<"YES";
    else cout<<"NO";
}


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

using namespace std;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using cd = complex<ld>;

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

  int w, h;
  cin >> w >> h;
  ll res = 0;
  vector<ll> a(w), b(h);
  for (ll &x : a) {
    cin >> x;
  }
  for (ll &x : b) {
    cin >> x;
  }
  sort(a.begin(), a.end());
  vector<ll> pref(w);
  for (int i = 0; i < a.size(); i++) {
    pref[i] = a[i];
    if (i > 0) {
      pref[i] += pref[i - 1];
    }
  }
  for (int i = 0; i < h; i++) {
    int l = -1, r = w;
    while (r - l > 1) {
      int m = (l + r) / 2;
      if (a[m] <= b[i]) {
        l = m;
      } else {
        r = m;
      }
    }
    if (l >= 0) {
      res += pref[l];
    }
    res += b[i] * (w - l);
  }
  res += pref.back();
  cout << res;
  return 0;
}

Measured memory_bytes: 5572
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<n;++i)

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 17;

double a[MAX_N][MAX_N];
double dp[1 << MAX_N][MAX_N];
int m,n;

int main()
{
	scanf("%d%d",&m,&n);
    rep(i,m){
        rep(j,n){
    		scanf("%lf",&a[i][j]);
    	}
    }
    for(int i = (1 << m) - 1; i >= 0; i--){
        for(int j = n-1; j >= 0; j--){
            double mx = 0;
            rep(k,m){
                if(!(i & (1 << k))){
                    double p = 1,res = 0;
                    for(int l = j; l < n; l++){
                        res += p * (1.0 - a[k][l]) * dp[i | (1 << k)][l];
                        p *= a[k][l];
                    }
                    res += p;
                    mx = max(res,mx);
                }
            }
            dp[i][j] = mx;
        }
    }
    printf("%.12lf\n",dp[0][0]);
	return 0;
}

Measured memory_bytes: 11936
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << endl;
#else
	#define DBG(X)
	#define endl '\n'
#endif
 
using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld  = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const ll mod = 1e9 + 7;
const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }

const int MAX_N = (int)1e5 + 77;

ll a[MAX_N], n;

inline ll compute(ll x)
{
	for(int i = 0; i < n; ++i)
		x -= x % a[i];

	return x;
}

void solve()
{
	cin >> n;

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

	if(compute(LL_INF) < 2)
	{
		cout << NIL << endl;
		return;
	}

	ll L = 0, R = LL_INF;

	while(R - L > 1)
	{
		ll M = (L + R) / 2;

		if(compute(M) >= 2)
			R = M;
		else
			L = M;
	}

	if(compute(R) != 2)
	{
		cout << NIL << endl;
		return;
	}

	cout << R << " ";

	L = 0;
	R = LL_INF;

	while(R - L > 1)
	{
		ll M = (L + R) / 2;

		if(compute(M) > 2)
			R = M;
		else
			L = M;
	}

	cout << R - 1 << endl;
}

int main()
{
	fast_io();
	solve();

	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const double PI = 3.1415926535897932;
const int MOD = 1e9 + 7;

int N, K;
map<int, int> D;
set<int> price;

void dfs(string total) {
  if (total.size() == 6) return;
  
  price.insert(atoi(total.c_str()));

  for (auto v : D) {
    if (v.second) {
      dfs(total + to_string(v.first));
    }
  }
  
}

//cin.tie(0);ios::sync_with_stdio(false);
int main() {
  cin >> N >> K;
  for (int i = 0; i <= 9; i++) D[i] = 1;
  rep (i, K) {
    int x;
    cin >> x;
    D[x] = 0;
  }

  dfs("");

  for (auto v : price) {
    if (v >= N) {
      cout << v << endl;
      return 0;
    }
  }

  
  return 0;
}


Measured memory_bytes: 6780
n,k = gets.strip.split.map(&:to_i)
array = []
while number = gets
  array << number.chomp.to_i
end
ary = array.sort
h = ary.max
i = 0
while i<=n-k do
  if h > ary[i+k-1]-ary[i]
    h = ary[i+k-1]-ary[i]
  end
  i += 1
end
puts h

Measured memory_bytes: 16744
S, T = input(), input()
cnt1, cnt2, r1, r2 =[], [], [], []
for c in S:
    if not c in r1:
        cnt1.append(S.count(c))
        r1.append(c)
for c in T:
    if not c in r2:
        cnt2.append(T.count(c))
        r2.append(c)
#cnt1.sort()
#cnt2.sort()
if cnt1 == cnt2:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3632
#include<stdio.h>
void check(int n,int y,int num[3])
{
    for(int i=0;i<=(y/10000);i++)
    {   
        if(((y-9000*i-1000*n)%4000)==0)
        {
            num[0] = i;
            num[1] = (y-9000*i-1000*n)/4000;
            num[2] = n - num[0] -num[1];
            if(num[2]<0||num[1]<0)
            {
                num[0] = -1;
                num[1] = -1;
                num[2] = -1;
            }
            else
            {
                break;
            }
        }
    }
}
int main(void)
{
    int n,y;
    int num[3] = {-1,-1,-1};
    scanf("%d%d",&n,&y);
    check(n,y,num);
    printf("%d %d %d",num[0],num[1],num[2]);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
/*
)
(()

1 0
0 1

)(
()

1 1
0 0 うちけしあったときに1 1でNG

4
((()))
((((((
))))))
()()()
0 0
0 6
6 0
0 0

3
(((
)
)
0 3
1 0
1 0

)(
)(
1 1
1 1 )()(でNG

どれかは0が必要か

3
(
)
))((

0 1
1 0
2 2

01
10
22

01
22 21
10 11


01 02 03 
6
10 20 20
5
HP6と HP5みたいな

01 = -1
10 = +1
12 = -1
16 = -5
21
21
...

0のやつだけHP管理。
それ以外は差分を入れる

01を先頭に、10を最後尾にする。

3
))    20
)()(( 12
(     01


01
12
20
*/

int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  
  ll N; cin >> N;
  ll zL=0, zR=0, zLR=0, L=0, R=0;
  vector<tuple<ll, ll, ll>> A;
  rep(i, N){
    string S; cin>>S;
    ll j=0, tmp=0, q=0, p=0;
    while (S[j]){
      if (S[j] == ')'){//qpで管理
        tmp--;
        chmin(q,tmp);
      }
      else
        tmp++;
      j++;
    }
    j--;
    tmp = 0;
    while (j>=0){
      if (S[j] == '('){
        tmp--;
        chmin(p, tmp);
      }
      else
        tmp++;
     j--;
    }
//cout<<"q:"<<q<<" p:"<<p<<" i:"<<i<<endl;    
    if (q==0 && p==0)
      zLR++;
    else if (q==0){
      zR++;
      R -= p;
    }
    else if (p==0){
      zL++;
      L -= q;
    }
    else{
      ll tmp = -(p-q);
      p = -p;
      q = -q;
      A.emplace_back(tmp, q, p);// ( = +1
    }
  }
  if (N==1 && zLR == 1){
    cout << "Yes" << endl;
    return 0;
  }
  bool ans = true;
  if (zL==0 && zR==0 && zLR < 2)
    ans = false;
  if ((zL==0 || zR==0) && zLR == 0)
    ans = false;
  sort(all(A));
  reverse(all(A));
  ll asz = A.size();
  //Rが(((　　Lが))))の数
  //差分を、p-qでとっているので、+だと ( 優位
//cout <<"startR:"<<R<<" L:"<<L<<endl;    
  rep(i, asz){
    R -= get<1>(A[i]);
//cout<<"i:"<<i<<" R:"<<R<<endl;
    if (R < 0){
      ans = false;
      break;
    }
    R += get<2>(A[i]);
  }
//cout <<"lastR:"<<R<<" L:"<<L<<endl;    
  R -= L;
  if (R != 0)
    ans = false;
  if (ans)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 9496
#include<stdio.h>
int main(){
  while(1){
    int a,b,ans;
    char c;
    scanf("%d %c %d", &a, &c, &b);
    if ( c == '?') break;
    if ( c == '+'){
      ans=a+b;
    }
    if (c == '-'){
      ans=a-b;
    }
    if (c == '*'){
      ans=a*b;
    }
    if (c == '/'){
      ans=a/b;
    }
    printf("%d\n", ans);
  }
    return 0;
  }



Measured memory_bytes: 2140
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>

using namespace std;


int main(){
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for(int i = 0; i < n; ++i){
    cin >> a[i];
  }
  cout << (n - 1 + k - 2) / (k - 1) << endl;

}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';


using namespace std;

int main(void){
    ll N;
    cin>>N;
    if(N%10==7 || (N/10)%10==7 || (N/100)%10==7)
        cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3632
s = input()

maxlen = 0

dna = ['A','C','G','T']

for i in range(len(s)):
  l = 0
  for j in range(i,len(s)):
    if s[j] in dna:
      l+=1
    else:
      break
  maxlen = max(maxlen,l)
print(maxlen)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define sz(a) ll((a).size())
#define all(a) (a).begin(), (a).end()
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPD(i,n) for(int i=(n)-1;i>=0;--i)
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define FORD(i,a,b) for(int i=(a);i>=(b);--i)
const ll MOD = 1E9+7;
const ll INF = 1E18;
const double EPS = 1E-9;
const double PI = atan(1.0) * 4.0;
template<class T> T getbit(T s, int i) {return s>>i&1;}
template<class T> void flipbit(T& s, int i) {s^=(1LL<<i);}
constexpr int cntbit(ll x) {return __builtin_popcountll(x);}
constexpr int lg2(ll x) {return __lg(x);} // return int(log2(x))
// mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count()); 
ll fpow(ll a,ll p){ll res=1LL;while(p){if(p&1LL) res=res*a%MOD;a=a*a%MOD;p>>=1LL;} return res;}

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	char a,b,c,d;
	cin>>a>>b>>c>>d;
	int n=(a-48)*10+b-48;
	int m=(c-48)*10+d-48;
	if((!n&&!m)||(n==0&&m>12)||(m==0&&n>12)||(n>12&&m>12)) exit(puts("NA\n")*0);
	if(0<n&&n<=12&&0<m&&m<=12) exit(puts("AMBIGUOUS\n")*0);
	if(!n||n>12) exit(puts("YYMM\n")*0);
	else exit(puts("MMYY\n")*0);
}



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

using namespace std;

#define  N 222

const double PI = 3.14159265359;
typedef long long ll;

void solve() {
    int a, b;
    cin >> a >> b;
    cout << 1ll *a * b / __gcd(a,b) << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifdef qwerty
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif


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

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    int l,r,d;
    cin >> l >> r >> d;
    int ans = 0;
    for (size_t i = l; i <= r; i++)
    {
        if(i%d == 0) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3672
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[4] = {-1, 0, 1, 0};
ll dy[4] = {0, 1, 0, -1};

int main(void){
    ll s;
    cin >> s;
    ll a = s/1000, b = s/100-a*10, c = s/10-a*100-b*10, d = s%10;
    if(a+b+c+d==7)
        cout << a << '+' << b << '+' << c << '+' << d << "=7";
    else if(a+b+c-d==7)
        cout << a << '+' << b << '+' << c << '-' << d << "=7";
    else if(a+b-c+d==7)
        cout << a << '+' << b << '-' << c << '+' << d << "=7";
    else if(a+b-c-d==7)
        cout << a << '+' << b << '-' << c << '-' << d << "=7";
    else if(a-b+c+d==7)
        cout << a << '-' << b << '+' << c << '+' << d << "=7";
    else if(a-b+c-d==7)
        cout << a << '-' << b << '+' << c << '-' << d << "=7";
    else if(a-b-c+d==7)
        cout << a << '-' << b << '-' << c << '+' << d << "=7";
    else if(a-b-c-d==7)
        cout << a << '-' << b << '-' << c << '-' << d << "=7";
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;

void solve(){
    ll n;
    cin >> n;
    bool b[n+10][n+10];
    vector<ll> v[n+10];
    //v[i]:頂点iから辺が伸びている頂点の集合
    rep(i,n){
        string s;
        cin >> s;
        rep(j,n){
            if(s[j]=='1') {
                b[i][j]=true;
                v[i].emplace_back(j);
            }
            else b[i][j]=false;
        }
    }
    /*
    rep(j,n){
        for(auto i:v[j]){
            cout << i << " ";
        }
        cout << endl;
    }
    */
    
    ll ans = -1;
    rep(i,n){
        ll d[n+10];
        bool visited[n+10];
        fill(d,d+n+10,0);
        fill(visited,visited+n+10,false);
        visited[i]=true;
        queue<ll> st;
        st.push(i);
        while(!st.empty()){
            ll tmp = st.front();
            st.pop();
            for(auto j:v[tmp]){
                if(!visited[j]){
                    d[j]=d[tmp]+1;
                    visited[j]=true;
                    st.push(j);
                }
            }
        }
        bool ok=true;
        rep(j,n){
            rep(k,n){
                if(b[j][k]){
                    //cout << "i,j:" << i << " " << j << ", d[i],d[j]:" << d[i] << " " << d[j] << endl;
                    if(d[j]==d[k]) ok=false;
                }
            }
        }
        ll m = 0;
        rep(j,n){
            //cout << "d[" << j << "]:" << d[j] << endl;
            m = max(m,d[j]);
        }
        if(ok) ans = max(ans, m+1);
    }

    cout << ans << endl;
    
}

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

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

int main() {
    const int MAX = 1000000;
    bool isPrime[MAX];
    fill_n(isPrime, MAX, true);
    for (int i = 4; i < MAX; i += 2) {
        isPrime[i] = false;
    }
    for (int i = 3; i * i <= MAX; i += 2) {
        if (isPrime[i]) {
            for (int j = 2 * i; j < MAX; j += i) {
                isPrime[j] = false;
            }
        }
    }
    int n;
    while (cin >> n) {
        int count = 0;
        for (int i = 2; i <= n; i++) {
            count += isPrime[i];
        }
        cout << count << endl;
    }
}

Measured memory_bytes: 0
k()=readline()|>chomp
s()=[parse(Int,x)for x=k()|>split]
n,q=s()
t=k()
a=zeros(Int,n)
c=0
for i=1:n-1
if t[i]=='A' && t[i+1]=='C'
c+=1
end
a[i+1]=c
end
for i=1:q
l,r=s()
println(a[r] - a[l])
end

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

int main(){
    string step;
    cin >> step;
    
    char negative;
    for(int i = 0; i < (int)step.size(); i++){
        negative = i%2 == 1 ? 'R' : 'L';
        if(step[i] == negative){
            cout << "No";
            return 0;
        } 
    }
    cout << "Yes";
    return 0;
}


Measured memory_bytes: 256
def num_4x_list():
    # 100以下の4の倍数をつくる
    return [4 * i for i in range(1, (100 // 4) + 1)]


def num_list_comb_4_7():
    # 4 と 7 の和の組み合わせで表現できる数を列挙する(最大は100)
    diff = 7 - 4  # ドーナツとケーキの差分が公差になる

    x = set()

    for i, num_4x in enumerate(num_4x_list(), start=1):
        for j in range(i + 1):
            element = num_4x + diff * j
            x |= {element}

    return {y for y in x if y <= 100}


def actual(N):
    if N in num_list_comb_4_7():
        return 'Yes'

    return 'No'

  
  
N = int(input())

print(actual(N))

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>



int main() {
	int n; std::cin >> n;
	std::vector<int> button(n); for (auto& a : button) std::cin >> a;
	int current = 0;
	int count = 0;
	while (button[current] >= 0 && current != 1) {
		auto next = button[current] - 1;
		button[current] = -1;
		current = next;
		++count;
	}
	if (current == 1) {
		std::cout << count << std::endl;
	}
	else {
		std::cout << -1 << std::endl;
	}
}

Measured memory_bytes: 640
#include<iostream>

typedef long long int ll;

using namespace std;

// 最大公約数
ll GCD(ll a, ll b){
    if(a < b) swap(a, b);
    // a > b
    ll r = a % b;
    while(r != 0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

// 最小公倍数
ll LCM(ll a, ll b){
    return a*b/GCD(a, b);
}

ll calc(ll a, ll b, ll c){
    return a-(a/b+a/c-a/LCM(b,c));
}

int main(void){

    ll A, B, C, D;

    cin >> A >> B >> C >> D;

    cout << calc(B, C, D) - calc(A-1, C, D) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define   sz(s)         s.size()
#define   ll            long long int
#define   ull           unsigned ll
#define   ld            long double
#define   print(v)      for(ll i=0;i<v.size();i++)cout<<v[i]<<" "
#define   printpair(v)  for(ll i=0;i<v.size();i++)cout<<v[i].first<<" "<<v[i].second<<"\n"
#define   bmd           1000000007
#define   bmd1          998244353
#define   umll          unordered_map<ll,ll>
#define   mll           map<ll,ll>
#define   mcl           map<char,ll>
#define   pll           pair<ll,ll>
#define   F             first
#define   S             second
#define   setp(x)       setprecision(x)
#define   pb            push_back
#define   all(v)        v.begin(),v.end()
#define   tr(a)         for(auto it=a.begin();it!=a.end();it++)
#define   trr(a)        for(auto it1=a.begin();it1!=a.end();it1++)
#define   vll           vector<long long int>
#define   sorty(v)      sort(v.begin(),v.end())
#define   rsort(v)      sort(v.rbegin(),v.rend())
#define   unik(v)       v.erase(unique(all(v)),v.end())
#define   PI            3.1415926535897932384626
#define   db()          cout<<"\n"<<"here"<<"\n"
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;


//---------------------------------------------------------------------------
const int MOD = bmd;
const int N=2e5+100;
inline  ll sqr(ll x){return x*x;}
inline  void normal(ll &a) { a = (a+MOD)%MOD; }
inline  ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline  ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline  ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline  ll modPow(ll b, ll p) { ll r = 1;b=b%MOD; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline  ll modInv(ll a) { return modPow(a, MOD-2); }
inline  ll modDiv(ll a,ll b) { return modMul(a, modInv(b)); }
//---------------------------------------------------------------------------
void solve()
{
    string s;
    cin>>s;
    ll sum = 0;
    for(auto x:s){
        sum+=(x-'0');
    }
    if(sum%9){
        cout <<"No"<<"\n";
    }
    else cout <<"Yes"<<"\n";
}
int main()
{
    //ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);//first give all input then gives output
    ll t=1;
    //cin>>t;
    while(t--){
        solve();
    }

    return 0;
}


Measured memory_bytes: 3716
#include <stdio.h>

#define max(a, b) (((a) > (b)) ? (a) : (b))

int main(void) {
    int i, j, k;
    int n,a;
    int sum[101] = {0}, tmp[101][101] = {0}, max;

    scanf("%d", &n);

    max = -10000;
    for (i = 0; i < n; i++) {
        for (j = 1; j <= n; j++) {
            scanf("%d", &a);
            sum[j] = sum[j - 1] + a;
        }

        for (j = 1; j <= n; j++)
            for (k = j; k <= n; k++) {
                tmp[j][k] = max(tmp[j][k] + sum[k] - sum[j - 1], sum[k] - sum[j - 1]);
                max = max(max, tmp[j][k]);
            }
    }

    printf("%d\n", max);

    return 0;
}

Measured memory_bytes: 648
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int total = a+b+c;
        if(total >=22) System.out.println("bust");
        else System.out.println("win");
    }
}


Measured memory_bytes: 35496
# -*- Coding: utf-8 -*-

a,b,k = map(int, input().split())

if k >= (a+b):
    print('{0} {1}'.format(0,0))
elif k < a:
    print('{0} {1}'.format(a-k, b))
elif k >= a:
    print('{0} {1}'.format(0, b-(k-a)))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
typedef long long ll;
typedef pair<int, int> P;
 
int main(){
  int n;
  cin >> n;
  vector<string> s(n);
  rep(i, n) cin >> s[i];

  list<string> ls;
  rep(i, n)  ls.push_back(s[i]);
  ls.sort();
  ls.unique();

  cout << ls.size() << endl;
  return 0;
}

Measured memory_bytes: 22000
#include <stdio.h>
#include <vector>
#include <stack>
using namespace std;
int main(){
    int n,m,x,y;
    bool went[100],f;
    vector<int> a[100];
    stack<int>ans;
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++)went[i]=false;
    for(int i=0;i<m;i++){
        scanf("%d%d",&x,&y);
        a[x].push_back(y);
    }
    for(int i=0;i<n;i++){
        f=true;
        for(int j=1;j<=n&&f;j++){
            if(a[j].size()==0&&!went[j]){
                ans.push(j);
                went[j]=true;
                for(int k=1;k<=n;k++){
                    f=true;
                    for(int c=0;c<a[k].size()&&f;c++){
                        if(a[k][c]==j){
                            a[k][c]=a[k][a[k].size()-1];
                            a[k].pop_back();
                            f=false;
                        }
                    }
                }
                f=false;
            }
        }
    }
    while(!ans.empty()){
        printf("%d\n",ans.top());
        ans.pop();
    }
}

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

int main() {
   int N, K, x;
   x = 1;
   cin >> N >> K;
   /*int i=0;
   while (2*x < x+K){
        if (i>=N) {break;}
   		x*=2;
        i++;
   }
   for (int j=0; j<N-i; j++){
     	x+=K;
   }
   cout << x << endl; */
  for (int i=0; i<N; i++){
  	  if (2*x < x+K){x*=2;}
      else {x+=K;}
  }
  cout << x << endl;
}


Measured memory_bytes: 3632
import java.util.*
fun main(args: Array<String>) {

    val sc = Scanner(System.`in`)
    val a = sc.nextInt()
    val b = sc.nextInt()
    val c = sc.nextInt()
    val d = sc.nextInt()
    val e = sc.nextInt()
    val k = sc.nextInt()
    //val (N,K) = readLine()!!.split(" ").map{it.toInt()}
    //for (i in  0 until N) {
    //}
    if (e-a  <= k)
    println("Yay!")
    else
    println(":(")
}


Measured memory_bytes: 29472
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <iomanip>

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

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

signed main(){
    vector<int> a(3);
    cin >> a[0] >> a[1] >> a[2];
    sort(a.begin(), a.end());

    int ans = 0;
    ans += (a[1] - a[0]) / 2;

    if((a[1] - a[0]) % 2 == 1){
        ans += a[2] - a[1] + 2;
    }else{
        ans += a[2] - a[1];
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 888
H, W, A, B = map(int, input().split())
MAX = 200000
MOD = 1000000007
fac = [0]*MAX
finv = [0]*MAX
inv = [0]*MAX
fac[0] = 1
fac[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
for i in range(2, MAX):
  fac[i] = fac[i-1]*i%MOD
  inv[i] = MOD - inv[MOD%i]*(MOD//i)%MOD
  finv[i] = finv[i-1]*inv[i]%MOD  
# sum_{i=B}^{W-1} C_{H-A-1+i}_{i}C_{A+W-i-2}_{A-1}
r = 0
for i in range(B, W):
  r += fac[H-A-1+i]*(finv[H-A-1]*finv[i]%MOD)%MOD * fac[A+W-i-2]*(finv[A-1]*finv[W-1-i]%MOD)%MOD
  r = r%MOD
print(r)


Measured memory_bytes: 26740
def insertionSort(a,n):
    for i in range(1,n):
        for k in range(n):
            print(a[k],end='')
            if k==n-1:
                print()
            else:
                print(' ',end='')

        v=a[i]
        j=i-1
        while j>=0 and a[j]>v:
            a[j+1]=a[j]
            a[j]=v
            j-=1
    for k in range(n):
        print(a[k],end='')
        if k==n-1:
            print()
        else:
            print(' ',end='')

n=int(input())
r=input()
data=r.split(' ')
for i in range(n):
    data[i]=int(data[i])
insertionSort(data,n)


Measured memory_bytes: 6316
a=list(input())
b=list(input())
c=list(input())

a.append('A')
b.append('B')
c.append('C')

def f(s):
  if len(s)>1:
    va=s[0]
    del s[0]
    if va=='a':
      f(a)
    elif va=='b':
      f(b)
    else:
      f(c)
  else:
    return print(s[0])
f(a)

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

int main(){
    string s;
    cin >> s;
    s = "A" + s;
    int cnt = 0;
    for(int i = 1; i < s.length(); i++){
        if(s[i-1] >= s[i])  cnt++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3208
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n;
vvi a;

int main(){
	cin>>n;
	a=vvi(3,vi(n));
	int res=0;
	for(int i=0;i<3;i++){
		int m;
		cin>>m;
		for(int j=0;j<m;j++){
			int x;
			cin>>x;
			a[i][x-1]++;
		}
		if(i==2) res+=m;
	}
	for(int i=0;i<n;i++) if(a[0][i]&&a[1][i]&&a[2][i]) res++;
	for(int i=0;i<n;i++) if(a[0][i]&&a[2][i]) res--;
	cout<<res<<endl;
}


Measured memory_bytes: 3156
#include <algorithm>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  string S, T; cin >> S >> T;
  std::map<char, char> m;
  for (int i = 0; i < 26; ++i) {
    char c = i + 'a';
    m[c] = c;
  }
  m['?'] = 'a';

  int SL = S.size();
  int TL = T.size();

  for (int i = SL - TL; i >= 0; --i) {
    string ss = S.substr(i, TL);
    bool ok = true;
    for (int j = 0; j < TL; ++j) {
      if (ss[j] != '?' && ss[j] != T[j]) {
        ok = false;
        break;
      }
    }

    if (ok) {
      for (int j = 0; j < i; ++j) cout << m[S[j]];
      cout << T;
      for (int j = i + TL; j < SL; ++j) cout << m[S[j]];
      cout << endl;
      return 0;
    }
  }

  cout << "UNRESTORABLE" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int main(void){
    int n;
    cin >> n;
    int sum = 0;
    for(int i = 0; i < n; i++){
        int l,r; cin >> l >> r;
        sum += r - l + 1;
    }
    cout << sum << endl;
}


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

const int MAX_P = 1001000;
const int MAX_W = 1020;
const int dx[4] = {+1,  0, -1,  0};
const int dy[4] = { 0, -1,  0, +1};

// is_p[n] := 正整数 n が素数かどうか
char is_p[MAX_P];
// a[y][x] := (x,y) の洞穴の番号
int a[MAX_W][MAX_W] = {0};
// dp[y][x] := (x,y) にたどり着くまでの素数洞穴を調べた個数
int dp[MAX_W][MAX_W];
// X[k] := 洞穴の番号 k の x 座標 (Yも同様)
int X[MAX_P];
int Y[MAX_P];

void init(){
	// エラトステネスの篩
	fill(is_p, is_p + MAX_P, 1);
	is_p[0] = is_p[1] = 0;
	for(int i = 2; i < MAX_P; i++){
		if( is_p[i] ){
			for(int j = i + i; j < MAX_P; j += i){
				is_p[j] = 0;
			}
		}
	}
}

void make_douketu(int m){
	for(int y = 0; y < MAX_W; y++){
		for(int x = 0; x < MAX_W; x++){
			a[y][x] = 0;
		}
	}
	int k = 1, x = MAX_W / 2, y = MAX_W / 2, dir = 0, d = 2;
	while( k < MAX_P ){
		for(int i = 0; i < (d / 2); i++){
			a[y][x] = k;
			X[k] = x;
			Y[k] = y;
			x += dx[dir];
			y += dy[dir];
			k++;
			if( m < k ) return;
			if( MAX_W <= x || MAX_W <= y ) break;
		}
		dir = (dir + 1) % 4;
		d++;
		if( MAX_W <= x || MAX_W <= y ) break;
	}
}

int main(){
	init();
	int n, m;
	while( cin >> m >> n, n || m){
		make_douketu(m);
		for(int y = 0; y < MAX_W; y++){
			for(int x = 0; x < MAX_W; x++){
				dp[y][x] = -1;
			}
		}
		int sx = X[n], sy = Y[n];
		dp[sy][sx] = is_p[n];
		
		int ans = 0;
		for(int y = 0; y < MAX_W; y++){
			for(int x = 0; x < MAX_W; x++){
				ans = max(ans, dp[y][x]);
				if( a[y][x] == 0 ) continue;
				
				if( dp[y][x] != -1 ){
					int my = y + 1;
					if( MAX_W <= my ) continue;
					
					int d[3] = {-1,0,1};
					for(int i = 0; i < 3; i++){
						int mx = x + d[i];
						if( mx < 0 || MAX_W <= mx ) continue;
						
						int k = a[my][mx];
						if( k == 0 ) continue;
						dp[my][mx] = max(dp[my][mx], dp[y][x] + is_p[k]);
						ans = max(ans, dp[my][mx]);
					}
				}
			}
		}
		
		if( ans == 0 ){
			cout << "0 0" << endl;
			continue;
		}
		int ans_n = 0;
		for(int y = 0; y < MAX_W; y++){
			for(int x = 0; x < MAX_W; x++){
				if( a[y][x] == 0 ) continue;
				if( dp[y][x] == ans ){
					int k = a[y][x];
					if( is_p[k] ){
						ans_n = max(ans_n, a[y][x]);
					}
				}
			}
		}
		cout << ans << " " << ans_n << endl;
	}
}

Measured memory_bytes: 18092
#!/usr/bin/perl
#= CPAN mocules =====================================================#
use strict;				# strictモード
use warnings;			# 警告有効

#= Global values ====================================================#
my ($H, $W);
my @g_field;
my @g_searchedField;
my @g_chkedField;
my @g_chkDetCnt;

#= Local routines ===================================================#
# 1ならチェック済み、0なら未チェック
sub isChked{
	my $i = shift;
	my $j = shift;

	if (($i < 0) || ($H <= $i)){
		return 1;
	}
	if (($j < 0) || ($W <= $j)){
		return 1;
	}
	if ($g_chkedField[$i]){
		return $g_chkedField[$i]->[$j];
	};
	if ($g_searchedField[$i]){
		return $g_searchedField[$i]->[$j];
	};
	
	return 0;
}
my @tbl = (
	# 方向、次回の方向、i側加算、j側加算
	[0x8, 0xD, -1,  0],	# 上
	[0x4, 0xE,  0,  1],	# 右
	[0x2, 0x7,  1,  0],	# 下
	[0x1, 0xB,  0, -1],	# 左
);

sub nextChk{
	my $i = shift;
	my $j = shift;
	my $expMark = shift;
	my $moveList = shift;

	my $mark = $g_field[$i]->[$j];
	if ($expMark eq $mark){
		if ($expMark eq "."){
			# ここで条件合致
			$g_chkDetCnt[1]++;
		}else{
			$g_chkDetCnt[0]++;
		}

		$g_chkedField[$i]->[$j] = 1;
		$g_searchedField[$i]->[$j] = 1;

		my $nextMark = ($mark eq ".")? "#" : "." ;
		foreach (@tbl){
			if ($moveList & $_->[0]){
				if (!isChked($i + $_->[2], $j + $_->[3])){
					nextChk($i + $_->[2], $j + $_->[3], $nextMark, $_->[1]);
				}
			}
		}
	}


}

sub main(){
	my $in = <>;chomp $in;
	($H, $W) = split(/ /, $in);

	foreach (1..$H){
		$in = <>; chomp $in;
		$g_field[$_ - 1] = [split(//, $in)];
	}

	my $detCnt = 0;
	@g_searchedField = ();

	foreach my $i (1..$H){
		foreach my $j (1..$W){
			my $nextMark = $g_field[$i-1]->[$j-1];
			if ($nextMark eq "#"){
				@g_chkDetCnt = (0, 0);
				@g_chkedField = ();
				if (!isChked($i - 1, $j - 1)){
					nextChk($i - 1, $j - 1, $nextMark, 0xF);
					$detCnt += $g_chkDetCnt[0] * $g_chkDetCnt[1];
				}
			}
		}
	}

	print $detCnt, "\n";

	return 0;
}

#----- 実行 -----#
exit( main() );




Measured memory_bytes: 303104
while True:
    n, x = map(int, input().split())

    if(n == 0 and x == 0):
        break

    ot = 0
    for i in range(1, n + 1):
        for j in range(i + 1, n + 1):
            for k in range(j + 1, n + 1):
                if i + j + k == x:
                    ot += 1

    print(ot)



Measured memory_bytes: 5596