akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

int pair(int a, int b, int c, int d, int e)
{
     int card[14] = {0};
     int i, t, u=0;
     
     t = a;
     card[t] = card[t] + 1;
     
     t = b;
     card[t] = card[t] + 1;
     
     t = c;
     card[t] = card[t] + 1;
     
     t = d;
     card[t] = card[t] + 1;
     
     t = e;
     card[t] = card[t] + 1;
     
     t = 0;
     for(i=0; i<14; i++){
	  if(card[i]==2) t = t + 1;
	  if(card[i]==3) u = 1;
	  if(card[i]==4) t = 6;
     }
     
     if(t==1 && u==1) return 5;
     if(t!=0 && t<=6) return t;
     if(u==1) return 3;
     else return 0;
}

int compare_int(const void *a, const void *b)
{
     return *(int*)a - *(int*)b;
}

int straight(int a, int b, int c, int d, int e)
{
     int num[] = {a, b, c, d, e};
     int v, w, x, y, z;
     
     qsort(num, 5, sizeof(int), compare_int);
     
     v = num[0];
     w = num[1];
     x = num[2];
     y = num[3];
     z = num[4];
	  
     if(w==v+1){
	  if(x==w+1){
	       if(y==x+1){
		    if(z==y+1) return 4;
	       }
	  }
     }
     
     if(v==1 && w==10 && x==11 && y==12 && z==13) return 4;

     return 0;
}

int main(void)
{
     int a, b, c, d, e, op;

     while(0<1){
	  if(scanf("%d,%d,%d,%d,%d", &a, &b, &c, &d, &e)==-1) break;

	  op = pair(a, b, c, d, e);
	  
	  if(op==0) op = straight(a, b, c, d, e);	  
	  
	  switch(op){
	  case 1: printf("one pair\n"); break;
	  case 2: printf("two pair\n"); break;
	  case 3: printf("three card\n"); break;
	  case 4: printf("straight\n"); break;
	  case 5: printf("full house\n"); break;
	  case 6: printf("four card\n"); break;
	  default: printf("null\n"); break;
	  }
	  
     }

     return 0;
}

Measured memory_bytes: 584
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;

int main(){
	int l, r, ans = 2020;
	cin >> l >> r;
	if (r - l > 2019){
		cout << 0 << endl;
	}else{
		for (int i = l; i < r; i++){
			for (int j = i+1; j <= r; j++){
				ans = min(ans, ((i%2019)*(j%2019))%2019);
			}
		}
		cout << ans << endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include<vector>
#include <algorithm>
#include<cstdlib>
#include<set>
#include<math.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(ll i=0;i<n;i++)



int main()
{
	int k, n;
	cin >> k >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];

	vector<int> b(n);
	rep(i, n-1)
	{
		b[i] = a[i + 1] - a[i];
	}
	b[n - 1] = a[0] + k - a[n - 1];
	int m;
	 m= std::max_element(b.begin(), b.end()) - b.begin();
	int ma= *std::max_element(b.begin(), b.end());

	cout << k - ma << "\n";
	return 0;
}

Measured memory_bytes: 4852
package main

import(
    "fmt"
    "sort"
    "strings"
)



func main() {
    var a,b,c int
    fmt.Scan(&a,&b,&c)
    ans := max32(a,max32(b,c))*9 + a + b + c
    fmt.Println(ans)
}





func abs32(a int) int {
    if a<0{
        return -a
    }
    return a
}

func abs64(a int64) int64 {
    if a<0{
        return -a
    }
    return a
}

func min32(a, b int) int {
    if a >= b {
        return b
    }
    return a
}

func max32(a, b int) int {
    if a >= b {
        return a
    }
    return b
}

func min64(a, b int64) int64 {
    if a >= b {
        return b
    }
    return a
}

func max64(a, b int64) int64 {
    if a >= b {
        return a
    }
    return b
}

func gcd(a, b int64) int64 {
    if a % b == 0 {
        return b
    } else {
        return gcd(b, a%b)
    }
}

func lcm(a, b int64) int64 {
    return a / gcd(a, b) * b
}

func scanNums(len int) (nums []int){
    var num int
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return
}

func scanNums64(len int) (nums []int64){
    var num int64
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return
}

func scanString(len int) (str []string){
    var s string
    for i:=0; i<len; i++{
        fmt.Scan(&s)
        str = append(str,s)
    }
    return
}

func scanTwoNums(n,m int) ([][]int){
    Nums := make([][]int, n)
    for i:=0; i<n; i++{
        Nums[i] = make([]int, m)
    }
    return Nums
}

func SortString(s string) string{
    t := strings.Split(s, "")
    sort.Strings(t)
    return strings.Join(t, "")
}


Measured memory_bytes: 640
import math
def is_prime(x):
	flag = True
	for i in range(2, round(math.sqrt(x)) + 1):
		if x % i == 0:
			flag = False
	return flag

if __name__ == "__main__":
	x = int(input())
	for i in range(x, 2*x):
		if is_prime(i):
			print(i)
			break

Measured memory_bytes: 3060
K,N=map(int,input().split())
dis_lst=list(map(int,input().split()))
sa_lst=[]
for i in range(N):
    if i==N-1 and 0 in dis_lst:
      sa_lst.append(K-dis_lst[i])
      break
    elif i==N-1:
      sa_lst.append(K-dis_lst[i]+dis_lst[0])
      #print(sa_lst)
      break
    sa_lst.append(abs(dis_lst[i]-dis_lst[i+1]))
    #print(sa_lst)
    #print('pass')
sa_lst.remove(max(sa_lst))
print(sum(sa_lst))

Measured memory_bytes: 26444
#include<stdio.h>
#include<string.h>
#define Max 10000000
typedef struct  {
  char name[100];
  int t;
  
} P;
P Q[Max];
int head,tail,n;
int isFull(){
  return head==(tail+1)%Max;
}
void initialize(){
  head=0;
  tail=0;
}
int isEmpty(){
  if(head==tail){
    return 1;
  }
  else return 0;
}
void enqueue(P x){
  if(isFull()){
    fprintf(stderr,"Overflow\n");
  }
     Q[tail]=x;
     if(tail+1==Max){
       tail=0;
     }
  else{
    tail++;
  }

}

P dequeue(){
  if(isEmpty()){
    fprintf(stderr,"Underflow\n");
    
  }
  if(head+1==Max){
    head=0;
  }
  else{
    head++;
    
 
}
    P x=Q[head];

  return x;
  
}
int min(int a,int b){
  return a < b ? a : b;
}
int main(){
  int L=0,c;
  int i,q;
  P a;
  scanf("%d%d",&n,&q);
  for(i=0;i<n;i++){
    scanf("%s",&Q[i+1].name);
    scanf("%d",&Q[i+1].t);
  }

head=0;
tail=n+1;
while(head!=tail){
  a=dequeue();
  c=min(q,a.t);
  a.t=a.t-c;
  L=L+c;
  if(a.t>0)enqueue(a);
  else{
    if(head-tail!=0)
    printf("%s %d\n",a.name,L);
  }
 }
 return 0;
 
}
  
      
  

Measured memory_bytes: 21076
#include<cstdio>
#include<algorithm>
#include<map> 
using namespace std;

typedef long long ll;

const int MAXN = 100010;

int a[MAXN];

map<int, bool> mp;

int main(){
	int N, ans = 0;
	scanf("%d", &N);
	for (int i = 1; i <= N; ++i)
		scanf("%d", &a[i]);
	for (int i = 1; i <= N; i += 2)
		mp[a[i]] = 1;
	for (int i = 2; i <= N; i += 2)
		mp[a[i]] = 0;
	sort(a + 1, a + 1 + N);
	for (int i = 1; i <= N; ++i)
		if ((i & 1) != mp[a[i]])
			++ans;
	printf("%d", ans >> 1);
	return 0;
}

Measured memory_bytes: 5376
import sys
from fractions import gcd
from collections import defaultdict
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())

