akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define sort_1(v) sort(v.begin(),v.end())
#define sort_2(v) sort(v.begin(),v.end(),greater<ll>())
#define reverse(v) reverse(v.begin(),v.end())
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
    int n,W;
    cin >> n >> W;
    int weight[n];
    int value[n];
    rep(i,0,n) cin >> value[i] >> weight[i];

    int dp[101][10001];

    rep(w,0,W+1) dp[0][w] = 0;

    rep(i,0,n){
        rep(w,0,W+1){
            if(w >= weight[i]){
                dp[i+1][w] = max(dp[i][w - weight[i]] + value[i], dp[i][w]);
            }else{
                dp[i+1][w] = dp[i][w];
            }
        }
    }

    cout << dp[n][W] << endl;
    return 0;
}


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

using namespace std;

int main(){
    cin.sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int N, K;
    cin >> N >> K;
    N -= K;
    if(K == 1){
        cout << 0 << endl;
        return 0;
    }
    cout << N << endl;
}


Measured memory_bytes: 256
main = do
  s <- getContents
  let v = map (map read . words) . lines $ s
  let w = map solve v
  let x = map (\x-> if x then "YES" else "NO") $ w
  mapM_ putStrLn x

solve::[Double] -> Bool
solve [xa,ya,xb,yb,xc,yc,xd,yd] =
  abs(dot u v)/len(u)/len(v) < eps
  where u = (xb-xa, yb-ya)
        v = (xd-xc, yd-yc)
        dot (a,b) (c,d) = a*c + b*d
        len (a,b) = sqrt(a^2+b^2)
        eps=1e-13

Measured memory_bytes: 4320
#include <iostream>

using namespace std;

int main(void) {
	int N,M;
	cin >> N >> M;
	int minc,maxc;
	cin >> minc >> maxc;
	for (int i = 1; i < M; ++i) {
		int L,R;
		cin >> L >> R;
		minc = max(L,minc);
		maxc = min(R,maxc);
	}
	cout << max(0,maxc-minc+1) << endl;
	return 0;
}



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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;




int n,m,k;


multiset<int> col;
vector<int> byrow[maxn];
int col_freq[maxn];


void add(int c) {
    col.erase(col.find(col_freq[c]));
    col.insert(++col_freq[c]);
}

void remove(int c) {
    col.erase(col.find(col_freq[c]));
    col.insert(--col_freq[c]);
}


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

    cin>>n>>m>>k;

    for (int j=1; j<=m; j++) {
	col.insert(0);
    }

    for (int i=0; i<k; i++) {
	int r,c;
	cin>>r>>c;
	byrow[r].push_back(c);
	add(c);
    }


    int ans = 0;

    for (int i=1; i<=n; i++) {
	for (int c: byrow[i]) {
	    remove(c);
	}
	int cur = int(byrow[i].size()) + *col.rbegin();
	ans = max(ans, cur);
	for (int c: byrow[i]) {
	    add(c);
	}
    }

    cout<<ans<<endl;    
    return 0;
}


Measured memory_bytes: 51664
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const double PI = acos(-1);

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	double r;
	cin >> r;
	double ans = PI * 2 * r;
	cout << fixed << setprecision(12) << ans << endl;
	return 0;
}


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

using namespace std;

char m[100][100];

int main()
{
	int h, w; cin >> h >> w;

	for (int i = 0; i < h; ++i) scanf("%s", m[i]);

	for (int i = 0; i < h; ++i) {
        int diff = -1;
		for (int j = 0; j < w; ++j) {
            if (m[i][j] == 'c') {
                diff = 0;
            } else if (diff >= 0) {
                diff++;
            }
            printf(j == 0 ? "%d" : " %d", diff);
		}
        printf("\n");
	}
}

Measured memory_bytes: 1184
#include<stdio.h>

