akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>
#include<deque>
#include<list>


using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;
const int BIG_INT = 1000000000;



int main() {
	int n, k;
	cin >> n >> k;


	ll ans = 0;
	vector<ll> facto(2 * n + 1);
	vector<ll> inv_mod(2 *n + 1);
	vector<ll> inv_facto(2 *n + 1);

	facto[0] = 1;
	inv_mod[1] = 1;
	inv_facto[0] = 1;
	for (int i = 1; i <= 2*n;i++) {
		facto[i] = (i * facto[i - 1]) % MOD_CONST;
	}
	for (int i = 2; i <=2 * n;i++) {
		inv_mod[i] = (MOD_CONST - (inv_mod[MOD_CONST%i] * (MOD_CONST / i)) % MOD_CONST) % MOD_CONST;
	}
	for (int i = 1; i <= 2 *n;i++) {
		inv_facto[i] = (inv_facto[i - 1] * inv_mod[i]) % MOD_CONST;
	}

	for (int i = 0; i < min(n,k+1);i++) {
		ll sum = (facto[n] * inv_facto[n - i]) % MOD_CONST;
		sum = (sum * inv_facto[i]) % MOD_CONST;
		sum = (sum * facto[n -1]) % MOD_CONST;
		sum = (sum * inv_facto[i]) % MOD_CONST;
		sum = (sum * inv_facto[n -i-1]) % MOD_CONST;
		
		ans = (ans + sum) % MOD_CONST;
	}
	cout << ans << endl;
}



Measured memory_bytes: 9600
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<map>
#include<algorithm>
#include<set>
#include<deque>
#include<queue>
#include<stack>
#include<bitset>
#include<list>
#include<vector>
#include<forward_list>
#include<array>
#define ll long long
#define ull unsigned long long
#define lowbit(x) (x&(-x))
#define inf 0x3f3f3f3f
#define IOS std::ios::sync_with_stdio(false)
#define undocin cin.tie(NULL)
using namespace std;
const int maxn=3e5+7;
const int maxm=2e6+7;
int Read(){
	int out=0,flag=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')flag=-1;c=getchar();}
	while(c>='0'&&c<='9'){out=out*10+c-'0';c=getchar();}
	return flag*out;
}
ll MOD=1e9+7,cnt[maxn];
int main()
{
	ll a,n,ans=0;
	cin>>n;
	for(ll i=1;i<=n;i++)
	{
		cin>>a;
		for(ll j=0;j<62;j++)
		{
			if(a&(1LL<<j))
			cnt[j]++;
		}
	}
	for(ll i=0;i<62;i++)
	{
		ans=(ans+((cnt[i]*(n-cnt[i]))%MOD*((1LL<<i)%MOD)%MOD)%MOD)%MOD;
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

	int N, M;
	cin >> N;
	map<string, int> s, t;
	set<string> v;
	rep(i, 0, N) {
		string tmp_s;
		cin >> tmp_s;
		s[tmp_s]++;
		v.insert(tmp_s);
	}

	cin >> M;
	rep(i, 0, M) {
		string tmp_t;
		cin >> tmp_t;
		s[tmp_t]--;
	}

	ll rsl = -1e9;
	for(set<string>::iterator it = v.begin(); it != v.end(); it++) {
		if(rsl < s[*it]) {
			rsl = s[*it];
		}
	}
	if(rsl < 0) cout << 0 << endl;
	else cout << rsl << endl;

}


Measured memory_bytes: 256
#include <string>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <utility>
#include <algorithm>
#include <numeric>
#include <iostream>

using namespace std;
template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

int calc(int l,int r,int ope)
{
	if(ope == 0) return l+r;
	else if(ope == 1) return l-r;
	else return l*r;
}

char o[] = "+-*";
int i,j,k;

const char * solve(int a[4]){
	sort(a,a+4);

	do{
		for (i = 0; i < 3; i++){
			for (j = 0; j < 3; j++){
				for (k = 0; k < 3; k++){
					if(calc(calc(calc(a[0],a[1],i),a[2],j),a[3],k) == 10)
						return "(((%d %c %d) %c %d) %c %d)\n";
					else if(calc(calc(a[0],a[1],i),calc(a[2],a[3],k),j) == 10)
						return "((%d %c %d) %c (%d %c %d))\n";
					else if(calc(calc(a[0],calc(a[1],a[2],j),i),a[3],k) == 10)
						return "((%d %c (%d %c %d)) %c %d)\n";
					else if(calc(a[0],calc(calc(a[1],a[2],j),a[3],k),i) == 10)
						return "(%d %c ((%d %c %d) %c %d))\n";
					else if(calc(a[0],calc(a[1],calc(a[2],a[3],k),j),i) == 10)
						return "(%d %c (%d %c (%d %c %d)))\n";
				}
			}
		}
	}while(next_permutation(a,a+4));

	return "0\n";
}

int main()
{
	int a[4];
	while(cin>>a[0]>>a[1]>>a[2]>>a[3],a[0]||a[1]||a[2]||a[3]){
		const char *format = solve(a);
		printf(format,a[0],o[i],a[1],o[j],a[2],o[k],a[3]);
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] v = new int[n];
        for (int i = 0; i < n; i++) {
            v[i] = in.nextInt();
        }
        Map<Integer, Integer> odds = new HashMap<>();
        Map<Integer, Integer> evens = new HashMap<>();

        int replacements = 0;

        for (int i = 0; i < n; i += 2) {
            odds.put(v[i], odds.getOrDefault(v[i], 0) + 1);
        }

        for (int i = 1; i < n; i += 2) {
            evens.put(v[i], evens.getOrDefault(v[i], 0) + 1);
        }

        int bestOdd = v[0];
        int bestOddVal = odds.get(bestOdd);
        for (int key : odds.keySet()) {
            if (odds.get(key) > odds.get(bestOdd)) {
                bestOdd = key;
                bestOddVal = odds.get(key);
            }
        }
        int bestEven = v[1];
        int bestEvenVal = evens.get(bestEven);
        for (int key : evens.keySet()) {
            if (evens.get(key) > evens.get(bestEven)) {
                bestEven = key;
                bestEvenVal = evens.get(key);
            }
        }

        if (bestOdd == bestEven) {
            if (odds.size() <= 1 && evens.size() <= 1) {
                System.out.println(n / 2);
                return;
            }
            if (odds.size() > 1 && evens.size() > 1) {
                odds.remove(bestOdd);
                evens.remove(bestEven);
                int secondBestOdd = Collections.max(odds.values());
                int secondBestEven = Collections.max(evens.values());
                if (secondBestOdd > secondBestEven) {
                    bestOddVal = secondBestOdd;
                }
                else {
                    bestEvenVal = secondBestEven;
                }
            }
            else if (odds.size() <= 1) {
                evens.remove(bestEven);
                bestEvenVal = Collections.max(evens.values());
            }
            else {
                odds.remove(bestOdd);
                bestOddVal = Collections.max(odds.values());
            }
        }

        replacements += (n + 1) / 2 - bestOddVal;
        replacements += n / 2 - bestEvenVal;

        System.out.println(replacements);
    }
}