def main():
    s = S()
    d = defaultdict(int)
    for i in range(4):
        d[s[i]] += 1
    if len(d) == 2:
        for v in d.values():
            if v != 2:
                break
        else:
            print("Yes")
            return
    print("No")



if __name__ == "__main__":
    main()

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

int main(){
	int n;cin >> n;
	bool ans=false;
	for(int i=0;i<15;++i){
		for(int j=0;j<=25;++j){
			if(4*j+7*i==n) ans=true;
		}
	}
	if(ans) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
import sys
N, Y = map(int,input().split())

for i in range (N+1):
    for j in range (N+1):
        if  10000*i + 5000*j + 1000*(N-i-j) == Y and (N-i-j)>=0:
            print('%d %d %d'%(i,j,(N-i-j)))
            sys.exit()
print('-1 -1 -1')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  int N, L;
  cin >> N >> L;
  vector<pair<int, int> > memo(N);
  rep(i, N)
    memo[i] = make_pair(abs(L+i), L+i);
  sort(memo.begin(), memo.end());
  ll ans = 0;
  REP(i, 1, N)
    ans += memo[i].second;
  cout << ans << endl;
  return 0;
}


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

int main() {
  // ダブリング
  int n;
  cin >> n;
  vector<int> h(n);
  rep(i, n) cin >> h[i];
  vector<int> next(n);
  next[n-1] = n-1;
  rep(i, n-1) {
    if (h[i] >= h[i+1]) next[i] = i+1;
    else next[i] = i;
  }
  rep(i, 20) {
    vector<int> prev = next;
    rep(j, n) next[j] = prev[next[j]];
  }
  int ans = 0;
  rep(i, n) {
    int temp = next[i] - i;
    if (temp > ans) ans = temp;    
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 4556
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                   \
  ifstream in("atcoder-problems/tenka1_2019_c.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v) \
rep(l, v.size()) { cout << v[l] << " "; } \
cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18+100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N;
  string S;
  cin >> N >> S;

  ll wsum = 0;
  rep(i, N) {
    if (S[i] == '.') wsum++;
  }
  ll ans = wsum;

  ll bsum = 0;
  rep(i, N) {
    if (S[i] == '#') bsum++;
    else
      wsum--;
    ans = min(ans, wsum + bsum);
  }

  cout << ans << endl;
}

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

#define fi first
#define se second
#define inf 0x3f3f3f3f
#define all(A) A.begin(),A.end()
#define allr(A) A.rbegin(),A.rend()
#define MOD 1000000007
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int32_t main(){
	
	string str;
	cin >> str;
	bool fl = true;
	if(str.size()%2==1)
		fl = false;
	for(int i=0;i<str.size();i+=2)
		if(str[i]!='h')
			fl = false;
	for(int i=1;i<str.size();i+=2)
		if(str[i]!='i')
			fl = false;
	cout << (fl?"Yes\n":"No\n");
	
	
#ifdef LOCAL_DEFINE
	cerr << "\nTime: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
}







Measured memory_bytes: 764
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

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

	vector<vector<int>> v(30);
	int max_ch = 0;
	for (int i = 0; i < s.size(); i++) {
		int t = (int)(s[i] - 'a');
		v[t].push_back(i);
		max_ch = max(max_ch, t);
	}

	int a = -1, b = -1;
	for (int i = 0; i <= max_ch; i++) {
		for (int j = 1; j < v[i].size(); j++) {
			int len_substr = v[i][j] - v[i][j - 1] + 1;

			if (len_substr <= 3) {
				a = v[i][j - 1] + 1;
				b = v[i][j] + 1;
				cout << a << " " << b << endl;
				return 0;
			}
		}
	}

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


Measured memory_bytes: 1148
A,B = map(int,input().split())

hoge = list(range(B*10,(B*10)+10))

ans = []
for i in hoge:
    if (i * 0.08) // 1 == A:
        ans.append(i)

if len(ans) == 0:
    print(-1)
else:
    print(min(ans))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
// cout << fixed << setprecision(10) << ans << endl;
// *min_element(c + l, c + r) *max_element(c + l, c + r)
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// struct Edge {
//   int to, id;
//   Edge(int to, int id): to(to), id(id) {}
// };

vector<int> bfs(int s,vector<vector<int>> &grp,vector<vector<int>> &to,int N) {
  vector<int> dist(N,-1);
  vector<int> par(N,-1);
  dist[s] = 0;
  queue<int> qu;
  qu.push(s);
  while(!qu.empty()) {
    int now = qu.front();
    qu.pop();
    for(auto nxt : grp[now]) {
      if(dist[nxt]==-1) {
	par[nxt] = now;
	dist[nxt] = dist[now] + 1;
	qu.push(nxt);
      }
    }
  }
  P best = P(N*100,-1);
  for(auto cand : to[s]) {
    if(best.first > dist[cand] && dist[cand]!=-1) {
      best = P(dist[cand],cand);
    }
  }
  vector<int> vec(N+1);
  if(best.second == -1) return vec;
  vector<int> res;
  int parent = best.second;
  res.push_back(best.second);
  //  rep(i,N) cout<<dist[i]<<" ";cout<<endl;
  while(1) {
    parent = par[parent];
    res.push_back(parent);
    if(parent == s) {
      break;
    }
  }
  return res;
}

int main() {
  int N,M;cin>>N>>M;
  vector<vector<int>> grp(N,vector<int>());
  vector<vector<int>> to(N,vector<int>());
  rep(i,M) {
    int a,b;cin>>a>>b;
    a--;b--;
    grp[a].push_back(b);
    to[b].push_back(a);
  }
  vector<int> ans;
  int mn = N+1;
  rep(i,N) {
    auto res = bfs(i,grp,to,N);
    if(res.size() < mn) {
      ans = res;
      mn = res.size();
    }
  }
  if(mn == N+1) {
    cout<<-1<<endl;
  }else {
    cout<<ans.size()<<endl;
    rep(i,ans.size()) {
      cout<<ans[i]+1<<endl;
    }
  }
}


Measured memory_bytes: 3692
#include<stdio.h>
#include<math.h>
int main()
{
	long long k=0;int n;
	scanf("%d",&n);
	printf("0:\n");
	for(int s=1;s<pow(2,n);s++)
	{
		printf("%d:",s);
		for(int i=0;i<=n-1;i++)if(s&(1<<i))printf(" %d",i);
		printf("\n");
	}
}


Measured memory_bytes: 2148
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
cnt=0
for i in range(n):
    cnt+=a[i]+a[i+1]-max(a[i]+a[i+1]-b[i],0)
    a[i+1]=max(0,a[i+1]-max(0,b[i]-a[i]))
print(cnt)


Measured memory_bytes: 18624
#include <bits/stdc++.h>
#define INF 1000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;


int main()
{
  ll N, K;
  cin >> N >> K;
  ll M = (N - 1) * (N - 2) / 2;
  if (K > M)
  {
    cout << -1 << endl;
    return 0;
  }
  cout << (N - 1) + (M - K) << endl;
  for (ll i = 2; i <= N; ++i)
  {
    cout << 1 << ' ' << i << endl;
  }
  if (M == K)
  {
    return 0;
  }
  ll cnt = 0;
  for (ll i = 2; i <= N - 1; ++i)
  {
    for (ll j = i + 1; j <= N; ++j)
    {
      cout << i << ' ' << j << endl;
      cnt += 1;
      if (cnt == M - K)
      {
        return 0;
      }
    }
  }
}


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


int main() {
  long int N, M, K, count = 0, t = 0, A, B, temp=0;
  vector<long int> a={0}, b={0};
  cin >> N >> M >> K;
  
  for (int i = 0; i < N; i++){
    cin >> A;
    a.push_back(a[i] + A);
  }
  for (int j = 0; j < M; j++){
    cin >> B;
    b.push_back(b[j] + B);
  }
  vector<long int>::iterator it1 = upper_bound(a.begin(),a.end(),K);
  A = it1 - a.begin()-1;
  count = A;
  
  for(int k = 0; k<A+1; k++){
    vector<long int>::iterator it2 = upper_bound(b.begin(),b.end(),K-a[k]);
    B = it2 - b.begin()-1;
    if(count < k + B) count = k+B;
  }
  cout << count << endl;
  return 0;
}

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

int n,m,s,ok[105];

int main(void){
	scanf("%d %d",&n,&m);
	for(int i=1;i<=m;i++){
		int d;
		scanf("%d",&d);
		for(int j=1;j<=d;j++){
			int a;
			scanf("%d",&a);
			if(ok[a]==0)s++;
			ok[a]=1;
		}
	}
	printf("%d\n",n-s);
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define rep2(i,a,n) for(int i=(a); i<(n); i++)
#define all(vec) vec.begin(),vec.end()
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;

int main(){
  string S, T; cin >> S >> T;
  
  rep(i,110){
    S.insert(S.begin(), S[S.size()-1]);
    S.pop_back();
    if(S ==T){ cout <<"Yes"<< endl; return 0;}
  }
  cout <<"No"<< endl;
  return 0;
}

Measured memory_bytes: 3628
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << '\n'
#define all(a) a.begin(), a.end()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = (int)1e9;
const ll  inf = (ll)1e18;
const int mod = 1000000007;
const int MAX_N = 100010;



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

	int n, k;
	cin >> n >> k;

	int sum = 0;

	rep(i, n) {
		int x;
		cin >> x;

		sum += min(abs(k - x), x) * 2;
	}

	out(sum);

	return 0;
}

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

int main(){
  int N;
  cin >> N ;
  
  vector<tuple<string,int,int>> name_score(N);
  
  string name;
  int score;
  int k=1;
  
  for(int i=0;i<N;i++){
    cin >>name>>score;
    name_score[i]=make_tuple(name,-1*score,k);
    k++;
  }
   
  sort(name_score.begin(),name_score.end());
  //reverse(name_score.begin(),name_score.end());
  
  int num;
  for(int i=0;i<N;i++){
    tie(name,score,num)=name_score[i];
    cout << num << endl;
  }
}
  


Measured memory_bytes: 3644
import heapq

h, w = map(int, input().split())

field = [input() for _ in range(h)]

todo = [[0, 0, 0, '.']]
seen = [[10**5] * w for _ in range(h)]
while todo:
    count, y, x, color = heapq.heappop(todo)
    if field[y][x] == color:
        pass
    else:
        if color == '.':
            count += 1
        color = field[y][x]

    if seen[y][x] <= count:
        continue
    seen[y][x] = count

    slide_right = [count, y, x+1, color]
    slide_down = [count, y+1, x, color]
    if x+1 < w:
        heapq.heappush(todo, slide_right)
    if y+1 < h:
        heapq.heappush(todo, slide_down)

print(seen[h-1][w-1])

Measured memory_bytes: 3316
import bisect
N=int(input())
l = list(map(int,input().split()))
l.sort()
ans = 0
for i in range(1,N-1):
  for j in range(i+1,N):
    m=bisect.bisect_right(l,l[j]-l[i])
    if i>m:
      ans+=i-m
print(ans)



Measured memory_bytes: 3188
def Main(N, K):
    if K == 1:
        return 0
    mo = N%K
    if K//2 <= mo:
        return K-mo
    else:
        return mo
         
    

def main():
    N, K = map(int, input().split())
    print(Main(N, K))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>

int main(void) {
  char str[1000][32] = {'\0'};
  int i = 0, j = 0, k, c, ans1 = 0, ans2 = 0, t1 , t2, count[32] = {0};

  while(1) {
    c = getchar();
    if (c == EOF)
      break;
    else if (c == ' '){
      i = 0;
      j++;
    }
    else {
      str[j][i] = c;
      i++;
    }
  }

  for (j = 0; j < 32; j++) {
    if (str[j][0] == '\0') break;
    else count[j]++;
    for (k = j; k < 32; k++) {
      if (str[k][0] == '\0') break;
      if (strcmp(str[j], str[k]) == 0) count[j]++;
    }
  }
  
  t1 = count[0];
  for (j = 1; j < 32; j++) {
    if (count[j] == 0) break;
    if (count[j] > t1) {
      ans1 = j;
      t1 = count[j];
    }
  }
  
  t2 = strlen(str[0]);
  for (j = 1; j < 32; j++) {
    if (str[j][0] == '\0') break;
    if (strlen(str[j]) > t2) {
      ans2 = j;
      t2 = strlen(str[j]);
    }
  }

  printf("%s", str[ans1]);
  putchar(' ');
  printf("%s", str[ans2]);
  putchar('\n');

  return 0;
}

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

int main() {
	int i, n;
	cin >> n;
	bool result = false;
	string msg;

	for (i = 9; i > 0; i--) {
		if (n % i == 0 && n / i < 10) result = true;
	}

	if (result) msg = "Yes";
	else msg = "No";

	cout << msg;

	return 0;
}

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

int  N,M;
typedef pair<int,int> P;
P bri[100000];
bool used[100000];

int main(void){
    cin >> N >>M;
    rep(i,M){
        cin >> bri[i].first >> bri[i].second;
        bri[i].first--;bri[i].second--;
    }
    sort(bri,bri+M,greater<P>() );
    
    int last = -1,ans=0;
    rep(i,M){
        if(bri[i].first <=last && last<bri[i].second)continue;
        ans++;
        last = bri[i].first;
    }
    
    cout << ans << endl;
    /*
    rep(i,M){
        cout << bri[i].first <<" " <<bri[i].second << endl;
    }
    */
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define ll int64_t
#define _GLIBCXX_DEBUG
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
//約数列挙(√N)
vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}
//素因数分解(√N)
map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}
//素数テーブル(NloglogN)
vector< bool > prime_table(int n) {
  vector< bool > prime(n + 1, true);
  if(n >= 0) prime[0] = false;
  if(n >= 1) prime[1] = false;
  for(int i = 2; i * i <= n; i++) {
    if(!prime[i]) continue;
    for(int j = i + i; j <= n; j += i) {
      prime[j] = false;
    }
  }
  return prime;
}
//二項係数(K)
template< typename T >
T binomial(int64_t N, int64_t K) {
  if(K < 0 || N < K) return 0;
  T ret = 1;
  for(T i = 1; i <= K; ++i) {
    ret *= N--;
    ret /= i;
  }
  return ret;
}
//二項係数テーブル(N^2)
template< typename T >
vector< vector< T > > binomial_table(int N) {
  vector< vector< T > > mat(N + 1, vector< T >(N + 1));
  for(int i = 0; i <= N; i++) {
    for(int j = 0; j <= i; j++) {
      if(j == 0 || j == i) mat[i][j] = 1;
      else mat[i][j] = mat[i - 1][j - 1] + mat[i - 1][j];
    }
  }
  return mat;
}
int main(){
  int n;
  ll sum=0;
  cin >> n;
  vector<int> a(100001);
  rep(i,n){
    int k;
    cin >> k;
    sum+=k;
    a.at(k)++;
  }
  int q;
  cin >> q;
  rep(i,q){
    int b,c;
    cin >> b>>c;
    sum+=(c-b)*a.at(b);
    a.at(c)+=a.at(b);
    a.at(b)=0;
    cout << sum << endl;
  }
}

Measured memory_bytes: 3788
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;

ll x;
ll f(ll n){
    if(n==-1ll) return -1;
    return n/x;
}

int main(){
    cout << fixed << setprecision(10);
    ll a,b;
    cin >> a >> b >> x;

    cout << f(b) - f(a-1ll) << endl;
    return 0;
}

Measured memory_bytes: 256
import itertools

L, R = list(map(int, input().split()))

if (R - L) >= 2019:
    ans = 0
else:
    l_mod = L % 2019
    r_mod = R % 2019
    if l_mod > r_mod:
        ans = 0
    else:
        ans = 2018
        for i, j in itertools.combinations(list(range(L, R+1)), 2):
            ans = min(ans, (i * j) % 2019)
print(ans)

Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 20)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね

//ここから編集する


int main() {
    int N;
    cin >> N;
//    vector<vector<bool> > flag(N, vector<bool>(N, false));
    vector<int> a(N);
    vector<int> pos(N + 1);

    REP(i, 0, N) {
//        cin >> a[i];
        scanf("%d",&a[i]);
        pos[a[i]] = i;
    }

    set<int> set1;
    set<int> rset;
//    set1.insert(-1);
    set1.insert(N);
    rset.insert(1);

    ll ans = 0;

    for (int i = 1; i <= N; i++) {
        set1.insert(pos[i]);
        rset.insert(-pos[i]);
        auto itA = rset.upper_bound(-pos[i]);
        auto itB = set1.upper_bound(pos[i]);
//        printf("i = %d,*itA = %d,*itB = %d\n", i, -*itA, *itB);
        ans += 1LL * i * (pos[i] + *itA) * (*itB - pos[i]);
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 20608
#include<bits/stdc++.h>
#define pb push_back

#define f(i,a,b) for(int i=a;i<b;i++)
#define f1(i,a,b) for(int i=a;i<=b;i++)
#define int long long
using namespace std;
#define mod 1000000007
vector<int>adj[100001];
int visited[100001];
void dfs(int s)
{
    visited[s] = 1;
    for(int i = 0; i < adj[s].size(); i++)
    {
        if(visited[adj[s][i]] == 0)
        {
            dfs(adj[s][i]);
        }
    }
}

signed main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n, m, a, b;
    cin >> n >> m;
    for(int i = 0; i < m; i++)
    {
        cin >> a >> b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    memset(visited, 0, sizeof(visited));
    int count = 0;
    for(int i = 1; i <= n; i++)
    {
        if(visited[i] == 0)
        {
            dfs(i);
            count++;
        }
    }
    cout << count - 1 << endl;

    return 0;
}


Measured memory_bytes: 11076
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
	int N,M;
	while(1){
	int n[4000]={};
	int G=0;
	int H=0;
	cin>>N>>M;if(N==0&&M==0)break;
	for(int i=0;i<N;i++)
	{
		
		cin>>n[i];
		
	}
	bool f=false;
	for(int i=0;i<M;i++)
	{
		int x;cin>>x;
		G+=x;
		G+=n[G];
		if(G>=N-1&&f==false){f=true;H=i+1;}
		//cout<<"#"<<i<<G<<endl;
	}
	cout<<H<<endl;
}
	return 0;
}
			
	

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

using namespace std;

#define int long long
#define MOD 1000000007

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T>
void print(T x)
{
    std::cout << x << '\n';
}

//typedef long long ll;
#define TENNINE 1000000005
#define TENFIVE 100005
//#define int long long

string s;

signed main()
{
    cin >> s;
    int ans = 0;

    for (int i = 0; i < (int)(s.size() / 2); i++)
    {
        if (s[i] != s[s.size() - 1 - i])
        {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
typedef long long ll;
using namespace std;

ll power2(int num){
    ll pow2=1;
    for(int i=0; i<num-1; i++) pow2 *= 2;
    return pow2;
}

int main(){
    ll H; cin >> H;
    ll ans=0, monster=1;
    while(H!=0){
        H = H/2;
        ans += power2(monster);
        monster++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby, 
C#, VB, Perl, Swift, Prolog, Javascript, Pascal, HTML, CSS, JS
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int x,y;
    cin>>x>>y;
    if(x*500>=y){cout<<"Yes";}else cout<<"No";
    return 0;
}


Measured memory_bytes: 256
////////////////////////////////////////BatTle rOweL ///////////////////////////////////////
#include <bits/stdc++.h>
#include <deque>
#include <vector>
using namespace std;
#define smackie ios_base::sync_with_stdio(0); cin.tie(0);
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
typedef long long ll;
#define mset(a,k) memset(a,k,sizeof(a));
#define rep(i,l,h) for(ll i=l;i<h;i++)
#define ds1(i,x) for(int  i=0;i<x.size();i++)
#define ds2(i,x) for(auto i:x)
typedef vector<ll>  vit;
typedef pair<int,int> pii;
#define pb push_back
#define pf push_front
#define pof pop_front()
#define pob pop_back()
#define mp make_pair
typedef map<ll,ll >   mps;
//-------------------------------------------<dec>-------------------------------
 bool isPrime(int n) 
{ 
    if (n <= 1) return false; 
    rep(i,2,n)  if (n % i == 0) return false;  
    return true; 
}
 
 
 
//------------------------------------------<Assumes>----------------------------
int main()
{
    smackie
    ll n;
    cin>>n;
    ll a[n];
    mps m1;
    vit v;
    rep(i,0,n){
        cin>>a[i],++m1[a[i]];
        if(m1[a[i]]==1) v.pb(a[i]);
    }
    ll s=0;
    rep(i,0,v.size()){
        s=s+m1[v[i]]*(m1[v[i]]-1)/2;
    }
    //cout<<s<<endl;
    rep(i,0,n){
        cout<<s-((m1[a[i]]-1)*m1[a[i]])/2+((m1[a[i]]-2)*(m1[a[i]]-1))/2<<endl;
    }
}

Measured memory_bytes: 12020
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> map(H, vector<char>(W, 'a'));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> map.at(i).at(j);
    }
  }
  //ここまで入力
  
  vector<vector<char>> mapA(H, vector<char>(W, 'a'));
  int height = 0;
  //行を削る表を作る
  
  for (int i = 0; i < H; i++) {
    bool A = false;
    
    for (int j = 0; j < W; j++) {

      if (map.at(i).at(j) == '#') {
        A = true;
        break;
      }
      //もしi+1行に1つでも黒があれば実行する
    }
    
    if (A) {
      mapA.at(height) = map.at(i);
      height++;
    }
  }
  
  vector<vector<char>> mapB(H, vector<char>(W, 'a'));
  int width = 0;
  //列を削る表を作る
  
  for (int i = 0; i < W; i++) {
    bool B = false;
    
    for (int j = 0; j < height; j++) {
      if (mapA.at(j).at(i) == '#') {
        B = true;
        break;
      }
      //もしi+1列に1つでも黒があれば実行する
    }
    
    if (B) {
      for (int k = 0; k < height; k++) {
        mapB.at(k).at(width) = mapA.at(k).at(i);
      }
      width++;
    }  
  }
  //圧縮が終了する
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << mapB.at(i).at(j);
      if (j == width - 1) {
        cout << endl;
      }
    }
  }
}

Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <utility>