int main(){
  int i, j;
  int h, w;

  while(1){
    scanf("%d %d", &h, &w);

    if(h == 0 && w == 0) break;
  
    for(i = 0; i < h; i++){
      for(j = 0; j < w; j++){
	if(i == 0 || i == h - 1 || j == 0 || j == w - 1){
	  printf("#");
	}
	else{
	  printf(".");
	}
      }
      printf("\n");
    }
    printf("\n");
  }
  
  return 0;
}


Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define all(v) v.begin(), v.end()
using pint = pair<int, int>;
typedef int64_t lint;
const int mod = 998244353;
struct mint {
	lint x;
	mint(lint x=0):x((x%mod+mod)%mod){}
	mint operator-() const { return mint(-x);}
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod-a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
	mint operator+(const mint a) const { return mint(*this) += a;}
	mint operator-(const mint a) const { return mint(*this) -= a;}
	mint operator*(const mint a) const { return mint(*this) *= a;}
	mint pow(lint t) const {
		if (!t) return 1;
		mint a = pow(t>>1);
		a *= a;
		if (t&1) a *= *this;
		return a;
	}

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

int main() {
	int N, K;
	cin >> N >> K;
	vector<pint> v(K);
	int a=0, b=0, c=0, x, y, z;
	rep(i, K) {
		cin >> x >> y;
		v.at(i) = make_pair(x,y);
	}
	sort(all(v));
	vector<mint> dp(N);
	dp[0] = 1;
	dp[1] = -1;
	rep(i, N) {
		if(i>0) dp[i] += dp[i-1];
		rep(j, v.size()) {
			tie(x, y) = v.at(j);
			if (i+x < N) {
				dp[i+x] += dp[i];
				if (i+y+1 < N) dp[i+y+1] -= dp[i];
			}
		}
	}
	std::cout << dp[N-1] << '\n';
}


Measured memory_bytes: 4796
s = input()
if len(set(s)) == 4:
    print('Good')
elif len(set(s)) == 1:
    print('Bad')
elif len(set(s)) == 2:
    if s[0] == s[2] and s.count(s[0]) == 2:
        print('Good')
    else:
        print('Bad')
else:
    if s[0] == s[1] or s[1] == s[2] or s[2] ==s[3]:
        print('Bad')
    else:
        print('Good')

Measured memory_bytes: 3064
n = int(input())
a = list(map(int,input().split()))

tot = sum(a)
cyc = tot// (n*(n+1)//2)
if(cyc == 0):
    print('NO')
    exit()
if( tot % cyc != 0):
    print('NO')
    exit()

cnt = 0
for i in range(n):
    tmp = a[i]-a[i-1]-cyc
    if(tmp%n != 0):
        print('NO')
        exit()
    cnt += abs(tmp//n)

if(cnt == cyc):
    print('YES')
else:
    print('NO')

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

int main() {
	int N, K, A, count = 0, SUM[200001] = {};
	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		cin >> A;
		if (SUM[A] == 0) count++;
		SUM[A]++;
	}
	if (count < K) cout << 0;
	else {
		sort(SUM, SUM + 200001, greater<int>());
		int sums = 0;
		for (int i = 0; i < K; i++) {
			sums += SUM[i];
		}
		cout << N - sums;
	}
}

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

using namespace std;

int main()
{
    map<char, int>charVal;
    charVal['a']=1;
    charVal['b']=2;
    charVal['c']=3;
    charVal['d']=4;
    charVal['e']=5;
    charVal['f']=6;
    charVal['g']=7;
    charVal['h']=8;
    charVal['i']=9;
    charVal['j']=10;
    charVal['k']=11;
    charVal['l']=12;
    charVal['m']=13;
    charVal['n']=14;
    charVal['o']=15;
    charVal['p']=16;
    charVal['q']=17;
    charVal['r']=18;
    charVal['s']=19;
    charVal['t']=20;
    charVal['u']=21;
    charVal['v']=22;
    charVal['w']=23;
    charVal['x']=24;
    charVal['y']=25;
    charVal['z']=26;

    string alphabet = "0abcdefghijklmnopqrstuvwxyz";

    map<char, int>occurence;

    string s;
    cin>>s;
    int len = s.length(), dlt=0;

    for(int i=0; i<len; i++)
    {
        occurence.insert(make_pair(s[i], 1));
    }

    bool found=false;

    while(0<=len)
    {
        while(dlt<26)
        {
            char alf=alphabet[dlt+1];
            if(occurence.find(alf)==occurence.end())
            {
                string add="";
                add+=alf;
                s.insert(len, add);
                found=true;
                break;
            }
            else
                dlt++;
        }

        if(!found)
        {
            len--;
            if(0<=len)
            {
                dlt=charVal[s[len]];
                occurence.erase(s[len]);
                s.erase(len, 1);
            }
        }
        else
            break;
    }

    if(found)
        cout<<s<<endl;
    else
        cout<<-1<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

#define ll long long

using namespace std;

int gcd(int a, int b) {
  if (b > a) return gcd(b, a);
  while(b%a!=0) {
    int r = b % a;
    b = a;
    a = r;
  }
  return a;
}

int main() {
  int K; cin >> K;
  ll sum = 0;
  for(int i=1;i<=K;i++) {
    for(int j=1;j<=K;j++) {
      for(int k=1;k<=K;k++) {
        sum += gcd(i, gcd(j, k));
      }
    }
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 3596
def solve():
    N,M,K = [int(i) for i in input().split()]

    A = [int(i) for i in input().split()]
    cumulative_A = [0] * (len(A)+1)
    for i in range(1, len(cumulative_A)):
        cumulative_A[i] = cumulative_A[i-1] + A[i-1]

    B = [int(i) for i in input().split()]
    cumulative_B = [0] * (len(B)+1)
    for i in range(1, len(cumulative_B)):
        cumulative_B[i] = cumulative_B[i-1] + B[i-1]

    max_j = len(cumulative_B) - 1
    ans = 0
    for i in range(len(cumulative_A)):
        time_A = cumulative_A[i]
        time_B = K - time_A
        is_found = False
        for j in reversed(range(max_j+1)):
            if cumulative_B[j] <= time_B:
                is_found = True
                break
        if is_found:
            cnt = i + j
            ans = max(cnt, ans)
        max_j = j

    print(ans)

if __name__ == "__main__":
    solve()

Measured memory_bytes: 53284
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp make_pair
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

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

  if(all_of(all(v), [](auto x){return x<=0;})){
    int idx = max_element(all(v)) - v.begin();
    cout << v[idx] << "\n";
    cout << n-1 << "\n";
    rep(i,n-idx-1) cout << n-i << "\n";
    rep(i,idx) cout << 1 << "\n";
    return 0;
  }

  long ans0 = 0, ans1 = 0;
  for(int i=0; i<n; i+=2) if(v[i]>0) ans0 += v[i];
  for(int i=1; i<n; i+=2) if(v[i]>0) ans1 += v[i];

  cout << max(ans0, ans1) << endl;

  vector<int> kotae;
  if(ans0 < ans1){
    kotae.pb(1);
    rep(i,n-1) v[i] = v[i+1];
    n--;
  }

  while(v.size()>2){
    if(v[0]<=0){
      kotae.pb(1);
      kotae.pb(1);
      rep(i,n-2) v[i] = v[i+2];
      n -= 2;
    }
    else if(v[2]<=0){
      kotae.pb(3);
      if(v.size()==3){
        n--;
      } else {
        v[1] += v[3];
        rep(i,2, n-2) v[i] = v[i+2];
        n -= 2;
      }
    }
    else {
      kotae.pb(2);
      v[0] += v[2];
      rep(i,1,n-2) v[i] = v[i+2];
      n -= 2;
    }
    v.resize(n);
  }

  if(v.size()==2){
    kotae.pb(2);
  }

  cout << kotae.size() << endl;
  for(auto x : kotae) cout << x << "\n";

  return 0;
}


Measured memory_bytes: 256
N,K=[int(i) for i in input().split()]
X=[int(i) for i in input().split()]
m=10**9
for i in range(N-K+1):
    m=min(m,X[K-1+i]-X[i]+min(abs(X[K-1+i]),abs(X[i])))

print(m)

Measured memory_bytes: 14384
using System; using System.Linq;
class A {
	static void Main() {

		var n = int.Parse(Console.ReadLine());
		var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
		var cnt = 0;
		for(int i = 0;i < n;i++) {
			if(i < a[i] - 1 && a[a[i]-1]-1 == i) {
				cnt ++;
			}
		}
		Console.WriteLine(cnt);
	}
}

Measured memory_bytes: 10968
#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
#include <utility>
#include <functional>
#include <map>
#include <string>
#include <set>
#include <math.h>

using namespace std;

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

  string s;
  cin >> s;

  string s0;
  string s1;

  int count0 = 0;
  for (int i = 0; i < s.size(); i++) {
    if (i % 2 == 0 && s[i] != '0') {
      count0++;
    }
    else if (i % 2 != 0 && s[i] != '1') {
      count0++;
    }
  }

  int count1 = 0;
  for (int i = 0; i < s.size(); i++) {
    if (i % 2 == 0 && s[i] != '1') {
      count1++;
    }
    else if (i % 2 != 0 && s[i] != '0') {
      count1++;
    }
  }

  cout << min(count0, count1) << endl;
}

Measured memory_bytes: 512
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations, combinations_with_replacement
from heapq import heappop, heappush
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    s = list(input())
    n = len(s)
    for  i in range(n):
        if s[i] == '?':
            s[i] = 'D'
    print(''.join(s))

if __name__ == "__main__":
    main()

Measured memory_bytes: 12572
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);
        String text = scan.next();
        int price = 700;
        char[] data = text.toCharArray();
        for(char c : data) {
            if (c == 'o') {
                price += 100;
            }
        }
        System.out.println(price);
    }
}