Measured memory_bytes: 55912
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<iomanip>
#include<map>
#include<cstring>

using namespace std;

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

int main(){
    int N;cin >> N;
    int dp[100001];//dp[i] : i円作るための最小枚数
    rep(i, N + 1)dp[i] = N;
    dp[0] = 0;

    for(int i = 0;i <= N;++i){
        for(int pow6 = 1;pow6 + i <= N;pow6*=6){
            dp[i + pow6] = min(dp[i + pow6], dp[i] + 1);
        }
        for(int pow9 = 1;pow9 + i <= N;pow9*=9){
            dp[i + pow9] = min(dp[i + pow9], dp[i] + 1);
        }
    }
    cout << dp[N] << endl;
}


Measured memory_bytes: 640
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

cnt = 0
for i, b in enumerate(B):
    if A[i] < b:
        cnt += A[i]
        delta = b - A[i]
        if A[i+1] < delta:
            cnt += A[i+1]
            A[i+1] = 0
        else:
            cnt += delta
            A[i+1] -= delta
    else:
        cnt += b

print(cnt)

Measured memory_bytes: 18476
import * as process from "process";
import * as readline from "readline";

process.stdin.resume();
process.stdin.setEncoding('utf8');

let lines = []
let reader = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

reader.on('line', line => {
    lines.push(line);
});

reader.on('close', () => {
    let [k, s] = lines[0].split(" ").map(s => parseInt(s));
    let ans = 0;
    for (let x of Array.from(Array(k + 1).keys())) {
        for (let y of Array.from(Array(k + 1).keys())) {
            let z = s - x - y;
            if (0 <= z && z <= k) {
                ans++;
            }
        }
    }
    console.log(ans);
});

Measured memory_bytes: 14780
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define INF 9223372036854775807
#define pairint pair<int,int>

signed main()
{
int x=0,y=0,z=0,w=0,n=0,m=2001,a=0,b=0;
string s;
std::cin >> s;
rep(i,s.size()){
  if(i%2==0){
    if(s[i]!='R'&&s[i]!='U'&&s[i]!='D'){
      std::cout << "No"<< '\n';
      return 0;
    }
  }else{
    if(s[i]!='L'&&s[i]!='U'&&s[i]!='D'){
      std::cout << "No"<< '\n';
      return 0;
    }
  }
}
std::cout << "Yes" << '\n';
return 0;
}


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

int main(){
  
  int n, l, r, sum = 0;
  cin >> n;
  
  for(int i = 0; i < n; i++){
    cin >> l >> r;
    sum += r - l + 1;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;
const int MAX_N = 20;

int main(){
  int N, p[MAX_N]; cin >>N;
  for(int i = 0; i < N; i++) cin >>p[i];
  int cnt = 0;
  for(int i = 1; i < N - 1; i++){
    if((p[i - 1] < p[i] && p[i] < p[i + 1]) || (p[i - 1] > p[i] && p[i] > p[i + 1])) cnt++;
  }
  cout <<cnt <<endl;
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python

n, k = map(int, input().split())
a = list(map(int ,input().split()))

def check(x):
    now = 0 
    for i in range(n):
        now += (a[i]-1)//x
    return now <= k

l = 0 
r = int(1e9)
while r-l > 1:
    mid = (l+r)//2

    if check(mid):
        r = mid 
    else:
        l = mid 

print(r)

Measured memory_bytes: 30688
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int a = scanner.nextInt();
    int b = scanner.nextInt();
    int c = scanner.nextInt();
    int d = scanner.nextInt();

    int area1 = a * b;
    int area2 = c * d;

    // 三項間演算子
    // 式(boolean) ? 答え1 : 答え2
    int maxArea = area1 >= area2 ? area1 : area2;
    System.out.println(maxArea);
  }
}


Measured memory_bytes: 35712
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
#define int long long
signed main() {
	int n; cin >> n;
	int m = 1001, sum = 0;;
	for (int i = 0; i < n; i++) {
		int a; cin >> a;
		sum += a;
		if (a % 2)m = min(m, a);
	}
	if (sum % 2)sum -= m;
	cout << sum / 2 << endl;
}


Measured memory_bytes: 3104
def f(n):
    if n % 2:
        return 3 * n + 1
    else:
        return n // 2


s = int(input())

already_exist = [s]
a = s
cnt = 1
while f(a) not in already_exist:
    a = f(a)
    already_exist.append(a)
    cnt += 1

print(cnt + 1)


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(r) (r).begin(), (r).end()

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; }
const long long INF = 1LL<<60;

int N;
long long W, weight[110], value[110];
long long dp[110][100100] = {0};

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

    rep(i, N) {
        rep(sum_w, W+1) {
            if (sum_w - weight[i] >= 0)
                chmax(dp[i+1][sum_w], dp[i][sum_w - weight[i]] + value[i]);

            chmax(dp[i+1][sum_w], dp[i][sum_w]);
        }
    }

    cout << dp[N][W] << endl;
}


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

using namespace std;

#define forn(i, n) for (int64_t i = 0; i < (int64_t) (n); ++i)
#define endl '\n'

template<typename T> void _dbg(const char*_s,T _h) { cerr<<_s<<" = "<<_h<<"\n"; }