using namespace std;

const long long MOD = 1000000007;

vector<int> graph[100001];

pair<long long, long long> dfs(int node, int par) {
    pair<long long, long long> ret = pair<long long, long long>(1, 1);
    for(int child: graph[node]) {
        if(child == par) continue;
        pair<long long, long long> child_ret = dfs(child, node);
        ret.first *= child_ret.first+child_ret.second;
        ret.second *= child_ret.first;
        ret.first %= MOD;
        ret.second %= MOD;
    }
    return ret;
}

int main() {
    int n,x,y;
    cin >> n;
    for(int i=0;i<n-1;++i) {
        cin >> x >> y;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }

    pair<long long, long long> ans = dfs(1, 0);

    cout << (ans.first+ans.second)%MOD << "\n";
}

Measured memory_bytes: 12672
from collections import defaultdict

def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)

def main():
    MOD = 1000000007
    N = int(input())
    # Ai * Aj + Bi * Bj = 0
    # -> Ai * Aj = -Bi * Bj
    # -> (Ai/Bi) = -(Aj/Bj)
    # のとき、そのイワシ同士は入れられない

    # そこで、 Ci = Ai/Bi を約分したもの（かつBi>0としておく）
    # を覚えておき、Ci = -Cj となるようなペア同士を数えていく

    C = defaultdict(int)
    n00 = 0
    for i in range(N):
        a, b = map(int, input().split())
        # (0, 0) はどのイワシとも仲が悪いので、考慮の対象から外して置き、
        # 後で(0, 0)のイワシの本数分足す
        if a == 0 and b == 0:
            n00 += 1
            continue

        # Bが0の場合、Aが0のイワシであればなんでも仲が悪くなるので、
        # C = -1 / 0 で統一する。
        if b == 0:
            C[(-1, 0)] += 1
            continue
        # Aが0の場合、Bが0のイワシであればなんでも仲が悪くなるので、
        # C = 0 / 1 で統一する。
        elif a == 0:
            C[(0, 1)] += 1
            continue
        _gcd = gcd(a, b)
        a = a // _gcd
        b = b // _gcd
        # bは常に0以上にする
        if b < 0:
            b = -b
            a = -a
        C[(a, b)] += 1
    
    C = dict(C)
    flag = {k: False for k in C.keys()}

    groups = []
    for c, nc in C.items():
        a, b = c
        # 仲の悪いイワシの個数
        bad_a, bad_b = -b, a
        if bad_b < 0:
            bad_b = -bad_b
            bad_a = -bad_a
        nBad = C.get((bad_a, bad_b), 0)
        # 仲の悪いイワシがいなければ、
        # この中からイワシを選ぶ時のすべての組み合わせ（全て選択しない場合を含む）の数を考える
        if nBad == 0:
            groups.append(2 ** nc)
            continue
        # 中の悪いグループがすでに調査済みなら何もしない
        elif flag[(bad_a, bad_b)]:
            continue

        # あるCのイワシがnc本、それと中の悪いイワシがnBad本あるとする。
        # nc + nBad 本のイワシのうち、OKな組み合わせの個数は
        # [nc本から1本以上選ぶ組み合わせ] + [nc本から1本以上選ぶ組み合わせ] + [イワシを全て選択しない場合]
        # (2^nc - 1) + (2^nBad - 1) + 1 = 2^nc + 2^nBad - 1
        groups.append((2 ** nc) + (2 ** nBad) - 1)
        flag[(a, b)] = True

    # 各グループの選択肢を掛け合わせ、-1する
    # (全て選択しないパターンを除外する)
    ans = 1
    for g in groups:
        ans = (ans * g) % MOD
    # -1 するついでに(0, 0) のイワシから1本以上選ぶ場合の数も足しておく
    ans = (ans + n00 - 1) % MOD
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 65084
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,k;
  cin>>n>>k;
  int kotae=0;
  if(n<=k)kotae=1;
  else {
    kotae=1+(n-k)/(k-1);
    if((n-k)%(k-1)!=0)kotae++;
  }
  cout<<kotae<<endl;
  return 0;
}