Measured memory_bytes: 21588
N = int(input())
a = [[],[]]
[a[i%2].append(t) for i, t in enumerate(map(int, input().split()))]

a_cnt = [{},{}]
for i in range(2):
    for j in range(len(a[i])):
        if a[i][j] in a_cnt[i]:
            a_cnt[i][a[i][j]] += 1
        else:
            a_cnt[i][a[i][j]] = 1

for i in range(2):
    # print(list(a_cnt[i].items()))
    a_cnt[i] = list(sorted(list(a_cnt[i].items()),\
        key=(lambda x:x[1]), reverse=True))[:2]

# print(a_cnt)
if a_cnt[0][0][0] != a_cnt[1][0][0]:
    print(N -a_cnt[0][0][1] -a_cnt[1][0][1])
else:
    if len(a_cnt[0])==1 and len(a_cnt[1])==1:
        print(N//2)
    else:
        ans1 = N -a_cnt[0][0][1] -a_cnt[1][1][1]
        ans2 = N -a_cnt[0][1][1] -a_cnt[1][0][1]
        print(min(ans1, ans2))


Measured memory_bytes: 19632
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;

int main(){
    double q;
    
    while(cin >> q, q != -1){
        double x = q/2;
        
        while(true){
            x -= (pow(x,3)-q)/(3*pow(x,2));
            if(abs(pow(x,3)-q) < 0.00001*q) break;
        }
        printf("%.6f\n" ,x);
    }
    
    return 0;
}

Measured memory_bytes: 1236
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
const ll MOD=1e9+7;
#define endl '\n'
#define F first
#define S second
const double PI = 3.141592653589793238460;
 
  void c_p_c()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  
  #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
    #endif
}


