akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

vector<pair<ll,ll>> v[2510];
ll dist[2510];
vector<int> used(2510,0);

void bfs(){
  queue<int> q;
  q.push(0);
  dist[0]=0;
  while(q.size()){
    int x=q.front(); q.pop();
    if(used[x]>3000){ continue; }
    for(auto e:v[x]){
      if(dist[e.F] > dist[x] + e.S){
        dist[e.F] = dist[x] + e.S;
        used[e.F]++;
        q.push(e.F);
      }
    }
  }
}

int main(){
  int n,m,p;
  cin >> n >> m >> p;
  rep(i,m){
    ll a,b,c;
    cin >> a >> b >> c; a--; b--;
    v[a].push_back({b,-c+p});
  }
  rep(i,n){ dist[i]=longinf; }
  
  bfs();
  
  if(used[n-1]>1000){ 
    cout << -1 << endl; 
  } else {
    cout << max(0LL,-dist[n-1]) << endl; 
  }
  return 0;
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f(i,x,n) for(int i=x;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100005,INF=1<<29;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        int N;cin>>N;
        if(N==0) break;
        
        vector<int> cnt(24*60*60+3);
        
        for(int i=0;i<N;i++){
            string S;cin>>S;
            int sum=0;
            sum+=(S[0]-'0')*10*60*60;
            sum+=(S[1]-'0')*60*60;
            sum+=(S[3]-'0')*10*60;
            sum+=(S[4]-'0')*60;
            sum+=(S[6]-'0')*10;
            sum+=(S[7]-'0');
            
            cnt[sum+1]++;
            
            sum=0;
            cin>>S;
            
            sum+=(S[0]-'0')*10*60*60;
            sum+=(S[1]-'0')*60*60;
            sum+=(S[3]-'0')*10*60;
            sum+=(S[4]-'0')*60;
            sum+=(S[6]-'0')*10;
            sum+=(S[7]-'0');
            
            cnt[sum+1]--;
        }
        
        int ans=0;
        
        for(int i=1;i<cnt.size();i++){
            cnt[i]+=cnt[i-1];
            ans=max(ans,cnt[i]);
        }
        
        cout<<ans<<endl;
        
    }
    
}



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

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

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

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

using namespace std;


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

const ll MOD = 1e9 + 7;


int h, w;

ll dp[1200][1200];


string s[1200];

void add(ll &a, ll b) {
	a = (a + b) % MOD;
}

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	cin >> h >> w;
	for (int i = 0; i < h; ++i)
		cin >> s[i];
	dp[0][0] = 1;
	for (int i = 0; i < h; ++i)
		for (int j = 0; j < w; ++j) {
			if (i + 1 < h && s[i + 1][j] == '.')
				add(dp[i + 1][j], dp[i][j]);
			if (j + 1 < w && s[i][j + 1] == '.')
				add(dp[i][j + 1], dp[i][j]);
		}
	cout << dp[h - 1][w - 1] << "\n";
	return 0;
}




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

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

    vector<ll> b(n), c(n);
    rep(i,n){
        b[i] = -a[i] - i;
        c[i] = a[i] - i;
    }
    ll ans = 0;
    unordered_map<ll, ll> counter;
    rep(i, n) {
        ans += counter[c[i]];
        counter[b[i]]++;
    }
    cout << ans << endl;
}

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

int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    long long int R = 0; long long int G = 0; long long int B = 0;
    R = count(S.begin(), S.end(), 'R');
    G = count(S.begin(), S.end(), 'G');
    B = count(S.begin(), S.end(), 'B');
    long long int count = R*G*B;
    for(int i = 0; i < N-2; i++) {
        for(int j = i+1; j < N-1; j++) {
            int k = 2*j - i;
            if(k < N && S[i] != S[j] && S[j] != S[k] && S[i] != S[k]) {
                count--;
            }
        }
    }
    cout << count << endl;
    return 0;
}


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

bool check(string s) {
    if (s.size() < 4)
        return false;
    string t = "YAKI";
    for (int i = 0; i < 4; ++i)
        if (s[i] != t[i])
            return false;
    return true;
}

int main() {
    string s;
    cin>>s;
    cout<<(check(s)?"Yes":"No")<<endl;
}

Measured memory_bytes: 256
import itertools,math
N = int(input())
x = [] 
y = []
for _ in range(N):
    a,b = map(int,input().split())
    x.append(a)
    y.append(b)
summation = 0

def dist(i,j):
    return math.sqrt((x[i] - x[j])**2 + (y[i]-y[j])**2)
permutations = list(itertools.permutations(range(N)))
for perm in permutations:
    subSum = 0
    for i in range(N-1):
        subSum += dist(perm[i], perm[i+1])
    summation += subSum

answer = summation / len(permutations)
print(answer)

Measured memory_bytes: 7972
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
//#define INF 1145141919
#define INF 2147483647
#define MOD 1000000007
#define MAX_N (1<<17) // 10^5

struct SegTree {
  long long seg[MAX_N*2-1];
  int lazy[MAX_N*2-1];
  SegTree() {
    for (int i=0; i<MAX_N*2-1; i++) seg[i] = 0, lazy[i] = 0;
  }

  inline void setLazy(int k, int v, int l, int r) {
    lazy[k] += v;
    seg[k] += 1LL*v*(r-l);
  }
  inline void fix(int k) {
    seg[k] = seg[k*2+1] + seg[k*2+2];
  }
  inline void push(int k, int l, int r) {
    if (lazy[k] == 0) return;
    setLazy(k*2+1, lazy[k], l, (l+r)/2);
    setLazy(k*2+2, lazy[k], (l+r)/2, r);
    lazy[k] = 0;
  }