Measured memory_bytes: 3604
from collections import deque

#Start(sx, sy)から各頂点への最短距離を求める

def bfs(sx, sy):
    cnt = 0
    f_inf = float('inf')
    dist = [[f_inf] * m for _ in range(n)]

    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]

    #Start地点を0にする
    que = deque([])
    que.append((sx, sy))
    dist[sx][sy] = 0

    while que:
        p = que.popleft()

        for i in range(4):
            #移動した点を(nx, ny)とする
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]

            #移動可能かと既に訪れたかの判定
            #dist[nx][ny] != f_infなら既に訪れた
            if n > nx >= 0 and \
               m > ny >= 0 and \
               s[nx][ny] != '#' and \
               dist[nx][ny] == f_inf:
                que.append((nx, ny))
                dist[nx][ny] = dist[p[0]][p[1]] + 1
                cnt = dist[nx][ny]

    return cnt


n, m = map(int, input().split())
s = [input() for _ in range(n)]

ans = 0
for i in range(n):
    for j in range(m):
        if s[i][j] == '#':
            continue
        ans = max(ans, bfs(i, j))
print(ans)

Measured memory_bytes: 3316
while True:
    n=int(input())
    if n==0:
        break
    else:
        list=[]
        for i in range(n):
            temp=int(input())
            list.append(temp)
    list.remove(max(list))
    list.remove(min(list))
    a=sum(list)//(n-2)
    print(a)