int  main()
{
  c_p_c();
 
  ll n,t,x;cin>>n>>x>>t;
  if(x>=n)
    cout<<t;
  else
  {
    if(n%x==0)
      cout<<t*(n/x);
    else
      cout<<t*((n/x)+1);
  }

  
  return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

// 約数の列挙O(√n)
vector<ll> enum_divisors(ll n){
    vector<ll> res;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            res.push_back(i);
            // 重複しないならばiの相方であるN/iもpush
            if(i!=n/i) res.push_back(n/i);
        }
    }
    // 小さい順に並び替える
    sort(res.begin(), res.end());
    return res;
}

int main() {
    int n;
    cin>>n;
    int ans=0;
    for(int i=1;i<=n;i++){
        if(i%2==0) continue;
        auto ed=enum_divisors(i);
        if(ed.size()==8) ans++;
    }

    cout<<ans<<endl;
}


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

int main() {
  int a,b,c,d,l,r;
  cin >> a >> b>>c>>d;
  l=a+b;
  r=c+d;
  if (l>r) {
    cout << "Left"<< endl;
  }
  else if(l<r){
  cout << "Right" <<endl;
  }
  else{
    cout<<"Balanced"<<endl;
}
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	var wk []int

	for i := 0; i < n; i++ {
		var in int
		fmt.Scan(&in)
		wk = append(wk, in)
	}

	res := abc081B(wk)
	fmt.Println(res)
}

func abc081B(wk []int) int {
	condition := true
	res := 0

	for condition {
		for i := 0; i < len(wk); i++ {
			if wk[i]%2 == 0 {
				wk[i] /= 2
			} else {
				condition = false
				break
			}
		}

		if condition {
			res++
		}
	}
	return res

}

Measured memory_bytes: 512
N = 50030
a = [True] *  N
i = 3
while i * i < N:
    for j in range(3 * i, N, 2 * i): a[j] = False
    i += 2
 
while True:
    try:
        n = int(input())
    except:
        break

    n0 = n + 2 if (n & 1) else n + 1
    for maxv in range(n0, N, 2):
        if a[maxv]: break
    n0 = n - 2 if (n & 1) else n - 1
    for minv in range(n0, 2, -2):
        if a[minv]: break
    else:
        minv = 2

    print(minv, maxv)

Measured memory_bytes: 6976
// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include<bits/stdc++.h>
using namespace std;

//for loop関係
#define rep(i,a,n) for(int i=(a);i<(n);++i)
#define repe(i,a,n) for(int i=(a);i<=(n);++i)
#define rrep(i,n,a) for(int i=(n);n>(a);--i)
#define rrepe(i,n,a) for(int i=(n);n>=(a);--i)

//略記
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define ENDL << "\n"

using ll = long long;
using P = pair<int,int>;
using itn = int;

//定数
const int INF = 1<<30;
const ll MOD = 1000000007;
const long double PI =(acos(-1));

//Degree <-> Radian
double toRad(double d){ double rad; rad=d*PI/180; return rad; }
double toDegree(double rad){ double d; d=rad*180/PI; return d; }
//The least common multiple : lcm
ll lcm(int a,int b){ return a*b/__gcd(a,b); }
//素数判定
bool isPrime(int n){
    int i; 
    if(n<2) return 0;
    else if(n==2) return 1;
    if(n%2==0) return 0;
    for(i=3;i*i<=n;i+=2) if(n%i==0) return 0;
    return 1;
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int r;
    cin >> r;
    cout << r*r ENDL;
    
    return 0;
}

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

void rotate (int len, char str[101]) {
	char tmp = str[len-1];
	for (int i=len-2; i>=0; i--)
		str[i+1] = str[i];

	str[0] = tmp;
}


int main () {
	char s[101];
	char t[101];
	int len;

	scanf ("%s", s);
	scanf ("%s", t);

	len = strlen (s);

	for (int i=0; i<len; i++) {
		if (! strcmp (s, t)) {
			printf ("Yes\n");
			return 0;
		}
		rotate (len, s);
	}

	printf ("No\n");
	return 0;
}


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define MAX 100000
#define INF -1

int n;
vector<int> g[4*MAX];
int d[4*MAX];

void bfs(int s){
	queue<int> q;
	fill(d, d+4*MAX, INF);
	q.push(s);
	d[s]=0;

	while(!q.empty()){
		int u=q.front();
		q.pop();
		for(int i=0; i<g[u].size(); i++){
			if(d[g[u][i]]==INF){
				q.push(g[u][i]);
				d[g[u][i]]=d[u]+1;
			}
		}
	}
	return;
}

int main(){
	int m;
	cin >> n >> m;
	for(int i=0; i<m; i++){
		int u, v;
		cin >> u >> v;
		u--; v--;
		for(int j=0; j<3; j++){
			g[j*MAX+u].push_back(((j+1)%3)*MAX+v);
		}
	}

	int s, t;
	cin >> s >> t;
	s--; t--;

	bfs(s);
	if(d[t]!=INF && d[t]%3==0) cout << d[t]/3 << endl;
	else cout << -1 << endl;
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

#define erep(i, x, n) for (auto i = x; i<=(ll)(n); i++)
#define rep(i, x, n) for(auto i = x; i<(ll)(n); i++)
#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define mod(n, m) ((n%m + m) % m)
#define reset(n, m) memset(n, m, sizeof n)
#define endl '\n'

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

	string x;
	cin >> x;
	map<string, bool> mp;

	int k;
	cin >> k;
	rep(i, 0, sz(x))
	{
		string y = "";
		rep(j, i, sz(x))
		{
			y += x[j];
			if (sz(y) > k)
				break;
			mp[y] = 1;
		}
	}

	for(auto i : mp)
	{
		k--;
		if (!k)
		{
			cout << i.first;
			break;
		}
	}

	return 0;
}



