akhauriyash/Code-Regression huggingface dataset:
fn main() {
    let v = read_vec::<u32>();
    let a = v[0];
    let b = v[1];
    let c = v[2];
    let d = v[3];
    println!("{}", std::cmp::max(a * b, c * d));
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long 
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define forn(i, a, b) for (int i=a; i<(signed)(b); ++i)
#define pb push_back
 
 
// debug templates 
#define debug(x)       cerr<< #x <<" : "<< x << endl;
#define debuga(A,N)    cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
#define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}
#define debugp(p)      cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n";
#define debugv(v)      cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n";
#define debugv2(v)     cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[0].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";}
#define debugs(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n";
#define debugm(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n";
 
const int mxN = 1e6 + 7;
int a[mxN],b[mxN];

void solve(){
	int n; cin >> n;
	forn(i,0,n) cin >> a[i];
	sort(a,a+n);
	set<int> dup;
	forn(i,1,n){
		if(a[i] == a[i-1] && dup.find(a[i]) == dup.end()){
			++b[a[i]];
			for(int j = 2*a[i]; j < mxN; j += a[i]){
				++b[j];
			}
			dup.insert(a[i]);
		}
	}
	int ans = 0;
	forn(i,0,n){
		if(b[a[i]]) continue;
		else {
			++ans;
			for(int j = 2*a[i]; j < mxN; j += a[i]){
				b[j] = 1;
			}
		}
	}
	
	cout << ans;
}
 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	solve();
	return 0;
}
 


Measured memory_bytes: 9048
#include<iostream>

int calc(int n){
	
	if(n==1)return 0;
	
	int a=n/3;
	if(n%3!=0)a+=1;
	
	return 1+calc(a);
	
}

int main(){
	
	int n;
	std::cin>>n;
	std::cout<<calc(n)<<std::endl;
	
}

Measured memory_bytes: 1160
def main():
    n = int(input())
    a = list(map(int, input().split()))

    ans = sum(a)
    dict_of_digit = {}
    for a_num in a:
        if a_num not in dict_of_digit.keys():
            dict_of_digit[a_num] = 1
        else:
            dict_of_digit[a_num] += 1

    q = int(input())

    for idx in range(q):
        b, c = map(int, input().split())
        if b in dict_of_digit.keys() and dict_of_digit[b] > 0:
            diff = c - b
            ans += diff * dict_of_digit[b]
            if c not in dict_of_digit.keys():
                dict_of_digit[c] = dict_of_digit[b]
            else:
                dict_of_digit[c] += dict_of_digit[b]
            dict_of_digit[b] = 0
        print(ans)


if __name__ == "__main__":
    main()


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

vector<int> g[50];

int dfs(int v,int a,int b,vector<bool> &visited){
    if(visited[v]) return 0;
    visited[v] = true;
    int cnt=1;
    for(int to : g[v]){
        if((v==a && to==b)||(v==b && to==a))continue;
        cnt += dfs(to,a,b,visited);
    }
    return cnt;
}