Measured memory_bytes: 5592
#include <stdio.h>

int main(void)
{
    int t;
    int h, m, s;

    scanf("%d", &t);

    h = t / 3600;
    m = (t - 3600*h) / 60;
    s =  t - 3600*h - 60*m;

    printf("%d:%d:%d\n", h, m, s);
    return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <cmath>
#include <cstring>
#include <assert.h>
#include <utility>
#include <tuple>
#include <array>
#include <bitset>
#include <cstdlib>

using int64 = long long;
using uint64 = unsigned long long;

using namespace std;

template <uint64 M>
struct ModInt {
    uint64 n;
    constexpr ModInt(const uint64 n = 0) noexcept : n(n) {}
    constexpr ModInt operator+(const ModInt rhs) const noexcept {
        return ModInt(*this) += rhs;
    }
    constexpr ModInt operator-(const ModInt rhs) const noexcept {
        return ModInt(*this) -= rhs;
    }
    constexpr ModInt operator*(const ModInt rhs) const noexcept {
        return ModInt(*this) *= rhs;
    }
    constexpr ModInt operator/(const ModInt rhs) const noexcept {
        return ModInt(*this) /= rhs;
    }

    constexpr ModInt inv() const noexcept {
        return ModInt(1) /= *this;
    }

    constexpr ModInt& operator+=(const ModInt rhs) noexcept {
        n += rhs.n;
        if (n >= M) {
            n -= M;
        }
        return *this;
    }
    constexpr ModInt& operator-=(const ModInt rhs) noexcept {
        n -= rhs.n;
        if (n < 0) {
            n += M;
        }
        return *this;
    }
    constexpr ModInt& operator*=(const ModInt rhs) noexcept {
        (n *= rhs.n) %= M;
        return *this;
    }
    constexpr ModInt& operator/=(ModInt rhs) noexcept {
        int a = M - 2;
        while (a) {
            if (a % 2) {
                *this *= rhs;
            }
            rhs *= rhs;
            a /= 2;
        }
        return *this;
    }
};

template <uint64 M>
struct Combination {
    vector<ModInt<M>> fact;
    vector<ModInt<M>> inv_fact;
    
    Combination(int max_n): fact(max_n + 1), inv_fact(max_n + 1) {
        fact[0] = 1;
        for (int i = 1; i <= max_n; i++) {
            fact[i] = fact[i - 1] * i;
        }
        inv_fact[max_n] = fact[max_n].inv();
        for (int i = max_n - 1; i >= 0; i--) {
            inv_fact[i] = inv_fact[i + 1] * (i + 1);
        }
    }

    ModInt<M> choose(int m, int n) {
        if (m < 0 || m < n) return 0;
        // m! / n! / (m - n)!
        return fact[m] * inv_fact[n] * inv_fact[m - n];
    }
};

// a^n mod M を計算
template <uint64 M>
ModInt<M> pow(ModInt<M> a, int n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        auto b = pow(a, n / 2);
        return b * b;
    }
    return a * pow(a, n - 1);
}