Measured memory_bytes: 1920
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<deque>
#include<queue>
#define ll long long int
#define ld long double
#define pi acos(-1)
#define pb push_back
using namespace std;

int main()
{
    ll i,j,a,k,b,c,n,t,m,p,q,d,e,f,y,g,z,h,r,l,x,o;
    ld aa,bb,cc,ee,dd,ff,kk,gg;
    vector<ll > v,s,vv;
    map<ll,vector<ll> > me;
    map<ll,ll > sa,ta,pa,ma;
    priority_queue<ll, vector<ll>, greater<ll> > aq,tq,pq;
    string st,et,ft,pt,ct;
    deque<ll> de,pe,ne;
    ios_base::sync_with_stdio(false);
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    cin>>a>>b>>c>>d;
    vv.pb(a*c);
    vv.pb(a*d);
    vv.pb(c*b);
    vv.pb(b*d);
    sort(vv.begin(),vv.end());
    cout<<vv[3]<<endl;
}


Measured memory_bytes: 3664
n, k = map(int, input().split())
lst = list(map(int, input().split()))
res = []
for i in range(min(k, len(lst))):
  throwaways = i
  take = min(k - throwaways, len(lst))
  # throwaways cannot be larger than take
  if throwaways > take:
    break
  for j in range(take+1):
    right = lst[:j]
    if len(right) < take:
      l = take - len(right)
      left = lst[l*-1:]
    else:
      left = []
    m_lst = sorted(right + left)
    for t in range(throwaways):
      # throw away if it's value is negative
      if m_lst[0] < 0:
        del m_lst[0]
    res.append(m_lst)
max_num = max([sum(e) for e in res])
if max_num <= 0:
  print(0)
else:
  print(max_num)

Measured memory_bytes: 4468
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
	int n,k;
	cin>>n>>k;
	int a=1;
	while(n--){
		a=min(a*2,a+k);
	}
	cout<<a<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
#include <algorithm>
#include <map>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
#define ll long long
#define rn(i,n) for(int i=1;i<=n;i++)



int main (){
  int n,m;
  ll sum=1;
  ll inf=1000000000+7;
  cin>>n>>m;

  if(abs(n-m)<=1){
    for(int i=1;i<=n;i++){
      sum=(sum*i)%inf;
    //  cout<<sum<<endl;
    }
    for(int i=1;i<=m;i++){
      sum=(sum*i)%inf;
//      cout<<sum<<endl;
    }
    if(abs(n-m)==0)sum=(sum*2)%inf;
    cout<<sum<<endl;
  }else cout<<0<<endl;

  return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
S = input()
Rs = []
now = S[0]
count = -1
 
for i in range(N):
    if S[i] == now:
        count += 1
    else:
        Rs.append(count)
        count = 0
        now = S[i]
Rs.append(count)
ans = 0

if S[0] == S[N-1]:
    if K >= (len(Rs)-1) // 2:
        ans = N-1
    else:
        ans = sum(Rs) + 2 * K
else:
    if K >= len(Rs) // 2:
        ans = N-1
    else:
        ans = sum(Rs) + 2 * K
  
print(ans)

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

int main() {

  int N, K;
  cin >> N >> K;

  vector<int> A(N);
  for (int i = 0; i < K; i++) {
    int d;
    cin >> d;
    for (int j = 0; j < d; j++) {
      int a;
      cin >> a;
      A[a-1]++;
    } 
  }

  int answer = 0;
  for (int i = 0; i < N; i++) {
    if (A[i] == 0) {
      answer++;
    }
  }

  cout << answer << endl;

  return 0;

}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for(int i = a; i < b; i++)
#define rrep(i, a, b) for(int i = b - 1; i >= a; i--)
#define ALL(a) a.begin(), a.end()
#define pii pair<int,int>
#pragma GCC optimize("Ofast")
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define pb push_back
#define mp make_pair
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define isSquare(x) (sqrt(x)*sqrt(x) == x)
template<class T>bool chmax(T &a, const T &b) {if(a<b){a = b; return 1;} return 0; };
template<class T>bool chmin(T &a, const T &b) {if(a>b){a = b; return 1;} return 0; };
inline void IN(void){return;}
template <typename First, typename... Rest> void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
inline void OUT(void){cout << "\n";return;}
template <typename First, typename... Rest> void OUT(First first, Rest... rest){cout << first << " ";OUT(rest...);return;}
const double EPS = 1e-9;
const int mod = 1e9 + 7;
const int INF = 1e9;
const long long LLINF = 1e18;
long long lcm(ll a, ll b){return a * b / __gcd(a,b);}
struct IoSetup { IoSetup() {
    cin.tie(nullptr);ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
} } iosetup;
template< int mod > struct ModInt {
    int x; ModInt() : x(0) {}
    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) {if((x += p.x) >= mod) x -= mod;return *this;}
    ModInt &operator-=(const ModInt &p) {if((x += mod - p.x) >= mod) x -= mod;return *this;}
    ModInt &operator*=(const ModInt &p) {x = (int) (1LL * x * p.x % mod);return *this;}
    ModInt &operator/=(const ModInt &p) {*this *= p.inverse();return *this;}
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }
    ModInt inverse() const {int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); }return ModInt(u);}
    ModInt pow(int64_t n) const {ModInt ret(1), mul(x); while(n > 0) {if(n & 1) ret *= mul;mul *= mul;n >>= 1;}return ret;}
    friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x;}
    friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt< mod >(t); return (is); }
    static int get_mod() { return mod; }
}; using modint = ModInt< mod >;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main(){
    iosetup;
    int N, x; cin >> N >> x;
    vector<int> a(N);
    rep(i, 0, N) cin >> a[i];

    sort(ALL(a));
    ll cnt = 0;
    rep(i, 0, N){
        x -= a[i];
        if(x < 0) break;
        cnt++;
    }
    if(x > 0) cnt--;
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


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

    if (s.length() <= k) cout << s << endl;
    else {
        rep(i, k) cout << s[i];
        cout << "..." << endl;
    }
    return 0;
}