int main(void){
    int N,M;
    cin>>N>>M;
    vector<int> a(M),b(M);
    rep(i,M){
        cin>>a[i]>>b[i];
        a[i]--,b[i]--;
        g[a[i]].push_back(b[i]);
        g[b[i]].push_back(a[i]);
    }

    int cnt=0;
    rep(i,M){
        vector<bool> visited(N,false);
        if(dfs(0,a[i],b[i],visited)!=N)cnt++;
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
   public static void main(String[] args) {
     Scanner sc = new Scanner(System.in);
     int r = sc.nextInt();
     int D = sc.nextInt();
     int x = sc.nextInt();
     int ans;
     for(int i = 1;i<=10;i++){
       ans = x*r - D;
       System.out.println(ans);
       x = ans;
     }


   }
}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int n, c;
    cin >> n >> c;
    int N = n + 1;
    vector<int> x(N), y(N), v1(n), v2(n);
    x[0] = y[0] = v1[0] = 0;
    rep(i, n) cin >> x[i + 1] >> v1[i];
    rep(i, n) y[i + 1] = c - x[n - i];
    v2 = v1;
    reverse(all(v2));
    vector<int> a(N), b(N), sum1(N), sum2(N);
    a[0] = b[0] = sum1[0] = sum2[0] = 0;
    rep(i, n)
    {
        sum1[i + 1] = sum1[i] + v1[i];
        sum2[i + 1] = sum2[i] + v2[i];
        a[i + 1] = max(sum1[i + 1] - x[i + 1], a[i]);
        b[i + 1] = max(sum2[i + 1] - y[i + 1], b[i]);
    }
    int ans = 0;
    rep(i, n)
    {
        int tmp = max(sum1[i + 1] - x[i + 1] + max(0LL, b[n - i - 1] - x[i + 1]), sum2[i + 1] - y[i + 1] + max(0LL, a[n - i - 1] - y[i + 1]));
        ans = max(ans, tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 6528
import sys
input = sys.stdin.readline

N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))

ans = 1
min_tmp = 1000

for i in range(N):
  tmp = abs(A - (T - H[i]*0.006))
  if min_tmp > tmp:
    ans = i+1
    min_tmp = tmp

print(ans)


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

#include <boost/heap/fibonacci_heap.hpp>
#define FASTIO
using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

struct Pos {
    ll x, y;
};

void solve() {
    ll H, W, K;
    cin >> H >> W >> K;
    Pos s, t;
    cin >> s.x >> s.y >> t.x >> t.y;
    --s.x, --s.y, --t.x, --t.y;
    vector<Vi> cell(H, Vi(W));
    for (ll i = 0; i < H; i++) {
        string S;
        cin >> S;
        for (ll j = 0; j < W; j++) {
            if (S[j] == '@') cell[i][j] = 1;
        }
    }

    if (cell[s.x][s.y] == 1) {
        cout << -1 << "\n";
        return;
    }

    constexpr Pos step[] = {{1, 0}, {0, -1}, {-1, 0}, {0, 1}};

    using Tup = tuple<ll, ll, ll, ll>;  // cost, x, y, v
    vector<vector<Vl>> dp(H, vector<Vl>(W, Vl(4, L_INF)));
    boost::heap::fibonacci_heap<Tup, boost::heap::compare<greater<Tup>>> q;
    q.emplace(0, s.x, s.y, 0);
    dp[s.x][s.y][0] = 0;
    while (!q.empty()) {
        auto [c, x, y, v] = q.top();
        q.pop();
        if (c > dp[x][y][v])
            continue;
        ll xn, yn;
        ll cn;
        // 前進
        xn = x + step[v].x;
        yn = y + step[v].y;
        if (xn >= 0 && xn < H && yn >= 0 && yn < W) {
            if (cell[xn][yn] == 0) {
                cn = c + 1;
                if (cn < dp[xn][yn][v]) {
                    dp[xn][yn][v] = cn;
                    q.emplace(cn, xn, yn, v);
                }
            }
        }
        // 回転
        v = (v + 1) % 4;
        xn = x;
        yn = y;
        if (xn >= 0 && xn < H && yn >= 0 && yn < W) {
            if (cell[xn][yn] == 0) {
                cn = (c + K - 1) / K * K;
                if (cn < dp[xn][yn][v]) {
                    dp[xn][yn][v] = cn;
                    q.emplace(cn, xn, yn, v);
                }
            }
        }
    }

    ll ans = L_INF;
    for (ll i = 0; i < 4; i++) {
        if (ll tmp = dp[t.x][t.y][i]; tmp != L_INF) {
            ans = min(ans, (tmp + K - 1) / K);
        }
    }

    if (ans != L_INF)
        cout << ans << "\n";
    else
        cout << -1 << "\n";
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

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

vector<vector<int>> X(100'001);
vector<vector<int>> Y(100'001);
vector<bool> x_visited(100'001);
vector<bool> y_visited(100'001);
vector<int> cnt(2);

void dfs(int mode, int v){
    if (mode == 0){//xのほう
        if (x_visited[v]) return;
        x_visited[v] = true;
        cnt[0]++;
        for (int i = 0; i < X[v].size(); i++) dfs(1, X[v][i]);
    }
    if (mode == 1){//yのほう
        if (y_visited[v]) return;
        y_visited[v] = true;
        cnt[1]++;
        for (int i = 0; i < Y[v].size(); i++) dfs(0, Y[v][i]);
    }
}

int main(){
    int n;
    cin >> n;
    vector<pair<int, int>> node;
    for (int i = 0; i < n; i++){
        int x, y;
        cin >> x >> y;
        X[x].push_back(y);
        Y[y].push_back(x);
        node.push_back({0, x});
        node.push_back({1, y});
    }
    long long ans = 0;
    for (int i = 0; i < 2 * n; i++){
        cnt[0] = 0;
        cnt[1] = 0;
        dfs(node[i].first, node[i].second);
        ans += (long long)cnt[0] * cnt[1];
    }
    cout << ans - n << endl;
}

Measured memory_bytes: 12784
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <vector>
#include <climits>
#include <cstring>

typedef long long ll;

using namespace std;

bool checkNum(int n){
    if(n%10 == 3) {
        return true;
    }else if(n < 3){
        return false;
    }else{
        return checkNum(n/10);
    }
}

void solve(){
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++){
        if(i%3 == 0){
            cout << " " << i;
        }else if(checkNum(i)){
            cout << " " << i;
        }
    }
    cout << endl;
}

int main() {
    solve();
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;

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

  int n,m;
  cin >> n;
  bool locked=true;
  string u[n],t;
  for(int i=0;i<n;i++) cin >> u[i];
  cin >> m;
  for(int i=0;i<m;i++){
    cin >> t;
    bool touroku=false;
    for(int j=0;j<n;j++){
      if(t==u[j]) touroku=true;
    }
    if(touroku){
      if(locked) cout << "Opened by " << t << endl;
      else cout << "Closed by " << t << endl;
      locked = !locked;
    }
    else cout << "Unknown " << t << endl;
  }
}

Measured memory_bytes: 3224
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

#define all(vec) vec.begin(),vec.end()
int main(){
    int n,m;cin >> n >> m;

    vector<int> index_of_x(n),index_of_y(n);
    for(int i=0;i<n;i++){
        cin >> index_of_x[i] >> index_of_y[i];
    }
    vector<int> value_of_x = index_of_x,
                value_of_y = index_of_y;

    sort(all(value_of_x));
    sort(all(value_of_y));
    value_of_x.erase(unique(all(value_of_x)),value_of_x.end());
    value_of_y.erase(unique(all(value_of_y)),value_of_y.end());
    for(int i=0;i<n;i++){
        index_of_x[i] = lower_bound(all(value_of_x),index_of_x[i]) - value_of_x.begin();
        index_of_y[i] = lower_bound(all(value_of_y),index_of_y[i]) - value_of_y.begin();
    }
    vector<vector<int>> v(value_of_y.size()+1,vector<int>(value_of_x.size()+1));
    {
        vector<vector<int>> p(value_of_y.size(),vector<int>(value_of_x.size()));
        for(int i=0;i<n;i++){
            p[index_of_y[i]][index_of_x[i]] += 1;
        }
        for(int y=1;y<=value_of_y.size();y++){
            for(int x=1;x<=value_of_x.size();x++){
                v[y][x] = v[y][x-1] + p[y-1][x-1];
            }
        }
        for(int x=0;x<=value_of_x.size();x++){
            for(int y=1;y<=value_of_y.size();y++){
                v[y][x] = v[y-1][x] + v[y][x];
            }
        }

    }

    for(int i=0;i<m;i++){
        int x1,y1,x2,y2;
        cin >> x1 >> y1 >> x2 >> y2;

        int sx = lower_bound(all(value_of_x),x1) - value_of_x.begin();
        int gx = upper_bound(all(value_of_x),x2) - value_of_x.begin();
        int sy = lower_bound(all(value_of_y),y1) - value_of_y.begin();
        int gy = upper_bound(all(value_of_y),y2) - value_of_y.begin();

        int ans = v[gy][gx] - v[sy][gx] - v[gy][sx] + v[sy][sx];
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 196884
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <bitset>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <sstream>
#include <fstream>
#include <string.h>

#define X first
#define Y second
#define MP make_pair
#define FOR(i, n) for(int (i) = 0; (i) < (n); (i)++)
typedef long long ll;
using namespace std;
const int MAX = 101;

template<class T, class U>
void convert(T &t, U &u){
    stringstream ss;
    ss << t;
    ss >> u;
}

int main(){
	int n;
	while(cin >> n && n){
		vector<int> seq(n, 0);
		map<int, int> tb;
		int c = 0;
		FOR(i, n) cin >> seq[i];
		while(1){
			vector<int> seq2(n, 0);
			bool f = true;

			FOR(i, n) tb[seq[i]]++;

			FOR(i, n){
				seq2[i] = tb[seq[i]];
				if(seq2[i]!=seq[i]) f = false;
			}

			if(f){
				cout << c << endl;
				FOR(i, n){
					if(i) cout << " ";
					cout << seq[i];
				}
				cout << endl;
				break;
			}else{
				seq = seq2;
				map<int, int>().swap(tb);
				c++;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 9999999999999999;
using ll = long long;
int main(){
  string s;
  cin>>s;
  int ans = 0;
  int pp = s.size();
  for(int i = 0;i<pp;i++){
    char p = s.at(i);
    int q = p - '0';
    ans += q;
  }
  if(ans%9 == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}
    

Measured memory_bytes: 3716
n=int(input())
a=list(map(int,input().split()))
cnt=0
ans=0
mini=10000000000
for i in a:
    if i<0:
        cnt+=1
    p=abs(i)
    ans+=p
    if p<mini:
        mini=p
if cnt%2==1:
    ans-=mini*2
print(ans)

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

int main(){
	int k, t;
	cin >> k >> t;
	
	vector<int> a(t);
	for(int i = 0; i < t; i++)	cin >> a[i];
	sort(a.begin(), a.end());
	
	int sum = a[t-1];
	for(int i = 0; i < t-1; i++)	sum -= a[i];
	
	cout << max(0, sum-1) << endl;
	
	return 0;
}

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

int gcd(int x,int y){
    return y?gcd(y,x%y):x;
}

int read(){
    int x=0;bool f=0;char c=getchar();
    while(c<'0'||c>'9')f|=c=='-',c=getchar();
    while(c>='0'&&c<='9')x=x*10+(c^48),c=getchar();
    return f?-x:x;
}

int main(){
    int A=read(),B=read(),C=read();
    printf("%d",C-min(A-B,C));
}


Measured memory_bytes: 128
N=int(input())
D=list(map(int,input().split()))
M=int(input())
T=list(map(int,input().split()))
D.sort()
T.sort()

j=0
sw=0
for i in range(M):
    while 1:
      if T[i]==D[j]:
        j+=1
        break
      j+=1
      if j==N:
        sw=1
        break
    if sw==1:
      break
print("NO" if sw==1 else "YES")



Measured memory_bytes: 35420
import itertools
import copy

h, w, k = map(int, input().split())
c = []
ans = 0

def count_black(c):
  cnt = 0
  for i in c:
    cnt += i.count('#')
  return cnt


a = []
b = []

for i in range(h):
  c.append(input())

for i in range(h+1):
  a += list(itertools.combinations(range(h), i))
  
for j in range(w+1):
  b += list(itertools.combinations(range(w), j))

def change_color(d, i, j):
  for y in j:
    for x in range(len(d)):
      d[x] = d[x][:y] + 'r' + d[x][y+1:]
  
  for x in i:
    d[x] = 'r'
    
  return d
    
  
for i in a:
  for j in b:
    d = copy.deepcopy(c)
    d = change_color(d, i, j)
    if count_black(d) == k:
      ans += 1
    
print(ans)

Measured memory_bytes: 71428
#include<iostream>

using namespace std;

int main(){
	
	int high, side;
	
	for (;;){
		cin >> high >> side;
		if (high == 0 && side == 0){
			break;
		}

		for (int i = 0; i < high; i++){
			for (int o = 0; o < side; o++){
				cout << "#";
			}
			if (i != high){
				cout << endl;
			}
		}
		cout << endl;
	}

	

	//system("pause");
	

}


Measured memory_bytes: 3068
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(S: str):
    s = list(S)
    s.sort()
    if ''.join(s) == 'abc':
        ret = YES
    else:
        ret = NO
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
int main() {
  char c[52][52];
  int h,w;
  cin >> h >> w;
  for(int i=0; i<h; i++) {
    for(int j=0; j<w; j++) {
      cin >> c[i][j];
    }
  }
  for(int i=0; i<h; i++) {
    for(int j=0; j<w; j++) {
      if(c[i][j]=='.') {
        continue;
      }
      if(c[i][j]=='#'&&c[i][j-1]=='#') {
        continue;
      }
      else if(c[i][j]=='#'&&c[i][j+1]=='#') {
        continue;
      }
      else if(c[i][j]=='#'&&c[i-1][j]=='#') {
        continue;
      }
      else if(c[i][j]=='#'&&c[i+1][j]=='#') {
        continue;
      }
      else {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}

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

#define all(x) begin(x), end(x)

using i64 = int_fast64_t;
using f64 = double;

constexpr i64 INF = INT_FAST64_MAX / 2;
constexpr f64 EPS = DBL_EPSILON;

void solve() {
    i64 n;
    cin >> n;
    vector<string> ss(n);
    vector<i64> ls(n, -INF), rs(n, -INF);
    vector<i64> pos, neg;
    for (i64 i = 0; i < n; i++) {
        cin >> ss[i];
        i64 m = ss[i].size();

        for (i64 j = 0, lc = 0; j < m; j++) {
            if (ss[i][j] == ')') lc++; else lc--;
            ls[i] = max(ls[i], lc);
        }
        for (i64 j = m - 1, rc = 0; j >= 0; j--) {
            if (ss[i][j] == '(') rc++; else rc--;
            rs[i] = max(rs[i], rc);
        }

        (rs[i] - ls[i] >= 0 ? pos : neg).emplace_back(i);
    }

    sort(begin(pos), end(pos), [&](i64 x, i64 y) { return ls[x] < ls[y]; });
    sort(begin(neg), end(neg), [&](i64 x, i64 y) { return rs[x] > rs[y]; });

    string str;
    for (auto& e : pos) str.append(ss[e]);
    for (auto& e : neg) str.append(ss[e]);

    i64 cnt = 0;
    for (auto& e : str) {
        if (e == '(') cnt++; else cnt--;
        if (cnt < 0) break;
    }

    cout << (cnt != 0 ? "No" : "Yes") << endl;
}

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


Measured memory_bytes: 60784
#include<iostream>
#include<algorithm>
using namespace std;
char  ta[50][50];
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

	void dfs(int y,int x){
		ta[y][x]='0';
		int ny=0,nx=0;
		for(int i=0;i<4;i++){
			ny=y+dy[i],nx=x+dx[i];
			if(ta[ny][nx]=='1')dfs(ny,nx);
		}
	}

int main(){
	while(1){
	for(int i=0;i<50;i++)for(int j=0;j<50;j++)ta[i][j]='0';
	
	for(int i=1;i<13;i++){
	for(int j=1;j<13;j++){
	if(cin>>ta[i][j]);
	else return 0;
	}
	}
	int cnt=0;
	for(int i=1;i<13;i++){
		for(int j=1;j<13;j++){
			if(ta[i][j]=='1'){dfs(i,j);cnt++;}
		}
	}
	cout<<cnt<<endl;
	}
	
	return 0;
}

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

zoro = 0
ans = False
for i in range(N):
    x, y = [int(x) for x in input().split()]
    if x == y:
        zoro += 1
    else:
        zoro = 0
    if zoro >= 3:
        ans = True

if ans:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
int main() {
  int H,W;
  cin >> H >> W;
  vector<vector<char>> M(H, vector<char> (W));
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin >> M[i][j];
    }
  }
  vector<vector<int>> d={
    {-1,-1}, {0,-1}, {1,-1} ,
    {-1,0}, {1,0},
    {-1,1}, {0,1}, {1,1}
  };
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(M[i][j]=='.'){
        int cnt=0;
        for(int k=0;k<8;k++){
          if(i+d[k][1]<0 || i+d[k][1]>H-1) continue;
          if(j+d[k][0]<0 || j+d[k][0]>W-1) continue;
          if(M[i+d[k][1]][j+d[k][0]]=='#'){
            cnt++;
          }
        }
        M[i][j]=char(cnt+'0');
      }
    }
  }
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cout << M[i][j];
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define F first
#define S second
//cout<<fixed<<setprecision(11);
const string nl="\n";
const ll MOD=1000000007;
const ll ARR_MAX = 1e5+1;
const ll INF=1e10+1;

void solve(){
    int n;cin>>n;
    ll dp[n+1]; //dp[i]=minimum cost required to reach rock i-1.
    ll h[n+1];
    // h[0]=0;
    for(int i=0;i<n;i++){
    	cin>>h[i];
    	dp[i+1]=INF;
    }
    dp[0]=0;
    for(int i=0;i<n;i++){
    	dp[i+1]=min(dp[i+1],dp[i]+max(h[i+1]-h[i],h[i]-h[i+1]));
    	dp[i+2]=min(dp[i+2],dp[i]+max(h[i+2]-h[i],h[i]-h[i+2]));
    }
    cout<<dp[n-1]<<nl;
}

int main(){
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
using namespace std;
using ll = long long;

int main(){
	int n;
	cin >> n;
	vector<ll> a(n);
	for(int i=0;i<n;i++){
		cin >> a.at(i);
	}
	set<ll> a2(a.begin(),a.end());
	if(a2.size() == n){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
}


Measured memory_bytes: 13704
n, x, m = map(int,input().split())
rem = [0] * m
chk = [0] * (m + 1)
rem[0] = x
if x == 0:
  print(0)
  exit()

for i in range(1,m):
  rem[i] = (rem[i - 1] ** 2) % m
  if chk[rem[i - 1] ** 2 % m] > 1:
    temp1 = (rem[i - 1] ** 2) % m
    temp2 = i
  else:
    temp1 = (rem[i - 1] ** 2) % m
    temp2 = i

for i in range(m):
  if rem[i] == temp1:
    temp3 = i
    break

if temp2 != temp3:
  num = (n - temp3) // (temp2 - temp3)
  S = sum(rem[:temp3]) + sum(rem[temp3:temp2]) * num + sum(rem[temp3:n - (num * (temp2 - temp3))])
  print(S)
else:
  print(sum(rem))

Measured memory_bytes: 14356
#include <iostream>
#include <vector>
#define llint long long

using namespace std;

llint n;
llint a[] = {2, 5, 63, 20};
vector<llint> vec[6], vec2;

int main(void)
{
	cin >> n;
	
	if(n <= 4){
		for(int i = 0; i < n; i++) cout << a[i] << " ";
		cout << endl;
		return 0;
	}
	
	for(int i = 1; i <= 30000; i++){
		if(i%2==0 || i%3==0) vec[i%6].push_back(i);
	}
	//for(int i = 0; i < 6; i++) cout << vec[i].size() << endl;
	for(int i = 0; i < 5000; i++){
		vec2.push_back(vec[2][i]);
		vec2.push_back(vec[4][i]);
	}
	for(int i = 0; i < 5000; i++){
		vec2.push_back(vec[3][i]);
	}
	vec2.insert(vec2.begin(), vec[3][4999]);
	vec2.insert(vec2.begin(), vec[3][4998]);
	vec2.pop_back();
	vec2.pop_back();
	
	if(n <= 15000){
		for(int i = 0; i < n/2*2; i++){
			cout << vec2[i] << " ";
		}
		if(n % 2) cout << vec[0][0];
		cout << endl;
		return 0;
	}
	for(int i = 0; i < vec2.size(); i++) cout << vec2[i] << " ";
	for(int i = 0; i < n-15000; i++) cout << vec[0][i] << " ";
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 896
#include <stdio.h>
#include<math.h>

int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    if((a==1&&b==2)||(a==2&&b==1))
        printf("3");
    if((a==1&&b==3)||(a==3&&b==1))
        printf("2");
    if((a==3&&b==2)||(a==2&&b==3))
        printf("1");
    return 0;
}


Measured memory_bytes: 128
def gcd(x, y):
    while y > 0:
        x, y = y, x%y
    return x

while True:
    N = int(input())
    if not N:
        break
    a = [list(map(int, input().split())) for _ in [0]*N]
    root = (set(range(1, N+1)) - set(n for bar in a for n in bar[2:])).pop()

    def solve(ratio_r, ratio_l, left, right):
        d = gcd(ratio_r, ratio_l)
        ratio_r //= d
        ratio_l //= d

        w_left = solve(*a[left-1]) if left else 0
        w_right = solve(*a[right-1]) if right else 0

        if w_left == w_right == 0:
            w_left, w_right = ratio_l, ratio_r
        elif w_left == 0:
            w_right = (w_right * ratio_r) // gcd(w_right, ratio_r)
            w_left = ratio_l * (w_right // ratio_r)
        elif w_right == 0:
            w_left = (w_left * ratio_l) // gcd(w_left, ratio_l)
            w_right = ratio_r * (w_left // ratio_l)
        else:
            _r, _l = w_left*ratio_r, w_right*ratio_l
            d = gcd(_l, _r)
            w_right, w_left = w_right*(_r // d), w_left*(_l // d)

        return w_right + w_left

    print(solve(*a[root-1]))


Measured memory_bytes: 5652
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
using P = pair<int,int>;
vector<int> point;
vector<vector<int>> ki;
void dfs(int now,int last = -1){

    for(int next:ki[now]){
        if (next == last)continue;
        point[next] += point[now];
        dfs(next,now);
    }

}
int main()
{
    int n,q;
    cin >> n >>  q;
    
    
    ki.resize(n);
    point.resize(n);
    rep(i,n-1){
        int a,b;

        cin >> a >> b;
        a--,b--;
        ki[a].push_back(b);
        ki[b].push_back(a);
    }
    
    rep(i,q){
        int p,x;
        cin >> p >> x;
        p--;
        point[p] += x;

    }
    dfs(0);
    rep(i,n){
        cout << point[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 23424
/* Karen {{{
  ___  ____
 |_  ||_  _|
   | |_/ /    ,--.   _ .--.  .---.  _ .--.
   |  __'.   `'_\ : [ `/'`\]/ /__\\[ `.-. |
  _| |  \ \_ // | |, | |    | \__., | | | |
 |____||____|\'-;__/[___]    '.__.'[___||__]
}}} */
// include {{{
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <math.h>
#include <string>
#include <vector>
#include <complex>
#include <iostream>
#include <algorithm>

using namespace std;

// }}}
/* cpp template {{{*/


#define endl '\n'

#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPS(i, a, n) for (int i = (a); i < (n); i++)
#define RREP(i, n) for (int i = 1; i <= (n); i++)

typedef double D;      // 座標値の型。doubleかlong doubleを想定
typedef long long ll;
typedef long double lb;
typedef complex<D> P;  // Point
typedef pair<P, P> L;  // Line
typedef vector<P> VP;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;
typedef pair<int, string> pis;
typedef pair<string, int> psi;

inline bool inside(int y, int x, int H, int W){return (y >= 0 && x >= 0 && y < H && x < W);}
inline int in() {int x; std::cin >> x; return x;}

template <typename T>
void print(std::vector<T>& v, char c = ' ') {
  REP(i, v.size()) {
    if (i != 0) std::cout << c;
    std::cout << v[i];
  }
  std::cout << endl;
}
template <typename T>
void print(T x) {
  std::cout << x << '\n';
}

/* 定数 */
const ll MOD = 1e9 + 7;
const ll INF = 1e9 + 9;
const D EPS  = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};


/* }}} */

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

  ll a = in(), b = in();

  if (a * b <= 0){
    cout << "Zero" << endl;
  }else if (a > 0 && b > 0){
    cout << "Positive" << endl;
  } else if ((a - b) % 2 == 0){
    cout << "Negative" << endl;
  } else {
    cout << "Positive" << endl;
  }
  
  return (0);
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6;
int d()
{
    int ret;
    scanf("%d", &ret);
    return ret;
}
long long lld()
{
    long long ret;
    scanf("%lld", &ret);
    return ret;
}
bool cmp(pair<int, int> s, pair<int, int> f)
{
    if (f.first > s.first)
        return true;
    else if (f.first == f.second && f.second < s.second)
        return true;
    else
        return false;
}
long long arr[N],n;
bool IsCover(long long d){
    long long lastcover=-1,used=0;
    for(int i=0;i<n;i++){
        if(arr[i]>lastcover){
        lastcover=arr[i]+(2*d);
        used++;
        }

    }
    return used<=3;
}
long long PS(){
    long long hi=1e5,lo=0,mid;
    while(hi-lo > 0){
        mid=(lo+hi)/2;
        if(IsCover(mid))hi=mid;
        else lo=mid+1;
    }
    return lo;
}
char num1[106],num2[106];
bool flag=false;
int main(){
scanf("%s",num1);
scanf("%s",num2);
int n1=strlen(num1);
int n2=strlen(num2);
if(n1>n2)
printf("GREATER\n");
else if(n2>n1)
printf("LESS\n");
else{

for(int i=0;i<n1;i++){
    if(num1[i]-'0' > num2[i]-'0'){
    printf("GREATER\n");
    flag=1;
    break;
    }
    else if(num1[i]-'0' < num2[i]-'0'){
    printf("LESS\n");
    flag=1;
    break;
    }
}
if(flag==0)
printf("EQUAL\n");

}

}


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

int main(){
    int N;
    string A, B, C;
    cin >> N >> A >> B >> C;
    int ans = 0;
    for(int i=0; i<N; i++){
        if(A[i] == B[i] && B[i] == C[i]) continue;
        if(A[i] != B[i] && B[i] != C[i] && C[i] != A[i]) ans+=2;
        else ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stack>
#include <algorithm>
#include <random>
#include <iomanip>
#include <unordered_map>
#include <map>
#include <queue>
#include <functional>
#include <numeric>
#include <chrono>
#include <cstdlib>
using ll = long long;
using namespace std;

const ll MOD = 1e9 + 7;
//const double EPS = 1e(-12);
const double pi = acos(-1);
typedef pair<int, int> P;
#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define EPS 1e-4
#define OUTPUT(i) (cout << (ll)i << endl)
#define ALL(a) ((a).begin(), (a).end())

bool operator<(const pair<ll, ll> &a, const pair<ll, ll> &b)
{

    if (a.first == b.first)
        return a.second < b.second;

    return a.first < b.first;
}

int arr[1010];
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(10);

    ll N, M;
    cin >> N >> M;
    ll ans = 0;
    if (M > 2 * N)
    {
        ans = N;
        M -= 2 * N;
    }
    else
    {
        cout << M / 2 << endl;
        return 0;
    }

    ans += M / 4;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <numeric>
#include <functional>
#include <math.h>

using namespace std;

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

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)


int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    int K, X;
    cin >> K >> X;
    for (int i = X-K+1; i <= X+K-1; ++i) {
        cout << i << ' ';
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <iomanip> 

using ll = long long;
using ull = unsigned long long;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;(i) < ((int)(n));++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

// const int dx[4] = { 1, 0, -1, 0 };
// const int dy[4] = { 0, 1, 0, -1 };

const int dx[8] = {1, 1, 0,-1,-1,-1, 0, 1};
const int dy[8] = {0, 1, 1, 1, 0,-1,-1,-1};

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline void print(T&& x){cout<<x<<endl;}// 改行付き出力
template<typename T>inline T SUM(vector<T> vec){return accumulate(all(vec),(T)0);} // vectorの中身を全部足す
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
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; }
int ctoi(char c){return c-'0';}


// TODO: write
int main() {
  int n;cin>>n;
  vector<int> a(n+1);rep(i,n+1)cin>>a[i];
  vector<int> b(n);rep(i,n)cin>>b[i];
  ll ans = 0;
  rep(i,n){
    ans += min(a[i],b[i]);
    b[i] -= min(a[i],b[i]);
    ans += min(a[i+1],b[i]);
    a[i+1] -= min(a[i+1],b[i]);
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 4012
H, W, K = map(int,input().split())

mod = 1000000007
fibonacci = [1,1,2,3,5,8,13,21]
Amida = [ [0] * W for h in range(H+1)]

for h in range(H+1):
    if W == 1:
        break
    for w in range(W):
        if h == 0:
            if w == 0:
                Amida[h][w] = 1
            else:
                break
        elif w == 0:
            Amida[h][w] = fibonacci[W-2] * Amida[h-1][w+1] + fibonacci[W-1] * Amida[h-1][w]
        elif w == W-1:
            Amida[h][w] = fibonacci[W-2] * Amida[h-1][w-1] + fibonacci[W-1] * Amida[h-1][w]
        else:
            Amida[h][w] += (fibonacci[w-1] * fibonacci[W-w-1] * Amida[h-1][w-1])
            Amida[h][w] += (fibonacci[w] * fibonacci[W-w-1] * Amida[h-1][w])
            Amida[h][w] += fibonacci[w] * fibonacci[W-w-2] * Amida[h-1][w+1]
        Amida[h][w] = Amida[h][w] % 1000000007

if W == 1:
    if K == 1:
        print(1)
    else:
        print(0)
else:
    print(Amida[H][K-1])

Measured memory_bytes: 3064
import collections
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n,p= map(int, input().split())
s=list(input())
mod=0
ans=[]
count=0

if p==2 or p==5:
    for i in range(n):
        if p==2 and s[n-1-i] in {'0', '2' ,'4','6' ,'8'}:
            count+=n-i
        elif p==5 and s[n-1-i] in {'0','5'}:
            count+=n-i
    print(count)
    exit()

s+='0'

for i in range(n+1):
    if s[n-i]!=0:
        mod+=(pow(10,i,p)*int(s[n-i]))%p
        mod%=p
    ans.append(mod)

ans = collections.Counter(ans)
ans=ans.most_common()
for i in range(len(ans)):
    if ans[i][1]>=2:
        count+=combinations_count(ans[i][1],2)

print(count)

Measured memory_bytes: 69676
#include<bits/stdc++.h>
using namespace std;
     
#define int long long
#define hell 1000000007  
#define endl "\n"
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define MAX_SIZE 1000001


int32_t main()
{   
    io
    int n;
    cin>>n;

    cout<<n*n*n;    

return 0;
}

Measured memory_bytes: 256
#include<string>
#include<vector>
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<functional>
#include<algorithm>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<utility>
#include<cmath>
#include<ctime>
#include<complex>

using namespace std;

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

int main(){

	int n;
	cin >> n;

	rep(i,n){

	vector<int>v;
	int d=0;
	char k;

	rep(j,8){
	cin >> k;
	v.push_back(k-'0');
	}

	sort(v.begin(),v.end());

	rep(l,8) d+=pow(10.0,l)*(v[l]-v[7-l]);

	cout << d << endl;

	v.clear(); d=0;

	}




	return 0;
}

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


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long  n,i,j,k,cnt=0;
    cin>>n;
    long long  a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(i=1;i<n;i++)
    {
        if(a[i]<a[i-1])
        {
            cnt+=a[i-1]-a[i];
            a[i]=a[i-1];
        }
    }
    cout<<cnt<<endl;


}


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

const string YES = "Yes";
const string NO = "No";

void solve(long long N, std::vector<std::string> W){
  map<string, bool> list;
  list[W[0]] = true;

  REP(i,N-1){
    if(list.count(W[(i+1)]) > 0) goto err;
    if(W[i].back() != W[(i+1)].front()) goto err;

    list[W[(i+1)]] = true;
  }

  cout << YES << endl;
  return;
  err:
  cout << NO << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
  scanf("%lld",&N);
  std::vector<std::string> W(N);
  for(int i = 0 ; i < N ; i++){
    std::cin >> W[i];
  }
    solve(N, std::move(W));
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	char c;
	int a, b;
	
	scanf("%d %c %d", &a, &c, &b);
	if(c == '+') {
		printf("%d", a + b);
	}
	else {
		printf("%d", a - b);
	}
	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

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



int main() {
    int n, m, x, a;
    
    cin >> n >> m >> x;
    
    int t1 = 0, t2 = 0;
    REP(i, m){
        cin >> a;
        
        if(a < x){
            t1++;
        }
        else{
            t2++;
        }
    }
    
    cout << min(t1, t2) << endl;
}

Measured memory_bytes: 256
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define ll long long
#define INF 1e9
#define MOD 1e9 + 7
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, a, n) for (int i = a; i < n; i++)
#define all(in) in.begin(), in.end()

string rev(string s) {
    string rev_s = "";
    for (int i = s.size() - 1; i >= 0; i--) rev_s += s[i];
    return rev_s;
}
int main() {
    int m;
    cin >> m;
    for (int querry = 1; querry <= m; querry++) {
        string S;
        cin >> S;
        set<string> train;
        int len = S.size();
        for (int i = 0; i < len; i++) {
            string left = "", right = "";
            for (int k = 0; k < i; k++) {
                left += S[k];
            }
            for (int k = i; k < len; k++) {
                right += S[k];
            }
            train.insert(left + right), train.insert(right + left);
            train.insert(rev(left) + right), train.insert(right + rev(left));
            train.insert(left + rev(right)), train.insert(rev(right) + left);
            train.insert(rev(left) + rev(right));
            train.insert(rev(right) + rev(left));
        }
        cout << (int)train.size() << endl;
    }
    return 0;
}


Measured memory_bytes: 3272
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const long Mod = 1000000007;
    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
        //MyDebugger.Test(process, "../TextFile2.txt");
        //MyDebugger.MakeTestCase("../TextFile2.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var spl   = input.ReadLine().Split(' ');
        var a     = long.Parse(spl[0]);
        var b     = long.Parse(spl[1]);
        var k     = long.Parse(spl[2]);

        var aa = Math.Max(a - k, 0);
        k = Math.Max(k - a, 0);
        var bb = Math.Max(b - k, 0);

        return aa + " " + bb;
    }
}

Measured memory_bytes: 11092
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1 for _ in range(n)]  # 各要素の親 自分が根の場合は -1 * (木の要素数)

    def root(self, x):  # xが属する木の根を返す
        if self.parents[x] < 0:  # 自分が根の場合
            return x
        else:
            self.parents[x] = self.root(self.parents[x])
            return self.parents[x]

    def merge(self, x, y):  # xが属する木とyが属する木を合体する
        x_root = self.root(x)  # xの根
        y_root = self.root(y)  # yの根

        if x_root == y_root:  # 同じ木に属する
            return

        if self.parents[x_root] > self.parents[y_root]:  # x_rootの要素数 > y_rootの要素数 にする
            x_root, y_root = y_root, x_root

        self.parents[x_root] += self.parents[y_root]
        self.parents[y_root] = x_root


def main():
    h, w = map(int, input().split())
    grid = [list(input()) for _ in range(h)]
    black_list = []
    uf = UnionFind(h * w)

    for r in range(h):
        for c in range(w):
            if grid[r][c] == "#":
                black_list.append([r, c])
            for dr, dc in [[0, 1], [1, 0]]:
                nr = r + dr
                nc = c + dc
                if not (0 <= nr < h and 0 <= nc < w):
                    continue
                if grid[r][c] != grid[nr][nc]:
                    uf.merge(r * w + c, nr * w + nc)

    ans = 0
    black_dict = dict()
    for r, c in black_list:
        z = uf.root(r * w + c)
        if z in black_dict:
            black_dict[z] += 1
        else:
            black_dict[z] = 1

    for index, num in enumerate(uf.parents):
        if num < 0:
            if index not in black_dict:
                continue
            ans += black_dict[index] * (- num - black_dict[index])

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 108620
#abc174_e

n,k=map(int,input().split())
a=[int(i) for i in input().split()]
    
ok=1001001001
ng=0
def check(x):
  cnt=0
  for q in a:
    cnt+=(q-1)//x
  return cnt<=k

while ok-ng>1:
  mid=(ok+ng)//2
  if check(mid):
    ok=mid
  else:
    ng=mid
print(ok)


Measured memory_bytes: 104188
import sys
input = sys.stdin.readline

import numpy as np

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

def solve(N,M,A,B):
    grid = np.full((N,M),'.',dtype='U1')
    put_row = np.full((N,M-1),10**9,dtype=np.int32)
    if N%2 == 0:
        for n in range(0,M//2):
            put_row[:,n+n] = np.arange(N*n,N*(n+1))
    elif M%2 == 0:
        # N-1行目を埋めたあと、2個ずつ
        put_row[-1,::2] = np.arange(M//2)
        x = M//2
        for n in range(M//2):
            put_row[:-1,n+n] = np.arange(x,x+N-1)
            x += N-1
    else:
        # N-1行目を右優先で埋めたあと、左上から
        put_row[-1,1::2] = np.arange(M//2)
        x = M//2
        for n in range(M//2):
            put_row[0,n+n] = x
            put_row[1:-1,n+n+1] = np.arange(x+1,x+N-1)[::-1]
            x += N-1
    # 置くべき優先度を定義し終わった
    x,y = np.where(put_row < A)
    if len(x) != A:
        print('NO')
        return
    grid[x,y] = '<'
    grid[x,y+1] = '>'
    # 空きます
    put_col = (grid == '.')
    # 下も空いている（上側としておける）
    put_col[:-1] &= put_col[1:]
    put_col[-1] = 0
    for n in range(1,N):
        # ひとつ上から置けるならやめる
        put_col[n] &= ~put_col[n-1]
    x,y = np.where(put_col)
    x = x[:B]; y = y[:B]
    if len(x) != B:
        print('NO')
        return
    grid[x,y] = '^'
    grid[x+1,y] = 'v'
    print('YES')
    print('\n'.join(''.join(row) for row in grid))
    return

solve(N,M,A,B)

Measured memory_bytes: 33080
from sys import stdin

char = stdin.readline().rstrip()

for i,c in enumerate(char):
    if i %2 ==0:
        if c not in ("R",'U','D'):
            print('No')
            break
    else:
        if c not in ("L",'U','D'):
            print('No')
            break
else:
    print('Yes')

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

int main(){
    int N;
    cin >> N;
    map<int, int> a;
    for (int i = 0; i < N; i++){
        int tmp;
        cin >> tmp;
        a[tmp] = i;
    }
    cout << a.size() << endl;
}

Measured memory_bytes: 256
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

typedef long long int64;
typedef pair<int, int> ii;

int main() {
  int lenA, lenB, m;
  scanf("%d%d%d", &lenA, &lenB, &m);
  vector<int64> a(lenA), b(lenB);
  for (int i = 0; i < lenA; ++i) {
    scanf("%lld", &a[i]);
  }
  for (int i = 0; i < lenB; ++i) {
    scanf("%lld", &b[i]);
  }
  while (m--) {
    int64 x;
    scanf("%lld", &x);
    int a2 = lower_bound(a.begin(), a.end(), x) - a.begin();
    int a1 = a2 - 1;
    int b2 = lower_bound(b.begin(), b.end(), x) - b.begin();
    int b1 = b2 - 1;
    int64 ret = 1LL << 60;
    if (a2 < lenA && b2 < lenB) {
      ret = min(ret, (a[a2] - x) + abs(a[a2] - b[b2]));
      ret = min(ret, (b[b2] - x) + abs(a[a2] - b[b2]));
    }
    if (a1 >= 0 && b1 >= 0) {
      ret = min(ret, (x - a[a1]) + abs(a[a1] - b[b1]));
      ret = min(ret, (x - b[b1]) + abs(a[a1] - b[b1]));
    }
    if (a2 < lenA && b1 >= 0) {
      ret = min(ret, (a[a2] - x) + abs(a[a2] - b[b1]));
      ret = min(ret, (x - b[b1]) + abs(a[a2] - b[b1]));
    }
    if (a1 >= 0 && b2 < lenB) {
      ret = min(ret, (x - a[a1]) + abs(a[a1] - b[b2]));
      ret = min(ret, (b[b2] - x) + abs(a[a1] - b[b2]));
    }
    printf("%lld\n", ret);
  }
  return 0;
}


Measured memory_bytes: 2816
#include<stdio.h>
#include<stdlib.h>

struct node
{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};

typedef struct node * Node;

Node root,NIL;
int maxh;

Node treeSearch(Node u,int k)
{
  while(u!=NIL&& k!=u->key)
    {
      if(k<u->key) u=u->left;
      else u=u->right;
    }
  return u;
}

void insert(int k)
{
  int H;
  Node y=NIL;
  Node x=root;
  Node z;

  z=malloc(sizeof(struct node));
  z->key=k;
  z->left=NIL;
  z->right=NIL;

  while(x!=NIL)
    {
      y=x;
      if(z->key < x->key)
        {
          x=x->left;
        }
      else
        {
          x=x->right;
        }
    }

  z->parent =y;
  if(y==NIL)
    {
      root=z;
    }
  else
    {
      if(z->key<y->key)
        {
          y->left=z;
        }
      else

{
          y->right=z;
        }
    }
}

void inorder(Node u)
{
  if(u==NIL)return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}

void preorder(Node u)
{
  if(u==NIL)return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}

int main()
{
  int n,i,x;
  char com[20];
  scanf("%d",&n);
  maxh =0;
  for(i=0;i<n;i++)
    {
      scanf("%s",com);
      if(com[0]=='f')
	{
	  scanf("%d",&x);
	  Node t=treeSearch(root,x);
	  if(t!=NIL) printf("yes\n");
	  else printf("no\n");
	}
      else if(com[0]=='i')
	{
	  scanf("%d",&x);
	  insert(x);
	}
      else if(com[0]=='p')
	{
	  inorder(root);
	  printf("\n");
	  preorder(root);
	  printf("\n");
	}
    }
    
  return 0;
}



Measured memory_bytes: 20552