template<typename T, typename... Ts> void _dbg(const char*_s,T _h,Ts... _t) {
    for(int _b=0;((_b+=*_s=='(')-=*_s==')')!=0||*_s!=',';)cerr<<*_s++;
    cerr<<" = "<<_h<<",";_dbg(_s+1,_t...);
}

#define int long long

#ifdef LOCAL
    #define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
    #define dbg(...)
#endif

const int N = 500 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

string s;

bool read() {
    if (!(cin >> s))
        return false;

    return true;
}

void solve() {
    map<char, string> mp;
    mp['S'] = "Cloudy";
    mp['C'] = "Rainy";
    mp['R'] = "Sunny";
    cout << mp[s[0]] << endl;
}

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

    while (read())
        solve();

    return 0;
}



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

int main() {
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(abs(a-c)<=d){
    cout<<"Yes"<<endl;
  }
  else if(abs(a-b)<=d&&abs(b-c)<=d){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
n=int(input())
a=[]
for i in range(n):
  b=int(input())
  a.append(b)
s=a.copy()
a=sorted(a,reverse=True)

if a[0]==a[1]:
  for i in range(n):
    print(a[0])
  exit()
for i in range(n):
  if s[i]==a[0]:
    print(a[1])
  else:
    print(a[0])

Measured memory_bytes: 14876
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 1e5 + 10;
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int x, a, b;
	cin >> x >> a >> b;
	if (b <= a) puts("delicious");
	else if (b <= x + a) puts("safe");
	else puts("dangerous");
	return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

type UnionFindTree struct {
	par   []int // 親
	rank  []int // 木の深さ
	count int   // 要素数
}

func NewUnionFindTree(count int) *UnionFindTree {
	par := make([]int, count)
	rank := make([]int, count)
	for i := 0; i < count; i++ {
		par[i] = i
		rank[i] = 0
	}
	return &UnionFindTree{par: par, rank: rank, count: count}
}

func (uf UnionFindTree) Find(x int) int {
	if uf.par[x] == x {
		return x
	} else {
		uf.par[x] = uf.par[uf.par[x]]
		return uf.Find(uf.par[x])
	}
}

func (uf *UnionFindTree) Unit(x, y int) {
	x = uf.Find(x)
	y = uf.Find(y)
	if x == y {
		return
	} else if uf.rank[x] < uf.rank[y] {
		uf.par[x] = y
	} else {
		uf.par[y] = x
		if uf.rank[x] == uf.rank[y] {
			uf.rank[x]++
		}
	}
}

func (uf UnionFindTree) Same(x, y int) bool {
	return uf.Find(x) == uf.Find(y)
}

type Point struct {
	pos int
	idx int
}

type ByPos []Point

func (b ByPos) Len() int {
	return len(b)
}

func (b ByPos) Less(i, j int) bool {
	return b[i].pos < b[j].pos
}

func (b ByPos) Swap(i, j int) {
	b[i], b[j] = b[j], b[i]
}

type Adjacent struct {
	distance int
	a        int
	b        int
}

type ByDistance []Adjacent

func (b ByDistance) Len() int {
	return len(b)
}

func (b ByDistance) Less(i, j int) bool {
	return b[i].distance < b[j].distance
}

func (b ByDistance) Swap(i, j int) {
	b[i], b[j] = b[j], b[i]
}

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

	N := nextInt()
	xP := make([]Point, N)
	yP := make([]Point, N)
	ut := NewUnionFindTree(N)

	for i := 0; i < N; i++ {
		xP[i] = Point{pos: nextInt(), idx: i}
		yP[i] = Point{pos: nextInt(), idx: i}
	}
	sort.Sort(ByPos(xP))
	sort.Sort(ByPos(yP))

	adj := make([]Adjacent, (N-1)*2)
	for i := 0; i < N-1; i++ {
		adj[2*i] = Adjacent{
			distance: xP[i+1].pos - xP[i].pos,
			a:        xP[i].idx,
			b:        xP[i+1].idx,
		}

		adj[2*i+1] = Adjacent{
			distance: yP[i+1].pos - yP[i].pos,
			a:        yP[i].idx,
			b:        yP[i+1].idx,
		}
	}
	sort.Sort(ByDistance(adj))

	ans := 0
	for i := 0; i < (N-1)*2; i++ {
		if !ut.Same(adj[i].a, adj[i].b) {
			ans += adj[i].distance
			ut.Unit(adj[i].a, adj[i].b)
		}
	}

	fmt.Println(ans)

}


Measured memory_bytes: 13312
import java.util.List;
import java.util.Scanner;

public class Main {

	static Scanner scanner;

	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    int n=gi();
	    int k=gi();
	    String S=gs();
	    StringBuilder sb=new StringBuilder();
	    for (int i=0; i<n;i++) {
	    	if(i==k-1) {
	    		String a=S.substring(i, i+1).toLowerCase();
	    		sb.append(a);
	    	} else {
	    		sb.append(S.charAt(i));
	    	}
	    }


	   
	    System.out.print(sb.toString());

//        if (a>b) {
//        	c+=a;
//        	a--;
//        	System.out.print(c+Math.max(a, b));
//        }else {
//        	c+=b;
//        	b--;
//        	System.out.print(c+Math.max(a, b));
//        }


	}
	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35612
MOD = 10 ** 9 + 7


def main():
    h, w, k = map(int, input().split())

    if w == 1:
        print(1)
        exit()

    cnt, valid = [0] * (w-1), []
    for i in range(2**(w-1)):
        c = [0] * (w-1)
        for j in range(w-1):
            if (i >> j) & 1:
                c[j] = 1

                if 0 < j and c[j-1] == 1:
                    break

        else:
            valid.append(c)
            for j in range(w-1):
                if c[j] == 1:
                    cnt[j] += 1

    num, ans = len(valid), 0
    for v in valid:
        dp = [[0] * w for i in range(h + 1)]
        if v[0]:
            dp[1][1] += 1
        else:
            dp[1][0] += 1

        for i in range(2, h+1):
            for j in range(w):
                com = num
                if 0 < j:
                    dp[i][j] = (dp[i][j]+dp[i-1][j-1]*cnt[j-1]) % MOD
                    com -= cnt[j-1]
                if j < w - 1:
                    dp[i][j] = (dp[i][j]+dp[i-1][j+1]*cnt[j]) % MOD
                    com -= cnt[j]
                dp[i][j] = (dp[i][j]+dp[i-1][j]*com) % MOD

        ans = (ans+dp[h][k-1]) % MOD

    print(ans)


if __name__ == '__main__':
    main()


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

// image
// 1 2 3 4 5 6 7 8 9 10 11 12 13 14
// x x x i x x x o o o  i  o  o  o

int main()
{
    int N, D;
    cin >> N >> D;

    int sum = 0;
    for (int i = 1; i <= N; i++)
    {
        sum = sum + (2 * D);
        sum++;
        if (sum >= N)
        {
            cout << i << endl;
            break;
        }
    }

    return (0);
}

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

int main(){
    while(true){
        int n;
        string str[1000];
        int nest[1000];
        cin >> n;
        if(!n) break;
        cin >> str[0];
        for(int i=1;i<n;++i){
            cin >> str[i];
            nest[i] = str[i].rfind('.');
            str[i][nest[i]] = '+';
            str[i].replace(0, nest[i], nest[i], ' ');
        }
        for(int i=n-2;i>0;--i){
            for(int j=0;j<min(nest[i],nest[i+1]+1);++j){
                if(str[i+1][j]=='+' || str[i+1][j]=='|') str[i][j]='|';
            }
        }
        for(int i=0;i<n;++i){
            cout << str[i] << endl;
        }
    }
}

Measured memory_bytes: 1996
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<set>
#include<map>
#include<queue>
#include<cstring>
#include<sstream>
using namespace std;

typedef long long ll;

int table[100010];

int main() {
  int N,M; cin >> N >> M;
  for ( int i = 0; i < M; i++ ) {
    int L,R; cin >> L >> R;
    table[L]++;
    table[R+1]--;
  }

  for ( int i = 1; i <= N; i++ ) {
     table[i] += table[i-1];
  }
  int ans = 0;
  for ( int i = 1; i <= N; i++ ) {
    if ( table[i] == M ) ans++;
  }

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


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	x=0;char c=getchar();bool f=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return  x;
}
template<class t> inline void write(t x){
	if(x<0){putchar('-'),write(-x);}
	else{if(x>9)write(x/10);putchar('0'+x%10);}
}

const int N=17;
int n,ans,a[N],x[N][N],y[N][N];

bool check(int s){
	for(int i=0;i<n;i++) if(s>>i&1)
		for(int j=1;j<=a[i];j++) if((s>>x[i][j]&1)!=y[i][j])
			return 0;
	return 1;
}

int count(int x){
	int ans=0;
	while(x){
		if(x&1) ans++;
		x>>=1;
	}
	return ans;
}

signed main(){
	read(n);
	for(int i=0;i<n;i++){
		read(a[i]);
		for(int j=1;j<=a[i];j++)
			read(x[i][j]),read(y[i][j]),x[i][j]--;
	}
	int lim=1<<n;
	for(int s=0;s<lim;s++) if(check(s)) ans=max(ans,count(s));
	write(ans);
}

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

int main()
{
    int n;
    cin >> n;
    int i = 1;
    int go = 0;
    while (true) {
        go += i;
        if (go >= n) {
            cout << i;
            return 0;
        }
        i++;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=2e8+5;
char s[N],t[N];
int n,m,xx,yy,nex[N];
void kmp_init()
{
    int i=1,k=0;
    while(i<=xx*m)
        if(k==0||t[i]==t[k]) nex[++i]=++k;
    else k=nex[k];
}
int main()
{
    scanf("%s%s",s+1,t+1);
    n=strlen(s+1);m=strlen(t+1);
    xx=50000000/m;
    for(int j=1;j<xx;j++)
    for(int i=1;i<=m;i++)
        t[i+m*j]=t[i];
    kmp_init();
    int ans=0,p=m*xx/n;
    int now=0,pos=0;
    m*=xx;
    for(int l=1;l<=p;l++)
    {
        for(int i=1;i<=n;i++)
        {
            pos++;
            now++;
            while(pos&&t[pos]!=s[i])
            {
                now-=pos-nex[pos];
                pos=nex[pos];
            }
            if(pos==0) now=0;
            if(pos==m)
                pos=0;
            ans=max(ans,now);
        }
    }
    m/=xx;
    if(ans==n*p||ans>=n*(p-1)) printf("-1\n");
    else printf("%d\n",ans/m);
}


Measured memory_bytes: 252160
#include <bits/stdc++.h>
#include <climits>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define srep(i, begin, end) for (__typeof(end) i = begin; i != end; i++)
#define si(x) int x = scanInt();
#define sll(x) LL x = scanLong();
#define sci(x) int x; scanf("%d", &x);
#define scll(x) LL x; scanf("%lld", &x);
#define pi(x) printf("%d ", x)
#define pll(x) printf("%lld ", x)
#define nl printf("\n")
#define clr(a) memset(a, 0, sizeof(a))
#define PB push_back
#define MP make_pair
using namespace std;
typedef unsigned int UI; // 32 bit integer
typedef long int LI; // 32 bit integer
typedef unsigned long int ULI; // 32 bit unsigned integer
typedef long long int LL; // 64 bit integer
typedef unsigned long long int ULL; // 64 bit unsigned integer
typedef long double LD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef deque<int> DI;
typedef deque<LL> DLL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
const LL MOD = 1e9+7;

/* Fast I/O */
inline int scanInt() {
	int n = 0;
	char ch = getchar();
	int sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(int)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

inline LL scanLong() {
	LL n = 0;
	char ch = getchar();
	LL sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(LL)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

const LL MAXN = 1e6+10;
LL dp[MAXN];

int main() {
	string s; cin >> s;
	reverse(s.begin(), s.end());
	LL n = s.length();
	LL carry = 0;
	LL ans = 0;
	rep(i, 0, n) {
		LL digit = (s[i] - '0') + carry;
		carry = (digit / 10);
		digit %= 10;

		if(digit < 5)	ans += digit;
		else if(digit > 5) {
			carry++;
			ans += (10 - digit);
		}
		else if(digit == 5 && (i+1 < n) && (s[i+1]-'0') >= 5) {
			carry = 1;
			ans += (10 - digit);
		}
		else if(digit == 5) {
			ans += digit;
		}
	}

	if(carry != 0)	ans += carry;

	pll(ans); nl;
}


Measured memory_bytes: 1412
#include <stdio.h>

int n, a[20];

int solve(int i, int m) {
  if (m == 0)
    return 1;
  if (i >= n)
    return 0;
  int res = solve(i + 1, m) || solve(i + 1, m - a[i]);
  return res;
}

int main(void) {
  int q, m, i;

  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]);

  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%d", &m);
    if (solve(0, m) == 1)
      printf("yes\n");
    else
      printf("no\n");
  }

  return 0;
}



Measured memory_bytes: 2096
#include <iostream>
#include <bits/stdc++.h>
typedef long long ll;
#define lp(i,n) for(ll i = 0;i < ll(n);i++)
#define rlp(i,n) for(ll i = ll(n);i >= 0;i--)
#define rg(i,a,b) for(ll i = ll(a);i <= ll(b);i++)
#define wh(t) while(t)
#define re return
#define pb push_back
#define sz(s) (ll)(s.size())
#define fx(n) fixed<<setprecision(n)
#define NeverGiveUp ios::sync_with_stdio(0), ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
/*freopen("input.txt","r", stdin);
	freopen("output.txt","w", stdout);*/
using namespace std;
/*ll mx = INT_MIN;
ll mn = INT_MAX;*/
/*ll xd,dx[4]={1,0,-1,0};
ll yd,dy[4]={0,1,0,-1};
bool valid(ll xd,ll yd,ll n,ll m){return xd>-1&&xd<n&&yd>-1&&yd<m;}*/
const int sz = 2e6+5;
const ll md = 1e9+7;
//ll lcm(ll a,ll b){return a*b/__gcd(a,b);}
ll n,ans=1,c,num;map<ll,ll>mp;
int main()
{
    NeverGiveUp
    cin>>n;
    rg(i,2,n){
        num=i;
        for(ll j=2;j<=num;j++){
            while(!(num%j)){
                num/=j;
                mp[j]++;
            }
        }
    }
    for(int i=0;i<=1000;i++){
        ans=(ans*(mp[i]+1))%md;
    }
    cout<<ans;
    re 0;
}


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

int main(void)
{
   string s;
   getline(cin,s); //1行読み込む
   for(int i = 0; i < s.size(); i++){
           char c = s[i];
           if('A' <= c && c <= 'Z'){
             //c = tolower(c);
             c = c + 32;
           }
           else if ('a' <= c && c <= 'z'){
               c = c - 32;
           }
           cout << c;
   }
   cout << endl;
}


Measured memory_bytes: 3172
#include <iostream>
using namespace std;
int a , b , c ;
int main(void){
     cin >> a >> b >> c ;
     long long ans = 0 ;
     while(true){
          if(a % 2 == 0 && b % 2 == 0 && c % 2 == 0){
               int d , e , f ;
               d = a/2 ; e = b/2 ; f = c/2 ;
               a = e + f ; b = d + f ; c = d + f ;
               ans++ ;
               
               if(ans == 100000000){
                    ans = -1 ;
                    break ;
               }
               
          }
          else{
               break ;
          }
     }
     
     cout << ans << endl ;
    
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#define llint long long

using namespace std;

int N;
string s[100005];
llint cnt[5];

int main(void)
{
	cin >> N;
	for(int i = 0; i < N; i++) cin >> s[i];
	
	
	for(int i = 0; i < N; i++){
		if(s[i][0] == 'M') cnt[0]++;
		if(s[i][0] == 'A') cnt[1]++;
		if(s[i][0] == 'R') cnt[2]++;
		if(s[i][0] == 'C') cnt[3]++;
		if(s[i][0] == 'H') cnt[4]++;
	}
	
	llint ans = 0;
	for(int i = 0; i < 5; i++){
		for(int j = 0; j < 5; j++){
			if(i >= j) continue;
			for(int k = 0; k < 5; k++){
				if(j >= k) continue;
				ans += cnt[i]*cnt[j]*cnt[k];
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6144
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <stdbool.h>
typedef long long LL;
typedef long double Lf;
#define in (void)scanf
#define Rep(i,a,n)for(int i=(int)(a);i<(int)(n);i++)
//#define Rep(i,a,n)for(LL i=(LL)(a);i<(LL)(n);i++)
#define rep(i,n)Rep(i,0,n)
#define Repp(i,l,r,k)for(int i=(int)(l);i<(int)(r);i+=(int)(k))
//#define Repp(i,l,r,k)for(LL i=(LL)(l);i<(LL)(r);i+=(LL)(k))
#define Ma(x,y) ((x)>(y)?(x):(y))
#define mi(x,y) ((x)<(y)?(x):(y))
#define MOD 1000000007//998244353,1000000007,1000000009,4999999999999997
int upi(const void* a, const void* b) { return*(int*)a<*(int*)b ? -1 : *(int*)a> * (int*)b ? 1 : 0; }
int downi(const void* a, const void* b) { return*(int*)a<*(int*)b ? 1 : *(int*)a> * (int*)b ? -1 : 0; }
void sortupi(int* a, int n) { qsort(a, n, sizeof(int), upi); } //1,2,3,4,...
void sortdowni(int* a, int n) { qsort(a, n, sizeof(int), downi); }
int upLL(const void* a, const void* b) { return*(LL*)a<*(LL*)b ? -1 : *(LL*)a> * (LL*)b ? 1 : 0; }
int downLL(const void* a, const void* b) { return*(LL*)a<*(LL*)b ? 1 : *(LL*)a> * (LL*)b ? -1 : 0; }
void sortupLL(LL* a, int n) { qsort(a, n, sizeof(LL), upLL); }
void sortdownLL(LL* a, int n) { qsort(a, n, sizeof(LL), downLL); }
int cmp_char(const void* a, const void* b) { return *(char*)a - *(char*)b; } // a,b,c,d
int cmp_str(const void* a, const void* b) { return strcmp(*(const char**)a, *(const char**)b); } // aaa,aab
LL gcd(LL p, LL q) { while (q) { LL t = p % q; p = q; q = t; }return p; }
LL modpow(LL a,LL n,int m){LL x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
#define invmodpow(b,p)modpow(b,p-2,p)// a/b≡a*b^{-1}(mod p)...return b^{-1}(mod p)
typedef struct fac { LL n, exp; }F;
LL fact(LL n,F*a){LL x,i,j,c=0;x=n;for(i=2;i*i<=x;i++){for(j=1;x%i==0;j++)x/=i;if(j>1){a[c].n=i;a[c++].exp=j-1;}}if(x-1){a[c].n=x;a[c++].exp=1;}return c;}
//snippet



#define N 1000009

void run() {
	int n, a[N], g;
	in("%d", &n);
	rep(i, n) {
		in("%d", &a[i]);
		if (!i)g = a[i];
		else g = gcd(a[i], g);
	}
	if (g - 1) {
		printf("not coprime\n");
		return;
	}

	int d[N] = { 0 };
	rep(i, n) {
		F f[20];
		int c = fact(a[i], f);
		rep(j, c)d[f[j].n]++;
	}
	rep(i, N)if (d[i] > 1) {
		printf("setwise coprime\n");
		return;
	}
	printf("pairwise coprime\n");
}

int main() {
	int test = 1;
//	in("%d", &test);
	while (test--) {
		run();
	}
}

Measured memory_bytes: 9472
<?php
$N = (int)fgets(STDIN);
$c = trim(fgets(STDIN));

$ans = 0;

while ($c !== '') {
    $c = remove($c);
}

echo $ans;





function remove($str) {
    global $ans;
    $len = strlen($str);
    $i = 0;
    while($i < $len) {
        if ($str[$i] === 'W') {
            break;
        }
        ++$i;
    }

    $str = substr($str, $i);

    /*if (!$str) {
        return '';
    }*/

    $i = strlen($str);
    while($i > 0) {
        if ($str[$i - 1] === 'R') {
            break;
        }
        --$i;
    }

    $str = substr($str, 0, $i);

    /*if (!$str) {
        return '';
    }*/

    if ($str[0] === 'W' && $str[strlen($str) - 1] === 'R') {
        $ans += 1;
        $str = substr($str, 1, strlen($str) - 2);
    }

    return $str;
}

Measured memory_bytes: 16640
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <random>
#include <algorithm>

using namespace std;

#define INF 1e9
#define MAXN 100005
#define MAXM 100005
#define MOD 1000000007
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pii pair<int, int>

int D;
vi C, S[370], T, V, cost;

int calc_minus(int day){
    int res = 0;
    rep(i, 26){
        res += C[i] * (day - cost[i]); 
    }
    return res;
}

int calc_S(vi t){
    ll ans = 0;
    cost.resize(26, 0);

    rep(i, D){
        ans += S[i][t[i]-1];
        cost[t[i]-1] = i+1;
        ans -= calc_minus(i+1);
    }

    return ans;
}

int get_max_c(int day){
    int res = -1, tmp = 0;

    rep(i, 26){
        if(tmp < S[day][i] + C[i]){
            res = i;
            tmp = S[day][i] + C[i];
        }
    }

    return res;
}

void solve(){
    int Score = calc_S(T);

    rep(k, 100000){
        int tmpd = rand() % D;
        int tmpc = rand() % 26 + 1;
        int tmpScr;

        swap(T[tmpd], tmpc);
        tmpScr = calc_S(T);

        if(Score >= tmpScr){
            swap(T[tmpd], tmpc);
        } else {
            Score = tmpScr;
            // cout << Score << endl;
        }
    }

    rep(i, D) cout << T[i] << endl;
}

int main(){
    cin >> D;
    C.resize(26);
    T.resize(D, 1);
    
    
    rep(i, 26){
        cin >> C[i];
    }   

    rep(i, D){
        S[i].resize(26);
        rep(j, 26) cin >> S[i][j];
    }

    solve();
}


Measured memory_bytes: 3672
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>

using namespace std;

int main(){

	string A;
	string B;
	string C;

	cin >> A >> B >> C;

	if(A[A.length()-1] == B[0] && B[B.length() - 1] == C[0]){
		cout << "YES";
	}else{
		cout << "NO";
	}


	return 0;

}


Measured memory_bytes: 256
# N泊したい
N = int(input())

# 最初のK泊までは、1泊あたりX円
# K+1泊以降では、1泊あたりY円
K = int(input())
X = int(input())
Y = int(input())

# 最初のK伯までの宿泊費を計算
# K泊以内の場合は、全部X円/泊で計算
first = min(K,N) * X

# K泊以降の宿泊費を計算
if N-K >0:
    # 超えた分だけY円/泊で計算
    after = (N-K) * Y
else:
    # K泊以内なら追加費用なし
    after = 0

# 答えを出力
print(first + after)

Measured memory_bytes: 38256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
#define G() Cr=getchar()
int Xr;char Cr;
inline int rd(){   //读入优化
	Xr=0,G();
	while(Cr<'0'||Cr>'9')G();
	while(Cr>='0'&&Cr<='9')Xr=(Xr<<3)+(Xr<<1)+Cr-'0',G();
	return Xr;
}
#define MAX_N 100002
int n,va[MAX_N];
int L,q,l,r,ans;
int lg[20],dp[MAX_N][20]; 
int main(){
	n=rd();
	for(int i=1;i<=n;i++)va[i]=rd();
	L=rd();
	lg[0]=1;
	for(int i=1;i<=16;i++)lg[i]=lg[i-1]<<1; // 预处理 2^i
	
	int t=0;
	for(int i=1;i<=n;i++){
		while(va[t+1]-va[i]<=L&&t<n)t++;
		dp[i][0]=t;
	}
	
	for(int k=1;k<=16;k++){
		for(int i=1;i<=n;i++){
			dp[i][k]=dp[ dp[i][k-1] ][k-1];
		}
	}
	
	q=rd();
	while(q--){
		l=rd(),r=rd();
		if(l>r)swap(l,r);
		ans=0;
		for(int i=16;i>=0;i--)if(dp[l][i]<r)l=dp[l][i],ans+=lg[i];
		printf("%d\n",ans+1);
	}
}

Measured memory_bytes: 9088
N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = input()
memo = [""]*N
ans = 0
for i in range(N):
    if i >= K:
        if T[i] == "r":
            if memo[i-K] == "p":
                if i+K <= N-1:
                    memo[i] = T[i+K]
            else:
                memo[i] = "p"
                ans += P
        elif T[i] == "s":
            if memo[i-K] == "r":
                if i+K <= N-1:
                    memo[i] = T[i+K]
            else:
                memo[i] = "r"
                ans += R
        else:
            if memo[i-K] == "s":
                if i+K <= N-1:
                    memo[i] = T[i+K]
            else:
                memo[i] = "s"
                ans += S
    else:
        if T[i] == "r":
            memo[i] = "p"
            ans += P
        elif T[i] == "s":
            memo[i] = "r"
            ans += R
        else:
            memo[i] = "s"
            ans += S
print(ans)



Measured memory_bytes: 43504
n, m = map(int, input().split())
s_list, c_list = [], []
for _ in range(m):
    s, c = map(int, input().split())
    s_list.append(s)
    c_list.append(str(c))

ans = []
for _ in range(n):
    ans.append('0')

for s, c in zip(s_list, c_list):
    if ans[s-1] == '0':
        ans[s-1] = c
    elif ans[s-1] == c:
        pass
    else:
        print(-1)
        exit()

int_ans = int(''.join(ans))
if len(list(str(int_ans))) == n:
    print(int_ans)
else:
    if not(1 in s_list) and ans[0] == '0':
        ans[0] = '1'
        print(int(''.join(ans)))
    else:
        print(-1)

Measured memory_bytes: 3064
//
// Created by Undefined on 2018/2/2.
//

#include <iostream>

using namespace std;

int main() {
    int a, b, count;
    while (cin >> a >> b) {
        count = 0;
        a += b;
        while (a) {
            a /= 10;
            count++;
        }
        cout << count << endl;
    }
    return 0;
}


Measured memory_bytes: 3088
#C
N,M = map(int,input().split())
PY = []

for i in range(M):
    p,y = map(int,input().split())
    PY.append([p,y,i])
    
ans = 0
PY.sort()
ans = ["" for i in range(M)]
count = 0
old = 0
for py in PY:
    p,y,i = py
    if old == p:
        city = p
        num = count
        sc = str(city)
        sn = str(num)
        while len(sc) < 6:
            sc = "0"+sc
        while len(sn) < 6:
            sn = "0"+sn
        ans[i] = sc+sn
        count+=1
    else:
        count = 1
        old = p
        city = p
        num = count
        sc = str(city)
        sn = str(num)
        while len(sc) < 6:
            sc = "0"+sc
        while len(sn) < 6:
            sn = "0"+sn
        ans[i] = sc+sn
        count+=1
        
for i in range(M):
    print(ans[i])
    





Measured memory_bytes: 31556
/*Made by Shivam Solanki*/
#include<bits/stdc++.h> 
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define ll long long int
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<pii> vp;
typedef vector<pll> vpll;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef set<int> sii;
typedef set<ll> sll;
typedef priority_queue<int> pq;
typedef unordered_map<int,int> umii;
typedef unordered_map<ll,ll> umll;
typedef queue<int> qii;
#define rep(i,k,n) for (int i = k; i < n; ++i) 
#define repr(i,k,n) for (int i = n; i>=k; --i)
#define repll(i,k,n) for (ll i = k; i < n; ++i) 
#define repllr(i,k,n) for (ll i = n; i >= k; --i) 
#define pb push_back
#define mp make_pair
#define gcd __gcd
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const int INF = 1e9+5;
const int MOD = 1e9+7;

void solve(){
    int a[3][3];
    rep(i,0,3){
        rep(j,0,3) cin>>a[i][j];
    }
    int q;
    cin>>q;
    while(q--){
        int x;
        cin>>x;
        rep(i,0,3){
            rep(j,0,3){
                if(x==a[i][j]) a[i][j]=0;
            }
        }
    }
    //check rows
    bool flag=0;
    rep(i,0,3){
        int ctr=0;
        rep(j,0,3){
            if(a[i][j]==0) ctr++;
        }
        if(ctr==3) flag=1;
    }
    //check columns
    rep(i,0,3){
        int ctr=0;
        rep(j,0,3){
            if(a[j][i]==0) ctr++;
        }
        if(ctr==3) flag=1;
    }
    //check left diagonal
    int ctr=0;
    rep(i,0,3){
        if(a[i][i]==0) ctr++;
    }
    if(ctr==3) flag=1;
    ctr=0;
    rep(i,0,3){
        if(a[i][2-i]==0) ctr++;
    }
    if(ctr==3) flag=1;
    cout<<(flag?"Yes\n":"No\n");
} 
 
  
int main(){
    // #ifndef ONLINE_JUDGE  
        // freopen("input.txt", "r", stdin); 
        // freopen("output.txt", "w", stdout); 
    // #endif 
    fastio;
    int t=1;
    // cin>>t;
    while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <stdio.h>
#include <iostream>
using namespace std;
using ll = long long;


int main(){
    ll A,B;
    bool b1 = true;
    cin >> A >> B;
    string str;
    cin >> str;
    for (int i=0;i<=A+B;i++){
        if((i==A && str[i] != '-')||(i != A && str[i]=='-')){
        b1 = false;
        }
    }
    if (b1 == true){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
def main():
    s = input()
    t = input()
    n, m = len(s), len(t)
    LCS = [[0]*(m+1) for i in range(n+1)]
    # LCS[i][j] is the longest common subsequence of strings s[0...i] and t[0...j]
    for i in range(1, n+1):
        for j in range(1, m+1):
            if s[i-1] == t[j-1]:
                LCS[i][j] = LCS[i-1][j-1] + 1
            else:
                LCS[i][j] = max(LCS[i-1][j], LCS[i][j-1])
    ans = ""
    i, j = n, m
    while i > 0 and j > 0:
        if s[i-1] == t[j-1]:
            ans += s[i-1]
            i -= 1
            j -= 1
        elif LCS[i][j-1] > LCS[i-1][j]:
            j -= 1
        else:
            i -= 1
    print(ans[::-1])


if __name__ == "__main__":
    main()


Measured memory_bytes: 111452
S = input()
K = int(input())
if K <= 100:
  ans = 1
  for i in range(K):
    if S[i] == '1':
      continue
    ans = S[i]
    break
  print(ans)
else:
  for si in S:
    if si == '1':
      continue
    ans = si
    break
  print(ans)

Measured memory_bytes: 3060
//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<set>
#include<ctime>
#include<vector>
#include<cmath>

using namespace std;
typedef long long ll;
const int MAXN = 20005;

char s[MAXN];
int n, k;
int t1[MAXN], t2[MAXN], c[MAXN];
int _rank[MAXN], height[MAXN], sa[MAXN];

bool cmp(int *r, int a, int b, int l) { return r[a] == r[b] && r[a + l] == r[b + l]; }

void da(char str[], int sa[], int rank[], int height[], int n, int m) {
    n++;
    int i, j, p, *x = t1, *y = t2;
    for (i = 0; i < m; i++)c[i] = 0;
    for (i = 0; i < n; i++)c[x[i] = str[i]]++;
    for (i = 1; i < m; i++)c[i] += c[i - 1];
    for (i = n - 1; i >= 0; i--)sa[--c[x[i]]] = i;
    for (j = 1; j <= n; j <<= 1) {
        p = 0;
        for (i = n - j; i < n; i++)
            y[p++] = i;
        for (i = 0; i < n; i++)
            if (sa[i] >= j)
                y[p++] = sa[i] - j;
        for (i = 0; i < m; i++)c[i] = 0;
        for (i = 0; i < n; i++)c[x[y[i]]]++;
        for (i = 1; i < m; i++)c[i] += c[i - 1];
        for (i = n - 1; i >= 0; i--)
            sa[--c[x[y[i]]]] = y[i];
        swap(x, y);
        p = 1;
        x[sa[0]] = 0;
        for (i = 1; i < n; i++) x[sa[i]] = cmp(y, sa[i - 1], sa[i], j) ? p - 1 : p++;
        if (p >= n)break;
        m = p;
    }
    int k = 0;
    n--;
    for (i = 0; i <= n; i++)rank[sa[i]] = i;
    for (i = 0; i < n; i++) {
        if (k)k--;
        j = sa[rank[i] - 1];
        while (str[i + k] == str[j + k])k++;
        height[rank[i]] = k;
    }
}

int getRepeatTimes(int l, int len) {
    int res = l;
    while (height[res] >= len && res <= n) res++;
    return res - l + 1;
}

/**
 * ÅÐ¶ÏÊÇ·ñÓÐ³€¶ÈÎªlenµÄÖØžŽkŽÎŒ°ÒÔÉÏµÄµÄ×ÓŽ®
 * @param len
 * @return
 */
bool repeatsMoreThanK(int len) {
    int l = 2;
    while (l <= n) {
        if (height[l] >= len) {
            int times = getRepeatTimes(l, len);
            if (times >= k)
                return true;
            l += times - 1;
        } else ++l;
    }
    return false;
}

bool repeatsMoreThanK(int n, int k) {
    int maxi = -1, mini = 0x3f3f3f3f;
    for (int i = 1; i <= n; ++i) {
        if (height[i] < k)
            maxi = sa[i], mini = sa[i];
        else {
            maxi = max(maxi, max(sa[i], sa[i - 1]));
            mini = min(mini, min(sa[i], sa[i - 1]));
            if (maxi - mini >= k) return true;
        }
    }
    return false;
}

int main() {
    k = 2;
    scanf("%d", &n);
    scanf("%s", s);
    s[n] = 0;
    da(s, sa, _rank, height, n, 128);
    int ans = 0, l = 1, r = n;
    while (l <= r) {
        int mid = (l + r) >> 1;
        if (repeatsMoreThanK(n, mid))
            ans = mid, l = mid + 1;
        else
            r = mid - 1;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

int main(){
    int n, sum = 0;
    cin >> n;
    vector<int> v(n);
    for(int i=0; i<n; i++) cin >> v[i];

    for(int i=0; i<n; i++){
        for(int j=i; j<n; j++){
            if(max(v[i], v[j]) == v[j]){
                swap(v[i], v[j]);
            }
        }
        // cout << v[i] << endl;
    }

    for(int i=0; i<n; i++) {
        if(i % 2 == 0) sum += v[i];
        else sum -= v[i];
    }

    cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
#define zero(x) memset(x, 0, sizeof(x))
#define negative(x) memset(x, ~0, sizeof(x))
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main(int argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  ll ans = 0;
  ll n, x;
  cin >> n;
  // ll n, m;
  // cin >> n >> m;
  // ll n, m, k;
  // cin >> n >> m >> k;
  map<ll, ll> m;
  fi(0, n) {
    cin >> x;
    m[x]++;
  }
  vector< pair<ll, ll> > v;
  for(auto x: m) {
    if(x.second >= 2) {
      v.push_back(x);
    }
  }
  sort(all(v), greater< pair<ll, ll> >());
  if(v.size() == 0) {
    ans = 0;
  }
  else if(v.size() == 1) {
    if(v[0].second >= 4) {
      ans = v[0].first * v[0].first;
    }
    else {
      ans = 0;
    }
  }
  else {
    if(v[0].second >= 4) {
      ans = v[0].first * v[0].first;
    }
    else
      ans = v[0].first * v[1].first;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
 
#define FAST ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
 
#define MAXX 10005
 
#define PI 3.14159265358979323846264338327950
 
#define F first
#define S second
 
#define ll 	 long long int
 
#define mod  1000000007

ll ss[MAXX];

int main()
{
	FAST;
	ll n;
	cin >> n;
	ll ans = 0;
	for(ll i = 105; i <= n; i+= 2){
		ll x = 0;
		for(ll j = 1; j * j < i; j++){
			if(i % j == 0){
				x += 2;
			}
		}
		if(floor(sqrt(i)) == ceil(sqrt(i))){
			x ++;
		}
		if(x == 8 && i % 2){
			ans ++;
		}
}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3624