Measured memory_bytes: 3628
let rs, cs, xys = Scanf.(Array.(scanf "%d %d" @@ fun n m -> make n 0, make n 1, init m @@ fun _ -> scanf " %d %d" @@ fun a b -> a - 1, b - 1))
let _ = rs.(0) <- 1; Array.(iter (fun (x, y) -> rs.(y) <- max rs.(y) rs.(x); cs.(y) <- cs.(y) + 1; cs.(x) <- cs.(x) - 1; rs.(x) <- min rs.(x) cs.(x)) xys; fold_left (+) 0 rs) |> Printf.printf "%d\n"

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, a, b, c, d;
  string s;

  cin >> n >> a >> b >> c >> d >> s;
  s.push_back('$');
  s.push_back('$');
  s.push_back('$');
  bool ok = false;
  a--;
  b--;
  c--;
  d--;
  for (int i = max(b - 1, 0); i <= d - 1; i++) {
    if (s[i] == '.' && s[i + 1] == '.' && s[i + 2] == '.') ok = true;
  }
  bool ac = true;
  bool bd = true;
  for (int i = a; i < c; i++) {
    if (s[i] == '#' && s[i + 1] == '#') ac = false;
  }
  for (int i = b; i < d; i++) {
    if (s[i] == '#' && s[i + 1] == '#') bd = false;
  }
  if (ac && bd) {
    if (c < d) {
      cout << "Yes" << endl;
    } else {
      if (ok) {
        cout << "Yes" << endl;
      } else {
        cout << "No" << endl;
      }
    }
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 592
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;


public class Main {
	
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			final String s = sc.next();
			
			if(s.equals("ABC")) {
				System.out.println("ARC");
			}else {
				System.out.println("ABC");
			}
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

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

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

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

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}


Measured memory_bytes: 32420
#include "bits/stdc++.h"
#define ll long long
#define ALL(x) x.begin(),x.end()
using namespace std;

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

ll min=-1,max=-1;
for(ll i=0;i<s.size();i++){
  if(s[i]=='A'&&min==-1){
    min = i;
  }

  if(min>=0&&s[i]=='Z'){

    max = i;
  }
}



cout<<max-min+1<<endl;


}


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