  void fill(int a, int b, int x, int k=0, int l=0, int r=MAX_N) {
    if (r <= a || b <= l) return;
    if (a <= l && r <= b) {
      setLazy(k, x, l, r);
      return;
    }
    push(k, l, r);
    fill(a, b, x, k*2+1, l, (l+r)/2);
    fill(a, b, x, k*2+2, (l+r)/2, r);
    fix(k);
  }

  long long query(int a, int b, int k=0, int l=0, int r=MAX_N) {
    if (r <= a || b <= l) return 0;
    if (a <= l && r <= b) return seg[k];
    push(k, l, r);
    return query(a, b, k*2+1, l, (l+r)/2) + query(a, b, k*2+2, (l+r)/2, r);
  }
};

int N, Q;
SegTree seg;

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N >> Q;
  rep(i, Q) {
    int t;
    cin >> t;
    if (t == 0) {
      int l, r, x;
      cin >> l >> r >> x;
      seg.fill(l, r+1, x);
    }
    else {
      int l, r;
      cin >> l >> r;
      cout << seg.query(l, r+1) << "\n";
    }
  }
  return 0;
}

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

typedef long long LL;

template<typename T>
void printmatrix(vector<vector<T> > ar){
    for (int i = 0; i < (int)ar.size(); i++) {
        for (int j = 0; j < (int)ar.size(); j++) {
            cout << ar[i][j];
        }
        cout << endl;
    }
}

template<typename T>
void printvector(vector<T> vec){
    for (int i = 0; i < (int)vec.size(); i++) {
        cout << vec[i] << endl;
    }
}

template<typename T>
void unique(vector<T>& vec){
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
}

template<typename T>
vector<T> cumsum(vector<T> vec){
    vector<T> newvec((T)vec.size());
    int tmp = 0;
    for (int i = 0; i < (int)vec.size(); i++) {
        tmp += vec[i];
        newvec[i] = tmp;
    }

    return newvec;
}


int main(int argc, char const* argv[])
{
    int a,b;
    cin >> a >> b;
    if (a+b == 15) {
        cout << "+" << endl;
    }else if (a*b == 15) {
        cout << "*" << endl;
    }else{
        cout << "x" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using vi = vector<int>;
using vv = vector<vi>;
using vvv= vector<vv>;
using P  = pair<int,int>;

const int INF = 1001001001;

int main(){
    int h, w, k;
    cin >> h >> w >> k;
    
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    x1--; y1--; x2--; y2--;
    
    vector<string> s(h);
    rep(i,h)cin>>s[i];
    
    vv cost(h, vi (w, INF));
    vv used(h, vi (w,   0));
    cost[x1][y1] = 0;
    
    queue<P> q;
    q.push(P(x1,y1));
    
    vector<int> dx={0,1,0,-1};
    vector<int> dy={1,0,-1,0};
    
    while(!q.empty()){
        
        int x  = q.front().first;
        int y  = q.front().second;
        int d  = cost[x][y];
        q.pop();
        /*
        if(x==x2 && y==y2){
            cout<<d<<endl;
            return 0;
        }
        */
        rep(i,4){
            int nx = x;
            int ny = y;
            for(int j=1; j<=k; j++){
                nx += dx[i];
                ny += dy[i];
                if(nx<0 || ny<0 || nx>=h || ny>=w)break;
                if(cost[nx][ny]<=d)break;
                if(s[nx][ny]=='@')break;
                
                if(cost[nx][ny]>d+1){
                    cost[nx][ny] = d+1;
                    q.push(P(nx,ny));
                }
            }
        }
    }
    cout << (cost[x2][y2]==INF?-1:cost[x2][y2]) << endl;
    return 0;
}

Measured memory_bytes: 16008
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

// int main(){
// 	int h,w,a,b;
// 	cin >> h >> w >> a >> b;

// 	for (int i = 0;i < h;i++){
// 		for(int j = 0;j < w;j++){
// 			if ((i <= b && j <= a) || (i > b && j > a)){
// 				cout << 0;
// 			}
// 			else{
// 				cout << 1;
// 			}
// 		}
// 		cout << endl;
// 	}

// 	return 0;
// }

int main(){
	int h,w,a,b;
	cin>>h>>w>>a>>b;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if((i<b)^(j<a))
				cout<<1;
			else
				cout<<0;
		}
		cout<<"\n";
	}
}

Measured memory_bytes: 1280
package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func intAbs(x int) int {
	return int(math.Abs(float64(x)))
}

func main() {
	sc.Split(bufio.ScanWords)

	N := scanInt()
	A := make([]int, N+2)
	for i := 1; i <= N; i++ {
		A[i] = scanInt()
	}

	sum := 0
	for i := 1; i <= N+1; i++ {
		sum += intAbs(A[i] - A[i-1])
	}

	for i := 1; i <= N; i++ {
		ans := sum - intAbs(A[i]-A[i-1]) - intAbs(A[i+1]-A[i]) + intAbs(A[i+1]-A[i-1])
		fmt.Println(ans)
	}
}


Measured memory_bytes: 4000
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeMap;

public class Main{
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		//文字列の個数
		int N = scan.nextInt();
		//文字列ごとに配列に入れる、文字列の個数分の配列ができる
		String[] L = new String[N];
		//文字列の個数の回数だけ取得する
		for(int i=0;i<N;i++) {
			L[i] = scan.next();
		}
		scan.close();

		//各文字列ごとに処理を行う、一文字ずつ取得して配列に入れ、MAP化する
		//MAP化した値を格納するためのリストを準備
		List<Map> ListL = new ArrayList<Map>();

