akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
#include <random>
#include <set>

void reverse(std::string& str, const int from, const int until) {
	std::reverse(std::next(str.begin(), from), std::next(str.begin(), until));
}
int main() {
	int n; std::cin >> n;
	std::unordered_set<std::string> set;
	for (auto i = 0; i < n; ++i) {
		set.clear();
		std::string str; std::cin >> str;
		for (auto j = 0; j < str.size(); ++j) {
			reverse(str, j, str.size());
			set.insert(str);
			reverse(str, 0, j);
			set.insert(str);
			reverse(str, j, str.size());
			set.insert(str);
			reverse(str, 0, str.size());
			set.insert(str);
			reverse(str, 0, str.size() - j);
			set.insert(str);
			reverse(str, str.size() - j, str.size());
			set.insert(str);
			reverse(str, 0, str.size() - j);
			set.insert(str);
			reverse(str, 0, str.size());
		}
		std::cout << set.size() << '\n';
	}
}


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

using namespace std;

int main(void)
{
    int A, B, H, M;
    cin >> A >> B >> H >> M;

    double aDeg = 360.0/12.0 * (H +  1.0 / 60.0 * M);
    double bDeg = 360.0 / 60.0 * M;

    double theta = abs(aDeg - bDeg) * 2.0 * M_PI / 360.0;
    // cout << aDe << endl << bRad << endl << theta << endl;
    printf("%.10lf", sqrt(A*A + B*B - 2*A*B*cos(theta)));
    return 0;
}


Measured memory_bytes: 4116
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;

int main()
 {
 	int a,b;
 	cin>>a>>b;
	if(a>=13)
		cout<<b<<endl;
	else if(a>=6&&a<=12)
		cout<<b/2<<endl;
	else
		cout<<"0"<<endl;
 	
	return 0;
}
 	
 					

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

#define MAX_N 10001

using namespace std;

int par[MAX_N],rank[MAX_N];

void init(int n){
  for(int i=0;i<n;i++){
    par[i]=i;
    rank[i]=0;
  }
}

int find(int x){
  if(par[x]==x)return x;
  return par[x]=find(par[x]);
}

void unit(int x,int y){
  x=find(x);
  y=find(y);
  if(x==y)return;

  if(rank[x]<rank[y])par[x]=y;
  else {
    par[y]=x;
    if(rank[x]==rank[y])rank[x]++;
  }
}

bool same(int x,int y){
  return find(x)==find(y);
}

int main(void){

  int n,q;
  cin >> n >> q;
  init(n);
  while(q--){
    int com,x,y;
    cin >> com >> x >> y;
    if(com)cout << same(x,y) << endl;
    else unit(x,y);
  }
  return 0;
}

Measured memory_bytes: 1240
#include <iostream>

using namespace std;

int main()
{
 int A,B,X,z=0;
 bool flag=false;
 cin>>A>>B>>X;
 if(A==X){
     cout<<"YES";
 }
 else{
 for(int i=0;i<B;i++){
    A+=1;
    if(A==X){
        cout<<"YES";
        flag=true;
        break;
    }
 }
 if(flag==false){
    cout<<"NO";
 }
 }
    return 0;
}


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

//nもrも10^5くらいのときにはこれ使うと良き
//二項係数の計算
const int MAX = 510000;
ll fac[MAX],finv[MAX],inv[MAX];

//テーブルの初期化
void COMinit(){
	fac[0] = fac[1] = 1;//階乗
	finv[0] = finv[1] = 1;//階乗の逆元
	inv[1] = 1;//逆元(1の逆元は1)
	for(int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % mod;//累積積的な感じ
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;//inv[i] = iの逆元(mod mod)
		finv[i] = finv[i - 1] * inv[i] % mod;//階乗の逆元の計算
	}
}
ll per(ll n,ll k){
	return fac[n] * finv[n - k] % mod;
}


ll n,k;
vector<ll> v(100001,0LL);
vector<vector<ll>> g(200001);
void dfs(int x,int parent,int dist){
	for(int i = 0; i < g[x].size(); i++) {
		if (g[x][i] != parent){
			v[x]++;//parent の子の数
			dfs(g[x][i],x,dist + 1);
		}
	}
}