int main(){
    string s;
    cin>>s;
    int cnt=0;
    for(int i=0;2*i<s.size()-1;i++){
        if(s[i]!=s[s.size()-1-i])cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}

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

#define ll long long int

int main()
{
   
   char s[4];
   ll i,k=0;
   for(i=0;i<4;i++)
   {
     cin>>s[i];
   }
    for(i=0;i<3;i++)
   {
     if(s[i]==s[i+1])
     {
         k++;
         cout<<"Bad";
         break;
     }
   }
   if(k==0)
   {
       cout<<"Good";
   }
   
   
    return 0;
}



Measured memory_bytes: 256
def main():
  n, x ,m = map(int, input().split())
  a = [0, x]
  place = [-1]*m
  place[x] = 1
  num = 2
  while True:
    x = (x**2%m)
    if place[x] >= 0:
      break
    a.append(x)
    place[x] = num
    num += 1
  loop = num-place[x]
  loop_sum = sum(a[place[x]:])
  loop_st = sum(a[:place[x]])
  
  if n <= place[x]:
    print(sum(a[:n+1]))
  else:
    n -= place[x]-1
    print(loop_st + loop_sum*(n//loop) + sum(a[place[x]:n%loop+place[x]]))
  
if __name__ == "__main__":
  main()

Measured memory_bytes: 13624
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<string>
#include<algorithm>


using namespace std;
const long long int MOD=1e9+7;

int main(){
  string s;
  long long k, ans=0;
  cin >> s;
  cin >> k;
  int  cnt = 0;
  char cur=s[0];
  int tmpcnt=1;
  for(int i=1;i<s.length();i++){
    if(cur==s[i])tmpcnt++;
    else{
      cnt+=tmpcnt/2;
      tmpcnt=1;
      cur=s[i];
    }
  }
  cnt += tmpcnt/2;
  ans = k*cnt;
  if(s[0]==s[s.length()-1]){
    int r=s.length(), l=s.length();
    for(int i=1;i<s.length();i++){
      if(s[i]!=s[0]){
        r=i;
        break;
      }
    }
    for(int i=1;i<s.length();i++){
      if(s[s.length()-1-i]!=s[s.length()-1]){
        l=i;
        break;
      }
    }
    if(r==s.length() && r%2==1){
      ans += (k/2);
    }
    else if(r%2==1 && l%2==1){
      ans += (k-1);
    }
  }
  cout << ans << endl;
}

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

using namespace std;

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

    int n;
    cin >> n;

    if(n & 1)
        cout << 2 * n;
    else
        cout << n;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(any{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

int main(){
	int N;
	cin >> N;
	vector<int> A(N);
	for(int i=0; i<N; i++) cin >> A[i];

	bool ok=true;
	for(int i=0; i<N; i++){
		if(A[i]%2) continue;
		if(A[i]%3!=0 && A[i]%5!=0) ok=false;
	}

	if(ok) cout << "APPROVED" << endl;
	else cout << "DENIED" << endl;

	return 0;
}


Measured memory_bytes: 256
### 解答


#入力はじめ

N,M,K=map(int,input().split())
A=list(map(int, input().split()))
B=list(map(int, input().split()))

#入力終わり


#累積和とる

A_wa = [0]
for i in range(N) :
    A_wa.append(A_wa[i]+A[i])

B_wa = [0]
for i in range(M) :
    B_wa.append(B_wa[i]+B[i])

#累積和計算おわり


ans = 0
end = N #二分探索の後に設定しなおしたいので先に設定しておく



for i in range(M+1):
    A_use = K-B_wa[i]
    if A_use<0: #BだけでKを超える場合
        break
    
    ##二分探索開始
    
    A_MAX = 0
    start = 0
    while  end-start>=1 : #調べるのが2個以上
        now = int((start + end + 1)/2)
        if A_wa[now]==A_use :  #A[i]がKと一致
            A_MAX = now #ここが最大
            break
        elif A_wa[now]<A_use : #A[i]がKより小さい
            start = now #目的の値はここ以上のとこにある
            A_MAX = now #現時点での最大値
        else : #A[i]がKより大きい
            end = now-1#目的の値はここより小さい
    
    end=A_MAX #endの再設定
    
    ##二分探索終了
    
    if A_MAX+i>ans :
        ans=A_MAX+i


#コンソールにだす
print(ans)
    

    






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

int main()
{
  int a,b;
  for(a=1;a<10;a++){
    for(b=1;b<10;b++){
        if(a==9&&b==10)
            break;
            else{
                cout<<a<<"x"<<b<<"="<<a*b<<endl;
            }

    }
  }
 return 0;
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for(int i=m; i<n; i++)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
template <typename T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0; }
template <typename T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1;} return 0; }

ll a[100000];
int main() {
    ll X; cin>>X;
    rep(i,1,200){
        a[i]=i;
        a[i]*=i;
        a[i]*=i;
        a[i]*=i;
        a[i]*=i;
    }
    rep(i,200,399){
        a[i]=a[i-199]*(-1);
    }
    rep(i,0,399){
        rep(j,0,399){
            if(a[i]-a[j]==X){
                if(i>199){
                    i-=199;
                    i*=-1;
                } 
                if(j>199){
                    j-=199;
                    j*=-1;
                } 
                cout<<i<<" "<<j<<endl;
                return 0;
            }
        }
    }

}

Measured memory_bytes: 3588
#include <cstdio>
#include <map>
#include <algorithm>
#include <vector>
#define MN 201000

std::vector<int> v[MN];
std::map<int, int> mp[MN];

int main()
{
	int h, w, n; scanf("%d%d%d", &h, &w, &n);
	for(int i = 1; i <= w; i++) v[i].push_back(h + 1), mp[h + 1][i] = 1;
	for(int i = 1; i <= n; i++)
	{
		int a, b; scanf("%d%d", &a, &b);
		mp[a][b] = 1;
		v[b].push_back(a);
	}
	for(int i = 1; i <= w; i++) std::sort(v[i].begin(), v[i].end());
	int r = 1;
	int ans = 1e9;
	for(int i = 1; i <= w; i++)
	{
		std::vector<int>::iterator it = std::lower_bound(v[i].begin(), v[i].end(), r);
		ans = std::min(ans, *it - 1);
		r++;
		while(r <= h && mp[r][i + 1]) r++;
		if(r > h) break;
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 46976
package main

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

var m map[int]int

const mod = 1000000007

func main() {
	m = make(map[int]int)
	n := getInt()

	for i := 2; i <= n; i++ {
		factorize(i)
	}

	ans := 1
	for _, v := range m {
		ans = (ans * (v + 1)) % mod
	}

	fmt.Println(ans)
}

func factorize(n int) {
	for n%2 == 0 {
		n /= 2
		m[2]++
	}

	for i := 3; i*i <= n; i += 2 {
		if n%i != 0 {
			continue
		}

		for n%i == 0 {
			n /= i
			m[i]++
		}
	}

	if n != 1 {
		m[n]++
	}
}

// -----------------------------------------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	// buf := 200001
	// sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
}

func getInt() int {
	i, err := strconv.Atoi(getString())
	if err != nil {
		panic(err)
	}
	return i
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}


Measured memory_bytes: 640
use std::cmp::Ordering;
use std::io;
use std::io::Read;

fn main() {
    let mut stdin = io::stdin();
    let mut buf = String::new();
    let _ = stdin.read_to_string(&mut buf);
    let inputs: Vec<i16> = buf.split_whitespace().map(|s| s.parse().unwrap()).collect();

    let answer = if inputs[2] >= 0 && inputs[3] >= 0 {
        inputs[2].cmp(&inputs[3])
    } else {
        inputs[1].cmp(&inputs[0])
    };

    println!(
        "{}",
        match answer {
            Ordering::Less => "Bob",
            Ordering::Equal => "Draw",
            Ordering::Greater => "Alice",
        }
    );
}



Measured memory_bytes: 5032
#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};
ll PS(ll a, ll b) {
  ll c=__gcd(a,b);
  ll d=a/c*b;
  return d;
}


int main() {
  ll N;
cin >>N;

vl ti(N);
rep(i,N) {
cin >>ti.at(i);
}
ll a1=ti.at(0);

rep(i,N) {
  
  a1=PS(a1,ti.at(i));
}
cout<<a1<<endl;
}




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

int main() {
  int n, d, x; cin >> n >> d >> x;
  int a[n]; for(int i = 0; i < n; i++) cin >> a[i];
  int ans = 0;
  for(int i = 0; i < n; i++) {
    int j = 0;
    while(j * a[i] + 1 <= d) {
      j++;
      ans++;
    }
  }
  cout << ans + x << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
typedef vector<ll>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
//const ll MOD = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

bool dp[88][88][2*80*88];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W;
    cin >> H >> W;
    vector<vector<int>> a(H, vector<int>(W)), b(H, vector<int>(W));
    REP(i,H) REP(j,W) cin >> a[i][j];
    REP(i,H) REP(j,W) cin >> b[i][j];
    dp[0][0][abs(a[0][0] - b[0][0])] = true;

    REP(i,H) REP(j,W){
        REP(k,2*80*88){
            if(i>0){
                if(dp[i-1][j][k]){
                    dp[i][j][k+abs(a[i][j]-b[i][j])] = true;
                    dp[i][j][abs(k-abs(a[i][j]-b[i][j]))] = true;
                }
            }
            if(j>0){
                if(dp[i][j-1][k]){
                    dp[i][j][k+abs(a[i][j]-b[i][j])] = true;
                    dp[i][j][abs(k-abs(a[i][j]-b[i][j]))] = true;
                }
            }
        }
    }

    REP(i,2*80*88){
        if(dp[H-1][W-1][i]){
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 97536
N = int(input())

combi = False
for i in range(N//4+1):  # N=40に対し、ケーキは0~10個のいずれか
    for j in range(N//7+1):  # N=40に対し、ドーナツは0~5個のいずれか
        if 4 * i + 7 * j == N:
            combi = True
            break
if combi:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 2940
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n = int(input())
    a = list(map(int, input().split()))
    ans = 0
    i = 0
    while i < n:
        while i+1<n and a[i]==a[i+1]:
            i += 1
        if i+1<n and a[i] < a[i+1]:
            while i+1<n and a[i]<=a[i+1]:
                i += 1
        elif i+1<n and a[i] > a[i+1]:
            while i+1<n and a[i]>=a[i+1]:
                i += 1
        ans += 1
        i += 1
    print(ans)
            
if __name__ == '__main__':
    main()

Measured memory_bytes: 20476
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
//    cout << x << "\n";
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;

void chmax(ll& x, ll y) {
    if (x < y) x = y;
}

struct UnionFind {
    vector<int> par;

    UnionFind(int n): par(n, -1) {}
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        return par[x] = root(par[x]);
    }

    int issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);

        if (x == y) return false;

        // merge by size
        // force size of x to be bigger than that of y
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;

        return true;
    }

    ll size(int x) {
        return -par[root(x)];
    }
};

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

    ll n, m; cin >> n >> m;

    vector<int> a(m), b(m);
    REP(i, m) cin >> a[i] >> b[i];

    reverse(ALL(a));
    reverse(ALL(b));

    UnionFind uf(n + 1);

    vector<ll> ans(m, 0);
    ans[0] = n * (n - 1) / 2;
    REP(i, m - 1) {
        ll t = uf.size(a[i]) * uf.size(b[i]);
        if (uf.issame(a[i], b[i])) t = 0;
        uf.merge(a[i], b[i]);
        ans[i + 1] = ans[i] - t;
    }

    reverse(ALL(ans));

    for(auto &e: ans) print(e);

}

Measured memory_bytes: 5316