		//文字列を一つ取得
		for(String str:L) {
			//文字列から取得した文字を格納するMAPを準備
			Map<String, Integer> map = new TreeMap<String, Integer>();
			//文字列を一文字ずつ分割してMAPに格納
			for(int i=0;i<str.length();i++) {
				String word =  String.valueOf(str.charAt(i));
				//もしキーに登録されていない文字が渡された場合
				if(map.get(word)==null) {
					//出現回数1回目でMAPに登録
					map.put(word,1);
					//すでにMAPに登録されている場合
				}else if (map.get(word)!=null) {
					//現在の出現数を取得
					int count = map.get(word);
					//今回の出現分を足す
					map.put(word, count+1);
				}
			}
			//一つの取得した文字列の文字分類が完了したら、分類結果をリストに登録する
			ListL.add(map);
		}

		//各MAPごとのキーの一致を比較、すべてのMAPで使用されているキーを取得
		//最初の文字列に使用されている文字、
		//兼、一致文字一覧用のリスト
		//一致しない文字をループで排除していくため、初期値は最初の文字列を採用
		Set<String> matchL = ListL.get(0).keySet();

		for(int i=1;i<N;i++) {
			//比較対象文字列の文字一覧格納用
			Set<String> diffL = ListL.get(i).keySet();
			//一致した文字の一時格納用
			List<String> tempL = new ArrayList<String>();
			//現段階で一致している文字の一覧と
			for(String diffA:matchL) {
				//未確認の文字の一覧を
				for(String diffB:diffL) {
					//比較して一致しているものがあれば
					if(diffA.equals(diffB)) {
						//一時一致リストに追加する
						tempL.add(diffA);
					}
				}
			}
			//比較が終わるごとに一致した文字を上書きする
			matchL = new HashSet<String>(tempL);
			//次のリストの値を入れるため、リセット
			diffL = null;

		}
;
		String resultL = "";

		//取得したキーの使用回数の最小値を取得
		//ループで該当文字の回数をリストから順に取得し、minである方を採用
		for(String str:matchL) {
			int strC = 0;
			for(Map<String, Integer> count:ListL) {
				int tempC = 0;
				tempC = count.get(str);
				if(strC==0 || tempC<strC) {
					strC = tempC;
				}
			}

			//最大値の数ずつキーを並べた文字列を作成、表示
			for(int i = 0;i<strC;i++) {
			resultL = resultL + str;
			}
		}

		System.out.println(resultL);

	}
}

Measured memory_bytes: 21588
#include<bits/stdc++.h>
using namespace std;
typedef complex<double> P;
double eps=1e-8;
struct S{
  P s,t;
  S(P s=P(),P t=P()): s(s),t(t) {}
};
struct C{
  P p;
  double r;
  C(P p=P(),double r=0):p(p),r(r){}
};


bool eq(double a,double b){
  return (-eps<a-b&&a-b<eps);
}

double Sqrt(double a){
  if(a<0)return 0;
  return sqrt(a);
}

int ccw(P a,P b,P c){
  b-=a;c-=a;a=c*conj(b);
  if(a.imag()>eps)return 1;
  if(a.imag()<-eps)return -1;
  if(a.real()<-eps)return 2;
  if(abs(b)+eps<abs(c))return -2;
  return 0;
}

bool isIntersect(S a,S b){
  return (ccw(a.s,a.t,b.s)*ccw(a.s,a.t,b.t)<=0 &&
          ccw(b.s,b.t,a.s)*ccw(b.s,b.t,a.t)<=0);
}
/*
S crossPoint(C a,C b){
  P base=b.p-a.p;
  double k=(-b.r*b.r+a.r*a.r+norm(base));
  double w=k/(4.0*abs(base)),h=Sqrt(a.r*a.r-w*w);
  base/=abs(base);
  return S(a.p+base*P(w,h),a.p+base*P(w,-h));
}
*/
P getCrossPointCC(P p1,double r1,P p2,double r2){
  double cA = (r1*r1+norm(p1-p2)-r2*r2) / (2.0*r1*abs(p1-p2));
  return p1+(p2-p1)/abs(p1-p2)*r1*P(cA,sqrt(1.0-cA*cA));
}

double abs(S s){
  return abs(s.s-s.t);
}

int n;
vector<C> t;
vector<S> u;

bool check(int l,int r,S s){
  for(int i=l;i<=r;i++){
    if(isIntersect(u[i],s))continue;
    return false;
  }
  return true;
}

double solve(){
  vector<double> A(n+1,1e9),B(n+1,1e9);
  u[0].s=u[0].t=t[0].p;
  u[n].s=u[n].t=t[n-1].p;
  A[0]=B[0]=0;
  for(int i=1;i<=n;i++){
    for(int j=0;j<i;j++){
      S target;
      
      target=S(u[j].s,u[i].s);
      if(check(j+1,i,target))A[i]=min(A[i],A[j]+abs(target));

      target=S(u[j].t,u[i].s);
      if(check(j+1,i,target))
        A[i]=min(A[i],B[j]+abs(target));

      target=S(u[j].s,u[i].t);
      if(check(j+1,i,target))
        B[i]=min(B[i],A[j]+abs(target));

      target=S(u[j].t,u[i].t);
      if(check(j+1,i,target))
        B[i]=min(B[i],B[j]+abs(target));
    }
    // printf("%d %.8f\n",i,min(A[i],B[i]));
  }
  return min(A[n],B[n]);
}