constexpr uint64 MOD = 998244353;

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

    int n, m, k;
    cin >> n >> m >> k;

    Combination<MOD> comb(n);
    // x: 隣り合う組の数
    ModInt<MOD> ans = 0;
    for (int x = 0; x <= k; x++) {
        ans += pow<MOD>(m - 1, n - x - 1) * m * comb.choose(n - 1, x);
    }
    cout << ans.n << endl;

    return 0;
}



Measured memory_bytes: 5916
import sys
from io import StringIO
import unittest


def resolve():
    s = input()
    t = input()

    # 初期値の設定(結果が偽の場合の値を初期値にしてしまう)
    ans = "UNRESTORABLE"

    # i文字目から代入した場合、を検証していく
    for i in range(len(s)-len(t)+1):

        # iから一文字ずつ、不正な点が無いか検証。

        for j in range(len(t)):
            isRestorable = True

            if not s[j+i] == t[j] and not s[j+i] == "?":
                isRestorable = False
                break

        # 文字が代入できるなら、代入した場合の文字を変数に入れる。
        # これをループしていくので、ansには最終的に、辞書最小値が格納される、というロジック。
        if isRestorable:
            ans = s[0:i] + t + s[i+len(t):len(s)]
            ans = ans.replace("?", "a")

    print(ans)

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """?tc????
coder"""
        output = """atcoder"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """??p??d??