int main(){
	cin>>n>>k;
	for(int i = 0; i <  n - 1; i++) {
		ll a,b;cin>>a>>b;
		g[a].pb(b);
		g[b].pb(a);
	}
	g[0].pb(1);
	dfs(0,-1,0);
	ll ans = 1LL;
	COMinit();
	for(ll i = 1; i <= n; i++) {
		if (i == 1){
			if (k - 1 < v[1]){
				cout << 0 << endl;
				return 0;
			}
			ans *= (k * per(k - 1,v[1]) % mod);
		}
		else{
			if (k - 2 < v[i]){
				cout << 0 << endl;
				return 0;
			} 
			if (v[i] == 0){continue;}
			ans *= per(k - 2 ,v[i]);
			ans %= mod;
		}
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 25472
# https://atcoder.jp/contests/abc124/submissions/4963013
N, K = gets.split(' ').map(&:to_i)
S = gets.chomp
 
now = 1
count = 0
nums = []
 
N.times do |i|
  if S[i] == (0 + now).to_s
    count += 1
  else
    nums.push(count)
    now = 1 - now
    count = 1
  end
end
 
nums.push(count) if count != 0
nums.push(0) if nums.size.even?
 
add = 2 * K + 1
# C++ の vector<int> 変数名(要素数) は全部 0 で初期化するらしい
sum = [0]
 
nums.size.times do |i|
  sum[i + 1] = sum[i] + nums[i]
end
 
ans = 0
 
nums.size.times do |i|
  next if i.odd?
 
  left = i
  right = [i + add, nums.size].min
 
  tmp = sum[right] - sum[left]
  ans = [tmp, ans].max
end
 
puts ans

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

from collections import Counter

def check(counter, A):
    return len(counter) != len(A)

def Main(N, A):
    counter = Counter(A)
    lenC = len(counter)
    remains = N-lenC
    if remains%2 == 0:
        return lenC
    else:
        return lenC-1
    
          
print(Main(N, A))

Measured memory_bytes: 18528
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;

int main()
{
  int cnt=0,x,y,f=0,nf=0,i=0,ind=0;
  string s;
  vector<int> X(0),Y(0);
  cin >> s;
  cin >> x >> y;
  for(int i=0;i<s.size();i++){
    if(s[i] == 'T'){
      ind = i;
      break;
    }
    if(i==s.size()-1){
      ind = i+1;
    }
  }
  for(int j=ind;j<s.size();j++){
    if(s[j] == 'T'){
      if(cnt!=0){
        if(nf)Y.push_back(cnt);else X.push_back(cnt);
      }
      if(nf)nf=0;else nf=1;
      cnt = 0;
      continue;
    }else{
      cnt++;
    }
  }
  if(cnt!=0){
    if(nf)Y.push_back(cnt);else X.push_back(cnt);
  }
  vector<vector<bool> > dpx(X.size()+1,vector<bool>(16010,false));
  vector<vector<bool> > dpy(Y.size()+1,vector<bool>(16010,false));
  dpx[0][8000+ind] = true;
  REP(i,X.size()){
    REP(j,16001){
      
      if(j - X[i] < 0 && j+X[i] > 16001){
        dpx[i+1][j] = false;
        continue;
      }
      if(j - X[i] >= 0 && j+X[i] <= 16001)
        dpx[i+1][j] = dpx[i][j-X[i]] || dpx[i][j+X[i]];
      else if(j-X[i] < 0)
        dpx[i+1][j] = dpx[i][j+X[i]];
      else
        dpx[i+1][j] = dpx[i][j-X[i]];
    }
  }
  
  dpy[0][8000] = true;
  
  REP(i,Y.size()){
    
    REP(j,16001){
      if(j - Y[i] < 0 && j+Y[i] > 16001){
        dpy[i+1][j] = false;
        continue;
      }
      if(j - Y[i] >= 0 && j+Y[i] <= 16001)
        dpy[i+1][j] = dpy[i][j-Y[i]] || dpy[i][j+Y[i]];
      else if(j-Y[i] < 0)
        dpy[i+1][j] = dpy[i][j+Y[i]];
      else
        dpy[i+1][j] = dpy[i][j-Y[i]];
      
    }
      
  }
  
  if(dpx[X.size()][8000+x] && dpy[Y.size()][8000+y])
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}



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

int main(void){

	int n,i,j;
	int a,b;
	int sum;
	char work[1001];
	char s[1001];
	char com[8];


	scanf("%s",s);
	scanf("%d",&n);

	for(i=0;i<n;i++){

		for(j=0;j<strlen(work);j++){
			work[j]=NULL;
		}
		for(j=0;j<8;j++){
			com[j]=NULL;
		}

		scanf("%s %d %d",com,&a,&b);
		if(strcmp("replace",com)==0){
			scanf("%s",work);
			sum=0;
			for(j=a;j<=b;j++){
				s[a+sum]=work[sum];
				sum++;
			}
		}
		else if(strcmp("reverse",com)==0){
			sum = 0;
			for(j=b;j>=a;j--){
				work[sum]=s[j];
				sum++;
			}
			sum--;
			for(j=b;j>=a;j--){
				s[j]=work[sum];
				sum--;
			}
		}
		else{
			for(j=a;j<=b;j++)
				printf("%c",s[j]);

			puts("");
		}

	}

	return 0;

}

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

x = sum(B)-sum(A)

one = 0
two = 0

for i in range(N):
    if A[i] > B[i]:
        one += A[i]-B[i]
    if A[i] < B[i]:
        two += (B[i]-A[i])//2
        if (B[i]-A[i])%2 == 1:
            one += 1

if one<=x and two<=x:
    print("Yes")
else:
    print("No")

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

int leap(int x) {
	int flg=0;
	if (x % 4 == 0) { flg = 1; }
	if (x % 100 == 0) { flg = 0; }
	if (x % 400 == 0) { flg = 1; }

	return flg;
}

int main() {
	int a, b;
	int q = 0;
	vector<int>va;
	while (cin >> a >> b,a,b) {
		q++;
		if (q >= 2) { cout << '\n'; }
		for (int i = a; i <=b; i++) {
			int c = leap(i);
			if (c==1) { va.push_back(i); }
		}
		if (!va.empty()) {
			for (int i = 0; i < va.size(); i++) {
				cout << va[i] << endl;
			}
		}
		else { cout << "NA" << endl; }
		va.erase(va.begin(), va.end());
	}
	return 0;
}

Measured memory_bytes: 3064
process.stdin.setEncoding('utf8');

run(function * () {
	var num = yield;

	var first = parseInt(num[0]);
	var rests = num.length - 1;
	for (var i=1, n=num.length; i<n; ++i) {
		if ('9' !== num[i]) {
			--first;
			break;
		}
	}
	console.log(rests * 9 + first);
});

/**
 * yield で標準入力を利用する
 * @param {GeneratorFunction} main 
 */
function run (main) {
	var gen_main = main();
	var cin = null;
	var words = [null];

	process.stdin.pause();

	function get_chunk (chunk) {
		// 標準入力を止める
		process.stdin.pause();
		// 空白区切りで分割
		var nexts = chunk.split(/\s+/);
		for (var i=0, n=nexts.length; i<n; ++i) {
			if (nexts[i]) {
				words.push(nexts[i]);
			}
		}
		loop();
	}
	function loop () {
		while (0 < words.length) {
			var result = gen_main.next(words.shift());
			if (undefined !== result.value) {
				// yield に渡された値を標準出力
				process.stdout.cork();
				process.stdout.write(result.value)
				process.stdout.uncork();
			}
			// main が return しているなら終了
			if (result.done) return;
		}

		process.stdin.resume();
	};
	process.stdin.on('data', get_chunk);

	loop();
}


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

#define MX 100005
struct node
{
    int l,r,i,b_indx,ans;
};
int bucket_size,q,res;
vector<int>v;
bool mark[MX];
node qry[MX];

void sieve()
{
    memset(mark,true,sizeof(mark));
    mark[0] = false;
    mark[1] = false;
    mark[2] = true;
    v.push_back(2);
    for(int i=4; i<MX; i+=2)    mark[i] = false;
    for(int i=3; i<MX; i+=2)
    {
        if(mark[i])
        {
            v.push_back(i);
            for(int j=(i+i); j<MX; j+=i) mark[j] = false;
        }
    }
    //cout<<"xx "<<v.size()<<endl;
    return;
}


bool comp1(node na,node nb)
{
    if(na.b_indx==nb.b_indx)    return  (na.r<nb.r);
    return  (na.b_indx<nb.b_indx);
}

bool comp2(node na,node nb)
{
    return  (na.i<nb.i);
}

void ADD(int x)
{
    int y = (x+1)/2;
    if(mark[x] && mark[y])  res++;
    return;
}

void REMOVE(int x)
{
    int y = (x+1)/2;
    if(mark[x] && mark[y])  res--;
    return;
}

void MO_s()
{
    sort(qry,qry+q,comp1);
    int l=qry[0].l,r=qry[0].r;
    res = 0;
    for(int i=0; i<q; i++)
    {
        while(l<qry[i].l)
        {
            REMOVE(l);
            l++;
        }
        while(l>qry[i].l)
        {
            l--;
            ADD(l);
        }
        while(r<qry[i].r)
        {
            r++;
            ADD(r);
        }
        while(r>qry[i].r)
        {
            REMOVE(r);
            r--;
        }
        if(!i)
        {
            for(int j=l; j<=r; j++) ADD(j);
        }
        qry[i].ans = res;
    }
    sort(qry,qry+q,comp2);
    return;
}

int main()
{
    int l,r,i;
    scanf("%d",&q);
    bucket_size = sqrt((int)MX);
    sieve();
    for(int i=0; i<q; i++)
    {
        scanf("%d %d",&qry[i].l,&qry[i].r);
        qry[i].i = i;
        qry[i].b_indx = qry[i].l/bucket_size;
    }
    MO_s();
    for(int i=0; i<q; i++)    printf("%d\n",qry[i].ans);
    return  0;
}


Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int INT_INF = 1e9;
const ll MOD = 1e9 + 7;
const int INT_MOD=1e9+7;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 0; i <= n; i++)
#define rrep(i,n) for(int i=n;i>0;i--)
#define RREP(i,n) for(int i=n;i>=0;i--)
typedef pair<int, int> Pi;
typedef pair<double, double> P;
using fint64 = int_fast64_t;
int dx[2]={1,0},dy[2]={0,1};
int dp[1005][1005];
char grid[1005][1005];
int h,w;

int main() { 
	cin>>h>>w;
    rep(i,h){
        rep(j,w){
            cin>>grid[j][i];
            if(grid[j][i]=='.') dp[j][i]=1;
            else dp[j][i]=0;
        }
    }
    dp[0][0]=1;
    rep(i,h){
        rep(j,w){
            if(dp[j][i]!=0){
                if(i!=0 and j!=0) dp[j][i]=(dp[j-1][i]+dp[j][i-1])%INT_MOD;
                else if(i!=0 and j==0) dp[j][i]=dp[j][i-1];
                else if(i==0 and j!=0) dp[j][i]=dp[j-1][i];
            }
        }
    }
    cout<<dp[w-1][h-1]%INT_MOD<<endl;
    return 0;
}


Measured memory_bytes: 5120
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <string>
#include <iomanip>
using namespace std;
long long mod=1e9+7;
long long modinv(long long a,long long m){
	long long b=m,u=1,v=0;
	while(b){
		long long t=a/b;
		a-=t*b;
		swap(a,b);
		u-=t*v;
		swap(u,v);
	}
	(u+=mod)%=mod;
	return u;
}
int main(){
	long long n,k;
	long long a[100000];
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
	long long cul[100001];
	cul[k-1]=1;
	for(int i=k;i<=n-1;i++){
		cul[i]=cul[i-1];
		(cul[i]*=i)%=mod;
		(cul[i]*=modinv(i-(k-1),mod))%=mod;
	}
	long long ans=0;
	for(int i=0;i<=n-k;i++){
		ans+=(mod-cul[n-i-1]*a[i]);
		ans%=mod;
	}
	for(int i=k-1;i<n;i++){
		ans+=cul[i]*a[i];
		ans%=mod;
	}
	cout<<ans<<endl;
	return 0;
}

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

#define DEBUG(x) cerr << #x << ": " << x << endl;

int main() {
    string n;
    cin >> n;
    int len = n.length();
    for (int i = 0; i < len; i++) {
        DEBUG(n[i]);
        if (n[i] == '9') {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
//Radhe Radhe
#include<bits/stdc++.h>
#define godspeed  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define rep1(i,a,b)    for(ll i=a; i<=b; i++)
#define repVect(i,n)    for(ll i=0; i<sum.size(); i++)
#define fixed cout.setf(ios::fixed);
#define Precise cout.precision(7);
#define yes cout<<"Yes"<<'\n';
#define no cout<<"No"<<'\n';
using namespace std;

int main()
{
    godspeed
    ll  t,i,x,j,k,n;
    string s;
    cin>>s;
    for(i=0;s[i];i++){
        if(i%2==0)
     cout<<s[i];
    }
     cout<<endl;

    return 0;
}





Measured memory_bytes: 3724
foldBool :: [Int] -> [Int] -> Bool                                                                                                                                          
foldBool [a, b] list = (foldr (||) False (map (==a) list)) && (foldr (||) False (map (==b) list))
  
main = do
  [a, b] <- map read . words <$> getLine
  if (foldBool [a, b] list1) || (foldBool [a, b] list2)
    then putStrLn "Yes"
    else putStrLn "No"
  where
    list1 = [1, 3, 5, 7, 8, 10, 12] 
    list2 = [4, 6, 9, 11]

Measured memory_bytes: 508
// ABC 085

// inputに入力データ全体が入る
function Main(input) {
  input = input.split("\n");
  var count = 0;
  input.splice(0,1); //先頭削除

  // 重複を削除したリスト
  var b = input.filter(function (x, i, self) {
    return self.indexOf(x) === i;
  });

  console.log(b.length-1)
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
N, M = map(int,input().split())

#訪れることができるかのリスト
lst = [0] * N

flag = False #フラグを立てる
for i in range(M): #M種の定期船について確認
    a, b = map(int,input().split())
    if a == 1: #スタートが1の時
        if lst[b-1] == 1: #Nから1回で来る船があるならOK
            flag = True
        else:
            lst[b-1] = 1 #Nから1回で来る船がない時、1からは1回で来れることをメモ
    if b == N: #ゴールがNの時
        if lst[a-1] == 1: #1から1回で来る船があるならOK
            flag = True
        else:
            lst[a-1] = 1 #1から1回で来る船がない時、Nからは1回で来れることメモ

if flag:
    print ('POSSIBLE')
else:
    print ('IMPOSSIBLE')
    




Measured memory_bytes: 51928
use std::collections::HashMap;
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

const MOD: i64 = 1e+9 as i64 + 7;

fn calc(n: usize, depth: usize, prev: Vec<char>, memo: &mut Vec<HashMap<Vec<char>, i64>>) -> i64 {
    if depth == n {
        return 1;
    }
    if let Some(&ret) = memo[depth].get(&prev) {
        return ret;
    }
    let mut ret = 0;
    for &c in ['A', 'G', 'C', 'T'].iter() {
        if prev.len() >= 2 {
            let mut last_two = vec![];
            last_two.push(prev[prev.len() - 2]);
            last_two.push(prev[prev.len() - 1]);
            if last_two == vec!['A', 'G'] && c == 'C'
                || last_two == vec!['G', 'A'] && c == 'C'
                || last_two == vec!['A', 'C'] && c == 'G'
            {
                continue;
            }
        }
        if prev.len() == 3
            && ((prev[0] == 'A' && prev[1] == 'G' && c == 'C')
                || (prev[0] == 'A' && prev[2] == 'G' && c == 'C'))
        {
            continue;
        }
        let mut next = prev.clone();
        next.push(c);
        // println!("{:?}", next);
        if next.len() == 4 {
            next.remove(0);
        }
        ret = (ret + calc(n, depth + 1, next, memo)) % MOD;
    }
    memo[depth].insert(prev, ret);
    ret
}

fn main() {
    let n = read::<usize>();
    let mut memo = vec![HashMap::<Vec<char>, i64>::new(); n];
    let ans = calc(n, 0, vec![], &mut memo);
    println!("{}", ans);
}


Measured memory_bytes: 4352
fun main(args: Array<String>) {
    // 文字列
//    val str = readLine()!!
    // 数値
//    val int =readLine()!!.toInt()
    // 行
    val (a,b,c) = readLine()!!.split(" ").map (String::toInt )
//    val (a,b) = readLine()!!.split(" ").map(String::toInt)

    var sum=0
    for(i in a..b){
        if (i % c==0){
            sum++
        }
    }
    print(sum)
}

Measured memory_bytes: 36340
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
#define int long long


void solve(long long N, std::vector<long long> A, std::vector<long long> B){
    if(A == B) {
        cout << 0 << endl;
        return;
    }
    int res = 0, mn = (int)1e10;
    for(int i = 0; i < N; ++i) {
        res += A[i];
        if (A[i] > B[i]) {
            mn = min(mn, B[i]);
        }
    }
    cout << res - mn << endl;
}

signed main(){
	ios::sync_with_stdio(false);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    std::vector<long long> B(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
        scanf("%lld",&B[i]);
    }
    solve(N, std::move(A), std::move(B));
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define endl "\n"

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b=mod-2,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
    oreno_initializer() {
        cin.tie(0);
        ios::sync_with_stdio(0);
    }
} oreno_initializer;



int n, a, b, c, x, y[111];

signed main() {
    while (1) {
        cin >> n >> a >> b >> c >> x;
        if (n==0) break;
        rep(i,n) cin >> y[i];
        int res = 0;
        rep(i,n) {
            if (i && x==y[i]) x = (a*x + b) %c, res++;
            while (1) {
                if (res>10000 || x==y[i]) break;
                x = (a*x + b) %c;
                res++;
            }
            if (res>10000) break;
        }
        cout << (res>10000 ? -1 : res) << endl;
    }
}



Measured memory_bytes: 3188
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
using namespace std;
int V;//頂点数
int t[200010];//親
vector<int> e[200010];//iから出る辺

int d[200010];
int c[200010];
bool c_end[200010];

void count(int s){
    if(!c_end[s]){
        if(s==1){
            c[1]=d[1];
            c_end[1]=true;
        }
        else{
            if(!c_end[t[s]]){count(t[s]);}
            c[s]=d[s]+c[t[s]];
            c_end[s]=true;
        }
    }
}


int main(){
    int n,Q;
    cin>>n>>Q;
    V=n;
    //辺情報の導入
    for(int i=0;i<V-1;i++){
        int a,b;
        cin>>a>>b;
        e[a].push_back(b);
        e[b].push_back(a);
    }
    //木の構成
    for(int i=1;i<=n;i++){
        t[i]=i;//初期情報の確率
    }
    queue <int> q;
    q.push(1);
    while(!q.empty()){
        int from;
        from=q.front();
        q.pop();
        while(!e[from].empty()){
            int to;
            to=e[from].back();
            e[from].pop_back();
            if(to!=t[from]){
                t[to]=from;
                q.push(to);
            }
        }
    }

    for(int i=0;i<Q;i++){
        int a,b;
        cin>>a>>b;
        d[a]=d[a]+b;
    }
    for(int i=1;i<=n;i++){
        c_end[i]=false;
    }
    for(int i=1;i<=n;i++){
        count(i);
    }
    
    for(int i=1;i<=n-1;i++){
        cout<<c[i]<<' ';
    }
    cout<<c[n]<<endl;
    return 0;
}

Measured memory_bytes: 18816
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int guthoku(vector<P> &in){
	int res = 0;
	for(int i = 0; i < in.size(); ++i){
		for(int j = i + 1; j < in.size(); ++j){
			res = max(res, abs(in[i].first - in[j].first) + abs(in[i].second - in[j].second));
		}
	}	
	return res;
}

int main(){
	int N; cin >> N;
	vector<P> point(N);
	rep(i,N)cin >> point[i].first >> point[i].second;
	P dM = point[0], dm = point[0], uM = point[0], um = point[0];
	rep(i,N){
		ll dsum = point[i].first + point[i].second;
		ll usum = - point[i].first + point[i].second;
		if(dsum > dM.first + dM.second)dM = point[i];
		if(dsum < dm.first + dm.second)dm = point[i];
		if(usum > uM.second - uM.first)uM = point[i];
		if(usum < um.second - um.first)um = point[i];
	}
	int ans1 = abs(dM.first - dm.first) + abs(dM.second - dm.second);
	int ans2 = abs(uM.first - um.first) + abs(uM.second - um.second);
	cout << max(ans1, ans2) << endl;
	return 0;
}


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

ll N, M;
pll sim(vector<vector<ll>>& A, vector<bool>& open)
{
  pll res = {0, -1};
  vector<ll> temp(M, 0);
  for (ll i = 0; i < N; ++i)
  {
    for (ll j = 0; j < M; ++j)
    {
      if (open.at(A.at(i).at(j)))
      {
        temp.at(A.at(i).at(j)) += 1;
        break;
      }
    }
  }
  for (ll i = 0; i < M; ++i)
  {
    if (temp.at(i) > res.first)
    {
      res = {temp.at(i), i};
    }
  }
  return res;
}

int main()
{
  cin >> N >> M;
  vector<vector<ll>> A(N, vector<ll>(M));
  for (ll i = 0; i < N; ++i)
  {
    for (ll j = 0; j < M; ++j)
    {
      ll a;
      cin >> a;
      A.at(i).at(j) = a - 1;
    }
  }
  ll ans = INF;
  vector<bool> open(M, true);
  for (ll i = 0; i < M; ++i)
  {
    pll temp = sim(A, open);
    ans = min(ans, temp.first);
    open.at(temp.second) = false;
  }
  cout << ans << endl;
}


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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define RREP(i,s,n) for(lli i=s;i>=n;i--)
#define MOD 1000000007
#define NUM 2520
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define INF (1LL<<50)

bool vis[100100];
lli dp[100100];

lli func(lli now){
	if(vis[now])return dp[now];
	if(dp[now]==-1)return 0;
	if(now<0)return 0;
	vis[now]=true;
	return dp[now] = (func(now-1)+func(now-2))%MOD;
}

signed main(){

	lli n,m;
	cin>>n>>m;

	vector<lli> a(m);
	REP(i,0,m){
		cin>>a[i];
		//a[i]--;
		dp[a[i]]=-1;
	}
	vis[0]=true;
	dp[0]=1;

	cout<<func(n)<<endl;

	return 0;
}

Measured memory_bytes: 4224
def main():
    N = int(input())
    A = [[] for i in range(N)]
    for i in range(N):
        for _ in range(int(input())):
            x, y = map(int, input().split())
            A[i].append((x - 1, y))

    ans = 0
    for i in range(1 << N):
        ok = True
        for j in range(N):
            if (i >> j & 1) != 1:
                continue
            for x, y in A[j]:
                if (i >> x & 1) ^ y:
                    ok = False
                    break
            if not ok:
                break
        if ok:
            cnt = 0
            for j in range(N):
                if (i >> j & 1) == 1:
                    cnt += 1
            ans = max(ans, cnt)
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
/* B - Judge Status Summary */

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

int main(){
  int N, cnt_AC = 0, cnt_WA = 0, cnt_TLE = 0, cnt_RE = 0;
  string S;
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> S;
    if(S == "AC"){
      cnt_AC++;
    }
    if(S == "WA"){
      cnt_WA++;
    }
    if(S == "TLE"){
      cnt_TLE++;
    }
    if(S == "RE"){
      cnt_RE++;
    }
  }
  cout << "AC x " << cnt_AC << endl;
  cout << "WA x " << cnt_WA << endl;
  cout << "TLE x " << cnt_TLE << endl;
  cout << "RE x " << cnt_RE << endl;
}


Measured memory_bytes: 3624
N = int(input())
h = list(map(int,input().split()))
inf = 10 ** 10 + 7
dp = [inf] * N
dp[0] = 0
for i in range(N):
  if i + 1 < N:
    dp[i + 1] = min(dp[i + 1], abs(h[i + 1] - h[i]) + dp[i])
  if i + 2 < N:
    dp[i + 2] = min(dp[i + 2], abs(h[i + 2] - h[i]) + dp[i])
print(dp[N - 1])

Measured memory_bytes: 52316
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	static int V;
	static int E;
	static ArrayList<Integer>[] g;

	@SuppressWarnings("unchecked")
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		V = sc.nextInt();
		E = sc.nextInt();
		g = new ArrayList[V];
		for (int i = 0; i < V; ++i)
			g[i] = new ArrayList<>();

		for (int i = 0; i < E; ++i) {
			int s = sc.nextInt();
			int t = sc.nextInt();
			g[s].add(t);
		}

		ord = new int[V];
		vis = new boolean[V];
		pending = new boolean[V];

		sort();

		for (int i = 0; i < V; ++i) {
			System.out.println(ord[i]);
		}
	}

	static int[] ord;
	static boolean[] vis;
	static boolean[] pending;
	static int now = 0;

	static void sort() {
		for (int i = 0; i < V; ++i) {
			if (!vis[i])
				dfs(i, -1);
		}
	}

	static void dfs(int cur, int pre) {
		for (int to : g[cur]) {
			if (to != pre && !vis[to]) {
				if (pending[to])
					throw new AssertionError();
				dfs(to, cur);
			}
		}
		ord[V - now - 1] = cur;
		vis[cur] = true;
		++now;
	}
}

Measured memory_bytes: 70688
#!/usr/bin/env python
from collections import deque, defaultdict
import bisect


def comb(a, b):
    result = 1
    for i in range(b):
        result *= (a - i) / (i + 1)
    return result


def main():
    N = int(input())
    Xs = list(map(int, input().split()))

    min_load = None
    for p in range(101):
        load = sum([(x - p) ** 2 for x in Xs])
        if min_load is None or min_load > load:
            min_load = load

    print(min_load)


if __name__ == '__main__':
    main()


Measured memory_bytes: 39152
def main():
    X = input()
    result = len(X)
    from collections import deque
    d = deque([])
    append = d.appendleft
    pop = d.popleft
    for x in X:
        if x == "S":
            append(x)
        else:
            if len(d) > 0 and d[0] == "S":
                result -= 2
                pop()
            else:
                append(x)
    print(result)
main()

Measured memory_bytes: 5096
# Polygon
N = gets.chomp.to_i
L = gets.chomp.split(" ").map(&:to_i)
sum = 0
for i in 0..N-1 do
    if L.index(L.max) != i
        sum = sum + L[i]
    end
end
if L.max < sum
    puts "Yes"
else
    puts "No"
end

Measured memory_bytes: 1788
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   abc109_c.cpp                                       :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: nkinoshi <nkinoshi@student.42tokyo.jp      +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/07/28 22:22:56 by nkinoshi          #+#    #+#             */
/*   Updated: 2020/07/28 22:25:42 by nkinoshi         ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define vv(T) std::vector<std::vector<T>>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;

ll	gcd(ll a, ll b)
{
	if (b > 0)
		gcd(b, a % b);
	return (a);
}

int		main(void)
{
	int n, x;
	cin >> n >> x;

	ll ans = 0;
	for (int i = 0; i < n; ++i)
	{
		int a;
		cin >> a;
		ans = gcd(ans, abs(x - a));
	}
	cout << ans << endl;
}


Measured memory_bytes: 3588
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort(key=lambda x: -abs(x))
mod=10**9+7
p=1
mm=0
for i in range(k):
    if a[i]<0:
        mm+=1
    p*=a[i]
    p%=mod
if n==k or mm%2==0:
    print(p)
    exit()
    
m=0
for i in a:
    if i<=0:
        m+=1
if m==n:
    p=1
    for i in range(k):
        p*=a[n-i-1]
        p%=mod
    print(p)
    exit()
b1=[]
b2=[]
for i in range(k):
    if len(b1)==0 and a[k-1-i]>=0:
        b1.append(a[k-1-i])
    if len(b2)==0 and a[k-1-i]<0:
        b2.append(a[k-1-i])
for i in range(n-k):
    if len(b1)==1 and a[k+i]<0:
        b1.append(a[k+i])
    if len(b2)==1 and a[k+i]>=0:
        b2.append(a[k+i])
f=0
if len(b1)==len(b2)==2:
    if b1[1]*b2[0]>=b1[0]*b2[1]:
        f=1
    else:
        f=2
elif len(b2)<2:
    f=1
else:
    f=2

if f==1:
    p*=b1[1]*pow(b1[0],mod-2,mod)
    print(p%mod)
    exit()
else:
    p*=b2[1]*pow(b2[0],mod-2,mod)
    print(p%mod)
    exit()


Measured memory_bytes: 31796
# coding:utf-8

N = int(input())
H = [int(hi) for hi in input().split()]
dp = [0]*N
dp[1] = abs(H[0]-H[1])

for i in range(2, N):
    dp[i] = min(abs(H[i]-H[i-2])+dp[i-2],abs(H[i]-H[i-1])+dp[i-1])
    
print(dp[N-1])

Measured memory_bytes: 13928
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<numeric>
#include<algorithm>
#include<unordered_map>
#define int long long
const int inf=1145141919810893;
const int mod=1000000007;
using namespace std;
template<class T>bool chmin(T &a,const T &b){
	if(a>b){
		a=b;
		return true;
	}
	return false;
}
template<class T>bool chmax(T &a,const T &b){
	if(a<b){
		a=b;
		return true;
	}
	return false;
}
template<class T>void debug(T *a,int l,int r,const char *name){
	for(int i=l;i<r;i++)
		cout<<name<<"["<<i<<"]="<<a[i]<<endl;
}
int p[50];
int X,Y;
int ma;
signed main(){
	int i,j;
	cin>>X>>Y;
	int u=X;
	for(i=0;u<=Y;i++)
		u*=2;
	cout<<i<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.HashMap;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    
    String[] w = scanner.nextLine().split("");
    
    // どの文字がいくつあるか
    HashMap<String, Integer> map = new HashMap<>();
    for(String word: w) {
      // マップから今の値を取得
      Integer num = map.get(word);
      // これがnullなら1をマップにいれる
      if(num == null) {
        map.put(word, 1);
      } else {
        // そうでなければその値 + 1をマップに戻す
        map.put(word, num + 1);
      }
    }
    
    // マップの「キーのコレクション」から「それぞれのキー」を取り出す
    boolean flg = true;
    for(String key: map.keySet()) {
      // 「キー」に対応した「値」が偶数か調べる
      if(map.get(key) % 2 != 0) {
        flg = false;
      }
    }
    
    if(flg) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 35640
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;

int main() {
	char c; cin >> c;
	char d = c + 1;

	cout << d << endl;
	return 0;
}


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

int main() {
    int n, k, q;
    cin >> n >> k >> q;
    int p[n];
    memset(p, 0, sizeof(int) * n);
    for (int i = 0; i < q; i++) {
        int a;
        cin >> a;
        p[--a]++;
    }
    for (int i = 0; i < n; i++) {
        int hp = k - (q - p[i]);
        if (hp <= 0)
            puts("No");
        else
            puts("Yes");
    }
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <iomanip>
using namespace std;
typedef long long ll;
int main(){
    ll n;
    vector<int>a;
    cin>>n;
    if(n==0) cout<<0;
    while(n){
        if(n%(-2)==-1){
            //cout<<n%(-2)+2;
            a.push_back(n%(-2)+2);
            n=n/(-2)+1;
        }else{
            //cout<<n%(-2);
            a.push_back(n%(-2));
            n/=(-2);
        }
        //cout<<n<<" ";
    }
    reverse(a.begin(),a.end());
    for(int i=0;i<a.size();i++){
        cout<<a[i];
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int H, W;
	cin >> H >> W;
	
	vector<int> A(H), B(H);
	REP(i, H) scanf("%d %d", &A[i], &B[i]), --A[i];
	
	int cur = 0;
	set<pii> dp; // pos, min-dist
	multiset<int> mind;
	REP(i, W) {
		dp.emplace(i, 0);
		mind.insert(0);
	}
	REP(i, H) {
		// B[i] を更新
		auto it = dp.lower_bound(pii(B[i], -1));
		if (B[i] != W && it != dp.begin()) {
			if (it == dp.end() || it->first != B[i]) {
				--it;
				int nd = it->second + (B[i] - it->first);
				pii upd(-1, -1);
				upd = pii(B[i], nd);
				dp.insert(upd);
				mind.insert(upd.second);
			}
		}
		
		// [A[i], B[i]) を削除
		it = dp.lower_bound(pii(A[i], -1));
		while (it != dp.end() && it->first < B[i]) {
			mind.erase(mind.find(it->second));
			it = dp.erase(it);
		}
		
		int ans = -1;
		if (!mind.empty()) ans = *mind.begin() + i + 1;
		printf("%d\n", ans);
	}
	
	return 0;
}


Measured memory_bytes: 23560
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <ctime>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <assert.h>
#include <iomanip>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define x first
#define y second
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define SZ(x) (int)x.size()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define pi acos(-1)
#define mod 1000000007
#define inf 1000000007
#define ll long long
#define ull unsigned long long
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
#define N 100010
#define _DEBUG
template <class U,class T> void Max(U &x, T y){if(x<y)x=y;}
template <class U,class T> void Min(U &x, T y){if(x>y)x=y;}
template <class T> void add(int &a,T b){a=(a+b)%mod;}
inline int gcd(int a,int b){return b==0?a:gcd(b,a%b);}
inline ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}

int pow(int a,int b){
    int ans=1;
    while(b){
        if(b&1)ans=1LL*ans*a%mod;
        a=1LL*a*a%mod;b>>=1;
    }
    return ans;
}
int pow(int a,int b,int c){
    int ans=1;
    while(b){
        if(b&1)ans=1LL*ans*a%c;
        a=1LL*a*a%c;b>>=1;
    }
    return ans;
}

char s[1005][1005];
int dp[1005][1005];
int main(){
    //srand(time(NULL)+clock());
    int ca=0,T,k,i,j,m=0,K,n;
    double start=clock();
    scanf("%d%d",&n,&m);
    rep(i,0,n){
        scanf("%s",s[i]);
    }
    dp[0][0]=1;
    rep(i,0,n){
        rep(j,0,m)if(dp[i][j]){
            if(j<m-1&&s[i][j+1]!='#')add(dp[i][j+1],dp[i][j]);
            if(i<n-1&&s[i+1][j]!='#')add(dp[i+1][j],dp[i][j]);
        }
    }
    printf("%d\n",dp[n-1][m-1]);
    cerr<<(1.*clock()-start)/CLOCKS_PER_SEC<<"\n";
}


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

using namespace std;

int main(){
    int n;
    string s;
    cin>>n>>s;
    vector<vector<int>> dp(n,vector<int>(2,-1));
    if(s[0]=='#'){
        dp[0][0]=0;
        dp[0][1]=1;
    }
    else {
        dp[0][0]=1;
        dp[0][1]=0;
    }
    for (int i = 1; i < n; ++i) {
        if(s[i]=='#'){
            dp[i][0]=min(dp[i-1][0],dp[i-1][1]);
            dp[i][1]=dp[i-1][1]+1;
        }
        else{
            dp[i][0]=min(dp[i-1][0],dp[i-1][1])+1;
            dp[i][1]=dp[i-1][1];
        }
    }
    cout<<min(dp[n-1][0],dp[n-1][1])<<endl;
    return 0;
}

Measured memory_bytes: 11396
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int data;
  int sum = 0;
  for(int i = 0; i < 5; i++) {
    cin >> data;
    if(data < 40)data = 40;
    sum += data;
  }
  cout << sum / 5 << endl;
  return 0;
}
  

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define pb(a) push_back(a)
#define pr(a) cout<<(a)<<endl
#define PR(a,b) cout<<(a)<<" "<<(b)<<endl
#define R cin>>
#define F first
#define S second
#define ll long long
bool check(int n,int m,int x,int y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

int p[100001];
int r[100001];
void init() {
  for(int i=0; i<100001; i++) {
    p[i]=i;
    r[i]=0;
  }
}
int find(int x) {
  if(p[x]==x) return x;
  else return p[x]=find(p[x]);
}
void unite(int x,int y) {
  x=find(x);
  y=find(y);
  if(x==y) return;

  if(r[x]<r[y]) p[x]=y;
  else {
    p[y]=x;
    if(r[x]==r[y]) r[x]++;
  }
}
bool same(int x, int y) {
  return find(x)==find(y);
}

ll mod_pow(ll x,ll n,ll mod){
  if(n == 0) return 1;
  ll res = mod_pow(x * x % mod,n / 2,mod);
  if(n & 1) res = res * x % mod;
  return res;
}

int main() {
  int n,m;
  while(cin >> n >> m && n) {
    init();
    rep(i,m) {
      int x,y;
      cin >> x >> y;
      unite(x,y);
    }
    set<int> s;
    REP(i,1,n+1) s.insert(find(i));
    cout << (mod_pow(2,s.size(),MAX)+(m?1:0))%MAX << endl;
  }
  return 0;
}


Measured memory_bytes: 6656
#include <iostream>
#include <map>
#include <algorithm>

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

int main() {

    int N, M;
    multimap<int, int> ab;

    cin >> N >> M;
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        ab.insert(make_pair(a,b));
    }
    int bf = 0;
    int count = 0;

    for (auto itr = ab.begin(); itr != ab.end(); ++itr) {
        if (itr == ab.begin()) {
            bf = itr->second;
        }
        if (bf > itr->second) {
            bf = itr->second;
        }
        if (bf <= itr->first) {
            count++;
            bf = itr->second;
        }

    }
    cout << count + 1 << endl;


    return 0;
}

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

using namespace std;

const int N = 87;
long long a[N];

int main(){
    int n;
    cin>>n;
    a[0] = 2;
    a[1] = 1;
    for(int i=2;i<=n;i++){
    	a[i] = a[i-1] + a[i-2];
    }
    cout<<a[n];
    return 0;
}

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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9

int gcd(int a, int b){
  if(a < b){
    swap(a, b);
  }
  if(b == 0){
    return a;
  }
  return gcd(b, a % b);
}

int main(){ 
  int N, K;
  cin >> N >> K;
  ll ans = 0;
  REP(i, K){
    if((2*i) % K == 0){
      ll cnt = N/K;
      if( i != 0 && N % K >= i){
        cnt++;
      }
      // cout << "i: " << i << " cnt: " << cnt << endl;
      ans += cnt * cnt * cnt;
    }
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

N, M = LI()
S = input()
T = input()

X = lcm(N, M)
L = X
XS, XT = {}, {}
count = 0
LN = L/N
while True:
    XS[int(count*LN)] = S[count]
    count += 1
    if count > N-1:
        break

count = 0
LM = L/M
while True:
    XT[int(count*LM)] = T[count]
    count += 1
    if count > M-1:
        break

for key, value in XS.items():
    if key in XT:
        if value != XT[key]:
            print(-1)
            exit()

print(L)


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

using namespace std;

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

const int N = 1e5 + 5;
const int mod = 1e9 + 7;

inline int mul(int x,int y) {
  return (ll) x * y % mod;
}

int add(int x,int y) {
  return x + y >= mod ? x + y - mod : x + y;
}

int n,ans,cnt[26];
char s[N];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  cin >> n >> (s + 1);
  for (int i = 1 ; i <= n ; i++)
    cnt[s[i] - 'a']++;
  ans = 1;
  for (int i = 0 ; i < 26 ; i++)
    ans = mul(ans,cnt[i] + 1);
  cout << add(ans,mod - 1) << endl;
}

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

int main() {
	ios_base::sync_with_stdio( false );

	int A, B, C;
	cin >> A >> B >> C;

	if( A == B ) {
		cout << C << endl;
	}
	else if( A == C ) {
		cout << B << endl;
	}
	else {
		cout << A << endl;
	}

	return 0;
}


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

int main() {
	char s[2][55];
	scanf("%s%s", &s[0], &s[1]);
	int l[2];
	l[0] = strlen(s[0]); l[1] = strlen(s[1]);
	int i[2], d = 0;
	i[0] = i[1] = 0;
	while (i[0] < l[0] || i[1] < l[1]) {
        if (i[d] < l[d]) printf("%c", s[d][i[d]]);
        i[d]++;
		d ^= 1;
	}
	puts("");
	return 0;
}



Measured memory_bytes: 128
#include<stdio.h>

#define ok 1
#define ng 0

  int h,w;
  int judge_flag = ok;
  char map[51][51];

void judge(int i, int j){

  int flag = 0;

  if(i != 0){
    if(map[i-1][j] == '#') flag = 1;
  }

  if(i != h){
    if(map[i+1][j] == '#') flag = 1;
  }

  if(j != 0){
    if(map[i][j-1] == '#') flag = 1;
  }

  if(j != w){
    if(map[i][j+1] == '#') flag = 1;
  }

  if(flag == 1){
     return;
  }else{
    judge_flag = ng;
    return;
  }
}

int main(){


  scanf("%d %d",&h,&w);

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

  for(int i = 0; i < h; ++i){
    for(int j = 0; j < w; ++j){
      if( map[i][j] == '#' ) judge(i,j);
      if( judge_flag == ng ){
        printf("No");
        return 0;
      }
    }
  }

  printf("Yes");
  return 0;

}


Measured memory_bytes: 128
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>
using namespace std;

int main(int argc, const char * argv[]) {
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, m;
    cin >> n >> m;
    vector<vector<int>> adjmat(n, vector<int>(n, 0));
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        adjmat.at(a - 1).at(b - 1) = 1;
        adjmat.at(b - 1).at(a - 1) = 1;
    }
    
    vector<int> a;
    for (int i = 0; i < n ; i++) {
        a.push_back(i);
    }
    int cnt = 0;
    do {
        bool flag = true;
        for (int i = 0; i < n - 1; i++) {
            if (adjmat.at(a.at(i)).at(a.at(i + 1)) == 0) {
                flag = false;
                break;
            }
        }
        if (!flag) continue;
        cnt++;
    } while (next_permutation(a.begin(), a.end()) && a.at(0) == 0);
    
    cout << cnt << endl;
    
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize(3)
#include <bits/stdc++.h>
#define MAXN 105
char a[MAXN], b[MAXN], c[MAXN];
int main()
{
	scanf("%s\n%s\n%s", a + 1, b + 1, c + 1);
	int la = strlen(a + 1), lb = strlen(b + 1), lc = strlen(c + 1);
	int na = 2, nb = 1, nc = 1;
	char turn = a[1];
	while(1)
	{
		if(turn == 'a')
		{
			if(na > la)
			{
				printf("A\n");
				return 0;
			}
			turn = a[na];
			na++;
		}
		if(turn == 'b')
		{
			if(nb > lb)
			{
				printf("B\n");
				return 0;
			}
			turn = b[nb];
			nb++;
		}
		if(turn == 'c')
		{
			if(nc > lc)
			{
				printf("C\n");
				return 0;
			}
			turn = c[nc];
			nc++;
		}
	}
}

Measured memory_bytes: 256