int main(){
  while(1){
    cin>>n;
    if(n==0)break;
    t.clear();
    t.resize(n+1);
    u.clear();
    u.resize(n+1);
    for(int i=0;i<n;i++){
      double x,y,r;
      cin>>x>>y>>r;
      t[i]=C(P(x,y),r);
      if(i){
        u[i].s=getCrossPointCC(t[i].p,t[i].r,t[i-1].p,t[i-1].r);
        u[i].t=getCrossPointCC(t[i-1].p,t[i-1].r,t[i].p,t[i].r);
      }
    }
    printf("%.8f\n",solve());
  }
  return 0;
}

Measured memory_bytes: 1288
#include<bits/stdc++.h>
using namespace std;
int main(){
    int i,j,n,m,ans=0,k,t,r,c;
    char ch;
    cin>>n>>m>>k;
    int a[n][m];
    memset(a,0,sizeof(a));
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            cin>>ch;
            if(ch=='#')a[i][j]=1;
        }
    }
    for(r=0;r<(1<<n);r++){
        for(c=0;c<(1<<m);c++){t=0;
            for(i=0;i<n;i++){
                for(j=0;j<m;j++){
                    if((1<<i)&r)continue;
                    if((1<<j)&c)continue;
                    t+=a[i][j];
                }
            }
            if(t==k)ans++;
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3640
g, h, j, k = map(int, input() .split())
a = g * j
b = g * k
c = h * j
d = h * k
if a >= b and a >= c and a>= d:
    print(a)
elif b >= a and b >= c and b >= d:
    print(b)
elif c >= a and c >= b and c >= d:
    print(c)
else:
    print(d) 

Measured memory_bytes: 9184
import java.util.*;
public class Main {
    public static void main(String[] args) {
    
    Scanner sc = new Scanner(System.in);
      
      //入力
      int N = sc.nextInt();//くじ引き回数
      String item[] = new String[N];
      int count =1;
      
      
      //景品を配列へ
      for(int i =0; i<N; i++){
      	item[i] = sc.next();
      }
      
      //景品を昇順に並び替え
      Arrays.sort(item);
      
      //景品が被っていたらカウント
      for(int i =0; i<N-1; i++){
        if(!item[i].equals(item[i+1])){
          count++;
        }
      }
      System.out.println(count);
    }
}     

Measured memory_bytes: 70848
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(double x){
  printf("%.15f",x);
}
template<class S, class T> inline S divup_L(S a, T b){
  return (a+b-1)/b;
}
int main(){
  int N;
  double res;
  rd(N);
  res = (divup_L(N,2)) / (double)N;
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190929-1

// --- original code ---
// {
//   int N;
//   double res;
//   rd(N);
//   res = (N /+ 2) / (double)N;
//   wt(res);
// }


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

using namespace std;

int main(){
  string S;

  cin >> S;

  int B = (S[0]-'0')*10 + S[1]-'0';
  int A = (S[2]-'0')*10 + S[3]-'0';

  if(1 <= B && B <= 12){
    if(1 <= A && A <= 12) cout << "AMBIGUOUS" << endl;
    else cout << "MMYY" << endl;
  }

  else if(1 <= A && A <= 12) cout << "YYMM" << endl;

  else cout << "NA" << endl;
}
  


Measured memory_bytes: 256
MOD=10**9+7
n, k = map(int, input().strip().split())
d=[0]*(k+1)
d[0]=None

for i in range(1,k+1):
    d[i]=pow(k//i,n,MOD)

# update d
for i in range(k,0,-1):
    for j in range(i*2,k+1,i):
        d[i]-=d[j]
        d[i]%=MOD
ans=0
for i in range(1,k+1):
    ans+=d[i]*i%MOD
    ans%=MOD
print(ans)

Measured memory_bytes: 11128
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

const int INF = 1000000000;

vi ans;
ll cnum[300000];

void solve(int K, int N, int ad) { // some extra stuff on the left or right
    if (N == 0) return;
    
    ad ++;
    int cur = (K+1)/2;
    while (abs(ad-2*cnum[N-1]) <= abs(ad) && cur >= 1) cur--, ad -= 2*cnum[N-1];
    while (abs(ad+2*cnum[N-1]) < abs(ad) && cur < K) cur++, ad += 2*cnum[N-1];
    if (cur == 0) return;
    ans.pb(cur);
    
    solve(K,N-1,ad);
}

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	int K,N; cin >> K >> N;
	cnum[0] = 1;
	FOR(i,1,300000) {
	    cnum[i] = K*cnum[i-1]+1;
	    if (cnum[i] > INF) cnum[i] %= INF, cnum[i] += INF;
	}
    if (K % 2 == 0) {
        cout << K/2 << " ";
        F0R(i,N-1) cout << K << " ";
        return 0;
    } 
    solve(K,N,-1);
    for (int i: ans) cout << i << " ";
}

// read!
// ll vs. int!

Measured memory_bytes: 24688
//itp1_6-b
#include <iostream>
#include <vector>
using namespace std;

int main(){
 int n;
 char mark;
 int rank;
 vector<bool> s(13,false);
 vector<bool> h(13,false);
 vector<bool> c(13,false);
 vector<bool> d(13,false);

 cin>>n;
 for(int i=0;i<n;i++){
  cin>>mark>>rank;
  if(mark=='S') s[rank-1]=true;
  else if(mark=='H') h[rank-1]=true;
  else if(mark=='C') c[rank-1]=true;
  else if(mark=='D') d[rank-1]=true;
 }
 for(int i=0;i<13;i++){
  if(s[i]==false)
   cout<<'S'<<" "<<i+1<<endl;
 }
 for(int i=0;i<13;i++){
  if(h[i]==false)
   cout<<'H'<<" "<<i+1<<endl;
 }
 for(int i=0;i<13;i++){
  if(c[i]==false)
   cout<<'C'<<" "<<i+1<<endl;
 }
 for(int i=0;i<13;i++){
  if(d[i]==false)
   cout<<'D'<<" "<<i+1<<endl;
 }
return 0;
}

Measured memory_bytes: 1196
fun main(args: Array<String>) {
    val (A, B) = readLine()!!.split(" ").map(String::toLong)
    //最大公約数・最小公倍数（セットで使う）
    fun gcd(a: Long, b: Long): Long {
        return if (b > 0) gcd(b, a % b) else a
    }

    fun lcm(a: Long, b: Long): Long {
        return a * b / gcd(a, b)
    }

    println(lcm(A, B))

}




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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

LL modinv(LL a) {
    LL b = MOD, u = 1, v = 0;
    while (b) {
        LL t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= MOD;
    if (u < 0) u += MOD;
    return u;
}

LL moddev(LL a, LL b){
	return a * modinv(b) % MOD;
}

void Main()
{
    int n,m;
    cin>>n>>m;
    if(n==m){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

	return;
}

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

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

int main(){
  int N,M;
  cin >> N>>M;
  vector<vector<int>> as(N);
  vector<vector<int>> cs(M);
  
  for(int i = 0; i < N; i++){
    vector<int> a(2);
    cin >> a.at(0) >> a.at(1);
    as.at(i) = a;
  }
  for(int i = 0; i < M; i++){
    vector<int> c(2);
    cin >> c.at(0) >> c.at(1);
    cs.at(i) = c;
  }
  for(int n = 0; n < N; n++){
    int minId = 0;
    int minLen = INT_MAX;
    for(int m = 0; m < M ; m++){
      int len = abs(cs.at(m).at(0) - as.at(n).at(0)) + abs(cs.at(m).at(1) - as.at(n).at(1));
      if(len < minLen) {
        minId = m;
        minLen = len;
      }
    }
    cout << minId +1<<endl; 
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VVI;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
 
int main(){
  int N,R;
  cin>>N>>R;
  if(N>=10) cout<<R<<endl;
  else cout<<R+100*(10-N)<<endl;
}

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

using namespace std;
int main()
{

	vector<long> p;
	set < long > w;
	int n, k;
	string m[1000];
	string a;
	int e;
	int count = 0;
	long  y;
	int f = 0;
	while (1){
		w.clear();
		count = 0;
		cin >> n >> k;
		if (n == 0)return 0;
		for (int i = 0; i < n; i++){
			cin >> m[i];
		}
		if (k == 4){
			for (int i = 0; i < n; i++){
				for (int i2 = 0; i2 < n; i2++){
					for (int i3 = 0; i3 < n; i3++){
						for (int i4 = 0; i4 < n; i4++){
							if (i != i2&&i3 != i4&&i != i3&&i != i4&&i2 != i3&&i2 != i4){
								a = m[i] + m[i2] + m[i3] + m[i4];
								y = atol(a.c_str());
								w.insert(y);
								a.clear();
							}
						}
					}
				}
			}

		}
		long u = 0;
		if (k == 3){
			for (int i = 0; i < n; i++){
				for (int i2 = 0; i2 < n; i2++){
					for (int i3 = 0; i3 < n; i3++){
						if (i != i2&&i != i3&&i2 != i3){
							a = m[i];
							a += m[i2];
							a += m[i3];

							y = atol(a.c_str());
							w.insert(y);
							a.clear();
						}
					}
				}
			}
		}
		int o;
		if (k == 2){
			for (int i = 0; i < n; i++){
				for (int i2 = 0; i2 < n; i2++){

					if (i != i2){
						a = m[i] + m[i2];
						y = atol(a.c_str());
						w.insert(y);
						a.clear();
					}
				}
			}
		}
		cout << w.size() << endl;
		
	}
}

Measured memory_bytes: 1340
main = do
  [a,b,c,d] <- map read . words <$> getLine :: IO [Int]
  let l = c*d `div` gcd c d
  let ans = b - ((b`div`c) + (b`div`d) - (b`div`l))
  print $ ans - ((a-1) - (((a-1)`div`c) + ((a-1)`div`d) - ((a-1)`div`l)))
  

-- 最大公約数を求める
mygcd :: Int -> Int -> Int 
mygcd a b
  | b == 0 = a
  | otherwise = mygcd a (a`mod`b)

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

int main()
{
	char str[21];
	int i, leng;

	scanf("%s", str);
	leng=strlen(str);
	for( i=leng-1; i>=0; i-- ){
		printf("%c", str[i]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int h,w;
	cin>>h>>w;
	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=w;j++)
		{
			string s;
			cin>>s;
			if(s=="snuke")
				cout<<char('A' + j-1)<<i<<'\n';
		}
	}
}

Measured memory_bytes: 764
import java.util.Scanner;

/**
 * Created by wild on 2016/07/23.
 */
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int[] iroha = new int[3];
        for (int i = 0; i < iroha.length; i++) {
            iroha[i] = scan.nextInt();
        }

        int count = 0;
        int counttwo = 0;
        for (int tmp : iroha) {
            if (tmp == 7) count++;
            if (tmp == 5) counttwo++;
        }

        if (count == 1 && counttwo == 2){
            System.out.println("YES");
        }else {
            System.out.println("NO");
        }
    }
}

Measured memory_bytes: 9940
#include<bits/stdc++.h>
using namespace std;
long ncr(int n,int r){
  int i,j;
  long ans = 1;
  j=2;
  for(i=n;i>n-r;i--){
    ans*=i;
    while(ans%j==0 && j<=r){
      ans/=j;
      j++;
    }
  }
  return ans;
}


int main(){
  int n;
  cin >> n;
  int p;
  cin >> p;
  vector<int>a(n);
  int i;
  for(i=0;i<n;i++){
    cin >> a[i];
  }
  int odd = 0;
  int even = 0;

  for(i=0;i<n;i++){
    if(a[i]%2==0)even++;
    else odd++;
  }
  long ansO = 0;
  long ansE = 0;
  for(i=0;i<=even;i++){
    ansE += ncr(even,i);
  }
  for(i=0;i+p<=odd;i+=2){
    ansO += ncr(odd,i+p);
  }
  cout << ansO*ansE << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
int N;
  int X;
  cin >>N>>X;
  vector<int> vec(N);
  rep(i,N) {
    cin >>vec.at(i);
  }
  int sum=0;
  rep(i,N) {
sum +=vec.at(i);
  }
  
  
  if(X==sum) {
    cout <<N<< endl;
  }
  else  {
    sort(all(vec));
    int count=0;
    int remain=X-sum;
    rep(i,INF) {
      if(remain>=vec.at(0)) {
        remain=remain-vec.at(0);
        count++;
      }
      if(remain<vec.at(0)) {
cout<<N+count<< endl;
        break;
      }
    }
  }
  
  
  
  
  
}
 

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main(int argc, char const *argv[]) {
  int n,l;
  cin>>n>>l;
  vector<string> s;
  string ans;
  for(int i=0;i<n;i++){
    string tmp;
    cin>>tmp;
    s.push_back(tmp);
  }
  sort(s.begin(),s.end());
  for(int i=0;i<n;i++){
    ans+=s[i];
  }
  cout<<ans<<endl;
  return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vi vector<int>
#define vivi vector<vi>
const int INF = 1<<29;
typedef long long int ll;

bool isKaibun(string S){
    int size = S.size();
    bool ok = true;
    for(int i = 0;i < size/2;++i){
        if(S[i] != S[size - i - 1])ok = false;
    }
    return ok;
}
int main(){
    string S;cin >> S;
    bool flg = true;
    if(!isKaibun(S))flg = false;
    if(!isKaibun(S.substr(0, (S.size()-1)/2)))flg = false;
    if(!isKaibun(S.substr((S.size()+3)/2 - 1)))flg = false;
    cout << ((flg) ? "Yes" : "No");
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char** argv, char** env) {
    string s;
    cin >> s;
    for (int i = 0; i < s.length(); ++i) {
        if(s[i] == 'C') {
            for (int j = i; j < s.length(); ++j) {
                if(s[j] == 'F') {
                    cout << "Yes" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] ag) {
		Scanner sc=new Scanner(System.in);
		int W=sc.nextInt();
		int A=sc.nextInt();
		int B=sc.nextInt();

		if(A<B) {
			if(A+W>=B) {
				System.out.println(0);
			}
			else if(A+W<B) {
				System.out.println(B-A-W);
			}
		}
		else if(A==B) {
			System.out.println(0);
		}
		else if(A>B) {
			if(B+W>=A) {
				System.out.println(0);
			}
			else if(B+W<A) {
				System.out.println(A-B-W);
			}
		}
	}
}

Measured memory_bytes: 23636
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<string>
#include<iostream>
#define R(i, n) for(int i = 0; i < n; i++)
#define S(a) scanf("%d", &a)
#define S2(a, b) scanf("%d%d", &a, &b)
#define S3(a, b, c) scanf("%d%d%d",  &a, &b, &c)
#define SL(a) scanf("%lld", &a)
#define P(a) printf("%d\n", a)
#define PY printf("%s", "Yes");
#define PN printf("%s", "No");
#define INF 1000000000
using namespace std;
typedef long long ll;
typedef pair<int, int> IR;

int main(){
	int n, a, b;
	string s;
	S3(n, a, b);
	cin >> s;
	int count = 0;
	int bnum = 0;
	R(i, n){
		if(s[i] == 'a'){
			if(count < a + b){
				PY;
				printf("\n");
				count++;
			}
			else{
				PN;
				printf("\n");
			}
		}
		else if(s[i] == 'b'){
			if(count < a + b && bnum < b){
				PY;
				printf("\n");
				count++;
				bnum++;
			}
			else{
				PN;
				printf("\n");
			}
		}
		else{
				PN;
				printf("\n");
		}
	}
}

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

int main(){
    int w,h,x,y,r;
    cin>>w>>h>>x>>y>>r;
    if(x+r<=w&&x-r>=0&&y+r<=h&&y-r>=0){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3092
from collections import deque
N,M = map(int, input().split())
g = [[] for _ in range(N)]
for i in range(M):
    a,b = map(int, input().split())
    a -= 1; b -= 1
    g[a].append(b)
    g[b].append(a)

ans = [-1]*N
ans[0] = 0
q = deque([0])    # 今の部屋

while q:
    now =  q.popleft()
    for nxt in g[now]:
        if ans[nxt] == -1:
            ans[nxt] = now
            q.append(nxt)
print('Yes')
for i in range(1,N):
    print(ans[i]+1)

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

int main() {
  int N;
  cin>>N;
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    cin>>vec.at(i);
  }
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  int alice=0;
  int bob=0;
  
  for(int i=0;i<N;i+=2){
    alice+=vec.at(i);
  }
  for(int i=1;i<N;i+=2){
    bob+=vec.at(i);
  }
  cout<<alice-bob<<endl;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var a, b, c []byte
	fmt.Scan(&a, &b, &c)
	var S [3][]byte
	S[0] = a
	S[1] = b
	S[2] = c
	var next byte = 0
	for {
		if len(S[int(next)]) == 0 {
			fmt.Printf("%s\n", string(next+'A'))
			return
		}
		m := S[next][0] - 'a'
		S[next] = S[next][1:]
		next = m
	}
}

Measured memory_bytes: 512
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
template<typename T>
void chmax(T& a, T b) {
	a = max(a, b);
}

template<typename T>
void chmin(T& a, T b) {
	a = min(a, b);
}

template<typename T>
void IN(vector<T> &A,int N=-1) {
	if (N == -1) {
		N = A.size();
	}
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
}

template<typename T>
void SO(vector<T> &A,bool F=false) {
	sort(A.begin(), A.end());
	if (F) {
		reverse(A.begin(), A.end());
	}
}
//////////////
bool  f(int a) {
	bool ans = false;
	if (1 <= a && a <= 12) {
		ans = true;
	}
	return ans;
}
void solve() {
	string S;
	cin >> S;

	int A = stoi(S.substr(0, 2));
	int B = stoi(S.substr(2, 2));
	string ans;
	if (f(A) && f(B)) {
		ans = "AMBIGUOUS";
	}
	else if (f(A)) {
		ans = "MMYY";
	}
	else if (f(B)) {
		ans = "YYMM";
	}
	else {
		ans = "NA";
	}
	cout << ans << endl;
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int Max = 1000000;
int main(){
    int N;
    cin >> N;
    long H[N];
    for(int i=0;i<N;i++) cin >> H[i];

    int ans = 0;
    int i=0;

    while(i<N-1){
        int cnt = 0;
        while(H[i]>=H[i+1]){
            cnt++;
            i++;
        }
        ans = max(ans, cnt);
        i++;
    }
    cout << ans <<endl;
      
  	return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <list>
#include <ctime>
#include <sstream>
#include <queue>
#include <stack>
#include <bitset>
#include <numeric>
#include <cassert>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
#define FOR(x, b, e) for(int x=(b); x<=(e); ++x)
#define FORD(x, b, e) for(int x=((int)(b))-1; x>=(e); --x)
#define REP(x, n) for(int x=0; x<(n); ++x)
#define ALL(c) c.begin(),c.end()
#define sz(x) ((int)((x).size()))
#define pb push_back
#define st first
#define nd second
#define mp(x,y) make_pair(x,y)
typedef short int sint;

#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 << ((it != d.b) ? ", " : "") << *it;
  }
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

ll p5(ll a) {
	return a*a*a*a*a;
}

int main() {
	ios_base::sync_with_stdio(false);
	int x;
	cin >> x;
	int GR = 4000;
	FOR(a, -GR, GR) {
		FOR(b, -GR, a) {
			ll now  = p5(a) - p5(b);
			if (now == x) {
				cout << a << ' ' << b << endl;
				return 0;
			}
		}
	}
}

Measured memory_bytes: 3648
# 解説を読みながら自作

S = input()
T = input()

s_len = len(S)
t_len = len(T)

res = []

init_K = "?" * s_len
for i in range(s_len - t_len + 1):
    K = list(init_K[:i] + T + init_K[i + t_len:])
    # KをSにしたがって書き換えていく。書き換えられない→正解ではない
    for j in range(s_len):
        if S[j] == "?" or S[j] == K[j]:  # Sが"?"またはSとKが一致、書き換える必要なし
            pass
        elif K[j] == "?":  # Sが"?"ではなくてKが"?"、書き換える
            K[j] = S[j]
        else:  # それ以外、書き換えられない
            break
    else:  # breakしなかった
        # 辞書順で最小になるように、残ったKの"?"を"a"に変える
        res.append("".join(K).replace("?", "a"))

if res:
    res.sort()
    print(res[0])
else:
    print("UNRESTORABLE")


Measured memory_bytes: 9040
//C - 4-adjacent: 30Min/ Muitos WA e testes/ Tive a ideia certa mas nao tava implementando corretamente;
//Assunto: Math;
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define loop(i, a, b) for(int i = a; i < b; i++)
#define loopBack(i, a, b) for(int i = a; i >= b; i--)
#define INF INT_MAX
#define LINF LLONG_MAX
#define DINF DBL_MAX
#define MAX 100050
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int n, d8 = 0, n2 = 0;
    bool ans = false;
    cin >> n;
    vector<int> seq(n);
    loop(i, 0, n) {
        cin >> seq[i];
        if(seq[i] % 4 == 0) d8++;
        else if(seq[i] % 4 == 2) n2++;
    }
    if(n2 % 2 == 0) n -= n2;
    else n -= (n2 - 1);
    if(d8 >= n / 2) ans = true;
    else ans = false;
    if(ans) cout << "Yes\n";
    else cout << "No\n";
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for ((i)=1;(i)<=(n);(i)++)
#define per(i,n) for ((i)=n;(i)>=(1);(i)--)
using namespace std;
int n,m,a,b,i,j;
int main()
{
	cin>>n>>m>>a>>b;
	if(n%a==0&&m%b==0)
	{
		puts("No");
		return 0;
	}
	puts("Yes");
	rep(i,n)
	{
		rep(j,m)
		{
			if(i%a==0&&j%b==0) printf("%d ",-(500*(a*b-1)+1)); else printf("500 ");
		}
		puts("");
	}
	return 0;
}

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


int main(){
	int a;
	scanf("%d",&a);
	int L=a/100;
	int R=a%100;
	
	if(1<=L&&L<=12){
	
	if(1<=R&&R<=12)printf("AMBIGUOUS\n");
	
	else printf("MMYY\n");
	}
	else{	
	if(1<=R&&R<=12)printf("YYMM\n");
	else printf("NA\n");
	}
}


Measured memory_bytes: 256
using System;
using System.Linq;
class aoj
{
    static void Main()
    {
        int[] c = new int[8];
        c[0] = 1;c[1] = 2;c[2] = 1;c[3] = 2;c[4] = 1;c[5] = 4;c[6] = 1;c[7] = 4;
        while (true)
        {
            string a = Console.ReadLine();
            if (String.IsNullOrEmpty(a)) break;
            int[] b = a.Split(' ').Select(int.Parse).ToArray();
            int[] f = new int[3];
            f[0] = 1000000000;
            for (int i = 0; i < 8; i++)
            {
                int e = 0;
                char[] h = new char[8];
                for (int j = 0; j < 8; j++)
                {
                    int d = j + i;
                    if (d >= 8)
                        d -= 8;
                    int g = b[j] - c[d];
                    if (g < 0)
                        g = 0;
                    e += g;
                    h[j] = (char)(c[d] + '0');
                }
                if (f[0] > e)
                {
                    f[0] = e;
                    f[1] = i;
                    string k = new string(h);
                    f[2] = int.Parse(k);
                }
                if (f[0] == e)
                {
                    string k = new string(h);
                    int l = int.Parse(k);
                    if (f[2] > l)
                    {
                        f[1] = i;
                        f[2] = l;
                    }
                }
            }
            int m = f[1];
            for (int i = 0; i < 8; i++)
            {
                int n = m + i;
                if (n >= 8)
                    n -= 8;
                if (i == 0)
                    Console.Write(c[n]);
                else
                    Console.Write(" " + c[n]);
            }
            Console.WriteLine();
        }
    }
}

Measured memory_bytes: 9376
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long N,K;
    cin>>N>>K;
    
    vector<long long> A(N);
    for(int i=0;i<N;i++) cin>>A[i];
    
    long long ans=0;
    for(int i=60;i>=-1;i--){
        if(i!=-1&&!(K&1LL<<i))continue;
        
        long long tmp=0;
        for(int j=60;j>=0;j--){
            long long num=0,mask=1LL<<j;
            for(int k=0;k<N;k++){
                if(A[k]&mask)num++;
            }
            if(j>i){
                if(K&mask)tmp+=mask*(N-num);
                else tmp+=mask*num;
            }else if(j==i){
                tmp+=mask*num;
            }else{
                tmp+=mask*max(num,N-num);
            }
        }
        
        ans=max(tmp,ans);
    }
    
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main()
{
	int H, W, i,j;
	while (1)
	{
		cin >> H >> W;
		if (H == 0 && W == 0)break;
		for (i = 0; i < H; i++)
		{for (j = 0; j < W; j++)
			
				cout << "#";
				cout << endl;
			}
		cout << endl;
	}
	return 0;
}


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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int n, ans, dn;

void check(vi &digits) {
  int val = 0;
  set<int> type;
  int i = 0;
  while (i < dn && digits[i] == 0) i++;
  srep(j, i, dn) {
    val = val * 10 + digits[j];
    type.insert(digits[j]);
  }
  if (type.count(0) == 0 && type.size() == 3 && val <= n) {
    ans++;
  }
}

void dfs(int d, vi &digits) {
  if (d == dn) {
    check(digits);
    return;
  }
  digits[d] = 7;
  dfs(d+1, digits);
  digits[d] = 5;
  dfs(d+1, digits);
  digits[d] = 3;
  dfs(d+1, digits);
  digits[d] = 0;
  dfs(d+1, digits);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  std::cin >> n;
  int nn = n;
  while (nn) dn++, nn /= 10;
  vi digits(dn);
  dfs(0, digits);
  std::cout << ans << "\n";
}


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

using namespace std;
typedef long long ll;
typedef double ld;

ll a[10];

int main(void)
{
	for(ll i = 1 ; i <= 5 ; i++)
		scanf("%lld", &a[i]);
	
	for(ll i = 1 ; i <= 5 ; i++)
	{
		if(a[i] == 0)
		{
			printf("%lld", i);
			return 0;
		}
	}
	
	return 0;
}

Measured memory_bytes: 3812
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;
typedef pair<int, int> pii;

typedef long long int ll;



template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const int INF = 1e9 + 7;


int main() {

	int a, b, c;
	cin >> a >> b >> c;
	cout << b * (c / a) << endl;


}





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


int main(void){
int x,y;
scanf("%d %d",&x,&y);
for(int i=0;i<1000;i++){
    for(int j=0;j<1000;j++){
        if(i+j==x&&4*j+i*2==y){printf("Yes");return 0;}
    }
}
{printf("No");}
}


Measured memory_bytes: 1728
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
public static class P {
  public static void Main() {
    var nk = Console.ReadLine().Split().Select(long.Parse).ToArray();
    var n = nk[0];
    var k = nk[1];
    var a = Console.ReadLine().Split().Select(long.Parse).OrderByDescending(x => x).ToArray();
    var f = Console.ReadLine().Split().Select(long.Parse).OrderBy(x => x).ToArray();
    var ok = long.MaxValue / 2;
    long ng = -1;
    while (ok - ng > 1) {
      var mid = (ok + ng) / 2;
      if (Achievable(k, mid, a, f)) ok = mid;
      else ng = mid;
    }
    Console.WriteLine(ok);
  }
  static bool Achievable(long k, long score, long[] a, long[] f) => a.Zip(f, (x, y) => Max(0, (x * y - score + y - 1) / y)).Sum() <= k;
}


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

int main(){
  while(1){
  int h,w;
  cin >> h >> w;
  if(h == 0 && w ==0) break;
  for(int i = 0;i < h;i++){
    for(int j = 0;j < w;j++){
      if(i == 0 || i == h-1 || j == 0 || j == w-1) cout << "#";
      else cout << ".";
    }
    cout << endl;
  }
  cout << endl;
  }
  return 0;
}



Measured memory_bytes: 3096