abc"""
        output = """UNRESTORABLE"""
        self.assertIO(input, output)

if __name__ == "__main__":
    # unittest.main()
    resolve()

Measured memory_bytes: 51180
#include <iostream>
#include <string>
using namespace std;
#define REP(i,x) for(int i=0;i<(int)(x);i++)

int n, m, t, si, p, ans, mx[101][101], mn[101][101], g[101][101];
string com;
main(){
	cin >> m >> n;
	REP(i, m){
		REP(j, n) mx[i][j] = 100;
		cin >> t;
		REP(j, t){
			cin >> si >> com >> p;
			if(com[0]=='>') mn[i][si-1] = max(mn[i][si-1], p);
			else mx[i][si-1] = min(mx[i][si-1], p);
		}
	}
	REP(i, m)REP(j, m)REP(k, n) g[i][j] |= mx[i][k] < mn[j][k];
	REP(k, m)REP(i, m)REP(j, m) g[i][j] |= g[i][k] & g[k][j];
	REP(i, m) ans |= g[i][i];
	cout << (ans ? "No" : "Yes") << endl;
	return 0;
}

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

int main() {
	ll x;
	cin >> x;
	ll ans = 2 * (x / 11);
	x %= 11;
	ans += x > 0;
	if (x > 6)
		++ans;
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;

void max_self(ll& a, ll b) {
    a = max(a, b);
}


int main() {
    int n;
    scanf("%d", &n);
    
    int base = 1;
    while(base <= n) {
        base *= 2;
    }
    // base is the smallest power of 2 that is not smaller than n
    vector<ll> tree(2 * base);
    
    vector<int> h(n), a(n);
    for(int i = 0; i < n; ++i) {
        scanf("%d", &h[i]);
    }
    for(int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
    }
    vector<ll> dp(n + 1);
    // dp[i] - the max total beauty so far if the last taken flower has height i
    for(int flower = 0; flower < n; ++flower) {
        
        // max dp[i] for i in [0, h[flower]-1]
        int x = h[flower] + base;
        ll best = 0;
        while(x > 1) {
            if(x % 2 == 1) {
                max_self(best, tree[x-1]);
            }
            x /= 2;
        }
        dp[h[flower]] = best + a[flower];
        
        for(int i = base + h[flower]; i >= 1; i /= 2) {
            max_self(tree[i], dp[h[flower]]);
        }
        
        //~ for(int i = 0; i < h[flower]; ++i) {
            //~ max_self(dp[h[flower]], dp[i] + a[flower]);
        //~ }
    }
    ll answer = 0;
    for(int i = 0; i <= n; ++i) {
        max_self(answer, dp[i]);
    }
    printf("%lld\n", answer);
}

Measured memory_bytes: 7424
#include<cstdio>
inline int max(int a,int b){return a>b?a:b;}
inline int min(int a,int b){return a<b?a:b;}
int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	if(a>0&&b>0) return printf("Positive")&0;
	if(a<0&&b<0&&(max(a,b)-min(a,b))%2==1) return printf("Positive")&0;
	if(a<0&&b<0&&(max(a,b)-min(a,b))%2==0) return printf("Negative")&0;
	return printf("Zero")&0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <math.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define printA(arr) for(int i = 0; i < SZ(arr); i++){cout << arr[i];if (i==SZ(arr)-1){cout<<endl;}else{cout << " ";}}
typedef long long ll;

int main()
{
  int N;
  cin >> N;
  vector<int> p;
  REP(i,N){
    int a;
    cin >> a;
    p.push_back(a);
  }

  if(p[0]!=0){
    cout << -1 << endl;
    return 0;
  }

  int diff;
  ll cnt=0;
  REP(i,N-1){
    diff = p[i+1] - p[i];
    if (diff>1){
      cout << -1 << endl;
      return 0;
    }
    else if(diff==1){
      cnt += 1;
    }
    else{
      cnt += p[i+1];
    }

  }
  cout << cnt << endl;

  return 0;
}


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

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

    int x, a, b;
    cin >> x >> a >> b;

    string m;
    if(-1 * a + b <= x){
        m = (-1 * a + b <= 0 ? "delicious" : "safe");
    }else{
        m = "dangerous";
    }

    cout << m << endl;

    return 0;
}

Measured memory_bytes: 256
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)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $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, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
use std::collections::HashMap;
fn main() {
    input! {
        n:usize,
        m:usize,
        abm:[(usize,usize);m],
    }
    let mut to_mid = vec![false;n];
    let mut to_n = vec![false;n];
    for &(a, b) in &abm {
        if b == n {
            to_n[a - 1] = true;
        } else if a == 1 {
            to_mid[b-1] = true;
        }
    }
    for j in 0..n{
        if to_mid[j] && to_n[j]{
            println!("POSSIBLE");
            return;
        }
    }
    println!("IMPOSSIBLE");
}


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

#define sz 100005
#define ll long long
ll int dp[sz+5],arr[sz+5];

int frog(int pos, int n){
    if(pos>n)return INT_MAX;
    if(pos==n)return 0;
    int a, b;
    if(dp[pos]!=-1)return dp[pos];
    for(ll int i=1; i<=2; i++){
    ll int a=abs(arr[pos]-arr[pos+i])+frog(pos+i,n);
     if(dp[pos]==-1)dp[pos]=a;
     else
     dp[pos]=min(dp[pos],a);
    }
    return dp[pos];
}

int main(){

    int n, i, j;
    cin>>n;
    for(i=1; i<=n; i++)
    cin>>arr[i];
    memset(dp,-1,sizeof(dp));
    cout<<frog(1,n)<<endl;
    return 0;
}


Measured memory_bytes: 6528